lodash.js 410 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557
  1. /**
  2. * @license
  3. * lodash 3.10.1 (Custom Build) <https://lodash.com/>
  4. * Build: `lodash compat -o ./lodash.js`
  5. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  6. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  7. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  8. * Available under MIT license <https://lodash.com/license>
  9. */
  10. ;(function() {
  11. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  12. var undefined;
  13. /** Used as the semantic version number. */
  14. var VERSION = '3.10.1';
  15. /** Used to compose bitmasks for wrapper metadata. */
  16. var BIND_FLAG = 1,
  17. BIND_KEY_FLAG = 2,
  18. CURRY_BOUND_FLAG = 4,
  19. CURRY_FLAG = 8,
  20. CURRY_RIGHT_FLAG = 16,
  21. PARTIAL_FLAG = 32,
  22. PARTIAL_RIGHT_FLAG = 64,
  23. ARY_FLAG = 128,
  24. REARG_FLAG = 256;
  25. /** Used as default options for `_.trunc`. */
  26. var DEFAULT_TRUNC_LENGTH = 30,
  27. DEFAULT_TRUNC_OMISSION = '...';
  28. /** Used to detect when a function becomes hot. */
  29. var HOT_COUNT = 150,
  30. HOT_SPAN = 16;
  31. /** Used as the size to enable large array optimizations. */
  32. var LARGE_ARRAY_SIZE = 200;
  33. /** Used to indicate the type of lazy iteratees. */
  34. var LAZY_FILTER_FLAG = 1,
  35. LAZY_MAP_FLAG = 2;
  36. /** Used as the `TypeError` message for "Functions" methods. */
  37. var FUNC_ERROR_TEXT = 'Expected a function';
  38. /** Used as the internal argument placeholder. */
  39. var PLACEHOLDER = '__lodash_placeholder__';
  40. /** `Object#toString` result references. */
  41. var argsTag = '[object Arguments]',
  42. arrayTag = '[object Array]',
  43. boolTag = '[object Boolean]',
  44. dateTag = '[object Date]',
  45. errorTag = '[object Error]',
  46. funcTag = '[object Function]',
  47. mapTag = '[object Map]',
  48. numberTag = '[object Number]',
  49. objectTag = '[object Object]',
  50. regexpTag = '[object RegExp]',
  51. setTag = '[object Set]',
  52. stringTag = '[object String]',
  53. weakMapTag = '[object WeakMap]';
  54. var arrayBufferTag = '[object ArrayBuffer]',
  55. float32Tag = '[object Float32Array]',
  56. float64Tag = '[object Float64Array]',
  57. int8Tag = '[object Int8Array]',
  58. int16Tag = '[object Int16Array]',
  59. int32Tag = '[object Int32Array]',
  60. uint8Tag = '[object Uint8Array]',
  61. uint8ClampedTag = '[object Uint8ClampedArray]',
  62. uint16Tag = '[object Uint16Array]',
  63. uint32Tag = '[object Uint32Array]';
  64. /** Used to match empty string literals in compiled template source. */
  65. var reEmptyStringLeading = /\b__p \+= '';/g,
  66. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  67. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  68. /** Used to match HTML entities and HTML characters. */
  69. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  70. reUnescapedHtml = /[&<>"'`]/g,
  71. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  72. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  73. /** Used to match template delimiters. */
  74. var reEscape = /<%-([\s\S]+?)%>/g,
  75. reEvaluate = /<%([\s\S]+?)%>/g,
  76. reInterpolate = /<%=([\s\S]+?)%>/g;
  77. /** Used to match property names within property paths. */
  78. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
  79. reIsPlainProp = /^\w*$/,
  80. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
  81. /**
  82. * Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
  83. * and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
  84. */
  85. var reRegExpChars = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,
  86. reHasRegExpChars = RegExp(reRegExpChars.source);
  87. /** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
  88. var reComboMark = /[\u0300-\u036f\ufe20-\ufe23]/g;
  89. /** Used to match backslashes in property paths. */
  90. var reEscapeChar = /\\(\\)?/g;
  91. /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
  92. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  93. /** Used to match `RegExp` flags from their coerced string values. */
  94. var reFlags = /\w*$/;
  95. /** Used to detect hexadecimal string values. */
  96. var reHasHexPrefix = /^0[xX]/;
  97. /** Used to detect host constructors (Safari > 5). */
  98. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  99. /** Used to detect unsigned integer values. */
  100. var reIsUint = /^\d+$/;
  101. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  102. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  103. /** Used to ensure capturing order of template delimiters. */
  104. var reNoMatch = /($^)/;
  105. /** Used to match unescaped characters in compiled string literals. */
  106. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  107. /** Used to match words to create compound words. */
  108. var reWords = (function() {
  109. var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
  110. lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
  111. return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
  112. }());
  113. /** Used to assign default `context` object properties. */
  114. var contextProps = [
  115. 'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
  116. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
  117. 'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'isFinite',
  118. 'parseFloat', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
  119. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap'
  120. ];
  121. /** Used to fix the JScript `[[DontEnum]]` bug. */
  122. var shadowProps = [
  123. 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
  124. 'toLocaleString', 'toString', 'valueOf'
  125. ];
  126. /** Used to make template sourceURLs easier to identify. */
  127. var templateCounter = -1;
  128. /** Used to identify `toStringTag` values of typed arrays. */
  129. var typedArrayTags = {};
  130. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  131. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  132. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  133. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  134. typedArrayTags[uint32Tag] = true;
  135. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  136. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  137. typedArrayTags[dateTag] = typedArrayTags[errorTag] =
  138. typedArrayTags[funcTag] = typedArrayTags[mapTag] =
  139. typedArrayTags[numberTag] = typedArrayTags[objectTag] =
  140. typedArrayTags[regexpTag] = typedArrayTags[setTag] =
  141. typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  142. /** Used to identify `toStringTag` values supported by `_.clone`. */
  143. var cloneableTags = {};
  144. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  145. cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
  146. cloneableTags[dateTag] = cloneableTags[float32Tag] =
  147. cloneableTags[float64Tag] = cloneableTags[int8Tag] =
  148. cloneableTags[int16Tag] = cloneableTags[int32Tag] =
  149. cloneableTags[numberTag] = cloneableTags[objectTag] =
  150. cloneableTags[regexpTag] = cloneableTags[stringTag] =
  151. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  152. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  153. cloneableTags[errorTag] = cloneableTags[funcTag] =
  154. cloneableTags[mapTag] = cloneableTags[setTag] =
  155. cloneableTags[weakMapTag] = false;
  156. /** Used to map latin-1 supplementary letters to basic latin letters. */
  157. var deburredLetters = {
  158. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  159. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  160. '\xc7': 'C', '\xe7': 'c',
  161. '\xd0': 'D', '\xf0': 'd',
  162. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  163. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  164. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  165. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  166. '\xd1': 'N', '\xf1': 'n',
  167. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  168. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  169. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  170. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  171. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  172. '\xc6': 'Ae', '\xe6': 'ae',
  173. '\xde': 'Th', '\xfe': 'th',
  174. '\xdf': 'ss'
  175. };
  176. /** Used to map characters to HTML entities. */
  177. var htmlEscapes = {
  178. '&': '&amp;',
  179. '<': '&lt;',
  180. '>': '&gt;',
  181. '"': '&quot;',
  182. "'": '&#39;',
  183. '`': '&#96;'
  184. };
  185. /** Used to map HTML entities to characters. */
  186. var htmlUnescapes = {
  187. '&amp;': '&',
  188. '&lt;': '<',
  189. '&gt;': '>',
  190. '&quot;': '"',
  191. '&#39;': "'",
  192. '&#96;': '`'
  193. };
  194. /** Used to determine if values are of the language type `Object`. */
  195. var objectTypes = {
  196. 'function': true,
  197. 'object': true
  198. };
  199. /** Used to escape characters for inclusion in compiled regexes. */
  200. var regexpEscapes = {
  201. '0': 'x30', '1': 'x31', '2': 'x32', '3': 'x33', '4': 'x34',
  202. '5': 'x35', '6': 'x36', '7': 'x37', '8': 'x38', '9': 'x39',
  203. 'A': 'x41', 'B': 'x42', 'C': 'x43', 'D': 'x44', 'E': 'x45', 'F': 'x46',
  204. 'a': 'x61', 'b': 'x62', 'c': 'x63', 'd': 'x64', 'e': 'x65', 'f': 'x66',
  205. 'n': 'x6e', 'r': 'x72', 't': 'x74', 'u': 'x75', 'v': 'x76', 'x': 'x78'
  206. };
  207. /** Used to escape characters for inclusion in compiled string literals. */
  208. var stringEscapes = {
  209. '\\': '\\',
  210. "'": "'",
  211. '\n': 'n',
  212. '\r': 'r',
  213. '\u2028': 'u2028',
  214. '\u2029': 'u2029'
  215. };
  216. /** Detect free variable `exports`. */
  217. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  218. /** Detect free variable `module`. */
  219. var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
  220. /** Detect free variable `global` from Node.js. */
  221. var freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
  222. /** Detect free variable `self`. */
  223. var freeSelf = objectTypes[typeof self] && self && self.Object && self;
  224. /** Detect free variable `window`. */
  225. var freeWindow = objectTypes[typeof window] && window && window.Object && window;
  226. /** Detect the popular CommonJS extension `module.exports`. */
  227. var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
  228. /**
  229. * Used as a reference to the global object.
  230. *
  231. * The `this` value is used if it's the global object to avoid Greasemonkey's
  232. * restricted `window` object, otherwise the `window` object is used.
  233. */
  234. var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
  235. /*--------------------------------------------------------------------------*/
  236. /**
  237. * The base implementation of `compareAscending` which compares values and
  238. * sorts them in ascending order without guaranteeing a stable sort.
  239. *
  240. * @private
  241. * @param {*} value The value to compare.
  242. * @param {*} other The other value to compare.
  243. * @returns {number} Returns the sort order indicator for `value`.
  244. */
  245. function baseCompareAscending(value, other) {
  246. if (value !== other) {
  247. var valIsNull = value === null,
  248. valIsUndef = value === undefined,
  249. valIsReflexive = value === value;
  250. var othIsNull = other === null,
  251. othIsUndef = other === undefined,
  252. othIsReflexive = other === other;
  253. if ((value > other && !othIsNull) || !valIsReflexive ||
  254. (valIsNull && !othIsUndef && othIsReflexive) ||
  255. (valIsUndef && othIsReflexive)) {
  256. return 1;
  257. }
  258. if ((value < other && !valIsNull) || !othIsReflexive ||
  259. (othIsNull && !valIsUndef && valIsReflexive) ||
  260. (othIsUndef && valIsReflexive)) {
  261. return -1;
  262. }
  263. }
  264. return 0;
  265. }
  266. /**
  267. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  268. * support for callback shorthands and `this` binding.
  269. *
  270. * @private
  271. * @param {Array} array The array to search.
  272. * @param {Function} predicate The function invoked per iteration.
  273. * @param {boolean} [fromRight] Specify iterating from right to left.
  274. * @returns {number} Returns the index of the matched value, else `-1`.
  275. */
  276. function baseFindIndex(array, predicate, fromRight) {
  277. var length = array.length,
  278. index = fromRight ? length : -1;
  279. while ((fromRight ? index-- : ++index < length)) {
  280. if (predicate(array[index], index, array)) {
  281. return index;
  282. }
  283. }
  284. return -1;
  285. }
  286. /**
  287. * The base implementation of `_.indexOf` without support for binary searches.
  288. *
  289. * @private
  290. * @param {Array} array The array to search.
  291. * @param {*} value The value to search for.
  292. * @param {number} fromIndex The index to search from.
  293. * @returns {number} Returns the index of the matched value, else `-1`.
  294. */
  295. function baseIndexOf(array, value, fromIndex) {
  296. if (value !== value) {
  297. return indexOfNaN(array, fromIndex);
  298. }
  299. var index = fromIndex - 1,
  300. length = array.length;
  301. while (++index < length) {
  302. if (array[index] === value) {
  303. return index;
  304. }
  305. }
  306. return -1;
  307. }
  308. /**
  309. * The base implementation of `_.isFunction` without support for environments
  310. * with incorrect `typeof` results.
  311. *
  312. * @private
  313. * @param {*} value The value to check.
  314. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  315. */
  316. function baseIsFunction(value) {
  317. // Avoid a Chakra JIT bug in compatibility modes of IE 11.
  318. // See https://github.com/jashkenas/underscore/issues/1621 for more details.
  319. return typeof value == 'function' || false;
  320. }
  321. /**
  322. * Converts `value` to a string if it's not one. An empty string is returned
  323. * for `null` or `undefined` values.
  324. *
  325. * @private
  326. * @param {*} value The value to process.
  327. * @returns {string} Returns the string.
  328. */
  329. function baseToString(value) {
  330. return value == null ? '' : (value + '');
  331. }
  332. /**
  333. * Used by `_.trim` and `_.trimLeft` to get the index of the first character
  334. * of `string` that is not found in `chars`.
  335. *
  336. * @private
  337. * @param {string} string The string to inspect.
  338. * @param {string} chars The characters to find.
  339. * @returns {number} Returns the index of the first character not found in `chars`.
  340. */
  341. function charsLeftIndex(string, chars) {
  342. var index = -1,
  343. length = string.length;
  344. while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
  345. return index;
  346. }
  347. /**
  348. * Used by `_.trim` and `_.trimRight` to get the index of the last character
  349. * of `string` that is not found in `chars`.
  350. *
  351. * @private
  352. * @param {string} string The string to inspect.
  353. * @param {string} chars The characters to find.
  354. * @returns {number} Returns the index of the last character not found in `chars`.
  355. */
  356. function charsRightIndex(string, chars) {
  357. var index = string.length;
  358. while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
  359. return index;
  360. }
  361. /**
  362. * Used by `_.sortBy` to compare transformed elements of a collection and stable
  363. * sort them in ascending order.
  364. *
  365. * @private
  366. * @param {Object} object The object to compare.
  367. * @param {Object} other The other object to compare.
  368. * @returns {number} Returns the sort order indicator for `object`.
  369. */
  370. function compareAscending(object, other) {
  371. return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
  372. }
  373. /**
  374. * Used by `_.sortByOrder` to compare multiple properties of a value to another
  375. * and stable sort them.
  376. *
  377. * If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise,
  378. * a value is sorted in ascending order if its corresponding order is "asc", and
  379. * descending if "desc".
  380. *
  381. * @private
  382. * @param {Object} object The object to compare.
  383. * @param {Object} other The other object to compare.
  384. * @param {boolean[]} orders The order to sort by for each property.
  385. * @returns {number} Returns the sort order indicator for `object`.
  386. */
  387. function compareMultiple(object, other, orders) {
  388. var index = -1,
  389. objCriteria = object.criteria,
  390. othCriteria = other.criteria,
  391. length = objCriteria.length,
  392. ordersLength = orders.length;
  393. while (++index < length) {
  394. var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
  395. if (result) {
  396. if (index >= ordersLength) {
  397. return result;
  398. }
  399. var order = orders[index];
  400. return result * ((order === 'asc' || order === true) ? 1 : -1);
  401. }
  402. }
  403. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  404. // that causes it, under certain circumstances, to provide the same value for
  405. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  406. // for more details.
  407. //
  408. // This also ensures a stable sort in V8 and other engines.
  409. // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
  410. return object.index - other.index;
  411. }
  412. /**
  413. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  414. *
  415. * @private
  416. * @param {string} letter The matched letter to deburr.
  417. * @returns {string} Returns the deburred letter.
  418. */
  419. function deburrLetter(letter) {
  420. return deburredLetters[letter];
  421. }
  422. /**
  423. * Used by `_.escape` to convert characters to HTML entities.
  424. *
  425. * @private
  426. * @param {string} chr The matched character to escape.
  427. * @returns {string} Returns the escaped character.
  428. */
  429. function escapeHtmlChar(chr) {
  430. return htmlEscapes[chr];
  431. }
  432. /**
  433. * Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
  434. *
  435. * @private
  436. * @param {string} chr The matched character to escape.
  437. * @param {string} leadingChar The capture group for a leading character.
  438. * @param {string} whitespaceChar The capture group for a whitespace character.
  439. * @returns {string} Returns the escaped character.
  440. */
  441. function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
  442. if (leadingChar) {
  443. chr = regexpEscapes[chr];
  444. } else if (whitespaceChar) {
  445. chr = stringEscapes[chr];
  446. }
  447. return '\\' + chr;
  448. }
  449. /**
  450. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  451. *
  452. * @private
  453. * @param {string} chr The matched character to escape.
  454. * @returns {string} Returns the escaped character.
  455. */
  456. function escapeStringChar(chr) {
  457. return '\\' + stringEscapes[chr];
  458. }
  459. /**
  460. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  461. *
  462. * @private
  463. * @param {Array} array The array to search.
  464. * @param {number} fromIndex The index to search from.
  465. * @param {boolean} [fromRight] Specify iterating from right to left.
  466. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  467. */
  468. function indexOfNaN(array, fromIndex, fromRight) {
  469. var length = array.length,
  470. index = fromIndex + (fromRight ? 0 : -1);
  471. while ((fromRight ? index-- : ++index < length)) {
  472. var other = array[index];
  473. if (other !== other) {
  474. return index;
  475. }
  476. }
  477. return -1;
  478. }
  479. /**
  480. * Checks if `value` is a host object in IE < 9.
  481. *
  482. * @private
  483. * @param {*} value The value to check.
  484. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  485. */
  486. var isHostObject = (function() {
  487. try {
  488. Object({ 'toString': 0 } + '');
  489. } catch(e) {
  490. return function() { return false; };
  491. }
  492. return function(value) {
  493. // IE < 9 presents many host objects as `Object` objects that can coerce
  494. // to strings despite having improperly defined `toString` methods.
  495. return typeof value.toString != 'function' && typeof (value + '') == 'string';
  496. };
  497. }());
  498. /**
  499. * Checks if `value` is object-like.
  500. *
  501. * @private
  502. * @param {*} value The value to check.
  503. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  504. */
  505. function isObjectLike(value) {
  506. return !!value && typeof value == 'object';
  507. }
  508. /**
  509. * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
  510. * character code is whitespace.
  511. *
  512. * @private
  513. * @param {number} charCode The character code to inspect.
  514. * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
  515. */
  516. function isSpace(charCode) {
  517. return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
  518. (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
  519. }
  520. /**
  521. * Replaces all `placeholder` elements in `array` with an internal placeholder
  522. * and returns an array of their indexes.
  523. *
  524. * @private
  525. * @param {Array} array The array to modify.
  526. * @param {*} placeholder The placeholder to replace.
  527. * @returns {Array} Returns the new array of placeholder indexes.
  528. */
  529. function replaceHolders(array, placeholder) {
  530. var index = -1,
  531. length = array.length,
  532. resIndex = -1,
  533. result = [];
  534. while (++index < length) {
  535. if (array[index] === placeholder) {
  536. array[index] = PLACEHOLDER;
  537. result[++resIndex] = index;
  538. }
  539. }
  540. return result;
  541. }
  542. /**
  543. * An implementation of `_.uniq` optimized for sorted arrays without support
  544. * for callback shorthands and `this` binding.
  545. *
  546. * @private
  547. * @param {Array} array The array to inspect.
  548. * @param {Function} [iteratee] The function invoked per iteration.
  549. * @returns {Array} Returns the new duplicate free array.
  550. */
  551. function sortedUniq(array, iteratee) {
  552. var seen,
  553. index = -1,
  554. length = array.length,
  555. resIndex = -1,
  556. result = [];
  557. while (++index < length) {
  558. var value = array[index],
  559. computed = iteratee ? iteratee(value, index, array) : value;
  560. if (!index || seen !== computed) {
  561. seen = computed;
  562. result[++resIndex] = value;
  563. }
  564. }
  565. return result;
  566. }
  567. /**
  568. * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
  569. * character of `string`.
  570. *
  571. * @private
  572. * @param {string} string The string to inspect.
  573. * @returns {number} Returns the index of the first non-whitespace character.
  574. */
  575. function trimmedLeftIndex(string) {
  576. var index = -1,
  577. length = string.length;
  578. while (++index < length && isSpace(string.charCodeAt(index))) {}
  579. return index;
  580. }
  581. /**
  582. * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
  583. * character of `string`.
  584. *
  585. * @private
  586. * @param {string} string The string to inspect.
  587. * @returns {number} Returns the index of the last non-whitespace character.
  588. */
  589. function trimmedRightIndex(string) {
  590. var index = string.length;
  591. while (index-- && isSpace(string.charCodeAt(index))) {}
  592. return index;
  593. }
  594. /**
  595. * Used by `_.unescape` to convert HTML entities to characters.
  596. *
  597. * @private
  598. * @param {string} chr The matched character to unescape.
  599. * @returns {string} Returns the unescaped character.
  600. */
  601. function unescapeHtmlChar(chr) {
  602. return htmlUnescapes[chr];
  603. }
  604. /*--------------------------------------------------------------------------*/
  605. /**
  606. * Create a new pristine `lodash` function using the given `context` object.
  607. *
  608. * @static
  609. * @memberOf _
  610. * @category Utility
  611. * @param {Object} [context=root] The context object.
  612. * @returns {Function} Returns a new `lodash` function.
  613. * @example
  614. *
  615. * _.mixin({ 'foo': _.constant('foo') });
  616. *
  617. * var lodash = _.runInContext();
  618. * lodash.mixin({ 'bar': lodash.constant('bar') });
  619. *
  620. * _.isFunction(_.foo);
  621. * // => true
  622. * _.isFunction(_.bar);
  623. * // => false
  624. *
  625. * lodash.isFunction(lodash.foo);
  626. * // => false
  627. * lodash.isFunction(lodash.bar);
  628. * // => true
  629. *
  630. * // using `context` to mock `Date#getTime` use in `_.now`
  631. * var mock = _.runInContext({
  632. * 'Date': function() {
  633. * return { 'getTime': getTimeMock };
  634. * }
  635. * });
  636. *
  637. * // or creating a suped-up `defer` in Node.js
  638. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  639. */
  640. function runInContext(context) {
  641. // Avoid issues with some ES3 environments that attempt to use values, named
  642. // after built-in constructors like `Object`, for the creation of literals.
  643. // ES5 clears this up by stating that literals must use built-in constructors.
  644. // See https://es5.github.io/#x11.1.5 for more details.
  645. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  646. /** Native constructor references. */
  647. var Array = context.Array,
  648. Date = context.Date,
  649. Error = context.Error,
  650. Function = context.Function,
  651. Math = context.Math,
  652. Number = context.Number,
  653. Object = context.Object,
  654. RegExp = context.RegExp,
  655. String = context.String,
  656. TypeError = context.TypeError;
  657. /** Used for native method references. */
  658. var arrayProto = Array.prototype,
  659. errorProto = Error.prototype,
  660. objectProto = Object.prototype,
  661. stringProto = String.prototype;
  662. /** Used to resolve the decompiled source of functions. */
  663. var fnToString = Function.prototype.toString;
  664. /** Used to check objects for own properties. */
  665. var hasOwnProperty = objectProto.hasOwnProperty;
  666. /** Used to generate unique IDs. */
  667. var idCounter = 0;
  668. /**
  669. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  670. * of values.
  671. */
  672. var objToString = objectProto.toString;
  673. /** Used to restore the original `_` reference in `_.noConflict`. */
  674. var oldDash = root._;
  675. /** Used to detect if a method is native. */
  676. var reIsNative = RegExp('^' +
  677. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  678. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  679. );
  680. /** Native method references. */
  681. var ArrayBuffer = context.ArrayBuffer,
  682. clearTimeout = context.clearTimeout,
  683. parseFloat = context.parseFloat,
  684. pow = Math.pow,
  685. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  686. Set = getNative(context, 'Set'),
  687. setTimeout = context.setTimeout,
  688. splice = arrayProto.splice,
  689. Uint8Array = context.Uint8Array,
  690. WeakMap = getNative(context, 'WeakMap');
  691. /* Native method references for those with the same name as other `lodash` methods. */
  692. var nativeCeil = Math.ceil,
  693. nativeCreate = getNative(Object, 'create'),
  694. nativeFloor = Math.floor,
  695. nativeIsArray = getNative(Array, 'isArray'),
  696. nativeIsFinite = context.isFinite,
  697. nativeKeys = getNative(Object, 'keys'),
  698. nativeMax = Math.max,
  699. nativeMin = Math.min,
  700. nativeNow = getNative(Date, 'now'),
  701. nativeParseInt = context.parseInt,
  702. nativeRandom = Math.random;
  703. /** Used as references for `-Infinity` and `Infinity`. */
  704. var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
  705. POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
  706. /** Used as references for the maximum length and index of an array. */
  707. var MAX_ARRAY_LENGTH = 4294967295,
  708. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  709. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  710. /**
  711. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  712. * of an array-like value.
  713. */
  714. var MAX_SAFE_INTEGER = 9007199254740991;
  715. /** Used to store function metadata. */
  716. var metaMap = WeakMap && new WeakMap;
  717. /** Used to lookup unminified function names. */
  718. var realNames = {};
  719. /** Used to lookup a type array constructors by `toStringTag`. */
  720. var ctorByTag = {};
  721. ctorByTag[float32Tag] = context.Float32Array;
  722. ctorByTag[float64Tag] = context.Float64Array;
  723. ctorByTag[int8Tag] = context.Int8Array;
  724. ctorByTag[int16Tag] = context.Int16Array;
  725. ctorByTag[int32Tag] = context.Int32Array;
  726. ctorByTag[uint8Tag] = Uint8Array;
  727. ctorByTag[uint8ClampedTag] = context.Uint8ClampedArray;
  728. ctorByTag[uint16Tag] = context.Uint16Array;
  729. ctorByTag[uint32Tag] = context.Uint32Array;
  730. /** Used to avoid iterating over non-enumerable properties in IE < 9. */
  731. var nonEnumProps = {};
  732. nonEnumProps[arrayTag] = nonEnumProps[dateTag] = nonEnumProps[numberTag] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
  733. nonEnumProps[boolTag] = nonEnumProps[stringTag] = { 'constructor': true, 'toString': true, 'valueOf': true };
  734. nonEnumProps[errorTag] = nonEnumProps[funcTag] = nonEnumProps[regexpTag] = { 'constructor': true, 'toString': true };
  735. nonEnumProps[objectTag] = { 'constructor': true };
  736. arrayEach(shadowProps, function(key) {
  737. for (var tag in nonEnumProps) {
  738. if (hasOwnProperty.call(nonEnumProps, tag)) {
  739. var props = nonEnumProps[tag];
  740. props[key] = hasOwnProperty.call(props, key);
  741. }
  742. }
  743. });
  744. /*------------------------------------------------------------------------*/
  745. /**
  746. * Creates a `lodash` object which wraps `value` to enable implicit chaining.
  747. * Methods that operate on and return arrays, collections, and functions can
  748. * be chained together. Methods that retrieve a single value or may return a
  749. * primitive value will automatically end the chain returning the unwrapped
  750. * value. Explicit chaining may be enabled using `_.chain`. The execution of
  751. * chained methods is lazy, that is, execution is deferred until `_#value`
  752. * is implicitly or explicitly called.
  753. *
  754. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  755. * fusion is an optimization strategy which merge iteratee calls; this can help
  756. * to avoid the creation of intermediate data structures and greatly reduce the
  757. * number of iteratee executions.
  758. *
  759. * Chaining is supported in custom builds as long as the `_#value` method is
  760. * directly or indirectly included in the build.
  761. *
  762. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  763. *
  764. * The wrapper `Array` methods are:
  765. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
  766. * `splice`, and `unshift`
  767. *
  768. * The wrapper `String` methods are:
  769. * `replace` and `split`
  770. *
  771. * The wrapper methods that support shortcut fusion are:
  772. * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
  773. * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
  774. * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
  775. * and `where`
  776. *
  777. * The chainable wrapper methods are:
  778. * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
  779. * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
  780. * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
  781. * `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
  782. * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
  783. * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
  784. * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
  785. * `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
  786. * `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
  787. * `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
  788. * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
  789. * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
  790. * `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
  791. * `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
  792. * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
  793. * `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
  794. * `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
  795. *
  796. * The wrapper methods that are **not** chainable by default are:
  797. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
  798. * `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
  799. * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
  800. * `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
  801. * `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
  802. * `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
  803. * `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
  804. * `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
  805. * `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
  806. * `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
  807. * `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
  808. * `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
  809. * `startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
  810. * `unescape`, `uniqueId`, `value`, and `words`
  811. *
  812. * The wrapper method `sample` will return a wrapped value when `n` is provided,
  813. * otherwise an unwrapped value is returned.
  814. *
  815. * @name _
  816. * @constructor
  817. * @category Chain
  818. * @param {*} value The value to wrap in a `lodash` instance.
  819. * @returns {Object} Returns the new `lodash` wrapper instance.
  820. * @example
  821. *
  822. * var wrapped = _([1, 2, 3]);
  823. *
  824. * // returns an unwrapped value
  825. * wrapped.reduce(function(total, n) {
  826. * return total + n;
  827. * });
  828. * // => 6
  829. *
  830. * // returns a wrapped value
  831. * var squares = wrapped.map(function(n) {
  832. * return n * n;
  833. * });
  834. *
  835. * _.isArray(squares);
  836. * // => false
  837. *
  838. * _.isArray(squares.value());
  839. * // => true
  840. */
  841. function lodash(value) {
  842. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  843. if (value instanceof LodashWrapper) {
  844. return value;
  845. }
  846. if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
  847. return wrapperClone(value);
  848. }
  849. }
  850. return new LodashWrapper(value);
  851. }
  852. /**
  853. * The function whose prototype all chaining wrappers inherit from.
  854. *
  855. * @private
  856. */
  857. function baseLodash() {
  858. // No operation performed.
  859. }
  860. /**
  861. * The base constructor for creating `lodash` wrapper objects.
  862. *
  863. * @private
  864. * @param {*} value The value to wrap.
  865. * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
  866. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
  867. */
  868. function LodashWrapper(value, chainAll, actions) {
  869. this.__wrapped__ = value;
  870. this.__actions__ = actions || [];
  871. this.__chain__ = !!chainAll;
  872. }
  873. /**
  874. * An object environment feature flags.
  875. *
  876. * @static
  877. * @memberOf _
  878. * @type Object
  879. */
  880. var support = lodash.support = {};
  881. (function(x) {
  882. var Ctor = function() { this.x = x; },
  883. object = { '0': x, 'length': x },
  884. props = [];
  885. Ctor.prototype = { 'valueOf': x, 'y': x };
  886. for (var key in new Ctor) { props.push(key); }
  887. /**
  888. * Detect if `name` or `message` properties of `Error.prototype` are
  889. * enumerable by default (IE < 9, Safari < 5.1).
  890. *
  891. * @memberOf _.support
  892. * @type boolean
  893. */
  894. support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') ||
  895. propertyIsEnumerable.call(errorProto, 'name');
  896. /**
  897. * Detect if `prototype` properties are enumerable by default.
  898. *
  899. * Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
  900. * (if the prototype or a property on the prototype has been set)
  901. * incorrectly set the `[[Enumerable]]` value of a function's `prototype`
  902. * property to `true`.
  903. *
  904. * @memberOf _.support
  905. * @type boolean
  906. */
  907. support.enumPrototypes = propertyIsEnumerable.call(Ctor, 'prototype');
  908. /**
  909. * Detect if properties shadowing those on `Object.prototype` are non-enumerable.
  910. *
  911. * In IE < 9 an object's own properties, shadowing non-enumerable ones,
  912. * are made non-enumerable as well (a.k.a the JScript `[[DontEnum]]` bug).
  913. *
  914. * @memberOf _.support
  915. * @type boolean
  916. */
  917. support.nonEnumShadows = !/valueOf/.test(props);
  918. /**
  919. * Detect if own properties are iterated after inherited properties (IE < 9).
  920. *
  921. * @memberOf _.support
  922. * @type boolean
  923. */
  924. support.ownLast = props[0] != 'x';
  925. /**
  926. * Detect if `Array#shift` and `Array#splice` augment array-like objects
  927. * correctly.
  928. *
  929. * Firefox < 10, compatibility modes of IE 8, and IE < 9 have buggy Array
  930. * `shift()` and `splice()` functions that fail to remove the last element,
  931. * `value[0]`, of array-like objects even though the "length" property is
  932. * set to `0`. The `shift()` method is buggy in compatibility modes of IE 8,
  933. * while `splice()` is buggy regardless of mode in IE < 9.
  934. *
  935. * @memberOf _.support
  936. * @type boolean
  937. */
  938. support.spliceObjects = (splice.call(object, 0, 1), !object[0]);
  939. /**
  940. * Detect lack of support for accessing string characters by index.
  941. *
  942. * IE < 8 can't access characters by index. IE 8 can only access characters
  943. * by index on string literals, not string objects.
  944. *
  945. * @memberOf _.support
  946. * @type boolean
  947. */
  948. support.unindexedChars = ('x'[0] + Object('x')[0]) != 'xx';
  949. }(1, 0));
  950. /**
  951. * By default, the template delimiters used by lodash are like those in
  952. * embedded Ruby (ERB). Change the following template settings to use
  953. * alternative delimiters.
  954. *
  955. * @static
  956. * @memberOf _
  957. * @type Object
  958. */
  959. lodash.templateSettings = {
  960. /**
  961. * Used to detect `data` property values to be HTML-escaped.
  962. *
  963. * @memberOf _.templateSettings
  964. * @type RegExp
  965. */
  966. 'escape': reEscape,
  967. /**
  968. * Used to detect code to be evaluated.
  969. *
  970. * @memberOf _.templateSettings
  971. * @type RegExp
  972. */
  973. 'evaluate': reEvaluate,
  974. /**
  975. * Used to detect `data` property values to inject.
  976. *
  977. * @memberOf _.templateSettings
  978. * @type RegExp
  979. */
  980. 'interpolate': reInterpolate,
  981. /**
  982. * Used to reference the data object in the template text.
  983. *
  984. * @memberOf _.templateSettings
  985. * @type string
  986. */
  987. 'variable': '',
  988. /**
  989. * Used to import variables into the compiled template.
  990. *
  991. * @memberOf _.templateSettings
  992. * @type Object
  993. */
  994. 'imports': {
  995. /**
  996. * A reference to the `lodash` function.
  997. *
  998. * @memberOf _.templateSettings.imports
  999. * @type Function
  1000. */
  1001. '_': lodash
  1002. }
  1003. };
  1004. /*------------------------------------------------------------------------*/
  1005. /**
  1006. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1007. *
  1008. * @private
  1009. * @param {*} value The value to wrap.
  1010. */
  1011. function LazyWrapper(value) {
  1012. this.__wrapped__ = value;
  1013. this.__actions__ = [];
  1014. this.__dir__ = 1;
  1015. this.__filtered__ = false;
  1016. this.__iteratees__ = [];
  1017. this.__takeCount__ = POSITIVE_INFINITY;
  1018. this.__views__ = [];
  1019. }
  1020. /**
  1021. * Creates a clone of the lazy wrapper object.
  1022. *
  1023. * @private
  1024. * @name clone
  1025. * @memberOf LazyWrapper
  1026. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1027. */
  1028. function lazyClone() {
  1029. var result = new LazyWrapper(this.__wrapped__);
  1030. result.__actions__ = arrayCopy(this.__actions__);
  1031. result.__dir__ = this.__dir__;
  1032. result.__filtered__ = this.__filtered__;
  1033. result.__iteratees__ = arrayCopy(this.__iteratees__);
  1034. result.__takeCount__ = this.__takeCount__;
  1035. result.__views__ = arrayCopy(this.__views__);
  1036. return result;
  1037. }
  1038. /**
  1039. * Reverses the direction of lazy iteration.
  1040. *
  1041. * @private
  1042. * @name reverse
  1043. * @memberOf LazyWrapper
  1044. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1045. */
  1046. function lazyReverse() {
  1047. if (this.__filtered__) {
  1048. var result = new LazyWrapper(this);
  1049. result.__dir__ = -1;
  1050. result.__filtered__ = true;
  1051. } else {
  1052. result = this.clone();
  1053. result.__dir__ *= -1;
  1054. }
  1055. return result;
  1056. }
  1057. /**
  1058. * Extracts the unwrapped value from its lazy wrapper.
  1059. *
  1060. * @private
  1061. * @name value
  1062. * @memberOf LazyWrapper
  1063. * @returns {*} Returns the unwrapped value.
  1064. */
  1065. function lazyValue() {
  1066. var array = this.__wrapped__.value(),
  1067. dir = this.__dir__,
  1068. isArr = isArray(array),
  1069. isRight = dir < 0,
  1070. arrLength = isArr ? array.length : 0,
  1071. view = getView(0, arrLength, this.__views__),
  1072. start = view.start,
  1073. end = view.end,
  1074. length = end - start,
  1075. index = isRight ? end : (start - 1),
  1076. iteratees = this.__iteratees__,
  1077. iterLength = iteratees.length,
  1078. resIndex = 0,
  1079. takeCount = nativeMin(length, this.__takeCount__);
  1080. if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
  1081. return baseWrapperValue(array, this.__actions__);
  1082. }
  1083. var result = [];
  1084. outer:
  1085. while (length-- && resIndex < takeCount) {
  1086. index += dir;
  1087. var iterIndex = -1,
  1088. value = array[index];
  1089. while (++iterIndex < iterLength) {
  1090. var data = iteratees[iterIndex],
  1091. iteratee = data.iteratee,
  1092. type = data.type,
  1093. computed = iteratee(value);
  1094. if (type == LAZY_MAP_FLAG) {
  1095. value = computed;
  1096. } else if (!computed) {
  1097. if (type == LAZY_FILTER_FLAG) {
  1098. continue outer;
  1099. } else {
  1100. break outer;
  1101. }
  1102. }
  1103. }
  1104. result[resIndex++] = value;
  1105. }
  1106. return result;
  1107. }
  1108. /*------------------------------------------------------------------------*/
  1109. /**
  1110. * Creates a cache object to store key/value pairs.
  1111. *
  1112. * @private
  1113. * @static
  1114. * @name Cache
  1115. * @memberOf _.memoize
  1116. */
  1117. function MapCache() {
  1118. this.__data__ = {};
  1119. }
  1120. /**
  1121. * Removes `key` and its value from the cache.
  1122. *
  1123. * @private
  1124. * @name delete
  1125. * @memberOf _.memoize.Cache
  1126. * @param {string} key The key of the value to remove.
  1127. * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
  1128. */
  1129. function mapDelete(key) {
  1130. return this.has(key) && delete this.__data__[key];
  1131. }
  1132. /**
  1133. * Gets the cached value for `key`.
  1134. *
  1135. * @private
  1136. * @name get
  1137. * @memberOf _.memoize.Cache
  1138. * @param {string} key The key of the value to get.
  1139. * @returns {*} Returns the cached value.
  1140. */
  1141. function mapGet(key) {
  1142. return key == '__proto__' ? undefined : this.__data__[key];
  1143. }
  1144. /**
  1145. * Checks if a cached value for `key` exists.
  1146. *
  1147. * @private
  1148. * @name has
  1149. * @memberOf _.memoize.Cache
  1150. * @param {string} key The key of the entry to check.
  1151. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1152. */
  1153. function mapHas(key) {
  1154. return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
  1155. }
  1156. /**
  1157. * Sets `value` to `key` of the cache.
  1158. *
  1159. * @private
  1160. * @name set
  1161. * @memberOf _.memoize.Cache
  1162. * @param {string} key The key of the value to cache.
  1163. * @param {*} value The value to cache.
  1164. * @returns {Object} Returns the cache object.
  1165. */
  1166. function mapSet(key, value) {
  1167. if (key != '__proto__') {
  1168. this.__data__[key] = value;
  1169. }
  1170. return this;
  1171. }
  1172. /*------------------------------------------------------------------------*/
  1173. /**
  1174. *
  1175. * Creates a cache object to store unique values.
  1176. *
  1177. * @private
  1178. * @param {Array} [values] The values to cache.
  1179. */
  1180. function SetCache(values) {
  1181. var length = values ? values.length : 0;
  1182. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  1183. while (length--) {
  1184. this.push(values[length]);
  1185. }
  1186. }
  1187. /**
  1188. * Checks if `value` is in `cache` mimicking the return signature of
  1189. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  1190. *
  1191. * @private
  1192. * @param {Object} cache The cache to search.
  1193. * @param {*} value The value to search for.
  1194. * @returns {number} Returns `0` if `value` is found, else `-1`.
  1195. */
  1196. function cacheIndexOf(cache, value) {
  1197. var data = cache.data,
  1198. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  1199. return result ? 0 : -1;
  1200. }
  1201. /**
  1202. * Adds `value` to the cache.
  1203. *
  1204. * @private
  1205. * @name push
  1206. * @memberOf SetCache
  1207. * @param {*} value The value to cache.
  1208. */
  1209. function cachePush(value) {
  1210. var data = this.data;
  1211. if (typeof value == 'string' || isObject(value)) {
  1212. data.set.add(value);
  1213. } else {
  1214. data.hash[value] = true;
  1215. }
  1216. }
  1217. /*------------------------------------------------------------------------*/
  1218. /**
  1219. * Creates a new array joining `array` with `other`.
  1220. *
  1221. * @private
  1222. * @param {Array} array The array to join.
  1223. * @param {Array} other The other array to join.
  1224. * @returns {Array} Returns the new concatenated array.
  1225. */
  1226. function arrayConcat(array, other) {
  1227. var index = -1,
  1228. length = array.length,
  1229. othIndex = -1,
  1230. othLength = other.length,
  1231. result = Array(length + othLength);
  1232. while (++index < length) {
  1233. result[index] = array[index];
  1234. }
  1235. while (++othIndex < othLength) {
  1236. result[index++] = other[othIndex];
  1237. }
  1238. return result;
  1239. }
  1240. /**
  1241. * Copies the values of `source` to `array`.
  1242. *
  1243. * @private
  1244. * @param {Array} source The array to copy values from.
  1245. * @param {Array} [array=[]] The array to copy values to.
  1246. * @returns {Array} Returns `array`.
  1247. */
  1248. function arrayCopy(source, array) {
  1249. var index = -1,
  1250. length = source.length;
  1251. array || (array = Array(length));
  1252. while (++index < length) {
  1253. array[index] = source[index];
  1254. }
  1255. return array;
  1256. }
  1257. /**
  1258. * A specialized version of `_.forEach` for arrays without support for callback
  1259. * shorthands and `this` binding.
  1260. *
  1261. * @private
  1262. * @param {Array} array The array to iterate over.
  1263. * @param {Function} iteratee The function invoked per iteration.
  1264. * @returns {Array} Returns `array`.
  1265. */
  1266. function arrayEach(array, iteratee) {
  1267. var index = -1,
  1268. length = array.length;
  1269. while (++index < length) {
  1270. if (iteratee(array[index], index, array) === false) {
  1271. break;
  1272. }
  1273. }
  1274. return array;
  1275. }
  1276. /**
  1277. * A specialized version of `_.forEachRight` for arrays without support for
  1278. * callback shorthands and `this` binding.
  1279. *
  1280. * @private
  1281. * @param {Array} array The array to iterate over.
  1282. * @param {Function} iteratee The function invoked per iteration.
  1283. * @returns {Array} Returns `array`.
  1284. */
  1285. function arrayEachRight(array, iteratee) {
  1286. var length = array.length;
  1287. while (length--) {
  1288. if (iteratee(array[length], length, array) === false) {
  1289. break;
  1290. }
  1291. }
  1292. return array;
  1293. }
  1294. /**
  1295. * A specialized version of `_.every` for arrays without support for callback
  1296. * shorthands and `this` binding.
  1297. *
  1298. * @private
  1299. * @param {Array} array The array to iterate over.
  1300. * @param {Function} predicate The function invoked per iteration.
  1301. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1302. * else `false`.
  1303. */
  1304. function arrayEvery(array, predicate) {
  1305. var index = -1,
  1306. length = array.length;
  1307. while (++index < length) {
  1308. if (!predicate(array[index], index, array)) {
  1309. return false;
  1310. }
  1311. }
  1312. return true;
  1313. }
  1314. /**
  1315. * A specialized version of `baseExtremum` for arrays which invokes `iteratee`
  1316. * with one argument: (value).
  1317. *
  1318. * @private
  1319. * @param {Array} array The array to iterate over.
  1320. * @param {Function} iteratee The function invoked per iteration.
  1321. * @param {Function} comparator The function used to compare values.
  1322. * @param {*} exValue The initial extremum value.
  1323. * @returns {*} Returns the extremum value.
  1324. */
  1325. function arrayExtremum(array, iteratee, comparator, exValue) {
  1326. var index = -1,
  1327. length = array.length,
  1328. computed = exValue,
  1329. result = computed;
  1330. while (++index < length) {
  1331. var value = array[index],
  1332. current = +iteratee(value);
  1333. if (comparator(current, computed)) {
  1334. computed = current;
  1335. result = value;
  1336. }
  1337. }
  1338. return result;
  1339. }
  1340. /**
  1341. * A specialized version of `_.filter` for arrays without support for callback
  1342. * shorthands and `this` binding.
  1343. *
  1344. * @private
  1345. * @param {Array} array The array to iterate over.
  1346. * @param {Function} predicate The function invoked per iteration.
  1347. * @returns {Array} Returns the new filtered array.
  1348. */
  1349. function arrayFilter(array, predicate) {
  1350. var index = -1,
  1351. length = array.length,
  1352. resIndex = -1,
  1353. result = [];
  1354. while (++index < length) {
  1355. var value = array[index];
  1356. if (predicate(value, index, array)) {
  1357. result[++resIndex] = value;
  1358. }
  1359. }
  1360. return result;
  1361. }
  1362. /**
  1363. * A specialized version of `_.map` for arrays without support for callback
  1364. * shorthands and `this` binding.
  1365. *
  1366. * @private
  1367. * @param {Array} array The array to iterate over.
  1368. * @param {Function} iteratee The function invoked per iteration.
  1369. * @returns {Array} Returns the new mapped array.
  1370. */
  1371. function arrayMap(array, iteratee) {
  1372. var index = -1,
  1373. length = array.length,
  1374. result = Array(length);
  1375. while (++index < length) {
  1376. result[index] = iteratee(array[index], index, array);
  1377. }
  1378. return result;
  1379. }
  1380. /**
  1381. * Appends the elements of `values` to `array`.
  1382. *
  1383. * @private
  1384. * @param {Array} array The array to modify.
  1385. * @param {Array} values The values to append.
  1386. * @returns {Array} Returns `array`.
  1387. */
  1388. function arrayPush(array, values) {
  1389. var index = -1,
  1390. length = values.length,
  1391. offset = array.length;
  1392. while (++index < length) {
  1393. array[offset + index] = values[index];
  1394. }
  1395. return array;
  1396. }
  1397. /**
  1398. * A specialized version of `_.reduce` for arrays without support for callback
  1399. * shorthands and `this` binding.
  1400. *
  1401. * @private
  1402. * @param {Array} array The array to iterate over.
  1403. * @param {Function} iteratee The function invoked per iteration.
  1404. * @param {*} [accumulator] The initial value.
  1405. * @param {boolean} [initFromArray] Specify using the first element of `array`
  1406. * as the initial value.
  1407. * @returns {*} Returns the accumulated value.
  1408. */
  1409. function arrayReduce(array, iteratee, accumulator, initFromArray) {
  1410. var index = -1,
  1411. length = array.length;
  1412. if (initFromArray && length) {
  1413. accumulator = array[++index];
  1414. }
  1415. while (++index < length) {
  1416. accumulator = iteratee(accumulator, array[index], index, array);
  1417. }
  1418. return accumulator;
  1419. }
  1420. /**
  1421. * A specialized version of `_.reduceRight` for arrays without support for
  1422. * callback shorthands and `this` binding.
  1423. *
  1424. * @private
  1425. * @param {Array} array The array to iterate over.
  1426. * @param {Function} iteratee The function invoked per iteration.
  1427. * @param {*} [accumulator] The initial value.
  1428. * @param {boolean} [initFromArray] Specify using the last element of `array`
  1429. * as the initial value.
  1430. * @returns {*} Returns the accumulated value.
  1431. */
  1432. function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
  1433. var length = array.length;
  1434. if (initFromArray && length) {
  1435. accumulator = array[--length];
  1436. }
  1437. while (length--) {
  1438. accumulator = iteratee(accumulator, array[length], length, array);
  1439. }
  1440. return accumulator;
  1441. }
  1442. /**
  1443. * A specialized version of `_.some` for arrays without support for callback
  1444. * shorthands and `this` binding.
  1445. *
  1446. * @private
  1447. * @param {Array} array The array to iterate over.
  1448. * @param {Function} predicate The function invoked per iteration.
  1449. * @returns {boolean} Returns `true` if any element passes the predicate check,
  1450. * else `false`.
  1451. */
  1452. function arraySome(array, predicate) {
  1453. var index = -1,
  1454. length = array.length;
  1455. while (++index < length) {
  1456. if (predicate(array[index], index, array)) {
  1457. return true;
  1458. }
  1459. }
  1460. return false;
  1461. }
  1462. /**
  1463. * A specialized version of `_.sum` for arrays without support for callback
  1464. * shorthands and `this` binding..
  1465. *
  1466. * @private
  1467. * @param {Array} array The array to iterate over.
  1468. * @param {Function} iteratee The function invoked per iteration.
  1469. * @returns {number} Returns the sum.
  1470. */
  1471. function arraySum(array, iteratee) {
  1472. var length = array.length,
  1473. result = 0;
  1474. while (length--) {
  1475. result += +iteratee(array[length]) || 0;
  1476. }
  1477. return result;
  1478. }
  1479. /**
  1480. * Used by `_.defaults` to customize its `_.assign` use.
  1481. *
  1482. * @private
  1483. * @param {*} objectValue The destination object property value.
  1484. * @param {*} sourceValue The source object property value.
  1485. * @returns {*} Returns the value to assign to the destination object.
  1486. */
  1487. function assignDefaults(objectValue, sourceValue) {
  1488. return objectValue === undefined ? sourceValue : objectValue;
  1489. }
  1490. /**
  1491. * Used by `_.template` to customize its `_.assign` use.
  1492. *
  1493. * **Note:** This function is like `assignDefaults` except that it ignores
  1494. * inherited property values when checking if a property is `undefined`.
  1495. *
  1496. * @private
  1497. * @param {*} objectValue The destination object property value.
  1498. * @param {*} sourceValue The source object property value.
  1499. * @param {string} key The key associated with the object and source values.
  1500. * @param {Object} object The destination object.
  1501. * @returns {*} Returns the value to assign to the destination object.
  1502. */
  1503. function assignOwnDefaults(objectValue, sourceValue, key, object) {
  1504. return (objectValue === undefined || !hasOwnProperty.call(object, key))
  1505. ? sourceValue
  1506. : objectValue;
  1507. }
  1508. /**
  1509. * A specialized version of `_.assign` for customizing assigned values without
  1510. * support for argument juggling, multiple sources, and `this` binding `customizer`
  1511. * functions.
  1512. *
  1513. * @private
  1514. * @param {Object} object The destination object.
  1515. * @param {Object} source The source object.
  1516. * @param {Function} customizer The function to customize assigned values.
  1517. * @returns {Object} Returns `object`.
  1518. */
  1519. function assignWith(object, source, customizer) {
  1520. var index = -1,
  1521. props = keys(source),
  1522. length = props.length;
  1523. while (++index < length) {
  1524. var key = props[index],
  1525. value = object[key],
  1526. result = customizer(value, source[key], key, object, source);
  1527. if ((result === result ? (result !== value) : (value === value)) ||
  1528. (value === undefined && !(key in object))) {
  1529. object[key] = result;
  1530. }
  1531. }
  1532. return object;
  1533. }
  1534. /**
  1535. * The base implementation of `_.assign` without support for argument juggling,
  1536. * multiple sources, and `customizer` functions.
  1537. *
  1538. * @private
  1539. * @param {Object} object The destination object.
  1540. * @param {Object} source The source object.
  1541. * @returns {Object} Returns `object`.
  1542. */
  1543. function baseAssign(object, source) {
  1544. return source == null
  1545. ? object
  1546. : baseCopy(source, keys(source), object);
  1547. }
  1548. /**
  1549. * The base implementation of `_.at` without support for string collections
  1550. * and individual key arguments.
  1551. *
  1552. * @private
  1553. * @param {Array|Object} collection The collection to iterate over.
  1554. * @param {number[]|string[]} props The property names or indexes of elements to pick.
  1555. * @returns {Array} Returns the new array of picked elements.
  1556. */
  1557. function baseAt(collection, props) {
  1558. var index = -1,
  1559. isNil = collection == null,
  1560. isArr = !isNil && isArrayLike(collection),
  1561. length = isArr ? collection.length : 0,
  1562. propsLength = props.length,
  1563. result = Array(propsLength);
  1564. while(++index < propsLength) {
  1565. var key = props[index];
  1566. if (isArr) {
  1567. result[index] = isIndex(key, length) ? collection[key] : undefined;
  1568. } else {
  1569. result[index] = isNil ? undefined : collection[key];
  1570. }
  1571. }
  1572. return result;
  1573. }
  1574. /**
  1575. * Copies properties of `source` to `object`.
  1576. *
  1577. * @private
  1578. * @param {Object} source The object to copy properties from.
  1579. * @param {Array} props The property names to copy.
  1580. * @param {Object} [object={}] The object to copy properties to.
  1581. * @returns {Object} Returns `object`.
  1582. */
  1583. function baseCopy(source, props, object) {
  1584. object || (object = {});
  1585. var index = -1,
  1586. length = props.length;
  1587. while (++index < length) {
  1588. var key = props[index];
  1589. object[key] = source[key];
  1590. }
  1591. return object;
  1592. }
  1593. /**
  1594. * The base implementation of `_.callback` which supports specifying the
  1595. * number of arguments to provide to `func`.
  1596. *
  1597. * @private
  1598. * @param {*} [func=_.identity] The value to convert to a callback.
  1599. * @param {*} [thisArg] The `this` binding of `func`.
  1600. * @param {number} [argCount] The number of arguments to provide to `func`.
  1601. * @returns {Function} Returns the callback.
  1602. */
  1603. function baseCallback(func, thisArg, argCount) {
  1604. var type = typeof func;
  1605. if (type == 'function') {
  1606. return thisArg === undefined
  1607. ? func
  1608. : bindCallback(func, thisArg, argCount);
  1609. }
  1610. if (func == null) {
  1611. return identity;
  1612. }
  1613. if (type == 'object') {
  1614. return baseMatches(func);
  1615. }
  1616. return thisArg === undefined
  1617. ? property(func)
  1618. : baseMatchesProperty(func, thisArg);
  1619. }
  1620. /**
  1621. * The base implementation of `_.clone` without support for argument juggling
  1622. * and `this` binding `customizer` functions.
  1623. *
  1624. * @private
  1625. * @param {*} value The value to clone.
  1626. * @param {boolean} [isDeep] Specify a deep clone.
  1627. * @param {Function} [customizer] The function to customize cloning values.
  1628. * @param {string} [key] The key of `value`.
  1629. * @param {Object} [object] The object `value` belongs to.
  1630. * @param {Array} [stackA=[]] Tracks traversed source objects.
  1631. * @param {Array} [stackB=[]] Associates clones with source counterparts.
  1632. * @returns {*} Returns the cloned value.
  1633. */
  1634. function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
  1635. var result;
  1636. if (customizer) {
  1637. result = object ? customizer(value, key, object) : customizer(value);
  1638. }
  1639. if (result !== undefined) {
  1640. return result;
  1641. }
  1642. if (!isObject(value)) {
  1643. return value;
  1644. }
  1645. var isArr = isArray(value);
  1646. if (isArr) {
  1647. result = initCloneArray(value);
  1648. if (!isDeep) {
  1649. return arrayCopy(value, result);
  1650. }
  1651. } else {
  1652. var tag = objToString.call(value),
  1653. isFunc = tag == funcTag;
  1654. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  1655. if (isHostObject(value)) {
  1656. return object ? value : {};
  1657. }
  1658. result = initCloneObject(isFunc ? {} : value);
  1659. if (!isDeep) {
  1660. return baseAssign(result, value);
  1661. }
  1662. } else {
  1663. return cloneableTags[tag]
  1664. ? initCloneByTag(value, tag, isDeep)
  1665. : (object ? value : {});
  1666. }
  1667. }
  1668. // Check for circular references and return its corresponding clone.
  1669. stackA || (stackA = []);
  1670. stackB || (stackB = []);
  1671. var length = stackA.length;
  1672. while (length--) {
  1673. if (stackA[length] == value) {
  1674. return stackB[length];
  1675. }
  1676. }
  1677. // Add the source value to the stack of traversed objects and associate it with its clone.
  1678. stackA.push(value);
  1679. stackB.push(result);
  1680. // Recursively populate clone (susceptible to call stack limits).
  1681. (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
  1682. result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
  1683. });
  1684. return result;
  1685. }
  1686. /**
  1687. * The base implementation of `_.create` without support for assigning
  1688. * properties to the created object.
  1689. *
  1690. * @private
  1691. * @param {Object} prototype The object to inherit from.
  1692. * @returns {Object} Returns the new object.
  1693. */
  1694. var baseCreate = (function() {
  1695. function object() {}
  1696. return function(prototype) {
  1697. if (isObject(prototype)) {
  1698. object.prototype = prototype;
  1699. var result = new object;
  1700. object.prototype = undefined;
  1701. }
  1702. return result || {};
  1703. };
  1704. }());
  1705. /**
  1706. * The base implementation of `_.delay` and `_.defer` which accepts an index
  1707. * of where to slice the arguments to provide to `func`.
  1708. *
  1709. * @private
  1710. * @param {Function} func The function to delay.
  1711. * @param {number} wait The number of milliseconds to delay invocation.
  1712. * @param {Object} args The arguments provide to `func`.
  1713. * @returns {number} Returns the timer id.
  1714. */
  1715. function baseDelay(func, wait, args) {
  1716. if (typeof func != 'function') {
  1717. throw new TypeError(FUNC_ERROR_TEXT);
  1718. }
  1719. return setTimeout(function() { func.apply(undefined, args); }, wait);
  1720. }
  1721. /**
  1722. * The base implementation of `_.difference` which accepts a single array
  1723. * of values to exclude.
  1724. *
  1725. * @private
  1726. * @param {Array} array The array to inspect.
  1727. * @param {Array} values The values to exclude.
  1728. * @returns {Array} Returns the new array of filtered values.
  1729. */
  1730. function baseDifference(array, values) {
  1731. var length = array ? array.length : 0,
  1732. result = [];
  1733. if (!length) {
  1734. return result;
  1735. }
  1736. var index = -1,
  1737. indexOf = getIndexOf(),
  1738. isCommon = indexOf === baseIndexOf,
  1739. cache = (isCommon && values.length >= LARGE_ARRAY_SIZE) ? createCache(values) : null,
  1740. valuesLength = values.length;
  1741. if (cache) {
  1742. indexOf = cacheIndexOf;
  1743. isCommon = false;
  1744. values = cache;
  1745. }
  1746. outer:
  1747. while (++index < length) {
  1748. var value = array[index];
  1749. if (isCommon && value === value) {
  1750. var valuesIndex = valuesLength;
  1751. while (valuesIndex--) {
  1752. if (values[valuesIndex] === value) {
  1753. continue outer;
  1754. }
  1755. }
  1756. result.push(value);
  1757. }
  1758. else if (indexOf(values, value, 0) < 0) {
  1759. result.push(value);
  1760. }
  1761. }
  1762. return result;
  1763. }
  1764. /**
  1765. * The base implementation of `_.forEach` without support for callback
  1766. * shorthands and `this` binding.
  1767. *
  1768. * @private
  1769. * @param {Array|Object|string} collection The collection to iterate over.
  1770. * @param {Function} iteratee The function invoked per iteration.
  1771. * @returns {Array|Object|string} Returns `collection`.
  1772. */
  1773. var baseEach = createBaseEach(baseForOwn);
  1774. /**
  1775. * The base implementation of `_.forEachRight` without support for callback
  1776. * shorthands and `this` binding.
  1777. *
  1778. * @private
  1779. * @param {Array|Object|string} collection The collection to iterate over.
  1780. * @param {Function} iteratee The function invoked per iteration.
  1781. * @returns {Array|Object|string} Returns `collection`.
  1782. */
  1783. var baseEachRight = createBaseEach(baseForOwnRight, true);
  1784. /**
  1785. * The base implementation of `_.every` without support for callback
  1786. * shorthands and `this` binding.
  1787. *
  1788. * @private
  1789. * @param {Array|Object|string} collection The collection to iterate over.
  1790. * @param {Function} predicate The function invoked per iteration.
  1791. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1792. * else `false`
  1793. */
  1794. function baseEvery(collection, predicate) {
  1795. var result = true;
  1796. baseEach(collection, function(value, index, collection) {
  1797. result = !!predicate(value, index, collection);
  1798. return result;
  1799. });
  1800. return result;
  1801. }
  1802. /**
  1803. * Gets the extremum value of `collection` invoking `iteratee` for each value
  1804. * in `collection` to generate the criterion by which the value is ranked.
  1805. * The `iteratee` is invoked with three arguments: (value, index|key, collection).
  1806. *
  1807. * @private
  1808. * @param {Array|Object|string} collection The collection to iterate over.
  1809. * @param {Function} iteratee The function invoked per iteration.
  1810. * @param {Function} comparator The function used to compare values.
  1811. * @param {*} exValue The initial extremum value.
  1812. * @returns {*} Returns the extremum value.
  1813. */
  1814. function baseExtremum(collection, iteratee, comparator, exValue) {
  1815. var computed = exValue,
  1816. result = computed;
  1817. baseEach(collection, function(value, index, collection) {
  1818. var current = +iteratee(value, index, collection);
  1819. if (comparator(current, computed) || (current === exValue && current === result)) {
  1820. computed = current;
  1821. result = value;
  1822. }
  1823. });
  1824. return result;
  1825. }
  1826. /**
  1827. * The base implementation of `_.fill` without an iteratee call guard.
  1828. *
  1829. * @private
  1830. * @param {Array} array The array to fill.
  1831. * @param {*} value The value to fill `array` with.
  1832. * @param {number} [start=0] The start position.
  1833. * @param {number} [end=array.length] The end position.
  1834. * @returns {Array} Returns `array`.
  1835. */
  1836. function baseFill(array, value, start, end) {
  1837. var length = array.length;
  1838. start = start == null ? 0 : (+start || 0);
  1839. if (start < 0) {
  1840. start = -start > length ? 0 : (length + start);
  1841. }
  1842. end = (end === undefined || end > length) ? length : (+end || 0);
  1843. if (end < 0) {
  1844. end += length;
  1845. }
  1846. length = start > end ? 0 : (end >>> 0);
  1847. start >>>= 0;
  1848. while (start < length) {
  1849. array[start++] = value;
  1850. }
  1851. return array;
  1852. }
  1853. /**
  1854. * The base implementation of `_.filter` without support for callback
  1855. * shorthands and `this` binding.
  1856. *
  1857. * @private
  1858. * @param {Array|Object|string} collection The collection to iterate over.
  1859. * @param {Function} predicate The function invoked per iteration.
  1860. * @returns {Array} Returns the new filtered array.
  1861. */
  1862. function baseFilter(collection, predicate) {
  1863. var result = [];
  1864. baseEach(collection, function(value, index, collection) {
  1865. if (predicate(value, index, collection)) {
  1866. result.push(value);
  1867. }
  1868. });
  1869. return result;
  1870. }
  1871. /**
  1872. * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
  1873. * without support for callback shorthands and `this` binding, which iterates
  1874. * over `collection` using the provided `eachFunc`.
  1875. *
  1876. * @private
  1877. * @param {Array|Object|string} collection The collection to search.
  1878. * @param {Function} predicate The function invoked per iteration.
  1879. * @param {Function} eachFunc The function to iterate over `collection`.
  1880. * @param {boolean} [retKey] Specify returning the key of the found element
  1881. * instead of the element itself.
  1882. * @returns {*} Returns the found element or its key, else `undefined`.
  1883. */
  1884. function baseFind(collection, predicate, eachFunc, retKey) {
  1885. var result;
  1886. eachFunc(collection, function(value, key, collection) {
  1887. if (predicate(value, key, collection)) {
  1888. result = retKey ? key : value;
  1889. return false;
  1890. }
  1891. });
  1892. return result;
  1893. }
  1894. /**
  1895. * The base implementation of `_.flatten` with added support for restricting
  1896. * flattening and specifying the start index.
  1897. *
  1898. * @private
  1899. * @param {Array} array The array to flatten.
  1900. * @param {boolean} [isDeep] Specify a deep flatten.
  1901. * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
  1902. * @param {Array} [result=[]] The initial result value.
  1903. * @returns {Array} Returns the new flattened array.
  1904. */
  1905. function baseFlatten(array, isDeep, isStrict, result) {
  1906. result || (result = []);
  1907. var index = -1,
  1908. length = array.length;
  1909. while (++index < length) {
  1910. var value = array[index];
  1911. if (isObjectLike(value) && isArrayLike(value) &&
  1912. (isStrict || isArray(value) || isArguments(value))) {
  1913. if (isDeep) {
  1914. // Recursively flatten arrays (susceptible to call stack limits).
  1915. baseFlatten(value, isDeep, isStrict, result);
  1916. } else {
  1917. arrayPush(result, value);
  1918. }
  1919. } else if (!isStrict) {
  1920. result[result.length] = value;
  1921. }
  1922. }
  1923. return result;
  1924. }
  1925. /**
  1926. * The base implementation of `baseForIn` and `baseForOwn` which iterates
  1927. * over `object` properties returned by `keysFunc` invoking `iteratee` for
  1928. * each property. Iteratee functions may exit iteration early by explicitly
  1929. * returning `false`.
  1930. *
  1931. * @private
  1932. * @param {Object} object The object to iterate over.
  1933. * @param {Function} iteratee The function invoked per iteration.
  1934. * @param {Function} keysFunc The function to get the keys of `object`.
  1935. * @returns {Object} Returns `object`.
  1936. */
  1937. var baseFor = createBaseFor();
  1938. /**
  1939. * This function is like `baseFor` except that it iterates over properties
  1940. * in the opposite order.
  1941. *
  1942. * @private
  1943. * @param {Object} object The object to iterate over.
  1944. * @param {Function} iteratee The function invoked per iteration.
  1945. * @param {Function} keysFunc The function to get the keys of `object`.
  1946. * @returns {Object} Returns `object`.
  1947. */
  1948. var baseForRight = createBaseFor(true);
  1949. /**
  1950. * The base implementation of `_.forIn` without support for callback
  1951. * shorthands and `this` binding.
  1952. *
  1953. * @private
  1954. * @param {Object} object The object to iterate over.
  1955. * @param {Function} iteratee The function invoked per iteration.
  1956. * @returns {Object} Returns `object`.
  1957. */
  1958. function baseForIn(object, iteratee) {
  1959. return baseFor(object, iteratee, keysIn);
  1960. }
  1961. /**
  1962. * The base implementation of `_.forOwn` without support for callback
  1963. * shorthands and `this` binding.
  1964. *
  1965. * @private
  1966. * @param {Object} object The object to iterate over.
  1967. * @param {Function} iteratee The function invoked per iteration.
  1968. * @returns {Object} Returns `object`.
  1969. */
  1970. function baseForOwn(object, iteratee) {
  1971. return baseFor(object, iteratee, keys);
  1972. }
  1973. /**
  1974. * The base implementation of `_.forOwnRight` without support for callback
  1975. * shorthands and `this` binding.
  1976. *
  1977. * @private
  1978. * @param {Object} object The object to iterate over.
  1979. * @param {Function} iteratee The function invoked per iteration.
  1980. * @returns {Object} Returns `object`.
  1981. */
  1982. function baseForOwnRight(object, iteratee) {
  1983. return baseForRight(object, iteratee, keys);
  1984. }
  1985. /**
  1986. * The base implementation of `_.functions` which creates an array of
  1987. * `object` function property names filtered from those provided.
  1988. *
  1989. * @private
  1990. * @param {Object} object The object to inspect.
  1991. * @param {Array} props The property names to filter.
  1992. * @returns {Array} Returns the new array of filtered property names.
  1993. */
  1994. function baseFunctions(object, props) {
  1995. var index = -1,
  1996. length = props.length,
  1997. resIndex = -1,
  1998. result = [];
  1999. while (++index < length) {
  2000. var key = props[index];
  2001. if (isFunction(object[key])) {
  2002. result[++resIndex] = key;
  2003. }
  2004. }
  2005. return result;
  2006. }
  2007. /**
  2008. * The base implementation of `get` without support for string paths
  2009. * and default values.
  2010. *
  2011. * @private
  2012. * @param {Object} object The object to query.
  2013. * @param {Array} path The path of the property to get.
  2014. * @param {string} [pathKey] The key representation of path.
  2015. * @returns {*} Returns the resolved value.
  2016. */
  2017. function baseGet(object, path, pathKey) {
  2018. if (object == null) {
  2019. return;
  2020. }
  2021. object = toObject(object);
  2022. if (pathKey !== undefined && pathKey in object) {
  2023. path = [pathKey];
  2024. }
  2025. var index = 0,
  2026. length = path.length;
  2027. while (object != null && index < length) {
  2028. object = toObject(object)[path[index++]];
  2029. }
  2030. return (index && index == length) ? object : undefined;
  2031. }
  2032. /**
  2033. * The base implementation of `_.isEqual` without support for `this` binding
  2034. * `customizer` functions.
  2035. *
  2036. * @private
  2037. * @param {*} value The value to compare.
  2038. * @param {*} other The other value to compare.
  2039. * @param {Function} [customizer] The function to customize comparing values.
  2040. * @param {boolean} [isLoose] Specify performing partial comparisons.
  2041. * @param {Array} [stackA] Tracks traversed `value` objects.
  2042. * @param {Array} [stackB] Tracks traversed `other` objects.
  2043. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2044. */
  2045. function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
  2046. if (value === other) {
  2047. return true;
  2048. }
  2049. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  2050. return value !== value && other !== other;
  2051. }
  2052. return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
  2053. }
  2054. /**
  2055. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2056. * deep comparisons and tracks traversed objects enabling objects with circular
  2057. * references to be compared.
  2058. *
  2059. * @private
  2060. * @param {Object} object The object to compare.
  2061. * @param {Object} other The other object to compare.
  2062. * @param {Function} equalFunc The function to determine equivalents of values.
  2063. * @param {Function} [customizer] The function to customize comparing objects.
  2064. * @param {boolean} [isLoose] Specify performing partial comparisons.
  2065. * @param {Array} [stackA=[]] Tracks traversed `value` objects.
  2066. * @param {Array} [stackB=[]] Tracks traversed `other` objects.
  2067. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2068. */
  2069. function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
  2070. var objIsArr = isArray(object),
  2071. othIsArr = isArray(other),
  2072. objTag = arrayTag,
  2073. othTag = arrayTag;
  2074. if (!objIsArr) {
  2075. objTag = objToString.call(object);
  2076. if (objTag == argsTag) {
  2077. objTag = objectTag;
  2078. } else if (objTag != objectTag) {
  2079. objIsArr = isTypedArray(object);
  2080. }
  2081. }
  2082. if (!othIsArr) {
  2083. othTag = objToString.call(other);
  2084. if (othTag == argsTag) {
  2085. othTag = objectTag;
  2086. } else if (othTag != objectTag) {
  2087. othIsArr = isTypedArray(other);
  2088. }
  2089. }
  2090. var objIsObj = objTag == objectTag && !isHostObject(object),
  2091. othIsObj = othTag == objectTag && !isHostObject(other),
  2092. isSameTag = objTag == othTag;
  2093. if (isSameTag && !(objIsArr || objIsObj)) {
  2094. return equalByTag(object, other, objTag);
  2095. }
  2096. if (!isLoose) {
  2097. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  2098. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  2099. if (objIsWrapped || othIsWrapped) {
  2100. return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
  2101. }
  2102. }
  2103. if (!isSameTag) {
  2104. return false;
  2105. }
  2106. // Assume cyclic values are equal.
  2107. // For more information on detecting circular references see https://es5.github.io/#JO.
  2108. stackA || (stackA = []);
  2109. stackB || (stackB = []);
  2110. var length = stackA.length;
  2111. while (length--) {
  2112. if (stackA[length] == object) {
  2113. return stackB[length] == other;
  2114. }
  2115. }
  2116. // Add `object` and `other` to the stack of traversed objects.
  2117. stackA.push(object);
  2118. stackB.push(other);
  2119. var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
  2120. stackA.pop();
  2121. stackB.pop();
  2122. return result;
  2123. }
  2124. /**
  2125. * The base implementation of `_.isMatch` without support for callback
  2126. * shorthands and `this` binding.
  2127. *
  2128. * @private
  2129. * @param {Object} object The object to inspect.
  2130. * @param {Array} matchData The propery names, values, and compare flags to match.
  2131. * @param {Function} [customizer] The function to customize comparing objects.
  2132. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  2133. */
  2134. function baseIsMatch(object, matchData, customizer) {
  2135. var index = matchData.length,
  2136. length = index,
  2137. noCustomizer = !customizer;
  2138. if (object == null) {
  2139. return !length;
  2140. }
  2141. object = toObject(object);
  2142. while (index--) {
  2143. var data = matchData[index];
  2144. if ((noCustomizer && data[2])
  2145. ? data[1] !== object[data[0]]
  2146. : !(data[0] in object)
  2147. ) {
  2148. return false;
  2149. }
  2150. }
  2151. while (++index < length) {
  2152. data = matchData[index];
  2153. var key = data[0],
  2154. objValue = object[key],
  2155. srcValue = data[1];
  2156. if (noCustomizer && data[2]) {
  2157. if (objValue === undefined && !(key in object)) {
  2158. return false;
  2159. }
  2160. } else {
  2161. var result = customizer ? customizer(objValue, srcValue, key) : undefined;
  2162. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
  2163. return false;
  2164. }
  2165. }
  2166. }
  2167. return true;
  2168. }
  2169. /**
  2170. * The base implementation of `_.map` without support for callback shorthands
  2171. * and `this` binding.
  2172. *
  2173. * @private
  2174. * @param {Array|Object|string} collection The collection to iterate over.
  2175. * @param {Function} iteratee The function invoked per iteration.
  2176. * @returns {Array} Returns the new mapped array.
  2177. */
  2178. function baseMap(collection, iteratee) {
  2179. var index = -1,
  2180. result = isArrayLike(collection) ? Array(collection.length) : [];
  2181. baseEach(collection, function(value, key, collection) {
  2182. result[++index] = iteratee(value, key, collection);
  2183. });
  2184. return result;
  2185. }
  2186. /**
  2187. * The base implementation of `_.matches` which does not clone `source`.
  2188. *
  2189. * @private
  2190. * @param {Object} source The object of property values to match.
  2191. * @returns {Function} Returns the new function.
  2192. */
  2193. function baseMatches(source) {
  2194. var matchData = getMatchData(source);
  2195. if (matchData.length == 1 && matchData[0][2]) {
  2196. var key = matchData[0][0],
  2197. value = matchData[0][1];
  2198. return function(object) {
  2199. if (object == null) {
  2200. return false;
  2201. }
  2202. object = toObject(object);
  2203. return object[key] === value && (value !== undefined || (key in object));
  2204. };
  2205. }
  2206. return function(object) {
  2207. return baseIsMatch(object, matchData);
  2208. };
  2209. }
  2210. /**
  2211. * The base implementation of `_.matchesProperty` which does not clone `srcValue`.
  2212. *
  2213. * @private
  2214. * @param {string} path The path of the property to get.
  2215. * @param {*} srcValue The value to compare.
  2216. * @returns {Function} Returns the new function.
  2217. */
  2218. function baseMatchesProperty(path, srcValue) {
  2219. var isArr = isArray(path),
  2220. isCommon = isKey(path) && isStrictComparable(srcValue),
  2221. pathKey = (path + '');
  2222. path = toPath(path);
  2223. return function(object) {
  2224. if (object == null) {
  2225. return false;
  2226. }
  2227. var key = pathKey;
  2228. object = toObject(object);
  2229. if ((isArr || !isCommon) && !(key in object)) {
  2230. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  2231. if (object == null) {
  2232. return false;
  2233. }
  2234. key = last(path);
  2235. object = toObject(object);
  2236. }
  2237. return object[key] === srcValue
  2238. ? (srcValue !== undefined || (key in object))
  2239. : baseIsEqual(srcValue, object[key], undefined, true);
  2240. };
  2241. }
  2242. /**
  2243. * The base implementation of `_.merge` without support for argument juggling,
  2244. * multiple sources, and `this` binding `customizer` functions.
  2245. *
  2246. * @private
  2247. * @param {Object} object The destination object.
  2248. * @param {Object} source The source object.
  2249. * @param {Function} [customizer] The function to customize merged values.
  2250. * @param {Array} [stackA=[]] Tracks traversed source objects.
  2251. * @param {Array} [stackB=[]] Associates values with source counterparts.
  2252. * @returns {Object} Returns `object`.
  2253. */
  2254. function baseMerge(object, source, customizer, stackA, stackB) {
  2255. if (!isObject(object)) {
  2256. return object;
  2257. }
  2258. var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
  2259. props = isSrcArr ? undefined : keys(source);
  2260. arrayEach(props || source, function(srcValue, key) {
  2261. if (props) {
  2262. key = srcValue;
  2263. srcValue = source[key];
  2264. }
  2265. if (isObjectLike(srcValue)) {
  2266. stackA || (stackA = []);
  2267. stackB || (stackB = []);
  2268. baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
  2269. }
  2270. else {
  2271. var value = object[key],
  2272. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  2273. isCommon = result === undefined;
  2274. if (isCommon) {
  2275. result = srcValue;
  2276. }
  2277. if ((result !== undefined || (isSrcArr && !(key in object))) &&
  2278. (isCommon || (result === result ? (result !== value) : (value === value)))) {
  2279. object[key] = result;
  2280. }
  2281. }
  2282. });
  2283. return object;
  2284. }
  2285. /**
  2286. * A specialized version of `baseMerge` for arrays and objects which performs
  2287. * deep merges and tracks traversed objects enabling objects with circular
  2288. * references to be merged.
  2289. *
  2290. * @private
  2291. * @param {Object} object The destination object.
  2292. * @param {Object} source The source object.
  2293. * @param {string} key The key of the value to merge.
  2294. * @param {Function} mergeFunc The function to merge values.
  2295. * @param {Function} [customizer] The function to customize merged values.
  2296. * @param {Array} [stackA=[]] Tracks traversed source objects.
  2297. * @param {Array} [stackB=[]] Associates values with source counterparts.
  2298. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2299. */
  2300. function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
  2301. var length = stackA.length,
  2302. srcValue = source[key];
  2303. while (length--) {
  2304. if (stackA[length] == srcValue) {
  2305. object[key] = stackB[length];
  2306. return;
  2307. }
  2308. }
  2309. var value = object[key],
  2310. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  2311. isCommon = result === undefined;
  2312. if (isCommon) {
  2313. result = srcValue;
  2314. if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
  2315. result = isArray(value)
  2316. ? value
  2317. : (isArrayLike(value) ? arrayCopy(value) : []);
  2318. }
  2319. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  2320. result = isArguments(value)
  2321. ? toPlainObject(value)
  2322. : (isPlainObject(value) ? value : {});
  2323. }
  2324. else {
  2325. isCommon = false;
  2326. }
  2327. }
  2328. // Add the source value to the stack of traversed objects and associate
  2329. // it with its merged value.
  2330. stackA.push(srcValue);
  2331. stackB.push(result);
  2332. if (isCommon) {
  2333. // Recursively merge objects and arrays (susceptible to call stack limits).
  2334. object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
  2335. } else if (result === result ? (result !== value) : (value === value)) {
  2336. object[key] = result;
  2337. }
  2338. }
  2339. /**
  2340. * The base implementation of `_.property` without support for deep paths.
  2341. *
  2342. * @private
  2343. * @param {string} key The key of the property to get.
  2344. * @returns {Function} Returns the new function.
  2345. */
  2346. function baseProperty(key) {
  2347. return function(object) {
  2348. return object == null ? undefined : toObject(object)[key];
  2349. };
  2350. }
  2351. /**
  2352. * A specialized version of `baseProperty` which supports deep paths.
  2353. *
  2354. * @private
  2355. * @param {Array|string} path The path of the property to get.
  2356. * @returns {Function} Returns the new function.
  2357. */
  2358. function basePropertyDeep(path) {
  2359. var pathKey = (path + '');
  2360. path = toPath(path);
  2361. return function(object) {
  2362. return baseGet(object, path, pathKey);
  2363. };
  2364. }
  2365. /**
  2366. * The base implementation of `_.pullAt` without support for individual
  2367. * index arguments and capturing the removed elements.
  2368. *
  2369. * @private
  2370. * @param {Array} array The array to modify.
  2371. * @param {number[]} indexes The indexes of elements to remove.
  2372. * @returns {Array} Returns `array`.
  2373. */
  2374. function basePullAt(array, indexes) {
  2375. var length = array ? indexes.length : 0;
  2376. while (length--) {
  2377. var index = indexes[length];
  2378. if (index != previous && isIndex(index)) {
  2379. var previous = index;
  2380. splice.call(array, index, 1);
  2381. }
  2382. }
  2383. return array;
  2384. }
  2385. /**
  2386. * The base implementation of `_.random` without support for argument juggling
  2387. * and returning floating-point numbers.
  2388. *
  2389. * @private
  2390. * @param {number} min The minimum possible value.
  2391. * @param {number} max The maximum possible value.
  2392. * @returns {number} Returns the random number.
  2393. */
  2394. function baseRandom(min, max) {
  2395. return min + nativeFloor(nativeRandom() * (max - min + 1));
  2396. }
  2397. /**
  2398. * The base implementation of `_.reduce` and `_.reduceRight` without support
  2399. * for callback shorthands and `this` binding, which iterates over `collection`
  2400. * using the provided `eachFunc`.
  2401. *
  2402. * @private
  2403. * @param {Array|Object|string} collection The collection to iterate over.
  2404. * @param {Function} iteratee The function invoked per iteration.
  2405. * @param {*} accumulator The initial value.
  2406. * @param {boolean} initFromCollection Specify using the first or last element
  2407. * of `collection` as the initial value.
  2408. * @param {Function} eachFunc The function to iterate over `collection`.
  2409. * @returns {*} Returns the accumulated value.
  2410. */
  2411. function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
  2412. eachFunc(collection, function(value, index, collection) {
  2413. accumulator = initFromCollection
  2414. ? (initFromCollection = false, value)
  2415. : iteratee(accumulator, value, index, collection);
  2416. });
  2417. return accumulator;
  2418. }
  2419. /**
  2420. * The base implementation of `setData` without support for hot loop detection.
  2421. *
  2422. * @private
  2423. * @param {Function} func The function to associate metadata with.
  2424. * @param {*} data The metadata.
  2425. * @returns {Function} Returns `func`.
  2426. */
  2427. var baseSetData = !metaMap ? identity : function(func, data) {
  2428. metaMap.set(func, data);
  2429. return func;
  2430. };
  2431. /**
  2432. * The base implementation of `_.slice` without an iteratee call guard.
  2433. *
  2434. * @private
  2435. * @param {Array} array The array to slice.
  2436. * @param {number} [start=0] The start position.
  2437. * @param {number} [end=array.length] The end position.
  2438. * @returns {Array} Returns the slice of `array`.
  2439. */
  2440. function baseSlice(array, start, end) {
  2441. var index = -1,
  2442. length = array.length;
  2443. start = start == null ? 0 : (+start || 0);
  2444. if (start < 0) {
  2445. start = -start > length ? 0 : (length + start);
  2446. }
  2447. end = (end === undefined || end > length) ? length : (+end || 0);
  2448. if (end < 0) {
  2449. end += length;
  2450. }
  2451. length = start > end ? 0 : ((end - start) >>> 0);
  2452. start >>>= 0;
  2453. var result = Array(length);
  2454. while (++index < length) {
  2455. result[index] = array[index + start];
  2456. }
  2457. return result;
  2458. }
  2459. /**
  2460. * The base implementation of `_.some` without support for callback shorthands
  2461. * and `this` binding.
  2462. *
  2463. * @private
  2464. * @param {Array|Object|string} collection The collection to iterate over.
  2465. * @param {Function} predicate The function invoked per iteration.
  2466. * @returns {boolean} Returns `true` if any element passes the predicate check,
  2467. * else `false`.
  2468. */
  2469. function baseSome(collection, predicate) {
  2470. var result;
  2471. baseEach(collection, function(value, index, collection) {
  2472. result = predicate(value, index, collection);
  2473. return !result;
  2474. });
  2475. return !!result;
  2476. }
  2477. /**
  2478. * The base implementation of `_.sortBy` which uses `comparer` to define
  2479. * the sort order of `array` and replaces criteria objects with their
  2480. * corresponding values.
  2481. *
  2482. * @private
  2483. * @param {Array} array The array to sort.
  2484. * @param {Function} comparer The function to define sort order.
  2485. * @returns {Array} Returns `array`.
  2486. */
  2487. function baseSortBy(array, comparer) {
  2488. var length = array.length;
  2489. array.sort(comparer);
  2490. while (length--) {
  2491. array[length] = array[length].value;
  2492. }
  2493. return array;
  2494. }
  2495. /**
  2496. * The base implementation of `_.sortByOrder` without param guards.
  2497. *
  2498. * @private
  2499. * @param {Array|Object|string} collection The collection to iterate over.
  2500. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  2501. * @param {boolean[]} orders The sort orders of `iteratees`.
  2502. * @returns {Array} Returns the new sorted array.
  2503. */
  2504. function baseSortByOrder(collection, iteratees, orders) {
  2505. var callback = getCallback(),
  2506. index = -1;
  2507. iteratees = arrayMap(iteratees, function(iteratee) { return callback(iteratee); });
  2508. var result = baseMap(collection, function(value) {
  2509. var criteria = arrayMap(iteratees, function(iteratee) { return iteratee(value); });
  2510. return { 'criteria': criteria, 'index': ++index, 'value': value };
  2511. });
  2512. return baseSortBy(result, function(object, other) {
  2513. return compareMultiple(object, other, orders);
  2514. });
  2515. }
  2516. /**
  2517. * The base implementation of `_.sum` without support for callback shorthands
  2518. * and `this` binding.
  2519. *
  2520. * @private
  2521. * @param {Array|Object|string} collection The collection to iterate over.
  2522. * @param {Function} iteratee The function invoked per iteration.
  2523. * @returns {number} Returns the sum.
  2524. */
  2525. function baseSum(collection, iteratee) {
  2526. var result = 0;
  2527. baseEach(collection, function(value, index, collection) {
  2528. result += +iteratee(value, index, collection) || 0;
  2529. });
  2530. return result;
  2531. }
  2532. /**
  2533. * The base implementation of `_.uniq` without support for callback shorthands
  2534. * and `this` binding.
  2535. *
  2536. * @private
  2537. * @param {Array} array The array to inspect.
  2538. * @param {Function} [iteratee] The function invoked per iteration.
  2539. * @returns {Array} Returns the new duplicate free array.
  2540. */
  2541. function baseUniq(array, iteratee) {
  2542. var index = -1,
  2543. indexOf = getIndexOf(),
  2544. length = array.length,
  2545. isCommon = indexOf === baseIndexOf,
  2546. isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
  2547. seen = isLarge ? createCache() : null,
  2548. result = [];
  2549. if (seen) {
  2550. indexOf = cacheIndexOf;
  2551. isCommon = false;
  2552. } else {
  2553. isLarge = false;
  2554. seen = iteratee ? [] : result;
  2555. }
  2556. outer:
  2557. while (++index < length) {
  2558. var value = array[index],
  2559. computed = iteratee ? iteratee(value, index, array) : value;
  2560. if (isCommon && value === value) {
  2561. var seenIndex = seen.length;
  2562. while (seenIndex--) {
  2563. if (seen[seenIndex] === computed) {
  2564. continue outer;
  2565. }
  2566. }
  2567. if (iteratee) {
  2568. seen.push(computed);
  2569. }
  2570. result.push(value);
  2571. }
  2572. else if (indexOf(seen, computed, 0) < 0) {
  2573. if (iteratee || isLarge) {
  2574. seen.push(computed);
  2575. }
  2576. result.push(value);
  2577. }
  2578. }
  2579. return result;
  2580. }
  2581. /**
  2582. * The base implementation of `_.values` and `_.valuesIn` which creates an
  2583. * array of `object` property values corresponding to the property names
  2584. * of `props`.
  2585. *
  2586. * @private
  2587. * @param {Object} object The object to query.
  2588. * @param {Array} props The property names to get values for.
  2589. * @returns {Object} Returns the array of property values.
  2590. */
  2591. function baseValues(object, props) {
  2592. var index = -1,
  2593. length = props.length,
  2594. result = Array(length);
  2595. while (++index < length) {
  2596. result[index] = object[props[index]];
  2597. }
  2598. return result;
  2599. }
  2600. /**
  2601. * The base implementation of `_.dropRightWhile`, `_.dropWhile`, `_.takeRightWhile`,
  2602. * and `_.takeWhile` without support for callback shorthands and `this` binding.
  2603. *
  2604. * @private
  2605. * @param {Array} array The array to query.
  2606. * @param {Function} predicate The function invoked per iteration.
  2607. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  2608. * @param {boolean} [fromRight] Specify iterating from right to left.
  2609. * @returns {Array} Returns the slice of `array`.
  2610. */
  2611. function baseWhile(array, predicate, isDrop, fromRight) {
  2612. var length = array.length,
  2613. index = fromRight ? length : -1;
  2614. while ((fromRight ? index-- : ++index < length) && predicate(array[index], index, array)) {}
  2615. return isDrop
  2616. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  2617. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  2618. }
  2619. /**
  2620. * The base implementation of `wrapperValue` which returns the result of
  2621. * performing a sequence of actions on the unwrapped `value`, where each
  2622. * successive action is supplied the return value of the previous.
  2623. *
  2624. * @private
  2625. * @param {*} value The unwrapped value.
  2626. * @param {Array} actions Actions to peform to resolve the unwrapped value.
  2627. * @returns {*} Returns the resolved value.
  2628. */
  2629. function baseWrapperValue(value, actions) {
  2630. var result = value;
  2631. if (result instanceof LazyWrapper) {
  2632. result = result.value();
  2633. }
  2634. var index = -1,
  2635. length = actions.length;
  2636. while (++index < length) {
  2637. var action = actions[index];
  2638. result = action.func.apply(action.thisArg, arrayPush([result], action.args));
  2639. }
  2640. return result;
  2641. }
  2642. /**
  2643. * Performs a binary search of `array` to determine the index at which `value`
  2644. * should be inserted into `array` in order to maintain its sort order.
  2645. *
  2646. * @private
  2647. * @param {Array} array The sorted array to inspect.
  2648. * @param {*} value The value to evaluate.
  2649. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  2650. * @returns {number} Returns the index at which `value` should be inserted
  2651. * into `array`.
  2652. */
  2653. function binaryIndex(array, value, retHighest) {
  2654. var low = 0,
  2655. high = array ? array.length : low;
  2656. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  2657. while (low < high) {
  2658. var mid = (low + high) >>> 1,
  2659. computed = array[mid];
  2660. if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
  2661. low = mid + 1;
  2662. } else {
  2663. high = mid;
  2664. }
  2665. }
  2666. return high;
  2667. }
  2668. return binaryIndexBy(array, value, identity, retHighest);
  2669. }
  2670. /**
  2671. * This function is like `binaryIndex` except that it invokes `iteratee` for
  2672. * `value` and each element of `array` to compute their sort ranking. The
  2673. * iteratee is invoked with one argument; (value).
  2674. *
  2675. * @private
  2676. * @param {Array} array The sorted array to inspect.
  2677. * @param {*} value The value to evaluate.
  2678. * @param {Function} iteratee The function invoked per iteration.
  2679. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  2680. * @returns {number} Returns the index at which `value` should be inserted
  2681. * into `array`.
  2682. */
  2683. function binaryIndexBy(array, value, iteratee, retHighest) {
  2684. value = iteratee(value);
  2685. var low = 0,
  2686. high = array ? array.length : 0,
  2687. valIsNaN = value !== value,
  2688. valIsNull = value === null,
  2689. valIsUndef = value === undefined;
  2690. while (low < high) {
  2691. var mid = nativeFloor((low + high) / 2),
  2692. computed = iteratee(array[mid]),
  2693. isDef = computed !== undefined,
  2694. isReflexive = computed === computed;
  2695. if (valIsNaN) {
  2696. var setLow = isReflexive || retHighest;
  2697. } else if (valIsNull) {
  2698. setLow = isReflexive && isDef && (retHighest || computed != null);
  2699. } else if (valIsUndef) {
  2700. setLow = isReflexive && (retHighest || isDef);
  2701. } else if (computed == null) {
  2702. setLow = false;
  2703. } else {
  2704. setLow = retHighest ? (computed <= value) : (computed < value);
  2705. }
  2706. if (setLow) {
  2707. low = mid + 1;
  2708. } else {
  2709. high = mid;
  2710. }
  2711. }
  2712. return nativeMin(high, MAX_ARRAY_INDEX);
  2713. }
  2714. /**
  2715. * A specialized version of `baseCallback` which only supports `this` binding
  2716. * and specifying the number of arguments to provide to `func`.
  2717. *
  2718. * @private
  2719. * @param {Function} func The function to bind.
  2720. * @param {*} thisArg The `this` binding of `func`.
  2721. * @param {number} [argCount] The number of arguments to provide to `func`.
  2722. * @returns {Function} Returns the callback.
  2723. */
  2724. function bindCallback(func, thisArg, argCount) {
  2725. if (typeof func != 'function') {
  2726. return identity;
  2727. }
  2728. if (thisArg === undefined) {
  2729. return func;
  2730. }
  2731. switch (argCount) {
  2732. case 1: return function(value) {
  2733. return func.call(thisArg, value);
  2734. };
  2735. case 3: return function(value, index, collection) {
  2736. return func.call(thisArg, value, index, collection);
  2737. };
  2738. case 4: return function(accumulator, value, index, collection) {
  2739. return func.call(thisArg, accumulator, value, index, collection);
  2740. };
  2741. case 5: return function(value, other, key, object, source) {
  2742. return func.call(thisArg, value, other, key, object, source);
  2743. };
  2744. }
  2745. return function() {
  2746. return func.apply(thisArg, arguments);
  2747. };
  2748. }
  2749. /**
  2750. * Creates a clone of the given array buffer.
  2751. *
  2752. * @private
  2753. * @param {ArrayBuffer} buffer The array buffer to clone.
  2754. * @returns {ArrayBuffer} Returns the cloned array buffer.
  2755. */
  2756. function bufferClone(buffer) {
  2757. var result = new ArrayBuffer(buffer.byteLength),
  2758. view = new Uint8Array(result);
  2759. view.set(new Uint8Array(buffer));
  2760. return result;
  2761. }
  2762. /**
  2763. * Creates an array that is the composition of partially applied arguments,
  2764. * placeholders, and provided arguments into a single array of arguments.
  2765. *
  2766. * @private
  2767. * @param {Array|Object} args The provided arguments.
  2768. * @param {Array} partials The arguments to prepend to those provided.
  2769. * @param {Array} holders The `partials` placeholder indexes.
  2770. * @returns {Array} Returns the new array of composed arguments.
  2771. */
  2772. function composeArgs(args, partials, holders) {
  2773. var holdersLength = holders.length,
  2774. argsIndex = -1,
  2775. argsLength = nativeMax(args.length - holdersLength, 0),
  2776. leftIndex = -1,
  2777. leftLength = partials.length,
  2778. result = Array(leftLength + argsLength);
  2779. while (++leftIndex < leftLength) {
  2780. result[leftIndex] = partials[leftIndex];
  2781. }
  2782. while (++argsIndex < holdersLength) {
  2783. result[holders[argsIndex]] = args[argsIndex];
  2784. }
  2785. while (argsLength--) {
  2786. result[leftIndex++] = args[argsIndex++];
  2787. }
  2788. return result;
  2789. }
  2790. /**
  2791. * This function is like `composeArgs` except that the arguments composition
  2792. * is tailored for `_.partialRight`.
  2793. *
  2794. * @private
  2795. * @param {Array|Object} args The provided arguments.
  2796. * @param {Array} partials The arguments to append to those provided.
  2797. * @param {Array} holders The `partials` placeholder indexes.
  2798. * @returns {Array} Returns the new array of composed arguments.
  2799. */
  2800. function composeArgsRight(args, partials, holders) {
  2801. var holdersIndex = -1,
  2802. holdersLength = holders.length,
  2803. argsIndex = -1,
  2804. argsLength = nativeMax(args.length - holdersLength, 0),
  2805. rightIndex = -1,
  2806. rightLength = partials.length,
  2807. result = Array(argsLength + rightLength);
  2808. while (++argsIndex < argsLength) {
  2809. result[argsIndex] = args[argsIndex];
  2810. }
  2811. var offset = argsIndex;
  2812. while (++rightIndex < rightLength) {
  2813. result[offset + rightIndex] = partials[rightIndex];
  2814. }
  2815. while (++holdersIndex < holdersLength) {
  2816. result[offset + holders[holdersIndex]] = args[argsIndex++];
  2817. }
  2818. return result;
  2819. }
  2820. /**
  2821. * Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
  2822. *
  2823. * @private
  2824. * @param {Function} setter The function to set keys and values of the accumulator object.
  2825. * @param {Function} [initializer] The function to initialize the accumulator object.
  2826. * @returns {Function} Returns the new aggregator function.
  2827. */
  2828. function createAggregator(setter, initializer) {
  2829. return function(collection, iteratee, thisArg) {
  2830. var result = initializer ? initializer() : {};
  2831. iteratee = getCallback(iteratee, thisArg, 3);
  2832. if (isArray(collection)) {
  2833. var index = -1,
  2834. length = collection.length;
  2835. while (++index < length) {
  2836. var value = collection[index];
  2837. setter(result, value, iteratee(value, index, collection), collection);
  2838. }
  2839. } else {
  2840. baseEach(collection, function(value, key, collection) {
  2841. setter(result, value, iteratee(value, key, collection), collection);
  2842. });
  2843. }
  2844. return result;
  2845. };
  2846. }
  2847. /**
  2848. * Creates a `_.assign`, `_.defaults`, or `_.merge` function.
  2849. *
  2850. * @private
  2851. * @param {Function} assigner The function to assign values.
  2852. * @returns {Function} Returns the new assigner function.
  2853. */
  2854. function createAssigner(assigner) {
  2855. return restParam(function(object, sources) {
  2856. var index = -1,
  2857. length = object == null ? 0 : sources.length,
  2858. customizer = length > 2 ? sources[length - 2] : undefined,
  2859. guard = length > 2 ? sources[2] : undefined,
  2860. thisArg = length > 1 ? sources[length - 1] : undefined;
  2861. if (typeof customizer == 'function') {
  2862. customizer = bindCallback(customizer, thisArg, 5);
  2863. length -= 2;
  2864. } else {
  2865. customizer = typeof thisArg == 'function' ? thisArg : undefined;
  2866. length -= (customizer ? 1 : 0);
  2867. }
  2868. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  2869. customizer = length < 3 ? undefined : customizer;
  2870. length = 1;
  2871. }
  2872. while (++index < length) {
  2873. var source = sources[index];
  2874. if (source) {
  2875. assigner(object, source, customizer);
  2876. }
  2877. }
  2878. return object;
  2879. });
  2880. }
  2881. /**
  2882. * Creates a `baseEach` or `baseEachRight` function.
  2883. *
  2884. * @private
  2885. * @param {Function} eachFunc The function to iterate over a collection.
  2886. * @param {boolean} [fromRight] Specify iterating from right to left.
  2887. * @returns {Function} Returns the new base function.
  2888. */
  2889. function createBaseEach(eachFunc, fromRight) {
  2890. return function(collection, iteratee) {
  2891. var length = collection ? getLength(collection) : 0;
  2892. if (!isLength(length)) {
  2893. return eachFunc(collection, iteratee);
  2894. }
  2895. var index = fromRight ? length : -1,
  2896. iterable = toObject(collection);
  2897. while ((fromRight ? index-- : ++index < length)) {
  2898. if (iteratee(iterable[index], index, iterable) === false) {
  2899. break;
  2900. }
  2901. }
  2902. return collection;
  2903. };
  2904. }
  2905. /**
  2906. * Creates a base function for `_.forIn` or `_.forInRight`.
  2907. *
  2908. * @private
  2909. * @param {boolean} [fromRight] Specify iterating from right to left.
  2910. * @returns {Function} Returns the new base function.
  2911. */
  2912. function createBaseFor(fromRight) {
  2913. return function(object, iteratee, keysFunc) {
  2914. var iterable = toObject(object),
  2915. props = keysFunc(object),
  2916. length = props.length,
  2917. index = fromRight ? length : -1;
  2918. while ((fromRight ? index-- : ++index < length)) {
  2919. var key = props[index];
  2920. if (iteratee(iterable[key], key, iterable) === false) {
  2921. break;
  2922. }
  2923. }
  2924. return object;
  2925. };
  2926. }
  2927. /**
  2928. * Creates a function that wraps `func` and invokes it with the `this`
  2929. * binding of `thisArg`.
  2930. *
  2931. * @private
  2932. * @param {Function} func The function to bind.
  2933. * @param {*} [thisArg] The `this` binding of `func`.
  2934. * @returns {Function} Returns the new bound function.
  2935. */
  2936. function createBindWrapper(func, thisArg) {
  2937. var Ctor = createCtorWrapper(func);
  2938. function wrapper() {
  2939. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  2940. return fn.apply(thisArg, arguments);
  2941. }
  2942. return wrapper;
  2943. }
  2944. /**
  2945. * Creates a `Set` cache object to optimize linear searches of large arrays.
  2946. *
  2947. * @private
  2948. * @param {Array} [values] The values to cache.
  2949. * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
  2950. */
  2951. function createCache(values) {
  2952. return (nativeCreate && Set) ? new SetCache(values) : null;
  2953. }
  2954. /**
  2955. * Creates a function that produces compound words out of the words in a
  2956. * given string.
  2957. *
  2958. * @private
  2959. * @param {Function} callback The function to combine each word.
  2960. * @returns {Function} Returns the new compounder function.
  2961. */
  2962. function createCompounder(callback) {
  2963. return function(string) {
  2964. var index = -1,
  2965. array = words(deburr(string)),
  2966. length = array.length,
  2967. result = '';
  2968. while (++index < length) {
  2969. result = callback(result, array[index], index);
  2970. }
  2971. return result;
  2972. };
  2973. }
  2974. /**
  2975. * Creates a function that produces an instance of `Ctor` regardless of
  2976. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  2977. *
  2978. * @private
  2979. * @param {Function} Ctor The constructor to wrap.
  2980. * @returns {Function} Returns the new wrapped function.
  2981. */
  2982. function createCtorWrapper(Ctor) {
  2983. return function() {
  2984. // Use a `switch` statement to work with class constructors.
  2985. // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  2986. // for more details.
  2987. var args = arguments;
  2988. switch (args.length) {
  2989. case 0: return new Ctor;
  2990. case 1: return new Ctor(args[0]);
  2991. case 2: return new Ctor(args[0], args[1]);
  2992. case 3: return new Ctor(args[0], args[1], args[2]);
  2993. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  2994. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  2995. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  2996. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  2997. }
  2998. var thisBinding = baseCreate(Ctor.prototype),
  2999. result = Ctor.apply(thisBinding, args);
  3000. // Mimic the constructor's `return` behavior.
  3001. // See https://es5.github.io/#x13.2.2 for more details.
  3002. return isObject(result) ? result : thisBinding;
  3003. };
  3004. }
  3005. /**
  3006. * Creates a `_.curry` or `_.curryRight` function.
  3007. *
  3008. * @private
  3009. * @param {boolean} flag The curry bit flag.
  3010. * @returns {Function} Returns the new curry function.
  3011. */
  3012. function createCurry(flag) {
  3013. function curryFunc(func, arity, guard) {
  3014. if (guard && isIterateeCall(func, arity, guard)) {
  3015. arity = undefined;
  3016. }
  3017. var result = createWrapper(func, flag, undefined, undefined, undefined, undefined, undefined, arity);
  3018. result.placeholder = curryFunc.placeholder;
  3019. return result;
  3020. }
  3021. return curryFunc;
  3022. }
  3023. /**
  3024. * Creates a `_.defaults` or `_.defaultsDeep` function.
  3025. *
  3026. * @private
  3027. * @param {Function} assigner The function to assign values.
  3028. * @param {Function} customizer The function to customize assigned values.
  3029. * @returns {Function} Returns the new defaults function.
  3030. */
  3031. function createDefaults(assigner, customizer) {
  3032. return restParam(function(args) {
  3033. var object = args[0];
  3034. if (object == null) {
  3035. return object;
  3036. }
  3037. args.push(customizer);
  3038. return assigner.apply(undefined, args);
  3039. });
  3040. }
  3041. /**
  3042. * Creates a `_.max` or `_.min` function.
  3043. *
  3044. * @private
  3045. * @param {Function} comparator The function used to compare values.
  3046. * @param {*} exValue The initial extremum value.
  3047. * @returns {Function} Returns the new extremum function.
  3048. */
  3049. function createExtremum(comparator, exValue) {
  3050. return function(collection, iteratee, thisArg) {
  3051. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  3052. iteratee = undefined;
  3053. }
  3054. iteratee = getCallback(iteratee, thisArg, 3);
  3055. if (iteratee.length == 1) {
  3056. collection = isArray(collection) ? collection : toIterable(collection);
  3057. var result = arrayExtremum(collection, iteratee, comparator, exValue);
  3058. if (!(collection.length && result === exValue)) {
  3059. return result;
  3060. }
  3061. }
  3062. return baseExtremum(collection, iteratee, comparator, exValue);
  3063. };
  3064. }
  3065. /**
  3066. * Creates a `_.find` or `_.findLast` function.
  3067. *
  3068. * @private
  3069. * @param {Function} eachFunc The function to iterate over a collection.
  3070. * @param {boolean} [fromRight] Specify iterating from right to left.
  3071. * @returns {Function} Returns the new find function.
  3072. */
  3073. function createFind(eachFunc, fromRight) {
  3074. return function(collection, predicate, thisArg) {
  3075. predicate = getCallback(predicate, thisArg, 3);
  3076. if (isArray(collection)) {
  3077. var index = baseFindIndex(collection, predicate, fromRight);
  3078. return index > -1 ? collection[index] : undefined;
  3079. }
  3080. return baseFind(collection, predicate, eachFunc);
  3081. };
  3082. }
  3083. /**
  3084. * Creates a `_.findIndex` or `_.findLastIndex` function.
  3085. *
  3086. * @private
  3087. * @param {boolean} [fromRight] Specify iterating from right to left.
  3088. * @returns {Function} Returns the new find function.
  3089. */
  3090. function createFindIndex(fromRight) {
  3091. return function(array, predicate, thisArg) {
  3092. if (!(array && array.length)) {
  3093. return -1;
  3094. }
  3095. predicate = getCallback(predicate, thisArg, 3);
  3096. return baseFindIndex(array, predicate, fromRight);
  3097. };
  3098. }
  3099. /**
  3100. * Creates a `_.findKey` or `_.findLastKey` function.
  3101. *
  3102. * @private
  3103. * @param {Function} objectFunc The function to iterate over an object.
  3104. * @returns {Function} Returns the new find function.
  3105. */
  3106. function createFindKey(objectFunc) {
  3107. return function(object, predicate, thisArg) {
  3108. predicate = getCallback(predicate, thisArg, 3);
  3109. return baseFind(object, predicate, objectFunc, true);
  3110. };
  3111. }
  3112. /**
  3113. * Creates a `_.flow` or `_.flowRight` function.
  3114. *
  3115. * @private
  3116. * @param {boolean} [fromRight] Specify iterating from right to left.
  3117. * @returns {Function} Returns the new flow function.
  3118. */
  3119. function createFlow(fromRight) {
  3120. return function() {
  3121. var wrapper,
  3122. length = arguments.length,
  3123. index = fromRight ? length : -1,
  3124. leftIndex = 0,
  3125. funcs = Array(length);
  3126. while ((fromRight ? index-- : ++index < length)) {
  3127. var func = funcs[leftIndex++] = arguments[index];
  3128. if (typeof func != 'function') {
  3129. throw new TypeError(FUNC_ERROR_TEXT);
  3130. }
  3131. if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
  3132. wrapper = new LodashWrapper([], true);
  3133. }
  3134. }
  3135. index = wrapper ? -1 : length;
  3136. while (++index < length) {
  3137. func = funcs[index];
  3138. var funcName = getFuncName(func),
  3139. data = funcName == 'wrapper' ? getData(func) : undefined;
  3140. if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
  3141. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  3142. } else {
  3143. wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
  3144. }
  3145. }
  3146. return function() {
  3147. var args = arguments,
  3148. value = args[0];
  3149. if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
  3150. return wrapper.plant(value).value();
  3151. }
  3152. var index = 0,
  3153. result = length ? funcs[index].apply(this, args) : value;
  3154. while (++index < length) {
  3155. result = funcs[index].call(this, result);
  3156. }
  3157. return result;
  3158. };
  3159. };
  3160. }
  3161. /**
  3162. * Creates a function for `_.forEach` or `_.forEachRight`.
  3163. *
  3164. * @private
  3165. * @param {Function} arrayFunc The function to iterate over an array.
  3166. * @param {Function} eachFunc The function to iterate over a collection.
  3167. * @returns {Function} Returns the new each function.
  3168. */
  3169. function createForEach(arrayFunc, eachFunc) {
  3170. return function(collection, iteratee, thisArg) {
  3171. return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
  3172. ? arrayFunc(collection, iteratee)
  3173. : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
  3174. };
  3175. }
  3176. /**
  3177. * Creates a function for `_.forIn` or `_.forInRight`.
  3178. *
  3179. * @private
  3180. * @param {Function} objectFunc The function to iterate over an object.
  3181. * @returns {Function} Returns the new each function.
  3182. */
  3183. function createForIn(objectFunc) {
  3184. return function(object, iteratee, thisArg) {
  3185. if (typeof iteratee != 'function' || thisArg !== undefined) {
  3186. iteratee = bindCallback(iteratee, thisArg, 3);
  3187. }
  3188. return objectFunc(object, iteratee, keysIn);
  3189. };
  3190. }
  3191. /**
  3192. * Creates a function for `_.forOwn` or `_.forOwnRight`.
  3193. *
  3194. * @private
  3195. * @param {Function} objectFunc The function to iterate over an object.
  3196. * @returns {Function} Returns the new each function.
  3197. */
  3198. function createForOwn(objectFunc) {
  3199. return function(object, iteratee, thisArg) {
  3200. if (typeof iteratee != 'function' || thisArg !== undefined) {
  3201. iteratee = bindCallback(iteratee, thisArg, 3);
  3202. }
  3203. return objectFunc(object, iteratee);
  3204. };
  3205. }
  3206. /**
  3207. * Creates a function for `_.mapKeys` or `_.mapValues`.
  3208. *
  3209. * @private
  3210. * @param {boolean} [isMapKeys] Specify mapping keys instead of values.
  3211. * @returns {Function} Returns the new map function.
  3212. */
  3213. function createObjectMapper(isMapKeys) {
  3214. return function(object, iteratee, thisArg) {
  3215. var result = {};
  3216. iteratee = getCallback(iteratee, thisArg, 3);
  3217. baseForOwn(object, function(value, key, object) {
  3218. var mapped = iteratee(value, key, object);
  3219. key = isMapKeys ? mapped : key;
  3220. value = isMapKeys ? value : mapped;
  3221. result[key] = value;
  3222. });
  3223. return result;
  3224. };
  3225. }
  3226. /**
  3227. * Creates a function for `_.padLeft` or `_.padRight`.
  3228. *
  3229. * @private
  3230. * @param {boolean} [fromRight] Specify padding from the right.
  3231. * @returns {Function} Returns the new pad function.
  3232. */
  3233. function createPadDir(fromRight) {
  3234. return function(string, length, chars) {
  3235. string = baseToString(string);
  3236. return (fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string);
  3237. };
  3238. }
  3239. /**
  3240. * Creates a `_.partial` or `_.partialRight` function.
  3241. *
  3242. * @private
  3243. * @param {boolean} flag The partial bit flag.
  3244. * @returns {Function} Returns the new partial function.
  3245. */
  3246. function createPartial(flag) {
  3247. var partialFunc = restParam(function(func, partials) {
  3248. var holders = replaceHolders(partials, partialFunc.placeholder);
  3249. return createWrapper(func, flag, undefined, partials, holders);
  3250. });
  3251. return partialFunc;
  3252. }
  3253. /**
  3254. * Creates a function for `_.reduce` or `_.reduceRight`.
  3255. *
  3256. * @private
  3257. * @param {Function} arrayFunc The function to iterate over an array.
  3258. * @param {Function} eachFunc The function to iterate over a collection.
  3259. * @returns {Function} Returns the new each function.
  3260. */
  3261. function createReduce(arrayFunc, eachFunc) {
  3262. return function(collection, iteratee, accumulator, thisArg) {
  3263. var initFromArray = arguments.length < 3;
  3264. return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
  3265. ? arrayFunc(collection, iteratee, accumulator, initFromArray)
  3266. : baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
  3267. };
  3268. }
  3269. /**
  3270. * Creates a function that wraps `func` and invokes it with optional `this`
  3271. * binding of, partial application, and currying.
  3272. *
  3273. * @private
  3274. * @param {Function|string} func The function or method name to reference.
  3275. * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
  3276. * @param {*} [thisArg] The `this` binding of `func`.
  3277. * @param {Array} [partials] The arguments to prepend to those provided to the new function.
  3278. * @param {Array} [holders] The `partials` placeholder indexes.
  3279. * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
  3280. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  3281. * @param {Array} [argPos] The argument positions of the new function.
  3282. * @param {number} [ary] The arity cap of `func`.
  3283. * @param {number} [arity] The arity of `func`.
  3284. * @returns {Function} Returns the new wrapped function.
  3285. */
  3286. function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  3287. var isAry = bitmask & ARY_FLAG,
  3288. isBind = bitmask & BIND_FLAG,
  3289. isBindKey = bitmask & BIND_KEY_FLAG,
  3290. isCurry = bitmask & CURRY_FLAG,
  3291. isCurryBound = bitmask & CURRY_BOUND_FLAG,
  3292. isCurryRight = bitmask & CURRY_RIGHT_FLAG,
  3293. Ctor = isBindKey ? undefined : createCtorWrapper(func);
  3294. function wrapper() {
  3295. // Avoid `arguments` object use disqualifying optimizations by
  3296. // converting it to an array before providing it to other functions.
  3297. var length = arguments.length,
  3298. index = length,
  3299. args = Array(length);
  3300. while (index--) {
  3301. args[index] = arguments[index];
  3302. }
  3303. if (partials) {
  3304. args = composeArgs(args, partials, holders);
  3305. }
  3306. if (partialsRight) {
  3307. args = composeArgsRight(args, partialsRight, holdersRight);
  3308. }
  3309. if (isCurry || isCurryRight) {
  3310. var placeholder = wrapper.placeholder,
  3311. argsHolders = replaceHolders(args, placeholder);
  3312. length -= argsHolders.length;
  3313. if (length < arity) {
  3314. var newArgPos = argPos ? arrayCopy(argPos) : undefined,
  3315. newArity = nativeMax(arity - length, 0),
  3316. newsHolders = isCurry ? argsHolders : undefined,
  3317. newHoldersRight = isCurry ? undefined : argsHolders,
  3318. newPartials = isCurry ? args : undefined,
  3319. newPartialsRight = isCurry ? undefined : args;
  3320. bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
  3321. bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
  3322. if (!isCurryBound) {
  3323. bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
  3324. }
  3325. var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
  3326. result = createHybridWrapper.apply(undefined, newData);
  3327. if (isLaziable(func)) {
  3328. setData(result, newData);
  3329. }
  3330. result.placeholder = placeholder;
  3331. return result;
  3332. }
  3333. }
  3334. var thisBinding = isBind ? thisArg : this,
  3335. fn = isBindKey ? thisBinding[func] : func;
  3336. if (argPos) {
  3337. args = reorder(args, argPos);
  3338. }
  3339. if (isAry && ary < args.length) {
  3340. args.length = ary;
  3341. }
  3342. if (this && this !== root && this instanceof wrapper) {
  3343. fn = Ctor || createCtorWrapper(func);
  3344. }
  3345. return fn.apply(thisBinding, args);
  3346. }
  3347. return wrapper;
  3348. }
  3349. /**
  3350. * Creates the padding required for `string` based on the given `length`.
  3351. * The `chars` string is truncated if the number of characters exceeds `length`.
  3352. *
  3353. * @private
  3354. * @param {string} string The string to create padding for.
  3355. * @param {number} [length=0] The padding length.
  3356. * @param {string} [chars=' '] The string used as padding.
  3357. * @returns {string} Returns the pad for `string`.
  3358. */
  3359. function createPadding(string, length, chars) {
  3360. var strLength = string.length;
  3361. length = +length;
  3362. if (strLength >= length || !nativeIsFinite(length)) {
  3363. return '';
  3364. }
  3365. var padLength = length - strLength;
  3366. chars = chars == null ? ' ' : (chars + '');
  3367. return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
  3368. }
  3369. /**
  3370. * Creates a function that wraps `func` and invokes it with the optional `this`
  3371. * binding of `thisArg` and the `partials` prepended to those provided to
  3372. * the wrapper.
  3373. *
  3374. * @private
  3375. * @param {Function} func The function to partially apply arguments to.
  3376. * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
  3377. * @param {*} thisArg The `this` binding of `func`.
  3378. * @param {Array} partials The arguments to prepend to those provided to the new function.
  3379. * @returns {Function} Returns the new bound function.
  3380. */
  3381. function createPartialWrapper(func, bitmask, thisArg, partials) {
  3382. var isBind = bitmask & BIND_FLAG,
  3383. Ctor = createCtorWrapper(func);
  3384. function wrapper() {
  3385. // Avoid `arguments` object use disqualifying optimizations by
  3386. // converting it to an array before providing it `func`.
  3387. var argsIndex = -1,
  3388. argsLength = arguments.length,
  3389. leftIndex = -1,
  3390. leftLength = partials.length,
  3391. args = Array(leftLength + argsLength);
  3392. while (++leftIndex < leftLength) {
  3393. args[leftIndex] = partials[leftIndex];
  3394. }
  3395. while (argsLength--) {
  3396. args[leftIndex++] = arguments[++argsIndex];
  3397. }
  3398. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  3399. return fn.apply(isBind ? thisArg : this, args);
  3400. }
  3401. return wrapper;
  3402. }
  3403. /**
  3404. * Creates a `_.ceil`, `_.floor`, or `_.round` function.
  3405. *
  3406. * @private
  3407. * @param {string} methodName The name of the `Math` method to use when rounding.
  3408. * @returns {Function} Returns the new round function.
  3409. */
  3410. function createRound(methodName) {
  3411. var func = Math[methodName];
  3412. return function(number, precision) {
  3413. precision = precision === undefined ? 0 : (+precision || 0);
  3414. if (precision) {
  3415. precision = pow(10, precision);
  3416. return func(number * precision) / precision;
  3417. }
  3418. return func(number);
  3419. };
  3420. }
  3421. /**
  3422. * Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
  3423. *
  3424. * @private
  3425. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3426. * @returns {Function} Returns the new index function.
  3427. */
  3428. function createSortedIndex(retHighest) {
  3429. return function(array, value, iteratee, thisArg) {
  3430. var callback = getCallback(iteratee);
  3431. return (iteratee == null && callback === baseCallback)
  3432. ? binaryIndex(array, value, retHighest)
  3433. : binaryIndexBy(array, value, callback(iteratee, thisArg, 1), retHighest);
  3434. };
  3435. }
  3436. /**
  3437. * Creates a function that either curries or invokes `func` with optional
  3438. * `this` binding and partially applied arguments.
  3439. *
  3440. * @private
  3441. * @param {Function|string} func The function or method name to reference.
  3442. * @param {number} bitmask The bitmask of flags.
  3443. * The bitmask may be composed of the following flags:
  3444. * 1 - `_.bind`
  3445. * 2 - `_.bindKey`
  3446. * 4 - `_.curry` or `_.curryRight` of a bound function
  3447. * 8 - `_.curry`
  3448. * 16 - `_.curryRight`
  3449. * 32 - `_.partial`
  3450. * 64 - `_.partialRight`
  3451. * 128 - `_.rearg`
  3452. * 256 - `_.ary`
  3453. * @param {*} [thisArg] The `this` binding of `func`.
  3454. * @param {Array} [partials] The arguments to be partially applied.
  3455. * @param {Array} [holders] The `partials` placeholder indexes.
  3456. * @param {Array} [argPos] The argument positions of the new function.
  3457. * @param {number} [ary] The arity cap of `func`.
  3458. * @param {number} [arity] The arity of `func`.
  3459. * @returns {Function} Returns the new wrapped function.
  3460. */
  3461. function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  3462. var isBindKey = bitmask & BIND_KEY_FLAG;
  3463. if (!isBindKey && typeof func != 'function') {
  3464. throw new TypeError(FUNC_ERROR_TEXT);
  3465. }
  3466. var length = partials ? partials.length : 0;
  3467. if (!length) {
  3468. bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
  3469. partials = holders = undefined;
  3470. }
  3471. length -= (holders ? holders.length : 0);
  3472. if (bitmask & PARTIAL_RIGHT_FLAG) {
  3473. var partialsRight = partials,
  3474. holdersRight = holders;
  3475. partials = holders = undefined;
  3476. }
  3477. var data = isBindKey ? undefined : getData(func),
  3478. newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
  3479. if (data) {
  3480. mergeData(newData, data);
  3481. bitmask = newData[1];
  3482. arity = newData[9];
  3483. }
  3484. newData[9] = arity == null
  3485. ? (isBindKey ? 0 : func.length)
  3486. : (nativeMax(arity - length, 0) || 0);
  3487. if (bitmask == BIND_FLAG) {
  3488. var result = createBindWrapper(newData[0], newData[2]);
  3489. } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
  3490. result = createPartialWrapper.apply(undefined, newData);
  3491. } else {
  3492. result = createHybridWrapper.apply(undefined, newData);
  3493. }
  3494. var setter = data ? baseSetData : setData;
  3495. return setter(result, newData);
  3496. }
  3497. /**
  3498. * A specialized version of `baseIsEqualDeep` for arrays with support for
  3499. * partial deep comparisons.
  3500. *
  3501. * @private
  3502. * @param {Array} array The array to compare.
  3503. * @param {Array} other The other array to compare.
  3504. * @param {Function} equalFunc The function to determine equivalents of values.
  3505. * @param {Function} [customizer] The function to customize comparing arrays.
  3506. * @param {boolean} [isLoose] Specify performing partial comparisons.
  3507. * @param {Array} [stackA] Tracks traversed `value` objects.
  3508. * @param {Array} [stackB] Tracks traversed `other` objects.
  3509. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  3510. */
  3511. function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
  3512. var index = -1,
  3513. arrLength = array.length,
  3514. othLength = other.length;
  3515. if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
  3516. return false;
  3517. }
  3518. // Ignore non-index properties.
  3519. while (++index < arrLength) {
  3520. var arrValue = array[index],
  3521. othValue = other[index],
  3522. result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
  3523. if (result !== undefined) {
  3524. if (result) {
  3525. continue;
  3526. }
  3527. return false;
  3528. }
  3529. // Recursively compare arrays (susceptible to call stack limits).
  3530. if (isLoose) {
  3531. if (!arraySome(other, function(othValue) {
  3532. return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
  3533. })) {
  3534. return false;
  3535. }
  3536. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
  3537. return false;
  3538. }
  3539. }
  3540. return true;
  3541. }
  3542. /**
  3543. * A specialized version of `baseIsEqualDeep` for comparing objects of
  3544. * the same `toStringTag`.
  3545. *
  3546. * **Note:** This function only supports comparing values with tags of
  3547. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  3548. *
  3549. * @private
  3550. * @param {Object} object The object to compare.
  3551. * @param {Object} other The other object to compare.
  3552. * @param {string} tag The `toStringTag` of the objects to compare.
  3553. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3554. */
  3555. function equalByTag(object, other, tag) {
  3556. switch (tag) {
  3557. case boolTag:
  3558. case dateTag:
  3559. // Coerce dates and booleans to numbers, dates to milliseconds and booleans
  3560. // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
  3561. return +object == +other;
  3562. case errorTag:
  3563. return object.name == other.name && object.message == other.message;
  3564. case numberTag:
  3565. // Treat `NaN` vs. `NaN` as equal.
  3566. return (object != +object)
  3567. ? other != +other
  3568. : object == +other;
  3569. case regexpTag:
  3570. case stringTag:
  3571. // Coerce regexes to strings and treat strings primitives and string
  3572. // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
  3573. return object == (other + '');
  3574. }
  3575. return false;
  3576. }
  3577. /**
  3578. * A specialized version of `baseIsEqualDeep` for objects with support for
  3579. * partial deep comparisons.
  3580. *
  3581. * @private
  3582. * @param {Object} object The object to compare.
  3583. * @param {Object} other The other object to compare.
  3584. * @param {Function} equalFunc The function to determine equivalents of values.
  3585. * @param {Function} [customizer] The function to customize comparing values.
  3586. * @param {boolean} [isLoose] Specify performing partial comparisons.
  3587. * @param {Array} [stackA] Tracks traversed `value` objects.
  3588. * @param {Array} [stackB] Tracks traversed `other` objects.
  3589. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3590. */
  3591. function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
  3592. var objProps = keys(object),
  3593. objLength = objProps.length,
  3594. othProps = keys(other),
  3595. othLength = othProps.length;
  3596. if (objLength != othLength && !isLoose) {
  3597. return false;
  3598. }
  3599. var index = objLength;
  3600. while (index--) {
  3601. var key = objProps[index];
  3602. if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
  3603. return false;
  3604. }
  3605. }
  3606. var skipCtor = isLoose;
  3607. while (++index < objLength) {
  3608. key = objProps[index];
  3609. var objValue = object[key],
  3610. othValue = other[key],
  3611. result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
  3612. // Recursively compare objects (susceptible to call stack limits).
  3613. if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
  3614. return false;
  3615. }
  3616. skipCtor || (skipCtor = key == 'constructor');
  3617. }
  3618. if (!skipCtor) {
  3619. var objCtor = object.constructor,
  3620. othCtor = other.constructor;
  3621. // Non `Object` object instances with different constructors are not equal.
  3622. if (objCtor != othCtor &&
  3623. ('constructor' in object && 'constructor' in other) &&
  3624. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  3625. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  3626. return false;
  3627. }
  3628. }
  3629. return true;
  3630. }
  3631. /**
  3632. * Gets the appropriate "callback" function. If the `_.callback` method is
  3633. * customized this function returns the custom method, otherwise it returns
  3634. * the `baseCallback` function. If arguments are provided the chosen function
  3635. * is invoked with them and its result is returned.
  3636. *
  3637. * @private
  3638. * @returns {Function} Returns the chosen function or its result.
  3639. */
  3640. function getCallback(func, thisArg, argCount) {
  3641. var result = lodash.callback || callback;
  3642. result = result === callback ? baseCallback : result;
  3643. return argCount ? result(func, thisArg, argCount) : result;
  3644. }
  3645. /**
  3646. * Gets metadata for `func`.
  3647. *
  3648. * @private
  3649. * @param {Function} func The function to query.
  3650. * @returns {*} Returns the metadata for `func`.
  3651. */
  3652. var getData = !metaMap ? noop : function(func) {
  3653. return metaMap.get(func);
  3654. };
  3655. /**
  3656. * Gets the name of `func`.
  3657. *
  3658. * @private
  3659. * @param {Function} func The function to query.
  3660. * @returns {string} Returns the function name.
  3661. */
  3662. function getFuncName(func) {
  3663. var result = (func.name + ''),
  3664. array = realNames[result],
  3665. length = array ? array.length : 0;
  3666. while (length--) {
  3667. var data = array[length],
  3668. otherFunc = data.func;
  3669. if (otherFunc == null || otherFunc == func) {
  3670. return data.name;
  3671. }
  3672. }
  3673. return result;
  3674. }
  3675. /**
  3676. * Gets the appropriate "indexOf" function. If the `_.indexOf` method is
  3677. * customized this function returns the custom method, otherwise it returns
  3678. * the `baseIndexOf` function. If arguments are provided the chosen function
  3679. * is invoked with them and its result is returned.
  3680. *
  3681. * @private
  3682. * @returns {Function|number} Returns the chosen function or its result.
  3683. */
  3684. function getIndexOf(collection, target, fromIndex) {
  3685. var result = lodash.indexOf || indexOf;
  3686. result = result === indexOf ? baseIndexOf : result;
  3687. return collection ? result(collection, target, fromIndex) : result;
  3688. }
  3689. /**
  3690. * Gets the "length" property value of `object`.
  3691. *
  3692. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  3693. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  3694. *
  3695. * @private
  3696. * @param {Object} object The object to query.
  3697. * @returns {*} Returns the "length" value.
  3698. */
  3699. var getLength = baseProperty('length');
  3700. /**
  3701. * Gets the propery names, values, and compare flags of `object`.
  3702. *
  3703. * @private
  3704. * @param {Object} object The object to query.
  3705. * @returns {Array} Returns the match data of `object`.
  3706. */
  3707. function getMatchData(object) {
  3708. var result = pairs(object),
  3709. length = result.length;
  3710. while (length--) {
  3711. result[length][2] = isStrictComparable(result[length][1]);
  3712. }
  3713. return result;
  3714. }
  3715. /**
  3716. * Gets the native function at `key` of `object`.
  3717. *
  3718. * @private
  3719. * @param {Object} object The object to query.
  3720. * @param {string} key The key of the method to get.
  3721. * @returns {*} Returns the function if it's native, else `undefined`.
  3722. */
  3723. function getNative(object, key) {
  3724. var value = object == null ? undefined : object[key];
  3725. return isNative(value) ? value : undefined;
  3726. }
  3727. /**
  3728. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  3729. *
  3730. * @private
  3731. * @param {number} start The start of the view.
  3732. * @param {number} end The end of the view.
  3733. * @param {Array} transforms The transformations to apply to the view.
  3734. * @returns {Object} Returns an object containing the `start` and `end`
  3735. * positions of the view.
  3736. */
  3737. function getView(start, end, transforms) {
  3738. var index = -1,
  3739. length = transforms.length;
  3740. while (++index < length) {
  3741. var data = transforms[index],
  3742. size = data.size;
  3743. switch (data.type) {
  3744. case 'drop': start += size; break;
  3745. case 'dropRight': end -= size; break;
  3746. case 'take': end = nativeMin(end, start + size); break;
  3747. case 'takeRight': start = nativeMax(start, end - size); break;
  3748. }
  3749. }
  3750. return { 'start': start, 'end': end };
  3751. }
  3752. /**
  3753. * Initializes an array clone.
  3754. *
  3755. * @private
  3756. * @param {Array} array The array to clone.
  3757. * @returns {Array} Returns the initialized clone.
  3758. */
  3759. function initCloneArray(array) {
  3760. var length = array.length,
  3761. result = new array.constructor(length);
  3762. // Add array properties assigned by `RegExp#exec`.
  3763. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  3764. result.index = array.index;
  3765. result.input = array.input;
  3766. }
  3767. return result;
  3768. }
  3769. /**
  3770. * Initializes an object clone.
  3771. *
  3772. * @private
  3773. * @param {Object} object The object to clone.
  3774. * @returns {Object} Returns the initialized clone.
  3775. */
  3776. function initCloneObject(object) {
  3777. var Ctor = object.constructor;
  3778. if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
  3779. Ctor = Object;
  3780. }
  3781. return new Ctor;
  3782. }
  3783. /**
  3784. * Initializes an object clone based on its `toStringTag`.
  3785. *
  3786. * **Note:** This function only supports cloning values with tags of
  3787. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  3788. *
  3789. * @private
  3790. * @param {Object} object The object to clone.
  3791. * @param {string} tag The `toStringTag` of the object to clone.
  3792. * @param {boolean} [isDeep] Specify a deep clone.
  3793. * @returns {Object} Returns the initialized clone.
  3794. */
  3795. function initCloneByTag(object, tag, isDeep) {
  3796. var Ctor = object.constructor;
  3797. switch (tag) {
  3798. case arrayBufferTag:
  3799. return bufferClone(object);
  3800. case boolTag:
  3801. case dateTag:
  3802. return new Ctor(+object);
  3803. case float32Tag: case float64Tag:
  3804. case int8Tag: case int16Tag: case int32Tag:
  3805. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  3806. // Safari 5 mobile incorrectly has `Object` as the constructor of typed arrays.
  3807. if (Ctor instanceof Ctor) {
  3808. Ctor = ctorByTag[tag];
  3809. }
  3810. var buffer = object.buffer;
  3811. return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
  3812. case numberTag:
  3813. case stringTag:
  3814. return new Ctor(object);
  3815. case regexpTag:
  3816. var result = new Ctor(object.source, reFlags.exec(object));
  3817. result.lastIndex = object.lastIndex;
  3818. }
  3819. return result;
  3820. }
  3821. /**
  3822. * Invokes the method at `path` on `object`.
  3823. *
  3824. * @private
  3825. * @param {Object} object The object to query.
  3826. * @param {Array|string} path The path of the method to invoke.
  3827. * @param {Array} args The arguments to invoke the method with.
  3828. * @returns {*} Returns the result of the invoked method.
  3829. */
  3830. function invokePath(object, path, args) {
  3831. if (object != null && !isKey(path, object)) {
  3832. path = toPath(path);
  3833. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  3834. path = last(path);
  3835. }
  3836. var func = object == null ? object : object[path];
  3837. return func == null ? undefined : func.apply(object, args);
  3838. }
  3839. /**
  3840. * Checks if `value` is array-like.
  3841. *
  3842. * @private
  3843. * @param {*} value The value to check.
  3844. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  3845. */
  3846. function isArrayLike(value) {
  3847. return value != null && isLength(getLength(value));
  3848. }
  3849. /**
  3850. * Checks if `value` is a valid array-like index.
  3851. *
  3852. * @private
  3853. * @param {*} value The value to check.
  3854. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  3855. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  3856. */
  3857. function isIndex(value, length) {
  3858. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  3859. length = length == null ? MAX_SAFE_INTEGER : length;
  3860. return value > -1 && value % 1 == 0 && value < length;
  3861. }
  3862. /**
  3863. * Checks if the provided arguments are from an iteratee call.
  3864. *
  3865. * @private
  3866. * @param {*} value The potential iteratee value argument.
  3867. * @param {*} index The potential iteratee index or key argument.
  3868. * @param {*} object The potential iteratee object argument.
  3869. * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
  3870. */
  3871. function isIterateeCall(value, index, object) {
  3872. if (!isObject(object)) {
  3873. return false;
  3874. }
  3875. var type = typeof index;
  3876. if (type == 'number'
  3877. ? (isArrayLike(object) && isIndex(index, object.length))
  3878. : (type == 'string' && index in object)) {
  3879. var other = object[index];
  3880. return value === value ? (value === other) : (other !== other);
  3881. }
  3882. return false;
  3883. }
  3884. /**
  3885. * Checks if `value` is a property name and not a property path.
  3886. *
  3887. * @private
  3888. * @param {*} value The value to check.
  3889. * @param {Object} [object] The object to query keys on.
  3890. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  3891. */
  3892. function isKey(value, object) {
  3893. var type = typeof value;
  3894. if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
  3895. return true;
  3896. }
  3897. if (isArray(value)) {
  3898. return false;
  3899. }
  3900. var result = !reIsDeepProp.test(value);
  3901. return result || (object != null && value in toObject(object));
  3902. }
  3903. /**
  3904. * Checks if `func` has a lazy counterpart.
  3905. *
  3906. * @private
  3907. * @param {Function} func The function to check.
  3908. * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
  3909. */
  3910. function isLaziable(func) {
  3911. var funcName = getFuncName(func),
  3912. other = lodash[funcName];
  3913. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  3914. return false;
  3915. }
  3916. if (func === other) {
  3917. return true;
  3918. }
  3919. var data = getData(other);
  3920. return !!data && func === data[0];
  3921. }
  3922. /**
  3923. * Checks if `value` is a valid array-like length.
  3924. *
  3925. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  3926. *
  3927. * @private
  3928. * @param {*} value The value to check.
  3929. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  3930. */
  3931. function isLength(value) {
  3932. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  3933. }
  3934. /**
  3935. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  3936. *
  3937. * @private
  3938. * @param {*} value The value to check.
  3939. * @returns {boolean} Returns `true` if `value` if suitable for strict
  3940. * equality comparisons, else `false`.
  3941. */
  3942. function isStrictComparable(value) {
  3943. return value === value && !isObject(value);
  3944. }
  3945. /**
  3946. * Merges the function metadata of `source` into `data`.
  3947. *
  3948. * Merging metadata reduces the number of wrappers required to invoke a function.
  3949. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  3950. * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
  3951. * augment function arguments, making the order in which they are executed important,
  3952. * preventing the merging of metadata. However, we make an exception for a safe
  3953. * common case where curried functions have `_.ary` and or `_.rearg` applied.
  3954. *
  3955. * @private
  3956. * @param {Array} data The destination metadata.
  3957. * @param {Array} source The source metadata.
  3958. * @returns {Array} Returns `data`.
  3959. */
  3960. function mergeData(data, source) {
  3961. var bitmask = data[1],
  3962. srcBitmask = source[1],
  3963. newBitmask = bitmask | srcBitmask,
  3964. isCommon = newBitmask < ARY_FLAG;
  3965. var isCombo =
  3966. (srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
  3967. (srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
  3968. (srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
  3969. // Exit early if metadata can't be merged.
  3970. if (!(isCommon || isCombo)) {
  3971. return data;
  3972. }
  3973. // Use source `thisArg` if available.
  3974. if (srcBitmask & BIND_FLAG) {
  3975. data[2] = source[2];
  3976. // Set when currying a bound function.
  3977. newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
  3978. }
  3979. // Compose partial arguments.
  3980. var value = source[3];
  3981. if (value) {
  3982. var partials = data[3];
  3983. data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
  3984. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
  3985. }
  3986. // Compose partial right arguments.
  3987. value = source[5];
  3988. if (value) {
  3989. partials = data[5];
  3990. data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
  3991. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
  3992. }
  3993. // Use source `argPos` if available.
  3994. value = source[7];
  3995. if (value) {
  3996. data[7] = arrayCopy(value);
  3997. }
  3998. // Use source `ary` if it's smaller.
  3999. if (srcBitmask & ARY_FLAG) {
  4000. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  4001. }
  4002. // Use source `arity` if one is not provided.
  4003. if (data[9] == null) {
  4004. data[9] = source[9];
  4005. }
  4006. // Use source `func` and merge bitmasks.
  4007. data[0] = source[0];
  4008. data[1] = newBitmask;
  4009. return data;
  4010. }
  4011. /**
  4012. * Used by `_.defaultsDeep` to customize its `_.merge` use.
  4013. *
  4014. * @private
  4015. * @param {*} objectValue The destination object property value.
  4016. * @param {*} sourceValue The source object property value.
  4017. * @returns {*} Returns the value to assign to the destination object.
  4018. */
  4019. function mergeDefaults(objectValue, sourceValue) {
  4020. return objectValue === undefined ? sourceValue : merge(objectValue, sourceValue, mergeDefaults);
  4021. }
  4022. /**
  4023. * A specialized version of `_.pick` which picks `object` properties specified
  4024. * by `props`.
  4025. *
  4026. * @private
  4027. * @param {Object} object The source object.
  4028. * @param {string[]} props The property names to pick.
  4029. * @returns {Object} Returns the new object.
  4030. */
  4031. function pickByArray(object, props) {
  4032. object = toObject(object);
  4033. var index = -1,
  4034. length = props.length,
  4035. result = {};
  4036. while (++index < length) {
  4037. var key = props[index];
  4038. if (key in object) {
  4039. result[key] = object[key];
  4040. }
  4041. }
  4042. return result;
  4043. }
  4044. /**
  4045. * A specialized version of `_.pick` which picks `object` properties `predicate`
  4046. * returns truthy for.
  4047. *
  4048. * @private
  4049. * @param {Object} object The source object.
  4050. * @param {Function} predicate The function invoked per iteration.
  4051. * @returns {Object} Returns the new object.
  4052. */
  4053. function pickByCallback(object, predicate) {
  4054. var result = {};
  4055. baseForIn(object, function(value, key, object) {
  4056. if (predicate(value, key, object)) {
  4057. result[key] = value;
  4058. }
  4059. });
  4060. return result;
  4061. }
  4062. /**
  4063. * Reorder `array` according to the specified indexes where the element at
  4064. * the first index is assigned as the first element, the element at
  4065. * the second index is assigned as the second element, and so on.
  4066. *
  4067. * @private
  4068. * @param {Array} array The array to reorder.
  4069. * @param {Array} indexes The arranged array indexes.
  4070. * @returns {Array} Returns `array`.
  4071. */
  4072. function reorder(array, indexes) {
  4073. var arrLength = array.length,
  4074. length = nativeMin(indexes.length, arrLength),
  4075. oldArray = arrayCopy(array);
  4076. while (length--) {
  4077. var index = indexes[length];
  4078. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  4079. }
  4080. return array;
  4081. }
  4082. /**
  4083. * Sets metadata for `func`.
  4084. *
  4085. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  4086. * period of time, it will trip its breaker and transition to an identity function
  4087. * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
  4088. * for more details.
  4089. *
  4090. * @private
  4091. * @param {Function} func The function to associate metadata with.
  4092. * @param {*} data The metadata.
  4093. * @returns {Function} Returns `func`.
  4094. */
  4095. var setData = (function() {
  4096. var count = 0,
  4097. lastCalled = 0;
  4098. return function(key, value) {
  4099. var stamp = now(),
  4100. remaining = HOT_SPAN - (stamp - lastCalled);
  4101. lastCalled = stamp;
  4102. if (remaining > 0) {
  4103. if (++count >= HOT_COUNT) {
  4104. return key;
  4105. }
  4106. } else {
  4107. count = 0;
  4108. }
  4109. return baseSetData(key, value);
  4110. };
  4111. }());
  4112. /**
  4113. * A fallback implementation of `Object.keys` which creates an array of the
  4114. * own enumerable property names of `object`.
  4115. *
  4116. * @private
  4117. * @param {Object} object The object to query.
  4118. * @returns {Array} Returns the array of property names.
  4119. */
  4120. function shimKeys(object) {
  4121. var props = keysIn(object),
  4122. propsLength = props.length,
  4123. length = propsLength && object.length;
  4124. var allowIndexes = !!length && isLength(length) &&
  4125. (isArray(object) || isArguments(object) || isString(object));
  4126. var index = -1,
  4127. result = [];
  4128. while (++index < propsLength) {
  4129. var key = props[index];
  4130. if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
  4131. result.push(key);
  4132. }
  4133. }
  4134. return result;
  4135. }
  4136. /**
  4137. * Converts `value` to an array-like object if it's not one.
  4138. *
  4139. * @private
  4140. * @param {*} value The value to process.
  4141. * @returns {Array|Object} Returns the array-like object.
  4142. */
  4143. function toIterable(value) {
  4144. if (value == null) {
  4145. return [];
  4146. }
  4147. if (!isArrayLike(value)) {
  4148. return values(value);
  4149. }
  4150. if (lodash.support.unindexedChars && isString(value)) {
  4151. return value.split('');
  4152. }
  4153. return isObject(value) ? value : Object(value);
  4154. }
  4155. /**
  4156. * Converts `value` to an object if it's not one.
  4157. *
  4158. * @private
  4159. * @param {*} value The value to process.
  4160. * @returns {Object} Returns the object.
  4161. */
  4162. function toObject(value) {
  4163. if (lodash.support.unindexedChars && isString(value)) {
  4164. var index = -1,
  4165. length = value.length,
  4166. result = Object(value);
  4167. while (++index < length) {
  4168. result[index] = value.charAt(index);
  4169. }
  4170. return result;
  4171. }
  4172. return isObject(value) ? value : Object(value);
  4173. }
  4174. /**
  4175. * Converts `value` to property path array if it's not one.
  4176. *
  4177. * @private
  4178. * @param {*} value The value to process.
  4179. * @returns {Array} Returns the property path array.
  4180. */
  4181. function toPath(value) {
  4182. if (isArray(value)) {
  4183. return value;
  4184. }
  4185. var result = [];
  4186. baseToString(value).replace(rePropName, function(match, number, quote, string) {
  4187. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  4188. });
  4189. return result;
  4190. }
  4191. /**
  4192. * Creates a clone of `wrapper`.
  4193. *
  4194. * @private
  4195. * @param {Object} wrapper The wrapper to clone.
  4196. * @returns {Object} Returns the cloned wrapper.
  4197. */
  4198. function wrapperClone(wrapper) {
  4199. return wrapper instanceof LazyWrapper
  4200. ? wrapper.clone()
  4201. : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
  4202. }
  4203. /*------------------------------------------------------------------------*/
  4204. /**
  4205. * Creates an array of elements split into groups the length of `size`.
  4206. * If `collection` can't be split evenly, the final chunk will be the remaining
  4207. * elements.
  4208. *
  4209. * @static
  4210. * @memberOf _
  4211. * @category Array
  4212. * @param {Array} array The array to process.
  4213. * @param {number} [size=1] The length of each chunk.
  4214. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4215. * @returns {Array} Returns the new array containing chunks.
  4216. * @example
  4217. *
  4218. * _.chunk(['a', 'b', 'c', 'd'], 2);
  4219. * // => [['a', 'b'], ['c', 'd']]
  4220. *
  4221. * _.chunk(['a', 'b', 'c', 'd'], 3);
  4222. * // => [['a', 'b', 'c'], ['d']]
  4223. */
  4224. function chunk(array, size, guard) {
  4225. if (guard ? isIterateeCall(array, size, guard) : size == null) {
  4226. size = 1;
  4227. } else {
  4228. size = nativeMax(nativeFloor(size) || 1, 1);
  4229. }
  4230. var index = 0,
  4231. length = array ? array.length : 0,
  4232. resIndex = -1,
  4233. result = Array(nativeCeil(length / size));
  4234. while (index < length) {
  4235. result[++resIndex] = baseSlice(array, index, (index += size));
  4236. }
  4237. return result;
  4238. }
  4239. /**
  4240. * Creates an array with all falsey values removed. The values `false`, `null`,
  4241. * `0`, `""`, `undefined`, and `NaN` are falsey.
  4242. *
  4243. * @static
  4244. * @memberOf _
  4245. * @category Array
  4246. * @param {Array} array The array to compact.
  4247. * @returns {Array} Returns the new array of filtered values.
  4248. * @example
  4249. *
  4250. * _.compact([0, 1, false, 2, '', 3]);
  4251. * // => [1, 2, 3]
  4252. */
  4253. function compact(array) {
  4254. var index = -1,
  4255. length = array ? array.length : 0,
  4256. resIndex = -1,
  4257. result = [];
  4258. while (++index < length) {
  4259. var value = array[index];
  4260. if (value) {
  4261. result[++resIndex] = value;
  4262. }
  4263. }
  4264. return result;
  4265. }
  4266. /**
  4267. * Creates an array of unique `array` values not included in the other
  4268. * provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  4269. * for equality comparisons.
  4270. *
  4271. * @static
  4272. * @memberOf _
  4273. * @category Array
  4274. * @param {Array} array The array to inspect.
  4275. * @param {...Array} [values] The arrays of values to exclude.
  4276. * @returns {Array} Returns the new array of filtered values.
  4277. * @example
  4278. *
  4279. * _.difference([1, 2, 3], [4, 2]);
  4280. * // => [1, 3]
  4281. */
  4282. var difference = restParam(function(array, values) {
  4283. return (isObjectLike(array) && isArrayLike(array))
  4284. ? baseDifference(array, baseFlatten(values, false, true))
  4285. : [];
  4286. });
  4287. /**
  4288. * Creates a slice of `array` with `n` elements dropped from the beginning.
  4289. *
  4290. * @static
  4291. * @memberOf _
  4292. * @category Array
  4293. * @param {Array} array The array to query.
  4294. * @param {number} [n=1] The number of elements to drop.
  4295. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4296. * @returns {Array} Returns the slice of `array`.
  4297. * @example
  4298. *
  4299. * _.drop([1, 2, 3]);
  4300. * // => [2, 3]
  4301. *
  4302. * _.drop([1, 2, 3], 2);
  4303. * // => [3]
  4304. *
  4305. * _.drop([1, 2, 3], 5);
  4306. * // => []
  4307. *
  4308. * _.drop([1, 2, 3], 0);
  4309. * // => [1, 2, 3]
  4310. */
  4311. function drop(array, n, guard) {
  4312. var length = array ? array.length : 0;
  4313. if (!length) {
  4314. return [];
  4315. }
  4316. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  4317. n = 1;
  4318. }
  4319. return baseSlice(array, n < 0 ? 0 : n);
  4320. }
  4321. /**
  4322. * Creates a slice of `array` with `n` elements dropped from the end.
  4323. *
  4324. * @static
  4325. * @memberOf _
  4326. * @category Array
  4327. * @param {Array} array The array to query.
  4328. * @param {number} [n=1] The number of elements to drop.
  4329. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4330. * @returns {Array} Returns the slice of `array`.
  4331. * @example
  4332. *
  4333. * _.dropRight([1, 2, 3]);
  4334. * // => [1, 2]
  4335. *
  4336. * _.dropRight([1, 2, 3], 2);
  4337. * // => [1]
  4338. *
  4339. * _.dropRight([1, 2, 3], 5);
  4340. * // => []
  4341. *
  4342. * _.dropRight([1, 2, 3], 0);
  4343. * // => [1, 2, 3]
  4344. */
  4345. function dropRight(array, n, guard) {
  4346. var length = array ? array.length : 0;
  4347. if (!length) {
  4348. return [];
  4349. }
  4350. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  4351. n = 1;
  4352. }
  4353. n = length - (+n || 0);
  4354. return baseSlice(array, 0, n < 0 ? 0 : n);
  4355. }
  4356. /**
  4357. * Creates a slice of `array` excluding elements dropped from the end.
  4358. * Elements are dropped until `predicate` returns falsey. The predicate is
  4359. * bound to `thisArg` and invoked with three arguments: (value, index, array).
  4360. *
  4361. * If a property name is provided for `predicate` the created `_.property`
  4362. * style callback returns the property value of the given element.
  4363. *
  4364. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4365. * style callback returns `true` for elements that have a matching property
  4366. * value, else `false`.
  4367. *
  4368. * If an object is provided for `predicate` the created `_.matches` style
  4369. * callback returns `true` for elements that match the properties of the given
  4370. * object, else `false`.
  4371. *
  4372. * @static
  4373. * @memberOf _
  4374. * @category Array
  4375. * @param {Array} array The array to query.
  4376. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4377. * per iteration.
  4378. * @param {*} [thisArg] The `this` binding of `predicate`.
  4379. * @returns {Array} Returns the slice of `array`.
  4380. * @example
  4381. *
  4382. * _.dropRightWhile([1, 2, 3], function(n) {
  4383. * return n > 1;
  4384. * });
  4385. * // => [1]
  4386. *
  4387. * var users = [
  4388. * { 'user': 'barney', 'active': true },
  4389. * { 'user': 'fred', 'active': false },
  4390. * { 'user': 'pebbles', 'active': false }
  4391. * ];
  4392. *
  4393. * // using the `_.matches` callback shorthand
  4394. * _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
  4395. * // => ['barney', 'fred']
  4396. *
  4397. * // using the `_.matchesProperty` callback shorthand
  4398. * _.pluck(_.dropRightWhile(users, 'active', false), 'user');
  4399. * // => ['barney']
  4400. *
  4401. * // using the `_.property` callback shorthand
  4402. * _.pluck(_.dropRightWhile(users, 'active'), 'user');
  4403. * // => ['barney', 'fred', 'pebbles']
  4404. */
  4405. function dropRightWhile(array, predicate, thisArg) {
  4406. return (array && array.length)
  4407. ? baseWhile(array, getCallback(predicate, thisArg, 3), true, true)
  4408. : [];
  4409. }
  4410. /**
  4411. * Creates a slice of `array` excluding elements dropped from the beginning.
  4412. * Elements are dropped until `predicate` returns falsey. The predicate is
  4413. * bound to `thisArg` and invoked with three arguments: (value, index, array).
  4414. *
  4415. * If a property name is provided for `predicate` the created `_.property`
  4416. * style callback returns the property value of the given element.
  4417. *
  4418. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4419. * style callback returns `true` for elements that have a matching property
  4420. * value, else `false`.
  4421. *
  4422. * If an object is provided for `predicate` the created `_.matches` style
  4423. * callback returns `true` for elements that have the properties of the given
  4424. * object, else `false`.
  4425. *
  4426. * @static
  4427. * @memberOf _
  4428. * @category Array
  4429. * @param {Array} array The array to query.
  4430. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4431. * per iteration.
  4432. * @param {*} [thisArg] The `this` binding of `predicate`.
  4433. * @returns {Array} Returns the slice of `array`.
  4434. * @example
  4435. *
  4436. * _.dropWhile([1, 2, 3], function(n) {
  4437. * return n < 3;
  4438. * });
  4439. * // => [3]
  4440. *
  4441. * var users = [
  4442. * { 'user': 'barney', 'active': false },
  4443. * { 'user': 'fred', 'active': false },
  4444. * { 'user': 'pebbles', 'active': true }
  4445. * ];
  4446. *
  4447. * // using the `_.matches` callback shorthand
  4448. * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
  4449. * // => ['fred', 'pebbles']
  4450. *
  4451. * // using the `_.matchesProperty` callback shorthand
  4452. * _.pluck(_.dropWhile(users, 'active', false), 'user');
  4453. * // => ['pebbles']
  4454. *
  4455. * // using the `_.property` callback shorthand
  4456. * _.pluck(_.dropWhile(users, 'active'), 'user');
  4457. * // => ['barney', 'fred', 'pebbles']
  4458. */
  4459. function dropWhile(array, predicate, thisArg) {
  4460. return (array && array.length)
  4461. ? baseWhile(array, getCallback(predicate, thisArg, 3), true)
  4462. : [];
  4463. }
  4464. /**
  4465. * Fills elements of `array` with `value` from `start` up to, but not
  4466. * including, `end`.
  4467. *
  4468. * **Note:** This method mutates `array`.
  4469. *
  4470. * @static
  4471. * @memberOf _
  4472. * @category Array
  4473. * @param {Array} array The array to fill.
  4474. * @param {*} value The value to fill `array` with.
  4475. * @param {number} [start=0] The start position.
  4476. * @param {number} [end=array.length] The end position.
  4477. * @returns {Array} Returns `array`.
  4478. * @example
  4479. *
  4480. * var array = [1, 2, 3];
  4481. *
  4482. * _.fill(array, 'a');
  4483. * console.log(array);
  4484. * // => ['a', 'a', 'a']
  4485. *
  4486. * _.fill(Array(3), 2);
  4487. * // => [2, 2, 2]
  4488. *
  4489. * _.fill([4, 6, 8], '*', 1, 2);
  4490. * // => [4, '*', 8]
  4491. */
  4492. function fill(array, value, start, end) {
  4493. var length = array ? array.length : 0;
  4494. if (!length) {
  4495. return [];
  4496. }
  4497. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  4498. start = 0;
  4499. end = length;
  4500. }
  4501. return baseFill(array, value, start, end);
  4502. }
  4503. /**
  4504. * This method is like `_.find` except that it returns the index of the first
  4505. * element `predicate` returns truthy for instead of the element itself.
  4506. *
  4507. * If a property name is provided for `predicate` the created `_.property`
  4508. * style callback returns the property value of the given element.
  4509. *
  4510. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4511. * style callback returns `true` for elements that have a matching property
  4512. * value, else `false`.
  4513. *
  4514. * If an object is provided for `predicate` the created `_.matches` style
  4515. * callback returns `true` for elements that have the properties of the given
  4516. * object, else `false`.
  4517. *
  4518. * @static
  4519. * @memberOf _
  4520. * @category Array
  4521. * @param {Array} array The array to search.
  4522. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4523. * per iteration.
  4524. * @param {*} [thisArg] The `this` binding of `predicate`.
  4525. * @returns {number} Returns the index of the found element, else `-1`.
  4526. * @example
  4527. *
  4528. * var users = [
  4529. * { 'user': 'barney', 'active': false },
  4530. * { 'user': 'fred', 'active': false },
  4531. * { 'user': 'pebbles', 'active': true }
  4532. * ];
  4533. *
  4534. * _.findIndex(users, function(chr) {
  4535. * return chr.user == 'barney';
  4536. * });
  4537. * // => 0
  4538. *
  4539. * // using the `_.matches` callback shorthand
  4540. * _.findIndex(users, { 'user': 'fred', 'active': false });
  4541. * // => 1
  4542. *
  4543. * // using the `_.matchesProperty` callback shorthand
  4544. * _.findIndex(users, 'active', false);
  4545. * // => 0
  4546. *
  4547. * // using the `_.property` callback shorthand
  4548. * _.findIndex(users, 'active');
  4549. * // => 2
  4550. */
  4551. var findIndex = createFindIndex();
  4552. /**
  4553. * This method is like `_.findIndex` except that it iterates over elements
  4554. * of `collection` from right to left.
  4555. *
  4556. * If a property name is provided for `predicate` the created `_.property`
  4557. * style callback returns the property value of the given element.
  4558. *
  4559. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4560. * style callback returns `true` for elements that have a matching property
  4561. * value, else `false`.
  4562. *
  4563. * If an object is provided for `predicate` the created `_.matches` style
  4564. * callback returns `true` for elements that have the properties of the given
  4565. * object, else `false`.
  4566. *
  4567. * @static
  4568. * @memberOf _
  4569. * @category Array
  4570. * @param {Array} array The array to search.
  4571. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4572. * per iteration.
  4573. * @param {*} [thisArg] The `this` binding of `predicate`.
  4574. * @returns {number} Returns the index of the found element, else `-1`.
  4575. * @example
  4576. *
  4577. * var users = [
  4578. * { 'user': 'barney', 'active': true },
  4579. * { 'user': 'fred', 'active': false },
  4580. * { 'user': 'pebbles', 'active': false }
  4581. * ];
  4582. *
  4583. * _.findLastIndex(users, function(chr) {
  4584. * return chr.user == 'pebbles';
  4585. * });
  4586. * // => 2
  4587. *
  4588. * // using the `_.matches` callback shorthand
  4589. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  4590. * // => 0
  4591. *
  4592. * // using the `_.matchesProperty` callback shorthand
  4593. * _.findLastIndex(users, 'active', false);
  4594. * // => 2
  4595. *
  4596. * // using the `_.property` callback shorthand
  4597. * _.findLastIndex(users, 'active');
  4598. * // => 0
  4599. */
  4600. var findLastIndex = createFindIndex(true);
  4601. /**
  4602. * Gets the first element of `array`.
  4603. *
  4604. * @static
  4605. * @memberOf _
  4606. * @alias head
  4607. * @category Array
  4608. * @param {Array} array The array to query.
  4609. * @returns {*} Returns the first element of `array`.
  4610. * @example
  4611. *
  4612. * _.first([1, 2, 3]);
  4613. * // => 1
  4614. *
  4615. * _.first([]);
  4616. * // => undefined
  4617. */
  4618. function first(array) {
  4619. return array ? array[0] : undefined;
  4620. }
  4621. /**
  4622. * Flattens a nested array. If `isDeep` is `true` the array is recursively
  4623. * flattened, otherwise it's only flattened a single level.
  4624. *
  4625. * @static
  4626. * @memberOf _
  4627. * @category Array
  4628. * @param {Array} array The array to flatten.
  4629. * @param {boolean} [isDeep] Specify a deep flatten.
  4630. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4631. * @returns {Array} Returns the new flattened array.
  4632. * @example
  4633. *
  4634. * _.flatten([1, [2, 3, [4]]]);
  4635. * // => [1, 2, 3, [4]]
  4636. *
  4637. * // using `isDeep`
  4638. * _.flatten([1, [2, 3, [4]]], true);
  4639. * // => [1, 2, 3, 4]
  4640. */
  4641. function flatten(array, isDeep, guard) {
  4642. var length = array ? array.length : 0;
  4643. if (guard && isIterateeCall(array, isDeep, guard)) {
  4644. isDeep = false;
  4645. }
  4646. return length ? baseFlatten(array, isDeep) : [];
  4647. }
  4648. /**
  4649. * Recursively flattens a nested array.
  4650. *
  4651. * @static
  4652. * @memberOf _
  4653. * @category Array
  4654. * @param {Array} array The array to recursively flatten.
  4655. * @returns {Array} Returns the new flattened array.
  4656. * @example
  4657. *
  4658. * _.flattenDeep([1, [2, 3, [4]]]);
  4659. * // => [1, 2, 3, 4]
  4660. */
  4661. function flattenDeep(array) {
  4662. var length = array ? array.length : 0;
  4663. return length ? baseFlatten(array, true) : [];
  4664. }
  4665. /**
  4666. * Gets the index at which the first occurrence of `value` is found in `array`
  4667. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  4668. * for equality comparisons. If `fromIndex` is negative, it's used as the offset
  4669. * from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
  4670. * performs a faster binary search.
  4671. *
  4672. * @static
  4673. * @memberOf _
  4674. * @category Array
  4675. * @param {Array} array The array to search.
  4676. * @param {*} value The value to search for.
  4677. * @param {boolean|number} [fromIndex=0] The index to search from or `true`
  4678. * to perform a binary search on a sorted array.
  4679. * @returns {number} Returns the index of the matched value, else `-1`.
  4680. * @example
  4681. *
  4682. * _.indexOf([1, 2, 1, 2], 2);
  4683. * // => 1
  4684. *
  4685. * // using `fromIndex`
  4686. * _.indexOf([1, 2, 1, 2], 2, 2);
  4687. * // => 3
  4688. *
  4689. * // performing a binary search
  4690. * _.indexOf([1, 1, 2, 2], 2, true);
  4691. * // => 2
  4692. */
  4693. function indexOf(array, value, fromIndex) {
  4694. var length = array ? array.length : 0;
  4695. if (!length) {
  4696. return -1;
  4697. }
  4698. if (typeof fromIndex == 'number') {
  4699. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
  4700. } else if (fromIndex) {
  4701. var index = binaryIndex(array, value);
  4702. if (index < length &&
  4703. (value === value ? (value === array[index]) : (array[index] !== array[index]))) {
  4704. return index;
  4705. }
  4706. return -1;
  4707. }
  4708. return baseIndexOf(array, value, fromIndex || 0);
  4709. }
  4710. /**
  4711. * Gets all but the last element of `array`.
  4712. *
  4713. * @static
  4714. * @memberOf _
  4715. * @category Array
  4716. * @param {Array} array The array to query.
  4717. * @returns {Array} Returns the slice of `array`.
  4718. * @example
  4719. *
  4720. * _.initial([1, 2, 3]);
  4721. * // => [1, 2]
  4722. */
  4723. function initial(array) {
  4724. return dropRight(array, 1);
  4725. }
  4726. /**
  4727. * Creates an array of unique values that are included in all of the provided
  4728. * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  4729. * for equality comparisons.
  4730. *
  4731. * @static
  4732. * @memberOf _
  4733. * @category Array
  4734. * @param {...Array} [arrays] The arrays to inspect.
  4735. * @returns {Array} Returns the new array of shared values.
  4736. * @example
  4737. * _.intersection([1, 2], [4, 2], [2, 1]);
  4738. * // => [2]
  4739. */
  4740. var intersection = restParam(function(arrays) {
  4741. var othLength = arrays.length,
  4742. othIndex = othLength,
  4743. caches = Array(length),
  4744. indexOf = getIndexOf(),
  4745. isCommon = indexOf === baseIndexOf,
  4746. result = [];
  4747. while (othIndex--) {
  4748. var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
  4749. caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
  4750. }
  4751. var array = arrays[0],
  4752. index = -1,
  4753. length = array ? array.length : 0,
  4754. seen = caches[0];
  4755. outer:
  4756. while (++index < length) {
  4757. value = array[index];
  4758. if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
  4759. var othIndex = othLength;
  4760. while (--othIndex) {
  4761. var cache = caches[othIndex];
  4762. if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
  4763. continue outer;
  4764. }
  4765. }
  4766. if (seen) {
  4767. seen.push(value);
  4768. }
  4769. result.push(value);
  4770. }
  4771. }
  4772. return result;
  4773. });
  4774. /**
  4775. * Gets the last element of `array`.
  4776. *
  4777. * @static
  4778. * @memberOf _
  4779. * @category Array
  4780. * @param {Array} array The array to query.
  4781. * @returns {*} Returns the last element of `array`.
  4782. * @example
  4783. *
  4784. * _.last([1, 2, 3]);
  4785. * // => 3
  4786. */
  4787. function last(array) {
  4788. var length = array ? array.length : 0;
  4789. return length ? array[length - 1] : undefined;
  4790. }
  4791. /**
  4792. * This method is like `_.indexOf` except that it iterates over elements of
  4793. * `array` from right to left.
  4794. *
  4795. * @static
  4796. * @memberOf _
  4797. * @category Array
  4798. * @param {Array} array The array to search.
  4799. * @param {*} value The value to search for.
  4800. * @param {boolean|number} [fromIndex=array.length-1] The index to search from
  4801. * or `true` to perform a binary search on a sorted array.
  4802. * @returns {number} Returns the index of the matched value, else `-1`.
  4803. * @example
  4804. *
  4805. * _.lastIndexOf([1, 2, 1, 2], 2);
  4806. * // => 3
  4807. *
  4808. * // using `fromIndex`
  4809. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  4810. * // => 1
  4811. *
  4812. * // performing a binary search
  4813. * _.lastIndexOf([1, 1, 2, 2], 2, true);
  4814. * // => 3
  4815. */
  4816. function lastIndexOf(array, value, fromIndex) {
  4817. var length = array ? array.length : 0;
  4818. if (!length) {
  4819. return -1;
  4820. }
  4821. var index = length;
  4822. if (typeof fromIndex == 'number') {
  4823. index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
  4824. } else if (fromIndex) {
  4825. index = binaryIndex(array, value, true) - 1;
  4826. var other = array[index];
  4827. if (value === value ? (value === other) : (other !== other)) {
  4828. return index;
  4829. }
  4830. return -1;
  4831. }
  4832. if (value !== value) {
  4833. return indexOfNaN(array, index, true);
  4834. }
  4835. while (index--) {
  4836. if (array[index] === value) {
  4837. return index;
  4838. }
  4839. }
  4840. return -1;
  4841. }
  4842. /**
  4843. * Removes all provided values from `array` using
  4844. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  4845. * for equality comparisons.
  4846. *
  4847. * **Note:** Unlike `_.without`, this method mutates `array`.
  4848. *
  4849. * @static
  4850. * @memberOf _
  4851. * @category Array
  4852. * @param {Array} array The array to modify.
  4853. * @param {...*} [values] The values to remove.
  4854. * @returns {Array} Returns `array`.
  4855. * @example
  4856. *
  4857. * var array = [1, 2, 3, 1, 2, 3];
  4858. *
  4859. * _.pull(array, 2, 3);
  4860. * console.log(array);
  4861. * // => [1, 1]
  4862. */
  4863. function pull() {
  4864. var args = arguments,
  4865. array = args[0];
  4866. if (!(array && array.length)) {
  4867. return array;
  4868. }
  4869. var index = 0,
  4870. indexOf = getIndexOf(),
  4871. length = args.length;
  4872. while (++index < length) {
  4873. var fromIndex = 0,
  4874. value = args[index];
  4875. while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
  4876. splice.call(array, fromIndex, 1);
  4877. }
  4878. }
  4879. return array;
  4880. }
  4881. /**
  4882. * Removes elements from `array` corresponding to the given indexes and returns
  4883. * an array of the removed elements. Indexes may be specified as an array of
  4884. * indexes or as individual arguments.
  4885. *
  4886. * **Note:** Unlike `_.at`, this method mutates `array`.
  4887. *
  4888. * @static
  4889. * @memberOf _
  4890. * @category Array
  4891. * @param {Array} array The array to modify.
  4892. * @param {...(number|number[])} [indexes] The indexes of elements to remove,
  4893. * specified as individual indexes or arrays of indexes.
  4894. * @returns {Array} Returns the new array of removed elements.
  4895. * @example
  4896. *
  4897. * var array = [5, 10, 15, 20];
  4898. * var evens = _.pullAt(array, 1, 3);
  4899. *
  4900. * console.log(array);
  4901. * // => [5, 15]
  4902. *
  4903. * console.log(evens);
  4904. * // => [10, 20]
  4905. */
  4906. var pullAt = restParam(function(array, indexes) {
  4907. indexes = baseFlatten(indexes);
  4908. var result = baseAt(array, indexes);
  4909. basePullAt(array, indexes.sort(baseCompareAscending));
  4910. return result;
  4911. });
  4912. /**
  4913. * Removes all elements from `array` that `predicate` returns truthy for
  4914. * and returns an array of the removed elements. The predicate is bound to
  4915. * `thisArg` and invoked with three arguments: (value, index, array).
  4916. *
  4917. * If a property name is provided for `predicate` the created `_.property`
  4918. * style callback returns the property value of the given element.
  4919. *
  4920. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4921. * style callback returns `true` for elements that have a matching property
  4922. * value, else `false`.
  4923. *
  4924. * If an object is provided for `predicate` the created `_.matches` style
  4925. * callback returns `true` for elements that have the properties of the given
  4926. * object, else `false`.
  4927. *
  4928. * **Note:** Unlike `_.filter`, this method mutates `array`.
  4929. *
  4930. * @static
  4931. * @memberOf _
  4932. * @category Array
  4933. * @param {Array} array The array to modify.
  4934. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4935. * per iteration.
  4936. * @param {*} [thisArg] The `this` binding of `predicate`.
  4937. * @returns {Array} Returns the new array of removed elements.
  4938. * @example
  4939. *
  4940. * var array = [1, 2, 3, 4];
  4941. * var evens = _.remove(array, function(n) {
  4942. * return n % 2 == 0;
  4943. * });
  4944. *
  4945. * console.log(array);
  4946. * // => [1, 3]
  4947. *
  4948. * console.log(evens);
  4949. * // => [2, 4]
  4950. */
  4951. function remove(array, predicate, thisArg) {
  4952. var result = [];
  4953. if (!(array && array.length)) {
  4954. return result;
  4955. }
  4956. var index = -1,
  4957. indexes = [],
  4958. length = array.length;
  4959. predicate = getCallback(predicate, thisArg, 3);
  4960. while (++index < length) {
  4961. var value = array[index];
  4962. if (predicate(value, index, array)) {
  4963. result.push(value);
  4964. indexes.push(index);
  4965. }
  4966. }
  4967. basePullAt(array, indexes);
  4968. return result;
  4969. }
  4970. /**
  4971. * Gets all but the first element of `array`.
  4972. *
  4973. * @static
  4974. * @memberOf _
  4975. * @alias tail
  4976. * @category Array
  4977. * @param {Array} array The array to query.
  4978. * @returns {Array} Returns the slice of `array`.
  4979. * @example
  4980. *
  4981. * _.rest([1, 2, 3]);
  4982. * // => [2, 3]
  4983. */
  4984. function rest(array) {
  4985. return drop(array, 1);
  4986. }
  4987. /**
  4988. * Creates a slice of `array` from `start` up to, but not including, `end`.
  4989. *
  4990. * **Note:** This method is used instead of `Array#slice` to support node
  4991. * lists in IE < 9 and to ensure dense arrays are returned.
  4992. *
  4993. * @static
  4994. * @memberOf _
  4995. * @category Array
  4996. * @param {Array} array The array to slice.
  4997. * @param {number} [start=0] The start position.
  4998. * @param {number} [end=array.length] The end position.
  4999. * @returns {Array} Returns the slice of `array`.
  5000. */
  5001. function slice(array, start, end) {
  5002. var length = array ? array.length : 0;
  5003. if (!length) {
  5004. return [];
  5005. }
  5006. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  5007. start = 0;
  5008. end = length;
  5009. }
  5010. return baseSlice(array, start, end);
  5011. }
  5012. /**
  5013. * Uses a binary search to determine the lowest index at which `value` should
  5014. * be inserted into `array` in order to maintain its sort order. If an iteratee
  5015. * function is provided it's invoked for `value` and each element of `array`
  5016. * to compute their sort ranking. The iteratee is bound to `thisArg` and
  5017. * invoked with one argument; (value).
  5018. *
  5019. * If a property name is provided for `iteratee` the created `_.property`
  5020. * style callback returns the property value of the given element.
  5021. *
  5022. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5023. * style callback returns `true` for elements that have a matching property
  5024. * value, else `false`.
  5025. *
  5026. * If an object is provided for `iteratee` the created `_.matches` style
  5027. * callback returns `true` for elements that have the properties of the given
  5028. * object, else `false`.
  5029. *
  5030. * @static
  5031. * @memberOf _
  5032. * @category Array
  5033. * @param {Array} array The sorted array to inspect.
  5034. * @param {*} value The value to evaluate.
  5035. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5036. * per iteration.
  5037. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5038. * @returns {number} Returns the index at which `value` should be inserted
  5039. * into `array`.
  5040. * @example
  5041. *
  5042. * _.sortedIndex([30, 50], 40);
  5043. * // => 1
  5044. *
  5045. * _.sortedIndex([4, 4, 5, 5], 5);
  5046. * // => 2
  5047. *
  5048. * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
  5049. *
  5050. * // using an iteratee function
  5051. * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
  5052. * return this.data[word];
  5053. * }, dict);
  5054. * // => 1
  5055. *
  5056. * // using the `_.property` callback shorthand
  5057. * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
  5058. * // => 1
  5059. */
  5060. var sortedIndex = createSortedIndex();
  5061. /**
  5062. * This method is like `_.sortedIndex` except that it returns the highest
  5063. * index at which `value` should be inserted into `array` in order to
  5064. * maintain its sort order.
  5065. *
  5066. * @static
  5067. * @memberOf _
  5068. * @category Array
  5069. * @param {Array} array The sorted array to inspect.
  5070. * @param {*} value The value to evaluate.
  5071. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5072. * per iteration.
  5073. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5074. * @returns {number} Returns the index at which `value` should be inserted
  5075. * into `array`.
  5076. * @example
  5077. *
  5078. * _.sortedLastIndex([4, 4, 5, 5], 5);
  5079. * // => 4
  5080. */
  5081. var sortedLastIndex = createSortedIndex(true);
  5082. /**
  5083. * Creates a slice of `array` with `n` elements taken from the beginning.
  5084. *
  5085. * @static
  5086. * @memberOf _
  5087. * @category Array
  5088. * @param {Array} array The array to query.
  5089. * @param {number} [n=1] The number of elements to take.
  5090. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  5091. * @returns {Array} Returns the slice of `array`.
  5092. * @example
  5093. *
  5094. * _.take([1, 2, 3]);
  5095. * // => [1]
  5096. *
  5097. * _.take([1, 2, 3], 2);
  5098. * // => [1, 2]
  5099. *
  5100. * _.take([1, 2, 3], 5);
  5101. * // => [1, 2, 3]
  5102. *
  5103. * _.take([1, 2, 3], 0);
  5104. * // => []
  5105. */
  5106. function take(array, n, guard) {
  5107. var length = array ? array.length : 0;
  5108. if (!length) {
  5109. return [];
  5110. }
  5111. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  5112. n = 1;
  5113. }
  5114. return baseSlice(array, 0, n < 0 ? 0 : n);
  5115. }
  5116. /**
  5117. * Creates a slice of `array` with `n` elements taken from the end.
  5118. *
  5119. * @static
  5120. * @memberOf _
  5121. * @category Array
  5122. * @param {Array} array The array to query.
  5123. * @param {number} [n=1] The number of elements to take.
  5124. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  5125. * @returns {Array} Returns the slice of `array`.
  5126. * @example
  5127. *
  5128. * _.takeRight([1, 2, 3]);
  5129. * // => [3]
  5130. *
  5131. * _.takeRight([1, 2, 3], 2);
  5132. * // => [2, 3]
  5133. *
  5134. * _.takeRight([1, 2, 3], 5);
  5135. * // => [1, 2, 3]
  5136. *
  5137. * _.takeRight([1, 2, 3], 0);
  5138. * // => []
  5139. */
  5140. function takeRight(array, n, guard) {
  5141. var length = array ? array.length : 0;
  5142. if (!length) {
  5143. return [];
  5144. }
  5145. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  5146. n = 1;
  5147. }
  5148. n = length - (+n || 0);
  5149. return baseSlice(array, n < 0 ? 0 : n);
  5150. }
  5151. /**
  5152. * Creates a slice of `array` with elements taken from the end. Elements are
  5153. * taken until `predicate` returns falsey. The predicate is bound to `thisArg`
  5154. * and invoked with three arguments: (value, index, array).
  5155. *
  5156. * If a property name is provided for `predicate` the created `_.property`
  5157. * style callback returns the property value of the given element.
  5158. *
  5159. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5160. * style callback returns `true` for elements that have a matching property
  5161. * value, else `false`.
  5162. *
  5163. * If an object is provided for `predicate` the created `_.matches` style
  5164. * callback returns `true` for elements that have the properties of the given
  5165. * object, else `false`.
  5166. *
  5167. * @static
  5168. * @memberOf _
  5169. * @category Array
  5170. * @param {Array} array The array to query.
  5171. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5172. * per iteration.
  5173. * @param {*} [thisArg] The `this` binding of `predicate`.
  5174. * @returns {Array} Returns the slice of `array`.
  5175. * @example
  5176. *
  5177. * _.takeRightWhile([1, 2, 3], function(n) {
  5178. * return n > 1;
  5179. * });
  5180. * // => [2, 3]
  5181. *
  5182. * var users = [
  5183. * { 'user': 'barney', 'active': true },
  5184. * { 'user': 'fred', 'active': false },
  5185. * { 'user': 'pebbles', 'active': false }
  5186. * ];
  5187. *
  5188. * // using the `_.matches` callback shorthand
  5189. * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
  5190. * // => ['pebbles']
  5191. *
  5192. * // using the `_.matchesProperty` callback shorthand
  5193. * _.pluck(_.takeRightWhile(users, 'active', false), 'user');
  5194. * // => ['fred', 'pebbles']
  5195. *
  5196. * // using the `_.property` callback shorthand
  5197. * _.pluck(_.takeRightWhile(users, 'active'), 'user');
  5198. * // => []
  5199. */
  5200. function takeRightWhile(array, predicate, thisArg) {
  5201. return (array && array.length)
  5202. ? baseWhile(array, getCallback(predicate, thisArg, 3), false, true)
  5203. : [];
  5204. }
  5205. /**
  5206. * Creates a slice of `array` with elements taken from the beginning. Elements
  5207. * are taken until `predicate` returns falsey. The predicate is bound to
  5208. * `thisArg` and invoked with three arguments: (value, index, array).
  5209. *
  5210. * If a property name is provided for `predicate` the created `_.property`
  5211. * style callback returns the property value of the given element.
  5212. *
  5213. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5214. * style callback returns `true` for elements that have a matching property
  5215. * value, else `false`.
  5216. *
  5217. * If an object is provided for `predicate` the created `_.matches` style
  5218. * callback returns `true` for elements that have the properties of the given
  5219. * object, else `false`.
  5220. *
  5221. * @static
  5222. * @memberOf _
  5223. * @category Array
  5224. * @param {Array} array The array to query.
  5225. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5226. * per iteration.
  5227. * @param {*} [thisArg] The `this` binding of `predicate`.
  5228. * @returns {Array} Returns the slice of `array`.
  5229. * @example
  5230. *
  5231. * _.takeWhile([1, 2, 3], function(n) {
  5232. * return n < 3;
  5233. * });
  5234. * // => [1, 2]
  5235. *
  5236. * var users = [
  5237. * { 'user': 'barney', 'active': false },
  5238. * { 'user': 'fred', 'active': false},
  5239. * { 'user': 'pebbles', 'active': true }
  5240. * ];
  5241. *
  5242. * // using the `_.matches` callback shorthand
  5243. * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
  5244. * // => ['barney']
  5245. *
  5246. * // using the `_.matchesProperty` callback shorthand
  5247. * _.pluck(_.takeWhile(users, 'active', false), 'user');
  5248. * // => ['barney', 'fred']
  5249. *
  5250. * // using the `_.property` callback shorthand
  5251. * _.pluck(_.takeWhile(users, 'active'), 'user');
  5252. * // => []
  5253. */
  5254. function takeWhile(array, predicate, thisArg) {
  5255. return (array && array.length)
  5256. ? baseWhile(array, getCallback(predicate, thisArg, 3))
  5257. : [];
  5258. }
  5259. /**
  5260. * Creates an array of unique values, in order, from all of the provided arrays
  5261. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  5262. * for equality comparisons.
  5263. *
  5264. * @static
  5265. * @memberOf _
  5266. * @category Array
  5267. * @param {...Array} [arrays] The arrays to inspect.
  5268. * @returns {Array} Returns the new array of combined values.
  5269. * @example
  5270. *
  5271. * _.union([1, 2], [4, 2], [2, 1]);
  5272. * // => [1, 2, 4]
  5273. */
  5274. var union = restParam(function(arrays) {
  5275. return baseUniq(baseFlatten(arrays, false, true));
  5276. });
  5277. /**
  5278. * Creates a duplicate-free version of an array, using
  5279. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  5280. * for equality comparisons, in which only the first occurence of each element
  5281. * is kept. Providing `true` for `isSorted` performs a faster search algorithm
  5282. * for sorted arrays. If an iteratee function is provided it's invoked for
  5283. * each element in the array to generate the criterion by which uniqueness
  5284. * is computed. The `iteratee` is bound to `thisArg` and invoked with three
  5285. * arguments: (value, index, array).
  5286. *
  5287. * If a property name is provided for `iteratee` the created `_.property`
  5288. * style callback returns the property value of the given element.
  5289. *
  5290. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5291. * style callback returns `true` for elements that have a matching property
  5292. * value, else `false`.
  5293. *
  5294. * If an object is provided for `iteratee` the created `_.matches` style
  5295. * callback returns `true` for elements that have the properties of the given
  5296. * object, else `false`.
  5297. *
  5298. * @static
  5299. * @memberOf _
  5300. * @alias unique
  5301. * @category Array
  5302. * @param {Array} array The array to inspect.
  5303. * @param {boolean} [isSorted] Specify the array is sorted.
  5304. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  5305. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5306. * @returns {Array} Returns the new duplicate-value-free array.
  5307. * @example
  5308. *
  5309. * _.uniq([2, 1, 2]);
  5310. * // => [2, 1]
  5311. *
  5312. * // using `isSorted`
  5313. * _.uniq([1, 1, 2], true);
  5314. * // => [1, 2]
  5315. *
  5316. * // using an iteratee function
  5317. * _.uniq([1, 2.5, 1.5, 2], function(n) {
  5318. * return this.floor(n);
  5319. * }, Math);
  5320. * // => [1, 2.5]
  5321. *
  5322. * // using the `_.property` callback shorthand
  5323. * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  5324. * // => [{ 'x': 1 }, { 'x': 2 }]
  5325. */
  5326. function uniq(array, isSorted, iteratee, thisArg) {
  5327. var length = array ? array.length : 0;
  5328. if (!length) {
  5329. return [];
  5330. }
  5331. if (isSorted != null && typeof isSorted != 'boolean') {
  5332. thisArg = iteratee;
  5333. iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
  5334. isSorted = false;
  5335. }
  5336. var callback = getCallback();
  5337. if (!(iteratee == null && callback === baseCallback)) {
  5338. iteratee = callback(iteratee, thisArg, 3);
  5339. }
  5340. return (isSorted && getIndexOf() === baseIndexOf)
  5341. ? sortedUniq(array, iteratee)
  5342. : baseUniq(array, iteratee);
  5343. }
  5344. /**
  5345. * This method is like `_.zip` except that it accepts an array of grouped
  5346. * elements and creates an array regrouping the elements to their pre-zip
  5347. * configuration.
  5348. *
  5349. * @static
  5350. * @memberOf _
  5351. * @category Array
  5352. * @param {Array} array The array of grouped elements to process.
  5353. * @returns {Array} Returns the new array of regrouped elements.
  5354. * @example
  5355. *
  5356. * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
  5357. * // => [['fred', 30, true], ['barney', 40, false]]
  5358. *
  5359. * _.unzip(zipped);
  5360. * // => [['fred', 'barney'], [30, 40], [true, false]]
  5361. */
  5362. function unzip(array) {
  5363. if (!(array && array.length)) {
  5364. return [];
  5365. }
  5366. var index = -1,
  5367. length = 0;
  5368. array = arrayFilter(array, function(group) {
  5369. if (isArrayLike(group)) {
  5370. length = nativeMax(group.length, length);
  5371. return true;
  5372. }
  5373. });
  5374. var result = Array(length);
  5375. while (++index < length) {
  5376. result[index] = arrayMap(array, baseProperty(index));
  5377. }
  5378. return result;
  5379. }
  5380. /**
  5381. * This method is like `_.unzip` except that it accepts an iteratee to specify
  5382. * how regrouped values should be combined. The `iteratee` is bound to `thisArg`
  5383. * and invoked with four arguments: (accumulator, value, index, group).
  5384. *
  5385. * @static
  5386. * @memberOf _
  5387. * @category Array
  5388. * @param {Array} array The array of grouped elements to process.
  5389. * @param {Function} [iteratee] The function to combine regrouped values.
  5390. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5391. * @returns {Array} Returns the new array of regrouped elements.
  5392. * @example
  5393. *
  5394. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  5395. * // => [[1, 10, 100], [2, 20, 200]]
  5396. *
  5397. * _.unzipWith(zipped, _.add);
  5398. * // => [3, 30, 300]
  5399. */
  5400. function unzipWith(array, iteratee, thisArg) {
  5401. var length = array ? array.length : 0;
  5402. if (!length) {
  5403. return [];
  5404. }
  5405. var result = unzip(array);
  5406. if (iteratee == null) {
  5407. return result;
  5408. }
  5409. iteratee = bindCallback(iteratee, thisArg, 4);
  5410. return arrayMap(result, function(group) {
  5411. return arrayReduce(group, iteratee, undefined, true);
  5412. });
  5413. }
  5414. /**
  5415. * Creates an array excluding all provided values using
  5416. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  5417. * for equality comparisons.
  5418. *
  5419. * @static
  5420. * @memberOf _
  5421. * @category Array
  5422. * @param {Array} array The array to filter.
  5423. * @param {...*} [values] The values to exclude.
  5424. * @returns {Array} Returns the new array of filtered values.
  5425. * @example
  5426. *
  5427. * _.without([1, 2, 1, 3], 1, 2);
  5428. * // => [3]
  5429. */
  5430. var without = restParam(function(array, values) {
  5431. return isArrayLike(array)
  5432. ? baseDifference(array, values)
  5433. : [];
  5434. });
  5435. /**
  5436. * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  5437. * of the provided arrays.
  5438. *
  5439. * @static
  5440. * @memberOf _
  5441. * @category Array
  5442. * @param {...Array} [arrays] The arrays to inspect.
  5443. * @returns {Array} Returns the new array of values.
  5444. * @example
  5445. *
  5446. * _.xor([1, 2], [4, 2]);
  5447. * // => [1, 4]
  5448. */
  5449. function xor() {
  5450. var index = -1,
  5451. length = arguments.length;
  5452. while (++index < length) {
  5453. var array = arguments[index];
  5454. if (isArrayLike(array)) {
  5455. var result = result
  5456. ? arrayPush(baseDifference(result, array), baseDifference(array, result))
  5457. : array;
  5458. }
  5459. }
  5460. return result ? baseUniq(result) : [];
  5461. }
  5462. /**
  5463. * Creates an array of grouped elements, the first of which contains the first
  5464. * elements of the given arrays, the second of which contains the second elements
  5465. * of the given arrays, and so on.
  5466. *
  5467. * @static
  5468. * @memberOf _
  5469. * @category Array
  5470. * @param {...Array} [arrays] The arrays to process.
  5471. * @returns {Array} Returns the new array of grouped elements.
  5472. * @example
  5473. *
  5474. * _.zip(['fred', 'barney'], [30, 40], [true, false]);
  5475. * // => [['fred', 30, true], ['barney', 40, false]]
  5476. */
  5477. var zip = restParam(unzip);
  5478. /**
  5479. * The inverse of `_.pairs`; this method returns an object composed from arrays
  5480. * of property names and values. Provide either a single two dimensional array,
  5481. * e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
  5482. * and one of corresponding values.
  5483. *
  5484. * @static
  5485. * @memberOf _
  5486. * @alias object
  5487. * @category Array
  5488. * @param {Array} props The property names.
  5489. * @param {Array} [values=[]] The property values.
  5490. * @returns {Object} Returns the new object.
  5491. * @example
  5492. *
  5493. * _.zipObject([['fred', 30], ['barney', 40]]);
  5494. * // => { 'fred': 30, 'barney': 40 }
  5495. *
  5496. * _.zipObject(['fred', 'barney'], [30, 40]);
  5497. * // => { 'fred': 30, 'barney': 40 }
  5498. */
  5499. function zipObject(props, values) {
  5500. var index = -1,
  5501. length = props ? props.length : 0,
  5502. result = {};
  5503. if (length && !values && !isArray(props[0])) {
  5504. values = [];
  5505. }
  5506. while (++index < length) {
  5507. var key = props[index];
  5508. if (values) {
  5509. result[key] = values[index];
  5510. } else if (key) {
  5511. result[key[0]] = key[1];
  5512. }
  5513. }
  5514. return result;
  5515. }
  5516. /**
  5517. * This method is like `_.zip` except that it accepts an iteratee to specify
  5518. * how grouped values should be combined. The `iteratee` is bound to `thisArg`
  5519. * and invoked with four arguments: (accumulator, value, index, group).
  5520. *
  5521. * @static
  5522. * @memberOf _
  5523. * @category Array
  5524. * @param {...Array} [arrays] The arrays to process.
  5525. * @param {Function} [iteratee] The function to combine grouped values.
  5526. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5527. * @returns {Array} Returns the new array of grouped elements.
  5528. * @example
  5529. *
  5530. * _.zipWith([1, 2], [10, 20], [100, 200], _.add);
  5531. * // => [111, 222]
  5532. */
  5533. var zipWith = restParam(function(arrays) {
  5534. var length = arrays.length,
  5535. iteratee = length > 2 ? arrays[length - 2] : undefined,
  5536. thisArg = length > 1 ? arrays[length - 1] : undefined;
  5537. if (length > 2 && typeof iteratee == 'function') {
  5538. length -= 2;
  5539. } else {
  5540. iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
  5541. thisArg = undefined;
  5542. }
  5543. arrays.length = length;
  5544. return unzipWith(arrays, iteratee, thisArg);
  5545. });
  5546. /*------------------------------------------------------------------------*/
  5547. /**
  5548. * Creates a `lodash` object that wraps `value` with explicit method
  5549. * chaining enabled.
  5550. *
  5551. * @static
  5552. * @memberOf _
  5553. * @category Chain
  5554. * @param {*} value The value to wrap.
  5555. * @returns {Object} Returns the new `lodash` wrapper instance.
  5556. * @example
  5557. *
  5558. * var users = [
  5559. * { 'user': 'barney', 'age': 36 },
  5560. * { 'user': 'fred', 'age': 40 },
  5561. * { 'user': 'pebbles', 'age': 1 }
  5562. * ];
  5563. *
  5564. * var youngest = _.chain(users)
  5565. * .sortBy('age')
  5566. * .map(function(chr) {
  5567. * return chr.user + ' is ' + chr.age;
  5568. * })
  5569. * .first()
  5570. * .value();
  5571. * // => 'pebbles is 1'
  5572. */
  5573. function chain(value) {
  5574. var result = lodash(value);
  5575. result.__chain__ = true;
  5576. return result;
  5577. }
  5578. /**
  5579. * This method invokes `interceptor` and returns `value`. The interceptor is
  5580. * bound to `thisArg` and invoked with one argument; (value). The purpose of
  5581. * this method is to "tap into" a method chain in order to perform operations
  5582. * on intermediate results within the chain.
  5583. *
  5584. * @static
  5585. * @memberOf _
  5586. * @category Chain
  5587. * @param {*} value The value to provide to `interceptor`.
  5588. * @param {Function} interceptor The function to invoke.
  5589. * @param {*} [thisArg] The `this` binding of `interceptor`.
  5590. * @returns {*} Returns `value`.
  5591. * @example
  5592. *
  5593. * _([1, 2, 3])
  5594. * .tap(function(array) {
  5595. * array.pop();
  5596. * })
  5597. * .reverse()
  5598. * .value();
  5599. * // => [2, 1]
  5600. */
  5601. function tap(value, interceptor, thisArg) {
  5602. interceptor.call(thisArg, value);
  5603. return value;
  5604. }
  5605. /**
  5606. * This method is like `_.tap` except that it returns the result of `interceptor`.
  5607. *
  5608. * @static
  5609. * @memberOf _
  5610. * @category Chain
  5611. * @param {*} value The value to provide to `interceptor`.
  5612. * @param {Function} interceptor The function to invoke.
  5613. * @param {*} [thisArg] The `this` binding of `interceptor`.
  5614. * @returns {*} Returns the result of `interceptor`.
  5615. * @example
  5616. *
  5617. * _(' abc ')
  5618. * .chain()
  5619. * .trim()
  5620. * .thru(function(value) {
  5621. * return [value];
  5622. * })
  5623. * .value();
  5624. * // => ['abc']
  5625. */
  5626. function thru(value, interceptor, thisArg) {
  5627. return interceptor.call(thisArg, value);
  5628. }
  5629. /**
  5630. * Enables explicit method chaining on the wrapper object.
  5631. *
  5632. * @name chain
  5633. * @memberOf _
  5634. * @category Chain
  5635. * @returns {Object} Returns the new `lodash` wrapper instance.
  5636. * @example
  5637. *
  5638. * var users = [
  5639. * { 'user': 'barney', 'age': 36 },
  5640. * { 'user': 'fred', 'age': 40 }
  5641. * ];
  5642. *
  5643. * // without explicit chaining
  5644. * _(users).first();
  5645. * // => { 'user': 'barney', 'age': 36 }
  5646. *
  5647. * // with explicit chaining
  5648. * _(users).chain()
  5649. * .first()
  5650. * .pick('user')
  5651. * .value();
  5652. * // => { 'user': 'barney' }
  5653. */
  5654. function wrapperChain() {
  5655. return chain(this);
  5656. }
  5657. /**
  5658. * Executes the chained sequence and returns the wrapped result.
  5659. *
  5660. * @name commit
  5661. * @memberOf _
  5662. * @category Chain
  5663. * @returns {Object} Returns the new `lodash` wrapper instance.
  5664. * @example
  5665. *
  5666. * var array = [1, 2];
  5667. * var wrapped = _(array).push(3);
  5668. *
  5669. * console.log(array);
  5670. * // => [1, 2]
  5671. *
  5672. * wrapped = wrapped.commit();
  5673. * console.log(array);
  5674. * // => [1, 2, 3]
  5675. *
  5676. * wrapped.last();
  5677. * // => 3
  5678. *
  5679. * console.log(array);
  5680. * // => [1, 2, 3]
  5681. */
  5682. function wrapperCommit() {
  5683. return new LodashWrapper(this.value(), this.__chain__);
  5684. }
  5685. /**
  5686. * Creates a new array joining a wrapped array with any additional arrays
  5687. * and/or values.
  5688. *
  5689. * @name concat
  5690. * @memberOf _
  5691. * @category Chain
  5692. * @param {...*} [values] The values to concatenate.
  5693. * @returns {Array} Returns the new concatenated array.
  5694. * @example
  5695. *
  5696. * var array = [1];
  5697. * var wrapped = _(array).concat(2, [3], [[4]]);
  5698. *
  5699. * console.log(wrapped.value());
  5700. * // => [1, 2, 3, [4]]
  5701. *
  5702. * console.log(array);
  5703. * // => [1]
  5704. */
  5705. var wrapperConcat = restParam(function(values) {
  5706. values = baseFlatten(values);
  5707. return this.thru(function(array) {
  5708. return arrayConcat(isArray(array) ? array : [toObject(array)], values);
  5709. });
  5710. });
  5711. /**
  5712. * Creates a clone of the chained sequence planting `value` as the wrapped value.
  5713. *
  5714. * @name plant
  5715. * @memberOf _
  5716. * @category Chain
  5717. * @returns {Object} Returns the new `lodash` wrapper instance.
  5718. * @example
  5719. *
  5720. * var array = [1, 2];
  5721. * var wrapped = _(array).map(function(value) {
  5722. * return Math.pow(value, 2);
  5723. * });
  5724. *
  5725. * var other = [3, 4];
  5726. * var otherWrapped = wrapped.plant(other);
  5727. *
  5728. * otherWrapped.value();
  5729. * // => [9, 16]
  5730. *
  5731. * wrapped.value();
  5732. * // => [1, 4]
  5733. */
  5734. function wrapperPlant(value) {
  5735. var result,
  5736. parent = this;
  5737. while (parent instanceof baseLodash) {
  5738. var clone = wrapperClone(parent);
  5739. if (result) {
  5740. previous.__wrapped__ = clone;
  5741. } else {
  5742. result = clone;
  5743. }
  5744. var previous = clone;
  5745. parent = parent.__wrapped__;
  5746. }
  5747. previous.__wrapped__ = value;
  5748. return result;
  5749. }
  5750. /**
  5751. * Reverses the wrapped array so the first element becomes the last, the
  5752. * second element becomes the second to last, and so on.
  5753. *
  5754. * **Note:** This method mutates the wrapped array.
  5755. *
  5756. * @name reverse
  5757. * @memberOf _
  5758. * @category Chain
  5759. * @returns {Object} Returns the new reversed `lodash` wrapper instance.
  5760. * @example
  5761. *
  5762. * var array = [1, 2, 3];
  5763. *
  5764. * _(array).reverse().value()
  5765. * // => [3, 2, 1]
  5766. *
  5767. * console.log(array);
  5768. * // => [3, 2, 1]
  5769. */
  5770. function wrapperReverse() {
  5771. var value = this.__wrapped__;
  5772. var interceptor = function(value) {
  5773. return value.reverse();
  5774. };
  5775. if (value instanceof LazyWrapper) {
  5776. var wrapped = value;
  5777. if (this.__actions__.length) {
  5778. wrapped = new LazyWrapper(this);
  5779. }
  5780. wrapped = wrapped.reverse();
  5781. wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  5782. return new LodashWrapper(wrapped, this.__chain__);
  5783. }
  5784. return this.thru(interceptor);
  5785. }
  5786. /**
  5787. * Produces the result of coercing the unwrapped value to a string.
  5788. *
  5789. * @name toString
  5790. * @memberOf _
  5791. * @category Chain
  5792. * @returns {string} Returns the coerced string value.
  5793. * @example
  5794. *
  5795. * _([1, 2, 3]).toString();
  5796. * // => '1,2,3'
  5797. */
  5798. function wrapperToString() {
  5799. return (this.value() + '');
  5800. }
  5801. /**
  5802. * Executes the chained sequence to extract the unwrapped value.
  5803. *
  5804. * @name value
  5805. * @memberOf _
  5806. * @alias run, toJSON, valueOf
  5807. * @category Chain
  5808. * @returns {*} Returns the resolved unwrapped value.
  5809. * @example
  5810. *
  5811. * _([1, 2, 3]).value();
  5812. * // => [1, 2, 3]
  5813. */
  5814. function wrapperValue() {
  5815. return baseWrapperValue(this.__wrapped__, this.__actions__);
  5816. }
  5817. /*------------------------------------------------------------------------*/
  5818. /**
  5819. * Creates an array of elements corresponding to the given keys, or indexes,
  5820. * of `collection`. Keys may be specified as individual arguments or as arrays
  5821. * of keys.
  5822. *
  5823. * @static
  5824. * @memberOf _
  5825. * @category Collection
  5826. * @param {Array|Object|string} collection The collection to iterate over.
  5827. * @param {...(number|number[]|string|string[])} [props] The property names
  5828. * or indexes of elements to pick, specified individually or in arrays.
  5829. * @returns {Array} Returns the new array of picked elements.
  5830. * @example
  5831. *
  5832. * _.at(['a', 'b', 'c'], [0, 2]);
  5833. * // => ['a', 'c']
  5834. *
  5835. * _.at(['barney', 'fred', 'pebbles'], 0, 2);
  5836. * // => ['barney', 'pebbles']
  5837. */
  5838. var at = restParam(function(collection, props) {
  5839. if (isArrayLike(collection)) {
  5840. collection = toIterable(collection);
  5841. }
  5842. return baseAt(collection, baseFlatten(props));
  5843. });
  5844. /**
  5845. * Creates an object composed of keys generated from the results of running
  5846. * each element of `collection` through `iteratee`. The corresponding value
  5847. * of each key is the number of times the key was returned by `iteratee`.
  5848. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  5849. * (value, index|key, collection).
  5850. *
  5851. * If a property name is provided for `iteratee` the created `_.property`
  5852. * style callback returns the property value of the given element.
  5853. *
  5854. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5855. * style callback returns `true` for elements that have a matching property
  5856. * value, else `false`.
  5857. *
  5858. * If an object is provided for `iteratee` the created `_.matches` style
  5859. * callback returns `true` for elements that have the properties of the given
  5860. * object, else `false`.
  5861. *
  5862. * @static
  5863. * @memberOf _
  5864. * @category Collection
  5865. * @param {Array|Object|string} collection The collection to iterate over.
  5866. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5867. * per iteration.
  5868. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5869. * @returns {Object} Returns the composed aggregate object.
  5870. * @example
  5871. *
  5872. * _.countBy([4.3, 6.1, 6.4], function(n) {
  5873. * return Math.floor(n);
  5874. * });
  5875. * // => { '4': 1, '6': 2 }
  5876. *
  5877. * _.countBy([4.3, 6.1, 6.4], function(n) {
  5878. * return this.floor(n);
  5879. * }, Math);
  5880. * // => { '4': 1, '6': 2 }
  5881. *
  5882. * _.countBy(['one', 'two', 'three'], 'length');
  5883. * // => { '3': 2, '5': 1 }
  5884. */
  5885. var countBy = createAggregator(function(result, value, key) {
  5886. hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
  5887. });
  5888. /**
  5889. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  5890. * The predicate is bound to `thisArg` and invoked with three arguments:
  5891. * (value, index|key, collection).
  5892. *
  5893. * If a property name is provided for `predicate` the created `_.property`
  5894. * style callback returns the property value of the given element.
  5895. *
  5896. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5897. * style callback returns `true` for elements that have a matching property
  5898. * value, else `false`.
  5899. *
  5900. * If an object is provided for `predicate` the created `_.matches` style
  5901. * callback returns `true` for elements that have the properties of the given
  5902. * object, else `false`.
  5903. *
  5904. * @static
  5905. * @memberOf _
  5906. * @alias all
  5907. * @category Collection
  5908. * @param {Array|Object|string} collection The collection to iterate over.
  5909. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5910. * per iteration.
  5911. * @param {*} [thisArg] The `this` binding of `predicate`.
  5912. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  5913. * else `false`.
  5914. * @example
  5915. *
  5916. * _.every([true, 1, null, 'yes'], Boolean);
  5917. * // => false
  5918. *
  5919. * var users = [
  5920. * { 'user': 'barney', 'active': false },
  5921. * { 'user': 'fred', 'active': false }
  5922. * ];
  5923. *
  5924. * // using the `_.matches` callback shorthand
  5925. * _.every(users, { 'user': 'barney', 'active': false });
  5926. * // => false
  5927. *
  5928. * // using the `_.matchesProperty` callback shorthand
  5929. * _.every(users, 'active', false);
  5930. * // => true
  5931. *
  5932. * // using the `_.property` callback shorthand
  5933. * _.every(users, 'active');
  5934. * // => false
  5935. */
  5936. function every(collection, predicate, thisArg) {
  5937. var func = isArray(collection) ? arrayEvery : baseEvery;
  5938. if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
  5939. predicate = undefined;
  5940. }
  5941. if (typeof predicate != 'function' || thisArg !== undefined) {
  5942. predicate = getCallback(predicate, thisArg, 3);
  5943. }
  5944. return func(collection, predicate);
  5945. }
  5946. /**
  5947. * Iterates over elements of `collection`, returning an array of all elements
  5948. * `predicate` returns truthy for. The predicate is bound to `thisArg` and
  5949. * invoked with three arguments: (value, index|key, collection).
  5950. *
  5951. * If a property name is provided for `predicate` the created `_.property`
  5952. * style callback returns the property value of the given element.
  5953. *
  5954. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5955. * style callback returns `true` for elements that have a matching property
  5956. * value, else `false`.
  5957. *
  5958. * If an object is provided for `predicate` the created `_.matches` style
  5959. * callback returns `true` for elements that have the properties of the given
  5960. * object, else `false`.
  5961. *
  5962. * @static
  5963. * @memberOf _
  5964. * @alias select
  5965. * @category Collection
  5966. * @param {Array|Object|string} collection The collection to iterate over.
  5967. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5968. * per iteration.
  5969. * @param {*} [thisArg] The `this` binding of `predicate`.
  5970. * @returns {Array} Returns the new filtered array.
  5971. * @example
  5972. *
  5973. * _.filter([4, 5, 6], function(n) {
  5974. * return n % 2 == 0;
  5975. * });
  5976. * // => [4, 6]
  5977. *
  5978. * var users = [
  5979. * { 'user': 'barney', 'age': 36, 'active': true },
  5980. * { 'user': 'fred', 'age': 40, 'active': false }
  5981. * ];
  5982. *
  5983. * // using the `_.matches` callback shorthand
  5984. * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
  5985. * // => ['barney']
  5986. *
  5987. * // using the `_.matchesProperty` callback shorthand
  5988. * _.pluck(_.filter(users, 'active', false), 'user');
  5989. * // => ['fred']
  5990. *
  5991. * // using the `_.property` callback shorthand
  5992. * _.pluck(_.filter(users, 'active'), 'user');
  5993. * // => ['barney']
  5994. */
  5995. function filter(collection, predicate, thisArg) {
  5996. var func = isArray(collection) ? arrayFilter : baseFilter;
  5997. predicate = getCallback(predicate, thisArg, 3);
  5998. return func(collection, predicate);
  5999. }
  6000. /**
  6001. * Iterates over elements of `collection`, returning the first element
  6002. * `predicate` returns truthy for. The predicate is bound to `thisArg` and
  6003. * invoked with three arguments: (value, index|key, collection).
  6004. *
  6005. * If a property name is provided for `predicate` the created `_.property`
  6006. * style callback returns the property value of the given element.
  6007. *
  6008. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6009. * style callback returns `true` for elements that have a matching property
  6010. * value, else `false`.
  6011. *
  6012. * If an object is provided for `predicate` the created `_.matches` style
  6013. * callback returns `true` for elements that have the properties of the given
  6014. * object, else `false`.
  6015. *
  6016. * @static
  6017. * @memberOf _
  6018. * @alias detect
  6019. * @category Collection
  6020. * @param {Array|Object|string} collection The collection to search.
  6021. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6022. * per iteration.
  6023. * @param {*} [thisArg] The `this` binding of `predicate`.
  6024. * @returns {*} Returns the matched element, else `undefined`.
  6025. * @example
  6026. *
  6027. * var users = [
  6028. * { 'user': 'barney', 'age': 36, 'active': true },
  6029. * { 'user': 'fred', 'age': 40, 'active': false },
  6030. * { 'user': 'pebbles', 'age': 1, 'active': true }
  6031. * ];
  6032. *
  6033. * _.result(_.find(users, function(chr) {
  6034. * return chr.age < 40;
  6035. * }), 'user');
  6036. * // => 'barney'
  6037. *
  6038. * // using the `_.matches` callback shorthand
  6039. * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
  6040. * // => 'pebbles'
  6041. *
  6042. * // using the `_.matchesProperty` callback shorthand
  6043. * _.result(_.find(users, 'active', false), 'user');
  6044. * // => 'fred'
  6045. *
  6046. * // using the `_.property` callback shorthand
  6047. * _.result(_.find(users, 'active'), 'user');
  6048. * // => 'barney'
  6049. */
  6050. var find = createFind(baseEach);
  6051. /**
  6052. * This method is like `_.find` except that it iterates over elements of
  6053. * `collection` from right to left.
  6054. *
  6055. * @static
  6056. * @memberOf _
  6057. * @category Collection
  6058. * @param {Array|Object|string} collection The collection to search.
  6059. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6060. * per iteration.
  6061. * @param {*} [thisArg] The `this` binding of `predicate`.
  6062. * @returns {*} Returns the matched element, else `undefined`.
  6063. * @example
  6064. *
  6065. * _.findLast([1, 2, 3, 4], function(n) {
  6066. * return n % 2 == 1;
  6067. * });
  6068. * // => 3
  6069. */
  6070. var findLast = createFind(baseEachRight, true);
  6071. /**
  6072. * Performs a deep comparison between each element in `collection` and the
  6073. * source object, returning the first element that has equivalent property
  6074. * values.
  6075. *
  6076. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  6077. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  6078. * their own, not inherited, enumerable properties. For comparing a single
  6079. * own or inherited property value see `_.matchesProperty`.
  6080. *
  6081. * @static
  6082. * @memberOf _
  6083. * @category Collection
  6084. * @param {Array|Object|string} collection The collection to search.
  6085. * @param {Object} source The object of property values to match.
  6086. * @returns {*} Returns the matched element, else `undefined`.
  6087. * @example
  6088. *
  6089. * var users = [
  6090. * { 'user': 'barney', 'age': 36, 'active': true },
  6091. * { 'user': 'fred', 'age': 40, 'active': false }
  6092. * ];
  6093. *
  6094. * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
  6095. * // => 'barney'
  6096. *
  6097. * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
  6098. * // => 'fred'
  6099. */
  6100. function findWhere(collection, source) {
  6101. return find(collection, baseMatches(source));
  6102. }
  6103. /**
  6104. * Iterates over elements of `collection` invoking `iteratee` for each element.
  6105. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  6106. * (value, index|key, collection). Iteratee functions may exit iteration early
  6107. * by explicitly returning `false`.
  6108. *
  6109. * **Note:** As with other "Collections" methods, objects with a "length" property
  6110. * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
  6111. * may be used for object iteration.
  6112. *
  6113. * @static
  6114. * @memberOf _
  6115. * @alias each
  6116. * @category Collection
  6117. * @param {Array|Object|string} collection The collection to iterate over.
  6118. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6119. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6120. * @returns {Array|Object|string} Returns `collection`.
  6121. * @example
  6122. *
  6123. * _([1, 2]).forEach(function(n) {
  6124. * console.log(n);
  6125. * }).value();
  6126. * // => logs each value from left to right and returns the array
  6127. *
  6128. * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
  6129. * console.log(n, key);
  6130. * });
  6131. * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
  6132. */
  6133. var forEach = createForEach(arrayEach, baseEach);
  6134. /**
  6135. * This method is like `_.forEach` except that it iterates over elements of
  6136. * `collection` from right to left.
  6137. *
  6138. * @static
  6139. * @memberOf _
  6140. * @alias eachRight
  6141. * @category Collection
  6142. * @param {Array|Object|string} collection The collection to iterate over.
  6143. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6144. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6145. * @returns {Array|Object|string} Returns `collection`.
  6146. * @example
  6147. *
  6148. * _([1, 2]).forEachRight(function(n) {
  6149. * console.log(n);
  6150. * }).value();
  6151. * // => logs each value from right to left and returns the array
  6152. */
  6153. var forEachRight = createForEach(arrayEachRight, baseEachRight);
  6154. /**
  6155. * Creates an object composed of keys generated from the results of running
  6156. * each element of `collection` through `iteratee`. The corresponding value
  6157. * of each key is an array of the elements responsible for generating the key.
  6158. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  6159. * (value, index|key, collection).
  6160. *
  6161. * If a property name is provided for `iteratee` the created `_.property`
  6162. * style callback returns the property value of the given element.
  6163. *
  6164. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6165. * style callback returns `true` for elements that have a matching property
  6166. * value, else `false`.
  6167. *
  6168. * If an object is provided for `iteratee` the created `_.matches` style
  6169. * callback returns `true` for elements that have the properties of the given
  6170. * object, else `false`.
  6171. *
  6172. * @static
  6173. * @memberOf _
  6174. * @category Collection
  6175. * @param {Array|Object|string} collection The collection to iterate over.
  6176. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6177. * per iteration.
  6178. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6179. * @returns {Object} Returns the composed aggregate object.
  6180. * @example
  6181. *
  6182. * _.groupBy([4.2, 6.1, 6.4], function(n) {
  6183. * return Math.floor(n);
  6184. * });
  6185. * // => { '4': [4.2], '6': [6.1, 6.4] }
  6186. *
  6187. * _.groupBy([4.2, 6.1, 6.4], function(n) {
  6188. * return this.floor(n);
  6189. * }, Math);
  6190. * // => { '4': [4.2], '6': [6.1, 6.4] }
  6191. *
  6192. * // using the `_.property` callback shorthand
  6193. * _.groupBy(['one', 'two', 'three'], 'length');
  6194. * // => { '3': ['one', 'two'], '5': ['three'] }
  6195. */
  6196. var groupBy = createAggregator(function(result, value, key) {
  6197. if (hasOwnProperty.call(result, key)) {
  6198. result[key].push(value);
  6199. } else {
  6200. result[key] = [value];
  6201. }
  6202. });
  6203. /**
  6204. * Checks if `target` is in `collection` using
  6205. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  6206. * for equality comparisons. If `fromIndex` is negative, it's used as the offset
  6207. * from the end of `collection`.
  6208. *
  6209. * @static
  6210. * @memberOf _
  6211. * @alias contains, include
  6212. * @category Collection
  6213. * @param {Array|Object|string} collection The collection to search.
  6214. * @param {*} target The value to search for.
  6215. * @param {number} [fromIndex=0] The index to search from.
  6216. * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
  6217. * @returns {boolean} Returns `true` if a matching element is found, else `false`.
  6218. * @example
  6219. *
  6220. * _.includes([1, 2, 3], 1);
  6221. * // => true
  6222. *
  6223. * _.includes([1, 2, 3], 1, 2);
  6224. * // => false
  6225. *
  6226. * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
  6227. * // => true
  6228. *
  6229. * _.includes('pebbles', 'eb');
  6230. * // => true
  6231. */
  6232. function includes(collection, target, fromIndex, guard) {
  6233. var length = collection ? getLength(collection) : 0;
  6234. if (!isLength(length)) {
  6235. collection = values(collection);
  6236. length = collection.length;
  6237. }
  6238. if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
  6239. fromIndex = 0;
  6240. } else {
  6241. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
  6242. }
  6243. return (typeof collection == 'string' || !isArray(collection) && isString(collection))
  6244. ? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1)
  6245. : (!!length && getIndexOf(collection, target, fromIndex) > -1);
  6246. }
  6247. /**
  6248. * Creates an object composed of keys generated from the results of running
  6249. * each element of `collection` through `iteratee`. The corresponding value
  6250. * of each key is the last element responsible for generating the key. The
  6251. * iteratee function is bound to `thisArg` and invoked with three arguments:
  6252. * (value, index|key, collection).
  6253. *
  6254. * If a property name is provided for `iteratee` the created `_.property`
  6255. * style callback returns the property value of the given element.
  6256. *
  6257. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6258. * style callback returns `true` for elements that have a matching property
  6259. * value, else `false`.
  6260. *
  6261. * If an object is provided for `iteratee` the created `_.matches` style
  6262. * callback returns `true` for elements that have the properties of the given
  6263. * object, else `false`.
  6264. *
  6265. * @static
  6266. * @memberOf _
  6267. * @category Collection
  6268. * @param {Array|Object|string} collection The collection to iterate over.
  6269. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6270. * per iteration.
  6271. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6272. * @returns {Object} Returns the composed aggregate object.
  6273. * @example
  6274. *
  6275. * var keyData = [
  6276. * { 'dir': 'left', 'code': 97 },
  6277. * { 'dir': 'right', 'code': 100 }
  6278. * ];
  6279. *
  6280. * _.indexBy(keyData, 'dir');
  6281. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  6282. *
  6283. * _.indexBy(keyData, function(object) {
  6284. * return String.fromCharCode(object.code);
  6285. * });
  6286. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  6287. *
  6288. * _.indexBy(keyData, function(object) {
  6289. * return this.fromCharCode(object.code);
  6290. * }, String);
  6291. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  6292. */
  6293. var indexBy = createAggregator(function(result, value, key) {
  6294. result[key] = value;
  6295. });
  6296. /**
  6297. * Invokes the method at `path` of each element in `collection`, returning
  6298. * an array of the results of each invoked method. Any additional arguments
  6299. * are provided to each invoked method. If `methodName` is a function it's
  6300. * invoked for, and `this` bound to, each element in `collection`.
  6301. *
  6302. * @static
  6303. * @memberOf _
  6304. * @category Collection
  6305. * @param {Array|Object|string} collection The collection to iterate over.
  6306. * @param {Array|Function|string} path The path of the method to invoke or
  6307. * the function invoked per iteration.
  6308. * @param {...*} [args] The arguments to invoke the method with.
  6309. * @returns {Array} Returns the array of results.
  6310. * @example
  6311. *
  6312. * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
  6313. * // => [[1, 5, 7], [1, 2, 3]]
  6314. *
  6315. * _.invoke([123, 456], String.prototype.split, '');
  6316. * // => [['1', '2', '3'], ['4', '5', '6']]
  6317. */
  6318. var invoke = restParam(function(collection, path, args) {
  6319. var index = -1,
  6320. isFunc = typeof path == 'function',
  6321. isProp = isKey(path),
  6322. result = isArrayLike(collection) ? Array(collection.length) : [];
  6323. baseEach(collection, function(value) {
  6324. var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
  6325. result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
  6326. });
  6327. return result;
  6328. });
  6329. /**
  6330. * Creates an array of values by running each element in `collection` through
  6331. * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
  6332. * arguments: (value, index|key, collection).
  6333. *
  6334. * If a property name is provided for `iteratee` the created `_.property`
  6335. * style callback returns the property value of the given element.
  6336. *
  6337. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6338. * style callback returns `true` for elements that have a matching property
  6339. * value, else `false`.
  6340. *
  6341. * If an object is provided for `iteratee` the created `_.matches` style
  6342. * callback returns `true` for elements that have the properties of the given
  6343. * object, else `false`.
  6344. *
  6345. * Many lodash methods are guarded to work as iteratees for methods like
  6346. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  6347. *
  6348. * The guarded methods are:
  6349. * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
  6350. * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
  6351. * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
  6352. * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
  6353. * `sum`, `uniq`, and `words`
  6354. *
  6355. * @static
  6356. * @memberOf _
  6357. * @alias collect
  6358. * @category Collection
  6359. * @param {Array|Object|string} collection The collection to iterate over.
  6360. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6361. * per iteration.
  6362. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6363. * @returns {Array} Returns the new mapped array.
  6364. * @example
  6365. *
  6366. * function timesThree(n) {
  6367. * return n * 3;
  6368. * }
  6369. *
  6370. * _.map([1, 2], timesThree);
  6371. * // => [3, 6]
  6372. *
  6373. * _.map({ 'a': 1, 'b': 2 }, timesThree);
  6374. * // => [3, 6] (iteration order is not guaranteed)
  6375. *
  6376. * var users = [
  6377. * { 'user': 'barney' },
  6378. * { 'user': 'fred' }
  6379. * ];
  6380. *
  6381. * // using the `_.property` callback shorthand
  6382. * _.map(users, 'user');
  6383. * // => ['barney', 'fred']
  6384. */
  6385. function map(collection, iteratee, thisArg) {
  6386. var func = isArray(collection) ? arrayMap : baseMap;
  6387. iteratee = getCallback(iteratee, thisArg, 3);
  6388. return func(collection, iteratee);
  6389. }
  6390. /**
  6391. * Creates an array of elements split into two groups, the first of which
  6392. * contains elements `predicate` returns truthy for, while the second of which
  6393. * contains elements `predicate` returns falsey for. The predicate is bound
  6394. * to `thisArg` and invoked with three arguments: (value, index|key, collection).
  6395. *
  6396. * If a property name is provided for `predicate` the created `_.property`
  6397. * style callback returns the property value of the given element.
  6398. *
  6399. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6400. * style callback returns `true` for elements that have a matching property
  6401. * value, else `false`.
  6402. *
  6403. * If an object is provided for `predicate` the created `_.matches` style
  6404. * callback returns `true` for elements that have the properties of the given
  6405. * object, else `false`.
  6406. *
  6407. * @static
  6408. * @memberOf _
  6409. * @category Collection
  6410. * @param {Array|Object|string} collection The collection to iterate over.
  6411. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6412. * per iteration.
  6413. * @param {*} [thisArg] The `this` binding of `predicate`.
  6414. * @returns {Array} Returns the array of grouped elements.
  6415. * @example
  6416. *
  6417. * _.partition([1, 2, 3], function(n) {
  6418. * return n % 2;
  6419. * });
  6420. * // => [[1, 3], [2]]
  6421. *
  6422. * _.partition([1.2, 2.3, 3.4], function(n) {
  6423. * return this.floor(n) % 2;
  6424. * }, Math);
  6425. * // => [[1.2, 3.4], [2.3]]
  6426. *
  6427. * var users = [
  6428. * { 'user': 'barney', 'age': 36, 'active': false },
  6429. * { 'user': 'fred', 'age': 40, 'active': true },
  6430. * { 'user': 'pebbles', 'age': 1, 'active': false }
  6431. * ];
  6432. *
  6433. * var mapper = function(array) {
  6434. * return _.pluck(array, 'user');
  6435. * };
  6436. *
  6437. * // using the `_.matches` callback shorthand
  6438. * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
  6439. * // => [['pebbles'], ['barney', 'fred']]
  6440. *
  6441. * // using the `_.matchesProperty` callback shorthand
  6442. * _.map(_.partition(users, 'active', false), mapper);
  6443. * // => [['barney', 'pebbles'], ['fred']]
  6444. *
  6445. * // using the `_.property` callback shorthand
  6446. * _.map(_.partition(users, 'active'), mapper);
  6447. * // => [['fred'], ['barney', 'pebbles']]
  6448. */
  6449. var partition = createAggregator(function(result, value, key) {
  6450. result[key ? 0 : 1].push(value);
  6451. }, function() { return [[], []]; });
  6452. /**
  6453. * Gets the property value of `path` from all elements in `collection`.
  6454. *
  6455. * @static
  6456. * @memberOf _
  6457. * @category Collection
  6458. * @param {Array|Object|string} collection The collection to iterate over.
  6459. * @param {Array|string} path The path of the property to pluck.
  6460. * @returns {Array} Returns the property values.
  6461. * @example
  6462. *
  6463. * var users = [
  6464. * { 'user': 'barney', 'age': 36 },
  6465. * { 'user': 'fred', 'age': 40 }
  6466. * ];
  6467. *
  6468. * _.pluck(users, 'user');
  6469. * // => ['barney', 'fred']
  6470. *
  6471. * var userIndex = _.indexBy(users, 'user');
  6472. * _.pluck(userIndex, 'age');
  6473. * // => [36, 40] (iteration order is not guaranteed)
  6474. */
  6475. function pluck(collection, path) {
  6476. return map(collection, property(path));
  6477. }
  6478. /**
  6479. * Reduces `collection` to a value which is the accumulated result of running
  6480. * each element in `collection` through `iteratee`, where each successive
  6481. * invocation is supplied the return value of the previous. If `accumulator`
  6482. * is not provided the first element of `collection` is used as the initial
  6483. * value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
  6484. * (accumulator, value, index|key, collection).
  6485. *
  6486. * Many lodash methods are guarded to work as iteratees for methods like
  6487. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  6488. *
  6489. * The guarded methods are:
  6490. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
  6491. * and `sortByOrder`
  6492. *
  6493. * @static
  6494. * @memberOf _
  6495. * @alias foldl, inject
  6496. * @category Collection
  6497. * @param {Array|Object|string} collection The collection to iterate over.
  6498. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6499. * @param {*} [accumulator] The initial value.
  6500. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6501. * @returns {*} Returns the accumulated value.
  6502. * @example
  6503. *
  6504. * _.reduce([1, 2], function(total, n) {
  6505. * return total + n;
  6506. * });
  6507. * // => 3
  6508. *
  6509. * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
  6510. * result[key] = n * 3;
  6511. * return result;
  6512. * }, {});
  6513. * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
  6514. */
  6515. var reduce = createReduce(arrayReduce, baseEach);
  6516. /**
  6517. * This method is like `_.reduce` except that it iterates over elements of
  6518. * `collection` from right to left.
  6519. *
  6520. * @static
  6521. * @memberOf _
  6522. * @alias foldr
  6523. * @category Collection
  6524. * @param {Array|Object|string} collection The collection to iterate over.
  6525. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6526. * @param {*} [accumulator] The initial value.
  6527. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6528. * @returns {*} Returns the accumulated value.
  6529. * @example
  6530. *
  6531. * var array = [[0, 1], [2, 3], [4, 5]];
  6532. *
  6533. * _.reduceRight(array, function(flattened, other) {
  6534. * return flattened.concat(other);
  6535. * }, []);
  6536. * // => [4, 5, 2, 3, 0, 1]
  6537. */
  6538. var reduceRight = createReduce(arrayReduceRight, baseEachRight);
  6539. /**
  6540. * The opposite of `_.filter`; this method returns the elements of `collection`
  6541. * that `predicate` does **not** return truthy for.
  6542. *
  6543. * @static
  6544. * @memberOf _
  6545. * @category Collection
  6546. * @param {Array|Object|string} collection The collection to iterate over.
  6547. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6548. * per iteration.
  6549. * @param {*} [thisArg] The `this` binding of `predicate`.
  6550. * @returns {Array} Returns the new filtered array.
  6551. * @example
  6552. *
  6553. * _.reject([1, 2, 3, 4], function(n) {
  6554. * return n % 2 == 0;
  6555. * });
  6556. * // => [1, 3]
  6557. *
  6558. * var users = [
  6559. * { 'user': 'barney', 'age': 36, 'active': false },
  6560. * { 'user': 'fred', 'age': 40, 'active': true }
  6561. * ];
  6562. *
  6563. * // using the `_.matches` callback shorthand
  6564. * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
  6565. * // => ['barney']
  6566. *
  6567. * // using the `_.matchesProperty` callback shorthand
  6568. * _.pluck(_.reject(users, 'active', false), 'user');
  6569. * // => ['fred']
  6570. *
  6571. * // using the `_.property` callback shorthand
  6572. * _.pluck(_.reject(users, 'active'), 'user');
  6573. * // => ['barney']
  6574. */
  6575. function reject(collection, predicate, thisArg) {
  6576. var func = isArray(collection) ? arrayFilter : baseFilter;
  6577. predicate = getCallback(predicate, thisArg, 3);
  6578. return func(collection, function(value, index, collection) {
  6579. return !predicate(value, index, collection);
  6580. });
  6581. }
  6582. /**
  6583. * Gets a random element or `n` random elements from a collection.
  6584. *
  6585. * @static
  6586. * @memberOf _
  6587. * @category Collection
  6588. * @param {Array|Object|string} collection The collection to sample.
  6589. * @param {number} [n] The number of elements to sample.
  6590. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6591. * @returns {*} Returns the random sample(s).
  6592. * @example
  6593. *
  6594. * _.sample([1, 2, 3, 4]);
  6595. * // => 2
  6596. *
  6597. * _.sample([1, 2, 3, 4], 2);
  6598. * // => [3, 1]
  6599. */
  6600. function sample(collection, n, guard) {
  6601. if (guard ? isIterateeCall(collection, n, guard) : n == null) {
  6602. collection = toIterable(collection);
  6603. var length = collection.length;
  6604. return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
  6605. }
  6606. var index = -1,
  6607. result = toArray(collection),
  6608. length = result.length,
  6609. lastIndex = length - 1;
  6610. n = nativeMin(n < 0 ? 0 : (+n || 0), length);
  6611. while (++index < n) {
  6612. var rand = baseRandom(index, lastIndex),
  6613. value = result[rand];
  6614. result[rand] = result[index];
  6615. result[index] = value;
  6616. }
  6617. result.length = n;
  6618. return result;
  6619. }
  6620. /**
  6621. * Creates an array of shuffled values, using a version of the
  6622. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  6623. *
  6624. * @static
  6625. * @memberOf _
  6626. * @category Collection
  6627. * @param {Array|Object|string} collection The collection to shuffle.
  6628. * @returns {Array} Returns the new shuffled array.
  6629. * @example
  6630. *
  6631. * _.shuffle([1, 2, 3, 4]);
  6632. * // => [4, 1, 3, 2]
  6633. */
  6634. function shuffle(collection) {
  6635. return sample(collection, POSITIVE_INFINITY);
  6636. }
  6637. /**
  6638. * Gets the size of `collection` by returning its length for array-like
  6639. * values or the number of own enumerable properties for objects.
  6640. *
  6641. * @static
  6642. * @memberOf _
  6643. * @category Collection
  6644. * @param {Array|Object|string} collection The collection to inspect.
  6645. * @returns {number} Returns the size of `collection`.
  6646. * @example
  6647. *
  6648. * _.size([1, 2, 3]);
  6649. * // => 3
  6650. *
  6651. * _.size({ 'a': 1, 'b': 2 });
  6652. * // => 2
  6653. *
  6654. * _.size('pebbles');
  6655. * // => 7
  6656. */
  6657. function size(collection) {
  6658. var length = collection ? getLength(collection) : 0;
  6659. return isLength(length) ? length : keys(collection).length;
  6660. }
  6661. /**
  6662. * Checks if `predicate` returns truthy for **any** element of `collection`.
  6663. * The function returns as soon as it finds a passing value and does not iterate
  6664. * over the entire collection. The predicate is bound to `thisArg` and invoked
  6665. * with three arguments: (value, index|key, collection).
  6666. *
  6667. * If a property name is provided for `predicate` the created `_.property`
  6668. * style callback returns the property value of the given element.
  6669. *
  6670. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6671. * style callback returns `true` for elements that have a matching property
  6672. * value, else `false`.
  6673. *
  6674. * If an object is provided for `predicate` the created `_.matches` style
  6675. * callback returns `true` for elements that have the properties of the given
  6676. * object, else `false`.
  6677. *
  6678. * @static
  6679. * @memberOf _
  6680. * @alias any
  6681. * @category Collection
  6682. * @param {Array|Object|string} collection The collection to iterate over.
  6683. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6684. * per iteration.
  6685. * @param {*} [thisArg] The `this` binding of `predicate`.
  6686. * @returns {boolean} Returns `true` if any element passes the predicate check,
  6687. * else `false`.
  6688. * @example
  6689. *
  6690. * _.some([null, 0, 'yes', false], Boolean);
  6691. * // => true
  6692. *
  6693. * var users = [
  6694. * { 'user': 'barney', 'active': true },
  6695. * { 'user': 'fred', 'active': false }
  6696. * ];
  6697. *
  6698. * // using the `_.matches` callback shorthand
  6699. * _.some(users, { 'user': 'barney', 'active': false });
  6700. * // => false
  6701. *
  6702. * // using the `_.matchesProperty` callback shorthand
  6703. * _.some(users, 'active', false);
  6704. * // => true
  6705. *
  6706. * // using the `_.property` callback shorthand
  6707. * _.some(users, 'active');
  6708. * // => true
  6709. */
  6710. function some(collection, predicate, thisArg) {
  6711. var func = isArray(collection) ? arraySome : baseSome;
  6712. if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
  6713. predicate = undefined;
  6714. }
  6715. if (typeof predicate != 'function' || thisArg !== undefined) {
  6716. predicate = getCallback(predicate, thisArg, 3);
  6717. }
  6718. return func(collection, predicate);
  6719. }
  6720. /**
  6721. * Creates an array of elements, sorted in ascending order by the results of
  6722. * running each element in a collection through `iteratee`. This method performs
  6723. * a stable sort, that is, it preserves the original sort order of equal elements.
  6724. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  6725. * (value, index|key, collection).
  6726. *
  6727. * If a property name is provided for `iteratee` the created `_.property`
  6728. * style callback returns the property value of the given element.
  6729. *
  6730. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6731. * style callback returns `true` for elements that have a matching property
  6732. * value, else `false`.
  6733. *
  6734. * If an object is provided for `iteratee` the created `_.matches` style
  6735. * callback returns `true` for elements that have the properties of the given
  6736. * object, else `false`.
  6737. *
  6738. * @static
  6739. * @memberOf _
  6740. * @category Collection
  6741. * @param {Array|Object|string} collection The collection to iterate over.
  6742. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6743. * per iteration.
  6744. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6745. * @returns {Array} Returns the new sorted array.
  6746. * @example
  6747. *
  6748. * _.sortBy([1, 2, 3], function(n) {
  6749. * return Math.sin(n);
  6750. * });
  6751. * // => [3, 1, 2]
  6752. *
  6753. * _.sortBy([1, 2, 3], function(n) {
  6754. * return this.sin(n);
  6755. * }, Math);
  6756. * // => [3, 1, 2]
  6757. *
  6758. * var users = [
  6759. * { 'user': 'fred' },
  6760. * { 'user': 'pebbles' },
  6761. * { 'user': 'barney' }
  6762. * ];
  6763. *
  6764. * // using the `_.property` callback shorthand
  6765. * _.pluck(_.sortBy(users, 'user'), 'user');
  6766. * // => ['barney', 'fred', 'pebbles']
  6767. */
  6768. function sortBy(collection, iteratee, thisArg) {
  6769. if (collection == null) {
  6770. return [];
  6771. }
  6772. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  6773. iteratee = undefined;
  6774. }
  6775. var index = -1;
  6776. iteratee = getCallback(iteratee, thisArg, 3);
  6777. var result = baseMap(collection, function(value, key, collection) {
  6778. return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
  6779. });
  6780. return baseSortBy(result, compareAscending);
  6781. }
  6782. /**
  6783. * This method is like `_.sortBy` except that it can sort by multiple iteratees
  6784. * or property names.
  6785. *
  6786. * If a property name is provided for an iteratee the created `_.property`
  6787. * style callback returns the property value of the given element.
  6788. *
  6789. * If an object is provided for an iteratee the created `_.matches` style
  6790. * callback returns `true` for elements that have the properties of the given
  6791. * object, else `false`.
  6792. *
  6793. * @static
  6794. * @memberOf _
  6795. * @category Collection
  6796. * @param {Array|Object|string} collection The collection to iterate over.
  6797. * @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
  6798. * The iteratees to sort by, specified as individual values or arrays of values.
  6799. * @returns {Array} Returns the new sorted array.
  6800. * @example
  6801. *
  6802. * var users = [
  6803. * { 'user': 'fred', 'age': 48 },
  6804. * { 'user': 'barney', 'age': 36 },
  6805. * { 'user': 'fred', 'age': 42 },
  6806. * { 'user': 'barney', 'age': 34 }
  6807. * ];
  6808. *
  6809. * _.map(_.sortByAll(users, ['user', 'age']), _.values);
  6810. * // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
  6811. *
  6812. * _.map(_.sortByAll(users, 'user', function(chr) {
  6813. * return Math.floor(chr.age / 10);
  6814. * }), _.values);
  6815. * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
  6816. */
  6817. var sortByAll = restParam(function(collection, iteratees) {
  6818. if (collection == null) {
  6819. return [];
  6820. }
  6821. var guard = iteratees[2];
  6822. if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
  6823. iteratees.length = 1;
  6824. }
  6825. return baseSortByOrder(collection, baseFlatten(iteratees), []);
  6826. });
  6827. /**
  6828. * This method is like `_.sortByAll` except that it allows specifying the
  6829. * sort orders of the iteratees to sort by. If `orders` is unspecified, all
  6830. * values are sorted in ascending order. Otherwise, a value is sorted in
  6831. * ascending order if its corresponding order is "asc", and descending if "desc".
  6832. *
  6833. * If a property name is provided for an iteratee the created `_.property`
  6834. * style callback returns the property value of the given element.
  6835. *
  6836. * If an object is provided for an iteratee the created `_.matches` style
  6837. * callback returns `true` for elements that have the properties of the given
  6838. * object, else `false`.
  6839. *
  6840. * @static
  6841. * @memberOf _
  6842. * @category Collection
  6843. * @param {Array|Object|string} collection The collection to iterate over.
  6844. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  6845. * @param {boolean[]} [orders] The sort orders of `iteratees`.
  6846. * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
  6847. * @returns {Array} Returns the new sorted array.
  6848. * @example
  6849. *
  6850. * var users = [
  6851. * { 'user': 'fred', 'age': 48 },
  6852. * { 'user': 'barney', 'age': 34 },
  6853. * { 'user': 'fred', 'age': 42 },
  6854. * { 'user': 'barney', 'age': 36 }
  6855. * ];
  6856. *
  6857. * // sort by `user` in ascending order and by `age` in descending order
  6858. * _.map(_.sortByOrder(users, ['user', 'age'], ['asc', 'desc']), _.values);
  6859. * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
  6860. */
  6861. function sortByOrder(collection, iteratees, orders, guard) {
  6862. if (collection == null) {
  6863. return [];
  6864. }
  6865. if (guard && isIterateeCall(iteratees, orders, guard)) {
  6866. orders = undefined;
  6867. }
  6868. if (!isArray(iteratees)) {
  6869. iteratees = iteratees == null ? [] : [iteratees];
  6870. }
  6871. if (!isArray(orders)) {
  6872. orders = orders == null ? [] : [orders];
  6873. }
  6874. return baseSortByOrder(collection, iteratees, orders);
  6875. }
  6876. /**
  6877. * Performs a deep comparison between each element in `collection` and the
  6878. * source object, returning an array of all elements that have equivalent
  6879. * property values.
  6880. *
  6881. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  6882. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  6883. * their own, not inherited, enumerable properties. For comparing a single
  6884. * own or inherited property value see `_.matchesProperty`.
  6885. *
  6886. * @static
  6887. * @memberOf _
  6888. * @category Collection
  6889. * @param {Array|Object|string} collection The collection to search.
  6890. * @param {Object} source The object of property values to match.
  6891. * @returns {Array} Returns the new filtered array.
  6892. * @example
  6893. *
  6894. * var users = [
  6895. * { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
  6896. * { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
  6897. * ];
  6898. *
  6899. * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
  6900. * // => ['barney']
  6901. *
  6902. * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
  6903. * // => ['fred']
  6904. */
  6905. function where(collection, source) {
  6906. return filter(collection, baseMatches(source));
  6907. }
  6908. /*------------------------------------------------------------------------*/
  6909. /**
  6910. * Gets the number of milliseconds that have elapsed since the Unix epoch
  6911. * (1 January 1970 00:00:00 UTC).
  6912. *
  6913. * @static
  6914. * @memberOf _
  6915. * @category Date
  6916. * @example
  6917. *
  6918. * _.defer(function(stamp) {
  6919. * console.log(_.now() - stamp);
  6920. * }, _.now());
  6921. * // => logs the number of milliseconds it took for the deferred function to be invoked
  6922. */
  6923. var now = nativeNow || function() {
  6924. return new Date().getTime();
  6925. };
  6926. /*------------------------------------------------------------------------*/
  6927. /**
  6928. * The opposite of `_.before`; this method creates a function that invokes
  6929. * `func` once it's called `n` or more times.
  6930. *
  6931. * @static
  6932. * @memberOf _
  6933. * @category Function
  6934. * @param {number} n The number of calls before `func` is invoked.
  6935. * @param {Function} func The function to restrict.
  6936. * @returns {Function} Returns the new restricted function.
  6937. * @example
  6938. *
  6939. * var saves = ['profile', 'settings'];
  6940. *
  6941. * var done = _.after(saves.length, function() {
  6942. * console.log('done saving!');
  6943. * });
  6944. *
  6945. * _.forEach(saves, function(type) {
  6946. * asyncSave({ 'type': type, 'complete': done });
  6947. * });
  6948. * // => logs 'done saving!' after the two async saves have completed
  6949. */
  6950. function after(n, func) {
  6951. if (typeof func != 'function') {
  6952. if (typeof n == 'function') {
  6953. var temp = n;
  6954. n = func;
  6955. func = temp;
  6956. } else {
  6957. throw new TypeError(FUNC_ERROR_TEXT);
  6958. }
  6959. }
  6960. n = nativeIsFinite(n = +n) ? n : 0;
  6961. return function() {
  6962. if (--n < 1) {
  6963. return func.apply(this, arguments);
  6964. }
  6965. };
  6966. }
  6967. /**
  6968. * Creates a function that accepts up to `n` arguments ignoring any
  6969. * additional arguments.
  6970. *
  6971. * @static
  6972. * @memberOf _
  6973. * @category Function
  6974. * @param {Function} func The function to cap arguments for.
  6975. * @param {number} [n=func.length] The arity cap.
  6976. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6977. * @returns {Function} Returns the new function.
  6978. * @example
  6979. *
  6980. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  6981. * // => [6, 8, 10]
  6982. */
  6983. function ary(func, n, guard) {
  6984. if (guard && isIterateeCall(func, n, guard)) {
  6985. n = undefined;
  6986. }
  6987. n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
  6988. return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
  6989. }
  6990. /**
  6991. * Creates a function that invokes `func`, with the `this` binding and arguments
  6992. * of the created function, while it's called less than `n` times. Subsequent
  6993. * calls to the created function return the result of the last `func` invocation.
  6994. *
  6995. * @static
  6996. * @memberOf _
  6997. * @category Function
  6998. * @param {number} n The number of calls at which `func` is no longer invoked.
  6999. * @param {Function} func The function to restrict.
  7000. * @returns {Function} Returns the new restricted function.
  7001. * @example
  7002. *
  7003. * jQuery('#add').on('click', _.before(5, addContactToList));
  7004. * // => allows adding up to 4 contacts to the list
  7005. */
  7006. function before(n, func) {
  7007. var result;
  7008. if (typeof func != 'function') {
  7009. if (typeof n == 'function') {
  7010. var temp = n;
  7011. n = func;
  7012. func = temp;
  7013. } else {
  7014. throw new TypeError(FUNC_ERROR_TEXT);
  7015. }
  7016. }
  7017. return function() {
  7018. if (--n > 0) {
  7019. result = func.apply(this, arguments);
  7020. }
  7021. if (n <= 1) {
  7022. func = undefined;
  7023. }
  7024. return result;
  7025. };
  7026. }
  7027. /**
  7028. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  7029. * and prepends any additional `_.bind` arguments to those provided to the
  7030. * bound function.
  7031. *
  7032. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  7033. * may be used as a placeholder for partially applied arguments.
  7034. *
  7035. * **Note:** Unlike native `Function#bind` this method does not set the "length"
  7036. * property of bound functions.
  7037. *
  7038. * @static
  7039. * @memberOf _
  7040. * @category Function
  7041. * @param {Function} func The function to bind.
  7042. * @param {*} thisArg The `this` binding of `func`.
  7043. * @param {...*} [partials] The arguments to be partially applied.
  7044. * @returns {Function} Returns the new bound function.
  7045. * @example
  7046. *
  7047. * var greet = function(greeting, punctuation) {
  7048. * return greeting + ' ' + this.user + punctuation;
  7049. * };
  7050. *
  7051. * var object = { 'user': 'fred' };
  7052. *
  7053. * var bound = _.bind(greet, object, 'hi');
  7054. * bound('!');
  7055. * // => 'hi fred!'
  7056. *
  7057. * // using placeholders
  7058. * var bound = _.bind(greet, object, _, '!');
  7059. * bound('hi');
  7060. * // => 'hi fred!'
  7061. */
  7062. var bind = restParam(function(func, thisArg, partials) {
  7063. var bitmask = BIND_FLAG;
  7064. if (partials.length) {
  7065. var holders = replaceHolders(partials, bind.placeholder);
  7066. bitmask |= PARTIAL_FLAG;
  7067. }
  7068. return createWrapper(func, bitmask, thisArg, partials, holders);
  7069. });
  7070. /**
  7071. * Binds methods of an object to the object itself, overwriting the existing
  7072. * method. Method names may be specified as individual arguments or as arrays
  7073. * of method names. If no method names are provided all enumerable function
  7074. * properties, own and inherited, of `object` are bound.
  7075. *
  7076. * **Note:** This method does not set the "length" property of bound functions.
  7077. *
  7078. * @static
  7079. * @memberOf _
  7080. * @category Function
  7081. * @param {Object} object The object to bind and assign the bound methods to.
  7082. * @param {...(string|string[])} [methodNames] The object method names to bind,
  7083. * specified as individual method names or arrays of method names.
  7084. * @returns {Object} Returns `object`.
  7085. * @example
  7086. *
  7087. * var view = {
  7088. * 'label': 'docs',
  7089. * 'onClick': function() {
  7090. * console.log('clicked ' + this.label);
  7091. * }
  7092. * };
  7093. *
  7094. * _.bindAll(view);
  7095. * jQuery('#docs').on('click', view.onClick);
  7096. * // => logs 'clicked docs' when the element is clicked
  7097. */
  7098. var bindAll = restParam(function(object, methodNames) {
  7099. methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
  7100. var index = -1,
  7101. length = methodNames.length;
  7102. while (++index < length) {
  7103. var key = methodNames[index];
  7104. object[key] = createWrapper(object[key], BIND_FLAG, object);
  7105. }
  7106. return object;
  7107. });
  7108. /**
  7109. * Creates a function that invokes the method at `object[key]` and prepends
  7110. * any additional `_.bindKey` arguments to those provided to the bound function.
  7111. *
  7112. * This method differs from `_.bind` by allowing bound functions to reference
  7113. * methods that may be redefined or don't yet exist.
  7114. * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  7115. * for more details.
  7116. *
  7117. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  7118. * builds, may be used as a placeholder for partially applied arguments.
  7119. *
  7120. * @static
  7121. * @memberOf _
  7122. * @category Function
  7123. * @param {Object} object The object the method belongs to.
  7124. * @param {string} key The key of the method.
  7125. * @param {...*} [partials] The arguments to be partially applied.
  7126. * @returns {Function} Returns the new bound function.
  7127. * @example
  7128. *
  7129. * var object = {
  7130. * 'user': 'fred',
  7131. * 'greet': function(greeting, punctuation) {
  7132. * return greeting + ' ' + this.user + punctuation;
  7133. * }
  7134. * };
  7135. *
  7136. * var bound = _.bindKey(object, 'greet', 'hi');
  7137. * bound('!');
  7138. * // => 'hi fred!'
  7139. *
  7140. * object.greet = function(greeting, punctuation) {
  7141. * return greeting + 'ya ' + this.user + punctuation;
  7142. * };
  7143. *
  7144. * bound('!');
  7145. * // => 'hiya fred!'
  7146. *
  7147. * // using placeholders
  7148. * var bound = _.bindKey(object, 'greet', _, '!');
  7149. * bound('hi');
  7150. * // => 'hiya fred!'
  7151. */
  7152. var bindKey = restParam(function(object, key, partials) {
  7153. var bitmask = BIND_FLAG | BIND_KEY_FLAG;
  7154. if (partials.length) {
  7155. var holders = replaceHolders(partials, bindKey.placeholder);
  7156. bitmask |= PARTIAL_FLAG;
  7157. }
  7158. return createWrapper(key, bitmask, object, partials, holders);
  7159. });
  7160. /**
  7161. * Creates a function that accepts one or more arguments of `func` that when
  7162. * called either invokes `func` returning its result, if all `func` arguments
  7163. * have been provided, or returns a function that accepts one or more of the
  7164. * remaining `func` arguments, and so on. The arity of `func` may be specified
  7165. * if `func.length` is not sufficient.
  7166. *
  7167. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  7168. * may be used as a placeholder for provided arguments.
  7169. *
  7170. * **Note:** This method does not set the "length" property of curried functions.
  7171. *
  7172. * @static
  7173. * @memberOf _
  7174. * @category Function
  7175. * @param {Function} func The function to curry.
  7176. * @param {number} [arity=func.length] The arity of `func`.
  7177. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  7178. * @returns {Function} Returns the new curried function.
  7179. * @example
  7180. *
  7181. * var abc = function(a, b, c) {
  7182. * return [a, b, c];
  7183. * };
  7184. *
  7185. * var curried = _.curry(abc);
  7186. *
  7187. * curried(1)(2)(3);
  7188. * // => [1, 2, 3]
  7189. *
  7190. * curried(1, 2)(3);
  7191. * // => [1, 2, 3]
  7192. *
  7193. * curried(1, 2, 3);
  7194. * // => [1, 2, 3]
  7195. *
  7196. * // using placeholders
  7197. * curried(1)(_, 3)(2);
  7198. * // => [1, 2, 3]
  7199. */
  7200. var curry = createCurry(CURRY_FLAG);
  7201. /**
  7202. * This method is like `_.curry` except that arguments are applied to `func`
  7203. * in the manner of `_.partialRight` instead of `_.partial`.
  7204. *
  7205. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  7206. * builds, may be used as a placeholder for provided arguments.
  7207. *
  7208. * **Note:** This method does not set the "length" property of curried functions.
  7209. *
  7210. * @static
  7211. * @memberOf _
  7212. * @category Function
  7213. * @param {Function} func The function to curry.
  7214. * @param {number} [arity=func.length] The arity of `func`.
  7215. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  7216. * @returns {Function} Returns the new curried function.
  7217. * @example
  7218. *
  7219. * var abc = function(a, b, c) {
  7220. * return [a, b, c];
  7221. * };
  7222. *
  7223. * var curried = _.curryRight(abc);
  7224. *
  7225. * curried(3)(2)(1);
  7226. * // => [1, 2, 3]
  7227. *
  7228. * curried(2, 3)(1);
  7229. * // => [1, 2, 3]
  7230. *
  7231. * curried(1, 2, 3);
  7232. * // => [1, 2, 3]
  7233. *
  7234. * // using placeholders
  7235. * curried(3)(1, _)(2);
  7236. * // => [1, 2, 3]
  7237. */
  7238. var curryRight = createCurry(CURRY_RIGHT_FLAG);
  7239. /**
  7240. * Creates a debounced function that delays invoking `func` until after `wait`
  7241. * milliseconds have elapsed since the last time the debounced function was
  7242. * invoked. The debounced function comes with a `cancel` method to cancel
  7243. * delayed invocations. Provide an options object to indicate that `func`
  7244. * should be invoked on the leading and/or trailing edge of the `wait` timeout.
  7245. * Subsequent calls to the debounced function return the result of the last
  7246. * `func` invocation.
  7247. *
  7248. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  7249. * on the trailing edge of the timeout only if the the debounced function is
  7250. * invoked more than once during the `wait` timeout.
  7251. *
  7252. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  7253. * for details over the differences between `_.debounce` and `_.throttle`.
  7254. *
  7255. * @static
  7256. * @memberOf _
  7257. * @category Function
  7258. * @param {Function} func The function to debounce.
  7259. * @param {number} [wait=0] The number of milliseconds to delay.
  7260. * @param {Object} [options] The options object.
  7261. * @param {boolean} [options.leading=false] Specify invoking on the leading
  7262. * edge of the timeout.
  7263. * @param {number} [options.maxWait] The maximum time `func` is allowed to be
  7264. * delayed before it's invoked.
  7265. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  7266. * edge of the timeout.
  7267. * @returns {Function} Returns the new debounced function.
  7268. * @example
  7269. *
  7270. * // avoid costly calculations while the window size is in flux
  7271. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  7272. *
  7273. * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
  7274. * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
  7275. * 'leading': true,
  7276. * 'trailing': false
  7277. * }));
  7278. *
  7279. * // ensure `batchLog` is invoked once after 1 second of debounced calls
  7280. * var source = new EventSource('/stream');
  7281. * jQuery(source).on('message', _.debounce(batchLog, 250, {
  7282. * 'maxWait': 1000
  7283. * }));
  7284. *
  7285. * // cancel a debounced call
  7286. * var todoChanges = _.debounce(batchLog, 1000);
  7287. * Object.observe(models.todo, todoChanges);
  7288. *
  7289. * Object.observe(models, function(changes) {
  7290. * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
  7291. * todoChanges.cancel();
  7292. * }
  7293. * }, ['delete']);
  7294. *
  7295. * // ...at some point `models.todo` is changed
  7296. * models.todo.completed = true;
  7297. *
  7298. * // ...before 1 second has passed `models.todo` is deleted
  7299. * // which cancels the debounced `todoChanges` call
  7300. * delete models.todo;
  7301. */
  7302. function debounce(func, wait, options) {
  7303. var args,
  7304. maxTimeoutId,
  7305. result,
  7306. stamp,
  7307. thisArg,
  7308. timeoutId,
  7309. trailingCall,
  7310. lastCalled = 0,
  7311. maxWait = false,
  7312. trailing = true;
  7313. if (typeof func != 'function') {
  7314. throw new TypeError(FUNC_ERROR_TEXT);
  7315. }
  7316. wait = wait < 0 ? 0 : (+wait || 0);
  7317. if (options === true) {
  7318. var leading = true;
  7319. trailing = false;
  7320. } else if (isObject(options)) {
  7321. leading = !!options.leading;
  7322. maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
  7323. trailing = 'trailing' in options ? !!options.trailing : trailing;
  7324. }
  7325. function cancel() {
  7326. if (timeoutId) {
  7327. clearTimeout(timeoutId);
  7328. }
  7329. if (maxTimeoutId) {
  7330. clearTimeout(maxTimeoutId);
  7331. }
  7332. lastCalled = 0;
  7333. maxTimeoutId = timeoutId = trailingCall = undefined;
  7334. }
  7335. function complete(isCalled, id) {
  7336. if (id) {
  7337. clearTimeout(id);
  7338. }
  7339. maxTimeoutId = timeoutId = trailingCall = undefined;
  7340. if (isCalled) {
  7341. lastCalled = now();
  7342. result = func.apply(thisArg, args);
  7343. if (!timeoutId && !maxTimeoutId) {
  7344. args = thisArg = undefined;
  7345. }
  7346. }
  7347. }
  7348. function delayed() {
  7349. var remaining = wait - (now() - stamp);
  7350. if (remaining <= 0 || remaining > wait) {
  7351. complete(trailingCall, maxTimeoutId);
  7352. } else {
  7353. timeoutId = setTimeout(delayed, remaining);
  7354. }
  7355. }
  7356. function maxDelayed() {
  7357. complete(trailing, timeoutId);
  7358. }
  7359. function debounced() {
  7360. args = arguments;
  7361. stamp = now();
  7362. thisArg = this;
  7363. trailingCall = trailing && (timeoutId || !leading);
  7364. if (maxWait === false) {
  7365. var leadingCall = leading && !timeoutId;
  7366. } else {
  7367. if (!maxTimeoutId && !leading) {
  7368. lastCalled = stamp;
  7369. }
  7370. var remaining = maxWait - (stamp - lastCalled),
  7371. isCalled = remaining <= 0 || remaining > maxWait;
  7372. if (isCalled) {
  7373. if (maxTimeoutId) {
  7374. maxTimeoutId = clearTimeout(maxTimeoutId);
  7375. }
  7376. lastCalled = stamp;
  7377. result = func.apply(thisArg, args);
  7378. }
  7379. else if (!maxTimeoutId) {
  7380. maxTimeoutId = setTimeout(maxDelayed, remaining);
  7381. }
  7382. }
  7383. if (isCalled && timeoutId) {
  7384. timeoutId = clearTimeout(timeoutId);
  7385. }
  7386. else if (!timeoutId && wait !== maxWait) {
  7387. timeoutId = setTimeout(delayed, wait);
  7388. }
  7389. if (leadingCall) {
  7390. isCalled = true;
  7391. result = func.apply(thisArg, args);
  7392. }
  7393. if (isCalled && !timeoutId && !maxTimeoutId) {
  7394. args = thisArg = undefined;
  7395. }
  7396. return result;
  7397. }
  7398. debounced.cancel = cancel;
  7399. return debounced;
  7400. }
  7401. /**
  7402. * Defers invoking the `func` until the current call stack has cleared. Any
  7403. * additional arguments are provided to `func` when it's invoked.
  7404. *
  7405. * @static
  7406. * @memberOf _
  7407. * @category Function
  7408. * @param {Function} func The function to defer.
  7409. * @param {...*} [args] The arguments to invoke the function with.
  7410. * @returns {number} Returns the timer id.
  7411. * @example
  7412. *
  7413. * _.defer(function(text) {
  7414. * console.log(text);
  7415. * }, 'deferred');
  7416. * // logs 'deferred' after one or more milliseconds
  7417. */
  7418. var defer = restParam(function(func, args) {
  7419. return baseDelay(func, 1, args);
  7420. });
  7421. /**
  7422. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  7423. * provided to `func` when it's invoked.
  7424. *
  7425. * @static
  7426. * @memberOf _
  7427. * @category Function
  7428. * @param {Function} func The function to delay.
  7429. * @param {number} wait The number of milliseconds to delay invocation.
  7430. * @param {...*} [args] The arguments to invoke the function with.
  7431. * @returns {number} Returns the timer id.
  7432. * @example
  7433. *
  7434. * _.delay(function(text) {
  7435. * console.log(text);
  7436. * }, 1000, 'later');
  7437. * // => logs 'later' after one second
  7438. */
  7439. var delay = restParam(function(func, wait, args) {
  7440. return baseDelay(func, wait, args);
  7441. });
  7442. /**
  7443. * Creates a function that returns the result of invoking the provided
  7444. * functions with the `this` binding of the created function, where each
  7445. * successive invocation is supplied the return value of the previous.
  7446. *
  7447. * @static
  7448. * @memberOf _
  7449. * @category Function
  7450. * @param {...Function} [funcs] Functions to invoke.
  7451. * @returns {Function} Returns the new function.
  7452. * @example
  7453. *
  7454. * function square(n) {
  7455. * return n * n;
  7456. * }
  7457. *
  7458. * var addSquare = _.flow(_.add, square);
  7459. * addSquare(1, 2);
  7460. * // => 9
  7461. */
  7462. var flow = createFlow();
  7463. /**
  7464. * This method is like `_.flow` except that it creates a function that
  7465. * invokes the provided functions from right to left.
  7466. *
  7467. * @static
  7468. * @memberOf _
  7469. * @alias backflow, compose
  7470. * @category Function
  7471. * @param {...Function} [funcs] Functions to invoke.
  7472. * @returns {Function} Returns the new function.
  7473. * @example
  7474. *
  7475. * function square(n) {
  7476. * return n * n;
  7477. * }
  7478. *
  7479. * var addSquare = _.flowRight(square, _.add);
  7480. * addSquare(1, 2);
  7481. * // => 9
  7482. */
  7483. var flowRight = createFlow(true);
  7484. /**
  7485. * Creates a function that memoizes the result of `func`. If `resolver` is
  7486. * provided it determines the cache key for storing the result based on the
  7487. * arguments provided to the memoized function. By default, the first argument
  7488. * provided to the memoized function is coerced to a string and used as the
  7489. * cache key. The `func` is invoked with the `this` binding of the memoized
  7490. * function.
  7491. *
  7492. * **Note:** The cache is exposed as the `cache` property on the memoized
  7493. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  7494. * constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
  7495. * method interface of `get`, `has`, and `set`.
  7496. *
  7497. * @static
  7498. * @memberOf _
  7499. * @category Function
  7500. * @param {Function} func The function to have its output memoized.
  7501. * @param {Function} [resolver] The function to resolve the cache key.
  7502. * @returns {Function} Returns the new memoizing function.
  7503. * @example
  7504. *
  7505. * var upperCase = _.memoize(function(string) {
  7506. * return string.toUpperCase();
  7507. * });
  7508. *
  7509. * upperCase('fred');
  7510. * // => 'FRED'
  7511. *
  7512. * // modifying the result cache
  7513. * upperCase.cache.set('fred', 'BARNEY');
  7514. * upperCase('fred');
  7515. * // => 'BARNEY'
  7516. *
  7517. * // replacing `_.memoize.Cache`
  7518. * var object = { 'user': 'fred' };
  7519. * var other = { 'user': 'barney' };
  7520. * var identity = _.memoize(_.identity);
  7521. *
  7522. * identity(object);
  7523. * // => { 'user': 'fred' }
  7524. * identity(other);
  7525. * // => { 'user': 'fred' }
  7526. *
  7527. * _.memoize.Cache = WeakMap;
  7528. * var identity = _.memoize(_.identity);
  7529. *
  7530. * identity(object);
  7531. * // => { 'user': 'fred' }
  7532. * identity(other);
  7533. * // => { 'user': 'barney' }
  7534. */
  7535. function memoize(func, resolver) {
  7536. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  7537. throw new TypeError(FUNC_ERROR_TEXT);
  7538. }
  7539. var memoized = function() {
  7540. var args = arguments,
  7541. key = resolver ? resolver.apply(this, args) : args[0],
  7542. cache = memoized.cache;
  7543. if (cache.has(key)) {
  7544. return cache.get(key);
  7545. }
  7546. var result = func.apply(this, args);
  7547. memoized.cache = cache.set(key, result);
  7548. return result;
  7549. };
  7550. memoized.cache = new memoize.Cache;
  7551. return memoized;
  7552. }
  7553. /**
  7554. * Creates a function that runs each argument through a corresponding
  7555. * transform function.
  7556. *
  7557. * @static
  7558. * @memberOf _
  7559. * @category Function
  7560. * @param {Function} func The function to wrap.
  7561. * @param {...(Function|Function[])} [transforms] The functions to transform
  7562. * arguments, specified as individual functions or arrays of functions.
  7563. * @returns {Function} Returns the new function.
  7564. * @example
  7565. *
  7566. * function doubled(n) {
  7567. * return n * 2;
  7568. * }
  7569. *
  7570. * function square(n) {
  7571. * return n * n;
  7572. * }
  7573. *
  7574. * var modded = _.modArgs(function(x, y) {
  7575. * return [x, y];
  7576. * }, square, doubled);
  7577. *
  7578. * modded(1, 2);
  7579. * // => [1, 4]
  7580. *
  7581. * modded(5, 10);
  7582. * // => [25, 20]
  7583. */
  7584. var modArgs = restParam(function(func, transforms) {
  7585. transforms = baseFlatten(transforms);
  7586. if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
  7587. throw new TypeError(FUNC_ERROR_TEXT);
  7588. }
  7589. var length = transforms.length;
  7590. return restParam(function(args) {
  7591. var index = nativeMin(args.length, length);
  7592. while (index--) {
  7593. args[index] = transforms[index](args[index]);
  7594. }
  7595. return func.apply(this, args);
  7596. });
  7597. });
  7598. /**
  7599. * Creates a function that negates the result of the predicate `func`. The
  7600. * `func` predicate is invoked with the `this` binding and arguments of the
  7601. * created function.
  7602. *
  7603. * @static
  7604. * @memberOf _
  7605. * @category Function
  7606. * @param {Function} predicate The predicate to negate.
  7607. * @returns {Function} Returns the new function.
  7608. * @example
  7609. *
  7610. * function isEven(n) {
  7611. * return n % 2 == 0;
  7612. * }
  7613. *
  7614. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  7615. * // => [1, 3, 5]
  7616. */
  7617. function negate(predicate) {
  7618. if (typeof predicate != 'function') {
  7619. throw new TypeError(FUNC_ERROR_TEXT);
  7620. }
  7621. return function() {
  7622. return !predicate.apply(this, arguments);
  7623. };
  7624. }
  7625. /**
  7626. * Creates a function that is restricted to invoking `func` once. Repeat calls
  7627. * to the function return the value of the first call. The `func` is invoked
  7628. * with the `this` binding and arguments of the created function.
  7629. *
  7630. * @static
  7631. * @memberOf _
  7632. * @category Function
  7633. * @param {Function} func The function to restrict.
  7634. * @returns {Function} Returns the new restricted function.
  7635. * @example
  7636. *
  7637. * var initialize = _.once(createApplication);
  7638. * initialize();
  7639. * initialize();
  7640. * // `initialize` invokes `createApplication` once
  7641. */
  7642. function once(func) {
  7643. return before(2, func);
  7644. }
  7645. /**
  7646. * Creates a function that invokes `func` with `partial` arguments prepended
  7647. * to those provided to the new function. This method is like `_.bind` except
  7648. * it does **not** alter the `this` binding.
  7649. *
  7650. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  7651. * builds, may be used as a placeholder for partially applied arguments.
  7652. *
  7653. * **Note:** This method does not set the "length" property of partially
  7654. * applied functions.
  7655. *
  7656. * @static
  7657. * @memberOf _
  7658. * @category Function
  7659. * @param {Function} func The function to partially apply arguments to.
  7660. * @param {...*} [partials] The arguments to be partially applied.
  7661. * @returns {Function} Returns the new partially applied function.
  7662. * @example
  7663. *
  7664. * var greet = function(greeting, name) {
  7665. * return greeting + ' ' + name;
  7666. * };
  7667. *
  7668. * var sayHelloTo = _.partial(greet, 'hello');
  7669. * sayHelloTo('fred');
  7670. * // => 'hello fred'
  7671. *
  7672. * // using placeholders
  7673. * var greetFred = _.partial(greet, _, 'fred');
  7674. * greetFred('hi');
  7675. * // => 'hi fred'
  7676. */
  7677. var partial = createPartial(PARTIAL_FLAG);
  7678. /**
  7679. * This method is like `_.partial` except that partially applied arguments
  7680. * are appended to those provided to the new function.
  7681. *
  7682. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  7683. * builds, may be used as a placeholder for partially applied arguments.
  7684. *
  7685. * **Note:** This method does not set the "length" property of partially
  7686. * applied functions.
  7687. *
  7688. * @static
  7689. * @memberOf _
  7690. * @category Function
  7691. * @param {Function} func The function to partially apply arguments to.
  7692. * @param {...*} [partials] The arguments to be partially applied.
  7693. * @returns {Function} Returns the new partially applied function.
  7694. * @example
  7695. *
  7696. * var greet = function(greeting, name) {
  7697. * return greeting + ' ' + name;
  7698. * };
  7699. *
  7700. * var greetFred = _.partialRight(greet, 'fred');
  7701. * greetFred('hi');
  7702. * // => 'hi fred'
  7703. *
  7704. * // using placeholders
  7705. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  7706. * sayHelloTo('fred');
  7707. * // => 'hello fred'
  7708. */
  7709. var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
  7710. /**
  7711. * Creates a function that invokes `func` with arguments arranged according
  7712. * to the specified indexes where the argument value at the first index is
  7713. * provided as the first argument, the argument value at the second index is
  7714. * provided as the second argument, and so on.
  7715. *
  7716. * @static
  7717. * @memberOf _
  7718. * @category Function
  7719. * @param {Function} func The function to rearrange arguments for.
  7720. * @param {...(number|number[])} indexes The arranged argument indexes,
  7721. * specified as individual indexes or arrays of indexes.
  7722. * @returns {Function} Returns the new function.
  7723. * @example
  7724. *
  7725. * var rearged = _.rearg(function(a, b, c) {
  7726. * return [a, b, c];
  7727. * }, 2, 0, 1);
  7728. *
  7729. * rearged('b', 'c', 'a')
  7730. * // => ['a', 'b', 'c']
  7731. *
  7732. * var map = _.rearg(_.map, [1, 0]);
  7733. * map(function(n) {
  7734. * return n * 3;
  7735. * }, [1, 2, 3]);
  7736. * // => [3, 6, 9]
  7737. */
  7738. var rearg = restParam(function(func, indexes) {
  7739. return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
  7740. });
  7741. /**
  7742. * Creates a function that invokes `func` with the `this` binding of the
  7743. * created function and arguments from `start` and beyond provided as an array.
  7744. *
  7745. * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/Web/JavaScript/Reference/Functions/rest_parameters).
  7746. *
  7747. * @static
  7748. * @memberOf _
  7749. * @category Function
  7750. * @param {Function} func The function to apply a rest parameter to.
  7751. * @param {number} [start=func.length-1] The start position of the rest parameter.
  7752. * @returns {Function} Returns the new function.
  7753. * @example
  7754. *
  7755. * var say = _.restParam(function(what, names) {
  7756. * return what + ' ' + _.initial(names).join(', ') +
  7757. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  7758. * });
  7759. *
  7760. * say('hello', 'fred', 'barney', 'pebbles');
  7761. * // => 'hello fred, barney, & pebbles'
  7762. */
  7763. function restParam(func, start) {
  7764. if (typeof func != 'function') {
  7765. throw new TypeError(FUNC_ERROR_TEXT);
  7766. }
  7767. start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
  7768. return function() {
  7769. var args = arguments,
  7770. index = -1,
  7771. length = nativeMax(args.length - start, 0),
  7772. rest = Array(length);
  7773. while (++index < length) {
  7774. rest[index] = args[start + index];
  7775. }
  7776. switch (start) {
  7777. case 0: return func.call(this, rest);
  7778. case 1: return func.call(this, args[0], rest);
  7779. case 2: return func.call(this, args[0], args[1], rest);
  7780. }
  7781. var otherArgs = Array(start + 1);
  7782. index = -1;
  7783. while (++index < start) {
  7784. otherArgs[index] = args[index];
  7785. }
  7786. otherArgs[start] = rest;
  7787. return func.apply(this, otherArgs);
  7788. };
  7789. }
  7790. /**
  7791. * Creates a function that invokes `func` with the `this` binding of the created
  7792. * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
  7793. *
  7794. * **Note:** This method is based on the [spread operator](https://developer.mozilla.org/Web/JavaScript/Reference/Operators/Spread_operator).
  7795. *
  7796. * @static
  7797. * @memberOf _
  7798. * @category Function
  7799. * @param {Function} func The function to spread arguments over.
  7800. * @returns {Function} Returns the new function.
  7801. * @example
  7802. *
  7803. * var say = _.spread(function(who, what) {
  7804. * return who + ' says ' + what;
  7805. * });
  7806. *
  7807. * say(['fred', 'hello']);
  7808. * // => 'fred says hello'
  7809. *
  7810. * // with a Promise
  7811. * var numbers = Promise.all([
  7812. * Promise.resolve(40),
  7813. * Promise.resolve(36)
  7814. * ]);
  7815. *
  7816. * numbers.then(_.spread(function(x, y) {
  7817. * return x + y;
  7818. * }));
  7819. * // => a Promise of 76
  7820. */
  7821. function spread(func) {
  7822. if (typeof func != 'function') {
  7823. throw new TypeError(FUNC_ERROR_TEXT);
  7824. }
  7825. return function(array) {
  7826. return func.apply(this, array);
  7827. };
  7828. }
  7829. /**
  7830. * Creates a throttled function that only invokes `func` at most once per
  7831. * every `wait` milliseconds. The throttled function comes with a `cancel`
  7832. * method to cancel delayed invocations. Provide an options object to indicate
  7833. * that `func` should be invoked on the leading and/or trailing edge of the
  7834. * `wait` timeout. Subsequent calls to the throttled function return the
  7835. * result of the last `func` call.
  7836. *
  7837. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  7838. * on the trailing edge of the timeout only if the the throttled function is
  7839. * invoked more than once during the `wait` timeout.
  7840. *
  7841. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  7842. * for details over the differences between `_.throttle` and `_.debounce`.
  7843. *
  7844. * @static
  7845. * @memberOf _
  7846. * @category Function
  7847. * @param {Function} func The function to throttle.
  7848. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  7849. * @param {Object} [options] The options object.
  7850. * @param {boolean} [options.leading=true] Specify invoking on the leading
  7851. * edge of the timeout.
  7852. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  7853. * edge of the timeout.
  7854. * @returns {Function} Returns the new throttled function.
  7855. * @example
  7856. *
  7857. * // avoid excessively updating the position while scrolling
  7858. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  7859. *
  7860. * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
  7861. * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
  7862. * 'trailing': false
  7863. * }));
  7864. *
  7865. * // cancel a trailing throttled call
  7866. * jQuery(window).on('popstate', throttled.cancel);
  7867. */
  7868. function throttle(func, wait, options) {
  7869. var leading = true,
  7870. trailing = true;
  7871. if (typeof func != 'function') {
  7872. throw new TypeError(FUNC_ERROR_TEXT);
  7873. }
  7874. if (options === false) {
  7875. leading = false;
  7876. } else if (isObject(options)) {
  7877. leading = 'leading' in options ? !!options.leading : leading;
  7878. trailing = 'trailing' in options ? !!options.trailing : trailing;
  7879. }
  7880. return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
  7881. }
  7882. /**
  7883. * Creates a function that provides `value` to the wrapper function as its
  7884. * first argument. Any additional arguments provided to the function are
  7885. * appended to those provided to the wrapper function. The wrapper is invoked
  7886. * with the `this` binding of the created function.
  7887. *
  7888. * @static
  7889. * @memberOf _
  7890. * @category Function
  7891. * @param {*} value The value to wrap.
  7892. * @param {Function} wrapper The wrapper function.
  7893. * @returns {Function} Returns the new function.
  7894. * @example
  7895. *
  7896. * var p = _.wrap(_.escape, function(func, text) {
  7897. * return '<p>' + func(text) + '</p>';
  7898. * });
  7899. *
  7900. * p('fred, barney, & pebbles');
  7901. * // => '<p>fred, barney, &amp; pebbles</p>'
  7902. */
  7903. function wrap(value, wrapper) {
  7904. wrapper = wrapper == null ? identity : wrapper;
  7905. return createWrapper(wrapper, PARTIAL_FLAG, undefined, [value], []);
  7906. }
  7907. /*------------------------------------------------------------------------*/
  7908. /**
  7909. * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
  7910. * otherwise they are assigned by reference. If `customizer` is provided it's
  7911. * invoked to produce the cloned values. If `customizer` returns `undefined`
  7912. * cloning is handled by the method instead. The `customizer` is bound to
  7913. * `thisArg` and invoked with up to three argument; (value [, index|key, object]).
  7914. *
  7915. * **Note:** This method is loosely based on the
  7916. * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
  7917. * The enumerable properties of `arguments` objects and objects created by
  7918. * constructors other than `Object` are cloned to plain `Object` objects. An
  7919. * empty object is returned for uncloneable values such as functions, DOM nodes,
  7920. * Maps, Sets, and WeakMaps.
  7921. *
  7922. * @static
  7923. * @memberOf _
  7924. * @category Lang
  7925. * @param {*} value The value to clone.
  7926. * @param {boolean} [isDeep] Specify a deep clone.
  7927. * @param {Function} [customizer] The function to customize cloning values.
  7928. * @param {*} [thisArg] The `this` binding of `customizer`.
  7929. * @returns {*} Returns the cloned value.
  7930. * @example
  7931. *
  7932. * var users = [
  7933. * { 'user': 'barney' },
  7934. * { 'user': 'fred' }
  7935. * ];
  7936. *
  7937. * var shallow = _.clone(users);
  7938. * shallow[0] === users[0];
  7939. * // => true
  7940. *
  7941. * var deep = _.clone(users, true);
  7942. * deep[0] === users[0];
  7943. * // => false
  7944. *
  7945. * // using a customizer callback
  7946. * var el = _.clone(document.body, function(value) {
  7947. * if (_.isElement(value)) {
  7948. * return value.cloneNode(false);
  7949. * }
  7950. * });
  7951. *
  7952. * el === document.body
  7953. * // => false
  7954. * el.nodeName
  7955. * // => BODY
  7956. * el.childNodes.length;
  7957. * // => 0
  7958. */
  7959. function clone(value, isDeep, customizer, thisArg) {
  7960. if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
  7961. isDeep = false;
  7962. }
  7963. else if (typeof isDeep == 'function') {
  7964. thisArg = customizer;
  7965. customizer = isDeep;
  7966. isDeep = false;
  7967. }
  7968. return typeof customizer == 'function'
  7969. ? baseClone(value, isDeep, bindCallback(customizer, thisArg, 3))
  7970. : baseClone(value, isDeep);
  7971. }
  7972. /**
  7973. * Creates a deep clone of `value`. If `customizer` is provided it's invoked
  7974. * to produce the cloned values. If `customizer` returns `undefined` cloning
  7975. * is handled by the method instead. The `customizer` is bound to `thisArg`
  7976. * and invoked with up to three argument; (value [, index|key, object]).
  7977. *
  7978. * **Note:** This method is loosely based on the
  7979. * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
  7980. * The enumerable properties of `arguments` objects and objects created by
  7981. * constructors other than `Object` are cloned to plain `Object` objects. An
  7982. * empty object is returned for uncloneable values such as functions, DOM nodes,
  7983. * Maps, Sets, and WeakMaps.
  7984. *
  7985. * @static
  7986. * @memberOf _
  7987. * @category Lang
  7988. * @param {*} value The value to deep clone.
  7989. * @param {Function} [customizer] The function to customize cloning values.
  7990. * @param {*} [thisArg] The `this` binding of `customizer`.
  7991. * @returns {*} Returns the deep cloned value.
  7992. * @example
  7993. *
  7994. * var users = [
  7995. * { 'user': 'barney' },
  7996. * { 'user': 'fred' }
  7997. * ];
  7998. *
  7999. * var deep = _.cloneDeep(users);
  8000. * deep[0] === users[0];
  8001. * // => false
  8002. *
  8003. * // using a customizer callback
  8004. * var el = _.cloneDeep(document.body, function(value) {
  8005. * if (_.isElement(value)) {
  8006. * return value.cloneNode(true);
  8007. * }
  8008. * });
  8009. *
  8010. * el === document.body
  8011. * // => false
  8012. * el.nodeName
  8013. * // => BODY
  8014. * el.childNodes.length;
  8015. * // => 20
  8016. */
  8017. function cloneDeep(value, customizer, thisArg) {
  8018. return typeof customizer == 'function'
  8019. ? baseClone(value, true, bindCallback(customizer, thisArg, 3))
  8020. : baseClone(value, true);
  8021. }
  8022. /**
  8023. * Checks if `value` is greater than `other`.
  8024. *
  8025. * @static
  8026. * @memberOf _
  8027. * @category Lang
  8028. * @param {*} value The value to compare.
  8029. * @param {*} other The other value to compare.
  8030. * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
  8031. * @example
  8032. *
  8033. * _.gt(3, 1);
  8034. * // => true
  8035. *
  8036. * _.gt(3, 3);
  8037. * // => false
  8038. *
  8039. * _.gt(1, 3);
  8040. * // => false
  8041. */
  8042. function gt(value, other) {
  8043. return value > other;
  8044. }
  8045. /**
  8046. * Checks if `value` is greater than or equal to `other`.
  8047. *
  8048. * @static
  8049. * @memberOf _
  8050. * @category Lang
  8051. * @param {*} value The value to compare.
  8052. * @param {*} other The other value to compare.
  8053. * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
  8054. * @example
  8055. *
  8056. * _.gte(3, 1);
  8057. * // => true
  8058. *
  8059. * _.gte(3, 3);
  8060. * // => true
  8061. *
  8062. * _.gte(1, 3);
  8063. * // => false
  8064. */
  8065. function gte(value, other) {
  8066. return value >= other;
  8067. }
  8068. /**
  8069. * Checks if `value` is classified as an `arguments` object.
  8070. *
  8071. * @static
  8072. * @memberOf _
  8073. * @category Lang
  8074. * @param {*} value The value to check.
  8075. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8076. * @example
  8077. *
  8078. * _.isArguments(function() { return arguments; }());
  8079. * // => true
  8080. *
  8081. * _.isArguments([1, 2, 3]);
  8082. * // => false
  8083. */
  8084. function isArguments(value) {
  8085. return isObjectLike(value) && isArrayLike(value) &&
  8086. hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
  8087. }
  8088. /**
  8089. * Checks if `value` is classified as an `Array` object.
  8090. *
  8091. * @static
  8092. * @memberOf _
  8093. * @category Lang
  8094. * @param {*} value The value to check.
  8095. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8096. * @example
  8097. *
  8098. * _.isArray([1, 2, 3]);
  8099. * // => true
  8100. *
  8101. * _.isArray(function() { return arguments; }());
  8102. * // => false
  8103. */
  8104. var isArray = nativeIsArray || function(value) {
  8105. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  8106. };
  8107. /**
  8108. * Checks if `value` is classified as a boolean primitive or object.
  8109. *
  8110. * @static
  8111. * @memberOf _
  8112. * @category Lang
  8113. * @param {*} value The value to check.
  8114. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8115. * @example
  8116. *
  8117. * _.isBoolean(false);
  8118. * // => true
  8119. *
  8120. * _.isBoolean(null);
  8121. * // => false
  8122. */
  8123. function isBoolean(value) {
  8124. return value === true || value === false || (isObjectLike(value) && objToString.call(value) == boolTag);
  8125. }
  8126. /**
  8127. * Checks if `value` is classified as a `Date` object.
  8128. *
  8129. * @static
  8130. * @memberOf _
  8131. * @category Lang
  8132. * @param {*} value The value to check.
  8133. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8134. * @example
  8135. *
  8136. * _.isDate(new Date);
  8137. * // => true
  8138. *
  8139. * _.isDate('Mon April 23 2012');
  8140. * // => false
  8141. */
  8142. function isDate(value) {
  8143. return isObjectLike(value) && objToString.call(value) == dateTag;
  8144. }
  8145. /**
  8146. * Checks if `value` is a DOM element.
  8147. *
  8148. * @static
  8149. * @memberOf _
  8150. * @category Lang
  8151. * @param {*} value The value to check.
  8152. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  8153. * @example
  8154. *
  8155. * _.isElement(document.body);
  8156. * // => true
  8157. *
  8158. * _.isElement('<body>');
  8159. * // => false
  8160. */
  8161. function isElement(value) {
  8162. return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
  8163. }
  8164. /**
  8165. * Checks if `value` is empty. A value is considered empty unless it's an
  8166. * `arguments` object, array, string, or jQuery-like collection with a length
  8167. * greater than `0` or an object with own enumerable properties.
  8168. *
  8169. * @static
  8170. * @memberOf _
  8171. * @category Lang
  8172. * @param {Array|Object|string} value The value to inspect.
  8173. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  8174. * @example
  8175. *
  8176. * _.isEmpty(null);
  8177. * // => true
  8178. *
  8179. * _.isEmpty(true);
  8180. * // => true
  8181. *
  8182. * _.isEmpty(1);
  8183. * // => true
  8184. *
  8185. * _.isEmpty([1, 2, 3]);
  8186. * // => false
  8187. *
  8188. * _.isEmpty({ 'a': 1 });
  8189. * // => false
  8190. */
  8191. function isEmpty(value) {
  8192. if (value == null) {
  8193. return true;
  8194. }
  8195. if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) ||
  8196. (isObjectLike(value) && isFunction(value.splice)))) {
  8197. return !value.length;
  8198. }
  8199. return !keys(value).length;
  8200. }
  8201. /**
  8202. * Performs a deep comparison between two values to determine if they are
  8203. * equivalent. If `customizer` is provided it's invoked to compare values.
  8204. * If `customizer` returns `undefined` comparisons are handled by the method
  8205. * instead. The `customizer` is bound to `thisArg` and invoked with up to
  8206. * three arguments: (value, other [, index|key]).
  8207. *
  8208. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  8209. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  8210. * their own, not inherited, enumerable properties. Functions and DOM nodes
  8211. * are **not** supported. Provide a customizer function to extend support
  8212. * for comparing other values.
  8213. *
  8214. * @static
  8215. * @memberOf _
  8216. * @alias eq
  8217. * @category Lang
  8218. * @param {*} value The value to compare.
  8219. * @param {*} other The other value to compare.
  8220. * @param {Function} [customizer] The function to customize value comparisons.
  8221. * @param {*} [thisArg] The `this` binding of `customizer`.
  8222. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  8223. * @example
  8224. *
  8225. * var object = { 'user': 'fred' };
  8226. * var other = { 'user': 'fred' };
  8227. *
  8228. * object == other;
  8229. * // => false
  8230. *
  8231. * _.isEqual(object, other);
  8232. * // => true
  8233. *
  8234. * // using a customizer callback
  8235. * var array = ['hello', 'goodbye'];
  8236. * var other = ['hi', 'goodbye'];
  8237. *
  8238. * _.isEqual(array, other, function(value, other) {
  8239. * if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
  8240. * return true;
  8241. * }
  8242. * });
  8243. * // => true
  8244. */
  8245. function isEqual(value, other, customizer, thisArg) {
  8246. customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
  8247. var result = customizer ? customizer(value, other) : undefined;
  8248. return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
  8249. }
  8250. /**
  8251. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  8252. * `SyntaxError`, `TypeError`, or `URIError` object.
  8253. *
  8254. * @static
  8255. * @memberOf _
  8256. * @category Lang
  8257. * @param {*} value The value to check.
  8258. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  8259. * @example
  8260. *
  8261. * _.isError(new Error);
  8262. * // => true
  8263. *
  8264. * _.isError(Error);
  8265. * // => false
  8266. */
  8267. function isError(value) {
  8268. return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
  8269. }
  8270. /**
  8271. * Checks if `value` is a finite primitive number.
  8272. *
  8273. * **Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite).
  8274. *
  8275. * @static
  8276. * @memberOf _
  8277. * @category Lang
  8278. * @param {*} value The value to check.
  8279. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  8280. * @example
  8281. *
  8282. * _.isFinite(10);
  8283. * // => true
  8284. *
  8285. * _.isFinite('10');
  8286. * // => false
  8287. *
  8288. * _.isFinite(true);
  8289. * // => false
  8290. *
  8291. * _.isFinite(Object(10));
  8292. * // => false
  8293. *
  8294. * _.isFinite(Infinity);
  8295. * // => false
  8296. */
  8297. function isFinite(value) {
  8298. return typeof value == 'number' && nativeIsFinite(value);
  8299. }
  8300. /**
  8301. * Checks if `value` is classified as a `Function` object.
  8302. *
  8303. * @static
  8304. * @memberOf _
  8305. * @category Lang
  8306. * @param {*} value The value to check.
  8307. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8308. * @example
  8309. *
  8310. * _.isFunction(_);
  8311. * // => true
  8312. *
  8313. * _.isFunction(/abc/);
  8314. * // => false
  8315. */
  8316. function isFunction(value) {
  8317. // The use of `Object#toString` avoids issues with the `typeof` operator
  8318. // in older versions of Chrome and Safari which return 'function' for regexes
  8319. // and Safari 8 which returns 'object' for typed array constructors.
  8320. return isObject(value) && objToString.call(value) == funcTag;
  8321. }
  8322. /**
  8323. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  8324. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  8325. *
  8326. * @static
  8327. * @memberOf _
  8328. * @category Lang
  8329. * @param {*} value The value to check.
  8330. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  8331. * @example
  8332. *
  8333. * _.isObject({});
  8334. * // => true
  8335. *
  8336. * _.isObject([1, 2, 3]);
  8337. * // => true
  8338. *
  8339. * _.isObject(1);
  8340. * // => false
  8341. */
  8342. function isObject(value) {
  8343. // Avoid a V8 JIT bug in Chrome 19-20.
  8344. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  8345. var type = typeof value;
  8346. return !!value && (type == 'object' || type == 'function');
  8347. }
  8348. /**
  8349. * Performs a deep comparison between `object` and `source` to determine if
  8350. * `object` contains equivalent property values. If `customizer` is provided
  8351. * it's invoked to compare values. If `customizer` returns `undefined`
  8352. * comparisons are handled by the method instead. The `customizer` is bound
  8353. * to `thisArg` and invoked with three arguments: (value, other, index|key).
  8354. *
  8355. * **Note:** This method supports comparing properties of arrays, booleans,
  8356. * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
  8357. * and DOM nodes are **not** supported. Provide a customizer function to extend
  8358. * support for comparing other values.
  8359. *
  8360. * @static
  8361. * @memberOf _
  8362. * @category Lang
  8363. * @param {Object} object The object to inspect.
  8364. * @param {Object} source The object of property values to match.
  8365. * @param {Function} [customizer] The function to customize value comparisons.
  8366. * @param {*} [thisArg] The `this` binding of `customizer`.
  8367. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  8368. * @example
  8369. *
  8370. * var object = { 'user': 'fred', 'age': 40 };
  8371. *
  8372. * _.isMatch(object, { 'age': 40 });
  8373. * // => true
  8374. *
  8375. * _.isMatch(object, { 'age': 36 });
  8376. * // => false
  8377. *
  8378. * // using a customizer callback
  8379. * var object = { 'greeting': 'hello' };
  8380. * var source = { 'greeting': 'hi' };
  8381. *
  8382. * _.isMatch(object, source, function(value, other) {
  8383. * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
  8384. * });
  8385. * // => true
  8386. */
  8387. function isMatch(object, source, customizer, thisArg) {
  8388. customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
  8389. return baseIsMatch(object, getMatchData(source), customizer);
  8390. }
  8391. /**
  8392. * Checks if `value` is `NaN`.
  8393. *
  8394. * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
  8395. * which returns `true` for `undefined` and other non-numeric values.
  8396. *
  8397. * @static
  8398. * @memberOf _
  8399. * @category Lang
  8400. * @param {*} value The value to check.
  8401. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  8402. * @example
  8403. *
  8404. * _.isNaN(NaN);
  8405. * // => true
  8406. *
  8407. * _.isNaN(new Number(NaN));
  8408. * // => true
  8409. *
  8410. * isNaN(undefined);
  8411. * // => true
  8412. *
  8413. * _.isNaN(undefined);
  8414. * // => false
  8415. */
  8416. function isNaN(value) {
  8417. // An `NaN` primitive is the only value that is not equal to itself.
  8418. // Perform the `toStringTag` check first to avoid errors with some host objects in IE.
  8419. return isNumber(value) && value != +value;
  8420. }
  8421. /**
  8422. * Checks if `value` is a native function.
  8423. *
  8424. * @static
  8425. * @memberOf _
  8426. * @category Lang
  8427. * @param {*} value The value to check.
  8428. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  8429. * @example
  8430. *
  8431. * _.isNative(Array.prototype.push);
  8432. * // => true
  8433. *
  8434. * _.isNative(_);
  8435. * // => false
  8436. */
  8437. function isNative(value) {
  8438. if (value == null) {
  8439. return false;
  8440. }
  8441. if (isFunction(value)) {
  8442. return reIsNative.test(fnToString.call(value));
  8443. }
  8444. return isObjectLike(value) && (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
  8445. }
  8446. /**
  8447. * Checks if `value` is `null`.
  8448. *
  8449. * @static
  8450. * @memberOf _
  8451. * @category Lang
  8452. * @param {*} value The value to check.
  8453. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  8454. * @example
  8455. *
  8456. * _.isNull(null);
  8457. * // => true
  8458. *
  8459. * _.isNull(void 0);
  8460. * // => false
  8461. */
  8462. function isNull(value) {
  8463. return value === null;
  8464. }
  8465. /**
  8466. * Checks if `value` is classified as a `Number` primitive or object.
  8467. *
  8468. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
  8469. * as numbers, use the `_.isFinite` method.
  8470. *
  8471. * @static
  8472. * @memberOf _
  8473. * @category Lang
  8474. * @param {*} value The value to check.
  8475. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8476. * @example
  8477. *
  8478. * _.isNumber(8.4);
  8479. * // => true
  8480. *
  8481. * _.isNumber(NaN);
  8482. * // => true
  8483. *
  8484. * _.isNumber('8.4');
  8485. * // => false
  8486. */
  8487. function isNumber(value) {
  8488. return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag);
  8489. }
  8490. /**
  8491. * Checks if `value` is a plain object, that is, an object created by the
  8492. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  8493. *
  8494. * **Note:** This method assumes objects created by the `Object` constructor
  8495. * have no inherited enumerable properties.
  8496. *
  8497. * @static
  8498. * @memberOf _
  8499. * @category Lang
  8500. * @param {*} value The value to check.
  8501. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  8502. * @example
  8503. *
  8504. * function Foo() {
  8505. * this.a = 1;
  8506. * }
  8507. *
  8508. * _.isPlainObject(new Foo);
  8509. * // => false
  8510. *
  8511. * _.isPlainObject([1, 2, 3]);
  8512. * // => false
  8513. *
  8514. * _.isPlainObject({ 'x': 0, 'y': 0 });
  8515. * // => true
  8516. *
  8517. * _.isPlainObject(Object.create(null));
  8518. * // => true
  8519. */
  8520. function isPlainObject(value) {
  8521. var Ctor;
  8522. // Exit early for non `Object` objects.
  8523. if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isHostObject(value) && !isArguments(value)) ||
  8524. (!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
  8525. return false;
  8526. }
  8527. // IE < 9 iterates inherited properties before own properties. If the first
  8528. // iterated property is an object's own property then there are no inherited
  8529. // enumerable properties.
  8530. var result;
  8531. if (lodash.support.ownLast) {
  8532. baseForIn(value, function(subValue, key, object) {
  8533. result = hasOwnProperty.call(object, key);
  8534. return false;
  8535. });
  8536. return result !== false;
  8537. }
  8538. // In most environments an object's own properties are iterated before
  8539. // its inherited properties. If the last iterated property is an object's
  8540. // own property then there are no inherited enumerable properties.
  8541. baseForIn(value, function(subValue, key) {
  8542. result = key;
  8543. });
  8544. return result === undefined || hasOwnProperty.call(value, result);
  8545. }
  8546. /**
  8547. * Checks if `value` is classified as a `RegExp` object.
  8548. *
  8549. * @static
  8550. * @memberOf _
  8551. * @category Lang
  8552. * @param {*} value The value to check.
  8553. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8554. * @example
  8555. *
  8556. * _.isRegExp(/abc/);
  8557. * // => true
  8558. *
  8559. * _.isRegExp('/abc/');
  8560. * // => false
  8561. */
  8562. function isRegExp(value) {
  8563. return isObject(value) && objToString.call(value) == regexpTag;
  8564. }
  8565. /**
  8566. * Checks if `value` is classified as a `String` primitive or object.
  8567. *
  8568. * @static
  8569. * @memberOf _
  8570. * @category Lang
  8571. * @param {*} value The value to check.
  8572. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8573. * @example
  8574. *
  8575. * _.isString('abc');
  8576. * // => true
  8577. *
  8578. * _.isString(1);
  8579. * // => false
  8580. */
  8581. function isString(value) {
  8582. return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
  8583. }
  8584. /**
  8585. * Checks if `value` is classified as a typed array.
  8586. *
  8587. * @static
  8588. * @memberOf _
  8589. * @category Lang
  8590. * @param {*} value The value to check.
  8591. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8592. * @example
  8593. *
  8594. * _.isTypedArray(new Uint8Array);
  8595. * // => true
  8596. *
  8597. * _.isTypedArray([]);
  8598. * // => false
  8599. */
  8600. function isTypedArray(value) {
  8601. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
  8602. }
  8603. /**
  8604. * Checks if `value` is `undefined`.
  8605. *
  8606. * @static
  8607. * @memberOf _
  8608. * @category Lang
  8609. * @param {*} value The value to check.
  8610. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  8611. * @example
  8612. *
  8613. * _.isUndefined(void 0);
  8614. * // => true
  8615. *
  8616. * _.isUndefined(null);
  8617. * // => false
  8618. */
  8619. function isUndefined(value) {
  8620. return value === undefined;
  8621. }
  8622. /**
  8623. * Checks if `value` is less than `other`.
  8624. *
  8625. * @static
  8626. * @memberOf _
  8627. * @category Lang
  8628. * @param {*} value The value to compare.
  8629. * @param {*} other The other value to compare.
  8630. * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
  8631. * @example
  8632. *
  8633. * _.lt(1, 3);
  8634. * // => true
  8635. *
  8636. * _.lt(3, 3);
  8637. * // => false
  8638. *
  8639. * _.lt(3, 1);
  8640. * // => false
  8641. */
  8642. function lt(value, other) {
  8643. return value < other;
  8644. }
  8645. /**
  8646. * Checks if `value` is less than or equal to `other`.
  8647. *
  8648. * @static
  8649. * @memberOf _
  8650. * @category Lang
  8651. * @param {*} value The value to compare.
  8652. * @param {*} other The other value to compare.
  8653. * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
  8654. * @example
  8655. *
  8656. * _.lte(1, 3);
  8657. * // => true
  8658. *
  8659. * _.lte(3, 3);
  8660. * // => true
  8661. *
  8662. * _.lte(3, 1);
  8663. * // => false
  8664. */
  8665. function lte(value, other) {
  8666. return value <= other;
  8667. }
  8668. /**
  8669. * Converts `value` to an array.
  8670. *
  8671. * @static
  8672. * @memberOf _
  8673. * @category Lang
  8674. * @param {*} value The value to convert.
  8675. * @returns {Array} Returns the converted array.
  8676. * @example
  8677. *
  8678. * (function() {
  8679. * return _.toArray(arguments).slice(1);
  8680. * }(1, 2, 3));
  8681. * // => [2, 3]
  8682. */
  8683. function toArray(value) {
  8684. var length = value ? getLength(value) : 0;
  8685. if (!isLength(length)) {
  8686. return values(value);
  8687. }
  8688. if (!length) {
  8689. return [];
  8690. }
  8691. return (lodash.support.unindexedChars && isString(value))
  8692. ? value.split('')
  8693. : arrayCopy(value);
  8694. }
  8695. /**
  8696. * Converts `value` to a plain object flattening inherited enumerable
  8697. * properties of `value` to own properties of the plain object.
  8698. *
  8699. * @static
  8700. * @memberOf _
  8701. * @category Lang
  8702. * @param {*} value The value to convert.
  8703. * @returns {Object} Returns the converted plain object.
  8704. * @example
  8705. *
  8706. * function Foo() {
  8707. * this.b = 2;
  8708. * }
  8709. *
  8710. * Foo.prototype.c = 3;
  8711. *
  8712. * _.assign({ 'a': 1 }, new Foo);
  8713. * // => { 'a': 1, 'b': 2 }
  8714. *
  8715. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  8716. * // => { 'a': 1, 'b': 2, 'c': 3 }
  8717. */
  8718. function toPlainObject(value) {
  8719. return baseCopy(value, keysIn(value));
  8720. }
  8721. /*------------------------------------------------------------------------*/
  8722. /**
  8723. * Recursively merges own enumerable properties of the source object(s), that
  8724. * don't resolve to `undefined` into the destination object. Subsequent sources
  8725. * overwrite property assignments of previous sources. If `customizer` is
  8726. * provided it's invoked to produce the merged values of the destination and
  8727. * source properties. If `customizer` returns `undefined` merging is handled
  8728. * by the method instead. The `customizer` is bound to `thisArg` and invoked
  8729. * with five arguments: (objectValue, sourceValue, key, object, source).
  8730. *
  8731. * @static
  8732. * @memberOf _
  8733. * @category Object
  8734. * @param {Object} object The destination object.
  8735. * @param {...Object} [sources] The source objects.
  8736. * @param {Function} [customizer] The function to customize assigned values.
  8737. * @param {*} [thisArg] The `this` binding of `customizer`.
  8738. * @returns {Object} Returns `object`.
  8739. * @example
  8740. *
  8741. * var users = {
  8742. * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
  8743. * };
  8744. *
  8745. * var ages = {
  8746. * 'data': [{ 'age': 36 }, { 'age': 40 }]
  8747. * };
  8748. *
  8749. * _.merge(users, ages);
  8750. * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
  8751. *
  8752. * // using a customizer callback
  8753. * var object = {
  8754. * 'fruits': ['apple'],
  8755. * 'vegetables': ['beet']
  8756. * };
  8757. *
  8758. * var other = {
  8759. * 'fruits': ['banana'],
  8760. * 'vegetables': ['carrot']
  8761. * };
  8762. *
  8763. * _.merge(object, other, function(a, b) {
  8764. * if (_.isArray(a)) {
  8765. * return a.concat(b);
  8766. * }
  8767. * });
  8768. * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
  8769. */
  8770. var merge = createAssigner(baseMerge);
  8771. /**
  8772. * Assigns own enumerable properties of source object(s) to the destination
  8773. * object. Subsequent sources overwrite property assignments of previous sources.
  8774. * If `customizer` is provided it's invoked to produce the assigned values.
  8775. * The `customizer` is bound to `thisArg` and invoked with five arguments:
  8776. * (objectValue, sourceValue, key, object, source).
  8777. *
  8778. * **Note:** This method mutates `object` and is based on
  8779. * [`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign).
  8780. *
  8781. * @static
  8782. * @memberOf _
  8783. * @alias extend
  8784. * @category Object
  8785. * @param {Object} object The destination object.
  8786. * @param {...Object} [sources] The source objects.
  8787. * @param {Function} [customizer] The function to customize assigned values.
  8788. * @param {*} [thisArg] The `this` binding of `customizer`.
  8789. * @returns {Object} Returns `object`.
  8790. * @example
  8791. *
  8792. * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
  8793. * // => { 'user': 'fred', 'age': 40 }
  8794. *
  8795. * // using a customizer callback
  8796. * var defaults = _.partialRight(_.assign, function(value, other) {
  8797. * return _.isUndefined(value) ? other : value;
  8798. * });
  8799. *
  8800. * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  8801. * // => { 'user': 'barney', 'age': 36 }
  8802. */
  8803. var assign = createAssigner(function(object, source, customizer) {
  8804. return customizer
  8805. ? assignWith(object, source, customizer)
  8806. : baseAssign(object, source);
  8807. });
  8808. /**
  8809. * Creates an object that inherits from the given `prototype` object. If a
  8810. * `properties` object is provided its own enumerable properties are assigned
  8811. * to the created object.
  8812. *
  8813. * @static
  8814. * @memberOf _
  8815. * @category Object
  8816. * @param {Object} prototype The object to inherit from.
  8817. * @param {Object} [properties] The properties to assign to the object.
  8818. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  8819. * @returns {Object} Returns the new object.
  8820. * @example
  8821. *
  8822. * function Shape() {
  8823. * this.x = 0;
  8824. * this.y = 0;
  8825. * }
  8826. *
  8827. * function Circle() {
  8828. * Shape.call(this);
  8829. * }
  8830. *
  8831. * Circle.prototype = _.create(Shape.prototype, {
  8832. * 'constructor': Circle
  8833. * });
  8834. *
  8835. * var circle = new Circle;
  8836. * circle instanceof Circle;
  8837. * // => true
  8838. *
  8839. * circle instanceof Shape;
  8840. * // => true
  8841. */
  8842. function create(prototype, properties, guard) {
  8843. var result = baseCreate(prototype);
  8844. if (guard && isIterateeCall(prototype, properties, guard)) {
  8845. properties = undefined;
  8846. }
  8847. return properties ? baseAssign(result, properties) : result;
  8848. }
  8849. /**
  8850. * Assigns own enumerable properties of source object(s) to the destination
  8851. * object for all destination properties that resolve to `undefined`. Once a
  8852. * property is set, additional values of the same property are ignored.
  8853. *
  8854. * **Note:** This method mutates `object`.
  8855. *
  8856. * @static
  8857. * @memberOf _
  8858. * @category Object
  8859. * @param {Object} object The destination object.
  8860. * @param {...Object} [sources] The source objects.
  8861. * @returns {Object} Returns `object`.
  8862. * @example
  8863. *
  8864. * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  8865. * // => { 'user': 'barney', 'age': 36 }
  8866. */
  8867. var defaults = createDefaults(assign, assignDefaults);
  8868. /**
  8869. * This method is like `_.defaults` except that it recursively assigns
  8870. * default properties.
  8871. *
  8872. * **Note:** This method mutates `object`.
  8873. *
  8874. * @static
  8875. * @memberOf _
  8876. * @category Object
  8877. * @param {Object} object The destination object.
  8878. * @param {...Object} [sources] The source objects.
  8879. * @returns {Object} Returns `object`.
  8880. * @example
  8881. *
  8882. * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
  8883. * // => { 'user': { 'name': 'barney', 'age': 36 } }
  8884. *
  8885. */
  8886. var defaultsDeep = createDefaults(merge, mergeDefaults);
  8887. /**
  8888. * This method is like `_.find` except that it returns the key of the first
  8889. * element `predicate` returns truthy for instead of the element itself.
  8890. *
  8891. * If a property name is provided for `predicate` the created `_.property`
  8892. * style callback returns the property value of the given element.
  8893. *
  8894. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8895. * style callback returns `true` for elements that have a matching property
  8896. * value, else `false`.
  8897. *
  8898. * If an object is provided for `predicate` the created `_.matches` style
  8899. * callback returns `true` for elements that have the properties of the given
  8900. * object, else `false`.
  8901. *
  8902. * @static
  8903. * @memberOf _
  8904. * @category Object
  8905. * @param {Object} object The object to search.
  8906. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  8907. * per iteration.
  8908. * @param {*} [thisArg] The `this` binding of `predicate`.
  8909. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
  8910. * @example
  8911. *
  8912. * var users = {
  8913. * 'barney': { 'age': 36, 'active': true },
  8914. * 'fred': { 'age': 40, 'active': false },
  8915. * 'pebbles': { 'age': 1, 'active': true }
  8916. * };
  8917. *
  8918. * _.findKey(users, function(chr) {
  8919. * return chr.age < 40;
  8920. * });
  8921. * // => 'barney' (iteration order is not guaranteed)
  8922. *
  8923. * // using the `_.matches` callback shorthand
  8924. * _.findKey(users, { 'age': 1, 'active': true });
  8925. * // => 'pebbles'
  8926. *
  8927. * // using the `_.matchesProperty` callback shorthand
  8928. * _.findKey(users, 'active', false);
  8929. * // => 'fred'
  8930. *
  8931. * // using the `_.property` callback shorthand
  8932. * _.findKey(users, 'active');
  8933. * // => 'barney'
  8934. */
  8935. var findKey = createFindKey(baseForOwn);
  8936. /**
  8937. * This method is like `_.findKey` except that it iterates over elements of
  8938. * a collection in the opposite order.
  8939. *
  8940. * If a property name is provided for `predicate` the created `_.property`
  8941. * style callback returns the property value of the given element.
  8942. *
  8943. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8944. * style callback returns `true` for elements that have a matching property
  8945. * value, else `false`.
  8946. *
  8947. * If an object is provided for `predicate` the created `_.matches` style
  8948. * callback returns `true` for elements that have the properties of the given
  8949. * object, else `false`.
  8950. *
  8951. * @static
  8952. * @memberOf _
  8953. * @category Object
  8954. * @param {Object} object The object to search.
  8955. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  8956. * per iteration.
  8957. * @param {*} [thisArg] The `this` binding of `predicate`.
  8958. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
  8959. * @example
  8960. *
  8961. * var users = {
  8962. * 'barney': { 'age': 36, 'active': true },
  8963. * 'fred': { 'age': 40, 'active': false },
  8964. * 'pebbles': { 'age': 1, 'active': true }
  8965. * };
  8966. *
  8967. * _.findLastKey(users, function(chr) {
  8968. * return chr.age < 40;
  8969. * });
  8970. * // => returns `pebbles` assuming `_.findKey` returns `barney`
  8971. *
  8972. * // using the `_.matches` callback shorthand
  8973. * _.findLastKey(users, { 'age': 36, 'active': true });
  8974. * // => 'barney'
  8975. *
  8976. * // using the `_.matchesProperty` callback shorthand
  8977. * _.findLastKey(users, 'active', false);
  8978. * // => 'fred'
  8979. *
  8980. * // using the `_.property` callback shorthand
  8981. * _.findLastKey(users, 'active');
  8982. * // => 'pebbles'
  8983. */
  8984. var findLastKey = createFindKey(baseForOwnRight);
  8985. /**
  8986. * Iterates over own and inherited enumerable properties of an object invoking
  8987. * `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
  8988. * with three arguments: (value, key, object). Iteratee functions may exit
  8989. * iteration early by explicitly returning `false`.
  8990. *
  8991. * @static
  8992. * @memberOf _
  8993. * @category Object
  8994. * @param {Object} object The object to iterate over.
  8995. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8996. * @param {*} [thisArg] The `this` binding of `iteratee`.
  8997. * @returns {Object} Returns `object`.
  8998. * @example
  8999. *
  9000. * function Foo() {
  9001. * this.a = 1;
  9002. * this.b = 2;
  9003. * }
  9004. *
  9005. * Foo.prototype.c = 3;
  9006. *
  9007. * _.forIn(new Foo, function(value, key) {
  9008. * console.log(key);
  9009. * });
  9010. * // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
  9011. */
  9012. var forIn = createForIn(baseFor);
  9013. /**
  9014. * This method is like `_.forIn` except that it iterates over properties of
  9015. * `object` in the opposite order.
  9016. *
  9017. * @static
  9018. * @memberOf _
  9019. * @category Object
  9020. * @param {Object} object The object to iterate over.
  9021. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9022. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9023. * @returns {Object} Returns `object`.
  9024. * @example
  9025. *
  9026. * function Foo() {
  9027. * this.a = 1;
  9028. * this.b = 2;
  9029. * }
  9030. *
  9031. * Foo.prototype.c = 3;
  9032. *
  9033. * _.forInRight(new Foo, function(value, key) {
  9034. * console.log(key);
  9035. * });
  9036. * // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
  9037. */
  9038. var forInRight = createForIn(baseForRight);
  9039. /**
  9040. * Iterates over own enumerable properties of an object invoking `iteratee`
  9041. * for each property. The `iteratee` is bound to `thisArg` and invoked with
  9042. * three arguments: (value, key, object). Iteratee functions may exit iteration
  9043. * early by explicitly returning `false`.
  9044. *
  9045. * @static
  9046. * @memberOf _
  9047. * @category Object
  9048. * @param {Object} object The object to iterate over.
  9049. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9050. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9051. * @returns {Object} Returns `object`.
  9052. * @example
  9053. *
  9054. * function Foo() {
  9055. * this.a = 1;
  9056. * this.b = 2;
  9057. * }
  9058. *
  9059. * Foo.prototype.c = 3;
  9060. *
  9061. * _.forOwn(new Foo, function(value, key) {
  9062. * console.log(key);
  9063. * });
  9064. * // => logs 'a' and 'b' (iteration order is not guaranteed)
  9065. */
  9066. var forOwn = createForOwn(baseForOwn);
  9067. /**
  9068. * This method is like `_.forOwn` except that it iterates over properties of
  9069. * `object` in the opposite order.
  9070. *
  9071. * @static
  9072. * @memberOf _
  9073. * @category Object
  9074. * @param {Object} object The object to iterate over.
  9075. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9076. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9077. * @returns {Object} Returns `object`.
  9078. * @example
  9079. *
  9080. * function Foo() {
  9081. * this.a = 1;
  9082. * this.b = 2;
  9083. * }
  9084. *
  9085. * Foo.prototype.c = 3;
  9086. *
  9087. * _.forOwnRight(new Foo, function(value, key) {
  9088. * console.log(key);
  9089. * });
  9090. * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
  9091. */
  9092. var forOwnRight = createForOwn(baseForOwnRight);
  9093. /**
  9094. * Creates an array of function property names from all enumerable properties,
  9095. * own and inherited, of `object`.
  9096. *
  9097. * @static
  9098. * @memberOf _
  9099. * @alias methods
  9100. * @category Object
  9101. * @param {Object} object The object to inspect.
  9102. * @returns {Array} Returns the new array of property names.
  9103. * @example
  9104. *
  9105. * _.functions(_);
  9106. * // => ['after', 'ary', 'assign', ...]
  9107. */
  9108. function functions(object) {
  9109. return baseFunctions(object, keysIn(object));
  9110. }
  9111. /**
  9112. * Gets the property value at `path` of `object`. If the resolved value is
  9113. * `undefined` the `defaultValue` is used in its place.
  9114. *
  9115. * @static
  9116. * @memberOf _
  9117. * @category Object
  9118. * @param {Object} object The object to query.
  9119. * @param {Array|string} path The path of the property to get.
  9120. * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
  9121. * @returns {*} Returns the resolved value.
  9122. * @example
  9123. *
  9124. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  9125. *
  9126. * _.get(object, 'a[0].b.c');
  9127. * // => 3
  9128. *
  9129. * _.get(object, ['a', '0', 'b', 'c']);
  9130. * // => 3
  9131. *
  9132. * _.get(object, 'a.b.c', 'default');
  9133. * // => 'default'
  9134. */
  9135. function get(object, path, defaultValue) {
  9136. var result = object == null ? undefined : baseGet(object, toPath(path), (path + ''));
  9137. return result === undefined ? defaultValue : result;
  9138. }
  9139. /**
  9140. * Checks if `path` is a direct property.
  9141. *
  9142. * @static
  9143. * @memberOf _
  9144. * @category Object
  9145. * @param {Object} object The object to query.
  9146. * @param {Array|string} path The path to check.
  9147. * @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
  9148. * @example
  9149. *
  9150. * var object = { 'a': { 'b': { 'c': 3 } } };
  9151. *
  9152. * _.has(object, 'a');
  9153. * // => true
  9154. *
  9155. * _.has(object, 'a.b.c');
  9156. * // => true
  9157. *
  9158. * _.has(object, ['a', 'b', 'c']);
  9159. * // => true
  9160. */
  9161. function has(object, path) {
  9162. if (object == null) {
  9163. return false;
  9164. }
  9165. var result = hasOwnProperty.call(object, path);
  9166. if (!result && !isKey(path)) {
  9167. path = toPath(path);
  9168. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  9169. if (object == null) {
  9170. return false;
  9171. }
  9172. path = last(path);
  9173. result = hasOwnProperty.call(object, path);
  9174. }
  9175. return result || (isLength(object.length) && isIndex(path, object.length) &&
  9176. (isArray(object) || isArguments(object) || isString(object)));
  9177. }
  9178. /**
  9179. * Creates an object composed of the inverted keys and values of `object`.
  9180. * If `object` contains duplicate values, subsequent values overwrite property
  9181. * assignments of previous values unless `multiValue` is `true`.
  9182. *
  9183. * @static
  9184. * @memberOf _
  9185. * @category Object
  9186. * @param {Object} object The object to invert.
  9187. * @param {boolean} [multiValue] Allow multiple values per key.
  9188. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  9189. * @returns {Object} Returns the new inverted object.
  9190. * @example
  9191. *
  9192. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  9193. *
  9194. * _.invert(object);
  9195. * // => { '1': 'c', '2': 'b' }
  9196. *
  9197. * // with `multiValue`
  9198. * _.invert(object, true);
  9199. * // => { '1': ['a', 'c'], '2': ['b'] }
  9200. */
  9201. function invert(object, multiValue, guard) {
  9202. if (guard && isIterateeCall(object, multiValue, guard)) {
  9203. multiValue = undefined;
  9204. }
  9205. var index = -1,
  9206. props = keys(object),
  9207. length = props.length,
  9208. result = {};
  9209. while (++index < length) {
  9210. var key = props[index],
  9211. value = object[key];
  9212. if (multiValue) {
  9213. if (hasOwnProperty.call(result, value)) {
  9214. result[value].push(key);
  9215. } else {
  9216. result[value] = [key];
  9217. }
  9218. }
  9219. else {
  9220. result[value] = key;
  9221. }
  9222. }
  9223. return result;
  9224. }
  9225. /**
  9226. * Creates an array of the own enumerable property names of `object`.
  9227. *
  9228. * **Note:** Non-object values are coerced to objects. See the
  9229. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  9230. * for more details.
  9231. *
  9232. * @static
  9233. * @memberOf _
  9234. * @category Object
  9235. * @param {Object} object The object to query.
  9236. * @returns {Array} Returns the array of property names.
  9237. * @example
  9238. *
  9239. * function Foo() {
  9240. * this.a = 1;
  9241. * this.b = 2;
  9242. * }
  9243. *
  9244. * Foo.prototype.c = 3;
  9245. *
  9246. * _.keys(new Foo);
  9247. * // => ['a', 'b'] (iteration order is not guaranteed)
  9248. *
  9249. * _.keys('hi');
  9250. * // => ['0', '1']
  9251. */
  9252. var keys = !nativeKeys ? shimKeys : function(object) {
  9253. var Ctor = object == null ? undefined : object.constructor;
  9254. if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
  9255. (typeof object == 'function' ? lodash.support.enumPrototypes : isArrayLike(object))) {
  9256. return shimKeys(object);
  9257. }
  9258. return isObject(object) ? nativeKeys(object) : [];
  9259. };
  9260. /**
  9261. * Creates an array of the own and inherited enumerable property names of `object`.
  9262. *
  9263. * **Note:** Non-object values are coerced to objects.
  9264. *
  9265. * @static
  9266. * @memberOf _
  9267. * @category Object
  9268. * @param {Object} object The object to query.
  9269. * @returns {Array} Returns the array of property names.
  9270. * @example
  9271. *
  9272. * function Foo() {
  9273. * this.a = 1;
  9274. * this.b = 2;
  9275. * }
  9276. *
  9277. * Foo.prototype.c = 3;
  9278. *
  9279. * _.keysIn(new Foo);
  9280. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  9281. */
  9282. function keysIn(object) {
  9283. if (object == null) {
  9284. return [];
  9285. }
  9286. if (!isObject(object)) {
  9287. object = Object(object);
  9288. }
  9289. var length = object.length,
  9290. support = lodash.support;
  9291. length = (length && isLength(length) &&
  9292. (isArray(object) || isArguments(object) || isString(object)) && length) || 0;
  9293. var Ctor = object.constructor,
  9294. index = -1,
  9295. proto = (isFunction(Ctor) && Ctor.prototype) || objectProto,
  9296. isProto = proto === object,
  9297. result = Array(length),
  9298. skipIndexes = length > 0,
  9299. skipErrorProps = support.enumErrorProps && (object === errorProto || object instanceof Error),
  9300. skipProto = support.enumPrototypes && isFunction(object);
  9301. while (++index < length) {
  9302. result[index] = (index + '');
  9303. }
  9304. // lodash skips the `constructor` property when it infers it's iterating
  9305. // over a `prototype` object because IE < 9 can't set the `[[Enumerable]]`
  9306. // attribute of an existing property and the `constructor` property of a
  9307. // prototype defaults to non-enumerable.
  9308. for (var key in object) {
  9309. if (!(skipProto && key == 'prototype') &&
  9310. !(skipErrorProps && (key == 'message' || key == 'name')) &&
  9311. !(skipIndexes && isIndex(key, length)) &&
  9312. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  9313. result.push(key);
  9314. }
  9315. }
  9316. if (support.nonEnumShadows && object !== objectProto) {
  9317. var tag = object === stringProto ? stringTag : (object === errorProto ? errorTag : objToString.call(object)),
  9318. nonEnums = nonEnumProps[tag] || nonEnumProps[objectTag];
  9319. if (tag == objectTag) {
  9320. proto = objectProto;
  9321. }
  9322. length = shadowProps.length;
  9323. while (length--) {
  9324. key = shadowProps[length];
  9325. var nonEnum = nonEnums[key];
  9326. if (!(isProto && nonEnum) &&
  9327. (nonEnum ? hasOwnProperty.call(object, key) : object[key] !== proto[key])) {
  9328. result.push(key);
  9329. }
  9330. }
  9331. }
  9332. return result;
  9333. }
  9334. /**
  9335. * The opposite of `_.mapValues`; this method creates an object with the
  9336. * same values as `object` and keys generated by running each own enumerable
  9337. * property of `object` through `iteratee`.
  9338. *
  9339. * @static
  9340. * @memberOf _
  9341. * @category Object
  9342. * @param {Object} object The object to iterate over.
  9343. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  9344. * per iteration.
  9345. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9346. * @returns {Object} Returns the new mapped object.
  9347. * @example
  9348. *
  9349. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  9350. * return key + value;
  9351. * });
  9352. * // => { 'a1': 1, 'b2': 2 }
  9353. */
  9354. var mapKeys = createObjectMapper(true);
  9355. /**
  9356. * Creates an object with the same keys as `object` and values generated by
  9357. * running each own enumerable property of `object` through `iteratee`. The
  9358. * iteratee function is bound to `thisArg` and invoked with three arguments:
  9359. * (value, key, object).
  9360. *
  9361. * If a property name is provided for `iteratee` the created `_.property`
  9362. * style callback returns the property value of the given element.
  9363. *
  9364. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  9365. * style callback returns `true` for elements that have a matching property
  9366. * value, else `false`.
  9367. *
  9368. * If an object is provided for `iteratee` the created `_.matches` style
  9369. * callback returns `true` for elements that have the properties of the given
  9370. * object, else `false`.
  9371. *
  9372. * @static
  9373. * @memberOf _
  9374. * @category Object
  9375. * @param {Object} object The object to iterate over.
  9376. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  9377. * per iteration.
  9378. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9379. * @returns {Object} Returns the new mapped object.
  9380. * @example
  9381. *
  9382. * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
  9383. * return n * 3;
  9384. * });
  9385. * // => { 'a': 3, 'b': 6 }
  9386. *
  9387. * var users = {
  9388. * 'fred': { 'user': 'fred', 'age': 40 },
  9389. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  9390. * };
  9391. *
  9392. * // using the `_.property` callback shorthand
  9393. * _.mapValues(users, 'age');
  9394. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  9395. */
  9396. var mapValues = createObjectMapper();
  9397. /**
  9398. * The opposite of `_.pick`; this method creates an object composed of the
  9399. * own and inherited enumerable properties of `object` that are not omitted.
  9400. *
  9401. * @static
  9402. * @memberOf _
  9403. * @category Object
  9404. * @param {Object} object The source object.
  9405. * @param {Function|...(string|string[])} [predicate] The function invoked per
  9406. * iteration or property names to omit, specified as individual property
  9407. * names or arrays of property names.
  9408. * @param {*} [thisArg] The `this` binding of `predicate`.
  9409. * @returns {Object} Returns the new object.
  9410. * @example
  9411. *
  9412. * var object = { 'user': 'fred', 'age': 40 };
  9413. *
  9414. * _.omit(object, 'age');
  9415. * // => { 'user': 'fred' }
  9416. *
  9417. * _.omit(object, _.isNumber);
  9418. * // => { 'user': 'fred' }
  9419. */
  9420. var omit = restParam(function(object, props) {
  9421. if (object == null) {
  9422. return {};
  9423. }
  9424. if (typeof props[0] != 'function') {
  9425. var props = arrayMap(baseFlatten(props), String);
  9426. return pickByArray(object, baseDifference(keysIn(object), props));
  9427. }
  9428. var predicate = bindCallback(props[0], props[1], 3);
  9429. return pickByCallback(object, function(value, key, object) {
  9430. return !predicate(value, key, object);
  9431. });
  9432. });
  9433. /**
  9434. * Creates a two dimensional array of the key-value pairs for `object`,
  9435. * e.g. `[[key1, value1], [key2, value2]]`.
  9436. *
  9437. * @static
  9438. * @memberOf _
  9439. * @category Object
  9440. * @param {Object} object The object to query.
  9441. * @returns {Array} Returns the new array of key-value pairs.
  9442. * @example
  9443. *
  9444. * _.pairs({ 'barney': 36, 'fred': 40 });
  9445. * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
  9446. */
  9447. function pairs(object) {
  9448. object = toObject(object);
  9449. var index = -1,
  9450. props = keys(object),
  9451. length = props.length,
  9452. result = Array(length);
  9453. while (++index < length) {
  9454. var key = props[index];
  9455. result[index] = [key, object[key]];
  9456. }
  9457. return result;
  9458. }
  9459. /**
  9460. * Creates an object composed of the picked `object` properties. Property
  9461. * names may be specified as individual arguments or as arrays of property
  9462. * names. If `predicate` is provided it's invoked for each property of `object`
  9463. * picking the properties `predicate` returns truthy for. The predicate is
  9464. * bound to `thisArg` and invoked with three arguments: (value, key, object).
  9465. *
  9466. * @static
  9467. * @memberOf _
  9468. * @category Object
  9469. * @param {Object} object The source object.
  9470. * @param {Function|...(string|string[])} [predicate] The function invoked per
  9471. * iteration or property names to pick, specified as individual property
  9472. * names or arrays of property names.
  9473. * @param {*} [thisArg] The `this` binding of `predicate`.
  9474. * @returns {Object} Returns the new object.
  9475. * @example
  9476. *
  9477. * var object = { 'user': 'fred', 'age': 40 };
  9478. *
  9479. * _.pick(object, 'user');
  9480. * // => { 'user': 'fred' }
  9481. *
  9482. * _.pick(object, _.isString);
  9483. * // => { 'user': 'fred' }
  9484. */
  9485. var pick = restParam(function(object, props) {
  9486. if (object == null) {
  9487. return {};
  9488. }
  9489. return typeof props[0] == 'function'
  9490. ? pickByCallback(object, bindCallback(props[0], props[1], 3))
  9491. : pickByArray(object, baseFlatten(props));
  9492. });
  9493. /**
  9494. * This method is like `_.get` except that if the resolved value is a function
  9495. * it's invoked with the `this` binding of its parent object and its result
  9496. * is returned.
  9497. *
  9498. * @static
  9499. * @memberOf _
  9500. * @category Object
  9501. * @param {Object} object The object to query.
  9502. * @param {Array|string} path The path of the property to resolve.
  9503. * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
  9504. * @returns {*} Returns the resolved value.
  9505. * @example
  9506. *
  9507. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  9508. *
  9509. * _.result(object, 'a[0].b.c1');
  9510. * // => 3
  9511. *
  9512. * _.result(object, 'a[0].b.c2');
  9513. * // => 4
  9514. *
  9515. * _.result(object, 'a.b.c', 'default');
  9516. * // => 'default'
  9517. *
  9518. * _.result(object, 'a.b.c', _.constant('default'));
  9519. * // => 'default'
  9520. */
  9521. function result(object, path, defaultValue) {
  9522. var result = object == null ? undefined : toObject(object)[path];
  9523. if (result === undefined) {
  9524. if (object != null && !isKey(path, object)) {
  9525. path = toPath(path);
  9526. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  9527. result = object == null ? undefined : toObject(object)[last(path)];
  9528. }
  9529. result = result === undefined ? defaultValue : result;
  9530. }
  9531. return isFunction(result) ? result.call(object) : result;
  9532. }
  9533. /**
  9534. * Sets the property value of `path` on `object`. If a portion of `path`
  9535. * does not exist it's created.
  9536. *
  9537. * @static
  9538. * @memberOf _
  9539. * @category Object
  9540. * @param {Object} object The object to augment.
  9541. * @param {Array|string} path The path of the property to set.
  9542. * @param {*} value The value to set.
  9543. * @returns {Object} Returns `object`.
  9544. * @example
  9545. *
  9546. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  9547. *
  9548. * _.set(object, 'a[0].b.c', 4);
  9549. * console.log(object.a[0].b.c);
  9550. * // => 4
  9551. *
  9552. * _.set(object, 'x[0].y.z', 5);
  9553. * console.log(object.x[0].y.z);
  9554. * // => 5
  9555. */
  9556. function set(object, path, value) {
  9557. if (object == null) {
  9558. return object;
  9559. }
  9560. var pathKey = (path + '');
  9561. path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path);
  9562. var index = -1,
  9563. length = path.length,
  9564. lastIndex = length - 1,
  9565. nested = object;
  9566. while (nested != null && ++index < length) {
  9567. var key = path[index];
  9568. if (isObject(nested)) {
  9569. if (index == lastIndex) {
  9570. nested[key] = value;
  9571. } else if (nested[key] == null) {
  9572. nested[key] = isIndex(path[index + 1]) ? [] : {};
  9573. }
  9574. }
  9575. nested = nested[key];
  9576. }
  9577. return object;
  9578. }
  9579. /**
  9580. * An alternative to `_.reduce`; this method transforms `object` to a new
  9581. * `accumulator` object which is the result of running each of its own enumerable
  9582. * properties through `iteratee`, with each invocation potentially mutating
  9583. * the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
  9584. * with four arguments: (accumulator, value, key, object). Iteratee functions
  9585. * may exit iteration early by explicitly returning `false`.
  9586. *
  9587. * @static
  9588. * @memberOf _
  9589. * @category Object
  9590. * @param {Array|Object} object The object to iterate over.
  9591. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9592. * @param {*} [accumulator] The custom accumulator value.
  9593. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9594. * @returns {*} Returns the accumulated value.
  9595. * @example
  9596. *
  9597. * _.transform([2, 3, 4], function(result, n) {
  9598. * result.push(n *= n);
  9599. * return n % 2 == 0;
  9600. * });
  9601. * // => [4, 9]
  9602. *
  9603. * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
  9604. * result[key] = n * 3;
  9605. * });
  9606. * // => { 'a': 3, 'b': 6 }
  9607. */
  9608. function transform(object, iteratee, accumulator, thisArg) {
  9609. var isArr = isArray(object) || isTypedArray(object);
  9610. iteratee = getCallback(iteratee, thisArg, 4);
  9611. if (accumulator == null) {
  9612. if (isArr || isObject(object)) {
  9613. var Ctor = object.constructor;
  9614. if (isArr) {
  9615. accumulator = isArray(object) ? new Ctor : [];
  9616. } else {
  9617. accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
  9618. }
  9619. } else {
  9620. accumulator = {};
  9621. }
  9622. }
  9623. (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
  9624. return iteratee(accumulator, value, index, object);
  9625. });
  9626. return accumulator;
  9627. }
  9628. /**
  9629. * Creates an array of the own enumerable property values of `object`.
  9630. *
  9631. * **Note:** Non-object values are coerced to objects.
  9632. *
  9633. * @static
  9634. * @memberOf _
  9635. * @category Object
  9636. * @param {Object} object The object to query.
  9637. * @returns {Array} Returns the array of property values.
  9638. * @example
  9639. *
  9640. * function Foo() {
  9641. * this.a = 1;
  9642. * this.b = 2;
  9643. * }
  9644. *
  9645. * Foo.prototype.c = 3;
  9646. *
  9647. * _.values(new Foo);
  9648. * // => [1, 2] (iteration order is not guaranteed)
  9649. *
  9650. * _.values('hi');
  9651. * // => ['h', 'i']
  9652. */
  9653. function values(object) {
  9654. return baseValues(object, keys(object));
  9655. }
  9656. /**
  9657. * Creates an array of the own and inherited enumerable property values
  9658. * of `object`.
  9659. *
  9660. * **Note:** Non-object values are coerced to objects.
  9661. *
  9662. * @static
  9663. * @memberOf _
  9664. * @category Object
  9665. * @param {Object} object The object to query.
  9666. * @returns {Array} Returns the array of property values.
  9667. * @example
  9668. *
  9669. * function Foo() {
  9670. * this.a = 1;
  9671. * this.b = 2;
  9672. * }
  9673. *
  9674. * Foo.prototype.c = 3;
  9675. *
  9676. * _.valuesIn(new Foo);
  9677. * // => [1, 2, 3] (iteration order is not guaranteed)
  9678. */
  9679. function valuesIn(object) {
  9680. return baseValues(object, keysIn(object));
  9681. }
  9682. /*------------------------------------------------------------------------*/
  9683. /**
  9684. * Checks if `n` is between `start` and up to but not including, `end`. If
  9685. * `end` is not specified it's set to `start` with `start` then set to `0`.
  9686. *
  9687. * @static
  9688. * @memberOf _
  9689. * @category Number
  9690. * @param {number} n The number to check.
  9691. * @param {number} [start=0] The start of the range.
  9692. * @param {number} end The end of the range.
  9693. * @returns {boolean} Returns `true` if `n` is in the range, else `false`.
  9694. * @example
  9695. *
  9696. * _.inRange(3, 2, 4);
  9697. * // => true
  9698. *
  9699. * _.inRange(4, 8);
  9700. * // => true
  9701. *
  9702. * _.inRange(4, 2);
  9703. * // => false
  9704. *
  9705. * _.inRange(2, 2);
  9706. * // => false
  9707. *
  9708. * _.inRange(1.2, 2);
  9709. * // => true
  9710. *
  9711. * _.inRange(5.2, 4);
  9712. * // => false
  9713. */
  9714. function inRange(value, start, end) {
  9715. start = +start || 0;
  9716. if (end === undefined) {
  9717. end = start;
  9718. start = 0;
  9719. } else {
  9720. end = +end || 0;
  9721. }
  9722. return value >= nativeMin(start, end) && value < nativeMax(start, end);
  9723. }
  9724. /**
  9725. * Produces a random number between `min` and `max` (inclusive). If only one
  9726. * argument is provided a number between `0` and the given number is returned.
  9727. * If `floating` is `true`, or either `min` or `max` are floats, a floating-point
  9728. * number is returned instead of an integer.
  9729. *
  9730. * @static
  9731. * @memberOf _
  9732. * @category Number
  9733. * @param {number} [min=0] The minimum possible value.
  9734. * @param {number} [max=1] The maximum possible value.
  9735. * @param {boolean} [floating] Specify returning a floating-point number.
  9736. * @returns {number} Returns the random number.
  9737. * @example
  9738. *
  9739. * _.random(0, 5);
  9740. * // => an integer between 0 and 5
  9741. *
  9742. * _.random(5);
  9743. * // => also an integer between 0 and 5
  9744. *
  9745. * _.random(5, true);
  9746. * // => a floating-point number between 0 and 5
  9747. *
  9748. * _.random(1.2, 5.2);
  9749. * // => a floating-point number between 1.2 and 5.2
  9750. */
  9751. function random(min, max, floating) {
  9752. if (floating && isIterateeCall(min, max, floating)) {
  9753. max = floating = undefined;
  9754. }
  9755. var noMin = min == null,
  9756. noMax = max == null;
  9757. if (floating == null) {
  9758. if (noMax && typeof min == 'boolean') {
  9759. floating = min;
  9760. min = 1;
  9761. }
  9762. else if (typeof max == 'boolean') {
  9763. floating = max;
  9764. noMax = true;
  9765. }
  9766. }
  9767. if (noMin && noMax) {
  9768. max = 1;
  9769. noMax = false;
  9770. }
  9771. min = +min || 0;
  9772. if (noMax) {
  9773. max = min;
  9774. min = 0;
  9775. } else {
  9776. max = +max || 0;
  9777. }
  9778. if (floating || min % 1 || max % 1) {
  9779. var rand = nativeRandom();
  9780. return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
  9781. }
  9782. return baseRandom(min, max);
  9783. }
  9784. /*------------------------------------------------------------------------*/
  9785. /**
  9786. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  9787. *
  9788. * @static
  9789. * @memberOf _
  9790. * @category String
  9791. * @param {string} [string=''] The string to convert.
  9792. * @returns {string} Returns the camel cased string.
  9793. * @example
  9794. *
  9795. * _.camelCase('Foo Bar');
  9796. * // => 'fooBar'
  9797. *
  9798. * _.camelCase('--foo-bar');
  9799. * // => 'fooBar'
  9800. *
  9801. * _.camelCase('__foo_bar__');
  9802. * // => 'fooBar'
  9803. */
  9804. var camelCase = createCompounder(function(result, word, index) {
  9805. word = word.toLowerCase();
  9806. return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
  9807. });
  9808. /**
  9809. * Capitalizes the first character of `string`.
  9810. *
  9811. * @static
  9812. * @memberOf _
  9813. * @category String
  9814. * @param {string} [string=''] The string to capitalize.
  9815. * @returns {string} Returns the capitalized string.
  9816. * @example
  9817. *
  9818. * _.capitalize('fred');
  9819. * // => 'Fred'
  9820. */
  9821. function capitalize(string) {
  9822. string = baseToString(string);
  9823. return string && (string.charAt(0).toUpperCase() + string.slice(1));
  9824. }
  9825. /**
  9826. * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  9827. * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  9828. *
  9829. * @static
  9830. * @memberOf _
  9831. * @category String
  9832. * @param {string} [string=''] The string to deburr.
  9833. * @returns {string} Returns the deburred string.
  9834. * @example
  9835. *
  9836. * _.deburr('déjà vu');
  9837. * // => 'deja vu'
  9838. */
  9839. function deburr(string) {
  9840. string = baseToString(string);
  9841. return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
  9842. }
  9843. /**
  9844. * Checks if `string` ends with the given target string.
  9845. *
  9846. * @static
  9847. * @memberOf _
  9848. * @category String
  9849. * @param {string} [string=''] The string to search.
  9850. * @param {string} [target] The string to search for.
  9851. * @param {number} [position=string.length] The position to search from.
  9852. * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
  9853. * @example
  9854. *
  9855. * _.endsWith('abc', 'c');
  9856. * // => true
  9857. *
  9858. * _.endsWith('abc', 'b');
  9859. * // => false
  9860. *
  9861. * _.endsWith('abc', 'b', 2);
  9862. * // => true
  9863. */
  9864. function endsWith(string, target, position) {
  9865. string = baseToString(string);
  9866. target = (target + '');
  9867. var length = string.length;
  9868. position = position === undefined
  9869. ? length
  9870. : nativeMin(position < 0 ? 0 : (+position || 0), length);
  9871. position -= target.length;
  9872. return position >= 0 && string.indexOf(target, position) == position;
  9873. }
  9874. /**
  9875. * Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
  9876. * their corresponding HTML entities.
  9877. *
  9878. * **Note:** No other characters are escaped. To escape additional characters
  9879. * use a third-party library like [_he_](https://mths.be/he).
  9880. *
  9881. * Though the ">" character is escaped for symmetry, characters like
  9882. * ">" and "/" don't need escaping in HTML and have no special meaning
  9883. * unless they're part of a tag or unquoted attribute value.
  9884. * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  9885. * (under "semi-related fun fact") for more details.
  9886. *
  9887. * Backticks are escaped because in Internet Explorer < 9, they can break out
  9888. * of attribute values or HTML comments. See [#59](https://html5sec.org/#59),
  9889. * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
  9890. * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
  9891. * for more details.
  9892. *
  9893. * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
  9894. * to reduce XSS vectors.
  9895. *
  9896. * @static
  9897. * @memberOf _
  9898. * @category String
  9899. * @param {string} [string=''] The string to escape.
  9900. * @returns {string} Returns the escaped string.
  9901. * @example
  9902. *
  9903. * _.escape('fred, barney, & pebbles');
  9904. * // => 'fred, barney, &amp; pebbles'
  9905. */
  9906. function escape(string) {
  9907. // Reset `lastIndex` because in IE < 9 `String#replace` does not.
  9908. string = baseToString(string);
  9909. return (string && reHasUnescapedHtml.test(string))
  9910. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  9911. : string;
  9912. }
  9913. /**
  9914. * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
  9915. * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
  9916. *
  9917. * @static
  9918. * @memberOf _
  9919. * @category String
  9920. * @param {string} [string=''] The string to escape.
  9921. * @returns {string} Returns the escaped string.
  9922. * @example
  9923. *
  9924. * _.escapeRegExp('[lodash](https://lodash.com/)');
  9925. * // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
  9926. */
  9927. function escapeRegExp(string) {
  9928. string = baseToString(string);
  9929. return (string && reHasRegExpChars.test(string))
  9930. ? string.replace(reRegExpChars, escapeRegExpChar)
  9931. : (string || '(?:)');
  9932. }
  9933. /**
  9934. * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  9935. *
  9936. * @static
  9937. * @memberOf _
  9938. * @category String
  9939. * @param {string} [string=''] The string to convert.
  9940. * @returns {string} Returns the kebab cased string.
  9941. * @example
  9942. *
  9943. * _.kebabCase('Foo Bar');
  9944. * // => 'foo-bar'
  9945. *
  9946. * _.kebabCase('fooBar');
  9947. * // => 'foo-bar'
  9948. *
  9949. * _.kebabCase('__foo_bar__');
  9950. * // => 'foo-bar'
  9951. */
  9952. var kebabCase = createCompounder(function(result, word, index) {
  9953. return result + (index ? '-' : '') + word.toLowerCase();
  9954. });
  9955. /**
  9956. * Pads `string` on the left and right sides if it's shorter than `length`.
  9957. * Padding characters are truncated if they can't be evenly divided by `length`.
  9958. *
  9959. * @static
  9960. * @memberOf _
  9961. * @category String
  9962. * @param {string} [string=''] The string to pad.
  9963. * @param {number} [length=0] The padding length.
  9964. * @param {string} [chars=' '] The string used as padding.
  9965. * @returns {string} Returns the padded string.
  9966. * @example
  9967. *
  9968. * _.pad('abc', 8);
  9969. * // => ' abc '
  9970. *
  9971. * _.pad('abc', 8, '_-');
  9972. * // => '_-abc_-_'
  9973. *
  9974. * _.pad('abc', 3);
  9975. * // => 'abc'
  9976. */
  9977. function pad(string, length, chars) {
  9978. string = baseToString(string);
  9979. length = +length;
  9980. var strLength = string.length;
  9981. if (strLength >= length || !nativeIsFinite(length)) {
  9982. return string;
  9983. }
  9984. var mid = (length - strLength) / 2,
  9985. leftLength = nativeFloor(mid),
  9986. rightLength = nativeCeil(mid);
  9987. chars = createPadding('', rightLength, chars);
  9988. return chars.slice(0, leftLength) + string + chars;
  9989. }
  9990. /**
  9991. * Pads `string` on the left side if it's shorter than `length`. Padding
  9992. * characters are truncated if they exceed `length`.
  9993. *
  9994. * @static
  9995. * @memberOf _
  9996. * @category String
  9997. * @param {string} [string=''] The string to pad.
  9998. * @param {number} [length=0] The padding length.
  9999. * @param {string} [chars=' '] The string used as padding.
  10000. * @returns {string} Returns the padded string.
  10001. * @example
  10002. *
  10003. * _.padLeft('abc', 6);
  10004. * // => ' abc'
  10005. *
  10006. * _.padLeft('abc', 6, '_-');
  10007. * // => '_-_abc'
  10008. *
  10009. * _.padLeft('abc', 3);
  10010. * // => 'abc'
  10011. */
  10012. var padLeft = createPadDir();
  10013. /**
  10014. * Pads `string` on the right side if it's shorter than `length`. Padding
  10015. * characters are truncated if they exceed `length`.
  10016. *
  10017. * @static
  10018. * @memberOf _
  10019. * @category String
  10020. * @param {string} [string=''] The string to pad.
  10021. * @param {number} [length=0] The padding length.
  10022. * @param {string} [chars=' '] The string used as padding.
  10023. * @returns {string} Returns the padded string.
  10024. * @example
  10025. *
  10026. * _.padRight('abc', 6);
  10027. * // => 'abc '
  10028. *
  10029. * _.padRight('abc', 6, '_-');
  10030. * // => 'abc_-_'
  10031. *
  10032. * _.padRight('abc', 3);
  10033. * // => 'abc'
  10034. */
  10035. var padRight = createPadDir(true);
  10036. /**
  10037. * Converts `string` to an integer of the specified radix. If `radix` is
  10038. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
  10039. * in which case a `radix` of `16` is used.
  10040. *
  10041. * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
  10042. * of `parseInt`.
  10043. *
  10044. * @static
  10045. * @memberOf _
  10046. * @category String
  10047. * @param {string} string The string to convert.
  10048. * @param {number} [radix] The radix to interpret `value` by.
  10049. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10050. * @returns {number} Returns the converted integer.
  10051. * @example
  10052. *
  10053. * _.parseInt('08');
  10054. * // => 8
  10055. *
  10056. * _.map(['6', '08', '10'], _.parseInt);
  10057. * // => [6, 8, 10]
  10058. */
  10059. function parseInt(string, radix, guard) {
  10060. // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
  10061. // Chrome fails to trim leading <BOM> whitespace characters.
  10062. // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
  10063. if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
  10064. radix = 0;
  10065. } else if (radix) {
  10066. radix = +radix;
  10067. }
  10068. string = trim(string);
  10069. return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
  10070. }
  10071. /**
  10072. * Repeats the given string `n` times.
  10073. *
  10074. * @static
  10075. * @memberOf _
  10076. * @category String
  10077. * @param {string} [string=''] The string to repeat.
  10078. * @param {number} [n=0] The number of times to repeat the string.
  10079. * @returns {string} Returns the repeated string.
  10080. * @example
  10081. *
  10082. * _.repeat('*', 3);
  10083. * // => '***'
  10084. *
  10085. * _.repeat('abc', 2);
  10086. * // => 'abcabc'
  10087. *
  10088. * _.repeat('abc', 0);
  10089. * // => ''
  10090. */
  10091. function repeat(string, n) {
  10092. var result = '';
  10093. string = baseToString(string);
  10094. n = +n;
  10095. if (n < 1 || !string || !nativeIsFinite(n)) {
  10096. return result;
  10097. }
  10098. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  10099. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  10100. do {
  10101. if (n % 2) {
  10102. result += string;
  10103. }
  10104. n = nativeFloor(n / 2);
  10105. string += string;
  10106. } while (n);
  10107. return result;
  10108. }
  10109. /**
  10110. * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
  10111. *
  10112. * @static
  10113. * @memberOf _
  10114. * @category String
  10115. * @param {string} [string=''] The string to convert.
  10116. * @returns {string} Returns the snake cased string.
  10117. * @example
  10118. *
  10119. * _.snakeCase('Foo Bar');
  10120. * // => 'foo_bar'
  10121. *
  10122. * _.snakeCase('fooBar');
  10123. * // => 'foo_bar'
  10124. *
  10125. * _.snakeCase('--foo-bar');
  10126. * // => 'foo_bar'
  10127. */
  10128. var snakeCase = createCompounder(function(result, word, index) {
  10129. return result + (index ? '_' : '') + word.toLowerCase();
  10130. });
  10131. /**
  10132. * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  10133. *
  10134. * @static
  10135. * @memberOf _
  10136. * @category String
  10137. * @param {string} [string=''] The string to convert.
  10138. * @returns {string} Returns the start cased string.
  10139. * @example
  10140. *
  10141. * _.startCase('--foo-bar');
  10142. * // => 'Foo Bar'
  10143. *
  10144. * _.startCase('fooBar');
  10145. * // => 'Foo Bar'
  10146. *
  10147. * _.startCase('__foo_bar__');
  10148. * // => 'Foo Bar'
  10149. */
  10150. var startCase = createCompounder(function(result, word, index) {
  10151. return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
  10152. });
  10153. /**
  10154. * Checks if `string` starts with the given target string.
  10155. *
  10156. * @static
  10157. * @memberOf _
  10158. * @category String
  10159. * @param {string} [string=''] The string to search.
  10160. * @param {string} [target] The string to search for.
  10161. * @param {number} [position=0] The position to search from.
  10162. * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
  10163. * @example
  10164. *
  10165. * _.startsWith('abc', 'a');
  10166. * // => true
  10167. *
  10168. * _.startsWith('abc', 'b');
  10169. * // => false
  10170. *
  10171. * _.startsWith('abc', 'b', 1);
  10172. * // => true
  10173. */
  10174. function startsWith(string, target, position) {
  10175. string = baseToString(string);
  10176. position = position == null
  10177. ? 0
  10178. : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
  10179. return string.lastIndexOf(target, position) == position;
  10180. }
  10181. /**
  10182. * Creates a compiled template function that can interpolate data properties
  10183. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  10184. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  10185. * properties may be accessed as free variables in the template. If a setting
  10186. * object is provided it takes precedence over `_.templateSettings` values.
  10187. *
  10188. * **Note:** In the development build `_.template` utilizes
  10189. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  10190. * for easier debugging.
  10191. *
  10192. * For more information on precompiling templates see
  10193. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  10194. *
  10195. * For more information on Chrome extension sandboxes see
  10196. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  10197. *
  10198. * @static
  10199. * @memberOf _
  10200. * @category String
  10201. * @param {string} [string=''] The template string.
  10202. * @param {Object} [options] The options object.
  10203. * @param {RegExp} [options.escape] The HTML "escape" delimiter.
  10204. * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
  10205. * @param {Object} [options.imports] An object to import into the template as free variables.
  10206. * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
  10207. * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
  10208. * @param {string} [options.variable] The data object variable name.
  10209. * @param- {Object} [otherOptions] Enables the legacy `options` param signature.
  10210. * @returns {Function} Returns the compiled template function.
  10211. * @example
  10212. *
  10213. * // using the "interpolate" delimiter to create a compiled template
  10214. * var compiled = _.template('hello <%= user %>!');
  10215. * compiled({ 'user': 'fred' });
  10216. * // => 'hello fred!'
  10217. *
  10218. * // using the HTML "escape" delimiter to escape data property values
  10219. * var compiled = _.template('<b><%- value %></b>');
  10220. * compiled({ 'value': '<script>' });
  10221. * // => '<b>&lt;script&gt;</b>'
  10222. *
  10223. * // using the "evaluate" delimiter to execute JavaScript and generate HTML
  10224. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  10225. * compiled({ 'users': ['fred', 'barney'] });
  10226. * // => '<li>fred</li><li>barney</li>'
  10227. *
  10228. * // using the internal `print` function in "evaluate" delimiters
  10229. * var compiled = _.template('<% print("hello " + user); %>!');
  10230. * compiled({ 'user': 'barney' });
  10231. * // => 'hello barney!'
  10232. *
  10233. * // using the ES delimiter as an alternative to the default "interpolate" delimiter
  10234. * var compiled = _.template('hello ${ user }!');
  10235. * compiled({ 'user': 'pebbles' });
  10236. * // => 'hello pebbles!'
  10237. *
  10238. * // using custom template delimiters
  10239. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  10240. * var compiled = _.template('hello {{ user }}!');
  10241. * compiled({ 'user': 'mustache' });
  10242. * // => 'hello mustache!'
  10243. *
  10244. * // using backslashes to treat delimiters as plain text
  10245. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  10246. * compiled({ 'value': 'ignored' });
  10247. * // => '<%- value %>'
  10248. *
  10249. * // using the `imports` option to import `jQuery` as `jq`
  10250. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  10251. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  10252. * compiled({ 'users': ['fred', 'barney'] });
  10253. * // => '<li>fred</li><li>barney</li>'
  10254. *
  10255. * // using the `sourceURL` option to specify a custom sourceURL for the template
  10256. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  10257. * compiled(data);
  10258. * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
  10259. *
  10260. * // using the `variable` option to ensure a with-statement isn't used in the compiled template
  10261. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  10262. * compiled.source;
  10263. * // => function(data) {
  10264. * // var __t, __p = '';
  10265. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  10266. * // return __p;
  10267. * // }
  10268. *
  10269. * // using the `source` property to inline compiled templates for meaningful
  10270. * // line numbers in error messages and a stack trace
  10271. * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
  10272. * var JST = {\
  10273. * "main": ' + _.template(mainText).source + '\
  10274. * };\
  10275. * ');
  10276. */
  10277. function template(string, options, otherOptions) {
  10278. // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
  10279. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  10280. var settings = lodash.templateSettings;
  10281. if (otherOptions && isIterateeCall(string, options, otherOptions)) {
  10282. options = otherOptions = undefined;
  10283. }
  10284. string = baseToString(string);
  10285. options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
  10286. var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
  10287. importsKeys = keys(imports),
  10288. importsValues = baseValues(imports, importsKeys);
  10289. var isEscaping,
  10290. isEvaluating,
  10291. index = 0,
  10292. interpolate = options.interpolate || reNoMatch,
  10293. source = "__p += '";
  10294. // Compile the regexp to match each delimiter.
  10295. var reDelimiters = RegExp(
  10296. (options.escape || reNoMatch).source + '|' +
  10297. interpolate.source + '|' +
  10298. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  10299. (options.evaluate || reNoMatch).source + '|$'
  10300. , 'g');
  10301. // Use a sourceURL for easier debugging.
  10302. var sourceURL = '//# sourceURL=' +
  10303. ('sourceURL' in options
  10304. ? options.sourceURL
  10305. : ('lodash.templateSources[' + (++templateCounter) + ']')
  10306. ) + '\n';
  10307. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  10308. interpolateValue || (interpolateValue = esTemplateValue);
  10309. // Escape characters that can't be included in string literals.
  10310. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  10311. // Replace delimiters with snippets.
  10312. if (escapeValue) {
  10313. isEscaping = true;
  10314. source += "' +\n__e(" + escapeValue + ") +\n'";
  10315. }
  10316. if (evaluateValue) {
  10317. isEvaluating = true;
  10318. source += "';\n" + evaluateValue + ";\n__p += '";
  10319. }
  10320. if (interpolateValue) {
  10321. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  10322. }
  10323. index = offset + match.length;
  10324. // The JS engine embedded in Adobe products requires returning the `match`
  10325. // string in order to produce the correct `offset` value.
  10326. return match;
  10327. });
  10328. source += "';\n";
  10329. // If `variable` is not specified wrap a with-statement around the generated
  10330. // code to add the data object to the top of the scope chain.
  10331. var variable = options.variable;
  10332. if (!variable) {
  10333. source = 'with (obj) {\n' + source + '\n}\n';
  10334. }
  10335. // Cleanup code by stripping empty strings.
  10336. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  10337. .replace(reEmptyStringMiddle, '$1')
  10338. .replace(reEmptyStringTrailing, '$1;');
  10339. // Frame code as the function body.
  10340. source = 'function(' + (variable || 'obj') + ') {\n' +
  10341. (variable
  10342. ? ''
  10343. : 'obj || (obj = {});\n'
  10344. ) +
  10345. "var __t, __p = ''" +
  10346. (isEscaping
  10347. ? ', __e = _.escape'
  10348. : ''
  10349. ) +
  10350. (isEvaluating
  10351. ? ', __j = Array.prototype.join;\n' +
  10352. "function print() { __p += __j.call(arguments, '') }\n"
  10353. : ';\n'
  10354. ) +
  10355. source +
  10356. 'return __p\n}';
  10357. var result = attempt(function() {
  10358. return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
  10359. });
  10360. // Provide the compiled function's source by its `toString` method or
  10361. // the `source` property as a convenience for inlining compiled templates.
  10362. result.source = source;
  10363. if (isError(result)) {
  10364. throw result;
  10365. }
  10366. return result;
  10367. }
  10368. /**
  10369. * Removes leading and trailing whitespace or specified characters from `string`.
  10370. *
  10371. * @static
  10372. * @memberOf _
  10373. * @category String
  10374. * @param {string} [string=''] The string to trim.
  10375. * @param {string} [chars=whitespace] The characters to trim.
  10376. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10377. * @returns {string} Returns the trimmed string.
  10378. * @example
  10379. *
  10380. * _.trim(' abc ');
  10381. * // => 'abc'
  10382. *
  10383. * _.trim('-_-abc-_-', '_-');
  10384. * // => 'abc'
  10385. *
  10386. * _.map([' foo ', ' bar '], _.trim);
  10387. * // => ['foo', 'bar']
  10388. */
  10389. function trim(string, chars, guard) {
  10390. var value = string;
  10391. string = baseToString(string);
  10392. if (!string) {
  10393. return string;
  10394. }
  10395. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  10396. return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
  10397. }
  10398. chars = (chars + '');
  10399. return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
  10400. }
  10401. /**
  10402. * Removes leading whitespace or specified characters from `string`.
  10403. *
  10404. * @static
  10405. * @memberOf _
  10406. * @category String
  10407. * @param {string} [string=''] The string to trim.
  10408. * @param {string} [chars=whitespace] The characters to trim.
  10409. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10410. * @returns {string} Returns the trimmed string.
  10411. * @example
  10412. *
  10413. * _.trimLeft(' abc ');
  10414. * // => 'abc '
  10415. *
  10416. * _.trimLeft('-_-abc-_-', '_-');
  10417. * // => 'abc-_-'
  10418. */
  10419. function trimLeft(string, chars, guard) {
  10420. var value = string;
  10421. string = baseToString(string);
  10422. if (!string) {
  10423. return string;
  10424. }
  10425. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  10426. return string.slice(trimmedLeftIndex(string));
  10427. }
  10428. return string.slice(charsLeftIndex(string, (chars + '')));
  10429. }
  10430. /**
  10431. * Removes trailing whitespace or specified characters from `string`.
  10432. *
  10433. * @static
  10434. * @memberOf _
  10435. * @category String
  10436. * @param {string} [string=''] The string to trim.
  10437. * @param {string} [chars=whitespace] The characters to trim.
  10438. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10439. * @returns {string} Returns the trimmed string.
  10440. * @example
  10441. *
  10442. * _.trimRight(' abc ');
  10443. * // => ' abc'
  10444. *
  10445. * _.trimRight('-_-abc-_-', '_-');
  10446. * // => '-_-abc'
  10447. */
  10448. function trimRight(string, chars, guard) {
  10449. var value = string;
  10450. string = baseToString(string);
  10451. if (!string) {
  10452. return string;
  10453. }
  10454. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  10455. return string.slice(0, trimmedRightIndex(string) + 1);
  10456. }
  10457. return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
  10458. }
  10459. /**
  10460. * Truncates `string` if it's longer than the given maximum string length.
  10461. * The last characters of the truncated string are replaced with the omission
  10462. * string which defaults to "...".
  10463. *
  10464. * @static
  10465. * @memberOf _
  10466. * @category String
  10467. * @param {string} [string=''] The string to truncate.
  10468. * @param {Object|number} [options] The options object or maximum string length.
  10469. * @param {number} [options.length=30] The maximum string length.
  10470. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  10471. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  10472. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10473. * @returns {string} Returns the truncated string.
  10474. * @example
  10475. *
  10476. * _.trunc('hi-diddly-ho there, neighborino');
  10477. * // => 'hi-diddly-ho there, neighbo...'
  10478. *
  10479. * _.trunc('hi-diddly-ho there, neighborino', 24);
  10480. * // => 'hi-diddly-ho there, n...'
  10481. *
  10482. * _.trunc('hi-diddly-ho there, neighborino', {
  10483. * 'length': 24,
  10484. * 'separator': ' '
  10485. * });
  10486. * // => 'hi-diddly-ho there,...'
  10487. *
  10488. * _.trunc('hi-diddly-ho there, neighborino', {
  10489. * 'length': 24,
  10490. * 'separator': /,? +/
  10491. * });
  10492. * // => 'hi-diddly-ho there...'
  10493. *
  10494. * _.trunc('hi-diddly-ho there, neighborino', {
  10495. * 'omission': ' [...]'
  10496. * });
  10497. * // => 'hi-diddly-ho there, neig [...]'
  10498. */
  10499. function trunc(string, options, guard) {
  10500. if (guard && isIterateeCall(string, options, guard)) {
  10501. options = undefined;
  10502. }
  10503. var length = DEFAULT_TRUNC_LENGTH,
  10504. omission = DEFAULT_TRUNC_OMISSION;
  10505. if (options != null) {
  10506. if (isObject(options)) {
  10507. var separator = 'separator' in options ? options.separator : separator;
  10508. length = 'length' in options ? (+options.length || 0) : length;
  10509. omission = 'omission' in options ? baseToString(options.omission) : omission;
  10510. } else {
  10511. length = +options || 0;
  10512. }
  10513. }
  10514. string = baseToString(string);
  10515. if (length >= string.length) {
  10516. return string;
  10517. }
  10518. var end = length - omission.length;
  10519. if (end < 1) {
  10520. return omission;
  10521. }
  10522. var result = string.slice(0, end);
  10523. if (separator == null) {
  10524. return result + omission;
  10525. }
  10526. if (isRegExp(separator)) {
  10527. if (string.slice(end).search(separator)) {
  10528. var match,
  10529. newEnd,
  10530. substring = string.slice(0, end);
  10531. if (!separator.global) {
  10532. separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
  10533. }
  10534. separator.lastIndex = 0;
  10535. while ((match = separator.exec(substring))) {
  10536. newEnd = match.index;
  10537. }
  10538. result = result.slice(0, newEnd == null ? end : newEnd);
  10539. }
  10540. } else if (string.indexOf(separator, end) != end) {
  10541. var index = result.lastIndexOf(separator);
  10542. if (index > -1) {
  10543. result = result.slice(0, index);
  10544. }
  10545. }
  10546. return result + omission;
  10547. }
  10548. /**
  10549. * The inverse of `_.escape`; this method converts the HTML entities
  10550. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to their
  10551. * corresponding characters.
  10552. *
  10553. * **Note:** No other HTML entities are unescaped. To unescape additional HTML
  10554. * entities use a third-party library like [_he_](https://mths.be/he).
  10555. *
  10556. * @static
  10557. * @memberOf _
  10558. * @category String
  10559. * @param {string} [string=''] The string to unescape.
  10560. * @returns {string} Returns the unescaped string.
  10561. * @example
  10562. *
  10563. * _.unescape('fred, barney, &amp; pebbles');
  10564. * // => 'fred, barney, & pebbles'
  10565. */
  10566. function unescape(string) {
  10567. string = baseToString(string);
  10568. return (string && reHasEscapedHtml.test(string))
  10569. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  10570. : string;
  10571. }
  10572. /**
  10573. * Splits `string` into an array of its words.
  10574. *
  10575. * @static
  10576. * @memberOf _
  10577. * @category String
  10578. * @param {string} [string=''] The string to inspect.
  10579. * @param {RegExp|string} [pattern] The pattern to match words.
  10580. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10581. * @returns {Array} Returns the words of `string`.
  10582. * @example
  10583. *
  10584. * _.words('fred, barney, & pebbles');
  10585. * // => ['fred', 'barney', 'pebbles']
  10586. *
  10587. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  10588. * // => ['fred', 'barney', '&', 'pebbles']
  10589. */
  10590. function words(string, pattern, guard) {
  10591. if (guard && isIterateeCall(string, pattern, guard)) {
  10592. pattern = undefined;
  10593. }
  10594. string = baseToString(string);
  10595. return string.match(pattern || reWords) || [];
  10596. }
  10597. /*------------------------------------------------------------------------*/
  10598. /**
  10599. * Attempts to invoke `func`, returning either the result or the caught error
  10600. * object. Any additional arguments are provided to `func` when it's invoked.
  10601. *
  10602. * @static
  10603. * @memberOf _
  10604. * @category Utility
  10605. * @param {Function} func The function to attempt.
  10606. * @returns {*} Returns the `func` result or error object.
  10607. * @example
  10608. *
  10609. * // avoid throwing errors for invalid selectors
  10610. * var elements = _.attempt(function(selector) {
  10611. * return document.querySelectorAll(selector);
  10612. * }, '>_>');
  10613. *
  10614. * if (_.isError(elements)) {
  10615. * elements = [];
  10616. * }
  10617. */
  10618. var attempt = restParam(function(func, args) {
  10619. try {
  10620. return func.apply(undefined, args);
  10621. } catch(e) {
  10622. return isError(e) ? e : new Error(e);
  10623. }
  10624. });
  10625. /**
  10626. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  10627. * and arguments of the created function. If `func` is a property name the
  10628. * created callback returns the property value for a given element. If `func`
  10629. * is an object the created callback returns `true` for elements that contain
  10630. * the equivalent object properties, otherwise it returns `false`.
  10631. *
  10632. * @static
  10633. * @memberOf _
  10634. * @alias iteratee
  10635. * @category Utility
  10636. * @param {*} [func=_.identity] The value to convert to a callback.
  10637. * @param {*} [thisArg] The `this` binding of `func`.
  10638. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10639. * @returns {Function} Returns the callback.
  10640. * @example
  10641. *
  10642. * var users = [
  10643. * { 'user': 'barney', 'age': 36 },
  10644. * { 'user': 'fred', 'age': 40 }
  10645. * ];
  10646. *
  10647. * // wrap to create custom callback shorthands
  10648. * _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
  10649. * var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
  10650. * if (!match) {
  10651. * return callback(func, thisArg);
  10652. * }
  10653. * return function(object) {
  10654. * return match[2] == 'gt'
  10655. * ? object[match[1]] > match[3]
  10656. * : object[match[1]] < match[3];
  10657. * };
  10658. * });
  10659. *
  10660. * _.filter(users, 'age__gt36');
  10661. * // => [{ 'user': 'fred', 'age': 40 }]
  10662. */
  10663. function callback(func, thisArg, guard) {
  10664. if (guard && isIterateeCall(func, thisArg, guard)) {
  10665. thisArg = undefined;
  10666. }
  10667. return isObjectLike(func)
  10668. ? matches(func)
  10669. : baseCallback(func, thisArg);
  10670. }
  10671. /**
  10672. * Creates a function that returns `value`.
  10673. *
  10674. * @static
  10675. * @memberOf _
  10676. * @category Utility
  10677. * @param {*} value The value to return from the new function.
  10678. * @returns {Function} Returns the new function.
  10679. * @example
  10680. *
  10681. * var object = { 'user': 'fred' };
  10682. * var getter = _.constant(object);
  10683. *
  10684. * getter() === object;
  10685. * // => true
  10686. */
  10687. function constant(value) {
  10688. return function() {
  10689. return value;
  10690. };
  10691. }
  10692. /**
  10693. * This method returns the first argument provided to it.
  10694. *
  10695. * @static
  10696. * @memberOf _
  10697. * @category Utility
  10698. * @param {*} value Any value.
  10699. * @returns {*} Returns `value`.
  10700. * @example
  10701. *
  10702. * var object = { 'user': 'fred' };
  10703. *
  10704. * _.identity(object) === object;
  10705. * // => true
  10706. */
  10707. function identity(value) {
  10708. return value;
  10709. }
  10710. /**
  10711. * Creates a function that performs a deep comparison between a given object
  10712. * and `source`, returning `true` if the given object has equivalent property
  10713. * values, else `false`.
  10714. *
  10715. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  10716. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  10717. * their own, not inherited, enumerable properties. For comparing a single
  10718. * own or inherited property value see `_.matchesProperty`.
  10719. *
  10720. * @static
  10721. * @memberOf _
  10722. * @category Utility
  10723. * @param {Object} source The object of property values to match.
  10724. * @returns {Function} Returns the new function.
  10725. * @example
  10726. *
  10727. * var users = [
  10728. * { 'user': 'barney', 'age': 36, 'active': true },
  10729. * { 'user': 'fred', 'age': 40, 'active': false }
  10730. * ];
  10731. *
  10732. * _.filter(users, _.matches({ 'age': 40, 'active': false }));
  10733. * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
  10734. */
  10735. function matches(source) {
  10736. return baseMatches(baseClone(source, true));
  10737. }
  10738. /**
  10739. * Creates a function that compares the property value of `path` on a given
  10740. * object to `value`.
  10741. *
  10742. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  10743. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  10744. * their own, not inherited, enumerable properties.
  10745. *
  10746. * @static
  10747. * @memberOf _
  10748. * @category Utility
  10749. * @param {Array|string} path The path of the property to get.
  10750. * @param {*} srcValue The value to match.
  10751. * @returns {Function} Returns the new function.
  10752. * @example
  10753. *
  10754. * var users = [
  10755. * { 'user': 'barney' },
  10756. * { 'user': 'fred' }
  10757. * ];
  10758. *
  10759. * _.find(users, _.matchesProperty('user', 'fred'));
  10760. * // => { 'user': 'fred' }
  10761. */
  10762. function matchesProperty(path, srcValue) {
  10763. return baseMatchesProperty(path, baseClone(srcValue, true));
  10764. }
  10765. /**
  10766. * Creates a function that invokes the method at `path` on a given object.
  10767. * Any additional arguments are provided to the invoked method.
  10768. *
  10769. * @static
  10770. * @memberOf _
  10771. * @category Utility
  10772. * @param {Array|string} path The path of the method to invoke.
  10773. * @param {...*} [args] The arguments to invoke the method with.
  10774. * @returns {Function} Returns the new function.
  10775. * @example
  10776. *
  10777. * var objects = [
  10778. * { 'a': { 'b': { 'c': _.constant(2) } } },
  10779. * { 'a': { 'b': { 'c': _.constant(1) } } }
  10780. * ];
  10781. *
  10782. * _.map(objects, _.method('a.b.c'));
  10783. * // => [2, 1]
  10784. *
  10785. * _.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
  10786. * // => [1, 2]
  10787. */
  10788. var method = restParam(function(path, args) {
  10789. return function(object) {
  10790. return invokePath(object, path, args);
  10791. };
  10792. });
  10793. /**
  10794. * The opposite of `_.method`; this method creates a function that invokes
  10795. * the method at a given path on `object`. Any additional arguments are
  10796. * provided to the invoked method.
  10797. *
  10798. * @static
  10799. * @memberOf _
  10800. * @category Utility
  10801. * @param {Object} object The object to query.
  10802. * @param {...*} [args] The arguments to invoke the method with.
  10803. * @returns {Function} Returns the new function.
  10804. * @example
  10805. *
  10806. * var array = _.times(3, _.constant),
  10807. * object = { 'a': array, 'b': array, 'c': array };
  10808. *
  10809. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  10810. * // => [2, 0]
  10811. *
  10812. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  10813. * // => [2, 0]
  10814. */
  10815. var methodOf = restParam(function(object, args) {
  10816. return function(path) {
  10817. return invokePath(object, path, args);
  10818. };
  10819. });
  10820. /**
  10821. * Adds all own enumerable function properties of a source object to the
  10822. * destination object. If `object` is a function then methods are added to
  10823. * its prototype as well.
  10824. *
  10825. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  10826. * avoid conflicts caused by modifying the original.
  10827. *
  10828. * @static
  10829. * @memberOf _
  10830. * @category Utility
  10831. * @param {Function|Object} [object=lodash] The destination object.
  10832. * @param {Object} source The object of functions to add.
  10833. * @param {Object} [options] The options object.
  10834. * @param {boolean} [options.chain=true] Specify whether the functions added
  10835. * are chainable.
  10836. * @returns {Function|Object} Returns `object`.
  10837. * @example
  10838. *
  10839. * function vowels(string) {
  10840. * return _.filter(string, function(v) {
  10841. * return /[aeiou]/i.test(v);
  10842. * });
  10843. * }
  10844. *
  10845. * _.mixin({ 'vowels': vowels });
  10846. * _.vowels('fred');
  10847. * // => ['e']
  10848. *
  10849. * _('fred').vowels().value();
  10850. * // => ['e']
  10851. *
  10852. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  10853. * _('fred').vowels();
  10854. * // => ['e']
  10855. */
  10856. function mixin(object, source, options) {
  10857. if (options == null) {
  10858. var isObj = isObject(source),
  10859. props = isObj ? keys(source) : undefined,
  10860. methodNames = (props && props.length) ? baseFunctions(source, props) : undefined;
  10861. if (!(methodNames ? methodNames.length : isObj)) {
  10862. methodNames = false;
  10863. options = source;
  10864. source = object;
  10865. object = this;
  10866. }
  10867. }
  10868. if (!methodNames) {
  10869. methodNames = baseFunctions(source, keys(source));
  10870. }
  10871. var chain = true,
  10872. index = -1,
  10873. isFunc = isFunction(object),
  10874. length = methodNames.length;
  10875. if (options === false) {
  10876. chain = false;
  10877. } else if (isObject(options) && 'chain' in options) {
  10878. chain = options.chain;
  10879. }
  10880. while (++index < length) {
  10881. var methodName = methodNames[index],
  10882. func = source[methodName];
  10883. object[methodName] = func;
  10884. if (isFunc) {
  10885. object.prototype[methodName] = (function(func) {
  10886. return function() {
  10887. var chainAll = this.__chain__;
  10888. if (chain || chainAll) {
  10889. var result = object(this.__wrapped__),
  10890. actions = result.__actions__ = arrayCopy(this.__actions__);
  10891. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  10892. result.__chain__ = chainAll;
  10893. return result;
  10894. }
  10895. return func.apply(object, arrayPush([this.value()], arguments));
  10896. };
  10897. }(func));
  10898. }
  10899. }
  10900. return object;
  10901. }
  10902. /**
  10903. * Reverts the `_` variable to its previous value and returns a reference to
  10904. * the `lodash` function.
  10905. *
  10906. * @static
  10907. * @memberOf _
  10908. * @category Utility
  10909. * @returns {Function} Returns the `lodash` function.
  10910. * @example
  10911. *
  10912. * var lodash = _.noConflict();
  10913. */
  10914. function noConflict() {
  10915. root._ = oldDash;
  10916. return this;
  10917. }
  10918. /**
  10919. * A no-operation function that returns `undefined` regardless of the
  10920. * arguments it receives.
  10921. *
  10922. * @static
  10923. * @memberOf _
  10924. * @category Utility
  10925. * @example
  10926. *
  10927. * var object = { 'user': 'fred' };
  10928. *
  10929. * _.noop(object) === undefined;
  10930. * // => true
  10931. */
  10932. function noop() {
  10933. // No operation performed.
  10934. }
  10935. /**
  10936. * Creates a function that returns the property value at `path` on a
  10937. * given object.
  10938. *
  10939. * @static
  10940. * @memberOf _
  10941. * @category Utility
  10942. * @param {Array|string} path The path of the property to get.
  10943. * @returns {Function} Returns the new function.
  10944. * @example
  10945. *
  10946. * var objects = [
  10947. * { 'a': { 'b': { 'c': 2 } } },
  10948. * { 'a': { 'b': { 'c': 1 } } }
  10949. * ];
  10950. *
  10951. * _.map(objects, _.property('a.b.c'));
  10952. * // => [2, 1]
  10953. *
  10954. * _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
  10955. * // => [1, 2]
  10956. */
  10957. function property(path) {
  10958. return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
  10959. }
  10960. /**
  10961. * The opposite of `_.property`; this method creates a function that returns
  10962. * the property value at a given path on `object`.
  10963. *
  10964. * @static
  10965. * @memberOf _
  10966. * @category Utility
  10967. * @param {Object} object The object to query.
  10968. * @returns {Function} Returns the new function.
  10969. * @example
  10970. *
  10971. * var array = [0, 1, 2],
  10972. * object = { 'a': array, 'b': array, 'c': array };
  10973. *
  10974. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  10975. * // => [2, 0]
  10976. *
  10977. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  10978. * // => [2, 0]
  10979. */
  10980. function propertyOf(object) {
  10981. return function(path) {
  10982. return baseGet(object, toPath(path), (path + ''));
  10983. };
  10984. }
  10985. /**
  10986. * Creates an array of numbers (positive and/or negative) progressing from
  10987. * `start` up to, but not including, `end`. If `end` is not specified it's
  10988. * set to `start` with `start` then set to `0`. If `end` is less than `start`
  10989. * a zero-length range is created unless a negative `step` is specified.
  10990. *
  10991. * @static
  10992. * @memberOf _
  10993. * @category Utility
  10994. * @param {number} [start=0] The start of the range.
  10995. * @param {number} end The end of the range.
  10996. * @param {number} [step=1] The value to increment or decrement by.
  10997. * @returns {Array} Returns the new array of numbers.
  10998. * @example
  10999. *
  11000. * _.range(4);
  11001. * // => [0, 1, 2, 3]
  11002. *
  11003. * _.range(1, 5);
  11004. * // => [1, 2, 3, 4]
  11005. *
  11006. * _.range(0, 20, 5);
  11007. * // => [0, 5, 10, 15]
  11008. *
  11009. * _.range(0, -4, -1);
  11010. * // => [0, -1, -2, -3]
  11011. *
  11012. * _.range(1, 4, 0);
  11013. * // => [1, 1, 1]
  11014. *
  11015. * _.range(0);
  11016. * // => []
  11017. */
  11018. function range(start, end, step) {
  11019. if (step && isIterateeCall(start, end, step)) {
  11020. end = step = undefined;
  11021. }
  11022. start = +start || 0;
  11023. step = step == null ? 1 : (+step || 0);
  11024. if (end == null) {
  11025. end = start;
  11026. start = 0;
  11027. } else {
  11028. end = +end || 0;
  11029. }
  11030. // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
  11031. // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
  11032. var index = -1,
  11033. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  11034. result = Array(length);
  11035. while (++index < length) {
  11036. result[index] = start;
  11037. start += step;
  11038. }
  11039. return result;
  11040. }
  11041. /**
  11042. * Invokes the iteratee function `n` times, returning an array of the results
  11043. * of each invocation. The `iteratee` is bound to `thisArg` and invoked with
  11044. * one argument; (index).
  11045. *
  11046. * @static
  11047. * @memberOf _
  11048. * @category Utility
  11049. * @param {number} n The number of times to invoke `iteratee`.
  11050. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11051. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11052. * @returns {Array} Returns the array of results.
  11053. * @example
  11054. *
  11055. * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
  11056. * // => [3, 6, 4]
  11057. *
  11058. * _.times(3, function(n) {
  11059. * mage.castSpell(n);
  11060. * });
  11061. * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
  11062. *
  11063. * _.times(3, function(n) {
  11064. * this.cast(n);
  11065. * }, mage);
  11066. * // => also invokes `mage.castSpell(n)` three times
  11067. */
  11068. function times(n, iteratee, thisArg) {
  11069. n = nativeFloor(n);
  11070. // Exit early to avoid a JSC JIT bug in Safari 8
  11071. // where `Array(0)` is treated as `Array(1)`.
  11072. if (n < 1 || !nativeIsFinite(n)) {
  11073. return [];
  11074. }
  11075. var index = -1,
  11076. result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
  11077. iteratee = bindCallback(iteratee, thisArg, 1);
  11078. while (++index < n) {
  11079. if (index < MAX_ARRAY_LENGTH) {
  11080. result[index] = iteratee(index);
  11081. } else {
  11082. iteratee(index);
  11083. }
  11084. }
  11085. return result;
  11086. }
  11087. /**
  11088. * Generates a unique ID. If `prefix` is provided the ID is appended to it.
  11089. *
  11090. * @static
  11091. * @memberOf _
  11092. * @category Utility
  11093. * @param {string} [prefix] The value to prefix the ID with.
  11094. * @returns {string} Returns the unique ID.
  11095. * @example
  11096. *
  11097. * _.uniqueId('contact_');
  11098. * // => 'contact_104'
  11099. *
  11100. * _.uniqueId();
  11101. * // => '105'
  11102. */
  11103. function uniqueId(prefix) {
  11104. var id = ++idCounter;
  11105. return baseToString(prefix) + id;
  11106. }
  11107. /*------------------------------------------------------------------------*/
  11108. /**
  11109. * Adds two numbers.
  11110. *
  11111. * @static
  11112. * @memberOf _
  11113. * @category Math
  11114. * @param {number} augend The first number to add.
  11115. * @param {number} addend The second number to add.
  11116. * @returns {number} Returns the sum.
  11117. * @example
  11118. *
  11119. * _.add(6, 4);
  11120. * // => 10
  11121. */
  11122. function add(augend, addend) {
  11123. return (+augend || 0) + (+addend || 0);
  11124. }
  11125. /**
  11126. * Calculates `n` rounded up to `precision`.
  11127. *
  11128. * @static
  11129. * @memberOf _
  11130. * @category Math
  11131. * @param {number} n The number to round up.
  11132. * @param {number} [precision=0] The precision to round up to.
  11133. * @returns {number} Returns the rounded up number.
  11134. * @example
  11135. *
  11136. * _.ceil(4.006);
  11137. * // => 5
  11138. *
  11139. * _.ceil(6.004, 2);
  11140. * // => 6.01
  11141. *
  11142. * _.ceil(6040, -2);
  11143. * // => 6100
  11144. */
  11145. var ceil = createRound('ceil');
  11146. /**
  11147. * Calculates `n` rounded down to `precision`.
  11148. *
  11149. * @static
  11150. * @memberOf _
  11151. * @category Math
  11152. * @param {number} n The number to round down.
  11153. * @param {number} [precision=0] The precision to round down to.
  11154. * @returns {number} Returns the rounded down number.
  11155. * @example
  11156. *
  11157. * _.floor(4.006);
  11158. * // => 4
  11159. *
  11160. * _.floor(0.046, 2);
  11161. * // => 0.04
  11162. *
  11163. * _.floor(4060, -2);
  11164. * // => 4000
  11165. */
  11166. var floor = createRound('floor');
  11167. /**
  11168. * Gets the maximum value of `collection`. If `collection` is empty or falsey
  11169. * `-Infinity` is returned. If an iteratee function is provided it's invoked
  11170. * for each value in `collection` to generate the criterion by which the value
  11171. * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
  11172. * arguments: (value, index, collection).
  11173. *
  11174. * If a property name is provided for `iteratee` the created `_.property`
  11175. * style callback returns the property value of the given element.
  11176. *
  11177. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  11178. * style callback returns `true` for elements that have a matching property
  11179. * value, else `false`.
  11180. *
  11181. * If an object is provided for `iteratee` the created `_.matches` style
  11182. * callback returns `true` for elements that have the properties of the given
  11183. * object, else `false`.
  11184. *
  11185. * @static
  11186. * @memberOf _
  11187. * @category Math
  11188. * @param {Array|Object|string} collection The collection to iterate over.
  11189. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  11190. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11191. * @returns {*} Returns the maximum value.
  11192. * @example
  11193. *
  11194. * _.max([4, 2, 8, 6]);
  11195. * // => 8
  11196. *
  11197. * _.max([]);
  11198. * // => -Infinity
  11199. *
  11200. * var users = [
  11201. * { 'user': 'barney', 'age': 36 },
  11202. * { 'user': 'fred', 'age': 40 }
  11203. * ];
  11204. *
  11205. * _.max(users, function(chr) {
  11206. * return chr.age;
  11207. * });
  11208. * // => { 'user': 'fred', 'age': 40 }
  11209. *
  11210. * // using the `_.property` callback shorthand
  11211. * _.max(users, 'age');
  11212. * // => { 'user': 'fred', 'age': 40 }
  11213. */
  11214. var max = createExtremum(gt, NEGATIVE_INFINITY);
  11215. /**
  11216. * Gets the minimum value of `collection`. If `collection` is empty or falsey
  11217. * `Infinity` is returned. If an iteratee function is provided it's invoked
  11218. * for each value in `collection` to generate the criterion by which the value
  11219. * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
  11220. * arguments: (value, index, collection).
  11221. *
  11222. * If a property name is provided for `iteratee` the created `_.property`
  11223. * style callback returns the property value of the given element.
  11224. *
  11225. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  11226. * style callback returns `true` for elements that have a matching property
  11227. * value, else `false`.
  11228. *
  11229. * If an object is provided for `iteratee` the created `_.matches` style
  11230. * callback returns `true` for elements that have the properties of the given
  11231. * object, else `false`.
  11232. *
  11233. * @static
  11234. * @memberOf _
  11235. * @category Math
  11236. * @param {Array|Object|string} collection The collection to iterate over.
  11237. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  11238. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11239. * @returns {*} Returns the minimum value.
  11240. * @example
  11241. *
  11242. * _.min([4, 2, 8, 6]);
  11243. * // => 2
  11244. *
  11245. * _.min([]);
  11246. * // => Infinity
  11247. *
  11248. * var users = [
  11249. * { 'user': 'barney', 'age': 36 },
  11250. * { 'user': 'fred', 'age': 40 }
  11251. * ];
  11252. *
  11253. * _.min(users, function(chr) {
  11254. * return chr.age;
  11255. * });
  11256. * // => { 'user': 'barney', 'age': 36 }
  11257. *
  11258. * // using the `_.property` callback shorthand
  11259. * _.min(users, 'age');
  11260. * // => { 'user': 'barney', 'age': 36 }
  11261. */
  11262. var min = createExtremum(lt, POSITIVE_INFINITY);
  11263. /**
  11264. * Calculates `n` rounded to `precision`.
  11265. *
  11266. * @static
  11267. * @memberOf _
  11268. * @category Math
  11269. * @param {number} n The number to round.
  11270. * @param {number} [precision=0] The precision to round to.
  11271. * @returns {number} Returns the rounded number.
  11272. * @example
  11273. *
  11274. * _.round(4.006);
  11275. * // => 4
  11276. *
  11277. * _.round(4.006, 2);
  11278. * // => 4.01
  11279. *
  11280. * _.round(4060, -2);
  11281. * // => 4100
  11282. */
  11283. var round = createRound('round');
  11284. /**
  11285. * Gets the sum of the values in `collection`.
  11286. *
  11287. * @static
  11288. * @memberOf _
  11289. * @category Math
  11290. * @param {Array|Object|string} collection The collection to iterate over.
  11291. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  11292. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11293. * @returns {number} Returns the sum.
  11294. * @example
  11295. *
  11296. * _.sum([4, 6]);
  11297. * // => 10
  11298. *
  11299. * _.sum({ 'a': 4, 'b': 6 });
  11300. * // => 10
  11301. *
  11302. * var objects = [
  11303. * { 'n': 4 },
  11304. * { 'n': 6 }
  11305. * ];
  11306. *
  11307. * _.sum(objects, function(object) {
  11308. * return object.n;
  11309. * });
  11310. * // => 10
  11311. *
  11312. * // using the `_.property` callback shorthand
  11313. * _.sum(objects, 'n');
  11314. * // => 10
  11315. */
  11316. function sum(collection, iteratee, thisArg) {
  11317. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  11318. iteratee = undefined;
  11319. }
  11320. iteratee = getCallback(iteratee, thisArg, 3);
  11321. return iteratee.length == 1
  11322. ? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee)
  11323. : baseSum(collection, iteratee);
  11324. }
  11325. /*------------------------------------------------------------------------*/
  11326. // Ensure wrappers are instances of `baseLodash`.
  11327. lodash.prototype = baseLodash.prototype;
  11328. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  11329. LodashWrapper.prototype.constructor = LodashWrapper;
  11330. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  11331. LazyWrapper.prototype.constructor = LazyWrapper;
  11332. // Add functions to the `Map` cache.
  11333. MapCache.prototype['delete'] = mapDelete;
  11334. MapCache.prototype.get = mapGet;
  11335. MapCache.prototype.has = mapHas;
  11336. MapCache.prototype.set = mapSet;
  11337. // Add functions to the `Set` cache.
  11338. SetCache.prototype.push = cachePush;
  11339. // Assign cache to `_.memoize`.
  11340. memoize.Cache = MapCache;
  11341. // Add functions that return wrapped values when chaining.
  11342. lodash.after = after;
  11343. lodash.ary = ary;
  11344. lodash.assign = assign;
  11345. lodash.at = at;
  11346. lodash.before = before;
  11347. lodash.bind = bind;
  11348. lodash.bindAll = bindAll;
  11349. lodash.bindKey = bindKey;
  11350. lodash.callback = callback;
  11351. lodash.chain = chain;
  11352. lodash.chunk = chunk;
  11353. lodash.compact = compact;
  11354. lodash.constant = constant;
  11355. lodash.countBy = countBy;
  11356. lodash.create = create;
  11357. lodash.curry = curry;
  11358. lodash.curryRight = curryRight;
  11359. lodash.debounce = debounce;
  11360. lodash.defaults = defaults;
  11361. lodash.defaultsDeep = defaultsDeep;
  11362. lodash.defer = defer;
  11363. lodash.delay = delay;
  11364. lodash.difference = difference;
  11365. lodash.drop = drop;
  11366. lodash.dropRight = dropRight;
  11367. lodash.dropRightWhile = dropRightWhile;
  11368. lodash.dropWhile = dropWhile;
  11369. lodash.fill = fill;
  11370. lodash.filter = filter;
  11371. lodash.flatten = flatten;
  11372. lodash.flattenDeep = flattenDeep;
  11373. lodash.flow = flow;
  11374. lodash.flowRight = flowRight;
  11375. lodash.forEach = forEach;
  11376. lodash.forEachRight = forEachRight;
  11377. lodash.forIn = forIn;
  11378. lodash.forInRight = forInRight;
  11379. lodash.forOwn = forOwn;
  11380. lodash.forOwnRight = forOwnRight;
  11381. lodash.functions = functions;
  11382. lodash.groupBy = groupBy;
  11383. lodash.indexBy = indexBy;
  11384. lodash.initial = initial;
  11385. lodash.intersection = intersection;
  11386. lodash.invert = invert;
  11387. lodash.invoke = invoke;
  11388. lodash.keys = keys;
  11389. lodash.keysIn = keysIn;
  11390. lodash.map = map;
  11391. lodash.mapKeys = mapKeys;
  11392. lodash.mapValues = mapValues;
  11393. lodash.matches = matches;
  11394. lodash.matchesProperty = matchesProperty;
  11395. lodash.memoize = memoize;
  11396. lodash.merge = merge;
  11397. lodash.method = method;
  11398. lodash.methodOf = methodOf;
  11399. lodash.mixin = mixin;
  11400. lodash.modArgs = modArgs;
  11401. lodash.negate = negate;
  11402. lodash.omit = omit;
  11403. lodash.once = once;
  11404. lodash.pairs = pairs;
  11405. lodash.partial = partial;
  11406. lodash.partialRight = partialRight;
  11407. lodash.partition = partition;
  11408. lodash.pick = pick;
  11409. lodash.pluck = pluck;
  11410. lodash.property = property;
  11411. lodash.propertyOf = propertyOf;
  11412. lodash.pull = pull;
  11413. lodash.pullAt = pullAt;
  11414. lodash.range = range;
  11415. lodash.rearg = rearg;
  11416. lodash.reject = reject;
  11417. lodash.remove = remove;
  11418. lodash.rest = rest;
  11419. lodash.restParam = restParam;
  11420. lodash.set = set;
  11421. lodash.shuffle = shuffle;
  11422. lodash.slice = slice;
  11423. lodash.sortBy = sortBy;
  11424. lodash.sortByAll = sortByAll;
  11425. lodash.sortByOrder = sortByOrder;
  11426. lodash.spread = spread;
  11427. lodash.take = take;
  11428. lodash.takeRight = takeRight;
  11429. lodash.takeRightWhile = takeRightWhile;
  11430. lodash.takeWhile = takeWhile;
  11431. lodash.tap = tap;
  11432. lodash.throttle = throttle;
  11433. lodash.thru = thru;
  11434. lodash.times = times;
  11435. lodash.toArray = toArray;
  11436. lodash.toPlainObject = toPlainObject;
  11437. lodash.transform = transform;
  11438. lodash.union = union;
  11439. lodash.uniq = uniq;
  11440. lodash.unzip = unzip;
  11441. lodash.unzipWith = unzipWith;
  11442. lodash.values = values;
  11443. lodash.valuesIn = valuesIn;
  11444. lodash.where = where;
  11445. lodash.without = without;
  11446. lodash.wrap = wrap;
  11447. lodash.xor = xor;
  11448. lodash.zip = zip;
  11449. lodash.zipObject = zipObject;
  11450. lodash.zipWith = zipWith;
  11451. // Add aliases.
  11452. lodash.backflow = flowRight;
  11453. lodash.collect = map;
  11454. lodash.compose = flowRight;
  11455. lodash.each = forEach;
  11456. lodash.eachRight = forEachRight;
  11457. lodash.extend = assign;
  11458. lodash.iteratee = callback;
  11459. lodash.methods = functions;
  11460. lodash.object = zipObject;
  11461. lodash.select = filter;
  11462. lodash.tail = rest;
  11463. lodash.unique = uniq;
  11464. // Add functions to `lodash.prototype`.
  11465. mixin(lodash, lodash);
  11466. /*------------------------------------------------------------------------*/
  11467. // Add functions that return unwrapped values when chaining.
  11468. lodash.add = add;
  11469. lodash.attempt = attempt;
  11470. lodash.camelCase = camelCase;
  11471. lodash.capitalize = capitalize;
  11472. lodash.ceil = ceil;
  11473. lodash.clone = clone;
  11474. lodash.cloneDeep = cloneDeep;
  11475. lodash.deburr = deburr;
  11476. lodash.endsWith = endsWith;
  11477. lodash.escape = escape;
  11478. lodash.escapeRegExp = escapeRegExp;
  11479. lodash.every = every;
  11480. lodash.find = find;
  11481. lodash.findIndex = findIndex;
  11482. lodash.findKey = findKey;
  11483. lodash.findLast = findLast;
  11484. lodash.findLastIndex = findLastIndex;
  11485. lodash.findLastKey = findLastKey;
  11486. lodash.findWhere = findWhere;
  11487. lodash.first = first;
  11488. lodash.floor = floor;
  11489. lodash.get = get;
  11490. lodash.gt = gt;
  11491. lodash.gte = gte;
  11492. lodash.has = has;
  11493. lodash.identity = identity;
  11494. lodash.includes = includes;
  11495. lodash.indexOf = indexOf;
  11496. lodash.inRange = inRange;
  11497. lodash.isArguments = isArguments;
  11498. lodash.isArray = isArray;
  11499. lodash.isBoolean = isBoolean;
  11500. lodash.isDate = isDate;
  11501. lodash.isElement = isElement;
  11502. lodash.isEmpty = isEmpty;
  11503. lodash.isEqual = isEqual;
  11504. lodash.isError = isError;
  11505. lodash.isFinite = isFinite;
  11506. lodash.isFunction = isFunction;
  11507. lodash.isMatch = isMatch;
  11508. lodash.isNaN = isNaN;
  11509. lodash.isNative = isNative;
  11510. lodash.isNull = isNull;
  11511. lodash.isNumber = isNumber;
  11512. lodash.isObject = isObject;
  11513. lodash.isPlainObject = isPlainObject;
  11514. lodash.isRegExp = isRegExp;
  11515. lodash.isString = isString;
  11516. lodash.isTypedArray = isTypedArray;
  11517. lodash.isUndefined = isUndefined;
  11518. lodash.kebabCase = kebabCase;
  11519. lodash.last = last;
  11520. lodash.lastIndexOf = lastIndexOf;
  11521. lodash.lt = lt;
  11522. lodash.lte = lte;
  11523. lodash.max = max;
  11524. lodash.min = min;
  11525. lodash.noConflict = noConflict;
  11526. lodash.noop = noop;
  11527. lodash.now = now;
  11528. lodash.pad = pad;
  11529. lodash.padLeft = padLeft;
  11530. lodash.padRight = padRight;
  11531. lodash.parseInt = parseInt;
  11532. lodash.random = random;
  11533. lodash.reduce = reduce;
  11534. lodash.reduceRight = reduceRight;
  11535. lodash.repeat = repeat;
  11536. lodash.result = result;
  11537. lodash.round = round;
  11538. lodash.runInContext = runInContext;
  11539. lodash.size = size;
  11540. lodash.snakeCase = snakeCase;
  11541. lodash.some = some;
  11542. lodash.sortedIndex = sortedIndex;
  11543. lodash.sortedLastIndex = sortedLastIndex;
  11544. lodash.startCase = startCase;
  11545. lodash.startsWith = startsWith;
  11546. lodash.sum = sum;
  11547. lodash.template = template;
  11548. lodash.trim = trim;
  11549. lodash.trimLeft = trimLeft;
  11550. lodash.trimRight = trimRight;
  11551. lodash.trunc = trunc;
  11552. lodash.unescape = unescape;
  11553. lodash.uniqueId = uniqueId;
  11554. lodash.words = words;
  11555. // Add aliases.
  11556. lodash.all = every;
  11557. lodash.any = some;
  11558. lodash.contains = includes;
  11559. lodash.eq = isEqual;
  11560. lodash.detect = find;
  11561. lodash.foldl = reduce;
  11562. lodash.foldr = reduceRight;
  11563. lodash.head = first;
  11564. lodash.include = includes;
  11565. lodash.inject = reduce;
  11566. mixin(lodash, (function() {
  11567. var source = {};
  11568. baseForOwn(lodash, function(func, methodName) {
  11569. if (!lodash.prototype[methodName]) {
  11570. source[methodName] = func;
  11571. }
  11572. });
  11573. return source;
  11574. }()), false);
  11575. /*------------------------------------------------------------------------*/
  11576. // Add functions capable of returning wrapped and unwrapped values when chaining.
  11577. lodash.sample = sample;
  11578. lodash.prototype.sample = function(n) {
  11579. if (!this.__chain__ && n == null) {
  11580. return sample(this.value());
  11581. }
  11582. return this.thru(function(value) {
  11583. return sample(value, n);
  11584. });
  11585. };
  11586. /*------------------------------------------------------------------------*/
  11587. /**
  11588. * The semantic version number.
  11589. *
  11590. * @static
  11591. * @memberOf _
  11592. * @type string
  11593. */
  11594. lodash.VERSION = VERSION;
  11595. // Assign default placeholders.
  11596. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  11597. lodash[methodName].placeholder = lodash;
  11598. });
  11599. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  11600. arrayEach(['drop', 'take'], function(methodName, index) {
  11601. LazyWrapper.prototype[methodName] = function(n) {
  11602. var filtered = this.__filtered__;
  11603. if (filtered && !index) {
  11604. return new LazyWrapper(this);
  11605. }
  11606. n = n == null ? 1 : nativeMax(nativeFloor(n) || 0, 0);
  11607. var result = this.clone();
  11608. if (filtered) {
  11609. result.__takeCount__ = nativeMin(result.__takeCount__, n);
  11610. } else {
  11611. result.__views__.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
  11612. }
  11613. return result;
  11614. };
  11615. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  11616. return this.reverse()[methodName](n).reverse();
  11617. };
  11618. });
  11619. // Add `LazyWrapper` methods that accept an `iteratee` value.
  11620. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  11621. var type = index + 1,
  11622. isFilter = type != LAZY_MAP_FLAG;
  11623. LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
  11624. var result = this.clone();
  11625. result.__iteratees__.push({ 'iteratee': getCallback(iteratee, thisArg, 1), 'type': type });
  11626. result.__filtered__ = result.__filtered__ || isFilter;
  11627. return result;
  11628. };
  11629. });
  11630. // Add `LazyWrapper` methods for `_.first` and `_.last`.
  11631. arrayEach(['first', 'last'], function(methodName, index) {
  11632. var takeName = 'take' + (index ? 'Right' : '');
  11633. LazyWrapper.prototype[methodName] = function() {
  11634. return this[takeName](1).value()[0];
  11635. };
  11636. });
  11637. // Add `LazyWrapper` methods for `_.initial` and `_.rest`.
  11638. arrayEach(['initial', 'rest'], function(methodName, index) {
  11639. var dropName = 'drop' + (index ? '' : 'Right');
  11640. LazyWrapper.prototype[methodName] = function() {
  11641. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  11642. };
  11643. });
  11644. // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
  11645. arrayEach(['pluck', 'where'], function(methodName, index) {
  11646. var operationName = index ? 'filter' : 'map',
  11647. createCallback = index ? baseMatches : property;
  11648. LazyWrapper.prototype[methodName] = function(value) {
  11649. return this[operationName](createCallback(value));
  11650. };
  11651. });
  11652. LazyWrapper.prototype.compact = function() {
  11653. return this.filter(identity);
  11654. };
  11655. LazyWrapper.prototype.reject = function(predicate, thisArg) {
  11656. predicate = getCallback(predicate, thisArg, 1);
  11657. return this.filter(function(value) {
  11658. return !predicate(value);
  11659. });
  11660. };
  11661. LazyWrapper.prototype.slice = function(start, end) {
  11662. start = start == null ? 0 : (+start || 0);
  11663. var result = this;
  11664. if (result.__filtered__ && (start > 0 || end < 0)) {
  11665. return new LazyWrapper(result);
  11666. }
  11667. if (start < 0) {
  11668. result = result.takeRight(-start);
  11669. } else if (start) {
  11670. result = result.drop(start);
  11671. }
  11672. if (end !== undefined) {
  11673. end = (+end || 0);
  11674. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  11675. }
  11676. return result;
  11677. };
  11678. LazyWrapper.prototype.takeRightWhile = function(predicate, thisArg) {
  11679. return this.reverse().takeWhile(predicate, thisArg).reverse();
  11680. };
  11681. LazyWrapper.prototype.toArray = function() {
  11682. return this.take(POSITIVE_INFINITY);
  11683. };
  11684. // Add `LazyWrapper` methods to `lodash.prototype`.
  11685. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  11686. var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
  11687. retUnwrapped = /^(?:first|last)$/.test(methodName),
  11688. lodashFunc = lodash[retUnwrapped ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName];
  11689. if (!lodashFunc) {
  11690. return;
  11691. }
  11692. lodash.prototype[methodName] = function() {
  11693. var args = retUnwrapped ? [1] : arguments,
  11694. chainAll = this.__chain__,
  11695. value = this.__wrapped__,
  11696. isHybrid = !!this.__actions__.length,
  11697. isLazy = value instanceof LazyWrapper,
  11698. iteratee = args[0],
  11699. useLazy = isLazy || isArray(value);
  11700. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  11701. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  11702. isLazy = useLazy = false;
  11703. }
  11704. var interceptor = function(value) {
  11705. return (retUnwrapped && chainAll)
  11706. ? lodashFunc(value, 1)[0]
  11707. : lodashFunc.apply(undefined, arrayPush([value], args));
  11708. };
  11709. var action = { 'func': thru, 'args': [interceptor], 'thisArg': undefined },
  11710. onlyLazy = isLazy && !isHybrid;
  11711. if (retUnwrapped && !chainAll) {
  11712. if (onlyLazy) {
  11713. value = value.clone();
  11714. value.__actions__.push(action);
  11715. return func.call(value);
  11716. }
  11717. return lodashFunc.call(undefined, this.value())[0];
  11718. }
  11719. if (!retUnwrapped && useLazy) {
  11720. value = onlyLazy ? value : new LazyWrapper(this);
  11721. var result = func.apply(value, args);
  11722. result.__actions__.push(action);
  11723. return new LodashWrapper(result, chainAll);
  11724. }
  11725. return this.thru(interceptor);
  11726. };
  11727. });
  11728. // Add `Array` and `String` methods to `lodash.prototype`.
  11729. arrayEach(['join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) {
  11730. var protoFunc = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName],
  11731. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  11732. fixObjects = !support.spliceObjects && /^(?:pop|shift|splice)$/.test(methodName),
  11733. retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
  11734. // Avoid array-like object bugs with `Array#shift` and `Array#splice` in
  11735. // IE < 9, Firefox < 10, and RingoJS.
  11736. var func = !fixObjects ? protoFunc : function() {
  11737. var result = protoFunc.apply(this, arguments);
  11738. if (this.length === 0) {
  11739. delete this[0];
  11740. }
  11741. return result;
  11742. };
  11743. lodash.prototype[methodName] = function() {
  11744. var args = arguments;
  11745. if (retUnwrapped && !this.__chain__) {
  11746. return func.apply(this.value(), args);
  11747. }
  11748. return this[chainName](function(value) {
  11749. return func.apply(value, args);
  11750. });
  11751. };
  11752. });
  11753. // Map minified function names to their real names.
  11754. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  11755. var lodashFunc = lodash[methodName];
  11756. if (lodashFunc) {
  11757. var key = (lodashFunc.name + ''),
  11758. names = realNames[key] || (realNames[key] = []);
  11759. names.push({ 'name': methodName, 'func': lodashFunc });
  11760. }
  11761. });
  11762. realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }];
  11763. // Add functions to the lazy wrapper.
  11764. LazyWrapper.prototype.clone = lazyClone;
  11765. LazyWrapper.prototype.reverse = lazyReverse;
  11766. LazyWrapper.prototype.value = lazyValue;
  11767. // Add chaining functions to the `lodash` wrapper.
  11768. lodash.prototype.chain = wrapperChain;
  11769. lodash.prototype.commit = wrapperCommit;
  11770. lodash.prototype.concat = wrapperConcat;
  11771. lodash.prototype.plant = wrapperPlant;
  11772. lodash.prototype.reverse = wrapperReverse;
  11773. lodash.prototype.toString = wrapperToString;
  11774. lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  11775. // Add function aliases to the `lodash` wrapper.
  11776. lodash.prototype.collect = lodash.prototype.map;
  11777. lodash.prototype.head = lodash.prototype.first;
  11778. lodash.prototype.select = lodash.prototype.filter;
  11779. lodash.prototype.tail = lodash.prototype.rest;
  11780. return lodash;
  11781. }
  11782. /*--------------------------------------------------------------------------*/
  11783. // Export lodash.
  11784. var _ = runInContext();
  11785. // Some AMD build optimizers like r.js check for condition patterns like the following:
  11786. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  11787. // Expose lodash to the global object when an AMD loader is present to avoid
  11788. // errors in cases where lodash is loaded by a script tag and not intended
  11789. // as an AMD module. See http://requirejs.org/docs/errors.html#mismatch for
  11790. // more details.
  11791. root._ = _;
  11792. // Define as an anonymous module so, through path mapping, it can be
  11793. // referenced as the "underscore" module.
  11794. define(function() {
  11795. return _;
  11796. });
  11797. }
  11798. // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
  11799. else if (freeExports && freeModule) {
  11800. // Export for Node.js or RingoJS.
  11801. if (moduleExports) {
  11802. (freeModule.exports = _)._ = _;
  11803. }
  11804. // Export for Rhino with CommonJS support.
  11805. else {
  11806. freeExports._ = _;
  11807. }
  11808. }
  11809. else {
  11810. // Export for a browser or Rhino.
  11811. root._ = _;
  11812. }
  11813. }.call(this));