bundle.js 532 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/
  8. /******/ // Check if module is in cache
  9. /******/ if(installedModules[moduleId]) {
  10. /******/ return installedModules[moduleId].exports;
  11. /******/ }
  12. /******/ // Create a new module (and put it into the cache)
  13. /******/ var module = installedModules[moduleId] = {
  14. /******/ i: moduleId,
  15. /******/ l: false,
  16. /******/ exports: {}
  17. /******/ };
  18. /******/
  19. /******/ // Execute the module function
  20. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  21. /******/
  22. /******/ // Flag the module as loaded
  23. /******/ module.l = true;
  24. /******/
  25. /******/ // Return the exports of the module
  26. /******/ return module.exports;
  27. /******/ }
  28. /******/
  29. /******/
  30. /******/ // expose the modules object (__webpack_modules__)
  31. /******/ __webpack_require__.m = modules;
  32. /******/
  33. /******/ // expose the module cache
  34. /******/ __webpack_require__.c = installedModules;
  35. /******/
  36. /******/ // define getter function for harmony exports
  37. /******/ __webpack_require__.d = function(exports, name, getter) {
  38. /******/ if(!__webpack_require__.o(exports, name)) {
  39. /******/ Object.defineProperty(exports, name, {
  40. /******/ configurable: false,
  41. /******/ enumerable: true,
  42. /******/ get: getter
  43. /******/ });
  44. /******/ }
  45. /******/ };
  46. /******/
  47. /******/ // getDefaultExport function for compatibility with non-harmony modules
  48. /******/ __webpack_require__.n = function(module) {
  49. /******/ var getter = module && module.__esModule ?
  50. /******/ function getDefault() { return module['default']; } :
  51. /******/ function getModuleExports() { return module; };
  52. /******/ __webpack_require__.d(getter, 'a', getter);
  53. /******/ return getter;
  54. /******/ };
  55. /******/
  56. /******/ // Object.prototype.hasOwnProperty.call
  57. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  58. /******/
  59. /******/ // __webpack_public_path__
  60. /******/ __webpack_require__.p = "";
  61. /******/
  62. /******/ // Load entry module and return exports
  63. /******/ return __webpack_require__(__webpack_require__.s = 0);
  64. /******/ })
  65. /************************************************************************/
  66. /******/ ([
  67. /* 0 */
  68. /***/ (function(module, __webpack_exports__, __webpack_require__) {
  69. "use strict";
  70. Object.defineProperty(__webpack_exports__, "__esModule", { value: true });
  71. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_lodash__ = __webpack_require__(1);
  72. /* harmony import */ var __WEBPACK_IMPORTED_MODULE_0_lodash___default = __webpack_require__.n(__WEBPACK_IMPORTED_MODULE_0_lodash__);
  73. //import express from 'express';
  74. //
  75. //const PORT = 3000;
  76. //const app = express();
  77. //
  78. //app.use(express.static('public'));
  79. //app.listen(PORT, () => {
  80. // console.log(`Listening on ${PORT}.`);
  81. //});
  82. function component() {
  83. var element = document.createElement('div');
  84. // Lodash, now imported by this script
  85. element.innerHTML = __WEBPACK_IMPORTED_MODULE_0_lodash___default.a.join(['Hello', 'webpack'], ' ');
  86. return element;
  87. }
  88. document.body.appendChild(component());
  89. /***/ }),
  90. /* 1 */
  91. /***/ (function(module, exports, __webpack_require__) {
  92. /* WEBPACK VAR INJECTION */(function(global, module) {var __WEBPACK_AMD_DEFINE_RESULT__;/**
  93. * @license
  94. * Lodash <https://lodash.com/>
  95. * Copyright JS Foundation and other contributors <https://js.foundation/>
  96. * Released under MIT license <https://lodash.com/license>
  97. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  98. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  99. */
  100. ;(function() {
  101. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  102. var undefined;
  103. /** Used as the semantic version number. */
  104. var VERSION = '4.17.4';
  105. /** Used as the size to enable large array optimizations. */
  106. var LARGE_ARRAY_SIZE = 200;
  107. /** Error message constants. */
  108. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  109. FUNC_ERROR_TEXT = 'Expected a function';
  110. /** Used to stand-in for `undefined` hash values. */
  111. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  112. /** Used as the maximum memoize cache size. */
  113. var MAX_MEMOIZE_SIZE = 500;
  114. /** Used as the internal argument placeholder. */
  115. var PLACEHOLDER = '__lodash_placeholder__';
  116. /** Used to compose bitmasks for cloning. */
  117. var CLONE_DEEP_FLAG = 1,
  118. CLONE_FLAT_FLAG = 2,
  119. CLONE_SYMBOLS_FLAG = 4;
  120. /** Used to compose bitmasks for value comparisons. */
  121. var COMPARE_PARTIAL_FLAG = 1,
  122. COMPARE_UNORDERED_FLAG = 2;
  123. /** Used to compose bitmasks for function metadata. */
  124. var WRAP_BIND_FLAG = 1,
  125. WRAP_BIND_KEY_FLAG = 2,
  126. WRAP_CURRY_BOUND_FLAG = 4,
  127. WRAP_CURRY_FLAG = 8,
  128. WRAP_CURRY_RIGHT_FLAG = 16,
  129. WRAP_PARTIAL_FLAG = 32,
  130. WRAP_PARTIAL_RIGHT_FLAG = 64,
  131. WRAP_ARY_FLAG = 128,
  132. WRAP_REARG_FLAG = 256,
  133. WRAP_FLIP_FLAG = 512;
  134. /** Used as default options for `_.truncate`. */
  135. var DEFAULT_TRUNC_LENGTH = 30,
  136. DEFAULT_TRUNC_OMISSION = '...';
  137. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  138. var HOT_COUNT = 800,
  139. HOT_SPAN = 16;
  140. /** Used to indicate the type of lazy iteratees. */
  141. var LAZY_FILTER_FLAG = 1,
  142. LAZY_MAP_FLAG = 2,
  143. LAZY_WHILE_FLAG = 3;
  144. /** Used as references for various `Number` constants. */
  145. var INFINITY = 1 / 0,
  146. MAX_SAFE_INTEGER = 9007199254740991,
  147. MAX_INTEGER = 1.7976931348623157e+308,
  148. NAN = 0 / 0;
  149. /** Used as references for the maximum length and index of an array. */
  150. var MAX_ARRAY_LENGTH = 4294967295,
  151. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  152. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  153. /** Used to associate wrap methods with their bit flags. */
  154. var wrapFlags = [
  155. ['ary', WRAP_ARY_FLAG],
  156. ['bind', WRAP_BIND_FLAG],
  157. ['bindKey', WRAP_BIND_KEY_FLAG],
  158. ['curry', WRAP_CURRY_FLAG],
  159. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  160. ['flip', WRAP_FLIP_FLAG],
  161. ['partial', WRAP_PARTIAL_FLAG],
  162. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  163. ['rearg', WRAP_REARG_FLAG]
  164. ];
  165. /** `Object#toString` result references. */
  166. var argsTag = '[object Arguments]',
  167. arrayTag = '[object Array]',
  168. asyncTag = '[object AsyncFunction]',
  169. boolTag = '[object Boolean]',
  170. dateTag = '[object Date]',
  171. domExcTag = '[object DOMException]',
  172. errorTag = '[object Error]',
  173. funcTag = '[object Function]',
  174. genTag = '[object GeneratorFunction]',
  175. mapTag = '[object Map]',
  176. numberTag = '[object Number]',
  177. nullTag = '[object Null]',
  178. objectTag = '[object Object]',
  179. promiseTag = '[object Promise]',
  180. proxyTag = '[object Proxy]',
  181. regexpTag = '[object RegExp]',
  182. setTag = '[object Set]',
  183. stringTag = '[object String]',
  184. symbolTag = '[object Symbol]',
  185. undefinedTag = '[object Undefined]',
  186. weakMapTag = '[object WeakMap]',
  187. weakSetTag = '[object WeakSet]';
  188. var arrayBufferTag = '[object ArrayBuffer]',
  189. dataViewTag = '[object DataView]',
  190. float32Tag = '[object Float32Array]',
  191. float64Tag = '[object Float64Array]',
  192. int8Tag = '[object Int8Array]',
  193. int16Tag = '[object Int16Array]',
  194. int32Tag = '[object Int32Array]',
  195. uint8Tag = '[object Uint8Array]',
  196. uint8ClampedTag = '[object Uint8ClampedArray]',
  197. uint16Tag = '[object Uint16Array]',
  198. uint32Tag = '[object Uint32Array]';
  199. /** Used to match empty string literals in compiled template source. */
  200. var reEmptyStringLeading = /\b__p \+= '';/g,
  201. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  202. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  203. /** Used to match HTML entities and HTML characters. */
  204. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  205. reUnescapedHtml = /[&<>"']/g,
  206. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  207. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  208. /** Used to match template delimiters. */
  209. var reEscape = /<%-([\s\S]+?)%>/g,
  210. reEvaluate = /<%([\s\S]+?)%>/g,
  211. reInterpolate = /<%=([\s\S]+?)%>/g;
  212. /** Used to match property names within property paths. */
  213. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  214. reIsPlainProp = /^\w*$/,
  215. reLeadingDot = /^\./,
  216. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  217. /**
  218. * Used to match `RegExp`
  219. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  220. */
  221. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  222. reHasRegExpChar = RegExp(reRegExpChar.source);
  223. /** Used to match leading and trailing whitespace. */
  224. var reTrim = /^\s+|\s+$/g,
  225. reTrimStart = /^\s+/,
  226. reTrimEnd = /\s+$/;
  227. /** Used to match wrap detail comments. */
  228. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  229. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  230. reSplitDetails = /,? & /;
  231. /** Used to match words composed of alphanumeric characters. */
  232. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  233. /** Used to match backslashes in property paths. */
  234. var reEscapeChar = /\\(\\)?/g;
  235. /**
  236. * Used to match
  237. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  238. */
  239. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  240. /** Used to match `RegExp` flags from their coerced string values. */
  241. var reFlags = /\w*$/;
  242. /** Used to detect bad signed hexadecimal string values. */
  243. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  244. /** Used to detect binary string values. */
  245. var reIsBinary = /^0b[01]+$/i;
  246. /** Used to detect host constructors (Safari). */
  247. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  248. /** Used to detect octal string values. */
  249. var reIsOctal = /^0o[0-7]+$/i;
  250. /** Used to detect unsigned integer values. */
  251. var reIsUint = /^(?:0|[1-9]\d*)$/;
  252. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  253. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  254. /** Used to ensure capturing order of template delimiters. */
  255. var reNoMatch = /($^)/;
  256. /** Used to match unescaped characters in compiled string literals. */
  257. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  258. /** Used to compose unicode character classes. */
  259. var rsAstralRange = '\\ud800-\\udfff',
  260. rsComboMarksRange = '\\u0300-\\u036f',
  261. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  262. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  263. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  264. rsDingbatRange = '\\u2700-\\u27bf',
  265. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  266. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  267. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  268. rsPunctuationRange = '\\u2000-\\u206f',
  269. 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',
  270. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  271. rsVarRange = '\\ufe0e\\ufe0f',
  272. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  273. /** Used to compose unicode capture groups. */
  274. var rsApos = "['\u2019]",
  275. rsAstral = '[' + rsAstralRange + ']',
  276. rsBreak = '[' + rsBreakRange + ']',
  277. rsCombo = '[' + rsComboRange + ']',
  278. rsDigits = '\\d+',
  279. rsDingbat = '[' + rsDingbatRange + ']',
  280. rsLower = '[' + rsLowerRange + ']',
  281. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  282. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  283. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  284. rsNonAstral = '[^' + rsAstralRange + ']',
  285. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  286. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  287. rsUpper = '[' + rsUpperRange + ']',
  288. rsZWJ = '\\u200d';
  289. /** Used to compose unicode regexes. */
  290. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  291. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  292. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  293. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  294. reOptMod = rsModifier + '?',
  295. rsOptVar = '[' + rsVarRange + ']?',
  296. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  297. rsOrdLower = '\\d*(?:(?:1st|2nd|3rd|(?![123])\\dth)\\b)',
  298. rsOrdUpper = '\\d*(?:(?:1ST|2ND|3RD|(?![123])\\dTH)\\b)',
  299. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  300. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  301. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  302. /** Used to match apostrophes. */
  303. var reApos = RegExp(rsApos, 'g');
  304. /**
  305. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  306. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  307. */
  308. var reComboMark = RegExp(rsCombo, 'g');
  309. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  310. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  311. /** Used to match complex or compound words. */
  312. var reUnicodeWord = RegExp([
  313. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  314. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  315. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  316. rsUpper + '+' + rsOptContrUpper,
  317. rsOrdUpper,
  318. rsOrdLower,
  319. rsDigits,
  320. rsEmoji
  321. ].join('|'), 'g');
  322. /** 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/). */
  323. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  324. /** Used to detect strings that need a more robust regexp to match words. */
  325. 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 ]/;
  326. /** Used to assign default `context` object properties. */
  327. var contextProps = [
  328. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  329. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  330. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  331. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  332. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  333. ];
  334. /** Used to make template sourceURLs easier to identify. */
  335. var templateCounter = -1;
  336. /** Used to identify `toStringTag` values of typed arrays. */
  337. var typedArrayTags = {};
  338. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  339. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  340. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  341. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  342. typedArrayTags[uint32Tag] = true;
  343. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  344. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  345. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  346. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  347. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  348. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  349. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  350. typedArrayTags[weakMapTag] = false;
  351. /** Used to identify `toStringTag` values supported by `_.clone`. */
  352. var cloneableTags = {};
  353. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  354. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  355. cloneableTags[boolTag] = cloneableTags[dateTag] =
  356. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  357. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  358. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  359. cloneableTags[numberTag] = cloneableTags[objectTag] =
  360. cloneableTags[regexpTag] = cloneableTags[setTag] =
  361. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  362. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  363. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  364. cloneableTags[errorTag] = cloneableTags[funcTag] =
  365. cloneableTags[weakMapTag] = false;
  366. /** Used to map Latin Unicode letters to basic Latin letters. */
  367. var deburredLetters = {
  368. // Latin-1 Supplement block.
  369. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  370. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  371. '\xc7': 'C', '\xe7': 'c',
  372. '\xd0': 'D', '\xf0': 'd',
  373. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  374. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  375. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  376. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  377. '\xd1': 'N', '\xf1': 'n',
  378. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  379. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  380. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  381. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  382. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  383. '\xc6': 'Ae', '\xe6': 'ae',
  384. '\xde': 'Th', '\xfe': 'th',
  385. '\xdf': 'ss',
  386. // Latin Extended-A block.
  387. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  388. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  389. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  390. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  391. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  392. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  393. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  394. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  395. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  396. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  397. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  398. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  399. '\u0134': 'J', '\u0135': 'j',
  400. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  401. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  402. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  403. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  404. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  405. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  406. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  407. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  408. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  409. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  410. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  411. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  412. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  413. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  414. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  415. '\u0174': 'W', '\u0175': 'w',
  416. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  417. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  418. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  419. '\u0132': 'IJ', '\u0133': 'ij',
  420. '\u0152': 'Oe', '\u0153': 'oe',
  421. '\u0149': "'n", '\u017f': 's'
  422. };
  423. /** Used to map characters to HTML entities. */
  424. var htmlEscapes = {
  425. '&': '&amp;',
  426. '<': '&lt;',
  427. '>': '&gt;',
  428. '"': '&quot;',
  429. "'": '&#39;'
  430. };
  431. /** Used to map HTML entities to characters. */
  432. var htmlUnescapes = {
  433. '&amp;': '&',
  434. '&lt;': '<',
  435. '&gt;': '>',
  436. '&quot;': '"',
  437. '&#39;': "'"
  438. };
  439. /** Used to escape characters for inclusion in compiled string literals. */
  440. var stringEscapes = {
  441. '\\': '\\',
  442. "'": "'",
  443. '\n': 'n',
  444. '\r': 'r',
  445. '\u2028': 'u2028',
  446. '\u2029': 'u2029'
  447. };
  448. /** Built-in method references without a dependency on `root`. */
  449. var freeParseFloat = parseFloat,
  450. freeParseInt = parseInt;
  451. /** Detect free variable `global` from Node.js. */
  452. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  453. /** Detect free variable `self`. */
  454. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  455. /** Used as a reference to the global object. */
  456. var root = freeGlobal || freeSelf || Function('return this')();
  457. /** Detect free variable `exports`. */
  458. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  459. /** Detect free variable `module`. */
  460. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  461. /** Detect the popular CommonJS extension `module.exports`. */
  462. var moduleExports = freeModule && freeModule.exports === freeExports;
  463. /** Detect free variable `process` from Node.js. */
  464. var freeProcess = moduleExports && freeGlobal.process;
  465. /** Used to access faster Node.js helpers. */
  466. var nodeUtil = (function() {
  467. try {
  468. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  469. } catch (e) {}
  470. }());
  471. /* Node.js helper references. */
  472. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  473. nodeIsDate = nodeUtil && nodeUtil.isDate,
  474. nodeIsMap = nodeUtil && nodeUtil.isMap,
  475. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  476. nodeIsSet = nodeUtil && nodeUtil.isSet,
  477. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  478. /*--------------------------------------------------------------------------*/
  479. /**
  480. * Adds the key-value `pair` to `map`.
  481. *
  482. * @private
  483. * @param {Object} map The map to modify.
  484. * @param {Array} pair The key-value pair to add.
  485. * @returns {Object} Returns `map`.
  486. */
  487. function addMapEntry(map, pair) {
  488. // Don't return `map.set` because it's not chainable in IE 11.
  489. map.set(pair[0], pair[1]);
  490. return map;
  491. }
  492. /**
  493. * Adds `value` to `set`.
  494. *
  495. * @private
  496. * @param {Object} set The set to modify.
  497. * @param {*} value The value to add.
  498. * @returns {Object} Returns `set`.
  499. */
  500. function addSetEntry(set, value) {
  501. // Don't return `set.add` because it's not chainable in IE 11.
  502. set.add(value);
  503. return set;
  504. }
  505. /**
  506. * A faster alternative to `Function#apply`, this function invokes `func`
  507. * with the `this` binding of `thisArg` and the arguments of `args`.
  508. *
  509. * @private
  510. * @param {Function} func The function to invoke.
  511. * @param {*} thisArg The `this` binding of `func`.
  512. * @param {Array} args The arguments to invoke `func` with.
  513. * @returns {*} Returns the result of `func`.
  514. */
  515. function apply(func, thisArg, args) {
  516. switch (args.length) {
  517. case 0: return func.call(thisArg);
  518. case 1: return func.call(thisArg, args[0]);
  519. case 2: return func.call(thisArg, args[0], args[1]);
  520. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  521. }
  522. return func.apply(thisArg, args);
  523. }
  524. /**
  525. * A specialized version of `baseAggregator` for arrays.
  526. *
  527. * @private
  528. * @param {Array} [array] The array to iterate over.
  529. * @param {Function} setter The function to set `accumulator` values.
  530. * @param {Function} iteratee The iteratee to transform keys.
  531. * @param {Object} accumulator The initial aggregated object.
  532. * @returns {Function} Returns `accumulator`.
  533. */
  534. function arrayAggregator(array, setter, iteratee, accumulator) {
  535. var index = -1,
  536. length = array == null ? 0 : array.length;
  537. while (++index < length) {
  538. var value = array[index];
  539. setter(accumulator, value, iteratee(value), array);
  540. }
  541. return accumulator;
  542. }
  543. /**
  544. * A specialized version of `_.forEach` for arrays without support for
  545. * iteratee shorthands.
  546. *
  547. * @private
  548. * @param {Array} [array] The array to iterate over.
  549. * @param {Function} iteratee The function invoked per iteration.
  550. * @returns {Array} Returns `array`.
  551. */
  552. function arrayEach(array, iteratee) {
  553. var index = -1,
  554. length = array == null ? 0 : array.length;
  555. while (++index < length) {
  556. if (iteratee(array[index], index, array) === false) {
  557. break;
  558. }
  559. }
  560. return array;
  561. }
  562. /**
  563. * A specialized version of `_.forEachRight` for arrays without support for
  564. * iteratee shorthands.
  565. *
  566. * @private
  567. * @param {Array} [array] The array to iterate over.
  568. * @param {Function} iteratee The function invoked per iteration.
  569. * @returns {Array} Returns `array`.
  570. */
  571. function arrayEachRight(array, iteratee) {
  572. var length = array == null ? 0 : array.length;
  573. while (length--) {
  574. if (iteratee(array[length], length, array) === false) {
  575. break;
  576. }
  577. }
  578. return array;
  579. }
  580. /**
  581. * A specialized version of `_.every` for arrays without support for
  582. * iteratee shorthands.
  583. *
  584. * @private
  585. * @param {Array} [array] The array to iterate over.
  586. * @param {Function} predicate The function invoked per iteration.
  587. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  588. * else `false`.
  589. */
  590. function arrayEvery(array, predicate) {
  591. var index = -1,
  592. length = array == null ? 0 : array.length;
  593. while (++index < length) {
  594. if (!predicate(array[index], index, array)) {
  595. return false;
  596. }
  597. }
  598. return true;
  599. }
  600. /**
  601. * A specialized version of `_.filter` for arrays without support for
  602. * iteratee shorthands.
  603. *
  604. * @private
  605. * @param {Array} [array] The array to iterate over.
  606. * @param {Function} predicate The function invoked per iteration.
  607. * @returns {Array} Returns the new filtered array.
  608. */
  609. function arrayFilter(array, predicate) {
  610. var index = -1,
  611. length = array == null ? 0 : array.length,
  612. resIndex = 0,
  613. result = [];
  614. while (++index < length) {
  615. var value = array[index];
  616. if (predicate(value, index, array)) {
  617. result[resIndex++] = value;
  618. }
  619. }
  620. return result;
  621. }
  622. /**
  623. * A specialized version of `_.includes` for arrays without support for
  624. * specifying an index to search from.
  625. *
  626. * @private
  627. * @param {Array} [array] The array to inspect.
  628. * @param {*} target The value to search for.
  629. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  630. */
  631. function arrayIncludes(array, value) {
  632. var length = array == null ? 0 : array.length;
  633. return !!length && baseIndexOf(array, value, 0) > -1;
  634. }
  635. /**
  636. * This function is like `arrayIncludes` except that it accepts a comparator.
  637. *
  638. * @private
  639. * @param {Array} [array] The array to inspect.
  640. * @param {*} target The value to search for.
  641. * @param {Function} comparator The comparator invoked per element.
  642. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  643. */
  644. function arrayIncludesWith(array, value, comparator) {
  645. var index = -1,
  646. length = array == null ? 0 : array.length;
  647. while (++index < length) {
  648. if (comparator(value, array[index])) {
  649. return true;
  650. }
  651. }
  652. return false;
  653. }
  654. /**
  655. * A specialized version of `_.map` for arrays without support for iteratee
  656. * shorthands.
  657. *
  658. * @private
  659. * @param {Array} [array] The array to iterate over.
  660. * @param {Function} iteratee The function invoked per iteration.
  661. * @returns {Array} Returns the new mapped array.
  662. */
  663. function arrayMap(array, iteratee) {
  664. var index = -1,
  665. length = array == null ? 0 : array.length,
  666. result = Array(length);
  667. while (++index < length) {
  668. result[index] = iteratee(array[index], index, array);
  669. }
  670. return result;
  671. }
  672. /**
  673. * Appends the elements of `values` to `array`.
  674. *
  675. * @private
  676. * @param {Array} array The array to modify.
  677. * @param {Array} values The values to append.
  678. * @returns {Array} Returns `array`.
  679. */
  680. function arrayPush(array, values) {
  681. var index = -1,
  682. length = values.length,
  683. offset = array.length;
  684. while (++index < length) {
  685. array[offset + index] = values[index];
  686. }
  687. return array;
  688. }
  689. /**
  690. * A specialized version of `_.reduce` for arrays without support for
  691. * iteratee shorthands.
  692. *
  693. * @private
  694. * @param {Array} [array] The array to iterate over.
  695. * @param {Function} iteratee The function invoked per iteration.
  696. * @param {*} [accumulator] The initial value.
  697. * @param {boolean} [initAccum] Specify using the first element of `array` as
  698. * the initial value.
  699. * @returns {*} Returns the accumulated value.
  700. */
  701. function arrayReduce(array, iteratee, accumulator, initAccum) {
  702. var index = -1,
  703. length = array == null ? 0 : array.length;
  704. if (initAccum && length) {
  705. accumulator = array[++index];
  706. }
  707. while (++index < length) {
  708. accumulator = iteratee(accumulator, array[index], index, array);
  709. }
  710. return accumulator;
  711. }
  712. /**
  713. * A specialized version of `_.reduceRight` for arrays without support for
  714. * iteratee shorthands.
  715. *
  716. * @private
  717. * @param {Array} [array] The array to iterate over.
  718. * @param {Function} iteratee The function invoked per iteration.
  719. * @param {*} [accumulator] The initial value.
  720. * @param {boolean} [initAccum] Specify using the last element of `array` as
  721. * the initial value.
  722. * @returns {*} Returns the accumulated value.
  723. */
  724. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  725. var length = array == null ? 0 : array.length;
  726. if (initAccum && length) {
  727. accumulator = array[--length];
  728. }
  729. while (length--) {
  730. accumulator = iteratee(accumulator, array[length], length, array);
  731. }
  732. return accumulator;
  733. }
  734. /**
  735. * A specialized version of `_.some` for arrays without support for iteratee
  736. * shorthands.
  737. *
  738. * @private
  739. * @param {Array} [array] The array to iterate over.
  740. * @param {Function} predicate The function invoked per iteration.
  741. * @returns {boolean} Returns `true` if any element passes the predicate check,
  742. * else `false`.
  743. */
  744. function arraySome(array, predicate) {
  745. var index = -1,
  746. length = array == null ? 0 : array.length;
  747. while (++index < length) {
  748. if (predicate(array[index], index, array)) {
  749. return true;
  750. }
  751. }
  752. return false;
  753. }
  754. /**
  755. * Gets the size of an ASCII `string`.
  756. *
  757. * @private
  758. * @param {string} string The string inspect.
  759. * @returns {number} Returns the string size.
  760. */
  761. var asciiSize = baseProperty('length');
  762. /**
  763. * Converts an ASCII `string` to an array.
  764. *
  765. * @private
  766. * @param {string} string The string to convert.
  767. * @returns {Array} Returns the converted array.
  768. */
  769. function asciiToArray(string) {
  770. return string.split('');
  771. }
  772. /**
  773. * Splits an ASCII `string` into an array of its words.
  774. *
  775. * @private
  776. * @param {string} The string to inspect.
  777. * @returns {Array} Returns the words of `string`.
  778. */
  779. function asciiWords(string) {
  780. return string.match(reAsciiWord) || [];
  781. }
  782. /**
  783. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  784. * without support for iteratee shorthands, which iterates over `collection`
  785. * using `eachFunc`.
  786. *
  787. * @private
  788. * @param {Array|Object} collection The collection to inspect.
  789. * @param {Function} predicate The function invoked per iteration.
  790. * @param {Function} eachFunc The function to iterate over `collection`.
  791. * @returns {*} Returns the found element or its key, else `undefined`.
  792. */
  793. function baseFindKey(collection, predicate, eachFunc) {
  794. var result;
  795. eachFunc(collection, function(value, key, collection) {
  796. if (predicate(value, key, collection)) {
  797. result = key;
  798. return false;
  799. }
  800. });
  801. return result;
  802. }
  803. /**
  804. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  805. * support for iteratee shorthands.
  806. *
  807. * @private
  808. * @param {Array} array The array to inspect.
  809. * @param {Function} predicate The function invoked per iteration.
  810. * @param {number} fromIndex The index to search from.
  811. * @param {boolean} [fromRight] Specify iterating from right to left.
  812. * @returns {number} Returns the index of the matched value, else `-1`.
  813. */
  814. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  815. var length = array.length,
  816. index = fromIndex + (fromRight ? 1 : -1);
  817. while ((fromRight ? index-- : ++index < length)) {
  818. if (predicate(array[index], index, array)) {
  819. return index;
  820. }
  821. }
  822. return -1;
  823. }
  824. /**
  825. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  826. *
  827. * @private
  828. * @param {Array} array The array to inspect.
  829. * @param {*} value The value to search for.
  830. * @param {number} fromIndex The index to search from.
  831. * @returns {number} Returns the index of the matched value, else `-1`.
  832. */
  833. function baseIndexOf(array, value, fromIndex) {
  834. return value === value
  835. ? strictIndexOf(array, value, fromIndex)
  836. : baseFindIndex(array, baseIsNaN, fromIndex);
  837. }
  838. /**
  839. * This function is like `baseIndexOf` except that it accepts a comparator.
  840. *
  841. * @private
  842. * @param {Array} array The array to inspect.
  843. * @param {*} value The value to search for.
  844. * @param {number} fromIndex The index to search from.
  845. * @param {Function} comparator The comparator invoked per element.
  846. * @returns {number} Returns the index of the matched value, else `-1`.
  847. */
  848. function baseIndexOfWith(array, value, fromIndex, comparator) {
  849. var index = fromIndex - 1,
  850. length = array.length;
  851. while (++index < length) {
  852. if (comparator(array[index], value)) {
  853. return index;
  854. }
  855. }
  856. return -1;
  857. }
  858. /**
  859. * The base implementation of `_.isNaN` without support for number objects.
  860. *
  861. * @private
  862. * @param {*} value The value to check.
  863. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  864. */
  865. function baseIsNaN(value) {
  866. return value !== value;
  867. }
  868. /**
  869. * The base implementation of `_.mean` and `_.meanBy` without support for
  870. * iteratee shorthands.
  871. *
  872. * @private
  873. * @param {Array} array The array to iterate over.
  874. * @param {Function} iteratee The function invoked per iteration.
  875. * @returns {number} Returns the mean.
  876. */
  877. function baseMean(array, iteratee) {
  878. var length = array == null ? 0 : array.length;
  879. return length ? (baseSum(array, iteratee) / length) : NAN;
  880. }
  881. /**
  882. * The base implementation of `_.property` without support for deep paths.
  883. *
  884. * @private
  885. * @param {string} key The key of the property to get.
  886. * @returns {Function} Returns the new accessor function.
  887. */
  888. function baseProperty(key) {
  889. return function(object) {
  890. return object == null ? undefined : object[key];
  891. };
  892. }
  893. /**
  894. * The base implementation of `_.propertyOf` without support for deep paths.
  895. *
  896. * @private
  897. * @param {Object} object The object to query.
  898. * @returns {Function} Returns the new accessor function.
  899. */
  900. function basePropertyOf(object) {
  901. return function(key) {
  902. return object == null ? undefined : object[key];
  903. };
  904. }
  905. /**
  906. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  907. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  908. *
  909. * @private
  910. * @param {Array|Object} collection The collection to iterate over.
  911. * @param {Function} iteratee The function invoked per iteration.
  912. * @param {*} accumulator The initial value.
  913. * @param {boolean} initAccum Specify using the first or last element of
  914. * `collection` as the initial value.
  915. * @param {Function} eachFunc The function to iterate over `collection`.
  916. * @returns {*} Returns the accumulated value.
  917. */
  918. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  919. eachFunc(collection, function(value, index, collection) {
  920. accumulator = initAccum
  921. ? (initAccum = false, value)
  922. : iteratee(accumulator, value, index, collection);
  923. });
  924. return accumulator;
  925. }
  926. /**
  927. * The base implementation of `_.sortBy` which uses `comparer` to define the
  928. * sort order of `array` and replaces criteria objects with their corresponding
  929. * values.
  930. *
  931. * @private
  932. * @param {Array} array The array to sort.
  933. * @param {Function} comparer The function to define sort order.
  934. * @returns {Array} Returns `array`.
  935. */
  936. function baseSortBy(array, comparer) {
  937. var length = array.length;
  938. array.sort(comparer);
  939. while (length--) {
  940. array[length] = array[length].value;
  941. }
  942. return array;
  943. }
  944. /**
  945. * The base implementation of `_.sum` and `_.sumBy` without support for
  946. * iteratee shorthands.
  947. *
  948. * @private
  949. * @param {Array} array The array to iterate over.
  950. * @param {Function} iteratee The function invoked per iteration.
  951. * @returns {number} Returns the sum.
  952. */
  953. function baseSum(array, iteratee) {
  954. var result,
  955. index = -1,
  956. length = array.length;
  957. while (++index < length) {
  958. var current = iteratee(array[index]);
  959. if (current !== undefined) {
  960. result = result === undefined ? current : (result + current);
  961. }
  962. }
  963. return result;
  964. }
  965. /**
  966. * The base implementation of `_.times` without support for iteratee shorthands
  967. * or max array length checks.
  968. *
  969. * @private
  970. * @param {number} n The number of times to invoke `iteratee`.
  971. * @param {Function} iteratee The function invoked per iteration.
  972. * @returns {Array} Returns the array of results.
  973. */
  974. function baseTimes(n, iteratee) {
  975. var index = -1,
  976. result = Array(n);
  977. while (++index < n) {
  978. result[index] = iteratee(index);
  979. }
  980. return result;
  981. }
  982. /**
  983. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  984. * of key-value pairs for `object` corresponding to the property names of `props`.
  985. *
  986. * @private
  987. * @param {Object} object The object to query.
  988. * @param {Array} props The property names to get values for.
  989. * @returns {Object} Returns the key-value pairs.
  990. */
  991. function baseToPairs(object, props) {
  992. return arrayMap(props, function(key) {
  993. return [key, object[key]];
  994. });
  995. }
  996. /**
  997. * The base implementation of `_.unary` without support for storing metadata.
  998. *
  999. * @private
  1000. * @param {Function} func The function to cap arguments for.
  1001. * @returns {Function} Returns the new capped function.
  1002. */
  1003. function baseUnary(func) {
  1004. return function(value) {
  1005. return func(value);
  1006. };
  1007. }
  1008. /**
  1009. * The base implementation of `_.values` and `_.valuesIn` which creates an
  1010. * array of `object` property values corresponding to the property names
  1011. * of `props`.
  1012. *
  1013. * @private
  1014. * @param {Object} object The object to query.
  1015. * @param {Array} props The property names to get values for.
  1016. * @returns {Object} Returns the array of property values.
  1017. */
  1018. function baseValues(object, props) {
  1019. return arrayMap(props, function(key) {
  1020. return object[key];
  1021. });
  1022. }
  1023. /**
  1024. * Checks if a `cache` value for `key` exists.
  1025. *
  1026. * @private
  1027. * @param {Object} cache The cache to query.
  1028. * @param {string} key The key of the entry to check.
  1029. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1030. */
  1031. function cacheHas(cache, key) {
  1032. return cache.has(key);
  1033. }
  1034. /**
  1035. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  1036. * that is not found in the character symbols.
  1037. *
  1038. * @private
  1039. * @param {Array} strSymbols The string symbols to inspect.
  1040. * @param {Array} chrSymbols The character symbols to find.
  1041. * @returns {number} Returns the index of the first unmatched string symbol.
  1042. */
  1043. function charsStartIndex(strSymbols, chrSymbols) {
  1044. var index = -1,
  1045. length = strSymbols.length;
  1046. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  1047. return index;
  1048. }
  1049. /**
  1050. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  1051. * that is not found in the character symbols.
  1052. *
  1053. * @private
  1054. * @param {Array} strSymbols The string symbols to inspect.
  1055. * @param {Array} chrSymbols The character symbols to find.
  1056. * @returns {number} Returns the index of the last unmatched string symbol.
  1057. */
  1058. function charsEndIndex(strSymbols, chrSymbols) {
  1059. var index = strSymbols.length;
  1060. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  1061. return index;
  1062. }
  1063. /**
  1064. * Gets the number of `placeholder` occurrences in `array`.
  1065. *
  1066. * @private
  1067. * @param {Array} array The array to inspect.
  1068. * @param {*} placeholder The placeholder to search for.
  1069. * @returns {number} Returns the placeholder count.
  1070. */
  1071. function countHolders(array, placeholder) {
  1072. var length = array.length,
  1073. result = 0;
  1074. while (length--) {
  1075. if (array[length] === placeholder) {
  1076. ++result;
  1077. }
  1078. }
  1079. return result;
  1080. }
  1081. /**
  1082. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  1083. * letters to basic Latin letters.
  1084. *
  1085. * @private
  1086. * @param {string} letter The matched letter to deburr.
  1087. * @returns {string} Returns the deburred letter.
  1088. */
  1089. var deburrLetter = basePropertyOf(deburredLetters);
  1090. /**
  1091. * Used by `_.escape` to convert characters to HTML entities.
  1092. *
  1093. * @private
  1094. * @param {string} chr The matched character to escape.
  1095. * @returns {string} Returns the escaped character.
  1096. */
  1097. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  1098. /**
  1099. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  1100. *
  1101. * @private
  1102. * @param {string} chr The matched character to escape.
  1103. * @returns {string} Returns the escaped character.
  1104. */
  1105. function escapeStringChar(chr) {
  1106. return '\\' + stringEscapes[chr];
  1107. }
  1108. /**
  1109. * Gets the value at `key` of `object`.
  1110. *
  1111. * @private
  1112. * @param {Object} [object] The object to query.
  1113. * @param {string} key The key of the property to get.
  1114. * @returns {*} Returns the property value.
  1115. */
  1116. function getValue(object, key) {
  1117. return object == null ? undefined : object[key];
  1118. }
  1119. /**
  1120. * Checks if `string` contains Unicode symbols.
  1121. *
  1122. * @private
  1123. * @param {string} string The string to inspect.
  1124. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1125. */
  1126. function hasUnicode(string) {
  1127. return reHasUnicode.test(string);
  1128. }
  1129. /**
  1130. * Checks if `string` contains a word composed of Unicode symbols.
  1131. *
  1132. * @private
  1133. * @param {string} string The string to inspect.
  1134. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1135. */
  1136. function hasUnicodeWord(string) {
  1137. return reHasUnicodeWord.test(string);
  1138. }
  1139. /**
  1140. * Converts `iterator` to an array.
  1141. *
  1142. * @private
  1143. * @param {Object} iterator The iterator to convert.
  1144. * @returns {Array} Returns the converted array.
  1145. */
  1146. function iteratorToArray(iterator) {
  1147. var data,
  1148. result = [];
  1149. while (!(data = iterator.next()).done) {
  1150. result.push(data.value);
  1151. }
  1152. return result;
  1153. }
  1154. /**
  1155. * Converts `map` to its key-value pairs.
  1156. *
  1157. * @private
  1158. * @param {Object} map The map to convert.
  1159. * @returns {Array} Returns the key-value pairs.
  1160. */
  1161. function mapToArray(map) {
  1162. var index = -1,
  1163. result = Array(map.size);
  1164. map.forEach(function(value, key) {
  1165. result[++index] = [key, value];
  1166. });
  1167. return result;
  1168. }
  1169. /**
  1170. * Creates a unary function that invokes `func` with its argument transformed.
  1171. *
  1172. * @private
  1173. * @param {Function} func The function to wrap.
  1174. * @param {Function} transform The argument transform.
  1175. * @returns {Function} Returns the new function.
  1176. */
  1177. function overArg(func, transform) {
  1178. return function(arg) {
  1179. return func(transform(arg));
  1180. };
  1181. }
  1182. /**
  1183. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1184. * and returns an array of their indexes.
  1185. *
  1186. * @private
  1187. * @param {Array} array The array to modify.
  1188. * @param {*} placeholder The placeholder to replace.
  1189. * @returns {Array} Returns the new array of placeholder indexes.
  1190. */
  1191. function replaceHolders(array, placeholder) {
  1192. var index = -1,
  1193. length = array.length,
  1194. resIndex = 0,
  1195. result = [];
  1196. while (++index < length) {
  1197. var value = array[index];
  1198. if (value === placeholder || value === PLACEHOLDER) {
  1199. array[index] = PLACEHOLDER;
  1200. result[resIndex++] = index;
  1201. }
  1202. }
  1203. return result;
  1204. }
  1205. /**
  1206. * Converts `set` to an array of its values.
  1207. *
  1208. * @private
  1209. * @param {Object} set The set to convert.
  1210. * @returns {Array} Returns the values.
  1211. */
  1212. function setToArray(set) {
  1213. var index = -1,
  1214. result = Array(set.size);
  1215. set.forEach(function(value) {
  1216. result[++index] = value;
  1217. });
  1218. return result;
  1219. }
  1220. /**
  1221. * Converts `set` to its value-value pairs.
  1222. *
  1223. * @private
  1224. * @param {Object} set The set to convert.
  1225. * @returns {Array} Returns the value-value pairs.
  1226. */
  1227. function setToPairs(set) {
  1228. var index = -1,
  1229. result = Array(set.size);
  1230. set.forEach(function(value) {
  1231. result[++index] = [value, value];
  1232. });
  1233. return result;
  1234. }
  1235. /**
  1236. * A specialized version of `_.indexOf` which performs strict equality
  1237. * comparisons of values, i.e. `===`.
  1238. *
  1239. * @private
  1240. * @param {Array} array The array to inspect.
  1241. * @param {*} value The value to search for.
  1242. * @param {number} fromIndex The index to search from.
  1243. * @returns {number} Returns the index of the matched value, else `-1`.
  1244. */
  1245. function strictIndexOf(array, value, fromIndex) {
  1246. var index = fromIndex - 1,
  1247. length = array.length;
  1248. while (++index < length) {
  1249. if (array[index] === value) {
  1250. return index;
  1251. }
  1252. }
  1253. return -1;
  1254. }
  1255. /**
  1256. * A specialized version of `_.lastIndexOf` which performs strict equality
  1257. * comparisons of values, i.e. `===`.
  1258. *
  1259. * @private
  1260. * @param {Array} array The array to inspect.
  1261. * @param {*} value The value to search for.
  1262. * @param {number} fromIndex The index to search from.
  1263. * @returns {number} Returns the index of the matched value, else `-1`.
  1264. */
  1265. function strictLastIndexOf(array, value, fromIndex) {
  1266. var index = fromIndex + 1;
  1267. while (index--) {
  1268. if (array[index] === value) {
  1269. return index;
  1270. }
  1271. }
  1272. return index;
  1273. }
  1274. /**
  1275. * Gets the number of symbols in `string`.
  1276. *
  1277. * @private
  1278. * @param {string} string The string to inspect.
  1279. * @returns {number} Returns the string size.
  1280. */
  1281. function stringSize(string) {
  1282. return hasUnicode(string)
  1283. ? unicodeSize(string)
  1284. : asciiSize(string);
  1285. }
  1286. /**
  1287. * Converts `string` to an array.
  1288. *
  1289. * @private
  1290. * @param {string} string The string to convert.
  1291. * @returns {Array} Returns the converted array.
  1292. */
  1293. function stringToArray(string) {
  1294. return hasUnicode(string)
  1295. ? unicodeToArray(string)
  1296. : asciiToArray(string);
  1297. }
  1298. /**
  1299. * Used by `_.unescape` to convert HTML entities to characters.
  1300. *
  1301. * @private
  1302. * @param {string} chr The matched character to unescape.
  1303. * @returns {string} Returns the unescaped character.
  1304. */
  1305. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1306. /**
  1307. * Gets the size of a Unicode `string`.
  1308. *
  1309. * @private
  1310. * @param {string} string The string inspect.
  1311. * @returns {number} Returns the string size.
  1312. */
  1313. function unicodeSize(string) {
  1314. var result = reUnicode.lastIndex = 0;
  1315. while (reUnicode.test(string)) {
  1316. ++result;
  1317. }
  1318. return result;
  1319. }
  1320. /**
  1321. * Converts a Unicode `string` to an array.
  1322. *
  1323. * @private
  1324. * @param {string} string The string to convert.
  1325. * @returns {Array} Returns the converted array.
  1326. */
  1327. function unicodeToArray(string) {
  1328. return string.match(reUnicode) || [];
  1329. }
  1330. /**
  1331. * Splits a Unicode `string` into an array of its words.
  1332. *
  1333. * @private
  1334. * @param {string} The string to inspect.
  1335. * @returns {Array} Returns the words of `string`.
  1336. */
  1337. function unicodeWords(string) {
  1338. return string.match(reUnicodeWord) || [];
  1339. }
  1340. /*--------------------------------------------------------------------------*/
  1341. /**
  1342. * Create a new pristine `lodash` function using the `context` object.
  1343. *
  1344. * @static
  1345. * @memberOf _
  1346. * @since 1.1.0
  1347. * @category Util
  1348. * @param {Object} [context=root] The context object.
  1349. * @returns {Function} Returns a new `lodash` function.
  1350. * @example
  1351. *
  1352. * _.mixin({ 'foo': _.constant('foo') });
  1353. *
  1354. * var lodash = _.runInContext();
  1355. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1356. *
  1357. * _.isFunction(_.foo);
  1358. * // => true
  1359. * _.isFunction(_.bar);
  1360. * // => false
  1361. *
  1362. * lodash.isFunction(lodash.foo);
  1363. * // => false
  1364. * lodash.isFunction(lodash.bar);
  1365. * // => true
  1366. *
  1367. * // Create a suped-up `defer` in Node.js.
  1368. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1369. */
  1370. var runInContext = (function runInContext(context) {
  1371. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1372. /** Built-in constructor references. */
  1373. var Array = context.Array,
  1374. Date = context.Date,
  1375. Error = context.Error,
  1376. Function = context.Function,
  1377. Math = context.Math,
  1378. Object = context.Object,
  1379. RegExp = context.RegExp,
  1380. String = context.String,
  1381. TypeError = context.TypeError;
  1382. /** Used for built-in method references. */
  1383. var arrayProto = Array.prototype,
  1384. funcProto = Function.prototype,
  1385. objectProto = Object.prototype;
  1386. /** Used to detect overreaching core-js shims. */
  1387. var coreJsData = context['__core-js_shared__'];
  1388. /** Used to resolve the decompiled source of functions. */
  1389. var funcToString = funcProto.toString;
  1390. /** Used to check objects for own properties. */
  1391. var hasOwnProperty = objectProto.hasOwnProperty;
  1392. /** Used to generate unique IDs. */
  1393. var idCounter = 0;
  1394. /** Used to detect methods masquerading as native. */
  1395. var maskSrcKey = (function() {
  1396. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1397. return uid ? ('Symbol(src)_1.' + uid) : '';
  1398. }());
  1399. /**
  1400. * Used to resolve the
  1401. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1402. * of values.
  1403. */
  1404. var nativeObjectToString = objectProto.toString;
  1405. /** Used to infer the `Object` constructor. */
  1406. var objectCtorString = funcToString.call(Object);
  1407. /** Used to restore the original `_` reference in `_.noConflict`. */
  1408. var oldDash = root._;
  1409. /** Used to detect if a method is native. */
  1410. var reIsNative = RegExp('^' +
  1411. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1412. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1413. );
  1414. /** Built-in value references. */
  1415. var Buffer = moduleExports ? context.Buffer : undefined,
  1416. Symbol = context.Symbol,
  1417. Uint8Array = context.Uint8Array,
  1418. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1419. getPrototype = overArg(Object.getPrototypeOf, Object),
  1420. objectCreate = Object.create,
  1421. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1422. splice = arrayProto.splice,
  1423. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1424. symIterator = Symbol ? Symbol.iterator : undefined,
  1425. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1426. var defineProperty = (function() {
  1427. try {
  1428. var func = getNative(Object, 'defineProperty');
  1429. func({}, '', {});
  1430. return func;
  1431. } catch (e) {}
  1432. }());
  1433. /** Mocked built-ins. */
  1434. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1435. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1436. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1437. /* Built-in method references for those with the same name as other `lodash` methods. */
  1438. var nativeCeil = Math.ceil,
  1439. nativeFloor = Math.floor,
  1440. nativeGetSymbols = Object.getOwnPropertySymbols,
  1441. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1442. nativeIsFinite = context.isFinite,
  1443. nativeJoin = arrayProto.join,
  1444. nativeKeys = overArg(Object.keys, Object),
  1445. nativeMax = Math.max,
  1446. nativeMin = Math.min,
  1447. nativeNow = Date.now,
  1448. nativeParseInt = context.parseInt,
  1449. nativeRandom = Math.random,
  1450. nativeReverse = arrayProto.reverse;
  1451. /* Built-in method references that are verified to be native. */
  1452. var DataView = getNative(context, 'DataView'),
  1453. Map = getNative(context, 'Map'),
  1454. Promise = getNative(context, 'Promise'),
  1455. Set = getNative(context, 'Set'),
  1456. WeakMap = getNative(context, 'WeakMap'),
  1457. nativeCreate = getNative(Object, 'create');
  1458. /** Used to store function metadata. */
  1459. var metaMap = WeakMap && new WeakMap;
  1460. /** Used to lookup unminified function names. */
  1461. var realNames = {};
  1462. /** Used to detect maps, sets, and weakmaps. */
  1463. var dataViewCtorString = toSource(DataView),
  1464. mapCtorString = toSource(Map),
  1465. promiseCtorString = toSource(Promise),
  1466. setCtorString = toSource(Set),
  1467. weakMapCtorString = toSource(WeakMap);
  1468. /** Used to convert symbols to primitives and strings. */
  1469. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1470. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1471. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1472. /*------------------------------------------------------------------------*/
  1473. /**
  1474. * Creates a `lodash` object which wraps `value` to enable implicit method
  1475. * chain sequences. Methods that operate on and return arrays, collections,
  1476. * and functions can be chained together. Methods that retrieve a single value
  1477. * or may return a primitive value will automatically end the chain sequence
  1478. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1479. * with `_#value`.
  1480. *
  1481. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1482. * enabled using `_.chain`.
  1483. *
  1484. * The execution of chained methods is lazy, that is, it's deferred until
  1485. * `_#value` is implicitly or explicitly called.
  1486. *
  1487. * Lazy evaluation allows several methods to support shortcut fusion.
  1488. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1489. * the creation of intermediate arrays and can greatly reduce the number of
  1490. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1491. * fusion if the section is applied to an array and iteratees accept only
  1492. * one argument. The heuristic for whether a section qualifies for shortcut
  1493. * fusion is subject to change.
  1494. *
  1495. * Chaining is supported in custom builds as long as the `_#value` method is
  1496. * directly or indirectly included in the build.
  1497. *
  1498. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1499. *
  1500. * The wrapper `Array` methods are:
  1501. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1502. *
  1503. * The wrapper `String` methods are:
  1504. * `replace` and `split`
  1505. *
  1506. * The wrapper methods that support shortcut fusion are:
  1507. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1508. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1509. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1510. *
  1511. * The chainable wrapper methods are:
  1512. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1513. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1514. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1515. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1516. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1517. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1518. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1519. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1520. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1521. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1522. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1523. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1524. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1525. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1526. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1527. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1528. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1529. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1530. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1531. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1532. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1533. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1534. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1535. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1536. *
  1537. * The wrapper methods that are **not** chainable by default are:
  1538. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1539. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1540. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1541. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1542. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1543. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1544. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1545. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1546. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1547. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1548. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1549. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1550. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1551. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1552. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1553. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1554. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1555. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1556. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1557. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1558. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1559. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1560. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1561. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1562. * `upperFirst`, `value`, and `words`
  1563. *
  1564. * @name _
  1565. * @constructor
  1566. * @category Seq
  1567. * @param {*} value The value to wrap in a `lodash` instance.
  1568. * @returns {Object} Returns the new `lodash` wrapper instance.
  1569. * @example
  1570. *
  1571. * function square(n) {
  1572. * return n * n;
  1573. * }
  1574. *
  1575. * var wrapped = _([1, 2, 3]);
  1576. *
  1577. * // Returns an unwrapped value.
  1578. * wrapped.reduce(_.add);
  1579. * // => 6
  1580. *
  1581. * // Returns a wrapped value.
  1582. * var squares = wrapped.map(square);
  1583. *
  1584. * _.isArray(squares);
  1585. * // => false
  1586. *
  1587. * _.isArray(squares.value());
  1588. * // => true
  1589. */
  1590. function lodash(value) {
  1591. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1592. if (value instanceof LodashWrapper) {
  1593. return value;
  1594. }
  1595. if (hasOwnProperty.call(value, '__wrapped__')) {
  1596. return wrapperClone(value);
  1597. }
  1598. }
  1599. return new LodashWrapper(value);
  1600. }
  1601. /**
  1602. * The base implementation of `_.create` without support for assigning
  1603. * properties to the created object.
  1604. *
  1605. * @private
  1606. * @param {Object} proto The object to inherit from.
  1607. * @returns {Object} Returns the new object.
  1608. */
  1609. var baseCreate = (function() {
  1610. function object() {}
  1611. return function(proto) {
  1612. if (!isObject(proto)) {
  1613. return {};
  1614. }
  1615. if (objectCreate) {
  1616. return objectCreate(proto);
  1617. }
  1618. object.prototype = proto;
  1619. var result = new object;
  1620. object.prototype = undefined;
  1621. return result;
  1622. };
  1623. }());
  1624. /**
  1625. * The function whose prototype chain sequence wrappers inherit from.
  1626. *
  1627. * @private
  1628. */
  1629. function baseLodash() {
  1630. // No operation performed.
  1631. }
  1632. /**
  1633. * The base constructor for creating `lodash` wrapper objects.
  1634. *
  1635. * @private
  1636. * @param {*} value The value to wrap.
  1637. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1638. */
  1639. function LodashWrapper(value, chainAll) {
  1640. this.__wrapped__ = value;
  1641. this.__actions__ = [];
  1642. this.__chain__ = !!chainAll;
  1643. this.__index__ = 0;
  1644. this.__values__ = undefined;
  1645. }
  1646. /**
  1647. * By default, the template delimiters used by lodash are like those in
  1648. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1649. * following template settings to use alternative delimiters.
  1650. *
  1651. * @static
  1652. * @memberOf _
  1653. * @type {Object}
  1654. */
  1655. lodash.templateSettings = {
  1656. /**
  1657. * Used to detect `data` property values to be HTML-escaped.
  1658. *
  1659. * @memberOf _.templateSettings
  1660. * @type {RegExp}
  1661. */
  1662. 'escape': reEscape,
  1663. /**
  1664. * Used to detect code to be evaluated.
  1665. *
  1666. * @memberOf _.templateSettings
  1667. * @type {RegExp}
  1668. */
  1669. 'evaluate': reEvaluate,
  1670. /**
  1671. * Used to detect `data` property values to inject.
  1672. *
  1673. * @memberOf _.templateSettings
  1674. * @type {RegExp}
  1675. */
  1676. 'interpolate': reInterpolate,
  1677. /**
  1678. * Used to reference the data object in the template text.
  1679. *
  1680. * @memberOf _.templateSettings
  1681. * @type {string}
  1682. */
  1683. 'variable': '',
  1684. /**
  1685. * Used to import variables into the compiled template.
  1686. *
  1687. * @memberOf _.templateSettings
  1688. * @type {Object}
  1689. */
  1690. 'imports': {
  1691. /**
  1692. * A reference to the `lodash` function.
  1693. *
  1694. * @memberOf _.templateSettings.imports
  1695. * @type {Function}
  1696. */
  1697. '_': lodash
  1698. }
  1699. };
  1700. // Ensure wrappers are instances of `baseLodash`.
  1701. lodash.prototype = baseLodash.prototype;
  1702. lodash.prototype.constructor = lodash;
  1703. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1704. LodashWrapper.prototype.constructor = LodashWrapper;
  1705. /*------------------------------------------------------------------------*/
  1706. /**
  1707. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1708. *
  1709. * @private
  1710. * @constructor
  1711. * @param {*} value The value to wrap.
  1712. */
  1713. function LazyWrapper(value) {
  1714. this.__wrapped__ = value;
  1715. this.__actions__ = [];
  1716. this.__dir__ = 1;
  1717. this.__filtered__ = false;
  1718. this.__iteratees__ = [];
  1719. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1720. this.__views__ = [];
  1721. }
  1722. /**
  1723. * Creates a clone of the lazy wrapper object.
  1724. *
  1725. * @private
  1726. * @name clone
  1727. * @memberOf LazyWrapper
  1728. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1729. */
  1730. function lazyClone() {
  1731. var result = new LazyWrapper(this.__wrapped__);
  1732. result.__actions__ = copyArray(this.__actions__);
  1733. result.__dir__ = this.__dir__;
  1734. result.__filtered__ = this.__filtered__;
  1735. result.__iteratees__ = copyArray(this.__iteratees__);
  1736. result.__takeCount__ = this.__takeCount__;
  1737. result.__views__ = copyArray(this.__views__);
  1738. return result;
  1739. }
  1740. /**
  1741. * Reverses the direction of lazy iteration.
  1742. *
  1743. * @private
  1744. * @name reverse
  1745. * @memberOf LazyWrapper
  1746. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1747. */
  1748. function lazyReverse() {
  1749. if (this.__filtered__) {
  1750. var result = new LazyWrapper(this);
  1751. result.__dir__ = -1;
  1752. result.__filtered__ = true;
  1753. } else {
  1754. result = this.clone();
  1755. result.__dir__ *= -1;
  1756. }
  1757. return result;
  1758. }
  1759. /**
  1760. * Extracts the unwrapped value from its lazy wrapper.
  1761. *
  1762. * @private
  1763. * @name value
  1764. * @memberOf LazyWrapper
  1765. * @returns {*} Returns the unwrapped value.
  1766. */
  1767. function lazyValue() {
  1768. var array = this.__wrapped__.value(),
  1769. dir = this.__dir__,
  1770. isArr = isArray(array),
  1771. isRight = dir < 0,
  1772. arrLength = isArr ? array.length : 0,
  1773. view = getView(0, arrLength, this.__views__),
  1774. start = view.start,
  1775. end = view.end,
  1776. length = end - start,
  1777. index = isRight ? end : (start - 1),
  1778. iteratees = this.__iteratees__,
  1779. iterLength = iteratees.length,
  1780. resIndex = 0,
  1781. takeCount = nativeMin(length, this.__takeCount__);
  1782. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1783. return baseWrapperValue(array, this.__actions__);
  1784. }
  1785. var result = [];
  1786. outer:
  1787. while (length-- && resIndex < takeCount) {
  1788. index += dir;
  1789. var iterIndex = -1,
  1790. value = array[index];
  1791. while (++iterIndex < iterLength) {
  1792. var data = iteratees[iterIndex],
  1793. iteratee = data.iteratee,
  1794. type = data.type,
  1795. computed = iteratee(value);
  1796. if (type == LAZY_MAP_FLAG) {
  1797. value = computed;
  1798. } else if (!computed) {
  1799. if (type == LAZY_FILTER_FLAG) {
  1800. continue outer;
  1801. } else {
  1802. break outer;
  1803. }
  1804. }
  1805. }
  1806. result[resIndex++] = value;
  1807. }
  1808. return result;
  1809. }
  1810. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1811. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1812. LazyWrapper.prototype.constructor = LazyWrapper;
  1813. /*------------------------------------------------------------------------*/
  1814. /**
  1815. * Creates a hash object.
  1816. *
  1817. * @private
  1818. * @constructor
  1819. * @param {Array} [entries] The key-value pairs to cache.
  1820. */
  1821. function Hash(entries) {
  1822. var index = -1,
  1823. length = entries == null ? 0 : entries.length;
  1824. this.clear();
  1825. while (++index < length) {
  1826. var entry = entries[index];
  1827. this.set(entry[0], entry[1]);
  1828. }
  1829. }
  1830. /**
  1831. * Removes all key-value entries from the hash.
  1832. *
  1833. * @private
  1834. * @name clear
  1835. * @memberOf Hash
  1836. */
  1837. function hashClear() {
  1838. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1839. this.size = 0;
  1840. }
  1841. /**
  1842. * Removes `key` and its value from the hash.
  1843. *
  1844. * @private
  1845. * @name delete
  1846. * @memberOf Hash
  1847. * @param {Object} hash The hash to modify.
  1848. * @param {string} key The key of the value to remove.
  1849. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1850. */
  1851. function hashDelete(key) {
  1852. var result = this.has(key) && delete this.__data__[key];
  1853. this.size -= result ? 1 : 0;
  1854. return result;
  1855. }
  1856. /**
  1857. * Gets the hash value for `key`.
  1858. *
  1859. * @private
  1860. * @name get
  1861. * @memberOf Hash
  1862. * @param {string} key The key of the value to get.
  1863. * @returns {*} Returns the entry value.
  1864. */
  1865. function hashGet(key) {
  1866. var data = this.__data__;
  1867. if (nativeCreate) {
  1868. var result = data[key];
  1869. return result === HASH_UNDEFINED ? undefined : result;
  1870. }
  1871. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1872. }
  1873. /**
  1874. * Checks if a hash value for `key` exists.
  1875. *
  1876. * @private
  1877. * @name has
  1878. * @memberOf Hash
  1879. * @param {string} key The key of the entry to check.
  1880. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1881. */
  1882. function hashHas(key) {
  1883. var data = this.__data__;
  1884. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1885. }
  1886. /**
  1887. * Sets the hash `key` to `value`.
  1888. *
  1889. * @private
  1890. * @name set
  1891. * @memberOf Hash
  1892. * @param {string} key The key of the value to set.
  1893. * @param {*} value The value to set.
  1894. * @returns {Object} Returns the hash instance.
  1895. */
  1896. function hashSet(key, value) {
  1897. var data = this.__data__;
  1898. this.size += this.has(key) ? 0 : 1;
  1899. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1900. return this;
  1901. }
  1902. // Add methods to `Hash`.
  1903. Hash.prototype.clear = hashClear;
  1904. Hash.prototype['delete'] = hashDelete;
  1905. Hash.prototype.get = hashGet;
  1906. Hash.prototype.has = hashHas;
  1907. Hash.prototype.set = hashSet;
  1908. /*------------------------------------------------------------------------*/
  1909. /**
  1910. * Creates an list cache object.
  1911. *
  1912. * @private
  1913. * @constructor
  1914. * @param {Array} [entries] The key-value pairs to cache.
  1915. */
  1916. function ListCache(entries) {
  1917. var index = -1,
  1918. length = entries == null ? 0 : entries.length;
  1919. this.clear();
  1920. while (++index < length) {
  1921. var entry = entries[index];
  1922. this.set(entry[0], entry[1]);
  1923. }
  1924. }
  1925. /**
  1926. * Removes all key-value entries from the list cache.
  1927. *
  1928. * @private
  1929. * @name clear
  1930. * @memberOf ListCache
  1931. */
  1932. function listCacheClear() {
  1933. this.__data__ = [];
  1934. this.size = 0;
  1935. }
  1936. /**
  1937. * Removes `key` and its value from the list cache.
  1938. *
  1939. * @private
  1940. * @name delete
  1941. * @memberOf ListCache
  1942. * @param {string} key The key of the value to remove.
  1943. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1944. */
  1945. function listCacheDelete(key) {
  1946. var data = this.__data__,
  1947. index = assocIndexOf(data, key);
  1948. if (index < 0) {
  1949. return false;
  1950. }
  1951. var lastIndex = data.length - 1;
  1952. if (index == lastIndex) {
  1953. data.pop();
  1954. } else {
  1955. splice.call(data, index, 1);
  1956. }
  1957. --this.size;
  1958. return true;
  1959. }
  1960. /**
  1961. * Gets the list cache value for `key`.
  1962. *
  1963. * @private
  1964. * @name get
  1965. * @memberOf ListCache
  1966. * @param {string} key The key of the value to get.
  1967. * @returns {*} Returns the entry value.
  1968. */
  1969. function listCacheGet(key) {
  1970. var data = this.__data__,
  1971. index = assocIndexOf(data, key);
  1972. return index < 0 ? undefined : data[index][1];
  1973. }
  1974. /**
  1975. * Checks if a list cache value for `key` exists.
  1976. *
  1977. * @private
  1978. * @name has
  1979. * @memberOf ListCache
  1980. * @param {string} key The key of the entry to check.
  1981. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1982. */
  1983. function listCacheHas(key) {
  1984. return assocIndexOf(this.__data__, key) > -1;
  1985. }
  1986. /**
  1987. * Sets the list cache `key` to `value`.
  1988. *
  1989. * @private
  1990. * @name set
  1991. * @memberOf ListCache
  1992. * @param {string} key The key of the value to set.
  1993. * @param {*} value The value to set.
  1994. * @returns {Object} Returns the list cache instance.
  1995. */
  1996. function listCacheSet(key, value) {
  1997. var data = this.__data__,
  1998. index = assocIndexOf(data, key);
  1999. if (index < 0) {
  2000. ++this.size;
  2001. data.push([key, value]);
  2002. } else {
  2003. data[index][1] = value;
  2004. }
  2005. return this;
  2006. }
  2007. // Add methods to `ListCache`.
  2008. ListCache.prototype.clear = listCacheClear;
  2009. ListCache.prototype['delete'] = listCacheDelete;
  2010. ListCache.prototype.get = listCacheGet;
  2011. ListCache.prototype.has = listCacheHas;
  2012. ListCache.prototype.set = listCacheSet;
  2013. /*------------------------------------------------------------------------*/
  2014. /**
  2015. * Creates a map cache object to store key-value pairs.
  2016. *
  2017. * @private
  2018. * @constructor
  2019. * @param {Array} [entries] The key-value pairs to cache.
  2020. */
  2021. function MapCache(entries) {
  2022. var index = -1,
  2023. length = entries == null ? 0 : entries.length;
  2024. this.clear();
  2025. while (++index < length) {
  2026. var entry = entries[index];
  2027. this.set(entry[0], entry[1]);
  2028. }
  2029. }
  2030. /**
  2031. * Removes all key-value entries from the map.
  2032. *
  2033. * @private
  2034. * @name clear
  2035. * @memberOf MapCache
  2036. */
  2037. function mapCacheClear() {
  2038. this.size = 0;
  2039. this.__data__ = {
  2040. 'hash': new Hash,
  2041. 'map': new (Map || ListCache),
  2042. 'string': new Hash
  2043. };
  2044. }
  2045. /**
  2046. * Removes `key` and its value from the map.
  2047. *
  2048. * @private
  2049. * @name delete
  2050. * @memberOf MapCache
  2051. * @param {string} key The key of the value to remove.
  2052. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2053. */
  2054. function mapCacheDelete(key) {
  2055. var result = getMapData(this, key)['delete'](key);
  2056. this.size -= result ? 1 : 0;
  2057. return result;
  2058. }
  2059. /**
  2060. * Gets the map value for `key`.
  2061. *
  2062. * @private
  2063. * @name get
  2064. * @memberOf MapCache
  2065. * @param {string} key The key of the value to get.
  2066. * @returns {*} Returns the entry value.
  2067. */
  2068. function mapCacheGet(key) {
  2069. return getMapData(this, key).get(key);
  2070. }
  2071. /**
  2072. * Checks if a map value for `key` exists.
  2073. *
  2074. * @private
  2075. * @name has
  2076. * @memberOf MapCache
  2077. * @param {string} key The key of the entry to check.
  2078. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2079. */
  2080. function mapCacheHas(key) {
  2081. return getMapData(this, key).has(key);
  2082. }
  2083. /**
  2084. * Sets the map `key` to `value`.
  2085. *
  2086. * @private
  2087. * @name set
  2088. * @memberOf MapCache
  2089. * @param {string} key The key of the value to set.
  2090. * @param {*} value The value to set.
  2091. * @returns {Object} Returns the map cache instance.
  2092. */
  2093. function mapCacheSet(key, value) {
  2094. var data = getMapData(this, key),
  2095. size = data.size;
  2096. data.set(key, value);
  2097. this.size += data.size == size ? 0 : 1;
  2098. return this;
  2099. }
  2100. // Add methods to `MapCache`.
  2101. MapCache.prototype.clear = mapCacheClear;
  2102. MapCache.prototype['delete'] = mapCacheDelete;
  2103. MapCache.prototype.get = mapCacheGet;
  2104. MapCache.prototype.has = mapCacheHas;
  2105. MapCache.prototype.set = mapCacheSet;
  2106. /*------------------------------------------------------------------------*/
  2107. /**
  2108. *
  2109. * Creates an array cache object to store unique values.
  2110. *
  2111. * @private
  2112. * @constructor
  2113. * @param {Array} [values] The values to cache.
  2114. */
  2115. function SetCache(values) {
  2116. var index = -1,
  2117. length = values == null ? 0 : values.length;
  2118. this.__data__ = new MapCache;
  2119. while (++index < length) {
  2120. this.add(values[index]);
  2121. }
  2122. }
  2123. /**
  2124. * Adds `value` to the array cache.
  2125. *
  2126. * @private
  2127. * @name add
  2128. * @memberOf SetCache
  2129. * @alias push
  2130. * @param {*} value The value to cache.
  2131. * @returns {Object} Returns the cache instance.
  2132. */
  2133. function setCacheAdd(value) {
  2134. this.__data__.set(value, HASH_UNDEFINED);
  2135. return this;
  2136. }
  2137. /**
  2138. * Checks if `value` is in the array cache.
  2139. *
  2140. * @private
  2141. * @name has
  2142. * @memberOf SetCache
  2143. * @param {*} value The value to search for.
  2144. * @returns {number} Returns `true` if `value` is found, else `false`.
  2145. */
  2146. function setCacheHas(value) {
  2147. return this.__data__.has(value);
  2148. }
  2149. // Add methods to `SetCache`.
  2150. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2151. SetCache.prototype.has = setCacheHas;
  2152. /*------------------------------------------------------------------------*/
  2153. /**
  2154. * Creates a stack cache object to store key-value pairs.
  2155. *
  2156. * @private
  2157. * @constructor
  2158. * @param {Array} [entries] The key-value pairs to cache.
  2159. */
  2160. function Stack(entries) {
  2161. var data = this.__data__ = new ListCache(entries);
  2162. this.size = data.size;
  2163. }
  2164. /**
  2165. * Removes all key-value entries from the stack.
  2166. *
  2167. * @private
  2168. * @name clear
  2169. * @memberOf Stack
  2170. */
  2171. function stackClear() {
  2172. this.__data__ = new ListCache;
  2173. this.size = 0;
  2174. }
  2175. /**
  2176. * Removes `key` and its value from the stack.
  2177. *
  2178. * @private
  2179. * @name delete
  2180. * @memberOf Stack
  2181. * @param {string} key The key of the value to remove.
  2182. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2183. */
  2184. function stackDelete(key) {
  2185. var data = this.__data__,
  2186. result = data['delete'](key);
  2187. this.size = data.size;
  2188. return result;
  2189. }
  2190. /**
  2191. * Gets the stack value for `key`.
  2192. *
  2193. * @private
  2194. * @name get
  2195. * @memberOf Stack
  2196. * @param {string} key The key of the value to get.
  2197. * @returns {*} Returns the entry value.
  2198. */
  2199. function stackGet(key) {
  2200. return this.__data__.get(key);
  2201. }
  2202. /**
  2203. * Checks if a stack value for `key` exists.
  2204. *
  2205. * @private
  2206. * @name has
  2207. * @memberOf Stack
  2208. * @param {string} key The key of the entry to check.
  2209. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2210. */
  2211. function stackHas(key) {
  2212. return this.__data__.has(key);
  2213. }
  2214. /**
  2215. * Sets the stack `key` to `value`.
  2216. *
  2217. * @private
  2218. * @name set
  2219. * @memberOf Stack
  2220. * @param {string} key The key of the value to set.
  2221. * @param {*} value The value to set.
  2222. * @returns {Object} Returns the stack cache instance.
  2223. */
  2224. function stackSet(key, value) {
  2225. var data = this.__data__;
  2226. if (data instanceof ListCache) {
  2227. var pairs = data.__data__;
  2228. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2229. pairs.push([key, value]);
  2230. this.size = ++data.size;
  2231. return this;
  2232. }
  2233. data = this.__data__ = new MapCache(pairs);
  2234. }
  2235. data.set(key, value);
  2236. this.size = data.size;
  2237. return this;
  2238. }
  2239. // Add methods to `Stack`.
  2240. Stack.prototype.clear = stackClear;
  2241. Stack.prototype['delete'] = stackDelete;
  2242. Stack.prototype.get = stackGet;
  2243. Stack.prototype.has = stackHas;
  2244. Stack.prototype.set = stackSet;
  2245. /*------------------------------------------------------------------------*/
  2246. /**
  2247. * Creates an array of the enumerable property names of the array-like `value`.
  2248. *
  2249. * @private
  2250. * @param {*} value The value to query.
  2251. * @param {boolean} inherited Specify returning inherited property names.
  2252. * @returns {Array} Returns the array of property names.
  2253. */
  2254. function arrayLikeKeys(value, inherited) {
  2255. var isArr = isArray(value),
  2256. isArg = !isArr && isArguments(value),
  2257. isBuff = !isArr && !isArg && isBuffer(value),
  2258. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2259. skipIndexes = isArr || isArg || isBuff || isType,
  2260. result = skipIndexes ? baseTimes(value.length, String) : [],
  2261. length = result.length;
  2262. for (var key in value) {
  2263. if ((inherited || hasOwnProperty.call(value, key)) &&
  2264. !(skipIndexes && (
  2265. // Safari 9 has enumerable `arguments.length` in strict mode.
  2266. key == 'length' ||
  2267. // Node.js 0.10 has enumerable non-index properties on buffers.
  2268. (isBuff && (key == 'offset' || key == 'parent')) ||
  2269. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2270. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2271. // Skip index properties.
  2272. isIndex(key, length)
  2273. ))) {
  2274. result.push(key);
  2275. }
  2276. }
  2277. return result;
  2278. }
  2279. /**
  2280. * A specialized version of `_.sample` for arrays.
  2281. *
  2282. * @private
  2283. * @param {Array} array The array to sample.
  2284. * @returns {*} Returns the random element.
  2285. */
  2286. function arraySample(array) {
  2287. var length = array.length;
  2288. return length ? array[baseRandom(0, length - 1)] : undefined;
  2289. }
  2290. /**
  2291. * A specialized version of `_.sampleSize` for arrays.
  2292. *
  2293. * @private
  2294. * @param {Array} array The array to sample.
  2295. * @param {number} n The number of elements to sample.
  2296. * @returns {Array} Returns the random elements.
  2297. */
  2298. function arraySampleSize(array, n) {
  2299. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2300. }
  2301. /**
  2302. * A specialized version of `_.shuffle` for arrays.
  2303. *
  2304. * @private
  2305. * @param {Array} array The array to shuffle.
  2306. * @returns {Array} Returns the new shuffled array.
  2307. */
  2308. function arrayShuffle(array) {
  2309. return shuffleSelf(copyArray(array));
  2310. }
  2311. /**
  2312. * This function is like `assignValue` except that it doesn't assign
  2313. * `undefined` values.
  2314. *
  2315. * @private
  2316. * @param {Object} object The object to modify.
  2317. * @param {string} key The key of the property to assign.
  2318. * @param {*} value The value to assign.
  2319. */
  2320. function assignMergeValue(object, key, value) {
  2321. if ((value !== undefined && !eq(object[key], value)) ||
  2322. (value === undefined && !(key in object))) {
  2323. baseAssignValue(object, key, value);
  2324. }
  2325. }
  2326. /**
  2327. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2328. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2329. * for equality comparisons.
  2330. *
  2331. * @private
  2332. * @param {Object} object The object to modify.
  2333. * @param {string} key The key of the property to assign.
  2334. * @param {*} value The value to assign.
  2335. */
  2336. function assignValue(object, key, value) {
  2337. var objValue = object[key];
  2338. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2339. (value === undefined && !(key in object))) {
  2340. baseAssignValue(object, key, value);
  2341. }
  2342. }
  2343. /**
  2344. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2345. *
  2346. * @private
  2347. * @param {Array} array The array to inspect.
  2348. * @param {*} key The key to search for.
  2349. * @returns {number} Returns the index of the matched value, else `-1`.
  2350. */
  2351. function assocIndexOf(array, key) {
  2352. var length = array.length;
  2353. while (length--) {
  2354. if (eq(array[length][0], key)) {
  2355. return length;
  2356. }
  2357. }
  2358. return -1;
  2359. }
  2360. /**
  2361. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2362. * by `iteratee` and values set by `setter`.
  2363. *
  2364. * @private
  2365. * @param {Array|Object} collection The collection to iterate over.
  2366. * @param {Function} setter The function to set `accumulator` values.
  2367. * @param {Function} iteratee The iteratee to transform keys.
  2368. * @param {Object} accumulator The initial aggregated object.
  2369. * @returns {Function} Returns `accumulator`.
  2370. */
  2371. function baseAggregator(collection, setter, iteratee, accumulator) {
  2372. baseEach(collection, function(value, key, collection) {
  2373. setter(accumulator, value, iteratee(value), collection);
  2374. });
  2375. return accumulator;
  2376. }
  2377. /**
  2378. * The base implementation of `_.assign` without support for multiple sources
  2379. * or `customizer` functions.
  2380. *
  2381. * @private
  2382. * @param {Object} object The destination object.
  2383. * @param {Object} source The source object.
  2384. * @returns {Object} Returns `object`.
  2385. */
  2386. function baseAssign(object, source) {
  2387. return object && copyObject(source, keys(source), object);
  2388. }
  2389. /**
  2390. * The base implementation of `_.assignIn` without support for multiple sources
  2391. * or `customizer` functions.
  2392. *
  2393. * @private
  2394. * @param {Object} object The destination object.
  2395. * @param {Object} source The source object.
  2396. * @returns {Object} Returns `object`.
  2397. */
  2398. function baseAssignIn(object, source) {
  2399. return object && copyObject(source, keysIn(source), object);
  2400. }
  2401. /**
  2402. * The base implementation of `assignValue` and `assignMergeValue` without
  2403. * value checks.
  2404. *
  2405. * @private
  2406. * @param {Object} object The object to modify.
  2407. * @param {string} key The key of the property to assign.
  2408. * @param {*} value The value to assign.
  2409. */
  2410. function baseAssignValue(object, key, value) {
  2411. if (key == '__proto__' && defineProperty) {
  2412. defineProperty(object, key, {
  2413. 'configurable': true,
  2414. 'enumerable': true,
  2415. 'value': value,
  2416. 'writable': true
  2417. });
  2418. } else {
  2419. object[key] = value;
  2420. }
  2421. }
  2422. /**
  2423. * The base implementation of `_.at` without support for individual paths.
  2424. *
  2425. * @private
  2426. * @param {Object} object The object to iterate over.
  2427. * @param {string[]} paths The property paths to pick.
  2428. * @returns {Array} Returns the picked elements.
  2429. */
  2430. function baseAt(object, paths) {
  2431. var index = -1,
  2432. length = paths.length,
  2433. result = Array(length),
  2434. skip = object == null;
  2435. while (++index < length) {
  2436. result[index] = skip ? undefined : get(object, paths[index]);
  2437. }
  2438. return result;
  2439. }
  2440. /**
  2441. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2442. *
  2443. * @private
  2444. * @param {number} number The number to clamp.
  2445. * @param {number} [lower] The lower bound.
  2446. * @param {number} upper The upper bound.
  2447. * @returns {number} Returns the clamped number.
  2448. */
  2449. function baseClamp(number, lower, upper) {
  2450. if (number === number) {
  2451. if (upper !== undefined) {
  2452. number = number <= upper ? number : upper;
  2453. }
  2454. if (lower !== undefined) {
  2455. number = number >= lower ? number : lower;
  2456. }
  2457. }
  2458. return number;
  2459. }
  2460. /**
  2461. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2462. * traversed objects.
  2463. *
  2464. * @private
  2465. * @param {*} value The value to clone.
  2466. * @param {boolean} bitmask The bitmask flags.
  2467. * 1 - Deep clone
  2468. * 2 - Flatten inherited properties
  2469. * 4 - Clone symbols
  2470. * @param {Function} [customizer] The function to customize cloning.
  2471. * @param {string} [key] The key of `value`.
  2472. * @param {Object} [object] The parent object of `value`.
  2473. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2474. * @returns {*} Returns the cloned value.
  2475. */
  2476. function baseClone(value, bitmask, customizer, key, object, stack) {
  2477. var result,
  2478. isDeep = bitmask & CLONE_DEEP_FLAG,
  2479. isFlat = bitmask & CLONE_FLAT_FLAG,
  2480. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2481. if (customizer) {
  2482. result = object ? customizer(value, key, object, stack) : customizer(value);
  2483. }
  2484. if (result !== undefined) {
  2485. return result;
  2486. }
  2487. if (!isObject(value)) {
  2488. return value;
  2489. }
  2490. var isArr = isArray(value);
  2491. if (isArr) {
  2492. result = initCloneArray(value);
  2493. if (!isDeep) {
  2494. return copyArray(value, result);
  2495. }
  2496. } else {
  2497. var tag = getTag(value),
  2498. isFunc = tag == funcTag || tag == genTag;
  2499. if (isBuffer(value)) {
  2500. return cloneBuffer(value, isDeep);
  2501. }
  2502. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2503. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2504. if (!isDeep) {
  2505. return isFlat
  2506. ? copySymbolsIn(value, baseAssignIn(result, value))
  2507. : copySymbols(value, baseAssign(result, value));
  2508. }
  2509. } else {
  2510. if (!cloneableTags[tag]) {
  2511. return object ? value : {};
  2512. }
  2513. result = initCloneByTag(value, tag, baseClone, isDeep);
  2514. }
  2515. }
  2516. // Check for circular references and return its corresponding clone.
  2517. stack || (stack = new Stack);
  2518. var stacked = stack.get(value);
  2519. if (stacked) {
  2520. return stacked;
  2521. }
  2522. stack.set(value, result);
  2523. var keysFunc = isFull
  2524. ? (isFlat ? getAllKeysIn : getAllKeys)
  2525. : (isFlat ? keysIn : keys);
  2526. var props = isArr ? undefined : keysFunc(value);
  2527. arrayEach(props || value, function(subValue, key) {
  2528. if (props) {
  2529. key = subValue;
  2530. subValue = value[key];
  2531. }
  2532. // Recursively populate clone (susceptible to call stack limits).
  2533. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2534. });
  2535. return result;
  2536. }
  2537. /**
  2538. * The base implementation of `_.conforms` which doesn't clone `source`.
  2539. *
  2540. * @private
  2541. * @param {Object} source The object of property predicates to conform to.
  2542. * @returns {Function} Returns the new spec function.
  2543. */
  2544. function baseConforms(source) {
  2545. var props = keys(source);
  2546. return function(object) {
  2547. return baseConformsTo(object, source, props);
  2548. };
  2549. }
  2550. /**
  2551. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2552. *
  2553. * @private
  2554. * @param {Object} object The object to inspect.
  2555. * @param {Object} source The object of property predicates to conform to.
  2556. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2557. */
  2558. function baseConformsTo(object, source, props) {
  2559. var length = props.length;
  2560. if (object == null) {
  2561. return !length;
  2562. }
  2563. object = Object(object);
  2564. while (length--) {
  2565. var key = props[length],
  2566. predicate = source[key],
  2567. value = object[key];
  2568. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2569. return false;
  2570. }
  2571. }
  2572. return true;
  2573. }
  2574. /**
  2575. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2576. * to provide to `func`.
  2577. *
  2578. * @private
  2579. * @param {Function} func The function to delay.
  2580. * @param {number} wait The number of milliseconds to delay invocation.
  2581. * @param {Array} args The arguments to provide to `func`.
  2582. * @returns {number|Object} Returns the timer id or timeout object.
  2583. */
  2584. function baseDelay(func, wait, args) {
  2585. if (typeof func != 'function') {
  2586. throw new TypeError(FUNC_ERROR_TEXT);
  2587. }
  2588. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2589. }
  2590. /**
  2591. * The base implementation of methods like `_.difference` without support
  2592. * for excluding multiple arrays or iteratee shorthands.
  2593. *
  2594. * @private
  2595. * @param {Array} array The array to inspect.
  2596. * @param {Array} values The values to exclude.
  2597. * @param {Function} [iteratee] The iteratee invoked per element.
  2598. * @param {Function} [comparator] The comparator invoked per element.
  2599. * @returns {Array} Returns the new array of filtered values.
  2600. */
  2601. function baseDifference(array, values, iteratee, comparator) {
  2602. var index = -1,
  2603. includes = arrayIncludes,
  2604. isCommon = true,
  2605. length = array.length,
  2606. result = [],
  2607. valuesLength = values.length;
  2608. if (!length) {
  2609. return result;
  2610. }
  2611. if (iteratee) {
  2612. values = arrayMap(values, baseUnary(iteratee));
  2613. }
  2614. if (comparator) {
  2615. includes = arrayIncludesWith;
  2616. isCommon = false;
  2617. }
  2618. else if (values.length >= LARGE_ARRAY_SIZE) {
  2619. includes = cacheHas;
  2620. isCommon = false;
  2621. values = new SetCache(values);
  2622. }
  2623. outer:
  2624. while (++index < length) {
  2625. var value = array[index],
  2626. computed = iteratee == null ? value : iteratee(value);
  2627. value = (comparator || value !== 0) ? value : 0;
  2628. if (isCommon && computed === computed) {
  2629. var valuesIndex = valuesLength;
  2630. while (valuesIndex--) {
  2631. if (values[valuesIndex] === computed) {
  2632. continue outer;
  2633. }
  2634. }
  2635. result.push(value);
  2636. }
  2637. else if (!includes(values, computed, comparator)) {
  2638. result.push(value);
  2639. }
  2640. }
  2641. return result;
  2642. }
  2643. /**
  2644. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2645. *
  2646. * @private
  2647. * @param {Array|Object} collection The collection to iterate over.
  2648. * @param {Function} iteratee The function invoked per iteration.
  2649. * @returns {Array|Object} Returns `collection`.
  2650. */
  2651. var baseEach = createBaseEach(baseForOwn);
  2652. /**
  2653. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2654. *
  2655. * @private
  2656. * @param {Array|Object} collection The collection to iterate over.
  2657. * @param {Function} iteratee The function invoked per iteration.
  2658. * @returns {Array|Object} Returns `collection`.
  2659. */
  2660. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2661. /**
  2662. * The base implementation of `_.every` without support for iteratee shorthands.
  2663. *
  2664. * @private
  2665. * @param {Array|Object} collection The collection to iterate over.
  2666. * @param {Function} predicate The function invoked per iteration.
  2667. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2668. * else `false`
  2669. */
  2670. function baseEvery(collection, predicate) {
  2671. var result = true;
  2672. baseEach(collection, function(value, index, collection) {
  2673. result = !!predicate(value, index, collection);
  2674. return result;
  2675. });
  2676. return result;
  2677. }
  2678. /**
  2679. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2680. * `comparator` to determine the extremum value.
  2681. *
  2682. * @private
  2683. * @param {Array} array The array to iterate over.
  2684. * @param {Function} iteratee The iteratee invoked per iteration.
  2685. * @param {Function} comparator The comparator used to compare values.
  2686. * @returns {*} Returns the extremum value.
  2687. */
  2688. function baseExtremum(array, iteratee, comparator) {
  2689. var index = -1,
  2690. length = array.length;
  2691. while (++index < length) {
  2692. var value = array[index],
  2693. current = iteratee(value);
  2694. if (current != null && (computed === undefined
  2695. ? (current === current && !isSymbol(current))
  2696. : comparator(current, computed)
  2697. )) {
  2698. var computed = current,
  2699. result = value;
  2700. }
  2701. }
  2702. return result;
  2703. }
  2704. /**
  2705. * The base implementation of `_.fill` without an iteratee call guard.
  2706. *
  2707. * @private
  2708. * @param {Array} array The array to fill.
  2709. * @param {*} value The value to fill `array` with.
  2710. * @param {number} [start=0] The start position.
  2711. * @param {number} [end=array.length] The end position.
  2712. * @returns {Array} Returns `array`.
  2713. */
  2714. function baseFill(array, value, start, end) {
  2715. var length = array.length;
  2716. start = toInteger(start);
  2717. if (start < 0) {
  2718. start = -start > length ? 0 : (length + start);
  2719. }
  2720. end = (end === undefined || end > length) ? length : toInteger(end);
  2721. if (end < 0) {
  2722. end += length;
  2723. }
  2724. end = start > end ? 0 : toLength(end);
  2725. while (start < end) {
  2726. array[start++] = value;
  2727. }
  2728. return array;
  2729. }
  2730. /**
  2731. * The base implementation of `_.filter` without support for iteratee shorthands.
  2732. *
  2733. * @private
  2734. * @param {Array|Object} collection The collection to iterate over.
  2735. * @param {Function} predicate The function invoked per iteration.
  2736. * @returns {Array} Returns the new filtered array.
  2737. */
  2738. function baseFilter(collection, predicate) {
  2739. var result = [];
  2740. baseEach(collection, function(value, index, collection) {
  2741. if (predicate(value, index, collection)) {
  2742. result.push(value);
  2743. }
  2744. });
  2745. return result;
  2746. }
  2747. /**
  2748. * The base implementation of `_.flatten` with support for restricting flattening.
  2749. *
  2750. * @private
  2751. * @param {Array} array The array to flatten.
  2752. * @param {number} depth The maximum recursion depth.
  2753. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2754. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2755. * @param {Array} [result=[]] The initial result value.
  2756. * @returns {Array} Returns the new flattened array.
  2757. */
  2758. function baseFlatten(array, depth, predicate, isStrict, result) {
  2759. var index = -1,
  2760. length = array.length;
  2761. predicate || (predicate = isFlattenable);
  2762. result || (result = []);
  2763. while (++index < length) {
  2764. var value = array[index];
  2765. if (depth > 0 && predicate(value)) {
  2766. if (depth > 1) {
  2767. // Recursively flatten arrays (susceptible to call stack limits).
  2768. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2769. } else {
  2770. arrayPush(result, value);
  2771. }
  2772. } else if (!isStrict) {
  2773. result[result.length] = value;
  2774. }
  2775. }
  2776. return result;
  2777. }
  2778. /**
  2779. * The base implementation of `baseForOwn` which iterates over `object`
  2780. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2781. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2782. *
  2783. * @private
  2784. * @param {Object} object The object to iterate over.
  2785. * @param {Function} iteratee The function invoked per iteration.
  2786. * @param {Function} keysFunc The function to get the keys of `object`.
  2787. * @returns {Object} Returns `object`.
  2788. */
  2789. var baseFor = createBaseFor();
  2790. /**
  2791. * This function is like `baseFor` except that it iterates over properties
  2792. * in the opposite order.
  2793. *
  2794. * @private
  2795. * @param {Object} object The object to iterate over.
  2796. * @param {Function} iteratee The function invoked per iteration.
  2797. * @param {Function} keysFunc The function to get the keys of `object`.
  2798. * @returns {Object} Returns `object`.
  2799. */
  2800. var baseForRight = createBaseFor(true);
  2801. /**
  2802. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2803. *
  2804. * @private
  2805. * @param {Object} object The object to iterate over.
  2806. * @param {Function} iteratee The function invoked per iteration.
  2807. * @returns {Object} Returns `object`.
  2808. */
  2809. function baseForOwn(object, iteratee) {
  2810. return object && baseFor(object, iteratee, keys);
  2811. }
  2812. /**
  2813. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2814. *
  2815. * @private
  2816. * @param {Object} object The object to iterate over.
  2817. * @param {Function} iteratee The function invoked per iteration.
  2818. * @returns {Object} Returns `object`.
  2819. */
  2820. function baseForOwnRight(object, iteratee) {
  2821. return object && baseForRight(object, iteratee, keys);
  2822. }
  2823. /**
  2824. * The base implementation of `_.functions` which creates an array of
  2825. * `object` function property names filtered from `props`.
  2826. *
  2827. * @private
  2828. * @param {Object} object The object to inspect.
  2829. * @param {Array} props The property names to filter.
  2830. * @returns {Array} Returns the function names.
  2831. */
  2832. function baseFunctions(object, props) {
  2833. return arrayFilter(props, function(key) {
  2834. return isFunction(object[key]);
  2835. });
  2836. }
  2837. /**
  2838. * The base implementation of `_.get` without support for default values.
  2839. *
  2840. * @private
  2841. * @param {Object} object The object to query.
  2842. * @param {Array|string} path The path of the property to get.
  2843. * @returns {*} Returns the resolved value.
  2844. */
  2845. function baseGet(object, path) {
  2846. path = castPath(path, object);
  2847. var index = 0,
  2848. length = path.length;
  2849. while (object != null && index < length) {
  2850. object = object[toKey(path[index++])];
  2851. }
  2852. return (index && index == length) ? object : undefined;
  2853. }
  2854. /**
  2855. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2856. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2857. * symbols of `object`.
  2858. *
  2859. * @private
  2860. * @param {Object} object The object to query.
  2861. * @param {Function} keysFunc The function to get the keys of `object`.
  2862. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2863. * @returns {Array} Returns the array of property names and symbols.
  2864. */
  2865. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2866. var result = keysFunc(object);
  2867. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2868. }
  2869. /**
  2870. * The base implementation of `getTag` without fallbacks for buggy environments.
  2871. *
  2872. * @private
  2873. * @param {*} value The value to query.
  2874. * @returns {string} Returns the `toStringTag`.
  2875. */
  2876. function baseGetTag(value) {
  2877. if (value == null) {
  2878. return value === undefined ? undefinedTag : nullTag;
  2879. }
  2880. return (symToStringTag && symToStringTag in Object(value))
  2881. ? getRawTag(value)
  2882. : objectToString(value);
  2883. }
  2884. /**
  2885. * The base implementation of `_.gt` which doesn't coerce arguments.
  2886. *
  2887. * @private
  2888. * @param {*} value The value to compare.
  2889. * @param {*} other The other value to compare.
  2890. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2891. * else `false`.
  2892. */
  2893. function baseGt(value, other) {
  2894. return value > other;
  2895. }
  2896. /**
  2897. * The base implementation of `_.has` without support for deep paths.
  2898. *
  2899. * @private
  2900. * @param {Object} [object] The object to query.
  2901. * @param {Array|string} key The key to check.
  2902. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2903. */
  2904. function baseHas(object, key) {
  2905. return object != null && hasOwnProperty.call(object, key);
  2906. }
  2907. /**
  2908. * The base implementation of `_.hasIn` without support for deep paths.
  2909. *
  2910. * @private
  2911. * @param {Object} [object] The object to query.
  2912. * @param {Array|string} key The key to check.
  2913. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2914. */
  2915. function baseHasIn(object, key) {
  2916. return object != null && key in Object(object);
  2917. }
  2918. /**
  2919. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2920. *
  2921. * @private
  2922. * @param {number} number The number to check.
  2923. * @param {number} start The start of the range.
  2924. * @param {number} end The end of the range.
  2925. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2926. */
  2927. function baseInRange(number, start, end) {
  2928. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2929. }
  2930. /**
  2931. * The base implementation of methods like `_.intersection`, without support
  2932. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2933. *
  2934. * @private
  2935. * @param {Array} arrays The arrays to inspect.
  2936. * @param {Function} [iteratee] The iteratee invoked per element.
  2937. * @param {Function} [comparator] The comparator invoked per element.
  2938. * @returns {Array} Returns the new array of shared values.
  2939. */
  2940. function baseIntersection(arrays, iteratee, comparator) {
  2941. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2942. length = arrays[0].length,
  2943. othLength = arrays.length,
  2944. othIndex = othLength,
  2945. caches = Array(othLength),
  2946. maxLength = Infinity,
  2947. result = [];
  2948. while (othIndex--) {
  2949. var array = arrays[othIndex];
  2950. if (othIndex && iteratee) {
  2951. array = arrayMap(array, baseUnary(iteratee));
  2952. }
  2953. maxLength = nativeMin(array.length, maxLength);
  2954. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2955. ? new SetCache(othIndex && array)
  2956. : undefined;
  2957. }
  2958. array = arrays[0];
  2959. var index = -1,
  2960. seen = caches[0];
  2961. outer:
  2962. while (++index < length && result.length < maxLength) {
  2963. var value = array[index],
  2964. computed = iteratee ? iteratee(value) : value;
  2965. value = (comparator || value !== 0) ? value : 0;
  2966. if (!(seen
  2967. ? cacheHas(seen, computed)
  2968. : includes(result, computed, comparator)
  2969. )) {
  2970. othIndex = othLength;
  2971. while (--othIndex) {
  2972. var cache = caches[othIndex];
  2973. if (!(cache
  2974. ? cacheHas(cache, computed)
  2975. : includes(arrays[othIndex], computed, comparator))
  2976. ) {
  2977. continue outer;
  2978. }
  2979. }
  2980. if (seen) {
  2981. seen.push(computed);
  2982. }
  2983. result.push(value);
  2984. }
  2985. }
  2986. return result;
  2987. }
  2988. /**
  2989. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2990. * `object` with values transformed by `iteratee` and set by `setter`.
  2991. *
  2992. * @private
  2993. * @param {Object} object The object to iterate over.
  2994. * @param {Function} setter The function to set `accumulator` values.
  2995. * @param {Function} iteratee The iteratee to transform values.
  2996. * @param {Object} accumulator The initial inverted object.
  2997. * @returns {Function} Returns `accumulator`.
  2998. */
  2999. function baseInverter(object, setter, iteratee, accumulator) {
  3000. baseForOwn(object, function(value, key, object) {
  3001. setter(accumulator, iteratee(value), key, object);
  3002. });
  3003. return accumulator;
  3004. }
  3005. /**
  3006. * The base implementation of `_.invoke` without support for individual
  3007. * method arguments.
  3008. *
  3009. * @private
  3010. * @param {Object} object The object to query.
  3011. * @param {Array|string} path The path of the method to invoke.
  3012. * @param {Array} args The arguments to invoke the method with.
  3013. * @returns {*} Returns the result of the invoked method.
  3014. */
  3015. function baseInvoke(object, path, args) {
  3016. path = castPath(path, object);
  3017. object = parent(object, path);
  3018. var func = object == null ? object : object[toKey(last(path))];
  3019. return func == null ? undefined : apply(func, object, args);
  3020. }
  3021. /**
  3022. * The base implementation of `_.isArguments`.
  3023. *
  3024. * @private
  3025. * @param {*} value The value to check.
  3026. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  3027. */
  3028. function baseIsArguments(value) {
  3029. return isObjectLike(value) && baseGetTag(value) == argsTag;
  3030. }
  3031. /**
  3032. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  3033. *
  3034. * @private
  3035. * @param {*} value The value to check.
  3036. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  3037. */
  3038. function baseIsArrayBuffer(value) {
  3039. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  3040. }
  3041. /**
  3042. * The base implementation of `_.isDate` without Node.js optimizations.
  3043. *
  3044. * @private
  3045. * @param {*} value The value to check.
  3046. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  3047. */
  3048. function baseIsDate(value) {
  3049. return isObjectLike(value) && baseGetTag(value) == dateTag;
  3050. }
  3051. /**
  3052. * The base implementation of `_.isEqual` which supports partial comparisons
  3053. * and tracks traversed objects.
  3054. *
  3055. * @private
  3056. * @param {*} value The value to compare.
  3057. * @param {*} other The other value to compare.
  3058. * @param {boolean} bitmask The bitmask flags.
  3059. * 1 - Unordered comparison
  3060. * 2 - Partial comparison
  3061. * @param {Function} [customizer] The function to customize comparisons.
  3062. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  3063. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  3064. */
  3065. function baseIsEqual(value, other, bitmask, customizer, stack) {
  3066. if (value === other) {
  3067. return true;
  3068. }
  3069. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  3070. return value !== value && other !== other;
  3071. }
  3072. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  3073. }
  3074. /**
  3075. * A specialized version of `baseIsEqual` for arrays and objects which performs
  3076. * deep comparisons and tracks traversed objects enabling objects with circular
  3077. * references to be compared.
  3078. *
  3079. * @private
  3080. * @param {Object} object The object to compare.
  3081. * @param {Object} other The other object to compare.
  3082. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  3083. * @param {Function} customizer The function to customize comparisons.
  3084. * @param {Function} equalFunc The function to determine equivalents of values.
  3085. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  3086. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3087. */
  3088. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  3089. var objIsArr = isArray(object),
  3090. othIsArr = isArray(other),
  3091. objTag = objIsArr ? arrayTag : getTag(object),
  3092. othTag = othIsArr ? arrayTag : getTag(other);
  3093. objTag = objTag == argsTag ? objectTag : objTag;
  3094. othTag = othTag == argsTag ? objectTag : othTag;
  3095. var objIsObj = objTag == objectTag,
  3096. othIsObj = othTag == objectTag,
  3097. isSameTag = objTag == othTag;
  3098. if (isSameTag && isBuffer(object)) {
  3099. if (!isBuffer(other)) {
  3100. return false;
  3101. }
  3102. objIsArr = true;
  3103. objIsObj = false;
  3104. }
  3105. if (isSameTag && !objIsObj) {
  3106. stack || (stack = new Stack);
  3107. return (objIsArr || isTypedArray(object))
  3108. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3109. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3110. }
  3111. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3112. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3113. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3114. if (objIsWrapped || othIsWrapped) {
  3115. var objUnwrapped = objIsWrapped ? object.value() : object,
  3116. othUnwrapped = othIsWrapped ? other.value() : other;
  3117. stack || (stack = new Stack);
  3118. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3119. }
  3120. }
  3121. if (!isSameTag) {
  3122. return false;
  3123. }
  3124. stack || (stack = new Stack);
  3125. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3126. }
  3127. /**
  3128. * The base implementation of `_.isMap` without Node.js optimizations.
  3129. *
  3130. * @private
  3131. * @param {*} value The value to check.
  3132. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3133. */
  3134. function baseIsMap(value) {
  3135. return isObjectLike(value) && getTag(value) == mapTag;
  3136. }
  3137. /**
  3138. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3139. *
  3140. * @private
  3141. * @param {Object} object The object to inspect.
  3142. * @param {Object} source The object of property values to match.
  3143. * @param {Array} matchData The property names, values, and compare flags to match.
  3144. * @param {Function} [customizer] The function to customize comparisons.
  3145. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3146. */
  3147. function baseIsMatch(object, source, matchData, customizer) {
  3148. var index = matchData.length,
  3149. length = index,
  3150. noCustomizer = !customizer;
  3151. if (object == null) {
  3152. return !length;
  3153. }
  3154. object = Object(object);
  3155. while (index--) {
  3156. var data = matchData[index];
  3157. if ((noCustomizer && data[2])
  3158. ? data[1] !== object[data[0]]
  3159. : !(data[0] in object)
  3160. ) {
  3161. return false;
  3162. }
  3163. }
  3164. while (++index < length) {
  3165. data = matchData[index];
  3166. var key = data[0],
  3167. objValue = object[key],
  3168. srcValue = data[1];
  3169. if (noCustomizer && data[2]) {
  3170. if (objValue === undefined && !(key in object)) {
  3171. return false;
  3172. }
  3173. } else {
  3174. var stack = new Stack;
  3175. if (customizer) {
  3176. var result = customizer(objValue, srcValue, key, object, source, stack);
  3177. }
  3178. if (!(result === undefined
  3179. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3180. : result
  3181. )) {
  3182. return false;
  3183. }
  3184. }
  3185. }
  3186. return true;
  3187. }
  3188. /**
  3189. * The base implementation of `_.isNative` without bad shim checks.
  3190. *
  3191. * @private
  3192. * @param {*} value The value to check.
  3193. * @returns {boolean} Returns `true` if `value` is a native function,
  3194. * else `false`.
  3195. */
  3196. function baseIsNative(value) {
  3197. if (!isObject(value) || isMasked(value)) {
  3198. return false;
  3199. }
  3200. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3201. return pattern.test(toSource(value));
  3202. }
  3203. /**
  3204. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3205. *
  3206. * @private
  3207. * @param {*} value The value to check.
  3208. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3209. */
  3210. function baseIsRegExp(value) {
  3211. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3212. }
  3213. /**
  3214. * The base implementation of `_.isSet` without Node.js optimizations.
  3215. *
  3216. * @private
  3217. * @param {*} value The value to check.
  3218. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3219. */
  3220. function baseIsSet(value) {
  3221. return isObjectLike(value) && getTag(value) == setTag;
  3222. }
  3223. /**
  3224. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3225. *
  3226. * @private
  3227. * @param {*} value The value to check.
  3228. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3229. */
  3230. function baseIsTypedArray(value) {
  3231. return isObjectLike(value) &&
  3232. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3233. }
  3234. /**
  3235. * The base implementation of `_.iteratee`.
  3236. *
  3237. * @private
  3238. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3239. * @returns {Function} Returns the iteratee.
  3240. */
  3241. function baseIteratee(value) {
  3242. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3243. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3244. if (typeof value == 'function') {
  3245. return value;
  3246. }
  3247. if (value == null) {
  3248. return identity;
  3249. }
  3250. if (typeof value == 'object') {
  3251. return isArray(value)
  3252. ? baseMatchesProperty(value[0], value[1])
  3253. : baseMatches(value);
  3254. }
  3255. return property(value);
  3256. }
  3257. /**
  3258. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3259. *
  3260. * @private
  3261. * @param {Object} object The object to query.
  3262. * @returns {Array} Returns the array of property names.
  3263. */
  3264. function baseKeys(object) {
  3265. if (!isPrototype(object)) {
  3266. return nativeKeys(object);
  3267. }
  3268. var result = [];
  3269. for (var key in Object(object)) {
  3270. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3271. result.push(key);
  3272. }
  3273. }
  3274. return result;
  3275. }
  3276. /**
  3277. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3278. *
  3279. * @private
  3280. * @param {Object} object The object to query.
  3281. * @returns {Array} Returns the array of property names.
  3282. */
  3283. function baseKeysIn(object) {
  3284. if (!isObject(object)) {
  3285. return nativeKeysIn(object);
  3286. }
  3287. var isProto = isPrototype(object),
  3288. result = [];
  3289. for (var key in object) {
  3290. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3291. result.push(key);
  3292. }
  3293. }
  3294. return result;
  3295. }
  3296. /**
  3297. * The base implementation of `_.lt` which doesn't coerce arguments.
  3298. *
  3299. * @private
  3300. * @param {*} value The value to compare.
  3301. * @param {*} other The other value to compare.
  3302. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3303. * else `false`.
  3304. */
  3305. function baseLt(value, other) {
  3306. return value < other;
  3307. }
  3308. /**
  3309. * The base implementation of `_.map` without support for iteratee shorthands.
  3310. *
  3311. * @private
  3312. * @param {Array|Object} collection The collection to iterate over.
  3313. * @param {Function} iteratee The function invoked per iteration.
  3314. * @returns {Array} Returns the new mapped array.
  3315. */
  3316. function baseMap(collection, iteratee) {
  3317. var index = -1,
  3318. result = isArrayLike(collection) ? Array(collection.length) : [];
  3319. baseEach(collection, function(value, key, collection) {
  3320. result[++index] = iteratee(value, key, collection);
  3321. });
  3322. return result;
  3323. }
  3324. /**
  3325. * The base implementation of `_.matches` which doesn't clone `source`.
  3326. *
  3327. * @private
  3328. * @param {Object} source The object of property values to match.
  3329. * @returns {Function} Returns the new spec function.
  3330. */
  3331. function baseMatches(source) {
  3332. var matchData = getMatchData(source);
  3333. if (matchData.length == 1 && matchData[0][2]) {
  3334. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3335. }
  3336. return function(object) {
  3337. return object === source || baseIsMatch(object, source, matchData);
  3338. };
  3339. }
  3340. /**
  3341. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3342. *
  3343. * @private
  3344. * @param {string} path The path of the property to get.
  3345. * @param {*} srcValue The value to match.
  3346. * @returns {Function} Returns the new spec function.
  3347. */
  3348. function baseMatchesProperty(path, srcValue) {
  3349. if (isKey(path) && isStrictComparable(srcValue)) {
  3350. return matchesStrictComparable(toKey(path), srcValue);
  3351. }
  3352. return function(object) {
  3353. var objValue = get(object, path);
  3354. return (objValue === undefined && objValue === srcValue)
  3355. ? hasIn(object, path)
  3356. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3357. };
  3358. }
  3359. /**
  3360. * The base implementation of `_.merge` without support for multiple sources.
  3361. *
  3362. * @private
  3363. * @param {Object} object The destination object.
  3364. * @param {Object} source The source object.
  3365. * @param {number} srcIndex The index of `source`.
  3366. * @param {Function} [customizer] The function to customize merged values.
  3367. * @param {Object} [stack] Tracks traversed source values and their merged
  3368. * counterparts.
  3369. */
  3370. function baseMerge(object, source, srcIndex, customizer, stack) {
  3371. if (object === source) {
  3372. return;
  3373. }
  3374. baseFor(source, function(srcValue, key) {
  3375. if (isObject(srcValue)) {
  3376. stack || (stack = new Stack);
  3377. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3378. }
  3379. else {
  3380. var newValue = customizer
  3381. ? customizer(object[key], srcValue, (key + ''), object, source, stack)
  3382. : undefined;
  3383. if (newValue === undefined) {
  3384. newValue = srcValue;
  3385. }
  3386. assignMergeValue(object, key, newValue);
  3387. }
  3388. }, keysIn);
  3389. }
  3390. /**
  3391. * A specialized version of `baseMerge` for arrays and objects which performs
  3392. * deep merges and tracks traversed objects enabling objects with circular
  3393. * references to be merged.
  3394. *
  3395. * @private
  3396. * @param {Object} object The destination object.
  3397. * @param {Object} source The source object.
  3398. * @param {string} key The key of the value to merge.
  3399. * @param {number} srcIndex The index of `source`.
  3400. * @param {Function} mergeFunc The function to merge values.
  3401. * @param {Function} [customizer] The function to customize assigned values.
  3402. * @param {Object} [stack] Tracks traversed source values and their merged
  3403. * counterparts.
  3404. */
  3405. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3406. var objValue = object[key],
  3407. srcValue = source[key],
  3408. stacked = stack.get(srcValue);
  3409. if (stacked) {
  3410. assignMergeValue(object, key, stacked);
  3411. return;
  3412. }
  3413. var newValue = customizer
  3414. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3415. : undefined;
  3416. var isCommon = newValue === undefined;
  3417. if (isCommon) {
  3418. var isArr = isArray(srcValue),
  3419. isBuff = !isArr && isBuffer(srcValue),
  3420. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3421. newValue = srcValue;
  3422. if (isArr || isBuff || isTyped) {
  3423. if (isArray(objValue)) {
  3424. newValue = objValue;
  3425. }
  3426. else if (isArrayLikeObject(objValue)) {
  3427. newValue = copyArray(objValue);
  3428. }
  3429. else if (isBuff) {
  3430. isCommon = false;
  3431. newValue = cloneBuffer(srcValue, true);
  3432. }
  3433. else if (isTyped) {
  3434. isCommon = false;
  3435. newValue = cloneTypedArray(srcValue, true);
  3436. }
  3437. else {
  3438. newValue = [];
  3439. }
  3440. }
  3441. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3442. newValue = objValue;
  3443. if (isArguments(objValue)) {
  3444. newValue = toPlainObject(objValue);
  3445. }
  3446. else if (!isObject(objValue) || (srcIndex && isFunction(objValue))) {
  3447. newValue = initCloneObject(srcValue);
  3448. }
  3449. }
  3450. else {
  3451. isCommon = false;
  3452. }
  3453. }
  3454. if (isCommon) {
  3455. // Recursively merge objects and arrays (susceptible to call stack limits).
  3456. stack.set(srcValue, newValue);
  3457. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3458. stack['delete'](srcValue);
  3459. }
  3460. assignMergeValue(object, key, newValue);
  3461. }
  3462. /**
  3463. * The base implementation of `_.nth` which doesn't coerce arguments.
  3464. *
  3465. * @private
  3466. * @param {Array} array The array to query.
  3467. * @param {number} n The index of the element to return.
  3468. * @returns {*} Returns the nth element of `array`.
  3469. */
  3470. function baseNth(array, n) {
  3471. var length = array.length;
  3472. if (!length) {
  3473. return;
  3474. }
  3475. n += n < 0 ? length : 0;
  3476. return isIndex(n, length) ? array[n] : undefined;
  3477. }
  3478. /**
  3479. * The base implementation of `_.orderBy` without param guards.
  3480. *
  3481. * @private
  3482. * @param {Array|Object} collection The collection to iterate over.
  3483. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3484. * @param {string[]} orders The sort orders of `iteratees`.
  3485. * @returns {Array} Returns the new sorted array.
  3486. */
  3487. function baseOrderBy(collection, iteratees, orders) {
  3488. var index = -1;
  3489. iteratees = arrayMap(iteratees.length ? iteratees : [identity], baseUnary(getIteratee()));
  3490. var result = baseMap(collection, function(value, key, collection) {
  3491. var criteria = arrayMap(iteratees, function(iteratee) {
  3492. return iteratee(value);
  3493. });
  3494. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3495. });
  3496. return baseSortBy(result, function(object, other) {
  3497. return compareMultiple(object, other, orders);
  3498. });
  3499. }
  3500. /**
  3501. * The base implementation of `_.pick` without support for individual
  3502. * property identifiers.
  3503. *
  3504. * @private
  3505. * @param {Object} object The source object.
  3506. * @param {string[]} paths The property paths to pick.
  3507. * @returns {Object} Returns the new object.
  3508. */
  3509. function basePick(object, paths) {
  3510. return basePickBy(object, paths, function(value, path) {
  3511. return hasIn(object, path);
  3512. });
  3513. }
  3514. /**
  3515. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3516. *
  3517. * @private
  3518. * @param {Object} object The source object.
  3519. * @param {string[]} paths The property paths to pick.
  3520. * @param {Function} predicate The function invoked per property.
  3521. * @returns {Object} Returns the new object.
  3522. */
  3523. function basePickBy(object, paths, predicate) {
  3524. var index = -1,
  3525. length = paths.length,
  3526. result = {};
  3527. while (++index < length) {
  3528. var path = paths[index],
  3529. value = baseGet(object, path);
  3530. if (predicate(value, path)) {
  3531. baseSet(result, castPath(path, object), value);
  3532. }
  3533. }
  3534. return result;
  3535. }
  3536. /**
  3537. * A specialized version of `baseProperty` which supports deep paths.
  3538. *
  3539. * @private
  3540. * @param {Array|string} path The path of the property to get.
  3541. * @returns {Function} Returns the new accessor function.
  3542. */
  3543. function basePropertyDeep(path) {
  3544. return function(object) {
  3545. return baseGet(object, path);
  3546. };
  3547. }
  3548. /**
  3549. * The base implementation of `_.pullAllBy` without support for iteratee
  3550. * shorthands.
  3551. *
  3552. * @private
  3553. * @param {Array} array The array to modify.
  3554. * @param {Array} values The values to remove.
  3555. * @param {Function} [iteratee] The iteratee invoked per element.
  3556. * @param {Function} [comparator] The comparator invoked per element.
  3557. * @returns {Array} Returns `array`.
  3558. */
  3559. function basePullAll(array, values, iteratee, comparator) {
  3560. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3561. index = -1,
  3562. length = values.length,
  3563. seen = array;
  3564. if (array === values) {
  3565. values = copyArray(values);
  3566. }
  3567. if (iteratee) {
  3568. seen = arrayMap(array, baseUnary(iteratee));
  3569. }
  3570. while (++index < length) {
  3571. var fromIndex = 0,
  3572. value = values[index],
  3573. computed = iteratee ? iteratee(value) : value;
  3574. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3575. if (seen !== array) {
  3576. splice.call(seen, fromIndex, 1);
  3577. }
  3578. splice.call(array, fromIndex, 1);
  3579. }
  3580. }
  3581. return array;
  3582. }
  3583. /**
  3584. * The base implementation of `_.pullAt` without support for individual
  3585. * indexes or capturing the removed elements.
  3586. *
  3587. * @private
  3588. * @param {Array} array The array to modify.
  3589. * @param {number[]} indexes The indexes of elements to remove.
  3590. * @returns {Array} Returns `array`.
  3591. */
  3592. function basePullAt(array, indexes) {
  3593. var length = array ? indexes.length : 0,
  3594. lastIndex = length - 1;
  3595. while (length--) {
  3596. var index = indexes[length];
  3597. if (length == lastIndex || index !== previous) {
  3598. var previous = index;
  3599. if (isIndex(index)) {
  3600. splice.call(array, index, 1);
  3601. } else {
  3602. baseUnset(array, index);
  3603. }
  3604. }
  3605. }
  3606. return array;
  3607. }
  3608. /**
  3609. * The base implementation of `_.random` without support for returning
  3610. * floating-point numbers.
  3611. *
  3612. * @private
  3613. * @param {number} lower The lower bound.
  3614. * @param {number} upper The upper bound.
  3615. * @returns {number} Returns the random number.
  3616. */
  3617. function baseRandom(lower, upper) {
  3618. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3619. }
  3620. /**
  3621. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3622. * coerce arguments.
  3623. *
  3624. * @private
  3625. * @param {number} start The start of the range.
  3626. * @param {number} end The end of the range.
  3627. * @param {number} step The value to increment or decrement by.
  3628. * @param {boolean} [fromRight] Specify iterating from right to left.
  3629. * @returns {Array} Returns the range of numbers.
  3630. */
  3631. function baseRange(start, end, step, fromRight) {
  3632. var index = -1,
  3633. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3634. result = Array(length);
  3635. while (length--) {
  3636. result[fromRight ? length : ++index] = start;
  3637. start += step;
  3638. }
  3639. return result;
  3640. }
  3641. /**
  3642. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3643. *
  3644. * @private
  3645. * @param {string} string The string to repeat.
  3646. * @param {number} n The number of times to repeat the string.
  3647. * @returns {string} Returns the repeated string.
  3648. */
  3649. function baseRepeat(string, n) {
  3650. var result = '';
  3651. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3652. return result;
  3653. }
  3654. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3655. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3656. do {
  3657. if (n % 2) {
  3658. result += string;
  3659. }
  3660. n = nativeFloor(n / 2);
  3661. if (n) {
  3662. string += string;
  3663. }
  3664. } while (n);
  3665. return result;
  3666. }
  3667. /**
  3668. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3669. *
  3670. * @private
  3671. * @param {Function} func The function to apply a rest parameter to.
  3672. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3673. * @returns {Function} Returns the new function.
  3674. */
  3675. function baseRest(func, start) {
  3676. return setToString(overRest(func, start, identity), func + '');
  3677. }
  3678. /**
  3679. * The base implementation of `_.sample`.
  3680. *
  3681. * @private
  3682. * @param {Array|Object} collection The collection to sample.
  3683. * @returns {*} Returns the random element.
  3684. */
  3685. function baseSample(collection) {
  3686. return arraySample(values(collection));
  3687. }
  3688. /**
  3689. * The base implementation of `_.sampleSize` without param guards.
  3690. *
  3691. * @private
  3692. * @param {Array|Object} collection The collection to sample.
  3693. * @param {number} n The number of elements to sample.
  3694. * @returns {Array} Returns the random elements.
  3695. */
  3696. function baseSampleSize(collection, n) {
  3697. var array = values(collection);
  3698. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3699. }
  3700. /**
  3701. * The base implementation of `_.set`.
  3702. *
  3703. * @private
  3704. * @param {Object} object The object to modify.
  3705. * @param {Array|string} path The path of the property to set.
  3706. * @param {*} value The value to set.
  3707. * @param {Function} [customizer] The function to customize path creation.
  3708. * @returns {Object} Returns `object`.
  3709. */
  3710. function baseSet(object, path, value, customizer) {
  3711. if (!isObject(object)) {
  3712. return object;
  3713. }
  3714. path = castPath(path, object);
  3715. var index = -1,
  3716. length = path.length,
  3717. lastIndex = length - 1,
  3718. nested = object;
  3719. while (nested != null && ++index < length) {
  3720. var key = toKey(path[index]),
  3721. newValue = value;
  3722. if (index != lastIndex) {
  3723. var objValue = nested[key];
  3724. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3725. if (newValue === undefined) {
  3726. newValue = isObject(objValue)
  3727. ? objValue
  3728. : (isIndex(path[index + 1]) ? [] : {});
  3729. }
  3730. }
  3731. assignValue(nested, key, newValue);
  3732. nested = nested[key];
  3733. }
  3734. return object;
  3735. }
  3736. /**
  3737. * The base implementation of `setData` without support for hot loop shorting.
  3738. *
  3739. * @private
  3740. * @param {Function} func The function to associate metadata with.
  3741. * @param {*} data The metadata.
  3742. * @returns {Function} Returns `func`.
  3743. */
  3744. var baseSetData = !metaMap ? identity : function(func, data) {
  3745. metaMap.set(func, data);
  3746. return func;
  3747. };
  3748. /**
  3749. * The base implementation of `setToString` without support for hot loop shorting.
  3750. *
  3751. * @private
  3752. * @param {Function} func The function to modify.
  3753. * @param {Function} string The `toString` result.
  3754. * @returns {Function} Returns `func`.
  3755. */
  3756. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3757. return defineProperty(func, 'toString', {
  3758. 'configurable': true,
  3759. 'enumerable': false,
  3760. 'value': constant(string),
  3761. 'writable': true
  3762. });
  3763. };
  3764. /**
  3765. * The base implementation of `_.shuffle`.
  3766. *
  3767. * @private
  3768. * @param {Array|Object} collection The collection to shuffle.
  3769. * @returns {Array} Returns the new shuffled array.
  3770. */
  3771. function baseShuffle(collection) {
  3772. return shuffleSelf(values(collection));
  3773. }
  3774. /**
  3775. * The base implementation of `_.slice` without an iteratee call guard.
  3776. *
  3777. * @private
  3778. * @param {Array} array The array to slice.
  3779. * @param {number} [start=0] The start position.
  3780. * @param {number} [end=array.length] The end position.
  3781. * @returns {Array} Returns the slice of `array`.
  3782. */
  3783. function baseSlice(array, start, end) {
  3784. var index = -1,
  3785. length = array.length;
  3786. if (start < 0) {
  3787. start = -start > length ? 0 : (length + start);
  3788. }
  3789. end = end > length ? length : end;
  3790. if (end < 0) {
  3791. end += length;
  3792. }
  3793. length = start > end ? 0 : ((end - start) >>> 0);
  3794. start >>>= 0;
  3795. var result = Array(length);
  3796. while (++index < length) {
  3797. result[index] = array[index + start];
  3798. }
  3799. return result;
  3800. }
  3801. /**
  3802. * The base implementation of `_.some` without support for iteratee shorthands.
  3803. *
  3804. * @private
  3805. * @param {Array|Object} collection The collection to iterate over.
  3806. * @param {Function} predicate The function invoked per iteration.
  3807. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3808. * else `false`.
  3809. */
  3810. function baseSome(collection, predicate) {
  3811. var result;
  3812. baseEach(collection, function(value, index, collection) {
  3813. result = predicate(value, index, collection);
  3814. return !result;
  3815. });
  3816. return !!result;
  3817. }
  3818. /**
  3819. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3820. * performs a binary search of `array` to determine the index at which `value`
  3821. * should be inserted into `array` in order to maintain its sort order.
  3822. *
  3823. * @private
  3824. * @param {Array} array The sorted array to inspect.
  3825. * @param {*} value The value to evaluate.
  3826. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3827. * @returns {number} Returns the index at which `value` should be inserted
  3828. * into `array`.
  3829. */
  3830. function baseSortedIndex(array, value, retHighest) {
  3831. var low = 0,
  3832. high = array == null ? low : array.length;
  3833. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3834. while (low < high) {
  3835. var mid = (low + high) >>> 1,
  3836. computed = array[mid];
  3837. if (computed !== null && !isSymbol(computed) &&
  3838. (retHighest ? (computed <= value) : (computed < value))) {
  3839. low = mid + 1;
  3840. } else {
  3841. high = mid;
  3842. }
  3843. }
  3844. return high;
  3845. }
  3846. return baseSortedIndexBy(array, value, identity, retHighest);
  3847. }
  3848. /**
  3849. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3850. * which invokes `iteratee` for `value` and each element of `array` to compute
  3851. * their sort ranking. The iteratee is invoked with one argument; (value).
  3852. *
  3853. * @private
  3854. * @param {Array} array The sorted array to inspect.
  3855. * @param {*} value The value to evaluate.
  3856. * @param {Function} iteratee The iteratee invoked per element.
  3857. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3858. * @returns {number} Returns the index at which `value` should be inserted
  3859. * into `array`.
  3860. */
  3861. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3862. value = iteratee(value);
  3863. var low = 0,
  3864. high = array == null ? 0 : array.length,
  3865. valIsNaN = value !== value,
  3866. valIsNull = value === null,
  3867. valIsSymbol = isSymbol(value),
  3868. valIsUndefined = value === undefined;
  3869. while (low < high) {
  3870. var mid = nativeFloor((low + high) / 2),
  3871. computed = iteratee(array[mid]),
  3872. othIsDefined = computed !== undefined,
  3873. othIsNull = computed === null,
  3874. othIsReflexive = computed === computed,
  3875. othIsSymbol = isSymbol(computed);
  3876. if (valIsNaN) {
  3877. var setLow = retHighest || othIsReflexive;
  3878. } else if (valIsUndefined) {
  3879. setLow = othIsReflexive && (retHighest || othIsDefined);
  3880. } else if (valIsNull) {
  3881. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3882. } else if (valIsSymbol) {
  3883. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3884. } else if (othIsNull || othIsSymbol) {
  3885. setLow = false;
  3886. } else {
  3887. setLow = retHighest ? (computed <= value) : (computed < value);
  3888. }
  3889. if (setLow) {
  3890. low = mid + 1;
  3891. } else {
  3892. high = mid;
  3893. }
  3894. }
  3895. return nativeMin(high, MAX_ARRAY_INDEX);
  3896. }
  3897. /**
  3898. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3899. * support for iteratee shorthands.
  3900. *
  3901. * @private
  3902. * @param {Array} array The array to inspect.
  3903. * @param {Function} [iteratee] The iteratee invoked per element.
  3904. * @returns {Array} Returns the new duplicate free array.
  3905. */
  3906. function baseSortedUniq(array, iteratee) {
  3907. var index = -1,
  3908. length = array.length,
  3909. resIndex = 0,
  3910. result = [];
  3911. while (++index < length) {
  3912. var value = array[index],
  3913. computed = iteratee ? iteratee(value) : value;
  3914. if (!index || !eq(computed, seen)) {
  3915. var seen = computed;
  3916. result[resIndex++] = value === 0 ? 0 : value;
  3917. }
  3918. }
  3919. return result;
  3920. }
  3921. /**
  3922. * The base implementation of `_.toNumber` which doesn't ensure correct
  3923. * conversions of binary, hexadecimal, or octal string values.
  3924. *
  3925. * @private
  3926. * @param {*} value The value to process.
  3927. * @returns {number} Returns the number.
  3928. */
  3929. function baseToNumber(value) {
  3930. if (typeof value == 'number') {
  3931. return value;
  3932. }
  3933. if (isSymbol(value)) {
  3934. return NAN;
  3935. }
  3936. return +value;
  3937. }
  3938. /**
  3939. * The base implementation of `_.toString` which doesn't convert nullish
  3940. * values to empty strings.
  3941. *
  3942. * @private
  3943. * @param {*} value The value to process.
  3944. * @returns {string} Returns the string.
  3945. */
  3946. function baseToString(value) {
  3947. // Exit early for strings to avoid a performance hit in some environments.
  3948. if (typeof value == 'string') {
  3949. return value;
  3950. }
  3951. if (isArray(value)) {
  3952. // Recursively convert values (susceptible to call stack limits).
  3953. return arrayMap(value, baseToString) + '';
  3954. }
  3955. if (isSymbol(value)) {
  3956. return symbolToString ? symbolToString.call(value) : '';
  3957. }
  3958. var result = (value + '');
  3959. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3960. }
  3961. /**
  3962. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3963. *
  3964. * @private
  3965. * @param {Array} array The array to inspect.
  3966. * @param {Function} [iteratee] The iteratee invoked per element.
  3967. * @param {Function} [comparator] The comparator invoked per element.
  3968. * @returns {Array} Returns the new duplicate free array.
  3969. */
  3970. function baseUniq(array, iteratee, comparator) {
  3971. var index = -1,
  3972. includes = arrayIncludes,
  3973. length = array.length,
  3974. isCommon = true,
  3975. result = [],
  3976. seen = result;
  3977. if (comparator) {
  3978. isCommon = false;
  3979. includes = arrayIncludesWith;
  3980. }
  3981. else if (length >= LARGE_ARRAY_SIZE) {
  3982. var set = iteratee ? null : createSet(array);
  3983. if (set) {
  3984. return setToArray(set);
  3985. }
  3986. isCommon = false;
  3987. includes = cacheHas;
  3988. seen = new SetCache;
  3989. }
  3990. else {
  3991. seen = iteratee ? [] : result;
  3992. }
  3993. outer:
  3994. while (++index < length) {
  3995. var value = array[index],
  3996. computed = iteratee ? iteratee(value) : value;
  3997. value = (comparator || value !== 0) ? value : 0;
  3998. if (isCommon && computed === computed) {
  3999. var seenIndex = seen.length;
  4000. while (seenIndex--) {
  4001. if (seen[seenIndex] === computed) {
  4002. continue outer;
  4003. }
  4004. }
  4005. if (iteratee) {
  4006. seen.push(computed);
  4007. }
  4008. result.push(value);
  4009. }
  4010. else if (!includes(seen, computed, comparator)) {
  4011. if (seen !== result) {
  4012. seen.push(computed);
  4013. }
  4014. result.push(value);
  4015. }
  4016. }
  4017. return result;
  4018. }
  4019. /**
  4020. * The base implementation of `_.unset`.
  4021. *
  4022. * @private
  4023. * @param {Object} object The object to modify.
  4024. * @param {Array|string} path The property path to unset.
  4025. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  4026. */
  4027. function baseUnset(object, path) {
  4028. path = castPath(path, object);
  4029. object = parent(object, path);
  4030. return object == null || delete object[toKey(last(path))];
  4031. }
  4032. /**
  4033. * The base implementation of `_.update`.
  4034. *
  4035. * @private
  4036. * @param {Object} object The object to modify.
  4037. * @param {Array|string} path The path of the property to update.
  4038. * @param {Function} updater The function to produce the updated value.
  4039. * @param {Function} [customizer] The function to customize path creation.
  4040. * @returns {Object} Returns `object`.
  4041. */
  4042. function baseUpdate(object, path, updater, customizer) {
  4043. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  4044. }
  4045. /**
  4046. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  4047. * without support for iteratee shorthands.
  4048. *
  4049. * @private
  4050. * @param {Array} array The array to query.
  4051. * @param {Function} predicate The function invoked per iteration.
  4052. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  4053. * @param {boolean} [fromRight] Specify iterating from right to left.
  4054. * @returns {Array} Returns the slice of `array`.
  4055. */
  4056. function baseWhile(array, predicate, isDrop, fromRight) {
  4057. var length = array.length,
  4058. index = fromRight ? length : -1;
  4059. while ((fromRight ? index-- : ++index < length) &&
  4060. predicate(array[index], index, array)) {}
  4061. return isDrop
  4062. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  4063. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  4064. }
  4065. /**
  4066. * The base implementation of `wrapperValue` which returns the result of
  4067. * performing a sequence of actions on the unwrapped `value`, where each
  4068. * successive action is supplied the return value of the previous.
  4069. *
  4070. * @private
  4071. * @param {*} value The unwrapped value.
  4072. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  4073. * @returns {*} Returns the resolved value.
  4074. */
  4075. function baseWrapperValue(value, actions) {
  4076. var result = value;
  4077. if (result instanceof LazyWrapper) {
  4078. result = result.value();
  4079. }
  4080. return arrayReduce(actions, function(result, action) {
  4081. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  4082. }, result);
  4083. }
  4084. /**
  4085. * The base implementation of methods like `_.xor`, without support for
  4086. * iteratee shorthands, that accepts an array of arrays to inspect.
  4087. *
  4088. * @private
  4089. * @param {Array} arrays The arrays to inspect.
  4090. * @param {Function} [iteratee] The iteratee invoked per element.
  4091. * @param {Function} [comparator] The comparator invoked per element.
  4092. * @returns {Array} Returns the new array of values.
  4093. */
  4094. function baseXor(arrays, iteratee, comparator) {
  4095. var length = arrays.length;
  4096. if (length < 2) {
  4097. return length ? baseUniq(arrays[0]) : [];
  4098. }
  4099. var index = -1,
  4100. result = Array(length);
  4101. while (++index < length) {
  4102. var array = arrays[index],
  4103. othIndex = -1;
  4104. while (++othIndex < length) {
  4105. if (othIndex != index) {
  4106. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4107. }
  4108. }
  4109. }
  4110. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4111. }
  4112. /**
  4113. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4114. *
  4115. * @private
  4116. * @param {Array} props The property identifiers.
  4117. * @param {Array} values The property values.
  4118. * @param {Function} assignFunc The function to assign values.
  4119. * @returns {Object} Returns the new object.
  4120. */
  4121. function baseZipObject(props, values, assignFunc) {
  4122. var index = -1,
  4123. length = props.length,
  4124. valsLength = values.length,
  4125. result = {};
  4126. while (++index < length) {
  4127. var value = index < valsLength ? values[index] : undefined;
  4128. assignFunc(result, props[index], value);
  4129. }
  4130. return result;
  4131. }
  4132. /**
  4133. * Casts `value` to an empty array if it's not an array like object.
  4134. *
  4135. * @private
  4136. * @param {*} value The value to inspect.
  4137. * @returns {Array|Object} Returns the cast array-like object.
  4138. */
  4139. function castArrayLikeObject(value) {
  4140. return isArrayLikeObject(value) ? value : [];
  4141. }
  4142. /**
  4143. * Casts `value` to `identity` if it's not a function.
  4144. *
  4145. * @private
  4146. * @param {*} value The value to inspect.
  4147. * @returns {Function} Returns cast function.
  4148. */
  4149. function castFunction(value) {
  4150. return typeof value == 'function' ? value : identity;
  4151. }
  4152. /**
  4153. * Casts `value` to a path array if it's not one.
  4154. *
  4155. * @private
  4156. * @param {*} value The value to inspect.
  4157. * @param {Object} [object] The object to query keys on.
  4158. * @returns {Array} Returns the cast property path array.
  4159. */
  4160. function castPath(value, object) {
  4161. if (isArray(value)) {
  4162. return value;
  4163. }
  4164. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4165. }
  4166. /**
  4167. * A `baseRest` alias which can be replaced with `identity` by module
  4168. * replacement plugins.
  4169. *
  4170. * @private
  4171. * @type {Function}
  4172. * @param {Function} func The function to apply a rest parameter to.
  4173. * @returns {Function} Returns the new function.
  4174. */
  4175. var castRest = baseRest;
  4176. /**
  4177. * Casts `array` to a slice if it's needed.
  4178. *
  4179. * @private
  4180. * @param {Array} array The array to inspect.
  4181. * @param {number} start The start position.
  4182. * @param {number} [end=array.length] The end position.
  4183. * @returns {Array} Returns the cast slice.
  4184. */
  4185. function castSlice(array, start, end) {
  4186. var length = array.length;
  4187. end = end === undefined ? length : end;
  4188. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4189. }
  4190. /**
  4191. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4192. *
  4193. * @private
  4194. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4195. */
  4196. var clearTimeout = ctxClearTimeout || function(id) {
  4197. return root.clearTimeout(id);
  4198. };
  4199. /**
  4200. * Creates a clone of `buffer`.
  4201. *
  4202. * @private
  4203. * @param {Buffer} buffer The buffer to clone.
  4204. * @param {boolean} [isDeep] Specify a deep clone.
  4205. * @returns {Buffer} Returns the cloned buffer.
  4206. */
  4207. function cloneBuffer(buffer, isDeep) {
  4208. if (isDeep) {
  4209. return buffer.slice();
  4210. }
  4211. var length = buffer.length,
  4212. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4213. buffer.copy(result);
  4214. return result;
  4215. }
  4216. /**
  4217. * Creates a clone of `arrayBuffer`.
  4218. *
  4219. * @private
  4220. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4221. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4222. */
  4223. function cloneArrayBuffer(arrayBuffer) {
  4224. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4225. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4226. return result;
  4227. }
  4228. /**
  4229. * Creates a clone of `dataView`.
  4230. *
  4231. * @private
  4232. * @param {Object} dataView The data view to clone.
  4233. * @param {boolean} [isDeep] Specify a deep clone.
  4234. * @returns {Object} Returns the cloned data view.
  4235. */
  4236. function cloneDataView(dataView, isDeep) {
  4237. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4238. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4239. }
  4240. /**
  4241. * Creates a clone of `map`.
  4242. *
  4243. * @private
  4244. * @param {Object} map The map to clone.
  4245. * @param {Function} cloneFunc The function to clone values.
  4246. * @param {boolean} [isDeep] Specify a deep clone.
  4247. * @returns {Object} Returns the cloned map.
  4248. */
  4249. function cloneMap(map, isDeep, cloneFunc) {
  4250. var array = isDeep ? cloneFunc(mapToArray(map), CLONE_DEEP_FLAG) : mapToArray(map);
  4251. return arrayReduce(array, addMapEntry, new map.constructor);
  4252. }
  4253. /**
  4254. * Creates a clone of `regexp`.
  4255. *
  4256. * @private
  4257. * @param {Object} regexp The regexp to clone.
  4258. * @returns {Object} Returns the cloned regexp.
  4259. */
  4260. function cloneRegExp(regexp) {
  4261. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4262. result.lastIndex = regexp.lastIndex;
  4263. return result;
  4264. }
  4265. /**
  4266. * Creates a clone of `set`.
  4267. *
  4268. * @private
  4269. * @param {Object} set The set to clone.
  4270. * @param {Function} cloneFunc The function to clone values.
  4271. * @param {boolean} [isDeep] Specify a deep clone.
  4272. * @returns {Object} Returns the cloned set.
  4273. */
  4274. function cloneSet(set, isDeep, cloneFunc) {
  4275. var array = isDeep ? cloneFunc(setToArray(set), CLONE_DEEP_FLAG) : setToArray(set);
  4276. return arrayReduce(array, addSetEntry, new set.constructor);
  4277. }
  4278. /**
  4279. * Creates a clone of the `symbol` object.
  4280. *
  4281. * @private
  4282. * @param {Object} symbol The symbol object to clone.
  4283. * @returns {Object} Returns the cloned symbol object.
  4284. */
  4285. function cloneSymbol(symbol) {
  4286. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4287. }
  4288. /**
  4289. * Creates a clone of `typedArray`.
  4290. *
  4291. * @private
  4292. * @param {Object} typedArray The typed array to clone.
  4293. * @param {boolean} [isDeep] Specify a deep clone.
  4294. * @returns {Object} Returns the cloned typed array.
  4295. */
  4296. function cloneTypedArray(typedArray, isDeep) {
  4297. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4298. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4299. }
  4300. /**
  4301. * Compares values to sort them in ascending order.
  4302. *
  4303. * @private
  4304. * @param {*} value The value to compare.
  4305. * @param {*} other The other value to compare.
  4306. * @returns {number} Returns the sort order indicator for `value`.
  4307. */
  4308. function compareAscending(value, other) {
  4309. if (value !== other) {
  4310. var valIsDefined = value !== undefined,
  4311. valIsNull = value === null,
  4312. valIsReflexive = value === value,
  4313. valIsSymbol = isSymbol(value);
  4314. var othIsDefined = other !== undefined,
  4315. othIsNull = other === null,
  4316. othIsReflexive = other === other,
  4317. othIsSymbol = isSymbol(other);
  4318. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4319. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4320. (valIsNull && othIsDefined && othIsReflexive) ||
  4321. (!valIsDefined && othIsReflexive) ||
  4322. !valIsReflexive) {
  4323. return 1;
  4324. }
  4325. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4326. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4327. (othIsNull && valIsDefined && valIsReflexive) ||
  4328. (!othIsDefined && valIsReflexive) ||
  4329. !othIsReflexive) {
  4330. return -1;
  4331. }
  4332. }
  4333. return 0;
  4334. }
  4335. /**
  4336. * Used by `_.orderBy` to compare multiple properties of a value to another
  4337. * and stable sort them.
  4338. *
  4339. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4340. * specify an order of "desc" for descending or "asc" for ascending sort order
  4341. * of corresponding values.
  4342. *
  4343. * @private
  4344. * @param {Object} object The object to compare.
  4345. * @param {Object} other The other object to compare.
  4346. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4347. * @returns {number} Returns the sort order indicator for `object`.
  4348. */
  4349. function compareMultiple(object, other, orders) {
  4350. var index = -1,
  4351. objCriteria = object.criteria,
  4352. othCriteria = other.criteria,
  4353. length = objCriteria.length,
  4354. ordersLength = orders.length;
  4355. while (++index < length) {
  4356. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4357. if (result) {
  4358. if (index >= ordersLength) {
  4359. return result;
  4360. }
  4361. var order = orders[index];
  4362. return result * (order == 'desc' ? -1 : 1);
  4363. }
  4364. }
  4365. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4366. // that causes it, under certain circumstances, to provide the same value for
  4367. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4368. // for more details.
  4369. //
  4370. // This also ensures a stable sort in V8 and other engines.
  4371. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4372. return object.index - other.index;
  4373. }
  4374. /**
  4375. * Creates an array that is the composition of partially applied arguments,
  4376. * placeholders, and provided arguments into a single array of arguments.
  4377. *
  4378. * @private
  4379. * @param {Array} args The provided arguments.
  4380. * @param {Array} partials The arguments to prepend to those provided.
  4381. * @param {Array} holders The `partials` placeholder indexes.
  4382. * @params {boolean} [isCurried] Specify composing for a curried function.
  4383. * @returns {Array} Returns the new array of composed arguments.
  4384. */
  4385. function composeArgs(args, partials, holders, isCurried) {
  4386. var argsIndex = -1,
  4387. argsLength = args.length,
  4388. holdersLength = holders.length,
  4389. leftIndex = -1,
  4390. leftLength = partials.length,
  4391. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4392. result = Array(leftLength + rangeLength),
  4393. isUncurried = !isCurried;
  4394. while (++leftIndex < leftLength) {
  4395. result[leftIndex] = partials[leftIndex];
  4396. }
  4397. while (++argsIndex < holdersLength) {
  4398. if (isUncurried || argsIndex < argsLength) {
  4399. result[holders[argsIndex]] = args[argsIndex];
  4400. }
  4401. }
  4402. while (rangeLength--) {
  4403. result[leftIndex++] = args[argsIndex++];
  4404. }
  4405. return result;
  4406. }
  4407. /**
  4408. * This function is like `composeArgs` except that the arguments composition
  4409. * is tailored for `_.partialRight`.
  4410. *
  4411. * @private
  4412. * @param {Array} args The provided arguments.
  4413. * @param {Array} partials The arguments to append to those provided.
  4414. * @param {Array} holders The `partials` placeholder indexes.
  4415. * @params {boolean} [isCurried] Specify composing for a curried function.
  4416. * @returns {Array} Returns the new array of composed arguments.
  4417. */
  4418. function composeArgsRight(args, partials, holders, isCurried) {
  4419. var argsIndex = -1,
  4420. argsLength = args.length,
  4421. holdersIndex = -1,
  4422. holdersLength = holders.length,
  4423. rightIndex = -1,
  4424. rightLength = partials.length,
  4425. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4426. result = Array(rangeLength + rightLength),
  4427. isUncurried = !isCurried;
  4428. while (++argsIndex < rangeLength) {
  4429. result[argsIndex] = args[argsIndex];
  4430. }
  4431. var offset = argsIndex;
  4432. while (++rightIndex < rightLength) {
  4433. result[offset + rightIndex] = partials[rightIndex];
  4434. }
  4435. while (++holdersIndex < holdersLength) {
  4436. if (isUncurried || argsIndex < argsLength) {
  4437. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4438. }
  4439. }
  4440. return result;
  4441. }
  4442. /**
  4443. * Copies the values of `source` to `array`.
  4444. *
  4445. * @private
  4446. * @param {Array} source The array to copy values from.
  4447. * @param {Array} [array=[]] The array to copy values to.
  4448. * @returns {Array} Returns `array`.
  4449. */
  4450. function copyArray(source, array) {
  4451. var index = -1,
  4452. length = source.length;
  4453. array || (array = Array(length));
  4454. while (++index < length) {
  4455. array[index] = source[index];
  4456. }
  4457. return array;
  4458. }
  4459. /**
  4460. * Copies properties of `source` to `object`.
  4461. *
  4462. * @private
  4463. * @param {Object} source The object to copy properties from.
  4464. * @param {Array} props The property identifiers to copy.
  4465. * @param {Object} [object={}] The object to copy properties to.
  4466. * @param {Function} [customizer] The function to customize copied values.
  4467. * @returns {Object} Returns `object`.
  4468. */
  4469. function copyObject(source, props, object, customizer) {
  4470. var isNew = !object;
  4471. object || (object = {});
  4472. var index = -1,
  4473. length = props.length;
  4474. while (++index < length) {
  4475. var key = props[index];
  4476. var newValue = customizer
  4477. ? customizer(object[key], source[key], key, object, source)
  4478. : undefined;
  4479. if (newValue === undefined) {
  4480. newValue = source[key];
  4481. }
  4482. if (isNew) {
  4483. baseAssignValue(object, key, newValue);
  4484. } else {
  4485. assignValue(object, key, newValue);
  4486. }
  4487. }
  4488. return object;
  4489. }
  4490. /**
  4491. * Copies own symbols of `source` to `object`.
  4492. *
  4493. * @private
  4494. * @param {Object} source The object to copy symbols from.
  4495. * @param {Object} [object={}] The object to copy symbols to.
  4496. * @returns {Object} Returns `object`.
  4497. */
  4498. function copySymbols(source, object) {
  4499. return copyObject(source, getSymbols(source), object);
  4500. }
  4501. /**
  4502. * Copies own and inherited symbols of `source` to `object`.
  4503. *
  4504. * @private
  4505. * @param {Object} source The object to copy symbols from.
  4506. * @param {Object} [object={}] The object to copy symbols to.
  4507. * @returns {Object} Returns `object`.
  4508. */
  4509. function copySymbolsIn(source, object) {
  4510. return copyObject(source, getSymbolsIn(source), object);
  4511. }
  4512. /**
  4513. * Creates a function like `_.groupBy`.
  4514. *
  4515. * @private
  4516. * @param {Function} setter The function to set accumulator values.
  4517. * @param {Function} [initializer] The accumulator object initializer.
  4518. * @returns {Function} Returns the new aggregator function.
  4519. */
  4520. function createAggregator(setter, initializer) {
  4521. return function(collection, iteratee) {
  4522. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4523. accumulator = initializer ? initializer() : {};
  4524. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4525. };
  4526. }
  4527. /**
  4528. * Creates a function like `_.assign`.
  4529. *
  4530. * @private
  4531. * @param {Function} assigner The function to assign values.
  4532. * @returns {Function} Returns the new assigner function.
  4533. */
  4534. function createAssigner(assigner) {
  4535. return baseRest(function(object, sources) {
  4536. var index = -1,
  4537. length = sources.length,
  4538. customizer = length > 1 ? sources[length - 1] : undefined,
  4539. guard = length > 2 ? sources[2] : undefined;
  4540. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4541. ? (length--, customizer)
  4542. : undefined;
  4543. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4544. customizer = length < 3 ? undefined : customizer;
  4545. length = 1;
  4546. }
  4547. object = Object(object);
  4548. while (++index < length) {
  4549. var source = sources[index];
  4550. if (source) {
  4551. assigner(object, source, index, customizer);
  4552. }
  4553. }
  4554. return object;
  4555. });
  4556. }
  4557. /**
  4558. * Creates a `baseEach` or `baseEachRight` function.
  4559. *
  4560. * @private
  4561. * @param {Function} eachFunc The function to iterate over a collection.
  4562. * @param {boolean} [fromRight] Specify iterating from right to left.
  4563. * @returns {Function} Returns the new base function.
  4564. */
  4565. function createBaseEach(eachFunc, fromRight) {
  4566. return function(collection, iteratee) {
  4567. if (collection == null) {
  4568. return collection;
  4569. }
  4570. if (!isArrayLike(collection)) {
  4571. return eachFunc(collection, iteratee);
  4572. }
  4573. var length = collection.length,
  4574. index = fromRight ? length : -1,
  4575. iterable = Object(collection);
  4576. while ((fromRight ? index-- : ++index < length)) {
  4577. if (iteratee(iterable[index], index, iterable) === false) {
  4578. break;
  4579. }
  4580. }
  4581. return collection;
  4582. };
  4583. }
  4584. /**
  4585. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4586. *
  4587. * @private
  4588. * @param {boolean} [fromRight] Specify iterating from right to left.
  4589. * @returns {Function} Returns the new base function.
  4590. */
  4591. function createBaseFor(fromRight) {
  4592. return function(object, iteratee, keysFunc) {
  4593. var index = -1,
  4594. iterable = Object(object),
  4595. props = keysFunc(object),
  4596. length = props.length;
  4597. while (length--) {
  4598. var key = props[fromRight ? length : ++index];
  4599. if (iteratee(iterable[key], key, iterable) === false) {
  4600. break;
  4601. }
  4602. }
  4603. return object;
  4604. };
  4605. }
  4606. /**
  4607. * Creates a function that wraps `func` to invoke it with the optional `this`
  4608. * binding of `thisArg`.
  4609. *
  4610. * @private
  4611. * @param {Function} func The function to wrap.
  4612. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4613. * @param {*} [thisArg] The `this` binding of `func`.
  4614. * @returns {Function} Returns the new wrapped function.
  4615. */
  4616. function createBind(func, bitmask, thisArg) {
  4617. var isBind = bitmask & WRAP_BIND_FLAG,
  4618. Ctor = createCtor(func);
  4619. function wrapper() {
  4620. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4621. return fn.apply(isBind ? thisArg : this, arguments);
  4622. }
  4623. return wrapper;
  4624. }
  4625. /**
  4626. * Creates a function like `_.lowerFirst`.
  4627. *
  4628. * @private
  4629. * @param {string} methodName The name of the `String` case method to use.
  4630. * @returns {Function} Returns the new case function.
  4631. */
  4632. function createCaseFirst(methodName) {
  4633. return function(string) {
  4634. string = toString(string);
  4635. var strSymbols = hasUnicode(string)
  4636. ? stringToArray(string)
  4637. : undefined;
  4638. var chr = strSymbols
  4639. ? strSymbols[0]
  4640. : string.charAt(0);
  4641. var trailing = strSymbols
  4642. ? castSlice(strSymbols, 1).join('')
  4643. : string.slice(1);
  4644. return chr[methodName]() + trailing;
  4645. };
  4646. }
  4647. /**
  4648. * Creates a function like `_.camelCase`.
  4649. *
  4650. * @private
  4651. * @param {Function} callback The function to combine each word.
  4652. * @returns {Function} Returns the new compounder function.
  4653. */
  4654. function createCompounder(callback) {
  4655. return function(string) {
  4656. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4657. };
  4658. }
  4659. /**
  4660. * Creates a function that produces an instance of `Ctor` regardless of
  4661. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4662. *
  4663. * @private
  4664. * @param {Function} Ctor The constructor to wrap.
  4665. * @returns {Function} Returns the new wrapped function.
  4666. */
  4667. function createCtor(Ctor) {
  4668. return function() {
  4669. // Use a `switch` statement to work with class constructors. See
  4670. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4671. // for more details.
  4672. var args = arguments;
  4673. switch (args.length) {
  4674. case 0: return new Ctor;
  4675. case 1: return new Ctor(args[0]);
  4676. case 2: return new Ctor(args[0], args[1]);
  4677. case 3: return new Ctor(args[0], args[1], args[2]);
  4678. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4679. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4680. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4681. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4682. }
  4683. var thisBinding = baseCreate(Ctor.prototype),
  4684. result = Ctor.apply(thisBinding, args);
  4685. // Mimic the constructor's `return` behavior.
  4686. // See https://es5.github.io/#x13.2.2 for more details.
  4687. return isObject(result) ? result : thisBinding;
  4688. };
  4689. }
  4690. /**
  4691. * Creates a function that wraps `func` to enable currying.
  4692. *
  4693. * @private
  4694. * @param {Function} func The function to wrap.
  4695. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4696. * @param {number} arity The arity of `func`.
  4697. * @returns {Function} Returns the new wrapped function.
  4698. */
  4699. function createCurry(func, bitmask, arity) {
  4700. var Ctor = createCtor(func);
  4701. function wrapper() {
  4702. var length = arguments.length,
  4703. args = Array(length),
  4704. index = length,
  4705. placeholder = getHolder(wrapper);
  4706. while (index--) {
  4707. args[index] = arguments[index];
  4708. }
  4709. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4710. ? []
  4711. : replaceHolders(args, placeholder);
  4712. length -= holders.length;
  4713. if (length < arity) {
  4714. return createRecurry(
  4715. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4716. args, holders, undefined, undefined, arity - length);
  4717. }
  4718. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4719. return apply(fn, this, args);
  4720. }
  4721. return wrapper;
  4722. }
  4723. /**
  4724. * Creates a `_.find` or `_.findLast` function.
  4725. *
  4726. * @private
  4727. * @param {Function} findIndexFunc The function to find the collection index.
  4728. * @returns {Function} Returns the new find function.
  4729. */
  4730. function createFind(findIndexFunc) {
  4731. return function(collection, predicate, fromIndex) {
  4732. var iterable = Object(collection);
  4733. if (!isArrayLike(collection)) {
  4734. var iteratee = getIteratee(predicate, 3);
  4735. collection = keys(collection);
  4736. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4737. }
  4738. var index = findIndexFunc(collection, predicate, fromIndex);
  4739. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4740. };
  4741. }
  4742. /**
  4743. * Creates a `_.flow` or `_.flowRight` function.
  4744. *
  4745. * @private
  4746. * @param {boolean} [fromRight] Specify iterating from right to left.
  4747. * @returns {Function} Returns the new flow function.
  4748. */
  4749. function createFlow(fromRight) {
  4750. return flatRest(function(funcs) {
  4751. var length = funcs.length,
  4752. index = length,
  4753. prereq = LodashWrapper.prototype.thru;
  4754. if (fromRight) {
  4755. funcs.reverse();
  4756. }
  4757. while (index--) {
  4758. var func = funcs[index];
  4759. if (typeof func != 'function') {
  4760. throw new TypeError(FUNC_ERROR_TEXT);
  4761. }
  4762. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4763. var wrapper = new LodashWrapper([], true);
  4764. }
  4765. }
  4766. index = wrapper ? index : length;
  4767. while (++index < length) {
  4768. func = funcs[index];
  4769. var funcName = getFuncName(func),
  4770. data = funcName == 'wrapper' ? getData(func) : undefined;
  4771. if (data && isLaziable(data[0]) &&
  4772. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4773. !data[4].length && data[9] == 1
  4774. ) {
  4775. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4776. } else {
  4777. wrapper = (func.length == 1 && isLaziable(func))
  4778. ? wrapper[funcName]()
  4779. : wrapper.thru(func);
  4780. }
  4781. }
  4782. return function() {
  4783. var args = arguments,
  4784. value = args[0];
  4785. if (wrapper && args.length == 1 && isArray(value)) {
  4786. return wrapper.plant(value).value();
  4787. }
  4788. var index = 0,
  4789. result = length ? funcs[index].apply(this, args) : value;
  4790. while (++index < length) {
  4791. result = funcs[index].call(this, result);
  4792. }
  4793. return result;
  4794. };
  4795. });
  4796. }
  4797. /**
  4798. * Creates a function that wraps `func` to invoke it with optional `this`
  4799. * binding of `thisArg`, partial application, and currying.
  4800. *
  4801. * @private
  4802. * @param {Function|string} func The function or method name to wrap.
  4803. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4804. * @param {*} [thisArg] The `this` binding of `func`.
  4805. * @param {Array} [partials] The arguments to prepend to those provided to
  4806. * the new function.
  4807. * @param {Array} [holders] The `partials` placeholder indexes.
  4808. * @param {Array} [partialsRight] The arguments to append to those provided
  4809. * to the new function.
  4810. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4811. * @param {Array} [argPos] The argument positions of the new function.
  4812. * @param {number} [ary] The arity cap of `func`.
  4813. * @param {number} [arity] The arity of `func`.
  4814. * @returns {Function} Returns the new wrapped function.
  4815. */
  4816. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4817. var isAry = bitmask & WRAP_ARY_FLAG,
  4818. isBind = bitmask & WRAP_BIND_FLAG,
  4819. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4820. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4821. isFlip = bitmask & WRAP_FLIP_FLAG,
  4822. Ctor = isBindKey ? undefined : createCtor(func);
  4823. function wrapper() {
  4824. var length = arguments.length,
  4825. args = Array(length),
  4826. index = length;
  4827. while (index--) {
  4828. args[index] = arguments[index];
  4829. }
  4830. if (isCurried) {
  4831. var placeholder = getHolder(wrapper),
  4832. holdersCount = countHolders(args, placeholder);
  4833. }
  4834. if (partials) {
  4835. args = composeArgs(args, partials, holders, isCurried);
  4836. }
  4837. if (partialsRight) {
  4838. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4839. }
  4840. length -= holdersCount;
  4841. if (isCurried && length < arity) {
  4842. var newHolders = replaceHolders(args, placeholder);
  4843. return createRecurry(
  4844. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4845. args, newHolders, argPos, ary, arity - length
  4846. );
  4847. }
  4848. var thisBinding = isBind ? thisArg : this,
  4849. fn = isBindKey ? thisBinding[func] : func;
  4850. length = args.length;
  4851. if (argPos) {
  4852. args = reorder(args, argPos);
  4853. } else if (isFlip && length > 1) {
  4854. args.reverse();
  4855. }
  4856. if (isAry && ary < length) {
  4857. args.length = ary;
  4858. }
  4859. if (this && this !== root && this instanceof wrapper) {
  4860. fn = Ctor || createCtor(fn);
  4861. }
  4862. return fn.apply(thisBinding, args);
  4863. }
  4864. return wrapper;
  4865. }
  4866. /**
  4867. * Creates a function like `_.invertBy`.
  4868. *
  4869. * @private
  4870. * @param {Function} setter The function to set accumulator values.
  4871. * @param {Function} toIteratee The function to resolve iteratees.
  4872. * @returns {Function} Returns the new inverter function.
  4873. */
  4874. function createInverter(setter, toIteratee) {
  4875. return function(object, iteratee) {
  4876. return baseInverter(object, setter, toIteratee(iteratee), {});
  4877. };
  4878. }
  4879. /**
  4880. * Creates a function that performs a mathematical operation on two values.
  4881. *
  4882. * @private
  4883. * @param {Function} operator The function to perform the operation.
  4884. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4885. * @returns {Function} Returns the new mathematical operation function.
  4886. */
  4887. function createMathOperation(operator, defaultValue) {
  4888. return function(value, other) {
  4889. var result;
  4890. if (value === undefined && other === undefined) {
  4891. return defaultValue;
  4892. }
  4893. if (value !== undefined) {
  4894. result = value;
  4895. }
  4896. if (other !== undefined) {
  4897. if (result === undefined) {
  4898. return other;
  4899. }
  4900. if (typeof value == 'string' || typeof other == 'string') {
  4901. value = baseToString(value);
  4902. other = baseToString(other);
  4903. } else {
  4904. value = baseToNumber(value);
  4905. other = baseToNumber(other);
  4906. }
  4907. result = operator(value, other);
  4908. }
  4909. return result;
  4910. };
  4911. }
  4912. /**
  4913. * Creates a function like `_.over`.
  4914. *
  4915. * @private
  4916. * @param {Function} arrayFunc The function to iterate over iteratees.
  4917. * @returns {Function} Returns the new over function.
  4918. */
  4919. function createOver(arrayFunc) {
  4920. return flatRest(function(iteratees) {
  4921. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4922. return baseRest(function(args) {
  4923. var thisArg = this;
  4924. return arrayFunc(iteratees, function(iteratee) {
  4925. return apply(iteratee, thisArg, args);
  4926. });
  4927. });
  4928. });
  4929. }
  4930. /**
  4931. * Creates the padding for `string` based on `length`. The `chars` string
  4932. * is truncated if the number of characters exceeds `length`.
  4933. *
  4934. * @private
  4935. * @param {number} length The padding length.
  4936. * @param {string} [chars=' '] The string used as padding.
  4937. * @returns {string} Returns the padding for `string`.
  4938. */
  4939. function createPadding(length, chars) {
  4940. chars = chars === undefined ? ' ' : baseToString(chars);
  4941. var charsLength = chars.length;
  4942. if (charsLength < 2) {
  4943. return charsLength ? baseRepeat(chars, length) : chars;
  4944. }
  4945. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4946. return hasUnicode(chars)
  4947. ? castSlice(stringToArray(result), 0, length).join('')
  4948. : result.slice(0, length);
  4949. }
  4950. /**
  4951. * Creates a function that wraps `func` to invoke it with the `this` binding
  4952. * of `thisArg` and `partials` prepended to the arguments it receives.
  4953. *
  4954. * @private
  4955. * @param {Function} func The function to wrap.
  4956. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4957. * @param {*} thisArg The `this` binding of `func`.
  4958. * @param {Array} partials The arguments to prepend to those provided to
  4959. * the new function.
  4960. * @returns {Function} Returns the new wrapped function.
  4961. */
  4962. function createPartial(func, bitmask, thisArg, partials) {
  4963. var isBind = bitmask & WRAP_BIND_FLAG,
  4964. Ctor = createCtor(func);
  4965. function wrapper() {
  4966. var argsIndex = -1,
  4967. argsLength = arguments.length,
  4968. leftIndex = -1,
  4969. leftLength = partials.length,
  4970. args = Array(leftLength + argsLength),
  4971. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4972. while (++leftIndex < leftLength) {
  4973. args[leftIndex] = partials[leftIndex];
  4974. }
  4975. while (argsLength--) {
  4976. args[leftIndex++] = arguments[++argsIndex];
  4977. }
  4978. return apply(fn, isBind ? thisArg : this, args);
  4979. }
  4980. return wrapper;
  4981. }
  4982. /**
  4983. * Creates a `_.range` or `_.rangeRight` function.
  4984. *
  4985. * @private
  4986. * @param {boolean} [fromRight] Specify iterating from right to left.
  4987. * @returns {Function} Returns the new range function.
  4988. */
  4989. function createRange(fromRight) {
  4990. return function(start, end, step) {
  4991. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4992. end = step = undefined;
  4993. }
  4994. // Ensure the sign of `-0` is preserved.
  4995. start = toFinite(start);
  4996. if (end === undefined) {
  4997. end = start;
  4998. start = 0;
  4999. } else {
  5000. end = toFinite(end);
  5001. }
  5002. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  5003. return baseRange(start, end, step, fromRight);
  5004. };
  5005. }
  5006. /**
  5007. * Creates a function that performs a relational operation on two values.
  5008. *
  5009. * @private
  5010. * @param {Function} operator The function to perform the operation.
  5011. * @returns {Function} Returns the new relational operation function.
  5012. */
  5013. function createRelationalOperation(operator) {
  5014. return function(value, other) {
  5015. if (!(typeof value == 'string' && typeof other == 'string')) {
  5016. value = toNumber(value);
  5017. other = toNumber(other);
  5018. }
  5019. return operator(value, other);
  5020. };
  5021. }
  5022. /**
  5023. * Creates a function that wraps `func` to continue currying.
  5024. *
  5025. * @private
  5026. * @param {Function} func The function to wrap.
  5027. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  5028. * @param {Function} wrapFunc The function to create the `func` wrapper.
  5029. * @param {*} placeholder The placeholder value.
  5030. * @param {*} [thisArg] The `this` binding of `func`.
  5031. * @param {Array} [partials] The arguments to prepend to those provided to
  5032. * the new function.
  5033. * @param {Array} [holders] The `partials` placeholder indexes.
  5034. * @param {Array} [argPos] The argument positions of the new function.
  5035. * @param {number} [ary] The arity cap of `func`.
  5036. * @param {number} [arity] The arity of `func`.
  5037. * @returns {Function} Returns the new wrapped function.
  5038. */
  5039. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  5040. var isCurry = bitmask & WRAP_CURRY_FLAG,
  5041. newHolders = isCurry ? holders : undefined,
  5042. newHoldersRight = isCurry ? undefined : holders,
  5043. newPartials = isCurry ? partials : undefined,
  5044. newPartialsRight = isCurry ? undefined : partials;
  5045. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  5046. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  5047. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  5048. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  5049. }
  5050. var newData = [
  5051. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  5052. newHoldersRight, argPos, ary, arity
  5053. ];
  5054. var result = wrapFunc.apply(undefined, newData);
  5055. if (isLaziable(func)) {
  5056. setData(result, newData);
  5057. }
  5058. result.placeholder = placeholder;
  5059. return setWrapToString(result, func, bitmask);
  5060. }
  5061. /**
  5062. * Creates a function like `_.round`.
  5063. *
  5064. * @private
  5065. * @param {string} methodName The name of the `Math` method to use when rounding.
  5066. * @returns {Function} Returns the new round function.
  5067. */
  5068. function createRound(methodName) {
  5069. var func = Math[methodName];
  5070. return function(number, precision) {
  5071. number = toNumber(number);
  5072. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  5073. if (precision) {
  5074. // Shift with exponential notation to avoid floating-point issues.
  5075. // See [MDN](https://mdn.io/round#Examples) for more details.
  5076. var pair = (toString(number) + 'e').split('e'),
  5077. value = func(pair[0] + 'e' + (+pair[1] + precision));
  5078. pair = (toString(value) + 'e').split('e');
  5079. return +(pair[0] + 'e' + (+pair[1] - precision));
  5080. }
  5081. return func(number);
  5082. };
  5083. }
  5084. /**
  5085. * Creates a set object of `values`.
  5086. *
  5087. * @private
  5088. * @param {Array} values The values to add to the set.
  5089. * @returns {Object} Returns the new set.
  5090. */
  5091. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  5092. return new Set(values);
  5093. };
  5094. /**
  5095. * Creates a `_.toPairs` or `_.toPairsIn` function.
  5096. *
  5097. * @private
  5098. * @param {Function} keysFunc The function to get the keys of a given object.
  5099. * @returns {Function} Returns the new pairs function.
  5100. */
  5101. function createToPairs(keysFunc) {
  5102. return function(object) {
  5103. var tag = getTag(object);
  5104. if (tag == mapTag) {
  5105. return mapToArray(object);
  5106. }
  5107. if (tag == setTag) {
  5108. return setToPairs(object);
  5109. }
  5110. return baseToPairs(object, keysFunc(object));
  5111. };
  5112. }
  5113. /**
  5114. * Creates a function that either curries or invokes `func` with optional
  5115. * `this` binding and partially applied arguments.
  5116. *
  5117. * @private
  5118. * @param {Function|string} func The function or method name to wrap.
  5119. * @param {number} bitmask The bitmask flags.
  5120. * 1 - `_.bind`
  5121. * 2 - `_.bindKey`
  5122. * 4 - `_.curry` or `_.curryRight` of a bound function
  5123. * 8 - `_.curry`
  5124. * 16 - `_.curryRight`
  5125. * 32 - `_.partial`
  5126. * 64 - `_.partialRight`
  5127. * 128 - `_.rearg`
  5128. * 256 - `_.ary`
  5129. * 512 - `_.flip`
  5130. * @param {*} [thisArg] The `this` binding of `func`.
  5131. * @param {Array} [partials] The arguments to be partially applied.
  5132. * @param {Array} [holders] The `partials` placeholder indexes.
  5133. * @param {Array} [argPos] The argument positions of the new function.
  5134. * @param {number} [ary] The arity cap of `func`.
  5135. * @param {number} [arity] The arity of `func`.
  5136. * @returns {Function} Returns the new wrapped function.
  5137. */
  5138. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5139. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5140. if (!isBindKey && typeof func != 'function') {
  5141. throw new TypeError(FUNC_ERROR_TEXT);
  5142. }
  5143. var length = partials ? partials.length : 0;
  5144. if (!length) {
  5145. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5146. partials = holders = undefined;
  5147. }
  5148. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5149. arity = arity === undefined ? arity : toInteger(arity);
  5150. length -= holders ? holders.length : 0;
  5151. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5152. var partialsRight = partials,
  5153. holdersRight = holders;
  5154. partials = holders = undefined;
  5155. }
  5156. var data = isBindKey ? undefined : getData(func);
  5157. var newData = [
  5158. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5159. argPos, ary, arity
  5160. ];
  5161. if (data) {
  5162. mergeData(newData, data);
  5163. }
  5164. func = newData[0];
  5165. bitmask = newData[1];
  5166. thisArg = newData[2];
  5167. partials = newData[3];
  5168. holders = newData[4];
  5169. arity = newData[9] = newData[9] === undefined
  5170. ? (isBindKey ? 0 : func.length)
  5171. : nativeMax(newData[9] - length, 0);
  5172. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5173. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5174. }
  5175. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5176. var result = createBind(func, bitmask, thisArg);
  5177. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5178. result = createCurry(func, bitmask, arity);
  5179. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5180. result = createPartial(func, bitmask, thisArg, partials);
  5181. } else {
  5182. result = createHybrid.apply(undefined, newData);
  5183. }
  5184. var setter = data ? baseSetData : setData;
  5185. return setWrapToString(setter(result, newData), func, bitmask);
  5186. }
  5187. /**
  5188. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5189. * of source objects to the destination object for all destination properties
  5190. * that resolve to `undefined`.
  5191. *
  5192. * @private
  5193. * @param {*} objValue The destination value.
  5194. * @param {*} srcValue The source value.
  5195. * @param {string} key The key of the property to assign.
  5196. * @param {Object} object The parent object of `objValue`.
  5197. * @returns {*} Returns the value to assign.
  5198. */
  5199. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5200. if (objValue === undefined ||
  5201. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5202. return srcValue;
  5203. }
  5204. return objValue;
  5205. }
  5206. /**
  5207. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5208. * objects into destination objects that are passed thru.
  5209. *
  5210. * @private
  5211. * @param {*} objValue The destination value.
  5212. * @param {*} srcValue The source value.
  5213. * @param {string} key The key of the property to merge.
  5214. * @param {Object} object The parent object of `objValue`.
  5215. * @param {Object} source The parent object of `srcValue`.
  5216. * @param {Object} [stack] Tracks traversed source values and their merged
  5217. * counterparts.
  5218. * @returns {*} Returns the value to assign.
  5219. */
  5220. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5221. if (isObject(objValue) && isObject(srcValue)) {
  5222. // Recursively merge objects and arrays (susceptible to call stack limits).
  5223. stack.set(srcValue, objValue);
  5224. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5225. stack['delete'](srcValue);
  5226. }
  5227. return objValue;
  5228. }
  5229. /**
  5230. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5231. * objects.
  5232. *
  5233. * @private
  5234. * @param {*} value The value to inspect.
  5235. * @param {string} key The key of the property to inspect.
  5236. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5237. */
  5238. function customOmitClone(value) {
  5239. return isPlainObject(value) ? undefined : value;
  5240. }
  5241. /**
  5242. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5243. * partial deep comparisons.
  5244. *
  5245. * @private
  5246. * @param {Array} array The array to compare.
  5247. * @param {Array} other The other array to compare.
  5248. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5249. * @param {Function} customizer The function to customize comparisons.
  5250. * @param {Function} equalFunc The function to determine equivalents of values.
  5251. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5252. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5253. */
  5254. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5255. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5256. arrLength = array.length,
  5257. othLength = other.length;
  5258. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5259. return false;
  5260. }
  5261. // Assume cyclic values are equal.
  5262. var stacked = stack.get(array);
  5263. if (stacked && stack.get(other)) {
  5264. return stacked == other;
  5265. }
  5266. var index = -1,
  5267. result = true,
  5268. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5269. stack.set(array, other);
  5270. stack.set(other, array);
  5271. // Ignore non-index properties.
  5272. while (++index < arrLength) {
  5273. var arrValue = array[index],
  5274. othValue = other[index];
  5275. if (customizer) {
  5276. var compared = isPartial
  5277. ? customizer(othValue, arrValue, index, other, array, stack)
  5278. : customizer(arrValue, othValue, index, array, other, stack);
  5279. }
  5280. if (compared !== undefined) {
  5281. if (compared) {
  5282. continue;
  5283. }
  5284. result = false;
  5285. break;
  5286. }
  5287. // Recursively compare arrays (susceptible to call stack limits).
  5288. if (seen) {
  5289. if (!arraySome(other, function(othValue, othIndex) {
  5290. if (!cacheHas(seen, othIndex) &&
  5291. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5292. return seen.push(othIndex);
  5293. }
  5294. })) {
  5295. result = false;
  5296. break;
  5297. }
  5298. } else if (!(
  5299. arrValue === othValue ||
  5300. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5301. )) {
  5302. result = false;
  5303. break;
  5304. }
  5305. }
  5306. stack['delete'](array);
  5307. stack['delete'](other);
  5308. return result;
  5309. }
  5310. /**
  5311. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5312. * the same `toStringTag`.
  5313. *
  5314. * **Note:** This function only supports comparing values with tags of
  5315. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5316. *
  5317. * @private
  5318. * @param {Object} object The object to compare.
  5319. * @param {Object} other The other object to compare.
  5320. * @param {string} tag The `toStringTag` of the objects to compare.
  5321. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5322. * @param {Function} customizer The function to customize comparisons.
  5323. * @param {Function} equalFunc The function to determine equivalents of values.
  5324. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5325. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5326. */
  5327. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5328. switch (tag) {
  5329. case dataViewTag:
  5330. if ((object.byteLength != other.byteLength) ||
  5331. (object.byteOffset != other.byteOffset)) {
  5332. return false;
  5333. }
  5334. object = object.buffer;
  5335. other = other.buffer;
  5336. case arrayBufferTag:
  5337. if ((object.byteLength != other.byteLength) ||
  5338. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5339. return false;
  5340. }
  5341. return true;
  5342. case boolTag:
  5343. case dateTag:
  5344. case numberTag:
  5345. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5346. // Invalid dates are coerced to `NaN`.
  5347. return eq(+object, +other);
  5348. case errorTag:
  5349. return object.name == other.name && object.message == other.message;
  5350. case regexpTag:
  5351. case stringTag:
  5352. // Coerce regexes to strings and treat strings, primitives and objects,
  5353. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5354. // for more details.
  5355. return object == (other + '');
  5356. case mapTag:
  5357. var convert = mapToArray;
  5358. case setTag:
  5359. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5360. convert || (convert = setToArray);
  5361. if (object.size != other.size && !isPartial) {
  5362. return false;
  5363. }
  5364. // Assume cyclic values are equal.
  5365. var stacked = stack.get(object);
  5366. if (stacked) {
  5367. return stacked == other;
  5368. }
  5369. bitmask |= COMPARE_UNORDERED_FLAG;
  5370. // Recursively compare objects (susceptible to call stack limits).
  5371. stack.set(object, other);
  5372. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5373. stack['delete'](object);
  5374. return result;
  5375. case symbolTag:
  5376. if (symbolValueOf) {
  5377. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5378. }
  5379. }
  5380. return false;
  5381. }
  5382. /**
  5383. * A specialized version of `baseIsEqualDeep` for objects with support for
  5384. * partial deep comparisons.
  5385. *
  5386. * @private
  5387. * @param {Object} object The object to compare.
  5388. * @param {Object} other The other object to compare.
  5389. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5390. * @param {Function} customizer The function to customize comparisons.
  5391. * @param {Function} equalFunc The function to determine equivalents of values.
  5392. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5393. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5394. */
  5395. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5396. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5397. objProps = getAllKeys(object),
  5398. objLength = objProps.length,
  5399. othProps = getAllKeys(other),
  5400. othLength = othProps.length;
  5401. if (objLength != othLength && !isPartial) {
  5402. return false;
  5403. }
  5404. var index = objLength;
  5405. while (index--) {
  5406. var key = objProps[index];
  5407. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5408. return false;
  5409. }
  5410. }
  5411. // Assume cyclic values are equal.
  5412. var stacked = stack.get(object);
  5413. if (stacked && stack.get(other)) {
  5414. return stacked == other;
  5415. }
  5416. var result = true;
  5417. stack.set(object, other);
  5418. stack.set(other, object);
  5419. var skipCtor = isPartial;
  5420. while (++index < objLength) {
  5421. key = objProps[index];
  5422. var objValue = object[key],
  5423. othValue = other[key];
  5424. if (customizer) {
  5425. var compared = isPartial
  5426. ? customizer(othValue, objValue, key, other, object, stack)
  5427. : customizer(objValue, othValue, key, object, other, stack);
  5428. }
  5429. // Recursively compare objects (susceptible to call stack limits).
  5430. if (!(compared === undefined
  5431. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5432. : compared
  5433. )) {
  5434. result = false;
  5435. break;
  5436. }
  5437. skipCtor || (skipCtor = key == 'constructor');
  5438. }
  5439. if (result && !skipCtor) {
  5440. var objCtor = object.constructor,
  5441. othCtor = other.constructor;
  5442. // Non `Object` object instances with different constructors are not equal.
  5443. if (objCtor != othCtor &&
  5444. ('constructor' in object && 'constructor' in other) &&
  5445. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5446. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5447. result = false;
  5448. }
  5449. }
  5450. stack['delete'](object);
  5451. stack['delete'](other);
  5452. return result;
  5453. }
  5454. /**
  5455. * A specialized version of `baseRest` which flattens the rest array.
  5456. *
  5457. * @private
  5458. * @param {Function} func The function to apply a rest parameter to.
  5459. * @returns {Function} Returns the new function.
  5460. */
  5461. function flatRest(func) {
  5462. return setToString(overRest(func, undefined, flatten), func + '');
  5463. }
  5464. /**
  5465. * Creates an array of own enumerable property names and symbols of `object`.
  5466. *
  5467. * @private
  5468. * @param {Object} object The object to query.
  5469. * @returns {Array} Returns the array of property names and symbols.
  5470. */
  5471. function getAllKeys(object) {
  5472. return baseGetAllKeys(object, keys, getSymbols);
  5473. }
  5474. /**
  5475. * Creates an array of own and inherited enumerable property names and
  5476. * symbols of `object`.
  5477. *
  5478. * @private
  5479. * @param {Object} object The object to query.
  5480. * @returns {Array} Returns the array of property names and symbols.
  5481. */
  5482. function getAllKeysIn(object) {
  5483. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5484. }
  5485. /**
  5486. * Gets metadata for `func`.
  5487. *
  5488. * @private
  5489. * @param {Function} func The function to query.
  5490. * @returns {*} Returns the metadata for `func`.
  5491. */
  5492. var getData = !metaMap ? noop : function(func) {
  5493. return metaMap.get(func);
  5494. };
  5495. /**
  5496. * Gets the name of `func`.
  5497. *
  5498. * @private
  5499. * @param {Function} func The function to query.
  5500. * @returns {string} Returns the function name.
  5501. */
  5502. function getFuncName(func) {
  5503. var result = (func.name + ''),
  5504. array = realNames[result],
  5505. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5506. while (length--) {
  5507. var data = array[length],
  5508. otherFunc = data.func;
  5509. if (otherFunc == null || otherFunc == func) {
  5510. return data.name;
  5511. }
  5512. }
  5513. return result;
  5514. }
  5515. /**
  5516. * Gets the argument placeholder value for `func`.
  5517. *
  5518. * @private
  5519. * @param {Function} func The function to inspect.
  5520. * @returns {*} Returns the placeholder value.
  5521. */
  5522. function getHolder(func) {
  5523. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5524. return object.placeholder;
  5525. }
  5526. /**
  5527. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5528. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5529. * If arguments are provided, the chosen function is invoked with them and
  5530. * its result is returned.
  5531. *
  5532. * @private
  5533. * @param {*} [value] The value to convert to an iteratee.
  5534. * @param {number} [arity] The arity of the created iteratee.
  5535. * @returns {Function} Returns the chosen function or its result.
  5536. */
  5537. function getIteratee() {
  5538. var result = lodash.iteratee || iteratee;
  5539. result = result === iteratee ? baseIteratee : result;
  5540. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5541. }
  5542. /**
  5543. * Gets the data for `map`.
  5544. *
  5545. * @private
  5546. * @param {Object} map The map to query.
  5547. * @param {string} key The reference key.
  5548. * @returns {*} Returns the map data.
  5549. */
  5550. function getMapData(map, key) {
  5551. var data = map.__data__;
  5552. return isKeyable(key)
  5553. ? data[typeof key == 'string' ? 'string' : 'hash']
  5554. : data.map;
  5555. }
  5556. /**
  5557. * Gets the property names, values, and compare flags of `object`.
  5558. *
  5559. * @private
  5560. * @param {Object} object The object to query.
  5561. * @returns {Array} Returns the match data of `object`.
  5562. */
  5563. function getMatchData(object) {
  5564. var result = keys(object),
  5565. length = result.length;
  5566. while (length--) {
  5567. var key = result[length],
  5568. value = object[key];
  5569. result[length] = [key, value, isStrictComparable(value)];
  5570. }
  5571. return result;
  5572. }
  5573. /**
  5574. * Gets the native function at `key` of `object`.
  5575. *
  5576. * @private
  5577. * @param {Object} object The object to query.
  5578. * @param {string} key The key of the method to get.
  5579. * @returns {*} Returns the function if it's native, else `undefined`.
  5580. */
  5581. function getNative(object, key) {
  5582. var value = getValue(object, key);
  5583. return baseIsNative(value) ? value : undefined;
  5584. }
  5585. /**
  5586. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5587. *
  5588. * @private
  5589. * @param {*} value The value to query.
  5590. * @returns {string} Returns the raw `toStringTag`.
  5591. */
  5592. function getRawTag(value) {
  5593. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5594. tag = value[symToStringTag];
  5595. try {
  5596. value[symToStringTag] = undefined;
  5597. var unmasked = true;
  5598. } catch (e) {}
  5599. var result = nativeObjectToString.call(value);
  5600. if (unmasked) {
  5601. if (isOwn) {
  5602. value[symToStringTag] = tag;
  5603. } else {
  5604. delete value[symToStringTag];
  5605. }
  5606. }
  5607. return result;
  5608. }
  5609. /**
  5610. * Creates an array of the own enumerable symbols of `object`.
  5611. *
  5612. * @private
  5613. * @param {Object} object The object to query.
  5614. * @returns {Array} Returns the array of symbols.
  5615. */
  5616. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5617. if (object == null) {
  5618. return [];
  5619. }
  5620. object = Object(object);
  5621. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5622. return propertyIsEnumerable.call(object, symbol);
  5623. });
  5624. };
  5625. /**
  5626. * Creates an array of the own and inherited enumerable symbols of `object`.
  5627. *
  5628. * @private
  5629. * @param {Object} object The object to query.
  5630. * @returns {Array} Returns the array of symbols.
  5631. */
  5632. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5633. var result = [];
  5634. while (object) {
  5635. arrayPush(result, getSymbols(object));
  5636. object = getPrototype(object);
  5637. }
  5638. return result;
  5639. };
  5640. /**
  5641. * Gets the `toStringTag` of `value`.
  5642. *
  5643. * @private
  5644. * @param {*} value The value to query.
  5645. * @returns {string} Returns the `toStringTag`.
  5646. */
  5647. var getTag = baseGetTag;
  5648. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5649. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5650. (Map && getTag(new Map) != mapTag) ||
  5651. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5652. (Set && getTag(new Set) != setTag) ||
  5653. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5654. getTag = function(value) {
  5655. var result = baseGetTag(value),
  5656. Ctor = result == objectTag ? value.constructor : undefined,
  5657. ctorString = Ctor ? toSource(Ctor) : '';
  5658. if (ctorString) {
  5659. switch (ctorString) {
  5660. case dataViewCtorString: return dataViewTag;
  5661. case mapCtorString: return mapTag;
  5662. case promiseCtorString: return promiseTag;
  5663. case setCtorString: return setTag;
  5664. case weakMapCtorString: return weakMapTag;
  5665. }
  5666. }
  5667. return result;
  5668. };
  5669. }
  5670. /**
  5671. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5672. *
  5673. * @private
  5674. * @param {number} start The start of the view.
  5675. * @param {number} end The end of the view.
  5676. * @param {Array} transforms The transformations to apply to the view.
  5677. * @returns {Object} Returns an object containing the `start` and `end`
  5678. * positions of the view.
  5679. */
  5680. function getView(start, end, transforms) {
  5681. var index = -1,
  5682. length = transforms.length;
  5683. while (++index < length) {
  5684. var data = transforms[index],
  5685. size = data.size;
  5686. switch (data.type) {
  5687. case 'drop': start += size; break;
  5688. case 'dropRight': end -= size; break;
  5689. case 'take': end = nativeMin(end, start + size); break;
  5690. case 'takeRight': start = nativeMax(start, end - size); break;
  5691. }
  5692. }
  5693. return { 'start': start, 'end': end };
  5694. }
  5695. /**
  5696. * Extracts wrapper details from the `source` body comment.
  5697. *
  5698. * @private
  5699. * @param {string} source The source to inspect.
  5700. * @returns {Array} Returns the wrapper details.
  5701. */
  5702. function getWrapDetails(source) {
  5703. var match = source.match(reWrapDetails);
  5704. return match ? match[1].split(reSplitDetails) : [];
  5705. }
  5706. /**
  5707. * Checks if `path` exists on `object`.
  5708. *
  5709. * @private
  5710. * @param {Object} object The object to query.
  5711. * @param {Array|string} path The path to check.
  5712. * @param {Function} hasFunc The function to check properties.
  5713. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5714. */
  5715. function hasPath(object, path, hasFunc) {
  5716. path = castPath(path, object);
  5717. var index = -1,
  5718. length = path.length,
  5719. result = false;
  5720. while (++index < length) {
  5721. var key = toKey(path[index]);
  5722. if (!(result = object != null && hasFunc(object, key))) {
  5723. break;
  5724. }
  5725. object = object[key];
  5726. }
  5727. if (result || ++index != length) {
  5728. return result;
  5729. }
  5730. length = object == null ? 0 : object.length;
  5731. return !!length && isLength(length) && isIndex(key, length) &&
  5732. (isArray(object) || isArguments(object));
  5733. }
  5734. /**
  5735. * Initializes an array clone.
  5736. *
  5737. * @private
  5738. * @param {Array} array The array to clone.
  5739. * @returns {Array} Returns the initialized clone.
  5740. */
  5741. function initCloneArray(array) {
  5742. var length = array.length,
  5743. result = array.constructor(length);
  5744. // Add properties assigned by `RegExp#exec`.
  5745. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5746. result.index = array.index;
  5747. result.input = array.input;
  5748. }
  5749. return result;
  5750. }
  5751. /**
  5752. * Initializes an object clone.
  5753. *
  5754. * @private
  5755. * @param {Object} object The object to clone.
  5756. * @returns {Object} Returns the initialized clone.
  5757. */
  5758. function initCloneObject(object) {
  5759. return (typeof object.constructor == 'function' && !isPrototype(object))
  5760. ? baseCreate(getPrototype(object))
  5761. : {};
  5762. }
  5763. /**
  5764. * Initializes an object clone based on its `toStringTag`.
  5765. *
  5766. * **Note:** This function only supports cloning values with tags of
  5767. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5768. *
  5769. * @private
  5770. * @param {Object} object The object to clone.
  5771. * @param {string} tag The `toStringTag` of the object to clone.
  5772. * @param {Function} cloneFunc The function to clone values.
  5773. * @param {boolean} [isDeep] Specify a deep clone.
  5774. * @returns {Object} Returns the initialized clone.
  5775. */
  5776. function initCloneByTag(object, tag, cloneFunc, isDeep) {
  5777. var Ctor = object.constructor;
  5778. switch (tag) {
  5779. case arrayBufferTag:
  5780. return cloneArrayBuffer(object);
  5781. case boolTag:
  5782. case dateTag:
  5783. return new Ctor(+object);
  5784. case dataViewTag:
  5785. return cloneDataView(object, isDeep);
  5786. case float32Tag: case float64Tag:
  5787. case int8Tag: case int16Tag: case int32Tag:
  5788. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5789. return cloneTypedArray(object, isDeep);
  5790. case mapTag:
  5791. return cloneMap(object, isDeep, cloneFunc);
  5792. case numberTag:
  5793. case stringTag:
  5794. return new Ctor(object);
  5795. case regexpTag:
  5796. return cloneRegExp(object);
  5797. case setTag:
  5798. return cloneSet(object, isDeep, cloneFunc);
  5799. case symbolTag:
  5800. return cloneSymbol(object);
  5801. }
  5802. }
  5803. /**
  5804. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5805. *
  5806. * @private
  5807. * @param {string} source The source to modify.
  5808. * @returns {Array} details The details to insert.
  5809. * @returns {string} Returns the modified source.
  5810. */
  5811. function insertWrapDetails(source, details) {
  5812. var length = details.length;
  5813. if (!length) {
  5814. return source;
  5815. }
  5816. var lastIndex = length - 1;
  5817. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5818. details = details.join(length > 2 ? ', ' : ' ');
  5819. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5820. }
  5821. /**
  5822. * Checks if `value` is a flattenable `arguments` object or array.
  5823. *
  5824. * @private
  5825. * @param {*} value The value to check.
  5826. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5827. */
  5828. function isFlattenable(value) {
  5829. return isArray(value) || isArguments(value) ||
  5830. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5831. }
  5832. /**
  5833. * Checks if `value` is a valid array-like index.
  5834. *
  5835. * @private
  5836. * @param {*} value The value to check.
  5837. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5838. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5839. */
  5840. function isIndex(value, length) {
  5841. length = length == null ? MAX_SAFE_INTEGER : length;
  5842. return !!length &&
  5843. (typeof value == 'number' || reIsUint.test(value)) &&
  5844. (value > -1 && value % 1 == 0 && value < length);
  5845. }
  5846. /**
  5847. * Checks if the given arguments are from an iteratee call.
  5848. *
  5849. * @private
  5850. * @param {*} value The potential iteratee value argument.
  5851. * @param {*} index The potential iteratee index or key argument.
  5852. * @param {*} object The potential iteratee object argument.
  5853. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5854. * else `false`.
  5855. */
  5856. function isIterateeCall(value, index, object) {
  5857. if (!isObject(object)) {
  5858. return false;
  5859. }
  5860. var type = typeof index;
  5861. if (type == 'number'
  5862. ? (isArrayLike(object) && isIndex(index, object.length))
  5863. : (type == 'string' && index in object)
  5864. ) {
  5865. return eq(object[index], value);
  5866. }
  5867. return false;
  5868. }
  5869. /**
  5870. * Checks if `value` is a property name and not a property path.
  5871. *
  5872. * @private
  5873. * @param {*} value The value to check.
  5874. * @param {Object} [object] The object to query keys on.
  5875. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5876. */
  5877. function isKey(value, object) {
  5878. if (isArray(value)) {
  5879. return false;
  5880. }
  5881. var type = typeof value;
  5882. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5883. value == null || isSymbol(value)) {
  5884. return true;
  5885. }
  5886. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5887. (object != null && value in Object(object));
  5888. }
  5889. /**
  5890. * Checks if `value` is suitable for use as unique object key.
  5891. *
  5892. * @private
  5893. * @param {*} value The value to check.
  5894. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5895. */
  5896. function isKeyable(value) {
  5897. var type = typeof value;
  5898. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5899. ? (value !== '__proto__')
  5900. : (value === null);
  5901. }
  5902. /**
  5903. * Checks if `func` has a lazy counterpart.
  5904. *
  5905. * @private
  5906. * @param {Function} func The function to check.
  5907. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5908. * else `false`.
  5909. */
  5910. function isLaziable(func) {
  5911. var funcName = getFuncName(func),
  5912. other = lodash[funcName];
  5913. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5914. return false;
  5915. }
  5916. if (func === other) {
  5917. return true;
  5918. }
  5919. var data = getData(other);
  5920. return !!data && func === data[0];
  5921. }
  5922. /**
  5923. * Checks if `func` has its source masked.
  5924. *
  5925. * @private
  5926. * @param {Function} func The function to check.
  5927. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5928. */
  5929. function isMasked(func) {
  5930. return !!maskSrcKey && (maskSrcKey in func);
  5931. }
  5932. /**
  5933. * Checks if `func` is capable of being masked.
  5934. *
  5935. * @private
  5936. * @param {*} value The value to check.
  5937. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5938. */
  5939. var isMaskable = coreJsData ? isFunction : stubFalse;
  5940. /**
  5941. * Checks if `value` is likely a prototype object.
  5942. *
  5943. * @private
  5944. * @param {*} value The value to check.
  5945. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5946. */
  5947. function isPrototype(value) {
  5948. var Ctor = value && value.constructor,
  5949. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5950. return value === proto;
  5951. }
  5952. /**
  5953. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5954. *
  5955. * @private
  5956. * @param {*} value The value to check.
  5957. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5958. * equality comparisons, else `false`.
  5959. */
  5960. function isStrictComparable(value) {
  5961. return value === value && !isObject(value);
  5962. }
  5963. /**
  5964. * A specialized version of `matchesProperty` for source values suitable
  5965. * for strict equality comparisons, i.e. `===`.
  5966. *
  5967. * @private
  5968. * @param {string} key The key of the property to get.
  5969. * @param {*} srcValue The value to match.
  5970. * @returns {Function} Returns the new spec function.
  5971. */
  5972. function matchesStrictComparable(key, srcValue) {
  5973. return function(object) {
  5974. if (object == null) {
  5975. return false;
  5976. }
  5977. return object[key] === srcValue &&
  5978. (srcValue !== undefined || (key in Object(object)));
  5979. };
  5980. }
  5981. /**
  5982. * A specialized version of `_.memoize` which clears the memoized function's
  5983. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5984. *
  5985. * @private
  5986. * @param {Function} func The function to have its output memoized.
  5987. * @returns {Function} Returns the new memoized function.
  5988. */
  5989. function memoizeCapped(func) {
  5990. var result = memoize(func, function(key) {
  5991. if (cache.size === MAX_MEMOIZE_SIZE) {
  5992. cache.clear();
  5993. }
  5994. return key;
  5995. });
  5996. var cache = result.cache;
  5997. return result;
  5998. }
  5999. /**
  6000. * Merges the function metadata of `source` into `data`.
  6001. *
  6002. * Merging metadata reduces the number of wrappers used to invoke a function.
  6003. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  6004. * may be applied regardless of execution order. Methods like `_.ary` and
  6005. * `_.rearg` modify function arguments, making the order in which they are
  6006. * executed important, preventing the merging of metadata. However, we make
  6007. * an exception for a safe combined case where curried functions have `_.ary`
  6008. * and or `_.rearg` applied.
  6009. *
  6010. * @private
  6011. * @param {Array} data The destination metadata.
  6012. * @param {Array} source The source metadata.
  6013. * @returns {Array} Returns `data`.
  6014. */
  6015. function mergeData(data, source) {
  6016. var bitmask = data[1],
  6017. srcBitmask = source[1],
  6018. newBitmask = bitmask | srcBitmask,
  6019. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  6020. var isCombo =
  6021. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  6022. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  6023. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  6024. // Exit early if metadata can't be merged.
  6025. if (!(isCommon || isCombo)) {
  6026. return data;
  6027. }
  6028. // Use source `thisArg` if available.
  6029. if (srcBitmask & WRAP_BIND_FLAG) {
  6030. data[2] = source[2];
  6031. // Set when currying a bound function.
  6032. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  6033. }
  6034. // Compose partial arguments.
  6035. var value = source[3];
  6036. if (value) {
  6037. var partials = data[3];
  6038. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  6039. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  6040. }
  6041. // Compose partial right arguments.
  6042. value = source[5];
  6043. if (value) {
  6044. partials = data[5];
  6045. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  6046. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  6047. }
  6048. // Use source `argPos` if available.
  6049. value = source[7];
  6050. if (value) {
  6051. data[7] = value;
  6052. }
  6053. // Use source `ary` if it's smaller.
  6054. if (srcBitmask & WRAP_ARY_FLAG) {
  6055. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  6056. }
  6057. // Use source `arity` if one is not provided.
  6058. if (data[9] == null) {
  6059. data[9] = source[9];
  6060. }
  6061. // Use source `func` and merge bitmasks.
  6062. data[0] = source[0];
  6063. data[1] = newBitmask;
  6064. return data;
  6065. }
  6066. /**
  6067. * This function is like
  6068. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  6069. * except that it includes inherited enumerable properties.
  6070. *
  6071. * @private
  6072. * @param {Object} object The object to query.
  6073. * @returns {Array} Returns the array of property names.
  6074. */
  6075. function nativeKeysIn(object) {
  6076. var result = [];
  6077. if (object != null) {
  6078. for (var key in Object(object)) {
  6079. result.push(key);
  6080. }
  6081. }
  6082. return result;
  6083. }
  6084. /**
  6085. * Converts `value` to a string using `Object.prototype.toString`.
  6086. *
  6087. * @private
  6088. * @param {*} value The value to convert.
  6089. * @returns {string} Returns the converted string.
  6090. */
  6091. function objectToString(value) {
  6092. return nativeObjectToString.call(value);
  6093. }
  6094. /**
  6095. * A specialized version of `baseRest` which transforms the rest array.
  6096. *
  6097. * @private
  6098. * @param {Function} func The function to apply a rest parameter to.
  6099. * @param {number} [start=func.length-1] The start position of the rest parameter.
  6100. * @param {Function} transform The rest array transform.
  6101. * @returns {Function} Returns the new function.
  6102. */
  6103. function overRest(func, start, transform) {
  6104. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  6105. return function() {
  6106. var args = arguments,
  6107. index = -1,
  6108. length = nativeMax(args.length - start, 0),
  6109. array = Array(length);
  6110. while (++index < length) {
  6111. array[index] = args[start + index];
  6112. }
  6113. index = -1;
  6114. var otherArgs = Array(start + 1);
  6115. while (++index < start) {
  6116. otherArgs[index] = args[index];
  6117. }
  6118. otherArgs[start] = transform(array);
  6119. return apply(func, this, otherArgs);
  6120. };
  6121. }
  6122. /**
  6123. * Gets the parent value at `path` of `object`.
  6124. *
  6125. * @private
  6126. * @param {Object} object The object to query.
  6127. * @param {Array} path The path to get the parent value of.
  6128. * @returns {*} Returns the parent value.
  6129. */
  6130. function parent(object, path) {
  6131. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6132. }
  6133. /**
  6134. * Reorder `array` according to the specified indexes where the element at
  6135. * the first index is assigned as the first element, the element at
  6136. * the second index is assigned as the second element, and so on.
  6137. *
  6138. * @private
  6139. * @param {Array} array The array to reorder.
  6140. * @param {Array} indexes The arranged array indexes.
  6141. * @returns {Array} Returns `array`.
  6142. */
  6143. function reorder(array, indexes) {
  6144. var arrLength = array.length,
  6145. length = nativeMin(indexes.length, arrLength),
  6146. oldArray = copyArray(array);
  6147. while (length--) {
  6148. var index = indexes[length];
  6149. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6150. }
  6151. return array;
  6152. }
  6153. /**
  6154. * Sets metadata for `func`.
  6155. *
  6156. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6157. * period of time, it will trip its breaker and transition to an identity
  6158. * function to avoid garbage collection pauses in V8. See
  6159. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6160. * for more details.
  6161. *
  6162. * @private
  6163. * @param {Function} func The function to associate metadata with.
  6164. * @param {*} data The metadata.
  6165. * @returns {Function} Returns `func`.
  6166. */
  6167. var setData = shortOut(baseSetData);
  6168. /**
  6169. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6170. *
  6171. * @private
  6172. * @param {Function} func The function to delay.
  6173. * @param {number} wait The number of milliseconds to delay invocation.
  6174. * @returns {number|Object} Returns the timer id or timeout object.
  6175. */
  6176. var setTimeout = ctxSetTimeout || function(func, wait) {
  6177. return root.setTimeout(func, wait);
  6178. };
  6179. /**
  6180. * Sets the `toString` method of `func` to return `string`.
  6181. *
  6182. * @private
  6183. * @param {Function} func The function to modify.
  6184. * @param {Function} string The `toString` result.
  6185. * @returns {Function} Returns `func`.
  6186. */
  6187. var setToString = shortOut(baseSetToString);
  6188. /**
  6189. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6190. * with wrapper details in a comment at the top of the source body.
  6191. *
  6192. * @private
  6193. * @param {Function} wrapper The function to modify.
  6194. * @param {Function} reference The reference function.
  6195. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6196. * @returns {Function} Returns `wrapper`.
  6197. */
  6198. function setWrapToString(wrapper, reference, bitmask) {
  6199. var source = (reference + '');
  6200. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6201. }
  6202. /**
  6203. * Creates a function that'll short out and invoke `identity` instead
  6204. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6205. * milliseconds.
  6206. *
  6207. * @private
  6208. * @param {Function} func The function to restrict.
  6209. * @returns {Function} Returns the new shortable function.
  6210. */
  6211. function shortOut(func) {
  6212. var count = 0,
  6213. lastCalled = 0;
  6214. return function() {
  6215. var stamp = nativeNow(),
  6216. remaining = HOT_SPAN - (stamp - lastCalled);
  6217. lastCalled = stamp;
  6218. if (remaining > 0) {
  6219. if (++count >= HOT_COUNT) {
  6220. return arguments[0];
  6221. }
  6222. } else {
  6223. count = 0;
  6224. }
  6225. return func.apply(undefined, arguments);
  6226. };
  6227. }
  6228. /**
  6229. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6230. *
  6231. * @private
  6232. * @param {Array} array The array to shuffle.
  6233. * @param {number} [size=array.length] The size of `array`.
  6234. * @returns {Array} Returns `array`.
  6235. */
  6236. function shuffleSelf(array, size) {
  6237. var index = -1,
  6238. length = array.length,
  6239. lastIndex = length - 1;
  6240. size = size === undefined ? length : size;
  6241. while (++index < size) {
  6242. var rand = baseRandom(index, lastIndex),
  6243. value = array[rand];
  6244. array[rand] = array[index];
  6245. array[index] = value;
  6246. }
  6247. array.length = size;
  6248. return array;
  6249. }
  6250. /**
  6251. * Converts `string` to a property path array.
  6252. *
  6253. * @private
  6254. * @param {string} string The string to convert.
  6255. * @returns {Array} Returns the property path array.
  6256. */
  6257. var stringToPath = memoizeCapped(function(string) {
  6258. var result = [];
  6259. if (reLeadingDot.test(string)) {
  6260. result.push('');
  6261. }
  6262. string.replace(rePropName, function(match, number, quote, string) {
  6263. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  6264. });
  6265. return result;
  6266. });
  6267. /**
  6268. * Converts `value` to a string key if it's not a string or symbol.
  6269. *
  6270. * @private
  6271. * @param {*} value The value to inspect.
  6272. * @returns {string|symbol} Returns the key.
  6273. */
  6274. function toKey(value) {
  6275. if (typeof value == 'string' || isSymbol(value)) {
  6276. return value;
  6277. }
  6278. var result = (value + '');
  6279. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6280. }
  6281. /**
  6282. * Converts `func` to its source code.
  6283. *
  6284. * @private
  6285. * @param {Function} func The function to convert.
  6286. * @returns {string} Returns the source code.
  6287. */
  6288. function toSource(func) {
  6289. if (func != null) {
  6290. try {
  6291. return funcToString.call(func);
  6292. } catch (e) {}
  6293. try {
  6294. return (func + '');
  6295. } catch (e) {}
  6296. }
  6297. return '';
  6298. }
  6299. /**
  6300. * Updates wrapper `details` based on `bitmask` flags.
  6301. *
  6302. * @private
  6303. * @returns {Array} details The details to modify.
  6304. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6305. * @returns {Array} Returns `details`.
  6306. */
  6307. function updateWrapDetails(details, bitmask) {
  6308. arrayEach(wrapFlags, function(pair) {
  6309. var value = '_.' + pair[0];
  6310. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6311. details.push(value);
  6312. }
  6313. });
  6314. return details.sort();
  6315. }
  6316. /**
  6317. * Creates a clone of `wrapper`.
  6318. *
  6319. * @private
  6320. * @param {Object} wrapper The wrapper to clone.
  6321. * @returns {Object} Returns the cloned wrapper.
  6322. */
  6323. function wrapperClone(wrapper) {
  6324. if (wrapper instanceof LazyWrapper) {
  6325. return wrapper.clone();
  6326. }
  6327. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6328. result.__actions__ = copyArray(wrapper.__actions__);
  6329. result.__index__ = wrapper.__index__;
  6330. result.__values__ = wrapper.__values__;
  6331. return result;
  6332. }
  6333. /*------------------------------------------------------------------------*/
  6334. /**
  6335. * Creates an array of elements split into groups the length of `size`.
  6336. * If `array` can't be split evenly, the final chunk will be the remaining
  6337. * elements.
  6338. *
  6339. * @static
  6340. * @memberOf _
  6341. * @since 3.0.0
  6342. * @category Array
  6343. * @param {Array} array The array to process.
  6344. * @param {number} [size=1] The length of each chunk
  6345. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6346. * @returns {Array} Returns the new array of chunks.
  6347. * @example
  6348. *
  6349. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6350. * // => [['a', 'b'], ['c', 'd']]
  6351. *
  6352. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6353. * // => [['a', 'b', 'c'], ['d']]
  6354. */
  6355. function chunk(array, size, guard) {
  6356. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6357. size = 1;
  6358. } else {
  6359. size = nativeMax(toInteger(size), 0);
  6360. }
  6361. var length = array == null ? 0 : array.length;
  6362. if (!length || size < 1) {
  6363. return [];
  6364. }
  6365. var index = 0,
  6366. resIndex = 0,
  6367. result = Array(nativeCeil(length / size));
  6368. while (index < length) {
  6369. result[resIndex++] = baseSlice(array, index, (index += size));
  6370. }
  6371. return result;
  6372. }
  6373. /**
  6374. * Creates an array with all falsey values removed. The values `false`, `null`,
  6375. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6376. *
  6377. * @static
  6378. * @memberOf _
  6379. * @since 0.1.0
  6380. * @category Array
  6381. * @param {Array} array The array to compact.
  6382. * @returns {Array} Returns the new array of filtered values.
  6383. * @example
  6384. *
  6385. * _.compact([0, 1, false, 2, '', 3]);
  6386. * // => [1, 2, 3]
  6387. */
  6388. function compact(array) {
  6389. var index = -1,
  6390. length = array == null ? 0 : array.length,
  6391. resIndex = 0,
  6392. result = [];
  6393. while (++index < length) {
  6394. var value = array[index];
  6395. if (value) {
  6396. result[resIndex++] = value;
  6397. }
  6398. }
  6399. return result;
  6400. }
  6401. /**
  6402. * Creates a new array concatenating `array` with any additional arrays
  6403. * and/or values.
  6404. *
  6405. * @static
  6406. * @memberOf _
  6407. * @since 4.0.0
  6408. * @category Array
  6409. * @param {Array} array The array to concatenate.
  6410. * @param {...*} [values] The values to concatenate.
  6411. * @returns {Array} Returns the new concatenated array.
  6412. * @example
  6413. *
  6414. * var array = [1];
  6415. * var other = _.concat(array, 2, [3], [[4]]);
  6416. *
  6417. * console.log(other);
  6418. * // => [1, 2, 3, [4]]
  6419. *
  6420. * console.log(array);
  6421. * // => [1]
  6422. */
  6423. function concat() {
  6424. var length = arguments.length;
  6425. if (!length) {
  6426. return [];
  6427. }
  6428. var args = Array(length - 1),
  6429. array = arguments[0],
  6430. index = length;
  6431. while (index--) {
  6432. args[index - 1] = arguments[index];
  6433. }
  6434. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6435. }
  6436. /**
  6437. * Creates an array of `array` values not included in the other given arrays
  6438. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6439. * for equality comparisons. The order and references of result values are
  6440. * determined by the first array.
  6441. *
  6442. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6443. *
  6444. * @static
  6445. * @memberOf _
  6446. * @since 0.1.0
  6447. * @category Array
  6448. * @param {Array} array The array to inspect.
  6449. * @param {...Array} [values] The values to exclude.
  6450. * @returns {Array} Returns the new array of filtered values.
  6451. * @see _.without, _.xor
  6452. * @example
  6453. *
  6454. * _.difference([2, 1], [2, 3]);
  6455. * // => [1]
  6456. */
  6457. var difference = baseRest(function(array, values) {
  6458. return isArrayLikeObject(array)
  6459. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6460. : [];
  6461. });
  6462. /**
  6463. * This method is like `_.difference` except that it accepts `iteratee` which
  6464. * is invoked for each element of `array` and `values` to generate the criterion
  6465. * by which they're compared. The order and references of result values are
  6466. * determined by the first array. The iteratee is invoked with one argument:
  6467. * (value).
  6468. *
  6469. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6470. *
  6471. * @static
  6472. * @memberOf _
  6473. * @since 4.0.0
  6474. * @category Array
  6475. * @param {Array} array The array to inspect.
  6476. * @param {...Array} [values] The values to exclude.
  6477. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6478. * @returns {Array} Returns the new array of filtered values.
  6479. * @example
  6480. *
  6481. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6482. * // => [1.2]
  6483. *
  6484. * // The `_.property` iteratee shorthand.
  6485. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6486. * // => [{ 'x': 2 }]
  6487. */
  6488. var differenceBy = baseRest(function(array, values) {
  6489. var iteratee = last(values);
  6490. if (isArrayLikeObject(iteratee)) {
  6491. iteratee = undefined;
  6492. }
  6493. return isArrayLikeObject(array)
  6494. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6495. : [];
  6496. });
  6497. /**
  6498. * This method is like `_.difference` except that it accepts `comparator`
  6499. * which is invoked to compare elements of `array` to `values`. The order and
  6500. * references of result values are determined by the first array. The comparator
  6501. * is invoked with two arguments: (arrVal, othVal).
  6502. *
  6503. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6504. *
  6505. * @static
  6506. * @memberOf _
  6507. * @since 4.0.0
  6508. * @category Array
  6509. * @param {Array} array The array to inspect.
  6510. * @param {...Array} [values] The values to exclude.
  6511. * @param {Function} [comparator] The comparator invoked per element.
  6512. * @returns {Array} Returns the new array of filtered values.
  6513. * @example
  6514. *
  6515. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6516. *
  6517. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6518. * // => [{ 'x': 2, 'y': 1 }]
  6519. */
  6520. var differenceWith = baseRest(function(array, values) {
  6521. var comparator = last(values);
  6522. if (isArrayLikeObject(comparator)) {
  6523. comparator = undefined;
  6524. }
  6525. return isArrayLikeObject(array)
  6526. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6527. : [];
  6528. });
  6529. /**
  6530. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6531. *
  6532. * @static
  6533. * @memberOf _
  6534. * @since 0.5.0
  6535. * @category Array
  6536. * @param {Array} array The array to query.
  6537. * @param {number} [n=1] The number of elements to drop.
  6538. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6539. * @returns {Array} Returns the slice of `array`.
  6540. * @example
  6541. *
  6542. * _.drop([1, 2, 3]);
  6543. * // => [2, 3]
  6544. *
  6545. * _.drop([1, 2, 3], 2);
  6546. * // => [3]
  6547. *
  6548. * _.drop([1, 2, 3], 5);
  6549. * // => []
  6550. *
  6551. * _.drop([1, 2, 3], 0);
  6552. * // => [1, 2, 3]
  6553. */
  6554. function drop(array, n, guard) {
  6555. var length = array == null ? 0 : array.length;
  6556. if (!length) {
  6557. return [];
  6558. }
  6559. n = (guard || n === undefined) ? 1 : toInteger(n);
  6560. return baseSlice(array, n < 0 ? 0 : n, length);
  6561. }
  6562. /**
  6563. * Creates a slice of `array` with `n` elements dropped from the end.
  6564. *
  6565. * @static
  6566. * @memberOf _
  6567. * @since 3.0.0
  6568. * @category Array
  6569. * @param {Array} array The array to query.
  6570. * @param {number} [n=1] The number of elements to drop.
  6571. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6572. * @returns {Array} Returns the slice of `array`.
  6573. * @example
  6574. *
  6575. * _.dropRight([1, 2, 3]);
  6576. * // => [1, 2]
  6577. *
  6578. * _.dropRight([1, 2, 3], 2);
  6579. * // => [1]
  6580. *
  6581. * _.dropRight([1, 2, 3], 5);
  6582. * // => []
  6583. *
  6584. * _.dropRight([1, 2, 3], 0);
  6585. * // => [1, 2, 3]
  6586. */
  6587. function dropRight(array, n, guard) {
  6588. var length = array == null ? 0 : array.length;
  6589. if (!length) {
  6590. return [];
  6591. }
  6592. n = (guard || n === undefined) ? 1 : toInteger(n);
  6593. n = length - n;
  6594. return baseSlice(array, 0, n < 0 ? 0 : n);
  6595. }
  6596. /**
  6597. * Creates a slice of `array` excluding elements dropped from the end.
  6598. * Elements are dropped until `predicate` returns falsey. The predicate is
  6599. * invoked with three arguments: (value, index, array).
  6600. *
  6601. * @static
  6602. * @memberOf _
  6603. * @since 3.0.0
  6604. * @category Array
  6605. * @param {Array} array The array to query.
  6606. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6607. * @returns {Array} Returns the slice of `array`.
  6608. * @example
  6609. *
  6610. * var users = [
  6611. * { 'user': 'barney', 'active': true },
  6612. * { 'user': 'fred', 'active': false },
  6613. * { 'user': 'pebbles', 'active': false }
  6614. * ];
  6615. *
  6616. * _.dropRightWhile(users, function(o) { return !o.active; });
  6617. * // => objects for ['barney']
  6618. *
  6619. * // The `_.matches` iteratee shorthand.
  6620. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6621. * // => objects for ['barney', 'fred']
  6622. *
  6623. * // The `_.matchesProperty` iteratee shorthand.
  6624. * _.dropRightWhile(users, ['active', false]);
  6625. * // => objects for ['barney']
  6626. *
  6627. * // The `_.property` iteratee shorthand.
  6628. * _.dropRightWhile(users, 'active');
  6629. * // => objects for ['barney', 'fred', 'pebbles']
  6630. */
  6631. function dropRightWhile(array, predicate) {
  6632. return (array && array.length)
  6633. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6634. : [];
  6635. }
  6636. /**
  6637. * Creates a slice of `array` excluding elements dropped from the beginning.
  6638. * Elements are dropped until `predicate` returns falsey. The predicate is
  6639. * invoked with three arguments: (value, index, array).
  6640. *
  6641. * @static
  6642. * @memberOf _
  6643. * @since 3.0.0
  6644. * @category Array
  6645. * @param {Array} array The array to query.
  6646. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6647. * @returns {Array} Returns the slice of `array`.
  6648. * @example
  6649. *
  6650. * var users = [
  6651. * { 'user': 'barney', 'active': false },
  6652. * { 'user': 'fred', 'active': false },
  6653. * { 'user': 'pebbles', 'active': true }
  6654. * ];
  6655. *
  6656. * _.dropWhile(users, function(o) { return !o.active; });
  6657. * // => objects for ['pebbles']
  6658. *
  6659. * // The `_.matches` iteratee shorthand.
  6660. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6661. * // => objects for ['fred', 'pebbles']
  6662. *
  6663. * // The `_.matchesProperty` iteratee shorthand.
  6664. * _.dropWhile(users, ['active', false]);
  6665. * // => objects for ['pebbles']
  6666. *
  6667. * // The `_.property` iteratee shorthand.
  6668. * _.dropWhile(users, 'active');
  6669. * // => objects for ['barney', 'fred', 'pebbles']
  6670. */
  6671. function dropWhile(array, predicate) {
  6672. return (array && array.length)
  6673. ? baseWhile(array, getIteratee(predicate, 3), true)
  6674. : [];
  6675. }
  6676. /**
  6677. * Fills elements of `array` with `value` from `start` up to, but not
  6678. * including, `end`.
  6679. *
  6680. * **Note:** This method mutates `array`.
  6681. *
  6682. * @static
  6683. * @memberOf _
  6684. * @since 3.2.0
  6685. * @category Array
  6686. * @param {Array} array The array to fill.
  6687. * @param {*} value The value to fill `array` with.
  6688. * @param {number} [start=0] The start position.
  6689. * @param {number} [end=array.length] The end position.
  6690. * @returns {Array} Returns `array`.
  6691. * @example
  6692. *
  6693. * var array = [1, 2, 3];
  6694. *
  6695. * _.fill(array, 'a');
  6696. * console.log(array);
  6697. * // => ['a', 'a', 'a']
  6698. *
  6699. * _.fill(Array(3), 2);
  6700. * // => [2, 2, 2]
  6701. *
  6702. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6703. * // => [4, '*', '*', 10]
  6704. */
  6705. function fill(array, value, start, end) {
  6706. var length = array == null ? 0 : array.length;
  6707. if (!length) {
  6708. return [];
  6709. }
  6710. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6711. start = 0;
  6712. end = length;
  6713. }
  6714. return baseFill(array, value, start, end);
  6715. }
  6716. /**
  6717. * This method is like `_.find` except that it returns the index of the first
  6718. * element `predicate` returns truthy for instead of the element itself.
  6719. *
  6720. * @static
  6721. * @memberOf _
  6722. * @since 1.1.0
  6723. * @category Array
  6724. * @param {Array} array The array to inspect.
  6725. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6726. * @param {number} [fromIndex=0] The index to search from.
  6727. * @returns {number} Returns the index of the found element, else `-1`.
  6728. * @example
  6729. *
  6730. * var users = [
  6731. * { 'user': 'barney', 'active': false },
  6732. * { 'user': 'fred', 'active': false },
  6733. * { 'user': 'pebbles', 'active': true }
  6734. * ];
  6735. *
  6736. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6737. * // => 0
  6738. *
  6739. * // The `_.matches` iteratee shorthand.
  6740. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6741. * // => 1
  6742. *
  6743. * // The `_.matchesProperty` iteratee shorthand.
  6744. * _.findIndex(users, ['active', false]);
  6745. * // => 0
  6746. *
  6747. * // The `_.property` iteratee shorthand.
  6748. * _.findIndex(users, 'active');
  6749. * // => 2
  6750. */
  6751. function findIndex(array, predicate, fromIndex) {
  6752. var length = array == null ? 0 : array.length;
  6753. if (!length) {
  6754. return -1;
  6755. }
  6756. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6757. if (index < 0) {
  6758. index = nativeMax(length + index, 0);
  6759. }
  6760. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6761. }
  6762. /**
  6763. * This method is like `_.findIndex` except that it iterates over elements
  6764. * of `collection` from right to left.
  6765. *
  6766. * @static
  6767. * @memberOf _
  6768. * @since 2.0.0
  6769. * @category Array
  6770. * @param {Array} array The array to inspect.
  6771. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6772. * @param {number} [fromIndex=array.length-1] The index to search from.
  6773. * @returns {number} Returns the index of the found element, else `-1`.
  6774. * @example
  6775. *
  6776. * var users = [
  6777. * { 'user': 'barney', 'active': true },
  6778. * { 'user': 'fred', 'active': false },
  6779. * { 'user': 'pebbles', 'active': false }
  6780. * ];
  6781. *
  6782. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6783. * // => 2
  6784. *
  6785. * // The `_.matches` iteratee shorthand.
  6786. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6787. * // => 0
  6788. *
  6789. * // The `_.matchesProperty` iteratee shorthand.
  6790. * _.findLastIndex(users, ['active', false]);
  6791. * // => 2
  6792. *
  6793. * // The `_.property` iteratee shorthand.
  6794. * _.findLastIndex(users, 'active');
  6795. * // => 0
  6796. */
  6797. function findLastIndex(array, predicate, fromIndex) {
  6798. var length = array == null ? 0 : array.length;
  6799. if (!length) {
  6800. return -1;
  6801. }
  6802. var index = length - 1;
  6803. if (fromIndex !== undefined) {
  6804. index = toInteger(fromIndex);
  6805. index = fromIndex < 0
  6806. ? nativeMax(length + index, 0)
  6807. : nativeMin(index, length - 1);
  6808. }
  6809. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6810. }
  6811. /**
  6812. * Flattens `array` a single level deep.
  6813. *
  6814. * @static
  6815. * @memberOf _
  6816. * @since 0.1.0
  6817. * @category Array
  6818. * @param {Array} array The array to flatten.
  6819. * @returns {Array} Returns the new flattened array.
  6820. * @example
  6821. *
  6822. * _.flatten([1, [2, [3, [4]], 5]]);
  6823. * // => [1, 2, [3, [4]], 5]
  6824. */
  6825. function flatten(array) {
  6826. var length = array == null ? 0 : array.length;
  6827. return length ? baseFlatten(array, 1) : [];
  6828. }
  6829. /**
  6830. * Recursively flattens `array`.
  6831. *
  6832. * @static
  6833. * @memberOf _
  6834. * @since 3.0.0
  6835. * @category Array
  6836. * @param {Array} array The array to flatten.
  6837. * @returns {Array} Returns the new flattened array.
  6838. * @example
  6839. *
  6840. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6841. * // => [1, 2, 3, 4, 5]
  6842. */
  6843. function flattenDeep(array) {
  6844. var length = array == null ? 0 : array.length;
  6845. return length ? baseFlatten(array, INFINITY) : [];
  6846. }
  6847. /**
  6848. * Recursively flatten `array` up to `depth` times.
  6849. *
  6850. * @static
  6851. * @memberOf _
  6852. * @since 4.4.0
  6853. * @category Array
  6854. * @param {Array} array The array to flatten.
  6855. * @param {number} [depth=1] The maximum recursion depth.
  6856. * @returns {Array} Returns the new flattened array.
  6857. * @example
  6858. *
  6859. * var array = [1, [2, [3, [4]], 5]];
  6860. *
  6861. * _.flattenDepth(array, 1);
  6862. * // => [1, 2, [3, [4]], 5]
  6863. *
  6864. * _.flattenDepth(array, 2);
  6865. * // => [1, 2, 3, [4], 5]
  6866. */
  6867. function flattenDepth(array, depth) {
  6868. var length = array == null ? 0 : array.length;
  6869. if (!length) {
  6870. return [];
  6871. }
  6872. depth = depth === undefined ? 1 : toInteger(depth);
  6873. return baseFlatten(array, depth);
  6874. }
  6875. /**
  6876. * The inverse of `_.toPairs`; this method returns an object composed
  6877. * from key-value `pairs`.
  6878. *
  6879. * @static
  6880. * @memberOf _
  6881. * @since 4.0.0
  6882. * @category Array
  6883. * @param {Array} pairs The key-value pairs.
  6884. * @returns {Object} Returns the new object.
  6885. * @example
  6886. *
  6887. * _.fromPairs([['a', 1], ['b', 2]]);
  6888. * // => { 'a': 1, 'b': 2 }
  6889. */
  6890. function fromPairs(pairs) {
  6891. var index = -1,
  6892. length = pairs == null ? 0 : pairs.length,
  6893. result = {};
  6894. while (++index < length) {
  6895. var pair = pairs[index];
  6896. result[pair[0]] = pair[1];
  6897. }
  6898. return result;
  6899. }
  6900. /**
  6901. * Gets the first element of `array`.
  6902. *
  6903. * @static
  6904. * @memberOf _
  6905. * @since 0.1.0
  6906. * @alias first
  6907. * @category Array
  6908. * @param {Array} array The array to query.
  6909. * @returns {*} Returns the first element of `array`.
  6910. * @example
  6911. *
  6912. * _.head([1, 2, 3]);
  6913. * // => 1
  6914. *
  6915. * _.head([]);
  6916. * // => undefined
  6917. */
  6918. function head(array) {
  6919. return (array && array.length) ? array[0] : undefined;
  6920. }
  6921. /**
  6922. * Gets the index at which the first occurrence of `value` is found in `array`
  6923. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6924. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6925. * offset from the end of `array`.
  6926. *
  6927. * @static
  6928. * @memberOf _
  6929. * @since 0.1.0
  6930. * @category Array
  6931. * @param {Array} array The array to inspect.
  6932. * @param {*} value The value to search for.
  6933. * @param {number} [fromIndex=0] The index to search from.
  6934. * @returns {number} Returns the index of the matched value, else `-1`.
  6935. * @example
  6936. *
  6937. * _.indexOf([1, 2, 1, 2], 2);
  6938. * // => 1
  6939. *
  6940. * // Search from the `fromIndex`.
  6941. * _.indexOf([1, 2, 1, 2], 2, 2);
  6942. * // => 3
  6943. */
  6944. function indexOf(array, value, fromIndex) {
  6945. var length = array == null ? 0 : array.length;
  6946. if (!length) {
  6947. return -1;
  6948. }
  6949. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6950. if (index < 0) {
  6951. index = nativeMax(length + index, 0);
  6952. }
  6953. return baseIndexOf(array, value, index);
  6954. }
  6955. /**
  6956. * Gets all but the last element of `array`.
  6957. *
  6958. * @static
  6959. * @memberOf _
  6960. * @since 0.1.0
  6961. * @category Array
  6962. * @param {Array} array The array to query.
  6963. * @returns {Array} Returns the slice of `array`.
  6964. * @example
  6965. *
  6966. * _.initial([1, 2, 3]);
  6967. * // => [1, 2]
  6968. */
  6969. function initial(array) {
  6970. var length = array == null ? 0 : array.length;
  6971. return length ? baseSlice(array, 0, -1) : [];
  6972. }
  6973. /**
  6974. * Creates an array of unique values that are included in all given arrays
  6975. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6976. * for equality comparisons. The order and references of result values are
  6977. * determined by the first array.
  6978. *
  6979. * @static
  6980. * @memberOf _
  6981. * @since 0.1.0
  6982. * @category Array
  6983. * @param {...Array} [arrays] The arrays to inspect.
  6984. * @returns {Array} Returns the new array of intersecting values.
  6985. * @example
  6986. *
  6987. * _.intersection([2, 1], [2, 3]);
  6988. * // => [2]
  6989. */
  6990. var intersection = baseRest(function(arrays) {
  6991. var mapped = arrayMap(arrays, castArrayLikeObject);
  6992. return (mapped.length && mapped[0] === arrays[0])
  6993. ? baseIntersection(mapped)
  6994. : [];
  6995. });
  6996. /**
  6997. * This method is like `_.intersection` except that it accepts `iteratee`
  6998. * which is invoked for each element of each `arrays` to generate the criterion
  6999. * by which they're compared. The order and references of result values are
  7000. * determined by the first array. The iteratee is invoked with one argument:
  7001. * (value).
  7002. *
  7003. * @static
  7004. * @memberOf _
  7005. * @since 4.0.0
  7006. * @category Array
  7007. * @param {...Array} [arrays] The arrays to inspect.
  7008. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7009. * @returns {Array} Returns the new array of intersecting values.
  7010. * @example
  7011. *
  7012. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7013. * // => [2.1]
  7014. *
  7015. * // The `_.property` iteratee shorthand.
  7016. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7017. * // => [{ 'x': 1 }]
  7018. */
  7019. var intersectionBy = baseRest(function(arrays) {
  7020. var iteratee = last(arrays),
  7021. mapped = arrayMap(arrays, castArrayLikeObject);
  7022. if (iteratee === last(mapped)) {
  7023. iteratee = undefined;
  7024. } else {
  7025. mapped.pop();
  7026. }
  7027. return (mapped.length && mapped[0] === arrays[0])
  7028. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  7029. : [];
  7030. });
  7031. /**
  7032. * This method is like `_.intersection` except that it accepts `comparator`
  7033. * which is invoked to compare elements of `arrays`. The order and references
  7034. * of result values are determined by the first array. The comparator is
  7035. * invoked with two arguments: (arrVal, othVal).
  7036. *
  7037. * @static
  7038. * @memberOf _
  7039. * @since 4.0.0
  7040. * @category Array
  7041. * @param {...Array} [arrays] The arrays to inspect.
  7042. * @param {Function} [comparator] The comparator invoked per element.
  7043. * @returns {Array} Returns the new array of intersecting values.
  7044. * @example
  7045. *
  7046. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7047. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7048. *
  7049. * _.intersectionWith(objects, others, _.isEqual);
  7050. * // => [{ 'x': 1, 'y': 2 }]
  7051. */
  7052. var intersectionWith = baseRest(function(arrays) {
  7053. var comparator = last(arrays),
  7054. mapped = arrayMap(arrays, castArrayLikeObject);
  7055. comparator = typeof comparator == 'function' ? comparator : undefined;
  7056. if (comparator) {
  7057. mapped.pop();
  7058. }
  7059. return (mapped.length && mapped[0] === arrays[0])
  7060. ? baseIntersection(mapped, undefined, comparator)
  7061. : [];
  7062. });
  7063. /**
  7064. * Converts all elements in `array` into a string separated by `separator`.
  7065. *
  7066. * @static
  7067. * @memberOf _
  7068. * @since 4.0.0
  7069. * @category Array
  7070. * @param {Array} array The array to convert.
  7071. * @param {string} [separator=','] The element separator.
  7072. * @returns {string} Returns the joined string.
  7073. * @example
  7074. *
  7075. * _.join(['a', 'b', 'c'], '~');
  7076. * // => 'a~b~c'
  7077. */
  7078. function join(array, separator) {
  7079. return array == null ? '' : nativeJoin.call(array, separator);
  7080. }
  7081. /**
  7082. * Gets the last element of `array`.
  7083. *
  7084. * @static
  7085. * @memberOf _
  7086. * @since 0.1.0
  7087. * @category Array
  7088. * @param {Array} array The array to query.
  7089. * @returns {*} Returns the last element of `array`.
  7090. * @example
  7091. *
  7092. * _.last([1, 2, 3]);
  7093. * // => 3
  7094. */
  7095. function last(array) {
  7096. var length = array == null ? 0 : array.length;
  7097. return length ? array[length - 1] : undefined;
  7098. }
  7099. /**
  7100. * This method is like `_.indexOf` except that it iterates over elements of
  7101. * `array` from right to left.
  7102. *
  7103. * @static
  7104. * @memberOf _
  7105. * @since 0.1.0
  7106. * @category Array
  7107. * @param {Array} array The array to inspect.
  7108. * @param {*} value The value to search for.
  7109. * @param {number} [fromIndex=array.length-1] The index to search from.
  7110. * @returns {number} Returns the index of the matched value, else `-1`.
  7111. * @example
  7112. *
  7113. * _.lastIndexOf([1, 2, 1, 2], 2);
  7114. * // => 3
  7115. *
  7116. * // Search from the `fromIndex`.
  7117. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7118. * // => 1
  7119. */
  7120. function lastIndexOf(array, value, fromIndex) {
  7121. var length = array == null ? 0 : array.length;
  7122. if (!length) {
  7123. return -1;
  7124. }
  7125. var index = length;
  7126. if (fromIndex !== undefined) {
  7127. index = toInteger(fromIndex);
  7128. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7129. }
  7130. return value === value
  7131. ? strictLastIndexOf(array, value, index)
  7132. : baseFindIndex(array, baseIsNaN, index, true);
  7133. }
  7134. /**
  7135. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7136. * element from the end is returned.
  7137. *
  7138. * @static
  7139. * @memberOf _
  7140. * @since 4.11.0
  7141. * @category Array
  7142. * @param {Array} array The array to query.
  7143. * @param {number} [n=0] The index of the element to return.
  7144. * @returns {*} Returns the nth element of `array`.
  7145. * @example
  7146. *
  7147. * var array = ['a', 'b', 'c', 'd'];
  7148. *
  7149. * _.nth(array, 1);
  7150. * // => 'b'
  7151. *
  7152. * _.nth(array, -2);
  7153. * // => 'c';
  7154. */
  7155. function nth(array, n) {
  7156. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7157. }
  7158. /**
  7159. * Removes all given values from `array` using
  7160. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7161. * for equality comparisons.
  7162. *
  7163. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7164. * to remove elements from an array by predicate.
  7165. *
  7166. * @static
  7167. * @memberOf _
  7168. * @since 2.0.0
  7169. * @category Array
  7170. * @param {Array} array The array to modify.
  7171. * @param {...*} [values] The values to remove.
  7172. * @returns {Array} Returns `array`.
  7173. * @example
  7174. *
  7175. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7176. *
  7177. * _.pull(array, 'a', 'c');
  7178. * console.log(array);
  7179. * // => ['b', 'b']
  7180. */
  7181. var pull = baseRest(pullAll);
  7182. /**
  7183. * This method is like `_.pull` except that it accepts an array of values to remove.
  7184. *
  7185. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7186. *
  7187. * @static
  7188. * @memberOf _
  7189. * @since 4.0.0
  7190. * @category Array
  7191. * @param {Array} array The array to modify.
  7192. * @param {Array} values The values to remove.
  7193. * @returns {Array} Returns `array`.
  7194. * @example
  7195. *
  7196. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7197. *
  7198. * _.pullAll(array, ['a', 'c']);
  7199. * console.log(array);
  7200. * // => ['b', 'b']
  7201. */
  7202. function pullAll(array, values) {
  7203. return (array && array.length && values && values.length)
  7204. ? basePullAll(array, values)
  7205. : array;
  7206. }
  7207. /**
  7208. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7209. * invoked for each element of `array` and `values` to generate the criterion
  7210. * by which they're compared. The iteratee is invoked with one argument: (value).
  7211. *
  7212. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7213. *
  7214. * @static
  7215. * @memberOf _
  7216. * @since 4.0.0
  7217. * @category Array
  7218. * @param {Array} array The array to modify.
  7219. * @param {Array} values The values to remove.
  7220. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7221. * @returns {Array} Returns `array`.
  7222. * @example
  7223. *
  7224. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7225. *
  7226. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7227. * console.log(array);
  7228. * // => [{ 'x': 2 }]
  7229. */
  7230. function pullAllBy(array, values, iteratee) {
  7231. return (array && array.length && values && values.length)
  7232. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7233. : array;
  7234. }
  7235. /**
  7236. * This method is like `_.pullAll` except that it accepts `comparator` which
  7237. * is invoked to compare elements of `array` to `values`. The comparator is
  7238. * invoked with two arguments: (arrVal, othVal).
  7239. *
  7240. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7241. *
  7242. * @static
  7243. * @memberOf _
  7244. * @since 4.6.0
  7245. * @category Array
  7246. * @param {Array} array The array to modify.
  7247. * @param {Array} values The values to remove.
  7248. * @param {Function} [comparator] The comparator invoked per element.
  7249. * @returns {Array} Returns `array`.
  7250. * @example
  7251. *
  7252. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7253. *
  7254. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7255. * console.log(array);
  7256. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7257. */
  7258. function pullAllWith(array, values, comparator) {
  7259. return (array && array.length && values && values.length)
  7260. ? basePullAll(array, values, undefined, comparator)
  7261. : array;
  7262. }
  7263. /**
  7264. * Removes elements from `array` corresponding to `indexes` and returns an
  7265. * array of removed elements.
  7266. *
  7267. * **Note:** Unlike `_.at`, this method mutates `array`.
  7268. *
  7269. * @static
  7270. * @memberOf _
  7271. * @since 3.0.0
  7272. * @category Array
  7273. * @param {Array} array The array to modify.
  7274. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7275. * @returns {Array} Returns the new array of removed elements.
  7276. * @example
  7277. *
  7278. * var array = ['a', 'b', 'c', 'd'];
  7279. * var pulled = _.pullAt(array, [1, 3]);
  7280. *
  7281. * console.log(array);
  7282. * // => ['a', 'c']
  7283. *
  7284. * console.log(pulled);
  7285. * // => ['b', 'd']
  7286. */
  7287. var pullAt = flatRest(function(array, indexes) {
  7288. var length = array == null ? 0 : array.length,
  7289. result = baseAt(array, indexes);
  7290. basePullAt(array, arrayMap(indexes, function(index) {
  7291. return isIndex(index, length) ? +index : index;
  7292. }).sort(compareAscending));
  7293. return result;
  7294. });
  7295. /**
  7296. * Removes all elements from `array` that `predicate` returns truthy for
  7297. * and returns an array of the removed elements. The predicate is invoked
  7298. * with three arguments: (value, index, array).
  7299. *
  7300. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7301. * to pull elements from an array by value.
  7302. *
  7303. * @static
  7304. * @memberOf _
  7305. * @since 2.0.0
  7306. * @category Array
  7307. * @param {Array} array The array to modify.
  7308. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7309. * @returns {Array} Returns the new array of removed elements.
  7310. * @example
  7311. *
  7312. * var array = [1, 2, 3, 4];
  7313. * var evens = _.remove(array, function(n) {
  7314. * return n % 2 == 0;
  7315. * });
  7316. *
  7317. * console.log(array);
  7318. * // => [1, 3]
  7319. *
  7320. * console.log(evens);
  7321. * // => [2, 4]
  7322. */
  7323. function remove(array, predicate) {
  7324. var result = [];
  7325. if (!(array && array.length)) {
  7326. return result;
  7327. }
  7328. var index = -1,
  7329. indexes = [],
  7330. length = array.length;
  7331. predicate = getIteratee(predicate, 3);
  7332. while (++index < length) {
  7333. var value = array[index];
  7334. if (predicate(value, index, array)) {
  7335. result.push(value);
  7336. indexes.push(index);
  7337. }
  7338. }
  7339. basePullAt(array, indexes);
  7340. return result;
  7341. }
  7342. /**
  7343. * Reverses `array` so that the first element becomes the last, the second
  7344. * element becomes the second to last, and so on.
  7345. *
  7346. * **Note:** This method mutates `array` and is based on
  7347. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7348. *
  7349. * @static
  7350. * @memberOf _
  7351. * @since 4.0.0
  7352. * @category Array
  7353. * @param {Array} array The array to modify.
  7354. * @returns {Array} Returns `array`.
  7355. * @example
  7356. *
  7357. * var array = [1, 2, 3];
  7358. *
  7359. * _.reverse(array);
  7360. * // => [3, 2, 1]
  7361. *
  7362. * console.log(array);
  7363. * // => [3, 2, 1]
  7364. */
  7365. function reverse(array) {
  7366. return array == null ? array : nativeReverse.call(array);
  7367. }
  7368. /**
  7369. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7370. *
  7371. * **Note:** This method is used instead of
  7372. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7373. * returned.
  7374. *
  7375. * @static
  7376. * @memberOf _
  7377. * @since 3.0.0
  7378. * @category Array
  7379. * @param {Array} array The array to slice.
  7380. * @param {number} [start=0] The start position.
  7381. * @param {number} [end=array.length] The end position.
  7382. * @returns {Array} Returns the slice of `array`.
  7383. */
  7384. function slice(array, start, end) {
  7385. var length = array == null ? 0 : array.length;
  7386. if (!length) {
  7387. return [];
  7388. }
  7389. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7390. start = 0;
  7391. end = length;
  7392. }
  7393. else {
  7394. start = start == null ? 0 : toInteger(start);
  7395. end = end === undefined ? length : toInteger(end);
  7396. }
  7397. return baseSlice(array, start, end);
  7398. }
  7399. /**
  7400. * Uses a binary search to determine the lowest index at which `value`
  7401. * should be inserted into `array` in order to maintain its sort order.
  7402. *
  7403. * @static
  7404. * @memberOf _
  7405. * @since 0.1.0
  7406. * @category Array
  7407. * @param {Array} array The sorted array to inspect.
  7408. * @param {*} value The value to evaluate.
  7409. * @returns {number} Returns the index at which `value` should be inserted
  7410. * into `array`.
  7411. * @example
  7412. *
  7413. * _.sortedIndex([30, 50], 40);
  7414. * // => 1
  7415. */
  7416. function sortedIndex(array, value) {
  7417. return baseSortedIndex(array, value);
  7418. }
  7419. /**
  7420. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7421. * which is invoked for `value` and each element of `array` to compute their
  7422. * sort ranking. The iteratee is invoked with one argument: (value).
  7423. *
  7424. * @static
  7425. * @memberOf _
  7426. * @since 4.0.0
  7427. * @category Array
  7428. * @param {Array} array The sorted array to inspect.
  7429. * @param {*} value The value to evaluate.
  7430. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7431. * @returns {number} Returns the index at which `value` should be inserted
  7432. * into `array`.
  7433. * @example
  7434. *
  7435. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7436. *
  7437. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7438. * // => 0
  7439. *
  7440. * // The `_.property` iteratee shorthand.
  7441. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7442. * // => 0
  7443. */
  7444. function sortedIndexBy(array, value, iteratee) {
  7445. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7446. }
  7447. /**
  7448. * This method is like `_.indexOf` except that it performs a binary
  7449. * search on a sorted `array`.
  7450. *
  7451. * @static
  7452. * @memberOf _
  7453. * @since 4.0.0
  7454. * @category Array
  7455. * @param {Array} array The array to inspect.
  7456. * @param {*} value The value to search for.
  7457. * @returns {number} Returns the index of the matched value, else `-1`.
  7458. * @example
  7459. *
  7460. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7461. * // => 1
  7462. */
  7463. function sortedIndexOf(array, value) {
  7464. var length = array == null ? 0 : array.length;
  7465. if (length) {
  7466. var index = baseSortedIndex(array, value);
  7467. if (index < length && eq(array[index], value)) {
  7468. return index;
  7469. }
  7470. }
  7471. return -1;
  7472. }
  7473. /**
  7474. * This method is like `_.sortedIndex` except that it returns the highest
  7475. * index at which `value` should be inserted into `array` in order to
  7476. * maintain its sort order.
  7477. *
  7478. * @static
  7479. * @memberOf _
  7480. * @since 3.0.0
  7481. * @category Array
  7482. * @param {Array} array The sorted array to inspect.
  7483. * @param {*} value The value to evaluate.
  7484. * @returns {number} Returns the index at which `value` should be inserted
  7485. * into `array`.
  7486. * @example
  7487. *
  7488. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7489. * // => 4
  7490. */
  7491. function sortedLastIndex(array, value) {
  7492. return baseSortedIndex(array, value, true);
  7493. }
  7494. /**
  7495. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7496. * which is invoked for `value` and each element of `array` to compute their
  7497. * sort ranking. The iteratee is invoked with one argument: (value).
  7498. *
  7499. * @static
  7500. * @memberOf _
  7501. * @since 4.0.0
  7502. * @category Array
  7503. * @param {Array} array The sorted array to inspect.
  7504. * @param {*} value The value to evaluate.
  7505. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7506. * @returns {number} Returns the index at which `value` should be inserted
  7507. * into `array`.
  7508. * @example
  7509. *
  7510. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7511. *
  7512. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7513. * // => 1
  7514. *
  7515. * // The `_.property` iteratee shorthand.
  7516. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7517. * // => 1
  7518. */
  7519. function sortedLastIndexBy(array, value, iteratee) {
  7520. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7521. }
  7522. /**
  7523. * This method is like `_.lastIndexOf` except that it performs a binary
  7524. * search on a sorted `array`.
  7525. *
  7526. * @static
  7527. * @memberOf _
  7528. * @since 4.0.0
  7529. * @category Array
  7530. * @param {Array} array The array to inspect.
  7531. * @param {*} value The value to search for.
  7532. * @returns {number} Returns the index of the matched value, else `-1`.
  7533. * @example
  7534. *
  7535. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7536. * // => 3
  7537. */
  7538. function sortedLastIndexOf(array, value) {
  7539. var length = array == null ? 0 : array.length;
  7540. if (length) {
  7541. var index = baseSortedIndex(array, value, true) - 1;
  7542. if (eq(array[index], value)) {
  7543. return index;
  7544. }
  7545. }
  7546. return -1;
  7547. }
  7548. /**
  7549. * This method is like `_.uniq` except that it's designed and optimized
  7550. * for sorted arrays.
  7551. *
  7552. * @static
  7553. * @memberOf _
  7554. * @since 4.0.0
  7555. * @category Array
  7556. * @param {Array} array The array to inspect.
  7557. * @returns {Array} Returns the new duplicate free array.
  7558. * @example
  7559. *
  7560. * _.sortedUniq([1, 1, 2]);
  7561. * // => [1, 2]
  7562. */
  7563. function sortedUniq(array) {
  7564. return (array && array.length)
  7565. ? baseSortedUniq(array)
  7566. : [];
  7567. }
  7568. /**
  7569. * This method is like `_.uniqBy` except that it's designed and optimized
  7570. * for sorted arrays.
  7571. *
  7572. * @static
  7573. * @memberOf _
  7574. * @since 4.0.0
  7575. * @category Array
  7576. * @param {Array} array The array to inspect.
  7577. * @param {Function} [iteratee] The iteratee invoked per element.
  7578. * @returns {Array} Returns the new duplicate free array.
  7579. * @example
  7580. *
  7581. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7582. * // => [1.1, 2.3]
  7583. */
  7584. function sortedUniqBy(array, iteratee) {
  7585. return (array && array.length)
  7586. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7587. : [];
  7588. }
  7589. /**
  7590. * Gets all but the first element of `array`.
  7591. *
  7592. * @static
  7593. * @memberOf _
  7594. * @since 4.0.0
  7595. * @category Array
  7596. * @param {Array} array The array to query.
  7597. * @returns {Array} Returns the slice of `array`.
  7598. * @example
  7599. *
  7600. * _.tail([1, 2, 3]);
  7601. * // => [2, 3]
  7602. */
  7603. function tail(array) {
  7604. var length = array == null ? 0 : array.length;
  7605. return length ? baseSlice(array, 1, length) : [];
  7606. }
  7607. /**
  7608. * Creates a slice of `array` with `n` elements taken from the beginning.
  7609. *
  7610. * @static
  7611. * @memberOf _
  7612. * @since 0.1.0
  7613. * @category Array
  7614. * @param {Array} array The array to query.
  7615. * @param {number} [n=1] The number of elements to take.
  7616. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7617. * @returns {Array} Returns the slice of `array`.
  7618. * @example
  7619. *
  7620. * _.take([1, 2, 3]);
  7621. * // => [1]
  7622. *
  7623. * _.take([1, 2, 3], 2);
  7624. * // => [1, 2]
  7625. *
  7626. * _.take([1, 2, 3], 5);
  7627. * // => [1, 2, 3]
  7628. *
  7629. * _.take([1, 2, 3], 0);
  7630. * // => []
  7631. */
  7632. function take(array, n, guard) {
  7633. if (!(array && array.length)) {
  7634. return [];
  7635. }
  7636. n = (guard || n === undefined) ? 1 : toInteger(n);
  7637. return baseSlice(array, 0, n < 0 ? 0 : n);
  7638. }
  7639. /**
  7640. * Creates a slice of `array` with `n` elements taken from the end.
  7641. *
  7642. * @static
  7643. * @memberOf _
  7644. * @since 3.0.0
  7645. * @category Array
  7646. * @param {Array} array The array to query.
  7647. * @param {number} [n=1] The number of elements to take.
  7648. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7649. * @returns {Array} Returns the slice of `array`.
  7650. * @example
  7651. *
  7652. * _.takeRight([1, 2, 3]);
  7653. * // => [3]
  7654. *
  7655. * _.takeRight([1, 2, 3], 2);
  7656. * // => [2, 3]
  7657. *
  7658. * _.takeRight([1, 2, 3], 5);
  7659. * // => [1, 2, 3]
  7660. *
  7661. * _.takeRight([1, 2, 3], 0);
  7662. * // => []
  7663. */
  7664. function takeRight(array, n, guard) {
  7665. var length = array == null ? 0 : array.length;
  7666. if (!length) {
  7667. return [];
  7668. }
  7669. n = (guard || n === undefined) ? 1 : toInteger(n);
  7670. n = length - n;
  7671. return baseSlice(array, n < 0 ? 0 : n, length);
  7672. }
  7673. /**
  7674. * Creates a slice of `array` with elements taken from the end. Elements are
  7675. * taken until `predicate` returns falsey. The predicate is invoked with
  7676. * three arguments: (value, index, array).
  7677. *
  7678. * @static
  7679. * @memberOf _
  7680. * @since 3.0.0
  7681. * @category Array
  7682. * @param {Array} array The array to query.
  7683. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7684. * @returns {Array} Returns the slice of `array`.
  7685. * @example
  7686. *
  7687. * var users = [
  7688. * { 'user': 'barney', 'active': true },
  7689. * { 'user': 'fred', 'active': false },
  7690. * { 'user': 'pebbles', 'active': false }
  7691. * ];
  7692. *
  7693. * _.takeRightWhile(users, function(o) { return !o.active; });
  7694. * // => objects for ['fred', 'pebbles']
  7695. *
  7696. * // The `_.matches` iteratee shorthand.
  7697. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7698. * // => objects for ['pebbles']
  7699. *
  7700. * // The `_.matchesProperty` iteratee shorthand.
  7701. * _.takeRightWhile(users, ['active', false]);
  7702. * // => objects for ['fred', 'pebbles']
  7703. *
  7704. * // The `_.property` iteratee shorthand.
  7705. * _.takeRightWhile(users, 'active');
  7706. * // => []
  7707. */
  7708. function takeRightWhile(array, predicate) {
  7709. return (array && array.length)
  7710. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7711. : [];
  7712. }
  7713. /**
  7714. * Creates a slice of `array` with elements taken from the beginning. Elements
  7715. * are taken until `predicate` returns falsey. The predicate is invoked with
  7716. * three arguments: (value, index, array).
  7717. *
  7718. * @static
  7719. * @memberOf _
  7720. * @since 3.0.0
  7721. * @category Array
  7722. * @param {Array} array The array to query.
  7723. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7724. * @returns {Array} Returns the slice of `array`.
  7725. * @example
  7726. *
  7727. * var users = [
  7728. * { 'user': 'barney', 'active': false },
  7729. * { 'user': 'fred', 'active': false },
  7730. * { 'user': 'pebbles', 'active': true }
  7731. * ];
  7732. *
  7733. * _.takeWhile(users, function(o) { return !o.active; });
  7734. * // => objects for ['barney', 'fred']
  7735. *
  7736. * // The `_.matches` iteratee shorthand.
  7737. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7738. * // => objects for ['barney']
  7739. *
  7740. * // The `_.matchesProperty` iteratee shorthand.
  7741. * _.takeWhile(users, ['active', false]);
  7742. * // => objects for ['barney', 'fred']
  7743. *
  7744. * // The `_.property` iteratee shorthand.
  7745. * _.takeWhile(users, 'active');
  7746. * // => []
  7747. */
  7748. function takeWhile(array, predicate) {
  7749. return (array && array.length)
  7750. ? baseWhile(array, getIteratee(predicate, 3))
  7751. : [];
  7752. }
  7753. /**
  7754. * Creates an array of unique values, in order, from all given arrays using
  7755. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7756. * for equality comparisons.
  7757. *
  7758. * @static
  7759. * @memberOf _
  7760. * @since 0.1.0
  7761. * @category Array
  7762. * @param {...Array} [arrays] The arrays to inspect.
  7763. * @returns {Array} Returns the new array of combined values.
  7764. * @example
  7765. *
  7766. * _.union([2], [1, 2]);
  7767. * // => [2, 1]
  7768. */
  7769. var union = baseRest(function(arrays) {
  7770. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7771. });
  7772. /**
  7773. * This method is like `_.union` except that it accepts `iteratee` which is
  7774. * invoked for each element of each `arrays` to generate the criterion by
  7775. * which uniqueness is computed. Result values are chosen from the first
  7776. * array in which the value occurs. The iteratee is invoked with one argument:
  7777. * (value).
  7778. *
  7779. * @static
  7780. * @memberOf _
  7781. * @since 4.0.0
  7782. * @category Array
  7783. * @param {...Array} [arrays] The arrays to inspect.
  7784. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7785. * @returns {Array} Returns the new array of combined values.
  7786. * @example
  7787. *
  7788. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7789. * // => [2.1, 1.2]
  7790. *
  7791. * // The `_.property` iteratee shorthand.
  7792. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7793. * // => [{ 'x': 1 }, { 'x': 2 }]
  7794. */
  7795. var unionBy = baseRest(function(arrays) {
  7796. var iteratee = last(arrays);
  7797. if (isArrayLikeObject(iteratee)) {
  7798. iteratee = undefined;
  7799. }
  7800. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7801. });
  7802. /**
  7803. * This method is like `_.union` except that it accepts `comparator` which
  7804. * is invoked to compare elements of `arrays`. Result values are chosen from
  7805. * the first array in which the value occurs. The comparator is invoked
  7806. * with two arguments: (arrVal, othVal).
  7807. *
  7808. * @static
  7809. * @memberOf _
  7810. * @since 4.0.0
  7811. * @category Array
  7812. * @param {...Array} [arrays] The arrays to inspect.
  7813. * @param {Function} [comparator] The comparator invoked per element.
  7814. * @returns {Array} Returns the new array of combined values.
  7815. * @example
  7816. *
  7817. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7818. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7819. *
  7820. * _.unionWith(objects, others, _.isEqual);
  7821. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7822. */
  7823. var unionWith = baseRest(function(arrays) {
  7824. var comparator = last(arrays);
  7825. comparator = typeof comparator == 'function' ? comparator : undefined;
  7826. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7827. });
  7828. /**
  7829. * Creates a duplicate-free version of an array, using
  7830. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7831. * for equality comparisons, in which only the first occurrence of each element
  7832. * is kept. The order of result values is determined by the order they occur
  7833. * in the array.
  7834. *
  7835. * @static
  7836. * @memberOf _
  7837. * @since 0.1.0
  7838. * @category Array
  7839. * @param {Array} array The array to inspect.
  7840. * @returns {Array} Returns the new duplicate free array.
  7841. * @example
  7842. *
  7843. * _.uniq([2, 1, 2]);
  7844. * // => [2, 1]
  7845. */
  7846. function uniq(array) {
  7847. return (array && array.length) ? baseUniq(array) : [];
  7848. }
  7849. /**
  7850. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7851. * invoked for each element in `array` to generate the criterion by which
  7852. * uniqueness is computed. The order of result values is determined by the
  7853. * order they occur in the array. The iteratee is invoked with one argument:
  7854. * (value).
  7855. *
  7856. * @static
  7857. * @memberOf _
  7858. * @since 4.0.0
  7859. * @category Array
  7860. * @param {Array} array The array to inspect.
  7861. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7862. * @returns {Array} Returns the new duplicate free array.
  7863. * @example
  7864. *
  7865. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7866. * // => [2.1, 1.2]
  7867. *
  7868. * // The `_.property` iteratee shorthand.
  7869. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7870. * // => [{ 'x': 1 }, { 'x': 2 }]
  7871. */
  7872. function uniqBy(array, iteratee) {
  7873. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7874. }
  7875. /**
  7876. * This method is like `_.uniq` except that it accepts `comparator` which
  7877. * is invoked to compare elements of `array`. The order of result values is
  7878. * determined by the order they occur in the array.The comparator is invoked
  7879. * with two arguments: (arrVal, othVal).
  7880. *
  7881. * @static
  7882. * @memberOf _
  7883. * @since 4.0.0
  7884. * @category Array
  7885. * @param {Array} array The array to inspect.
  7886. * @param {Function} [comparator] The comparator invoked per element.
  7887. * @returns {Array} Returns the new duplicate free array.
  7888. * @example
  7889. *
  7890. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7891. *
  7892. * _.uniqWith(objects, _.isEqual);
  7893. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7894. */
  7895. function uniqWith(array, comparator) {
  7896. comparator = typeof comparator == 'function' ? comparator : undefined;
  7897. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7898. }
  7899. /**
  7900. * This method is like `_.zip` except that it accepts an array of grouped
  7901. * elements and creates an array regrouping the elements to their pre-zip
  7902. * configuration.
  7903. *
  7904. * @static
  7905. * @memberOf _
  7906. * @since 1.2.0
  7907. * @category Array
  7908. * @param {Array} array The array of grouped elements to process.
  7909. * @returns {Array} Returns the new array of regrouped elements.
  7910. * @example
  7911. *
  7912. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7913. * // => [['a', 1, true], ['b', 2, false]]
  7914. *
  7915. * _.unzip(zipped);
  7916. * // => [['a', 'b'], [1, 2], [true, false]]
  7917. */
  7918. function unzip(array) {
  7919. if (!(array && array.length)) {
  7920. return [];
  7921. }
  7922. var length = 0;
  7923. array = arrayFilter(array, function(group) {
  7924. if (isArrayLikeObject(group)) {
  7925. length = nativeMax(group.length, length);
  7926. return true;
  7927. }
  7928. });
  7929. return baseTimes(length, function(index) {
  7930. return arrayMap(array, baseProperty(index));
  7931. });
  7932. }
  7933. /**
  7934. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7935. * how regrouped values should be combined. The iteratee is invoked with the
  7936. * elements of each group: (...group).
  7937. *
  7938. * @static
  7939. * @memberOf _
  7940. * @since 3.8.0
  7941. * @category Array
  7942. * @param {Array} array The array of grouped elements to process.
  7943. * @param {Function} [iteratee=_.identity] The function to combine
  7944. * regrouped values.
  7945. * @returns {Array} Returns the new array of regrouped elements.
  7946. * @example
  7947. *
  7948. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7949. * // => [[1, 10, 100], [2, 20, 200]]
  7950. *
  7951. * _.unzipWith(zipped, _.add);
  7952. * // => [3, 30, 300]
  7953. */
  7954. function unzipWith(array, iteratee) {
  7955. if (!(array && array.length)) {
  7956. return [];
  7957. }
  7958. var result = unzip(array);
  7959. if (iteratee == null) {
  7960. return result;
  7961. }
  7962. return arrayMap(result, function(group) {
  7963. return apply(iteratee, undefined, group);
  7964. });
  7965. }
  7966. /**
  7967. * Creates an array excluding all given values using
  7968. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7969. * for equality comparisons.
  7970. *
  7971. * **Note:** Unlike `_.pull`, this method returns a new array.
  7972. *
  7973. * @static
  7974. * @memberOf _
  7975. * @since 0.1.0
  7976. * @category Array
  7977. * @param {Array} array The array to inspect.
  7978. * @param {...*} [values] The values to exclude.
  7979. * @returns {Array} Returns the new array of filtered values.
  7980. * @see _.difference, _.xor
  7981. * @example
  7982. *
  7983. * _.without([2, 1, 2, 3], 1, 2);
  7984. * // => [3]
  7985. */
  7986. var without = baseRest(function(array, values) {
  7987. return isArrayLikeObject(array)
  7988. ? baseDifference(array, values)
  7989. : [];
  7990. });
  7991. /**
  7992. * Creates an array of unique values that is the
  7993. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7994. * of the given arrays. The order of result values is determined by the order
  7995. * they occur in the arrays.
  7996. *
  7997. * @static
  7998. * @memberOf _
  7999. * @since 2.4.0
  8000. * @category Array
  8001. * @param {...Array} [arrays] The arrays to inspect.
  8002. * @returns {Array} Returns the new array of filtered values.
  8003. * @see _.difference, _.without
  8004. * @example
  8005. *
  8006. * _.xor([2, 1], [2, 3]);
  8007. * // => [1, 3]
  8008. */
  8009. var xor = baseRest(function(arrays) {
  8010. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  8011. });
  8012. /**
  8013. * This method is like `_.xor` except that it accepts `iteratee` which is
  8014. * invoked for each element of each `arrays` to generate the criterion by
  8015. * which by which they're compared. The order of result values is determined
  8016. * by the order they occur in the arrays. The iteratee is invoked with one
  8017. * argument: (value).
  8018. *
  8019. * @static
  8020. * @memberOf _
  8021. * @since 4.0.0
  8022. * @category Array
  8023. * @param {...Array} [arrays] The arrays to inspect.
  8024. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  8025. * @returns {Array} Returns the new array of filtered values.
  8026. * @example
  8027. *
  8028. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  8029. * // => [1.2, 3.4]
  8030. *
  8031. * // The `_.property` iteratee shorthand.
  8032. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  8033. * // => [{ 'x': 2 }]
  8034. */
  8035. var xorBy = baseRest(function(arrays) {
  8036. var iteratee = last(arrays);
  8037. if (isArrayLikeObject(iteratee)) {
  8038. iteratee = undefined;
  8039. }
  8040. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  8041. });
  8042. /**
  8043. * This method is like `_.xor` except that it accepts `comparator` which is
  8044. * invoked to compare elements of `arrays`. The order of result values is
  8045. * determined by the order they occur in the arrays. The comparator is invoked
  8046. * with two arguments: (arrVal, othVal).
  8047. *
  8048. * @static
  8049. * @memberOf _
  8050. * @since 4.0.0
  8051. * @category Array
  8052. * @param {...Array} [arrays] The arrays to inspect.
  8053. * @param {Function} [comparator] The comparator invoked per element.
  8054. * @returns {Array} Returns the new array of filtered values.
  8055. * @example
  8056. *
  8057. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  8058. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  8059. *
  8060. * _.xorWith(objects, others, _.isEqual);
  8061. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  8062. */
  8063. var xorWith = baseRest(function(arrays) {
  8064. var comparator = last(arrays);
  8065. comparator = typeof comparator == 'function' ? comparator : undefined;
  8066. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  8067. });
  8068. /**
  8069. * Creates an array of grouped elements, the first of which contains the
  8070. * first elements of the given arrays, the second of which contains the
  8071. * second elements of the given arrays, and so on.
  8072. *
  8073. * @static
  8074. * @memberOf _
  8075. * @since 0.1.0
  8076. * @category Array
  8077. * @param {...Array} [arrays] The arrays to process.
  8078. * @returns {Array} Returns the new array of grouped elements.
  8079. * @example
  8080. *
  8081. * _.zip(['a', 'b'], [1, 2], [true, false]);
  8082. * // => [['a', 1, true], ['b', 2, false]]
  8083. */
  8084. var zip = baseRest(unzip);
  8085. /**
  8086. * This method is like `_.fromPairs` except that it accepts two arrays,
  8087. * one of property identifiers and one of corresponding values.
  8088. *
  8089. * @static
  8090. * @memberOf _
  8091. * @since 0.4.0
  8092. * @category Array
  8093. * @param {Array} [props=[]] The property identifiers.
  8094. * @param {Array} [values=[]] The property values.
  8095. * @returns {Object} Returns the new object.
  8096. * @example
  8097. *
  8098. * _.zipObject(['a', 'b'], [1, 2]);
  8099. * // => { 'a': 1, 'b': 2 }
  8100. */
  8101. function zipObject(props, values) {
  8102. return baseZipObject(props || [], values || [], assignValue);
  8103. }
  8104. /**
  8105. * This method is like `_.zipObject` except that it supports property paths.
  8106. *
  8107. * @static
  8108. * @memberOf _
  8109. * @since 4.1.0
  8110. * @category Array
  8111. * @param {Array} [props=[]] The property identifiers.
  8112. * @param {Array} [values=[]] The property values.
  8113. * @returns {Object} Returns the new object.
  8114. * @example
  8115. *
  8116. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8117. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8118. */
  8119. function zipObjectDeep(props, values) {
  8120. return baseZipObject(props || [], values || [], baseSet);
  8121. }
  8122. /**
  8123. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8124. * how grouped values should be combined. The iteratee is invoked with the
  8125. * elements of each group: (...group).
  8126. *
  8127. * @static
  8128. * @memberOf _
  8129. * @since 3.8.0
  8130. * @category Array
  8131. * @param {...Array} [arrays] The arrays to process.
  8132. * @param {Function} [iteratee=_.identity] The function to combine
  8133. * grouped values.
  8134. * @returns {Array} Returns the new array of grouped elements.
  8135. * @example
  8136. *
  8137. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8138. * return a + b + c;
  8139. * });
  8140. * // => [111, 222]
  8141. */
  8142. var zipWith = baseRest(function(arrays) {
  8143. var length = arrays.length,
  8144. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8145. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8146. return unzipWith(arrays, iteratee);
  8147. });
  8148. /*------------------------------------------------------------------------*/
  8149. /**
  8150. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8151. * chain sequences enabled. The result of such sequences must be unwrapped
  8152. * with `_#value`.
  8153. *
  8154. * @static
  8155. * @memberOf _
  8156. * @since 1.3.0
  8157. * @category Seq
  8158. * @param {*} value The value to wrap.
  8159. * @returns {Object} Returns the new `lodash` wrapper instance.
  8160. * @example
  8161. *
  8162. * var users = [
  8163. * { 'user': 'barney', 'age': 36 },
  8164. * { 'user': 'fred', 'age': 40 },
  8165. * { 'user': 'pebbles', 'age': 1 }
  8166. * ];
  8167. *
  8168. * var youngest = _
  8169. * .chain(users)
  8170. * .sortBy('age')
  8171. * .map(function(o) {
  8172. * return o.user + ' is ' + o.age;
  8173. * })
  8174. * .head()
  8175. * .value();
  8176. * // => 'pebbles is 1'
  8177. */
  8178. function chain(value) {
  8179. var result = lodash(value);
  8180. result.__chain__ = true;
  8181. return result;
  8182. }
  8183. /**
  8184. * This method invokes `interceptor` and returns `value`. The interceptor
  8185. * is invoked with one argument; (value). The purpose of this method is to
  8186. * "tap into" a method chain sequence in order to modify intermediate results.
  8187. *
  8188. * @static
  8189. * @memberOf _
  8190. * @since 0.1.0
  8191. * @category Seq
  8192. * @param {*} value The value to provide to `interceptor`.
  8193. * @param {Function} interceptor The function to invoke.
  8194. * @returns {*} Returns `value`.
  8195. * @example
  8196. *
  8197. * _([1, 2, 3])
  8198. * .tap(function(array) {
  8199. * // Mutate input array.
  8200. * array.pop();
  8201. * })
  8202. * .reverse()
  8203. * .value();
  8204. * // => [2, 1]
  8205. */
  8206. function tap(value, interceptor) {
  8207. interceptor(value);
  8208. return value;
  8209. }
  8210. /**
  8211. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8212. * The purpose of this method is to "pass thru" values replacing intermediate
  8213. * results in a method chain sequence.
  8214. *
  8215. * @static
  8216. * @memberOf _
  8217. * @since 3.0.0
  8218. * @category Seq
  8219. * @param {*} value The value to provide to `interceptor`.
  8220. * @param {Function} interceptor The function to invoke.
  8221. * @returns {*} Returns the result of `interceptor`.
  8222. * @example
  8223. *
  8224. * _(' abc ')
  8225. * .chain()
  8226. * .trim()
  8227. * .thru(function(value) {
  8228. * return [value];
  8229. * })
  8230. * .value();
  8231. * // => ['abc']
  8232. */
  8233. function thru(value, interceptor) {
  8234. return interceptor(value);
  8235. }
  8236. /**
  8237. * This method is the wrapper version of `_.at`.
  8238. *
  8239. * @name at
  8240. * @memberOf _
  8241. * @since 1.0.0
  8242. * @category Seq
  8243. * @param {...(string|string[])} [paths] The property paths to pick.
  8244. * @returns {Object} Returns the new `lodash` wrapper instance.
  8245. * @example
  8246. *
  8247. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8248. *
  8249. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8250. * // => [3, 4]
  8251. */
  8252. var wrapperAt = flatRest(function(paths) {
  8253. var length = paths.length,
  8254. start = length ? paths[0] : 0,
  8255. value = this.__wrapped__,
  8256. interceptor = function(object) { return baseAt(object, paths); };
  8257. if (length > 1 || this.__actions__.length ||
  8258. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8259. return this.thru(interceptor);
  8260. }
  8261. value = value.slice(start, +start + (length ? 1 : 0));
  8262. value.__actions__.push({
  8263. 'func': thru,
  8264. 'args': [interceptor],
  8265. 'thisArg': undefined
  8266. });
  8267. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8268. if (length && !array.length) {
  8269. array.push(undefined);
  8270. }
  8271. return array;
  8272. });
  8273. });
  8274. /**
  8275. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8276. *
  8277. * @name chain
  8278. * @memberOf _
  8279. * @since 0.1.0
  8280. * @category Seq
  8281. * @returns {Object} Returns the new `lodash` wrapper instance.
  8282. * @example
  8283. *
  8284. * var users = [
  8285. * { 'user': 'barney', 'age': 36 },
  8286. * { 'user': 'fred', 'age': 40 }
  8287. * ];
  8288. *
  8289. * // A sequence without explicit chaining.
  8290. * _(users).head();
  8291. * // => { 'user': 'barney', 'age': 36 }
  8292. *
  8293. * // A sequence with explicit chaining.
  8294. * _(users)
  8295. * .chain()
  8296. * .head()
  8297. * .pick('user')
  8298. * .value();
  8299. * // => { 'user': 'barney' }
  8300. */
  8301. function wrapperChain() {
  8302. return chain(this);
  8303. }
  8304. /**
  8305. * Executes the chain sequence and returns the wrapped result.
  8306. *
  8307. * @name commit
  8308. * @memberOf _
  8309. * @since 3.2.0
  8310. * @category Seq
  8311. * @returns {Object} Returns the new `lodash` wrapper instance.
  8312. * @example
  8313. *
  8314. * var array = [1, 2];
  8315. * var wrapped = _(array).push(3);
  8316. *
  8317. * console.log(array);
  8318. * // => [1, 2]
  8319. *
  8320. * wrapped = wrapped.commit();
  8321. * console.log(array);
  8322. * // => [1, 2, 3]
  8323. *
  8324. * wrapped.last();
  8325. * // => 3
  8326. *
  8327. * console.log(array);
  8328. * // => [1, 2, 3]
  8329. */
  8330. function wrapperCommit() {
  8331. return new LodashWrapper(this.value(), this.__chain__);
  8332. }
  8333. /**
  8334. * Gets the next value on a wrapped object following the
  8335. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8336. *
  8337. * @name next
  8338. * @memberOf _
  8339. * @since 4.0.0
  8340. * @category Seq
  8341. * @returns {Object} Returns the next iterator value.
  8342. * @example
  8343. *
  8344. * var wrapped = _([1, 2]);
  8345. *
  8346. * wrapped.next();
  8347. * // => { 'done': false, 'value': 1 }
  8348. *
  8349. * wrapped.next();
  8350. * // => { 'done': false, 'value': 2 }
  8351. *
  8352. * wrapped.next();
  8353. * // => { 'done': true, 'value': undefined }
  8354. */
  8355. function wrapperNext() {
  8356. if (this.__values__ === undefined) {
  8357. this.__values__ = toArray(this.value());
  8358. }
  8359. var done = this.__index__ >= this.__values__.length,
  8360. value = done ? undefined : this.__values__[this.__index__++];
  8361. return { 'done': done, 'value': value };
  8362. }
  8363. /**
  8364. * Enables the wrapper to be iterable.
  8365. *
  8366. * @name Symbol.iterator
  8367. * @memberOf _
  8368. * @since 4.0.0
  8369. * @category Seq
  8370. * @returns {Object} Returns the wrapper object.
  8371. * @example
  8372. *
  8373. * var wrapped = _([1, 2]);
  8374. *
  8375. * wrapped[Symbol.iterator]() === wrapped;
  8376. * // => true
  8377. *
  8378. * Array.from(wrapped);
  8379. * // => [1, 2]
  8380. */
  8381. function wrapperToIterator() {
  8382. return this;
  8383. }
  8384. /**
  8385. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8386. *
  8387. * @name plant
  8388. * @memberOf _
  8389. * @since 3.2.0
  8390. * @category Seq
  8391. * @param {*} value The value to plant.
  8392. * @returns {Object} Returns the new `lodash` wrapper instance.
  8393. * @example
  8394. *
  8395. * function square(n) {
  8396. * return n * n;
  8397. * }
  8398. *
  8399. * var wrapped = _([1, 2]).map(square);
  8400. * var other = wrapped.plant([3, 4]);
  8401. *
  8402. * other.value();
  8403. * // => [9, 16]
  8404. *
  8405. * wrapped.value();
  8406. * // => [1, 4]
  8407. */
  8408. function wrapperPlant(value) {
  8409. var result,
  8410. parent = this;
  8411. while (parent instanceof baseLodash) {
  8412. var clone = wrapperClone(parent);
  8413. clone.__index__ = 0;
  8414. clone.__values__ = undefined;
  8415. if (result) {
  8416. previous.__wrapped__ = clone;
  8417. } else {
  8418. result = clone;
  8419. }
  8420. var previous = clone;
  8421. parent = parent.__wrapped__;
  8422. }
  8423. previous.__wrapped__ = value;
  8424. return result;
  8425. }
  8426. /**
  8427. * This method is the wrapper version of `_.reverse`.
  8428. *
  8429. * **Note:** This method mutates the wrapped array.
  8430. *
  8431. * @name reverse
  8432. * @memberOf _
  8433. * @since 0.1.0
  8434. * @category Seq
  8435. * @returns {Object} Returns the new `lodash` wrapper instance.
  8436. * @example
  8437. *
  8438. * var array = [1, 2, 3];
  8439. *
  8440. * _(array).reverse().value()
  8441. * // => [3, 2, 1]
  8442. *
  8443. * console.log(array);
  8444. * // => [3, 2, 1]
  8445. */
  8446. function wrapperReverse() {
  8447. var value = this.__wrapped__;
  8448. if (value instanceof LazyWrapper) {
  8449. var wrapped = value;
  8450. if (this.__actions__.length) {
  8451. wrapped = new LazyWrapper(this);
  8452. }
  8453. wrapped = wrapped.reverse();
  8454. wrapped.__actions__.push({
  8455. 'func': thru,
  8456. 'args': [reverse],
  8457. 'thisArg': undefined
  8458. });
  8459. return new LodashWrapper(wrapped, this.__chain__);
  8460. }
  8461. return this.thru(reverse);
  8462. }
  8463. /**
  8464. * Executes the chain sequence to resolve the unwrapped value.
  8465. *
  8466. * @name value
  8467. * @memberOf _
  8468. * @since 0.1.0
  8469. * @alias toJSON, valueOf
  8470. * @category Seq
  8471. * @returns {*} Returns the resolved unwrapped value.
  8472. * @example
  8473. *
  8474. * _([1, 2, 3]).value();
  8475. * // => [1, 2, 3]
  8476. */
  8477. function wrapperValue() {
  8478. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8479. }
  8480. /*------------------------------------------------------------------------*/
  8481. /**
  8482. * Creates an object composed of keys generated from the results of running
  8483. * each element of `collection` thru `iteratee`. The corresponding value of
  8484. * each key is the number of times the key was returned by `iteratee`. The
  8485. * iteratee is invoked with one argument: (value).
  8486. *
  8487. * @static
  8488. * @memberOf _
  8489. * @since 0.5.0
  8490. * @category Collection
  8491. * @param {Array|Object} collection The collection to iterate over.
  8492. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8493. * @returns {Object} Returns the composed aggregate object.
  8494. * @example
  8495. *
  8496. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8497. * // => { '4': 1, '6': 2 }
  8498. *
  8499. * // The `_.property` iteratee shorthand.
  8500. * _.countBy(['one', 'two', 'three'], 'length');
  8501. * // => { '3': 2, '5': 1 }
  8502. */
  8503. var countBy = createAggregator(function(result, value, key) {
  8504. if (hasOwnProperty.call(result, key)) {
  8505. ++result[key];
  8506. } else {
  8507. baseAssignValue(result, key, 1);
  8508. }
  8509. });
  8510. /**
  8511. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8512. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8513. * invoked with three arguments: (value, index|key, collection).
  8514. *
  8515. * **Note:** This method returns `true` for
  8516. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8517. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8518. * elements of empty collections.
  8519. *
  8520. * @static
  8521. * @memberOf _
  8522. * @since 0.1.0
  8523. * @category Collection
  8524. * @param {Array|Object} collection The collection to iterate over.
  8525. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8526. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8527. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8528. * else `false`.
  8529. * @example
  8530. *
  8531. * _.every([true, 1, null, 'yes'], Boolean);
  8532. * // => false
  8533. *
  8534. * var users = [
  8535. * { 'user': 'barney', 'age': 36, 'active': false },
  8536. * { 'user': 'fred', 'age': 40, 'active': false }
  8537. * ];
  8538. *
  8539. * // The `_.matches` iteratee shorthand.
  8540. * _.every(users, { 'user': 'barney', 'active': false });
  8541. * // => false
  8542. *
  8543. * // The `_.matchesProperty` iteratee shorthand.
  8544. * _.every(users, ['active', false]);
  8545. * // => true
  8546. *
  8547. * // The `_.property` iteratee shorthand.
  8548. * _.every(users, 'active');
  8549. * // => false
  8550. */
  8551. function every(collection, predicate, guard) {
  8552. var func = isArray(collection) ? arrayEvery : baseEvery;
  8553. if (guard && isIterateeCall(collection, predicate, guard)) {
  8554. predicate = undefined;
  8555. }
  8556. return func(collection, getIteratee(predicate, 3));
  8557. }
  8558. /**
  8559. * Iterates over elements of `collection`, returning an array of all elements
  8560. * `predicate` returns truthy for. The predicate is invoked with three
  8561. * arguments: (value, index|key, collection).
  8562. *
  8563. * **Note:** Unlike `_.remove`, this method returns a new array.
  8564. *
  8565. * @static
  8566. * @memberOf _
  8567. * @since 0.1.0
  8568. * @category Collection
  8569. * @param {Array|Object} collection The collection to iterate over.
  8570. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8571. * @returns {Array} Returns the new filtered array.
  8572. * @see _.reject
  8573. * @example
  8574. *
  8575. * var users = [
  8576. * { 'user': 'barney', 'age': 36, 'active': true },
  8577. * { 'user': 'fred', 'age': 40, 'active': false }
  8578. * ];
  8579. *
  8580. * _.filter(users, function(o) { return !o.active; });
  8581. * // => objects for ['fred']
  8582. *
  8583. * // The `_.matches` iteratee shorthand.
  8584. * _.filter(users, { 'age': 36, 'active': true });
  8585. * // => objects for ['barney']
  8586. *
  8587. * // The `_.matchesProperty` iteratee shorthand.
  8588. * _.filter(users, ['active', false]);
  8589. * // => objects for ['fred']
  8590. *
  8591. * // The `_.property` iteratee shorthand.
  8592. * _.filter(users, 'active');
  8593. * // => objects for ['barney']
  8594. */
  8595. function filter(collection, predicate) {
  8596. var func = isArray(collection) ? arrayFilter : baseFilter;
  8597. return func(collection, getIteratee(predicate, 3));
  8598. }
  8599. /**
  8600. * Iterates over elements of `collection`, returning the first element
  8601. * `predicate` returns truthy for. The predicate is invoked with three
  8602. * arguments: (value, index|key, collection).
  8603. *
  8604. * @static
  8605. * @memberOf _
  8606. * @since 0.1.0
  8607. * @category Collection
  8608. * @param {Array|Object} collection The collection to inspect.
  8609. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8610. * @param {number} [fromIndex=0] The index to search from.
  8611. * @returns {*} Returns the matched element, else `undefined`.
  8612. * @example
  8613. *
  8614. * var users = [
  8615. * { 'user': 'barney', 'age': 36, 'active': true },
  8616. * { 'user': 'fred', 'age': 40, 'active': false },
  8617. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8618. * ];
  8619. *
  8620. * _.find(users, function(o) { return o.age < 40; });
  8621. * // => object for 'barney'
  8622. *
  8623. * // The `_.matches` iteratee shorthand.
  8624. * _.find(users, { 'age': 1, 'active': true });
  8625. * // => object for 'pebbles'
  8626. *
  8627. * // The `_.matchesProperty` iteratee shorthand.
  8628. * _.find(users, ['active', false]);
  8629. * // => object for 'fred'
  8630. *
  8631. * // The `_.property` iteratee shorthand.
  8632. * _.find(users, 'active');
  8633. * // => object for 'barney'
  8634. */
  8635. var find = createFind(findIndex);
  8636. /**
  8637. * This method is like `_.find` except that it iterates over elements of
  8638. * `collection` from right to left.
  8639. *
  8640. * @static
  8641. * @memberOf _
  8642. * @since 2.0.0
  8643. * @category Collection
  8644. * @param {Array|Object} collection The collection to inspect.
  8645. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8646. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8647. * @returns {*} Returns the matched element, else `undefined`.
  8648. * @example
  8649. *
  8650. * _.findLast([1, 2, 3, 4], function(n) {
  8651. * return n % 2 == 1;
  8652. * });
  8653. * // => 3
  8654. */
  8655. var findLast = createFind(findLastIndex);
  8656. /**
  8657. * Creates a flattened array of values by running each element in `collection`
  8658. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8659. * with three arguments: (value, index|key, collection).
  8660. *
  8661. * @static
  8662. * @memberOf _
  8663. * @since 4.0.0
  8664. * @category Collection
  8665. * @param {Array|Object} collection The collection to iterate over.
  8666. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8667. * @returns {Array} Returns the new flattened array.
  8668. * @example
  8669. *
  8670. * function duplicate(n) {
  8671. * return [n, n];
  8672. * }
  8673. *
  8674. * _.flatMap([1, 2], duplicate);
  8675. * // => [1, 1, 2, 2]
  8676. */
  8677. function flatMap(collection, iteratee) {
  8678. return baseFlatten(map(collection, iteratee), 1);
  8679. }
  8680. /**
  8681. * This method is like `_.flatMap` except that it recursively flattens the
  8682. * mapped results.
  8683. *
  8684. * @static
  8685. * @memberOf _
  8686. * @since 4.7.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. * @returns {Array} Returns the new flattened array.
  8691. * @example
  8692. *
  8693. * function duplicate(n) {
  8694. * return [[[n, n]]];
  8695. * }
  8696. *
  8697. * _.flatMapDeep([1, 2], duplicate);
  8698. * // => [1, 1, 2, 2]
  8699. */
  8700. function flatMapDeep(collection, iteratee) {
  8701. return baseFlatten(map(collection, iteratee), INFINITY);
  8702. }
  8703. /**
  8704. * This method is like `_.flatMap` except that it recursively flattens the
  8705. * mapped results up to `depth` times.
  8706. *
  8707. * @static
  8708. * @memberOf _
  8709. * @since 4.7.0
  8710. * @category Collection
  8711. * @param {Array|Object} collection The collection to iterate over.
  8712. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8713. * @param {number} [depth=1] The maximum recursion depth.
  8714. * @returns {Array} Returns the new flattened array.
  8715. * @example
  8716. *
  8717. * function duplicate(n) {
  8718. * return [[[n, n]]];
  8719. * }
  8720. *
  8721. * _.flatMapDepth([1, 2], duplicate, 2);
  8722. * // => [[1, 1], [2, 2]]
  8723. */
  8724. function flatMapDepth(collection, iteratee, depth) {
  8725. depth = depth === undefined ? 1 : toInteger(depth);
  8726. return baseFlatten(map(collection, iteratee), depth);
  8727. }
  8728. /**
  8729. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8730. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8731. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8732. *
  8733. * **Note:** As with other "Collections" methods, objects with a "length"
  8734. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8735. * or `_.forOwn` for object iteration.
  8736. *
  8737. * @static
  8738. * @memberOf _
  8739. * @since 0.1.0
  8740. * @alias each
  8741. * @category Collection
  8742. * @param {Array|Object} collection The collection to iterate over.
  8743. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8744. * @returns {Array|Object} Returns `collection`.
  8745. * @see _.forEachRight
  8746. * @example
  8747. *
  8748. * _.forEach([1, 2], function(value) {
  8749. * console.log(value);
  8750. * });
  8751. * // => Logs `1` then `2`.
  8752. *
  8753. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8754. * console.log(key);
  8755. * });
  8756. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8757. */
  8758. function forEach(collection, iteratee) {
  8759. var func = isArray(collection) ? arrayEach : baseEach;
  8760. return func(collection, getIteratee(iteratee, 3));
  8761. }
  8762. /**
  8763. * This method is like `_.forEach` except that it iterates over elements of
  8764. * `collection` from right to left.
  8765. *
  8766. * @static
  8767. * @memberOf _
  8768. * @since 2.0.0
  8769. * @alias eachRight
  8770. * @category Collection
  8771. * @param {Array|Object} collection The collection to iterate over.
  8772. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8773. * @returns {Array|Object} Returns `collection`.
  8774. * @see _.forEach
  8775. * @example
  8776. *
  8777. * _.forEachRight([1, 2], function(value) {
  8778. * console.log(value);
  8779. * });
  8780. * // => Logs `2` then `1`.
  8781. */
  8782. function forEachRight(collection, iteratee) {
  8783. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8784. return func(collection, getIteratee(iteratee, 3));
  8785. }
  8786. /**
  8787. * Creates an object composed of keys generated from the results of running
  8788. * each element of `collection` thru `iteratee`. The order of grouped values
  8789. * is determined by the order they occur in `collection`. The corresponding
  8790. * value of each key is an array of elements responsible for generating the
  8791. * key. The iteratee is invoked with one argument: (value).
  8792. *
  8793. * @static
  8794. * @memberOf _
  8795. * @since 0.1.0
  8796. * @category Collection
  8797. * @param {Array|Object} collection The collection to iterate over.
  8798. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8799. * @returns {Object} Returns the composed aggregate object.
  8800. * @example
  8801. *
  8802. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8803. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8804. *
  8805. * // The `_.property` iteratee shorthand.
  8806. * _.groupBy(['one', 'two', 'three'], 'length');
  8807. * // => { '3': ['one', 'two'], '5': ['three'] }
  8808. */
  8809. var groupBy = createAggregator(function(result, value, key) {
  8810. if (hasOwnProperty.call(result, key)) {
  8811. result[key].push(value);
  8812. } else {
  8813. baseAssignValue(result, key, [value]);
  8814. }
  8815. });
  8816. /**
  8817. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8818. * checked for a substring of `value`, otherwise
  8819. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8820. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8821. * the offset from the end of `collection`.
  8822. *
  8823. * @static
  8824. * @memberOf _
  8825. * @since 0.1.0
  8826. * @category Collection
  8827. * @param {Array|Object|string} collection The collection to inspect.
  8828. * @param {*} value The value to search for.
  8829. * @param {number} [fromIndex=0] The index to search from.
  8830. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8831. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8832. * @example
  8833. *
  8834. * _.includes([1, 2, 3], 1);
  8835. * // => true
  8836. *
  8837. * _.includes([1, 2, 3], 1, 2);
  8838. * // => false
  8839. *
  8840. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8841. * // => true
  8842. *
  8843. * _.includes('abcd', 'bc');
  8844. * // => true
  8845. */
  8846. function includes(collection, value, fromIndex, guard) {
  8847. collection = isArrayLike(collection) ? collection : values(collection);
  8848. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8849. var length = collection.length;
  8850. if (fromIndex < 0) {
  8851. fromIndex = nativeMax(length + fromIndex, 0);
  8852. }
  8853. return isString(collection)
  8854. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8855. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8856. }
  8857. /**
  8858. * Invokes the method at `path` of each element in `collection`, returning
  8859. * an array of the results of each invoked method. Any additional arguments
  8860. * are provided to each invoked method. If `path` is a function, it's invoked
  8861. * for, and `this` bound to, each element in `collection`.
  8862. *
  8863. * @static
  8864. * @memberOf _
  8865. * @since 4.0.0
  8866. * @category Collection
  8867. * @param {Array|Object} collection The collection to iterate over.
  8868. * @param {Array|Function|string} path The path of the method to invoke or
  8869. * the function invoked per iteration.
  8870. * @param {...*} [args] The arguments to invoke each method with.
  8871. * @returns {Array} Returns the array of results.
  8872. * @example
  8873. *
  8874. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8875. * // => [[1, 5, 7], [1, 2, 3]]
  8876. *
  8877. * _.invokeMap([123, 456], String.prototype.split, '');
  8878. * // => [['1', '2', '3'], ['4', '5', '6']]
  8879. */
  8880. var invokeMap = baseRest(function(collection, path, args) {
  8881. var index = -1,
  8882. isFunc = typeof path == 'function',
  8883. result = isArrayLike(collection) ? Array(collection.length) : [];
  8884. baseEach(collection, function(value) {
  8885. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8886. });
  8887. return result;
  8888. });
  8889. /**
  8890. * Creates an object composed of keys generated from the results of running
  8891. * each element of `collection` thru `iteratee`. The corresponding value of
  8892. * each key is the last element responsible for generating the key. The
  8893. * iteratee is invoked with one argument: (value).
  8894. *
  8895. * @static
  8896. * @memberOf _
  8897. * @since 4.0.0
  8898. * @category Collection
  8899. * @param {Array|Object} collection The collection to iterate over.
  8900. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8901. * @returns {Object} Returns the composed aggregate object.
  8902. * @example
  8903. *
  8904. * var array = [
  8905. * { 'dir': 'left', 'code': 97 },
  8906. * { 'dir': 'right', 'code': 100 }
  8907. * ];
  8908. *
  8909. * _.keyBy(array, function(o) {
  8910. * return String.fromCharCode(o.code);
  8911. * });
  8912. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8913. *
  8914. * _.keyBy(array, 'dir');
  8915. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8916. */
  8917. var keyBy = createAggregator(function(result, value, key) {
  8918. baseAssignValue(result, key, value);
  8919. });
  8920. /**
  8921. * Creates an array of values by running each element in `collection` thru
  8922. * `iteratee`. The iteratee is invoked with three arguments:
  8923. * (value, index|key, collection).
  8924. *
  8925. * Many lodash methods are guarded to work as iteratees for methods like
  8926. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8927. *
  8928. * The guarded methods are:
  8929. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8930. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8931. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8932. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8933. *
  8934. * @static
  8935. * @memberOf _
  8936. * @since 0.1.0
  8937. * @category Collection
  8938. * @param {Array|Object} collection The collection to iterate over.
  8939. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8940. * @returns {Array} Returns the new mapped array.
  8941. * @example
  8942. *
  8943. * function square(n) {
  8944. * return n * n;
  8945. * }
  8946. *
  8947. * _.map([4, 8], square);
  8948. * // => [16, 64]
  8949. *
  8950. * _.map({ 'a': 4, 'b': 8 }, square);
  8951. * // => [16, 64] (iteration order is not guaranteed)
  8952. *
  8953. * var users = [
  8954. * { 'user': 'barney' },
  8955. * { 'user': 'fred' }
  8956. * ];
  8957. *
  8958. * // The `_.property` iteratee shorthand.
  8959. * _.map(users, 'user');
  8960. * // => ['barney', 'fred']
  8961. */
  8962. function map(collection, iteratee) {
  8963. var func = isArray(collection) ? arrayMap : baseMap;
  8964. return func(collection, getIteratee(iteratee, 3));
  8965. }
  8966. /**
  8967. * This method is like `_.sortBy` except that it allows specifying the sort
  8968. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8969. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8970. * descending or "asc" for ascending sort order of corresponding values.
  8971. *
  8972. * @static
  8973. * @memberOf _
  8974. * @since 4.0.0
  8975. * @category Collection
  8976. * @param {Array|Object} collection The collection to iterate over.
  8977. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8978. * The iteratees to sort by.
  8979. * @param {string[]} [orders] The sort orders of `iteratees`.
  8980. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8981. * @returns {Array} Returns the new sorted array.
  8982. * @example
  8983. *
  8984. * var users = [
  8985. * { 'user': 'fred', 'age': 48 },
  8986. * { 'user': 'barney', 'age': 34 },
  8987. * { 'user': 'fred', 'age': 40 },
  8988. * { 'user': 'barney', 'age': 36 }
  8989. * ];
  8990. *
  8991. * // Sort by `user` in ascending order and by `age` in descending order.
  8992. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8993. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8994. */
  8995. function orderBy(collection, iteratees, orders, guard) {
  8996. if (collection == null) {
  8997. return [];
  8998. }
  8999. if (!isArray(iteratees)) {
  9000. iteratees = iteratees == null ? [] : [iteratees];
  9001. }
  9002. orders = guard ? undefined : orders;
  9003. if (!isArray(orders)) {
  9004. orders = orders == null ? [] : [orders];
  9005. }
  9006. return baseOrderBy(collection, iteratees, orders);
  9007. }
  9008. /**
  9009. * Creates an array of elements split into two groups, the first of which
  9010. * contains elements `predicate` returns truthy for, the second of which
  9011. * contains elements `predicate` returns falsey for. The predicate is
  9012. * invoked with one argument: (value).
  9013. *
  9014. * @static
  9015. * @memberOf _
  9016. * @since 3.0.0
  9017. * @category Collection
  9018. * @param {Array|Object} collection The collection to iterate over.
  9019. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9020. * @returns {Array} Returns the array of grouped elements.
  9021. * @example
  9022. *
  9023. * var users = [
  9024. * { 'user': 'barney', 'age': 36, 'active': false },
  9025. * { 'user': 'fred', 'age': 40, 'active': true },
  9026. * { 'user': 'pebbles', 'age': 1, 'active': false }
  9027. * ];
  9028. *
  9029. * _.partition(users, function(o) { return o.active; });
  9030. * // => objects for [['fred'], ['barney', 'pebbles']]
  9031. *
  9032. * // The `_.matches` iteratee shorthand.
  9033. * _.partition(users, { 'age': 1, 'active': false });
  9034. * // => objects for [['pebbles'], ['barney', 'fred']]
  9035. *
  9036. * // The `_.matchesProperty` iteratee shorthand.
  9037. * _.partition(users, ['active', false]);
  9038. * // => objects for [['barney', 'pebbles'], ['fred']]
  9039. *
  9040. * // The `_.property` iteratee shorthand.
  9041. * _.partition(users, 'active');
  9042. * // => objects for [['fred'], ['barney', 'pebbles']]
  9043. */
  9044. var partition = createAggregator(function(result, value, key) {
  9045. result[key ? 0 : 1].push(value);
  9046. }, function() { return [[], []]; });
  9047. /**
  9048. * Reduces `collection` to a value which is the accumulated result of running
  9049. * each element in `collection` thru `iteratee`, where each successive
  9050. * invocation is supplied the return value of the previous. If `accumulator`
  9051. * is not given, the first element of `collection` is used as the initial
  9052. * value. The iteratee is invoked with four arguments:
  9053. * (accumulator, value, index|key, collection).
  9054. *
  9055. * Many lodash methods are guarded to work as iteratees for methods like
  9056. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  9057. *
  9058. * The guarded methods are:
  9059. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  9060. * and `sortBy`
  9061. *
  9062. * @static
  9063. * @memberOf _
  9064. * @since 0.1.0
  9065. * @category Collection
  9066. * @param {Array|Object} collection The collection to iterate over.
  9067. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9068. * @param {*} [accumulator] The initial value.
  9069. * @returns {*} Returns the accumulated value.
  9070. * @see _.reduceRight
  9071. * @example
  9072. *
  9073. * _.reduce([1, 2], function(sum, n) {
  9074. * return sum + n;
  9075. * }, 0);
  9076. * // => 3
  9077. *
  9078. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  9079. * (result[value] || (result[value] = [])).push(key);
  9080. * return result;
  9081. * }, {});
  9082. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  9083. */
  9084. function reduce(collection, iteratee, accumulator) {
  9085. var func = isArray(collection) ? arrayReduce : baseReduce,
  9086. initAccum = arguments.length < 3;
  9087. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  9088. }
  9089. /**
  9090. * This method is like `_.reduce` except that it iterates over elements of
  9091. * `collection` from right to left.
  9092. *
  9093. * @static
  9094. * @memberOf _
  9095. * @since 0.1.0
  9096. * @category Collection
  9097. * @param {Array|Object} collection The collection to iterate over.
  9098. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9099. * @param {*} [accumulator] The initial value.
  9100. * @returns {*} Returns the accumulated value.
  9101. * @see _.reduce
  9102. * @example
  9103. *
  9104. * var array = [[0, 1], [2, 3], [4, 5]];
  9105. *
  9106. * _.reduceRight(array, function(flattened, other) {
  9107. * return flattened.concat(other);
  9108. * }, []);
  9109. * // => [4, 5, 2, 3, 0, 1]
  9110. */
  9111. function reduceRight(collection, iteratee, accumulator) {
  9112. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9113. initAccum = arguments.length < 3;
  9114. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9115. }
  9116. /**
  9117. * The opposite of `_.filter`; this method returns the elements of `collection`
  9118. * that `predicate` does **not** return truthy for.
  9119. *
  9120. * @static
  9121. * @memberOf _
  9122. * @since 0.1.0
  9123. * @category Collection
  9124. * @param {Array|Object} collection The collection to iterate over.
  9125. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9126. * @returns {Array} Returns the new filtered array.
  9127. * @see _.filter
  9128. * @example
  9129. *
  9130. * var users = [
  9131. * { 'user': 'barney', 'age': 36, 'active': false },
  9132. * { 'user': 'fred', 'age': 40, 'active': true }
  9133. * ];
  9134. *
  9135. * _.reject(users, function(o) { return !o.active; });
  9136. * // => objects for ['fred']
  9137. *
  9138. * // The `_.matches` iteratee shorthand.
  9139. * _.reject(users, { 'age': 40, 'active': true });
  9140. * // => objects for ['barney']
  9141. *
  9142. * // The `_.matchesProperty` iteratee shorthand.
  9143. * _.reject(users, ['active', false]);
  9144. * // => objects for ['fred']
  9145. *
  9146. * // The `_.property` iteratee shorthand.
  9147. * _.reject(users, 'active');
  9148. * // => objects for ['barney']
  9149. */
  9150. function reject(collection, predicate) {
  9151. var func = isArray(collection) ? arrayFilter : baseFilter;
  9152. return func(collection, negate(getIteratee(predicate, 3)));
  9153. }
  9154. /**
  9155. * Gets a random element from `collection`.
  9156. *
  9157. * @static
  9158. * @memberOf _
  9159. * @since 2.0.0
  9160. * @category Collection
  9161. * @param {Array|Object} collection The collection to sample.
  9162. * @returns {*} Returns the random element.
  9163. * @example
  9164. *
  9165. * _.sample([1, 2, 3, 4]);
  9166. * // => 2
  9167. */
  9168. function sample(collection) {
  9169. var func = isArray(collection) ? arraySample : baseSample;
  9170. return func(collection);
  9171. }
  9172. /**
  9173. * Gets `n` random elements at unique keys from `collection` up to the
  9174. * size of `collection`.
  9175. *
  9176. * @static
  9177. * @memberOf _
  9178. * @since 4.0.0
  9179. * @category Collection
  9180. * @param {Array|Object} collection The collection to sample.
  9181. * @param {number} [n=1] The number of elements to sample.
  9182. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9183. * @returns {Array} Returns the random elements.
  9184. * @example
  9185. *
  9186. * _.sampleSize([1, 2, 3], 2);
  9187. * // => [3, 1]
  9188. *
  9189. * _.sampleSize([1, 2, 3], 4);
  9190. * // => [2, 3, 1]
  9191. */
  9192. function sampleSize(collection, n, guard) {
  9193. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9194. n = 1;
  9195. } else {
  9196. n = toInteger(n);
  9197. }
  9198. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9199. return func(collection, n);
  9200. }
  9201. /**
  9202. * Creates an array of shuffled values, using a version of the
  9203. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9204. *
  9205. * @static
  9206. * @memberOf _
  9207. * @since 0.1.0
  9208. * @category Collection
  9209. * @param {Array|Object} collection The collection to shuffle.
  9210. * @returns {Array} Returns the new shuffled array.
  9211. * @example
  9212. *
  9213. * _.shuffle([1, 2, 3, 4]);
  9214. * // => [4, 1, 3, 2]
  9215. */
  9216. function shuffle(collection) {
  9217. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9218. return func(collection);
  9219. }
  9220. /**
  9221. * Gets the size of `collection` by returning its length for array-like
  9222. * values or the number of own enumerable string keyed properties for objects.
  9223. *
  9224. * @static
  9225. * @memberOf _
  9226. * @since 0.1.0
  9227. * @category Collection
  9228. * @param {Array|Object|string} collection The collection to inspect.
  9229. * @returns {number} Returns the collection size.
  9230. * @example
  9231. *
  9232. * _.size([1, 2, 3]);
  9233. * // => 3
  9234. *
  9235. * _.size({ 'a': 1, 'b': 2 });
  9236. * // => 2
  9237. *
  9238. * _.size('pebbles');
  9239. * // => 7
  9240. */
  9241. function size(collection) {
  9242. if (collection == null) {
  9243. return 0;
  9244. }
  9245. if (isArrayLike(collection)) {
  9246. return isString(collection) ? stringSize(collection) : collection.length;
  9247. }
  9248. var tag = getTag(collection);
  9249. if (tag == mapTag || tag == setTag) {
  9250. return collection.size;
  9251. }
  9252. return baseKeys(collection).length;
  9253. }
  9254. /**
  9255. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9256. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9257. * invoked with three arguments: (value, index|key, collection).
  9258. *
  9259. * @static
  9260. * @memberOf _
  9261. * @since 0.1.0
  9262. * @category Collection
  9263. * @param {Array|Object} collection The collection to iterate over.
  9264. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9265. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9266. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9267. * else `false`.
  9268. * @example
  9269. *
  9270. * _.some([null, 0, 'yes', false], Boolean);
  9271. * // => true
  9272. *
  9273. * var users = [
  9274. * { 'user': 'barney', 'active': true },
  9275. * { 'user': 'fred', 'active': false }
  9276. * ];
  9277. *
  9278. * // The `_.matches` iteratee shorthand.
  9279. * _.some(users, { 'user': 'barney', 'active': false });
  9280. * // => false
  9281. *
  9282. * // The `_.matchesProperty` iteratee shorthand.
  9283. * _.some(users, ['active', false]);
  9284. * // => true
  9285. *
  9286. * // The `_.property` iteratee shorthand.
  9287. * _.some(users, 'active');
  9288. * // => true
  9289. */
  9290. function some(collection, predicate, guard) {
  9291. var func = isArray(collection) ? arraySome : baseSome;
  9292. if (guard && isIterateeCall(collection, predicate, guard)) {
  9293. predicate = undefined;
  9294. }
  9295. return func(collection, getIteratee(predicate, 3));
  9296. }
  9297. /**
  9298. * Creates an array of elements, sorted in ascending order by the results of
  9299. * running each element in a collection thru each iteratee. This method
  9300. * performs a stable sort, that is, it preserves the original sort order of
  9301. * equal elements. The iteratees are invoked with one argument: (value).
  9302. *
  9303. * @static
  9304. * @memberOf _
  9305. * @since 0.1.0
  9306. * @category Collection
  9307. * @param {Array|Object} collection The collection to iterate over.
  9308. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9309. * The iteratees to sort by.
  9310. * @returns {Array} Returns the new sorted array.
  9311. * @example
  9312. *
  9313. * var users = [
  9314. * { 'user': 'fred', 'age': 48 },
  9315. * { 'user': 'barney', 'age': 36 },
  9316. * { 'user': 'fred', 'age': 40 },
  9317. * { 'user': 'barney', 'age': 34 }
  9318. * ];
  9319. *
  9320. * _.sortBy(users, [function(o) { return o.user; }]);
  9321. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  9322. *
  9323. * _.sortBy(users, ['user', 'age']);
  9324. * // => objects for [['barney', 34], ['barney', 36], ['fred', 40], ['fred', 48]]
  9325. */
  9326. var sortBy = baseRest(function(collection, iteratees) {
  9327. if (collection == null) {
  9328. return [];
  9329. }
  9330. var length = iteratees.length;
  9331. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9332. iteratees = [];
  9333. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9334. iteratees = [iteratees[0]];
  9335. }
  9336. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9337. });
  9338. /*------------------------------------------------------------------------*/
  9339. /**
  9340. * Gets the timestamp of the number of milliseconds that have elapsed since
  9341. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9342. *
  9343. * @static
  9344. * @memberOf _
  9345. * @since 2.4.0
  9346. * @category Date
  9347. * @returns {number} Returns the timestamp.
  9348. * @example
  9349. *
  9350. * _.defer(function(stamp) {
  9351. * console.log(_.now() - stamp);
  9352. * }, _.now());
  9353. * // => Logs the number of milliseconds it took for the deferred invocation.
  9354. */
  9355. var now = ctxNow || function() {
  9356. return root.Date.now();
  9357. };
  9358. /*------------------------------------------------------------------------*/
  9359. /**
  9360. * The opposite of `_.before`; this method creates a function that invokes
  9361. * `func` once it's called `n` or more times.
  9362. *
  9363. * @static
  9364. * @memberOf _
  9365. * @since 0.1.0
  9366. * @category Function
  9367. * @param {number} n The number of calls before `func` is invoked.
  9368. * @param {Function} func The function to restrict.
  9369. * @returns {Function} Returns the new restricted function.
  9370. * @example
  9371. *
  9372. * var saves = ['profile', 'settings'];
  9373. *
  9374. * var done = _.after(saves.length, function() {
  9375. * console.log('done saving!');
  9376. * });
  9377. *
  9378. * _.forEach(saves, function(type) {
  9379. * asyncSave({ 'type': type, 'complete': done });
  9380. * });
  9381. * // => Logs 'done saving!' after the two async saves have completed.
  9382. */
  9383. function after(n, func) {
  9384. if (typeof func != 'function') {
  9385. throw new TypeError(FUNC_ERROR_TEXT);
  9386. }
  9387. n = toInteger(n);
  9388. return function() {
  9389. if (--n < 1) {
  9390. return func.apply(this, arguments);
  9391. }
  9392. };
  9393. }
  9394. /**
  9395. * Creates a function that invokes `func`, with up to `n` arguments,
  9396. * ignoring any additional arguments.
  9397. *
  9398. * @static
  9399. * @memberOf _
  9400. * @since 3.0.0
  9401. * @category Function
  9402. * @param {Function} func The function to cap arguments for.
  9403. * @param {number} [n=func.length] The arity cap.
  9404. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9405. * @returns {Function} Returns the new capped function.
  9406. * @example
  9407. *
  9408. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9409. * // => [6, 8, 10]
  9410. */
  9411. function ary(func, n, guard) {
  9412. n = guard ? undefined : n;
  9413. n = (func && n == null) ? func.length : n;
  9414. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9415. }
  9416. /**
  9417. * Creates a function that invokes `func`, with the `this` binding and arguments
  9418. * of the created function, while it's called less than `n` times. Subsequent
  9419. * calls to the created function return the result of the last `func` invocation.
  9420. *
  9421. * @static
  9422. * @memberOf _
  9423. * @since 3.0.0
  9424. * @category Function
  9425. * @param {number} n The number of calls at which `func` is no longer invoked.
  9426. * @param {Function} func The function to restrict.
  9427. * @returns {Function} Returns the new restricted function.
  9428. * @example
  9429. *
  9430. * jQuery(element).on('click', _.before(5, addContactToList));
  9431. * // => Allows adding up to 4 contacts to the list.
  9432. */
  9433. function before(n, func) {
  9434. var result;
  9435. if (typeof func != 'function') {
  9436. throw new TypeError(FUNC_ERROR_TEXT);
  9437. }
  9438. n = toInteger(n);
  9439. return function() {
  9440. if (--n > 0) {
  9441. result = func.apply(this, arguments);
  9442. }
  9443. if (n <= 1) {
  9444. func = undefined;
  9445. }
  9446. return result;
  9447. };
  9448. }
  9449. /**
  9450. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9451. * and `partials` prepended to the arguments it receives.
  9452. *
  9453. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9454. * may be used as a placeholder for partially applied arguments.
  9455. *
  9456. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9457. * property of bound functions.
  9458. *
  9459. * @static
  9460. * @memberOf _
  9461. * @since 0.1.0
  9462. * @category Function
  9463. * @param {Function} func The function to bind.
  9464. * @param {*} thisArg The `this` binding of `func`.
  9465. * @param {...*} [partials] The arguments to be partially applied.
  9466. * @returns {Function} Returns the new bound function.
  9467. * @example
  9468. *
  9469. * function greet(greeting, punctuation) {
  9470. * return greeting + ' ' + this.user + punctuation;
  9471. * }
  9472. *
  9473. * var object = { 'user': 'fred' };
  9474. *
  9475. * var bound = _.bind(greet, object, 'hi');
  9476. * bound('!');
  9477. * // => 'hi fred!'
  9478. *
  9479. * // Bound with placeholders.
  9480. * var bound = _.bind(greet, object, _, '!');
  9481. * bound('hi');
  9482. * // => 'hi fred!'
  9483. */
  9484. var bind = baseRest(function(func, thisArg, partials) {
  9485. var bitmask = WRAP_BIND_FLAG;
  9486. if (partials.length) {
  9487. var holders = replaceHolders(partials, getHolder(bind));
  9488. bitmask |= WRAP_PARTIAL_FLAG;
  9489. }
  9490. return createWrap(func, bitmask, thisArg, partials, holders);
  9491. });
  9492. /**
  9493. * Creates a function that invokes the method at `object[key]` with `partials`
  9494. * prepended to the arguments it receives.
  9495. *
  9496. * This method differs from `_.bind` by allowing bound functions to reference
  9497. * methods that may be redefined or don't yet exist. See
  9498. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9499. * for more details.
  9500. *
  9501. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9502. * builds, may be used as a placeholder for partially applied arguments.
  9503. *
  9504. * @static
  9505. * @memberOf _
  9506. * @since 0.10.0
  9507. * @category Function
  9508. * @param {Object} object The object to invoke the method on.
  9509. * @param {string} key The key of the method.
  9510. * @param {...*} [partials] The arguments to be partially applied.
  9511. * @returns {Function} Returns the new bound function.
  9512. * @example
  9513. *
  9514. * var object = {
  9515. * 'user': 'fred',
  9516. * 'greet': function(greeting, punctuation) {
  9517. * return greeting + ' ' + this.user + punctuation;
  9518. * }
  9519. * };
  9520. *
  9521. * var bound = _.bindKey(object, 'greet', 'hi');
  9522. * bound('!');
  9523. * // => 'hi fred!'
  9524. *
  9525. * object.greet = function(greeting, punctuation) {
  9526. * return greeting + 'ya ' + this.user + punctuation;
  9527. * };
  9528. *
  9529. * bound('!');
  9530. * // => 'hiya fred!'
  9531. *
  9532. * // Bound with placeholders.
  9533. * var bound = _.bindKey(object, 'greet', _, '!');
  9534. * bound('hi');
  9535. * // => 'hiya fred!'
  9536. */
  9537. var bindKey = baseRest(function(object, key, partials) {
  9538. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9539. if (partials.length) {
  9540. var holders = replaceHolders(partials, getHolder(bindKey));
  9541. bitmask |= WRAP_PARTIAL_FLAG;
  9542. }
  9543. return createWrap(key, bitmask, object, partials, holders);
  9544. });
  9545. /**
  9546. * Creates a function that accepts arguments of `func` and either invokes
  9547. * `func` returning its result, if at least `arity` number of arguments have
  9548. * been provided, or returns a function that accepts the remaining `func`
  9549. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9550. * is not sufficient.
  9551. *
  9552. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9553. * may be used as a placeholder for provided arguments.
  9554. *
  9555. * **Note:** This method doesn't set the "length" property of curried functions.
  9556. *
  9557. * @static
  9558. * @memberOf _
  9559. * @since 2.0.0
  9560. * @category Function
  9561. * @param {Function} func The function to curry.
  9562. * @param {number} [arity=func.length] The arity of `func`.
  9563. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9564. * @returns {Function} Returns the new curried function.
  9565. * @example
  9566. *
  9567. * var abc = function(a, b, c) {
  9568. * return [a, b, c];
  9569. * };
  9570. *
  9571. * var curried = _.curry(abc);
  9572. *
  9573. * curried(1)(2)(3);
  9574. * // => [1, 2, 3]
  9575. *
  9576. * curried(1, 2)(3);
  9577. * // => [1, 2, 3]
  9578. *
  9579. * curried(1, 2, 3);
  9580. * // => [1, 2, 3]
  9581. *
  9582. * // Curried with placeholders.
  9583. * curried(1)(_, 3)(2);
  9584. * // => [1, 2, 3]
  9585. */
  9586. function curry(func, arity, guard) {
  9587. arity = guard ? undefined : arity;
  9588. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9589. result.placeholder = curry.placeholder;
  9590. return result;
  9591. }
  9592. /**
  9593. * This method is like `_.curry` except that arguments are applied to `func`
  9594. * in the manner of `_.partialRight` instead of `_.partial`.
  9595. *
  9596. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9597. * builds, may be used as a placeholder for provided arguments.
  9598. *
  9599. * **Note:** This method doesn't set the "length" property of curried functions.
  9600. *
  9601. * @static
  9602. * @memberOf _
  9603. * @since 3.0.0
  9604. * @category Function
  9605. * @param {Function} func The function to curry.
  9606. * @param {number} [arity=func.length] The arity of `func`.
  9607. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9608. * @returns {Function} Returns the new curried function.
  9609. * @example
  9610. *
  9611. * var abc = function(a, b, c) {
  9612. * return [a, b, c];
  9613. * };
  9614. *
  9615. * var curried = _.curryRight(abc);
  9616. *
  9617. * curried(3)(2)(1);
  9618. * // => [1, 2, 3]
  9619. *
  9620. * curried(2, 3)(1);
  9621. * // => [1, 2, 3]
  9622. *
  9623. * curried(1, 2, 3);
  9624. * // => [1, 2, 3]
  9625. *
  9626. * // Curried with placeholders.
  9627. * curried(3)(1, _)(2);
  9628. * // => [1, 2, 3]
  9629. */
  9630. function curryRight(func, arity, guard) {
  9631. arity = guard ? undefined : arity;
  9632. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9633. result.placeholder = curryRight.placeholder;
  9634. return result;
  9635. }
  9636. /**
  9637. * Creates a debounced function that delays invoking `func` until after `wait`
  9638. * milliseconds have elapsed since the last time the debounced function was
  9639. * invoked. The debounced function comes with a `cancel` method to cancel
  9640. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9641. * Provide `options` to indicate whether `func` should be invoked on the
  9642. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9643. * with the last arguments provided to the debounced function. Subsequent
  9644. * calls to the debounced function return the result of the last `func`
  9645. * invocation.
  9646. *
  9647. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9648. * invoked on the trailing edge of the timeout only if the debounced function
  9649. * is invoked more than once during the `wait` timeout.
  9650. *
  9651. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9652. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9653. *
  9654. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9655. * for details over the differences between `_.debounce` and `_.throttle`.
  9656. *
  9657. * @static
  9658. * @memberOf _
  9659. * @since 0.1.0
  9660. * @category Function
  9661. * @param {Function} func The function to debounce.
  9662. * @param {number} [wait=0] The number of milliseconds to delay.
  9663. * @param {Object} [options={}] The options object.
  9664. * @param {boolean} [options.leading=false]
  9665. * Specify invoking on the leading edge of the timeout.
  9666. * @param {number} [options.maxWait]
  9667. * The maximum time `func` is allowed to be delayed before it's invoked.
  9668. * @param {boolean} [options.trailing=true]
  9669. * Specify invoking on the trailing edge of the timeout.
  9670. * @returns {Function} Returns the new debounced function.
  9671. * @example
  9672. *
  9673. * // Avoid costly calculations while the window size is in flux.
  9674. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9675. *
  9676. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9677. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9678. * 'leading': true,
  9679. * 'trailing': false
  9680. * }));
  9681. *
  9682. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9683. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9684. * var source = new EventSource('/stream');
  9685. * jQuery(source).on('message', debounced);
  9686. *
  9687. * // Cancel the trailing debounced invocation.
  9688. * jQuery(window).on('popstate', debounced.cancel);
  9689. */
  9690. function debounce(func, wait, options) {
  9691. var lastArgs,
  9692. lastThis,
  9693. maxWait,
  9694. result,
  9695. timerId,
  9696. lastCallTime,
  9697. lastInvokeTime = 0,
  9698. leading = false,
  9699. maxing = false,
  9700. trailing = true;
  9701. if (typeof func != 'function') {
  9702. throw new TypeError(FUNC_ERROR_TEXT);
  9703. }
  9704. wait = toNumber(wait) || 0;
  9705. if (isObject(options)) {
  9706. leading = !!options.leading;
  9707. maxing = 'maxWait' in options;
  9708. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9709. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9710. }
  9711. function invokeFunc(time) {
  9712. var args = lastArgs,
  9713. thisArg = lastThis;
  9714. lastArgs = lastThis = undefined;
  9715. lastInvokeTime = time;
  9716. result = func.apply(thisArg, args);
  9717. return result;
  9718. }
  9719. function leadingEdge(time) {
  9720. // Reset any `maxWait` timer.
  9721. lastInvokeTime = time;
  9722. // Start the timer for the trailing edge.
  9723. timerId = setTimeout(timerExpired, wait);
  9724. // Invoke the leading edge.
  9725. return leading ? invokeFunc(time) : result;
  9726. }
  9727. function remainingWait(time) {
  9728. var timeSinceLastCall = time - lastCallTime,
  9729. timeSinceLastInvoke = time - lastInvokeTime,
  9730. result = wait - timeSinceLastCall;
  9731. return maxing ? nativeMin(result, maxWait - timeSinceLastInvoke) : result;
  9732. }
  9733. function shouldInvoke(time) {
  9734. var timeSinceLastCall = time - lastCallTime,
  9735. timeSinceLastInvoke = time - lastInvokeTime;
  9736. // Either this is the first call, activity has stopped and we're at the
  9737. // trailing edge, the system time has gone backwards and we're treating
  9738. // it as the trailing edge, or we've hit the `maxWait` limit.
  9739. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9740. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9741. }
  9742. function timerExpired() {
  9743. var time = now();
  9744. if (shouldInvoke(time)) {
  9745. return trailingEdge(time);
  9746. }
  9747. // Restart the timer.
  9748. timerId = setTimeout(timerExpired, remainingWait(time));
  9749. }
  9750. function trailingEdge(time) {
  9751. timerId = undefined;
  9752. // Only invoke if we have `lastArgs` which means `func` has been
  9753. // debounced at least once.
  9754. if (trailing && lastArgs) {
  9755. return invokeFunc(time);
  9756. }
  9757. lastArgs = lastThis = undefined;
  9758. return result;
  9759. }
  9760. function cancel() {
  9761. if (timerId !== undefined) {
  9762. clearTimeout(timerId);
  9763. }
  9764. lastInvokeTime = 0;
  9765. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9766. }
  9767. function flush() {
  9768. return timerId === undefined ? result : trailingEdge(now());
  9769. }
  9770. function debounced() {
  9771. var time = now(),
  9772. isInvoking = shouldInvoke(time);
  9773. lastArgs = arguments;
  9774. lastThis = this;
  9775. lastCallTime = time;
  9776. if (isInvoking) {
  9777. if (timerId === undefined) {
  9778. return leadingEdge(lastCallTime);
  9779. }
  9780. if (maxing) {
  9781. // Handle invocations in a tight loop.
  9782. timerId = setTimeout(timerExpired, wait);
  9783. return invokeFunc(lastCallTime);
  9784. }
  9785. }
  9786. if (timerId === undefined) {
  9787. timerId = setTimeout(timerExpired, wait);
  9788. }
  9789. return result;
  9790. }
  9791. debounced.cancel = cancel;
  9792. debounced.flush = flush;
  9793. return debounced;
  9794. }
  9795. /**
  9796. * Defers invoking the `func` until the current call stack has cleared. Any
  9797. * additional arguments are provided to `func` when it's invoked.
  9798. *
  9799. * @static
  9800. * @memberOf _
  9801. * @since 0.1.0
  9802. * @category Function
  9803. * @param {Function} func The function to defer.
  9804. * @param {...*} [args] The arguments to invoke `func` with.
  9805. * @returns {number} Returns the timer id.
  9806. * @example
  9807. *
  9808. * _.defer(function(text) {
  9809. * console.log(text);
  9810. * }, 'deferred');
  9811. * // => Logs 'deferred' after one millisecond.
  9812. */
  9813. var defer = baseRest(function(func, args) {
  9814. return baseDelay(func, 1, args);
  9815. });
  9816. /**
  9817. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9818. * provided to `func` when it's invoked.
  9819. *
  9820. * @static
  9821. * @memberOf _
  9822. * @since 0.1.0
  9823. * @category Function
  9824. * @param {Function} func The function to delay.
  9825. * @param {number} wait The number of milliseconds to delay invocation.
  9826. * @param {...*} [args] The arguments to invoke `func` with.
  9827. * @returns {number} Returns the timer id.
  9828. * @example
  9829. *
  9830. * _.delay(function(text) {
  9831. * console.log(text);
  9832. * }, 1000, 'later');
  9833. * // => Logs 'later' after one second.
  9834. */
  9835. var delay = baseRest(function(func, wait, args) {
  9836. return baseDelay(func, toNumber(wait) || 0, args);
  9837. });
  9838. /**
  9839. * Creates a function that invokes `func` with arguments reversed.
  9840. *
  9841. * @static
  9842. * @memberOf _
  9843. * @since 4.0.0
  9844. * @category Function
  9845. * @param {Function} func The function to flip arguments for.
  9846. * @returns {Function} Returns the new flipped function.
  9847. * @example
  9848. *
  9849. * var flipped = _.flip(function() {
  9850. * return _.toArray(arguments);
  9851. * });
  9852. *
  9853. * flipped('a', 'b', 'c', 'd');
  9854. * // => ['d', 'c', 'b', 'a']
  9855. */
  9856. function flip(func) {
  9857. return createWrap(func, WRAP_FLIP_FLAG);
  9858. }
  9859. /**
  9860. * Creates a function that memoizes the result of `func`. If `resolver` is
  9861. * provided, it determines the cache key for storing the result based on the
  9862. * arguments provided to the memoized function. By default, the first argument
  9863. * provided to the memoized function is used as the map cache key. The `func`
  9864. * is invoked with the `this` binding of the memoized function.
  9865. *
  9866. * **Note:** The cache is exposed as the `cache` property on the memoized
  9867. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9868. * constructor with one whose instances implement the
  9869. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9870. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9871. *
  9872. * @static
  9873. * @memberOf _
  9874. * @since 0.1.0
  9875. * @category Function
  9876. * @param {Function} func The function to have its output memoized.
  9877. * @param {Function} [resolver] The function to resolve the cache key.
  9878. * @returns {Function} Returns the new memoized function.
  9879. * @example
  9880. *
  9881. * var object = { 'a': 1, 'b': 2 };
  9882. * var other = { 'c': 3, 'd': 4 };
  9883. *
  9884. * var values = _.memoize(_.values);
  9885. * values(object);
  9886. * // => [1, 2]
  9887. *
  9888. * values(other);
  9889. * // => [3, 4]
  9890. *
  9891. * object.a = 2;
  9892. * values(object);
  9893. * // => [1, 2]
  9894. *
  9895. * // Modify the result cache.
  9896. * values.cache.set(object, ['a', 'b']);
  9897. * values(object);
  9898. * // => ['a', 'b']
  9899. *
  9900. * // Replace `_.memoize.Cache`.
  9901. * _.memoize.Cache = WeakMap;
  9902. */
  9903. function memoize(func, resolver) {
  9904. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9905. throw new TypeError(FUNC_ERROR_TEXT);
  9906. }
  9907. var memoized = function() {
  9908. var args = arguments,
  9909. key = resolver ? resolver.apply(this, args) : args[0],
  9910. cache = memoized.cache;
  9911. if (cache.has(key)) {
  9912. return cache.get(key);
  9913. }
  9914. var result = func.apply(this, args);
  9915. memoized.cache = cache.set(key, result) || cache;
  9916. return result;
  9917. };
  9918. memoized.cache = new (memoize.Cache || MapCache);
  9919. return memoized;
  9920. }
  9921. // Expose `MapCache`.
  9922. memoize.Cache = MapCache;
  9923. /**
  9924. * Creates a function that negates the result of the predicate `func`. The
  9925. * `func` predicate is invoked with the `this` binding and arguments of the
  9926. * created function.
  9927. *
  9928. * @static
  9929. * @memberOf _
  9930. * @since 3.0.0
  9931. * @category Function
  9932. * @param {Function} predicate The predicate to negate.
  9933. * @returns {Function} Returns the new negated function.
  9934. * @example
  9935. *
  9936. * function isEven(n) {
  9937. * return n % 2 == 0;
  9938. * }
  9939. *
  9940. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9941. * // => [1, 3, 5]
  9942. */
  9943. function negate(predicate) {
  9944. if (typeof predicate != 'function') {
  9945. throw new TypeError(FUNC_ERROR_TEXT);
  9946. }
  9947. return function() {
  9948. var args = arguments;
  9949. switch (args.length) {
  9950. case 0: return !predicate.call(this);
  9951. case 1: return !predicate.call(this, args[0]);
  9952. case 2: return !predicate.call(this, args[0], args[1]);
  9953. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9954. }
  9955. return !predicate.apply(this, args);
  9956. };
  9957. }
  9958. /**
  9959. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9960. * to the function return the value of the first invocation. The `func` is
  9961. * invoked with the `this` binding and arguments of the created function.
  9962. *
  9963. * @static
  9964. * @memberOf _
  9965. * @since 0.1.0
  9966. * @category Function
  9967. * @param {Function} func The function to restrict.
  9968. * @returns {Function} Returns the new restricted function.
  9969. * @example
  9970. *
  9971. * var initialize = _.once(createApplication);
  9972. * initialize();
  9973. * initialize();
  9974. * // => `createApplication` is invoked once
  9975. */
  9976. function once(func) {
  9977. return before(2, func);
  9978. }
  9979. /**
  9980. * Creates a function that invokes `func` with its arguments transformed.
  9981. *
  9982. * @static
  9983. * @since 4.0.0
  9984. * @memberOf _
  9985. * @category Function
  9986. * @param {Function} func The function to wrap.
  9987. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9988. * The argument transforms.
  9989. * @returns {Function} Returns the new function.
  9990. * @example
  9991. *
  9992. * function doubled(n) {
  9993. * return n * 2;
  9994. * }
  9995. *
  9996. * function square(n) {
  9997. * return n * n;
  9998. * }
  9999. *
  10000. * var func = _.overArgs(function(x, y) {
  10001. * return [x, y];
  10002. * }, [square, doubled]);
  10003. *
  10004. * func(9, 3);
  10005. * // => [81, 6]
  10006. *
  10007. * func(10, 5);
  10008. * // => [100, 10]
  10009. */
  10010. var overArgs = castRest(function(func, transforms) {
  10011. transforms = (transforms.length == 1 && isArray(transforms[0]))
  10012. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  10013. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  10014. var funcsLength = transforms.length;
  10015. return baseRest(function(args) {
  10016. var index = -1,
  10017. length = nativeMin(args.length, funcsLength);
  10018. while (++index < length) {
  10019. args[index] = transforms[index].call(this, args[index]);
  10020. }
  10021. return apply(func, this, args);
  10022. });
  10023. });
  10024. /**
  10025. * Creates a function that invokes `func` with `partials` prepended to the
  10026. * arguments it receives. This method is like `_.bind` except it does **not**
  10027. * alter the `this` binding.
  10028. *
  10029. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  10030. * builds, may be used as a placeholder for partially applied arguments.
  10031. *
  10032. * **Note:** This method doesn't set the "length" property of partially
  10033. * applied functions.
  10034. *
  10035. * @static
  10036. * @memberOf _
  10037. * @since 0.2.0
  10038. * @category Function
  10039. * @param {Function} func The function to partially apply arguments to.
  10040. * @param {...*} [partials] The arguments to be partially applied.
  10041. * @returns {Function} Returns the new partially applied function.
  10042. * @example
  10043. *
  10044. * function greet(greeting, name) {
  10045. * return greeting + ' ' + name;
  10046. * }
  10047. *
  10048. * var sayHelloTo = _.partial(greet, 'hello');
  10049. * sayHelloTo('fred');
  10050. * // => 'hello fred'
  10051. *
  10052. * // Partially applied with placeholders.
  10053. * var greetFred = _.partial(greet, _, 'fred');
  10054. * greetFred('hi');
  10055. * // => 'hi fred'
  10056. */
  10057. var partial = baseRest(function(func, partials) {
  10058. var holders = replaceHolders(partials, getHolder(partial));
  10059. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  10060. });
  10061. /**
  10062. * This method is like `_.partial` except that partially applied arguments
  10063. * are appended to the arguments it receives.
  10064. *
  10065. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  10066. * builds, may be used as a placeholder for partially applied arguments.
  10067. *
  10068. * **Note:** This method doesn't set the "length" property of partially
  10069. * applied functions.
  10070. *
  10071. * @static
  10072. * @memberOf _
  10073. * @since 1.0.0
  10074. * @category Function
  10075. * @param {Function} func The function to partially apply arguments to.
  10076. * @param {...*} [partials] The arguments to be partially applied.
  10077. * @returns {Function} Returns the new partially applied function.
  10078. * @example
  10079. *
  10080. * function greet(greeting, name) {
  10081. * return greeting + ' ' + name;
  10082. * }
  10083. *
  10084. * var greetFred = _.partialRight(greet, 'fred');
  10085. * greetFred('hi');
  10086. * // => 'hi fred'
  10087. *
  10088. * // Partially applied with placeholders.
  10089. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  10090. * sayHelloTo('fred');
  10091. * // => 'hello fred'
  10092. */
  10093. var partialRight = baseRest(function(func, partials) {
  10094. var holders = replaceHolders(partials, getHolder(partialRight));
  10095. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  10096. });
  10097. /**
  10098. * Creates a function that invokes `func` with arguments arranged according
  10099. * to the specified `indexes` where the argument value at the first index is
  10100. * provided as the first argument, the argument value at the second index is
  10101. * provided as the second argument, and so on.
  10102. *
  10103. * @static
  10104. * @memberOf _
  10105. * @since 3.0.0
  10106. * @category Function
  10107. * @param {Function} func The function to rearrange arguments for.
  10108. * @param {...(number|number[])} indexes The arranged argument indexes.
  10109. * @returns {Function} Returns the new function.
  10110. * @example
  10111. *
  10112. * var rearged = _.rearg(function(a, b, c) {
  10113. * return [a, b, c];
  10114. * }, [2, 0, 1]);
  10115. *
  10116. * rearged('b', 'c', 'a')
  10117. * // => ['a', 'b', 'c']
  10118. */
  10119. var rearg = flatRest(function(func, indexes) {
  10120. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10121. });
  10122. /**
  10123. * Creates a function that invokes `func` with the `this` binding of the
  10124. * created function and arguments from `start` and beyond provided as
  10125. * an array.
  10126. *
  10127. * **Note:** This method is based on the
  10128. * [rest parameter](https://mdn.io/rest_parameters).
  10129. *
  10130. * @static
  10131. * @memberOf _
  10132. * @since 4.0.0
  10133. * @category Function
  10134. * @param {Function} func The function to apply a rest parameter to.
  10135. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10136. * @returns {Function} Returns the new function.
  10137. * @example
  10138. *
  10139. * var say = _.rest(function(what, names) {
  10140. * return what + ' ' + _.initial(names).join(', ') +
  10141. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10142. * });
  10143. *
  10144. * say('hello', 'fred', 'barney', 'pebbles');
  10145. * // => 'hello fred, barney, & pebbles'
  10146. */
  10147. function rest(func, start) {
  10148. if (typeof func != 'function') {
  10149. throw new TypeError(FUNC_ERROR_TEXT);
  10150. }
  10151. start = start === undefined ? start : toInteger(start);
  10152. return baseRest(func, start);
  10153. }
  10154. /**
  10155. * Creates a function that invokes `func` with the `this` binding of the
  10156. * create function and an array of arguments much like
  10157. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10158. *
  10159. * **Note:** This method is based on the
  10160. * [spread operator](https://mdn.io/spread_operator).
  10161. *
  10162. * @static
  10163. * @memberOf _
  10164. * @since 3.2.0
  10165. * @category Function
  10166. * @param {Function} func The function to spread arguments over.
  10167. * @param {number} [start=0] The start position of the spread.
  10168. * @returns {Function} Returns the new function.
  10169. * @example
  10170. *
  10171. * var say = _.spread(function(who, what) {
  10172. * return who + ' says ' + what;
  10173. * });
  10174. *
  10175. * say(['fred', 'hello']);
  10176. * // => 'fred says hello'
  10177. *
  10178. * var numbers = Promise.all([
  10179. * Promise.resolve(40),
  10180. * Promise.resolve(36)
  10181. * ]);
  10182. *
  10183. * numbers.then(_.spread(function(x, y) {
  10184. * return x + y;
  10185. * }));
  10186. * // => a Promise of 76
  10187. */
  10188. function spread(func, start) {
  10189. if (typeof func != 'function') {
  10190. throw new TypeError(FUNC_ERROR_TEXT);
  10191. }
  10192. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10193. return baseRest(function(args) {
  10194. var array = args[start],
  10195. otherArgs = castSlice(args, 0, start);
  10196. if (array) {
  10197. arrayPush(otherArgs, array);
  10198. }
  10199. return apply(func, this, otherArgs);
  10200. });
  10201. }
  10202. /**
  10203. * Creates a throttled function that only invokes `func` at most once per
  10204. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10205. * method to cancel delayed `func` invocations and a `flush` method to
  10206. * immediately invoke them. Provide `options` to indicate whether `func`
  10207. * should be invoked on the leading and/or trailing edge of the `wait`
  10208. * timeout. The `func` is invoked with the last arguments provided to the
  10209. * throttled function. Subsequent calls to the throttled function return the
  10210. * result of the last `func` invocation.
  10211. *
  10212. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10213. * invoked on the trailing edge of the timeout only if the throttled function
  10214. * is invoked more than once during the `wait` timeout.
  10215. *
  10216. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10217. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10218. *
  10219. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10220. * for details over the differences between `_.throttle` and `_.debounce`.
  10221. *
  10222. * @static
  10223. * @memberOf _
  10224. * @since 0.1.0
  10225. * @category Function
  10226. * @param {Function} func The function to throttle.
  10227. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10228. * @param {Object} [options={}] The options object.
  10229. * @param {boolean} [options.leading=true]
  10230. * Specify invoking on the leading edge of the timeout.
  10231. * @param {boolean} [options.trailing=true]
  10232. * Specify invoking on the trailing edge of the timeout.
  10233. * @returns {Function} Returns the new throttled function.
  10234. * @example
  10235. *
  10236. * // Avoid excessively updating the position while scrolling.
  10237. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10238. *
  10239. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10240. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10241. * jQuery(element).on('click', throttled);
  10242. *
  10243. * // Cancel the trailing throttled invocation.
  10244. * jQuery(window).on('popstate', throttled.cancel);
  10245. */
  10246. function throttle(func, wait, options) {
  10247. var leading = true,
  10248. trailing = true;
  10249. if (typeof func != 'function') {
  10250. throw new TypeError(FUNC_ERROR_TEXT);
  10251. }
  10252. if (isObject(options)) {
  10253. leading = 'leading' in options ? !!options.leading : leading;
  10254. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10255. }
  10256. return debounce(func, wait, {
  10257. 'leading': leading,
  10258. 'maxWait': wait,
  10259. 'trailing': trailing
  10260. });
  10261. }
  10262. /**
  10263. * Creates a function that accepts up to one argument, ignoring any
  10264. * additional arguments.
  10265. *
  10266. * @static
  10267. * @memberOf _
  10268. * @since 4.0.0
  10269. * @category Function
  10270. * @param {Function} func The function to cap arguments for.
  10271. * @returns {Function} Returns the new capped function.
  10272. * @example
  10273. *
  10274. * _.map(['6', '8', '10'], _.unary(parseInt));
  10275. * // => [6, 8, 10]
  10276. */
  10277. function unary(func) {
  10278. return ary(func, 1);
  10279. }
  10280. /**
  10281. * Creates a function that provides `value` to `wrapper` as its first
  10282. * argument. Any additional arguments provided to the function are appended
  10283. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10284. * binding of the created function.
  10285. *
  10286. * @static
  10287. * @memberOf _
  10288. * @since 0.1.0
  10289. * @category Function
  10290. * @param {*} value The value to wrap.
  10291. * @param {Function} [wrapper=identity] The wrapper function.
  10292. * @returns {Function} Returns the new function.
  10293. * @example
  10294. *
  10295. * var p = _.wrap(_.escape, function(func, text) {
  10296. * return '<p>' + func(text) + '</p>';
  10297. * });
  10298. *
  10299. * p('fred, barney, & pebbles');
  10300. * // => '<p>fred, barney, &amp; pebbles</p>'
  10301. */
  10302. function wrap(value, wrapper) {
  10303. return partial(castFunction(wrapper), value);
  10304. }
  10305. /*------------------------------------------------------------------------*/
  10306. /**
  10307. * Casts `value` as an array if it's not one.
  10308. *
  10309. * @static
  10310. * @memberOf _
  10311. * @since 4.4.0
  10312. * @category Lang
  10313. * @param {*} value The value to inspect.
  10314. * @returns {Array} Returns the cast array.
  10315. * @example
  10316. *
  10317. * _.castArray(1);
  10318. * // => [1]
  10319. *
  10320. * _.castArray({ 'a': 1 });
  10321. * // => [{ 'a': 1 }]
  10322. *
  10323. * _.castArray('abc');
  10324. * // => ['abc']
  10325. *
  10326. * _.castArray(null);
  10327. * // => [null]
  10328. *
  10329. * _.castArray(undefined);
  10330. * // => [undefined]
  10331. *
  10332. * _.castArray();
  10333. * // => []
  10334. *
  10335. * var array = [1, 2, 3];
  10336. * console.log(_.castArray(array) === array);
  10337. * // => true
  10338. */
  10339. function castArray() {
  10340. if (!arguments.length) {
  10341. return [];
  10342. }
  10343. var value = arguments[0];
  10344. return isArray(value) ? value : [value];
  10345. }
  10346. /**
  10347. * Creates a shallow clone of `value`.
  10348. *
  10349. * **Note:** This method is loosely based on the
  10350. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10351. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10352. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10353. * arrays. The own enumerable properties of `arguments` objects are cloned
  10354. * as plain objects. An empty object is returned for uncloneable values such
  10355. * as error objects, functions, DOM nodes, and WeakMaps.
  10356. *
  10357. * @static
  10358. * @memberOf _
  10359. * @since 0.1.0
  10360. * @category Lang
  10361. * @param {*} value The value to clone.
  10362. * @returns {*} Returns the cloned value.
  10363. * @see _.cloneDeep
  10364. * @example
  10365. *
  10366. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10367. *
  10368. * var shallow = _.clone(objects);
  10369. * console.log(shallow[0] === objects[0]);
  10370. * // => true
  10371. */
  10372. function clone(value) {
  10373. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10374. }
  10375. /**
  10376. * This method is like `_.clone` except that it accepts `customizer` which
  10377. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10378. * cloning is handled by the method instead. The `customizer` is invoked with
  10379. * up to four arguments; (value [, index|key, object, stack]).
  10380. *
  10381. * @static
  10382. * @memberOf _
  10383. * @since 4.0.0
  10384. * @category Lang
  10385. * @param {*} value The value to clone.
  10386. * @param {Function} [customizer] The function to customize cloning.
  10387. * @returns {*} Returns the cloned value.
  10388. * @see _.cloneDeepWith
  10389. * @example
  10390. *
  10391. * function customizer(value) {
  10392. * if (_.isElement(value)) {
  10393. * return value.cloneNode(false);
  10394. * }
  10395. * }
  10396. *
  10397. * var el = _.cloneWith(document.body, customizer);
  10398. *
  10399. * console.log(el === document.body);
  10400. * // => false
  10401. * console.log(el.nodeName);
  10402. * // => 'BODY'
  10403. * console.log(el.childNodes.length);
  10404. * // => 0
  10405. */
  10406. function cloneWith(value, customizer) {
  10407. customizer = typeof customizer == 'function' ? customizer : undefined;
  10408. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10409. }
  10410. /**
  10411. * This method is like `_.clone` except that it recursively clones `value`.
  10412. *
  10413. * @static
  10414. * @memberOf _
  10415. * @since 1.0.0
  10416. * @category Lang
  10417. * @param {*} value The value to recursively clone.
  10418. * @returns {*} Returns the deep cloned value.
  10419. * @see _.clone
  10420. * @example
  10421. *
  10422. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10423. *
  10424. * var deep = _.cloneDeep(objects);
  10425. * console.log(deep[0] === objects[0]);
  10426. * // => false
  10427. */
  10428. function cloneDeep(value) {
  10429. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10430. }
  10431. /**
  10432. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10433. *
  10434. * @static
  10435. * @memberOf _
  10436. * @since 4.0.0
  10437. * @category Lang
  10438. * @param {*} value The value to recursively clone.
  10439. * @param {Function} [customizer] The function to customize cloning.
  10440. * @returns {*} Returns the deep cloned value.
  10441. * @see _.cloneWith
  10442. * @example
  10443. *
  10444. * function customizer(value) {
  10445. * if (_.isElement(value)) {
  10446. * return value.cloneNode(true);
  10447. * }
  10448. * }
  10449. *
  10450. * var el = _.cloneDeepWith(document.body, customizer);
  10451. *
  10452. * console.log(el === document.body);
  10453. * // => false
  10454. * console.log(el.nodeName);
  10455. * // => 'BODY'
  10456. * console.log(el.childNodes.length);
  10457. * // => 20
  10458. */
  10459. function cloneDeepWith(value, customizer) {
  10460. customizer = typeof customizer == 'function' ? customizer : undefined;
  10461. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10462. }
  10463. /**
  10464. * Checks if `object` conforms to `source` by invoking the predicate
  10465. * properties of `source` with the corresponding property values of `object`.
  10466. *
  10467. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10468. * partially applied.
  10469. *
  10470. * @static
  10471. * @memberOf _
  10472. * @since 4.14.0
  10473. * @category Lang
  10474. * @param {Object} object The object to inspect.
  10475. * @param {Object} source The object of property predicates to conform to.
  10476. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10477. * @example
  10478. *
  10479. * var object = { 'a': 1, 'b': 2 };
  10480. *
  10481. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10482. * // => true
  10483. *
  10484. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10485. * // => false
  10486. */
  10487. function conformsTo(object, source) {
  10488. return source == null || baseConformsTo(object, source, keys(source));
  10489. }
  10490. /**
  10491. * Performs a
  10492. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10493. * comparison between two values to determine if they are equivalent.
  10494. *
  10495. * @static
  10496. * @memberOf _
  10497. * @since 4.0.0
  10498. * @category Lang
  10499. * @param {*} value The value to compare.
  10500. * @param {*} other The other value to compare.
  10501. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10502. * @example
  10503. *
  10504. * var object = { 'a': 1 };
  10505. * var other = { 'a': 1 };
  10506. *
  10507. * _.eq(object, object);
  10508. * // => true
  10509. *
  10510. * _.eq(object, other);
  10511. * // => false
  10512. *
  10513. * _.eq('a', 'a');
  10514. * // => true
  10515. *
  10516. * _.eq('a', Object('a'));
  10517. * // => false
  10518. *
  10519. * _.eq(NaN, NaN);
  10520. * // => true
  10521. */
  10522. function eq(value, other) {
  10523. return value === other || (value !== value && other !== other);
  10524. }
  10525. /**
  10526. * Checks if `value` is greater than `other`.
  10527. *
  10528. * @static
  10529. * @memberOf _
  10530. * @since 3.9.0
  10531. * @category Lang
  10532. * @param {*} value The value to compare.
  10533. * @param {*} other The other value to compare.
  10534. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10535. * else `false`.
  10536. * @see _.lt
  10537. * @example
  10538. *
  10539. * _.gt(3, 1);
  10540. * // => true
  10541. *
  10542. * _.gt(3, 3);
  10543. * // => false
  10544. *
  10545. * _.gt(1, 3);
  10546. * // => false
  10547. */
  10548. var gt = createRelationalOperation(baseGt);
  10549. /**
  10550. * Checks if `value` is greater than or equal to `other`.
  10551. *
  10552. * @static
  10553. * @memberOf _
  10554. * @since 3.9.0
  10555. * @category Lang
  10556. * @param {*} value The value to compare.
  10557. * @param {*} other The other value to compare.
  10558. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10559. * `other`, else `false`.
  10560. * @see _.lte
  10561. * @example
  10562. *
  10563. * _.gte(3, 1);
  10564. * // => true
  10565. *
  10566. * _.gte(3, 3);
  10567. * // => true
  10568. *
  10569. * _.gte(1, 3);
  10570. * // => false
  10571. */
  10572. var gte = createRelationalOperation(function(value, other) {
  10573. return value >= other;
  10574. });
  10575. /**
  10576. * Checks if `value` is likely an `arguments` object.
  10577. *
  10578. * @static
  10579. * @memberOf _
  10580. * @since 0.1.0
  10581. * @category Lang
  10582. * @param {*} value The value to check.
  10583. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10584. * else `false`.
  10585. * @example
  10586. *
  10587. * _.isArguments(function() { return arguments; }());
  10588. * // => true
  10589. *
  10590. * _.isArguments([1, 2, 3]);
  10591. * // => false
  10592. */
  10593. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10594. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10595. !propertyIsEnumerable.call(value, 'callee');
  10596. };
  10597. /**
  10598. * Checks if `value` is classified as an `Array` object.
  10599. *
  10600. * @static
  10601. * @memberOf _
  10602. * @since 0.1.0
  10603. * @category Lang
  10604. * @param {*} value The value to check.
  10605. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10606. * @example
  10607. *
  10608. * _.isArray([1, 2, 3]);
  10609. * // => true
  10610. *
  10611. * _.isArray(document.body.children);
  10612. * // => false
  10613. *
  10614. * _.isArray('abc');
  10615. * // => false
  10616. *
  10617. * _.isArray(_.noop);
  10618. * // => false
  10619. */
  10620. var isArray = Array.isArray;
  10621. /**
  10622. * Checks if `value` is classified as an `ArrayBuffer` object.
  10623. *
  10624. * @static
  10625. * @memberOf _
  10626. * @since 4.3.0
  10627. * @category Lang
  10628. * @param {*} value The value to check.
  10629. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10630. * @example
  10631. *
  10632. * _.isArrayBuffer(new ArrayBuffer(2));
  10633. * // => true
  10634. *
  10635. * _.isArrayBuffer(new Array(2));
  10636. * // => false
  10637. */
  10638. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10639. /**
  10640. * Checks if `value` is array-like. A value is considered array-like if it's
  10641. * not a function and has a `value.length` that's an integer greater than or
  10642. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10643. *
  10644. * @static
  10645. * @memberOf _
  10646. * @since 4.0.0
  10647. * @category Lang
  10648. * @param {*} value The value to check.
  10649. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10650. * @example
  10651. *
  10652. * _.isArrayLike([1, 2, 3]);
  10653. * // => true
  10654. *
  10655. * _.isArrayLike(document.body.children);
  10656. * // => true
  10657. *
  10658. * _.isArrayLike('abc');
  10659. * // => true
  10660. *
  10661. * _.isArrayLike(_.noop);
  10662. * // => false
  10663. */
  10664. function isArrayLike(value) {
  10665. return value != null && isLength(value.length) && !isFunction(value);
  10666. }
  10667. /**
  10668. * This method is like `_.isArrayLike` except that it also checks if `value`
  10669. * is an object.
  10670. *
  10671. * @static
  10672. * @memberOf _
  10673. * @since 4.0.0
  10674. * @category Lang
  10675. * @param {*} value The value to check.
  10676. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10677. * else `false`.
  10678. * @example
  10679. *
  10680. * _.isArrayLikeObject([1, 2, 3]);
  10681. * // => true
  10682. *
  10683. * _.isArrayLikeObject(document.body.children);
  10684. * // => true
  10685. *
  10686. * _.isArrayLikeObject('abc');
  10687. * // => false
  10688. *
  10689. * _.isArrayLikeObject(_.noop);
  10690. * // => false
  10691. */
  10692. function isArrayLikeObject(value) {
  10693. return isObjectLike(value) && isArrayLike(value);
  10694. }
  10695. /**
  10696. * Checks if `value` is classified as a boolean primitive or object.
  10697. *
  10698. * @static
  10699. * @memberOf _
  10700. * @since 0.1.0
  10701. * @category Lang
  10702. * @param {*} value The value to check.
  10703. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10704. * @example
  10705. *
  10706. * _.isBoolean(false);
  10707. * // => true
  10708. *
  10709. * _.isBoolean(null);
  10710. * // => false
  10711. */
  10712. function isBoolean(value) {
  10713. return value === true || value === false ||
  10714. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10715. }
  10716. /**
  10717. * Checks if `value` is a buffer.
  10718. *
  10719. * @static
  10720. * @memberOf _
  10721. * @since 4.3.0
  10722. * @category Lang
  10723. * @param {*} value The value to check.
  10724. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10725. * @example
  10726. *
  10727. * _.isBuffer(new Buffer(2));
  10728. * // => true
  10729. *
  10730. * _.isBuffer(new Uint8Array(2));
  10731. * // => false
  10732. */
  10733. var isBuffer = nativeIsBuffer || stubFalse;
  10734. /**
  10735. * Checks if `value` is classified as a `Date` object.
  10736. *
  10737. * @static
  10738. * @memberOf _
  10739. * @since 0.1.0
  10740. * @category Lang
  10741. * @param {*} value The value to check.
  10742. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10743. * @example
  10744. *
  10745. * _.isDate(new Date);
  10746. * // => true
  10747. *
  10748. * _.isDate('Mon April 23 2012');
  10749. * // => false
  10750. */
  10751. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10752. /**
  10753. * Checks if `value` is likely a DOM element.
  10754. *
  10755. * @static
  10756. * @memberOf _
  10757. * @since 0.1.0
  10758. * @category Lang
  10759. * @param {*} value The value to check.
  10760. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10761. * @example
  10762. *
  10763. * _.isElement(document.body);
  10764. * // => true
  10765. *
  10766. * _.isElement('<body>');
  10767. * // => false
  10768. */
  10769. function isElement(value) {
  10770. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10771. }
  10772. /**
  10773. * Checks if `value` is an empty object, collection, map, or set.
  10774. *
  10775. * Objects are considered empty if they have no own enumerable string keyed
  10776. * properties.
  10777. *
  10778. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10779. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10780. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10781. *
  10782. * @static
  10783. * @memberOf _
  10784. * @since 0.1.0
  10785. * @category Lang
  10786. * @param {*} value The value to check.
  10787. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10788. * @example
  10789. *
  10790. * _.isEmpty(null);
  10791. * // => true
  10792. *
  10793. * _.isEmpty(true);
  10794. * // => true
  10795. *
  10796. * _.isEmpty(1);
  10797. * // => true
  10798. *
  10799. * _.isEmpty([1, 2, 3]);
  10800. * // => false
  10801. *
  10802. * _.isEmpty({ 'a': 1 });
  10803. * // => false
  10804. */
  10805. function isEmpty(value) {
  10806. if (value == null) {
  10807. return true;
  10808. }
  10809. if (isArrayLike(value) &&
  10810. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10811. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10812. return !value.length;
  10813. }
  10814. var tag = getTag(value);
  10815. if (tag == mapTag || tag == setTag) {
  10816. return !value.size;
  10817. }
  10818. if (isPrototype(value)) {
  10819. return !baseKeys(value).length;
  10820. }
  10821. for (var key in value) {
  10822. if (hasOwnProperty.call(value, key)) {
  10823. return false;
  10824. }
  10825. }
  10826. return true;
  10827. }
  10828. /**
  10829. * Performs a deep comparison between two values to determine if they are
  10830. * equivalent.
  10831. *
  10832. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10833. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10834. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10835. * by their own, not inherited, enumerable properties. Functions and DOM
  10836. * nodes are compared by strict equality, i.e. `===`.
  10837. *
  10838. * @static
  10839. * @memberOf _
  10840. * @since 0.1.0
  10841. * @category Lang
  10842. * @param {*} value The value to compare.
  10843. * @param {*} other The other value to compare.
  10844. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10845. * @example
  10846. *
  10847. * var object = { 'a': 1 };
  10848. * var other = { 'a': 1 };
  10849. *
  10850. * _.isEqual(object, other);
  10851. * // => true
  10852. *
  10853. * object === other;
  10854. * // => false
  10855. */
  10856. function isEqual(value, other) {
  10857. return baseIsEqual(value, other);
  10858. }
  10859. /**
  10860. * This method is like `_.isEqual` except that it accepts `customizer` which
  10861. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10862. * are handled by the method instead. The `customizer` is invoked with up to
  10863. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10864. *
  10865. * @static
  10866. * @memberOf _
  10867. * @since 4.0.0
  10868. * @category Lang
  10869. * @param {*} value The value to compare.
  10870. * @param {*} other The other value to compare.
  10871. * @param {Function} [customizer] The function to customize comparisons.
  10872. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10873. * @example
  10874. *
  10875. * function isGreeting(value) {
  10876. * return /^h(?:i|ello)$/.test(value);
  10877. * }
  10878. *
  10879. * function customizer(objValue, othValue) {
  10880. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10881. * return true;
  10882. * }
  10883. * }
  10884. *
  10885. * var array = ['hello', 'goodbye'];
  10886. * var other = ['hi', 'goodbye'];
  10887. *
  10888. * _.isEqualWith(array, other, customizer);
  10889. * // => true
  10890. */
  10891. function isEqualWith(value, other, customizer) {
  10892. customizer = typeof customizer == 'function' ? customizer : undefined;
  10893. var result = customizer ? customizer(value, other) : undefined;
  10894. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10895. }
  10896. /**
  10897. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10898. * `SyntaxError`, `TypeError`, or `URIError` object.
  10899. *
  10900. * @static
  10901. * @memberOf _
  10902. * @since 3.0.0
  10903. * @category Lang
  10904. * @param {*} value The value to check.
  10905. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10906. * @example
  10907. *
  10908. * _.isError(new Error);
  10909. * // => true
  10910. *
  10911. * _.isError(Error);
  10912. * // => false
  10913. */
  10914. function isError(value) {
  10915. if (!isObjectLike(value)) {
  10916. return false;
  10917. }
  10918. var tag = baseGetTag(value);
  10919. return tag == errorTag || tag == domExcTag ||
  10920. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10921. }
  10922. /**
  10923. * Checks if `value` is a finite primitive number.
  10924. *
  10925. * **Note:** This method is based on
  10926. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10927. *
  10928. * @static
  10929. * @memberOf _
  10930. * @since 0.1.0
  10931. * @category Lang
  10932. * @param {*} value The value to check.
  10933. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10934. * @example
  10935. *
  10936. * _.isFinite(3);
  10937. * // => true
  10938. *
  10939. * _.isFinite(Number.MIN_VALUE);
  10940. * // => true
  10941. *
  10942. * _.isFinite(Infinity);
  10943. * // => false
  10944. *
  10945. * _.isFinite('3');
  10946. * // => false
  10947. */
  10948. function isFinite(value) {
  10949. return typeof value == 'number' && nativeIsFinite(value);
  10950. }
  10951. /**
  10952. * Checks if `value` is classified as a `Function` object.
  10953. *
  10954. * @static
  10955. * @memberOf _
  10956. * @since 0.1.0
  10957. * @category Lang
  10958. * @param {*} value The value to check.
  10959. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10960. * @example
  10961. *
  10962. * _.isFunction(_);
  10963. * // => true
  10964. *
  10965. * _.isFunction(/abc/);
  10966. * // => false
  10967. */
  10968. function isFunction(value) {
  10969. if (!isObject(value)) {
  10970. return false;
  10971. }
  10972. // The use of `Object#toString` avoids issues with the `typeof` operator
  10973. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10974. var tag = baseGetTag(value);
  10975. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10976. }
  10977. /**
  10978. * Checks if `value` is an integer.
  10979. *
  10980. * **Note:** This method is based on
  10981. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10982. *
  10983. * @static
  10984. * @memberOf _
  10985. * @since 4.0.0
  10986. * @category Lang
  10987. * @param {*} value The value to check.
  10988. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10989. * @example
  10990. *
  10991. * _.isInteger(3);
  10992. * // => true
  10993. *
  10994. * _.isInteger(Number.MIN_VALUE);
  10995. * // => false
  10996. *
  10997. * _.isInteger(Infinity);
  10998. * // => false
  10999. *
  11000. * _.isInteger('3');
  11001. * // => false
  11002. */
  11003. function isInteger(value) {
  11004. return typeof value == 'number' && value == toInteger(value);
  11005. }
  11006. /**
  11007. * Checks if `value` is a valid array-like length.
  11008. *
  11009. * **Note:** This method is loosely based on
  11010. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11011. *
  11012. * @static
  11013. * @memberOf _
  11014. * @since 4.0.0
  11015. * @category Lang
  11016. * @param {*} value The value to check.
  11017. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  11018. * @example
  11019. *
  11020. * _.isLength(3);
  11021. * // => true
  11022. *
  11023. * _.isLength(Number.MIN_VALUE);
  11024. * // => false
  11025. *
  11026. * _.isLength(Infinity);
  11027. * // => false
  11028. *
  11029. * _.isLength('3');
  11030. * // => false
  11031. */
  11032. function isLength(value) {
  11033. return typeof value == 'number' &&
  11034. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  11035. }
  11036. /**
  11037. * Checks if `value` is the
  11038. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  11039. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  11040. *
  11041. * @static
  11042. * @memberOf _
  11043. * @since 0.1.0
  11044. * @category Lang
  11045. * @param {*} value The value to check.
  11046. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  11047. * @example
  11048. *
  11049. * _.isObject({});
  11050. * // => true
  11051. *
  11052. * _.isObject([1, 2, 3]);
  11053. * // => true
  11054. *
  11055. * _.isObject(_.noop);
  11056. * // => true
  11057. *
  11058. * _.isObject(null);
  11059. * // => false
  11060. */
  11061. function isObject(value) {
  11062. var type = typeof value;
  11063. return value != null && (type == 'object' || type == 'function');
  11064. }
  11065. /**
  11066. * Checks if `value` is object-like. A value is object-like if it's not `null`
  11067. * and has a `typeof` result of "object".
  11068. *
  11069. * @static
  11070. * @memberOf _
  11071. * @since 4.0.0
  11072. * @category Lang
  11073. * @param {*} value The value to check.
  11074. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  11075. * @example
  11076. *
  11077. * _.isObjectLike({});
  11078. * // => true
  11079. *
  11080. * _.isObjectLike([1, 2, 3]);
  11081. * // => true
  11082. *
  11083. * _.isObjectLike(_.noop);
  11084. * // => false
  11085. *
  11086. * _.isObjectLike(null);
  11087. * // => false
  11088. */
  11089. function isObjectLike(value) {
  11090. return value != null && typeof value == 'object';
  11091. }
  11092. /**
  11093. * Checks if `value` is classified as a `Map` object.
  11094. *
  11095. * @static
  11096. * @memberOf _
  11097. * @since 4.3.0
  11098. * @category Lang
  11099. * @param {*} value The value to check.
  11100. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  11101. * @example
  11102. *
  11103. * _.isMap(new Map);
  11104. * // => true
  11105. *
  11106. * _.isMap(new WeakMap);
  11107. * // => false
  11108. */
  11109. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11110. /**
  11111. * Performs a partial deep comparison between `object` and `source` to
  11112. * determine if `object` contains equivalent property values.
  11113. *
  11114. * **Note:** This method is equivalent to `_.matches` when `source` is
  11115. * partially applied.
  11116. *
  11117. * Partial comparisons will match empty array and empty object `source`
  11118. * values against any array or object value, respectively. See `_.isEqual`
  11119. * for a list of supported value comparisons.
  11120. *
  11121. * @static
  11122. * @memberOf _
  11123. * @since 3.0.0
  11124. * @category Lang
  11125. * @param {Object} object The object to inspect.
  11126. * @param {Object} source The object of property values to match.
  11127. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11128. * @example
  11129. *
  11130. * var object = { 'a': 1, 'b': 2 };
  11131. *
  11132. * _.isMatch(object, { 'b': 2 });
  11133. * // => true
  11134. *
  11135. * _.isMatch(object, { 'b': 1 });
  11136. * // => false
  11137. */
  11138. function isMatch(object, source) {
  11139. return object === source || baseIsMatch(object, source, getMatchData(source));
  11140. }
  11141. /**
  11142. * This method is like `_.isMatch` except that it accepts `customizer` which
  11143. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11144. * are handled by the method instead. The `customizer` is invoked with five
  11145. * arguments: (objValue, srcValue, index|key, object, source).
  11146. *
  11147. * @static
  11148. * @memberOf _
  11149. * @since 4.0.0
  11150. * @category Lang
  11151. * @param {Object} object The object to inspect.
  11152. * @param {Object} source The object of property values to match.
  11153. * @param {Function} [customizer] The function to customize comparisons.
  11154. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11155. * @example
  11156. *
  11157. * function isGreeting(value) {
  11158. * return /^h(?:i|ello)$/.test(value);
  11159. * }
  11160. *
  11161. * function customizer(objValue, srcValue) {
  11162. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11163. * return true;
  11164. * }
  11165. * }
  11166. *
  11167. * var object = { 'greeting': 'hello' };
  11168. * var source = { 'greeting': 'hi' };
  11169. *
  11170. * _.isMatchWith(object, source, customizer);
  11171. * // => true
  11172. */
  11173. function isMatchWith(object, source, customizer) {
  11174. customizer = typeof customizer == 'function' ? customizer : undefined;
  11175. return baseIsMatch(object, source, getMatchData(source), customizer);
  11176. }
  11177. /**
  11178. * Checks if `value` is `NaN`.
  11179. *
  11180. * **Note:** This method is based on
  11181. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11182. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11183. * `undefined` and other non-number values.
  11184. *
  11185. * @static
  11186. * @memberOf _
  11187. * @since 0.1.0
  11188. * @category Lang
  11189. * @param {*} value The value to check.
  11190. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11191. * @example
  11192. *
  11193. * _.isNaN(NaN);
  11194. * // => true
  11195. *
  11196. * _.isNaN(new Number(NaN));
  11197. * // => true
  11198. *
  11199. * isNaN(undefined);
  11200. * // => true
  11201. *
  11202. * _.isNaN(undefined);
  11203. * // => false
  11204. */
  11205. function isNaN(value) {
  11206. // An `NaN` primitive is the only value that is not equal to itself.
  11207. // Perform the `toStringTag` check first to avoid errors with some
  11208. // ActiveX objects in IE.
  11209. return isNumber(value) && value != +value;
  11210. }
  11211. /**
  11212. * Checks if `value` is a pristine native function.
  11213. *
  11214. * **Note:** This method can't reliably detect native functions in the presence
  11215. * of the core-js package because core-js circumvents this kind of detection.
  11216. * Despite multiple requests, the core-js maintainer has made it clear: any
  11217. * attempt to fix the detection will be obstructed. As a result, we're left
  11218. * with little choice but to throw an error. Unfortunately, this also affects
  11219. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11220. * which rely on core-js.
  11221. *
  11222. * @static
  11223. * @memberOf _
  11224. * @since 3.0.0
  11225. * @category Lang
  11226. * @param {*} value The value to check.
  11227. * @returns {boolean} Returns `true` if `value` is a native function,
  11228. * else `false`.
  11229. * @example
  11230. *
  11231. * _.isNative(Array.prototype.push);
  11232. * // => true
  11233. *
  11234. * _.isNative(_);
  11235. * // => false
  11236. */
  11237. function isNative(value) {
  11238. if (isMaskable(value)) {
  11239. throw new Error(CORE_ERROR_TEXT);
  11240. }
  11241. return baseIsNative(value);
  11242. }
  11243. /**
  11244. * Checks if `value` is `null`.
  11245. *
  11246. * @static
  11247. * @memberOf _
  11248. * @since 0.1.0
  11249. * @category Lang
  11250. * @param {*} value The value to check.
  11251. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11252. * @example
  11253. *
  11254. * _.isNull(null);
  11255. * // => true
  11256. *
  11257. * _.isNull(void 0);
  11258. * // => false
  11259. */
  11260. function isNull(value) {
  11261. return value === null;
  11262. }
  11263. /**
  11264. * Checks if `value` is `null` or `undefined`.
  11265. *
  11266. * @static
  11267. * @memberOf _
  11268. * @since 4.0.0
  11269. * @category Lang
  11270. * @param {*} value The value to check.
  11271. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11272. * @example
  11273. *
  11274. * _.isNil(null);
  11275. * // => true
  11276. *
  11277. * _.isNil(void 0);
  11278. * // => true
  11279. *
  11280. * _.isNil(NaN);
  11281. * // => false
  11282. */
  11283. function isNil(value) {
  11284. return value == null;
  11285. }
  11286. /**
  11287. * Checks if `value` is classified as a `Number` primitive or object.
  11288. *
  11289. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11290. * classified as numbers, use the `_.isFinite` method.
  11291. *
  11292. * @static
  11293. * @memberOf _
  11294. * @since 0.1.0
  11295. * @category Lang
  11296. * @param {*} value The value to check.
  11297. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11298. * @example
  11299. *
  11300. * _.isNumber(3);
  11301. * // => true
  11302. *
  11303. * _.isNumber(Number.MIN_VALUE);
  11304. * // => true
  11305. *
  11306. * _.isNumber(Infinity);
  11307. * // => true
  11308. *
  11309. * _.isNumber('3');
  11310. * // => false
  11311. */
  11312. function isNumber(value) {
  11313. return typeof value == 'number' ||
  11314. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11315. }
  11316. /**
  11317. * Checks if `value` is a plain object, that is, an object created by the
  11318. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11319. *
  11320. * @static
  11321. * @memberOf _
  11322. * @since 0.8.0
  11323. * @category Lang
  11324. * @param {*} value The value to check.
  11325. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11326. * @example
  11327. *
  11328. * function Foo() {
  11329. * this.a = 1;
  11330. * }
  11331. *
  11332. * _.isPlainObject(new Foo);
  11333. * // => false
  11334. *
  11335. * _.isPlainObject([1, 2, 3]);
  11336. * // => false
  11337. *
  11338. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11339. * // => true
  11340. *
  11341. * _.isPlainObject(Object.create(null));
  11342. * // => true
  11343. */
  11344. function isPlainObject(value) {
  11345. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11346. return false;
  11347. }
  11348. var proto = getPrototype(value);
  11349. if (proto === null) {
  11350. return true;
  11351. }
  11352. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11353. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11354. funcToString.call(Ctor) == objectCtorString;
  11355. }
  11356. /**
  11357. * Checks if `value` is classified as a `RegExp` object.
  11358. *
  11359. * @static
  11360. * @memberOf _
  11361. * @since 0.1.0
  11362. * @category Lang
  11363. * @param {*} value The value to check.
  11364. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11365. * @example
  11366. *
  11367. * _.isRegExp(/abc/);
  11368. * // => true
  11369. *
  11370. * _.isRegExp('/abc/');
  11371. * // => false
  11372. */
  11373. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11374. /**
  11375. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11376. * double precision number which isn't the result of a rounded unsafe integer.
  11377. *
  11378. * **Note:** This method is based on
  11379. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11380. *
  11381. * @static
  11382. * @memberOf _
  11383. * @since 4.0.0
  11384. * @category Lang
  11385. * @param {*} value The value to check.
  11386. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11387. * @example
  11388. *
  11389. * _.isSafeInteger(3);
  11390. * // => true
  11391. *
  11392. * _.isSafeInteger(Number.MIN_VALUE);
  11393. * // => false
  11394. *
  11395. * _.isSafeInteger(Infinity);
  11396. * // => false
  11397. *
  11398. * _.isSafeInteger('3');
  11399. * // => false
  11400. */
  11401. function isSafeInteger(value) {
  11402. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11403. }
  11404. /**
  11405. * Checks if `value` is classified as a `Set` object.
  11406. *
  11407. * @static
  11408. * @memberOf _
  11409. * @since 4.3.0
  11410. * @category Lang
  11411. * @param {*} value The value to check.
  11412. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11413. * @example
  11414. *
  11415. * _.isSet(new Set);
  11416. * // => true
  11417. *
  11418. * _.isSet(new WeakSet);
  11419. * // => false
  11420. */
  11421. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11422. /**
  11423. * Checks if `value` is classified as a `String` primitive or object.
  11424. *
  11425. * @static
  11426. * @since 0.1.0
  11427. * @memberOf _
  11428. * @category Lang
  11429. * @param {*} value The value to check.
  11430. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11431. * @example
  11432. *
  11433. * _.isString('abc');
  11434. * // => true
  11435. *
  11436. * _.isString(1);
  11437. * // => false
  11438. */
  11439. function isString(value) {
  11440. return typeof value == 'string' ||
  11441. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11442. }
  11443. /**
  11444. * Checks if `value` is classified as a `Symbol` primitive or object.
  11445. *
  11446. * @static
  11447. * @memberOf _
  11448. * @since 4.0.0
  11449. * @category Lang
  11450. * @param {*} value The value to check.
  11451. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11452. * @example
  11453. *
  11454. * _.isSymbol(Symbol.iterator);
  11455. * // => true
  11456. *
  11457. * _.isSymbol('abc');
  11458. * // => false
  11459. */
  11460. function isSymbol(value) {
  11461. return typeof value == 'symbol' ||
  11462. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11463. }
  11464. /**
  11465. * Checks if `value` is classified as a typed array.
  11466. *
  11467. * @static
  11468. * @memberOf _
  11469. * @since 3.0.0
  11470. * @category Lang
  11471. * @param {*} value The value to check.
  11472. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11473. * @example
  11474. *
  11475. * _.isTypedArray(new Uint8Array);
  11476. * // => true
  11477. *
  11478. * _.isTypedArray([]);
  11479. * // => false
  11480. */
  11481. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11482. /**
  11483. * Checks if `value` is `undefined`.
  11484. *
  11485. * @static
  11486. * @since 0.1.0
  11487. * @memberOf _
  11488. * @category Lang
  11489. * @param {*} value The value to check.
  11490. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11491. * @example
  11492. *
  11493. * _.isUndefined(void 0);
  11494. * // => true
  11495. *
  11496. * _.isUndefined(null);
  11497. * // => false
  11498. */
  11499. function isUndefined(value) {
  11500. return value === undefined;
  11501. }
  11502. /**
  11503. * Checks if `value` is classified as a `WeakMap` object.
  11504. *
  11505. * @static
  11506. * @memberOf _
  11507. * @since 4.3.0
  11508. * @category Lang
  11509. * @param {*} value The value to check.
  11510. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11511. * @example
  11512. *
  11513. * _.isWeakMap(new WeakMap);
  11514. * // => true
  11515. *
  11516. * _.isWeakMap(new Map);
  11517. * // => false
  11518. */
  11519. function isWeakMap(value) {
  11520. return isObjectLike(value) && getTag(value) == weakMapTag;
  11521. }
  11522. /**
  11523. * Checks if `value` is classified as a `WeakSet` object.
  11524. *
  11525. * @static
  11526. * @memberOf _
  11527. * @since 4.3.0
  11528. * @category Lang
  11529. * @param {*} value The value to check.
  11530. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11531. * @example
  11532. *
  11533. * _.isWeakSet(new WeakSet);
  11534. * // => true
  11535. *
  11536. * _.isWeakSet(new Set);
  11537. * // => false
  11538. */
  11539. function isWeakSet(value) {
  11540. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11541. }
  11542. /**
  11543. * Checks if `value` is less than `other`.
  11544. *
  11545. * @static
  11546. * @memberOf _
  11547. * @since 3.9.0
  11548. * @category Lang
  11549. * @param {*} value The value to compare.
  11550. * @param {*} other The other value to compare.
  11551. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11552. * else `false`.
  11553. * @see _.gt
  11554. * @example
  11555. *
  11556. * _.lt(1, 3);
  11557. * // => true
  11558. *
  11559. * _.lt(3, 3);
  11560. * // => false
  11561. *
  11562. * _.lt(3, 1);
  11563. * // => false
  11564. */
  11565. var lt = createRelationalOperation(baseLt);
  11566. /**
  11567. * Checks if `value` is less than or equal to `other`.
  11568. *
  11569. * @static
  11570. * @memberOf _
  11571. * @since 3.9.0
  11572. * @category Lang
  11573. * @param {*} value The value to compare.
  11574. * @param {*} other The other value to compare.
  11575. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11576. * `other`, else `false`.
  11577. * @see _.gte
  11578. * @example
  11579. *
  11580. * _.lte(1, 3);
  11581. * // => true
  11582. *
  11583. * _.lte(3, 3);
  11584. * // => true
  11585. *
  11586. * _.lte(3, 1);
  11587. * // => false
  11588. */
  11589. var lte = createRelationalOperation(function(value, other) {
  11590. return value <= other;
  11591. });
  11592. /**
  11593. * Converts `value` to an array.
  11594. *
  11595. * @static
  11596. * @since 0.1.0
  11597. * @memberOf _
  11598. * @category Lang
  11599. * @param {*} value The value to convert.
  11600. * @returns {Array} Returns the converted array.
  11601. * @example
  11602. *
  11603. * _.toArray({ 'a': 1, 'b': 2 });
  11604. * // => [1, 2]
  11605. *
  11606. * _.toArray('abc');
  11607. * // => ['a', 'b', 'c']
  11608. *
  11609. * _.toArray(1);
  11610. * // => []
  11611. *
  11612. * _.toArray(null);
  11613. * // => []
  11614. */
  11615. function toArray(value) {
  11616. if (!value) {
  11617. return [];
  11618. }
  11619. if (isArrayLike(value)) {
  11620. return isString(value) ? stringToArray(value) : copyArray(value);
  11621. }
  11622. if (symIterator && value[symIterator]) {
  11623. return iteratorToArray(value[symIterator]());
  11624. }
  11625. var tag = getTag(value),
  11626. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11627. return func(value);
  11628. }
  11629. /**
  11630. * Converts `value` to a finite number.
  11631. *
  11632. * @static
  11633. * @memberOf _
  11634. * @since 4.12.0
  11635. * @category Lang
  11636. * @param {*} value The value to convert.
  11637. * @returns {number} Returns the converted number.
  11638. * @example
  11639. *
  11640. * _.toFinite(3.2);
  11641. * // => 3.2
  11642. *
  11643. * _.toFinite(Number.MIN_VALUE);
  11644. * // => 5e-324
  11645. *
  11646. * _.toFinite(Infinity);
  11647. * // => 1.7976931348623157e+308
  11648. *
  11649. * _.toFinite('3.2');
  11650. * // => 3.2
  11651. */
  11652. function toFinite(value) {
  11653. if (!value) {
  11654. return value === 0 ? value : 0;
  11655. }
  11656. value = toNumber(value);
  11657. if (value === INFINITY || value === -INFINITY) {
  11658. var sign = (value < 0 ? -1 : 1);
  11659. return sign * MAX_INTEGER;
  11660. }
  11661. return value === value ? value : 0;
  11662. }
  11663. /**
  11664. * Converts `value` to an integer.
  11665. *
  11666. * **Note:** This method is loosely based on
  11667. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11668. *
  11669. * @static
  11670. * @memberOf _
  11671. * @since 4.0.0
  11672. * @category Lang
  11673. * @param {*} value The value to convert.
  11674. * @returns {number} Returns the converted integer.
  11675. * @example
  11676. *
  11677. * _.toInteger(3.2);
  11678. * // => 3
  11679. *
  11680. * _.toInteger(Number.MIN_VALUE);
  11681. * // => 0
  11682. *
  11683. * _.toInteger(Infinity);
  11684. * // => 1.7976931348623157e+308
  11685. *
  11686. * _.toInteger('3.2');
  11687. * // => 3
  11688. */
  11689. function toInteger(value) {
  11690. var result = toFinite(value),
  11691. remainder = result % 1;
  11692. return result === result ? (remainder ? result - remainder : result) : 0;
  11693. }
  11694. /**
  11695. * Converts `value` to an integer suitable for use as the length of an
  11696. * array-like object.
  11697. *
  11698. * **Note:** This method is based on
  11699. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11700. *
  11701. * @static
  11702. * @memberOf _
  11703. * @since 4.0.0
  11704. * @category Lang
  11705. * @param {*} value The value to convert.
  11706. * @returns {number} Returns the converted integer.
  11707. * @example
  11708. *
  11709. * _.toLength(3.2);
  11710. * // => 3
  11711. *
  11712. * _.toLength(Number.MIN_VALUE);
  11713. * // => 0
  11714. *
  11715. * _.toLength(Infinity);
  11716. * // => 4294967295
  11717. *
  11718. * _.toLength('3.2');
  11719. * // => 3
  11720. */
  11721. function toLength(value) {
  11722. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11723. }
  11724. /**
  11725. * Converts `value` to a number.
  11726. *
  11727. * @static
  11728. * @memberOf _
  11729. * @since 4.0.0
  11730. * @category Lang
  11731. * @param {*} value The value to process.
  11732. * @returns {number} Returns the number.
  11733. * @example
  11734. *
  11735. * _.toNumber(3.2);
  11736. * // => 3.2
  11737. *
  11738. * _.toNumber(Number.MIN_VALUE);
  11739. * // => 5e-324
  11740. *
  11741. * _.toNumber(Infinity);
  11742. * // => Infinity
  11743. *
  11744. * _.toNumber('3.2');
  11745. * // => 3.2
  11746. */
  11747. function toNumber(value) {
  11748. if (typeof value == 'number') {
  11749. return value;
  11750. }
  11751. if (isSymbol(value)) {
  11752. return NAN;
  11753. }
  11754. if (isObject(value)) {
  11755. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11756. value = isObject(other) ? (other + '') : other;
  11757. }
  11758. if (typeof value != 'string') {
  11759. return value === 0 ? value : +value;
  11760. }
  11761. value = value.replace(reTrim, '');
  11762. var isBinary = reIsBinary.test(value);
  11763. return (isBinary || reIsOctal.test(value))
  11764. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11765. : (reIsBadHex.test(value) ? NAN : +value);
  11766. }
  11767. /**
  11768. * Converts `value` to a plain object flattening inherited enumerable string
  11769. * keyed properties of `value` to own properties of the plain object.
  11770. *
  11771. * @static
  11772. * @memberOf _
  11773. * @since 3.0.0
  11774. * @category Lang
  11775. * @param {*} value The value to convert.
  11776. * @returns {Object} Returns the converted plain object.
  11777. * @example
  11778. *
  11779. * function Foo() {
  11780. * this.b = 2;
  11781. * }
  11782. *
  11783. * Foo.prototype.c = 3;
  11784. *
  11785. * _.assign({ 'a': 1 }, new Foo);
  11786. * // => { 'a': 1, 'b': 2 }
  11787. *
  11788. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11789. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11790. */
  11791. function toPlainObject(value) {
  11792. return copyObject(value, keysIn(value));
  11793. }
  11794. /**
  11795. * Converts `value` to a safe integer. A safe integer can be compared and
  11796. * represented correctly.
  11797. *
  11798. * @static
  11799. * @memberOf _
  11800. * @since 4.0.0
  11801. * @category Lang
  11802. * @param {*} value The value to convert.
  11803. * @returns {number} Returns the converted integer.
  11804. * @example
  11805. *
  11806. * _.toSafeInteger(3.2);
  11807. * // => 3
  11808. *
  11809. * _.toSafeInteger(Number.MIN_VALUE);
  11810. * // => 0
  11811. *
  11812. * _.toSafeInteger(Infinity);
  11813. * // => 9007199254740991
  11814. *
  11815. * _.toSafeInteger('3.2');
  11816. * // => 3
  11817. */
  11818. function toSafeInteger(value) {
  11819. return value
  11820. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11821. : (value === 0 ? value : 0);
  11822. }
  11823. /**
  11824. * Converts `value` to a string. An empty string is returned for `null`
  11825. * and `undefined` values. The sign of `-0` is preserved.
  11826. *
  11827. * @static
  11828. * @memberOf _
  11829. * @since 4.0.0
  11830. * @category Lang
  11831. * @param {*} value The value to convert.
  11832. * @returns {string} Returns the converted string.
  11833. * @example
  11834. *
  11835. * _.toString(null);
  11836. * // => ''
  11837. *
  11838. * _.toString(-0);
  11839. * // => '-0'
  11840. *
  11841. * _.toString([1, 2, 3]);
  11842. * // => '1,2,3'
  11843. */
  11844. function toString(value) {
  11845. return value == null ? '' : baseToString(value);
  11846. }
  11847. /*------------------------------------------------------------------------*/
  11848. /**
  11849. * Assigns own enumerable string keyed properties of source objects to the
  11850. * destination object. Source objects are applied from left to right.
  11851. * Subsequent sources overwrite property assignments of previous sources.
  11852. *
  11853. * **Note:** This method mutates `object` and is loosely based on
  11854. * [`Object.assign`](https://mdn.io/Object/assign).
  11855. *
  11856. * @static
  11857. * @memberOf _
  11858. * @since 0.10.0
  11859. * @category Object
  11860. * @param {Object} object The destination object.
  11861. * @param {...Object} [sources] The source objects.
  11862. * @returns {Object} Returns `object`.
  11863. * @see _.assignIn
  11864. * @example
  11865. *
  11866. * function Foo() {
  11867. * this.a = 1;
  11868. * }
  11869. *
  11870. * function Bar() {
  11871. * this.c = 3;
  11872. * }
  11873. *
  11874. * Foo.prototype.b = 2;
  11875. * Bar.prototype.d = 4;
  11876. *
  11877. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11878. * // => { 'a': 1, 'c': 3 }
  11879. */
  11880. var assign = createAssigner(function(object, source) {
  11881. if (isPrototype(source) || isArrayLike(source)) {
  11882. copyObject(source, keys(source), object);
  11883. return;
  11884. }
  11885. for (var key in source) {
  11886. if (hasOwnProperty.call(source, key)) {
  11887. assignValue(object, key, source[key]);
  11888. }
  11889. }
  11890. });
  11891. /**
  11892. * This method is like `_.assign` except that it iterates over own and
  11893. * inherited source properties.
  11894. *
  11895. * **Note:** This method mutates `object`.
  11896. *
  11897. * @static
  11898. * @memberOf _
  11899. * @since 4.0.0
  11900. * @alias extend
  11901. * @category Object
  11902. * @param {Object} object The destination object.
  11903. * @param {...Object} [sources] The source objects.
  11904. * @returns {Object} Returns `object`.
  11905. * @see _.assign
  11906. * @example
  11907. *
  11908. * function Foo() {
  11909. * this.a = 1;
  11910. * }
  11911. *
  11912. * function Bar() {
  11913. * this.c = 3;
  11914. * }
  11915. *
  11916. * Foo.prototype.b = 2;
  11917. * Bar.prototype.d = 4;
  11918. *
  11919. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11920. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11921. */
  11922. var assignIn = createAssigner(function(object, source) {
  11923. copyObject(source, keysIn(source), object);
  11924. });
  11925. /**
  11926. * This method is like `_.assignIn` except that it accepts `customizer`
  11927. * which is invoked to produce the assigned values. If `customizer` returns
  11928. * `undefined`, assignment is handled by the method instead. The `customizer`
  11929. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11930. *
  11931. * **Note:** This method mutates `object`.
  11932. *
  11933. * @static
  11934. * @memberOf _
  11935. * @since 4.0.0
  11936. * @alias extendWith
  11937. * @category Object
  11938. * @param {Object} object The destination object.
  11939. * @param {...Object} sources The source objects.
  11940. * @param {Function} [customizer] The function to customize assigned values.
  11941. * @returns {Object} Returns `object`.
  11942. * @see _.assignWith
  11943. * @example
  11944. *
  11945. * function customizer(objValue, srcValue) {
  11946. * return _.isUndefined(objValue) ? srcValue : objValue;
  11947. * }
  11948. *
  11949. * var defaults = _.partialRight(_.assignInWith, customizer);
  11950. *
  11951. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11952. * // => { 'a': 1, 'b': 2 }
  11953. */
  11954. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11955. copyObject(source, keysIn(source), object, customizer);
  11956. });
  11957. /**
  11958. * This method is like `_.assign` except that it accepts `customizer`
  11959. * which is invoked to produce the assigned values. If `customizer` returns
  11960. * `undefined`, assignment is handled by the method instead. The `customizer`
  11961. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11962. *
  11963. * **Note:** This method mutates `object`.
  11964. *
  11965. * @static
  11966. * @memberOf _
  11967. * @since 4.0.0
  11968. * @category Object
  11969. * @param {Object} object The destination object.
  11970. * @param {...Object} sources The source objects.
  11971. * @param {Function} [customizer] The function to customize assigned values.
  11972. * @returns {Object} Returns `object`.
  11973. * @see _.assignInWith
  11974. * @example
  11975. *
  11976. * function customizer(objValue, srcValue) {
  11977. * return _.isUndefined(objValue) ? srcValue : objValue;
  11978. * }
  11979. *
  11980. * var defaults = _.partialRight(_.assignWith, customizer);
  11981. *
  11982. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11983. * // => { 'a': 1, 'b': 2 }
  11984. */
  11985. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11986. copyObject(source, keys(source), object, customizer);
  11987. });
  11988. /**
  11989. * Creates an array of values corresponding to `paths` of `object`.
  11990. *
  11991. * @static
  11992. * @memberOf _
  11993. * @since 1.0.0
  11994. * @category Object
  11995. * @param {Object} object The object to iterate over.
  11996. * @param {...(string|string[])} [paths] The property paths to pick.
  11997. * @returns {Array} Returns the picked values.
  11998. * @example
  11999. *
  12000. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  12001. *
  12002. * _.at(object, ['a[0].b.c', 'a[1]']);
  12003. * // => [3, 4]
  12004. */
  12005. var at = flatRest(baseAt);
  12006. /**
  12007. * Creates an object that inherits from the `prototype` object. If a
  12008. * `properties` object is given, its own enumerable string keyed properties
  12009. * are assigned to the created object.
  12010. *
  12011. * @static
  12012. * @memberOf _
  12013. * @since 2.3.0
  12014. * @category Object
  12015. * @param {Object} prototype The object to inherit from.
  12016. * @param {Object} [properties] The properties to assign to the object.
  12017. * @returns {Object} Returns the new object.
  12018. * @example
  12019. *
  12020. * function Shape() {
  12021. * this.x = 0;
  12022. * this.y = 0;
  12023. * }
  12024. *
  12025. * function Circle() {
  12026. * Shape.call(this);
  12027. * }
  12028. *
  12029. * Circle.prototype = _.create(Shape.prototype, {
  12030. * 'constructor': Circle
  12031. * });
  12032. *
  12033. * var circle = new Circle;
  12034. * circle instanceof Circle;
  12035. * // => true
  12036. *
  12037. * circle instanceof Shape;
  12038. * // => true
  12039. */
  12040. function create(prototype, properties) {
  12041. var result = baseCreate(prototype);
  12042. return properties == null ? result : baseAssign(result, properties);
  12043. }
  12044. /**
  12045. * Assigns own and inherited enumerable string keyed properties of source
  12046. * objects to the destination object for all destination properties that
  12047. * resolve to `undefined`. Source objects are applied from left to right.
  12048. * Once a property is set, additional values of the same property are ignored.
  12049. *
  12050. * **Note:** This method mutates `object`.
  12051. *
  12052. * @static
  12053. * @since 0.1.0
  12054. * @memberOf _
  12055. * @category Object
  12056. * @param {Object} object The destination object.
  12057. * @param {...Object} [sources] The source objects.
  12058. * @returns {Object} Returns `object`.
  12059. * @see _.defaultsDeep
  12060. * @example
  12061. *
  12062. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  12063. * // => { 'a': 1, 'b': 2 }
  12064. */
  12065. var defaults = baseRest(function(args) {
  12066. args.push(undefined, customDefaultsAssignIn);
  12067. return apply(assignInWith, undefined, args);
  12068. });
  12069. /**
  12070. * This method is like `_.defaults` except that it recursively assigns
  12071. * default properties.
  12072. *
  12073. * **Note:** This method mutates `object`.
  12074. *
  12075. * @static
  12076. * @memberOf _
  12077. * @since 3.10.0
  12078. * @category Object
  12079. * @param {Object} object The destination object.
  12080. * @param {...Object} [sources] The source objects.
  12081. * @returns {Object} Returns `object`.
  12082. * @see _.defaults
  12083. * @example
  12084. *
  12085. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  12086. * // => { 'a': { 'b': 2, 'c': 3 } }
  12087. */
  12088. var defaultsDeep = baseRest(function(args) {
  12089. args.push(undefined, customDefaultsMerge);
  12090. return apply(mergeWith, undefined, args);
  12091. });
  12092. /**
  12093. * This method is like `_.find` except that it returns the key of the first
  12094. * element `predicate` returns truthy for instead of the element itself.
  12095. *
  12096. * @static
  12097. * @memberOf _
  12098. * @since 1.1.0
  12099. * @category Object
  12100. * @param {Object} object The object to inspect.
  12101. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12102. * @returns {string|undefined} Returns the key of the matched element,
  12103. * else `undefined`.
  12104. * @example
  12105. *
  12106. * var users = {
  12107. * 'barney': { 'age': 36, 'active': true },
  12108. * 'fred': { 'age': 40, 'active': false },
  12109. * 'pebbles': { 'age': 1, 'active': true }
  12110. * };
  12111. *
  12112. * _.findKey(users, function(o) { return o.age < 40; });
  12113. * // => 'barney' (iteration order is not guaranteed)
  12114. *
  12115. * // The `_.matches` iteratee shorthand.
  12116. * _.findKey(users, { 'age': 1, 'active': true });
  12117. * // => 'pebbles'
  12118. *
  12119. * // The `_.matchesProperty` iteratee shorthand.
  12120. * _.findKey(users, ['active', false]);
  12121. * // => 'fred'
  12122. *
  12123. * // The `_.property` iteratee shorthand.
  12124. * _.findKey(users, 'active');
  12125. * // => 'barney'
  12126. */
  12127. function findKey(object, predicate) {
  12128. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12129. }
  12130. /**
  12131. * This method is like `_.findKey` except that it iterates over elements of
  12132. * a collection in the opposite order.
  12133. *
  12134. * @static
  12135. * @memberOf _
  12136. * @since 2.0.0
  12137. * @category Object
  12138. * @param {Object} object The object to inspect.
  12139. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12140. * @returns {string|undefined} Returns the key of the matched element,
  12141. * else `undefined`.
  12142. * @example
  12143. *
  12144. * var users = {
  12145. * 'barney': { 'age': 36, 'active': true },
  12146. * 'fred': { 'age': 40, 'active': false },
  12147. * 'pebbles': { 'age': 1, 'active': true }
  12148. * };
  12149. *
  12150. * _.findLastKey(users, function(o) { return o.age < 40; });
  12151. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12152. *
  12153. * // The `_.matches` iteratee shorthand.
  12154. * _.findLastKey(users, { 'age': 36, 'active': true });
  12155. * // => 'barney'
  12156. *
  12157. * // The `_.matchesProperty` iteratee shorthand.
  12158. * _.findLastKey(users, ['active', false]);
  12159. * // => 'fred'
  12160. *
  12161. * // The `_.property` iteratee shorthand.
  12162. * _.findLastKey(users, 'active');
  12163. * // => 'pebbles'
  12164. */
  12165. function findLastKey(object, predicate) {
  12166. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12167. }
  12168. /**
  12169. * Iterates over own and inherited enumerable string keyed properties of an
  12170. * object and invokes `iteratee` for each property. The iteratee is invoked
  12171. * with three arguments: (value, key, object). Iteratee functions may exit
  12172. * iteration early by explicitly returning `false`.
  12173. *
  12174. * @static
  12175. * @memberOf _
  12176. * @since 0.3.0
  12177. * @category Object
  12178. * @param {Object} object The object to iterate over.
  12179. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12180. * @returns {Object} Returns `object`.
  12181. * @see _.forInRight
  12182. * @example
  12183. *
  12184. * function Foo() {
  12185. * this.a = 1;
  12186. * this.b = 2;
  12187. * }
  12188. *
  12189. * Foo.prototype.c = 3;
  12190. *
  12191. * _.forIn(new Foo, function(value, key) {
  12192. * console.log(key);
  12193. * });
  12194. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12195. */
  12196. function forIn(object, iteratee) {
  12197. return object == null
  12198. ? object
  12199. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12200. }
  12201. /**
  12202. * This method is like `_.forIn` except that it iterates over properties of
  12203. * `object` in the opposite order.
  12204. *
  12205. * @static
  12206. * @memberOf _
  12207. * @since 2.0.0
  12208. * @category Object
  12209. * @param {Object} object The object to iterate over.
  12210. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12211. * @returns {Object} Returns `object`.
  12212. * @see _.forIn
  12213. * @example
  12214. *
  12215. * function Foo() {
  12216. * this.a = 1;
  12217. * this.b = 2;
  12218. * }
  12219. *
  12220. * Foo.prototype.c = 3;
  12221. *
  12222. * _.forInRight(new Foo, function(value, key) {
  12223. * console.log(key);
  12224. * });
  12225. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12226. */
  12227. function forInRight(object, iteratee) {
  12228. return object == null
  12229. ? object
  12230. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12231. }
  12232. /**
  12233. * Iterates over own enumerable string keyed properties of an object and
  12234. * invokes `iteratee` for each property. The iteratee is invoked with three
  12235. * arguments: (value, key, object). Iteratee functions may exit iteration
  12236. * early by explicitly returning `false`.
  12237. *
  12238. * @static
  12239. * @memberOf _
  12240. * @since 0.3.0
  12241. * @category Object
  12242. * @param {Object} object The object to iterate over.
  12243. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12244. * @returns {Object} Returns `object`.
  12245. * @see _.forOwnRight
  12246. * @example
  12247. *
  12248. * function Foo() {
  12249. * this.a = 1;
  12250. * this.b = 2;
  12251. * }
  12252. *
  12253. * Foo.prototype.c = 3;
  12254. *
  12255. * _.forOwn(new Foo, function(value, key) {
  12256. * console.log(key);
  12257. * });
  12258. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12259. */
  12260. function forOwn(object, iteratee) {
  12261. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12262. }
  12263. /**
  12264. * This method is like `_.forOwn` except that it iterates over properties of
  12265. * `object` in the opposite order.
  12266. *
  12267. * @static
  12268. * @memberOf _
  12269. * @since 2.0.0
  12270. * @category Object
  12271. * @param {Object} object The object to iterate over.
  12272. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12273. * @returns {Object} Returns `object`.
  12274. * @see _.forOwn
  12275. * @example
  12276. *
  12277. * function Foo() {
  12278. * this.a = 1;
  12279. * this.b = 2;
  12280. * }
  12281. *
  12282. * Foo.prototype.c = 3;
  12283. *
  12284. * _.forOwnRight(new Foo, function(value, key) {
  12285. * console.log(key);
  12286. * });
  12287. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12288. */
  12289. function forOwnRight(object, iteratee) {
  12290. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12291. }
  12292. /**
  12293. * Creates an array of function property names from own enumerable properties
  12294. * of `object`.
  12295. *
  12296. * @static
  12297. * @since 0.1.0
  12298. * @memberOf _
  12299. * @category Object
  12300. * @param {Object} object The object to inspect.
  12301. * @returns {Array} Returns the function names.
  12302. * @see _.functionsIn
  12303. * @example
  12304. *
  12305. * function Foo() {
  12306. * this.a = _.constant('a');
  12307. * this.b = _.constant('b');
  12308. * }
  12309. *
  12310. * Foo.prototype.c = _.constant('c');
  12311. *
  12312. * _.functions(new Foo);
  12313. * // => ['a', 'b']
  12314. */
  12315. function functions(object) {
  12316. return object == null ? [] : baseFunctions(object, keys(object));
  12317. }
  12318. /**
  12319. * Creates an array of function property names from own and inherited
  12320. * enumerable properties of `object`.
  12321. *
  12322. * @static
  12323. * @memberOf _
  12324. * @since 4.0.0
  12325. * @category Object
  12326. * @param {Object} object The object to inspect.
  12327. * @returns {Array} Returns the function names.
  12328. * @see _.functions
  12329. * @example
  12330. *
  12331. * function Foo() {
  12332. * this.a = _.constant('a');
  12333. * this.b = _.constant('b');
  12334. * }
  12335. *
  12336. * Foo.prototype.c = _.constant('c');
  12337. *
  12338. * _.functionsIn(new Foo);
  12339. * // => ['a', 'b', 'c']
  12340. */
  12341. function functionsIn(object) {
  12342. return object == null ? [] : baseFunctions(object, keysIn(object));
  12343. }
  12344. /**
  12345. * Gets the value at `path` of `object`. If the resolved value is
  12346. * `undefined`, the `defaultValue` is returned in its place.
  12347. *
  12348. * @static
  12349. * @memberOf _
  12350. * @since 3.7.0
  12351. * @category Object
  12352. * @param {Object} object The object to query.
  12353. * @param {Array|string} path The path of the property to get.
  12354. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12355. * @returns {*} Returns the resolved value.
  12356. * @example
  12357. *
  12358. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12359. *
  12360. * _.get(object, 'a[0].b.c');
  12361. * // => 3
  12362. *
  12363. * _.get(object, ['a', '0', 'b', 'c']);
  12364. * // => 3
  12365. *
  12366. * _.get(object, 'a.b.c', 'default');
  12367. * // => 'default'
  12368. */
  12369. function get(object, path, defaultValue) {
  12370. var result = object == null ? undefined : baseGet(object, path);
  12371. return result === undefined ? defaultValue : result;
  12372. }
  12373. /**
  12374. * Checks if `path` is a direct property of `object`.
  12375. *
  12376. * @static
  12377. * @since 0.1.0
  12378. * @memberOf _
  12379. * @category Object
  12380. * @param {Object} object The object to query.
  12381. * @param {Array|string} path The path to check.
  12382. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12383. * @example
  12384. *
  12385. * var object = { 'a': { 'b': 2 } };
  12386. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12387. *
  12388. * _.has(object, 'a');
  12389. * // => true
  12390. *
  12391. * _.has(object, 'a.b');
  12392. * // => true
  12393. *
  12394. * _.has(object, ['a', 'b']);
  12395. * // => true
  12396. *
  12397. * _.has(other, 'a');
  12398. * // => false
  12399. */
  12400. function has(object, path) {
  12401. return object != null && hasPath(object, path, baseHas);
  12402. }
  12403. /**
  12404. * Checks if `path` is a direct or inherited property of `object`.
  12405. *
  12406. * @static
  12407. * @memberOf _
  12408. * @since 4.0.0
  12409. * @category Object
  12410. * @param {Object} object The object to query.
  12411. * @param {Array|string} path The path to check.
  12412. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12413. * @example
  12414. *
  12415. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12416. *
  12417. * _.hasIn(object, 'a');
  12418. * // => true
  12419. *
  12420. * _.hasIn(object, 'a.b');
  12421. * // => true
  12422. *
  12423. * _.hasIn(object, ['a', 'b']);
  12424. * // => true
  12425. *
  12426. * _.hasIn(object, 'b');
  12427. * // => false
  12428. */
  12429. function hasIn(object, path) {
  12430. return object != null && hasPath(object, path, baseHasIn);
  12431. }
  12432. /**
  12433. * Creates an object composed of the inverted keys and values of `object`.
  12434. * If `object` contains duplicate values, subsequent values overwrite
  12435. * property assignments of previous values.
  12436. *
  12437. * @static
  12438. * @memberOf _
  12439. * @since 0.7.0
  12440. * @category Object
  12441. * @param {Object} object The object to invert.
  12442. * @returns {Object} Returns the new inverted object.
  12443. * @example
  12444. *
  12445. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12446. *
  12447. * _.invert(object);
  12448. * // => { '1': 'c', '2': 'b' }
  12449. */
  12450. var invert = createInverter(function(result, value, key) {
  12451. result[value] = key;
  12452. }, constant(identity));
  12453. /**
  12454. * This method is like `_.invert` except that the inverted object is generated
  12455. * from the results of running each element of `object` thru `iteratee`. The
  12456. * corresponding inverted value of each inverted key is an array of keys
  12457. * responsible for generating the inverted value. The iteratee is invoked
  12458. * with one argument: (value).
  12459. *
  12460. * @static
  12461. * @memberOf _
  12462. * @since 4.1.0
  12463. * @category Object
  12464. * @param {Object} object The object to invert.
  12465. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12466. * @returns {Object} Returns the new inverted object.
  12467. * @example
  12468. *
  12469. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12470. *
  12471. * _.invertBy(object);
  12472. * // => { '1': ['a', 'c'], '2': ['b'] }
  12473. *
  12474. * _.invertBy(object, function(value) {
  12475. * return 'group' + value;
  12476. * });
  12477. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12478. */
  12479. var invertBy = createInverter(function(result, value, key) {
  12480. if (hasOwnProperty.call(result, value)) {
  12481. result[value].push(key);
  12482. } else {
  12483. result[value] = [key];
  12484. }
  12485. }, getIteratee);
  12486. /**
  12487. * Invokes the method at `path` of `object`.
  12488. *
  12489. * @static
  12490. * @memberOf _
  12491. * @since 4.0.0
  12492. * @category Object
  12493. * @param {Object} object The object to query.
  12494. * @param {Array|string} path The path of the method to invoke.
  12495. * @param {...*} [args] The arguments to invoke the method with.
  12496. * @returns {*} Returns the result of the invoked method.
  12497. * @example
  12498. *
  12499. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12500. *
  12501. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12502. * // => [2, 3]
  12503. */
  12504. var invoke = baseRest(baseInvoke);
  12505. /**
  12506. * Creates an array of the own enumerable property names of `object`.
  12507. *
  12508. * **Note:** Non-object values are coerced to objects. See the
  12509. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12510. * for more details.
  12511. *
  12512. * @static
  12513. * @since 0.1.0
  12514. * @memberOf _
  12515. * @category Object
  12516. * @param {Object} object The object to query.
  12517. * @returns {Array} Returns the array of property names.
  12518. * @example
  12519. *
  12520. * function Foo() {
  12521. * this.a = 1;
  12522. * this.b = 2;
  12523. * }
  12524. *
  12525. * Foo.prototype.c = 3;
  12526. *
  12527. * _.keys(new Foo);
  12528. * // => ['a', 'b'] (iteration order is not guaranteed)
  12529. *
  12530. * _.keys('hi');
  12531. * // => ['0', '1']
  12532. */
  12533. function keys(object) {
  12534. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12535. }
  12536. /**
  12537. * Creates an array of the own and inherited enumerable property names of `object`.
  12538. *
  12539. * **Note:** Non-object values are coerced to objects.
  12540. *
  12541. * @static
  12542. * @memberOf _
  12543. * @since 3.0.0
  12544. * @category Object
  12545. * @param {Object} object The object to query.
  12546. * @returns {Array} Returns the array of property names.
  12547. * @example
  12548. *
  12549. * function Foo() {
  12550. * this.a = 1;
  12551. * this.b = 2;
  12552. * }
  12553. *
  12554. * Foo.prototype.c = 3;
  12555. *
  12556. * _.keysIn(new Foo);
  12557. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12558. */
  12559. function keysIn(object) {
  12560. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12561. }
  12562. /**
  12563. * The opposite of `_.mapValues`; this method creates an object with the
  12564. * same values as `object` and keys generated by running each own enumerable
  12565. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12566. * with three arguments: (value, key, object).
  12567. *
  12568. * @static
  12569. * @memberOf _
  12570. * @since 3.8.0
  12571. * @category Object
  12572. * @param {Object} object The object to iterate over.
  12573. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12574. * @returns {Object} Returns the new mapped object.
  12575. * @see _.mapValues
  12576. * @example
  12577. *
  12578. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12579. * return key + value;
  12580. * });
  12581. * // => { 'a1': 1, 'b2': 2 }
  12582. */
  12583. function mapKeys(object, iteratee) {
  12584. var result = {};
  12585. iteratee = getIteratee(iteratee, 3);
  12586. baseForOwn(object, function(value, key, object) {
  12587. baseAssignValue(result, iteratee(value, key, object), value);
  12588. });
  12589. return result;
  12590. }
  12591. /**
  12592. * Creates an object with the same keys as `object` and values generated
  12593. * by running each own enumerable string keyed property of `object` thru
  12594. * `iteratee`. The iteratee is invoked with three arguments:
  12595. * (value, key, object).
  12596. *
  12597. * @static
  12598. * @memberOf _
  12599. * @since 2.4.0
  12600. * @category Object
  12601. * @param {Object} object The object to iterate over.
  12602. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12603. * @returns {Object} Returns the new mapped object.
  12604. * @see _.mapKeys
  12605. * @example
  12606. *
  12607. * var users = {
  12608. * 'fred': { 'user': 'fred', 'age': 40 },
  12609. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12610. * };
  12611. *
  12612. * _.mapValues(users, function(o) { return o.age; });
  12613. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12614. *
  12615. * // The `_.property` iteratee shorthand.
  12616. * _.mapValues(users, 'age');
  12617. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12618. */
  12619. function mapValues(object, iteratee) {
  12620. var result = {};
  12621. iteratee = getIteratee(iteratee, 3);
  12622. baseForOwn(object, function(value, key, object) {
  12623. baseAssignValue(result, key, iteratee(value, key, object));
  12624. });
  12625. return result;
  12626. }
  12627. /**
  12628. * This method is like `_.assign` except that it recursively merges own and
  12629. * inherited enumerable string keyed properties of source objects into the
  12630. * destination object. Source properties that resolve to `undefined` are
  12631. * skipped if a destination value exists. Array and plain object properties
  12632. * are merged recursively. Other objects and value types are overridden by
  12633. * assignment. Source objects are applied from left to right. Subsequent
  12634. * sources overwrite property assignments of previous sources.
  12635. *
  12636. * **Note:** This method mutates `object`.
  12637. *
  12638. * @static
  12639. * @memberOf _
  12640. * @since 0.5.0
  12641. * @category Object
  12642. * @param {Object} object The destination object.
  12643. * @param {...Object} [sources] The source objects.
  12644. * @returns {Object} Returns `object`.
  12645. * @example
  12646. *
  12647. * var object = {
  12648. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12649. * };
  12650. *
  12651. * var other = {
  12652. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12653. * };
  12654. *
  12655. * _.merge(object, other);
  12656. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12657. */
  12658. var merge = createAssigner(function(object, source, srcIndex) {
  12659. baseMerge(object, source, srcIndex);
  12660. });
  12661. /**
  12662. * This method is like `_.merge` except that it accepts `customizer` which
  12663. * is invoked to produce the merged values of the destination and source
  12664. * properties. If `customizer` returns `undefined`, merging is handled by the
  12665. * method instead. The `customizer` is invoked with six arguments:
  12666. * (objValue, srcValue, key, object, source, stack).
  12667. *
  12668. * **Note:** This method mutates `object`.
  12669. *
  12670. * @static
  12671. * @memberOf _
  12672. * @since 4.0.0
  12673. * @category Object
  12674. * @param {Object} object The destination object.
  12675. * @param {...Object} sources The source objects.
  12676. * @param {Function} customizer The function to customize assigned values.
  12677. * @returns {Object} Returns `object`.
  12678. * @example
  12679. *
  12680. * function customizer(objValue, srcValue) {
  12681. * if (_.isArray(objValue)) {
  12682. * return objValue.concat(srcValue);
  12683. * }
  12684. * }
  12685. *
  12686. * var object = { 'a': [1], 'b': [2] };
  12687. * var other = { 'a': [3], 'b': [4] };
  12688. *
  12689. * _.mergeWith(object, other, customizer);
  12690. * // => { 'a': [1, 3], 'b': [2, 4] }
  12691. */
  12692. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12693. baseMerge(object, source, srcIndex, customizer);
  12694. });
  12695. /**
  12696. * The opposite of `_.pick`; this method creates an object composed of the
  12697. * own and inherited enumerable property paths of `object` that are not omitted.
  12698. *
  12699. * **Note:** This method is considerably slower than `_.pick`.
  12700. *
  12701. * @static
  12702. * @since 0.1.0
  12703. * @memberOf _
  12704. * @category Object
  12705. * @param {Object} object The source object.
  12706. * @param {...(string|string[])} [paths] The property paths to omit.
  12707. * @returns {Object} Returns the new object.
  12708. * @example
  12709. *
  12710. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12711. *
  12712. * _.omit(object, ['a', 'c']);
  12713. * // => { 'b': '2' }
  12714. */
  12715. var omit = flatRest(function(object, paths) {
  12716. var result = {};
  12717. if (object == null) {
  12718. return result;
  12719. }
  12720. var isDeep = false;
  12721. paths = arrayMap(paths, function(path) {
  12722. path = castPath(path, object);
  12723. isDeep || (isDeep = path.length > 1);
  12724. return path;
  12725. });
  12726. copyObject(object, getAllKeysIn(object), result);
  12727. if (isDeep) {
  12728. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12729. }
  12730. var length = paths.length;
  12731. while (length--) {
  12732. baseUnset(result, paths[length]);
  12733. }
  12734. return result;
  12735. });
  12736. /**
  12737. * The opposite of `_.pickBy`; this method creates an object composed of
  12738. * the own and inherited enumerable string keyed properties of `object` that
  12739. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12740. * arguments: (value, key).
  12741. *
  12742. * @static
  12743. * @memberOf _
  12744. * @since 4.0.0
  12745. * @category Object
  12746. * @param {Object} object The source object.
  12747. * @param {Function} [predicate=_.identity] The function invoked per property.
  12748. * @returns {Object} Returns the new object.
  12749. * @example
  12750. *
  12751. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12752. *
  12753. * _.omitBy(object, _.isNumber);
  12754. * // => { 'b': '2' }
  12755. */
  12756. function omitBy(object, predicate) {
  12757. return pickBy(object, negate(getIteratee(predicate)));
  12758. }
  12759. /**
  12760. * Creates an object composed of the picked `object` properties.
  12761. *
  12762. * @static
  12763. * @since 0.1.0
  12764. * @memberOf _
  12765. * @category Object
  12766. * @param {Object} object The source object.
  12767. * @param {...(string|string[])} [paths] The property paths to pick.
  12768. * @returns {Object} Returns the new object.
  12769. * @example
  12770. *
  12771. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12772. *
  12773. * _.pick(object, ['a', 'c']);
  12774. * // => { 'a': 1, 'c': 3 }
  12775. */
  12776. var pick = flatRest(function(object, paths) {
  12777. return object == null ? {} : basePick(object, paths);
  12778. });
  12779. /**
  12780. * Creates an object composed of the `object` properties `predicate` returns
  12781. * truthy for. The predicate is invoked with two arguments: (value, key).
  12782. *
  12783. * @static
  12784. * @memberOf _
  12785. * @since 4.0.0
  12786. * @category Object
  12787. * @param {Object} object The source object.
  12788. * @param {Function} [predicate=_.identity] The function invoked per property.
  12789. * @returns {Object} Returns the new object.
  12790. * @example
  12791. *
  12792. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12793. *
  12794. * _.pickBy(object, _.isNumber);
  12795. * // => { 'a': 1, 'c': 3 }
  12796. */
  12797. function pickBy(object, predicate) {
  12798. if (object == null) {
  12799. return {};
  12800. }
  12801. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12802. return [prop];
  12803. });
  12804. predicate = getIteratee(predicate);
  12805. return basePickBy(object, props, function(value, path) {
  12806. return predicate(value, path[0]);
  12807. });
  12808. }
  12809. /**
  12810. * This method is like `_.get` except that if the resolved value is a
  12811. * function it's invoked with the `this` binding of its parent object and
  12812. * its result is returned.
  12813. *
  12814. * @static
  12815. * @since 0.1.0
  12816. * @memberOf _
  12817. * @category Object
  12818. * @param {Object} object The object to query.
  12819. * @param {Array|string} path The path of the property to resolve.
  12820. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12821. * @returns {*} Returns the resolved value.
  12822. * @example
  12823. *
  12824. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12825. *
  12826. * _.result(object, 'a[0].b.c1');
  12827. * // => 3
  12828. *
  12829. * _.result(object, 'a[0].b.c2');
  12830. * // => 4
  12831. *
  12832. * _.result(object, 'a[0].b.c3', 'default');
  12833. * // => 'default'
  12834. *
  12835. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12836. * // => 'default'
  12837. */
  12838. function result(object, path, defaultValue) {
  12839. path = castPath(path, object);
  12840. var index = -1,
  12841. length = path.length;
  12842. // Ensure the loop is entered when path is empty.
  12843. if (!length) {
  12844. length = 1;
  12845. object = undefined;
  12846. }
  12847. while (++index < length) {
  12848. var value = object == null ? undefined : object[toKey(path[index])];
  12849. if (value === undefined) {
  12850. index = length;
  12851. value = defaultValue;
  12852. }
  12853. object = isFunction(value) ? value.call(object) : value;
  12854. }
  12855. return object;
  12856. }
  12857. /**
  12858. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12859. * it's created. Arrays are created for missing index properties while objects
  12860. * are created for all other missing properties. Use `_.setWith` to customize
  12861. * `path` creation.
  12862. *
  12863. * **Note:** This method mutates `object`.
  12864. *
  12865. * @static
  12866. * @memberOf _
  12867. * @since 3.7.0
  12868. * @category Object
  12869. * @param {Object} object The object to modify.
  12870. * @param {Array|string} path The path of the property to set.
  12871. * @param {*} value The value to set.
  12872. * @returns {Object} Returns `object`.
  12873. * @example
  12874. *
  12875. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12876. *
  12877. * _.set(object, 'a[0].b.c', 4);
  12878. * console.log(object.a[0].b.c);
  12879. * // => 4
  12880. *
  12881. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12882. * console.log(object.x[0].y.z);
  12883. * // => 5
  12884. */
  12885. function set(object, path, value) {
  12886. return object == null ? object : baseSet(object, path, value);
  12887. }
  12888. /**
  12889. * This method is like `_.set` except that it accepts `customizer` which is
  12890. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12891. * path creation is handled by the method instead. The `customizer` is invoked
  12892. * with three arguments: (nsValue, key, nsObject).
  12893. *
  12894. * **Note:** This method mutates `object`.
  12895. *
  12896. * @static
  12897. * @memberOf _
  12898. * @since 4.0.0
  12899. * @category Object
  12900. * @param {Object} object The object to modify.
  12901. * @param {Array|string} path The path of the property to set.
  12902. * @param {*} value The value to set.
  12903. * @param {Function} [customizer] The function to customize assigned values.
  12904. * @returns {Object} Returns `object`.
  12905. * @example
  12906. *
  12907. * var object = {};
  12908. *
  12909. * _.setWith(object, '[0][1]', 'a', Object);
  12910. * // => { '0': { '1': 'a' } }
  12911. */
  12912. function setWith(object, path, value, customizer) {
  12913. customizer = typeof customizer == 'function' ? customizer : undefined;
  12914. return object == null ? object : baseSet(object, path, value, customizer);
  12915. }
  12916. /**
  12917. * Creates an array of own enumerable string keyed-value pairs for `object`
  12918. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12919. * entries are returned.
  12920. *
  12921. * @static
  12922. * @memberOf _
  12923. * @since 4.0.0
  12924. * @alias entries
  12925. * @category Object
  12926. * @param {Object} object The object to query.
  12927. * @returns {Array} Returns the key-value pairs.
  12928. * @example
  12929. *
  12930. * function Foo() {
  12931. * this.a = 1;
  12932. * this.b = 2;
  12933. * }
  12934. *
  12935. * Foo.prototype.c = 3;
  12936. *
  12937. * _.toPairs(new Foo);
  12938. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12939. */
  12940. var toPairs = createToPairs(keys);
  12941. /**
  12942. * Creates an array of own and inherited enumerable string keyed-value pairs
  12943. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12944. * or set, its entries are returned.
  12945. *
  12946. * @static
  12947. * @memberOf _
  12948. * @since 4.0.0
  12949. * @alias entriesIn
  12950. * @category Object
  12951. * @param {Object} object The object to query.
  12952. * @returns {Array} Returns the key-value pairs.
  12953. * @example
  12954. *
  12955. * function Foo() {
  12956. * this.a = 1;
  12957. * this.b = 2;
  12958. * }
  12959. *
  12960. * Foo.prototype.c = 3;
  12961. *
  12962. * _.toPairsIn(new Foo);
  12963. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12964. */
  12965. var toPairsIn = createToPairs(keysIn);
  12966. /**
  12967. * An alternative to `_.reduce`; this method transforms `object` to a new
  12968. * `accumulator` object which is the result of running each of its own
  12969. * enumerable string keyed properties thru `iteratee`, with each invocation
  12970. * potentially mutating the `accumulator` object. If `accumulator` is not
  12971. * provided, a new object with the same `[[Prototype]]` will be used. The
  12972. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12973. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12974. *
  12975. * @static
  12976. * @memberOf _
  12977. * @since 1.3.0
  12978. * @category Object
  12979. * @param {Object} object The object to iterate over.
  12980. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12981. * @param {*} [accumulator] The custom accumulator value.
  12982. * @returns {*} Returns the accumulated value.
  12983. * @example
  12984. *
  12985. * _.transform([2, 3, 4], function(result, n) {
  12986. * result.push(n *= n);
  12987. * return n % 2 == 0;
  12988. * }, []);
  12989. * // => [4, 9]
  12990. *
  12991. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12992. * (result[value] || (result[value] = [])).push(key);
  12993. * }, {});
  12994. * // => { '1': ['a', 'c'], '2': ['b'] }
  12995. */
  12996. function transform(object, iteratee, accumulator) {
  12997. var isArr = isArray(object),
  12998. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12999. iteratee = getIteratee(iteratee, 4);
  13000. if (accumulator == null) {
  13001. var Ctor = object && object.constructor;
  13002. if (isArrLike) {
  13003. accumulator = isArr ? new Ctor : [];
  13004. }
  13005. else if (isObject(object)) {
  13006. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  13007. }
  13008. else {
  13009. accumulator = {};
  13010. }
  13011. }
  13012. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  13013. return iteratee(accumulator, value, index, object);
  13014. });
  13015. return accumulator;
  13016. }
  13017. /**
  13018. * Removes the property at `path` of `object`.
  13019. *
  13020. * **Note:** This method mutates `object`.
  13021. *
  13022. * @static
  13023. * @memberOf _
  13024. * @since 4.0.0
  13025. * @category Object
  13026. * @param {Object} object The object to modify.
  13027. * @param {Array|string} path The path of the property to unset.
  13028. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  13029. * @example
  13030. *
  13031. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  13032. * _.unset(object, 'a[0].b.c');
  13033. * // => true
  13034. *
  13035. * console.log(object);
  13036. * // => { 'a': [{ 'b': {} }] };
  13037. *
  13038. * _.unset(object, ['a', '0', 'b', 'c']);
  13039. * // => true
  13040. *
  13041. * console.log(object);
  13042. * // => { 'a': [{ 'b': {} }] };
  13043. */
  13044. function unset(object, path) {
  13045. return object == null ? true : baseUnset(object, path);
  13046. }
  13047. /**
  13048. * This method is like `_.set` except that accepts `updater` to produce the
  13049. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  13050. * is invoked with one argument: (value).
  13051. *
  13052. * **Note:** This method mutates `object`.
  13053. *
  13054. * @static
  13055. * @memberOf _
  13056. * @since 4.6.0
  13057. * @category Object
  13058. * @param {Object} object The object to modify.
  13059. * @param {Array|string} path The path of the property to set.
  13060. * @param {Function} updater The function to produce the updated value.
  13061. * @returns {Object} Returns `object`.
  13062. * @example
  13063. *
  13064. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  13065. *
  13066. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  13067. * console.log(object.a[0].b.c);
  13068. * // => 9
  13069. *
  13070. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  13071. * console.log(object.x[0].y.z);
  13072. * // => 0
  13073. */
  13074. function update(object, path, updater) {
  13075. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  13076. }
  13077. /**
  13078. * This method is like `_.update` except that it accepts `customizer` which is
  13079. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  13080. * path creation is handled by the method instead. The `customizer` is invoked
  13081. * with three arguments: (nsValue, key, nsObject).
  13082. *
  13083. * **Note:** This method mutates `object`.
  13084. *
  13085. * @static
  13086. * @memberOf _
  13087. * @since 4.6.0
  13088. * @category Object
  13089. * @param {Object} object The object to modify.
  13090. * @param {Array|string} path The path of the property to set.
  13091. * @param {Function} updater The function to produce the updated value.
  13092. * @param {Function} [customizer] The function to customize assigned values.
  13093. * @returns {Object} Returns `object`.
  13094. * @example
  13095. *
  13096. * var object = {};
  13097. *
  13098. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13099. * // => { '0': { '1': 'a' } }
  13100. */
  13101. function updateWith(object, path, updater, customizer) {
  13102. customizer = typeof customizer == 'function' ? customizer : undefined;
  13103. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13104. }
  13105. /**
  13106. * Creates an array of the own enumerable string keyed property values of `object`.
  13107. *
  13108. * **Note:** Non-object values are coerced to objects.
  13109. *
  13110. * @static
  13111. * @since 0.1.0
  13112. * @memberOf _
  13113. * @category Object
  13114. * @param {Object} object The object to query.
  13115. * @returns {Array} Returns the array of property values.
  13116. * @example
  13117. *
  13118. * function Foo() {
  13119. * this.a = 1;
  13120. * this.b = 2;
  13121. * }
  13122. *
  13123. * Foo.prototype.c = 3;
  13124. *
  13125. * _.values(new Foo);
  13126. * // => [1, 2] (iteration order is not guaranteed)
  13127. *
  13128. * _.values('hi');
  13129. * // => ['h', 'i']
  13130. */
  13131. function values(object) {
  13132. return object == null ? [] : baseValues(object, keys(object));
  13133. }
  13134. /**
  13135. * Creates an array of the own and inherited enumerable string keyed property
  13136. * values of `object`.
  13137. *
  13138. * **Note:** Non-object values are coerced to objects.
  13139. *
  13140. * @static
  13141. * @memberOf _
  13142. * @since 3.0.0
  13143. * @category Object
  13144. * @param {Object} object The object to query.
  13145. * @returns {Array} Returns the array of property values.
  13146. * @example
  13147. *
  13148. * function Foo() {
  13149. * this.a = 1;
  13150. * this.b = 2;
  13151. * }
  13152. *
  13153. * Foo.prototype.c = 3;
  13154. *
  13155. * _.valuesIn(new Foo);
  13156. * // => [1, 2, 3] (iteration order is not guaranteed)
  13157. */
  13158. function valuesIn(object) {
  13159. return object == null ? [] : baseValues(object, keysIn(object));
  13160. }
  13161. /*------------------------------------------------------------------------*/
  13162. /**
  13163. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13164. *
  13165. * @static
  13166. * @memberOf _
  13167. * @since 4.0.0
  13168. * @category Number
  13169. * @param {number} number The number to clamp.
  13170. * @param {number} [lower] The lower bound.
  13171. * @param {number} upper The upper bound.
  13172. * @returns {number} Returns the clamped number.
  13173. * @example
  13174. *
  13175. * _.clamp(-10, -5, 5);
  13176. * // => -5
  13177. *
  13178. * _.clamp(10, -5, 5);
  13179. * // => 5
  13180. */
  13181. function clamp(number, lower, upper) {
  13182. if (upper === undefined) {
  13183. upper = lower;
  13184. lower = undefined;
  13185. }
  13186. if (upper !== undefined) {
  13187. upper = toNumber(upper);
  13188. upper = upper === upper ? upper : 0;
  13189. }
  13190. if (lower !== undefined) {
  13191. lower = toNumber(lower);
  13192. lower = lower === lower ? lower : 0;
  13193. }
  13194. return baseClamp(toNumber(number), lower, upper);
  13195. }
  13196. /**
  13197. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13198. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13199. * If `start` is greater than `end` the params are swapped to support
  13200. * negative ranges.
  13201. *
  13202. * @static
  13203. * @memberOf _
  13204. * @since 3.3.0
  13205. * @category Number
  13206. * @param {number} number The number to check.
  13207. * @param {number} [start=0] The start of the range.
  13208. * @param {number} end The end of the range.
  13209. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13210. * @see _.range, _.rangeRight
  13211. * @example
  13212. *
  13213. * _.inRange(3, 2, 4);
  13214. * // => true
  13215. *
  13216. * _.inRange(4, 8);
  13217. * // => true
  13218. *
  13219. * _.inRange(4, 2);
  13220. * // => false
  13221. *
  13222. * _.inRange(2, 2);
  13223. * // => false
  13224. *
  13225. * _.inRange(1.2, 2);
  13226. * // => true
  13227. *
  13228. * _.inRange(5.2, 4);
  13229. * // => false
  13230. *
  13231. * _.inRange(-3, -2, -6);
  13232. * // => true
  13233. */
  13234. function inRange(number, start, end) {
  13235. start = toFinite(start);
  13236. if (end === undefined) {
  13237. end = start;
  13238. start = 0;
  13239. } else {
  13240. end = toFinite(end);
  13241. }
  13242. number = toNumber(number);
  13243. return baseInRange(number, start, end);
  13244. }
  13245. /**
  13246. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13247. * If only one argument is provided a number between `0` and the given number
  13248. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13249. * floats, a floating-point number is returned instead of an integer.
  13250. *
  13251. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13252. * floating-point values which can produce unexpected results.
  13253. *
  13254. * @static
  13255. * @memberOf _
  13256. * @since 0.7.0
  13257. * @category Number
  13258. * @param {number} [lower=0] The lower bound.
  13259. * @param {number} [upper=1] The upper bound.
  13260. * @param {boolean} [floating] Specify returning a floating-point number.
  13261. * @returns {number} Returns the random number.
  13262. * @example
  13263. *
  13264. * _.random(0, 5);
  13265. * // => an integer between 0 and 5
  13266. *
  13267. * _.random(5);
  13268. * // => also an integer between 0 and 5
  13269. *
  13270. * _.random(5, true);
  13271. * // => a floating-point number between 0 and 5
  13272. *
  13273. * _.random(1.2, 5.2);
  13274. * // => a floating-point number between 1.2 and 5.2
  13275. */
  13276. function random(lower, upper, floating) {
  13277. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13278. upper = floating = undefined;
  13279. }
  13280. if (floating === undefined) {
  13281. if (typeof upper == 'boolean') {
  13282. floating = upper;
  13283. upper = undefined;
  13284. }
  13285. else if (typeof lower == 'boolean') {
  13286. floating = lower;
  13287. lower = undefined;
  13288. }
  13289. }
  13290. if (lower === undefined && upper === undefined) {
  13291. lower = 0;
  13292. upper = 1;
  13293. }
  13294. else {
  13295. lower = toFinite(lower);
  13296. if (upper === undefined) {
  13297. upper = lower;
  13298. lower = 0;
  13299. } else {
  13300. upper = toFinite(upper);
  13301. }
  13302. }
  13303. if (lower > upper) {
  13304. var temp = lower;
  13305. lower = upper;
  13306. upper = temp;
  13307. }
  13308. if (floating || lower % 1 || upper % 1) {
  13309. var rand = nativeRandom();
  13310. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13311. }
  13312. return baseRandom(lower, upper);
  13313. }
  13314. /*------------------------------------------------------------------------*/
  13315. /**
  13316. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13317. *
  13318. * @static
  13319. * @memberOf _
  13320. * @since 3.0.0
  13321. * @category String
  13322. * @param {string} [string=''] The string to convert.
  13323. * @returns {string} Returns the camel cased string.
  13324. * @example
  13325. *
  13326. * _.camelCase('Foo Bar');
  13327. * // => 'fooBar'
  13328. *
  13329. * _.camelCase('--foo-bar--');
  13330. * // => 'fooBar'
  13331. *
  13332. * _.camelCase('__FOO_BAR__');
  13333. * // => 'fooBar'
  13334. */
  13335. var camelCase = createCompounder(function(result, word, index) {
  13336. word = word.toLowerCase();
  13337. return result + (index ? capitalize(word) : word);
  13338. });
  13339. /**
  13340. * Converts the first character of `string` to upper case and the remaining
  13341. * to lower case.
  13342. *
  13343. * @static
  13344. * @memberOf _
  13345. * @since 3.0.0
  13346. * @category String
  13347. * @param {string} [string=''] The string to capitalize.
  13348. * @returns {string} Returns the capitalized string.
  13349. * @example
  13350. *
  13351. * _.capitalize('FRED');
  13352. * // => 'Fred'
  13353. */
  13354. function capitalize(string) {
  13355. return upperFirst(toString(string).toLowerCase());
  13356. }
  13357. /**
  13358. * Deburrs `string` by converting
  13359. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13360. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13361. * letters to basic Latin letters and removing
  13362. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13363. *
  13364. * @static
  13365. * @memberOf _
  13366. * @since 3.0.0
  13367. * @category String
  13368. * @param {string} [string=''] The string to deburr.
  13369. * @returns {string} Returns the deburred string.
  13370. * @example
  13371. *
  13372. * _.deburr('déjà vu');
  13373. * // => 'deja vu'
  13374. */
  13375. function deburr(string) {
  13376. string = toString(string);
  13377. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13378. }
  13379. /**
  13380. * Checks if `string` ends with the given target string.
  13381. *
  13382. * @static
  13383. * @memberOf _
  13384. * @since 3.0.0
  13385. * @category String
  13386. * @param {string} [string=''] The string to inspect.
  13387. * @param {string} [target] The string to search for.
  13388. * @param {number} [position=string.length] The position to search up to.
  13389. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13390. * else `false`.
  13391. * @example
  13392. *
  13393. * _.endsWith('abc', 'c');
  13394. * // => true
  13395. *
  13396. * _.endsWith('abc', 'b');
  13397. * // => false
  13398. *
  13399. * _.endsWith('abc', 'b', 2);
  13400. * // => true
  13401. */
  13402. function endsWith(string, target, position) {
  13403. string = toString(string);
  13404. target = baseToString(target);
  13405. var length = string.length;
  13406. position = position === undefined
  13407. ? length
  13408. : baseClamp(toInteger(position), 0, length);
  13409. var end = position;
  13410. position -= target.length;
  13411. return position >= 0 && string.slice(position, end) == target;
  13412. }
  13413. /**
  13414. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13415. * corresponding HTML entities.
  13416. *
  13417. * **Note:** No other characters are escaped. To escape additional
  13418. * characters use a third-party library like [_he_](https://mths.be/he).
  13419. *
  13420. * Though the ">" character is escaped for symmetry, characters like
  13421. * ">" and "/" don't need escaping in HTML and have no special meaning
  13422. * unless they're part of a tag or unquoted attribute value. See
  13423. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13424. * (under "semi-related fun fact") for more details.
  13425. *
  13426. * When working with HTML you should always
  13427. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13428. * XSS vectors.
  13429. *
  13430. * @static
  13431. * @since 0.1.0
  13432. * @memberOf _
  13433. * @category String
  13434. * @param {string} [string=''] The string to escape.
  13435. * @returns {string} Returns the escaped string.
  13436. * @example
  13437. *
  13438. * _.escape('fred, barney, & pebbles');
  13439. * // => 'fred, barney, &amp; pebbles'
  13440. */
  13441. function escape(string) {
  13442. string = toString(string);
  13443. return (string && reHasUnescapedHtml.test(string))
  13444. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13445. : string;
  13446. }
  13447. /**
  13448. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13449. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13450. *
  13451. * @static
  13452. * @memberOf _
  13453. * @since 3.0.0
  13454. * @category String
  13455. * @param {string} [string=''] The string to escape.
  13456. * @returns {string} Returns the escaped string.
  13457. * @example
  13458. *
  13459. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13460. * // => '\[lodash\]\(https://lodash\.com/\)'
  13461. */
  13462. function escapeRegExp(string) {
  13463. string = toString(string);
  13464. return (string && reHasRegExpChar.test(string))
  13465. ? string.replace(reRegExpChar, '\\$&')
  13466. : string;
  13467. }
  13468. /**
  13469. * Converts `string` to
  13470. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13471. *
  13472. * @static
  13473. * @memberOf _
  13474. * @since 3.0.0
  13475. * @category String
  13476. * @param {string} [string=''] The string to convert.
  13477. * @returns {string} Returns the kebab cased string.
  13478. * @example
  13479. *
  13480. * _.kebabCase('Foo Bar');
  13481. * // => 'foo-bar'
  13482. *
  13483. * _.kebabCase('fooBar');
  13484. * // => 'foo-bar'
  13485. *
  13486. * _.kebabCase('__FOO_BAR__');
  13487. * // => 'foo-bar'
  13488. */
  13489. var kebabCase = createCompounder(function(result, word, index) {
  13490. return result + (index ? '-' : '') + word.toLowerCase();
  13491. });
  13492. /**
  13493. * Converts `string`, as space separated words, to lower case.
  13494. *
  13495. * @static
  13496. * @memberOf _
  13497. * @since 4.0.0
  13498. * @category String
  13499. * @param {string} [string=''] The string to convert.
  13500. * @returns {string} Returns the lower cased string.
  13501. * @example
  13502. *
  13503. * _.lowerCase('--Foo-Bar--');
  13504. * // => 'foo bar'
  13505. *
  13506. * _.lowerCase('fooBar');
  13507. * // => 'foo bar'
  13508. *
  13509. * _.lowerCase('__FOO_BAR__');
  13510. * // => 'foo bar'
  13511. */
  13512. var lowerCase = createCompounder(function(result, word, index) {
  13513. return result + (index ? ' ' : '') + word.toLowerCase();
  13514. });
  13515. /**
  13516. * Converts the first character of `string` to lower case.
  13517. *
  13518. * @static
  13519. * @memberOf _
  13520. * @since 4.0.0
  13521. * @category String
  13522. * @param {string} [string=''] The string to convert.
  13523. * @returns {string} Returns the converted string.
  13524. * @example
  13525. *
  13526. * _.lowerFirst('Fred');
  13527. * // => 'fred'
  13528. *
  13529. * _.lowerFirst('FRED');
  13530. * // => 'fRED'
  13531. */
  13532. var lowerFirst = createCaseFirst('toLowerCase');
  13533. /**
  13534. * Pads `string` on the left and right sides if it's shorter than `length`.
  13535. * Padding characters are truncated if they can't be evenly divided by `length`.
  13536. *
  13537. * @static
  13538. * @memberOf _
  13539. * @since 3.0.0
  13540. * @category String
  13541. * @param {string} [string=''] The string to pad.
  13542. * @param {number} [length=0] The padding length.
  13543. * @param {string} [chars=' '] The string used as padding.
  13544. * @returns {string} Returns the padded string.
  13545. * @example
  13546. *
  13547. * _.pad('abc', 8);
  13548. * // => ' abc '
  13549. *
  13550. * _.pad('abc', 8, '_-');
  13551. * // => '_-abc_-_'
  13552. *
  13553. * _.pad('abc', 3);
  13554. * // => 'abc'
  13555. */
  13556. function pad(string, length, chars) {
  13557. string = toString(string);
  13558. length = toInteger(length);
  13559. var strLength = length ? stringSize(string) : 0;
  13560. if (!length || strLength >= length) {
  13561. return string;
  13562. }
  13563. var mid = (length - strLength) / 2;
  13564. return (
  13565. createPadding(nativeFloor(mid), chars) +
  13566. string +
  13567. createPadding(nativeCeil(mid), chars)
  13568. );
  13569. }
  13570. /**
  13571. * Pads `string` on the right side if it's shorter than `length`. Padding
  13572. * characters are truncated if they exceed `length`.
  13573. *
  13574. * @static
  13575. * @memberOf _
  13576. * @since 4.0.0
  13577. * @category String
  13578. * @param {string} [string=''] The string to pad.
  13579. * @param {number} [length=0] The padding length.
  13580. * @param {string} [chars=' '] The string used as padding.
  13581. * @returns {string} Returns the padded string.
  13582. * @example
  13583. *
  13584. * _.padEnd('abc', 6);
  13585. * // => 'abc '
  13586. *
  13587. * _.padEnd('abc', 6, '_-');
  13588. * // => 'abc_-_'
  13589. *
  13590. * _.padEnd('abc', 3);
  13591. * // => 'abc'
  13592. */
  13593. function padEnd(string, length, chars) {
  13594. string = toString(string);
  13595. length = toInteger(length);
  13596. var strLength = length ? stringSize(string) : 0;
  13597. return (length && strLength < length)
  13598. ? (string + createPadding(length - strLength, chars))
  13599. : string;
  13600. }
  13601. /**
  13602. * Pads `string` on the left side if it's shorter than `length`. Padding
  13603. * characters are truncated if they exceed `length`.
  13604. *
  13605. * @static
  13606. * @memberOf _
  13607. * @since 4.0.0
  13608. * @category String
  13609. * @param {string} [string=''] The string to pad.
  13610. * @param {number} [length=0] The padding length.
  13611. * @param {string} [chars=' '] The string used as padding.
  13612. * @returns {string} Returns the padded string.
  13613. * @example
  13614. *
  13615. * _.padStart('abc', 6);
  13616. * // => ' abc'
  13617. *
  13618. * _.padStart('abc', 6, '_-');
  13619. * // => '_-_abc'
  13620. *
  13621. * _.padStart('abc', 3);
  13622. * // => 'abc'
  13623. */
  13624. function padStart(string, length, chars) {
  13625. string = toString(string);
  13626. length = toInteger(length);
  13627. var strLength = length ? stringSize(string) : 0;
  13628. return (length && strLength < length)
  13629. ? (createPadding(length - strLength, chars) + string)
  13630. : string;
  13631. }
  13632. /**
  13633. * Converts `string` to an integer of the specified radix. If `radix` is
  13634. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13635. * hexadecimal, in which case a `radix` of `16` is used.
  13636. *
  13637. * **Note:** This method aligns with the
  13638. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13639. *
  13640. * @static
  13641. * @memberOf _
  13642. * @since 1.1.0
  13643. * @category String
  13644. * @param {string} string The string to convert.
  13645. * @param {number} [radix=10] The radix to interpret `value` by.
  13646. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13647. * @returns {number} Returns the converted integer.
  13648. * @example
  13649. *
  13650. * _.parseInt('08');
  13651. * // => 8
  13652. *
  13653. * _.map(['6', '08', '10'], _.parseInt);
  13654. * // => [6, 8, 10]
  13655. */
  13656. function parseInt(string, radix, guard) {
  13657. if (guard || radix == null) {
  13658. radix = 0;
  13659. } else if (radix) {
  13660. radix = +radix;
  13661. }
  13662. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13663. }
  13664. /**
  13665. * Repeats the given string `n` times.
  13666. *
  13667. * @static
  13668. * @memberOf _
  13669. * @since 3.0.0
  13670. * @category String
  13671. * @param {string} [string=''] The string to repeat.
  13672. * @param {number} [n=1] The number of times to repeat the string.
  13673. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13674. * @returns {string} Returns the repeated string.
  13675. * @example
  13676. *
  13677. * _.repeat('*', 3);
  13678. * // => '***'
  13679. *
  13680. * _.repeat('abc', 2);
  13681. * // => 'abcabc'
  13682. *
  13683. * _.repeat('abc', 0);
  13684. * // => ''
  13685. */
  13686. function repeat(string, n, guard) {
  13687. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13688. n = 1;
  13689. } else {
  13690. n = toInteger(n);
  13691. }
  13692. return baseRepeat(toString(string), n);
  13693. }
  13694. /**
  13695. * Replaces matches for `pattern` in `string` with `replacement`.
  13696. *
  13697. * **Note:** This method is based on
  13698. * [`String#replace`](https://mdn.io/String/replace).
  13699. *
  13700. * @static
  13701. * @memberOf _
  13702. * @since 4.0.0
  13703. * @category String
  13704. * @param {string} [string=''] The string to modify.
  13705. * @param {RegExp|string} pattern The pattern to replace.
  13706. * @param {Function|string} replacement The match replacement.
  13707. * @returns {string} Returns the modified string.
  13708. * @example
  13709. *
  13710. * _.replace('Hi Fred', 'Fred', 'Barney');
  13711. * // => 'Hi Barney'
  13712. */
  13713. function replace() {
  13714. var args = arguments,
  13715. string = toString(args[0]);
  13716. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13717. }
  13718. /**
  13719. * Converts `string` to
  13720. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13721. *
  13722. * @static
  13723. * @memberOf _
  13724. * @since 3.0.0
  13725. * @category String
  13726. * @param {string} [string=''] The string to convert.
  13727. * @returns {string} Returns the snake cased string.
  13728. * @example
  13729. *
  13730. * _.snakeCase('Foo Bar');
  13731. * // => 'foo_bar'
  13732. *
  13733. * _.snakeCase('fooBar');
  13734. * // => 'foo_bar'
  13735. *
  13736. * _.snakeCase('--FOO-BAR--');
  13737. * // => 'foo_bar'
  13738. */
  13739. var snakeCase = createCompounder(function(result, word, index) {
  13740. return result + (index ? '_' : '') + word.toLowerCase();
  13741. });
  13742. /**
  13743. * Splits `string` by `separator`.
  13744. *
  13745. * **Note:** This method is based on
  13746. * [`String#split`](https://mdn.io/String/split).
  13747. *
  13748. * @static
  13749. * @memberOf _
  13750. * @since 4.0.0
  13751. * @category String
  13752. * @param {string} [string=''] The string to split.
  13753. * @param {RegExp|string} separator The separator pattern to split by.
  13754. * @param {number} [limit] The length to truncate results to.
  13755. * @returns {Array} Returns the string segments.
  13756. * @example
  13757. *
  13758. * _.split('a-b-c', '-', 2);
  13759. * // => ['a', 'b']
  13760. */
  13761. function split(string, separator, limit) {
  13762. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13763. separator = limit = undefined;
  13764. }
  13765. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13766. if (!limit) {
  13767. return [];
  13768. }
  13769. string = toString(string);
  13770. if (string && (
  13771. typeof separator == 'string' ||
  13772. (separator != null && !isRegExp(separator))
  13773. )) {
  13774. separator = baseToString(separator);
  13775. if (!separator && hasUnicode(string)) {
  13776. return castSlice(stringToArray(string), 0, limit);
  13777. }
  13778. }
  13779. return string.split(separator, limit);
  13780. }
  13781. /**
  13782. * Converts `string` to
  13783. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13784. *
  13785. * @static
  13786. * @memberOf _
  13787. * @since 3.1.0
  13788. * @category String
  13789. * @param {string} [string=''] The string to convert.
  13790. * @returns {string} Returns the start cased string.
  13791. * @example
  13792. *
  13793. * _.startCase('--foo-bar--');
  13794. * // => 'Foo Bar'
  13795. *
  13796. * _.startCase('fooBar');
  13797. * // => 'Foo Bar'
  13798. *
  13799. * _.startCase('__FOO_BAR__');
  13800. * // => 'FOO BAR'
  13801. */
  13802. var startCase = createCompounder(function(result, word, index) {
  13803. return result + (index ? ' ' : '') + upperFirst(word);
  13804. });
  13805. /**
  13806. * Checks if `string` starts with the given target string.
  13807. *
  13808. * @static
  13809. * @memberOf _
  13810. * @since 3.0.0
  13811. * @category String
  13812. * @param {string} [string=''] The string to inspect.
  13813. * @param {string} [target] The string to search for.
  13814. * @param {number} [position=0] The position to search from.
  13815. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13816. * else `false`.
  13817. * @example
  13818. *
  13819. * _.startsWith('abc', 'a');
  13820. * // => true
  13821. *
  13822. * _.startsWith('abc', 'b');
  13823. * // => false
  13824. *
  13825. * _.startsWith('abc', 'b', 1);
  13826. * // => true
  13827. */
  13828. function startsWith(string, target, position) {
  13829. string = toString(string);
  13830. position = position == null
  13831. ? 0
  13832. : baseClamp(toInteger(position), 0, string.length);
  13833. target = baseToString(target);
  13834. return string.slice(position, position + target.length) == target;
  13835. }
  13836. /**
  13837. * Creates a compiled template function that can interpolate data properties
  13838. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13839. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13840. * properties may be accessed as free variables in the template. If a setting
  13841. * object is given, it takes precedence over `_.templateSettings` values.
  13842. *
  13843. * **Note:** In the development build `_.template` utilizes
  13844. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13845. * for easier debugging.
  13846. *
  13847. * For more information on precompiling templates see
  13848. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13849. *
  13850. * For more information on Chrome extension sandboxes see
  13851. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13852. *
  13853. * @static
  13854. * @since 0.1.0
  13855. * @memberOf _
  13856. * @category String
  13857. * @param {string} [string=''] The template string.
  13858. * @param {Object} [options={}] The options object.
  13859. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13860. * The HTML "escape" delimiter.
  13861. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13862. * The "evaluate" delimiter.
  13863. * @param {Object} [options.imports=_.templateSettings.imports]
  13864. * An object to import into the template as free variables.
  13865. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13866. * The "interpolate" delimiter.
  13867. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13868. * The sourceURL of the compiled template.
  13869. * @param {string} [options.variable='obj']
  13870. * The data object variable name.
  13871. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13872. * @returns {Function} Returns the compiled template function.
  13873. * @example
  13874. *
  13875. * // Use the "interpolate" delimiter to create a compiled template.
  13876. * var compiled = _.template('hello <%= user %>!');
  13877. * compiled({ 'user': 'fred' });
  13878. * // => 'hello fred!'
  13879. *
  13880. * // Use the HTML "escape" delimiter to escape data property values.
  13881. * var compiled = _.template('<b><%- value %></b>');
  13882. * compiled({ 'value': '<script>' });
  13883. * // => '<b>&lt;script&gt;</b>'
  13884. *
  13885. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13886. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13887. * compiled({ 'users': ['fred', 'barney'] });
  13888. * // => '<li>fred</li><li>barney</li>'
  13889. *
  13890. * // Use the internal `print` function in "evaluate" delimiters.
  13891. * var compiled = _.template('<% print("hello " + user); %>!');
  13892. * compiled({ 'user': 'barney' });
  13893. * // => 'hello barney!'
  13894. *
  13895. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13896. * // Disable support by replacing the "interpolate" delimiter.
  13897. * var compiled = _.template('hello ${ user }!');
  13898. * compiled({ 'user': 'pebbles' });
  13899. * // => 'hello pebbles!'
  13900. *
  13901. * // Use backslashes to treat delimiters as plain text.
  13902. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13903. * compiled({ 'value': 'ignored' });
  13904. * // => '<%- value %>'
  13905. *
  13906. * // Use the `imports` option to import `jQuery` as `jq`.
  13907. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13908. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13909. * compiled({ 'users': ['fred', 'barney'] });
  13910. * // => '<li>fred</li><li>barney</li>'
  13911. *
  13912. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13913. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13914. * compiled(data);
  13915. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13916. *
  13917. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13918. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13919. * compiled.source;
  13920. * // => function(data) {
  13921. * // var __t, __p = '';
  13922. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13923. * // return __p;
  13924. * // }
  13925. *
  13926. * // Use custom template delimiters.
  13927. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13928. * var compiled = _.template('hello {{ user }}!');
  13929. * compiled({ 'user': 'mustache' });
  13930. * // => 'hello mustache!'
  13931. *
  13932. * // Use the `source` property to inline compiled templates for meaningful
  13933. * // line numbers in error messages and stack traces.
  13934. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13935. * var JST = {\
  13936. * "main": ' + _.template(mainText).source + '\
  13937. * };\
  13938. * ');
  13939. */
  13940. function template(string, options, guard) {
  13941. // Based on John Resig's `tmpl` implementation
  13942. // (http://ejohn.org/blog/javascript-micro-templating/)
  13943. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13944. var settings = lodash.templateSettings;
  13945. if (guard && isIterateeCall(string, options, guard)) {
  13946. options = undefined;
  13947. }
  13948. string = toString(string);
  13949. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13950. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13951. importsKeys = keys(imports),
  13952. importsValues = baseValues(imports, importsKeys);
  13953. var isEscaping,
  13954. isEvaluating,
  13955. index = 0,
  13956. interpolate = options.interpolate || reNoMatch,
  13957. source = "__p += '";
  13958. // Compile the regexp to match each delimiter.
  13959. var reDelimiters = RegExp(
  13960. (options.escape || reNoMatch).source + '|' +
  13961. interpolate.source + '|' +
  13962. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13963. (options.evaluate || reNoMatch).source + '|$'
  13964. , 'g');
  13965. // Use a sourceURL for easier debugging.
  13966. var sourceURL = '//# sourceURL=' +
  13967. ('sourceURL' in options
  13968. ? options.sourceURL
  13969. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13970. ) + '\n';
  13971. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13972. interpolateValue || (interpolateValue = esTemplateValue);
  13973. // Escape characters that can't be included in string literals.
  13974. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13975. // Replace delimiters with snippets.
  13976. if (escapeValue) {
  13977. isEscaping = true;
  13978. source += "' +\n__e(" + escapeValue + ") +\n'";
  13979. }
  13980. if (evaluateValue) {
  13981. isEvaluating = true;
  13982. source += "';\n" + evaluateValue + ";\n__p += '";
  13983. }
  13984. if (interpolateValue) {
  13985. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13986. }
  13987. index = offset + match.length;
  13988. // The JS engine embedded in Adobe products needs `match` returned in
  13989. // order to produce the correct `offset` value.
  13990. return match;
  13991. });
  13992. source += "';\n";
  13993. // If `variable` is not specified wrap a with-statement around the generated
  13994. // code to add the data object to the top of the scope chain.
  13995. var variable = options.variable;
  13996. if (!variable) {
  13997. source = 'with (obj) {\n' + source + '\n}\n';
  13998. }
  13999. // Cleanup code by stripping empty strings.
  14000. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  14001. .replace(reEmptyStringMiddle, '$1')
  14002. .replace(reEmptyStringTrailing, '$1;');
  14003. // Frame code as the function body.
  14004. source = 'function(' + (variable || 'obj') + ') {\n' +
  14005. (variable
  14006. ? ''
  14007. : 'obj || (obj = {});\n'
  14008. ) +
  14009. "var __t, __p = ''" +
  14010. (isEscaping
  14011. ? ', __e = _.escape'
  14012. : ''
  14013. ) +
  14014. (isEvaluating
  14015. ? ', __j = Array.prototype.join;\n' +
  14016. "function print() { __p += __j.call(arguments, '') }\n"
  14017. : ';\n'
  14018. ) +
  14019. source +
  14020. 'return __p\n}';
  14021. var result = attempt(function() {
  14022. return Function(importsKeys, sourceURL + 'return ' + source)
  14023. .apply(undefined, importsValues);
  14024. });
  14025. // Provide the compiled function's source by its `toString` method or
  14026. // the `source` property as a convenience for inlining compiled templates.
  14027. result.source = source;
  14028. if (isError(result)) {
  14029. throw result;
  14030. }
  14031. return result;
  14032. }
  14033. /**
  14034. * Converts `string`, as a whole, to lower case just like
  14035. * [String#toLowerCase](https://mdn.io/toLowerCase).
  14036. *
  14037. * @static
  14038. * @memberOf _
  14039. * @since 4.0.0
  14040. * @category String
  14041. * @param {string} [string=''] The string to convert.
  14042. * @returns {string} Returns the lower cased string.
  14043. * @example
  14044. *
  14045. * _.toLower('--Foo-Bar--');
  14046. * // => '--foo-bar--'
  14047. *
  14048. * _.toLower('fooBar');
  14049. * // => 'foobar'
  14050. *
  14051. * _.toLower('__FOO_BAR__');
  14052. * // => '__foo_bar__'
  14053. */
  14054. function toLower(value) {
  14055. return toString(value).toLowerCase();
  14056. }
  14057. /**
  14058. * Converts `string`, as a whole, to upper case just like
  14059. * [String#toUpperCase](https://mdn.io/toUpperCase).
  14060. *
  14061. * @static
  14062. * @memberOf _
  14063. * @since 4.0.0
  14064. * @category String
  14065. * @param {string} [string=''] The string to convert.
  14066. * @returns {string} Returns the upper cased string.
  14067. * @example
  14068. *
  14069. * _.toUpper('--foo-bar--');
  14070. * // => '--FOO-BAR--'
  14071. *
  14072. * _.toUpper('fooBar');
  14073. * // => 'FOOBAR'
  14074. *
  14075. * _.toUpper('__foo_bar__');
  14076. * // => '__FOO_BAR__'
  14077. */
  14078. function toUpper(value) {
  14079. return toString(value).toUpperCase();
  14080. }
  14081. /**
  14082. * Removes leading and trailing whitespace or specified characters from `string`.
  14083. *
  14084. * @static
  14085. * @memberOf _
  14086. * @since 3.0.0
  14087. * @category String
  14088. * @param {string} [string=''] The string to trim.
  14089. * @param {string} [chars=whitespace] The characters to trim.
  14090. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14091. * @returns {string} Returns the trimmed string.
  14092. * @example
  14093. *
  14094. * _.trim(' abc ');
  14095. * // => 'abc'
  14096. *
  14097. * _.trim('-_-abc-_-', '_-');
  14098. * // => 'abc'
  14099. *
  14100. * _.map([' foo ', ' bar '], _.trim);
  14101. * // => ['foo', 'bar']
  14102. */
  14103. function trim(string, chars, guard) {
  14104. string = toString(string);
  14105. if (string && (guard || chars === undefined)) {
  14106. return string.replace(reTrim, '');
  14107. }
  14108. if (!string || !(chars = baseToString(chars))) {
  14109. return string;
  14110. }
  14111. var strSymbols = stringToArray(string),
  14112. chrSymbols = stringToArray(chars),
  14113. start = charsStartIndex(strSymbols, chrSymbols),
  14114. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14115. return castSlice(strSymbols, start, end).join('');
  14116. }
  14117. /**
  14118. * Removes trailing whitespace or specified characters from `string`.
  14119. *
  14120. * @static
  14121. * @memberOf _
  14122. * @since 4.0.0
  14123. * @category String
  14124. * @param {string} [string=''] The string to trim.
  14125. * @param {string} [chars=whitespace] The characters to trim.
  14126. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14127. * @returns {string} Returns the trimmed string.
  14128. * @example
  14129. *
  14130. * _.trimEnd(' abc ');
  14131. * // => ' abc'
  14132. *
  14133. * _.trimEnd('-_-abc-_-', '_-');
  14134. * // => '-_-abc'
  14135. */
  14136. function trimEnd(string, chars, guard) {
  14137. string = toString(string);
  14138. if (string && (guard || chars === undefined)) {
  14139. return string.replace(reTrimEnd, '');
  14140. }
  14141. if (!string || !(chars = baseToString(chars))) {
  14142. return string;
  14143. }
  14144. var strSymbols = stringToArray(string),
  14145. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14146. return castSlice(strSymbols, 0, end).join('');
  14147. }
  14148. /**
  14149. * Removes leading whitespace or specified characters from `string`.
  14150. *
  14151. * @static
  14152. * @memberOf _
  14153. * @since 4.0.0
  14154. * @category String
  14155. * @param {string} [string=''] The string to trim.
  14156. * @param {string} [chars=whitespace] The characters to trim.
  14157. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14158. * @returns {string} Returns the trimmed string.
  14159. * @example
  14160. *
  14161. * _.trimStart(' abc ');
  14162. * // => 'abc '
  14163. *
  14164. * _.trimStart('-_-abc-_-', '_-');
  14165. * // => 'abc-_-'
  14166. */
  14167. function trimStart(string, chars, guard) {
  14168. string = toString(string);
  14169. if (string && (guard || chars === undefined)) {
  14170. return string.replace(reTrimStart, '');
  14171. }
  14172. if (!string || !(chars = baseToString(chars))) {
  14173. return string;
  14174. }
  14175. var strSymbols = stringToArray(string),
  14176. start = charsStartIndex(strSymbols, stringToArray(chars));
  14177. return castSlice(strSymbols, start).join('');
  14178. }
  14179. /**
  14180. * Truncates `string` if it's longer than the given maximum string length.
  14181. * The last characters of the truncated string are replaced with the omission
  14182. * string which defaults to "...".
  14183. *
  14184. * @static
  14185. * @memberOf _
  14186. * @since 4.0.0
  14187. * @category String
  14188. * @param {string} [string=''] The string to truncate.
  14189. * @param {Object} [options={}] The options object.
  14190. * @param {number} [options.length=30] The maximum string length.
  14191. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14192. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14193. * @returns {string} Returns the truncated string.
  14194. * @example
  14195. *
  14196. * _.truncate('hi-diddly-ho there, neighborino');
  14197. * // => 'hi-diddly-ho there, neighbo...'
  14198. *
  14199. * _.truncate('hi-diddly-ho there, neighborino', {
  14200. * 'length': 24,
  14201. * 'separator': ' '
  14202. * });
  14203. * // => 'hi-diddly-ho there,...'
  14204. *
  14205. * _.truncate('hi-diddly-ho there, neighborino', {
  14206. * 'length': 24,
  14207. * 'separator': /,? +/
  14208. * });
  14209. * // => 'hi-diddly-ho there...'
  14210. *
  14211. * _.truncate('hi-diddly-ho there, neighborino', {
  14212. * 'omission': ' [...]'
  14213. * });
  14214. * // => 'hi-diddly-ho there, neig [...]'
  14215. */
  14216. function truncate(string, options) {
  14217. var length = DEFAULT_TRUNC_LENGTH,
  14218. omission = DEFAULT_TRUNC_OMISSION;
  14219. if (isObject(options)) {
  14220. var separator = 'separator' in options ? options.separator : separator;
  14221. length = 'length' in options ? toInteger(options.length) : length;
  14222. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14223. }
  14224. string = toString(string);
  14225. var strLength = string.length;
  14226. if (hasUnicode(string)) {
  14227. var strSymbols = stringToArray(string);
  14228. strLength = strSymbols.length;
  14229. }
  14230. if (length >= strLength) {
  14231. return string;
  14232. }
  14233. var end = length - stringSize(omission);
  14234. if (end < 1) {
  14235. return omission;
  14236. }
  14237. var result = strSymbols
  14238. ? castSlice(strSymbols, 0, end).join('')
  14239. : string.slice(0, end);
  14240. if (separator === undefined) {
  14241. return result + omission;
  14242. }
  14243. if (strSymbols) {
  14244. end += (result.length - end);
  14245. }
  14246. if (isRegExp(separator)) {
  14247. if (string.slice(end).search(separator)) {
  14248. var match,
  14249. substring = result;
  14250. if (!separator.global) {
  14251. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14252. }
  14253. separator.lastIndex = 0;
  14254. while ((match = separator.exec(substring))) {
  14255. var newEnd = match.index;
  14256. }
  14257. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14258. }
  14259. } else if (string.indexOf(baseToString(separator), end) != end) {
  14260. var index = result.lastIndexOf(separator);
  14261. if (index > -1) {
  14262. result = result.slice(0, index);
  14263. }
  14264. }
  14265. return result + omission;
  14266. }
  14267. /**
  14268. * The inverse of `_.escape`; this method converts the HTML entities
  14269. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14270. * their corresponding characters.
  14271. *
  14272. * **Note:** No other HTML entities are unescaped. To unescape additional
  14273. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14274. *
  14275. * @static
  14276. * @memberOf _
  14277. * @since 0.6.0
  14278. * @category String
  14279. * @param {string} [string=''] The string to unescape.
  14280. * @returns {string} Returns the unescaped string.
  14281. * @example
  14282. *
  14283. * _.unescape('fred, barney, &amp; pebbles');
  14284. * // => 'fred, barney, & pebbles'
  14285. */
  14286. function unescape(string) {
  14287. string = toString(string);
  14288. return (string && reHasEscapedHtml.test(string))
  14289. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14290. : string;
  14291. }
  14292. /**
  14293. * Converts `string`, as space separated words, to upper case.
  14294. *
  14295. * @static
  14296. * @memberOf _
  14297. * @since 4.0.0
  14298. * @category String
  14299. * @param {string} [string=''] The string to convert.
  14300. * @returns {string} Returns the upper cased string.
  14301. * @example
  14302. *
  14303. * _.upperCase('--foo-bar');
  14304. * // => 'FOO BAR'
  14305. *
  14306. * _.upperCase('fooBar');
  14307. * // => 'FOO BAR'
  14308. *
  14309. * _.upperCase('__foo_bar__');
  14310. * // => 'FOO BAR'
  14311. */
  14312. var upperCase = createCompounder(function(result, word, index) {
  14313. return result + (index ? ' ' : '') + word.toUpperCase();
  14314. });
  14315. /**
  14316. * Converts the first character of `string` to upper case.
  14317. *
  14318. * @static
  14319. * @memberOf _
  14320. * @since 4.0.0
  14321. * @category String
  14322. * @param {string} [string=''] The string to convert.
  14323. * @returns {string} Returns the converted string.
  14324. * @example
  14325. *
  14326. * _.upperFirst('fred');
  14327. * // => 'Fred'
  14328. *
  14329. * _.upperFirst('FRED');
  14330. * // => 'FRED'
  14331. */
  14332. var upperFirst = createCaseFirst('toUpperCase');
  14333. /**
  14334. * Splits `string` into an array of its words.
  14335. *
  14336. * @static
  14337. * @memberOf _
  14338. * @since 3.0.0
  14339. * @category String
  14340. * @param {string} [string=''] The string to inspect.
  14341. * @param {RegExp|string} [pattern] The pattern to match words.
  14342. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14343. * @returns {Array} Returns the words of `string`.
  14344. * @example
  14345. *
  14346. * _.words('fred, barney, & pebbles');
  14347. * // => ['fred', 'barney', 'pebbles']
  14348. *
  14349. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14350. * // => ['fred', 'barney', '&', 'pebbles']
  14351. */
  14352. function words(string, pattern, guard) {
  14353. string = toString(string);
  14354. pattern = guard ? undefined : pattern;
  14355. if (pattern === undefined) {
  14356. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14357. }
  14358. return string.match(pattern) || [];
  14359. }
  14360. /*------------------------------------------------------------------------*/
  14361. /**
  14362. * Attempts to invoke `func`, returning either the result or the caught error
  14363. * object. Any additional arguments are provided to `func` when it's invoked.
  14364. *
  14365. * @static
  14366. * @memberOf _
  14367. * @since 3.0.0
  14368. * @category Util
  14369. * @param {Function} func The function to attempt.
  14370. * @param {...*} [args] The arguments to invoke `func` with.
  14371. * @returns {*} Returns the `func` result or error object.
  14372. * @example
  14373. *
  14374. * // Avoid throwing errors for invalid selectors.
  14375. * var elements = _.attempt(function(selector) {
  14376. * return document.querySelectorAll(selector);
  14377. * }, '>_>');
  14378. *
  14379. * if (_.isError(elements)) {
  14380. * elements = [];
  14381. * }
  14382. */
  14383. var attempt = baseRest(function(func, args) {
  14384. try {
  14385. return apply(func, undefined, args);
  14386. } catch (e) {
  14387. return isError(e) ? e : new Error(e);
  14388. }
  14389. });
  14390. /**
  14391. * Binds methods of an object to the object itself, overwriting the existing
  14392. * method.
  14393. *
  14394. * **Note:** This method doesn't set the "length" property of bound functions.
  14395. *
  14396. * @static
  14397. * @since 0.1.0
  14398. * @memberOf _
  14399. * @category Util
  14400. * @param {Object} object The object to bind and assign the bound methods to.
  14401. * @param {...(string|string[])} methodNames The object method names to bind.
  14402. * @returns {Object} Returns `object`.
  14403. * @example
  14404. *
  14405. * var view = {
  14406. * 'label': 'docs',
  14407. * 'click': function() {
  14408. * console.log('clicked ' + this.label);
  14409. * }
  14410. * };
  14411. *
  14412. * _.bindAll(view, ['click']);
  14413. * jQuery(element).on('click', view.click);
  14414. * // => Logs 'clicked docs' when clicked.
  14415. */
  14416. var bindAll = flatRest(function(object, methodNames) {
  14417. arrayEach(methodNames, function(key) {
  14418. key = toKey(key);
  14419. baseAssignValue(object, key, bind(object[key], object));
  14420. });
  14421. return object;
  14422. });
  14423. /**
  14424. * Creates a function that iterates over `pairs` and invokes the corresponding
  14425. * function of the first predicate to return truthy. The predicate-function
  14426. * pairs are invoked with the `this` binding and arguments of the created
  14427. * function.
  14428. *
  14429. * @static
  14430. * @memberOf _
  14431. * @since 4.0.0
  14432. * @category Util
  14433. * @param {Array} pairs The predicate-function pairs.
  14434. * @returns {Function} Returns the new composite function.
  14435. * @example
  14436. *
  14437. * var func = _.cond([
  14438. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14439. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14440. * [_.stubTrue, _.constant('no match')]
  14441. * ]);
  14442. *
  14443. * func({ 'a': 1, 'b': 2 });
  14444. * // => 'matches A'
  14445. *
  14446. * func({ 'a': 0, 'b': 1 });
  14447. * // => 'matches B'
  14448. *
  14449. * func({ 'a': '1', 'b': '2' });
  14450. * // => 'no match'
  14451. */
  14452. function cond(pairs) {
  14453. var length = pairs == null ? 0 : pairs.length,
  14454. toIteratee = getIteratee();
  14455. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14456. if (typeof pair[1] != 'function') {
  14457. throw new TypeError(FUNC_ERROR_TEXT);
  14458. }
  14459. return [toIteratee(pair[0]), pair[1]];
  14460. });
  14461. return baseRest(function(args) {
  14462. var index = -1;
  14463. while (++index < length) {
  14464. var pair = pairs[index];
  14465. if (apply(pair[0], this, args)) {
  14466. return apply(pair[1], this, args);
  14467. }
  14468. }
  14469. });
  14470. }
  14471. /**
  14472. * Creates a function that invokes the predicate properties of `source` with
  14473. * the corresponding property values of a given object, returning `true` if
  14474. * all predicates return truthy, else `false`.
  14475. *
  14476. * **Note:** The created function is equivalent to `_.conformsTo` with
  14477. * `source` partially applied.
  14478. *
  14479. * @static
  14480. * @memberOf _
  14481. * @since 4.0.0
  14482. * @category Util
  14483. * @param {Object} source The object of property predicates to conform to.
  14484. * @returns {Function} Returns the new spec function.
  14485. * @example
  14486. *
  14487. * var objects = [
  14488. * { 'a': 2, 'b': 1 },
  14489. * { 'a': 1, 'b': 2 }
  14490. * ];
  14491. *
  14492. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14493. * // => [{ 'a': 1, 'b': 2 }]
  14494. */
  14495. function conforms(source) {
  14496. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14497. }
  14498. /**
  14499. * Creates a function that returns `value`.
  14500. *
  14501. * @static
  14502. * @memberOf _
  14503. * @since 2.4.0
  14504. * @category Util
  14505. * @param {*} value The value to return from the new function.
  14506. * @returns {Function} Returns the new constant function.
  14507. * @example
  14508. *
  14509. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14510. *
  14511. * console.log(objects);
  14512. * // => [{ 'a': 1 }, { 'a': 1 }]
  14513. *
  14514. * console.log(objects[0] === objects[1]);
  14515. * // => true
  14516. */
  14517. function constant(value) {
  14518. return function() {
  14519. return value;
  14520. };
  14521. }
  14522. /**
  14523. * Checks `value` to determine whether a default value should be returned in
  14524. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14525. * or `undefined`.
  14526. *
  14527. * @static
  14528. * @memberOf _
  14529. * @since 4.14.0
  14530. * @category Util
  14531. * @param {*} value The value to check.
  14532. * @param {*} defaultValue The default value.
  14533. * @returns {*} Returns the resolved value.
  14534. * @example
  14535. *
  14536. * _.defaultTo(1, 10);
  14537. * // => 1
  14538. *
  14539. * _.defaultTo(undefined, 10);
  14540. * // => 10
  14541. */
  14542. function defaultTo(value, defaultValue) {
  14543. return (value == null || value !== value) ? defaultValue : value;
  14544. }
  14545. /**
  14546. * Creates a function that returns the result of invoking the given functions
  14547. * with the `this` binding of the created function, where each successive
  14548. * invocation is supplied the return value of the previous.
  14549. *
  14550. * @static
  14551. * @memberOf _
  14552. * @since 3.0.0
  14553. * @category Util
  14554. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14555. * @returns {Function} Returns the new composite function.
  14556. * @see _.flowRight
  14557. * @example
  14558. *
  14559. * function square(n) {
  14560. * return n * n;
  14561. * }
  14562. *
  14563. * var addSquare = _.flow([_.add, square]);
  14564. * addSquare(1, 2);
  14565. * // => 9
  14566. */
  14567. var flow = createFlow();
  14568. /**
  14569. * This method is like `_.flow` except that it creates a function that
  14570. * invokes the given functions from right to left.
  14571. *
  14572. * @static
  14573. * @since 3.0.0
  14574. * @memberOf _
  14575. * @category Util
  14576. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14577. * @returns {Function} Returns the new composite function.
  14578. * @see _.flow
  14579. * @example
  14580. *
  14581. * function square(n) {
  14582. * return n * n;
  14583. * }
  14584. *
  14585. * var addSquare = _.flowRight([square, _.add]);
  14586. * addSquare(1, 2);
  14587. * // => 9
  14588. */
  14589. var flowRight = createFlow(true);
  14590. /**
  14591. * This method returns the first argument it receives.
  14592. *
  14593. * @static
  14594. * @since 0.1.0
  14595. * @memberOf _
  14596. * @category Util
  14597. * @param {*} value Any value.
  14598. * @returns {*} Returns `value`.
  14599. * @example
  14600. *
  14601. * var object = { 'a': 1 };
  14602. *
  14603. * console.log(_.identity(object) === object);
  14604. * // => true
  14605. */
  14606. function identity(value) {
  14607. return value;
  14608. }
  14609. /**
  14610. * Creates a function that invokes `func` with the arguments of the created
  14611. * function. If `func` is a property name, the created function returns the
  14612. * property value for a given element. If `func` is an array or object, the
  14613. * created function returns `true` for elements that contain the equivalent
  14614. * source properties, otherwise it returns `false`.
  14615. *
  14616. * @static
  14617. * @since 4.0.0
  14618. * @memberOf _
  14619. * @category Util
  14620. * @param {*} [func=_.identity] The value to convert to a callback.
  14621. * @returns {Function} Returns the callback.
  14622. * @example
  14623. *
  14624. * var users = [
  14625. * { 'user': 'barney', 'age': 36, 'active': true },
  14626. * { 'user': 'fred', 'age': 40, 'active': false }
  14627. * ];
  14628. *
  14629. * // The `_.matches` iteratee shorthand.
  14630. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14631. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14632. *
  14633. * // The `_.matchesProperty` iteratee shorthand.
  14634. * _.filter(users, _.iteratee(['user', 'fred']));
  14635. * // => [{ 'user': 'fred', 'age': 40 }]
  14636. *
  14637. * // The `_.property` iteratee shorthand.
  14638. * _.map(users, _.iteratee('user'));
  14639. * // => ['barney', 'fred']
  14640. *
  14641. * // Create custom iteratee shorthands.
  14642. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14643. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14644. * return func.test(string);
  14645. * };
  14646. * });
  14647. *
  14648. * _.filter(['abc', 'def'], /ef/);
  14649. * // => ['def']
  14650. */
  14651. function iteratee(func) {
  14652. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14653. }
  14654. /**
  14655. * Creates a function that performs a partial deep comparison between a given
  14656. * object and `source`, returning `true` if the given object has equivalent
  14657. * property values, else `false`.
  14658. *
  14659. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14660. * partially applied.
  14661. *
  14662. * Partial comparisons will match empty array and empty object `source`
  14663. * values against any array or object value, respectively. See `_.isEqual`
  14664. * for a list of supported value comparisons.
  14665. *
  14666. * @static
  14667. * @memberOf _
  14668. * @since 3.0.0
  14669. * @category Util
  14670. * @param {Object} source The object of property values to match.
  14671. * @returns {Function} Returns the new spec function.
  14672. * @example
  14673. *
  14674. * var objects = [
  14675. * { 'a': 1, 'b': 2, 'c': 3 },
  14676. * { 'a': 4, 'b': 5, 'c': 6 }
  14677. * ];
  14678. *
  14679. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14680. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14681. */
  14682. function matches(source) {
  14683. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14684. }
  14685. /**
  14686. * Creates a function that performs a partial deep comparison between the
  14687. * value at `path` of a given object to `srcValue`, returning `true` if the
  14688. * object value is equivalent, else `false`.
  14689. *
  14690. * **Note:** Partial comparisons will match empty array and empty object
  14691. * `srcValue` values against any array or object value, respectively. See
  14692. * `_.isEqual` for a list of supported value comparisons.
  14693. *
  14694. * @static
  14695. * @memberOf _
  14696. * @since 3.2.0
  14697. * @category Util
  14698. * @param {Array|string} path The path of the property to get.
  14699. * @param {*} srcValue The value to match.
  14700. * @returns {Function} Returns the new spec function.
  14701. * @example
  14702. *
  14703. * var objects = [
  14704. * { 'a': 1, 'b': 2, 'c': 3 },
  14705. * { 'a': 4, 'b': 5, 'c': 6 }
  14706. * ];
  14707. *
  14708. * _.find(objects, _.matchesProperty('a', 4));
  14709. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14710. */
  14711. function matchesProperty(path, srcValue) {
  14712. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14713. }
  14714. /**
  14715. * Creates a function that invokes the method at `path` of a given object.
  14716. * Any additional arguments are provided to the invoked method.
  14717. *
  14718. * @static
  14719. * @memberOf _
  14720. * @since 3.7.0
  14721. * @category Util
  14722. * @param {Array|string} path The path of the method to invoke.
  14723. * @param {...*} [args] The arguments to invoke the method with.
  14724. * @returns {Function} Returns the new invoker function.
  14725. * @example
  14726. *
  14727. * var objects = [
  14728. * { 'a': { 'b': _.constant(2) } },
  14729. * { 'a': { 'b': _.constant(1) } }
  14730. * ];
  14731. *
  14732. * _.map(objects, _.method('a.b'));
  14733. * // => [2, 1]
  14734. *
  14735. * _.map(objects, _.method(['a', 'b']));
  14736. * // => [2, 1]
  14737. */
  14738. var method = baseRest(function(path, args) {
  14739. return function(object) {
  14740. return baseInvoke(object, path, args);
  14741. };
  14742. });
  14743. /**
  14744. * The opposite of `_.method`; this method creates a function that invokes
  14745. * the method at a given path of `object`. Any additional arguments are
  14746. * provided to the invoked method.
  14747. *
  14748. * @static
  14749. * @memberOf _
  14750. * @since 3.7.0
  14751. * @category Util
  14752. * @param {Object} object The object to query.
  14753. * @param {...*} [args] The arguments to invoke the method with.
  14754. * @returns {Function} Returns the new invoker function.
  14755. * @example
  14756. *
  14757. * var array = _.times(3, _.constant),
  14758. * object = { 'a': array, 'b': array, 'c': array };
  14759. *
  14760. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14761. * // => [2, 0]
  14762. *
  14763. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14764. * // => [2, 0]
  14765. */
  14766. var methodOf = baseRest(function(object, args) {
  14767. return function(path) {
  14768. return baseInvoke(object, path, args);
  14769. };
  14770. });
  14771. /**
  14772. * Adds all own enumerable string keyed function properties of a source
  14773. * object to the destination object. If `object` is a function, then methods
  14774. * are added to its prototype as well.
  14775. *
  14776. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14777. * avoid conflicts caused by modifying the original.
  14778. *
  14779. * @static
  14780. * @since 0.1.0
  14781. * @memberOf _
  14782. * @category Util
  14783. * @param {Function|Object} [object=lodash] The destination object.
  14784. * @param {Object} source The object of functions to add.
  14785. * @param {Object} [options={}] The options object.
  14786. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14787. * @returns {Function|Object} Returns `object`.
  14788. * @example
  14789. *
  14790. * function vowels(string) {
  14791. * return _.filter(string, function(v) {
  14792. * return /[aeiou]/i.test(v);
  14793. * });
  14794. * }
  14795. *
  14796. * _.mixin({ 'vowels': vowels });
  14797. * _.vowels('fred');
  14798. * // => ['e']
  14799. *
  14800. * _('fred').vowels().value();
  14801. * // => ['e']
  14802. *
  14803. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14804. * _('fred').vowels();
  14805. * // => ['e']
  14806. */
  14807. function mixin(object, source, options) {
  14808. var props = keys(source),
  14809. methodNames = baseFunctions(source, props);
  14810. if (options == null &&
  14811. !(isObject(source) && (methodNames.length || !props.length))) {
  14812. options = source;
  14813. source = object;
  14814. object = this;
  14815. methodNames = baseFunctions(source, keys(source));
  14816. }
  14817. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14818. isFunc = isFunction(object);
  14819. arrayEach(methodNames, function(methodName) {
  14820. var func = source[methodName];
  14821. object[methodName] = func;
  14822. if (isFunc) {
  14823. object.prototype[methodName] = function() {
  14824. var chainAll = this.__chain__;
  14825. if (chain || chainAll) {
  14826. var result = object(this.__wrapped__),
  14827. actions = result.__actions__ = copyArray(this.__actions__);
  14828. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14829. result.__chain__ = chainAll;
  14830. return result;
  14831. }
  14832. return func.apply(object, arrayPush([this.value()], arguments));
  14833. };
  14834. }
  14835. });
  14836. return object;
  14837. }
  14838. /**
  14839. * Reverts the `_` variable to its previous value and returns a reference to
  14840. * the `lodash` function.
  14841. *
  14842. * @static
  14843. * @since 0.1.0
  14844. * @memberOf _
  14845. * @category Util
  14846. * @returns {Function} Returns the `lodash` function.
  14847. * @example
  14848. *
  14849. * var lodash = _.noConflict();
  14850. */
  14851. function noConflict() {
  14852. if (root._ === this) {
  14853. root._ = oldDash;
  14854. }
  14855. return this;
  14856. }
  14857. /**
  14858. * This method returns `undefined`.
  14859. *
  14860. * @static
  14861. * @memberOf _
  14862. * @since 2.3.0
  14863. * @category Util
  14864. * @example
  14865. *
  14866. * _.times(2, _.noop);
  14867. * // => [undefined, undefined]
  14868. */
  14869. function noop() {
  14870. // No operation performed.
  14871. }
  14872. /**
  14873. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14874. * the nth argument from the end is returned.
  14875. *
  14876. * @static
  14877. * @memberOf _
  14878. * @since 4.0.0
  14879. * @category Util
  14880. * @param {number} [n=0] The index of the argument to return.
  14881. * @returns {Function} Returns the new pass-thru function.
  14882. * @example
  14883. *
  14884. * var func = _.nthArg(1);
  14885. * func('a', 'b', 'c', 'd');
  14886. * // => 'b'
  14887. *
  14888. * var func = _.nthArg(-2);
  14889. * func('a', 'b', 'c', 'd');
  14890. * // => 'c'
  14891. */
  14892. function nthArg(n) {
  14893. n = toInteger(n);
  14894. return baseRest(function(args) {
  14895. return baseNth(args, n);
  14896. });
  14897. }
  14898. /**
  14899. * Creates a function that invokes `iteratees` with the arguments it receives
  14900. * and returns their results.
  14901. *
  14902. * @static
  14903. * @memberOf _
  14904. * @since 4.0.0
  14905. * @category Util
  14906. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14907. * The iteratees to invoke.
  14908. * @returns {Function} Returns the new function.
  14909. * @example
  14910. *
  14911. * var func = _.over([Math.max, Math.min]);
  14912. *
  14913. * func(1, 2, 3, 4);
  14914. * // => [4, 1]
  14915. */
  14916. var over = createOver(arrayMap);
  14917. /**
  14918. * Creates a function that checks if **all** of the `predicates` return
  14919. * truthy when invoked with the arguments it receives.
  14920. *
  14921. * @static
  14922. * @memberOf _
  14923. * @since 4.0.0
  14924. * @category Util
  14925. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14926. * The predicates to check.
  14927. * @returns {Function} Returns the new function.
  14928. * @example
  14929. *
  14930. * var func = _.overEvery([Boolean, isFinite]);
  14931. *
  14932. * func('1');
  14933. * // => true
  14934. *
  14935. * func(null);
  14936. * // => false
  14937. *
  14938. * func(NaN);
  14939. * // => false
  14940. */
  14941. var overEvery = createOver(arrayEvery);
  14942. /**
  14943. * Creates a function that checks if **any** of the `predicates` return
  14944. * truthy when invoked with the arguments it receives.
  14945. *
  14946. * @static
  14947. * @memberOf _
  14948. * @since 4.0.0
  14949. * @category Util
  14950. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14951. * The predicates to check.
  14952. * @returns {Function} Returns the new function.
  14953. * @example
  14954. *
  14955. * var func = _.overSome([Boolean, isFinite]);
  14956. *
  14957. * func('1');
  14958. * // => true
  14959. *
  14960. * func(null);
  14961. * // => true
  14962. *
  14963. * func(NaN);
  14964. * // => false
  14965. */
  14966. var overSome = createOver(arraySome);
  14967. /**
  14968. * Creates a function that returns the value at `path` of a given object.
  14969. *
  14970. * @static
  14971. * @memberOf _
  14972. * @since 2.4.0
  14973. * @category Util
  14974. * @param {Array|string} path The path of the property to get.
  14975. * @returns {Function} Returns the new accessor function.
  14976. * @example
  14977. *
  14978. * var objects = [
  14979. * { 'a': { 'b': 2 } },
  14980. * { 'a': { 'b': 1 } }
  14981. * ];
  14982. *
  14983. * _.map(objects, _.property('a.b'));
  14984. * // => [2, 1]
  14985. *
  14986. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  14987. * // => [1, 2]
  14988. */
  14989. function property(path) {
  14990. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  14991. }
  14992. /**
  14993. * The opposite of `_.property`; this method creates a function that returns
  14994. * the value at a given path of `object`.
  14995. *
  14996. * @static
  14997. * @memberOf _
  14998. * @since 3.0.0
  14999. * @category Util
  15000. * @param {Object} object The object to query.
  15001. * @returns {Function} Returns the new accessor function.
  15002. * @example
  15003. *
  15004. * var array = [0, 1, 2],
  15005. * object = { 'a': array, 'b': array, 'c': array };
  15006. *
  15007. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  15008. * // => [2, 0]
  15009. *
  15010. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  15011. * // => [2, 0]
  15012. */
  15013. function propertyOf(object) {
  15014. return function(path) {
  15015. return object == null ? undefined : baseGet(object, path);
  15016. };
  15017. }
  15018. /**
  15019. * Creates an array of numbers (positive and/or negative) progressing from
  15020. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  15021. * `start` is specified without an `end` or `step`. If `end` is not specified,
  15022. * it's set to `start` with `start` then set to `0`.
  15023. *
  15024. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  15025. * floating-point values which can produce unexpected results.
  15026. *
  15027. * @static
  15028. * @since 0.1.0
  15029. * @memberOf _
  15030. * @category Util
  15031. * @param {number} [start=0] The start of the range.
  15032. * @param {number} end The end of the range.
  15033. * @param {number} [step=1] The value to increment or decrement by.
  15034. * @returns {Array} Returns the range of numbers.
  15035. * @see _.inRange, _.rangeRight
  15036. * @example
  15037. *
  15038. * _.range(4);
  15039. * // => [0, 1, 2, 3]
  15040. *
  15041. * _.range(-4);
  15042. * // => [0, -1, -2, -3]
  15043. *
  15044. * _.range(1, 5);
  15045. * // => [1, 2, 3, 4]
  15046. *
  15047. * _.range(0, 20, 5);
  15048. * // => [0, 5, 10, 15]
  15049. *
  15050. * _.range(0, -4, -1);
  15051. * // => [0, -1, -2, -3]
  15052. *
  15053. * _.range(1, 4, 0);
  15054. * // => [1, 1, 1]
  15055. *
  15056. * _.range(0);
  15057. * // => []
  15058. */
  15059. var range = createRange();
  15060. /**
  15061. * This method is like `_.range` except that it populates values in
  15062. * descending order.
  15063. *
  15064. * @static
  15065. * @memberOf _
  15066. * @since 4.0.0
  15067. * @category Util
  15068. * @param {number} [start=0] The start of the range.
  15069. * @param {number} end The end of the range.
  15070. * @param {number} [step=1] The value to increment or decrement by.
  15071. * @returns {Array} Returns the range of numbers.
  15072. * @see _.inRange, _.range
  15073. * @example
  15074. *
  15075. * _.rangeRight(4);
  15076. * // => [3, 2, 1, 0]
  15077. *
  15078. * _.rangeRight(-4);
  15079. * // => [-3, -2, -1, 0]
  15080. *
  15081. * _.rangeRight(1, 5);
  15082. * // => [4, 3, 2, 1]
  15083. *
  15084. * _.rangeRight(0, 20, 5);
  15085. * // => [15, 10, 5, 0]
  15086. *
  15087. * _.rangeRight(0, -4, -1);
  15088. * // => [-3, -2, -1, 0]
  15089. *
  15090. * _.rangeRight(1, 4, 0);
  15091. * // => [1, 1, 1]
  15092. *
  15093. * _.rangeRight(0);
  15094. * // => []
  15095. */
  15096. var rangeRight = createRange(true);
  15097. /**
  15098. * This method returns a new empty array.
  15099. *
  15100. * @static
  15101. * @memberOf _
  15102. * @since 4.13.0
  15103. * @category Util
  15104. * @returns {Array} Returns the new empty array.
  15105. * @example
  15106. *
  15107. * var arrays = _.times(2, _.stubArray);
  15108. *
  15109. * console.log(arrays);
  15110. * // => [[], []]
  15111. *
  15112. * console.log(arrays[0] === arrays[1]);
  15113. * // => false
  15114. */
  15115. function stubArray() {
  15116. return [];
  15117. }
  15118. /**
  15119. * This method returns `false`.
  15120. *
  15121. * @static
  15122. * @memberOf _
  15123. * @since 4.13.0
  15124. * @category Util
  15125. * @returns {boolean} Returns `false`.
  15126. * @example
  15127. *
  15128. * _.times(2, _.stubFalse);
  15129. * // => [false, false]
  15130. */
  15131. function stubFalse() {
  15132. return false;
  15133. }
  15134. /**
  15135. * This method returns a new empty object.
  15136. *
  15137. * @static
  15138. * @memberOf _
  15139. * @since 4.13.0
  15140. * @category Util
  15141. * @returns {Object} Returns the new empty object.
  15142. * @example
  15143. *
  15144. * var objects = _.times(2, _.stubObject);
  15145. *
  15146. * console.log(objects);
  15147. * // => [{}, {}]
  15148. *
  15149. * console.log(objects[0] === objects[1]);
  15150. * // => false
  15151. */
  15152. function stubObject() {
  15153. return {};
  15154. }
  15155. /**
  15156. * This method returns an empty string.
  15157. *
  15158. * @static
  15159. * @memberOf _
  15160. * @since 4.13.0
  15161. * @category Util
  15162. * @returns {string} Returns the empty string.
  15163. * @example
  15164. *
  15165. * _.times(2, _.stubString);
  15166. * // => ['', '']
  15167. */
  15168. function stubString() {
  15169. return '';
  15170. }
  15171. /**
  15172. * This method returns `true`.
  15173. *
  15174. * @static
  15175. * @memberOf _
  15176. * @since 4.13.0
  15177. * @category Util
  15178. * @returns {boolean} Returns `true`.
  15179. * @example
  15180. *
  15181. * _.times(2, _.stubTrue);
  15182. * // => [true, true]
  15183. */
  15184. function stubTrue() {
  15185. return true;
  15186. }
  15187. /**
  15188. * Invokes the iteratee `n` times, returning an array of the results of
  15189. * each invocation. The iteratee is invoked with one argument; (index).
  15190. *
  15191. * @static
  15192. * @since 0.1.0
  15193. * @memberOf _
  15194. * @category Util
  15195. * @param {number} n The number of times to invoke `iteratee`.
  15196. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15197. * @returns {Array} Returns the array of results.
  15198. * @example
  15199. *
  15200. * _.times(3, String);
  15201. * // => ['0', '1', '2']
  15202. *
  15203. * _.times(4, _.constant(0));
  15204. * // => [0, 0, 0, 0]
  15205. */
  15206. function times(n, iteratee) {
  15207. n = toInteger(n);
  15208. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15209. return [];
  15210. }
  15211. var index = MAX_ARRAY_LENGTH,
  15212. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15213. iteratee = getIteratee(iteratee);
  15214. n -= MAX_ARRAY_LENGTH;
  15215. var result = baseTimes(length, iteratee);
  15216. while (++index < n) {
  15217. iteratee(index);
  15218. }
  15219. return result;
  15220. }
  15221. /**
  15222. * Converts `value` to a property path array.
  15223. *
  15224. * @static
  15225. * @memberOf _
  15226. * @since 4.0.0
  15227. * @category Util
  15228. * @param {*} value The value to convert.
  15229. * @returns {Array} Returns the new property path array.
  15230. * @example
  15231. *
  15232. * _.toPath('a.b.c');
  15233. * // => ['a', 'b', 'c']
  15234. *
  15235. * _.toPath('a[0].b.c');
  15236. * // => ['a', '0', 'b', 'c']
  15237. */
  15238. function toPath(value) {
  15239. if (isArray(value)) {
  15240. return arrayMap(value, toKey);
  15241. }
  15242. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15243. }
  15244. /**
  15245. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15246. *
  15247. * @static
  15248. * @since 0.1.0
  15249. * @memberOf _
  15250. * @category Util
  15251. * @param {string} [prefix=''] The value to prefix the ID with.
  15252. * @returns {string} Returns the unique ID.
  15253. * @example
  15254. *
  15255. * _.uniqueId('contact_');
  15256. * // => 'contact_104'
  15257. *
  15258. * _.uniqueId();
  15259. * // => '105'
  15260. */
  15261. function uniqueId(prefix) {
  15262. var id = ++idCounter;
  15263. return toString(prefix) + id;
  15264. }
  15265. /*------------------------------------------------------------------------*/
  15266. /**
  15267. * Adds two numbers.
  15268. *
  15269. * @static
  15270. * @memberOf _
  15271. * @since 3.4.0
  15272. * @category Math
  15273. * @param {number} augend The first number in an addition.
  15274. * @param {number} addend The second number in an addition.
  15275. * @returns {number} Returns the total.
  15276. * @example
  15277. *
  15278. * _.add(6, 4);
  15279. * // => 10
  15280. */
  15281. var add = createMathOperation(function(augend, addend) {
  15282. return augend + addend;
  15283. }, 0);
  15284. /**
  15285. * Computes `number` rounded up to `precision`.
  15286. *
  15287. * @static
  15288. * @memberOf _
  15289. * @since 3.10.0
  15290. * @category Math
  15291. * @param {number} number The number to round up.
  15292. * @param {number} [precision=0] The precision to round up to.
  15293. * @returns {number} Returns the rounded up number.
  15294. * @example
  15295. *
  15296. * _.ceil(4.006);
  15297. * // => 5
  15298. *
  15299. * _.ceil(6.004, 2);
  15300. * // => 6.01
  15301. *
  15302. * _.ceil(6040, -2);
  15303. * // => 6100
  15304. */
  15305. var ceil = createRound('ceil');
  15306. /**
  15307. * Divide two numbers.
  15308. *
  15309. * @static
  15310. * @memberOf _
  15311. * @since 4.7.0
  15312. * @category Math
  15313. * @param {number} dividend The first number in a division.
  15314. * @param {number} divisor The second number in a division.
  15315. * @returns {number} Returns the quotient.
  15316. * @example
  15317. *
  15318. * _.divide(6, 4);
  15319. * // => 1.5
  15320. */
  15321. var divide = createMathOperation(function(dividend, divisor) {
  15322. return dividend / divisor;
  15323. }, 1);
  15324. /**
  15325. * Computes `number` rounded down to `precision`.
  15326. *
  15327. * @static
  15328. * @memberOf _
  15329. * @since 3.10.0
  15330. * @category Math
  15331. * @param {number} number The number to round down.
  15332. * @param {number} [precision=0] The precision to round down to.
  15333. * @returns {number} Returns the rounded down number.
  15334. * @example
  15335. *
  15336. * _.floor(4.006);
  15337. * // => 4
  15338. *
  15339. * _.floor(0.046, 2);
  15340. * // => 0.04
  15341. *
  15342. * _.floor(4060, -2);
  15343. * // => 4000
  15344. */
  15345. var floor = createRound('floor');
  15346. /**
  15347. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15348. * `undefined` is returned.
  15349. *
  15350. * @static
  15351. * @since 0.1.0
  15352. * @memberOf _
  15353. * @category Math
  15354. * @param {Array} array The array to iterate over.
  15355. * @returns {*} Returns the maximum value.
  15356. * @example
  15357. *
  15358. * _.max([4, 2, 8, 6]);
  15359. * // => 8
  15360. *
  15361. * _.max([]);
  15362. * // => undefined
  15363. */
  15364. function max(array) {
  15365. return (array && array.length)
  15366. ? baseExtremum(array, identity, baseGt)
  15367. : undefined;
  15368. }
  15369. /**
  15370. * This method is like `_.max` except that it accepts `iteratee` which is
  15371. * invoked for each element in `array` to generate the criterion by which
  15372. * the value is ranked. The iteratee is invoked with one argument: (value).
  15373. *
  15374. * @static
  15375. * @memberOf _
  15376. * @since 4.0.0
  15377. * @category Math
  15378. * @param {Array} array The array to iterate over.
  15379. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15380. * @returns {*} Returns the maximum value.
  15381. * @example
  15382. *
  15383. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15384. *
  15385. * _.maxBy(objects, function(o) { return o.n; });
  15386. * // => { 'n': 2 }
  15387. *
  15388. * // The `_.property` iteratee shorthand.
  15389. * _.maxBy(objects, 'n');
  15390. * // => { 'n': 2 }
  15391. */
  15392. function maxBy(array, iteratee) {
  15393. return (array && array.length)
  15394. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15395. : undefined;
  15396. }
  15397. /**
  15398. * Computes the mean of the values in `array`.
  15399. *
  15400. * @static
  15401. * @memberOf _
  15402. * @since 4.0.0
  15403. * @category Math
  15404. * @param {Array} array The array to iterate over.
  15405. * @returns {number} Returns the mean.
  15406. * @example
  15407. *
  15408. * _.mean([4, 2, 8, 6]);
  15409. * // => 5
  15410. */
  15411. function mean(array) {
  15412. return baseMean(array, identity);
  15413. }
  15414. /**
  15415. * This method is like `_.mean` except that it accepts `iteratee` which is
  15416. * invoked for each element in `array` to generate the value to be averaged.
  15417. * The iteratee is invoked with one argument: (value).
  15418. *
  15419. * @static
  15420. * @memberOf _
  15421. * @since 4.7.0
  15422. * @category Math
  15423. * @param {Array} array The array to iterate over.
  15424. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15425. * @returns {number} Returns the mean.
  15426. * @example
  15427. *
  15428. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15429. *
  15430. * _.meanBy(objects, function(o) { return o.n; });
  15431. * // => 5
  15432. *
  15433. * // The `_.property` iteratee shorthand.
  15434. * _.meanBy(objects, 'n');
  15435. * // => 5
  15436. */
  15437. function meanBy(array, iteratee) {
  15438. return baseMean(array, getIteratee(iteratee, 2));
  15439. }
  15440. /**
  15441. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15442. * `undefined` is returned.
  15443. *
  15444. * @static
  15445. * @since 0.1.0
  15446. * @memberOf _
  15447. * @category Math
  15448. * @param {Array} array The array to iterate over.
  15449. * @returns {*} Returns the minimum value.
  15450. * @example
  15451. *
  15452. * _.min([4, 2, 8, 6]);
  15453. * // => 2
  15454. *
  15455. * _.min([]);
  15456. * // => undefined
  15457. */
  15458. function min(array) {
  15459. return (array && array.length)
  15460. ? baseExtremum(array, identity, baseLt)
  15461. : undefined;
  15462. }
  15463. /**
  15464. * This method is like `_.min` except that it accepts `iteratee` which is
  15465. * invoked for each element in `array` to generate the criterion by which
  15466. * the value is ranked. The iteratee is invoked with one argument: (value).
  15467. *
  15468. * @static
  15469. * @memberOf _
  15470. * @since 4.0.0
  15471. * @category Math
  15472. * @param {Array} array The array to iterate over.
  15473. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15474. * @returns {*} Returns the minimum value.
  15475. * @example
  15476. *
  15477. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15478. *
  15479. * _.minBy(objects, function(o) { return o.n; });
  15480. * // => { 'n': 1 }
  15481. *
  15482. * // The `_.property` iteratee shorthand.
  15483. * _.minBy(objects, 'n');
  15484. * // => { 'n': 1 }
  15485. */
  15486. function minBy(array, iteratee) {
  15487. return (array && array.length)
  15488. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15489. : undefined;
  15490. }
  15491. /**
  15492. * Multiply two numbers.
  15493. *
  15494. * @static
  15495. * @memberOf _
  15496. * @since 4.7.0
  15497. * @category Math
  15498. * @param {number} multiplier The first number in a multiplication.
  15499. * @param {number} multiplicand The second number in a multiplication.
  15500. * @returns {number} Returns the product.
  15501. * @example
  15502. *
  15503. * _.multiply(6, 4);
  15504. * // => 24
  15505. */
  15506. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15507. return multiplier * multiplicand;
  15508. }, 1);
  15509. /**
  15510. * Computes `number` rounded to `precision`.
  15511. *
  15512. * @static
  15513. * @memberOf _
  15514. * @since 3.10.0
  15515. * @category Math
  15516. * @param {number} number The number to round.
  15517. * @param {number} [precision=0] The precision to round to.
  15518. * @returns {number} Returns the rounded number.
  15519. * @example
  15520. *
  15521. * _.round(4.006);
  15522. * // => 4
  15523. *
  15524. * _.round(4.006, 2);
  15525. * // => 4.01
  15526. *
  15527. * _.round(4060, -2);
  15528. * // => 4100
  15529. */
  15530. var round = createRound('round');
  15531. /**
  15532. * Subtract two numbers.
  15533. *
  15534. * @static
  15535. * @memberOf _
  15536. * @since 4.0.0
  15537. * @category Math
  15538. * @param {number} minuend The first number in a subtraction.
  15539. * @param {number} subtrahend The second number in a subtraction.
  15540. * @returns {number} Returns the difference.
  15541. * @example
  15542. *
  15543. * _.subtract(6, 4);
  15544. * // => 2
  15545. */
  15546. var subtract = createMathOperation(function(minuend, subtrahend) {
  15547. return minuend - subtrahend;
  15548. }, 0);
  15549. /**
  15550. * Computes the sum of the values in `array`.
  15551. *
  15552. * @static
  15553. * @memberOf _
  15554. * @since 3.4.0
  15555. * @category Math
  15556. * @param {Array} array The array to iterate over.
  15557. * @returns {number} Returns the sum.
  15558. * @example
  15559. *
  15560. * _.sum([4, 2, 8, 6]);
  15561. * // => 20
  15562. */
  15563. function sum(array) {
  15564. return (array && array.length)
  15565. ? baseSum(array, identity)
  15566. : 0;
  15567. }
  15568. /**
  15569. * This method is like `_.sum` except that it accepts `iteratee` which is
  15570. * invoked for each element in `array` to generate the value to be summed.
  15571. * The iteratee is invoked with one argument: (value).
  15572. *
  15573. * @static
  15574. * @memberOf _
  15575. * @since 4.0.0
  15576. * @category Math
  15577. * @param {Array} array The array to iterate over.
  15578. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15579. * @returns {number} Returns the sum.
  15580. * @example
  15581. *
  15582. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15583. *
  15584. * _.sumBy(objects, function(o) { return o.n; });
  15585. * // => 20
  15586. *
  15587. * // The `_.property` iteratee shorthand.
  15588. * _.sumBy(objects, 'n');
  15589. * // => 20
  15590. */
  15591. function sumBy(array, iteratee) {
  15592. return (array && array.length)
  15593. ? baseSum(array, getIteratee(iteratee, 2))
  15594. : 0;
  15595. }
  15596. /*------------------------------------------------------------------------*/
  15597. // Add methods that return wrapped values in chain sequences.
  15598. lodash.after = after;
  15599. lodash.ary = ary;
  15600. lodash.assign = assign;
  15601. lodash.assignIn = assignIn;
  15602. lodash.assignInWith = assignInWith;
  15603. lodash.assignWith = assignWith;
  15604. lodash.at = at;
  15605. lodash.before = before;
  15606. lodash.bind = bind;
  15607. lodash.bindAll = bindAll;
  15608. lodash.bindKey = bindKey;
  15609. lodash.castArray = castArray;
  15610. lodash.chain = chain;
  15611. lodash.chunk = chunk;
  15612. lodash.compact = compact;
  15613. lodash.concat = concat;
  15614. lodash.cond = cond;
  15615. lodash.conforms = conforms;
  15616. lodash.constant = constant;
  15617. lodash.countBy = countBy;
  15618. lodash.create = create;
  15619. lodash.curry = curry;
  15620. lodash.curryRight = curryRight;
  15621. lodash.debounce = debounce;
  15622. lodash.defaults = defaults;
  15623. lodash.defaultsDeep = defaultsDeep;
  15624. lodash.defer = defer;
  15625. lodash.delay = delay;
  15626. lodash.difference = difference;
  15627. lodash.differenceBy = differenceBy;
  15628. lodash.differenceWith = differenceWith;
  15629. lodash.drop = drop;
  15630. lodash.dropRight = dropRight;
  15631. lodash.dropRightWhile = dropRightWhile;
  15632. lodash.dropWhile = dropWhile;
  15633. lodash.fill = fill;
  15634. lodash.filter = filter;
  15635. lodash.flatMap = flatMap;
  15636. lodash.flatMapDeep = flatMapDeep;
  15637. lodash.flatMapDepth = flatMapDepth;
  15638. lodash.flatten = flatten;
  15639. lodash.flattenDeep = flattenDeep;
  15640. lodash.flattenDepth = flattenDepth;
  15641. lodash.flip = flip;
  15642. lodash.flow = flow;
  15643. lodash.flowRight = flowRight;
  15644. lodash.fromPairs = fromPairs;
  15645. lodash.functions = functions;
  15646. lodash.functionsIn = functionsIn;
  15647. lodash.groupBy = groupBy;
  15648. lodash.initial = initial;
  15649. lodash.intersection = intersection;
  15650. lodash.intersectionBy = intersectionBy;
  15651. lodash.intersectionWith = intersectionWith;
  15652. lodash.invert = invert;
  15653. lodash.invertBy = invertBy;
  15654. lodash.invokeMap = invokeMap;
  15655. lodash.iteratee = iteratee;
  15656. lodash.keyBy = keyBy;
  15657. lodash.keys = keys;
  15658. lodash.keysIn = keysIn;
  15659. lodash.map = map;
  15660. lodash.mapKeys = mapKeys;
  15661. lodash.mapValues = mapValues;
  15662. lodash.matches = matches;
  15663. lodash.matchesProperty = matchesProperty;
  15664. lodash.memoize = memoize;
  15665. lodash.merge = merge;
  15666. lodash.mergeWith = mergeWith;
  15667. lodash.method = method;
  15668. lodash.methodOf = methodOf;
  15669. lodash.mixin = mixin;
  15670. lodash.negate = negate;
  15671. lodash.nthArg = nthArg;
  15672. lodash.omit = omit;
  15673. lodash.omitBy = omitBy;
  15674. lodash.once = once;
  15675. lodash.orderBy = orderBy;
  15676. lodash.over = over;
  15677. lodash.overArgs = overArgs;
  15678. lodash.overEvery = overEvery;
  15679. lodash.overSome = overSome;
  15680. lodash.partial = partial;
  15681. lodash.partialRight = partialRight;
  15682. lodash.partition = partition;
  15683. lodash.pick = pick;
  15684. lodash.pickBy = pickBy;
  15685. lodash.property = property;
  15686. lodash.propertyOf = propertyOf;
  15687. lodash.pull = pull;
  15688. lodash.pullAll = pullAll;
  15689. lodash.pullAllBy = pullAllBy;
  15690. lodash.pullAllWith = pullAllWith;
  15691. lodash.pullAt = pullAt;
  15692. lodash.range = range;
  15693. lodash.rangeRight = rangeRight;
  15694. lodash.rearg = rearg;
  15695. lodash.reject = reject;
  15696. lodash.remove = remove;
  15697. lodash.rest = rest;
  15698. lodash.reverse = reverse;
  15699. lodash.sampleSize = sampleSize;
  15700. lodash.set = set;
  15701. lodash.setWith = setWith;
  15702. lodash.shuffle = shuffle;
  15703. lodash.slice = slice;
  15704. lodash.sortBy = sortBy;
  15705. lodash.sortedUniq = sortedUniq;
  15706. lodash.sortedUniqBy = sortedUniqBy;
  15707. lodash.split = split;
  15708. lodash.spread = spread;
  15709. lodash.tail = tail;
  15710. lodash.take = take;
  15711. lodash.takeRight = takeRight;
  15712. lodash.takeRightWhile = takeRightWhile;
  15713. lodash.takeWhile = takeWhile;
  15714. lodash.tap = tap;
  15715. lodash.throttle = throttle;
  15716. lodash.thru = thru;
  15717. lodash.toArray = toArray;
  15718. lodash.toPairs = toPairs;
  15719. lodash.toPairsIn = toPairsIn;
  15720. lodash.toPath = toPath;
  15721. lodash.toPlainObject = toPlainObject;
  15722. lodash.transform = transform;
  15723. lodash.unary = unary;
  15724. lodash.union = union;
  15725. lodash.unionBy = unionBy;
  15726. lodash.unionWith = unionWith;
  15727. lodash.uniq = uniq;
  15728. lodash.uniqBy = uniqBy;
  15729. lodash.uniqWith = uniqWith;
  15730. lodash.unset = unset;
  15731. lodash.unzip = unzip;
  15732. lodash.unzipWith = unzipWith;
  15733. lodash.update = update;
  15734. lodash.updateWith = updateWith;
  15735. lodash.values = values;
  15736. lodash.valuesIn = valuesIn;
  15737. lodash.without = without;
  15738. lodash.words = words;
  15739. lodash.wrap = wrap;
  15740. lodash.xor = xor;
  15741. lodash.xorBy = xorBy;
  15742. lodash.xorWith = xorWith;
  15743. lodash.zip = zip;
  15744. lodash.zipObject = zipObject;
  15745. lodash.zipObjectDeep = zipObjectDeep;
  15746. lodash.zipWith = zipWith;
  15747. // Add aliases.
  15748. lodash.entries = toPairs;
  15749. lodash.entriesIn = toPairsIn;
  15750. lodash.extend = assignIn;
  15751. lodash.extendWith = assignInWith;
  15752. // Add methods to `lodash.prototype`.
  15753. mixin(lodash, lodash);
  15754. /*------------------------------------------------------------------------*/
  15755. // Add methods that return unwrapped values in chain sequences.
  15756. lodash.add = add;
  15757. lodash.attempt = attempt;
  15758. lodash.camelCase = camelCase;
  15759. lodash.capitalize = capitalize;
  15760. lodash.ceil = ceil;
  15761. lodash.clamp = clamp;
  15762. lodash.clone = clone;
  15763. lodash.cloneDeep = cloneDeep;
  15764. lodash.cloneDeepWith = cloneDeepWith;
  15765. lodash.cloneWith = cloneWith;
  15766. lodash.conformsTo = conformsTo;
  15767. lodash.deburr = deburr;
  15768. lodash.defaultTo = defaultTo;
  15769. lodash.divide = divide;
  15770. lodash.endsWith = endsWith;
  15771. lodash.eq = eq;
  15772. lodash.escape = escape;
  15773. lodash.escapeRegExp = escapeRegExp;
  15774. lodash.every = every;
  15775. lodash.find = find;
  15776. lodash.findIndex = findIndex;
  15777. lodash.findKey = findKey;
  15778. lodash.findLast = findLast;
  15779. lodash.findLastIndex = findLastIndex;
  15780. lodash.findLastKey = findLastKey;
  15781. lodash.floor = floor;
  15782. lodash.forEach = forEach;
  15783. lodash.forEachRight = forEachRight;
  15784. lodash.forIn = forIn;
  15785. lodash.forInRight = forInRight;
  15786. lodash.forOwn = forOwn;
  15787. lodash.forOwnRight = forOwnRight;
  15788. lodash.get = get;
  15789. lodash.gt = gt;
  15790. lodash.gte = gte;
  15791. lodash.has = has;
  15792. lodash.hasIn = hasIn;
  15793. lodash.head = head;
  15794. lodash.identity = identity;
  15795. lodash.includes = includes;
  15796. lodash.indexOf = indexOf;
  15797. lodash.inRange = inRange;
  15798. lodash.invoke = invoke;
  15799. lodash.isArguments = isArguments;
  15800. lodash.isArray = isArray;
  15801. lodash.isArrayBuffer = isArrayBuffer;
  15802. lodash.isArrayLike = isArrayLike;
  15803. lodash.isArrayLikeObject = isArrayLikeObject;
  15804. lodash.isBoolean = isBoolean;
  15805. lodash.isBuffer = isBuffer;
  15806. lodash.isDate = isDate;
  15807. lodash.isElement = isElement;
  15808. lodash.isEmpty = isEmpty;
  15809. lodash.isEqual = isEqual;
  15810. lodash.isEqualWith = isEqualWith;
  15811. lodash.isError = isError;
  15812. lodash.isFinite = isFinite;
  15813. lodash.isFunction = isFunction;
  15814. lodash.isInteger = isInteger;
  15815. lodash.isLength = isLength;
  15816. lodash.isMap = isMap;
  15817. lodash.isMatch = isMatch;
  15818. lodash.isMatchWith = isMatchWith;
  15819. lodash.isNaN = isNaN;
  15820. lodash.isNative = isNative;
  15821. lodash.isNil = isNil;
  15822. lodash.isNull = isNull;
  15823. lodash.isNumber = isNumber;
  15824. lodash.isObject = isObject;
  15825. lodash.isObjectLike = isObjectLike;
  15826. lodash.isPlainObject = isPlainObject;
  15827. lodash.isRegExp = isRegExp;
  15828. lodash.isSafeInteger = isSafeInteger;
  15829. lodash.isSet = isSet;
  15830. lodash.isString = isString;
  15831. lodash.isSymbol = isSymbol;
  15832. lodash.isTypedArray = isTypedArray;
  15833. lodash.isUndefined = isUndefined;
  15834. lodash.isWeakMap = isWeakMap;
  15835. lodash.isWeakSet = isWeakSet;
  15836. lodash.join = join;
  15837. lodash.kebabCase = kebabCase;
  15838. lodash.last = last;
  15839. lodash.lastIndexOf = lastIndexOf;
  15840. lodash.lowerCase = lowerCase;
  15841. lodash.lowerFirst = lowerFirst;
  15842. lodash.lt = lt;
  15843. lodash.lte = lte;
  15844. lodash.max = max;
  15845. lodash.maxBy = maxBy;
  15846. lodash.mean = mean;
  15847. lodash.meanBy = meanBy;
  15848. lodash.min = min;
  15849. lodash.minBy = minBy;
  15850. lodash.stubArray = stubArray;
  15851. lodash.stubFalse = stubFalse;
  15852. lodash.stubObject = stubObject;
  15853. lodash.stubString = stubString;
  15854. lodash.stubTrue = stubTrue;
  15855. lodash.multiply = multiply;
  15856. lodash.nth = nth;
  15857. lodash.noConflict = noConflict;
  15858. lodash.noop = noop;
  15859. lodash.now = now;
  15860. lodash.pad = pad;
  15861. lodash.padEnd = padEnd;
  15862. lodash.padStart = padStart;
  15863. lodash.parseInt = parseInt;
  15864. lodash.random = random;
  15865. lodash.reduce = reduce;
  15866. lodash.reduceRight = reduceRight;
  15867. lodash.repeat = repeat;
  15868. lodash.replace = replace;
  15869. lodash.result = result;
  15870. lodash.round = round;
  15871. lodash.runInContext = runInContext;
  15872. lodash.sample = sample;
  15873. lodash.size = size;
  15874. lodash.snakeCase = snakeCase;
  15875. lodash.some = some;
  15876. lodash.sortedIndex = sortedIndex;
  15877. lodash.sortedIndexBy = sortedIndexBy;
  15878. lodash.sortedIndexOf = sortedIndexOf;
  15879. lodash.sortedLastIndex = sortedLastIndex;
  15880. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15881. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15882. lodash.startCase = startCase;
  15883. lodash.startsWith = startsWith;
  15884. lodash.subtract = subtract;
  15885. lodash.sum = sum;
  15886. lodash.sumBy = sumBy;
  15887. lodash.template = template;
  15888. lodash.times = times;
  15889. lodash.toFinite = toFinite;
  15890. lodash.toInteger = toInteger;
  15891. lodash.toLength = toLength;
  15892. lodash.toLower = toLower;
  15893. lodash.toNumber = toNumber;
  15894. lodash.toSafeInteger = toSafeInteger;
  15895. lodash.toString = toString;
  15896. lodash.toUpper = toUpper;
  15897. lodash.trim = trim;
  15898. lodash.trimEnd = trimEnd;
  15899. lodash.trimStart = trimStart;
  15900. lodash.truncate = truncate;
  15901. lodash.unescape = unescape;
  15902. lodash.uniqueId = uniqueId;
  15903. lodash.upperCase = upperCase;
  15904. lodash.upperFirst = upperFirst;
  15905. // Add aliases.
  15906. lodash.each = forEach;
  15907. lodash.eachRight = forEachRight;
  15908. lodash.first = head;
  15909. mixin(lodash, (function() {
  15910. var source = {};
  15911. baseForOwn(lodash, function(func, methodName) {
  15912. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15913. source[methodName] = func;
  15914. }
  15915. });
  15916. return source;
  15917. }()), { 'chain': false });
  15918. /*------------------------------------------------------------------------*/
  15919. /**
  15920. * The semantic version number.
  15921. *
  15922. * @static
  15923. * @memberOf _
  15924. * @type {string}
  15925. */
  15926. lodash.VERSION = VERSION;
  15927. // Assign default placeholders.
  15928. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15929. lodash[methodName].placeholder = lodash;
  15930. });
  15931. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15932. arrayEach(['drop', 'take'], function(methodName, index) {
  15933. LazyWrapper.prototype[methodName] = function(n) {
  15934. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15935. var result = (this.__filtered__ && !index)
  15936. ? new LazyWrapper(this)
  15937. : this.clone();
  15938. if (result.__filtered__) {
  15939. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15940. } else {
  15941. result.__views__.push({
  15942. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15943. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15944. });
  15945. }
  15946. return result;
  15947. };
  15948. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15949. return this.reverse()[methodName](n).reverse();
  15950. };
  15951. });
  15952. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15953. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15954. var type = index + 1,
  15955. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15956. LazyWrapper.prototype[methodName] = function(iteratee) {
  15957. var result = this.clone();
  15958. result.__iteratees__.push({
  15959. 'iteratee': getIteratee(iteratee, 3),
  15960. 'type': type
  15961. });
  15962. result.__filtered__ = result.__filtered__ || isFilter;
  15963. return result;
  15964. };
  15965. });
  15966. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15967. arrayEach(['head', 'last'], function(methodName, index) {
  15968. var takeName = 'take' + (index ? 'Right' : '');
  15969. LazyWrapper.prototype[methodName] = function() {
  15970. return this[takeName](1).value()[0];
  15971. };
  15972. });
  15973. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15974. arrayEach(['initial', 'tail'], function(methodName, index) {
  15975. var dropName = 'drop' + (index ? '' : 'Right');
  15976. LazyWrapper.prototype[methodName] = function() {
  15977. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15978. };
  15979. });
  15980. LazyWrapper.prototype.compact = function() {
  15981. return this.filter(identity);
  15982. };
  15983. LazyWrapper.prototype.find = function(predicate) {
  15984. return this.filter(predicate).head();
  15985. };
  15986. LazyWrapper.prototype.findLast = function(predicate) {
  15987. return this.reverse().find(predicate);
  15988. };
  15989. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  15990. if (typeof path == 'function') {
  15991. return new LazyWrapper(this);
  15992. }
  15993. return this.map(function(value) {
  15994. return baseInvoke(value, path, args);
  15995. });
  15996. });
  15997. LazyWrapper.prototype.reject = function(predicate) {
  15998. return this.filter(negate(getIteratee(predicate)));
  15999. };
  16000. LazyWrapper.prototype.slice = function(start, end) {
  16001. start = toInteger(start);
  16002. var result = this;
  16003. if (result.__filtered__ && (start > 0 || end < 0)) {
  16004. return new LazyWrapper(result);
  16005. }
  16006. if (start < 0) {
  16007. result = result.takeRight(-start);
  16008. } else if (start) {
  16009. result = result.drop(start);
  16010. }
  16011. if (end !== undefined) {
  16012. end = toInteger(end);
  16013. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  16014. }
  16015. return result;
  16016. };
  16017. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  16018. return this.reverse().takeWhile(predicate).reverse();
  16019. };
  16020. LazyWrapper.prototype.toArray = function() {
  16021. return this.take(MAX_ARRAY_LENGTH);
  16022. };
  16023. // Add `LazyWrapper` methods to `lodash.prototype`.
  16024. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16025. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  16026. isTaker = /^(?:head|last)$/.test(methodName),
  16027. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  16028. retUnwrapped = isTaker || /^find/.test(methodName);
  16029. if (!lodashFunc) {
  16030. return;
  16031. }
  16032. lodash.prototype[methodName] = function() {
  16033. var value = this.__wrapped__,
  16034. args = isTaker ? [1] : arguments,
  16035. isLazy = value instanceof LazyWrapper,
  16036. iteratee = args[0],
  16037. useLazy = isLazy || isArray(value);
  16038. var interceptor = function(value) {
  16039. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  16040. return (isTaker && chainAll) ? result[0] : result;
  16041. };
  16042. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  16043. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  16044. isLazy = useLazy = false;
  16045. }
  16046. var chainAll = this.__chain__,
  16047. isHybrid = !!this.__actions__.length,
  16048. isUnwrapped = retUnwrapped && !chainAll,
  16049. onlyLazy = isLazy && !isHybrid;
  16050. if (!retUnwrapped && useLazy) {
  16051. value = onlyLazy ? value : new LazyWrapper(this);
  16052. var result = func.apply(value, args);
  16053. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  16054. return new LodashWrapper(result, chainAll);
  16055. }
  16056. if (isUnwrapped && onlyLazy) {
  16057. return func.apply(this, args);
  16058. }
  16059. result = this.thru(interceptor);
  16060. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  16061. };
  16062. });
  16063. // Add `Array` methods to `lodash.prototype`.
  16064. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  16065. var func = arrayProto[methodName],
  16066. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  16067. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  16068. lodash.prototype[methodName] = function() {
  16069. var args = arguments;
  16070. if (retUnwrapped && !this.__chain__) {
  16071. var value = this.value();
  16072. return func.apply(isArray(value) ? value : [], args);
  16073. }
  16074. return this[chainName](function(value) {
  16075. return func.apply(isArray(value) ? value : [], args);
  16076. });
  16077. };
  16078. });
  16079. // Map minified method names to their real names.
  16080. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16081. var lodashFunc = lodash[methodName];
  16082. if (lodashFunc) {
  16083. var key = (lodashFunc.name + ''),
  16084. names = realNames[key] || (realNames[key] = []);
  16085. names.push({ 'name': methodName, 'func': lodashFunc });
  16086. }
  16087. });
  16088. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  16089. 'name': 'wrapper',
  16090. 'func': undefined
  16091. }];
  16092. // Add methods to `LazyWrapper`.
  16093. LazyWrapper.prototype.clone = lazyClone;
  16094. LazyWrapper.prototype.reverse = lazyReverse;
  16095. LazyWrapper.prototype.value = lazyValue;
  16096. // Add chain sequence methods to the `lodash` wrapper.
  16097. lodash.prototype.at = wrapperAt;
  16098. lodash.prototype.chain = wrapperChain;
  16099. lodash.prototype.commit = wrapperCommit;
  16100. lodash.prototype.next = wrapperNext;
  16101. lodash.prototype.plant = wrapperPlant;
  16102. lodash.prototype.reverse = wrapperReverse;
  16103. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16104. // Add lazy aliases.
  16105. lodash.prototype.first = lodash.prototype.head;
  16106. if (symIterator) {
  16107. lodash.prototype[symIterator] = wrapperToIterator;
  16108. }
  16109. return lodash;
  16110. });
  16111. /*--------------------------------------------------------------------------*/
  16112. // Export lodash.
  16113. var _ = runInContext();
  16114. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16115. if (true) {
  16116. // Expose Lodash on the global object to prevent errors when Lodash is
  16117. // loaded by a script tag in the presence of an AMD loader.
  16118. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16119. // Use `_.noConflict` to remove Lodash from the global object.
  16120. root._ = _;
  16121. // Define as an anonymous module so, through path mapping, it can be
  16122. // referenced as the "underscore" module.
  16123. !(__WEBPACK_AMD_DEFINE_RESULT__ = (function() {
  16124. return _;
  16125. }).call(exports, __webpack_require__, exports, module),
  16126. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  16127. }
  16128. // Check for `exports` after `define` in case a build optimizer adds it.
  16129. else if (freeModule) {
  16130. // Export for Node.js.
  16131. (freeModule.exports = _)._ = _;
  16132. // Export for CommonJS support.
  16133. freeExports._ = _;
  16134. }
  16135. else {
  16136. // Export to the global object.
  16137. root._ = _;
  16138. }
  16139. }.call(this));
  16140. /* WEBPACK VAR INJECTION */}.call(exports, __webpack_require__(2), __webpack_require__(3)(module)))
  16141. /***/ }),
  16142. /* 2 */
  16143. /***/ (function(module, exports) {
  16144. var g;
  16145. // This works in non-strict mode
  16146. g = (function() {
  16147. return this;
  16148. })();
  16149. try {
  16150. // This works if eval is allowed (see CSP)
  16151. g = g || Function("return this")() || (1,eval)("this");
  16152. } catch(e) {
  16153. // This works if the window reference is available
  16154. if(typeof window === "object")
  16155. g = window;
  16156. }
  16157. // g can still be undefined, but nothing to do about it...
  16158. // We return undefined, instead of nothing here, so it's
  16159. // easier to handle this case. if(!global) { ...}
  16160. module.exports = g;
  16161. /***/ }),
  16162. /* 3 */
  16163. /***/ (function(module, exports) {
  16164. module.exports = function(module) {
  16165. if(!module.webpackPolyfill) {
  16166. module.deprecate = function() {};
  16167. module.paths = [];
  16168. // module.parent = undefined by default
  16169. if(!module.children) module.children = [];
  16170. Object.defineProperty(module, "loaded", {
  16171. enumerable: true,
  16172. get: function() {
  16173. return module.l;
  16174. }
  16175. });
  16176. Object.defineProperty(module, "id", {
  16177. enumerable: true,
  16178. get: function() {
  16179. return module.i;
  16180. }
  16181. });
  16182. module.webpackPolyfill = 1;
  16183. }
  16184. return module;
  16185. };
  16186. /***/ })
  16187. /******/ ]);