lodash.js 515 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733
  1. /**
  2. * @license
  3. * lodash <https://lodash.com/>
  4. * Copyright jQuery Foundation and other contributors <https://jquery.org/>
  5. * Released under MIT license <https://lodash.com/license>
  6. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  7. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. */
  9. ;(function() {
  10. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  11. var undefined;
  12. /** Used as the semantic version number. */
  13. var VERSION = '4.15.0';
  14. /** Used as the size to enable large array optimizations. */
  15. var LARGE_ARRAY_SIZE = 200;
  16. /** Used as the `TypeError` message for "Functions" methods. */
  17. var FUNC_ERROR_TEXT = 'Expected a function';
  18. /** Used to stand-in for `undefined` hash values. */
  19. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  20. /** Used as the internal argument placeholder. */
  21. var PLACEHOLDER = '__lodash_placeholder__';
  22. /** Used to compose bitmasks for function metadata. */
  23. var BIND_FLAG = 1,
  24. BIND_KEY_FLAG = 2,
  25. CURRY_BOUND_FLAG = 4,
  26. CURRY_FLAG = 8,
  27. CURRY_RIGHT_FLAG = 16,
  28. PARTIAL_FLAG = 32,
  29. PARTIAL_RIGHT_FLAG = 64,
  30. ARY_FLAG = 128,
  31. REARG_FLAG = 256,
  32. FLIP_FLAG = 512;
  33. /** Used to compose bitmasks for comparison styles. */
  34. var UNORDERED_COMPARE_FLAG = 1,
  35. PARTIAL_COMPARE_FLAG = 2;
  36. /** Used as default options for `_.truncate`. */
  37. var DEFAULT_TRUNC_LENGTH = 30,
  38. DEFAULT_TRUNC_OMISSION = '...';
  39. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  40. var HOT_COUNT = 150,
  41. HOT_SPAN = 16;
  42. /** Used to indicate the type of lazy iteratees. */
  43. var LAZY_FILTER_FLAG = 1,
  44. LAZY_MAP_FLAG = 2,
  45. LAZY_WHILE_FLAG = 3;
  46. /** Used as references for various `Number` constants. */
  47. var INFINITY = 1 / 0,
  48. MAX_SAFE_INTEGER = 9007199254740991,
  49. MAX_INTEGER = 1.7976931348623157e+308,
  50. NAN = 0 / 0;
  51. /** Used as references for the maximum length and index of an array. */
  52. var MAX_ARRAY_LENGTH = 4294967295,
  53. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  54. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  55. /** Used to associate wrap methods with their bit flags. */
  56. var wrapFlags = [
  57. ['ary', ARY_FLAG],
  58. ['bind', BIND_FLAG],
  59. ['bindKey', BIND_KEY_FLAG],
  60. ['curry', CURRY_FLAG],
  61. ['curryRight', CURRY_RIGHT_FLAG],
  62. ['flip', FLIP_FLAG],
  63. ['partial', PARTIAL_FLAG],
  64. ['partialRight', PARTIAL_RIGHT_FLAG],
  65. ['rearg', REARG_FLAG]
  66. ];
  67. /** `Object#toString` result references. */
  68. var argsTag = '[object Arguments]',
  69. arrayTag = '[object Array]',
  70. boolTag = '[object Boolean]',
  71. dateTag = '[object Date]',
  72. errorTag = '[object Error]',
  73. funcTag = '[object Function]',
  74. genTag = '[object GeneratorFunction]',
  75. mapTag = '[object Map]',
  76. numberTag = '[object Number]',
  77. objectTag = '[object Object]',
  78. promiseTag = '[object Promise]',
  79. regexpTag = '[object RegExp]',
  80. setTag = '[object Set]',
  81. stringTag = '[object String]',
  82. symbolTag = '[object Symbol]',
  83. weakMapTag = '[object WeakMap]',
  84. weakSetTag = '[object WeakSet]';
  85. var arrayBufferTag = '[object ArrayBuffer]',
  86. dataViewTag = '[object DataView]',
  87. float32Tag = '[object Float32Array]',
  88. float64Tag = '[object Float64Array]',
  89. int8Tag = '[object Int8Array]',
  90. int16Tag = '[object Int16Array]',
  91. int32Tag = '[object Int32Array]',
  92. uint8Tag = '[object Uint8Array]',
  93. uint8ClampedTag = '[object Uint8ClampedArray]',
  94. uint16Tag = '[object Uint16Array]',
  95. uint32Tag = '[object Uint32Array]';
  96. /** Used to match empty string literals in compiled template source. */
  97. var reEmptyStringLeading = /\b__p \+= '';/g,
  98. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  99. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  100. /** Used to match HTML entities and HTML characters. */
  101. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  102. reUnescapedHtml = /[&<>"'`]/g,
  103. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  104. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  105. /** Used to match template delimiters. */
  106. var reEscape = /<%-([\s\S]+?)%>/g,
  107. reEvaluate = /<%([\s\S]+?)%>/g,
  108. reInterpolate = /<%=([\s\S]+?)%>/g;
  109. /** Used to match property names within property paths. */
  110. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  111. reIsPlainProp = /^\w*$/,
  112. reLeadingDot = /^\./,
  113. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  114. /**
  115. * Used to match `RegExp`
  116. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  117. */
  118. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  119. reHasRegExpChar = RegExp(reRegExpChar.source);
  120. /** Used to match leading and trailing whitespace. */
  121. var reTrim = /^\s+|\s+$/g,
  122. reTrimStart = /^\s+/,
  123. reTrimEnd = /\s+$/;
  124. /** Used to match wrap detail comments. */
  125. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  126. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  127. reSplitDetails = /,? & /;
  128. /** Used to match words composed of alphanumeric characters. */
  129. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  130. /** Used to match backslashes in property paths. */
  131. var reEscapeChar = /\\(\\)?/g;
  132. /**
  133. * Used to match
  134. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  135. */
  136. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  137. /** Used to match `RegExp` flags from their coerced string values. */
  138. var reFlags = /\w*$/;
  139. /** Used to detect hexadecimal string values. */
  140. var reHasHexPrefix = /^0x/i;
  141. /** Used to detect bad signed hexadecimal string values. */
  142. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  143. /** Used to detect binary string values. */
  144. var reIsBinary = /^0b[01]+$/i;
  145. /** Used to detect host constructors (Safari). */
  146. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  147. /** Used to detect octal string values. */
  148. var reIsOctal = /^0o[0-7]+$/i;
  149. /** Used to detect unsigned integer values. */
  150. var reIsUint = /^(?:0|[1-9]\d*)$/;
  151. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  152. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  153. /** Used to ensure capturing order of template delimiters. */
  154. var reNoMatch = /($^)/;
  155. /** Used to match unescaped characters in compiled string literals. */
  156. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  157. /** Used to compose unicode character classes. */
  158. var rsAstralRange = '\\ud800-\\udfff',
  159. rsComboMarksRange = '\\u0300-\\u036f\\ufe20-\\ufe23',
  160. rsComboSymbolsRange = '\\u20d0-\\u20f0',
  161. rsDingbatRange = '\\u2700-\\u27bf',
  162. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  163. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  164. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  165. rsPunctuationRange = '\\u2000-\\u206f',
  166. 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',
  167. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  168. rsVarRange = '\\ufe0e\\ufe0f',
  169. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  170. /** Used to compose unicode capture groups. */
  171. var rsApos = "['\u2019]",
  172. rsAstral = '[' + rsAstralRange + ']',
  173. rsBreak = '[' + rsBreakRange + ']',
  174. rsCombo = '[' + rsComboMarksRange + rsComboSymbolsRange + ']',
  175. rsDigits = '\\d+',
  176. rsDingbat = '[' + rsDingbatRange + ']',
  177. rsLower = '[' + rsLowerRange + ']',
  178. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  179. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  180. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  181. rsNonAstral = '[^' + rsAstralRange + ']',
  182. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  183. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  184. rsUpper = '[' + rsUpperRange + ']',
  185. rsZWJ = '\\u200d';
  186. /** Used to compose unicode regexes. */
  187. var rsLowerMisc = '(?:' + rsLower + '|' + rsMisc + ')',
  188. rsUpperMisc = '(?:' + rsUpper + '|' + rsMisc + ')',
  189. rsOptLowerContr = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  190. rsOptUpperContr = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  191. reOptMod = rsModifier + '?',
  192. rsOptVar = '[' + rsVarRange + ']?',
  193. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  194. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  195. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  196. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  197. /** Used to match apostrophes. */
  198. var reApos = RegExp(rsApos, 'g');
  199. /**
  200. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  201. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  202. */
  203. var reComboMark = RegExp(rsCombo, 'g');
  204. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  205. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  206. /** Used to match complex or compound words. */
  207. var reUnicodeWord = RegExp([
  208. rsUpper + '?' + rsLower + '+' + rsOptLowerContr + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  209. rsUpperMisc + '+' + rsOptUpperContr + '(?=' + [rsBreak, rsUpper + rsLowerMisc, '$'].join('|') + ')',
  210. rsUpper + '?' + rsLowerMisc + '+' + rsOptLowerContr,
  211. rsUpper + '+' + rsOptUpperContr,
  212. rsDigits,
  213. rsEmoji
  214. ].join('|'), 'g');
  215. /** 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/). */
  216. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboMarksRange + rsComboSymbolsRange + rsVarRange + ']');
  217. /** Used to detect strings that need a more robust regexp to match words. */
  218. 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 ]/;
  219. /** Used to assign default `context` object properties. */
  220. var contextProps = [
  221. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  222. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  223. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  224. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  225. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  226. ];
  227. /** Used to make template sourceURLs easier to identify. */
  228. var templateCounter = -1;
  229. /** Used to identify `toStringTag` values of typed arrays. */
  230. var typedArrayTags = {};
  231. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  232. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  233. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  234. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  235. typedArrayTags[uint32Tag] = true;
  236. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  237. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  238. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  239. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  240. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  241. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  242. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  243. typedArrayTags[weakMapTag] = false;
  244. /** Used to identify `toStringTag` values supported by `_.clone`. */
  245. var cloneableTags = {};
  246. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  247. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  248. cloneableTags[boolTag] = cloneableTags[dateTag] =
  249. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  250. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  251. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  252. cloneableTags[numberTag] = cloneableTags[objectTag] =
  253. cloneableTags[regexpTag] = cloneableTags[setTag] =
  254. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  255. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  256. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  257. cloneableTags[errorTag] = cloneableTags[funcTag] =
  258. cloneableTags[weakMapTag] = false;
  259. /** Used to map Latin Unicode letters to basic Latin letters. */
  260. var deburredLetters = {
  261. // Latin-1 Supplement block.
  262. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  263. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  264. '\xc7': 'C', '\xe7': 'c',
  265. '\xd0': 'D', '\xf0': 'd',
  266. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  267. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  268. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  269. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  270. '\xd1': 'N', '\xf1': 'n',
  271. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  272. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  273. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  274. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  275. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  276. '\xc6': 'Ae', '\xe6': 'ae',
  277. '\xde': 'Th', '\xfe': 'th',
  278. '\xdf': 'ss',
  279. // Latin Extended-A block.
  280. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  281. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  282. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  283. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  284. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  285. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  286. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  287. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  288. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  289. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  290. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  291. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  292. '\u0134': 'J', '\u0135': 'j',
  293. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  294. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  295. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  296. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  297. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  298. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  299. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  300. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  301. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  302. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  303. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  304. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  305. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  306. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  307. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  308. '\u0174': 'W', '\u0175': 'w',
  309. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  310. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  311. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  312. '\u0132': 'IJ', '\u0133': 'ij',
  313. '\u0152': 'Oe', '\u0153': 'oe',
  314. '\u0149': "'n", '\u017f': 'ss'
  315. };
  316. /** Used to map characters to HTML entities. */
  317. var htmlEscapes = {
  318. '&': '&amp;',
  319. '<': '&lt;',
  320. '>': '&gt;',
  321. '"': '&quot;',
  322. "'": '&#39;',
  323. '`': '&#96;'
  324. };
  325. /** Used to map HTML entities to characters. */
  326. var htmlUnescapes = {
  327. '&amp;': '&',
  328. '&lt;': '<',
  329. '&gt;': '>',
  330. '&quot;': '"',
  331. '&#39;': "'",
  332. '&#96;': '`'
  333. };
  334. /** Used to escape characters for inclusion in compiled string literals. */
  335. var stringEscapes = {
  336. '\\': '\\',
  337. "'": "'",
  338. '\n': 'n',
  339. '\r': 'r',
  340. '\u2028': 'u2028',
  341. '\u2029': 'u2029'
  342. };
  343. /** Built-in method references without a dependency on `root`. */
  344. var freeParseFloat = parseFloat,
  345. freeParseInt = parseInt;
  346. /** Detect free variable `global` from Node.js. */
  347. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  348. /** Detect free variable `self`. */
  349. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  350. /** Used as a reference to the global object. */
  351. var root = freeGlobal || freeSelf || Function('return this')();
  352. /** Detect free variable `exports`. */
  353. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  354. /** Detect free variable `module`. */
  355. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  356. /** Detect the popular CommonJS extension `module.exports`. */
  357. var moduleExports = freeModule && freeModule.exports === freeExports;
  358. /** Detect free variable `process` from Node.js. */
  359. var freeProcess = moduleExports && freeGlobal.process;
  360. /** Used to access faster Node.js helpers. */
  361. var nodeUtil = (function() {
  362. try {
  363. return freeProcess && freeProcess.binding('util');
  364. } catch (e) {}
  365. }());
  366. /* Node.js helper references. */
  367. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  368. nodeIsDate = nodeUtil && nodeUtil.isDate,
  369. nodeIsMap = nodeUtil && nodeUtil.isMap,
  370. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  371. nodeIsSet = nodeUtil && nodeUtil.isSet,
  372. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  373. /*--------------------------------------------------------------------------*/
  374. /**
  375. * Adds the key-value `pair` to `map`.
  376. *
  377. * @private
  378. * @param {Object} map The map to modify.
  379. * @param {Array} pair The key-value pair to add.
  380. * @returns {Object} Returns `map`.
  381. */
  382. function addMapEntry(map, pair) {
  383. // Don't return `map.set` because it's not chainable in IE 11.
  384. map.set(pair[0], pair[1]);
  385. return map;
  386. }
  387. /**
  388. * Adds `value` to `set`.
  389. *
  390. * @private
  391. * @param {Object} set The set to modify.
  392. * @param {*} value The value to add.
  393. * @returns {Object} Returns `set`.
  394. */
  395. function addSetEntry(set, value) {
  396. // Don't return `set.add` because it's not chainable in IE 11.
  397. set.add(value);
  398. return set;
  399. }
  400. /**
  401. * A faster alternative to `Function#apply`, this function invokes `func`
  402. * with the `this` binding of `thisArg` and the arguments of `args`.
  403. *
  404. * @private
  405. * @param {Function} func The function to invoke.
  406. * @param {*} thisArg The `this` binding of `func`.
  407. * @param {Array} args The arguments to invoke `func` with.
  408. * @returns {*} Returns the result of `func`.
  409. */
  410. function apply(func, thisArg, args) {
  411. switch (args.length) {
  412. case 0: return func.call(thisArg);
  413. case 1: return func.call(thisArg, args[0]);
  414. case 2: return func.call(thisArg, args[0], args[1]);
  415. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  416. }
  417. return func.apply(thisArg, args);
  418. }
  419. /**
  420. * A specialized version of `baseAggregator` for arrays.
  421. *
  422. * @private
  423. * @param {Array} [array] The array to iterate over.
  424. * @param {Function} setter The function to set `accumulator` values.
  425. * @param {Function} iteratee The iteratee to transform keys.
  426. * @param {Object} accumulator The initial aggregated object.
  427. * @returns {Function} Returns `accumulator`.
  428. */
  429. function arrayAggregator(array, setter, iteratee, accumulator) {
  430. var index = -1,
  431. length = array ? array.length : 0;
  432. while (++index < length) {
  433. var value = array[index];
  434. setter(accumulator, value, iteratee(value), array);
  435. }
  436. return accumulator;
  437. }
  438. /**
  439. * A specialized version of `_.forEach` for arrays without support for
  440. * iteratee shorthands.
  441. *
  442. * @private
  443. * @param {Array} [array] The array to iterate over.
  444. * @param {Function} iteratee The function invoked per iteration.
  445. * @returns {Array} Returns `array`.
  446. */
  447. function arrayEach(array, iteratee) {
  448. var index = -1,
  449. length = array ? array.length : 0;
  450. while (++index < length) {
  451. if (iteratee(array[index], index, array) === false) {
  452. break;
  453. }
  454. }
  455. return array;
  456. }
  457. /**
  458. * A specialized version of `_.forEachRight` for arrays without support for
  459. * iteratee shorthands.
  460. *
  461. * @private
  462. * @param {Array} [array] The array to iterate over.
  463. * @param {Function} iteratee The function invoked per iteration.
  464. * @returns {Array} Returns `array`.
  465. */
  466. function arrayEachRight(array, iteratee) {
  467. var length = array ? array.length : 0;
  468. while (length--) {
  469. if (iteratee(array[length], length, array) === false) {
  470. break;
  471. }
  472. }
  473. return array;
  474. }
  475. /**
  476. * A specialized version of `_.every` for arrays without support for
  477. * iteratee shorthands.
  478. *
  479. * @private
  480. * @param {Array} [array] The array to iterate over.
  481. * @param {Function} predicate The function invoked per iteration.
  482. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  483. * else `false`.
  484. */
  485. function arrayEvery(array, predicate) {
  486. var index = -1,
  487. length = array ? array.length : 0;
  488. while (++index < length) {
  489. if (!predicate(array[index], index, array)) {
  490. return false;
  491. }
  492. }
  493. return true;
  494. }
  495. /**
  496. * A specialized version of `_.filter` for arrays without support for
  497. * iteratee shorthands.
  498. *
  499. * @private
  500. * @param {Array} [array] The array to iterate over.
  501. * @param {Function} predicate The function invoked per iteration.
  502. * @returns {Array} Returns the new filtered array.
  503. */
  504. function arrayFilter(array, predicate) {
  505. var index = -1,
  506. length = array ? array.length : 0,
  507. resIndex = 0,
  508. result = [];
  509. while (++index < length) {
  510. var value = array[index];
  511. if (predicate(value, index, array)) {
  512. result[resIndex++] = value;
  513. }
  514. }
  515. return result;
  516. }
  517. /**
  518. * A specialized version of `_.includes` for arrays without support for
  519. * specifying an index to search from.
  520. *
  521. * @private
  522. * @param {Array} [array] The array to inspect.
  523. * @param {*} target The value to search for.
  524. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  525. */
  526. function arrayIncludes(array, value) {
  527. var length = array ? array.length : 0;
  528. return !!length && baseIndexOf(array, value, 0) > -1;
  529. }
  530. /**
  531. * This function is like `arrayIncludes` except that it accepts a comparator.
  532. *
  533. * @private
  534. * @param {Array} [array] The array to inspect.
  535. * @param {*} target The value to search for.
  536. * @param {Function} comparator The comparator invoked per element.
  537. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  538. */
  539. function arrayIncludesWith(array, value, comparator) {
  540. var index = -1,
  541. length = array ? array.length : 0;
  542. while (++index < length) {
  543. if (comparator(value, array[index])) {
  544. return true;
  545. }
  546. }
  547. return false;
  548. }
  549. /**
  550. * A specialized version of `_.map` for arrays without support for iteratee
  551. * shorthands.
  552. *
  553. * @private
  554. * @param {Array} [array] The array to iterate over.
  555. * @param {Function} iteratee The function invoked per iteration.
  556. * @returns {Array} Returns the new mapped array.
  557. */
  558. function arrayMap(array, iteratee) {
  559. var index = -1,
  560. length = array ? array.length : 0,
  561. result = Array(length);
  562. while (++index < length) {
  563. result[index] = iteratee(array[index], index, array);
  564. }
  565. return result;
  566. }
  567. /**
  568. * Appends the elements of `values` to `array`.
  569. *
  570. * @private
  571. * @param {Array} array The array to modify.
  572. * @param {Array} values The values to append.
  573. * @returns {Array} Returns `array`.
  574. */
  575. function arrayPush(array, values) {
  576. var index = -1,
  577. length = values.length,
  578. offset = array.length;
  579. while (++index < length) {
  580. array[offset + index] = values[index];
  581. }
  582. return array;
  583. }
  584. /**
  585. * A specialized version of `_.reduce` for arrays without support for
  586. * iteratee shorthands.
  587. *
  588. * @private
  589. * @param {Array} [array] The array to iterate over.
  590. * @param {Function} iteratee The function invoked per iteration.
  591. * @param {*} [accumulator] The initial value.
  592. * @param {boolean} [initAccum] Specify using the first element of `array` as
  593. * the initial value.
  594. * @returns {*} Returns the accumulated value.
  595. */
  596. function arrayReduce(array, iteratee, accumulator, initAccum) {
  597. var index = -1,
  598. length = array ? array.length : 0;
  599. if (initAccum && length) {
  600. accumulator = array[++index];
  601. }
  602. while (++index < length) {
  603. accumulator = iteratee(accumulator, array[index], index, array);
  604. }
  605. return accumulator;
  606. }
  607. /**
  608. * A specialized version of `_.reduceRight` for arrays without support for
  609. * iteratee shorthands.
  610. *
  611. * @private
  612. * @param {Array} [array] The array to iterate over.
  613. * @param {Function} iteratee The function invoked per iteration.
  614. * @param {*} [accumulator] The initial value.
  615. * @param {boolean} [initAccum] Specify using the last element of `array` as
  616. * the initial value.
  617. * @returns {*} Returns the accumulated value.
  618. */
  619. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  620. var length = array ? array.length : 0;
  621. if (initAccum && length) {
  622. accumulator = array[--length];
  623. }
  624. while (length--) {
  625. accumulator = iteratee(accumulator, array[length], length, array);
  626. }
  627. return accumulator;
  628. }
  629. /**
  630. * A specialized version of `_.some` for arrays without support for iteratee
  631. * shorthands.
  632. *
  633. * @private
  634. * @param {Array} [array] The array to iterate over.
  635. * @param {Function} predicate The function invoked per iteration.
  636. * @returns {boolean} Returns `true` if any element passes the predicate check,
  637. * else `false`.
  638. */
  639. function arraySome(array, predicate) {
  640. var index = -1,
  641. length = array ? array.length : 0;
  642. while (++index < length) {
  643. if (predicate(array[index], index, array)) {
  644. return true;
  645. }
  646. }
  647. return false;
  648. }
  649. /**
  650. * Gets the size of an ASCII `string`.
  651. *
  652. * @private
  653. * @param {string} string The string inspect.
  654. * @returns {number} Returns the string size.
  655. */
  656. var asciiSize = baseProperty('length');
  657. /**
  658. * Converts an ASCII `string` to an array.
  659. *
  660. * @private
  661. * @param {string} string The string to convert.
  662. * @returns {Array} Returns the converted array.
  663. */
  664. function asciiToArray(string) {
  665. return string.split('');
  666. }
  667. /**
  668. * Splits an ASCII `string` into an array of its words.
  669. *
  670. * @private
  671. * @param {string} The string to inspect.
  672. * @returns {Array} Returns the words of `string`.
  673. */
  674. function asciiWords(string) {
  675. return string.match(reAsciiWord) || [];
  676. }
  677. /**
  678. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  679. * without support for iteratee shorthands, which iterates over `collection`
  680. * using `eachFunc`.
  681. *
  682. * @private
  683. * @param {Array|Object} collection The collection to inspect.
  684. * @param {Function} predicate The function invoked per iteration.
  685. * @param {Function} eachFunc The function to iterate over `collection`.
  686. * @returns {*} Returns the found element or its key, else `undefined`.
  687. */
  688. function baseFindKey(collection, predicate, eachFunc) {
  689. var result;
  690. eachFunc(collection, function(value, key, collection) {
  691. if (predicate(value, key, collection)) {
  692. result = key;
  693. return false;
  694. }
  695. });
  696. return result;
  697. }
  698. /**
  699. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  700. * support for iteratee shorthands.
  701. *
  702. * @private
  703. * @param {Array} array The array to inspect.
  704. * @param {Function} predicate The function invoked per iteration.
  705. * @param {number} fromIndex The index to search from.
  706. * @param {boolean} [fromRight] Specify iterating from right to left.
  707. * @returns {number} Returns the index of the matched value, else `-1`.
  708. */
  709. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  710. var length = array.length,
  711. index = fromIndex + (fromRight ? 1 : -1);
  712. while ((fromRight ? index-- : ++index < length)) {
  713. if (predicate(array[index], index, array)) {
  714. return index;
  715. }
  716. }
  717. return -1;
  718. }
  719. /**
  720. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  721. *
  722. * @private
  723. * @param {Array} array The array to inspect.
  724. * @param {*} value The value to search for.
  725. * @param {number} fromIndex The index to search from.
  726. * @returns {number} Returns the index of the matched value, else `-1`.
  727. */
  728. function baseIndexOf(array, value, fromIndex) {
  729. if (value !== value) {
  730. return baseFindIndex(array, baseIsNaN, fromIndex);
  731. }
  732. var index = fromIndex - 1,
  733. length = array.length;
  734. while (++index < length) {
  735. if (array[index] === value) {
  736. return index;
  737. }
  738. }
  739. return -1;
  740. }
  741. /**
  742. * This function is like `baseIndexOf` except that it accepts a comparator.
  743. *
  744. * @private
  745. * @param {Array} array The array to inspect.
  746. * @param {*} value The value to search for.
  747. * @param {number} fromIndex The index to search from.
  748. * @param {Function} comparator The comparator invoked per element.
  749. * @returns {number} Returns the index of the matched value, else `-1`.
  750. */
  751. function baseIndexOfWith(array, value, fromIndex, comparator) {
  752. var index = fromIndex - 1,
  753. length = array.length;
  754. while (++index < length) {
  755. if (comparator(array[index], value)) {
  756. return index;
  757. }
  758. }
  759. return -1;
  760. }
  761. /**
  762. * The base implementation of `_.isNaN` without support for number objects.
  763. *
  764. * @private
  765. * @param {*} value The value to check.
  766. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  767. */
  768. function baseIsNaN(value) {
  769. return value !== value;
  770. }
  771. /**
  772. * The base implementation of `_.mean` and `_.meanBy` without support for
  773. * iteratee shorthands.
  774. *
  775. * @private
  776. * @param {Array} array The array to iterate over.
  777. * @param {Function} iteratee The function invoked per iteration.
  778. * @returns {number} Returns the mean.
  779. */
  780. function baseMean(array, iteratee) {
  781. var length = array ? array.length : 0;
  782. return length ? (baseSum(array, iteratee) / length) : NAN;
  783. }
  784. /**
  785. * The base implementation of `_.property` without support for deep paths.
  786. *
  787. * @private
  788. * @param {string} key The key of the property to get.
  789. * @returns {Function} Returns the new accessor function.
  790. */
  791. function baseProperty(key) {
  792. return function(object) {
  793. return object == null ? undefined : object[key];
  794. };
  795. }
  796. /**
  797. * The base implementation of `_.propertyOf` without support for deep paths.
  798. *
  799. * @private
  800. * @param {Object} object The object to query.
  801. * @returns {Function} Returns the new accessor function.
  802. */
  803. function basePropertyOf(object) {
  804. return function(key) {
  805. return object == null ? undefined : object[key];
  806. };
  807. }
  808. /**
  809. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  810. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  811. *
  812. * @private
  813. * @param {Array|Object} collection The collection to iterate over.
  814. * @param {Function} iteratee The function invoked per iteration.
  815. * @param {*} accumulator The initial value.
  816. * @param {boolean} initAccum Specify using the first or last element of
  817. * `collection` as the initial value.
  818. * @param {Function} eachFunc The function to iterate over `collection`.
  819. * @returns {*} Returns the accumulated value.
  820. */
  821. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  822. eachFunc(collection, function(value, index, collection) {
  823. accumulator = initAccum
  824. ? (initAccum = false, value)
  825. : iteratee(accumulator, value, index, collection);
  826. });
  827. return accumulator;
  828. }
  829. /**
  830. * The base implementation of `_.sortBy` which uses `comparer` to define the
  831. * sort order of `array` and replaces criteria objects with their corresponding
  832. * values.
  833. *
  834. * @private
  835. * @param {Array} array The array to sort.
  836. * @param {Function} comparer The function to define sort order.
  837. * @returns {Array} Returns `array`.
  838. */
  839. function baseSortBy(array, comparer) {
  840. var length = array.length;
  841. array.sort(comparer);
  842. while (length--) {
  843. array[length] = array[length].value;
  844. }
  845. return array;
  846. }
  847. /**
  848. * The base implementation of `_.sum` and `_.sumBy` without support for
  849. * iteratee shorthands.
  850. *
  851. * @private
  852. * @param {Array} array The array to iterate over.
  853. * @param {Function} iteratee The function invoked per iteration.
  854. * @returns {number} Returns the sum.
  855. */
  856. function baseSum(array, iteratee) {
  857. var result,
  858. index = -1,
  859. length = array.length;
  860. while (++index < length) {
  861. var current = iteratee(array[index]);
  862. if (current !== undefined) {
  863. result = result === undefined ? current : (result + current);
  864. }
  865. }
  866. return result;
  867. }
  868. /**
  869. * The base implementation of `_.times` without support for iteratee shorthands
  870. * or max array length checks.
  871. *
  872. * @private
  873. * @param {number} n The number of times to invoke `iteratee`.
  874. * @param {Function} iteratee The function invoked per iteration.
  875. * @returns {Array} Returns the array of results.
  876. */
  877. function baseTimes(n, iteratee) {
  878. var index = -1,
  879. result = Array(n);
  880. while (++index < n) {
  881. result[index] = iteratee(index);
  882. }
  883. return result;
  884. }
  885. /**
  886. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  887. * of key-value pairs for `object` corresponding to the property names of `props`.
  888. *
  889. * @private
  890. * @param {Object} object The object to query.
  891. * @param {Array} props The property names to get values for.
  892. * @returns {Object} Returns the key-value pairs.
  893. */
  894. function baseToPairs(object, props) {
  895. return arrayMap(props, function(key) {
  896. return [key, object[key]];
  897. });
  898. }
  899. /**
  900. * The base implementation of `_.unary` without support for storing metadata.
  901. *
  902. * @private
  903. * @param {Function} func The function to cap arguments for.
  904. * @returns {Function} Returns the new capped function.
  905. */
  906. function baseUnary(func) {
  907. return function(value) {
  908. return func(value);
  909. };
  910. }
  911. /**
  912. * The base implementation of `_.values` and `_.valuesIn` which creates an
  913. * array of `object` property values corresponding to the property names
  914. * of `props`.
  915. *
  916. * @private
  917. * @param {Object} object The object to query.
  918. * @param {Array} props The property names to get values for.
  919. * @returns {Object} Returns the array of property values.
  920. */
  921. function baseValues(object, props) {
  922. return arrayMap(props, function(key) {
  923. return object[key];
  924. });
  925. }
  926. /**
  927. * Checks if a cache value for `key` exists.
  928. *
  929. * @private
  930. * @param {Object} cache The cache to query.
  931. * @param {string} key The key of the entry to check.
  932. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  933. */
  934. function cacheHas(cache, key) {
  935. return cache.has(key);
  936. }
  937. /**
  938. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  939. * that is not found in the character symbols.
  940. *
  941. * @private
  942. * @param {Array} strSymbols The string symbols to inspect.
  943. * @param {Array} chrSymbols The character symbols to find.
  944. * @returns {number} Returns the index of the first unmatched string symbol.
  945. */
  946. function charsStartIndex(strSymbols, chrSymbols) {
  947. var index = -1,
  948. length = strSymbols.length;
  949. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  950. return index;
  951. }
  952. /**
  953. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  954. * that is not found in the character symbols.
  955. *
  956. * @private
  957. * @param {Array} strSymbols The string symbols to inspect.
  958. * @param {Array} chrSymbols The character symbols to find.
  959. * @returns {number} Returns the index of the last unmatched string symbol.
  960. */
  961. function charsEndIndex(strSymbols, chrSymbols) {
  962. var index = strSymbols.length;
  963. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  964. return index;
  965. }
  966. /**
  967. * Gets the number of `placeholder` occurrences in `array`.
  968. *
  969. * @private
  970. * @param {Array} array The array to inspect.
  971. * @param {*} placeholder The placeholder to search for.
  972. * @returns {number} Returns the placeholder count.
  973. */
  974. function countHolders(array, placeholder) {
  975. var length = array.length,
  976. result = 0;
  977. while (length--) {
  978. if (array[length] === placeholder) {
  979. result++;
  980. }
  981. }
  982. return result;
  983. }
  984. /**
  985. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  986. * letters to basic Latin letters.
  987. *
  988. * @private
  989. * @param {string} letter The matched letter to deburr.
  990. * @returns {string} Returns the deburred letter.
  991. */
  992. var deburrLetter = basePropertyOf(deburredLetters);
  993. /**
  994. * Used by `_.escape` to convert characters to HTML entities.
  995. *
  996. * @private
  997. * @param {string} chr The matched character to escape.
  998. * @returns {string} Returns the escaped character.
  999. */
  1000. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  1001. /**
  1002. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  1003. *
  1004. * @private
  1005. * @param {string} chr The matched character to escape.
  1006. * @returns {string} Returns the escaped character.
  1007. */
  1008. function escapeStringChar(chr) {
  1009. return '\\' + stringEscapes[chr];
  1010. }
  1011. /**
  1012. * Gets the value at `key` of `object`.
  1013. *
  1014. * @private
  1015. * @param {Object} [object] The object to query.
  1016. * @param {string} key The key of the property to get.
  1017. * @returns {*} Returns the property value.
  1018. */
  1019. function getValue(object, key) {
  1020. return object == null ? undefined : object[key];
  1021. }
  1022. /**
  1023. * Checks if `string` contains Unicode symbols.
  1024. *
  1025. * @private
  1026. * @param {string} string The string to inspect.
  1027. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1028. */
  1029. function hasUnicode(string) {
  1030. return reHasUnicode.test(string);
  1031. }
  1032. /**
  1033. * Checks if `string` contains a word composed of Unicode symbols.
  1034. *
  1035. * @private
  1036. * @param {string} string The string to inspect.
  1037. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1038. */
  1039. function hasUnicodeWord(string) {
  1040. return reHasUnicodeWord.test(string);
  1041. }
  1042. /**
  1043. * Checks if `value` is a host object in IE < 9.
  1044. *
  1045. * @private
  1046. * @param {*} value The value to check.
  1047. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  1048. */
  1049. function isHostObject(value) {
  1050. // Many host objects are `Object` objects that can coerce to strings
  1051. // despite having improperly defined `toString` methods.
  1052. var result = false;
  1053. if (value != null && typeof value.toString != 'function') {
  1054. try {
  1055. result = !!(value + '');
  1056. } catch (e) {}
  1057. }
  1058. return result;
  1059. }
  1060. /**
  1061. * Converts `iterator` to an array.
  1062. *
  1063. * @private
  1064. * @param {Object} iterator The iterator to convert.
  1065. * @returns {Array} Returns the converted array.
  1066. */
  1067. function iteratorToArray(iterator) {
  1068. var data,
  1069. result = [];
  1070. while (!(data = iterator.next()).done) {
  1071. result.push(data.value);
  1072. }
  1073. return result;
  1074. }
  1075. /**
  1076. * Converts `map` to its key-value pairs.
  1077. *
  1078. * @private
  1079. * @param {Object} map The map to convert.
  1080. * @returns {Array} Returns the key-value pairs.
  1081. */
  1082. function mapToArray(map) {
  1083. var index = -1,
  1084. result = Array(map.size);
  1085. map.forEach(function(value, key) {
  1086. result[++index] = [key, value];
  1087. });
  1088. return result;
  1089. }
  1090. /**
  1091. * Creates a unary function that invokes `func` with its argument transformed.
  1092. *
  1093. * @private
  1094. * @param {Function} func The function to wrap.
  1095. * @param {Function} transform The argument transform.
  1096. * @returns {Function} Returns the new function.
  1097. */
  1098. function overArg(func, transform) {
  1099. return function(arg) {
  1100. return func(transform(arg));
  1101. };
  1102. }
  1103. /**
  1104. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1105. * and returns an array of their indexes.
  1106. *
  1107. * @private
  1108. * @param {Array} array The array to modify.
  1109. * @param {*} placeholder The placeholder to replace.
  1110. * @returns {Array} Returns the new array of placeholder indexes.
  1111. */
  1112. function replaceHolders(array, placeholder) {
  1113. var index = -1,
  1114. length = array.length,
  1115. resIndex = 0,
  1116. result = [];
  1117. while (++index < length) {
  1118. var value = array[index];
  1119. if (value === placeholder || value === PLACEHOLDER) {
  1120. array[index] = PLACEHOLDER;
  1121. result[resIndex++] = index;
  1122. }
  1123. }
  1124. return result;
  1125. }
  1126. /**
  1127. * Converts `set` to an array of its values.
  1128. *
  1129. * @private
  1130. * @param {Object} set The set to convert.
  1131. * @returns {Array} Returns the values.
  1132. */
  1133. function setToArray(set) {
  1134. var index = -1,
  1135. result = Array(set.size);
  1136. set.forEach(function(value) {
  1137. result[++index] = value;
  1138. });
  1139. return result;
  1140. }
  1141. /**
  1142. * Converts `set` to its value-value pairs.
  1143. *
  1144. * @private
  1145. * @param {Object} set The set to convert.
  1146. * @returns {Array} Returns the value-value pairs.
  1147. */
  1148. function setToPairs(set) {
  1149. var index = -1,
  1150. result = Array(set.size);
  1151. set.forEach(function(value) {
  1152. result[++index] = [value, value];
  1153. });
  1154. return result;
  1155. }
  1156. /**
  1157. * Gets the number of symbols in `string`.
  1158. *
  1159. * @private
  1160. * @param {string} string The string to inspect.
  1161. * @returns {number} Returns the string size.
  1162. */
  1163. function stringSize(string) {
  1164. return hasUnicode(string)
  1165. ? unicodeSize(string)
  1166. : asciiSize(string);
  1167. }
  1168. /**
  1169. * Converts `string` to an array.
  1170. *
  1171. * @private
  1172. * @param {string} string The string to convert.
  1173. * @returns {Array} Returns the converted array.
  1174. */
  1175. function stringToArray(string) {
  1176. return hasUnicode(string)
  1177. ? unicodeToArray(string)
  1178. : asciiToArray(string);
  1179. }
  1180. /**
  1181. * Used by `_.unescape` to convert HTML entities to characters.
  1182. *
  1183. * @private
  1184. * @param {string} chr The matched character to unescape.
  1185. * @returns {string} Returns the unescaped character.
  1186. */
  1187. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1188. /**
  1189. * Gets the size of a Unicode `string`.
  1190. *
  1191. * @private
  1192. * @param {string} string The string inspect.
  1193. * @returns {number} Returns the string size.
  1194. */
  1195. function unicodeSize(string) {
  1196. var result = reUnicode.lastIndex = 0;
  1197. while (reUnicode.test(string)) {
  1198. result++;
  1199. }
  1200. return result;
  1201. }
  1202. /**
  1203. * Converts a Unicode `string` to an array.
  1204. *
  1205. * @private
  1206. * @param {string} string The string to convert.
  1207. * @returns {Array} Returns the converted array.
  1208. */
  1209. function unicodeToArray(string) {
  1210. return string.match(reUnicode) || [];
  1211. }
  1212. /**
  1213. * Splits a Unicode `string` into an array of its words.
  1214. *
  1215. * @private
  1216. * @param {string} The string to inspect.
  1217. * @returns {Array} Returns the words of `string`.
  1218. */
  1219. function unicodeWords(string) {
  1220. return string.match(reUnicodeWord) || [];
  1221. }
  1222. /*--------------------------------------------------------------------------*/
  1223. /**
  1224. * Create a new pristine `lodash` function using the `context` object.
  1225. *
  1226. * @static
  1227. * @memberOf _
  1228. * @since 1.1.0
  1229. * @category Util
  1230. * @param {Object} [context=root] The context object.
  1231. * @returns {Function} Returns a new `lodash` function.
  1232. * @example
  1233. *
  1234. * _.mixin({ 'foo': _.constant('foo') });
  1235. *
  1236. * var lodash = _.runInContext();
  1237. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1238. *
  1239. * _.isFunction(_.foo);
  1240. * // => true
  1241. * _.isFunction(_.bar);
  1242. * // => false
  1243. *
  1244. * lodash.isFunction(lodash.foo);
  1245. * // => false
  1246. * lodash.isFunction(lodash.bar);
  1247. * // => true
  1248. *
  1249. * // Use `context` to stub `Date#getTime` use in `_.now`.
  1250. * var stubbed = _.runInContext({
  1251. * 'Date': function() {
  1252. * return { 'getTime': stubGetTime };
  1253. * }
  1254. * });
  1255. *
  1256. * // Create a suped-up `defer` in Node.js.
  1257. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1258. */
  1259. function runInContext(context) {
  1260. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  1261. /** Built-in constructor references. */
  1262. var Array = context.Array,
  1263. Date = context.Date,
  1264. Error = context.Error,
  1265. Function = context.Function,
  1266. Math = context.Math,
  1267. Object = context.Object,
  1268. RegExp = context.RegExp,
  1269. String = context.String,
  1270. TypeError = context.TypeError;
  1271. /** Used for built-in method references. */
  1272. var arrayProto = Array.prototype,
  1273. funcProto = Function.prototype,
  1274. objectProto = Object.prototype;
  1275. /** Used to detect overreaching core-js shims. */
  1276. var coreJsData = context['__core-js_shared__'];
  1277. /** Used to detect methods masquerading as native. */
  1278. var maskSrcKey = (function() {
  1279. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1280. return uid ? ('Symbol(src)_1.' + uid) : '';
  1281. }());
  1282. /** Used to resolve the decompiled source of functions. */
  1283. var funcToString = funcProto.toString;
  1284. /** Used to check objects for own properties. */
  1285. var hasOwnProperty = objectProto.hasOwnProperty;
  1286. /** Used to generate unique IDs. */
  1287. var idCounter = 0;
  1288. /** Used to infer the `Object` constructor. */
  1289. var objectCtorString = funcToString.call(Object);
  1290. /**
  1291. * Used to resolve the
  1292. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1293. * of values.
  1294. */
  1295. var objectToString = objectProto.toString;
  1296. /** Used to restore the original `_` reference in `_.noConflict`. */
  1297. var oldDash = root._;
  1298. /** Used to detect if a method is native. */
  1299. var reIsNative = RegExp('^' +
  1300. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1301. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1302. );
  1303. /** Built-in value references. */
  1304. var Buffer = moduleExports ? context.Buffer : undefined,
  1305. Symbol = context.Symbol,
  1306. Uint8Array = context.Uint8Array,
  1307. getPrototype = overArg(Object.getPrototypeOf, Object),
  1308. iteratorSymbol = Symbol ? Symbol.iterator : undefined,
  1309. objectCreate = Object.create,
  1310. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1311. splice = arrayProto.splice,
  1312. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined;
  1313. /** Mocked built-ins. */
  1314. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1315. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1316. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1317. /* Built-in method references for those with the same name as other `lodash` methods. */
  1318. var nativeCeil = Math.ceil,
  1319. nativeFloor = Math.floor,
  1320. nativeGetSymbols = Object.getOwnPropertySymbols,
  1321. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1322. nativeIsFinite = context.isFinite,
  1323. nativeJoin = arrayProto.join,
  1324. nativeKeys = overArg(Object.keys, Object),
  1325. nativeMax = Math.max,
  1326. nativeMin = Math.min,
  1327. nativeParseInt = context.parseInt,
  1328. nativeRandom = Math.random,
  1329. nativeReverse = arrayProto.reverse;
  1330. /* Built-in method references that are verified to be native. */
  1331. var DataView = getNative(context, 'DataView'),
  1332. Map = getNative(context, 'Map'),
  1333. Promise = getNative(context, 'Promise'),
  1334. Set = getNative(context, 'Set'),
  1335. WeakMap = getNative(context, 'WeakMap'),
  1336. nativeCreate = getNative(Object, 'create');
  1337. /* Used to set `toString` methods. */
  1338. var defineProperty = (function() {
  1339. var func = getNative(Object, 'defineProperty'),
  1340. name = getNative.name;
  1341. return (name && name.length > 2) ? func : undefined;
  1342. }());
  1343. /** Used to store function metadata. */
  1344. var metaMap = WeakMap && new WeakMap;
  1345. /** Detect if properties shadowing those on `Object.prototype` are non-enumerable. */
  1346. var nonEnumShadows = !propertyIsEnumerable.call({ 'valueOf': 1 }, 'valueOf');
  1347. /** Used to lookup unminified function names. */
  1348. var realNames = {};
  1349. /** Used to detect maps, sets, and weakmaps. */
  1350. var dataViewCtorString = toSource(DataView),
  1351. mapCtorString = toSource(Map),
  1352. promiseCtorString = toSource(Promise),
  1353. setCtorString = toSource(Set),
  1354. weakMapCtorString = toSource(WeakMap);
  1355. /** Used to convert symbols to primitives and strings. */
  1356. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1357. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1358. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1359. /*------------------------------------------------------------------------*/
  1360. /**
  1361. * Creates a `lodash` object which wraps `value` to enable implicit method
  1362. * chain sequences. Methods that operate on and return arrays, collections,
  1363. * and functions can be chained together. Methods that retrieve a single value
  1364. * or may return a primitive value will automatically end the chain sequence
  1365. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1366. * with `_#value`.
  1367. *
  1368. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1369. * enabled using `_.chain`.
  1370. *
  1371. * The execution of chained methods is lazy, that is, it's deferred until
  1372. * `_#value` is implicitly or explicitly called.
  1373. *
  1374. * Lazy evaluation allows several methods to support shortcut fusion.
  1375. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1376. * the creation of intermediate arrays and can greatly reduce the number of
  1377. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1378. * fusion if the section is applied to an array of at least `200` elements
  1379. * and any iteratees accept only one argument. The heuristic for whether a
  1380. * section qualifies for shortcut fusion is subject to change.
  1381. *
  1382. * Chaining is supported in custom builds as long as the `_#value` method is
  1383. * directly or indirectly included in the build.
  1384. *
  1385. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1386. *
  1387. * The wrapper `Array` methods are:
  1388. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1389. *
  1390. * The wrapper `String` methods are:
  1391. * `replace` and `split`
  1392. *
  1393. * The wrapper methods that support shortcut fusion are:
  1394. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1395. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1396. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1397. *
  1398. * The chainable wrapper methods are:
  1399. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1400. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1401. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1402. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1403. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1404. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1405. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1406. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1407. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1408. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1409. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1410. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1411. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1412. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1413. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1414. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1415. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1416. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1417. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1418. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1419. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1420. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1421. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1422. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1423. *
  1424. * The wrapper methods that are **not** chainable by default are:
  1425. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1426. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1427. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1428. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1429. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1430. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1431. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1432. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1433. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1434. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1435. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1436. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1437. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1438. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1439. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1440. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1441. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1442. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1443. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1444. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1445. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1446. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1447. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1448. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1449. * `upperFirst`, `value`, and `words`
  1450. *
  1451. * @name _
  1452. * @constructor
  1453. * @category Seq
  1454. * @param {*} value The value to wrap in a `lodash` instance.
  1455. * @returns {Object} Returns the new `lodash` wrapper instance.
  1456. * @example
  1457. *
  1458. * function square(n) {
  1459. * return n * n;
  1460. * }
  1461. *
  1462. * var wrapped = _([1, 2, 3]);
  1463. *
  1464. * // Returns an unwrapped value.
  1465. * wrapped.reduce(_.add);
  1466. * // => 6
  1467. *
  1468. * // Returns a wrapped value.
  1469. * var squares = wrapped.map(square);
  1470. *
  1471. * _.isArray(squares);
  1472. * // => false
  1473. *
  1474. * _.isArray(squares.value());
  1475. * // => true
  1476. */
  1477. function lodash(value) {
  1478. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1479. if (value instanceof LodashWrapper) {
  1480. return value;
  1481. }
  1482. if (hasOwnProperty.call(value, '__wrapped__')) {
  1483. return wrapperClone(value);
  1484. }
  1485. }
  1486. return new LodashWrapper(value);
  1487. }
  1488. /**
  1489. * The function whose prototype chain sequence wrappers inherit from.
  1490. *
  1491. * @private
  1492. */
  1493. function baseLodash() {
  1494. // No operation performed.
  1495. }
  1496. /**
  1497. * The base constructor for creating `lodash` wrapper objects.
  1498. *
  1499. * @private
  1500. * @param {*} value The value to wrap.
  1501. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1502. */
  1503. function LodashWrapper(value, chainAll) {
  1504. this.__wrapped__ = value;
  1505. this.__actions__ = [];
  1506. this.__chain__ = !!chainAll;
  1507. this.__index__ = 0;
  1508. this.__values__ = undefined;
  1509. }
  1510. /**
  1511. * By default, the template delimiters used by lodash are like those in
  1512. * embedded Ruby (ERB). Change the following template settings to use
  1513. * alternative delimiters.
  1514. *
  1515. * @static
  1516. * @memberOf _
  1517. * @type {Object}
  1518. */
  1519. lodash.templateSettings = {
  1520. /**
  1521. * Used to detect `data` property values to be HTML-escaped.
  1522. *
  1523. * @memberOf _.templateSettings
  1524. * @type {RegExp}
  1525. */
  1526. 'escape': reEscape,
  1527. /**
  1528. * Used to detect code to be evaluated.
  1529. *
  1530. * @memberOf _.templateSettings
  1531. * @type {RegExp}
  1532. */
  1533. 'evaluate': reEvaluate,
  1534. /**
  1535. * Used to detect `data` property values to inject.
  1536. *
  1537. * @memberOf _.templateSettings
  1538. * @type {RegExp}
  1539. */
  1540. 'interpolate': reInterpolate,
  1541. /**
  1542. * Used to reference the data object in the template text.
  1543. *
  1544. * @memberOf _.templateSettings
  1545. * @type {string}
  1546. */
  1547. 'variable': '',
  1548. /**
  1549. * Used to import variables into the compiled template.
  1550. *
  1551. * @memberOf _.templateSettings
  1552. * @type {Object}
  1553. */
  1554. 'imports': {
  1555. /**
  1556. * A reference to the `lodash` function.
  1557. *
  1558. * @memberOf _.templateSettings.imports
  1559. * @type {Function}
  1560. */
  1561. '_': lodash
  1562. }
  1563. };
  1564. // Ensure wrappers are instances of `baseLodash`.
  1565. lodash.prototype = baseLodash.prototype;
  1566. lodash.prototype.constructor = lodash;
  1567. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1568. LodashWrapper.prototype.constructor = LodashWrapper;
  1569. /*------------------------------------------------------------------------*/
  1570. /**
  1571. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1572. *
  1573. * @private
  1574. * @constructor
  1575. * @param {*} value The value to wrap.
  1576. */
  1577. function LazyWrapper(value) {
  1578. this.__wrapped__ = value;
  1579. this.__actions__ = [];
  1580. this.__dir__ = 1;
  1581. this.__filtered__ = false;
  1582. this.__iteratees__ = [];
  1583. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1584. this.__views__ = [];
  1585. }
  1586. /**
  1587. * Creates a clone of the lazy wrapper object.
  1588. *
  1589. * @private
  1590. * @name clone
  1591. * @memberOf LazyWrapper
  1592. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1593. */
  1594. function lazyClone() {
  1595. var result = new LazyWrapper(this.__wrapped__);
  1596. result.__actions__ = copyArray(this.__actions__);
  1597. result.__dir__ = this.__dir__;
  1598. result.__filtered__ = this.__filtered__;
  1599. result.__iteratees__ = copyArray(this.__iteratees__);
  1600. result.__takeCount__ = this.__takeCount__;
  1601. result.__views__ = copyArray(this.__views__);
  1602. return result;
  1603. }
  1604. /**
  1605. * Reverses the direction of lazy iteration.
  1606. *
  1607. * @private
  1608. * @name reverse
  1609. * @memberOf LazyWrapper
  1610. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1611. */
  1612. function lazyReverse() {
  1613. if (this.__filtered__) {
  1614. var result = new LazyWrapper(this);
  1615. result.__dir__ = -1;
  1616. result.__filtered__ = true;
  1617. } else {
  1618. result = this.clone();
  1619. result.__dir__ *= -1;
  1620. }
  1621. return result;
  1622. }
  1623. /**
  1624. * Extracts the unwrapped value from its lazy wrapper.
  1625. *
  1626. * @private
  1627. * @name value
  1628. * @memberOf LazyWrapper
  1629. * @returns {*} Returns the unwrapped value.
  1630. */
  1631. function lazyValue() {
  1632. var array = this.__wrapped__.value(),
  1633. dir = this.__dir__,
  1634. isArr = isArray(array),
  1635. isRight = dir < 0,
  1636. arrLength = isArr ? array.length : 0,
  1637. view = getView(0, arrLength, this.__views__),
  1638. start = view.start,
  1639. end = view.end,
  1640. length = end - start,
  1641. index = isRight ? end : (start - 1),
  1642. iteratees = this.__iteratees__,
  1643. iterLength = iteratees.length,
  1644. resIndex = 0,
  1645. takeCount = nativeMin(length, this.__takeCount__);
  1646. if (!isArr || arrLength < LARGE_ARRAY_SIZE ||
  1647. (arrLength == length && takeCount == length)) {
  1648. return baseWrapperValue(array, this.__actions__);
  1649. }
  1650. var result = [];
  1651. outer:
  1652. while (length-- && resIndex < takeCount) {
  1653. index += dir;
  1654. var iterIndex = -1,
  1655. value = array[index];
  1656. while (++iterIndex < iterLength) {
  1657. var data = iteratees[iterIndex],
  1658. iteratee = data.iteratee,
  1659. type = data.type,
  1660. computed = iteratee(value);
  1661. if (type == LAZY_MAP_FLAG) {
  1662. value = computed;
  1663. } else if (!computed) {
  1664. if (type == LAZY_FILTER_FLAG) {
  1665. continue outer;
  1666. } else {
  1667. break outer;
  1668. }
  1669. }
  1670. }
  1671. result[resIndex++] = value;
  1672. }
  1673. return result;
  1674. }
  1675. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1676. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1677. LazyWrapper.prototype.constructor = LazyWrapper;
  1678. /*------------------------------------------------------------------------*/
  1679. /**
  1680. * Creates a hash object.
  1681. *
  1682. * @private
  1683. * @constructor
  1684. * @param {Array} [entries] The key-value pairs to cache.
  1685. */
  1686. function Hash(entries) {
  1687. var index = -1,
  1688. length = entries ? entries.length : 0;
  1689. this.clear();
  1690. while (++index < length) {
  1691. var entry = entries[index];
  1692. this.set(entry[0], entry[1]);
  1693. }
  1694. }
  1695. /**
  1696. * Removes all key-value entries from the hash.
  1697. *
  1698. * @private
  1699. * @name clear
  1700. * @memberOf Hash
  1701. */
  1702. function hashClear() {
  1703. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1704. }
  1705. /**
  1706. * Removes `key` and its value from the hash.
  1707. *
  1708. * @private
  1709. * @name delete
  1710. * @memberOf Hash
  1711. * @param {Object} hash The hash to modify.
  1712. * @param {string} key The key of the value to remove.
  1713. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1714. */
  1715. function hashDelete(key) {
  1716. return this.has(key) && delete this.__data__[key];
  1717. }
  1718. /**
  1719. * Gets the hash value for `key`.
  1720. *
  1721. * @private
  1722. * @name get
  1723. * @memberOf Hash
  1724. * @param {string} key The key of the value to get.
  1725. * @returns {*} Returns the entry value.
  1726. */
  1727. function hashGet(key) {
  1728. var data = this.__data__;
  1729. if (nativeCreate) {
  1730. var result = data[key];
  1731. return result === HASH_UNDEFINED ? undefined : result;
  1732. }
  1733. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1734. }
  1735. /**
  1736. * Checks if a hash value for `key` exists.
  1737. *
  1738. * @private
  1739. * @name has
  1740. * @memberOf Hash
  1741. * @param {string} key The key of the entry to check.
  1742. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1743. */
  1744. function hashHas(key) {
  1745. var data = this.__data__;
  1746. return nativeCreate ? data[key] !== undefined : hasOwnProperty.call(data, key);
  1747. }
  1748. /**
  1749. * Sets the hash `key` to `value`.
  1750. *
  1751. * @private
  1752. * @name set
  1753. * @memberOf Hash
  1754. * @param {string} key The key of the value to set.
  1755. * @param {*} value The value to set.
  1756. * @returns {Object} Returns the hash instance.
  1757. */
  1758. function hashSet(key, value) {
  1759. var data = this.__data__;
  1760. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1761. return this;
  1762. }
  1763. // Add methods to `Hash`.
  1764. Hash.prototype.clear = hashClear;
  1765. Hash.prototype['delete'] = hashDelete;
  1766. Hash.prototype.get = hashGet;
  1767. Hash.prototype.has = hashHas;
  1768. Hash.prototype.set = hashSet;
  1769. /*------------------------------------------------------------------------*/
  1770. /**
  1771. * Creates an list cache object.
  1772. *
  1773. * @private
  1774. * @constructor
  1775. * @param {Array} [entries] The key-value pairs to cache.
  1776. */
  1777. function ListCache(entries) {
  1778. var index = -1,
  1779. length = entries ? entries.length : 0;
  1780. this.clear();
  1781. while (++index < length) {
  1782. var entry = entries[index];
  1783. this.set(entry[0], entry[1]);
  1784. }
  1785. }
  1786. /**
  1787. * Removes all key-value entries from the list cache.
  1788. *
  1789. * @private
  1790. * @name clear
  1791. * @memberOf ListCache
  1792. */
  1793. function listCacheClear() {
  1794. this.__data__ = [];
  1795. }
  1796. /**
  1797. * Removes `key` and its value from the list cache.
  1798. *
  1799. * @private
  1800. * @name delete
  1801. * @memberOf ListCache
  1802. * @param {string} key The key of the value to remove.
  1803. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1804. */
  1805. function listCacheDelete(key) {
  1806. var data = this.__data__,
  1807. index = assocIndexOf(data, key);
  1808. if (index < 0) {
  1809. return false;
  1810. }
  1811. var lastIndex = data.length - 1;
  1812. if (index == lastIndex) {
  1813. data.pop();
  1814. } else {
  1815. splice.call(data, index, 1);
  1816. }
  1817. return true;
  1818. }
  1819. /**
  1820. * Gets the list cache value for `key`.
  1821. *
  1822. * @private
  1823. * @name get
  1824. * @memberOf ListCache
  1825. * @param {string} key The key of the value to get.
  1826. * @returns {*} Returns the entry value.
  1827. */
  1828. function listCacheGet(key) {
  1829. var data = this.__data__,
  1830. index = assocIndexOf(data, key);
  1831. return index < 0 ? undefined : data[index][1];
  1832. }
  1833. /**
  1834. * Checks if a list cache value for `key` exists.
  1835. *
  1836. * @private
  1837. * @name has
  1838. * @memberOf ListCache
  1839. * @param {string} key The key of the entry to check.
  1840. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1841. */
  1842. function listCacheHas(key) {
  1843. return assocIndexOf(this.__data__, key) > -1;
  1844. }
  1845. /**
  1846. * Sets the list cache `key` to `value`.
  1847. *
  1848. * @private
  1849. * @name set
  1850. * @memberOf ListCache
  1851. * @param {string} key The key of the value to set.
  1852. * @param {*} value The value to set.
  1853. * @returns {Object} Returns the list cache instance.
  1854. */
  1855. function listCacheSet(key, value) {
  1856. var data = this.__data__,
  1857. index = assocIndexOf(data, key);
  1858. if (index < 0) {
  1859. data.push([key, value]);
  1860. } else {
  1861. data[index][1] = value;
  1862. }
  1863. return this;
  1864. }
  1865. // Add methods to `ListCache`.
  1866. ListCache.prototype.clear = listCacheClear;
  1867. ListCache.prototype['delete'] = listCacheDelete;
  1868. ListCache.prototype.get = listCacheGet;
  1869. ListCache.prototype.has = listCacheHas;
  1870. ListCache.prototype.set = listCacheSet;
  1871. /*------------------------------------------------------------------------*/
  1872. /**
  1873. * Creates a map cache object to store key-value pairs.
  1874. *
  1875. * @private
  1876. * @constructor
  1877. * @param {Array} [entries] The key-value pairs to cache.
  1878. */
  1879. function MapCache(entries) {
  1880. var index = -1,
  1881. length = entries ? entries.length : 0;
  1882. this.clear();
  1883. while (++index < length) {
  1884. var entry = entries[index];
  1885. this.set(entry[0], entry[1]);
  1886. }
  1887. }
  1888. /**
  1889. * Removes all key-value entries from the map.
  1890. *
  1891. * @private
  1892. * @name clear
  1893. * @memberOf MapCache
  1894. */
  1895. function mapCacheClear() {
  1896. this.__data__ = {
  1897. 'hash': new Hash,
  1898. 'map': new (Map || ListCache),
  1899. 'string': new Hash
  1900. };
  1901. }
  1902. /**
  1903. * Removes `key` and its value from the map.
  1904. *
  1905. * @private
  1906. * @name delete
  1907. * @memberOf MapCache
  1908. * @param {string} key The key of the value to remove.
  1909. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1910. */
  1911. function mapCacheDelete(key) {
  1912. return getMapData(this, key)['delete'](key);
  1913. }
  1914. /**
  1915. * Gets the map value for `key`.
  1916. *
  1917. * @private
  1918. * @name get
  1919. * @memberOf MapCache
  1920. * @param {string} key The key of the value to get.
  1921. * @returns {*} Returns the entry value.
  1922. */
  1923. function mapCacheGet(key) {
  1924. return getMapData(this, key).get(key);
  1925. }
  1926. /**
  1927. * Checks if a map value for `key` exists.
  1928. *
  1929. * @private
  1930. * @name has
  1931. * @memberOf MapCache
  1932. * @param {string} key The key of the entry to check.
  1933. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1934. */
  1935. function mapCacheHas(key) {
  1936. return getMapData(this, key).has(key);
  1937. }
  1938. /**
  1939. * Sets the map `key` to `value`.
  1940. *
  1941. * @private
  1942. * @name set
  1943. * @memberOf MapCache
  1944. * @param {string} key The key of the value to set.
  1945. * @param {*} value The value to set.
  1946. * @returns {Object} Returns the map cache instance.
  1947. */
  1948. function mapCacheSet(key, value) {
  1949. getMapData(this, key).set(key, value);
  1950. return this;
  1951. }
  1952. // Add methods to `MapCache`.
  1953. MapCache.prototype.clear = mapCacheClear;
  1954. MapCache.prototype['delete'] = mapCacheDelete;
  1955. MapCache.prototype.get = mapCacheGet;
  1956. MapCache.prototype.has = mapCacheHas;
  1957. MapCache.prototype.set = mapCacheSet;
  1958. /*------------------------------------------------------------------------*/
  1959. /**
  1960. *
  1961. * Creates an array cache object to store unique values.
  1962. *
  1963. * @private
  1964. * @constructor
  1965. * @param {Array} [values] The values to cache.
  1966. */
  1967. function SetCache(values) {
  1968. var index = -1,
  1969. length = values ? values.length : 0;
  1970. this.__data__ = new MapCache;
  1971. while (++index < length) {
  1972. this.add(values[index]);
  1973. }
  1974. }
  1975. /**
  1976. * Adds `value` to the array cache.
  1977. *
  1978. * @private
  1979. * @name add
  1980. * @memberOf SetCache
  1981. * @alias push
  1982. * @param {*} value The value to cache.
  1983. * @returns {Object} Returns the cache instance.
  1984. */
  1985. function setCacheAdd(value) {
  1986. this.__data__.set(value, HASH_UNDEFINED);
  1987. return this;
  1988. }
  1989. /**
  1990. * Checks if `value` is in the array cache.
  1991. *
  1992. * @private
  1993. * @name has
  1994. * @memberOf SetCache
  1995. * @param {*} value The value to search for.
  1996. * @returns {number} Returns `true` if `value` is found, else `false`.
  1997. */
  1998. function setCacheHas(value) {
  1999. return this.__data__.has(value);
  2000. }
  2001. // Add methods to `SetCache`.
  2002. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2003. SetCache.prototype.has = setCacheHas;
  2004. /*------------------------------------------------------------------------*/
  2005. /**
  2006. * Creates a stack cache object to store key-value pairs.
  2007. *
  2008. * @private
  2009. * @constructor
  2010. * @param {Array} [entries] The key-value pairs to cache.
  2011. */
  2012. function Stack(entries) {
  2013. this.__data__ = new ListCache(entries);
  2014. }
  2015. /**
  2016. * Removes all key-value entries from the stack.
  2017. *
  2018. * @private
  2019. * @name clear
  2020. * @memberOf Stack
  2021. */
  2022. function stackClear() {
  2023. this.__data__ = new ListCache;
  2024. }
  2025. /**
  2026. * Removes `key` and its value from the stack.
  2027. *
  2028. * @private
  2029. * @name delete
  2030. * @memberOf Stack
  2031. * @param {string} key The key of the value to remove.
  2032. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2033. */
  2034. function stackDelete(key) {
  2035. return this.__data__['delete'](key);
  2036. }
  2037. /**
  2038. * Gets the stack value for `key`.
  2039. *
  2040. * @private
  2041. * @name get
  2042. * @memberOf Stack
  2043. * @param {string} key The key of the value to get.
  2044. * @returns {*} Returns the entry value.
  2045. */
  2046. function stackGet(key) {
  2047. return this.__data__.get(key);
  2048. }
  2049. /**
  2050. * Checks if a stack value for `key` exists.
  2051. *
  2052. * @private
  2053. * @name has
  2054. * @memberOf Stack
  2055. * @param {string} key The key of the entry to check.
  2056. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2057. */
  2058. function stackHas(key) {
  2059. return this.__data__.has(key);
  2060. }
  2061. /**
  2062. * Sets the stack `key` to `value`.
  2063. *
  2064. * @private
  2065. * @name set
  2066. * @memberOf Stack
  2067. * @param {string} key The key of the value to set.
  2068. * @param {*} value The value to set.
  2069. * @returns {Object} Returns the stack cache instance.
  2070. */
  2071. function stackSet(key, value) {
  2072. var cache = this.__data__;
  2073. if (cache instanceof ListCache) {
  2074. var pairs = cache.__data__;
  2075. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2076. pairs.push([key, value]);
  2077. return this;
  2078. }
  2079. cache = this.__data__ = new MapCache(pairs);
  2080. }
  2081. cache.set(key, value);
  2082. return this;
  2083. }
  2084. // Add methods to `Stack`.
  2085. Stack.prototype.clear = stackClear;
  2086. Stack.prototype['delete'] = stackDelete;
  2087. Stack.prototype.get = stackGet;
  2088. Stack.prototype.has = stackHas;
  2089. Stack.prototype.set = stackSet;
  2090. /*------------------------------------------------------------------------*/
  2091. /**
  2092. * Creates an array of the enumerable property names of the array-like `value`.
  2093. *
  2094. * @private
  2095. * @param {*} value The value to query.
  2096. * @param {boolean} inherited Specify returning inherited property names.
  2097. * @returns {Array} Returns the array of property names.
  2098. */
  2099. function arrayLikeKeys(value, inherited) {
  2100. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  2101. // Safari 9 makes `arguments.length` enumerable in strict mode.
  2102. var result = (isArray(value) || isArguments(value))
  2103. ? baseTimes(value.length, String)
  2104. : [];
  2105. var length = result.length,
  2106. skipIndexes = !!length;
  2107. for (var key in value) {
  2108. if ((inherited || hasOwnProperty.call(value, key)) &&
  2109. !(skipIndexes && (key == 'length' || isIndex(key, length)))) {
  2110. result.push(key);
  2111. }
  2112. }
  2113. return result;
  2114. }
  2115. /**
  2116. * Used by `_.defaults` to customize its `_.assignIn` use.
  2117. *
  2118. * @private
  2119. * @param {*} objValue The destination value.
  2120. * @param {*} srcValue The source value.
  2121. * @param {string} key The key of the property to assign.
  2122. * @param {Object} object The parent object of `objValue`.
  2123. * @returns {*} Returns the value to assign.
  2124. */
  2125. function assignInDefaults(objValue, srcValue, key, object) {
  2126. if (objValue === undefined ||
  2127. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  2128. return srcValue;
  2129. }
  2130. return objValue;
  2131. }
  2132. /**
  2133. * This function is like `assignValue` except that it doesn't assign
  2134. * `undefined` values.
  2135. *
  2136. * @private
  2137. * @param {Object} object The object to modify.
  2138. * @param {string} key The key of the property to assign.
  2139. * @param {*} value The value to assign.
  2140. */
  2141. function assignMergeValue(object, key, value) {
  2142. if ((value !== undefined && !eq(object[key], value)) ||
  2143. (typeof key == 'number' && value === undefined && !(key in object))) {
  2144. object[key] = value;
  2145. }
  2146. }
  2147. /**
  2148. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2149. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2150. * for equality comparisons.
  2151. *
  2152. * @private
  2153. * @param {Object} object The object to modify.
  2154. * @param {string} key The key of the property to assign.
  2155. * @param {*} value The value to assign.
  2156. */
  2157. function assignValue(object, key, value) {
  2158. var objValue = object[key];
  2159. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2160. (value === undefined && !(key in object))) {
  2161. object[key] = value;
  2162. }
  2163. }
  2164. /**
  2165. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2166. *
  2167. * @private
  2168. * @param {Array} array The array to inspect.
  2169. * @param {*} key The key to search for.
  2170. * @returns {number} Returns the index of the matched value, else `-1`.
  2171. */
  2172. function assocIndexOf(array, key) {
  2173. var length = array.length;
  2174. while (length--) {
  2175. if (eq(array[length][0], key)) {
  2176. return length;
  2177. }
  2178. }
  2179. return -1;
  2180. }
  2181. /**
  2182. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2183. * by `iteratee` and values set by `setter`.
  2184. *
  2185. * @private
  2186. * @param {Array|Object} collection The collection to iterate over.
  2187. * @param {Function} setter The function to set `accumulator` values.
  2188. * @param {Function} iteratee The iteratee to transform keys.
  2189. * @param {Object} accumulator The initial aggregated object.
  2190. * @returns {Function} Returns `accumulator`.
  2191. */
  2192. function baseAggregator(collection, setter, iteratee, accumulator) {
  2193. baseEach(collection, function(value, key, collection) {
  2194. setter(accumulator, value, iteratee(value), collection);
  2195. });
  2196. return accumulator;
  2197. }
  2198. /**
  2199. * The base implementation of `_.assign` without support for multiple sources
  2200. * or `customizer` functions.
  2201. *
  2202. * @private
  2203. * @param {Object} object The destination object.
  2204. * @param {Object} source The source object.
  2205. * @returns {Object} Returns `object`.
  2206. */
  2207. function baseAssign(object, source) {
  2208. return object && copyObject(source, keys(source), object);
  2209. }
  2210. /**
  2211. * The base implementation of `_.at` without support for individual paths.
  2212. *
  2213. * @private
  2214. * @param {Object} object The object to iterate over.
  2215. * @param {string[]} paths The property paths of elements to pick.
  2216. * @returns {Array} Returns the picked elements.
  2217. */
  2218. function baseAt(object, paths) {
  2219. var index = -1,
  2220. isNil = object == null,
  2221. length = paths.length,
  2222. result = Array(length);
  2223. while (++index < length) {
  2224. result[index] = isNil ? undefined : get(object, paths[index]);
  2225. }
  2226. return result;
  2227. }
  2228. /**
  2229. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2230. *
  2231. * @private
  2232. * @param {number} number The number to clamp.
  2233. * @param {number} [lower] The lower bound.
  2234. * @param {number} upper The upper bound.
  2235. * @returns {number} Returns the clamped number.
  2236. */
  2237. function baseClamp(number, lower, upper) {
  2238. if (number === number) {
  2239. if (upper !== undefined) {
  2240. number = number <= upper ? number : upper;
  2241. }
  2242. if (lower !== undefined) {
  2243. number = number >= lower ? number : lower;
  2244. }
  2245. }
  2246. return number;
  2247. }
  2248. /**
  2249. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2250. * traversed objects.
  2251. *
  2252. * @private
  2253. * @param {*} value The value to clone.
  2254. * @param {boolean} [isDeep] Specify a deep clone.
  2255. * @param {boolean} [isFull] Specify a clone including symbols.
  2256. * @param {Function} [customizer] The function to customize cloning.
  2257. * @param {string} [key] The key of `value`.
  2258. * @param {Object} [object] The parent object of `value`.
  2259. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2260. * @returns {*} Returns the cloned value.
  2261. */
  2262. function baseClone(value, isDeep, isFull, customizer, key, object, stack) {
  2263. var result;
  2264. if (customizer) {
  2265. result = object ? customizer(value, key, object, stack) : customizer(value);
  2266. }
  2267. if (result !== undefined) {
  2268. return result;
  2269. }
  2270. if (!isObject(value)) {
  2271. return value;
  2272. }
  2273. var isArr = isArray(value);
  2274. if (isArr) {
  2275. result = initCloneArray(value);
  2276. if (!isDeep) {
  2277. return copyArray(value, result);
  2278. }
  2279. } else {
  2280. var tag = getTag(value),
  2281. isFunc = tag == funcTag || tag == genTag;
  2282. if (isBuffer(value)) {
  2283. return cloneBuffer(value, isDeep);
  2284. }
  2285. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2286. if (isHostObject(value)) {
  2287. return object ? value : {};
  2288. }
  2289. result = initCloneObject(isFunc ? {} : value);
  2290. if (!isDeep) {
  2291. return copySymbols(value, baseAssign(result, value));
  2292. }
  2293. } else {
  2294. if (!cloneableTags[tag]) {
  2295. return object ? value : {};
  2296. }
  2297. result = initCloneByTag(value, tag, baseClone, isDeep);
  2298. }
  2299. }
  2300. // Check for circular references and return its corresponding clone.
  2301. stack || (stack = new Stack);
  2302. var stacked = stack.get(value);
  2303. if (stacked) {
  2304. return stacked;
  2305. }
  2306. stack.set(value, result);
  2307. if (!isArr) {
  2308. var props = isFull ? getAllKeys(value) : keys(value);
  2309. }
  2310. arrayEach(props || value, function(subValue, key) {
  2311. if (props) {
  2312. key = subValue;
  2313. subValue = value[key];
  2314. }
  2315. // Recursively populate clone (susceptible to call stack limits).
  2316. assignValue(result, key, baseClone(subValue, isDeep, isFull, customizer, key, value, stack));
  2317. });
  2318. return result;
  2319. }
  2320. /**
  2321. * The base implementation of `_.conforms` which doesn't clone `source`.
  2322. *
  2323. * @private
  2324. * @param {Object} source The object of property predicates to conform to.
  2325. * @returns {Function} Returns the new spec function.
  2326. */
  2327. function baseConforms(source) {
  2328. var props = keys(source);
  2329. return function(object) {
  2330. return baseConformsTo(object, source, props);
  2331. };
  2332. }
  2333. /**
  2334. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2335. *
  2336. * @private
  2337. * @param {Object} object The object to inspect.
  2338. * @param {Object} source The object of property predicates to conform to.
  2339. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2340. */
  2341. function baseConformsTo(object, source, props) {
  2342. var length = props.length;
  2343. if (object == null) {
  2344. return !length;
  2345. }
  2346. object = Object(object);
  2347. while (length--) {
  2348. var key = props[length],
  2349. predicate = source[key],
  2350. value = object[key];
  2351. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2352. return false;
  2353. }
  2354. }
  2355. return true;
  2356. }
  2357. /**
  2358. * The base implementation of `_.create` without support for assigning
  2359. * properties to the created object.
  2360. *
  2361. * @private
  2362. * @param {Object} prototype The object to inherit from.
  2363. * @returns {Object} Returns the new object.
  2364. */
  2365. function baseCreate(proto) {
  2366. return isObject(proto) ? objectCreate(proto) : {};
  2367. }
  2368. /**
  2369. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2370. * to provide to `func`.
  2371. *
  2372. * @private
  2373. * @param {Function} func The function to delay.
  2374. * @param {number} wait The number of milliseconds to delay invocation.
  2375. * @param {Array} args The arguments to provide to `func`.
  2376. * @returns {number|Object} Returns the timer id or timeout object.
  2377. */
  2378. function baseDelay(func, wait, args) {
  2379. if (typeof func != 'function') {
  2380. throw new TypeError(FUNC_ERROR_TEXT);
  2381. }
  2382. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2383. }
  2384. /**
  2385. * The base implementation of methods like `_.difference` without support
  2386. * for excluding multiple arrays or iteratee shorthands.
  2387. *
  2388. * @private
  2389. * @param {Array} array The array to inspect.
  2390. * @param {Array} values The values to exclude.
  2391. * @param {Function} [iteratee] The iteratee invoked per element.
  2392. * @param {Function} [comparator] The comparator invoked per element.
  2393. * @returns {Array} Returns the new array of filtered values.
  2394. */
  2395. function baseDifference(array, values, iteratee, comparator) {
  2396. var index = -1,
  2397. includes = arrayIncludes,
  2398. isCommon = true,
  2399. length = array.length,
  2400. result = [],
  2401. valuesLength = values.length;
  2402. if (!length) {
  2403. return result;
  2404. }
  2405. if (iteratee) {
  2406. values = arrayMap(values, baseUnary(iteratee));
  2407. }
  2408. if (comparator) {
  2409. includes = arrayIncludesWith;
  2410. isCommon = false;
  2411. }
  2412. else if (values.length >= LARGE_ARRAY_SIZE) {
  2413. includes = cacheHas;
  2414. isCommon = false;
  2415. values = new SetCache(values);
  2416. }
  2417. outer:
  2418. while (++index < length) {
  2419. var value = array[index],
  2420. computed = iteratee ? iteratee(value) : value;
  2421. value = (comparator || value !== 0) ? value : 0;
  2422. if (isCommon && computed === computed) {
  2423. var valuesIndex = valuesLength;
  2424. while (valuesIndex--) {
  2425. if (values[valuesIndex] === computed) {
  2426. continue outer;
  2427. }
  2428. }
  2429. result.push(value);
  2430. }
  2431. else if (!includes(values, computed, comparator)) {
  2432. result.push(value);
  2433. }
  2434. }
  2435. return result;
  2436. }
  2437. /**
  2438. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2439. *
  2440. * @private
  2441. * @param {Array|Object} collection The collection to iterate over.
  2442. * @param {Function} iteratee The function invoked per iteration.
  2443. * @returns {Array|Object} Returns `collection`.
  2444. */
  2445. var baseEach = createBaseEach(baseForOwn);
  2446. /**
  2447. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2448. *
  2449. * @private
  2450. * @param {Array|Object} collection The collection to iterate over.
  2451. * @param {Function} iteratee The function invoked per iteration.
  2452. * @returns {Array|Object} Returns `collection`.
  2453. */
  2454. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2455. /**
  2456. * The base implementation of `_.every` without support for iteratee shorthands.
  2457. *
  2458. * @private
  2459. * @param {Array|Object} collection The collection to iterate over.
  2460. * @param {Function} predicate The function invoked per iteration.
  2461. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2462. * else `false`
  2463. */
  2464. function baseEvery(collection, predicate) {
  2465. var result = true;
  2466. baseEach(collection, function(value, index, collection) {
  2467. result = !!predicate(value, index, collection);
  2468. return result;
  2469. });
  2470. return result;
  2471. }
  2472. /**
  2473. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2474. * `comparator` to determine the extremum value.
  2475. *
  2476. * @private
  2477. * @param {Array} array The array to iterate over.
  2478. * @param {Function} iteratee The iteratee invoked per iteration.
  2479. * @param {Function} comparator The comparator used to compare values.
  2480. * @returns {*} Returns the extremum value.
  2481. */
  2482. function baseExtremum(array, iteratee, comparator) {
  2483. var index = -1,
  2484. length = array.length;
  2485. while (++index < length) {
  2486. var value = array[index],
  2487. current = iteratee(value);
  2488. if (current != null && (computed === undefined
  2489. ? (current === current && !isSymbol(current))
  2490. : comparator(current, computed)
  2491. )) {
  2492. var computed = current,
  2493. result = value;
  2494. }
  2495. }
  2496. return result;
  2497. }
  2498. /**
  2499. * The base implementation of `_.fill` without an iteratee call guard.
  2500. *
  2501. * @private
  2502. * @param {Array} array The array to fill.
  2503. * @param {*} value The value to fill `array` with.
  2504. * @param {number} [start=0] The start position.
  2505. * @param {number} [end=array.length] The end position.
  2506. * @returns {Array} Returns `array`.
  2507. */
  2508. function baseFill(array, value, start, end) {
  2509. var length = array.length;
  2510. start = toInteger(start);
  2511. if (start < 0) {
  2512. start = -start > length ? 0 : (length + start);
  2513. }
  2514. end = (end === undefined || end > length) ? length : toInteger(end);
  2515. if (end < 0) {
  2516. end += length;
  2517. }
  2518. end = start > end ? 0 : toLength(end);
  2519. while (start < end) {
  2520. array[start++] = value;
  2521. }
  2522. return array;
  2523. }
  2524. /**
  2525. * The base implementation of `_.filter` without support for iteratee shorthands.
  2526. *
  2527. * @private
  2528. * @param {Array|Object} collection The collection to iterate over.
  2529. * @param {Function} predicate The function invoked per iteration.
  2530. * @returns {Array} Returns the new filtered array.
  2531. */
  2532. function baseFilter(collection, predicate) {
  2533. var result = [];
  2534. baseEach(collection, function(value, index, collection) {
  2535. if (predicate(value, index, collection)) {
  2536. result.push(value);
  2537. }
  2538. });
  2539. return result;
  2540. }
  2541. /**
  2542. * The base implementation of `_.flatten` with support for restricting flattening.
  2543. *
  2544. * @private
  2545. * @param {Array} array The array to flatten.
  2546. * @param {number} depth The maximum recursion depth.
  2547. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2548. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2549. * @param {Array} [result=[]] The initial result value.
  2550. * @returns {Array} Returns the new flattened array.
  2551. */
  2552. function baseFlatten(array, depth, predicate, isStrict, result) {
  2553. var index = -1,
  2554. length = array.length;
  2555. predicate || (predicate = isFlattenable);
  2556. result || (result = []);
  2557. while (++index < length) {
  2558. var value = array[index];
  2559. if (depth > 0 && predicate(value)) {
  2560. if (depth > 1) {
  2561. // Recursively flatten arrays (susceptible to call stack limits).
  2562. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2563. } else {
  2564. arrayPush(result, value);
  2565. }
  2566. } else if (!isStrict) {
  2567. result[result.length] = value;
  2568. }
  2569. }
  2570. return result;
  2571. }
  2572. /**
  2573. * The base implementation of `baseForOwn` which iterates over `object`
  2574. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2575. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2576. *
  2577. * @private
  2578. * @param {Object} object The object to iterate over.
  2579. * @param {Function} iteratee The function invoked per iteration.
  2580. * @param {Function} keysFunc The function to get the keys of `object`.
  2581. * @returns {Object} Returns `object`.
  2582. */
  2583. var baseFor = createBaseFor();
  2584. /**
  2585. * This function is like `baseFor` except that it iterates over properties
  2586. * in the opposite order.
  2587. *
  2588. * @private
  2589. * @param {Object} object The object to iterate over.
  2590. * @param {Function} iteratee The function invoked per iteration.
  2591. * @param {Function} keysFunc The function to get the keys of `object`.
  2592. * @returns {Object} Returns `object`.
  2593. */
  2594. var baseForRight = createBaseFor(true);
  2595. /**
  2596. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2597. *
  2598. * @private
  2599. * @param {Object} object The object to iterate over.
  2600. * @param {Function} iteratee The function invoked per iteration.
  2601. * @returns {Object} Returns `object`.
  2602. */
  2603. function baseForOwn(object, iteratee) {
  2604. return object && baseFor(object, iteratee, keys);
  2605. }
  2606. /**
  2607. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2608. *
  2609. * @private
  2610. * @param {Object} object The object to iterate over.
  2611. * @param {Function} iteratee The function invoked per iteration.
  2612. * @returns {Object} Returns `object`.
  2613. */
  2614. function baseForOwnRight(object, iteratee) {
  2615. return object && baseForRight(object, iteratee, keys);
  2616. }
  2617. /**
  2618. * The base implementation of `_.functions` which creates an array of
  2619. * `object` function property names filtered from `props`.
  2620. *
  2621. * @private
  2622. * @param {Object} object The object to inspect.
  2623. * @param {Array} props The property names to filter.
  2624. * @returns {Array} Returns the function names.
  2625. */
  2626. function baseFunctions(object, props) {
  2627. return arrayFilter(props, function(key) {
  2628. return isFunction(object[key]);
  2629. });
  2630. }
  2631. /**
  2632. * The base implementation of `_.get` without support for default values.
  2633. *
  2634. * @private
  2635. * @param {Object} object The object to query.
  2636. * @param {Array|string} path The path of the property to get.
  2637. * @returns {*} Returns the resolved value.
  2638. */
  2639. function baseGet(object, path) {
  2640. path = isKey(path, object) ? [path] : castPath(path);
  2641. var index = 0,
  2642. length = path.length;
  2643. while (object != null && index < length) {
  2644. object = object[toKey(path[index++])];
  2645. }
  2646. return (index && index == length) ? object : undefined;
  2647. }
  2648. /**
  2649. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2650. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2651. * symbols of `object`.
  2652. *
  2653. * @private
  2654. * @param {Object} object The object to query.
  2655. * @param {Function} keysFunc The function to get the keys of `object`.
  2656. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2657. * @returns {Array} Returns the array of property names and symbols.
  2658. */
  2659. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2660. var result = keysFunc(object);
  2661. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2662. }
  2663. /**
  2664. * The base implementation of `getTag`.
  2665. *
  2666. * @private
  2667. * @param {*} value The value to query.
  2668. * @returns {string} Returns the `toStringTag`.
  2669. */
  2670. function baseGetTag(value) {
  2671. return objectToString.call(value);
  2672. }
  2673. /**
  2674. * The base implementation of `_.gt` which doesn't coerce arguments.
  2675. *
  2676. * @private
  2677. * @param {*} value The value to compare.
  2678. * @param {*} other The other value to compare.
  2679. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2680. * else `false`.
  2681. */
  2682. function baseGt(value, other) {
  2683. return value > other;
  2684. }
  2685. /**
  2686. * The base implementation of `_.has` without support for deep paths.
  2687. *
  2688. * @private
  2689. * @param {Object} [object] The object to query.
  2690. * @param {Array|string} key The key to check.
  2691. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2692. */
  2693. function baseHas(object, key) {
  2694. return object != null && hasOwnProperty.call(object, key);
  2695. }
  2696. /**
  2697. * The base implementation of `_.hasIn` without support for deep paths.
  2698. *
  2699. * @private
  2700. * @param {Object} [object] The object to query.
  2701. * @param {Array|string} key The key to check.
  2702. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2703. */
  2704. function baseHasIn(object, key) {
  2705. return object != null && key in Object(object);
  2706. }
  2707. /**
  2708. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2709. *
  2710. * @private
  2711. * @param {number} number The number to check.
  2712. * @param {number} start The start of the range.
  2713. * @param {number} end The end of the range.
  2714. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2715. */
  2716. function baseInRange(number, start, end) {
  2717. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2718. }
  2719. /**
  2720. * The base implementation of methods like `_.intersection`, without support
  2721. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2722. *
  2723. * @private
  2724. * @param {Array} arrays The arrays to inspect.
  2725. * @param {Function} [iteratee] The iteratee invoked per element.
  2726. * @param {Function} [comparator] The comparator invoked per element.
  2727. * @returns {Array} Returns the new array of shared values.
  2728. */
  2729. function baseIntersection(arrays, iteratee, comparator) {
  2730. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2731. length = arrays[0].length,
  2732. othLength = arrays.length,
  2733. othIndex = othLength,
  2734. caches = Array(othLength),
  2735. maxLength = Infinity,
  2736. result = [];
  2737. while (othIndex--) {
  2738. var array = arrays[othIndex];
  2739. if (othIndex && iteratee) {
  2740. array = arrayMap(array, baseUnary(iteratee));
  2741. }
  2742. maxLength = nativeMin(array.length, maxLength);
  2743. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2744. ? new SetCache(othIndex && array)
  2745. : undefined;
  2746. }
  2747. array = arrays[0];
  2748. var index = -1,
  2749. seen = caches[0];
  2750. outer:
  2751. while (++index < length && result.length < maxLength) {
  2752. var value = array[index],
  2753. computed = iteratee ? iteratee(value) : value;
  2754. value = (comparator || value !== 0) ? value : 0;
  2755. if (!(seen
  2756. ? cacheHas(seen, computed)
  2757. : includes(result, computed, comparator)
  2758. )) {
  2759. othIndex = othLength;
  2760. while (--othIndex) {
  2761. var cache = caches[othIndex];
  2762. if (!(cache
  2763. ? cacheHas(cache, computed)
  2764. : includes(arrays[othIndex], computed, comparator))
  2765. ) {
  2766. continue outer;
  2767. }
  2768. }
  2769. if (seen) {
  2770. seen.push(computed);
  2771. }
  2772. result.push(value);
  2773. }
  2774. }
  2775. return result;
  2776. }
  2777. /**
  2778. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2779. * `object` with values transformed by `iteratee` and set by `setter`.
  2780. *
  2781. * @private
  2782. * @param {Object} object The object to iterate over.
  2783. * @param {Function} setter The function to set `accumulator` values.
  2784. * @param {Function} iteratee The iteratee to transform values.
  2785. * @param {Object} accumulator The initial inverted object.
  2786. * @returns {Function} Returns `accumulator`.
  2787. */
  2788. function baseInverter(object, setter, iteratee, accumulator) {
  2789. baseForOwn(object, function(value, key, object) {
  2790. setter(accumulator, iteratee(value), key, object);
  2791. });
  2792. return accumulator;
  2793. }
  2794. /**
  2795. * The base implementation of `_.invoke` without support for individual
  2796. * method arguments.
  2797. *
  2798. * @private
  2799. * @param {Object} object The object to query.
  2800. * @param {Array|string} path The path of the method to invoke.
  2801. * @param {Array} args The arguments to invoke the method with.
  2802. * @returns {*} Returns the result of the invoked method.
  2803. */
  2804. function baseInvoke(object, path, args) {
  2805. if (!isKey(path, object)) {
  2806. path = castPath(path);
  2807. object = parent(object, path);
  2808. path = last(path);
  2809. }
  2810. var func = object == null ? object : object[toKey(path)];
  2811. return func == null ? undefined : apply(func, object, args);
  2812. }
  2813. /**
  2814. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2815. *
  2816. * @private
  2817. * @param {*} value The value to check.
  2818. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2819. */
  2820. function baseIsArrayBuffer(value) {
  2821. return isObjectLike(value) && objectToString.call(value) == arrayBufferTag;
  2822. }
  2823. /**
  2824. * The base implementation of `_.isDate` without Node.js optimizations.
  2825. *
  2826. * @private
  2827. * @param {*} value The value to check.
  2828. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2829. */
  2830. function baseIsDate(value) {
  2831. return isObjectLike(value) && objectToString.call(value) == dateTag;
  2832. }
  2833. /**
  2834. * The base implementation of `_.isEqual` which supports partial comparisons
  2835. * and tracks traversed objects.
  2836. *
  2837. * @private
  2838. * @param {*} value The value to compare.
  2839. * @param {*} other The other value to compare.
  2840. * @param {Function} [customizer] The function to customize comparisons.
  2841. * @param {boolean} [bitmask] The bitmask of comparison flags.
  2842. * The bitmask may be composed of the following flags:
  2843. * 1 - Unordered comparison
  2844. * 2 - Partial comparison
  2845. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  2846. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2847. */
  2848. function baseIsEqual(value, other, customizer, bitmask, stack) {
  2849. if (value === other) {
  2850. return true;
  2851. }
  2852. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  2853. return value !== value && other !== other;
  2854. }
  2855. return baseIsEqualDeep(value, other, baseIsEqual, customizer, bitmask, stack);
  2856. }
  2857. /**
  2858. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2859. * deep comparisons and tracks traversed objects enabling objects with circular
  2860. * references to be compared.
  2861. *
  2862. * @private
  2863. * @param {Object} object The object to compare.
  2864. * @param {Object} other The other object to compare.
  2865. * @param {Function} equalFunc The function to determine equivalents of values.
  2866. * @param {Function} [customizer] The function to customize comparisons.
  2867. * @param {number} [bitmask] The bitmask of comparison flags. See `baseIsEqual`
  2868. * for more details.
  2869. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  2870. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2871. */
  2872. function baseIsEqualDeep(object, other, equalFunc, customizer, bitmask, stack) {
  2873. var objIsArr = isArray(object),
  2874. othIsArr = isArray(other),
  2875. objTag = arrayTag,
  2876. othTag = arrayTag;
  2877. if (!objIsArr) {
  2878. objTag = getTag(object);
  2879. objTag = objTag == argsTag ? objectTag : objTag;
  2880. }
  2881. if (!othIsArr) {
  2882. othTag = getTag(other);
  2883. othTag = othTag == argsTag ? objectTag : othTag;
  2884. }
  2885. var objIsObj = objTag == objectTag && !isHostObject(object),
  2886. othIsObj = othTag == objectTag && !isHostObject(other),
  2887. isSameTag = objTag == othTag;
  2888. if (isSameTag && !objIsObj) {
  2889. stack || (stack = new Stack);
  2890. return (objIsArr || isTypedArray(object))
  2891. ? equalArrays(object, other, equalFunc, customizer, bitmask, stack)
  2892. : equalByTag(object, other, objTag, equalFunc, customizer, bitmask, stack);
  2893. }
  2894. if (!(bitmask & PARTIAL_COMPARE_FLAG)) {
  2895. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  2896. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  2897. if (objIsWrapped || othIsWrapped) {
  2898. var objUnwrapped = objIsWrapped ? object.value() : object,
  2899. othUnwrapped = othIsWrapped ? other.value() : other;
  2900. stack || (stack = new Stack);
  2901. return equalFunc(objUnwrapped, othUnwrapped, customizer, bitmask, stack);
  2902. }
  2903. }
  2904. if (!isSameTag) {
  2905. return false;
  2906. }
  2907. stack || (stack = new Stack);
  2908. return equalObjects(object, other, equalFunc, customizer, bitmask, stack);
  2909. }
  2910. /**
  2911. * The base implementation of `_.isMap` without Node.js optimizations.
  2912. *
  2913. * @private
  2914. * @param {*} value The value to check.
  2915. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  2916. */
  2917. function baseIsMap(value) {
  2918. return isObjectLike(value) && getTag(value) == mapTag;
  2919. }
  2920. /**
  2921. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  2922. *
  2923. * @private
  2924. * @param {Object} object The object to inspect.
  2925. * @param {Object} source The object of property values to match.
  2926. * @param {Array} matchData The property names, values, and compare flags to match.
  2927. * @param {Function} [customizer] The function to customize comparisons.
  2928. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  2929. */
  2930. function baseIsMatch(object, source, matchData, customizer) {
  2931. var index = matchData.length,
  2932. length = index,
  2933. noCustomizer = !customizer;
  2934. if (object == null) {
  2935. return !length;
  2936. }
  2937. object = Object(object);
  2938. while (index--) {
  2939. var data = matchData[index];
  2940. if ((noCustomizer && data[2])
  2941. ? data[1] !== object[data[0]]
  2942. : !(data[0] in object)
  2943. ) {
  2944. return false;
  2945. }
  2946. }
  2947. while (++index < length) {
  2948. data = matchData[index];
  2949. var key = data[0],
  2950. objValue = object[key],
  2951. srcValue = data[1];
  2952. if (noCustomizer && data[2]) {
  2953. if (objValue === undefined && !(key in object)) {
  2954. return false;
  2955. }
  2956. } else {
  2957. var stack = new Stack;
  2958. if (customizer) {
  2959. var result = customizer(objValue, srcValue, key, object, source, stack);
  2960. }
  2961. if (!(result === undefined
  2962. ? baseIsEqual(srcValue, objValue, customizer, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG, stack)
  2963. : result
  2964. )) {
  2965. return false;
  2966. }
  2967. }
  2968. }
  2969. return true;
  2970. }
  2971. /**
  2972. * The base implementation of `_.isNative` without bad shim checks.
  2973. *
  2974. * @private
  2975. * @param {*} value The value to check.
  2976. * @returns {boolean} Returns `true` if `value` is a native function,
  2977. * else `false`.
  2978. */
  2979. function baseIsNative(value) {
  2980. if (!isObject(value) || isMasked(value)) {
  2981. return false;
  2982. }
  2983. var pattern = (isFunction(value) || isHostObject(value)) ? reIsNative : reIsHostCtor;
  2984. return pattern.test(toSource(value));
  2985. }
  2986. /**
  2987. * The base implementation of `_.isRegExp` without Node.js optimizations.
  2988. *
  2989. * @private
  2990. * @param {*} value The value to check.
  2991. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  2992. */
  2993. function baseIsRegExp(value) {
  2994. return isObject(value) && objectToString.call(value) == regexpTag;
  2995. }
  2996. /**
  2997. * The base implementation of `_.isSet` without Node.js optimizations.
  2998. *
  2999. * @private
  3000. * @param {*} value The value to check.
  3001. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3002. */
  3003. function baseIsSet(value) {
  3004. return isObjectLike(value) && getTag(value) == setTag;
  3005. }
  3006. /**
  3007. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3008. *
  3009. * @private
  3010. * @param {*} value The value to check.
  3011. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3012. */
  3013. function baseIsTypedArray(value) {
  3014. return isObjectLike(value) &&
  3015. isLength(value.length) && !!typedArrayTags[objectToString.call(value)];
  3016. }
  3017. /**
  3018. * The base implementation of `_.iteratee`.
  3019. *
  3020. * @private
  3021. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3022. * @returns {Function} Returns the iteratee.
  3023. */
  3024. function baseIteratee(value) {
  3025. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3026. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3027. if (typeof value == 'function') {
  3028. return value;
  3029. }
  3030. if (value == null) {
  3031. return identity;
  3032. }
  3033. if (typeof value == 'object') {
  3034. return isArray(value)
  3035. ? baseMatchesProperty(value[0], value[1])
  3036. : baseMatches(value);
  3037. }
  3038. return property(value);
  3039. }
  3040. /**
  3041. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3042. *
  3043. * @private
  3044. * @param {Object} object The object to query.
  3045. * @returns {Array} Returns the array of property names.
  3046. */
  3047. function baseKeys(object) {
  3048. if (!isPrototype(object)) {
  3049. return nativeKeys(object);
  3050. }
  3051. var result = [];
  3052. for (var key in Object(object)) {
  3053. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3054. result.push(key);
  3055. }
  3056. }
  3057. return result;
  3058. }
  3059. /**
  3060. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3061. *
  3062. * @private
  3063. * @param {Object} object The object to query.
  3064. * @returns {Array} Returns the array of property names.
  3065. */
  3066. function baseKeysIn(object) {
  3067. if (!isObject(object)) {
  3068. return nativeKeysIn(object);
  3069. }
  3070. var isProto = isPrototype(object),
  3071. result = [];
  3072. for (var key in object) {
  3073. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3074. result.push(key);
  3075. }
  3076. }
  3077. return result;
  3078. }
  3079. /**
  3080. * The base implementation of `_.lt` which doesn't coerce arguments.
  3081. *
  3082. * @private
  3083. * @param {*} value The value to compare.
  3084. * @param {*} other The other value to compare.
  3085. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3086. * else `false`.
  3087. */
  3088. function baseLt(value, other) {
  3089. return value < other;
  3090. }
  3091. /**
  3092. * The base implementation of `_.map` without support for iteratee shorthands.
  3093. *
  3094. * @private
  3095. * @param {Array|Object} collection The collection to iterate over.
  3096. * @param {Function} iteratee The function invoked per iteration.
  3097. * @returns {Array} Returns the new mapped array.
  3098. */
  3099. function baseMap(collection, iteratee) {
  3100. var index = -1,
  3101. result = isArrayLike(collection) ? Array(collection.length) : [];
  3102. baseEach(collection, function(value, key, collection) {
  3103. result[++index] = iteratee(value, key, collection);
  3104. });
  3105. return result;
  3106. }
  3107. /**
  3108. * The base implementation of `_.matches` which doesn't clone `source`.
  3109. *
  3110. * @private
  3111. * @param {Object} source The object of property values to match.
  3112. * @returns {Function} Returns the new spec function.
  3113. */
  3114. function baseMatches(source) {
  3115. var matchData = getMatchData(source);
  3116. if (matchData.length == 1 && matchData[0][2]) {
  3117. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3118. }
  3119. return function(object) {
  3120. return object === source || baseIsMatch(object, source, matchData);
  3121. };
  3122. }
  3123. /**
  3124. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3125. *
  3126. * @private
  3127. * @param {string} path The path of the property to get.
  3128. * @param {*} srcValue The value to match.
  3129. * @returns {Function} Returns the new spec function.
  3130. */
  3131. function baseMatchesProperty(path, srcValue) {
  3132. if (isKey(path) && isStrictComparable(srcValue)) {
  3133. return matchesStrictComparable(toKey(path), srcValue);
  3134. }
  3135. return function(object) {
  3136. var objValue = get(object, path);
  3137. return (objValue === undefined && objValue === srcValue)
  3138. ? hasIn(object, path)
  3139. : baseIsEqual(srcValue, objValue, undefined, UNORDERED_COMPARE_FLAG | PARTIAL_COMPARE_FLAG);
  3140. };
  3141. }
  3142. /**
  3143. * The base implementation of `_.merge` without support for multiple sources.
  3144. *
  3145. * @private
  3146. * @param {Object} object The destination object.
  3147. * @param {Object} source The source object.
  3148. * @param {number} srcIndex The index of `source`.
  3149. * @param {Function} [customizer] The function to customize merged values.
  3150. * @param {Object} [stack] Tracks traversed source values and their merged
  3151. * counterparts.
  3152. */
  3153. function baseMerge(object, source, srcIndex, customizer, stack) {
  3154. if (object === source) {
  3155. return;
  3156. }
  3157. if (!(isArray(source) || isTypedArray(source))) {
  3158. var props = baseKeysIn(source);
  3159. }
  3160. arrayEach(props || source, function(srcValue, key) {
  3161. if (props) {
  3162. key = srcValue;
  3163. srcValue = source[key];
  3164. }
  3165. if (isObject(srcValue)) {
  3166. stack || (stack = new Stack);
  3167. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3168. }
  3169. else {
  3170. var newValue = customizer
  3171. ? customizer(object[key], srcValue, (key + ''), object, source, stack)
  3172. : undefined;
  3173. if (newValue === undefined) {
  3174. newValue = srcValue;
  3175. }
  3176. assignMergeValue(object, key, newValue);
  3177. }
  3178. });
  3179. }
  3180. /**
  3181. * A specialized version of `baseMerge` for arrays and objects which performs
  3182. * deep merges and tracks traversed objects enabling objects with circular
  3183. * references to be merged.
  3184. *
  3185. * @private
  3186. * @param {Object} object The destination object.
  3187. * @param {Object} source The source object.
  3188. * @param {string} key The key of the value to merge.
  3189. * @param {number} srcIndex The index of `source`.
  3190. * @param {Function} mergeFunc The function to merge values.
  3191. * @param {Function} [customizer] The function to customize assigned values.
  3192. * @param {Object} [stack] Tracks traversed source values and their merged
  3193. * counterparts.
  3194. */
  3195. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3196. var objValue = object[key],
  3197. srcValue = source[key],
  3198. stacked = stack.get(srcValue);
  3199. if (stacked) {
  3200. assignMergeValue(object, key, stacked);
  3201. return;
  3202. }
  3203. var newValue = customizer
  3204. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3205. : undefined;
  3206. var isCommon = newValue === undefined;
  3207. if (isCommon) {
  3208. newValue = srcValue;
  3209. if (isArray(srcValue) || isTypedArray(srcValue)) {
  3210. if (isArray(objValue)) {
  3211. newValue = objValue;
  3212. }
  3213. else if (isArrayLikeObject(objValue)) {
  3214. newValue = copyArray(objValue);
  3215. }
  3216. else {
  3217. isCommon = false;
  3218. newValue = baseClone(srcValue, true);
  3219. }
  3220. }
  3221. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3222. if (isArguments(objValue)) {
  3223. newValue = toPlainObject(objValue);
  3224. }
  3225. else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
  3226. isCommon = false;
  3227. newValue = baseClone(srcValue, true);
  3228. }
  3229. else {
  3230. newValue = objValue;
  3231. }
  3232. }
  3233. else {
  3234. isCommon = false;
  3235. }
  3236. }
  3237. if (isCommon) {
  3238. // Recursively merge objects and arrays (susceptible to call stack limits).
  3239. stack.set(srcValue, newValue);
  3240. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3241. stack['delete'](srcValue);
  3242. }
  3243. assignMergeValue(object, key, newValue);
  3244. }
  3245. /**
  3246. * The base implementation of `_.nth` which doesn't coerce arguments.
  3247. *
  3248. * @private
  3249. * @param {Array} array The array to query.
  3250. * @param {number} n The index of the element to return.
  3251. * @returns {*} Returns the nth element of `array`.
  3252. */
  3253. function baseNth(array, n) {
  3254. var length = array.length;
  3255. if (!length) {
  3256. return;
  3257. }
  3258. n += n < 0 ? length : 0;
  3259. return isIndex(n, length) ? array[n] : undefined;
  3260. }
  3261. /**
  3262. * The base implementation of `_.orderBy` without param guards.
  3263. *
  3264. * @private
  3265. * @param {Array|Object} collection The collection to iterate over.
  3266. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3267. * @param {string[]} orders The sort orders of `iteratees`.
  3268. * @returns {Array} Returns the new sorted array.
  3269. */
  3270. function baseOrderBy(collection, iteratees, orders) {
  3271. var index = -1;
  3272. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  3273. var result = baseMap(collection, function(value, key, collection) {
  3274. var criteria = arrayMap(iteratees, function(iteratee) {
  3275. return iteratee(value);
  3276. });
  3277. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3278. });
  3279. return baseSortBy(result, function(object, other) {
  3280. return compareMultiple(object, other, orders);
  3281. });
  3282. }
  3283. /**
  3284. * The base implementation of `_.pick` without support for individual
  3285. * property identifiers.
  3286. *
  3287. * @private
  3288. * @param {Object} object The source object.
  3289. * @param {string[]} props The property identifiers to pick.
  3290. * @returns {Object} Returns the new object.
  3291. */
  3292. function basePick(object, props) {
  3293. object = Object(object);
  3294. return basePickBy(object, props, function(value, key) {
  3295. return key in object;
  3296. });
  3297. }
  3298. /**
  3299. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3300. *
  3301. * @private
  3302. * @param {Object} object The source object.
  3303. * @param {string[]} props The property identifiers to pick from.
  3304. * @param {Function} predicate The function invoked per property.
  3305. * @returns {Object} Returns the new object.
  3306. */
  3307. function basePickBy(object, props, predicate) {
  3308. var index = -1,
  3309. length = props.length,
  3310. result = {};
  3311. while (++index < length) {
  3312. var key = props[index],
  3313. value = object[key];
  3314. if (predicate(value, key)) {
  3315. result[key] = value;
  3316. }
  3317. }
  3318. return result;
  3319. }
  3320. /**
  3321. * A specialized version of `baseProperty` which supports deep paths.
  3322. *
  3323. * @private
  3324. * @param {Array|string} path The path of the property to get.
  3325. * @returns {Function} Returns the new accessor function.
  3326. */
  3327. function basePropertyDeep(path) {
  3328. return function(object) {
  3329. return baseGet(object, path);
  3330. };
  3331. }
  3332. /**
  3333. * The base implementation of `_.pullAllBy` without support for iteratee
  3334. * shorthands.
  3335. *
  3336. * @private
  3337. * @param {Array} array The array to modify.
  3338. * @param {Array} values The values to remove.
  3339. * @param {Function} [iteratee] The iteratee invoked per element.
  3340. * @param {Function} [comparator] The comparator invoked per element.
  3341. * @returns {Array} Returns `array`.
  3342. */
  3343. function basePullAll(array, values, iteratee, comparator) {
  3344. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3345. index = -1,
  3346. length = values.length,
  3347. seen = array;
  3348. if (array === values) {
  3349. values = copyArray(values);
  3350. }
  3351. if (iteratee) {
  3352. seen = arrayMap(array, baseUnary(iteratee));
  3353. }
  3354. while (++index < length) {
  3355. var fromIndex = 0,
  3356. value = values[index],
  3357. computed = iteratee ? iteratee(value) : value;
  3358. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3359. if (seen !== array) {
  3360. splice.call(seen, fromIndex, 1);
  3361. }
  3362. splice.call(array, fromIndex, 1);
  3363. }
  3364. }
  3365. return array;
  3366. }
  3367. /**
  3368. * The base implementation of `_.pullAt` without support for individual
  3369. * indexes or capturing the removed elements.
  3370. *
  3371. * @private
  3372. * @param {Array} array The array to modify.
  3373. * @param {number[]} indexes The indexes of elements to remove.
  3374. * @returns {Array} Returns `array`.
  3375. */
  3376. function basePullAt(array, indexes) {
  3377. var length = array ? indexes.length : 0,
  3378. lastIndex = length - 1;
  3379. while (length--) {
  3380. var index = indexes[length];
  3381. if (length == lastIndex || index !== previous) {
  3382. var previous = index;
  3383. if (isIndex(index)) {
  3384. splice.call(array, index, 1);
  3385. }
  3386. else if (!isKey(index, array)) {
  3387. var path = castPath(index),
  3388. object = parent(array, path);
  3389. if (object != null) {
  3390. delete object[toKey(last(path))];
  3391. }
  3392. }
  3393. else {
  3394. delete array[toKey(index)];
  3395. }
  3396. }
  3397. }
  3398. return array;
  3399. }
  3400. /**
  3401. * The base implementation of `_.random` without support for returning
  3402. * floating-point numbers.
  3403. *
  3404. * @private
  3405. * @param {number} lower The lower bound.
  3406. * @param {number} upper The upper bound.
  3407. * @returns {number} Returns the random number.
  3408. */
  3409. function baseRandom(lower, upper) {
  3410. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3411. }
  3412. /**
  3413. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3414. * coerce arguments.
  3415. *
  3416. * @private
  3417. * @param {number} start The start of the range.
  3418. * @param {number} end The end of the range.
  3419. * @param {number} step The value to increment or decrement by.
  3420. * @param {boolean} [fromRight] Specify iterating from right to left.
  3421. * @returns {Array} Returns the range of numbers.
  3422. */
  3423. function baseRange(start, end, step, fromRight) {
  3424. var index = -1,
  3425. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3426. result = Array(length);
  3427. while (length--) {
  3428. result[fromRight ? length : ++index] = start;
  3429. start += step;
  3430. }
  3431. return result;
  3432. }
  3433. /**
  3434. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3435. *
  3436. * @private
  3437. * @param {string} string The string to repeat.
  3438. * @param {number} n The number of times to repeat the string.
  3439. * @returns {string} Returns the repeated string.
  3440. */
  3441. function baseRepeat(string, n) {
  3442. var result = '';
  3443. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3444. return result;
  3445. }
  3446. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3447. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3448. do {
  3449. if (n % 2) {
  3450. result += string;
  3451. }
  3452. n = nativeFloor(n / 2);
  3453. if (n) {
  3454. string += string;
  3455. }
  3456. } while (n);
  3457. return result;
  3458. }
  3459. /**
  3460. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3461. *
  3462. * @private
  3463. * @param {Function} func The function to apply a rest parameter to.
  3464. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3465. * @returns {Function} Returns the new function.
  3466. */
  3467. function baseRest(func, start) {
  3468. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  3469. return function() {
  3470. var args = arguments,
  3471. index = -1,
  3472. length = nativeMax(args.length - start, 0),
  3473. array = Array(length);
  3474. while (++index < length) {
  3475. array[index] = args[start + index];
  3476. }
  3477. index = -1;
  3478. var otherArgs = Array(start + 1);
  3479. while (++index < start) {
  3480. otherArgs[index] = args[index];
  3481. }
  3482. otherArgs[start] = array;
  3483. return apply(func, this, otherArgs);
  3484. };
  3485. }
  3486. /**
  3487. * The base implementation of `_.set`.
  3488. *
  3489. * @private
  3490. * @param {Object} object The object to modify.
  3491. * @param {Array|string} path The path of the property to set.
  3492. * @param {*} value The value to set.
  3493. * @param {Function} [customizer] The function to customize path creation.
  3494. * @returns {Object} Returns `object`.
  3495. */
  3496. function baseSet(object, path, value, customizer) {
  3497. if (!isObject(object)) {
  3498. return object;
  3499. }
  3500. path = isKey(path, object) ? [path] : castPath(path);
  3501. var index = -1,
  3502. length = path.length,
  3503. lastIndex = length - 1,
  3504. nested = object;
  3505. while (nested != null && ++index < length) {
  3506. var key = toKey(path[index]),
  3507. newValue = value;
  3508. if (index != lastIndex) {
  3509. var objValue = nested[key];
  3510. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3511. if (newValue === undefined) {
  3512. newValue = isObject(objValue)
  3513. ? objValue
  3514. : (isIndex(path[index + 1]) ? [] : {});
  3515. }
  3516. }
  3517. assignValue(nested, key, newValue);
  3518. nested = nested[key];
  3519. }
  3520. return object;
  3521. }
  3522. /**
  3523. * The base implementation of `setData` without support for hot loop detection.
  3524. *
  3525. * @private
  3526. * @param {Function} func The function to associate metadata with.
  3527. * @param {*} data The metadata.
  3528. * @returns {Function} Returns `func`.
  3529. */
  3530. var baseSetData = !metaMap ? identity : function(func, data) {
  3531. metaMap.set(func, data);
  3532. return func;
  3533. };
  3534. /**
  3535. * The base implementation of `_.slice` without an iteratee call guard.
  3536. *
  3537. * @private
  3538. * @param {Array} array The array to slice.
  3539. * @param {number} [start=0] The start position.
  3540. * @param {number} [end=array.length] The end position.
  3541. * @returns {Array} Returns the slice of `array`.
  3542. */
  3543. function baseSlice(array, start, end) {
  3544. var index = -1,
  3545. length = array.length;
  3546. if (start < 0) {
  3547. start = -start > length ? 0 : (length + start);
  3548. }
  3549. end = end > length ? length : end;
  3550. if (end < 0) {
  3551. end += length;
  3552. }
  3553. length = start > end ? 0 : ((end - start) >>> 0);
  3554. start >>>= 0;
  3555. var result = Array(length);
  3556. while (++index < length) {
  3557. result[index] = array[index + start];
  3558. }
  3559. return result;
  3560. }
  3561. /**
  3562. * The base implementation of `_.some` without support for iteratee shorthands.
  3563. *
  3564. * @private
  3565. * @param {Array|Object} collection The collection to iterate over.
  3566. * @param {Function} predicate The function invoked per iteration.
  3567. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3568. * else `false`.
  3569. */
  3570. function baseSome(collection, predicate) {
  3571. var result;
  3572. baseEach(collection, function(value, index, collection) {
  3573. result = predicate(value, index, collection);
  3574. return !result;
  3575. });
  3576. return !!result;
  3577. }
  3578. /**
  3579. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3580. * performs a binary search of `array` to determine the index at which `value`
  3581. * should be inserted into `array` in order to maintain its sort order.
  3582. *
  3583. * @private
  3584. * @param {Array} array The sorted array to inspect.
  3585. * @param {*} value The value to evaluate.
  3586. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3587. * @returns {number} Returns the index at which `value` should be inserted
  3588. * into `array`.
  3589. */
  3590. function baseSortedIndex(array, value, retHighest) {
  3591. var low = 0,
  3592. high = array ? array.length : low;
  3593. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3594. while (low < high) {
  3595. var mid = (low + high) >>> 1,
  3596. computed = array[mid];
  3597. if (computed !== null && !isSymbol(computed) &&
  3598. (retHighest ? (computed <= value) : (computed < value))) {
  3599. low = mid + 1;
  3600. } else {
  3601. high = mid;
  3602. }
  3603. }
  3604. return high;
  3605. }
  3606. return baseSortedIndexBy(array, value, identity, retHighest);
  3607. }
  3608. /**
  3609. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3610. * which invokes `iteratee` for `value` and each element of `array` to compute
  3611. * their sort ranking. The iteratee is invoked with one argument; (value).
  3612. *
  3613. * @private
  3614. * @param {Array} array The sorted array to inspect.
  3615. * @param {*} value The value to evaluate.
  3616. * @param {Function} iteratee The iteratee invoked per element.
  3617. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3618. * @returns {number} Returns the index at which `value` should be inserted
  3619. * into `array`.
  3620. */
  3621. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3622. value = iteratee(value);
  3623. var low = 0,
  3624. high = array ? array.length : 0,
  3625. valIsNaN = value !== value,
  3626. valIsNull = value === null,
  3627. valIsSymbol = isSymbol(value),
  3628. valIsUndefined = value === undefined;
  3629. while (low < high) {
  3630. var mid = nativeFloor((low + high) / 2),
  3631. computed = iteratee(array[mid]),
  3632. othIsDefined = computed !== undefined,
  3633. othIsNull = computed === null,
  3634. othIsReflexive = computed === computed,
  3635. othIsSymbol = isSymbol(computed);
  3636. if (valIsNaN) {
  3637. var setLow = retHighest || othIsReflexive;
  3638. } else if (valIsUndefined) {
  3639. setLow = othIsReflexive && (retHighest || othIsDefined);
  3640. } else if (valIsNull) {
  3641. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3642. } else if (valIsSymbol) {
  3643. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3644. } else if (othIsNull || othIsSymbol) {
  3645. setLow = false;
  3646. } else {
  3647. setLow = retHighest ? (computed <= value) : (computed < value);
  3648. }
  3649. if (setLow) {
  3650. low = mid + 1;
  3651. } else {
  3652. high = mid;
  3653. }
  3654. }
  3655. return nativeMin(high, MAX_ARRAY_INDEX);
  3656. }
  3657. /**
  3658. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3659. * support for iteratee shorthands.
  3660. *
  3661. * @private
  3662. * @param {Array} array The array to inspect.
  3663. * @param {Function} [iteratee] The iteratee invoked per element.
  3664. * @returns {Array} Returns the new duplicate free array.
  3665. */
  3666. function baseSortedUniq(array, iteratee) {
  3667. var index = -1,
  3668. length = array.length,
  3669. resIndex = 0,
  3670. result = [];
  3671. while (++index < length) {
  3672. var value = array[index],
  3673. computed = iteratee ? iteratee(value) : value;
  3674. if (!index || !eq(computed, seen)) {
  3675. var seen = computed;
  3676. result[resIndex++] = value === 0 ? 0 : value;
  3677. }
  3678. }
  3679. return result;
  3680. }
  3681. /**
  3682. * The base implementation of `_.toNumber` which doesn't ensure correct
  3683. * conversions of binary, hexadecimal, or octal string values.
  3684. *
  3685. * @private
  3686. * @param {*} value The value to process.
  3687. * @returns {number} Returns the number.
  3688. */
  3689. function baseToNumber(value) {
  3690. if (typeof value == 'number') {
  3691. return value;
  3692. }
  3693. if (isSymbol(value)) {
  3694. return NAN;
  3695. }
  3696. return +value;
  3697. }
  3698. /**
  3699. * The base implementation of `_.toString` which doesn't convert nullish
  3700. * values to empty strings.
  3701. *
  3702. * @private
  3703. * @param {*} value The value to process.
  3704. * @returns {string} Returns the string.
  3705. */
  3706. function baseToString(value) {
  3707. // Exit early for strings to avoid a performance hit in some environments.
  3708. if (typeof value == 'string') {
  3709. return value;
  3710. }
  3711. if (isSymbol(value)) {
  3712. return symbolToString ? symbolToString.call(value) : '';
  3713. }
  3714. var result = (value + '');
  3715. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3716. }
  3717. /**
  3718. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3719. *
  3720. * @private
  3721. * @param {Array} array The array to inspect.
  3722. * @param {Function} [iteratee] The iteratee invoked per element.
  3723. * @param {Function} [comparator] The comparator invoked per element.
  3724. * @returns {Array} Returns the new duplicate free array.
  3725. */
  3726. function baseUniq(array, iteratee, comparator) {
  3727. var index = -1,
  3728. includes = arrayIncludes,
  3729. length = array.length,
  3730. isCommon = true,
  3731. result = [],
  3732. seen = result;
  3733. if (comparator) {
  3734. isCommon = false;
  3735. includes = arrayIncludesWith;
  3736. }
  3737. else if (length >= LARGE_ARRAY_SIZE) {
  3738. var set = iteratee ? null : createSet(array);
  3739. if (set) {
  3740. return setToArray(set);
  3741. }
  3742. isCommon = false;
  3743. includes = cacheHas;
  3744. seen = new SetCache;
  3745. }
  3746. else {
  3747. seen = iteratee ? [] : result;
  3748. }
  3749. outer:
  3750. while (++index < length) {
  3751. var value = array[index],
  3752. computed = iteratee ? iteratee(value) : value;
  3753. value = (comparator || value !== 0) ? value : 0;
  3754. if (isCommon && computed === computed) {
  3755. var seenIndex = seen.length;
  3756. while (seenIndex--) {
  3757. if (seen[seenIndex] === computed) {
  3758. continue outer;
  3759. }
  3760. }
  3761. if (iteratee) {
  3762. seen.push(computed);
  3763. }
  3764. result.push(value);
  3765. }
  3766. else if (!includes(seen, computed, comparator)) {
  3767. if (seen !== result) {
  3768. seen.push(computed);
  3769. }
  3770. result.push(value);
  3771. }
  3772. }
  3773. return result;
  3774. }
  3775. /**
  3776. * The base implementation of `_.unset`.
  3777. *
  3778. * @private
  3779. * @param {Object} object The object to modify.
  3780. * @param {Array|string} path The path of the property to unset.
  3781. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3782. */
  3783. function baseUnset(object, path) {
  3784. path = isKey(path, object) ? [path] : castPath(path);
  3785. object = parent(object, path);
  3786. var key = toKey(last(path));
  3787. return !(object != null && hasOwnProperty.call(object, key)) || delete object[key];
  3788. }
  3789. /**
  3790. * The base implementation of `_.update`.
  3791. *
  3792. * @private
  3793. * @param {Object} object The object to modify.
  3794. * @param {Array|string} path The path of the property to update.
  3795. * @param {Function} updater The function to produce the updated value.
  3796. * @param {Function} [customizer] The function to customize path creation.
  3797. * @returns {Object} Returns `object`.
  3798. */
  3799. function baseUpdate(object, path, updater, customizer) {
  3800. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  3801. }
  3802. /**
  3803. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  3804. * without support for iteratee shorthands.
  3805. *
  3806. * @private
  3807. * @param {Array} array The array to query.
  3808. * @param {Function} predicate The function invoked per iteration.
  3809. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  3810. * @param {boolean} [fromRight] Specify iterating from right to left.
  3811. * @returns {Array} Returns the slice of `array`.
  3812. */
  3813. function baseWhile(array, predicate, isDrop, fromRight) {
  3814. var length = array.length,
  3815. index = fromRight ? length : -1;
  3816. while ((fromRight ? index-- : ++index < length) &&
  3817. predicate(array[index], index, array)) {}
  3818. return isDrop
  3819. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  3820. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  3821. }
  3822. /**
  3823. * The base implementation of `wrapperValue` which returns the result of
  3824. * performing a sequence of actions on the unwrapped `value`, where each
  3825. * successive action is supplied the return value of the previous.
  3826. *
  3827. * @private
  3828. * @param {*} value The unwrapped value.
  3829. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  3830. * @returns {*} Returns the resolved value.
  3831. */
  3832. function baseWrapperValue(value, actions) {
  3833. var result = value;
  3834. if (result instanceof LazyWrapper) {
  3835. result = result.value();
  3836. }
  3837. return arrayReduce(actions, function(result, action) {
  3838. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  3839. }, result);
  3840. }
  3841. /**
  3842. * The base implementation of methods like `_.xor`, without support for
  3843. * iteratee shorthands, that accepts an array of arrays to inspect.
  3844. *
  3845. * @private
  3846. * @param {Array} arrays The arrays to inspect.
  3847. * @param {Function} [iteratee] The iteratee invoked per element.
  3848. * @param {Function} [comparator] The comparator invoked per element.
  3849. * @returns {Array} Returns the new array of values.
  3850. */
  3851. function baseXor(arrays, iteratee, comparator) {
  3852. var index = -1,
  3853. length = arrays.length;
  3854. while (++index < length) {
  3855. var result = result
  3856. ? arrayPush(
  3857. baseDifference(result, arrays[index], iteratee, comparator),
  3858. baseDifference(arrays[index], result, iteratee, comparator)
  3859. )
  3860. : arrays[index];
  3861. }
  3862. return (result && result.length) ? baseUniq(result, iteratee, comparator) : [];
  3863. }
  3864. /**
  3865. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  3866. *
  3867. * @private
  3868. * @param {Array} props The property identifiers.
  3869. * @param {Array} values The property values.
  3870. * @param {Function} assignFunc The function to assign values.
  3871. * @returns {Object} Returns the new object.
  3872. */
  3873. function baseZipObject(props, values, assignFunc) {
  3874. var index = -1,
  3875. length = props.length,
  3876. valsLength = values.length,
  3877. result = {};
  3878. while (++index < length) {
  3879. var value = index < valsLength ? values[index] : undefined;
  3880. assignFunc(result, props[index], value);
  3881. }
  3882. return result;
  3883. }
  3884. /**
  3885. * Casts `value` to an empty array if it's not an array like object.
  3886. *
  3887. * @private
  3888. * @param {*} value The value to inspect.
  3889. * @returns {Array|Object} Returns the cast array-like object.
  3890. */
  3891. function castArrayLikeObject(value) {
  3892. return isArrayLikeObject(value) ? value : [];
  3893. }
  3894. /**
  3895. * Casts `value` to `identity` if it's not a function.
  3896. *
  3897. * @private
  3898. * @param {*} value The value to inspect.
  3899. * @returns {Function} Returns cast function.
  3900. */
  3901. function castFunction(value) {
  3902. return typeof value == 'function' ? value : identity;
  3903. }
  3904. /**
  3905. * Casts `value` to a path array if it's not one.
  3906. *
  3907. * @private
  3908. * @param {*} value The value to inspect.
  3909. * @returns {Array} Returns the cast property path array.
  3910. */
  3911. function castPath(value) {
  3912. return isArray(value) ? value : stringToPath(value);
  3913. }
  3914. /**
  3915. * Casts `array` to a slice if it's needed.
  3916. *
  3917. * @private
  3918. * @param {Array} array The array to inspect.
  3919. * @param {number} start The start position.
  3920. * @param {number} [end=array.length] The end position.
  3921. * @returns {Array} Returns the cast slice.
  3922. */
  3923. function castSlice(array, start, end) {
  3924. var length = array.length;
  3925. end = end === undefined ? length : end;
  3926. return (!start && end >= length) ? array : baseSlice(array, start, end);
  3927. }
  3928. /**
  3929. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  3930. *
  3931. * @private
  3932. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  3933. */
  3934. var clearTimeout = ctxClearTimeout || function(id) {
  3935. return root.clearTimeout(id);
  3936. };
  3937. /**
  3938. * Creates a clone of `buffer`.
  3939. *
  3940. * @private
  3941. * @param {Buffer} buffer The buffer to clone.
  3942. * @param {boolean} [isDeep] Specify a deep clone.
  3943. * @returns {Buffer} Returns the cloned buffer.
  3944. */
  3945. function cloneBuffer(buffer, isDeep) {
  3946. if (isDeep) {
  3947. return buffer.slice();
  3948. }
  3949. var result = new buffer.constructor(buffer.length);
  3950. buffer.copy(result);
  3951. return result;
  3952. }
  3953. /**
  3954. * Creates a clone of `arrayBuffer`.
  3955. *
  3956. * @private
  3957. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  3958. * @returns {ArrayBuffer} Returns the cloned array buffer.
  3959. */
  3960. function cloneArrayBuffer(arrayBuffer) {
  3961. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  3962. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  3963. return result;
  3964. }
  3965. /**
  3966. * Creates a clone of `dataView`.
  3967. *
  3968. * @private
  3969. * @param {Object} dataView The data view to clone.
  3970. * @param {boolean} [isDeep] Specify a deep clone.
  3971. * @returns {Object} Returns the cloned data view.
  3972. */
  3973. function cloneDataView(dataView, isDeep) {
  3974. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  3975. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  3976. }
  3977. /**
  3978. * Creates a clone of `map`.
  3979. *
  3980. * @private
  3981. * @param {Object} map The map to clone.
  3982. * @param {Function} cloneFunc The function to clone values.
  3983. * @param {boolean} [isDeep] Specify a deep clone.
  3984. * @returns {Object} Returns the cloned map.
  3985. */
  3986. function cloneMap(map, isDeep, cloneFunc) {
  3987. var array = isDeep ? cloneFunc(mapToArray(map), true) : mapToArray(map);
  3988. return arrayReduce(array, addMapEntry, new map.constructor);
  3989. }
  3990. /**
  3991. * Creates a clone of `regexp`.
  3992. *
  3993. * @private
  3994. * @param {Object} regexp The regexp to clone.
  3995. * @returns {Object} Returns the cloned regexp.
  3996. */
  3997. function cloneRegExp(regexp) {
  3998. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  3999. result.lastIndex = regexp.lastIndex;
  4000. return result;
  4001. }
  4002. /**
  4003. * Creates a clone of `set`.
  4004. *
  4005. * @private
  4006. * @param {Object} set The set to clone.
  4007. * @param {Function} cloneFunc The function to clone values.
  4008. * @param {boolean} [isDeep] Specify a deep clone.
  4009. * @returns {Object} Returns the cloned set.
  4010. */
  4011. function cloneSet(set, isDeep, cloneFunc) {
  4012. var array = isDeep ? cloneFunc(setToArray(set), true) : setToArray(set);
  4013. return arrayReduce(array, addSetEntry, new set.constructor);
  4014. }
  4015. /**
  4016. * Creates a clone of the `symbol` object.
  4017. *
  4018. * @private
  4019. * @param {Object} symbol The symbol object to clone.
  4020. * @returns {Object} Returns the cloned symbol object.
  4021. */
  4022. function cloneSymbol(symbol) {
  4023. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4024. }
  4025. /**
  4026. * Creates a clone of `typedArray`.
  4027. *
  4028. * @private
  4029. * @param {Object} typedArray The typed array to clone.
  4030. * @param {boolean} [isDeep] Specify a deep clone.
  4031. * @returns {Object} Returns the cloned typed array.
  4032. */
  4033. function cloneTypedArray(typedArray, isDeep) {
  4034. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4035. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4036. }
  4037. /**
  4038. * Compares values to sort them in ascending order.
  4039. *
  4040. * @private
  4041. * @param {*} value The value to compare.
  4042. * @param {*} other The other value to compare.
  4043. * @returns {number} Returns the sort order indicator for `value`.
  4044. */
  4045. function compareAscending(value, other) {
  4046. if (value !== other) {
  4047. var valIsDefined = value !== undefined,
  4048. valIsNull = value === null,
  4049. valIsReflexive = value === value,
  4050. valIsSymbol = isSymbol(value);
  4051. var othIsDefined = other !== undefined,
  4052. othIsNull = other === null,
  4053. othIsReflexive = other === other,
  4054. othIsSymbol = isSymbol(other);
  4055. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4056. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4057. (valIsNull && othIsDefined && othIsReflexive) ||
  4058. (!valIsDefined && othIsReflexive) ||
  4059. !valIsReflexive) {
  4060. return 1;
  4061. }
  4062. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4063. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4064. (othIsNull && valIsDefined && valIsReflexive) ||
  4065. (!othIsDefined && valIsReflexive) ||
  4066. !othIsReflexive) {
  4067. return -1;
  4068. }
  4069. }
  4070. return 0;
  4071. }
  4072. /**
  4073. * Used by `_.orderBy` to compare multiple properties of a value to another
  4074. * and stable sort them.
  4075. *
  4076. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4077. * specify an order of "desc" for descending or "asc" for ascending sort order
  4078. * of corresponding values.
  4079. *
  4080. * @private
  4081. * @param {Object} object The object to compare.
  4082. * @param {Object} other The other object to compare.
  4083. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4084. * @returns {number} Returns the sort order indicator for `object`.
  4085. */
  4086. function compareMultiple(object, other, orders) {
  4087. var index = -1,
  4088. objCriteria = object.criteria,
  4089. othCriteria = other.criteria,
  4090. length = objCriteria.length,
  4091. ordersLength = orders.length;
  4092. while (++index < length) {
  4093. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4094. if (result) {
  4095. if (index >= ordersLength) {
  4096. return result;
  4097. }
  4098. var order = orders[index];
  4099. return result * (order == 'desc' ? -1 : 1);
  4100. }
  4101. }
  4102. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4103. // that causes it, under certain circumstances, to provide the same value for
  4104. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4105. // for more details.
  4106. //
  4107. // This also ensures a stable sort in V8 and other engines.
  4108. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4109. return object.index - other.index;
  4110. }
  4111. /**
  4112. * Creates an array that is the composition of partially applied arguments,
  4113. * placeholders, and provided arguments into a single array of arguments.
  4114. *
  4115. * @private
  4116. * @param {Array} args The provided arguments.
  4117. * @param {Array} partials The arguments to prepend to those provided.
  4118. * @param {Array} holders The `partials` placeholder indexes.
  4119. * @params {boolean} [isCurried] Specify composing for a curried function.
  4120. * @returns {Array} Returns the new array of composed arguments.
  4121. */
  4122. function composeArgs(args, partials, holders, isCurried) {
  4123. var argsIndex = -1,
  4124. argsLength = args.length,
  4125. holdersLength = holders.length,
  4126. leftIndex = -1,
  4127. leftLength = partials.length,
  4128. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4129. result = Array(leftLength + rangeLength),
  4130. isUncurried = !isCurried;
  4131. while (++leftIndex < leftLength) {
  4132. result[leftIndex] = partials[leftIndex];
  4133. }
  4134. while (++argsIndex < holdersLength) {
  4135. if (isUncurried || argsIndex < argsLength) {
  4136. result[holders[argsIndex]] = args[argsIndex];
  4137. }
  4138. }
  4139. while (rangeLength--) {
  4140. result[leftIndex++] = args[argsIndex++];
  4141. }
  4142. return result;
  4143. }
  4144. /**
  4145. * This function is like `composeArgs` except that the arguments composition
  4146. * is tailored for `_.partialRight`.
  4147. *
  4148. * @private
  4149. * @param {Array} args The provided arguments.
  4150. * @param {Array} partials The arguments to append to those provided.
  4151. * @param {Array} holders The `partials` placeholder indexes.
  4152. * @params {boolean} [isCurried] Specify composing for a curried function.
  4153. * @returns {Array} Returns the new array of composed arguments.
  4154. */
  4155. function composeArgsRight(args, partials, holders, isCurried) {
  4156. var argsIndex = -1,
  4157. argsLength = args.length,
  4158. holdersIndex = -1,
  4159. holdersLength = holders.length,
  4160. rightIndex = -1,
  4161. rightLength = partials.length,
  4162. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4163. result = Array(rangeLength + rightLength),
  4164. isUncurried = !isCurried;
  4165. while (++argsIndex < rangeLength) {
  4166. result[argsIndex] = args[argsIndex];
  4167. }
  4168. var offset = argsIndex;
  4169. while (++rightIndex < rightLength) {
  4170. result[offset + rightIndex] = partials[rightIndex];
  4171. }
  4172. while (++holdersIndex < holdersLength) {
  4173. if (isUncurried || argsIndex < argsLength) {
  4174. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4175. }
  4176. }
  4177. return result;
  4178. }
  4179. /**
  4180. * Copies the values of `source` to `array`.
  4181. *
  4182. * @private
  4183. * @param {Array} source The array to copy values from.
  4184. * @param {Array} [array=[]] The array to copy values to.
  4185. * @returns {Array} Returns `array`.
  4186. */
  4187. function copyArray(source, array) {
  4188. var index = -1,
  4189. length = source.length;
  4190. array || (array = Array(length));
  4191. while (++index < length) {
  4192. array[index] = source[index];
  4193. }
  4194. return array;
  4195. }
  4196. /**
  4197. * Copies properties of `source` to `object`.
  4198. *
  4199. * @private
  4200. * @param {Object} source The object to copy properties from.
  4201. * @param {Array} props The property identifiers to copy.
  4202. * @param {Object} [object={}] The object to copy properties to.
  4203. * @param {Function} [customizer] The function to customize copied values.
  4204. * @returns {Object} Returns `object`.
  4205. */
  4206. function copyObject(source, props, object, customizer) {
  4207. object || (object = {});
  4208. var index = -1,
  4209. length = props.length;
  4210. while (++index < length) {
  4211. var key = props[index];
  4212. var newValue = customizer
  4213. ? customizer(object[key], source[key], key, object, source)
  4214. : undefined;
  4215. assignValue(object, key, newValue === undefined ? source[key] : newValue);
  4216. }
  4217. return object;
  4218. }
  4219. /**
  4220. * Copies own symbol properties of `source` to `object`.
  4221. *
  4222. * @private
  4223. * @param {Object} source The object to copy symbols from.
  4224. * @param {Object} [object={}] The object to copy symbols to.
  4225. * @returns {Object} Returns `object`.
  4226. */
  4227. function copySymbols(source, object) {
  4228. return copyObject(source, getSymbols(source), object);
  4229. }
  4230. /**
  4231. * Creates a function like `_.groupBy`.
  4232. *
  4233. * @private
  4234. * @param {Function} setter The function to set accumulator values.
  4235. * @param {Function} [initializer] The accumulator object initializer.
  4236. * @returns {Function} Returns the new aggregator function.
  4237. */
  4238. function createAggregator(setter, initializer) {
  4239. return function(collection, iteratee) {
  4240. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4241. accumulator = initializer ? initializer() : {};
  4242. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4243. };
  4244. }
  4245. /**
  4246. * Creates a function like `_.assign`.
  4247. *
  4248. * @private
  4249. * @param {Function} assigner The function to assign values.
  4250. * @returns {Function} Returns the new assigner function.
  4251. */
  4252. function createAssigner(assigner) {
  4253. return baseRest(function(object, sources) {
  4254. var index = -1,
  4255. length = sources.length,
  4256. customizer = length > 1 ? sources[length - 1] : undefined,
  4257. guard = length > 2 ? sources[2] : undefined;
  4258. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4259. ? (length--, customizer)
  4260. : undefined;
  4261. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4262. customizer = length < 3 ? undefined : customizer;
  4263. length = 1;
  4264. }
  4265. object = Object(object);
  4266. while (++index < length) {
  4267. var source = sources[index];
  4268. if (source) {
  4269. assigner(object, source, index, customizer);
  4270. }
  4271. }
  4272. return object;
  4273. });
  4274. }
  4275. /**
  4276. * Creates a `baseEach` or `baseEachRight` function.
  4277. *
  4278. * @private
  4279. * @param {Function} eachFunc The function to iterate over a collection.
  4280. * @param {boolean} [fromRight] Specify iterating from right to left.
  4281. * @returns {Function} Returns the new base function.
  4282. */
  4283. function createBaseEach(eachFunc, fromRight) {
  4284. return function(collection, iteratee) {
  4285. if (collection == null) {
  4286. return collection;
  4287. }
  4288. if (!isArrayLike(collection)) {
  4289. return eachFunc(collection, iteratee);
  4290. }
  4291. var length = collection.length,
  4292. index = fromRight ? length : -1,
  4293. iterable = Object(collection);
  4294. while ((fromRight ? index-- : ++index < length)) {
  4295. if (iteratee(iterable[index], index, iterable) === false) {
  4296. break;
  4297. }
  4298. }
  4299. return collection;
  4300. };
  4301. }
  4302. /**
  4303. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4304. *
  4305. * @private
  4306. * @param {boolean} [fromRight] Specify iterating from right to left.
  4307. * @returns {Function} Returns the new base function.
  4308. */
  4309. function createBaseFor(fromRight) {
  4310. return function(object, iteratee, keysFunc) {
  4311. var index = -1,
  4312. iterable = Object(object),
  4313. props = keysFunc(object),
  4314. length = props.length;
  4315. while (length--) {
  4316. var key = props[fromRight ? length : ++index];
  4317. if (iteratee(iterable[key], key, iterable) === false) {
  4318. break;
  4319. }
  4320. }
  4321. return object;
  4322. };
  4323. }
  4324. /**
  4325. * Creates a function that wraps `func` to invoke it with the optional `this`
  4326. * binding of `thisArg`.
  4327. *
  4328. * @private
  4329. * @param {Function} func The function to wrap.
  4330. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4331. * @param {*} [thisArg] The `this` binding of `func`.
  4332. * @returns {Function} Returns the new wrapped function.
  4333. */
  4334. function createBind(func, bitmask, thisArg) {
  4335. var isBind = bitmask & BIND_FLAG,
  4336. Ctor = createCtor(func);
  4337. function wrapper() {
  4338. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4339. return fn.apply(isBind ? thisArg : this, arguments);
  4340. }
  4341. return wrapper;
  4342. }
  4343. /**
  4344. * Creates a function like `_.lowerFirst`.
  4345. *
  4346. * @private
  4347. * @param {string} methodName The name of the `String` case method to use.
  4348. * @returns {Function} Returns the new case function.
  4349. */
  4350. function createCaseFirst(methodName) {
  4351. return function(string) {
  4352. string = toString(string);
  4353. var strSymbols = hasUnicode(string)
  4354. ? stringToArray(string)
  4355. : undefined;
  4356. var chr = strSymbols
  4357. ? strSymbols[0]
  4358. : string.charAt(0);
  4359. var trailing = strSymbols
  4360. ? castSlice(strSymbols, 1).join('')
  4361. : string.slice(1);
  4362. return chr[methodName]() + trailing;
  4363. };
  4364. }
  4365. /**
  4366. * Creates a function like `_.camelCase`.
  4367. *
  4368. * @private
  4369. * @param {Function} callback The function to combine each word.
  4370. * @returns {Function} Returns the new compounder function.
  4371. */
  4372. function createCompounder(callback) {
  4373. return function(string) {
  4374. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4375. };
  4376. }
  4377. /**
  4378. * Creates a function that produces an instance of `Ctor` regardless of
  4379. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4380. *
  4381. * @private
  4382. * @param {Function} Ctor The constructor to wrap.
  4383. * @returns {Function} Returns the new wrapped function.
  4384. */
  4385. function createCtor(Ctor) {
  4386. return function() {
  4387. // Use a `switch` statement to work with class constructors. See
  4388. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4389. // for more details.
  4390. var args = arguments;
  4391. switch (args.length) {
  4392. case 0: return new Ctor;
  4393. case 1: return new Ctor(args[0]);
  4394. case 2: return new Ctor(args[0], args[1]);
  4395. case 3: return new Ctor(args[0], args[1], args[2]);
  4396. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4397. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4398. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4399. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4400. }
  4401. var thisBinding = baseCreate(Ctor.prototype),
  4402. result = Ctor.apply(thisBinding, args);
  4403. // Mimic the constructor's `return` behavior.
  4404. // See https://es5.github.io/#x13.2.2 for more details.
  4405. return isObject(result) ? result : thisBinding;
  4406. };
  4407. }
  4408. /**
  4409. * Creates a function that wraps `func` to enable currying.
  4410. *
  4411. * @private
  4412. * @param {Function} func The function to wrap.
  4413. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4414. * @param {number} arity The arity of `func`.
  4415. * @returns {Function} Returns the new wrapped function.
  4416. */
  4417. function createCurry(func, bitmask, arity) {
  4418. var Ctor = createCtor(func);
  4419. function wrapper() {
  4420. var length = arguments.length,
  4421. args = Array(length),
  4422. index = length,
  4423. placeholder = getHolder(wrapper);
  4424. while (index--) {
  4425. args[index] = arguments[index];
  4426. }
  4427. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4428. ? []
  4429. : replaceHolders(args, placeholder);
  4430. length -= holders.length;
  4431. if (length < arity) {
  4432. return createRecurry(
  4433. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4434. args, holders, undefined, undefined, arity - length);
  4435. }
  4436. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4437. return apply(fn, this, args);
  4438. }
  4439. return wrapper;
  4440. }
  4441. /**
  4442. * Creates a `_.find` or `_.findLast` function.
  4443. *
  4444. * @private
  4445. * @param {Function} findIndexFunc The function to find the collection index.
  4446. * @returns {Function} Returns the new find function.
  4447. */
  4448. function createFind(findIndexFunc) {
  4449. return function(collection, predicate, fromIndex) {
  4450. var iterable = Object(collection);
  4451. if (!isArrayLike(collection)) {
  4452. var iteratee = getIteratee(predicate, 3);
  4453. collection = keys(collection);
  4454. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4455. }
  4456. var index = findIndexFunc(collection, predicate, fromIndex);
  4457. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4458. };
  4459. }
  4460. /**
  4461. * Creates a `_.flow` or `_.flowRight` function.
  4462. *
  4463. * @private
  4464. * @param {boolean} [fromRight] Specify iterating from right to left.
  4465. * @returns {Function} Returns the new flow function.
  4466. */
  4467. function createFlow(fromRight) {
  4468. return baseRest(function(funcs) {
  4469. funcs = baseFlatten(funcs, 1);
  4470. var length = funcs.length,
  4471. index = length,
  4472. prereq = LodashWrapper.prototype.thru;
  4473. if (fromRight) {
  4474. funcs.reverse();
  4475. }
  4476. while (index--) {
  4477. var func = funcs[index];
  4478. if (typeof func != 'function') {
  4479. throw new TypeError(FUNC_ERROR_TEXT);
  4480. }
  4481. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4482. var wrapper = new LodashWrapper([], true);
  4483. }
  4484. }
  4485. index = wrapper ? index : length;
  4486. while (++index < length) {
  4487. func = funcs[index];
  4488. var funcName = getFuncName(func),
  4489. data = funcName == 'wrapper' ? getData(func) : undefined;
  4490. if (data && isLaziable(data[0]) &&
  4491. data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) &&
  4492. !data[4].length && data[9] == 1
  4493. ) {
  4494. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4495. } else {
  4496. wrapper = (func.length == 1 && isLaziable(func))
  4497. ? wrapper[funcName]()
  4498. : wrapper.thru(func);
  4499. }
  4500. }
  4501. return function() {
  4502. var args = arguments,
  4503. value = args[0];
  4504. if (wrapper && args.length == 1 &&
  4505. isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
  4506. return wrapper.plant(value).value();
  4507. }
  4508. var index = 0,
  4509. result = length ? funcs[index].apply(this, args) : value;
  4510. while (++index < length) {
  4511. result = funcs[index].call(this, result);
  4512. }
  4513. return result;
  4514. };
  4515. });
  4516. }
  4517. /**
  4518. * Creates a function that wraps `func` to invoke it with optional `this`
  4519. * binding of `thisArg`, partial application, and currying.
  4520. *
  4521. * @private
  4522. * @param {Function|string} func The function or method name to wrap.
  4523. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4524. * @param {*} [thisArg] The `this` binding of `func`.
  4525. * @param {Array} [partials] The arguments to prepend to those provided to
  4526. * the new function.
  4527. * @param {Array} [holders] The `partials` placeholder indexes.
  4528. * @param {Array} [partialsRight] The arguments to append to those provided
  4529. * to the new function.
  4530. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4531. * @param {Array} [argPos] The argument positions of the new function.
  4532. * @param {number} [ary] The arity cap of `func`.
  4533. * @param {number} [arity] The arity of `func`.
  4534. * @returns {Function} Returns the new wrapped function.
  4535. */
  4536. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4537. var isAry = bitmask & ARY_FLAG,
  4538. isBind = bitmask & BIND_FLAG,
  4539. isBindKey = bitmask & BIND_KEY_FLAG,
  4540. isCurried = bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG),
  4541. isFlip = bitmask & FLIP_FLAG,
  4542. Ctor = isBindKey ? undefined : createCtor(func);
  4543. function wrapper() {
  4544. var length = arguments.length,
  4545. args = Array(length),
  4546. index = length;
  4547. while (index--) {
  4548. args[index] = arguments[index];
  4549. }
  4550. if (isCurried) {
  4551. var placeholder = getHolder(wrapper),
  4552. holdersCount = countHolders(args, placeholder);
  4553. }
  4554. if (partials) {
  4555. args = composeArgs(args, partials, holders, isCurried);
  4556. }
  4557. if (partialsRight) {
  4558. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4559. }
  4560. length -= holdersCount;
  4561. if (isCurried && length < arity) {
  4562. var newHolders = replaceHolders(args, placeholder);
  4563. return createRecurry(
  4564. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4565. args, newHolders, argPos, ary, arity - length
  4566. );
  4567. }
  4568. var thisBinding = isBind ? thisArg : this,
  4569. fn = isBindKey ? thisBinding[func] : func;
  4570. length = args.length;
  4571. if (argPos) {
  4572. args = reorder(args, argPos);
  4573. } else if (isFlip && length > 1) {
  4574. args.reverse();
  4575. }
  4576. if (isAry && ary < length) {
  4577. args.length = ary;
  4578. }
  4579. if (this && this !== root && this instanceof wrapper) {
  4580. fn = Ctor || createCtor(fn);
  4581. }
  4582. return fn.apply(thisBinding, args);
  4583. }
  4584. return wrapper;
  4585. }
  4586. /**
  4587. * Creates a function like `_.invertBy`.
  4588. *
  4589. * @private
  4590. * @param {Function} setter The function to set accumulator values.
  4591. * @param {Function} toIteratee The function to resolve iteratees.
  4592. * @returns {Function} Returns the new inverter function.
  4593. */
  4594. function createInverter(setter, toIteratee) {
  4595. return function(object, iteratee) {
  4596. return baseInverter(object, setter, toIteratee(iteratee), {});
  4597. };
  4598. }
  4599. /**
  4600. * Creates a function that performs a mathematical operation on two values.
  4601. *
  4602. * @private
  4603. * @param {Function} operator The function to perform the operation.
  4604. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4605. * @returns {Function} Returns the new mathematical operation function.
  4606. */
  4607. function createMathOperation(operator, defaultValue) {
  4608. return function(value, other) {
  4609. var result;
  4610. if (value === undefined && other === undefined) {
  4611. return defaultValue;
  4612. }
  4613. if (value !== undefined) {
  4614. result = value;
  4615. }
  4616. if (other !== undefined) {
  4617. if (result === undefined) {
  4618. return other;
  4619. }
  4620. if (typeof value == 'string' || typeof other == 'string') {
  4621. value = baseToString(value);
  4622. other = baseToString(other);
  4623. } else {
  4624. value = baseToNumber(value);
  4625. other = baseToNumber(other);
  4626. }
  4627. result = operator(value, other);
  4628. }
  4629. return result;
  4630. };
  4631. }
  4632. /**
  4633. * Creates a function like `_.over`.
  4634. *
  4635. * @private
  4636. * @param {Function} arrayFunc The function to iterate over iteratees.
  4637. * @returns {Function} Returns the new over function.
  4638. */
  4639. function createOver(arrayFunc) {
  4640. return baseRest(function(iteratees) {
  4641. iteratees = (iteratees.length == 1 && isArray(iteratees[0]))
  4642. ? arrayMap(iteratees[0], baseUnary(getIteratee()))
  4643. : arrayMap(baseFlatten(iteratees, 1), baseUnary(getIteratee()));
  4644. return baseRest(function(args) {
  4645. var thisArg = this;
  4646. return arrayFunc(iteratees, function(iteratee) {
  4647. return apply(iteratee, thisArg, args);
  4648. });
  4649. });
  4650. });
  4651. }
  4652. /**
  4653. * Creates the padding for `string` based on `length`. The `chars` string
  4654. * is truncated if the number of characters exceeds `length`.
  4655. *
  4656. * @private
  4657. * @param {number} length The padding length.
  4658. * @param {string} [chars=' '] The string used as padding.
  4659. * @returns {string} Returns the padding for `string`.
  4660. */
  4661. function createPadding(length, chars) {
  4662. chars = chars === undefined ? ' ' : baseToString(chars);
  4663. var charsLength = chars.length;
  4664. if (charsLength < 2) {
  4665. return charsLength ? baseRepeat(chars, length) : chars;
  4666. }
  4667. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4668. return hasUnicode(chars)
  4669. ? castSlice(stringToArray(result), 0, length).join('')
  4670. : result.slice(0, length);
  4671. }
  4672. /**
  4673. * Creates a function that wraps `func` to invoke it with the `this` binding
  4674. * of `thisArg` and `partials` prepended to the arguments it receives.
  4675. *
  4676. * @private
  4677. * @param {Function} func The function to wrap.
  4678. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4679. * @param {*} thisArg The `this` binding of `func`.
  4680. * @param {Array} partials The arguments to prepend to those provided to
  4681. * the new function.
  4682. * @returns {Function} Returns the new wrapped function.
  4683. */
  4684. function createPartial(func, bitmask, thisArg, partials) {
  4685. var isBind = bitmask & BIND_FLAG,
  4686. Ctor = createCtor(func);
  4687. function wrapper() {
  4688. var argsIndex = -1,
  4689. argsLength = arguments.length,
  4690. leftIndex = -1,
  4691. leftLength = partials.length,
  4692. args = Array(leftLength + argsLength),
  4693. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4694. while (++leftIndex < leftLength) {
  4695. args[leftIndex] = partials[leftIndex];
  4696. }
  4697. while (argsLength--) {
  4698. args[leftIndex++] = arguments[++argsIndex];
  4699. }
  4700. return apply(fn, isBind ? thisArg : this, args);
  4701. }
  4702. return wrapper;
  4703. }
  4704. /**
  4705. * Creates a `_.range` or `_.rangeRight` function.
  4706. *
  4707. * @private
  4708. * @param {boolean} [fromRight] Specify iterating from right to left.
  4709. * @returns {Function} Returns the new range function.
  4710. */
  4711. function createRange(fromRight) {
  4712. return function(start, end, step) {
  4713. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4714. end = step = undefined;
  4715. }
  4716. // Ensure the sign of `-0` is preserved.
  4717. start = toFinite(start);
  4718. if (end === undefined) {
  4719. end = start;
  4720. start = 0;
  4721. } else {
  4722. end = toFinite(end);
  4723. }
  4724. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4725. return baseRange(start, end, step, fromRight);
  4726. };
  4727. }
  4728. /**
  4729. * Creates a function that performs a relational operation on two values.
  4730. *
  4731. * @private
  4732. * @param {Function} operator The function to perform the operation.
  4733. * @returns {Function} Returns the new relational operation function.
  4734. */
  4735. function createRelationalOperation(operator) {
  4736. return function(value, other) {
  4737. if (!(typeof value == 'string' && typeof other == 'string')) {
  4738. value = toNumber(value);
  4739. other = toNumber(other);
  4740. }
  4741. return operator(value, other);
  4742. };
  4743. }
  4744. /**
  4745. * Creates a function that wraps `func` to continue currying.
  4746. *
  4747. * @private
  4748. * @param {Function} func The function to wrap.
  4749. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4750. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4751. * @param {*} placeholder The placeholder value.
  4752. * @param {*} [thisArg] The `this` binding of `func`.
  4753. * @param {Array} [partials] The arguments to prepend to those provided to
  4754. * the new function.
  4755. * @param {Array} [holders] The `partials` placeholder indexes.
  4756. * @param {Array} [argPos] The argument positions of the new function.
  4757. * @param {number} [ary] The arity cap of `func`.
  4758. * @param {number} [arity] The arity of `func`.
  4759. * @returns {Function} Returns the new wrapped function.
  4760. */
  4761. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4762. var isCurry = bitmask & CURRY_FLAG,
  4763. newHolders = isCurry ? holders : undefined,
  4764. newHoldersRight = isCurry ? undefined : holders,
  4765. newPartials = isCurry ? partials : undefined,
  4766. newPartialsRight = isCurry ? undefined : partials;
  4767. bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
  4768. bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
  4769. if (!(bitmask & CURRY_BOUND_FLAG)) {
  4770. bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
  4771. }
  4772. var newData = [
  4773. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4774. newHoldersRight, argPos, ary, arity
  4775. ];
  4776. var result = wrapFunc.apply(undefined, newData);
  4777. if (isLaziable(func)) {
  4778. setData(result, newData);
  4779. }
  4780. result.placeholder = placeholder;
  4781. return setWrapToString(result, func, bitmask);
  4782. }
  4783. /**
  4784. * Creates a function like `_.round`.
  4785. *
  4786. * @private
  4787. * @param {string} methodName The name of the `Math` method to use when rounding.
  4788. * @returns {Function} Returns the new round function.
  4789. */
  4790. function createRound(methodName) {
  4791. var func = Math[methodName];
  4792. return function(number, precision) {
  4793. number = toNumber(number);
  4794. precision = nativeMin(toInteger(precision), 292);
  4795. if (precision) {
  4796. // Shift with exponential notation to avoid floating-point issues.
  4797. // See [MDN](https://mdn.io/round#Examples) for more details.
  4798. var pair = (toString(number) + 'e').split('e'),
  4799. value = func(pair[0] + 'e' + (+pair[1] + precision));
  4800. pair = (toString(value) + 'e').split('e');
  4801. return +(pair[0] + 'e' + (+pair[1] - precision));
  4802. }
  4803. return func(number);
  4804. };
  4805. }
  4806. /**
  4807. * Creates a set object of `values`.
  4808. *
  4809. * @private
  4810. * @param {Array} values The values to add to the set.
  4811. * @returns {Object} Returns the new set.
  4812. */
  4813. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  4814. return new Set(values);
  4815. };
  4816. /**
  4817. * Creates a `_.toPairs` or `_.toPairsIn` function.
  4818. *
  4819. * @private
  4820. * @param {Function} keysFunc The function to get the keys of a given object.
  4821. * @returns {Function} Returns the new pairs function.
  4822. */
  4823. function createToPairs(keysFunc) {
  4824. return function(object) {
  4825. var tag = getTag(object);
  4826. if (tag == mapTag) {
  4827. return mapToArray(object);
  4828. }
  4829. if (tag == setTag) {
  4830. return setToPairs(object);
  4831. }
  4832. return baseToPairs(object, keysFunc(object));
  4833. };
  4834. }
  4835. /**
  4836. * Creates a function that either curries or invokes `func` with optional
  4837. * `this` binding and partially applied arguments.
  4838. *
  4839. * @private
  4840. * @param {Function|string} func The function or method name to wrap.
  4841. * @param {number} bitmask The bitmask flags.
  4842. * The bitmask may be composed of the following flags:
  4843. * 1 - `_.bind`
  4844. * 2 - `_.bindKey`
  4845. * 4 - `_.curry` or `_.curryRight` of a bound function
  4846. * 8 - `_.curry`
  4847. * 16 - `_.curryRight`
  4848. * 32 - `_.partial`
  4849. * 64 - `_.partialRight`
  4850. * 128 - `_.rearg`
  4851. * 256 - `_.ary`
  4852. * 512 - `_.flip`
  4853. * @param {*} [thisArg] The `this` binding of `func`.
  4854. * @param {Array} [partials] The arguments to be partially applied.
  4855. * @param {Array} [holders] The `partials` placeholder indexes.
  4856. * @param {Array} [argPos] The argument positions of the new function.
  4857. * @param {number} [ary] The arity cap of `func`.
  4858. * @param {number} [arity] The arity of `func`.
  4859. * @returns {Function} Returns the new wrapped function.
  4860. */
  4861. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  4862. var isBindKey = bitmask & BIND_KEY_FLAG;
  4863. if (!isBindKey && typeof func != 'function') {
  4864. throw new TypeError(FUNC_ERROR_TEXT);
  4865. }
  4866. var length = partials ? partials.length : 0;
  4867. if (!length) {
  4868. bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
  4869. partials = holders = undefined;
  4870. }
  4871. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  4872. arity = arity === undefined ? arity : toInteger(arity);
  4873. length -= holders ? holders.length : 0;
  4874. if (bitmask & PARTIAL_RIGHT_FLAG) {
  4875. var partialsRight = partials,
  4876. holdersRight = holders;
  4877. partials = holders = undefined;
  4878. }
  4879. var data = isBindKey ? undefined : getData(func);
  4880. var newData = [
  4881. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  4882. argPos, ary, arity
  4883. ];
  4884. if (data) {
  4885. mergeData(newData, data);
  4886. }
  4887. func = newData[0];
  4888. bitmask = newData[1];
  4889. thisArg = newData[2];
  4890. partials = newData[3];
  4891. holders = newData[4];
  4892. arity = newData[9] = newData[9] == null
  4893. ? (isBindKey ? 0 : func.length)
  4894. : nativeMax(newData[9] - length, 0);
  4895. if (!arity && bitmask & (CURRY_FLAG | CURRY_RIGHT_FLAG)) {
  4896. bitmask &= ~(CURRY_FLAG | CURRY_RIGHT_FLAG);
  4897. }
  4898. if (!bitmask || bitmask == BIND_FLAG) {
  4899. var result = createBind(func, bitmask, thisArg);
  4900. } else if (bitmask == CURRY_FLAG || bitmask == CURRY_RIGHT_FLAG) {
  4901. result = createCurry(func, bitmask, arity);
  4902. } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !holders.length) {
  4903. result = createPartial(func, bitmask, thisArg, partials);
  4904. } else {
  4905. result = createHybrid.apply(undefined, newData);
  4906. }
  4907. var setter = data ? baseSetData : setData;
  4908. return setWrapToString(setter(result, newData), func, bitmask);
  4909. }
  4910. /**
  4911. * A specialized version of `baseIsEqualDeep` for arrays with support for
  4912. * partial deep comparisons.
  4913. *
  4914. * @private
  4915. * @param {Array} array The array to compare.
  4916. * @param {Array} other The other array to compare.
  4917. * @param {Function} equalFunc The function to determine equivalents of values.
  4918. * @param {Function} customizer The function to customize comparisons.
  4919. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  4920. * for more details.
  4921. * @param {Object} stack Tracks traversed `array` and `other` objects.
  4922. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  4923. */
  4924. function equalArrays(array, other, equalFunc, customizer, bitmask, stack) {
  4925. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  4926. arrLength = array.length,
  4927. othLength = other.length;
  4928. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  4929. return false;
  4930. }
  4931. // Assume cyclic values are equal.
  4932. var stacked = stack.get(array);
  4933. if (stacked && stack.get(other)) {
  4934. return stacked == other;
  4935. }
  4936. var index = -1,
  4937. result = true,
  4938. seen = (bitmask & UNORDERED_COMPARE_FLAG) ? new SetCache : undefined;
  4939. stack.set(array, other);
  4940. stack.set(other, array);
  4941. // Ignore non-index properties.
  4942. while (++index < arrLength) {
  4943. var arrValue = array[index],
  4944. othValue = other[index];
  4945. if (customizer) {
  4946. var compared = isPartial
  4947. ? customizer(othValue, arrValue, index, other, array, stack)
  4948. : customizer(arrValue, othValue, index, array, other, stack);
  4949. }
  4950. if (compared !== undefined) {
  4951. if (compared) {
  4952. continue;
  4953. }
  4954. result = false;
  4955. break;
  4956. }
  4957. // Recursively compare arrays (susceptible to call stack limits).
  4958. if (seen) {
  4959. if (!arraySome(other, function(othValue, othIndex) {
  4960. if (!seen.has(othIndex) &&
  4961. (arrValue === othValue || equalFunc(arrValue, othValue, customizer, bitmask, stack))) {
  4962. return seen.add(othIndex);
  4963. }
  4964. })) {
  4965. result = false;
  4966. break;
  4967. }
  4968. } else if (!(
  4969. arrValue === othValue ||
  4970. equalFunc(arrValue, othValue, customizer, bitmask, stack)
  4971. )) {
  4972. result = false;
  4973. break;
  4974. }
  4975. }
  4976. stack['delete'](array);
  4977. stack['delete'](other);
  4978. return result;
  4979. }
  4980. /**
  4981. * A specialized version of `baseIsEqualDeep` for comparing objects of
  4982. * the same `toStringTag`.
  4983. *
  4984. * **Note:** This function only supports comparing values with tags of
  4985. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  4986. *
  4987. * @private
  4988. * @param {Object} object The object to compare.
  4989. * @param {Object} other The other object to compare.
  4990. * @param {string} tag The `toStringTag` of the objects to compare.
  4991. * @param {Function} equalFunc The function to determine equivalents of values.
  4992. * @param {Function} customizer The function to customize comparisons.
  4993. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  4994. * for more details.
  4995. * @param {Object} stack Tracks traversed `object` and `other` objects.
  4996. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  4997. */
  4998. function equalByTag(object, other, tag, equalFunc, customizer, bitmask, stack) {
  4999. switch (tag) {
  5000. case dataViewTag:
  5001. if ((object.byteLength != other.byteLength) ||
  5002. (object.byteOffset != other.byteOffset)) {
  5003. return false;
  5004. }
  5005. object = object.buffer;
  5006. other = other.buffer;
  5007. case arrayBufferTag:
  5008. if ((object.byteLength != other.byteLength) ||
  5009. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5010. return false;
  5011. }
  5012. return true;
  5013. case boolTag:
  5014. case dateTag:
  5015. case numberTag:
  5016. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5017. // Invalid dates are coerced to `NaN`.
  5018. return eq(+object, +other);
  5019. case errorTag:
  5020. return object.name == other.name && object.message == other.message;
  5021. case regexpTag:
  5022. case stringTag:
  5023. // Coerce regexes to strings and treat strings, primitives and objects,
  5024. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5025. // for more details.
  5026. return object == (other + '');
  5027. case mapTag:
  5028. var convert = mapToArray;
  5029. case setTag:
  5030. var isPartial = bitmask & PARTIAL_COMPARE_FLAG;
  5031. convert || (convert = setToArray);
  5032. if (object.size != other.size && !isPartial) {
  5033. return false;
  5034. }
  5035. // Assume cyclic values are equal.
  5036. var stacked = stack.get(object);
  5037. if (stacked) {
  5038. return stacked == other;
  5039. }
  5040. bitmask |= UNORDERED_COMPARE_FLAG;
  5041. // Recursively compare objects (susceptible to call stack limits).
  5042. stack.set(object, other);
  5043. var result = equalArrays(convert(object), convert(other), equalFunc, customizer, bitmask, stack);
  5044. stack['delete'](object);
  5045. return result;
  5046. case symbolTag:
  5047. if (symbolValueOf) {
  5048. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5049. }
  5050. }
  5051. return false;
  5052. }
  5053. /**
  5054. * A specialized version of `baseIsEqualDeep` for objects with support for
  5055. * partial deep comparisons.
  5056. *
  5057. * @private
  5058. * @param {Object} object The object to compare.
  5059. * @param {Object} other The other object to compare.
  5060. * @param {Function} equalFunc The function to determine equivalents of values.
  5061. * @param {Function} customizer The function to customize comparisons.
  5062. * @param {number} bitmask The bitmask of comparison flags. See `baseIsEqual`
  5063. * for more details.
  5064. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5065. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5066. */
  5067. function equalObjects(object, other, equalFunc, customizer, bitmask, stack) {
  5068. var isPartial = bitmask & PARTIAL_COMPARE_FLAG,
  5069. objProps = keys(object),
  5070. objLength = objProps.length,
  5071. othProps = keys(other),
  5072. othLength = othProps.length;
  5073. if (objLength != othLength && !isPartial) {
  5074. return false;
  5075. }
  5076. var index = objLength;
  5077. while (index--) {
  5078. var key = objProps[index];
  5079. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5080. return false;
  5081. }
  5082. }
  5083. // Assume cyclic values are equal.
  5084. var stacked = stack.get(object);
  5085. if (stacked && stack.get(other)) {
  5086. return stacked == other;
  5087. }
  5088. var result = true;
  5089. stack.set(object, other);
  5090. stack.set(other, object);
  5091. var skipCtor = isPartial;
  5092. while (++index < objLength) {
  5093. key = objProps[index];
  5094. var objValue = object[key],
  5095. othValue = other[key];
  5096. if (customizer) {
  5097. var compared = isPartial
  5098. ? customizer(othValue, objValue, key, other, object, stack)
  5099. : customizer(objValue, othValue, key, object, other, stack);
  5100. }
  5101. // Recursively compare objects (susceptible to call stack limits).
  5102. if (!(compared === undefined
  5103. ? (objValue === othValue || equalFunc(objValue, othValue, customizer, bitmask, stack))
  5104. : compared
  5105. )) {
  5106. result = false;
  5107. break;
  5108. }
  5109. skipCtor || (skipCtor = key == 'constructor');
  5110. }
  5111. if (result && !skipCtor) {
  5112. var objCtor = object.constructor,
  5113. othCtor = other.constructor;
  5114. // Non `Object` object instances with different constructors are not equal.
  5115. if (objCtor != othCtor &&
  5116. ('constructor' in object && 'constructor' in other) &&
  5117. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5118. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5119. result = false;
  5120. }
  5121. }
  5122. stack['delete'](object);
  5123. stack['delete'](other);
  5124. return result;
  5125. }
  5126. /**
  5127. * Creates an array of own enumerable property names and symbols of `object`.
  5128. *
  5129. * @private
  5130. * @param {Object} object The object to query.
  5131. * @returns {Array} Returns the array of property names and symbols.
  5132. */
  5133. function getAllKeys(object) {
  5134. return baseGetAllKeys(object, keys, getSymbols);
  5135. }
  5136. /**
  5137. * Creates an array of own and inherited enumerable property names and
  5138. * symbols of `object`.
  5139. *
  5140. * @private
  5141. * @param {Object} object The object to query.
  5142. * @returns {Array} Returns the array of property names and symbols.
  5143. */
  5144. function getAllKeysIn(object) {
  5145. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5146. }
  5147. /**
  5148. * Gets metadata for `func`.
  5149. *
  5150. * @private
  5151. * @param {Function} func The function to query.
  5152. * @returns {*} Returns the metadata for `func`.
  5153. */
  5154. var getData = !metaMap ? noop : function(func) {
  5155. return metaMap.get(func);
  5156. };
  5157. /**
  5158. * Gets the name of `func`.
  5159. *
  5160. * @private
  5161. * @param {Function} func The function to query.
  5162. * @returns {string} Returns the function name.
  5163. */
  5164. function getFuncName(func) {
  5165. var result = (func.name + ''),
  5166. array = realNames[result],
  5167. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5168. while (length--) {
  5169. var data = array[length],
  5170. otherFunc = data.func;
  5171. if (otherFunc == null || otherFunc == func) {
  5172. return data.name;
  5173. }
  5174. }
  5175. return result;
  5176. }
  5177. /**
  5178. * Gets the argument placeholder value for `func`.
  5179. *
  5180. * @private
  5181. * @param {Function} func The function to inspect.
  5182. * @returns {*} Returns the placeholder value.
  5183. */
  5184. function getHolder(func) {
  5185. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5186. return object.placeholder;
  5187. }
  5188. /**
  5189. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5190. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5191. * If arguments are provided, the chosen function is invoked with them and
  5192. * its result is returned.
  5193. *
  5194. * @private
  5195. * @param {*} [value] The value to convert to an iteratee.
  5196. * @param {number} [arity] The arity of the created iteratee.
  5197. * @returns {Function} Returns the chosen function or its result.
  5198. */
  5199. function getIteratee() {
  5200. var result = lodash.iteratee || iteratee;
  5201. result = result === iteratee ? baseIteratee : result;
  5202. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5203. }
  5204. /**
  5205. * Gets the data for `map`.
  5206. *
  5207. * @private
  5208. * @param {Object} map The map to query.
  5209. * @param {string} key The reference key.
  5210. * @returns {*} Returns the map data.
  5211. */
  5212. function getMapData(map, key) {
  5213. var data = map.__data__;
  5214. return isKeyable(key)
  5215. ? data[typeof key == 'string' ? 'string' : 'hash']
  5216. : data.map;
  5217. }
  5218. /**
  5219. * Gets the property names, values, and compare flags of `object`.
  5220. *
  5221. * @private
  5222. * @param {Object} object The object to query.
  5223. * @returns {Array} Returns the match data of `object`.
  5224. */
  5225. function getMatchData(object) {
  5226. var result = keys(object),
  5227. length = result.length;
  5228. while (length--) {
  5229. var key = result[length],
  5230. value = object[key];
  5231. result[length] = [key, value, isStrictComparable(value)];
  5232. }
  5233. return result;
  5234. }
  5235. /**
  5236. * Gets the native function at `key` of `object`.
  5237. *
  5238. * @private
  5239. * @param {Object} object The object to query.
  5240. * @param {string} key The key of the method to get.
  5241. * @returns {*} Returns the function if it's native, else `undefined`.
  5242. */
  5243. function getNative(object, key) {
  5244. var value = getValue(object, key);
  5245. return baseIsNative(value) ? value : undefined;
  5246. }
  5247. /**
  5248. * Creates an array of the own enumerable symbol properties of `object`.
  5249. *
  5250. * @private
  5251. * @param {Object} object The object to query.
  5252. * @returns {Array} Returns the array of symbols.
  5253. */
  5254. var getSymbols = nativeGetSymbols ? overArg(nativeGetSymbols, Object) : stubArray;
  5255. /**
  5256. * Creates an array of the own and inherited enumerable symbol properties
  5257. * of `object`.
  5258. *
  5259. * @private
  5260. * @param {Object} object The object to query.
  5261. * @returns {Array} Returns the array of symbols.
  5262. */
  5263. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5264. var result = [];
  5265. while (object) {
  5266. arrayPush(result, getSymbols(object));
  5267. object = getPrototype(object);
  5268. }
  5269. return result;
  5270. };
  5271. /**
  5272. * Gets the `toStringTag` of `value`.
  5273. *
  5274. * @private
  5275. * @param {*} value The value to query.
  5276. * @returns {string} Returns the `toStringTag`.
  5277. */
  5278. var getTag = baseGetTag;
  5279. // Fallback for data views, maps, sets, and weak maps in IE 11,
  5280. // for data views in Edge < 14, and promises in Node.js.
  5281. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5282. (Map && getTag(new Map) != mapTag) ||
  5283. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5284. (Set && getTag(new Set) != setTag) ||
  5285. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5286. getTag = function(value) {
  5287. var result = objectToString.call(value),
  5288. Ctor = result == objectTag ? value.constructor : undefined,
  5289. ctorString = Ctor ? toSource(Ctor) : undefined;
  5290. if (ctorString) {
  5291. switch (ctorString) {
  5292. case dataViewCtorString: return dataViewTag;
  5293. case mapCtorString: return mapTag;
  5294. case promiseCtorString: return promiseTag;
  5295. case setCtorString: return setTag;
  5296. case weakMapCtorString: return weakMapTag;
  5297. }
  5298. }
  5299. return result;
  5300. };
  5301. }
  5302. /**
  5303. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5304. *
  5305. * @private
  5306. * @param {number} start The start of the view.
  5307. * @param {number} end The end of the view.
  5308. * @param {Array} transforms The transformations to apply to the view.
  5309. * @returns {Object} Returns an object containing the `start` and `end`
  5310. * positions of the view.
  5311. */
  5312. function getView(start, end, transforms) {
  5313. var index = -1,
  5314. length = transforms.length;
  5315. while (++index < length) {
  5316. var data = transforms[index],
  5317. size = data.size;
  5318. switch (data.type) {
  5319. case 'drop': start += size; break;
  5320. case 'dropRight': end -= size; break;
  5321. case 'take': end = nativeMin(end, start + size); break;
  5322. case 'takeRight': start = nativeMax(start, end - size); break;
  5323. }
  5324. }
  5325. return { 'start': start, 'end': end };
  5326. }
  5327. /**
  5328. * Extracts wrapper details from the `source` body comment.
  5329. *
  5330. * @private
  5331. * @param {string} source The source to inspect.
  5332. * @returns {Array} Returns the wrapper details.
  5333. */
  5334. function getWrapDetails(source) {
  5335. var match = source.match(reWrapDetails);
  5336. return match ? match[1].split(reSplitDetails) : [];
  5337. }
  5338. /**
  5339. * Checks if `path` exists on `object`.
  5340. *
  5341. * @private
  5342. * @param {Object} object The object to query.
  5343. * @param {Array|string} path The path to check.
  5344. * @param {Function} hasFunc The function to check properties.
  5345. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5346. */
  5347. function hasPath(object, path, hasFunc) {
  5348. path = isKey(path, object) ? [path] : castPath(path);
  5349. var result,
  5350. index = -1,
  5351. length = path.length;
  5352. while (++index < length) {
  5353. var key = toKey(path[index]);
  5354. if (!(result = object != null && hasFunc(object, key))) {
  5355. break;
  5356. }
  5357. object = object[key];
  5358. }
  5359. if (result) {
  5360. return result;
  5361. }
  5362. var length = object ? object.length : 0;
  5363. return !!length && isLength(length) && isIndex(key, length) &&
  5364. (isArray(object) || isArguments(object));
  5365. }
  5366. /**
  5367. * Initializes an array clone.
  5368. *
  5369. * @private
  5370. * @param {Array} array The array to clone.
  5371. * @returns {Array} Returns the initialized clone.
  5372. */
  5373. function initCloneArray(array) {
  5374. var length = array.length,
  5375. result = array.constructor(length);
  5376. // Add properties assigned by `RegExp#exec`.
  5377. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5378. result.index = array.index;
  5379. result.input = array.input;
  5380. }
  5381. return result;
  5382. }
  5383. /**
  5384. * Initializes an object clone.
  5385. *
  5386. * @private
  5387. * @param {Object} object The object to clone.
  5388. * @returns {Object} Returns the initialized clone.
  5389. */
  5390. function initCloneObject(object) {
  5391. return (typeof object.constructor == 'function' && !isPrototype(object))
  5392. ? baseCreate(getPrototype(object))
  5393. : {};
  5394. }
  5395. /**
  5396. * Initializes an object clone based on its `toStringTag`.
  5397. *
  5398. * **Note:** This function only supports cloning values with tags of
  5399. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5400. *
  5401. * @private
  5402. * @param {Object} object The object to clone.
  5403. * @param {string} tag The `toStringTag` of the object to clone.
  5404. * @param {Function} cloneFunc The function to clone values.
  5405. * @param {boolean} [isDeep] Specify a deep clone.
  5406. * @returns {Object} Returns the initialized clone.
  5407. */
  5408. function initCloneByTag(object, tag, cloneFunc, isDeep) {
  5409. var Ctor = object.constructor;
  5410. switch (tag) {
  5411. case arrayBufferTag:
  5412. return cloneArrayBuffer(object);
  5413. case boolTag:
  5414. case dateTag:
  5415. return new Ctor(+object);
  5416. case dataViewTag:
  5417. return cloneDataView(object, isDeep);
  5418. case float32Tag: case float64Tag:
  5419. case int8Tag: case int16Tag: case int32Tag:
  5420. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5421. return cloneTypedArray(object, isDeep);
  5422. case mapTag:
  5423. return cloneMap(object, isDeep, cloneFunc);
  5424. case numberTag:
  5425. case stringTag:
  5426. return new Ctor(object);
  5427. case regexpTag:
  5428. return cloneRegExp(object);
  5429. case setTag:
  5430. return cloneSet(object, isDeep, cloneFunc);
  5431. case symbolTag:
  5432. return cloneSymbol(object);
  5433. }
  5434. }
  5435. /**
  5436. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5437. *
  5438. * @private
  5439. * @param {string} source The source to modify.
  5440. * @returns {Array} details The details to insert.
  5441. * @returns {string} Returns the modified source.
  5442. */
  5443. function insertWrapDetails(source, details) {
  5444. var length = details.length,
  5445. lastIndex = length - 1;
  5446. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5447. details = details.join(length > 2 ? ', ' : ' ');
  5448. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5449. }
  5450. /**
  5451. * Checks if `value` is a flattenable `arguments` object or array.
  5452. *
  5453. * @private
  5454. * @param {*} value The value to check.
  5455. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5456. */
  5457. function isFlattenable(value) {
  5458. return isArray(value) || isArguments(value) ||
  5459. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5460. }
  5461. /**
  5462. * Checks if `value` is a valid array-like index.
  5463. *
  5464. * @private
  5465. * @param {*} value The value to check.
  5466. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5467. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5468. */
  5469. function isIndex(value, length) {
  5470. length = length == null ? MAX_SAFE_INTEGER : length;
  5471. return !!length &&
  5472. (typeof value == 'number' || reIsUint.test(value)) &&
  5473. (value > -1 && value % 1 == 0 && value < length);
  5474. }
  5475. /**
  5476. * Checks if the given arguments are from an iteratee call.
  5477. *
  5478. * @private
  5479. * @param {*} value The potential iteratee value argument.
  5480. * @param {*} index The potential iteratee index or key argument.
  5481. * @param {*} object The potential iteratee object argument.
  5482. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5483. * else `false`.
  5484. */
  5485. function isIterateeCall(value, index, object) {
  5486. if (!isObject(object)) {
  5487. return false;
  5488. }
  5489. var type = typeof index;
  5490. if (type == 'number'
  5491. ? (isArrayLike(object) && isIndex(index, object.length))
  5492. : (type == 'string' && index in object)
  5493. ) {
  5494. return eq(object[index], value);
  5495. }
  5496. return false;
  5497. }
  5498. /**
  5499. * Checks if `value` is a property name and not a property path.
  5500. *
  5501. * @private
  5502. * @param {*} value The value to check.
  5503. * @param {Object} [object] The object to query keys on.
  5504. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5505. */
  5506. function isKey(value, object) {
  5507. if (isArray(value)) {
  5508. return false;
  5509. }
  5510. var type = typeof value;
  5511. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5512. value == null || isSymbol(value)) {
  5513. return true;
  5514. }
  5515. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5516. (object != null && value in Object(object));
  5517. }
  5518. /**
  5519. * Checks if `value` is suitable for use as unique object key.
  5520. *
  5521. * @private
  5522. * @param {*} value The value to check.
  5523. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5524. */
  5525. function isKeyable(value) {
  5526. var type = typeof value;
  5527. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5528. ? (value !== '__proto__')
  5529. : (value === null);
  5530. }
  5531. /**
  5532. * Checks if `func` has a lazy counterpart.
  5533. *
  5534. * @private
  5535. * @param {Function} func The function to check.
  5536. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5537. * else `false`.
  5538. */
  5539. function isLaziable(func) {
  5540. var funcName = getFuncName(func),
  5541. other = lodash[funcName];
  5542. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5543. return false;
  5544. }
  5545. if (func === other) {
  5546. return true;
  5547. }
  5548. var data = getData(other);
  5549. return !!data && func === data[0];
  5550. }
  5551. /**
  5552. * Checks if `func` has its source masked.
  5553. *
  5554. * @private
  5555. * @param {Function} func The function to check.
  5556. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5557. */
  5558. function isMasked(func) {
  5559. return !!maskSrcKey && (maskSrcKey in func);
  5560. }
  5561. /**
  5562. * Checks if `func` is capable of being masked.
  5563. *
  5564. * @private
  5565. * @param {*} value The value to check.
  5566. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5567. */
  5568. var isMaskable = coreJsData ? isFunction : stubFalse;
  5569. /**
  5570. * Checks if `value` is likely a prototype object.
  5571. *
  5572. * @private
  5573. * @param {*} value The value to check.
  5574. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5575. */
  5576. function isPrototype(value) {
  5577. var Ctor = value && value.constructor,
  5578. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5579. return value === proto;
  5580. }
  5581. /**
  5582. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5583. *
  5584. * @private
  5585. * @param {*} value The value to check.
  5586. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5587. * equality comparisons, else `false`.
  5588. */
  5589. function isStrictComparable(value) {
  5590. return value === value && !isObject(value);
  5591. }
  5592. /**
  5593. * A specialized version of `matchesProperty` for source values suitable
  5594. * for strict equality comparisons, i.e. `===`.
  5595. *
  5596. * @private
  5597. * @param {string} key The key of the property to get.
  5598. * @param {*} srcValue The value to match.
  5599. * @returns {Function} Returns the new spec function.
  5600. */
  5601. function matchesStrictComparable(key, srcValue) {
  5602. return function(object) {
  5603. if (object == null) {
  5604. return false;
  5605. }
  5606. return object[key] === srcValue &&
  5607. (srcValue !== undefined || (key in Object(object)));
  5608. };
  5609. }
  5610. /**
  5611. * Merges the function metadata of `source` into `data`.
  5612. *
  5613. * Merging metadata reduces the number of wrappers used to invoke a function.
  5614. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5615. * may be applied regardless of execution order. Methods like `_.ary` and
  5616. * `_.rearg` modify function arguments, making the order in which they are
  5617. * executed important, preventing the merging of metadata. However, we make
  5618. * an exception for a safe combined case where curried functions have `_.ary`
  5619. * and or `_.rearg` applied.
  5620. *
  5621. * @private
  5622. * @param {Array} data The destination metadata.
  5623. * @param {Array} source The source metadata.
  5624. * @returns {Array} Returns `data`.
  5625. */
  5626. function mergeData(data, source) {
  5627. var bitmask = data[1],
  5628. srcBitmask = source[1],
  5629. newBitmask = bitmask | srcBitmask,
  5630. isCommon = newBitmask < (BIND_FLAG | BIND_KEY_FLAG | ARY_FLAG);
  5631. var isCombo =
  5632. ((srcBitmask == ARY_FLAG) && (bitmask == CURRY_FLAG)) ||
  5633. ((srcBitmask == ARY_FLAG) && (bitmask == REARG_FLAG) && (data[7].length <= source[8])) ||
  5634. ((srcBitmask == (ARY_FLAG | REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == CURRY_FLAG));
  5635. // Exit early if metadata can't be merged.
  5636. if (!(isCommon || isCombo)) {
  5637. return data;
  5638. }
  5639. // Use source `thisArg` if available.
  5640. if (srcBitmask & BIND_FLAG) {
  5641. data[2] = source[2];
  5642. // Set when currying a bound function.
  5643. newBitmask |= bitmask & BIND_FLAG ? 0 : CURRY_BOUND_FLAG;
  5644. }
  5645. // Compose partial arguments.
  5646. var value = source[3];
  5647. if (value) {
  5648. var partials = data[3];
  5649. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5650. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5651. }
  5652. // Compose partial right arguments.
  5653. value = source[5];
  5654. if (value) {
  5655. partials = data[5];
  5656. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5657. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5658. }
  5659. // Use source `argPos` if available.
  5660. value = source[7];
  5661. if (value) {
  5662. data[7] = value;
  5663. }
  5664. // Use source `ary` if it's smaller.
  5665. if (srcBitmask & ARY_FLAG) {
  5666. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5667. }
  5668. // Use source `arity` if one is not provided.
  5669. if (data[9] == null) {
  5670. data[9] = source[9];
  5671. }
  5672. // Use source `func` and merge bitmasks.
  5673. data[0] = source[0];
  5674. data[1] = newBitmask;
  5675. return data;
  5676. }
  5677. /**
  5678. * Used by `_.defaultsDeep` to customize its `_.merge` use.
  5679. *
  5680. * @private
  5681. * @param {*} objValue The destination value.
  5682. * @param {*} srcValue The source value.
  5683. * @param {string} key The key of the property to merge.
  5684. * @param {Object} object The parent object of `objValue`.
  5685. * @param {Object} source The parent object of `srcValue`.
  5686. * @param {Object} [stack] Tracks traversed source values and their merged
  5687. * counterparts.
  5688. * @returns {*} Returns the value to assign.
  5689. */
  5690. function mergeDefaults(objValue, srcValue, key, object, source, stack) {
  5691. if (isObject(objValue) && isObject(srcValue)) {
  5692. // Recursively merge objects and arrays (susceptible to call stack limits).
  5693. stack.set(srcValue, objValue);
  5694. baseMerge(objValue, srcValue, undefined, mergeDefaults, stack);
  5695. stack['delete'](srcValue);
  5696. }
  5697. return objValue;
  5698. }
  5699. /**
  5700. * This function is like
  5701. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  5702. * except that it includes inherited enumerable properties.
  5703. *
  5704. * @private
  5705. * @param {Object} object The object to query.
  5706. * @returns {Array} Returns the array of property names.
  5707. */
  5708. function nativeKeysIn(object) {
  5709. var result = [];
  5710. if (object != null) {
  5711. for (var key in Object(object)) {
  5712. result.push(key);
  5713. }
  5714. }
  5715. return result;
  5716. }
  5717. /**
  5718. * Gets the parent value at `path` of `object`.
  5719. *
  5720. * @private
  5721. * @param {Object} object The object to query.
  5722. * @param {Array} path The path to get the parent value of.
  5723. * @returns {*} Returns the parent value.
  5724. */
  5725. function parent(object, path) {
  5726. return path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  5727. }
  5728. /**
  5729. * Reorder `array` according to the specified indexes where the element at
  5730. * the first index is assigned as the first element, the element at
  5731. * the second index is assigned as the second element, and so on.
  5732. *
  5733. * @private
  5734. * @param {Array} array The array to reorder.
  5735. * @param {Array} indexes The arranged array indexes.
  5736. * @returns {Array} Returns `array`.
  5737. */
  5738. function reorder(array, indexes) {
  5739. var arrLength = array.length,
  5740. length = nativeMin(indexes.length, arrLength),
  5741. oldArray = copyArray(array);
  5742. while (length--) {
  5743. var index = indexes[length];
  5744. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  5745. }
  5746. return array;
  5747. }
  5748. /**
  5749. * Sets metadata for `func`.
  5750. *
  5751. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  5752. * period of time, it will trip its breaker and transition to an identity
  5753. * function to avoid garbage collection pauses in V8. See
  5754. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  5755. * for more details.
  5756. *
  5757. * @private
  5758. * @param {Function} func The function to associate metadata with.
  5759. * @param {*} data The metadata.
  5760. * @returns {Function} Returns `func`.
  5761. */
  5762. var setData = (function() {
  5763. var count = 0,
  5764. lastCalled = 0;
  5765. return function(key, value) {
  5766. var stamp = now(),
  5767. remaining = HOT_SPAN - (stamp - lastCalled);
  5768. lastCalled = stamp;
  5769. if (remaining > 0) {
  5770. if (++count >= HOT_COUNT) {
  5771. return key;
  5772. }
  5773. } else {
  5774. count = 0;
  5775. }
  5776. return baseSetData(key, value);
  5777. };
  5778. }());
  5779. /**
  5780. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  5781. *
  5782. * @private
  5783. * @param {Function} func The function to delay.
  5784. * @param {number} wait The number of milliseconds to delay invocation.
  5785. * @returns {number|Object} Returns the timer id or timeout object.
  5786. */
  5787. var setTimeout = ctxSetTimeout || function(func, wait) {
  5788. return root.setTimeout(func, wait);
  5789. };
  5790. /**
  5791. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  5792. * with wrapper details in a comment at the top of the source body.
  5793. *
  5794. * @private
  5795. * @param {Function} wrapper The function to modify.
  5796. * @param {Function} reference The reference function.
  5797. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  5798. * @returns {Function} Returns `wrapper`.
  5799. */
  5800. var setWrapToString = !defineProperty ? identity : function(wrapper, reference, bitmask) {
  5801. var source = (reference + '');
  5802. return defineProperty(wrapper, 'toString', {
  5803. 'configurable': true,
  5804. 'enumerable': false,
  5805. 'value': constant(insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)))
  5806. });
  5807. };
  5808. /**
  5809. * Converts `string` to a property path array.
  5810. *
  5811. * @private
  5812. * @param {string} string The string to convert.
  5813. * @returns {Array} Returns the property path array.
  5814. */
  5815. var stringToPath = memoize(function(string) {
  5816. string = toString(string);
  5817. var result = [];
  5818. if (reLeadingDot.test(string)) {
  5819. result.push('');
  5820. }
  5821. string.replace(rePropName, function(match, number, quote, string) {
  5822. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  5823. });
  5824. return result;
  5825. });
  5826. /**
  5827. * Converts `value` to a string key if it's not a string or symbol.
  5828. *
  5829. * @private
  5830. * @param {*} value The value to inspect.
  5831. * @returns {string|symbol} Returns the key.
  5832. */
  5833. function toKey(value) {
  5834. if (typeof value == 'string' || isSymbol(value)) {
  5835. return value;
  5836. }
  5837. var result = (value + '');
  5838. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  5839. }
  5840. /**
  5841. * Converts `func` to its source code.
  5842. *
  5843. * @private
  5844. * @param {Function} func The function to process.
  5845. * @returns {string} Returns the source code.
  5846. */
  5847. function toSource(func) {
  5848. if (func != null) {
  5849. try {
  5850. return funcToString.call(func);
  5851. } catch (e) {}
  5852. try {
  5853. return (func + '');
  5854. } catch (e) {}
  5855. }
  5856. return '';
  5857. }
  5858. /**
  5859. * Updates wrapper `details` based on `bitmask` flags.
  5860. *
  5861. * @private
  5862. * @returns {Array} details The details to modify.
  5863. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  5864. * @returns {Array} Returns `details`.
  5865. */
  5866. function updateWrapDetails(details, bitmask) {
  5867. arrayEach(wrapFlags, function(pair) {
  5868. var value = '_.' + pair[0];
  5869. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  5870. details.push(value);
  5871. }
  5872. });
  5873. return details.sort();
  5874. }
  5875. /**
  5876. * Creates a clone of `wrapper`.
  5877. *
  5878. * @private
  5879. * @param {Object} wrapper The wrapper to clone.
  5880. * @returns {Object} Returns the cloned wrapper.
  5881. */
  5882. function wrapperClone(wrapper) {
  5883. if (wrapper instanceof LazyWrapper) {
  5884. return wrapper.clone();
  5885. }
  5886. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  5887. result.__actions__ = copyArray(wrapper.__actions__);
  5888. result.__index__ = wrapper.__index__;
  5889. result.__values__ = wrapper.__values__;
  5890. return result;
  5891. }
  5892. /*------------------------------------------------------------------------*/
  5893. /**
  5894. * Creates an array of elements split into groups the length of `size`.
  5895. * If `array` can't be split evenly, the final chunk will be the remaining
  5896. * elements.
  5897. *
  5898. * @static
  5899. * @memberOf _
  5900. * @since 3.0.0
  5901. * @category Array
  5902. * @param {Array} array The array to process.
  5903. * @param {number} [size=1] The length of each chunk
  5904. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  5905. * @returns {Array} Returns the new array of chunks.
  5906. * @example
  5907. *
  5908. * _.chunk(['a', 'b', 'c', 'd'], 2);
  5909. * // => [['a', 'b'], ['c', 'd']]
  5910. *
  5911. * _.chunk(['a', 'b', 'c', 'd'], 3);
  5912. * // => [['a', 'b', 'c'], ['d']]
  5913. */
  5914. function chunk(array, size, guard) {
  5915. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  5916. size = 1;
  5917. } else {
  5918. size = nativeMax(toInteger(size), 0);
  5919. }
  5920. var length = array ? array.length : 0;
  5921. if (!length || size < 1) {
  5922. return [];
  5923. }
  5924. var index = 0,
  5925. resIndex = 0,
  5926. result = Array(nativeCeil(length / size));
  5927. while (index < length) {
  5928. result[resIndex++] = baseSlice(array, index, (index += size));
  5929. }
  5930. return result;
  5931. }
  5932. /**
  5933. * Creates an array with all falsey values removed. The values `false`, `null`,
  5934. * `0`, `""`, `undefined`, and `NaN` are falsey.
  5935. *
  5936. * @static
  5937. * @memberOf _
  5938. * @since 0.1.0
  5939. * @category Array
  5940. * @param {Array} array The array to compact.
  5941. * @returns {Array} Returns the new array of filtered values.
  5942. * @example
  5943. *
  5944. * _.compact([0, 1, false, 2, '', 3]);
  5945. * // => [1, 2, 3]
  5946. */
  5947. function compact(array) {
  5948. var index = -1,
  5949. length = array ? array.length : 0,
  5950. resIndex = 0,
  5951. result = [];
  5952. while (++index < length) {
  5953. var value = array[index];
  5954. if (value) {
  5955. result[resIndex++] = value;
  5956. }
  5957. }
  5958. return result;
  5959. }
  5960. /**
  5961. * Creates a new array concatenating `array` with any additional arrays
  5962. * and/or values.
  5963. *
  5964. * @static
  5965. * @memberOf _
  5966. * @since 4.0.0
  5967. * @category Array
  5968. * @param {Array} array The array to concatenate.
  5969. * @param {...*} [values] The values to concatenate.
  5970. * @returns {Array} Returns the new concatenated array.
  5971. * @example
  5972. *
  5973. * var array = [1];
  5974. * var other = _.concat(array, 2, [3], [[4]]);
  5975. *
  5976. * console.log(other);
  5977. * // => [1, 2, 3, [4]]
  5978. *
  5979. * console.log(array);
  5980. * // => [1]
  5981. */
  5982. function concat() {
  5983. var length = arguments.length,
  5984. args = Array(length ? length - 1 : 0),
  5985. array = arguments[0],
  5986. index = length;
  5987. while (index--) {
  5988. args[index - 1] = arguments[index];
  5989. }
  5990. return length
  5991. ? arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1))
  5992. : [];
  5993. }
  5994. /**
  5995. * Creates an array of `array` values not included in the other given arrays
  5996. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  5997. * for equality comparisons. The order of result values is determined by the
  5998. * order they occur in the first array.
  5999. *
  6000. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6001. *
  6002. * @static
  6003. * @memberOf _
  6004. * @since 0.1.0
  6005. * @category Array
  6006. * @param {Array} array The array to inspect.
  6007. * @param {...Array} [values] The values to exclude.
  6008. * @returns {Array} Returns the new array of filtered values.
  6009. * @see _.without, _.xor
  6010. * @example
  6011. *
  6012. * _.difference([2, 1], [2, 3]);
  6013. * // => [1]
  6014. */
  6015. var difference = baseRest(function(array, values) {
  6016. return isArrayLikeObject(array)
  6017. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6018. : [];
  6019. });
  6020. /**
  6021. * This method is like `_.difference` except that it accepts `iteratee` which
  6022. * is invoked for each element of `array` and `values` to generate the criterion
  6023. * by which they're compared. Result values are chosen from the first array.
  6024. * The iteratee is invoked with one argument: (value).
  6025. *
  6026. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6027. *
  6028. * @static
  6029. * @memberOf _
  6030. * @since 4.0.0
  6031. * @category Array
  6032. * @param {Array} array The array to inspect.
  6033. * @param {...Array} [values] The values to exclude.
  6034. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6035. * @returns {Array} Returns the new array of filtered values.
  6036. * @example
  6037. *
  6038. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6039. * // => [1.2]
  6040. *
  6041. * // The `_.property` iteratee shorthand.
  6042. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6043. * // => [{ 'x': 2 }]
  6044. */
  6045. var differenceBy = baseRest(function(array, values) {
  6046. var iteratee = last(values);
  6047. if (isArrayLikeObject(iteratee)) {
  6048. iteratee = undefined;
  6049. }
  6050. return isArrayLikeObject(array)
  6051. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6052. : [];
  6053. });
  6054. /**
  6055. * This method is like `_.difference` except that it accepts `comparator`
  6056. * which is invoked to compare elements of `array` to `values`. Result values
  6057. * are chosen from the first array. The comparator is invoked with two arguments:
  6058. * (arrVal, othVal).
  6059. *
  6060. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6061. *
  6062. * @static
  6063. * @memberOf _
  6064. * @since 4.0.0
  6065. * @category Array
  6066. * @param {Array} array The array to inspect.
  6067. * @param {...Array} [values] The values to exclude.
  6068. * @param {Function} [comparator] The comparator invoked per element.
  6069. * @returns {Array} Returns the new array of filtered values.
  6070. * @example
  6071. *
  6072. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6073. *
  6074. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6075. * // => [{ 'x': 2, 'y': 1 }]
  6076. */
  6077. var differenceWith = baseRest(function(array, values) {
  6078. var comparator = last(values);
  6079. if (isArrayLikeObject(comparator)) {
  6080. comparator = undefined;
  6081. }
  6082. return isArrayLikeObject(array)
  6083. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6084. : [];
  6085. });
  6086. /**
  6087. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6088. *
  6089. * @static
  6090. * @memberOf _
  6091. * @since 0.5.0
  6092. * @category Array
  6093. * @param {Array} array The array to query.
  6094. * @param {number} [n=1] The number of elements to drop.
  6095. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6096. * @returns {Array} Returns the slice of `array`.
  6097. * @example
  6098. *
  6099. * _.drop([1, 2, 3]);
  6100. * // => [2, 3]
  6101. *
  6102. * _.drop([1, 2, 3], 2);
  6103. * // => [3]
  6104. *
  6105. * _.drop([1, 2, 3], 5);
  6106. * // => []
  6107. *
  6108. * _.drop([1, 2, 3], 0);
  6109. * // => [1, 2, 3]
  6110. */
  6111. function drop(array, n, guard) {
  6112. var length = array ? array.length : 0;
  6113. if (!length) {
  6114. return [];
  6115. }
  6116. n = (guard || n === undefined) ? 1 : toInteger(n);
  6117. return baseSlice(array, n < 0 ? 0 : n, length);
  6118. }
  6119. /**
  6120. * Creates a slice of `array` with `n` elements dropped from the end.
  6121. *
  6122. * @static
  6123. * @memberOf _
  6124. * @since 3.0.0
  6125. * @category Array
  6126. * @param {Array} array The array to query.
  6127. * @param {number} [n=1] The number of elements to drop.
  6128. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6129. * @returns {Array} Returns the slice of `array`.
  6130. * @example
  6131. *
  6132. * _.dropRight([1, 2, 3]);
  6133. * // => [1, 2]
  6134. *
  6135. * _.dropRight([1, 2, 3], 2);
  6136. * // => [1]
  6137. *
  6138. * _.dropRight([1, 2, 3], 5);
  6139. * // => []
  6140. *
  6141. * _.dropRight([1, 2, 3], 0);
  6142. * // => [1, 2, 3]
  6143. */
  6144. function dropRight(array, n, guard) {
  6145. var length = array ? array.length : 0;
  6146. if (!length) {
  6147. return [];
  6148. }
  6149. n = (guard || n === undefined) ? 1 : toInteger(n);
  6150. n = length - n;
  6151. return baseSlice(array, 0, n < 0 ? 0 : n);
  6152. }
  6153. /**
  6154. * Creates a slice of `array` excluding elements dropped from the end.
  6155. * Elements are dropped until `predicate` returns falsey. The predicate is
  6156. * invoked with three arguments: (value, index, array).
  6157. *
  6158. * @static
  6159. * @memberOf _
  6160. * @since 3.0.0
  6161. * @category Array
  6162. * @param {Array} array The array to query.
  6163. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6164. * @returns {Array} Returns the slice of `array`.
  6165. * @example
  6166. *
  6167. * var users = [
  6168. * { 'user': 'barney', 'active': true },
  6169. * { 'user': 'fred', 'active': false },
  6170. * { 'user': 'pebbles', 'active': false }
  6171. * ];
  6172. *
  6173. * _.dropRightWhile(users, function(o) { return !o.active; });
  6174. * // => objects for ['barney']
  6175. *
  6176. * // The `_.matches` iteratee shorthand.
  6177. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6178. * // => objects for ['barney', 'fred']
  6179. *
  6180. * // The `_.matchesProperty` iteratee shorthand.
  6181. * _.dropRightWhile(users, ['active', false]);
  6182. * // => objects for ['barney']
  6183. *
  6184. * // The `_.property` iteratee shorthand.
  6185. * _.dropRightWhile(users, 'active');
  6186. * // => objects for ['barney', 'fred', 'pebbles']
  6187. */
  6188. function dropRightWhile(array, predicate) {
  6189. return (array && array.length)
  6190. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6191. : [];
  6192. }
  6193. /**
  6194. * Creates a slice of `array` excluding elements dropped from the beginning.
  6195. * Elements are dropped until `predicate` returns falsey. The predicate is
  6196. * invoked with three arguments: (value, index, array).
  6197. *
  6198. * @static
  6199. * @memberOf _
  6200. * @since 3.0.0
  6201. * @category Array
  6202. * @param {Array} array The array to query.
  6203. * @param {Function} [predicate=_.identity]
  6204. * The function invoked per iteration.
  6205. * @returns {Array} Returns the slice of `array`.
  6206. * @example
  6207. *
  6208. * var users = [
  6209. * { 'user': 'barney', 'active': false },
  6210. * { 'user': 'fred', 'active': false },
  6211. * { 'user': 'pebbles', 'active': true }
  6212. * ];
  6213. *
  6214. * _.dropWhile(users, function(o) { return !o.active; });
  6215. * // => objects for ['pebbles']
  6216. *
  6217. * // The `_.matches` iteratee shorthand.
  6218. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6219. * // => objects for ['fred', 'pebbles']
  6220. *
  6221. * // The `_.matchesProperty` iteratee shorthand.
  6222. * _.dropWhile(users, ['active', false]);
  6223. * // => objects for ['pebbles']
  6224. *
  6225. * // The `_.property` iteratee shorthand.
  6226. * _.dropWhile(users, 'active');
  6227. * // => objects for ['barney', 'fred', 'pebbles']
  6228. */
  6229. function dropWhile(array, predicate) {
  6230. return (array && array.length)
  6231. ? baseWhile(array, getIteratee(predicate, 3), true)
  6232. : [];
  6233. }
  6234. /**
  6235. * Fills elements of `array` with `value` from `start` up to, but not
  6236. * including, `end`.
  6237. *
  6238. * **Note:** This method mutates `array`.
  6239. *
  6240. * @static
  6241. * @memberOf _
  6242. * @since 3.2.0
  6243. * @category Array
  6244. * @param {Array} array The array to fill.
  6245. * @param {*} value The value to fill `array` with.
  6246. * @param {number} [start=0] The start position.
  6247. * @param {number} [end=array.length] The end position.
  6248. * @returns {Array} Returns `array`.
  6249. * @example
  6250. *
  6251. * var array = [1, 2, 3];
  6252. *
  6253. * _.fill(array, 'a');
  6254. * console.log(array);
  6255. * // => ['a', 'a', 'a']
  6256. *
  6257. * _.fill(Array(3), 2);
  6258. * // => [2, 2, 2]
  6259. *
  6260. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6261. * // => [4, '*', '*', 10]
  6262. */
  6263. function fill(array, value, start, end) {
  6264. var length = array ? array.length : 0;
  6265. if (!length) {
  6266. return [];
  6267. }
  6268. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6269. start = 0;
  6270. end = length;
  6271. }
  6272. return baseFill(array, value, start, end);
  6273. }
  6274. /**
  6275. * This method is like `_.find` except that it returns the index of the first
  6276. * element `predicate` returns truthy for instead of the element itself.
  6277. *
  6278. * @static
  6279. * @memberOf _
  6280. * @since 1.1.0
  6281. * @category Array
  6282. * @param {Array} array The array to inspect.
  6283. * @param {Function} [predicate=_.identity]
  6284. * The function invoked per iteration.
  6285. * @param {number} [fromIndex=0] The index to search from.
  6286. * @returns {number} Returns the index of the found element, else `-1`.
  6287. * @example
  6288. *
  6289. * var users = [
  6290. * { 'user': 'barney', 'active': false },
  6291. * { 'user': 'fred', 'active': false },
  6292. * { 'user': 'pebbles', 'active': true }
  6293. * ];
  6294. *
  6295. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6296. * // => 0
  6297. *
  6298. * // The `_.matches` iteratee shorthand.
  6299. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6300. * // => 1
  6301. *
  6302. * // The `_.matchesProperty` iteratee shorthand.
  6303. * _.findIndex(users, ['active', false]);
  6304. * // => 0
  6305. *
  6306. * // The `_.property` iteratee shorthand.
  6307. * _.findIndex(users, 'active');
  6308. * // => 2
  6309. */
  6310. function findIndex(array, predicate, fromIndex) {
  6311. var length = array ? array.length : 0;
  6312. if (!length) {
  6313. return -1;
  6314. }
  6315. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6316. if (index < 0) {
  6317. index = nativeMax(length + index, 0);
  6318. }
  6319. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6320. }
  6321. /**
  6322. * This method is like `_.findIndex` except that it iterates over elements
  6323. * of `collection` from right to left.
  6324. *
  6325. * @static
  6326. * @memberOf _
  6327. * @since 2.0.0
  6328. * @category Array
  6329. * @param {Array} array The array to inspect.
  6330. * @param {Function} [predicate=_.identity]
  6331. * The function invoked per iteration.
  6332. * @param {number} [fromIndex=array.length-1] The index to search from.
  6333. * @returns {number} Returns the index of the found element, else `-1`.
  6334. * @example
  6335. *
  6336. * var users = [
  6337. * { 'user': 'barney', 'active': true },
  6338. * { 'user': 'fred', 'active': false },
  6339. * { 'user': 'pebbles', 'active': false }
  6340. * ];
  6341. *
  6342. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6343. * // => 2
  6344. *
  6345. * // The `_.matches` iteratee shorthand.
  6346. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6347. * // => 0
  6348. *
  6349. * // The `_.matchesProperty` iteratee shorthand.
  6350. * _.findLastIndex(users, ['active', false]);
  6351. * // => 2
  6352. *
  6353. * // The `_.property` iteratee shorthand.
  6354. * _.findLastIndex(users, 'active');
  6355. * // => 0
  6356. */
  6357. function findLastIndex(array, predicate, fromIndex) {
  6358. var length = array ? array.length : 0;
  6359. if (!length) {
  6360. return -1;
  6361. }
  6362. var index = length - 1;
  6363. if (fromIndex !== undefined) {
  6364. index = toInteger(fromIndex);
  6365. index = fromIndex < 0
  6366. ? nativeMax(length + index, 0)
  6367. : nativeMin(index, length - 1);
  6368. }
  6369. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6370. }
  6371. /**
  6372. * Flattens `array` a single level deep.
  6373. *
  6374. * @static
  6375. * @memberOf _
  6376. * @since 0.1.0
  6377. * @category Array
  6378. * @param {Array} array The array to flatten.
  6379. * @returns {Array} Returns the new flattened array.
  6380. * @example
  6381. *
  6382. * _.flatten([1, [2, [3, [4]], 5]]);
  6383. * // => [1, 2, [3, [4]], 5]
  6384. */
  6385. function flatten(array) {
  6386. var length = array ? array.length : 0;
  6387. return length ? baseFlatten(array, 1) : [];
  6388. }
  6389. /**
  6390. * Recursively flattens `array`.
  6391. *
  6392. * @static
  6393. * @memberOf _
  6394. * @since 3.0.0
  6395. * @category Array
  6396. * @param {Array} array The array to flatten.
  6397. * @returns {Array} Returns the new flattened array.
  6398. * @example
  6399. *
  6400. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6401. * // => [1, 2, 3, 4, 5]
  6402. */
  6403. function flattenDeep(array) {
  6404. var length = array ? array.length : 0;
  6405. return length ? baseFlatten(array, INFINITY) : [];
  6406. }
  6407. /**
  6408. * Recursively flatten `array` up to `depth` times.
  6409. *
  6410. * @static
  6411. * @memberOf _
  6412. * @since 4.4.0
  6413. * @category Array
  6414. * @param {Array} array The array to flatten.
  6415. * @param {number} [depth=1] The maximum recursion depth.
  6416. * @returns {Array} Returns the new flattened array.
  6417. * @example
  6418. *
  6419. * var array = [1, [2, [3, [4]], 5]];
  6420. *
  6421. * _.flattenDepth(array, 1);
  6422. * // => [1, 2, [3, [4]], 5]
  6423. *
  6424. * _.flattenDepth(array, 2);
  6425. * // => [1, 2, 3, [4], 5]
  6426. */
  6427. function flattenDepth(array, depth) {
  6428. var length = array ? array.length : 0;
  6429. if (!length) {
  6430. return [];
  6431. }
  6432. depth = depth === undefined ? 1 : toInteger(depth);
  6433. return baseFlatten(array, depth);
  6434. }
  6435. /**
  6436. * The inverse of `_.toPairs`; this method returns an object composed
  6437. * from key-value `pairs`.
  6438. *
  6439. * @static
  6440. * @memberOf _
  6441. * @since 4.0.0
  6442. * @category Array
  6443. * @param {Array} pairs The key-value pairs.
  6444. * @returns {Object} Returns the new object.
  6445. * @example
  6446. *
  6447. * _.fromPairs([['a', 1], ['b', 2]]);
  6448. * // => { 'a': 1, 'b': 2 }
  6449. */
  6450. function fromPairs(pairs) {
  6451. var index = -1,
  6452. length = pairs ? pairs.length : 0,
  6453. result = {};
  6454. while (++index < length) {
  6455. var pair = pairs[index];
  6456. result[pair[0]] = pair[1];
  6457. }
  6458. return result;
  6459. }
  6460. /**
  6461. * Gets the first element of `array`.
  6462. *
  6463. * @static
  6464. * @memberOf _
  6465. * @since 0.1.0
  6466. * @alias first
  6467. * @category Array
  6468. * @param {Array} array The array to query.
  6469. * @returns {*} Returns the first element of `array`.
  6470. * @example
  6471. *
  6472. * _.head([1, 2, 3]);
  6473. * // => 1
  6474. *
  6475. * _.head([]);
  6476. * // => undefined
  6477. */
  6478. function head(array) {
  6479. return (array && array.length) ? array[0] : undefined;
  6480. }
  6481. /**
  6482. * Gets the index at which the first occurrence of `value` is found in `array`
  6483. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6484. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6485. * offset from the end of `array`.
  6486. *
  6487. * @static
  6488. * @memberOf _
  6489. * @since 0.1.0
  6490. * @category Array
  6491. * @param {Array} array The array to inspect.
  6492. * @param {*} value The value to search for.
  6493. * @param {number} [fromIndex=0] The index to search from.
  6494. * @returns {number} Returns the index of the matched value, else `-1`.
  6495. * @example
  6496. *
  6497. * _.indexOf([1, 2, 1, 2], 2);
  6498. * // => 1
  6499. *
  6500. * // Search from the `fromIndex`.
  6501. * _.indexOf([1, 2, 1, 2], 2, 2);
  6502. * // => 3
  6503. */
  6504. function indexOf(array, value, fromIndex) {
  6505. var length = array ? array.length : 0;
  6506. if (!length) {
  6507. return -1;
  6508. }
  6509. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6510. if (index < 0) {
  6511. index = nativeMax(length + index, 0);
  6512. }
  6513. return baseIndexOf(array, value, index);
  6514. }
  6515. /**
  6516. * Gets all but the last element of `array`.
  6517. *
  6518. * @static
  6519. * @memberOf _
  6520. * @since 0.1.0
  6521. * @category Array
  6522. * @param {Array} array The array to query.
  6523. * @returns {Array} Returns the slice of `array`.
  6524. * @example
  6525. *
  6526. * _.initial([1, 2, 3]);
  6527. * // => [1, 2]
  6528. */
  6529. function initial(array) {
  6530. var length = array ? array.length : 0;
  6531. return length ? baseSlice(array, 0, -1) : [];
  6532. }
  6533. /**
  6534. * Creates an array of unique values that are included in all given arrays
  6535. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6536. * for equality comparisons. The order of result values is determined by the
  6537. * order they occur in the first array.
  6538. *
  6539. * @static
  6540. * @memberOf _
  6541. * @since 0.1.0
  6542. * @category Array
  6543. * @param {...Array} [arrays] The arrays to inspect.
  6544. * @returns {Array} Returns the new array of intersecting values.
  6545. * @example
  6546. *
  6547. * _.intersection([2, 1], [2, 3]);
  6548. * // => [2]
  6549. */
  6550. var intersection = baseRest(function(arrays) {
  6551. var mapped = arrayMap(arrays, castArrayLikeObject);
  6552. return (mapped.length && mapped[0] === arrays[0])
  6553. ? baseIntersection(mapped)
  6554. : [];
  6555. });
  6556. /**
  6557. * This method is like `_.intersection` except that it accepts `iteratee`
  6558. * which is invoked for each element of each `arrays` to generate the criterion
  6559. * by which they're compared. Result values are chosen from the first array.
  6560. * The iteratee is invoked with one argument: (value).
  6561. *
  6562. * @static
  6563. * @memberOf _
  6564. * @since 4.0.0
  6565. * @category Array
  6566. * @param {...Array} [arrays] The arrays to inspect.
  6567. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6568. * @returns {Array} Returns the new array of intersecting values.
  6569. * @example
  6570. *
  6571. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6572. * // => [2.1]
  6573. *
  6574. * // The `_.property` iteratee shorthand.
  6575. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6576. * // => [{ 'x': 1 }]
  6577. */
  6578. var intersectionBy = baseRest(function(arrays) {
  6579. var iteratee = last(arrays),
  6580. mapped = arrayMap(arrays, castArrayLikeObject);
  6581. if (iteratee === last(mapped)) {
  6582. iteratee = undefined;
  6583. } else {
  6584. mapped.pop();
  6585. }
  6586. return (mapped.length && mapped[0] === arrays[0])
  6587. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6588. : [];
  6589. });
  6590. /**
  6591. * This method is like `_.intersection` except that it accepts `comparator`
  6592. * which is invoked to compare elements of `arrays`. Result values are chosen
  6593. * from the first array. The comparator is invoked with two arguments:
  6594. * (arrVal, othVal).
  6595. *
  6596. * @static
  6597. * @memberOf _
  6598. * @since 4.0.0
  6599. * @category Array
  6600. * @param {...Array} [arrays] The arrays to inspect.
  6601. * @param {Function} [comparator] The comparator invoked per element.
  6602. * @returns {Array} Returns the new array of intersecting values.
  6603. * @example
  6604. *
  6605. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6606. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  6607. *
  6608. * _.intersectionWith(objects, others, _.isEqual);
  6609. * // => [{ 'x': 1, 'y': 2 }]
  6610. */
  6611. var intersectionWith = baseRest(function(arrays) {
  6612. var comparator = last(arrays),
  6613. mapped = arrayMap(arrays, castArrayLikeObject);
  6614. if (comparator === last(mapped)) {
  6615. comparator = undefined;
  6616. } else {
  6617. mapped.pop();
  6618. }
  6619. return (mapped.length && mapped[0] === arrays[0])
  6620. ? baseIntersection(mapped, undefined, comparator)
  6621. : [];
  6622. });
  6623. /**
  6624. * Converts all elements in `array` into a string separated by `separator`.
  6625. *
  6626. * @static
  6627. * @memberOf _
  6628. * @since 4.0.0
  6629. * @category Array
  6630. * @param {Array} array The array to convert.
  6631. * @param {string} [separator=','] The element separator.
  6632. * @returns {string} Returns the joined string.
  6633. * @example
  6634. *
  6635. * _.join(['a', 'b', 'c'], '~');
  6636. * // => 'a~b~c'
  6637. */
  6638. function join(array, separator) {
  6639. return array ? nativeJoin.call(array, separator) : '';
  6640. }
  6641. /**
  6642. * Gets the last element of `array`.
  6643. *
  6644. * @static
  6645. * @memberOf _
  6646. * @since 0.1.0
  6647. * @category Array
  6648. * @param {Array} array The array to query.
  6649. * @returns {*} Returns the last element of `array`.
  6650. * @example
  6651. *
  6652. * _.last([1, 2, 3]);
  6653. * // => 3
  6654. */
  6655. function last(array) {
  6656. var length = array ? array.length : 0;
  6657. return length ? array[length - 1] : undefined;
  6658. }
  6659. /**
  6660. * This method is like `_.indexOf` except that it iterates over elements of
  6661. * `array` from right to left.
  6662. *
  6663. * @static
  6664. * @memberOf _
  6665. * @since 0.1.0
  6666. * @category Array
  6667. * @param {Array} array The array to inspect.
  6668. * @param {*} value The value to search for.
  6669. * @param {number} [fromIndex=array.length-1] The index to search from.
  6670. * @returns {number} Returns the index of the matched value, else `-1`.
  6671. * @example
  6672. *
  6673. * _.lastIndexOf([1, 2, 1, 2], 2);
  6674. * // => 3
  6675. *
  6676. * // Search from the `fromIndex`.
  6677. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  6678. * // => 1
  6679. */
  6680. function lastIndexOf(array, value, fromIndex) {
  6681. var length = array ? array.length : 0;
  6682. if (!length) {
  6683. return -1;
  6684. }
  6685. var index = length;
  6686. if (fromIndex !== undefined) {
  6687. index = toInteger(fromIndex);
  6688. index = (
  6689. index < 0
  6690. ? nativeMax(length + index, 0)
  6691. : nativeMin(index, length - 1)
  6692. ) + 1;
  6693. }
  6694. if (value !== value) {
  6695. return baseFindIndex(array, baseIsNaN, index - 1, true);
  6696. }
  6697. while (index--) {
  6698. if (array[index] === value) {
  6699. return index;
  6700. }
  6701. }
  6702. return -1;
  6703. }
  6704. /**
  6705. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  6706. * element from the end is returned.
  6707. *
  6708. * @static
  6709. * @memberOf _
  6710. * @since 4.11.0
  6711. * @category Array
  6712. * @param {Array} array The array to query.
  6713. * @param {number} [n=0] The index of the element to return.
  6714. * @returns {*} Returns the nth element of `array`.
  6715. * @example
  6716. *
  6717. * var array = ['a', 'b', 'c', 'd'];
  6718. *
  6719. * _.nth(array, 1);
  6720. * // => 'b'
  6721. *
  6722. * _.nth(array, -2);
  6723. * // => 'c';
  6724. */
  6725. function nth(array, n) {
  6726. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  6727. }
  6728. /**
  6729. * Removes all given values from `array` using
  6730. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6731. * for equality comparisons.
  6732. *
  6733. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  6734. * to remove elements from an array by predicate.
  6735. *
  6736. * @static
  6737. * @memberOf _
  6738. * @since 2.0.0
  6739. * @category Array
  6740. * @param {Array} array The array to modify.
  6741. * @param {...*} [values] The values to remove.
  6742. * @returns {Array} Returns `array`.
  6743. * @example
  6744. *
  6745. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  6746. *
  6747. * _.pull(array, 'a', 'c');
  6748. * console.log(array);
  6749. * // => ['b', 'b']
  6750. */
  6751. var pull = baseRest(pullAll);
  6752. /**
  6753. * This method is like `_.pull` except that it accepts an array of values to remove.
  6754. *
  6755. * **Note:** Unlike `_.difference`, this method mutates `array`.
  6756. *
  6757. * @static
  6758. * @memberOf _
  6759. * @since 4.0.0
  6760. * @category Array
  6761. * @param {Array} array The array to modify.
  6762. * @param {Array} values The values to remove.
  6763. * @returns {Array} Returns `array`.
  6764. * @example
  6765. *
  6766. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  6767. *
  6768. * _.pullAll(array, ['a', 'c']);
  6769. * console.log(array);
  6770. * // => ['b', 'b']
  6771. */
  6772. function pullAll(array, values) {
  6773. return (array && array.length && values && values.length)
  6774. ? basePullAll(array, values)
  6775. : array;
  6776. }
  6777. /**
  6778. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  6779. * invoked for each element of `array` and `values` to generate the criterion
  6780. * by which they're compared. The iteratee is invoked with one argument: (value).
  6781. *
  6782. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  6783. *
  6784. * @static
  6785. * @memberOf _
  6786. * @since 4.0.0
  6787. * @category Array
  6788. * @param {Array} array The array to modify.
  6789. * @param {Array} values The values to remove.
  6790. * @param {Function} [iteratee=_.identity]
  6791. * The iteratee invoked per element.
  6792. * @returns {Array} Returns `array`.
  6793. * @example
  6794. *
  6795. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  6796. *
  6797. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  6798. * console.log(array);
  6799. * // => [{ 'x': 2 }]
  6800. */
  6801. function pullAllBy(array, values, iteratee) {
  6802. return (array && array.length && values && values.length)
  6803. ? basePullAll(array, values, getIteratee(iteratee, 2))
  6804. : array;
  6805. }
  6806. /**
  6807. * This method is like `_.pullAll` except that it accepts `comparator` which
  6808. * is invoked to compare elements of `array` to `values`. The comparator is
  6809. * invoked with two arguments: (arrVal, othVal).
  6810. *
  6811. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  6812. *
  6813. * @static
  6814. * @memberOf _
  6815. * @since 4.6.0
  6816. * @category Array
  6817. * @param {Array} array The array to modify.
  6818. * @param {Array} values The values to remove.
  6819. * @param {Function} [comparator] The comparator invoked per element.
  6820. * @returns {Array} Returns `array`.
  6821. * @example
  6822. *
  6823. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  6824. *
  6825. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  6826. * console.log(array);
  6827. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  6828. */
  6829. function pullAllWith(array, values, comparator) {
  6830. return (array && array.length && values && values.length)
  6831. ? basePullAll(array, values, undefined, comparator)
  6832. : array;
  6833. }
  6834. /**
  6835. * Removes elements from `array` corresponding to `indexes` and returns an
  6836. * array of removed elements.
  6837. *
  6838. * **Note:** Unlike `_.at`, this method mutates `array`.
  6839. *
  6840. * @static
  6841. * @memberOf _
  6842. * @since 3.0.0
  6843. * @category Array
  6844. * @param {Array} array The array to modify.
  6845. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  6846. * @returns {Array} Returns the new array of removed elements.
  6847. * @example
  6848. *
  6849. * var array = ['a', 'b', 'c', 'd'];
  6850. * var pulled = _.pullAt(array, [1, 3]);
  6851. *
  6852. * console.log(array);
  6853. * // => ['a', 'c']
  6854. *
  6855. * console.log(pulled);
  6856. * // => ['b', 'd']
  6857. */
  6858. var pullAt = baseRest(function(array, indexes) {
  6859. indexes = baseFlatten(indexes, 1);
  6860. var length = array ? array.length : 0,
  6861. result = baseAt(array, indexes);
  6862. basePullAt(array, arrayMap(indexes, function(index) {
  6863. return isIndex(index, length) ? +index : index;
  6864. }).sort(compareAscending));
  6865. return result;
  6866. });
  6867. /**
  6868. * Removes all elements from `array` that `predicate` returns truthy for
  6869. * and returns an array of the removed elements. The predicate is invoked
  6870. * with three arguments: (value, index, array).
  6871. *
  6872. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  6873. * to pull elements from an array by value.
  6874. *
  6875. * @static
  6876. * @memberOf _
  6877. * @since 2.0.0
  6878. * @category Array
  6879. * @param {Array} array The array to modify.
  6880. * @param {Function} [predicate=_.identity]
  6881. * The function invoked per iteration.
  6882. * @returns {Array} Returns the new array of removed elements.
  6883. * @example
  6884. *
  6885. * var array = [1, 2, 3, 4];
  6886. * var evens = _.remove(array, function(n) {
  6887. * return n % 2 == 0;
  6888. * });
  6889. *
  6890. * console.log(array);
  6891. * // => [1, 3]
  6892. *
  6893. * console.log(evens);
  6894. * // => [2, 4]
  6895. */
  6896. function remove(array, predicate) {
  6897. var result = [];
  6898. if (!(array && array.length)) {
  6899. return result;
  6900. }
  6901. var index = -1,
  6902. indexes = [],
  6903. length = array.length;
  6904. predicate = getIteratee(predicate, 3);
  6905. while (++index < length) {
  6906. var value = array[index];
  6907. if (predicate(value, index, array)) {
  6908. result.push(value);
  6909. indexes.push(index);
  6910. }
  6911. }
  6912. basePullAt(array, indexes);
  6913. return result;
  6914. }
  6915. /**
  6916. * Reverses `array` so that the first element becomes the last, the second
  6917. * element becomes the second to last, and so on.
  6918. *
  6919. * **Note:** This method mutates `array` and is based on
  6920. * [`Array#reverse`](https://mdn.io/Array/reverse).
  6921. *
  6922. * @static
  6923. * @memberOf _
  6924. * @since 4.0.0
  6925. * @category Array
  6926. * @param {Array} array The array to modify.
  6927. * @returns {Array} Returns `array`.
  6928. * @example
  6929. *
  6930. * var array = [1, 2, 3];
  6931. *
  6932. * _.reverse(array);
  6933. * // => [3, 2, 1]
  6934. *
  6935. * console.log(array);
  6936. * // => [3, 2, 1]
  6937. */
  6938. function reverse(array) {
  6939. return array ? nativeReverse.call(array) : array;
  6940. }
  6941. /**
  6942. * Creates a slice of `array` from `start` up to, but not including, `end`.
  6943. *
  6944. * **Note:** This method is used instead of
  6945. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  6946. * returned.
  6947. *
  6948. * @static
  6949. * @memberOf _
  6950. * @since 3.0.0
  6951. * @category Array
  6952. * @param {Array} array The array to slice.
  6953. * @param {number} [start=0] The start position.
  6954. * @param {number} [end=array.length] The end position.
  6955. * @returns {Array} Returns the slice of `array`.
  6956. */
  6957. function slice(array, start, end) {
  6958. var length = array ? array.length : 0;
  6959. if (!length) {
  6960. return [];
  6961. }
  6962. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  6963. start = 0;
  6964. end = length;
  6965. }
  6966. else {
  6967. start = start == null ? 0 : toInteger(start);
  6968. end = end === undefined ? length : toInteger(end);
  6969. }
  6970. return baseSlice(array, start, end);
  6971. }
  6972. /**
  6973. * Uses a binary search to determine the lowest index at which `value`
  6974. * should be inserted into `array` in order to maintain its sort order.
  6975. *
  6976. * @static
  6977. * @memberOf _
  6978. * @since 0.1.0
  6979. * @category Array
  6980. * @param {Array} array The sorted array to inspect.
  6981. * @param {*} value The value to evaluate.
  6982. * @returns {number} Returns the index at which `value` should be inserted
  6983. * into `array`.
  6984. * @example
  6985. *
  6986. * _.sortedIndex([30, 50], 40);
  6987. * // => 1
  6988. */
  6989. function sortedIndex(array, value) {
  6990. return baseSortedIndex(array, value);
  6991. }
  6992. /**
  6993. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  6994. * which is invoked for `value` and each element of `array` to compute their
  6995. * sort ranking. The iteratee is invoked with one argument: (value).
  6996. *
  6997. * @static
  6998. * @memberOf _
  6999. * @since 4.0.0
  7000. * @category Array
  7001. * @param {Array} array The sorted array to inspect.
  7002. * @param {*} value The value to evaluate.
  7003. * @param {Function} [iteratee=_.identity]
  7004. * The iteratee invoked per element.
  7005. * @returns {number} Returns the index at which `value` should be inserted
  7006. * into `array`.
  7007. * @example
  7008. *
  7009. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7010. *
  7011. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7012. * // => 0
  7013. *
  7014. * // The `_.property` iteratee shorthand.
  7015. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7016. * // => 0
  7017. */
  7018. function sortedIndexBy(array, value, iteratee) {
  7019. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7020. }
  7021. /**
  7022. * This method is like `_.indexOf` except that it performs a binary
  7023. * search on a sorted `array`.
  7024. *
  7025. * @static
  7026. * @memberOf _
  7027. * @since 4.0.0
  7028. * @category Array
  7029. * @param {Array} array The array to inspect.
  7030. * @param {*} value The value to search for.
  7031. * @returns {number} Returns the index of the matched value, else `-1`.
  7032. * @example
  7033. *
  7034. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7035. * // => 1
  7036. */
  7037. function sortedIndexOf(array, value) {
  7038. var length = array ? array.length : 0;
  7039. if (length) {
  7040. var index = baseSortedIndex(array, value);
  7041. if (index < length && eq(array[index], value)) {
  7042. return index;
  7043. }
  7044. }
  7045. return -1;
  7046. }
  7047. /**
  7048. * This method is like `_.sortedIndex` except that it returns the highest
  7049. * index at which `value` should be inserted into `array` in order to
  7050. * maintain its sort order.
  7051. *
  7052. * @static
  7053. * @memberOf _
  7054. * @since 3.0.0
  7055. * @category Array
  7056. * @param {Array} array The sorted array to inspect.
  7057. * @param {*} value The value to evaluate.
  7058. * @returns {number} Returns the index at which `value` should be inserted
  7059. * into `array`.
  7060. * @example
  7061. *
  7062. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7063. * // => 4
  7064. */
  7065. function sortedLastIndex(array, value) {
  7066. return baseSortedIndex(array, value, true);
  7067. }
  7068. /**
  7069. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7070. * which is invoked for `value` and each element of `array` to compute their
  7071. * sort ranking. The iteratee is invoked with one argument: (value).
  7072. *
  7073. * @static
  7074. * @memberOf _
  7075. * @since 4.0.0
  7076. * @category Array
  7077. * @param {Array} array The sorted array to inspect.
  7078. * @param {*} value The value to evaluate.
  7079. * @param {Function} [iteratee=_.identity]
  7080. * The iteratee invoked per element.
  7081. * @returns {number} Returns the index at which `value` should be inserted
  7082. * into `array`.
  7083. * @example
  7084. *
  7085. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7086. *
  7087. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7088. * // => 1
  7089. *
  7090. * // The `_.property` iteratee shorthand.
  7091. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7092. * // => 1
  7093. */
  7094. function sortedLastIndexBy(array, value, iteratee) {
  7095. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7096. }
  7097. /**
  7098. * This method is like `_.lastIndexOf` except that it performs a binary
  7099. * search on a sorted `array`.
  7100. *
  7101. * @static
  7102. * @memberOf _
  7103. * @since 4.0.0
  7104. * @category Array
  7105. * @param {Array} array The array to inspect.
  7106. * @param {*} value The value to search for.
  7107. * @returns {number} Returns the index of the matched value, else `-1`.
  7108. * @example
  7109. *
  7110. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7111. * // => 3
  7112. */
  7113. function sortedLastIndexOf(array, value) {
  7114. var length = array ? array.length : 0;
  7115. if (length) {
  7116. var index = baseSortedIndex(array, value, true) - 1;
  7117. if (eq(array[index], value)) {
  7118. return index;
  7119. }
  7120. }
  7121. return -1;
  7122. }
  7123. /**
  7124. * This method is like `_.uniq` except that it's designed and optimized
  7125. * for sorted arrays.
  7126. *
  7127. * @static
  7128. * @memberOf _
  7129. * @since 4.0.0
  7130. * @category Array
  7131. * @param {Array} array The array to inspect.
  7132. * @returns {Array} Returns the new duplicate free array.
  7133. * @example
  7134. *
  7135. * _.sortedUniq([1, 1, 2]);
  7136. * // => [1, 2]
  7137. */
  7138. function sortedUniq(array) {
  7139. return (array && array.length)
  7140. ? baseSortedUniq(array)
  7141. : [];
  7142. }
  7143. /**
  7144. * This method is like `_.uniqBy` except that it's designed and optimized
  7145. * for sorted arrays.
  7146. *
  7147. * @static
  7148. * @memberOf _
  7149. * @since 4.0.0
  7150. * @category Array
  7151. * @param {Array} array The array to inspect.
  7152. * @param {Function} [iteratee] The iteratee invoked per element.
  7153. * @returns {Array} Returns the new duplicate free array.
  7154. * @example
  7155. *
  7156. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7157. * // => [1.1, 2.3]
  7158. */
  7159. function sortedUniqBy(array, iteratee) {
  7160. return (array && array.length)
  7161. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7162. : [];
  7163. }
  7164. /**
  7165. * Gets all but the first element of `array`.
  7166. *
  7167. * @static
  7168. * @memberOf _
  7169. * @since 4.0.0
  7170. * @category Array
  7171. * @param {Array} array The array to query.
  7172. * @returns {Array} Returns the slice of `array`.
  7173. * @example
  7174. *
  7175. * _.tail([1, 2, 3]);
  7176. * // => [2, 3]
  7177. */
  7178. function tail(array) {
  7179. var length = array ? array.length : 0;
  7180. return length ? baseSlice(array, 1, length) : [];
  7181. }
  7182. /**
  7183. * Creates a slice of `array` with `n` elements taken from the beginning.
  7184. *
  7185. * @static
  7186. * @memberOf _
  7187. * @since 0.1.0
  7188. * @category Array
  7189. * @param {Array} array The array to query.
  7190. * @param {number} [n=1] The number of elements to take.
  7191. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7192. * @returns {Array} Returns the slice of `array`.
  7193. * @example
  7194. *
  7195. * _.take([1, 2, 3]);
  7196. * // => [1]
  7197. *
  7198. * _.take([1, 2, 3], 2);
  7199. * // => [1, 2]
  7200. *
  7201. * _.take([1, 2, 3], 5);
  7202. * // => [1, 2, 3]
  7203. *
  7204. * _.take([1, 2, 3], 0);
  7205. * // => []
  7206. */
  7207. function take(array, n, guard) {
  7208. if (!(array && array.length)) {
  7209. return [];
  7210. }
  7211. n = (guard || n === undefined) ? 1 : toInteger(n);
  7212. return baseSlice(array, 0, n < 0 ? 0 : n);
  7213. }
  7214. /**
  7215. * Creates a slice of `array` with `n` elements taken from the end.
  7216. *
  7217. * @static
  7218. * @memberOf _
  7219. * @since 3.0.0
  7220. * @category Array
  7221. * @param {Array} array The array to query.
  7222. * @param {number} [n=1] The number of elements to take.
  7223. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7224. * @returns {Array} Returns the slice of `array`.
  7225. * @example
  7226. *
  7227. * _.takeRight([1, 2, 3]);
  7228. * // => [3]
  7229. *
  7230. * _.takeRight([1, 2, 3], 2);
  7231. * // => [2, 3]
  7232. *
  7233. * _.takeRight([1, 2, 3], 5);
  7234. * // => [1, 2, 3]
  7235. *
  7236. * _.takeRight([1, 2, 3], 0);
  7237. * // => []
  7238. */
  7239. function takeRight(array, n, guard) {
  7240. var length = array ? array.length : 0;
  7241. if (!length) {
  7242. return [];
  7243. }
  7244. n = (guard || n === undefined) ? 1 : toInteger(n);
  7245. n = length - n;
  7246. return baseSlice(array, n < 0 ? 0 : n, length);
  7247. }
  7248. /**
  7249. * Creates a slice of `array` with elements taken from the end. Elements are
  7250. * taken until `predicate` returns falsey. The predicate is invoked with
  7251. * three arguments: (value, index, array).
  7252. *
  7253. * @static
  7254. * @memberOf _
  7255. * @since 3.0.0
  7256. * @category Array
  7257. * @param {Array} array The array to query.
  7258. * @param {Function} [predicate=_.identity]
  7259. * The function invoked per iteration.
  7260. * @returns {Array} Returns the slice of `array`.
  7261. * @example
  7262. *
  7263. * var users = [
  7264. * { 'user': 'barney', 'active': true },
  7265. * { 'user': 'fred', 'active': false },
  7266. * { 'user': 'pebbles', 'active': false }
  7267. * ];
  7268. *
  7269. * _.takeRightWhile(users, function(o) { return !o.active; });
  7270. * // => objects for ['fred', 'pebbles']
  7271. *
  7272. * // The `_.matches` iteratee shorthand.
  7273. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7274. * // => objects for ['pebbles']
  7275. *
  7276. * // The `_.matchesProperty` iteratee shorthand.
  7277. * _.takeRightWhile(users, ['active', false]);
  7278. * // => objects for ['fred', 'pebbles']
  7279. *
  7280. * // The `_.property` iteratee shorthand.
  7281. * _.takeRightWhile(users, 'active');
  7282. * // => []
  7283. */
  7284. function takeRightWhile(array, predicate) {
  7285. return (array && array.length)
  7286. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7287. : [];
  7288. }
  7289. /**
  7290. * Creates a slice of `array` with elements taken from the beginning. Elements
  7291. * are taken until `predicate` returns falsey. The predicate is invoked with
  7292. * three arguments: (value, index, array).
  7293. *
  7294. * @static
  7295. * @memberOf _
  7296. * @since 3.0.0
  7297. * @category Array
  7298. * @param {Array} array The array to query.
  7299. * @param {Function} [predicate=_.identity]
  7300. * The function invoked per iteration.
  7301. * @returns {Array} Returns the slice of `array`.
  7302. * @example
  7303. *
  7304. * var users = [
  7305. * { 'user': 'barney', 'active': false },
  7306. * { 'user': 'fred', 'active': false},
  7307. * { 'user': 'pebbles', 'active': true }
  7308. * ];
  7309. *
  7310. * _.takeWhile(users, function(o) { return !o.active; });
  7311. * // => objects for ['barney', 'fred']
  7312. *
  7313. * // The `_.matches` iteratee shorthand.
  7314. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7315. * // => objects for ['barney']
  7316. *
  7317. * // The `_.matchesProperty` iteratee shorthand.
  7318. * _.takeWhile(users, ['active', false]);
  7319. * // => objects for ['barney', 'fred']
  7320. *
  7321. * // The `_.property` iteratee shorthand.
  7322. * _.takeWhile(users, 'active');
  7323. * // => []
  7324. */
  7325. function takeWhile(array, predicate) {
  7326. return (array && array.length)
  7327. ? baseWhile(array, getIteratee(predicate, 3))
  7328. : [];
  7329. }
  7330. /**
  7331. * Creates an array of unique values, in order, from all given arrays using
  7332. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7333. * for equality comparisons.
  7334. *
  7335. * @static
  7336. * @memberOf _
  7337. * @since 0.1.0
  7338. * @category Array
  7339. * @param {...Array} [arrays] The arrays to inspect.
  7340. * @returns {Array} Returns the new array of combined values.
  7341. * @example
  7342. *
  7343. * _.union([2], [1, 2]);
  7344. * // => [2, 1]
  7345. */
  7346. var union = baseRest(function(arrays) {
  7347. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7348. });
  7349. /**
  7350. * This method is like `_.union` except that it accepts `iteratee` which is
  7351. * invoked for each element of each `arrays` to generate the criterion by
  7352. * which uniqueness is computed. Result values are chosen from the first
  7353. * array in which the value occurs. The iteratee is invoked with one argument:
  7354. * (value).
  7355. *
  7356. * @static
  7357. * @memberOf _
  7358. * @since 4.0.0
  7359. * @category Array
  7360. * @param {...Array} [arrays] The arrays to inspect.
  7361. * @param {Function} [iteratee=_.identity]
  7362. * The iteratee invoked per element.
  7363. * @returns {Array} Returns the new array of combined values.
  7364. * @example
  7365. *
  7366. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7367. * // => [2.1, 1.2]
  7368. *
  7369. * // The `_.property` iteratee shorthand.
  7370. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7371. * // => [{ 'x': 1 }, { 'x': 2 }]
  7372. */
  7373. var unionBy = baseRest(function(arrays) {
  7374. var iteratee = last(arrays);
  7375. if (isArrayLikeObject(iteratee)) {
  7376. iteratee = undefined;
  7377. }
  7378. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7379. });
  7380. /**
  7381. * This method is like `_.union` except that it accepts `comparator` which
  7382. * is invoked to compare elements of `arrays`. Result values are chosen from
  7383. * the first array in which the value occurs. The comparator is invoked
  7384. * with two arguments: (arrVal, othVal).
  7385. *
  7386. * @static
  7387. * @memberOf _
  7388. * @since 4.0.0
  7389. * @category Array
  7390. * @param {...Array} [arrays] The arrays to inspect.
  7391. * @param {Function} [comparator] The comparator invoked per element.
  7392. * @returns {Array} Returns the new array of combined values.
  7393. * @example
  7394. *
  7395. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7396. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7397. *
  7398. * _.unionWith(objects, others, _.isEqual);
  7399. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7400. */
  7401. var unionWith = baseRest(function(arrays) {
  7402. var comparator = last(arrays);
  7403. if (isArrayLikeObject(comparator)) {
  7404. comparator = undefined;
  7405. }
  7406. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7407. });
  7408. /**
  7409. * Creates a duplicate-free version of an array, using
  7410. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7411. * for equality comparisons, in which only the first occurrence of each
  7412. * element is kept.
  7413. *
  7414. * @static
  7415. * @memberOf _
  7416. * @since 0.1.0
  7417. * @category Array
  7418. * @param {Array} array The array to inspect.
  7419. * @returns {Array} Returns the new duplicate free array.
  7420. * @example
  7421. *
  7422. * _.uniq([2, 1, 2]);
  7423. * // => [2, 1]
  7424. */
  7425. function uniq(array) {
  7426. return (array && array.length)
  7427. ? baseUniq(array)
  7428. : [];
  7429. }
  7430. /**
  7431. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7432. * invoked for each element in `array` to generate the criterion by which
  7433. * uniqueness is computed. The iteratee is invoked with one argument: (value).
  7434. *
  7435. * @static
  7436. * @memberOf _
  7437. * @since 4.0.0
  7438. * @category Array
  7439. * @param {Array} array The array to inspect.
  7440. * @param {Function} [iteratee=_.identity]
  7441. * The iteratee invoked per element.
  7442. * @returns {Array} Returns the new duplicate free array.
  7443. * @example
  7444. *
  7445. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7446. * // => [2.1, 1.2]
  7447. *
  7448. * // The `_.property` iteratee shorthand.
  7449. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7450. * // => [{ 'x': 1 }, { 'x': 2 }]
  7451. */
  7452. function uniqBy(array, iteratee) {
  7453. return (array && array.length)
  7454. ? baseUniq(array, getIteratee(iteratee, 2))
  7455. : [];
  7456. }
  7457. /**
  7458. * This method is like `_.uniq` except that it accepts `comparator` which
  7459. * is invoked to compare elements of `array`. The comparator is invoked with
  7460. * two arguments: (arrVal, othVal).
  7461. *
  7462. * @static
  7463. * @memberOf _
  7464. * @since 4.0.0
  7465. * @category Array
  7466. * @param {Array} array The array to inspect.
  7467. * @param {Function} [comparator] The comparator invoked per element.
  7468. * @returns {Array} Returns the new duplicate free array.
  7469. * @example
  7470. *
  7471. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7472. *
  7473. * _.uniqWith(objects, _.isEqual);
  7474. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7475. */
  7476. function uniqWith(array, comparator) {
  7477. return (array && array.length)
  7478. ? baseUniq(array, undefined, comparator)
  7479. : [];
  7480. }
  7481. /**
  7482. * This method is like `_.zip` except that it accepts an array of grouped
  7483. * elements and creates an array regrouping the elements to their pre-zip
  7484. * configuration.
  7485. *
  7486. * @static
  7487. * @memberOf _
  7488. * @since 1.2.0
  7489. * @category Array
  7490. * @param {Array} array The array of grouped elements to process.
  7491. * @returns {Array} Returns the new array of regrouped elements.
  7492. * @example
  7493. *
  7494. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7495. * // => [['a', 1, true], ['b', 2, false]]
  7496. *
  7497. * _.unzip(zipped);
  7498. * // => [['a', 'b'], [1, 2], [true, false]]
  7499. */
  7500. function unzip(array) {
  7501. if (!(array && array.length)) {
  7502. return [];
  7503. }
  7504. var length = 0;
  7505. array = arrayFilter(array, function(group) {
  7506. if (isArrayLikeObject(group)) {
  7507. length = nativeMax(group.length, length);
  7508. return true;
  7509. }
  7510. });
  7511. return baseTimes(length, function(index) {
  7512. return arrayMap(array, baseProperty(index));
  7513. });
  7514. }
  7515. /**
  7516. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7517. * how regrouped values should be combined. The iteratee is invoked with the
  7518. * elements of each group: (...group).
  7519. *
  7520. * @static
  7521. * @memberOf _
  7522. * @since 3.8.0
  7523. * @category Array
  7524. * @param {Array} array The array of grouped elements to process.
  7525. * @param {Function} [iteratee=_.identity] The function to combine
  7526. * regrouped values.
  7527. * @returns {Array} Returns the new array of regrouped elements.
  7528. * @example
  7529. *
  7530. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7531. * // => [[1, 10, 100], [2, 20, 200]]
  7532. *
  7533. * _.unzipWith(zipped, _.add);
  7534. * // => [3, 30, 300]
  7535. */
  7536. function unzipWith(array, iteratee) {
  7537. if (!(array && array.length)) {
  7538. return [];
  7539. }
  7540. var result = unzip(array);
  7541. if (iteratee == null) {
  7542. return result;
  7543. }
  7544. return arrayMap(result, function(group) {
  7545. return apply(iteratee, undefined, group);
  7546. });
  7547. }
  7548. /**
  7549. * Creates an array excluding all given values using
  7550. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7551. * for equality comparisons.
  7552. *
  7553. * **Note:** Unlike `_.pull`, this method returns a new array.
  7554. *
  7555. * @static
  7556. * @memberOf _
  7557. * @since 0.1.0
  7558. * @category Array
  7559. * @param {Array} array The array to inspect.
  7560. * @param {...*} [values] The values to exclude.
  7561. * @returns {Array} Returns the new array of filtered values.
  7562. * @see _.difference, _.xor
  7563. * @example
  7564. *
  7565. * _.without([2, 1, 2, 3], 1, 2);
  7566. * // => [3]
  7567. */
  7568. var without = baseRest(function(array, values) {
  7569. return isArrayLikeObject(array)
  7570. ? baseDifference(array, values)
  7571. : [];
  7572. });
  7573. /**
  7574. * Creates an array of unique values that is the
  7575. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7576. * of the given arrays. The order of result values is determined by the order
  7577. * they occur in the arrays.
  7578. *
  7579. * @static
  7580. * @memberOf _
  7581. * @since 2.4.0
  7582. * @category Array
  7583. * @param {...Array} [arrays] The arrays to inspect.
  7584. * @returns {Array} Returns the new array of filtered values.
  7585. * @see _.difference, _.without
  7586. * @example
  7587. *
  7588. * _.xor([2, 1], [2, 3]);
  7589. * // => [1, 3]
  7590. */
  7591. var xor = baseRest(function(arrays) {
  7592. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7593. });
  7594. /**
  7595. * This method is like `_.xor` except that it accepts `iteratee` which is
  7596. * invoked for each element of each `arrays` to generate the criterion by
  7597. * which by which they're compared. The iteratee is invoked with one argument:
  7598. * (value).
  7599. *
  7600. * @static
  7601. * @memberOf _
  7602. * @since 4.0.0
  7603. * @category Array
  7604. * @param {...Array} [arrays] The arrays to inspect.
  7605. * @param {Function} [iteratee=_.identity]
  7606. * The iteratee invoked per element.
  7607. * @returns {Array} Returns the new array of filtered values.
  7608. * @example
  7609. *
  7610. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7611. * // => [1.2, 3.4]
  7612. *
  7613. * // The `_.property` iteratee shorthand.
  7614. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7615. * // => [{ 'x': 2 }]
  7616. */
  7617. var xorBy = baseRest(function(arrays) {
  7618. var iteratee = last(arrays);
  7619. if (isArrayLikeObject(iteratee)) {
  7620. iteratee = undefined;
  7621. }
  7622. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7623. });
  7624. /**
  7625. * This method is like `_.xor` except that it accepts `comparator` which is
  7626. * invoked to compare elements of `arrays`. The comparator is invoked with
  7627. * two arguments: (arrVal, othVal).
  7628. *
  7629. * @static
  7630. * @memberOf _
  7631. * @since 4.0.0
  7632. * @category Array
  7633. * @param {...Array} [arrays] The arrays to inspect.
  7634. * @param {Function} [comparator] The comparator invoked per element.
  7635. * @returns {Array} Returns the new array of filtered values.
  7636. * @example
  7637. *
  7638. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7639. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7640. *
  7641. * _.xorWith(objects, others, _.isEqual);
  7642. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7643. */
  7644. var xorWith = baseRest(function(arrays) {
  7645. var comparator = last(arrays);
  7646. if (isArrayLikeObject(comparator)) {
  7647. comparator = undefined;
  7648. }
  7649. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  7650. });
  7651. /**
  7652. * Creates an array of grouped elements, the first of which contains the
  7653. * first elements of the given arrays, the second of which contains the
  7654. * second elements of the given arrays, and so on.
  7655. *
  7656. * @static
  7657. * @memberOf _
  7658. * @since 0.1.0
  7659. * @category Array
  7660. * @param {...Array} [arrays] The arrays to process.
  7661. * @returns {Array} Returns the new array of grouped elements.
  7662. * @example
  7663. *
  7664. * _.zip(['a', 'b'], [1, 2], [true, false]);
  7665. * // => [['a', 1, true], ['b', 2, false]]
  7666. */
  7667. var zip = baseRest(unzip);
  7668. /**
  7669. * This method is like `_.fromPairs` except that it accepts two arrays,
  7670. * one of property identifiers and one of corresponding values.
  7671. *
  7672. * @static
  7673. * @memberOf _
  7674. * @since 0.4.0
  7675. * @category Array
  7676. * @param {Array} [props=[]] The property identifiers.
  7677. * @param {Array} [values=[]] The property values.
  7678. * @returns {Object} Returns the new object.
  7679. * @example
  7680. *
  7681. * _.zipObject(['a', 'b'], [1, 2]);
  7682. * // => { 'a': 1, 'b': 2 }
  7683. */
  7684. function zipObject(props, values) {
  7685. return baseZipObject(props || [], values || [], assignValue);
  7686. }
  7687. /**
  7688. * This method is like `_.zipObject` except that it supports property paths.
  7689. *
  7690. * @static
  7691. * @memberOf _
  7692. * @since 4.1.0
  7693. * @category Array
  7694. * @param {Array} [props=[]] The property identifiers.
  7695. * @param {Array} [values=[]] The property values.
  7696. * @returns {Object} Returns the new object.
  7697. * @example
  7698. *
  7699. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  7700. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  7701. */
  7702. function zipObjectDeep(props, values) {
  7703. return baseZipObject(props || [], values || [], baseSet);
  7704. }
  7705. /**
  7706. * This method is like `_.zip` except that it accepts `iteratee` to specify
  7707. * how grouped values should be combined. The iteratee is invoked with the
  7708. * elements of each group: (...group).
  7709. *
  7710. * @static
  7711. * @memberOf _
  7712. * @since 3.8.0
  7713. * @category Array
  7714. * @param {...Array} [arrays] The arrays to process.
  7715. * @param {Function} [iteratee=_.identity] The function to combine grouped values.
  7716. * @returns {Array} Returns the new array of grouped elements.
  7717. * @example
  7718. *
  7719. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  7720. * return a + b + c;
  7721. * });
  7722. * // => [111, 222]
  7723. */
  7724. var zipWith = baseRest(function(arrays) {
  7725. var length = arrays.length,
  7726. iteratee = length > 1 ? arrays[length - 1] : undefined;
  7727. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  7728. return unzipWith(arrays, iteratee);
  7729. });
  7730. /*------------------------------------------------------------------------*/
  7731. /**
  7732. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  7733. * chain sequences enabled. The result of such sequences must be unwrapped
  7734. * with `_#value`.
  7735. *
  7736. * @static
  7737. * @memberOf _
  7738. * @since 1.3.0
  7739. * @category Seq
  7740. * @param {*} value The value to wrap.
  7741. * @returns {Object} Returns the new `lodash` wrapper instance.
  7742. * @example
  7743. *
  7744. * var users = [
  7745. * { 'user': 'barney', 'age': 36 },
  7746. * { 'user': 'fred', 'age': 40 },
  7747. * { 'user': 'pebbles', 'age': 1 }
  7748. * ];
  7749. *
  7750. * var youngest = _
  7751. * .chain(users)
  7752. * .sortBy('age')
  7753. * .map(function(o) {
  7754. * return o.user + ' is ' + o.age;
  7755. * })
  7756. * .head()
  7757. * .value();
  7758. * // => 'pebbles is 1'
  7759. */
  7760. function chain(value) {
  7761. var result = lodash(value);
  7762. result.__chain__ = true;
  7763. return result;
  7764. }
  7765. /**
  7766. * This method invokes `interceptor` and returns `value`. The interceptor
  7767. * is invoked with one argument; (value). The purpose of this method is to
  7768. * "tap into" a method chain sequence in order to modify intermediate results.
  7769. *
  7770. * @static
  7771. * @memberOf _
  7772. * @since 0.1.0
  7773. * @category Seq
  7774. * @param {*} value The value to provide to `interceptor`.
  7775. * @param {Function} interceptor The function to invoke.
  7776. * @returns {*} Returns `value`.
  7777. * @example
  7778. *
  7779. * _([1, 2, 3])
  7780. * .tap(function(array) {
  7781. * // Mutate input array.
  7782. * array.pop();
  7783. * })
  7784. * .reverse()
  7785. * .value();
  7786. * // => [2, 1]
  7787. */
  7788. function tap(value, interceptor) {
  7789. interceptor(value);
  7790. return value;
  7791. }
  7792. /**
  7793. * This method is like `_.tap` except that it returns the result of `interceptor`.
  7794. * The purpose of this method is to "pass thru" values replacing intermediate
  7795. * results in a method chain sequence.
  7796. *
  7797. * @static
  7798. * @memberOf _
  7799. * @since 3.0.0
  7800. * @category Seq
  7801. * @param {*} value The value to provide to `interceptor`.
  7802. * @param {Function} interceptor The function to invoke.
  7803. * @returns {*} Returns the result of `interceptor`.
  7804. * @example
  7805. *
  7806. * _(' abc ')
  7807. * .chain()
  7808. * .trim()
  7809. * .thru(function(value) {
  7810. * return [value];
  7811. * })
  7812. * .value();
  7813. * // => ['abc']
  7814. */
  7815. function thru(value, interceptor) {
  7816. return interceptor(value);
  7817. }
  7818. /**
  7819. * This method is the wrapper version of `_.at`.
  7820. *
  7821. * @name at
  7822. * @memberOf _
  7823. * @since 1.0.0
  7824. * @category Seq
  7825. * @param {...(string|string[])} [paths] The property paths of elements to pick.
  7826. * @returns {Object} Returns the new `lodash` wrapper instance.
  7827. * @example
  7828. *
  7829. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  7830. *
  7831. * _(object).at(['a[0].b.c', 'a[1]']).value();
  7832. * // => [3, 4]
  7833. */
  7834. var wrapperAt = baseRest(function(paths) {
  7835. paths = baseFlatten(paths, 1);
  7836. var length = paths.length,
  7837. start = length ? paths[0] : 0,
  7838. value = this.__wrapped__,
  7839. interceptor = function(object) { return baseAt(object, paths); };
  7840. if (length > 1 || this.__actions__.length ||
  7841. !(value instanceof LazyWrapper) || !isIndex(start)) {
  7842. return this.thru(interceptor);
  7843. }
  7844. value = value.slice(start, +start + (length ? 1 : 0));
  7845. value.__actions__.push({
  7846. 'func': thru,
  7847. 'args': [interceptor],
  7848. 'thisArg': undefined
  7849. });
  7850. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  7851. if (length && !array.length) {
  7852. array.push(undefined);
  7853. }
  7854. return array;
  7855. });
  7856. });
  7857. /**
  7858. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  7859. *
  7860. * @name chain
  7861. * @memberOf _
  7862. * @since 0.1.0
  7863. * @category Seq
  7864. * @returns {Object} Returns the new `lodash` wrapper instance.
  7865. * @example
  7866. *
  7867. * var users = [
  7868. * { 'user': 'barney', 'age': 36 },
  7869. * { 'user': 'fred', 'age': 40 }
  7870. * ];
  7871. *
  7872. * // A sequence without explicit chaining.
  7873. * _(users).head();
  7874. * // => { 'user': 'barney', 'age': 36 }
  7875. *
  7876. * // A sequence with explicit chaining.
  7877. * _(users)
  7878. * .chain()
  7879. * .head()
  7880. * .pick('user')
  7881. * .value();
  7882. * // => { 'user': 'barney' }
  7883. */
  7884. function wrapperChain() {
  7885. return chain(this);
  7886. }
  7887. /**
  7888. * Executes the chain sequence and returns the wrapped result.
  7889. *
  7890. * @name commit
  7891. * @memberOf _
  7892. * @since 3.2.0
  7893. * @category Seq
  7894. * @returns {Object} Returns the new `lodash` wrapper instance.
  7895. * @example
  7896. *
  7897. * var array = [1, 2];
  7898. * var wrapped = _(array).push(3);
  7899. *
  7900. * console.log(array);
  7901. * // => [1, 2]
  7902. *
  7903. * wrapped = wrapped.commit();
  7904. * console.log(array);
  7905. * // => [1, 2, 3]
  7906. *
  7907. * wrapped.last();
  7908. * // => 3
  7909. *
  7910. * console.log(array);
  7911. * // => [1, 2, 3]
  7912. */
  7913. function wrapperCommit() {
  7914. return new LodashWrapper(this.value(), this.__chain__);
  7915. }
  7916. /**
  7917. * Gets the next value on a wrapped object following the
  7918. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  7919. *
  7920. * @name next
  7921. * @memberOf _
  7922. * @since 4.0.0
  7923. * @category Seq
  7924. * @returns {Object} Returns the next iterator value.
  7925. * @example
  7926. *
  7927. * var wrapped = _([1, 2]);
  7928. *
  7929. * wrapped.next();
  7930. * // => { 'done': false, 'value': 1 }
  7931. *
  7932. * wrapped.next();
  7933. * // => { 'done': false, 'value': 2 }
  7934. *
  7935. * wrapped.next();
  7936. * // => { 'done': true, 'value': undefined }
  7937. */
  7938. function wrapperNext() {
  7939. if (this.__values__ === undefined) {
  7940. this.__values__ = toArray(this.value());
  7941. }
  7942. var done = this.__index__ >= this.__values__.length,
  7943. value = done ? undefined : this.__values__[this.__index__++];
  7944. return { 'done': done, 'value': value };
  7945. }
  7946. /**
  7947. * Enables the wrapper to be iterable.
  7948. *
  7949. * @name Symbol.iterator
  7950. * @memberOf _
  7951. * @since 4.0.0
  7952. * @category Seq
  7953. * @returns {Object} Returns the wrapper object.
  7954. * @example
  7955. *
  7956. * var wrapped = _([1, 2]);
  7957. *
  7958. * wrapped[Symbol.iterator]() === wrapped;
  7959. * // => true
  7960. *
  7961. * Array.from(wrapped);
  7962. * // => [1, 2]
  7963. */
  7964. function wrapperToIterator() {
  7965. return this;
  7966. }
  7967. /**
  7968. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  7969. *
  7970. * @name plant
  7971. * @memberOf _
  7972. * @since 3.2.0
  7973. * @category Seq
  7974. * @param {*} value The value to plant.
  7975. * @returns {Object} Returns the new `lodash` wrapper instance.
  7976. * @example
  7977. *
  7978. * function square(n) {
  7979. * return n * n;
  7980. * }
  7981. *
  7982. * var wrapped = _([1, 2]).map(square);
  7983. * var other = wrapped.plant([3, 4]);
  7984. *
  7985. * other.value();
  7986. * // => [9, 16]
  7987. *
  7988. * wrapped.value();
  7989. * // => [1, 4]
  7990. */
  7991. function wrapperPlant(value) {
  7992. var result,
  7993. parent = this;
  7994. while (parent instanceof baseLodash) {
  7995. var clone = wrapperClone(parent);
  7996. clone.__index__ = 0;
  7997. clone.__values__ = undefined;
  7998. if (result) {
  7999. previous.__wrapped__ = clone;
  8000. } else {
  8001. result = clone;
  8002. }
  8003. var previous = clone;
  8004. parent = parent.__wrapped__;
  8005. }
  8006. previous.__wrapped__ = value;
  8007. return result;
  8008. }
  8009. /**
  8010. * This method is the wrapper version of `_.reverse`.
  8011. *
  8012. * **Note:** This method mutates the wrapped array.
  8013. *
  8014. * @name reverse
  8015. * @memberOf _
  8016. * @since 0.1.0
  8017. * @category Seq
  8018. * @returns {Object} Returns the new `lodash` wrapper instance.
  8019. * @example
  8020. *
  8021. * var array = [1, 2, 3];
  8022. *
  8023. * _(array).reverse().value()
  8024. * // => [3, 2, 1]
  8025. *
  8026. * console.log(array);
  8027. * // => [3, 2, 1]
  8028. */
  8029. function wrapperReverse() {
  8030. var value = this.__wrapped__;
  8031. if (value instanceof LazyWrapper) {
  8032. var wrapped = value;
  8033. if (this.__actions__.length) {
  8034. wrapped = new LazyWrapper(this);
  8035. }
  8036. wrapped = wrapped.reverse();
  8037. wrapped.__actions__.push({
  8038. 'func': thru,
  8039. 'args': [reverse],
  8040. 'thisArg': undefined
  8041. });
  8042. return new LodashWrapper(wrapped, this.__chain__);
  8043. }
  8044. return this.thru(reverse);
  8045. }
  8046. /**
  8047. * Executes the chain sequence to resolve the unwrapped value.
  8048. *
  8049. * @name value
  8050. * @memberOf _
  8051. * @since 0.1.0
  8052. * @alias toJSON, valueOf
  8053. * @category Seq
  8054. * @returns {*} Returns the resolved unwrapped value.
  8055. * @example
  8056. *
  8057. * _([1, 2, 3]).value();
  8058. * // => [1, 2, 3]
  8059. */
  8060. function wrapperValue() {
  8061. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8062. }
  8063. /*------------------------------------------------------------------------*/
  8064. /**
  8065. * Creates an object composed of keys generated from the results of running
  8066. * each element of `collection` thru `iteratee`. The corresponding value of
  8067. * each key is the number of times the key was returned by `iteratee`. The
  8068. * iteratee is invoked with one argument: (value).
  8069. *
  8070. * @static
  8071. * @memberOf _
  8072. * @since 0.5.0
  8073. * @category Collection
  8074. * @param {Array|Object} collection The collection to iterate over.
  8075. * @param {Function} [iteratee=_.identity]
  8076. * The iteratee to transform keys.
  8077. * @returns {Object} Returns the composed aggregate object.
  8078. * @example
  8079. *
  8080. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8081. * // => { '4': 1, '6': 2 }
  8082. *
  8083. * // The `_.property` iteratee shorthand.
  8084. * _.countBy(['one', 'two', 'three'], 'length');
  8085. * // => { '3': 2, '5': 1 }
  8086. */
  8087. var countBy = createAggregator(function(result, value, key) {
  8088. hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
  8089. });
  8090. /**
  8091. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8092. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8093. * invoked with three arguments: (value, index|key, collection).
  8094. *
  8095. * **Note:** This method returns `true` for
  8096. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8097. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8098. * elements of empty collections.
  8099. *
  8100. * @static
  8101. * @memberOf _
  8102. * @since 0.1.0
  8103. * @category Collection
  8104. * @param {Array|Object} collection The collection to iterate over.
  8105. * @param {Function} [predicate=_.identity]
  8106. * The function invoked per iteration.
  8107. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8108. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8109. * else `false`.
  8110. * @example
  8111. *
  8112. * _.every([true, 1, null, 'yes'], Boolean);
  8113. * // => false
  8114. *
  8115. * var users = [
  8116. * { 'user': 'barney', 'age': 36, 'active': false },
  8117. * { 'user': 'fred', 'age': 40, 'active': false }
  8118. * ];
  8119. *
  8120. * // The `_.matches` iteratee shorthand.
  8121. * _.every(users, { 'user': 'barney', 'active': false });
  8122. * // => false
  8123. *
  8124. * // The `_.matchesProperty` iteratee shorthand.
  8125. * _.every(users, ['active', false]);
  8126. * // => true
  8127. *
  8128. * // The `_.property` iteratee shorthand.
  8129. * _.every(users, 'active');
  8130. * // => false
  8131. */
  8132. function every(collection, predicate, guard) {
  8133. var func = isArray(collection) ? arrayEvery : baseEvery;
  8134. if (guard && isIterateeCall(collection, predicate, guard)) {
  8135. predicate = undefined;
  8136. }
  8137. return func(collection, getIteratee(predicate, 3));
  8138. }
  8139. /**
  8140. * Iterates over elements of `collection`, returning an array of all elements
  8141. * `predicate` returns truthy for. The predicate is invoked with three
  8142. * arguments: (value, index|key, collection).
  8143. *
  8144. * **Note:** Unlike `_.remove`, this method returns a new array.
  8145. *
  8146. * @static
  8147. * @memberOf _
  8148. * @since 0.1.0
  8149. * @category Collection
  8150. * @param {Array|Object} collection The collection to iterate over.
  8151. * @param {Function} [predicate=_.identity]
  8152. * The function invoked per iteration.
  8153. * @returns {Array} Returns the new filtered array.
  8154. * @see _.reject
  8155. * @example
  8156. *
  8157. * var users = [
  8158. * { 'user': 'barney', 'age': 36, 'active': true },
  8159. * { 'user': 'fred', 'age': 40, 'active': false }
  8160. * ];
  8161. *
  8162. * _.filter(users, function(o) { return !o.active; });
  8163. * // => objects for ['fred']
  8164. *
  8165. * // The `_.matches` iteratee shorthand.
  8166. * _.filter(users, { 'age': 36, 'active': true });
  8167. * // => objects for ['barney']
  8168. *
  8169. * // The `_.matchesProperty` iteratee shorthand.
  8170. * _.filter(users, ['active', false]);
  8171. * // => objects for ['fred']
  8172. *
  8173. * // The `_.property` iteratee shorthand.
  8174. * _.filter(users, 'active');
  8175. * // => objects for ['barney']
  8176. */
  8177. function filter(collection, predicate) {
  8178. var func = isArray(collection) ? arrayFilter : baseFilter;
  8179. return func(collection, getIteratee(predicate, 3));
  8180. }
  8181. /**
  8182. * Iterates over elements of `collection`, returning the first element
  8183. * `predicate` returns truthy for. The predicate is invoked with three
  8184. * arguments: (value, index|key, collection).
  8185. *
  8186. * @static
  8187. * @memberOf _
  8188. * @since 0.1.0
  8189. * @category Collection
  8190. * @param {Array|Object} collection The collection to inspect.
  8191. * @param {Function} [predicate=_.identity]
  8192. * The function invoked per iteration.
  8193. * @param {number} [fromIndex=0] The index to search from.
  8194. * @returns {*} Returns the matched element, else `undefined`.
  8195. * @example
  8196. *
  8197. * var users = [
  8198. * { 'user': 'barney', 'age': 36, 'active': true },
  8199. * { 'user': 'fred', 'age': 40, 'active': false },
  8200. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8201. * ];
  8202. *
  8203. * _.find(users, function(o) { return o.age < 40; });
  8204. * // => object for 'barney'
  8205. *
  8206. * // The `_.matches` iteratee shorthand.
  8207. * _.find(users, { 'age': 1, 'active': true });
  8208. * // => object for 'pebbles'
  8209. *
  8210. * // The `_.matchesProperty` iteratee shorthand.
  8211. * _.find(users, ['active', false]);
  8212. * // => object for 'fred'
  8213. *
  8214. * // The `_.property` iteratee shorthand.
  8215. * _.find(users, 'active');
  8216. * // => object for 'barney'
  8217. */
  8218. var find = createFind(findIndex);
  8219. /**
  8220. * This method is like `_.find` except that it iterates over elements of
  8221. * `collection` from right to left.
  8222. *
  8223. * @static
  8224. * @memberOf _
  8225. * @since 2.0.0
  8226. * @category Collection
  8227. * @param {Array|Object} collection The collection to inspect.
  8228. * @param {Function} [predicate=_.identity]
  8229. * The function invoked per iteration.
  8230. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8231. * @returns {*} Returns the matched element, else `undefined`.
  8232. * @example
  8233. *
  8234. * _.findLast([1, 2, 3, 4], function(n) {
  8235. * return n % 2 == 1;
  8236. * });
  8237. * // => 3
  8238. */
  8239. var findLast = createFind(findLastIndex);
  8240. /**
  8241. * Creates a flattened array of values by running each element in `collection`
  8242. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8243. * with three arguments: (value, index|key, collection).
  8244. *
  8245. * @static
  8246. * @memberOf _
  8247. * @since 4.0.0
  8248. * @category Collection
  8249. * @param {Array|Object} collection The collection to iterate over.
  8250. * @param {Function} [iteratee=_.identity]
  8251. * The function invoked per iteration.
  8252. * @returns {Array} Returns the new flattened array.
  8253. * @example
  8254. *
  8255. * function duplicate(n) {
  8256. * return [n, n];
  8257. * }
  8258. *
  8259. * _.flatMap([1, 2], duplicate);
  8260. * // => [1, 1, 2, 2]
  8261. */
  8262. function flatMap(collection, iteratee) {
  8263. return baseFlatten(map(collection, iteratee), 1);
  8264. }
  8265. /**
  8266. * This method is like `_.flatMap` except that it recursively flattens the
  8267. * mapped results.
  8268. *
  8269. * @static
  8270. * @memberOf _
  8271. * @since 4.7.0
  8272. * @category Collection
  8273. * @param {Array|Object} collection The collection to iterate over.
  8274. * @param {Function} [iteratee=_.identity]
  8275. * The function invoked per iteration.
  8276. * @returns {Array} Returns the new flattened array.
  8277. * @example
  8278. *
  8279. * function duplicate(n) {
  8280. * return [[[n, n]]];
  8281. * }
  8282. *
  8283. * _.flatMapDeep([1, 2], duplicate);
  8284. * // => [1, 1, 2, 2]
  8285. */
  8286. function flatMapDeep(collection, iteratee) {
  8287. return baseFlatten(map(collection, iteratee), INFINITY);
  8288. }
  8289. /**
  8290. * This method is like `_.flatMap` except that it recursively flattens the
  8291. * mapped results up to `depth` times.
  8292. *
  8293. * @static
  8294. * @memberOf _
  8295. * @since 4.7.0
  8296. * @category Collection
  8297. * @param {Array|Object} collection The collection to iterate over.
  8298. * @param {Function} [iteratee=_.identity]
  8299. * The function invoked per iteration.
  8300. * @param {number} [depth=1] The maximum recursion depth.
  8301. * @returns {Array} Returns the new flattened array.
  8302. * @example
  8303. *
  8304. * function duplicate(n) {
  8305. * return [[[n, n]]];
  8306. * }
  8307. *
  8308. * _.flatMapDepth([1, 2], duplicate, 2);
  8309. * // => [[1, 1], [2, 2]]
  8310. */
  8311. function flatMapDepth(collection, iteratee, depth) {
  8312. depth = depth === undefined ? 1 : toInteger(depth);
  8313. return baseFlatten(map(collection, iteratee), depth);
  8314. }
  8315. /**
  8316. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8317. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8318. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8319. *
  8320. * **Note:** As with other "Collections" methods, objects with a "length"
  8321. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8322. * or `_.forOwn` for object iteration.
  8323. *
  8324. * @static
  8325. * @memberOf _
  8326. * @since 0.1.0
  8327. * @alias each
  8328. * @category Collection
  8329. * @param {Array|Object} collection The collection to iterate over.
  8330. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8331. * @returns {Array|Object} Returns `collection`.
  8332. * @see _.forEachRight
  8333. * @example
  8334. *
  8335. * _([1, 2]).forEach(function(value) {
  8336. * console.log(value);
  8337. * });
  8338. * // => Logs `1` then `2`.
  8339. *
  8340. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8341. * console.log(key);
  8342. * });
  8343. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8344. */
  8345. function forEach(collection, iteratee) {
  8346. var func = isArray(collection) ? arrayEach : baseEach;
  8347. return func(collection, getIteratee(iteratee, 3));
  8348. }
  8349. /**
  8350. * This method is like `_.forEach` except that it iterates over elements of
  8351. * `collection` from right to left.
  8352. *
  8353. * @static
  8354. * @memberOf _
  8355. * @since 2.0.0
  8356. * @alias eachRight
  8357. * @category Collection
  8358. * @param {Array|Object} collection The collection to iterate over.
  8359. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8360. * @returns {Array|Object} Returns `collection`.
  8361. * @see _.forEach
  8362. * @example
  8363. *
  8364. * _.forEachRight([1, 2], function(value) {
  8365. * console.log(value);
  8366. * });
  8367. * // => Logs `2` then `1`.
  8368. */
  8369. function forEachRight(collection, iteratee) {
  8370. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8371. return func(collection, getIteratee(iteratee, 3));
  8372. }
  8373. /**
  8374. * Creates an object composed of keys generated from the results of running
  8375. * each element of `collection` thru `iteratee`. The order of grouped values
  8376. * is determined by the order they occur in `collection`. The corresponding
  8377. * value of each key is an array of elements responsible for generating the
  8378. * key. The iteratee is invoked with one argument: (value).
  8379. *
  8380. * @static
  8381. * @memberOf _
  8382. * @since 0.1.0
  8383. * @category Collection
  8384. * @param {Array|Object} collection The collection to iterate over.
  8385. * @param {Function} [iteratee=_.identity]
  8386. * The iteratee to transform keys.
  8387. * @returns {Object} Returns the composed aggregate object.
  8388. * @example
  8389. *
  8390. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8391. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8392. *
  8393. * // The `_.property` iteratee shorthand.
  8394. * _.groupBy(['one', 'two', 'three'], 'length');
  8395. * // => { '3': ['one', 'two'], '5': ['three'] }
  8396. */
  8397. var groupBy = createAggregator(function(result, value, key) {
  8398. if (hasOwnProperty.call(result, key)) {
  8399. result[key].push(value);
  8400. } else {
  8401. result[key] = [value];
  8402. }
  8403. });
  8404. /**
  8405. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8406. * checked for a substring of `value`, otherwise
  8407. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8408. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8409. * the offset from the end of `collection`.
  8410. *
  8411. * @static
  8412. * @memberOf _
  8413. * @since 0.1.0
  8414. * @category Collection
  8415. * @param {Array|Object|string} collection The collection to inspect.
  8416. * @param {*} value The value to search for.
  8417. * @param {number} [fromIndex=0] The index to search from.
  8418. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8419. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8420. * @example
  8421. *
  8422. * _.includes([1, 2, 3], 1);
  8423. * // => true
  8424. *
  8425. * _.includes([1, 2, 3], 1, 2);
  8426. * // => false
  8427. *
  8428. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8429. * // => true
  8430. *
  8431. * _.includes('abcd', 'bc');
  8432. * // => true
  8433. */
  8434. function includes(collection, value, fromIndex, guard) {
  8435. collection = isArrayLike(collection) ? collection : values(collection);
  8436. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8437. var length = collection.length;
  8438. if (fromIndex < 0) {
  8439. fromIndex = nativeMax(length + fromIndex, 0);
  8440. }
  8441. return isString(collection)
  8442. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8443. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8444. }
  8445. /**
  8446. * Invokes the method at `path` of each element in `collection`, returning
  8447. * an array of the results of each invoked method. Any additional arguments
  8448. * are provided to each invoked method. If `path` is a function, it's invoked
  8449. * for, and `this` bound to, each element in `collection`.
  8450. *
  8451. * @static
  8452. * @memberOf _
  8453. * @since 4.0.0
  8454. * @category Collection
  8455. * @param {Array|Object} collection The collection to iterate over.
  8456. * @param {Array|Function|string} path The path of the method to invoke or
  8457. * the function invoked per iteration.
  8458. * @param {...*} [args] The arguments to invoke each method with.
  8459. * @returns {Array} Returns the array of results.
  8460. * @example
  8461. *
  8462. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8463. * // => [[1, 5, 7], [1, 2, 3]]
  8464. *
  8465. * _.invokeMap([123, 456], String.prototype.split, '');
  8466. * // => [['1', '2', '3'], ['4', '5', '6']]
  8467. */
  8468. var invokeMap = baseRest(function(collection, path, args) {
  8469. var index = -1,
  8470. isFunc = typeof path == 'function',
  8471. isProp = isKey(path),
  8472. result = isArrayLike(collection) ? Array(collection.length) : [];
  8473. baseEach(collection, function(value) {
  8474. var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
  8475. result[++index] = func ? apply(func, value, args) : baseInvoke(value, path, args);
  8476. });
  8477. return result;
  8478. });
  8479. /**
  8480. * Creates an object composed of keys generated from the results of running
  8481. * each element of `collection` thru `iteratee`. The corresponding value of
  8482. * each key is the last element responsible for generating the key. The
  8483. * iteratee is invoked with one argument: (value).
  8484. *
  8485. * @static
  8486. * @memberOf _
  8487. * @since 4.0.0
  8488. * @category Collection
  8489. * @param {Array|Object} collection The collection to iterate over.
  8490. * @param {Function} [iteratee=_.identity]
  8491. * The iteratee to transform keys.
  8492. * @returns {Object} Returns the composed aggregate object.
  8493. * @example
  8494. *
  8495. * var array = [
  8496. * { 'dir': 'left', 'code': 97 },
  8497. * { 'dir': 'right', 'code': 100 }
  8498. * ];
  8499. *
  8500. * _.keyBy(array, function(o) {
  8501. * return String.fromCharCode(o.code);
  8502. * });
  8503. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8504. *
  8505. * _.keyBy(array, 'dir');
  8506. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8507. */
  8508. var keyBy = createAggregator(function(result, value, key) {
  8509. result[key] = value;
  8510. });
  8511. /**
  8512. * Creates an array of values by running each element in `collection` thru
  8513. * `iteratee`. The iteratee is invoked with three arguments:
  8514. * (value, index|key, collection).
  8515. *
  8516. * Many lodash methods are guarded to work as iteratees for methods like
  8517. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8518. *
  8519. * The guarded methods are:
  8520. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8521. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8522. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8523. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8524. *
  8525. * @static
  8526. * @memberOf _
  8527. * @since 0.1.0
  8528. * @category Collection
  8529. * @param {Array|Object} collection The collection to iterate over.
  8530. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8531. * @returns {Array} Returns the new mapped array.
  8532. * @example
  8533. *
  8534. * function square(n) {
  8535. * return n * n;
  8536. * }
  8537. *
  8538. * _.map([4, 8], square);
  8539. * // => [16, 64]
  8540. *
  8541. * _.map({ 'a': 4, 'b': 8 }, square);
  8542. * // => [16, 64] (iteration order is not guaranteed)
  8543. *
  8544. * var users = [
  8545. * { 'user': 'barney' },
  8546. * { 'user': 'fred' }
  8547. * ];
  8548. *
  8549. * // The `_.property` iteratee shorthand.
  8550. * _.map(users, 'user');
  8551. * // => ['barney', 'fred']
  8552. */
  8553. function map(collection, iteratee) {
  8554. var func = isArray(collection) ? arrayMap : baseMap;
  8555. return func(collection, getIteratee(iteratee, 3));
  8556. }
  8557. /**
  8558. * This method is like `_.sortBy` except that it allows specifying the sort
  8559. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8560. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8561. * descending or "asc" for ascending sort order of corresponding values.
  8562. *
  8563. * @static
  8564. * @memberOf _
  8565. * @since 4.0.0
  8566. * @category Collection
  8567. * @param {Array|Object} collection The collection to iterate over.
  8568. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8569. * The iteratees to sort by.
  8570. * @param {string[]} [orders] The sort orders of `iteratees`.
  8571. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8572. * @returns {Array} Returns the new sorted array.
  8573. * @example
  8574. *
  8575. * var users = [
  8576. * { 'user': 'fred', 'age': 48 },
  8577. * { 'user': 'barney', 'age': 34 },
  8578. * { 'user': 'fred', 'age': 40 },
  8579. * { 'user': 'barney', 'age': 36 }
  8580. * ];
  8581. *
  8582. * // Sort by `user` in ascending order and by `age` in descending order.
  8583. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8584. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8585. */
  8586. function orderBy(collection, iteratees, orders, guard) {
  8587. if (collection == null) {
  8588. return [];
  8589. }
  8590. if (!isArray(iteratees)) {
  8591. iteratees = iteratees == null ? [] : [iteratees];
  8592. }
  8593. orders = guard ? undefined : orders;
  8594. if (!isArray(orders)) {
  8595. orders = orders == null ? [] : [orders];
  8596. }
  8597. return baseOrderBy(collection, iteratees, orders);
  8598. }
  8599. /**
  8600. * Creates an array of elements split into two groups, the first of which
  8601. * contains elements `predicate` returns truthy for, the second of which
  8602. * contains elements `predicate` returns falsey for. The predicate is
  8603. * invoked with one argument: (value).
  8604. *
  8605. * @static
  8606. * @memberOf _
  8607. * @since 3.0.0
  8608. * @category Collection
  8609. * @param {Array|Object} collection The collection to iterate over.
  8610. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8611. * @returns {Array} Returns the array of grouped elements.
  8612. * @example
  8613. *
  8614. * var users = [
  8615. * { 'user': 'barney', 'age': 36, 'active': false },
  8616. * { 'user': 'fred', 'age': 40, 'active': true },
  8617. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8618. * ];
  8619. *
  8620. * _.partition(users, function(o) { return o.active; });
  8621. * // => objects for [['fred'], ['barney', 'pebbles']]
  8622. *
  8623. * // The `_.matches` iteratee shorthand.
  8624. * _.partition(users, { 'age': 1, 'active': false });
  8625. * // => objects for [['pebbles'], ['barney', 'fred']]
  8626. *
  8627. * // The `_.matchesProperty` iteratee shorthand.
  8628. * _.partition(users, ['active', false]);
  8629. * // => objects for [['barney', 'pebbles'], ['fred']]
  8630. *
  8631. * // The `_.property` iteratee shorthand.
  8632. * _.partition(users, 'active');
  8633. * // => objects for [['fred'], ['barney', 'pebbles']]
  8634. */
  8635. var partition = createAggregator(function(result, value, key) {
  8636. result[key ? 0 : 1].push(value);
  8637. }, function() { return [[], []]; });
  8638. /**
  8639. * Reduces `collection` to a value which is the accumulated result of running
  8640. * each element in `collection` thru `iteratee`, where each successive
  8641. * invocation is supplied the return value of the previous. If `accumulator`
  8642. * is not given, the first element of `collection` is used as the initial
  8643. * value. The iteratee is invoked with four arguments:
  8644. * (accumulator, value, index|key, collection).
  8645. *
  8646. * Many lodash methods are guarded to work as iteratees for methods like
  8647. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  8648. *
  8649. * The guarded methods are:
  8650. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  8651. * and `sortBy`
  8652. *
  8653. * @static
  8654. * @memberOf _
  8655. * @since 0.1.0
  8656. * @category Collection
  8657. * @param {Array|Object} collection The collection to iterate over.
  8658. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8659. * @param {*} [accumulator] The initial value.
  8660. * @returns {*} Returns the accumulated value.
  8661. * @see _.reduceRight
  8662. * @example
  8663. *
  8664. * _.reduce([1, 2], function(sum, n) {
  8665. * return sum + n;
  8666. * }, 0);
  8667. * // => 3
  8668. *
  8669. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  8670. * (result[value] || (result[value] = [])).push(key);
  8671. * return result;
  8672. * }, {});
  8673. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  8674. */
  8675. function reduce(collection, iteratee, accumulator) {
  8676. var func = isArray(collection) ? arrayReduce : baseReduce,
  8677. initAccum = arguments.length < 3;
  8678. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  8679. }
  8680. /**
  8681. * This method is like `_.reduce` except that it iterates over elements of
  8682. * `collection` from right to left.
  8683. *
  8684. * @static
  8685. * @memberOf _
  8686. * @since 0.1.0
  8687. * @category Collection
  8688. * @param {Array|Object} collection The collection to iterate over.
  8689. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8690. * @param {*} [accumulator] The initial value.
  8691. * @returns {*} Returns the accumulated value.
  8692. * @see _.reduce
  8693. * @example
  8694. *
  8695. * var array = [[0, 1], [2, 3], [4, 5]];
  8696. *
  8697. * _.reduceRight(array, function(flattened, other) {
  8698. * return flattened.concat(other);
  8699. * }, []);
  8700. * // => [4, 5, 2, 3, 0, 1]
  8701. */
  8702. function reduceRight(collection, iteratee, accumulator) {
  8703. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  8704. initAccum = arguments.length < 3;
  8705. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  8706. }
  8707. /**
  8708. * The opposite of `_.filter`; this method returns the elements of `collection`
  8709. * that `predicate` does **not** return truthy for.
  8710. *
  8711. * @static
  8712. * @memberOf _
  8713. * @since 0.1.0
  8714. * @category Collection
  8715. * @param {Array|Object} collection The collection to iterate over.
  8716. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8717. * @returns {Array} Returns the new filtered array.
  8718. * @see _.filter
  8719. * @example
  8720. *
  8721. * var users = [
  8722. * { 'user': 'barney', 'age': 36, 'active': false },
  8723. * { 'user': 'fred', 'age': 40, 'active': true }
  8724. * ];
  8725. *
  8726. * _.reject(users, function(o) { return !o.active; });
  8727. * // => objects for ['fred']
  8728. *
  8729. * // The `_.matches` iteratee shorthand.
  8730. * _.reject(users, { 'age': 40, 'active': true });
  8731. * // => objects for ['barney']
  8732. *
  8733. * // The `_.matchesProperty` iteratee shorthand.
  8734. * _.reject(users, ['active', false]);
  8735. * // => objects for ['fred']
  8736. *
  8737. * // The `_.property` iteratee shorthand.
  8738. * _.reject(users, 'active');
  8739. * // => objects for ['barney']
  8740. */
  8741. function reject(collection, predicate) {
  8742. var func = isArray(collection) ? arrayFilter : baseFilter;
  8743. return func(collection, negate(getIteratee(predicate, 3)));
  8744. }
  8745. /**
  8746. * Gets a random element from `collection`.
  8747. *
  8748. * @static
  8749. * @memberOf _
  8750. * @since 2.0.0
  8751. * @category Collection
  8752. * @param {Array|Object} collection The collection to sample.
  8753. * @returns {*} Returns the random element.
  8754. * @example
  8755. *
  8756. * _.sample([1, 2, 3, 4]);
  8757. * // => 2
  8758. */
  8759. function sample(collection) {
  8760. var array = isArrayLike(collection) ? collection : values(collection),
  8761. length = array.length;
  8762. return length > 0 ? array[baseRandom(0, length - 1)] : undefined;
  8763. }
  8764. /**
  8765. * Gets `n` random elements at unique keys from `collection` up to the
  8766. * size of `collection`.
  8767. *
  8768. * @static
  8769. * @memberOf _
  8770. * @since 4.0.0
  8771. * @category Collection
  8772. * @param {Array|Object} collection The collection to sample.
  8773. * @param {number} [n=1] The number of elements to sample.
  8774. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8775. * @returns {Array} Returns the random elements.
  8776. * @example
  8777. *
  8778. * _.sampleSize([1, 2, 3], 2);
  8779. * // => [3, 1]
  8780. *
  8781. * _.sampleSize([1, 2, 3], 4);
  8782. * // => [2, 3, 1]
  8783. */
  8784. function sampleSize(collection, n, guard) {
  8785. var index = -1,
  8786. result = toArray(collection),
  8787. length = result.length,
  8788. lastIndex = length - 1;
  8789. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  8790. n = 1;
  8791. } else {
  8792. n = baseClamp(toInteger(n), 0, length);
  8793. }
  8794. while (++index < n) {
  8795. var rand = baseRandom(index, lastIndex),
  8796. value = result[rand];
  8797. result[rand] = result[index];
  8798. result[index] = value;
  8799. }
  8800. result.length = n;
  8801. return result;
  8802. }
  8803. /**
  8804. * Creates an array of shuffled values, using a version of the
  8805. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  8806. *
  8807. * @static
  8808. * @memberOf _
  8809. * @since 0.1.0
  8810. * @category Collection
  8811. * @param {Array|Object} collection The collection to shuffle.
  8812. * @returns {Array} Returns the new shuffled array.
  8813. * @example
  8814. *
  8815. * _.shuffle([1, 2, 3, 4]);
  8816. * // => [4, 1, 3, 2]
  8817. */
  8818. function shuffle(collection) {
  8819. return sampleSize(collection, MAX_ARRAY_LENGTH);
  8820. }
  8821. /**
  8822. * Gets the size of `collection` by returning its length for array-like
  8823. * values or the number of own enumerable string keyed properties for objects.
  8824. *
  8825. * @static
  8826. * @memberOf _
  8827. * @since 0.1.0
  8828. * @category Collection
  8829. * @param {Array|Object|string} collection The collection to inspect.
  8830. * @returns {number} Returns the collection size.
  8831. * @example
  8832. *
  8833. * _.size([1, 2, 3]);
  8834. * // => 3
  8835. *
  8836. * _.size({ 'a': 1, 'b': 2 });
  8837. * // => 2
  8838. *
  8839. * _.size('pebbles');
  8840. * // => 7
  8841. */
  8842. function size(collection) {
  8843. if (collection == null) {
  8844. return 0;
  8845. }
  8846. if (isArrayLike(collection)) {
  8847. return isString(collection) ? stringSize(collection) : collection.length;
  8848. }
  8849. var tag = getTag(collection);
  8850. if (tag == mapTag || tag == setTag) {
  8851. return collection.size;
  8852. }
  8853. return baseKeys(collection).length;
  8854. }
  8855. /**
  8856. * Checks if `predicate` returns truthy for **any** element of `collection`.
  8857. * Iteration is stopped once `predicate` returns truthy. The predicate is
  8858. * invoked with three arguments: (value, index|key, collection).
  8859. *
  8860. * @static
  8861. * @memberOf _
  8862. * @since 0.1.0
  8863. * @category Collection
  8864. * @param {Array|Object} collection The collection to iterate over.
  8865. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8866. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8867. * @returns {boolean} Returns `true` if any element passes the predicate check,
  8868. * else `false`.
  8869. * @example
  8870. *
  8871. * _.some([null, 0, 'yes', false], Boolean);
  8872. * // => true
  8873. *
  8874. * var users = [
  8875. * { 'user': 'barney', 'active': true },
  8876. * { 'user': 'fred', 'active': false }
  8877. * ];
  8878. *
  8879. * // The `_.matches` iteratee shorthand.
  8880. * _.some(users, { 'user': 'barney', 'active': false });
  8881. * // => false
  8882. *
  8883. * // The `_.matchesProperty` iteratee shorthand.
  8884. * _.some(users, ['active', false]);
  8885. * // => true
  8886. *
  8887. * // The `_.property` iteratee shorthand.
  8888. * _.some(users, 'active');
  8889. * // => true
  8890. */
  8891. function some(collection, predicate, guard) {
  8892. var func = isArray(collection) ? arraySome : baseSome;
  8893. if (guard && isIterateeCall(collection, predicate, guard)) {
  8894. predicate = undefined;
  8895. }
  8896. return func(collection, getIteratee(predicate, 3));
  8897. }
  8898. /**
  8899. * Creates an array of elements, sorted in ascending order by the results of
  8900. * running each element in a collection thru each iteratee. This method
  8901. * performs a stable sort, that is, it preserves the original sort order of
  8902. * equal elements. The iteratees are invoked with one argument: (value).
  8903. *
  8904. * @static
  8905. * @memberOf _
  8906. * @since 0.1.0
  8907. * @category Collection
  8908. * @param {Array|Object} collection The collection to iterate over.
  8909. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  8910. * The iteratees to sort by.
  8911. * @returns {Array} Returns the new sorted array.
  8912. * @example
  8913. *
  8914. * var users = [
  8915. * { 'user': 'fred', 'age': 48 },
  8916. * { 'user': 'barney', 'age': 36 },
  8917. * { 'user': 'fred', 'age': 40 },
  8918. * { 'user': 'barney', 'age': 34 }
  8919. * ];
  8920. *
  8921. * _.sortBy(users, function(o) { return o.user; });
  8922. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8923. *
  8924. * _.sortBy(users, ['user', 'age']);
  8925. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  8926. *
  8927. * _.sortBy(users, 'user', function(o) {
  8928. * return Math.floor(o.age / 10);
  8929. * });
  8930. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8931. */
  8932. var sortBy = baseRest(function(collection, iteratees) {
  8933. if (collection == null) {
  8934. return [];
  8935. }
  8936. var length = iteratees.length;
  8937. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  8938. iteratees = [];
  8939. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  8940. iteratees = [iteratees[0]];
  8941. }
  8942. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  8943. });
  8944. /*------------------------------------------------------------------------*/
  8945. /**
  8946. * Gets the timestamp of the number of milliseconds that have elapsed since
  8947. * the Unix epoch (1 January 1970 00:00:00 UTC).
  8948. *
  8949. * @static
  8950. * @memberOf _
  8951. * @since 2.4.0
  8952. * @category Date
  8953. * @returns {number} Returns the timestamp.
  8954. * @example
  8955. *
  8956. * _.defer(function(stamp) {
  8957. * console.log(_.now() - stamp);
  8958. * }, _.now());
  8959. * // => Logs the number of milliseconds it took for the deferred invocation.
  8960. */
  8961. var now = ctxNow || function() {
  8962. return root.Date.now();
  8963. };
  8964. /*------------------------------------------------------------------------*/
  8965. /**
  8966. * The opposite of `_.before`; this method creates a function that invokes
  8967. * `func` once it's called `n` or more times.
  8968. *
  8969. * @static
  8970. * @memberOf _
  8971. * @since 0.1.0
  8972. * @category Function
  8973. * @param {number} n The number of calls before `func` is invoked.
  8974. * @param {Function} func The function to restrict.
  8975. * @returns {Function} Returns the new restricted function.
  8976. * @example
  8977. *
  8978. * var saves = ['profile', 'settings'];
  8979. *
  8980. * var done = _.after(saves.length, function() {
  8981. * console.log('done saving!');
  8982. * });
  8983. *
  8984. * _.forEach(saves, function(type) {
  8985. * asyncSave({ 'type': type, 'complete': done });
  8986. * });
  8987. * // => Logs 'done saving!' after the two async saves have completed.
  8988. */
  8989. function after(n, func) {
  8990. if (typeof func != 'function') {
  8991. throw new TypeError(FUNC_ERROR_TEXT);
  8992. }
  8993. n = toInteger(n);
  8994. return function() {
  8995. if (--n < 1) {
  8996. return func.apply(this, arguments);
  8997. }
  8998. };
  8999. }
  9000. /**
  9001. * Creates a function that invokes `func`, with up to `n` arguments,
  9002. * ignoring any additional arguments.
  9003. *
  9004. * @static
  9005. * @memberOf _
  9006. * @since 3.0.0
  9007. * @category Function
  9008. * @param {Function} func The function to cap arguments for.
  9009. * @param {number} [n=func.length] The arity cap.
  9010. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9011. * @returns {Function} Returns the new capped function.
  9012. * @example
  9013. *
  9014. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9015. * // => [6, 8, 10]
  9016. */
  9017. function ary(func, n, guard) {
  9018. n = guard ? undefined : n;
  9019. n = (func && n == null) ? func.length : n;
  9020. return createWrap(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9021. }
  9022. /**
  9023. * Creates a function that invokes `func`, with the `this` binding and arguments
  9024. * of the created function, while it's called less than `n` times. Subsequent
  9025. * calls to the created function return the result of the last `func` invocation.
  9026. *
  9027. * @static
  9028. * @memberOf _
  9029. * @since 3.0.0
  9030. * @category Function
  9031. * @param {number} n The number of calls at which `func` is no longer invoked.
  9032. * @param {Function} func The function to restrict.
  9033. * @returns {Function} Returns the new restricted function.
  9034. * @example
  9035. *
  9036. * jQuery(element).on('click', _.before(5, addContactToList));
  9037. * // => Allows adding up to 4 contacts to the list.
  9038. */
  9039. function before(n, func) {
  9040. var result;
  9041. if (typeof func != 'function') {
  9042. throw new TypeError(FUNC_ERROR_TEXT);
  9043. }
  9044. n = toInteger(n);
  9045. return function() {
  9046. if (--n > 0) {
  9047. result = func.apply(this, arguments);
  9048. }
  9049. if (n <= 1) {
  9050. func = undefined;
  9051. }
  9052. return result;
  9053. };
  9054. }
  9055. /**
  9056. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9057. * and `partials` prepended to the arguments it receives.
  9058. *
  9059. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9060. * may be used as a placeholder for partially applied arguments.
  9061. *
  9062. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9063. * property of bound functions.
  9064. *
  9065. * @static
  9066. * @memberOf _
  9067. * @since 0.1.0
  9068. * @category Function
  9069. * @param {Function} func The function to bind.
  9070. * @param {*} thisArg The `this` binding of `func`.
  9071. * @param {...*} [partials] The arguments to be partially applied.
  9072. * @returns {Function} Returns the new bound function.
  9073. * @example
  9074. *
  9075. * function greet(greeting, punctuation) {
  9076. * return greeting + ' ' + this.user + punctuation;
  9077. * }
  9078. *
  9079. * var object = { 'user': 'fred' };
  9080. *
  9081. * var bound = _.bind(greet, object, 'hi');
  9082. * bound('!');
  9083. * // => 'hi fred!'
  9084. *
  9085. * // Bound with placeholders.
  9086. * var bound = _.bind(greet, object, _, '!');
  9087. * bound('hi');
  9088. * // => 'hi fred!'
  9089. */
  9090. var bind = baseRest(function(func, thisArg, partials) {
  9091. var bitmask = BIND_FLAG;
  9092. if (partials.length) {
  9093. var holders = replaceHolders(partials, getHolder(bind));
  9094. bitmask |= PARTIAL_FLAG;
  9095. }
  9096. return createWrap(func, bitmask, thisArg, partials, holders);
  9097. });
  9098. /**
  9099. * Creates a function that invokes the method at `object[key]` with `partials`
  9100. * prepended to the arguments it receives.
  9101. *
  9102. * This method differs from `_.bind` by allowing bound functions to reference
  9103. * methods that may be redefined or don't yet exist. See
  9104. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9105. * for more details.
  9106. *
  9107. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9108. * builds, may be used as a placeholder for partially applied arguments.
  9109. *
  9110. * @static
  9111. * @memberOf _
  9112. * @since 0.10.0
  9113. * @category Function
  9114. * @param {Object} object The object to invoke the method on.
  9115. * @param {string} key The key of the method.
  9116. * @param {...*} [partials] The arguments to be partially applied.
  9117. * @returns {Function} Returns the new bound function.
  9118. * @example
  9119. *
  9120. * var object = {
  9121. * 'user': 'fred',
  9122. * 'greet': function(greeting, punctuation) {
  9123. * return greeting + ' ' + this.user + punctuation;
  9124. * }
  9125. * };
  9126. *
  9127. * var bound = _.bindKey(object, 'greet', 'hi');
  9128. * bound('!');
  9129. * // => 'hi fred!'
  9130. *
  9131. * object.greet = function(greeting, punctuation) {
  9132. * return greeting + 'ya ' + this.user + punctuation;
  9133. * };
  9134. *
  9135. * bound('!');
  9136. * // => 'hiya fred!'
  9137. *
  9138. * // Bound with placeholders.
  9139. * var bound = _.bindKey(object, 'greet', _, '!');
  9140. * bound('hi');
  9141. * // => 'hiya fred!'
  9142. */
  9143. var bindKey = baseRest(function(object, key, partials) {
  9144. var bitmask = BIND_FLAG | BIND_KEY_FLAG;
  9145. if (partials.length) {
  9146. var holders = replaceHolders(partials, getHolder(bindKey));
  9147. bitmask |= PARTIAL_FLAG;
  9148. }
  9149. return createWrap(key, bitmask, object, partials, holders);
  9150. });
  9151. /**
  9152. * Creates a function that accepts arguments of `func` and either invokes
  9153. * `func` returning its result, if at least `arity` number of arguments have
  9154. * been provided, or returns a function that accepts the remaining `func`
  9155. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9156. * is not sufficient.
  9157. *
  9158. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9159. * may be used as a placeholder for provided arguments.
  9160. *
  9161. * **Note:** This method doesn't set the "length" property of curried functions.
  9162. *
  9163. * @static
  9164. * @memberOf _
  9165. * @since 2.0.0
  9166. * @category Function
  9167. * @param {Function} func The function to curry.
  9168. * @param {number} [arity=func.length] The arity of `func`.
  9169. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9170. * @returns {Function} Returns the new curried function.
  9171. * @example
  9172. *
  9173. * var abc = function(a, b, c) {
  9174. * return [a, b, c];
  9175. * };
  9176. *
  9177. * var curried = _.curry(abc);
  9178. *
  9179. * curried(1)(2)(3);
  9180. * // => [1, 2, 3]
  9181. *
  9182. * curried(1, 2)(3);
  9183. * // => [1, 2, 3]
  9184. *
  9185. * curried(1, 2, 3);
  9186. * // => [1, 2, 3]
  9187. *
  9188. * // Curried with placeholders.
  9189. * curried(1)(_, 3)(2);
  9190. * // => [1, 2, 3]
  9191. */
  9192. function curry(func, arity, guard) {
  9193. arity = guard ? undefined : arity;
  9194. var result = createWrap(func, CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9195. result.placeholder = curry.placeholder;
  9196. return result;
  9197. }
  9198. /**
  9199. * This method is like `_.curry` except that arguments are applied to `func`
  9200. * in the manner of `_.partialRight` instead of `_.partial`.
  9201. *
  9202. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9203. * builds, may be used as a placeholder for provided arguments.
  9204. *
  9205. * **Note:** This method doesn't set the "length" property of curried functions.
  9206. *
  9207. * @static
  9208. * @memberOf _
  9209. * @since 3.0.0
  9210. * @category Function
  9211. * @param {Function} func The function to curry.
  9212. * @param {number} [arity=func.length] The arity of `func`.
  9213. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9214. * @returns {Function} Returns the new curried function.
  9215. * @example
  9216. *
  9217. * var abc = function(a, b, c) {
  9218. * return [a, b, c];
  9219. * };
  9220. *
  9221. * var curried = _.curryRight(abc);
  9222. *
  9223. * curried(3)(2)(1);
  9224. * // => [1, 2, 3]
  9225. *
  9226. * curried(2, 3)(1);
  9227. * // => [1, 2, 3]
  9228. *
  9229. * curried(1, 2, 3);
  9230. * // => [1, 2, 3]
  9231. *
  9232. * // Curried with placeholders.
  9233. * curried(3)(1, _)(2);
  9234. * // => [1, 2, 3]
  9235. */
  9236. function curryRight(func, arity, guard) {
  9237. arity = guard ? undefined : arity;
  9238. var result = createWrap(func, CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9239. result.placeholder = curryRight.placeholder;
  9240. return result;
  9241. }
  9242. /**
  9243. * Creates a debounced function that delays invoking `func` until after `wait`
  9244. * milliseconds have elapsed since the last time the debounced function was
  9245. * invoked. The debounced function comes with a `cancel` method to cancel
  9246. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9247. * Provide `options` to indicate whether `func` should be invoked on the
  9248. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9249. * with the last arguments provided to the debounced function. Subsequent
  9250. * calls to the debounced function return the result of the last `func`
  9251. * invocation.
  9252. *
  9253. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9254. * invoked on the trailing edge of the timeout only if the debounced function
  9255. * is invoked more than once during the `wait` timeout.
  9256. *
  9257. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9258. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9259. *
  9260. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9261. * for details over the differences between `_.debounce` and `_.throttle`.
  9262. *
  9263. * @static
  9264. * @memberOf _
  9265. * @since 0.1.0
  9266. * @category Function
  9267. * @param {Function} func The function to debounce.
  9268. * @param {number} [wait=0] The number of milliseconds to delay.
  9269. * @param {Object} [options={}] The options object.
  9270. * @param {boolean} [options.leading=false]
  9271. * Specify invoking on the leading edge of the timeout.
  9272. * @param {number} [options.maxWait]
  9273. * The maximum time `func` is allowed to be delayed before it's invoked.
  9274. * @param {boolean} [options.trailing=true]
  9275. * Specify invoking on the trailing edge of the timeout.
  9276. * @returns {Function} Returns the new debounced function.
  9277. * @example
  9278. *
  9279. * // Avoid costly calculations while the window size is in flux.
  9280. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9281. *
  9282. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9283. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9284. * 'leading': true,
  9285. * 'trailing': false
  9286. * }));
  9287. *
  9288. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9289. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9290. * var source = new EventSource('/stream');
  9291. * jQuery(source).on('message', debounced);
  9292. *
  9293. * // Cancel the trailing debounced invocation.
  9294. * jQuery(window).on('popstate', debounced.cancel);
  9295. */
  9296. function debounce(func, wait, options) {
  9297. var lastArgs,
  9298. lastThis,
  9299. maxWait,
  9300. result,
  9301. timerId,
  9302. lastCallTime,
  9303. lastInvokeTime = 0,
  9304. leading = false,
  9305. maxing = false,
  9306. trailing = true;
  9307. if (typeof func != 'function') {
  9308. throw new TypeError(FUNC_ERROR_TEXT);
  9309. }
  9310. wait = toNumber(wait) || 0;
  9311. if (isObject(options)) {
  9312. leading = !!options.leading;
  9313. maxing = 'maxWait' in options;
  9314. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9315. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9316. }
  9317. function invokeFunc(time) {
  9318. var args = lastArgs,
  9319. thisArg = lastThis;
  9320. lastArgs = lastThis = undefined;
  9321. lastInvokeTime = time;
  9322. result = func.apply(thisArg, args);
  9323. return result;
  9324. }
  9325. function leadingEdge(time) {
  9326. // Reset any `maxWait` timer.
  9327. lastInvokeTime = time;
  9328. // Start the timer for the trailing edge.
  9329. timerId = setTimeout(timerExpired, wait);
  9330. // Invoke the leading edge.
  9331. return leading ? invokeFunc(time) : result;
  9332. }
  9333. function remainingWait(time) {
  9334. var timeSinceLastCall = time - lastCallTime,
  9335. timeSinceLastInvoke = time - lastInvokeTime,
  9336. result = wait - timeSinceLastCall;
  9337. return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
  9338. }
  9339. function shouldInvoke(time) {
  9340. var timeSinceLastCall = time - lastCallTime,
  9341. timeSinceLastInvoke = time - lastInvokeTime;
  9342. // Either this is the first call, activity has stopped and we're at the
  9343. // trailing edge, the system time has gone backwards and we're treating
  9344. // it as the trailing edge, or we've hit the `maxWait` limit.
  9345. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9346. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9347. }
  9348. function timerExpired() {
  9349. var time = now();
  9350. if (shouldInvoke(time)) {
  9351. return trailingEdge(time);
  9352. }
  9353. // Restart the timer.
  9354. timerId = setTimeout(timerExpired, remainingWait(time));
  9355. }
  9356. function trailingEdge(time) {
  9357. timerId = undefined;
  9358. // Only invoke if we have `lastArgs` which means `func` has been
  9359. // debounced at least once.
  9360. if (trailing && lastArgs) {
  9361. return invokeFunc(time);
  9362. }
  9363. lastArgs = lastThis = undefined;
  9364. return result;
  9365. }
  9366. function cancel() {
  9367. if (timerId !== undefined) {
  9368. clearTimeout(timerId);
  9369. }
  9370. lastInvokeTime = 0;
  9371. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9372. }
  9373. function flush() {
  9374. return timerId === undefined ? result : trailingEdge(now());
  9375. }
  9376. function debounced() {
  9377. var time = now(),
  9378. isInvoking = shouldInvoke(time);
  9379. lastArgs = arguments;
  9380. lastThis = this;
  9381. lastCallTime = time;
  9382. if (isInvoking) {
  9383. if (timerId === undefined) {
  9384. return leadingEdge(lastCallTime);
  9385. }
  9386. if (maxing) {
  9387. // Handle invocations in a tight loop.
  9388. timerId = setTimeout(timerExpired, wait);
  9389. return invokeFunc(lastCallTime);
  9390. }
  9391. }
  9392. if (timerId === undefined) {
  9393. timerId = setTimeout(timerExpired, wait);
  9394. }
  9395. return result;
  9396. }
  9397. debounced.cancel = cancel;
  9398. debounced.flush = flush;
  9399. return debounced;
  9400. }
  9401. /**
  9402. * Defers invoking the `func` until the current call stack has cleared. Any
  9403. * additional arguments are provided to `func` when it's invoked.
  9404. *
  9405. * @static
  9406. * @memberOf _
  9407. * @since 0.1.0
  9408. * @category Function
  9409. * @param {Function} func The function to defer.
  9410. * @param {...*} [args] The arguments to invoke `func` with.
  9411. * @returns {number} Returns the timer id.
  9412. * @example
  9413. *
  9414. * _.defer(function(text) {
  9415. * console.log(text);
  9416. * }, 'deferred');
  9417. * // => Logs 'deferred' after one or more milliseconds.
  9418. */
  9419. var defer = baseRest(function(func, args) {
  9420. return baseDelay(func, 1, args);
  9421. });
  9422. /**
  9423. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9424. * provided to `func` when it's invoked.
  9425. *
  9426. * @static
  9427. * @memberOf _
  9428. * @since 0.1.0
  9429. * @category Function
  9430. * @param {Function} func The function to delay.
  9431. * @param {number} wait The number of milliseconds to delay invocation.
  9432. * @param {...*} [args] The arguments to invoke `func` with.
  9433. * @returns {number} Returns the timer id.
  9434. * @example
  9435. *
  9436. * _.delay(function(text) {
  9437. * console.log(text);
  9438. * }, 1000, 'later');
  9439. * // => Logs 'later' after one second.
  9440. */
  9441. var delay = baseRest(function(func, wait, args) {
  9442. return baseDelay(func, toNumber(wait) || 0, args);
  9443. });
  9444. /**
  9445. * Creates a function that invokes `func` with arguments reversed.
  9446. *
  9447. * @static
  9448. * @memberOf _
  9449. * @since 4.0.0
  9450. * @category Function
  9451. * @param {Function} func The function to flip arguments for.
  9452. * @returns {Function} Returns the new flipped function.
  9453. * @example
  9454. *
  9455. * var flipped = _.flip(function() {
  9456. * return _.toArray(arguments);
  9457. * });
  9458. *
  9459. * flipped('a', 'b', 'c', 'd');
  9460. * // => ['d', 'c', 'b', 'a']
  9461. */
  9462. function flip(func) {
  9463. return createWrap(func, FLIP_FLAG);
  9464. }
  9465. /**
  9466. * Creates a function that memoizes the result of `func`. If `resolver` is
  9467. * provided, it determines the cache key for storing the result based on the
  9468. * arguments provided to the memoized function. By default, the first argument
  9469. * provided to the memoized function is used as the map cache key. The `func`
  9470. * is invoked with the `this` binding of the memoized function.
  9471. *
  9472. * **Note:** The cache is exposed as the `cache` property on the memoized
  9473. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9474. * constructor with one whose instances implement the
  9475. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9476. * method interface of `delete`, `get`, `has`, and `set`.
  9477. *
  9478. * @static
  9479. * @memberOf _
  9480. * @since 0.1.0
  9481. * @category Function
  9482. * @param {Function} func The function to have its output memoized.
  9483. * @param {Function} [resolver] The function to resolve the cache key.
  9484. * @returns {Function} Returns the new memoized function.
  9485. * @example
  9486. *
  9487. * var object = { 'a': 1, 'b': 2 };
  9488. * var other = { 'c': 3, 'd': 4 };
  9489. *
  9490. * var values = _.memoize(_.values);
  9491. * values(object);
  9492. * // => [1, 2]
  9493. *
  9494. * values(other);
  9495. * // => [3, 4]
  9496. *
  9497. * object.a = 2;
  9498. * values(object);
  9499. * // => [1, 2]
  9500. *
  9501. * // Modify the result cache.
  9502. * values.cache.set(object, ['a', 'b']);
  9503. * values(object);
  9504. * // => ['a', 'b']
  9505. *
  9506. * // Replace `_.memoize.Cache`.
  9507. * _.memoize.Cache = WeakMap;
  9508. */
  9509. function memoize(func, resolver) {
  9510. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  9511. throw new TypeError(FUNC_ERROR_TEXT);
  9512. }
  9513. var memoized = function() {
  9514. var args = arguments,
  9515. key = resolver ? resolver.apply(this, args) : args[0],
  9516. cache = memoized.cache;
  9517. if (cache.has(key)) {
  9518. return cache.get(key);
  9519. }
  9520. var result = func.apply(this, args);
  9521. memoized.cache = cache.set(key, result);
  9522. return result;
  9523. };
  9524. memoized.cache = new (memoize.Cache || MapCache);
  9525. return memoized;
  9526. }
  9527. // Assign cache to `_.memoize`.
  9528. memoize.Cache = MapCache;
  9529. /**
  9530. * Creates a function that negates the result of the predicate `func`. The
  9531. * `func` predicate is invoked with the `this` binding and arguments of the
  9532. * created function.
  9533. *
  9534. * @static
  9535. * @memberOf _
  9536. * @since 3.0.0
  9537. * @category Function
  9538. * @param {Function} predicate The predicate to negate.
  9539. * @returns {Function} Returns the new negated function.
  9540. * @example
  9541. *
  9542. * function isEven(n) {
  9543. * return n % 2 == 0;
  9544. * }
  9545. *
  9546. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9547. * // => [1, 3, 5]
  9548. */
  9549. function negate(predicate) {
  9550. if (typeof predicate != 'function') {
  9551. throw new TypeError(FUNC_ERROR_TEXT);
  9552. }
  9553. return function() {
  9554. var args = arguments;
  9555. switch (args.length) {
  9556. case 0: return !predicate.call(this);
  9557. case 1: return !predicate.call(this, args[0]);
  9558. case 2: return !predicate.call(this, args[0], args[1]);
  9559. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9560. }
  9561. return !predicate.apply(this, args);
  9562. };
  9563. }
  9564. /**
  9565. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9566. * to the function return the value of the first invocation. The `func` is
  9567. * invoked with the `this` binding and arguments of the created function.
  9568. *
  9569. * @static
  9570. * @memberOf _
  9571. * @since 0.1.0
  9572. * @category Function
  9573. * @param {Function} func The function to restrict.
  9574. * @returns {Function} Returns the new restricted function.
  9575. * @example
  9576. *
  9577. * var initialize = _.once(createApplication);
  9578. * initialize();
  9579. * initialize();
  9580. * // => `createApplication` is invoked once
  9581. */
  9582. function once(func) {
  9583. return before(2, func);
  9584. }
  9585. /**
  9586. * Creates a function that invokes `func` with its arguments transformed.
  9587. *
  9588. * @static
  9589. * @since 4.0.0
  9590. * @memberOf _
  9591. * @category Function
  9592. * @param {Function} func The function to wrap.
  9593. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9594. * The argument transforms.
  9595. * @returns {Function} Returns the new function.
  9596. * @example
  9597. *
  9598. * function doubled(n) {
  9599. * return n * 2;
  9600. * }
  9601. *
  9602. * function square(n) {
  9603. * return n * n;
  9604. * }
  9605. *
  9606. * var func = _.overArgs(function(x, y) {
  9607. * return [x, y];
  9608. * }, [square, doubled]);
  9609. *
  9610. * func(9, 3);
  9611. * // => [81, 6]
  9612. *
  9613. * func(10, 5);
  9614. * // => [100, 10]
  9615. */
  9616. var overArgs = baseRest(function(func, transforms) {
  9617. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9618. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9619. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9620. var funcsLength = transforms.length;
  9621. return baseRest(function(args) {
  9622. var index = -1,
  9623. length = nativeMin(args.length, funcsLength);
  9624. while (++index < length) {
  9625. args[index] = transforms[index].call(this, args[index]);
  9626. }
  9627. return apply(func, this, args);
  9628. });
  9629. });
  9630. /**
  9631. * Creates a function that invokes `func` with `partials` prepended to the
  9632. * arguments it receives. This method is like `_.bind` except it does **not**
  9633. * alter the `this` binding.
  9634. *
  9635. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9636. * builds, may be used as a placeholder for partially applied arguments.
  9637. *
  9638. * **Note:** This method doesn't set the "length" property of partially
  9639. * applied functions.
  9640. *
  9641. * @static
  9642. * @memberOf _
  9643. * @since 0.2.0
  9644. * @category Function
  9645. * @param {Function} func The function to partially apply arguments to.
  9646. * @param {...*} [partials] The arguments to be partially applied.
  9647. * @returns {Function} Returns the new partially applied function.
  9648. * @example
  9649. *
  9650. * function greet(greeting, name) {
  9651. * return greeting + ' ' + name;
  9652. * }
  9653. *
  9654. * var sayHelloTo = _.partial(greet, 'hello');
  9655. * sayHelloTo('fred');
  9656. * // => 'hello fred'
  9657. *
  9658. * // Partially applied with placeholders.
  9659. * var greetFred = _.partial(greet, _, 'fred');
  9660. * greetFred('hi');
  9661. * // => 'hi fred'
  9662. */
  9663. var partial = baseRest(function(func, partials) {
  9664. var holders = replaceHolders(partials, getHolder(partial));
  9665. return createWrap(func, PARTIAL_FLAG, undefined, partials, holders);
  9666. });
  9667. /**
  9668. * This method is like `_.partial` except that partially applied arguments
  9669. * are appended to the arguments it receives.
  9670. *
  9671. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  9672. * builds, may be used as a placeholder for partially applied arguments.
  9673. *
  9674. * **Note:** This method doesn't set the "length" property of partially
  9675. * applied functions.
  9676. *
  9677. * @static
  9678. * @memberOf _
  9679. * @since 1.0.0
  9680. * @category Function
  9681. * @param {Function} func The function to partially apply arguments to.
  9682. * @param {...*} [partials] The arguments to be partially applied.
  9683. * @returns {Function} Returns the new partially applied function.
  9684. * @example
  9685. *
  9686. * function greet(greeting, name) {
  9687. * return greeting + ' ' + name;
  9688. * }
  9689. *
  9690. * var greetFred = _.partialRight(greet, 'fred');
  9691. * greetFred('hi');
  9692. * // => 'hi fred'
  9693. *
  9694. * // Partially applied with placeholders.
  9695. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  9696. * sayHelloTo('fred');
  9697. * // => 'hello fred'
  9698. */
  9699. var partialRight = baseRest(function(func, partials) {
  9700. var holders = replaceHolders(partials, getHolder(partialRight));
  9701. return createWrap(func, PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  9702. });
  9703. /**
  9704. * Creates a function that invokes `func` with arguments arranged according
  9705. * to the specified `indexes` where the argument value at the first index is
  9706. * provided as the first argument, the argument value at the second index is
  9707. * provided as the second argument, and so on.
  9708. *
  9709. * @static
  9710. * @memberOf _
  9711. * @since 3.0.0
  9712. * @category Function
  9713. * @param {Function} func The function to rearrange arguments for.
  9714. * @param {...(number|number[])} indexes The arranged argument indexes.
  9715. * @returns {Function} Returns the new function.
  9716. * @example
  9717. *
  9718. * var rearged = _.rearg(function(a, b, c) {
  9719. * return [a, b, c];
  9720. * }, [2, 0, 1]);
  9721. *
  9722. * rearged('b', 'c', 'a')
  9723. * // => ['a', 'b', 'c']
  9724. */
  9725. var rearg = baseRest(function(func, indexes) {
  9726. return createWrap(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes, 1));
  9727. });
  9728. /**
  9729. * Creates a function that invokes `func` with the `this` binding of the
  9730. * created function and arguments from `start` and beyond provided as
  9731. * an array.
  9732. *
  9733. * **Note:** This method is based on the
  9734. * [rest parameter](https://mdn.io/rest_parameters).
  9735. *
  9736. * @static
  9737. * @memberOf _
  9738. * @since 4.0.0
  9739. * @category Function
  9740. * @param {Function} func The function to apply a rest parameter to.
  9741. * @param {number} [start=func.length-1] The start position of the rest parameter.
  9742. * @returns {Function} Returns the new function.
  9743. * @example
  9744. *
  9745. * var say = _.rest(function(what, names) {
  9746. * return what + ' ' + _.initial(names).join(', ') +
  9747. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  9748. * });
  9749. *
  9750. * say('hello', 'fred', 'barney', 'pebbles');
  9751. * // => 'hello fred, barney, & pebbles'
  9752. */
  9753. function rest(func, start) {
  9754. if (typeof func != 'function') {
  9755. throw new TypeError(FUNC_ERROR_TEXT);
  9756. }
  9757. start = start === undefined ? start : toInteger(start);
  9758. return baseRest(func, start);
  9759. }
  9760. /**
  9761. * Creates a function that invokes `func` with the `this` binding of the
  9762. * create function and an array of arguments much like
  9763. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  9764. *
  9765. * **Note:** This method is based on the
  9766. * [spread operator](https://mdn.io/spread_operator).
  9767. *
  9768. * @static
  9769. * @memberOf _
  9770. * @since 3.2.0
  9771. * @category Function
  9772. * @param {Function} func The function to spread arguments over.
  9773. * @param {number} [start=0] The start position of the spread.
  9774. * @returns {Function} Returns the new function.
  9775. * @example
  9776. *
  9777. * var say = _.spread(function(who, what) {
  9778. * return who + ' says ' + what;
  9779. * });
  9780. *
  9781. * say(['fred', 'hello']);
  9782. * // => 'fred says hello'
  9783. *
  9784. * var numbers = Promise.all([
  9785. * Promise.resolve(40),
  9786. * Promise.resolve(36)
  9787. * ]);
  9788. *
  9789. * numbers.then(_.spread(function(x, y) {
  9790. * return x + y;
  9791. * }));
  9792. * // => a Promise of 76
  9793. */
  9794. function spread(func, start) {
  9795. if (typeof func != 'function') {
  9796. throw new TypeError(FUNC_ERROR_TEXT);
  9797. }
  9798. start = start === undefined ? 0 : nativeMax(toInteger(start), 0);
  9799. return baseRest(function(args) {
  9800. var array = args[start],
  9801. otherArgs = castSlice(args, 0, start);
  9802. if (array) {
  9803. arrayPush(otherArgs, array);
  9804. }
  9805. return apply(func, this, otherArgs);
  9806. });
  9807. }
  9808. /**
  9809. * Creates a throttled function that only invokes `func` at most once per
  9810. * every `wait` milliseconds. The throttled function comes with a `cancel`
  9811. * method to cancel delayed `func` invocations and a `flush` method to
  9812. * immediately invoke them. Provide `options` to indicate whether `func`
  9813. * should be invoked on the leading and/or trailing edge of the `wait`
  9814. * timeout. The `func` is invoked with the last arguments provided to the
  9815. * throttled function. Subsequent calls to the throttled function return the
  9816. * result of the last `func` invocation.
  9817. *
  9818. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9819. * invoked on the trailing edge of the timeout only if the throttled function
  9820. * is invoked more than once during the `wait` timeout.
  9821. *
  9822. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9823. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9824. *
  9825. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9826. * for details over the differences between `_.throttle` and `_.debounce`.
  9827. *
  9828. * @static
  9829. * @memberOf _
  9830. * @since 0.1.0
  9831. * @category Function
  9832. * @param {Function} func The function to throttle.
  9833. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  9834. * @param {Object} [options={}] The options object.
  9835. * @param {boolean} [options.leading=true]
  9836. * Specify invoking on the leading edge of the timeout.
  9837. * @param {boolean} [options.trailing=true]
  9838. * Specify invoking on the trailing edge of the timeout.
  9839. * @returns {Function} Returns the new throttled function.
  9840. * @example
  9841. *
  9842. * // Avoid excessively updating the position while scrolling.
  9843. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  9844. *
  9845. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  9846. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  9847. * jQuery(element).on('click', throttled);
  9848. *
  9849. * // Cancel the trailing throttled invocation.
  9850. * jQuery(window).on('popstate', throttled.cancel);
  9851. */
  9852. function throttle(func, wait, options) {
  9853. var leading = true,
  9854. trailing = true;
  9855. if (typeof func != 'function') {
  9856. throw new TypeError(FUNC_ERROR_TEXT);
  9857. }
  9858. if (isObject(options)) {
  9859. leading = 'leading' in options ? !!options.leading : leading;
  9860. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9861. }
  9862. return debounce(func, wait, {
  9863. 'leading': leading,
  9864. 'maxWait': wait,
  9865. 'trailing': trailing
  9866. });
  9867. }
  9868. /**
  9869. * Creates a function that accepts up to one argument, ignoring any
  9870. * additional arguments.
  9871. *
  9872. * @static
  9873. * @memberOf _
  9874. * @since 4.0.0
  9875. * @category Function
  9876. * @param {Function} func The function to cap arguments for.
  9877. * @returns {Function} Returns the new capped function.
  9878. * @example
  9879. *
  9880. * _.map(['6', '8', '10'], _.unary(parseInt));
  9881. * // => [6, 8, 10]
  9882. */
  9883. function unary(func) {
  9884. return ary(func, 1);
  9885. }
  9886. /**
  9887. * Creates a function that provides `value` to `wrapper` as its first
  9888. * argument. Any additional arguments provided to the function are appended
  9889. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  9890. * binding of the created function.
  9891. *
  9892. * @static
  9893. * @memberOf _
  9894. * @since 0.1.0
  9895. * @category Function
  9896. * @param {*} value The value to wrap.
  9897. * @param {Function} [wrapper=identity] The wrapper function.
  9898. * @returns {Function} Returns the new function.
  9899. * @example
  9900. *
  9901. * var p = _.wrap(_.escape, function(func, text) {
  9902. * return '<p>' + func(text) + '</p>';
  9903. * });
  9904. *
  9905. * p('fred, barney, & pebbles');
  9906. * // => '<p>fred, barney, &amp; pebbles</p>'
  9907. */
  9908. function wrap(value, wrapper) {
  9909. wrapper = wrapper == null ? identity : wrapper;
  9910. return partial(wrapper, value);
  9911. }
  9912. /*------------------------------------------------------------------------*/
  9913. /**
  9914. * Casts `value` as an array if it's not one.
  9915. *
  9916. * @static
  9917. * @memberOf _
  9918. * @since 4.4.0
  9919. * @category Lang
  9920. * @param {*} value The value to inspect.
  9921. * @returns {Array} Returns the cast array.
  9922. * @example
  9923. *
  9924. * _.castArray(1);
  9925. * // => [1]
  9926. *
  9927. * _.castArray({ 'a': 1 });
  9928. * // => [{ 'a': 1 }]
  9929. *
  9930. * _.castArray('abc');
  9931. * // => ['abc']
  9932. *
  9933. * _.castArray(null);
  9934. * // => [null]
  9935. *
  9936. * _.castArray(undefined);
  9937. * // => [undefined]
  9938. *
  9939. * _.castArray();
  9940. * // => []
  9941. *
  9942. * var array = [1, 2, 3];
  9943. * console.log(_.castArray(array) === array);
  9944. * // => true
  9945. */
  9946. function castArray() {
  9947. if (!arguments.length) {
  9948. return [];
  9949. }
  9950. var value = arguments[0];
  9951. return isArray(value) ? value : [value];
  9952. }
  9953. /**
  9954. * Creates a shallow clone of `value`.
  9955. *
  9956. * **Note:** This method is loosely based on the
  9957. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  9958. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  9959. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  9960. * arrays. The own enumerable properties of `arguments` objects are cloned
  9961. * as plain objects. An empty object is returned for uncloneable values such
  9962. * as error objects, functions, DOM nodes, and WeakMaps.
  9963. *
  9964. * @static
  9965. * @memberOf _
  9966. * @since 0.1.0
  9967. * @category Lang
  9968. * @param {*} value The value to clone.
  9969. * @returns {*} Returns the cloned value.
  9970. * @see _.cloneDeep
  9971. * @example
  9972. *
  9973. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  9974. *
  9975. * var shallow = _.clone(objects);
  9976. * console.log(shallow[0] === objects[0]);
  9977. * // => true
  9978. */
  9979. function clone(value) {
  9980. return baseClone(value, false, true);
  9981. }
  9982. /**
  9983. * This method is like `_.clone` except that it accepts `customizer` which
  9984. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  9985. * cloning is handled by the method instead. The `customizer` is invoked with
  9986. * up to four arguments; (value [, index|key, object, stack]).
  9987. *
  9988. * @static
  9989. * @memberOf _
  9990. * @since 4.0.0
  9991. * @category Lang
  9992. * @param {*} value The value to clone.
  9993. * @param {Function} [customizer] The function to customize cloning.
  9994. * @returns {*} Returns the cloned value.
  9995. * @see _.cloneDeepWith
  9996. * @example
  9997. *
  9998. * function customizer(value) {
  9999. * if (_.isElement(value)) {
  10000. * return value.cloneNode(false);
  10001. * }
  10002. * }
  10003. *
  10004. * var el = _.cloneWith(document.body, customizer);
  10005. *
  10006. * console.log(el === document.body);
  10007. * // => false
  10008. * console.log(el.nodeName);
  10009. * // => 'BODY'
  10010. * console.log(el.childNodes.length);
  10011. * // => 0
  10012. */
  10013. function cloneWith(value, customizer) {
  10014. return baseClone(value, false, true, customizer);
  10015. }
  10016. /**
  10017. * This method is like `_.clone` except that it recursively clones `value`.
  10018. *
  10019. * @static
  10020. * @memberOf _
  10021. * @since 1.0.0
  10022. * @category Lang
  10023. * @param {*} value The value to recursively clone.
  10024. * @returns {*} Returns the deep cloned value.
  10025. * @see _.clone
  10026. * @example
  10027. *
  10028. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10029. *
  10030. * var deep = _.cloneDeep(objects);
  10031. * console.log(deep[0] === objects[0]);
  10032. * // => false
  10033. */
  10034. function cloneDeep(value) {
  10035. return baseClone(value, true, true);
  10036. }
  10037. /**
  10038. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10039. *
  10040. * @static
  10041. * @memberOf _
  10042. * @since 4.0.0
  10043. * @category Lang
  10044. * @param {*} value The value to recursively clone.
  10045. * @param {Function} [customizer] The function to customize cloning.
  10046. * @returns {*} Returns the deep cloned value.
  10047. * @see _.cloneWith
  10048. * @example
  10049. *
  10050. * function customizer(value) {
  10051. * if (_.isElement(value)) {
  10052. * return value.cloneNode(true);
  10053. * }
  10054. * }
  10055. *
  10056. * var el = _.cloneDeepWith(document.body, customizer);
  10057. *
  10058. * console.log(el === document.body);
  10059. * // => false
  10060. * console.log(el.nodeName);
  10061. * // => 'BODY'
  10062. * console.log(el.childNodes.length);
  10063. * // => 20
  10064. */
  10065. function cloneDeepWith(value, customizer) {
  10066. return baseClone(value, true, true, customizer);
  10067. }
  10068. /**
  10069. * Checks if `object` conforms to `source` by invoking the predicate
  10070. * properties of `source` with the corresponding property values of `object`.
  10071. *
  10072. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10073. * partially applied.
  10074. *
  10075. * @static
  10076. * @memberOf _
  10077. * @since 4.14.0
  10078. * @category Lang
  10079. * @param {Object} object The object to inspect.
  10080. * @param {Object} source The object of property predicates to conform to.
  10081. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10082. * @example
  10083. *
  10084. * var object = { 'a': 1, 'b': 2 };
  10085. *
  10086. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10087. * // => true
  10088. *
  10089. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10090. * // => false
  10091. */
  10092. function conformsTo(object, source) {
  10093. return source == null || baseConformsTo(object, source, keys(source));
  10094. }
  10095. /**
  10096. * Performs a
  10097. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10098. * comparison between two values to determine if they are equivalent.
  10099. *
  10100. * @static
  10101. * @memberOf _
  10102. * @since 4.0.0
  10103. * @category Lang
  10104. * @param {*} value The value to compare.
  10105. * @param {*} other The other value to compare.
  10106. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10107. * @example
  10108. *
  10109. * var object = { 'a': 1 };
  10110. * var other = { 'a': 1 };
  10111. *
  10112. * _.eq(object, object);
  10113. * // => true
  10114. *
  10115. * _.eq(object, other);
  10116. * // => false
  10117. *
  10118. * _.eq('a', 'a');
  10119. * // => true
  10120. *
  10121. * _.eq('a', Object('a'));
  10122. * // => false
  10123. *
  10124. * _.eq(NaN, NaN);
  10125. * // => true
  10126. */
  10127. function eq(value, other) {
  10128. return value === other || (value !== value && other !== other);
  10129. }
  10130. /**
  10131. * Checks if `value` is greater than `other`.
  10132. *
  10133. * @static
  10134. * @memberOf _
  10135. * @since 3.9.0
  10136. * @category Lang
  10137. * @param {*} value The value to compare.
  10138. * @param {*} other The other value to compare.
  10139. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10140. * else `false`.
  10141. * @see _.lt
  10142. * @example
  10143. *
  10144. * _.gt(3, 1);
  10145. * // => true
  10146. *
  10147. * _.gt(3, 3);
  10148. * // => false
  10149. *
  10150. * _.gt(1, 3);
  10151. * // => false
  10152. */
  10153. var gt = createRelationalOperation(baseGt);
  10154. /**
  10155. * Checks if `value` is greater than or equal to `other`.
  10156. *
  10157. * @static
  10158. * @memberOf _
  10159. * @since 3.9.0
  10160. * @category Lang
  10161. * @param {*} value The value to compare.
  10162. * @param {*} other The other value to compare.
  10163. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10164. * `other`, else `false`.
  10165. * @see _.lte
  10166. * @example
  10167. *
  10168. * _.gte(3, 1);
  10169. * // => true
  10170. *
  10171. * _.gte(3, 3);
  10172. * // => true
  10173. *
  10174. * _.gte(1, 3);
  10175. * // => false
  10176. */
  10177. var gte = createRelationalOperation(function(value, other) {
  10178. return value >= other;
  10179. });
  10180. /**
  10181. * Checks if `value` is likely an `arguments` object.
  10182. *
  10183. * @static
  10184. * @memberOf _
  10185. * @since 0.1.0
  10186. * @category Lang
  10187. * @param {*} value The value to check.
  10188. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10189. * else `false`.
  10190. * @example
  10191. *
  10192. * _.isArguments(function() { return arguments; }());
  10193. * // => true
  10194. *
  10195. * _.isArguments([1, 2, 3]);
  10196. * // => false
  10197. */
  10198. function isArguments(value) {
  10199. // Safari 8.1 makes `arguments.callee` enumerable in strict mode.
  10200. return isArrayLikeObject(value) && hasOwnProperty.call(value, 'callee') &&
  10201. (!propertyIsEnumerable.call(value, 'callee') || objectToString.call(value) == argsTag);
  10202. }
  10203. /**
  10204. * Checks if `value` is classified as an `Array` object.
  10205. *
  10206. * @static
  10207. * @memberOf _
  10208. * @since 0.1.0
  10209. * @category Lang
  10210. * @param {*} value The value to check.
  10211. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10212. * @example
  10213. *
  10214. * _.isArray([1, 2, 3]);
  10215. * // => true
  10216. *
  10217. * _.isArray(document.body.children);
  10218. * // => false
  10219. *
  10220. * _.isArray('abc');
  10221. * // => false
  10222. *
  10223. * _.isArray(_.noop);
  10224. * // => false
  10225. */
  10226. var isArray = Array.isArray;
  10227. /**
  10228. * Checks if `value` is classified as an `ArrayBuffer` object.
  10229. *
  10230. * @static
  10231. * @memberOf _
  10232. * @since 4.3.0
  10233. * @category Lang
  10234. * @param {*} value The value to check.
  10235. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10236. * @example
  10237. *
  10238. * _.isArrayBuffer(new ArrayBuffer(2));
  10239. * // => true
  10240. *
  10241. * _.isArrayBuffer(new Array(2));
  10242. * // => false
  10243. */
  10244. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10245. /**
  10246. * Checks if `value` is array-like. A value is considered array-like if it's
  10247. * not a function and has a `value.length` that's an integer greater than or
  10248. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10249. *
  10250. * @static
  10251. * @memberOf _
  10252. * @since 4.0.0
  10253. * @category Lang
  10254. * @param {*} value The value to check.
  10255. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10256. * @example
  10257. *
  10258. * _.isArrayLike([1, 2, 3]);
  10259. * // => true
  10260. *
  10261. * _.isArrayLike(document.body.children);
  10262. * // => true
  10263. *
  10264. * _.isArrayLike('abc');
  10265. * // => true
  10266. *
  10267. * _.isArrayLike(_.noop);
  10268. * // => false
  10269. */
  10270. function isArrayLike(value) {
  10271. return value != null && isLength(value.length) && !isFunction(value);
  10272. }
  10273. /**
  10274. * This method is like `_.isArrayLike` except that it also checks if `value`
  10275. * is an object.
  10276. *
  10277. * @static
  10278. * @memberOf _
  10279. * @since 4.0.0
  10280. * @category Lang
  10281. * @param {*} value The value to check.
  10282. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10283. * else `false`.
  10284. * @example
  10285. *
  10286. * _.isArrayLikeObject([1, 2, 3]);
  10287. * // => true
  10288. *
  10289. * _.isArrayLikeObject(document.body.children);
  10290. * // => true
  10291. *
  10292. * _.isArrayLikeObject('abc');
  10293. * // => false
  10294. *
  10295. * _.isArrayLikeObject(_.noop);
  10296. * // => false
  10297. */
  10298. function isArrayLikeObject(value) {
  10299. return isObjectLike(value) && isArrayLike(value);
  10300. }
  10301. /**
  10302. * Checks if `value` is classified as a boolean primitive or object.
  10303. *
  10304. * @static
  10305. * @memberOf _
  10306. * @since 0.1.0
  10307. * @category Lang
  10308. * @param {*} value The value to check.
  10309. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10310. * @example
  10311. *
  10312. * _.isBoolean(false);
  10313. * // => true
  10314. *
  10315. * _.isBoolean(null);
  10316. * // => false
  10317. */
  10318. function isBoolean(value) {
  10319. return value === true || value === false ||
  10320. (isObjectLike(value) && objectToString.call(value) == boolTag);
  10321. }
  10322. /**
  10323. * Checks if `value` is a buffer.
  10324. *
  10325. * @static
  10326. * @memberOf _
  10327. * @since 4.3.0
  10328. * @category Lang
  10329. * @param {*} value The value to check.
  10330. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10331. * @example
  10332. *
  10333. * _.isBuffer(new Buffer(2));
  10334. * // => true
  10335. *
  10336. * _.isBuffer(new Uint8Array(2));
  10337. * // => false
  10338. */
  10339. var isBuffer = nativeIsBuffer || stubFalse;
  10340. /**
  10341. * Checks if `value` is classified as a `Date` object.
  10342. *
  10343. * @static
  10344. * @memberOf _
  10345. * @since 0.1.0
  10346. * @category Lang
  10347. * @param {*} value The value to check.
  10348. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10349. * @example
  10350. *
  10351. * _.isDate(new Date);
  10352. * // => true
  10353. *
  10354. * _.isDate('Mon April 23 2012');
  10355. * // => false
  10356. */
  10357. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10358. /**
  10359. * Checks if `value` is likely a DOM element.
  10360. *
  10361. * @static
  10362. * @memberOf _
  10363. * @since 0.1.0
  10364. * @category Lang
  10365. * @param {*} value The value to check.
  10366. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10367. * @example
  10368. *
  10369. * _.isElement(document.body);
  10370. * // => true
  10371. *
  10372. * _.isElement('<body>');
  10373. * // => false
  10374. */
  10375. function isElement(value) {
  10376. return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
  10377. }
  10378. /**
  10379. * Checks if `value` is an empty object, collection, map, or set.
  10380. *
  10381. * Objects are considered empty if they have no own enumerable string keyed
  10382. * properties.
  10383. *
  10384. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10385. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10386. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10387. *
  10388. * @static
  10389. * @memberOf _
  10390. * @since 0.1.0
  10391. * @category Lang
  10392. * @param {*} value The value to check.
  10393. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10394. * @example
  10395. *
  10396. * _.isEmpty(null);
  10397. * // => true
  10398. *
  10399. * _.isEmpty(true);
  10400. * // => true
  10401. *
  10402. * _.isEmpty(1);
  10403. * // => true
  10404. *
  10405. * _.isEmpty([1, 2, 3]);
  10406. * // => false
  10407. *
  10408. * _.isEmpty({ 'a': 1 });
  10409. * // => false
  10410. */
  10411. function isEmpty(value) {
  10412. if (isArrayLike(value) &&
  10413. (isArray(value) || typeof value == 'string' ||
  10414. typeof value.splice == 'function' || isBuffer(value) || isArguments(value))) {
  10415. return !value.length;
  10416. }
  10417. var tag = getTag(value);
  10418. if (tag == mapTag || tag == setTag) {
  10419. return !value.size;
  10420. }
  10421. if (nonEnumShadows || isPrototype(value)) {
  10422. return !nativeKeys(value).length;
  10423. }
  10424. for (var key in value) {
  10425. if (hasOwnProperty.call(value, key)) {
  10426. return false;
  10427. }
  10428. }
  10429. return true;
  10430. }
  10431. /**
  10432. * Performs a deep comparison between two values to determine if they are
  10433. * equivalent.
  10434. *
  10435. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10436. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10437. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10438. * by their own, not inherited, enumerable properties. Functions and DOM
  10439. * nodes are **not** supported.
  10440. *
  10441. * @static
  10442. * @memberOf _
  10443. * @since 0.1.0
  10444. * @category Lang
  10445. * @param {*} value The value to compare.
  10446. * @param {*} other The other value to compare.
  10447. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10448. * @example
  10449. *
  10450. * var object = { 'a': 1 };
  10451. * var other = { 'a': 1 };
  10452. *
  10453. * _.isEqual(object, other);
  10454. * // => true
  10455. *
  10456. * object === other;
  10457. * // => false
  10458. */
  10459. function isEqual(value, other) {
  10460. return baseIsEqual(value, other);
  10461. }
  10462. /**
  10463. * This method is like `_.isEqual` except that it accepts `customizer` which
  10464. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10465. * are handled by the method instead. The `customizer` is invoked with up to
  10466. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10467. *
  10468. * @static
  10469. * @memberOf _
  10470. * @since 4.0.0
  10471. * @category Lang
  10472. * @param {*} value The value to compare.
  10473. * @param {*} other The other value to compare.
  10474. * @param {Function} [customizer] The function to customize comparisons.
  10475. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10476. * @example
  10477. *
  10478. * function isGreeting(value) {
  10479. * return /^h(?:i|ello)$/.test(value);
  10480. * }
  10481. *
  10482. * function customizer(objValue, othValue) {
  10483. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10484. * return true;
  10485. * }
  10486. * }
  10487. *
  10488. * var array = ['hello', 'goodbye'];
  10489. * var other = ['hi', 'goodbye'];
  10490. *
  10491. * _.isEqualWith(array, other, customizer);
  10492. * // => true
  10493. */
  10494. function isEqualWith(value, other, customizer) {
  10495. customizer = typeof customizer == 'function' ? customizer : undefined;
  10496. var result = customizer ? customizer(value, other) : undefined;
  10497. return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
  10498. }
  10499. /**
  10500. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10501. * `SyntaxError`, `TypeError`, or `URIError` object.
  10502. *
  10503. * @static
  10504. * @memberOf _
  10505. * @since 3.0.0
  10506. * @category Lang
  10507. * @param {*} value The value to check.
  10508. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10509. * @example
  10510. *
  10511. * _.isError(new Error);
  10512. * // => true
  10513. *
  10514. * _.isError(Error);
  10515. * // => false
  10516. */
  10517. function isError(value) {
  10518. if (!isObjectLike(value)) {
  10519. return false;
  10520. }
  10521. return (objectToString.call(value) == errorTag) ||
  10522. (typeof value.message == 'string' && typeof value.name == 'string');
  10523. }
  10524. /**
  10525. * Checks if `value` is a finite primitive number.
  10526. *
  10527. * **Note:** This method is based on
  10528. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10529. *
  10530. * @static
  10531. * @memberOf _
  10532. * @since 0.1.0
  10533. * @category Lang
  10534. * @param {*} value The value to check.
  10535. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10536. * @example
  10537. *
  10538. * _.isFinite(3);
  10539. * // => true
  10540. *
  10541. * _.isFinite(Number.MIN_VALUE);
  10542. * // => true
  10543. *
  10544. * _.isFinite(Infinity);
  10545. * // => false
  10546. *
  10547. * _.isFinite('3');
  10548. * // => false
  10549. */
  10550. function isFinite(value) {
  10551. return typeof value == 'number' && nativeIsFinite(value);
  10552. }
  10553. /**
  10554. * Checks if `value` is classified as a `Function` object.
  10555. *
  10556. * @static
  10557. * @memberOf _
  10558. * @since 0.1.0
  10559. * @category Lang
  10560. * @param {*} value The value to check.
  10561. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10562. * @example
  10563. *
  10564. * _.isFunction(_);
  10565. * // => true
  10566. *
  10567. * _.isFunction(/abc/);
  10568. * // => false
  10569. */
  10570. function isFunction(value) {
  10571. // The use of `Object#toString` avoids issues with the `typeof` operator
  10572. // in Safari 8-9 which returns 'object' for typed array and other constructors.
  10573. var tag = isObject(value) ? objectToString.call(value) : '';
  10574. return tag == funcTag || tag == genTag;
  10575. }
  10576. /**
  10577. * Checks if `value` is an integer.
  10578. *
  10579. * **Note:** This method is based on
  10580. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10581. *
  10582. * @static
  10583. * @memberOf _
  10584. * @since 4.0.0
  10585. * @category Lang
  10586. * @param {*} value The value to check.
  10587. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10588. * @example
  10589. *
  10590. * _.isInteger(3);
  10591. * // => true
  10592. *
  10593. * _.isInteger(Number.MIN_VALUE);
  10594. * // => false
  10595. *
  10596. * _.isInteger(Infinity);
  10597. * // => false
  10598. *
  10599. * _.isInteger('3');
  10600. * // => false
  10601. */
  10602. function isInteger(value) {
  10603. return typeof value == 'number' && value == toInteger(value);
  10604. }
  10605. /**
  10606. * Checks if `value` is a valid array-like length.
  10607. *
  10608. * **Note:** This method is loosely based on
  10609. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10610. *
  10611. * @static
  10612. * @memberOf _
  10613. * @since 4.0.0
  10614. * @category Lang
  10615. * @param {*} value The value to check.
  10616. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10617. * @example
  10618. *
  10619. * _.isLength(3);
  10620. * // => true
  10621. *
  10622. * _.isLength(Number.MIN_VALUE);
  10623. * // => false
  10624. *
  10625. * _.isLength(Infinity);
  10626. * // => false
  10627. *
  10628. * _.isLength('3');
  10629. * // => false
  10630. */
  10631. function isLength(value) {
  10632. return typeof value == 'number' &&
  10633. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10634. }
  10635. /**
  10636. * Checks if `value` is the
  10637. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10638. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  10639. *
  10640. * @static
  10641. * @memberOf _
  10642. * @since 0.1.0
  10643. * @category Lang
  10644. * @param {*} value The value to check.
  10645. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  10646. * @example
  10647. *
  10648. * _.isObject({});
  10649. * // => true
  10650. *
  10651. * _.isObject([1, 2, 3]);
  10652. * // => true
  10653. *
  10654. * _.isObject(_.noop);
  10655. * // => true
  10656. *
  10657. * _.isObject(null);
  10658. * // => false
  10659. */
  10660. function isObject(value) {
  10661. var type = typeof value;
  10662. return !!value && (type == 'object' || type == 'function');
  10663. }
  10664. /**
  10665. * Checks if `value` is object-like. A value is object-like if it's not `null`
  10666. * and has a `typeof` result of "object".
  10667. *
  10668. * @static
  10669. * @memberOf _
  10670. * @since 4.0.0
  10671. * @category Lang
  10672. * @param {*} value The value to check.
  10673. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  10674. * @example
  10675. *
  10676. * _.isObjectLike({});
  10677. * // => true
  10678. *
  10679. * _.isObjectLike([1, 2, 3]);
  10680. * // => true
  10681. *
  10682. * _.isObjectLike(_.noop);
  10683. * // => false
  10684. *
  10685. * _.isObjectLike(null);
  10686. * // => false
  10687. */
  10688. function isObjectLike(value) {
  10689. return !!value && typeof value == 'object';
  10690. }
  10691. /**
  10692. * Checks if `value` is classified as a `Map` object.
  10693. *
  10694. * @static
  10695. * @memberOf _
  10696. * @since 4.3.0
  10697. * @category Lang
  10698. * @param {*} value The value to check.
  10699. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  10700. * @example
  10701. *
  10702. * _.isMap(new Map);
  10703. * // => true
  10704. *
  10705. * _.isMap(new WeakMap);
  10706. * // => false
  10707. */
  10708. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  10709. /**
  10710. * Performs a partial deep comparison between `object` and `source` to
  10711. * determine if `object` contains equivalent property values.
  10712. *
  10713. * **Note:** This method is equivalent to `_.matches` when `source` is
  10714. * partially applied.
  10715. *
  10716. * Partial comparisons will match empty array and empty object `source`
  10717. * values against any array or object value, respectively. See `_.isEqual`
  10718. * for a list of supported value comparisons.
  10719. *
  10720. * @static
  10721. * @memberOf _
  10722. * @since 3.0.0
  10723. * @category Lang
  10724. * @param {Object} object The object to inspect.
  10725. * @param {Object} source The object of property values to match.
  10726. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  10727. * @example
  10728. *
  10729. * var object = { 'a': 1, 'b': 2 };
  10730. *
  10731. * _.isMatch(object, { 'b': 2 });
  10732. * // => true
  10733. *
  10734. * _.isMatch(object, { 'b': 1 });
  10735. * // => false
  10736. */
  10737. function isMatch(object, source) {
  10738. return object === source || baseIsMatch(object, source, getMatchData(source));
  10739. }
  10740. /**
  10741. * This method is like `_.isMatch` except that it accepts `customizer` which
  10742. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10743. * are handled by the method instead. The `customizer` is invoked with five
  10744. * arguments: (objValue, srcValue, index|key, object, source).
  10745. *
  10746. * @static
  10747. * @memberOf _
  10748. * @since 4.0.0
  10749. * @category Lang
  10750. * @param {Object} object The object to inspect.
  10751. * @param {Object} source The object of property values to match.
  10752. * @param {Function} [customizer] The function to customize comparisons.
  10753. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  10754. * @example
  10755. *
  10756. * function isGreeting(value) {
  10757. * return /^h(?:i|ello)$/.test(value);
  10758. * }
  10759. *
  10760. * function customizer(objValue, srcValue) {
  10761. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  10762. * return true;
  10763. * }
  10764. * }
  10765. *
  10766. * var object = { 'greeting': 'hello' };
  10767. * var source = { 'greeting': 'hi' };
  10768. *
  10769. * _.isMatchWith(object, source, customizer);
  10770. * // => true
  10771. */
  10772. function isMatchWith(object, source, customizer) {
  10773. customizer = typeof customizer == 'function' ? customizer : undefined;
  10774. return baseIsMatch(object, source, getMatchData(source), customizer);
  10775. }
  10776. /**
  10777. * Checks if `value` is `NaN`.
  10778. *
  10779. * **Note:** This method is based on
  10780. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  10781. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  10782. * `undefined` and other non-number values.
  10783. *
  10784. * @static
  10785. * @memberOf _
  10786. * @since 0.1.0
  10787. * @category Lang
  10788. * @param {*} value The value to check.
  10789. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  10790. * @example
  10791. *
  10792. * _.isNaN(NaN);
  10793. * // => true
  10794. *
  10795. * _.isNaN(new Number(NaN));
  10796. * // => true
  10797. *
  10798. * isNaN(undefined);
  10799. * // => true
  10800. *
  10801. * _.isNaN(undefined);
  10802. * // => false
  10803. */
  10804. function isNaN(value) {
  10805. // An `NaN` primitive is the only value that is not equal to itself.
  10806. // Perform the `toStringTag` check first to avoid errors with some
  10807. // ActiveX objects in IE.
  10808. return isNumber(value) && value != +value;
  10809. }
  10810. /**
  10811. * Checks if `value` is a pristine native function.
  10812. *
  10813. * **Note:** This method can't reliably detect native functions in the presence
  10814. * of the core-js package because core-js circumvents this kind of detection.
  10815. * Despite multiple requests, the core-js maintainer has made it clear: any
  10816. * attempt to fix the detection will be obstructed. As a result, we're left
  10817. * with little choice but to throw an error. Unfortunately, this also affects
  10818. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  10819. * which rely on core-js.
  10820. *
  10821. * @static
  10822. * @memberOf _
  10823. * @since 3.0.0
  10824. * @category Lang
  10825. * @param {*} value The value to check.
  10826. * @returns {boolean} Returns `true` if `value` is a native function,
  10827. * else `false`.
  10828. * @example
  10829. *
  10830. * _.isNative(Array.prototype.push);
  10831. * // => true
  10832. *
  10833. * _.isNative(_);
  10834. * // => false
  10835. */
  10836. function isNative(value) {
  10837. if (isMaskable(value)) {
  10838. throw new Error('This method is not supported with core-js. Try https://github.com/es-shims.');
  10839. }
  10840. return baseIsNative(value);
  10841. }
  10842. /**
  10843. * Checks if `value` is `null`.
  10844. *
  10845. * @static
  10846. * @memberOf _
  10847. * @since 0.1.0
  10848. * @category Lang
  10849. * @param {*} value The value to check.
  10850. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  10851. * @example
  10852. *
  10853. * _.isNull(null);
  10854. * // => true
  10855. *
  10856. * _.isNull(void 0);
  10857. * // => false
  10858. */
  10859. function isNull(value) {
  10860. return value === null;
  10861. }
  10862. /**
  10863. * Checks if `value` is `null` or `undefined`.
  10864. *
  10865. * @static
  10866. * @memberOf _
  10867. * @since 4.0.0
  10868. * @category Lang
  10869. * @param {*} value The value to check.
  10870. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  10871. * @example
  10872. *
  10873. * _.isNil(null);
  10874. * // => true
  10875. *
  10876. * _.isNil(void 0);
  10877. * // => true
  10878. *
  10879. * _.isNil(NaN);
  10880. * // => false
  10881. */
  10882. function isNil(value) {
  10883. return value == null;
  10884. }
  10885. /**
  10886. * Checks if `value` is classified as a `Number` primitive or object.
  10887. *
  10888. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  10889. * classified as numbers, use the `_.isFinite` method.
  10890. *
  10891. * @static
  10892. * @memberOf _
  10893. * @since 0.1.0
  10894. * @category Lang
  10895. * @param {*} value The value to check.
  10896. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  10897. * @example
  10898. *
  10899. * _.isNumber(3);
  10900. * // => true
  10901. *
  10902. * _.isNumber(Number.MIN_VALUE);
  10903. * // => true
  10904. *
  10905. * _.isNumber(Infinity);
  10906. * // => true
  10907. *
  10908. * _.isNumber('3');
  10909. * // => false
  10910. */
  10911. function isNumber(value) {
  10912. return typeof value == 'number' ||
  10913. (isObjectLike(value) && objectToString.call(value) == numberTag);
  10914. }
  10915. /**
  10916. * Checks if `value` is a plain object, that is, an object created by the
  10917. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  10918. *
  10919. * @static
  10920. * @memberOf _
  10921. * @since 0.8.0
  10922. * @category Lang
  10923. * @param {*} value The value to check.
  10924. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  10925. * @example
  10926. *
  10927. * function Foo() {
  10928. * this.a = 1;
  10929. * }
  10930. *
  10931. * _.isPlainObject(new Foo);
  10932. * // => false
  10933. *
  10934. * _.isPlainObject([1, 2, 3]);
  10935. * // => false
  10936. *
  10937. * _.isPlainObject({ 'x': 0, 'y': 0 });
  10938. * // => true
  10939. *
  10940. * _.isPlainObject(Object.create(null));
  10941. * // => true
  10942. */
  10943. function isPlainObject(value) {
  10944. if (!isObjectLike(value) ||
  10945. objectToString.call(value) != objectTag || isHostObject(value)) {
  10946. return false;
  10947. }
  10948. var proto = getPrototype(value);
  10949. if (proto === null) {
  10950. return true;
  10951. }
  10952. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  10953. return (typeof Ctor == 'function' &&
  10954. Ctor instanceof Ctor && funcToString.call(Ctor) == objectCtorString);
  10955. }
  10956. /**
  10957. * Checks if `value` is classified as a `RegExp` object.
  10958. *
  10959. * @static
  10960. * @memberOf _
  10961. * @since 0.1.0
  10962. * @category Lang
  10963. * @param {*} value The value to check.
  10964. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  10965. * @example
  10966. *
  10967. * _.isRegExp(/abc/);
  10968. * // => true
  10969. *
  10970. * _.isRegExp('/abc/');
  10971. * // => false
  10972. */
  10973. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  10974. /**
  10975. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  10976. * double precision number which isn't the result of a rounded unsafe integer.
  10977. *
  10978. * **Note:** This method is based on
  10979. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  10980. *
  10981. * @static
  10982. * @memberOf _
  10983. * @since 4.0.0
  10984. * @category Lang
  10985. * @param {*} value The value to check.
  10986. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  10987. * @example
  10988. *
  10989. * _.isSafeInteger(3);
  10990. * // => true
  10991. *
  10992. * _.isSafeInteger(Number.MIN_VALUE);
  10993. * // => false
  10994. *
  10995. * _.isSafeInteger(Infinity);
  10996. * // => false
  10997. *
  10998. * _.isSafeInteger('3');
  10999. * // => false
  11000. */
  11001. function isSafeInteger(value) {
  11002. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11003. }
  11004. /**
  11005. * Checks if `value` is classified as a `Set` object.
  11006. *
  11007. * @static
  11008. * @memberOf _
  11009. * @since 4.3.0
  11010. * @category Lang
  11011. * @param {*} value The value to check.
  11012. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11013. * @example
  11014. *
  11015. * _.isSet(new Set);
  11016. * // => true
  11017. *
  11018. * _.isSet(new WeakSet);
  11019. * // => false
  11020. */
  11021. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11022. /**
  11023. * Checks if `value` is classified as a `String` primitive or object.
  11024. *
  11025. * @static
  11026. * @since 0.1.0
  11027. * @memberOf _
  11028. * @category Lang
  11029. * @param {*} value The value to check.
  11030. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11031. * @example
  11032. *
  11033. * _.isString('abc');
  11034. * // => true
  11035. *
  11036. * _.isString(1);
  11037. * // => false
  11038. */
  11039. function isString(value) {
  11040. return typeof value == 'string' ||
  11041. (!isArray(value) && isObjectLike(value) && objectToString.call(value) == stringTag);
  11042. }
  11043. /**
  11044. * Checks if `value` is classified as a `Symbol` primitive or object.
  11045. *
  11046. * @static
  11047. * @memberOf _
  11048. * @since 4.0.0
  11049. * @category Lang
  11050. * @param {*} value The value to check.
  11051. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11052. * @example
  11053. *
  11054. * _.isSymbol(Symbol.iterator);
  11055. * // => true
  11056. *
  11057. * _.isSymbol('abc');
  11058. * // => false
  11059. */
  11060. function isSymbol(value) {
  11061. return typeof value == 'symbol' ||
  11062. (isObjectLike(value) && objectToString.call(value) == symbolTag);
  11063. }
  11064. /**
  11065. * Checks if `value` is classified as a typed array.
  11066. *
  11067. * @static
  11068. * @memberOf _
  11069. * @since 3.0.0
  11070. * @category Lang
  11071. * @param {*} value The value to check.
  11072. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11073. * @example
  11074. *
  11075. * _.isTypedArray(new Uint8Array);
  11076. * // => true
  11077. *
  11078. * _.isTypedArray([]);
  11079. * // => false
  11080. */
  11081. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11082. /**
  11083. * Checks if `value` is `undefined`.
  11084. *
  11085. * @static
  11086. * @since 0.1.0
  11087. * @memberOf _
  11088. * @category Lang
  11089. * @param {*} value The value to check.
  11090. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11091. * @example
  11092. *
  11093. * _.isUndefined(void 0);
  11094. * // => true
  11095. *
  11096. * _.isUndefined(null);
  11097. * // => false
  11098. */
  11099. function isUndefined(value) {
  11100. return value === undefined;
  11101. }
  11102. /**
  11103. * Checks if `value` is classified as a `WeakMap` object.
  11104. *
  11105. * @static
  11106. * @memberOf _
  11107. * @since 4.3.0
  11108. * @category Lang
  11109. * @param {*} value The value to check.
  11110. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11111. * @example
  11112. *
  11113. * _.isWeakMap(new WeakMap);
  11114. * // => true
  11115. *
  11116. * _.isWeakMap(new Map);
  11117. * // => false
  11118. */
  11119. function isWeakMap(value) {
  11120. return isObjectLike(value) && getTag(value) == weakMapTag;
  11121. }
  11122. /**
  11123. * Checks if `value` is classified as a `WeakSet` object.
  11124. *
  11125. * @static
  11126. * @memberOf _
  11127. * @since 4.3.0
  11128. * @category Lang
  11129. * @param {*} value The value to check.
  11130. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11131. * @example
  11132. *
  11133. * _.isWeakSet(new WeakSet);
  11134. * // => true
  11135. *
  11136. * _.isWeakSet(new Set);
  11137. * // => false
  11138. */
  11139. function isWeakSet(value) {
  11140. return isObjectLike(value) && objectToString.call(value) == weakSetTag;
  11141. }
  11142. /**
  11143. * Checks if `value` is less than `other`.
  11144. *
  11145. * @static
  11146. * @memberOf _
  11147. * @since 3.9.0
  11148. * @category Lang
  11149. * @param {*} value The value to compare.
  11150. * @param {*} other The other value to compare.
  11151. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11152. * else `false`.
  11153. * @see _.gt
  11154. * @example
  11155. *
  11156. * _.lt(1, 3);
  11157. * // => true
  11158. *
  11159. * _.lt(3, 3);
  11160. * // => false
  11161. *
  11162. * _.lt(3, 1);
  11163. * // => false
  11164. */
  11165. var lt = createRelationalOperation(baseLt);
  11166. /**
  11167. * Checks if `value` is less than or equal to `other`.
  11168. *
  11169. * @static
  11170. * @memberOf _
  11171. * @since 3.9.0
  11172. * @category Lang
  11173. * @param {*} value The value to compare.
  11174. * @param {*} other The other value to compare.
  11175. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11176. * `other`, else `false`.
  11177. * @see _.gte
  11178. * @example
  11179. *
  11180. * _.lte(1, 3);
  11181. * // => true
  11182. *
  11183. * _.lte(3, 3);
  11184. * // => true
  11185. *
  11186. * _.lte(3, 1);
  11187. * // => false
  11188. */
  11189. var lte = createRelationalOperation(function(value, other) {
  11190. return value <= other;
  11191. });
  11192. /**
  11193. * Converts `value` to an array.
  11194. *
  11195. * @static
  11196. * @since 0.1.0
  11197. * @memberOf _
  11198. * @category Lang
  11199. * @param {*} value The value to convert.
  11200. * @returns {Array} Returns the converted array.
  11201. * @example
  11202. *
  11203. * _.toArray({ 'a': 1, 'b': 2 });
  11204. * // => [1, 2]
  11205. *
  11206. * _.toArray('abc');
  11207. * // => ['a', 'b', 'c']
  11208. *
  11209. * _.toArray(1);
  11210. * // => []
  11211. *
  11212. * _.toArray(null);
  11213. * // => []
  11214. */
  11215. function toArray(value) {
  11216. if (!value) {
  11217. return [];
  11218. }
  11219. if (isArrayLike(value)) {
  11220. return isString(value) ? stringToArray(value) : copyArray(value);
  11221. }
  11222. if (iteratorSymbol && value[iteratorSymbol]) {
  11223. return iteratorToArray(value[iteratorSymbol]());
  11224. }
  11225. var tag = getTag(value),
  11226. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11227. return func(value);
  11228. }
  11229. /**
  11230. * Converts `value` to a finite number.
  11231. *
  11232. * @static
  11233. * @memberOf _
  11234. * @since 4.12.0
  11235. * @category Lang
  11236. * @param {*} value The value to convert.
  11237. * @returns {number} Returns the converted number.
  11238. * @example
  11239. *
  11240. * _.toFinite(3.2);
  11241. * // => 3.2
  11242. *
  11243. * _.toFinite(Number.MIN_VALUE);
  11244. * // => 5e-324
  11245. *
  11246. * _.toFinite(Infinity);
  11247. * // => 1.7976931348623157e+308
  11248. *
  11249. * _.toFinite('3.2');
  11250. * // => 3.2
  11251. */
  11252. function toFinite(value) {
  11253. if (!value) {
  11254. return value === 0 ? value : 0;
  11255. }
  11256. value = toNumber(value);
  11257. if (value === INFINITY || value === -INFINITY) {
  11258. var sign = (value < 0 ? -1 : 1);
  11259. return sign * MAX_INTEGER;
  11260. }
  11261. return value === value ? value : 0;
  11262. }
  11263. /**
  11264. * Converts `value` to an integer.
  11265. *
  11266. * **Note:** This method is loosely based on
  11267. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11268. *
  11269. * @static
  11270. * @memberOf _
  11271. * @since 4.0.0
  11272. * @category Lang
  11273. * @param {*} value The value to convert.
  11274. * @returns {number} Returns the converted integer.
  11275. * @example
  11276. *
  11277. * _.toInteger(3.2);
  11278. * // => 3
  11279. *
  11280. * _.toInteger(Number.MIN_VALUE);
  11281. * // => 0
  11282. *
  11283. * _.toInteger(Infinity);
  11284. * // => 1.7976931348623157e+308
  11285. *
  11286. * _.toInteger('3.2');
  11287. * // => 3
  11288. */
  11289. function toInteger(value) {
  11290. var result = toFinite(value),
  11291. remainder = result % 1;
  11292. return result === result ? (remainder ? result - remainder : result) : 0;
  11293. }
  11294. /**
  11295. * Converts `value` to an integer suitable for use as the length of an
  11296. * array-like object.
  11297. *
  11298. * **Note:** This method is based on
  11299. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11300. *
  11301. * @static
  11302. * @memberOf _
  11303. * @since 4.0.0
  11304. * @category Lang
  11305. * @param {*} value The value to convert.
  11306. * @returns {number} Returns the converted integer.
  11307. * @example
  11308. *
  11309. * _.toLength(3.2);
  11310. * // => 3
  11311. *
  11312. * _.toLength(Number.MIN_VALUE);
  11313. * // => 0
  11314. *
  11315. * _.toLength(Infinity);
  11316. * // => 4294967295
  11317. *
  11318. * _.toLength('3.2');
  11319. * // => 3
  11320. */
  11321. function toLength(value) {
  11322. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11323. }
  11324. /**
  11325. * Converts `value` to a number.
  11326. *
  11327. * @static
  11328. * @memberOf _
  11329. * @since 4.0.0
  11330. * @category Lang
  11331. * @param {*} value The value to process.
  11332. * @returns {number} Returns the number.
  11333. * @example
  11334. *
  11335. * _.toNumber(3.2);
  11336. * // => 3.2
  11337. *
  11338. * _.toNumber(Number.MIN_VALUE);
  11339. * // => 5e-324
  11340. *
  11341. * _.toNumber(Infinity);
  11342. * // => Infinity
  11343. *
  11344. * _.toNumber('3.2');
  11345. * // => 3.2
  11346. */
  11347. function toNumber(value) {
  11348. if (typeof value == 'number') {
  11349. return value;
  11350. }
  11351. if (isSymbol(value)) {
  11352. return NAN;
  11353. }
  11354. if (isObject(value)) {
  11355. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11356. value = isObject(other) ? (other + '') : other;
  11357. }
  11358. if (typeof value != 'string') {
  11359. return value === 0 ? value : +value;
  11360. }
  11361. value = value.replace(reTrim, '');
  11362. var isBinary = reIsBinary.test(value);
  11363. return (isBinary || reIsOctal.test(value))
  11364. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11365. : (reIsBadHex.test(value) ? NAN : +value);
  11366. }
  11367. /**
  11368. * Converts `value` to a plain object flattening inherited enumerable string
  11369. * keyed properties of `value` to own properties of the plain object.
  11370. *
  11371. * @static
  11372. * @memberOf _
  11373. * @since 3.0.0
  11374. * @category Lang
  11375. * @param {*} value The value to convert.
  11376. * @returns {Object} Returns the converted plain object.
  11377. * @example
  11378. *
  11379. * function Foo() {
  11380. * this.b = 2;
  11381. * }
  11382. *
  11383. * Foo.prototype.c = 3;
  11384. *
  11385. * _.assign({ 'a': 1 }, new Foo);
  11386. * // => { 'a': 1, 'b': 2 }
  11387. *
  11388. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11389. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11390. */
  11391. function toPlainObject(value) {
  11392. return copyObject(value, keysIn(value));
  11393. }
  11394. /**
  11395. * Converts `value` to a safe integer. A safe integer can be compared and
  11396. * represented correctly.
  11397. *
  11398. * @static
  11399. * @memberOf _
  11400. * @since 4.0.0
  11401. * @category Lang
  11402. * @param {*} value The value to convert.
  11403. * @returns {number} Returns the converted integer.
  11404. * @example
  11405. *
  11406. * _.toSafeInteger(3.2);
  11407. * // => 3
  11408. *
  11409. * _.toSafeInteger(Number.MIN_VALUE);
  11410. * // => 0
  11411. *
  11412. * _.toSafeInteger(Infinity);
  11413. * // => 9007199254740991
  11414. *
  11415. * _.toSafeInteger('3.2');
  11416. * // => 3
  11417. */
  11418. function toSafeInteger(value) {
  11419. return baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER);
  11420. }
  11421. /**
  11422. * Converts `value` to a string. An empty string is returned for `null`
  11423. * and `undefined` values. The sign of `-0` is preserved.
  11424. *
  11425. * @static
  11426. * @memberOf _
  11427. * @since 4.0.0
  11428. * @category Lang
  11429. * @param {*} value The value to process.
  11430. * @returns {string} Returns the string.
  11431. * @example
  11432. *
  11433. * _.toString(null);
  11434. * // => ''
  11435. *
  11436. * _.toString(-0);
  11437. * // => '-0'
  11438. *
  11439. * _.toString([1, 2, 3]);
  11440. * // => '1,2,3'
  11441. */
  11442. function toString(value) {
  11443. return value == null ? '' : baseToString(value);
  11444. }
  11445. /*------------------------------------------------------------------------*/
  11446. /**
  11447. * Assigns own enumerable string keyed properties of source objects to the
  11448. * destination object. Source objects are applied from left to right.
  11449. * Subsequent sources overwrite property assignments of previous sources.
  11450. *
  11451. * **Note:** This method mutates `object` and is loosely based on
  11452. * [`Object.assign`](https://mdn.io/Object/assign).
  11453. *
  11454. * @static
  11455. * @memberOf _
  11456. * @since 0.10.0
  11457. * @category Object
  11458. * @param {Object} object The destination object.
  11459. * @param {...Object} [sources] The source objects.
  11460. * @returns {Object} Returns `object`.
  11461. * @see _.assignIn
  11462. * @example
  11463. *
  11464. * function Foo() {
  11465. * this.a = 1;
  11466. * }
  11467. *
  11468. * function Bar() {
  11469. * this.c = 3;
  11470. * }
  11471. *
  11472. * Foo.prototype.b = 2;
  11473. * Bar.prototype.d = 4;
  11474. *
  11475. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11476. * // => { 'a': 1, 'c': 3 }
  11477. */
  11478. var assign = createAssigner(function(object, source) {
  11479. if (nonEnumShadows || isPrototype(source) || isArrayLike(source)) {
  11480. copyObject(source, keys(source), object);
  11481. return;
  11482. }
  11483. for (var key in source) {
  11484. if (hasOwnProperty.call(source, key)) {
  11485. assignValue(object, key, source[key]);
  11486. }
  11487. }
  11488. });
  11489. /**
  11490. * This method is like `_.assign` except that it iterates over own and
  11491. * inherited source properties.
  11492. *
  11493. * **Note:** This method mutates `object`.
  11494. *
  11495. * @static
  11496. * @memberOf _
  11497. * @since 4.0.0
  11498. * @alias extend
  11499. * @category Object
  11500. * @param {Object} object The destination object.
  11501. * @param {...Object} [sources] The source objects.
  11502. * @returns {Object} Returns `object`.
  11503. * @see _.assign
  11504. * @example
  11505. *
  11506. * function Foo() {
  11507. * this.a = 1;
  11508. * }
  11509. *
  11510. * function Bar() {
  11511. * this.c = 3;
  11512. * }
  11513. *
  11514. * Foo.prototype.b = 2;
  11515. * Bar.prototype.d = 4;
  11516. *
  11517. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11518. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11519. */
  11520. var assignIn = createAssigner(function(object, source) {
  11521. copyObject(source, keysIn(source), object);
  11522. });
  11523. /**
  11524. * This method is like `_.assignIn` except that it accepts `customizer`
  11525. * which is invoked to produce the assigned values. If `customizer` returns
  11526. * `undefined`, assignment is handled by the method instead. The `customizer`
  11527. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11528. *
  11529. * **Note:** This method mutates `object`.
  11530. *
  11531. * @static
  11532. * @memberOf _
  11533. * @since 4.0.0
  11534. * @alias extendWith
  11535. * @category Object
  11536. * @param {Object} object The destination object.
  11537. * @param {...Object} sources The source objects.
  11538. * @param {Function} [customizer] The function to customize assigned values.
  11539. * @returns {Object} Returns `object`.
  11540. * @see _.assignWith
  11541. * @example
  11542. *
  11543. * function customizer(objValue, srcValue) {
  11544. * return _.isUndefined(objValue) ? srcValue : objValue;
  11545. * }
  11546. *
  11547. * var defaults = _.partialRight(_.assignInWith, customizer);
  11548. *
  11549. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11550. * // => { 'a': 1, 'b': 2 }
  11551. */
  11552. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11553. copyObject(source, keysIn(source), object, customizer);
  11554. });
  11555. /**
  11556. * This method is like `_.assign` except that it accepts `customizer`
  11557. * which is invoked to produce the assigned values. If `customizer` returns
  11558. * `undefined`, assignment is handled by the method instead. The `customizer`
  11559. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11560. *
  11561. * **Note:** This method mutates `object`.
  11562. *
  11563. * @static
  11564. * @memberOf _
  11565. * @since 4.0.0
  11566. * @category Object
  11567. * @param {Object} object The destination object.
  11568. * @param {...Object} sources The source objects.
  11569. * @param {Function} [customizer] The function to customize assigned values.
  11570. * @returns {Object} Returns `object`.
  11571. * @see _.assignInWith
  11572. * @example
  11573. *
  11574. * function customizer(objValue, srcValue) {
  11575. * return _.isUndefined(objValue) ? srcValue : objValue;
  11576. * }
  11577. *
  11578. * var defaults = _.partialRight(_.assignWith, customizer);
  11579. *
  11580. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11581. * // => { 'a': 1, 'b': 2 }
  11582. */
  11583. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11584. copyObject(source, keys(source), object, customizer);
  11585. });
  11586. /**
  11587. * Creates an array of values corresponding to `paths` of `object`.
  11588. *
  11589. * @static
  11590. * @memberOf _
  11591. * @since 1.0.0
  11592. * @category Object
  11593. * @param {Object} object The object to iterate over.
  11594. * @param {...(string|string[])} [paths] The property paths of elements to pick.
  11595. * @returns {Array} Returns the picked values.
  11596. * @example
  11597. *
  11598. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11599. *
  11600. * _.at(object, ['a[0].b.c', 'a[1]']);
  11601. * // => [3, 4]
  11602. */
  11603. var at = baseRest(function(object, paths) {
  11604. return baseAt(object, baseFlatten(paths, 1));
  11605. });
  11606. /**
  11607. * Creates an object that inherits from the `prototype` object. If a
  11608. * `properties` object is given, its own enumerable string keyed properties
  11609. * are assigned to the created object.
  11610. *
  11611. * @static
  11612. * @memberOf _
  11613. * @since 2.3.0
  11614. * @category Object
  11615. * @param {Object} prototype The object to inherit from.
  11616. * @param {Object} [properties] The properties to assign to the object.
  11617. * @returns {Object} Returns the new object.
  11618. * @example
  11619. *
  11620. * function Shape() {
  11621. * this.x = 0;
  11622. * this.y = 0;
  11623. * }
  11624. *
  11625. * function Circle() {
  11626. * Shape.call(this);
  11627. * }
  11628. *
  11629. * Circle.prototype = _.create(Shape.prototype, {
  11630. * 'constructor': Circle
  11631. * });
  11632. *
  11633. * var circle = new Circle;
  11634. * circle instanceof Circle;
  11635. * // => true
  11636. *
  11637. * circle instanceof Shape;
  11638. * // => true
  11639. */
  11640. function create(prototype, properties) {
  11641. var result = baseCreate(prototype);
  11642. return properties ? baseAssign(result, properties) : result;
  11643. }
  11644. /**
  11645. * Assigns own and inherited enumerable string keyed properties of source
  11646. * objects to the destination object for all destination properties that
  11647. * resolve to `undefined`. Source objects are applied from left to right.
  11648. * Once a property is set, additional values of the same property are ignored.
  11649. *
  11650. * **Note:** This method mutates `object`.
  11651. *
  11652. * @static
  11653. * @since 0.1.0
  11654. * @memberOf _
  11655. * @category Object
  11656. * @param {Object} object The destination object.
  11657. * @param {...Object} [sources] The source objects.
  11658. * @returns {Object} Returns `object`.
  11659. * @see _.defaultsDeep
  11660. * @example
  11661. *
  11662. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11663. * // => { 'a': 1, 'b': 2 }
  11664. */
  11665. var defaults = baseRest(function(args) {
  11666. args.push(undefined, assignInDefaults);
  11667. return apply(assignInWith, undefined, args);
  11668. });
  11669. /**
  11670. * This method is like `_.defaults` except that it recursively assigns
  11671. * default properties.
  11672. *
  11673. * **Note:** This method mutates `object`.
  11674. *
  11675. * @static
  11676. * @memberOf _
  11677. * @since 3.10.0
  11678. * @category Object
  11679. * @param {Object} object The destination object.
  11680. * @param {...Object} [sources] The source objects.
  11681. * @returns {Object} Returns `object`.
  11682. * @see _.defaults
  11683. * @example
  11684. *
  11685. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  11686. * // => { 'a': { 'b': 2, 'c': 3 } }
  11687. */
  11688. var defaultsDeep = baseRest(function(args) {
  11689. args.push(undefined, mergeDefaults);
  11690. return apply(mergeWith, undefined, args);
  11691. });
  11692. /**
  11693. * This method is like `_.find` except that it returns the key of the first
  11694. * element `predicate` returns truthy for instead of the element itself.
  11695. *
  11696. * @static
  11697. * @memberOf _
  11698. * @since 1.1.0
  11699. * @category Object
  11700. * @param {Object} object The object to inspect.
  11701. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11702. * @returns {string|undefined} Returns the key of the matched element,
  11703. * else `undefined`.
  11704. * @example
  11705. *
  11706. * var users = {
  11707. * 'barney': { 'age': 36, 'active': true },
  11708. * 'fred': { 'age': 40, 'active': false },
  11709. * 'pebbles': { 'age': 1, 'active': true }
  11710. * };
  11711. *
  11712. * _.findKey(users, function(o) { return o.age < 40; });
  11713. * // => 'barney' (iteration order is not guaranteed)
  11714. *
  11715. * // The `_.matches` iteratee shorthand.
  11716. * _.findKey(users, { 'age': 1, 'active': true });
  11717. * // => 'pebbles'
  11718. *
  11719. * // The `_.matchesProperty` iteratee shorthand.
  11720. * _.findKey(users, ['active', false]);
  11721. * // => 'fred'
  11722. *
  11723. * // The `_.property` iteratee shorthand.
  11724. * _.findKey(users, 'active');
  11725. * // => 'barney'
  11726. */
  11727. function findKey(object, predicate) {
  11728. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  11729. }
  11730. /**
  11731. * This method is like `_.findKey` except that it iterates over elements of
  11732. * a collection in the opposite order.
  11733. *
  11734. * @static
  11735. * @memberOf _
  11736. * @since 2.0.0
  11737. * @category Object
  11738. * @param {Object} object The object to inspect.
  11739. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11740. * @returns {string|undefined} Returns the key of the matched element,
  11741. * else `undefined`.
  11742. * @example
  11743. *
  11744. * var users = {
  11745. * 'barney': { 'age': 36, 'active': true },
  11746. * 'fred': { 'age': 40, 'active': false },
  11747. * 'pebbles': { 'age': 1, 'active': true }
  11748. * };
  11749. *
  11750. * _.findLastKey(users, function(o) { return o.age < 40; });
  11751. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  11752. *
  11753. * // The `_.matches` iteratee shorthand.
  11754. * _.findLastKey(users, { 'age': 36, 'active': true });
  11755. * // => 'barney'
  11756. *
  11757. * // The `_.matchesProperty` iteratee shorthand.
  11758. * _.findLastKey(users, ['active', false]);
  11759. * // => 'fred'
  11760. *
  11761. * // The `_.property` iteratee shorthand.
  11762. * _.findLastKey(users, 'active');
  11763. * // => 'pebbles'
  11764. */
  11765. function findLastKey(object, predicate) {
  11766. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  11767. }
  11768. /**
  11769. * Iterates over own and inherited enumerable string keyed properties of an
  11770. * object and invokes `iteratee` for each property. The iteratee is invoked
  11771. * with three arguments: (value, key, object). Iteratee functions may exit
  11772. * iteration early by explicitly returning `false`.
  11773. *
  11774. * @static
  11775. * @memberOf _
  11776. * @since 0.3.0
  11777. * @category Object
  11778. * @param {Object} object The object to iterate over.
  11779. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11780. * @returns {Object} Returns `object`.
  11781. * @see _.forInRight
  11782. * @example
  11783. *
  11784. * function Foo() {
  11785. * this.a = 1;
  11786. * this.b = 2;
  11787. * }
  11788. *
  11789. * Foo.prototype.c = 3;
  11790. *
  11791. * _.forIn(new Foo, function(value, key) {
  11792. * console.log(key);
  11793. * });
  11794. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  11795. */
  11796. function forIn(object, iteratee) {
  11797. return object == null
  11798. ? object
  11799. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  11800. }
  11801. /**
  11802. * This method is like `_.forIn` except that it iterates over properties of
  11803. * `object` in the opposite order.
  11804. *
  11805. * @static
  11806. * @memberOf _
  11807. * @since 2.0.0
  11808. * @category Object
  11809. * @param {Object} object The object to iterate over.
  11810. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11811. * @returns {Object} Returns `object`.
  11812. * @see _.forIn
  11813. * @example
  11814. *
  11815. * function Foo() {
  11816. * this.a = 1;
  11817. * this.b = 2;
  11818. * }
  11819. *
  11820. * Foo.prototype.c = 3;
  11821. *
  11822. * _.forInRight(new Foo, function(value, key) {
  11823. * console.log(key);
  11824. * });
  11825. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  11826. */
  11827. function forInRight(object, iteratee) {
  11828. return object == null
  11829. ? object
  11830. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  11831. }
  11832. /**
  11833. * Iterates over own enumerable string keyed properties of an object and
  11834. * invokes `iteratee` for each property. The iteratee is invoked with three
  11835. * arguments: (value, key, object). Iteratee functions may exit iteration
  11836. * early by explicitly returning `false`.
  11837. *
  11838. * @static
  11839. * @memberOf _
  11840. * @since 0.3.0
  11841. * @category Object
  11842. * @param {Object} object The object to iterate over.
  11843. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11844. * @returns {Object} Returns `object`.
  11845. * @see _.forOwnRight
  11846. * @example
  11847. *
  11848. * function Foo() {
  11849. * this.a = 1;
  11850. * this.b = 2;
  11851. * }
  11852. *
  11853. * Foo.prototype.c = 3;
  11854. *
  11855. * _.forOwn(new Foo, function(value, key) {
  11856. * console.log(key);
  11857. * });
  11858. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  11859. */
  11860. function forOwn(object, iteratee) {
  11861. return object && baseForOwn(object, getIteratee(iteratee, 3));
  11862. }
  11863. /**
  11864. * This method is like `_.forOwn` except that it iterates over properties of
  11865. * `object` in the opposite order.
  11866. *
  11867. * @static
  11868. * @memberOf _
  11869. * @since 2.0.0
  11870. * @category Object
  11871. * @param {Object} object The object to iterate over.
  11872. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11873. * @returns {Object} Returns `object`.
  11874. * @see _.forOwn
  11875. * @example
  11876. *
  11877. * function Foo() {
  11878. * this.a = 1;
  11879. * this.b = 2;
  11880. * }
  11881. *
  11882. * Foo.prototype.c = 3;
  11883. *
  11884. * _.forOwnRight(new Foo, function(value, key) {
  11885. * console.log(key);
  11886. * });
  11887. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  11888. */
  11889. function forOwnRight(object, iteratee) {
  11890. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  11891. }
  11892. /**
  11893. * Creates an array of function property names from own enumerable properties
  11894. * of `object`.
  11895. *
  11896. * @static
  11897. * @since 0.1.0
  11898. * @memberOf _
  11899. * @category Object
  11900. * @param {Object} object The object to inspect.
  11901. * @returns {Array} Returns the function names.
  11902. * @see _.functionsIn
  11903. * @example
  11904. *
  11905. * function Foo() {
  11906. * this.a = _.constant('a');
  11907. * this.b = _.constant('b');
  11908. * }
  11909. *
  11910. * Foo.prototype.c = _.constant('c');
  11911. *
  11912. * _.functions(new Foo);
  11913. * // => ['a', 'b']
  11914. */
  11915. function functions(object) {
  11916. return object == null ? [] : baseFunctions(object, keys(object));
  11917. }
  11918. /**
  11919. * Creates an array of function property names from own and inherited
  11920. * enumerable properties of `object`.
  11921. *
  11922. * @static
  11923. * @memberOf _
  11924. * @since 4.0.0
  11925. * @category Object
  11926. * @param {Object} object The object to inspect.
  11927. * @returns {Array} Returns the function names.
  11928. * @see _.functions
  11929. * @example
  11930. *
  11931. * function Foo() {
  11932. * this.a = _.constant('a');
  11933. * this.b = _.constant('b');
  11934. * }
  11935. *
  11936. * Foo.prototype.c = _.constant('c');
  11937. *
  11938. * _.functionsIn(new Foo);
  11939. * // => ['a', 'b', 'c']
  11940. */
  11941. function functionsIn(object) {
  11942. return object == null ? [] : baseFunctions(object, keysIn(object));
  11943. }
  11944. /**
  11945. * Gets the value at `path` of `object`. If the resolved value is
  11946. * `undefined`, the `defaultValue` is returned in its place.
  11947. *
  11948. * @static
  11949. * @memberOf _
  11950. * @since 3.7.0
  11951. * @category Object
  11952. * @param {Object} object The object to query.
  11953. * @param {Array|string} path The path of the property to get.
  11954. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  11955. * @returns {*} Returns the resolved value.
  11956. * @example
  11957. *
  11958. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  11959. *
  11960. * _.get(object, 'a[0].b.c');
  11961. * // => 3
  11962. *
  11963. * _.get(object, ['a', '0', 'b', 'c']);
  11964. * // => 3
  11965. *
  11966. * _.get(object, 'a.b.c', 'default');
  11967. * // => 'default'
  11968. */
  11969. function get(object, path, defaultValue) {
  11970. var result = object == null ? undefined : baseGet(object, path);
  11971. return result === undefined ? defaultValue : result;
  11972. }
  11973. /**
  11974. * Checks if `path` is a direct property of `object`.
  11975. *
  11976. * @static
  11977. * @since 0.1.0
  11978. * @memberOf _
  11979. * @category Object
  11980. * @param {Object} object The object to query.
  11981. * @param {Array|string} path The path to check.
  11982. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  11983. * @example
  11984. *
  11985. * var object = { 'a': { 'b': 2 } };
  11986. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  11987. *
  11988. * _.has(object, 'a');
  11989. * // => true
  11990. *
  11991. * _.has(object, 'a.b');
  11992. * // => true
  11993. *
  11994. * _.has(object, ['a', 'b']);
  11995. * // => true
  11996. *
  11997. * _.has(other, 'a');
  11998. * // => false
  11999. */
  12000. function has(object, path) {
  12001. return object != null && hasPath(object, path, baseHas);
  12002. }
  12003. /**
  12004. * Checks if `path` is a direct or inherited property of `object`.
  12005. *
  12006. * @static
  12007. * @memberOf _
  12008. * @since 4.0.0
  12009. * @category Object
  12010. * @param {Object} object The object to query.
  12011. * @param {Array|string} path The path to check.
  12012. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12013. * @example
  12014. *
  12015. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12016. *
  12017. * _.hasIn(object, 'a');
  12018. * // => true
  12019. *
  12020. * _.hasIn(object, 'a.b');
  12021. * // => true
  12022. *
  12023. * _.hasIn(object, ['a', 'b']);
  12024. * // => true
  12025. *
  12026. * _.hasIn(object, 'b');
  12027. * // => false
  12028. */
  12029. function hasIn(object, path) {
  12030. return object != null && hasPath(object, path, baseHasIn);
  12031. }
  12032. /**
  12033. * Creates an object composed of the inverted keys and values of `object`.
  12034. * If `object` contains duplicate values, subsequent values overwrite
  12035. * property assignments of previous values.
  12036. *
  12037. * @static
  12038. * @memberOf _
  12039. * @since 0.7.0
  12040. * @category Object
  12041. * @param {Object} object The object to invert.
  12042. * @returns {Object} Returns the new inverted object.
  12043. * @example
  12044. *
  12045. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12046. *
  12047. * _.invert(object);
  12048. * // => { '1': 'c', '2': 'b' }
  12049. */
  12050. var invert = createInverter(function(result, value, key) {
  12051. result[value] = key;
  12052. }, constant(identity));
  12053. /**
  12054. * This method is like `_.invert` except that the inverted object is generated
  12055. * from the results of running each element of `object` thru `iteratee`. The
  12056. * corresponding inverted value of each inverted key is an array of keys
  12057. * responsible for generating the inverted value. The iteratee is invoked
  12058. * with one argument: (value).
  12059. *
  12060. * @static
  12061. * @memberOf _
  12062. * @since 4.1.0
  12063. * @category Object
  12064. * @param {Object} object The object to invert.
  12065. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12066. * @returns {Object} Returns the new inverted object.
  12067. * @example
  12068. *
  12069. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12070. *
  12071. * _.invertBy(object);
  12072. * // => { '1': ['a', 'c'], '2': ['b'] }
  12073. *
  12074. * _.invertBy(object, function(value) {
  12075. * return 'group' + value;
  12076. * });
  12077. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12078. */
  12079. var invertBy = createInverter(function(result, value, key) {
  12080. if (hasOwnProperty.call(result, value)) {
  12081. result[value].push(key);
  12082. } else {
  12083. result[value] = [key];
  12084. }
  12085. }, getIteratee);
  12086. /**
  12087. * Invokes the method at `path` of `object`.
  12088. *
  12089. * @static
  12090. * @memberOf _
  12091. * @since 4.0.0
  12092. * @category Object
  12093. * @param {Object} object The object to query.
  12094. * @param {Array|string} path The path of the method to invoke.
  12095. * @param {...*} [args] The arguments to invoke the method with.
  12096. * @returns {*} Returns the result of the invoked method.
  12097. * @example
  12098. *
  12099. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12100. *
  12101. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12102. * // => [2, 3]
  12103. */
  12104. var invoke = baseRest(baseInvoke);
  12105. /**
  12106. * Creates an array of the own enumerable property names of `object`.
  12107. *
  12108. * **Note:** Non-object values are coerced to objects. See the
  12109. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12110. * for more details.
  12111. *
  12112. * @static
  12113. * @since 0.1.0
  12114. * @memberOf _
  12115. * @category Object
  12116. * @param {Object} object The object to query.
  12117. * @returns {Array} Returns the array of property names.
  12118. * @example
  12119. *
  12120. * function Foo() {
  12121. * this.a = 1;
  12122. * this.b = 2;
  12123. * }
  12124. *
  12125. * Foo.prototype.c = 3;
  12126. *
  12127. * _.keys(new Foo);
  12128. * // => ['a', 'b'] (iteration order is not guaranteed)
  12129. *
  12130. * _.keys('hi');
  12131. * // => ['0', '1']
  12132. */
  12133. function keys(object) {
  12134. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12135. }
  12136. /**
  12137. * Creates an array of the own and inherited enumerable property names of `object`.
  12138. *
  12139. * **Note:** Non-object values are coerced to objects.
  12140. *
  12141. * @static
  12142. * @memberOf _
  12143. * @since 3.0.0
  12144. * @category Object
  12145. * @param {Object} object The object to query.
  12146. * @returns {Array} Returns the array of property names.
  12147. * @example
  12148. *
  12149. * function Foo() {
  12150. * this.a = 1;
  12151. * this.b = 2;
  12152. * }
  12153. *
  12154. * Foo.prototype.c = 3;
  12155. *
  12156. * _.keysIn(new Foo);
  12157. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12158. */
  12159. function keysIn(object) {
  12160. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12161. }
  12162. /**
  12163. * The opposite of `_.mapValues`; this method creates an object with the
  12164. * same values as `object` and keys generated by running each own enumerable
  12165. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12166. * with three arguments: (value, key, object).
  12167. *
  12168. * @static
  12169. * @memberOf _
  12170. * @since 3.8.0
  12171. * @category Object
  12172. * @param {Object} object The object to iterate over.
  12173. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12174. * @returns {Object} Returns the new mapped object.
  12175. * @see _.mapValues
  12176. * @example
  12177. *
  12178. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12179. * return key + value;
  12180. * });
  12181. * // => { 'a1': 1, 'b2': 2 }
  12182. */
  12183. function mapKeys(object, iteratee) {
  12184. var result = {};
  12185. iteratee = getIteratee(iteratee, 3);
  12186. baseForOwn(object, function(value, key, object) {
  12187. result[iteratee(value, key, object)] = value;
  12188. });
  12189. return result;
  12190. }
  12191. /**
  12192. * Creates an object with the same keys as `object` and values generated
  12193. * by running each own enumerable string keyed property of `object` thru
  12194. * `iteratee`. The iteratee is invoked with three arguments:
  12195. * (value, key, object).
  12196. *
  12197. * @static
  12198. * @memberOf _
  12199. * @since 2.4.0
  12200. * @category Object
  12201. * @param {Object} object The object to iterate over.
  12202. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12203. * @returns {Object} Returns the new mapped object.
  12204. * @see _.mapKeys
  12205. * @example
  12206. *
  12207. * var users = {
  12208. * 'fred': { 'user': 'fred', 'age': 40 },
  12209. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12210. * };
  12211. *
  12212. * _.mapValues(users, function(o) { return o.age; });
  12213. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12214. *
  12215. * // The `_.property` iteratee shorthand.
  12216. * _.mapValues(users, 'age');
  12217. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12218. */
  12219. function mapValues(object, iteratee) {
  12220. var result = {};
  12221. iteratee = getIteratee(iteratee, 3);
  12222. baseForOwn(object, function(value, key, object) {
  12223. result[key] = iteratee(value, key, object);
  12224. });
  12225. return result;
  12226. }
  12227. /**
  12228. * This method is like `_.assign` except that it recursively merges own and
  12229. * inherited enumerable string keyed properties of source objects into the
  12230. * destination object. Source properties that resolve to `undefined` are
  12231. * skipped if a destination value exists. Array and plain object properties
  12232. * are merged recursively. Other objects and value types are overridden by
  12233. * assignment. Source objects are applied from left to right. Subsequent
  12234. * sources overwrite property assignments of previous sources.
  12235. *
  12236. * **Note:** This method mutates `object`.
  12237. *
  12238. * @static
  12239. * @memberOf _
  12240. * @since 0.5.0
  12241. * @category Object
  12242. * @param {Object} object The destination object.
  12243. * @param {...Object} [sources] The source objects.
  12244. * @returns {Object} Returns `object`.
  12245. * @example
  12246. *
  12247. * var object = {
  12248. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12249. * };
  12250. *
  12251. * var other = {
  12252. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12253. * };
  12254. *
  12255. * _.merge(object, other);
  12256. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12257. */
  12258. var merge = createAssigner(function(object, source, srcIndex) {
  12259. baseMerge(object, source, srcIndex);
  12260. });
  12261. /**
  12262. * This method is like `_.merge` except that it accepts `customizer` which
  12263. * is invoked to produce the merged values of the destination and source
  12264. * properties. If `customizer` returns `undefined`, merging is handled by the
  12265. * method instead. The `customizer` is invoked with seven arguments:
  12266. * (objValue, srcValue, key, object, source, stack).
  12267. *
  12268. * **Note:** This method mutates `object`.
  12269. *
  12270. * @static
  12271. * @memberOf _
  12272. * @since 4.0.0
  12273. * @category Object
  12274. * @param {Object} object The destination object.
  12275. * @param {...Object} sources The source objects.
  12276. * @param {Function} customizer The function to customize assigned values.
  12277. * @returns {Object} Returns `object`.
  12278. * @example
  12279. *
  12280. * function customizer(objValue, srcValue) {
  12281. * if (_.isArray(objValue)) {
  12282. * return objValue.concat(srcValue);
  12283. * }
  12284. * }
  12285. *
  12286. * var object = { 'a': [1], 'b': [2] };
  12287. * var other = { 'a': [3], 'b': [4] };
  12288. *
  12289. * _.mergeWith(object, other, customizer);
  12290. * // => { 'a': [1, 3], 'b': [2, 4] }
  12291. */
  12292. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12293. baseMerge(object, source, srcIndex, customizer);
  12294. });
  12295. /**
  12296. * The opposite of `_.pick`; this method creates an object composed of the
  12297. * own and inherited enumerable string keyed properties of `object` that are
  12298. * not omitted.
  12299. *
  12300. * @static
  12301. * @since 0.1.0
  12302. * @memberOf _
  12303. * @category Object
  12304. * @param {Object} object The source object.
  12305. * @param {...(string|string[])} [props] The property identifiers to omit.
  12306. * @returns {Object} Returns the new object.
  12307. * @example
  12308. *
  12309. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12310. *
  12311. * _.omit(object, ['a', 'c']);
  12312. * // => { 'b': '2' }
  12313. */
  12314. var omit = baseRest(function(object, props) {
  12315. if (object == null) {
  12316. return {};
  12317. }
  12318. props = arrayMap(baseFlatten(props, 1), toKey);
  12319. return basePick(object, baseDifference(getAllKeysIn(object), props));
  12320. });
  12321. /**
  12322. * The opposite of `_.pickBy`; this method creates an object composed of
  12323. * the own and inherited enumerable string keyed properties of `object` that
  12324. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12325. * arguments: (value, key).
  12326. *
  12327. * @static
  12328. * @memberOf _
  12329. * @since 4.0.0
  12330. * @category Object
  12331. * @param {Object} object The source object.
  12332. * @param {Function} [predicate=_.identity] The function invoked per property.
  12333. * @returns {Object} Returns the new object.
  12334. * @example
  12335. *
  12336. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12337. *
  12338. * _.omitBy(object, _.isNumber);
  12339. * // => { 'b': '2' }
  12340. */
  12341. function omitBy(object, predicate) {
  12342. return pickBy(object, negate(getIteratee(predicate)));
  12343. }
  12344. /**
  12345. * Creates an object composed of the picked `object` properties.
  12346. *
  12347. * @static
  12348. * @since 0.1.0
  12349. * @memberOf _
  12350. * @category Object
  12351. * @param {Object} object The source object.
  12352. * @param {...(string|string[])} [props] The property identifiers to pick.
  12353. * @returns {Object} Returns the new object.
  12354. * @example
  12355. *
  12356. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12357. *
  12358. * _.pick(object, ['a', 'c']);
  12359. * // => { 'a': 1, 'c': 3 }
  12360. */
  12361. var pick = baseRest(function(object, props) {
  12362. return object == null ? {} : basePick(object, arrayMap(baseFlatten(props, 1), toKey));
  12363. });
  12364. /**
  12365. * Creates an object composed of the `object` properties `predicate` returns
  12366. * truthy for. The predicate is invoked with two arguments: (value, key).
  12367. *
  12368. * @static
  12369. * @memberOf _
  12370. * @since 4.0.0
  12371. * @category Object
  12372. * @param {Object} object The source object.
  12373. * @param {Function} [predicate=_.identity] The function invoked per property.
  12374. * @returns {Object} Returns the new object.
  12375. * @example
  12376. *
  12377. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12378. *
  12379. * _.pickBy(object, _.isNumber);
  12380. * // => { 'a': 1, 'c': 3 }
  12381. */
  12382. function pickBy(object, predicate) {
  12383. return object == null ? {} : basePickBy(object, getAllKeysIn(object), getIteratee(predicate));
  12384. }
  12385. /**
  12386. * This method is like `_.get` except that if the resolved value is a
  12387. * function it's invoked with the `this` binding of its parent object and
  12388. * its result is returned.
  12389. *
  12390. * @static
  12391. * @since 0.1.0
  12392. * @memberOf _
  12393. * @category Object
  12394. * @param {Object} object The object to query.
  12395. * @param {Array|string} path The path of the property to resolve.
  12396. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12397. * @returns {*} Returns the resolved value.
  12398. * @example
  12399. *
  12400. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12401. *
  12402. * _.result(object, 'a[0].b.c1');
  12403. * // => 3
  12404. *
  12405. * _.result(object, 'a[0].b.c2');
  12406. * // => 4
  12407. *
  12408. * _.result(object, 'a[0].b.c3', 'default');
  12409. * // => 'default'
  12410. *
  12411. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12412. * // => 'default'
  12413. */
  12414. function result(object, path, defaultValue) {
  12415. path = isKey(path, object) ? [path] : castPath(path);
  12416. var index = -1,
  12417. length = path.length;
  12418. // Ensure the loop is entered when path is empty.
  12419. if (!length) {
  12420. object = undefined;
  12421. length = 1;
  12422. }
  12423. while (++index < length) {
  12424. var value = object == null ? undefined : object[toKey(path[index])];
  12425. if (value === undefined) {
  12426. index = length;
  12427. value = defaultValue;
  12428. }
  12429. object = isFunction(value) ? value.call(object) : value;
  12430. }
  12431. return object;
  12432. }
  12433. /**
  12434. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12435. * it's created. Arrays are created for missing index properties while objects
  12436. * are created for all other missing properties. Use `_.setWith` to customize
  12437. * `path` creation.
  12438. *
  12439. * **Note:** This method mutates `object`.
  12440. *
  12441. * @static
  12442. * @memberOf _
  12443. * @since 3.7.0
  12444. * @category Object
  12445. * @param {Object} object The object to modify.
  12446. * @param {Array|string} path The path of the property to set.
  12447. * @param {*} value The value to set.
  12448. * @returns {Object} Returns `object`.
  12449. * @example
  12450. *
  12451. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12452. *
  12453. * _.set(object, 'a[0].b.c', 4);
  12454. * console.log(object.a[0].b.c);
  12455. * // => 4
  12456. *
  12457. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12458. * console.log(object.x[0].y.z);
  12459. * // => 5
  12460. */
  12461. function set(object, path, value) {
  12462. return object == null ? object : baseSet(object, path, value);
  12463. }
  12464. /**
  12465. * This method is like `_.set` except that it accepts `customizer` which is
  12466. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12467. * path creation is handled by the method instead. The `customizer` is invoked
  12468. * with three arguments: (nsValue, key, nsObject).
  12469. *
  12470. * **Note:** This method mutates `object`.
  12471. *
  12472. * @static
  12473. * @memberOf _
  12474. * @since 4.0.0
  12475. * @category Object
  12476. * @param {Object} object The object to modify.
  12477. * @param {Array|string} path The path of the property to set.
  12478. * @param {*} value The value to set.
  12479. * @param {Function} [customizer] The function to customize assigned values.
  12480. * @returns {Object} Returns `object`.
  12481. * @example
  12482. *
  12483. * var object = {};
  12484. *
  12485. * _.setWith(object, '[0][1]', 'a', Object);
  12486. * // => { '0': { '1': 'a' } }
  12487. */
  12488. function setWith(object, path, value, customizer) {
  12489. customizer = typeof customizer == 'function' ? customizer : undefined;
  12490. return object == null ? object : baseSet(object, path, value, customizer);
  12491. }
  12492. /**
  12493. * Creates an array of own enumerable string keyed-value pairs for `object`
  12494. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12495. * entries are returned.
  12496. *
  12497. * @static
  12498. * @memberOf _
  12499. * @since 4.0.0
  12500. * @alias entries
  12501. * @category Object
  12502. * @param {Object} object The object to query.
  12503. * @returns {Array} Returns the key-value pairs.
  12504. * @example
  12505. *
  12506. * function Foo() {
  12507. * this.a = 1;
  12508. * this.b = 2;
  12509. * }
  12510. *
  12511. * Foo.prototype.c = 3;
  12512. *
  12513. * _.toPairs(new Foo);
  12514. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12515. */
  12516. var toPairs = createToPairs(keys);
  12517. /**
  12518. * Creates an array of own and inherited enumerable string keyed-value pairs
  12519. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12520. * or set, its entries are returned.
  12521. *
  12522. * @static
  12523. * @memberOf _
  12524. * @since 4.0.0
  12525. * @alias entriesIn
  12526. * @category Object
  12527. * @param {Object} object The object to query.
  12528. * @returns {Array} Returns the key-value pairs.
  12529. * @example
  12530. *
  12531. * function Foo() {
  12532. * this.a = 1;
  12533. * this.b = 2;
  12534. * }
  12535. *
  12536. * Foo.prototype.c = 3;
  12537. *
  12538. * _.toPairsIn(new Foo);
  12539. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12540. */
  12541. var toPairsIn = createToPairs(keysIn);
  12542. /**
  12543. * An alternative to `_.reduce`; this method transforms `object` to a new
  12544. * `accumulator` object which is the result of running each of its own
  12545. * enumerable string keyed properties thru `iteratee`, with each invocation
  12546. * potentially mutating the `accumulator` object. If `accumulator` is not
  12547. * provided, a new object with the same `[[Prototype]]` will be used. The
  12548. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12549. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12550. *
  12551. * @static
  12552. * @memberOf _
  12553. * @since 1.3.0
  12554. * @category Object
  12555. * @param {Object} object The object to iterate over.
  12556. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12557. * @param {*} [accumulator] The custom accumulator value.
  12558. * @returns {*} Returns the accumulated value.
  12559. * @example
  12560. *
  12561. * _.transform([2, 3, 4], function(result, n) {
  12562. * result.push(n *= n);
  12563. * return n % 2 == 0;
  12564. * }, []);
  12565. * // => [4, 9]
  12566. *
  12567. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12568. * (result[value] || (result[value] = [])).push(key);
  12569. * }, {});
  12570. * // => { '1': ['a', 'c'], '2': ['b'] }
  12571. */
  12572. function transform(object, iteratee, accumulator) {
  12573. var isArr = isArray(object) || isTypedArray(object);
  12574. iteratee = getIteratee(iteratee, 4);
  12575. if (accumulator == null) {
  12576. if (isArr || isObject(object)) {
  12577. var Ctor = object.constructor;
  12578. if (isArr) {
  12579. accumulator = isArray(object) ? new Ctor : [];
  12580. } else {
  12581. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12582. }
  12583. } else {
  12584. accumulator = {};
  12585. }
  12586. }
  12587. (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
  12588. return iteratee(accumulator, value, index, object);
  12589. });
  12590. return accumulator;
  12591. }
  12592. /**
  12593. * Removes the property at `path` of `object`.
  12594. *
  12595. * **Note:** This method mutates `object`.
  12596. *
  12597. * @static
  12598. * @memberOf _
  12599. * @since 4.0.0
  12600. * @category Object
  12601. * @param {Object} object The object to modify.
  12602. * @param {Array|string} path The path of the property to unset.
  12603. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  12604. * @example
  12605. *
  12606. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  12607. * _.unset(object, 'a[0].b.c');
  12608. * // => true
  12609. *
  12610. * console.log(object);
  12611. * // => { 'a': [{ 'b': {} }] };
  12612. *
  12613. * _.unset(object, ['a', '0', 'b', 'c']);
  12614. * // => true
  12615. *
  12616. * console.log(object);
  12617. * // => { 'a': [{ 'b': {} }] };
  12618. */
  12619. function unset(object, path) {
  12620. return object == null ? true : baseUnset(object, path);
  12621. }
  12622. /**
  12623. * This method is like `_.set` except that accepts `updater` to produce the
  12624. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  12625. * is invoked with one argument: (value).
  12626. *
  12627. * **Note:** This method mutates `object`.
  12628. *
  12629. * @static
  12630. * @memberOf _
  12631. * @since 4.6.0
  12632. * @category Object
  12633. * @param {Object} object The object to modify.
  12634. * @param {Array|string} path The path of the property to set.
  12635. * @param {Function} updater The function to produce the updated value.
  12636. * @returns {Object} Returns `object`.
  12637. * @example
  12638. *
  12639. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12640. *
  12641. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  12642. * console.log(object.a[0].b.c);
  12643. * // => 9
  12644. *
  12645. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  12646. * console.log(object.x[0].y.z);
  12647. * // => 0
  12648. */
  12649. function update(object, path, updater) {
  12650. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  12651. }
  12652. /**
  12653. * This method is like `_.update` except that it accepts `customizer` which is
  12654. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12655. * path creation is handled by the method instead. The `customizer` is invoked
  12656. * with three arguments: (nsValue, key, nsObject).
  12657. *
  12658. * **Note:** This method mutates `object`.
  12659. *
  12660. * @static
  12661. * @memberOf _
  12662. * @since 4.6.0
  12663. * @category Object
  12664. * @param {Object} object The object to modify.
  12665. * @param {Array|string} path The path of the property to set.
  12666. * @param {Function} updater The function to produce the updated value.
  12667. * @param {Function} [customizer] The function to customize assigned values.
  12668. * @returns {Object} Returns `object`.
  12669. * @example
  12670. *
  12671. * var object = {};
  12672. *
  12673. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  12674. * // => { '0': { '1': 'a' } }
  12675. */
  12676. function updateWith(object, path, updater, customizer) {
  12677. customizer = typeof customizer == 'function' ? customizer : undefined;
  12678. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  12679. }
  12680. /**
  12681. * Creates an array of the own enumerable string keyed property values of `object`.
  12682. *
  12683. * **Note:** Non-object values are coerced to objects.
  12684. *
  12685. * @static
  12686. * @since 0.1.0
  12687. * @memberOf _
  12688. * @category Object
  12689. * @param {Object} object The object to query.
  12690. * @returns {Array} Returns the array of property values.
  12691. * @example
  12692. *
  12693. * function Foo() {
  12694. * this.a = 1;
  12695. * this.b = 2;
  12696. * }
  12697. *
  12698. * Foo.prototype.c = 3;
  12699. *
  12700. * _.values(new Foo);
  12701. * // => [1, 2] (iteration order is not guaranteed)
  12702. *
  12703. * _.values('hi');
  12704. * // => ['h', 'i']
  12705. */
  12706. function values(object) {
  12707. return object ? baseValues(object, keys(object)) : [];
  12708. }
  12709. /**
  12710. * Creates an array of the own and inherited enumerable string keyed property
  12711. * values of `object`.
  12712. *
  12713. * **Note:** Non-object values are coerced to objects.
  12714. *
  12715. * @static
  12716. * @memberOf _
  12717. * @since 3.0.0
  12718. * @category Object
  12719. * @param {Object} object The object to query.
  12720. * @returns {Array} Returns the array of property values.
  12721. * @example
  12722. *
  12723. * function Foo() {
  12724. * this.a = 1;
  12725. * this.b = 2;
  12726. * }
  12727. *
  12728. * Foo.prototype.c = 3;
  12729. *
  12730. * _.valuesIn(new Foo);
  12731. * // => [1, 2, 3] (iteration order is not guaranteed)
  12732. */
  12733. function valuesIn(object) {
  12734. return object == null ? [] : baseValues(object, keysIn(object));
  12735. }
  12736. /*------------------------------------------------------------------------*/
  12737. /**
  12738. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  12739. *
  12740. * @static
  12741. * @memberOf _
  12742. * @since 4.0.0
  12743. * @category Number
  12744. * @param {number} number The number to clamp.
  12745. * @param {number} [lower] The lower bound.
  12746. * @param {number} upper The upper bound.
  12747. * @returns {number} Returns the clamped number.
  12748. * @example
  12749. *
  12750. * _.clamp(-10, -5, 5);
  12751. * // => -5
  12752. *
  12753. * _.clamp(10, -5, 5);
  12754. * // => 5
  12755. */
  12756. function clamp(number, lower, upper) {
  12757. if (upper === undefined) {
  12758. upper = lower;
  12759. lower = undefined;
  12760. }
  12761. if (upper !== undefined) {
  12762. upper = toNumber(upper);
  12763. upper = upper === upper ? upper : 0;
  12764. }
  12765. if (lower !== undefined) {
  12766. lower = toNumber(lower);
  12767. lower = lower === lower ? lower : 0;
  12768. }
  12769. return baseClamp(toNumber(number), lower, upper);
  12770. }
  12771. /**
  12772. * Checks if `n` is between `start` and up to, but not including, `end`. If
  12773. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  12774. * If `start` is greater than `end` the params are swapped to support
  12775. * negative ranges.
  12776. *
  12777. * @static
  12778. * @memberOf _
  12779. * @since 3.3.0
  12780. * @category Number
  12781. * @param {number} number The number to check.
  12782. * @param {number} [start=0] The start of the range.
  12783. * @param {number} end The end of the range.
  12784. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  12785. * @see _.range, _.rangeRight
  12786. * @example
  12787. *
  12788. * _.inRange(3, 2, 4);
  12789. * // => true
  12790. *
  12791. * _.inRange(4, 8);
  12792. * // => true
  12793. *
  12794. * _.inRange(4, 2);
  12795. * // => false
  12796. *
  12797. * _.inRange(2, 2);
  12798. * // => false
  12799. *
  12800. * _.inRange(1.2, 2);
  12801. * // => true
  12802. *
  12803. * _.inRange(5.2, 4);
  12804. * // => false
  12805. *
  12806. * _.inRange(-3, -2, -6);
  12807. * // => true
  12808. */
  12809. function inRange(number, start, end) {
  12810. start = toFinite(start);
  12811. if (end === undefined) {
  12812. end = start;
  12813. start = 0;
  12814. } else {
  12815. end = toFinite(end);
  12816. }
  12817. number = toNumber(number);
  12818. return baseInRange(number, start, end);
  12819. }
  12820. /**
  12821. * Produces a random number between the inclusive `lower` and `upper` bounds.
  12822. * If only one argument is provided a number between `0` and the given number
  12823. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  12824. * floats, a floating-point number is returned instead of an integer.
  12825. *
  12826. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  12827. * floating-point values which can produce unexpected results.
  12828. *
  12829. * @static
  12830. * @memberOf _
  12831. * @since 0.7.0
  12832. * @category Number
  12833. * @param {number} [lower=0] The lower bound.
  12834. * @param {number} [upper=1] The upper bound.
  12835. * @param {boolean} [floating] Specify returning a floating-point number.
  12836. * @returns {number} Returns the random number.
  12837. * @example
  12838. *
  12839. * _.random(0, 5);
  12840. * // => an integer between 0 and 5
  12841. *
  12842. * _.random(5);
  12843. * // => also an integer between 0 and 5
  12844. *
  12845. * _.random(5, true);
  12846. * // => a floating-point number between 0 and 5
  12847. *
  12848. * _.random(1.2, 5.2);
  12849. * // => a floating-point number between 1.2 and 5.2
  12850. */
  12851. function random(lower, upper, floating) {
  12852. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  12853. upper = floating = undefined;
  12854. }
  12855. if (floating === undefined) {
  12856. if (typeof upper == 'boolean') {
  12857. floating = upper;
  12858. upper = undefined;
  12859. }
  12860. else if (typeof lower == 'boolean') {
  12861. floating = lower;
  12862. lower = undefined;
  12863. }
  12864. }
  12865. if (lower === undefined && upper === undefined) {
  12866. lower = 0;
  12867. upper = 1;
  12868. }
  12869. else {
  12870. lower = toFinite(lower);
  12871. if (upper === undefined) {
  12872. upper = lower;
  12873. lower = 0;
  12874. } else {
  12875. upper = toFinite(upper);
  12876. }
  12877. }
  12878. if (lower > upper) {
  12879. var temp = lower;
  12880. lower = upper;
  12881. upper = temp;
  12882. }
  12883. if (floating || lower % 1 || upper % 1) {
  12884. var rand = nativeRandom();
  12885. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  12886. }
  12887. return baseRandom(lower, upper);
  12888. }
  12889. /*------------------------------------------------------------------------*/
  12890. /**
  12891. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  12892. *
  12893. * @static
  12894. * @memberOf _
  12895. * @since 3.0.0
  12896. * @category String
  12897. * @param {string} [string=''] The string to convert.
  12898. * @returns {string} Returns the camel cased string.
  12899. * @example
  12900. *
  12901. * _.camelCase('Foo Bar');
  12902. * // => 'fooBar'
  12903. *
  12904. * _.camelCase('--foo-bar--');
  12905. * // => 'fooBar'
  12906. *
  12907. * _.camelCase('__FOO_BAR__');
  12908. * // => 'fooBar'
  12909. */
  12910. var camelCase = createCompounder(function(result, word, index) {
  12911. word = word.toLowerCase();
  12912. return result + (index ? capitalize(word) : word);
  12913. });
  12914. /**
  12915. * Converts the first character of `string` to upper case and the remaining
  12916. * to lower case.
  12917. *
  12918. * @static
  12919. * @memberOf _
  12920. * @since 3.0.0
  12921. * @category String
  12922. * @param {string} [string=''] The string to capitalize.
  12923. * @returns {string} Returns the capitalized string.
  12924. * @example
  12925. *
  12926. * _.capitalize('FRED');
  12927. * // => 'Fred'
  12928. */
  12929. function capitalize(string) {
  12930. return upperFirst(toString(string).toLowerCase());
  12931. }
  12932. /**
  12933. * Deburrs `string` by converting
  12934. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  12935. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  12936. * letters to basic Latin letters and removing
  12937. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  12938. *
  12939. * @static
  12940. * @memberOf _
  12941. * @since 3.0.0
  12942. * @category String
  12943. * @param {string} [string=''] The string to deburr.
  12944. * @returns {string} Returns the deburred string.
  12945. * @example
  12946. *
  12947. * _.deburr('déjà vu');
  12948. * // => 'deja vu'
  12949. */
  12950. function deburr(string) {
  12951. string = toString(string);
  12952. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  12953. }
  12954. /**
  12955. * Checks if `string` ends with the given target string.
  12956. *
  12957. * @static
  12958. * @memberOf _
  12959. * @since 3.0.0
  12960. * @category String
  12961. * @param {string} [string=''] The string to inspect.
  12962. * @param {string} [target] The string to search for.
  12963. * @param {number} [position=string.length] The position to search up to.
  12964. * @returns {boolean} Returns `true` if `string` ends with `target`,
  12965. * else `false`.
  12966. * @example
  12967. *
  12968. * _.endsWith('abc', 'c');
  12969. * // => true
  12970. *
  12971. * _.endsWith('abc', 'b');
  12972. * // => false
  12973. *
  12974. * _.endsWith('abc', 'b', 2);
  12975. * // => true
  12976. */
  12977. function endsWith(string, target, position) {
  12978. string = toString(string);
  12979. target = baseToString(target);
  12980. var length = string.length;
  12981. position = position === undefined
  12982. ? length
  12983. : baseClamp(toInteger(position), 0, length);
  12984. var end = position;
  12985. position -= target.length;
  12986. return position >= 0 && string.slice(position, end) == target;
  12987. }
  12988. /**
  12989. * Converts the characters "&", "<", ">", '"', "'", and "\`" in `string` to
  12990. * their corresponding HTML entities.
  12991. *
  12992. * **Note:** No other characters are escaped. To escape additional
  12993. * characters use a third-party library like [_he_](https://mths.be/he).
  12994. *
  12995. * Though the ">" character is escaped for symmetry, characters like
  12996. * ">" and "/" don't need escaping in HTML and have no special meaning
  12997. * unless they're part of a tag or unquoted attribute value. See
  12998. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  12999. * (under "semi-related fun fact") for more details.
  13000. *
  13001. * Backticks are escaped because in IE < 9, they can break out of
  13002. * attribute values or HTML comments. See [#59](https://html5sec.org/#59),
  13003. * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
  13004. * [#133](https://html5sec.org/#133) of the
  13005. * [HTML5 Security Cheatsheet](https://html5sec.org/) for more details.
  13006. *
  13007. * When working with HTML you should always
  13008. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13009. * XSS vectors.
  13010. *
  13011. * @static
  13012. * @since 0.1.0
  13013. * @memberOf _
  13014. * @category String
  13015. * @param {string} [string=''] The string to escape.
  13016. * @returns {string} Returns the escaped string.
  13017. * @example
  13018. *
  13019. * _.escape('fred, barney, & pebbles');
  13020. * // => 'fred, barney, &amp; pebbles'
  13021. */
  13022. function escape(string) {
  13023. string = toString(string);
  13024. return (string && reHasUnescapedHtml.test(string))
  13025. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13026. : string;
  13027. }
  13028. /**
  13029. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13030. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13031. *
  13032. * @static
  13033. * @memberOf _
  13034. * @since 3.0.0
  13035. * @category String
  13036. * @param {string} [string=''] The string to escape.
  13037. * @returns {string} Returns the escaped string.
  13038. * @example
  13039. *
  13040. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13041. * // => '\[lodash\]\(https://lodash\.com/\)'
  13042. */
  13043. function escapeRegExp(string) {
  13044. string = toString(string);
  13045. return (string && reHasRegExpChar.test(string))
  13046. ? string.replace(reRegExpChar, '\\$&')
  13047. : string;
  13048. }
  13049. /**
  13050. * Converts `string` to
  13051. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13052. *
  13053. * @static
  13054. * @memberOf _
  13055. * @since 3.0.0
  13056. * @category String
  13057. * @param {string} [string=''] The string to convert.
  13058. * @returns {string} Returns the kebab cased string.
  13059. * @example
  13060. *
  13061. * _.kebabCase('Foo Bar');
  13062. * // => 'foo-bar'
  13063. *
  13064. * _.kebabCase('fooBar');
  13065. * // => 'foo-bar'
  13066. *
  13067. * _.kebabCase('__FOO_BAR__');
  13068. * // => 'foo-bar'
  13069. */
  13070. var kebabCase = createCompounder(function(result, word, index) {
  13071. return result + (index ? '-' : '') + word.toLowerCase();
  13072. });
  13073. /**
  13074. * Converts `string`, as space separated words, to lower case.
  13075. *
  13076. * @static
  13077. * @memberOf _
  13078. * @since 4.0.0
  13079. * @category String
  13080. * @param {string} [string=''] The string to convert.
  13081. * @returns {string} Returns the lower cased string.
  13082. * @example
  13083. *
  13084. * _.lowerCase('--Foo-Bar--');
  13085. * // => 'foo bar'
  13086. *
  13087. * _.lowerCase('fooBar');
  13088. * // => 'foo bar'
  13089. *
  13090. * _.lowerCase('__FOO_BAR__');
  13091. * // => 'foo bar'
  13092. */
  13093. var lowerCase = createCompounder(function(result, word, index) {
  13094. return result + (index ? ' ' : '') + word.toLowerCase();
  13095. });
  13096. /**
  13097. * Converts the first character of `string` to lower case.
  13098. *
  13099. * @static
  13100. * @memberOf _
  13101. * @since 4.0.0
  13102. * @category String
  13103. * @param {string} [string=''] The string to convert.
  13104. * @returns {string} Returns the converted string.
  13105. * @example
  13106. *
  13107. * _.lowerFirst('Fred');
  13108. * // => 'fred'
  13109. *
  13110. * _.lowerFirst('FRED');
  13111. * // => 'fRED'
  13112. */
  13113. var lowerFirst = createCaseFirst('toLowerCase');
  13114. /**
  13115. * Pads `string` on the left and right sides if it's shorter than `length`.
  13116. * Padding characters are truncated if they can't be evenly divided by `length`.
  13117. *
  13118. * @static
  13119. * @memberOf _
  13120. * @since 3.0.0
  13121. * @category String
  13122. * @param {string} [string=''] The string to pad.
  13123. * @param {number} [length=0] The padding length.
  13124. * @param {string} [chars=' '] The string used as padding.
  13125. * @returns {string} Returns the padded string.
  13126. * @example
  13127. *
  13128. * _.pad('abc', 8);
  13129. * // => ' abc '
  13130. *
  13131. * _.pad('abc', 8, '_-');
  13132. * // => '_-abc_-_'
  13133. *
  13134. * _.pad('abc', 3);
  13135. * // => 'abc'
  13136. */
  13137. function pad(string, length, chars) {
  13138. string = toString(string);
  13139. length = toInteger(length);
  13140. var strLength = length ? stringSize(string) : 0;
  13141. if (!length || strLength >= length) {
  13142. return string;
  13143. }
  13144. var mid = (length - strLength) / 2;
  13145. return (
  13146. createPadding(nativeFloor(mid), chars) +
  13147. string +
  13148. createPadding(nativeCeil(mid), chars)
  13149. );
  13150. }
  13151. /**
  13152. * Pads `string` on the right side if it's shorter than `length`. Padding
  13153. * characters are truncated if they exceed `length`.
  13154. *
  13155. * @static
  13156. * @memberOf _
  13157. * @since 4.0.0
  13158. * @category String
  13159. * @param {string} [string=''] The string to pad.
  13160. * @param {number} [length=0] The padding length.
  13161. * @param {string} [chars=' '] The string used as padding.
  13162. * @returns {string} Returns the padded string.
  13163. * @example
  13164. *
  13165. * _.padEnd('abc', 6);
  13166. * // => 'abc '
  13167. *
  13168. * _.padEnd('abc', 6, '_-');
  13169. * // => 'abc_-_'
  13170. *
  13171. * _.padEnd('abc', 3);
  13172. * // => 'abc'
  13173. */
  13174. function padEnd(string, length, chars) {
  13175. string = toString(string);
  13176. length = toInteger(length);
  13177. var strLength = length ? stringSize(string) : 0;
  13178. return (length && strLength < length)
  13179. ? (string + createPadding(length - strLength, chars))
  13180. : string;
  13181. }
  13182. /**
  13183. * Pads `string` on the left side if it's shorter than `length`. Padding
  13184. * characters are truncated if they exceed `length`.
  13185. *
  13186. * @static
  13187. * @memberOf _
  13188. * @since 4.0.0
  13189. * @category String
  13190. * @param {string} [string=''] The string to pad.
  13191. * @param {number} [length=0] The padding length.
  13192. * @param {string} [chars=' '] The string used as padding.
  13193. * @returns {string} Returns the padded string.
  13194. * @example
  13195. *
  13196. * _.padStart('abc', 6);
  13197. * // => ' abc'
  13198. *
  13199. * _.padStart('abc', 6, '_-');
  13200. * // => '_-_abc'
  13201. *
  13202. * _.padStart('abc', 3);
  13203. * // => 'abc'
  13204. */
  13205. function padStart(string, length, chars) {
  13206. string = toString(string);
  13207. length = toInteger(length);
  13208. var strLength = length ? stringSize(string) : 0;
  13209. return (length && strLength < length)
  13210. ? (createPadding(length - strLength, chars) + string)
  13211. : string;
  13212. }
  13213. /**
  13214. * Converts `string` to an integer of the specified radix. If `radix` is
  13215. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13216. * hexadecimal, in which case a `radix` of `16` is used.
  13217. *
  13218. * **Note:** This method aligns with the
  13219. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13220. *
  13221. * @static
  13222. * @memberOf _
  13223. * @since 1.1.0
  13224. * @category String
  13225. * @param {string} string The string to convert.
  13226. * @param {number} [radix=10] The radix to interpret `value` by.
  13227. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13228. * @returns {number} Returns the converted integer.
  13229. * @example
  13230. *
  13231. * _.parseInt('08');
  13232. * // => 8
  13233. *
  13234. * _.map(['6', '08', '10'], _.parseInt);
  13235. * // => [6, 8, 10]
  13236. */
  13237. function parseInt(string, radix, guard) {
  13238. // Chrome fails to trim leading <BOM> whitespace characters.
  13239. // See https://bugs.chromium.org/p/v8/issues/detail?id=3109 for more details.
  13240. if (guard || radix == null) {
  13241. radix = 0;
  13242. } else if (radix) {
  13243. radix = +radix;
  13244. }
  13245. string = toString(string).replace(reTrim, '');
  13246. return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
  13247. }
  13248. /**
  13249. * Repeats the given string `n` times.
  13250. *
  13251. * @static
  13252. * @memberOf _
  13253. * @since 3.0.0
  13254. * @category String
  13255. * @param {string} [string=''] The string to repeat.
  13256. * @param {number} [n=1] The number of times to repeat the string.
  13257. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13258. * @returns {string} Returns the repeated string.
  13259. * @example
  13260. *
  13261. * _.repeat('*', 3);
  13262. * // => '***'
  13263. *
  13264. * _.repeat('abc', 2);
  13265. * // => 'abcabc'
  13266. *
  13267. * _.repeat('abc', 0);
  13268. * // => ''
  13269. */
  13270. function repeat(string, n, guard) {
  13271. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13272. n = 1;
  13273. } else {
  13274. n = toInteger(n);
  13275. }
  13276. return baseRepeat(toString(string), n);
  13277. }
  13278. /**
  13279. * Replaces matches for `pattern` in `string` with `replacement`.
  13280. *
  13281. * **Note:** This method is based on
  13282. * [`String#replace`](https://mdn.io/String/replace).
  13283. *
  13284. * @static
  13285. * @memberOf _
  13286. * @since 4.0.0
  13287. * @category String
  13288. * @param {string} [string=''] The string to modify.
  13289. * @param {RegExp|string} pattern The pattern to replace.
  13290. * @param {Function|string} replacement The match replacement.
  13291. * @returns {string} Returns the modified string.
  13292. * @example
  13293. *
  13294. * _.replace('Hi Fred', 'Fred', 'Barney');
  13295. * // => 'Hi Barney'
  13296. */
  13297. function replace() {
  13298. var args = arguments,
  13299. string = toString(args[0]);
  13300. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13301. }
  13302. /**
  13303. * Converts `string` to
  13304. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13305. *
  13306. * @static
  13307. * @memberOf _
  13308. * @since 3.0.0
  13309. * @category String
  13310. * @param {string} [string=''] The string to convert.
  13311. * @returns {string} Returns the snake cased string.
  13312. * @example
  13313. *
  13314. * _.snakeCase('Foo Bar');
  13315. * // => 'foo_bar'
  13316. *
  13317. * _.snakeCase('fooBar');
  13318. * // => 'foo_bar'
  13319. *
  13320. * _.snakeCase('--FOO-BAR--');
  13321. * // => 'foo_bar'
  13322. */
  13323. var snakeCase = createCompounder(function(result, word, index) {
  13324. return result + (index ? '_' : '') + word.toLowerCase();
  13325. });
  13326. /**
  13327. * Splits `string` by `separator`.
  13328. *
  13329. * **Note:** This method is based on
  13330. * [`String#split`](https://mdn.io/String/split).
  13331. *
  13332. * @static
  13333. * @memberOf _
  13334. * @since 4.0.0
  13335. * @category String
  13336. * @param {string} [string=''] The string to split.
  13337. * @param {RegExp|string} separator The separator pattern to split by.
  13338. * @param {number} [limit] The length to truncate results to.
  13339. * @returns {Array} Returns the string segments.
  13340. * @example
  13341. *
  13342. * _.split('a-b-c', '-', 2);
  13343. * // => ['a', 'b']
  13344. */
  13345. function split(string, separator, limit) {
  13346. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13347. separator = limit = undefined;
  13348. }
  13349. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13350. if (!limit) {
  13351. return [];
  13352. }
  13353. string = toString(string);
  13354. if (string && (
  13355. typeof separator == 'string' ||
  13356. (separator != null && !isRegExp(separator))
  13357. )) {
  13358. separator = baseToString(separator);
  13359. if (!separator && hasUnicode(string)) {
  13360. return castSlice(stringToArray(string), 0, limit);
  13361. }
  13362. }
  13363. return string.split(separator, limit);
  13364. }
  13365. /**
  13366. * Converts `string` to
  13367. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13368. *
  13369. * @static
  13370. * @memberOf _
  13371. * @since 3.1.0
  13372. * @category String
  13373. * @param {string} [string=''] The string to convert.
  13374. * @returns {string} Returns the start cased string.
  13375. * @example
  13376. *
  13377. * _.startCase('--foo-bar--');
  13378. * // => 'Foo Bar'
  13379. *
  13380. * _.startCase('fooBar');
  13381. * // => 'Foo Bar'
  13382. *
  13383. * _.startCase('__FOO_BAR__');
  13384. * // => 'FOO BAR'
  13385. */
  13386. var startCase = createCompounder(function(result, word, index) {
  13387. return result + (index ? ' ' : '') + upperFirst(word);
  13388. });
  13389. /**
  13390. * Checks if `string` starts with the given target string.
  13391. *
  13392. * @static
  13393. * @memberOf _
  13394. * @since 3.0.0
  13395. * @category String
  13396. * @param {string} [string=''] The string to inspect.
  13397. * @param {string} [target] The string to search for.
  13398. * @param {number} [position=0] The position to search from.
  13399. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13400. * else `false`.
  13401. * @example
  13402. *
  13403. * _.startsWith('abc', 'a');
  13404. * // => true
  13405. *
  13406. * _.startsWith('abc', 'b');
  13407. * // => false
  13408. *
  13409. * _.startsWith('abc', 'b', 1);
  13410. * // => true
  13411. */
  13412. function startsWith(string, target, position) {
  13413. string = toString(string);
  13414. position = baseClamp(toInteger(position), 0, string.length);
  13415. target = baseToString(target);
  13416. return string.slice(position, position + target.length) == target;
  13417. }
  13418. /**
  13419. * Creates a compiled template function that can interpolate data properties
  13420. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13421. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13422. * properties may be accessed as free variables in the template. If a setting
  13423. * object is given, it takes precedence over `_.templateSettings` values.
  13424. *
  13425. * **Note:** In the development build `_.template` utilizes
  13426. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13427. * for easier debugging.
  13428. *
  13429. * For more information on precompiling templates see
  13430. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13431. *
  13432. * For more information on Chrome extension sandboxes see
  13433. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13434. *
  13435. * @static
  13436. * @since 0.1.0
  13437. * @memberOf _
  13438. * @category String
  13439. * @param {string} [string=''] The template string.
  13440. * @param {Object} [options={}] The options object.
  13441. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13442. * The HTML "escape" delimiter.
  13443. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13444. * The "evaluate" delimiter.
  13445. * @param {Object} [options.imports=_.templateSettings.imports]
  13446. * An object to import into the template as free variables.
  13447. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13448. * The "interpolate" delimiter.
  13449. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13450. * The sourceURL of the compiled template.
  13451. * @param {string} [options.variable='obj']
  13452. * The data object variable name.
  13453. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13454. * @returns {Function} Returns the compiled template function.
  13455. * @example
  13456. *
  13457. * // Use the "interpolate" delimiter to create a compiled template.
  13458. * var compiled = _.template('hello <%= user %>!');
  13459. * compiled({ 'user': 'fred' });
  13460. * // => 'hello fred!'
  13461. *
  13462. * // Use the HTML "escape" delimiter to escape data property values.
  13463. * var compiled = _.template('<b><%- value %></b>');
  13464. * compiled({ 'value': '<script>' });
  13465. * // => '<b>&lt;script&gt;</b>'
  13466. *
  13467. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13468. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13469. * compiled({ 'users': ['fred', 'barney'] });
  13470. * // => '<li>fred</li><li>barney</li>'
  13471. *
  13472. * // Use the internal `print` function in "evaluate" delimiters.
  13473. * var compiled = _.template('<% print("hello " + user); %>!');
  13474. * compiled({ 'user': 'barney' });
  13475. * // => 'hello barney!'
  13476. *
  13477. * // Use the ES delimiter as an alternative to the default "interpolate" delimiter.
  13478. * var compiled = _.template('hello ${ user }!');
  13479. * compiled({ 'user': 'pebbles' });
  13480. * // => 'hello pebbles!'
  13481. *
  13482. * // Use backslashes to treat delimiters as plain text.
  13483. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13484. * compiled({ 'value': 'ignored' });
  13485. * // => '<%- value %>'
  13486. *
  13487. * // Use the `imports` option to import `jQuery` as `jq`.
  13488. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13489. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13490. * compiled({ 'users': ['fred', 'barney'] });
  13491. * // => '<li>fred</li><li>barney</li>'
  13492. *
  13493. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13494. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13495. * compiled(data);
  13496. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13497. *
  13498. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13499. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13500. * compiled.source;
  13501. * // => function(data) {
  13502. * // var __t, __p = '';
  13503. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13504. * // return __p;
  13505. * // }
  13506. *
  13507. * // Use custom template delimiters.
  13508. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13509. * var compiled = _.template('hello {{ user }}!');
  13510. * compiled({ 'user': 'mustache' });
  13511. * // => 'hello mustache!'
  13512. *
  13513. * // Use the `source` property to inline compiled templates for meaningful
  13514. * // line numbers in error messages and stack traces.
  13515. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13516. * var JST = {\
  13517. * "main": ' + _.template(mainText).source + '\
  13518. * };\
  13519. * ');
  13520. */
  13521. function template(string, options, guard) {
  13522. // Based on John Resig's `tmpl` implementation
  13523. // (http://ejohn.org/blog/javascript-micro-templating/)
  13524. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13525. var settings = lodash.templateSettings;
  13526. if (guard && isIterateeCall(string, options, guard)) {
  13527. options = undefined;
  13528. }
  13529. string = toString(string);
  13530. options = assignInWith({}, options, settings, assignInDefaults);
  13531. var imports = assignInWith({}, options.imports, settings.imports, assignInDefaults),
  13532. importsKeys = keys(imports),
  13533. importsValues = baseValues(imports, importsKeys);
  13534. var isEscaping,
  13535. isEvaluating,
  13536. index = 0,
  13537. interpolate = options.interpolate || reNoMatch,
  13538. source = "__p += '";
  13539. // Compile the regexp to match each delimiter.
  13540. var reDelimiters = RegExp(
  13541. (options.escape || reNoMatch).source + '|' +
  13542. interpolate.source + '|' +
  13543. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13544. (options.evaluate || reNoMatch).source + '|$'
  13545. , 'g');
  13546. // Use a sourceURL for easier debugging.
  13547. var sourceURL = '//# sourceURL=' +
  13548. ('sourceURL' in options
  13549. ? options.sourceURL
  13550. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13551. ) + '\n';
  13552. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13553. interpolateValue || (interpolateValue = esTemplateValue);
  13554. // Escape characters that can't be included in string literals.
  13555. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13556. // Replace delimiters with snippets.
  13557. if (escapeValue) {
  13558. isEscaping = true;
  13559. source += "' +\n__e(" + escapeValue + ") +\n'";
  13560. }
  13561. if (evaluateValue) {
  13562. isEvaluating = true;
  13563. source += "';\n" + evaluateValue + ";\n__p += '";
  13564. }
  13565. if (interpolateValue) {
  13566. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13567. }
  13568. index = offset + match.length;
  13569. // The JS engine embedded in Adobe products needs `match` returned in
  13570. // order to produce the correct `offset` value.
  13571. return match;
  13572. });
  13573. source += "';\n";
  13574. // If `variable` is not specified wrap a with-statement around the generated
  13575. // code to add the data object to the top of the scope chain.
  13576. var variable = options.variable;
  13577. if (!variable) {
  13578. source = 'with (obj) {\n' + source + '\n}\n';
  13579. }
  13580. // Cleanup code by stripping empty strings.
  13581. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13582. .replace(reEmptyStringMiddle, '$1')
  13583. .replace(reEmptyStringTrailing, '$1;');
  13584. // Frame code as the function body.
  13585. source = 'function(' + (variable || 'obj') + ') {\n' +
  13586. (variable
  13587. ? ''
  13588. : 'obj || (obj = {});\n'
  13589. ) +
  13590. "var __t, __p = ''" +
  13591. (isEscaping
  13592. ? ', __e = _.escape'
  13593. : ''
  13594. ) +
  13595. (isEvaluating
  13596. ? ', __j = Array.prototype.join;\n' +
  13597. "function print() { __p += __j.call(arguments, '') }\n"
  13598. : ';\n'
  13599. ) +
  13600. source +
  13601. 'return __p\n}';
  13602. var result = attempt(function() {
  13603. return Function(importsKeys, sourceURL + 'return ' + source)
  13604. .apply(undefined, importsValues);
  13605. });
  13606. // Provide the compiled function's source by its `toString` method or
  13607. // the `source` property as a convenience for inlining compiled templates.
  13608. result.source = source;
  13609. if (isError(result)) {
  13610. throw result;
  13611. }
  13612. return result;
  13613. }
  13614. /**
  13615. * Converts `string`, as a whole, to lower case just like
  13616. * [String#toLowerCase](https://mdn.io/toLowerCase).
  13617. *
  13618. * @static
  13619. * @memberOf _
  13620. * @since 4.0.0
  13621. * @category String
  13622. * @param {string} [string=''] The string to convert.
  13623. * @returns {string} Returns the lower cased string.
  13624. * @example
  13625. *
  13626. * _.toLower('--Foo-Bar--');
  13627. * // => '--foo-bar--'
  13628. *
  13629. * _.toLower('fooBar');
  13630. * // => 'foobar'
  13631. *
  13632. * _.toLower('__FOO_BAR__');
  13633. * // => '__foo_bar__'
  13634. */
  13635. function toLower(value) {
  13636. return toString(value).toLowerCase();
  13637. }
  13638. /**
  13639. * Converts `string`, as a whole, to upper case just like
  13640. * [String#toUpperCase](https://mdn.io/toUpperCase).
  13641. *
  13642. * @static
  13643. * @memberOf _
  13644. * @since 4.0.0
  13645. * @category String
  13646. * @param {string} [string=''] The string to convert.
  13647. * @returns {string} Returns the upper cased string.
  13648. * @example
  13649. *
  13650. * _.toUpper('--foo-bar--');
  13651. * // => '--FOO-BAR--'
  13652. *
  13653. * _.toUpper('fooBar');
  13654. * // => 'FOOBAR'
  13655. *
  13656. * _.toUpper('__foo_bar__');
  13657. * // => '__FOO_BAR__'
  13658. */
  13659. function toUpper(value) {
  13660. return toString(value).toUpperCase();
  13661. }
  13662. /**
  13663. * Removes leading and trailing whitespace or specified characters from `string`.
  13664. *
  13665. * @static
  13666. * @memberOf _
  13667. * @since 3.0.0
  13668. * @category String
  13669. * @param {string} [string=''] The string to trim.
  13670. * @param {string} [chars=whitespace] The characters to trim.
  13671. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13672. * @returns {string} Returns the trimmed string.
  13673. * @example
  13674. *
  13675. * _.trim(' abc ');
  13676. * // => 'abc'
  13677. *
  13678. * _.trim('-_-abc-_-', '_-');
  13679. * // => 'abc'
  13680. *
  13681. * _.map([' foo ', ' bar '], _.trim);
  13682. * // => ['foo', 'bar']
  13683. */
  13684. function trim(string, chars, guard) {
  13685. string = toString(string);
  13686. if (string && (guard || chars === undefined)) {
  13687. return string.replace(reTrim, '');
  13688. }
  13689. if (!string || !(chars = baseToString(chars))) {
  13690. return string;
  13691. }
  13692. var strSymbols = stringToArray(string),
  13693. chrSymbols = stringToArray(chars),
  13694. start = charsStartIndex(strSymbols, chrSymbols),
  13695. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  13696. return castSlice(strSymbols, start, end).join('');
  13697. }
  13698. /**
  13699. * Removes trailing whitespace or specified characters from `string`.
  13700. *
  13701. * @static
  13702. * @memberOf _
  13703. * @since 4.0.0
  13704. * @category String
  13705. * @param {string} [string=''] The string to trim.
  13706. * @param {string} [chars=whitespace] The characters to trim.
  13707. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13708. * @returns {string} Returns the trimmed string.
  13709. * @example
  13710. *
  13711. * _.trimEnd(' abc ');
  13712. * // => ' abc'
  13713. *
  13714. * _.trimEnd('-_-abc-_-', '_-');
  13715. * // => '-_-abc'
  13716. */
  13717. function trimEnd(string, chars, guard) {
  13718. string = toString(string);
  13719. if (string && (guard || chars === undefined)) {
  13720. return string.replace(reTrimEnd, '');
  13721. }
  13722. if (!string || !(chars = baseToString(chars))) {
  13723. return string;
  13724. }
  13725. var strSymbols = stringToArray(string),
  13726. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  13727. return castSlice(strSymbols, 0, end).join('');
  13728. }
  13729. /**
  13730. * Removes leading whitespace or specified characters from `string`.
  13731. *
  13732. * @static
  13733. * @memberOf _
  13734. * @since 4.0.0
  13735. * @category String
  13736. * @param {string} [string=''] The string to trim.
  13737. * @param {string} [chars=whitespace] The characters to trim.
  13738. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13739. * @returns {string} Returns the trimmed string.
  13740. * @example
  13741. *
  13742. * _.trimStart(' abc ');
  13743. * // => 'abc '
  13744. *
  13745. * _.trimStart('-_-abc-_-', '_-');
  13746. * // => 'abc-_-'
  13747. */
  13748. function trimStart(string, chars, guard) {
  13749. string = toString(string);
  13750. if (string && (guard || chars === undefined)) {
  13751. return string.replace(reTrimStart, '');
  13752. }
  13753. if (!string || !(chars = baseToString(chars))) {
  13754. return string;
  13755. }
  13756. var strSymbols = stringToArray(string),
  13757. start = charsStartIndex(strSymbols, stringToArray(chars));
  13758. return castSlice(strSymbols, start).join('');
  13759. }
  13760. /**
  13761. * Truncates `string` if it's longer than the given maximum string length.
  13762. * The last characters of the truncated string are replaced with the omission
  13763. * string which defaults to "...".
  13764. *
  13765. * @static
  13766. * @memberOf _
  13767. * @since 4.0.0
  13768. * @category String
  13769. * @param {string} [string=''] The string to truncate.
  13770. * @param {Object} [options={}] The options object.
  13771. * @param {number} [options.length=30] The maximum string length.
  13772. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  13773. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  13774. * @returns {string} Returns the truncated string.
  13775. * @example
  13776. *
  13777. * _.truncate('hi-diddly-ho there, neighborino');
  13778. * // => 'hi-diddly-ho there, neighbo...'
  13779. *
  13780. * _.truncate('hi-diddly-ho there, neighborino', {
  13781. * 'length': 24,
  13782. * 'separator': ' '
  13783. * });
  13784. * // => 'hi-diddly-ho there,...'
  13785. *
  13786. * _.truncate('hi-diddly-ho there, neighborino', {
  13787. * 'length': 24,
  13788. * 'separator': /,? +/
  13789. * });
  13790. * // => 'hi-diddly-ho there...'
  13791. *
  13792. * _.truncate('hi-diddly-ho there, neighborino', {
  13793. * 'omission': ' [...]'
  13794. * });
  13795. * // => 'hi-diddly-ho there, neig [...]'
  13796. */
  13797. function truncate(string, options) {
  13798. var length = DEFAULT_TRUNC_LENGTH,
  13799. omission = DEFAULT_TRUNC_OMISSION;
  13800. if (isObject(options)) {
  13801. var separator = 'separator' in options ? options.separator : separator;
  13802. length = 'length' in options ? toInteger(options.length) : length;
  13803. omission = 'omission' in options ? baseToString(options.omission) : omission;
  13804. }
  13805. string = toString(string);
  13806. var strLength = string.length;
  13807. if (hasUnicode(string)) {
  13808. var strSymbols = stringToArray(string);
  13809. strLength = strSymbols.length;
  13810. }
  13811. if (length >= strLength) {
  13812. return string;
  13813. }
  13814. var end = length - stringSize(omission);
  13815. if (end < 1) {
  13816. return omission;
  13817. }
  13818. var result = strSymbols
  13819. ? castSlice(strSymbols, 0, end).join('')
  13820. : string.slice(0, end);
  13821. if (separator === undefined) {
  13822. return result + omission;
  13823. }
  13824. if (strSymbols) {
  13825. end += (result.length - end);
  13826. }
  13827. if (isRegExp(separator)) {
  13828. if (string.slice(end).search(separator)) {
  13829. var match,
  13830. substring = result;
  13831. if (!separator.global) {
  13832. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  13833. }
  13834. separator.lastIndex = 0;
  13835. while ((match = separator.exec(substring))) {
  13836. var newEnd = match.index;
  13837. }
  13838. result = result.slice(0, newEnd === undefined ? end : newEnd);
  13839. }
  13840. } else if (string.indexOf(baseToString(separator), end) != end) {
  13841. var index = result.lastIndexOf(separator);
  13842. if (index > -1) {
  13843. result = result.slice(0, index);
  13844. }
  13845. }
  13846. return result + omission;
  13847. }
  13848. /**
  13849. * The inverse of `_.escape`; this method converts the HTML entities
  13850. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to
  13851. * their corresponding characters.
  13852. *
  13853. * **Note:** No other HTML entities are unescaped. To unescape additional
  13854. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  13855. *
  13856. * @static
  13857. * @memberOf _
  13858. * @since 0.6.0
  13859. * @category String
  13860. * @param {string} [string=''] The string to unescape.
  13861. * @returns {string} Returns the unescaped string.
  13862. * @example
  13863. *
  13864. * _.unescape('fred, barney, &amp; pebbles');
  13865. * // => 'fred, barney, & pebbles'
  13866. */
  13867. function unescape(string) {
  13868. string = toString(string);
  13869. return (string && reHasEscapedHtml.test(string))
  13870. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  13871. : string;
  13872. }
  13873. /**
  13874. * Converts `string`, as space separated words, to upper case.
  13875. *
  13876. * @static
  13877. * @memberOf _
  13878. * @since 4.0.0
  13879. * @category String
  13880. * @param {string} [string=''] The string to convert.
  13881. * @returns {string} Returns the upper cased string.
  13882. * @example
  13883. *
  13884. * _.upperCase('--foo-bar');
  13885. * // => 'FOO BAR'
  13886. *
  13887. * _.upperCase('fooBar');
  13888. * // => 'FOO BAR'
  13889. *
  13890. * _.upperCase('__foo_bar__');
  13891. * // => 'FOO BAR'
  13892. */
  13893. var upperCase = createCompounder(function(result, word, index) {
  13894. return result + (index ? ' ' : '') + word.toUpperCase();
  13895. });
  13896. /**
  13897. * Converts the first character of `string` to upper case.
  13898. *
  13899. * @static
  13900. * @memberOf _
  13901. * @since 4.0.0
  13902. * @category String
  13903. * @param {string} [string=''] The string to convert.
  13904. * @returns {string} Returns the converted string.
  13905. * @example
  13906. *
  13907. * _.upperFirst('fred');
  13908. * // => 'Fred'
  13909. *
  13910. * _.upperFirst('FRED');
  13911. * // => 'FRED'
  13912. */
  13913. var upperFirst = createCaseFirst('toUpperCase');
  13914. /**
  13915. * Splits `string` into an array of its words.
  13916. *
  13917. * @static
  13918. * @memberOf _
  13919. * @since 3.0.0
  13920. * @category String
  13921. * @param {string} [string=''] The string to inspect.
  13922. * @param {RegExp|string} [pattern] The pattern to match words.
  13923. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13924. * @returns {Array} Returns the words of `string`.
  13925. * @example
  13926. *
  13927. * _.words('fred, barney, & pebbles');
  13928. * // => ['fred', 'barney', 'pebbles']
  13929. *
  13930. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  13931. * // => ['fred', 'barney', '&', 'pebbles']
  13932. */
  13933. function words(string, pattern, guard) {
  13934. string = toString(string);
  13935. pattern = guard ? undefined : pattern;
  13936. if (pattern === undefined) {
  13937. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  13938. }
  13939. return string.match(pattern) || [];
  13940. }
  13941. /*------------------------------------------------------------------------*/
  13942. /**
  13943. * Attempts to invoke `func`, returning either the result or the caught error
  13944. * object. Any additional arguments are provided to `func` when it's invoked.
  13945. *
  13946. * @static
  13947. * @memberOf _
  13948. * @since 3.0.0
  13949. * @category Util
  13950. * @param {Function} func The function to attempt.
  13951. * @param {...*} [args] The arguments to invoke `func` with.
  13952. * @returns {*} Returns the `func` result or error object.
  13953. * @example
  13954. *
  13955. * // Avoid throwing errors for invalid selectors.
  13956. * var elements = _.attempt(function(selector) {
  13957. * return document.querySelectorAll(selector);
  13958. * }, '>_>');
  13959. *
  13960. * if (_.isError(elements)) {
  13961. * elements = [];
  13962. * }
  13963. */
  13964. var attempt = baseRest(function(func, args) {
  13965. try {
  13966. return apply(func, undefined, args);
  13967. } catch (e) {
  13968. return isError(e) ? e : new Error(e);
  13969. }
  13970. });
  13971. /**
  13972. * Binds methods of an object to the object itself, overwriting the existing
  13973. * method.
  13974. *
  13975. * **Note:** This method doesn't set the "length" property of bound functions.
  13976. *
  13977. * @static
  13978. * @since 0.1.0
  13979. * @memberOf _
  13980. * @category Util
  13981. * @param {Object} object The object to bind and assign the bound methods to.
  13982. * @param {...(string|string[])} methodNames The object method names to bind.
  13983. * @returns {Object} Returns `object`.
  13984. * @example
  13985. *
  13986. * var view = {
  13987. * 'label': 'docs',
  13988. * 'click': function() {
  13989. * console.log('clicked ' + this.label);
  13990. * }
  13991. * };
  13992. *
  13993. * _.bindAll(view, ['click']);
  13994. * jQuery(element).on('click', view.click);
  13995. * // => Logs 'clicked docs' when clicked.
  13996. */
  13997. var bindAll = baseRest(function(object, methodNames) {
  13998. arrayEach(baseFlatten(methodNames, 1), function(key) {
  13999. key = toKey(key);
  14000. object[key] = bind(object[key], object);
  14001. });
  14002. return object;
  14003. });
  14004. /**
  14005. * Creates a function that iterates over `pairs` and invokes the corresponding
  14006. * function of the first predicate to return truthy. The predicate-function
  14007. * pairs are invoked with the `this` binding and arguments of the created
  14008. * function.
  14009. *
  14010. * @static
  14011. * @memberOf _
  14012. * @since 4.0.0
  14013. * @category Util
  14014. * @param {Array} pairs The predicate-function pairs.
  14015. * @returns {Function} Returns the new composite function.
  14016. * @example
  14017. *
  14018. * var func = _.cond([
  14019. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14020. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14021. * [_.stubTrue, _.constant('no match')]
  14022. * ]);
  14023. *
  14024. * func({ 'a': 1, 'b': 2 });
  14025. * // => 'matches A'
  14026. *
  14027. * func({ 'a': 0, 'b': 1 });
  14028. * // => 'matches B'
  14029. *
  14030. * func({ 'a': '1', 'b': '2' });
  14031. * // => 'no match'
  14032. */
  14033. function cond(pairs) {
  14034. var length = pairs ? pairs.length : 0,
  14035. toIteratee = getIteratee();
  14036. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14037. if (typeof pair[1] != 'function') {
  14038. throw new TypeError(FUNC_ERROR_TEXT);
  14039. }
  14040. return [toIteratee(pair[0]), pair[1]];
  14041. });
  14042. return baseRest(function(args) {
  14043. var index = -1;
  14044. while (++index < length) {
  14045. var pair = pairs[index];
  14046. if (apply(pair[0], this, args)) {
  14047. return apply(pair[1], this, args);
  14048. }
  14049. }
  14050. });
  14051. }
  14052. /**
  14053. * Creates a function that invokes the predicate properties of `source` with
  14054. * the corresponding property values of a given object, returning `true` if
  14055. * all predicates return truthy, else `false`.
  14056. *
  14057. * **Note:** The created function is equivalent to `_.conformsTo` with
  14058. * `source` partially applied.
  14059. *
  14060. * @static
  14061. * @memberOf _
  14062. * @since 4.0.0
  14063. * @category Util
  14064. * @param {Object} source The object of property predicates to conform to.
  14065. * @returns {Function} Returns the new spec function.
  14066. * @example
  14067. *
  14068. * var objects = [
  14069. * { 'a': 2, 'b': 1 },
  14070. * { 'a': 1, 'b': 2 }
  14071. * ];
  14072. *
  14073. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14074. * // => [{ 'a': 1, 'b': 2 }]
  14075. */
  14076. function conforms(source) {
  14077. return baseConforms(baseClone(source, true));
  14078. }
  14079. /**
  14080. * Creates a function that returns `value`.
  14081. *
  14082. * @static
  14083. * @memberOf _
  14084. * @since 2.4.0
  14085. * @category Util
  14086. * @param {*} value The value to return from the new function.
  14087. * @returns {Function} Returns the new constant function.
  14088. * @example
  14089. *
  14090. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14091. *
  14092. * console.log(objects);
  14093. * // => [{ 'a': 1 }, { 'a': 1 }]
  14094. *
  14095. * console.log(objects[0] === objects[1]);
  14096. * // => true
  14097. */
  14098. function constant(value) {
  14099. return function() {
  14100. return value;
  14101. };
  14102. }
  14103. /**
  14104. * Checks `value` to determine whether a default value should be returned in
  14105. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14106. * or `undefined`.
  14107. *
  14108. * @static
  14109. * @memberOf _
  14110. * @since 4.14.0
  14111. * @category Util
  14112. * @param {*} value The value to check.
  14113. * @param {*} defaultValue The default value.
  14114. * @returns {*} Returns the resolved value.
  14115. * @example
  14116. *
  14117. * _.defaultTo(1, 10);
  14118. * // => 1
  14119. *
  14120. * _.defaultTo(undefined, 10);
  14121. * // => 10
  14122. */
  14123. function defaultTo(value, defaultValue) {
  14124. return (value == null || value !== value) ? defaultValue : value;
  14125. }
  14126. /**
  14127. * Creates a function that returns the result of invoking the given functions
  14128. * with the `this` binding of the created function, where each successive
  14129. * invocation is supplied the return value of the previous.
  14130. *
  14131. * @static
  14132. * @memberOf _
  14133. * @since 3.0.0
  14134. * @category Util
  14135. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14136. * @returns {Function} Returns the new composite function.
  14137. * @see _.flowRight
  14138. * @example
  14139. *
  14140. * function square(n) {
  14141. * return n * n;
  14142. * }
  14143. *
  14144. * var addSquare = _.flow([_.add, square]);
  14145. * addSquare(1, 2);
  14146. * // => 9
  14147. */
  14148. var flow = createFlow();
  14149. /**
  14150. * This method is like `_.flow` except that it creates a function that
  14151. * invokes the given functions from right to left.
  14152. *
  14153. * @static
  14154. * @since 3.0.0
  14155. * @memberOf _
  14156. * @category Util
  14157. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14158. * @returns {Function} Returns the new composite function.
  14159. * @see _.flow
  14160. * @example
  14161. *
  14162. * function square(n) {
  14163. * return n * n;
  14164. * }
  14165. *
  14166. * var addSquare = _.flowRight([square, _.add]);
  14167. * addSquare(1, 2);
  14168. * // => 9
  14169. */
  14170. var flowRight = createFlow(true);
  14171. /**
  14172. * This method returns the first argument it receives.
  14173. *
  14174. * @static
  14175. * @since 0.1.0
  14176. * @memberOf _
  14177. * @category Util
  14178. * @param {*} value Any value.
  14179. * @returns {*} Returns `value`.
  14180. * @example
  14181. *
  14182. * var object = { 'a': 1 };
  14183. *
  14184. * console.log(_.identity(object) === object);
  14185. * // => true
  14186. */
  14187. function identity(value) {
  14188. return value;
  14189. }
  14190. /**
  14191. * Creates a function that invokes `func` with the arguments of the created
  14192. * function. If `func` is a property name, the created function returns the
  14193. * property value for a given element. If `func` is an array or object, the
  14194. * created function returns `true` for elements that contain the equivalent
  14195. * source properties, otherwise it returns `false`.
  14196. *
  14197. * @static
  14198. * @since 4.0.0
  14199. * @memberOf _
  14200. * @category Util
  14201. * @param {*} [func=_.identity] The value to convert to a callback.
  14202. * @returns {Function} Returns the callback.
  14203. * @example
  14204. *
  14205. * var users = [
  14206. * { 'user': 'barney', 'age': 36, 'active': true },
  14207. * { 'user': 'fred', 'age': 40, 'active': false }
  14208. * ];
  14209. *
  14210. * // The `_.matches` iteratee shorthand.
  14211. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14212. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14213. *
  14214. * // The `_.matchesProperty` iteratee shorthand.
  14215. * _.filter(users, _.iteratee(['user', 'fred']));
  14216. * // => [{ 'user': 'fred', 'age': 40 }]
  14217. *
  14218. * // The `_.property` iteratee shorthand.
  14219. * _.map(users, _.iteratee('user'));
  14220. * // => ['barney', 'fred']
  14221. *
  14222. * // Create custom iteratee shorthands.
  14223. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14224. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14225. * return func.test(string);
  14226. * };
  14227. * });
  14228. *
  14229. * _.filter(['abc', 'def'], /ef/);
  14230. * // => ['def']
  14231. */
  14232. function iteratee(func) {
  14233. return baseIteratee(typeof func == 'function' ? func : baseClone(func, true));
  14234. }
  14235. /**
  14236. * Creates a function that performs a partial deep comparison between a given
  14237. * object and `source`, returning `true` if the given object has equivalent
  14238. * property values, else `false`.
  14239. *
  14240. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14241. * partially applied.
  14242. *
  14243. * Partial comparisons will match empty array and empty object `source`
  14244. * values against any array or object value, respectively. See `_.isEqual`
  14245. * for a list of supported value comparisons.
  14246. *
  14247. * @static
  14248. * @memberOf _
  14249. * @since 3.0.0
  14250. * @category Util
  14251. * @param {Object} source The object of property values to match.
  14252. * @returns {Function} Returns the new spec function.
  14253. * @example
  14254. *
  14255. * var objects = [
  14256. * { 'a': 1, 'b': 2, 'c': 3 },
  14257. * { 'a': 4, 'b': 5, 'c': 6 }
  14258. * ];
  14259. *
  14260. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14261. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14262. */
  14263. function matches(source) {
  14264. return baseMatches(baseClone(source, true));
  14265. }
  14266. /**
  14267. * Creates a function that performs a partial deep comparison between the
  14268. * value at `path` of a given object to `srcValue`, returning `true` if the
  14269. * object value is equivalent, else `false`.
  14270. *
  14271. * **Note:** Partial comparisons will match empty array and empty object
  14272. * `srcValue` values against any array or object value, respectively. See
  14273. * `_.isEqual` for a list of supported value comparisons.
  14274. *
  14275. * @static
  14276. * @memberOf _
  14277. * @since 3.2.0
  14278. * @category Util
  14279. * @param {Array|string} path The path of the property to get.
  14280. * @param {*} srcValue The value to match.
  14281. * @returns {Function} Returns the new spec function.
  14282. * @example
  14283. *
  14284. * var objects = [
  14285. * { 'a': 1, 'b': 2, 'c': 3 },
  14286. * { 'a': 4, 'b': 5, 'c': 6 }
  14287. * ];
  14288. *
  14289. * _.find(objects, _.matchesProperty('a', 4));
  14290. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14291. */
  14292. function matchesProperty(path, srcValue) {
  14293. return baseMatchesProperty(path, baseClone(srcValue, true));
  14294. }
  14295. /**
  14296. * Creates a function that invokes the method at `path` of a given object.
  14297. * Any additional arguments are provided to the invoked method.
  14298. *
  14299. * @static
  14300. * @memberOf _
  14301. * @since 3.7.0
  14302. * @category Util
  14303. * @param {Array|string} path The path of the method to invoke.
  14304. * @param {...*} [args] The arguments to invoke the method with.
  14305. * @returns {Function} Returns the new invoker function.
  14306. * @example
  14307. *
  14308. * var objects = [
  14309. * { 'a': { 'b': _.constant(2) } },
  14310. * { 'a': { 'b': _.constant(1) } }
  14311. * ];
  14312. *
  14313. * _.map(objects, _.method('a.b'));
  14314. * // => [2, 1]
  14315. *
  14316. * _.map(objects, _.method(['a', 'b']));
  14317. * // => [2, 1]
  14318. */
  14319. var method = baseRest(function(path, args) {
  14320. return function(object) {
  14321. return baseInvoke(object, path, args);
  14322. };
  14323. });
  14324. /**
  14325. * The opposite of `_.method`; this method creates a function that invokes
  14326. * the method at a given path of `object`. Any additional arguments are
  14327. * provided to the invoked method.
  14328. *
  14329. * @static
  14330. * @memberOf _
  14331. * @since 3.7.0
  14332. * @category Util
  14333. * @param {Object} object The object to query.
  14334. * @param {...*} [args] The arguments to invoke the method with.
  14335. * @returns {Function} Returns the new invoker function.
  14336. * @example
  14337. *
  14338. * var array = _.times(3, _.constant),
  14339. * object = { 'a': array, 'b': array, 'c': array };
  14340. *
  14341. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14342. * // => [2, 0]
  14343. *
  14344. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14345. * // => [2, 0]
  14346. */
  14347. var methodOf = baseRest(function(object, args) {
  14348. return function(path) {
  14349. return baseInvoke(object, path, args);
  14350. };
  14351. });
  14352. /**
  14353. * Adds all own enumerable string keyed function properties of a source
  14354. * object to the destination object. If `object` is a function, then methods
  14355. * are added to its prototype as well.
  14356. *
  14357. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14358. * avoid conflicts caused by modifying the original.
  14359. *
  14360. * @static
  14361. * @since 0.1.0
  14362. * @memberOf _
  14363. * @category Util
  14364. * @param {Function|Object} [object=lodash] The destination object.
  14365. * @param {Object} source The object of functions to add.
  14366. * @param {Object} [options={}] The options object.
  14367. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14368. * @returns {Function|Object} Returns `object`.
  14369. * @example
  14370. *
  14371. * function vowels(string) {
  14372. * return _.filter(string, function(v) {
  14373. * return /[aeiou]/i.test(v);
  14374. * });
  14375. * }
  14376. *
  14377. * _.mixin({ 'vowels': vowels });
  14378. * _.vowels('fred');
  14379. * // => ['e']
  14380. *
  14381. * _('fred').vowels().value();
  14382. * // => ['e']
  14383. *
  14384. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14385. * _('fred').vowels();
  14386. * // => ['e']
  14387. */
  14388. function mixin(object, source, options) {
  14389. var props = keys(source),
  14390. methodNames = baseFunctions(source, props);
  14391. if (options == null &&
  14392. !(isObject(source) && (methodNames.length || !props.length))) {
  14393. options = source;
  14394. source = object;
  14395. object = this;
  14396. methodNames = baseFunctions(source, keys(source));
  14397. }
  14398. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14399. isFunc = isFunction(object);
  14400. arrayEach(methodNames, function(methodName) {
  14401. var func = source[methodName];
  14402. object[methodName] = func;
  14403. if (isFunc) {
  14404. object.prototype[methodName] = function() {
  14405. var chainAll = this.__chain__;
  14406. if (chain || chainAll) {
  14407. var result = object(this.__wrapped__),
  14408. actions = result.__actions__ = copyArray(this.__actions__);
  14409. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14410. result.__chain__ = chainAll;
  14411. return result;
  14412. }
  14413. return func.apply(object, arrayPush([this.value()], arguments));
  14414. };
  14415. }
  14416. });
  14417. return object;
  14418. }
  14419. /**
  14420. * Reverts the `_` variable to its previous value and returns a reference to
  14421. * the `lodash` function.
  14422. *
  14423. * @static
  14424. * @since 0.1.0
  14425. * @memberOf _
  14426. * @category Util
  14427. * @returns {Function} Returns the `lodash` function.
  14428. * @example
  14429. *
  14430. * var lodash = _.noConflict();
  14431. */
  14432. function noConflict() {
  14433. if (root._ === this) {
  14434. root._ = oldDash;
  14435. }
  14436. return this;
  14437. }
  14438. /**
  14439. * This method returns `undefined`.
  14440. *
  14441. * @static
  14442. * @memberOf _
  14443. * @since 2.3.0
  14444. * @category Util
  14445. * @example
  14446. *
  14447. * _.times(2, _.noop);
  14448. * // => [undefined, undefined]
  14449. */
  14450. function noop() {
  14451. // No operation performed.
  14452. }
  14453. /**
  14454. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14455. * the nth argument from the end is returned.
  14456. *
  14457. * @static
  14458. * @memberOf _
  14459. * @since 4.0.0
  14460. * @category Util
  14461. * @param {number} [n=0] The index of the argument to return.
  14462. * @returns {Function} Returns the new pass-thru function.
  14463. * @example
  14464. *
  14465. * var func = _.nthArg(1);
  14466. * func('a', 'b', 'c', 'd');
  14467. * // => 'b'
  14468. *
  14469. * var func = _.nthArg(-2);
  14470. * func('a', 'b', 'c', 'd');
  14471. * // => 'c'
  14472. */
  14473. function nthArg(n) {
  14474. n = toInteger(n);
  14475. return baseRest(function(args) {
  14476. return baseNth(args, n);
  14477. });
  14478. }
  14479. /**
  14480. * Creates a function that invokes `iteratees` with the arguments it receives
  14481. * and returns their results.
  14482. *
  14483. * @static
  14484. * @memberOf _
  14485. * @since 4.0.0
  14486. * @category Util
  14487. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14488. * The iteratees to invoke.
  14489. * @returns {Function} Returns the new function.
  14490. * @example
  14491. *
  14492. * var func = _.over([Math.max, Math.min]);
  14493. *
  14494. * func(1, 2, 3, 4);
  14495. * // => [4, 1]
  14496. */
  14497. var over = createOver(arrayMap);
  14498. /**
  14499. * Creates a function that checks if **all** of the `predicates` return
  14500. * truthy when invoked with the arguments it receives.
  14501. *
  14502. * @static
  14503. * @memberOf _
  14504. * @since 4.0.0
  14505. * @category Util
  14506. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14507. * The predicates to check.
  14508. * @returns {Function} Returns the new function.
  14509. * @example
  14510. *
  14511. * var func = _.overEvery([Boolean, isFinite]);
  14512. *
  14513. * func('1');
  14514. * // => true
  14515. *
  14516. * func(null);
  14517. * // => false
  14518. *
  14519. * func(NaN);
  14520. * // => false
  14521. */
  14522. var overEvery = createOver(arrayEvery);
  14523. /**
  14524. * Creates a function that checks if **any** of the `predicates` return
  14525. * truthy when invoked with the arguments it receives.
  14526. *
  14527. * @static
  14528. * @memberOf _
  14529. * @since 4.0.0
  14530. * @category Util
  14531. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14532. * The predicates to check.
  14533. * @returns {Function} Returns the new function.
  14534. * @example
  14535. *
  14536. * var func = _.overSome([Boolean, isFinite]);
  14537. *
  14538. * func('1');
  14539. * // => true
  14540. *
  14541. * func(null);
  14542. * // => true
  14543. *
  14544. * func(NaN);
  14545. * // => false
  14546. */
  14547. var overSome = createOver(arraySome);
  14548. /**
  14549. * Creates a function that returns the value at `path` of a given object.
  14550. *
  14551. * @static
  14552. * @memberOf _
  14553. * @since 2.4.0
  14554. * @category Util
  14555. * @param {Array|string} path The path of the property to get.
  14556. * @returns {Function} Returns the new accessor function.
  14557. * @example
  14558. *
  14559. * var objects = [
  14560. * { 'a': { 'b': 2 } },
  14561. * { 'a': { 'b': 1 } }
  14562. * ];
  14563. *
  14564. * _.map(objects, _.property('a.b'));
  14565. * // => [2, 1]
  14566. *
  14567. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14568. * // => [1, 2]
  14569. */
  14570. function property(path) {
  14571. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  14572. }
  14573. /**
  14574. * The opposite of `_.property`; this method creates a function that returns
  14575. * the value at a given path of `object`.
  14576. *
  14577. * @static
  14578. * @memberOf _
  14579. * @since 3.0.0
  14580. * @category Util
  14581. * @param {Object} object The object to query.
  14582. * @returns {Function} Returns the new accessor function.
  14583. * @example
  14584. *
  14585. * var array = [0, 1, 2],
  14586. * object = { 'a': array, 'b': array, 'c': array };
  14587. *
  14588. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  14589. * // => [2, 0]
  14590. *
  14591. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  14592. * // => [2, 0]
  14593. */
  14594. function propertyOf(object) {
  14595. return function(path) {
  14596. return object == null ? undefined : baseGet(object, path);
  14597. };
  14598. }
  14599. /**
  14600. * Creates an array of numbers (positive and/or negative) progressing from
  14601. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  14602. * `start` is specified without an `end` or `step`. If `end` is not specified,
  14603. * it's set to `start` with `start` then set to `0`.
  14604. *
  14605. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  14606. * floating-point values which can produce unexpected results.
  14607. *
  14608. * @static
  14609. * @since 0.1.0
  14610. * @memberOf _
  14611. * @category Util
  14612. * @param {number} [start=0] The start of the range.
  14613. * @param {number} end The end of the range.
  14614. * @param {number} [step=1] The value to increment or decrement by.
  14615. * @returns {Array} Returns the range of numbers.
  14616. * @see _.inRange, _.rangeRight
  14617. * @example
  14618. *
  14619. * _.range(4);
  14620. * // => [0, 1, 2, 3]
  14621. *
  14622. * _.range(-4);
  14623. * // => [0, -1, -2, -3]
  14624. *
  14625. * _.range(1, 5);
  14626. * // => [1, 2, 3, 4]
  14627. *
  14628. * _.range(0, 20, 5);
  14629. * // => [0, 5, 10, 15]
  14630. *
  14631. * _.range(0, -4, -1);
  14632. * // => [0, -1, -2, -3]
  14633. *
  14634. * _.range(1, 4, 0);
  14635. * // => [1, 1, 1]
  14636. *
  14637. * _.range(0);
  14638. * // => []
  14639. */
  14640. var range = createRange();
  14641. /**
  14642. * This method is like `_.range` except that it populates values in
  14643. * descending order.
  14644. *
  14645. * @static
  14646. * @memberOf _
  14647. * @since 4.0.0
  14648. * @category Util
  14649. * @param {number} [start=0] The start of the range.
  14650. * @param {number} end The end of the range.
  14651. * @param {number} [step=1] The value to increment or decrement by.
  14652. * @returns {Array} Returns the range of numbers.
  14653. * @see _.inRange, _.range
  14654. * @example
  14655. *
  14656. * _.rangeRight(4);
  14657. * // => [3, 2, 1, 0]
  14658. *
  14659. * _.rangeRight(-4);
  14660. * // => [-3, -2, -1, 0]
  14661. *
  14662. * _.rangeRight(1, 5);
  14663. * // => [4, 3, 2, 1]
  14664. *
  14665. * _.rangeRight(0, 20, 5);
  14666. * // => [15, 10, 5, 0]
  14667. *
  14668. * _.rangeRight(0, -4, -1);
  14669. * // => [-3, -2, -1, 0]
  14670. *
  14671. * _.rangeRight(1, 4, 0);
  14672. * // => [1, 1, 1]
  14673. *
  14674. * _.rangeRight(0);
  14675. * // => []
  14676. */
  14677. var rangeRight = createRange(true);
  14678. /**
  14679. * This method returns a new empty array.
  14680. *
  14681. * @static
  14682. * @memberOf _
  14683. * @since 4.13.0
  14684. * @category Util
  14685. * @returns {Array} Returns the new empty array.
  14686. * @example
  14687. *
  14688. * var arrays = _.times(2, _.stubArray);
  14689. *
  14690. * console.log(arrays);
  14691. * // => [[], []]
  14692. *
  14693. * console.log(arrays[0] === arrays[1]);
  14694. * // => false
  14695. */
  14696. function stubArray() {
  14697. return [];
  14698. }
  14699. /**
  14700. * This method returns `false`.
  14701. *
  14702. * @static
  14703. * @memberOf _
  14704. * @since 4.13.0
  14705. * @category Util
  14706. * @returns {boolean} Returns `false`.
  14707. * @example
  14708. *
  14709. * _.times(2, _.stubFalse);
  14710. * // => [false, false]
  14711. */
  14712. function stubFalse() {
  14713. return false;
  14714. }
  14715. /**
  14716. * This method returns a new empty object.
  14717. *
  14718. * @static
  14719. * @memberOf _
  14720. * @since 4.13.0
  14721. * @category Util
  14722. * @returns {Object} Returns the new empty object.
  14723. * @example
  14724. *
  14725. * var objects = _.times(2, _.stubObject);
  14726. *
  14727. * console.log(objects);
  14728. * // => [{}, {}]
  14729. *
  14730. * console.log(objects[0] === objects[1]);
  14731. * // => false
  14732. */
  14733. function stubObject() {
  14734. return {};
  14735. }
  14736. /**
  14737. * This method returns an empty string.
  14738. *
  14739. * @static
  14740. * @memberOf _
  14741. * @since 4.13.0
  14742. * @category Util
  14743. * @returns {string} Returns the empty string.
  14744. * @example
  14745. *
  14746. * _.times(2, _.stubString);
  14747. * // => ['', '']
  14748. */
  14749. function stubString() {
  14750. return '';
  14751. }
  14752. /**
  14753. * This method returns `true`.
  14754. *
  14755. * @static
  14756. * @memberOf _
  14757. * @since 4.13.0
  14758. * @category Util
  14759. * @returns {boolean} Returns `true`.
  14760. * @example
  14761. *
  14762. * _.times(2, _.stubTrue);
  14763. * // => [true, true]
  14764. */
  14765. function stubTrue() {
  14766. return true;
  14767. }
  14768. /**
  14769. * Invokes the iteratee `n` times, returning an array of the results of
  14770. * each invocation. The iteratee is invoked with one argument; (index).
  14771. *
  14772. * @static
  14773. * @since 0.1.0
  14774. * @memberOf _
  14775. * @category Util
  14776. * @param {number} n The number of times to invoke `iteratee`.
  14777. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  14778. * @returns {Array} Returns the array of results.
  14779. * @example
  14780. *
  14781. * _.times(3, String);
  14782. * // => ['0', '1', '2']
  14783. *
  14784. * _.times(4, _.constant(0));
  14785. * // => [0, 0, 0, 0]
  14786. */
  14787. function times(n, iteratee) {
  14788. n = toInteger(n);
  14789. if (n < 1 || n > MAX_SAFE_INTEGER) {
  14790. return [];
  14791. }
  14792. var index = MAX_ARRAY_LENGTH,
  14793. length = nativeMin(n, MAX_ARRAY_LENGTH);
  14794. iteratee = getIteratee(iteratee);
  14795. n -= MAX_ARRAY_LENGTH;
  14796. var result = baseTimes(length, iteratee);
  14797. while (++index < n) {
  14798. iteratee(index);
  14799. }
  14800. return result;
  14801. }
  14802. /**
  14803. * Converts `value` to a property path array.
  14804. *
  14805. * @static
  14806. * @memberOf _
  14807. * @since 4.0.0
  14808. * @category Util
  14809. * @param {*} value The value to convert.
  14810. * @returns {Array} Returns the new property path array.
  14811. * @example
  14812. *
  14813. * _.toPath('a.b.c');
  14814. * // => ['a', 'b', 'c']
  14815. *
  14816. * _.toPath('a[0].b.c');
  14817. * // => ['a', '0', 'b', 'c']
  14818. */
  14819. function toPath(value) {
  14820. if (isArray(value)) {
  14821. return arrayMap(value, toKey);
  14822. }
  14823. return isSymbol(value) ? [value] : copyArray(stringToPath(value));
  14824. }
  14825. /**
  14826. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  14827. *
  14828. * @static
  14829. * @since 0.1.0
  14830. * @memberOf _
  14831. * @category Util
  14832. * @param {string} [prefix=''] The value to prefix the ID with.
  14833. * @returns {string} Returns the unique ID.
  14834. * @example
  14835. *
  14836. * _.uniqueId('contact_');
  14837. * // => 'contact_104'
  14838. *
  14839. * _.uniqueId();
  14840. * // => '105'
  14841. */
  14842. function uniqueId(prefix) {
  14843. var id = ++idCounter;
  14844. return toString(prefix) + id;
  14845. }
  14846. /*------------------------------------------------------------------------*/
  14847. /**
  14848. * Adds two numbers.
  14849. *
  14850. * @static
  14851. * @memberOf _
  14852. * @since 3.4.0
  14853. * @category Math
  14854. * @param {number} augend The first number in an addition.
  14855. * @param {number} addend The second number in an addition.
  14856. * @returns {number} Returns the total.
  14857. * @example
  14858. *
  14859. * _.add(6, 4);
  14860. * // => 10
  14861. */
  14862. var add = createMathOperation(function(augend, addend) {
  14863. return augend + addend;
  14864. }, 0);
  14865. /**
  14866. * Computes `number` rounded up to `precision`.
  14867. *
  14868. * @static
  14869. * @memberOf _
  14870. * @since 3.10.0
  14871. * @category Math
  14872. * @param {number} number The number to round up.
  14873. * @param {number} [precision=0] The precision to round up to.
  14874. * @returns {number} Returns the rounded up number.
  14875. * @example
  14876. *
  14877. * _.ceil(4.006);
  14878. * // => 5
  14879. *
  14880. * _.ceil(6.004, 2);
  14881. * // => 6.01
  14882. *
  14883. * _.ceil(6040, -2);
  14884. * // => 6100
  14885. */
  14886. var ceil = createRound('ceil');
  14887. /**
  14888. * Divide two numbers.
  14889. *
  14890. * @static
  14891. * @memberOf _
  14892. * @since 4.7.0
  14893. * @category Math
  14894. * @param {number} dividend The first number in a division.
  14895. * @param {number} divisor The second number in a division.
  14896. * @returns {number} Returns the quotient.
  14897. * @example
  14898. *
  14899. * _.divide(6, 4);
  14900. * // => 1.5
  14901. */
  14902. var divide = createMathOperation(function(dividend, divisor) {
  14903. return dividend / divisor;
  14904. }, 1);
  14905. /**
  14906. * Computes `number` rounded down to `precision`.
  14907. *
  14908. * @static
  14909. * @memberOf _
  14910. * @since 3.10.0
  14911. * @category Math
  14912. * @param {number} number The number to round down.
  14913. * @param {number} [precision=0] The precision to round down to.
  14914. * @returns {number} Returns the rounded down number.
  14915. * @example
  14916. *
  14917. * _.floor(4.006);
  14918. * // => 4
  14919. *
  14920. * _.floor(0.046, 2);
  14921. * // => 0.04
  14922. *
  14923. * _.floor(4060, -2);
  14924. * // => 4000
  14925. */
  14926. var floor = createRound('floor');
  14927. /**
  14928. * Computes the maximum value of `array`. If `array` is empty or falsey,
  14929. * `undefined` is returned.
  14930. *
  14931. * @static
  14932. * @since 0.1.0
  14933. * @memberOf _
  14934. * @category Math
  14935. * @param {Array} array The array to iterate over.
  14936. * @returns {*} Returns the maximum value.
  14937. * @example
  14938. *
  14939. * _.max([4, 2, 8, 6]);
  14940. * // => 8
  14941. *
  14942. * _.max([]);
  14943. * // => undefined
  14944. */
  14945. function max(array) {
  14946. return (array && array.length)
  14947. ? baseExtremum(array, identity, baseGt)
  14948. : undefined;
  14949. }
  14950. /**
  14951. * This method is like `_.max` except that it accepts `iteratee` which is
  14952. * invoked for each element in `array` to generate the criterion by which
  14953. * the value is ranked. The iteratee is invoked with one argument: (value).
  14954. *
  14955. * @static
  14956. * @memberOf _
  14957. * @since 4.0.0
  14958. * @category Math
  14959. * @param {Array} array The array to iterate over.
  14960. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  14961. * @returns {*} Returns the maximum value.
  14962. * @example
  14963. *
  14964. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  14965. *
  14966. * _.maxBy(objects, function(o) { return o.n; });
  14967. * // => { 'n': 2 }
  14968. *
  14969. * // The `_.property` iteratee shorthand.
  14970. * _.maxBy(objects, 'n');
  14971. * // => { 'n': 2 }
  14972. */
  14973. function maxBy(array, iteratee) {
  14974. return (array && array.length)
  14975. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  14976. : undefined;
  14977. }
  14978. /**
  14979. * Computes the mean of the values in `array`.
  14980. *
  14981. * @static
  14982. * @memberOf _
  14983. * @since 4.0.0
  14984. * @category Math
  14985. * @param {Array} array The array to iterate over.
  14986. * @returns {number} Returns the mean.
  14987. * @example
  14988. *
  14989. * _.mean([4, 2, 8, 6]);
  14990. * // => 5
  14991. */
  14992. function mean(array) {
  14993. return baseMean(array, identity);
  14994. }
  14995. /**
  14996. * This method is like `_.mean` except that it accepts `iteratee` which is
  14997. * invoked for each element in `array` to generate the value to be averaged.
  14998. * The iteratee is invoked with one argument: (value).
  14999. *
  15000. * @static
  15001. * @memberOf _
  15002. * @since 4.7.0
  15003. * @category Math
  15004. * @param {Array} array The array to iterate over.
  15005. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15006. * @returns {number} Returns the mean.
  15007. * @example
  15008. *
  15009. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15010. *
  15011. * _.meanBy(objects, function(o) { return o.n; });
  15012. * // => 5
  15013. *
  15014. * // The `_.property` iteratee shorthand.
  15015. * _.meanBy(objects, 'n');
  15016. * // => 5
  15017. */
  15018. function meanBy(array, iteratee) {
  15019. return baseMean(array, getIteratee(iteratee, 2));
  15020. }
  15021. /**
  15022. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15023. * `undefined` is returned.
  15024. *
  15025. * @static
  15026. * @since 0.1.0
  15027. * @memberOf _
  15028. * @category Math
  15029. * @param {Array} array The array to iterate over.
  15030. * @returns {*} Returns the minimum value.
  15031. * @example
  15032. *
  15033. * _.min([4, 2, 8, 6]);
  15034. * // => 2
  15035. *
  15036. * _.min([]);
  15037. * // => undefined
  15038. */
  15039. function min(array) {
  15040. return (array && array.length)
  15041. ? baseExtremum(array, identity, baseLt)
  15042. : undefined;
  15043. }
  15044. /**
  15045. * This method is like `_.min` except that it accepts `iteratee` which is
  15046. * invoked for each element in `array` to generate the criterion by which
  15047. * the value is ranked. The iteratee is invoked with one argument: (value).
  15048. *
  15049. * @static
  15050. * @memberOf _
  15051. * @since 4.0.0
  15052. * @category Math
  15053. * @param {Array} array The array to iterate over.
  15054. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15055. * @returns {*} Returns the minimum value.
  15056. * @example
  15057. *
  15058. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15059. *
  15060. * _.minBy(objects, function(o) { return o.n; });
  15061. * // => { 'n': 1 }
  15062. *
  15063. * // The `_.property` iteratee shorthand.
  15064. * _.minBy(objects, 'n');
  15065. * // => { 'n': 1 }
  15066. */
  15067. function minBy(array, iteratee) {
  15068. return (array && array.length)
  15069. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15070. : undefined;
  15071. }
  15072. /**
  15073. * Multiply two numbers.
  15074. *
  15075. * @static
  15076. * @memberOf _
  15077. * @since 4.7.0
  15078. * @category Math
  15079. * @param {number} multiplier The first number in a multiplication.
  15080. * @param {number} multiplicand The second number in a multiplication.
  15081. * @returns {number} Returns the product.
  15082. * @example
  15083. *
  15084. * _.multiply(6, 4);
  15085. * // => 24
  15086. */
  15087. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15088. return multiplier * multiplicand;
  15089. }, 1);
  15090. /**
  15091. * Computes `number` rounded to `precision`.
  15092. *
  15093. * @static
  15094. * @memberOf _
  15095. * @since 3.10.0
  15096. * @category Math
  15097. * @param {number} number The number to round.
  15098. * @param {number} [precision=0] The precision to round to.
  15099. * @returns {number} Returns the rounded number.
  15100. * @example
  15101. *
  15102. * _.round(4.006);
  15103. * // => 4
  15104. *
  15105. * _.round(4.006, 2);
  15106. * // => 4.01
  15107. *
  15108. * _.round(4060, -2);
  15109. * // => 4100
  15110. */
  15111. var round = createRound('round');
  15112. /**
  15113. * Subtract two numbers.
  15114. *
  15115. * @static
  15116. * @memberOf _
  15117. * @since 4.0.0
  15118. * @category Math
  15119. * @param {number} minuend The first number in a subtraction.
  15120. * @param {number} subtrahend The second number in a subtraction.
  15121. * @returns {number} Returns the difference.
  15122. * @example
  15123. *
  15124. * _.subtract(6, 4);
  15125. * // => 2
  15126. */
  15127. var subtract = createMathOperation(function(minuend, subtrahend) {
  15128. return minuend - subtrahend;
  15129. }, 0);
  15130. /**
  15131. * Computes the sum of the values in `array`.
  15132. *
  15133. * @static
  15134. * @memberOf _
  15135. * @since 3.4.0
  15136. * @category Math
  15137. * @param {Array} array The array to iterate over.
  15138. * @returns {number} Returns the sum.
  15139. * @example
  15140. *
  15141. * _.sum([4, 2, 8, 6]);
  15142. * // => 20
  15143. */
  15144. function sum(array) {
  15145. return (array && array.length)
  15146. ? baseSum(array, identity)
  15147. : 0;
  15148. }
  15149. /**
  15150. * This method is like `_.sum` except that it accepts `iteratee` which is
  15151. * invoked for each element in `array` to generate the value to be summed.
  15152. * The iteratee is invoked with one argument: (value).
  15153. *
  15154. * @static
  15155. * @memberOf _
  15156. * @since 4.0.0
  15157. * @category Math
  15158. * @param {Array} array The array to iterate over.
  15159. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15160. * @returns {number} Returns the sum.
  15161. * @example
  15162. *
  15163. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15164. *
  15165. * _.sumBy(objects, function(o) { return o.n; });
  15166. * // => 20
  15167. *
  15168. * // The `_.property` iteratee shorthand.
  15169. * _.sumBy(objects, 'n');
  15170. * // => 20
  15171. */
  15172. function sumBy(array, iteratee) {
  15173. return (array && array.length)
  15174. ? baseSum(array, getIteratee(iteratee, 2))
  15175. : 0;
  15176. }
  15177. /*------------------------------------------------------------------------*/
  15178. // Add methods that return wrapped values in chain sequences.
  15179. lodash.after = after;
  15180. lodash.ary = ary;
  15181. lodash.assign = assign;
  15182. lodash.assignIn = assignIn;
  15183. lodash.assignInWith = assignInWith;
  15184. lodash.assignWith = assignWith;
  15185. lodash.at = at;
  15186. lodash.before = before;
  15187. lodash.bind = bind;
  15188. lodash.bindAll = bindAll;
  15189. lodash.bindKey = bindKey;
  15190. lodash.castArray = castArray;
  15191. lodash.chain = chain;
  15192. lodash.chunk = chunk;
  15193. lodash.compact = compact;
  15194. lodash.concat = concat;
  15195. lodash.cond = cond;
  15196. lodash.conforms = conforms;
  15197. lodash.constant = constant;
  15198. lodash.countBy = countBy;
  15199. lodash.create = create;
  15200. lodash.curry = curry;
  15201. lodash.curryRight = curryRight;
  15202. lodash.debounce = debounce;
  15203. lodash.defaults = defaults;
  15204. lodash.defaultsDeep = defaultsDeep;
  15205. lodash.defer = defer;
  15206. lodash.delay = delay;
  15207. lodash.difference = difference;
  15208. lodash.differenceBy = differenceBy;
  15209. lodash.differenceWith = differenceWith;
  15210. lodash.drop = drop;
  15211. lodash.dropRight = dropRight;
  15212. lodash.dropRightWhile = dropRightWhile;
  15213. lodash.dropWhile = dropWhile;
  15214. lodash.fill = fill;
  15215. lodash.filter = filter;
  15216. lodash.flatMap = flatMap;
  15217. lodash.flatMapDeep = flatMapDeep;
  15218. lodash.flatMapDepth = flatMapDepth;
  15219. lodash.flatten = flatten;
  15220. lodash.flattenDeep = flattenDeep;
  15221. lodash.flattenDepth = flattenDepth;
  15222. lodash.flip = flip;
  15223. lodash.flow = flow;
  15224. lodash.flowRight = flowRight;
  15225. lodash.fromPairs = fromPairs;
  15226. lodash.functions = functions;
  15227. lodash.functionsIn = functionsIn;
  15228. lodash.groupBy = groupBy;
  15229. lodash.initial = initial;
  15230. lodash.intersection = intersection;
  15231. lodash.intersectionBy = intersectionBy;
  15232. lodash.intersectionWith = intersectionWith;
  15233. lodash.invert = invert;
  15234. lodash.invertBy = invertBy;
  15235. lodash.invokeMap = invokeMap;
  15236. lodash.iteratee = iteratee;
  15237. lodash.keyBy = keyBy;
  15238. lodash.keys = keys;
  15239. lodash.keysIn = keysIn;
  15240. lodash.map = map;
  15241. lodash.mapKeys = mapKeys;
  15242. lodash.mapValues = mapValues;
  15243. lodash.matches = matches;
  15244. lodash.matchesProperty = matchesProperty;
  15245. lodash.memoize = memoize;
  15246. lodash.merge = merge;
  15247. lodash.mergeWith = mergeWith;
  15248. lodash.method = method;
  15249. lodash.methodOf = methodOf;
  15250. lodash.mixin = mixin;
  15251. lodash.negate = negate;
  15252. lodash.nthArg = nthArg;
  15253. lodash.omit = omit;
  15254. lodash.omitBy = omitBy;
  15255. lodash.once = once;
  15256. lodash.orderBy = orderBy;
  15257. lodash.over = over;
  15258. lodash.overArgs = overArgs;
  15259. lodash.overEvery = overEvery;
  15260. lodash.overSome = overSome;
  15261. lodash.partial = partial;
  15262. lodash.partialRight = partialRight;
  15263. lodash.partition = partition;
  15264. lodash.pick = pick;
  15265. lodash.pickBy = pickBy;
  15266. lodash.property = property;
  15267. lodash.propertyOf = propertyOf;
  15268. lodash.pull = pull;
  15269. lodash.pullAll = pullAll;
  15270. lodash.pullAllBy = pullAllBy;
  15271. lodash.pullAllWith = pullAllWith;
  15272. lodash.pullAt = pullAt;
  15273. lodash.range = range;
  15274. lodash.rangeRight = rangeRight;
  15275. lodash.rearg = rearg;
  15276. lodash.reject = reject;
  15277. lodash.remove = remove;
  15278. lodash.rest = rest;
  15279. lodash.reverse = reverse;
  15280. lodash.sampleSize = sampleSize;
  15281. lodash.set = set;
  15282. lodash.setWith = setWith;
  15283. lodash.shuffle = shuffle;
  15284. lodash.slice = slice;
  15285. lodash.sortBy = sortBy;
  15286. lodash.sortedUniq = sortedUniq;
  15287. lodash.sortedUniqBy = sortedUniqBy;
  15288. lodash.split = split;
  15289. lodash.spread = spread;
  15290. lodash.tail = tail;
  15291. lodash.take = take;
  15292. lodash.takeRight = takeRight;
  15293. lodash.takeRightWhile = takeRightWhile;
  15294. lodash.takeWhile = takeWhile;
  15295. lodash.tap = tap;
  15296. lodash.throttle = throttle;
  15297. lodash.thru = thru;
  15298. lodash.toArray = toArray;
  15299. lodash.toPairs = toPairs;
  15300. lodash.toPairsIn = toPairsIn;
  15301. lodash.toPath = toPath;
  15302. lodash.toPlainObject = toPlainObject;
  15303. lodash.transform = transform;
  15304. lodash.unary = unary;
  15305. lodash.union = union;
  15306. lodash.unionBy = unionBy;
  15307. lodash.unionWith = unionWith;
  15308. lodash.uniq = uniq;
  15309. lodash.uniqBy = uniqBy;
  15310. lodash.uniqWith = uniqWith;
  15311. lodash.unset = unset;
  15312. lodash.unzip = unzip;
  15313. lodash.unzipWith = unzipWith;
  15314. lodash.update = update;
  15315. lodash.updateWith = updateWith;
  15316. lodash.values = values;
  15317. lodash.valuesIn = valuesIn;
  15318. lodash.without = without;
  15319. lodash.words = words;
  15320. lodash.wrap = wrap;
  15321. lodash.xor = xor;
  15322. lodash.xorBy = xorBy;
  15323. lodash.xorWith = xorWith;
  15324. lodash.zip = zip;
  15325. lodash.zipObject = zipObject;
  15326. lodash.zipObjectDeep = zipObjectDeep;
  15327. lodash.zipWith = zipWith;
  15328. // Add aliases.
  15329. lodash.entries = toPairs;
  15330. lodash.entriesIn = toPairsIn;
  15331. lodash.extend = assignIn;
  15332. lodash.extendWith = assignInWith;
  15333. // Add methods to `lodash.prototype`.
  15334. mixin(lodash, lodash);
  15335. /*------------------------------------------------------------------------*/
  15336. // Add methods that return unwrapped values in chain sequences.
  15337. lodash.add = add;
  15338. lodash.attempt = attempt;
  15339. lodash.camelCase = camelCase;
  15340. lodash.capitalize = capitalize;
  15341. lodash.ceil = ceil;
  15342. lodash.clamp = clamp;
  15343. lodash.clone = clone;
  15344. lodash.cloneDeep = cloneDeep;
  15345. lodash.cloneDeepWith = cloneDeepWith;
  15346. lodash.cloneWith = cloneWith;
  15347. lodash.conformsTo = conformsTo;
  15348. lodash.deburr = deburr;
  15349. lodash.defaultTo = defaultTo;
  15350. lodash.divide = divide;
  15351. lodash.endsWith = endsWith;
  15352. lodash.eq = eq;
  15353. lodash.escape = escape;
  15354. lodash.escapeRegExp = escapeRegExp;
  15355. lodash.every = every;
  15356. lodash.find = find;
  15357. lodash.findIndex = findIndex;
  15358. lodash.findKey = findKey;
  15359. lodash.findLast = findLast;
  15360. lodash.findLastIndex = findLastIndex;
  15361. lodash.findLastKey = findLastKey;
  15362. lodash.floor = floor;
  15363. lodash.forEach = forEach;
  15364. lodash.forEachRight = forEachRight;
  15365. lodash.forIn = forIn;
  15366. lodash.forInRight = forInRight;
  15367. lodash.forOwn = forOwn;
  15368. lodash.forOwnRight = forOwnRight;
  15369. lodash.get = get;
  15370. lodash.gt = gt;
  15371. lodash.gte = gte;
  15372. lodash.has = has;
  15373. lodash.hasIn = hasIn;
  15374. lodash.head = head;
  15375. lodash.identity = identity;
  15376. lodash.includes = includes;
  15377. lodash.indexOf = indexOf;
  15378. lodash.inRange = inRange;
  15379. lodash.invoke = invoke;
  15380. lodash.isArguments = isArguments;
  15381. lodash.isArray = isArray;
  15382. lodash.isArrayBuffer = isArrayBuffer;
  15383. lodash.isArrayLike = isArrayLike;
  15384. lodash.isArrayLikeObject = isArrayLikeObject;
  15385. lodash.isBoolean = isBoolean;
  15386. lodash.isBuffer = isBuffer;
  15387. lodash.isDate = isDate;
  15388. lodash.isElement = isElement;
  15389. lodash.isEmpty = isEmpty;
  15390. lodash.isEqual = isEqual;
  15391. lodash.isEqualWith = isEqualWith;
  15392. lodash.isError = isError;
  15393. lodash.isFinite = isFinite;
  15394. lodash.isFunction = isFunction;
  15395. lodash.isInteger = isInteger;
  15396. lodash.isLength = isLength;
  15397. lodash.isMap = isMap;
  15398. lodash.isMatch = isMatch;
  15399. lodash.isMatchWith = isMatchWith;
  15400. lodash.isNaN = isNaN;
  15401. lodash.isNative = isNative;
  15402. lodash.isNil = isNil;
  15403. lodash.isNull = isNull;
  15404. lodash.isNumber = isNumber;
  15405. lodash.isObject = isObject;
  15406. lodash.isObjectLike = isObjectLike;
  15407. lodash.isPlainObject = isPlainObject;
  15408. lodash.isRegExp = isRegExp;
  15409. lodash.isSafeInteger = isSafeInteger;
  15410. lodash.isSet = isSet;
  15411. lodash.isString = isString;
  15412. lodash.isSymbol = isSymbol;
  15413. lodash.isTypedArray = isTypedArray;
  15414. lodash.isUndefined = isUndefined;
  15415. lodash.isWeakMap = isWeakMap;
  15416. lodash.isWeakSet = isWeakSet;
  15417. lodash.join = join;
  15418. lodash.kebabCase = kebabCase;
  15419. lodash.last = last;
  15420. lodash.lastIndexOf = lastIndexOf;
  15421. lodash.lowerCase = lowerCase;
  15422. lodash.lowerFirst = lowerFirst;
  15423. lodash.lt = lt;
  15424. lodash.lte = lte;
  15425. lodash.max = max;
  15426. lodash.maxBy = maxBy;
  15427. lodash.mean = mean;
  15428. lodash.meanBy = meanBy;
  15429. lodash.min = min;
  15430. lodash.minBy = minBy;
  15431. lodash.stubArray = stubArray;
  15432. lodash.stubFalse = stubFalse;
  15433. lodash.stubObject = stubObject;
  15434. lodash.stubString = stubString;
  15435. lodash.stubTrue = stubTrue;
  15436. lodash.multiply = multiply;
  15437. lodash.nth = nth;
  15438. lodash.noConflict = noConflict;
  15439. lodash.noop = noop;
  15440. lodash.now = now;
  15441. lodash.pad = pad;
  15442. lodash.padEnd = padEnd;
  15443. lodash.padStart = padStart;
  15444. lodash.parseInt = parseInt;
  15445. lodash.random = random;
  15446. lodash.reduce = reduce;
  15447. lodash.reduceRight = reduceRight;
  15448. lodash.repeat = repeat;
  15449. lodash.replace = replace;
  15450. lodash.result = result;
  15451. lodash.round = round;
  15452. lodash.runInContext = runInContext;
  15453. lodash.sample = sample;
  15454. lodash.size = size;
  15455. lodash.snakeCase = snakeCase;
  15456. lodash.some = some;
  15457. lodash.sortedIndex = sortedIndex;
  15458. lodash.sortedIndexBy = sortedIndexBy;
  15459. lodash.sortedIndexOf = sortedIndexOf;
  15460. lodash.sortedLastIndex = sortedLastIndex;
  15461. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15462. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15463. lodash.startCase = startCase;
  15464. lodash.startsWith = startsWith;
  15465. lodash.subtract = subtract;
  15466. lodash.sum = sum;
  15467. lodash.sumBy = sumBy;
  15468. lodash.template = template;
  15469. lodash.times = times;
  15470. lodash.toFinite = toFinite;
  15471. lodash.toInteger = toInteger;
  15472. lodash.toLength = toLength;
  15473. lodash.toLower = toLower;
  15474. lodash.toNumber = toNumber;
  15475. lodash.toSafeInteger = toSafeInteger;
  15476. lodash.toString = toString;
  15477. lodash.toUpper = toUpper;
  15478. lodash.trim = trim;
  15479. lodash.trimEnd = trimEnd;
  15480. lodash.trimStart = trimStart;
  15481. lodash.truncate = truncate;
  15482. lodash.unescape = unescape;
  15483. lodash.uniqueId = uniqueId;
  15484. lodash.upperCase = upperCase;
  15485. lodash.upperFirst = upperFirst;
  15486. // Add aliases.
  15487. lodash.each = forEach;
  15488. lodash.eachRight = forEachRight;
  15489. lodash.first = head;
  15490. mixin(lodash, (function() {
  15491. var source = {};
  15492. baseForOwn(lodash, function(func, methodName) {
  15493. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15494. source[methodName] = func;
  15495. }
  15496. });
  15497. return source;
  15498. }()), { 'chain': false });
  15499. /*------------------------------------------------------------------------*/
  15500. /**
  15501. * The semantic version number.
  15502. *
  15503. * @static
  15504. * @memberOf _
  15505. * @type {string}
  15506. */
  15507. lodash.VERSION = VERSION;
  15508. // Assign default placeholders.
  15509. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15510. lodash[methodName].placeholder = lodash;
  15511. });
  15512. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15513. arrayEach(['drop', 'take'], function(methodName, index) {
  15514. LazyWrapper.prototype[methodName] = function(n) {
  15515. var filtered = this.__filtered__;
  15516. if (filtered && !index) {
  15517. return new LazyWrapper(this);
  15518. }
  15519. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15520. var result = this.clone();
  15521. if (filtered) {
  15522. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15523. } else {
  15524. result.__views__.push({
  15525. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15526. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15527. });
  15528. }
  15529. return result;
  15530. };
  15531. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15532. return this.reverse()[methodName](n).reverse();
  15533. };
  15534. });
  15535. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15536. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15537. var type = index + 1,
  15538. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15539. LazyWrapper.prototype[methodName] = function(iteratee) {
  15540. var result = this.clone();
  15541. result.__iteratees__.push({
  15542. 'iteratee': getIteratee(iteratee, 3),
  15543. 'type': type
  15544. });
  15545. result.__filtered__ = result.__filtered__ || isFilter;
  15546. return result;
  15547. };
  15548. });
  15549. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15550. arrayEach(['head', 'last'], function(methodName, index) {
  15551. var takeName = 'take' + (index ? 'Right' : '');
  15552. LazyWrapper.prototype[methodName] = function() {
  15553. return this[takeName](1).value()[0];
  15554. };
  15555. });
  15556. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15557. arrayEach(['initial', 'tail'], function(methodName, index) {
  15558. var dropName = 'drop' + (index ? '' : 'Right');
  15559. LazyWrapper.prototype[methodName] = function() {
  15560. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15561. };
  15562. });
  15563. LazyWrapper.prototype.compact = function() {
  15564. return this.filter(identity);
  15565. };
  15566. LazyWrapper.prototype.find = function(predicate) {
  15567. return this.filter(predicate).head();
  15568. };
  15569. LazyWrapper.prototype.findLast = function(predicate) {
  15570. return this.reverse().find(predicate);
  15571. };
  15572. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  15573. if (typeof path == 'function') {
  15574. return new LazyWrapper(this);
  15575. }
  15576. return this.map(function(value) {
  15577. return baseInvoke(value, path, args);
  15578. });
  15579. });
  15580. LazyWrapper.prototype.reject = function(predicate) {
  15581. return this.filter(negate(getIteratee(predicate)));
  15582. };
  15583. LazyWrapper.prototype.slice = function(start, end) {
  15584. start = toInteger(start);
  15585. var result = this;
  15586. if (result.__filtered__ && (start > 0 || end < 0)) {
  15587. return new LazyWrapper(result);
  15588. }
  15589. if (start < 0) {
  15590. result = result.takeRight(-start);
  15591. } else if (start) {
  15592. result = result.drop(start);
  15593. }
  15594. if (end !== undefined) {
  15595. end = toInteger(end);
  15596. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  15597. }
  15598. return result;
  15599. };
  15600. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  15601. return this.reverse().takeWhile(predicate).reverse();
  15602. };
  15603. LazyWrapper.prototype.toArray = function() {
  15604. return this.take(MAX_ARRAY_LENGTH);
  15605. };
  15606. // Add `LazyWrapper` methods to `lodash.prototype`.
  15607. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15608. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  15609. isTaker = /^(?:head|last)$/.test(methodName),
  15610. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  15611. retUnwrapped = isTaker || /^find/.test(methodName);
  15612. if (!lodashFunc) {
  15613. return;
  15614. }
  15615. lodash.prototype[methodName] = function() {
  15616. var value = this.__wrapped__,
  15617. args = isTaker ? [1] : arguments,
  15618. isLazy = value instanceof LazyWrapper,
  15619. iteratee = args[0],
  15620. useLazy = isLazy || isArray(value);
  15621. var interceptor = function(value) {
  15622. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  15623. return (isTaker && chainAll) ? result[0] : result;
  15624. };
  15625. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  15626. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  15627. isLazy = useLazy = false;
  15628. }
  15629. var chainAll = this.__chain__,
  15630. isHybrid = !!this.__actions__.length,
  15631. isUnwrapped = retUnwrapped && !chainAll,
  15632. onlyLazy = isLazy && !isHybrid;
  15633. if (!retUnwrapped && useLazy) {
  15634. value = onlyLazy ? value : new LazyWrapper(this);
  15635. var result = func.apply(value, args);
  15636. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  15637. return new LodashWrapper(result, chainAll);
  15638. }
  15639. if (isUnwrapped && onlyLazy) {
  15640. return func.apply(this, args);
  15641. }
  15642. result = this.thru(interceptor);
  15643. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  15644. };
  15645. });
  15646. // Add `Array` methods to `lodash.prototype`.
  15647. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  15648. var func = arrayProto[methodName],
  15649. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  15650. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  15651. lodash.prototype[methodName] = function() {
  15652. var args = arguments;
  15653. if (retUnwrapped && !this.__chain__) {
  15654. var value = this.value();
  15655. return func.apply(isArray(value) ? value : [], args);
  15656. }
  15657. return this[chainName](function(value) {
  15658. return func.apply(isArray(value) ? value : [], args);
  15659. });
  15660. };
  15661. });
  15662. // Map minified method names to their real names.
  15663. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  15664. var lodashFunc = lodash[methodName];
  15665. if (lodashFunc) {
  15666. var key = (lodashFunc.name + ''),
  15667. names = realNames[key] || (realNames[key] = []);
  15668. names.push({ 'name': methodName, 'func': lodashFunc });
  15669. }
  15670. });
  15671. realNames[createHybrid(undefined, BIND_KEY_FLAG).name] = [{
  15672. 'name': 'wrapper',
  15673. 'func': undefined
  15674. }];
  15675. // Add methods to `LazyWrapper`.
  15676. LazyWrapper.prototype.clone = lazyClone;
  15677. LazyWrapper.prototype.reverse = lazyReverse;
  15678. LazyWrapper.prototype.value = lazyValue;
  15679. // Add chain sequence methods to the `lodash` wrapper.
  15680. lodash.prototype.at = wrapperAt;
  15681. lodash.prototype.chain = wrapperChain;
  15682. lodash.prototype.commit = wrapperCommit;
  15683. lodash.prototype.next = wrapperNext;
  15684. lodash.prototype.plant = wrapperPlant;
  15685. lodash.prototype.reverse = wrapperReverse;
  15686. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  15687. // Add lazy aliases.
  15688. lodash.prototype.first = lodash.prototype.head;
  15689. if (iteratorSymbol) {
  15690. lodash.prototype[iteratorSymbol] = wrapperToIterator;
  15691. }
  15692. return lodash;
  15693. }
  15694. /*--------------------------------------------------------------------------*/
  15695. // Export lodash.
  15696. var _ = runInContext();
  15697. // Some AMD build optimizers, like r.js, check for condition patterns like:
  15698. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  15699. // Expose Lodash on the global object to prevent errors when Lodash is
  15700. // loaded by a script tag in the presence of an AMD loader.
  15701. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  15702. // Use `_.noConflict` to remove Lodash from the global object.
  15703. root._ = _;
  15704. // Define as an anonymous module so, through path mapping, it can be
  15705. // referenced as the "underscore" module.
  15706. define(function() {
  15707. return _;
  15708. });
  15709. }
  15710. // Check for `exports` after `define` in case a build optimizer adds it.
  15711. else if (freeModule) {
  15712. // Export for Node.js.
  15713. (freeModule.exports = _)._ = _;
  15714. // Export for CommonJS support.
  15715. freeExports._ = _;
  15716. }
  15717. else {
  15718. // Export to the global object.
  15719. root._ = _;
  15720. }
  15721. }.call(this));