app.js 669 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938189391894018941189421894318944189451894618947189481894918950189511895218953189541895518956189571895818959189601896118962189631896418965189661896718968189691897018971189721897318974189751897618977189781897918980189811898218983189841898518986189871898818989189901899118992189931899418995189961899718998189991900019001190021900319004190051900619007190081900919010190111901219013190141901519016190171901819019190201902119022190231902419025190261902719028190291903019031190321903319034190351903619037190381903919040190411904219043190441904519046190471904819049190501905119052190531905419055190561905719058190591906019061190621906319064190651906619067190681906919070190711907219073190741907519076190771907819079190801908119082190831908419085190861908719088190891909019091190921909319094190951909619097190981909919100191011910219103191041910519106191071910819109191101911119112191131911419115191161911719118191191912019121191221912319124191251912619127191281912919130191311913219133191341913519136191371913819139191401914119142191431914419145191461914719148191491915019151191521915319154191551915619157191581915919160191611916219163191641916519166191671916819169191701917119172191731917419175191761917719178191791918019181191821918319184191851918619187191881918919190191911919219193191941919519196191971919819199192001920119202192031920419205192061920719208192091921019211192121921319214192151921619217192181921919220192211922219223192241922519226192271922819229192301923119232192331923419235192361923719238192391924019241192421924319244192451924619247192481924919250192511925219253192541925519256192571925819259192601926119262192631926419265192661926719268192691927019271192721927319274192751927619277192781927919280192811928219283192841928519286192871928819289192901929119292192931929419295192961929719298192991930019301193021930319304193051930619307193081930919310193111931219313193141931519316193171931819319193201932119322193231932419325193261932719328193291933019331193321933319334193351933619337193381933919340193411934219343193441934519346193471934819349193501935119352193531935419355193561935719358193591936019361193621936319364193651936619367193681936919370193711937219373193741937519376193771937819379193801938119382193831938419385193861938719388193891939019391193921939319394193951939619397193981939919400194011940219403194041940519406194071940819409194101941119412194131941419415194161941719418194191942019421194221942319424194251942619427194281942919430194311943219433194341943519436194371943819439194401944119442194431944419445194461944719448194491945019451194521945319454194551945619457194581945919460194611946219463194641946519466194671946819469194701947119472194731947419475194761947719478194791948019481194821948319484194851948619487194881948919490194911949219493194941949519496194971949819499195001950119502195031950419505195061950719508195091951019511195121951319514195151951619517195181951919520195211952219523195241952519526195271952819529195301953119532195331953419535195361953719538195391954019541195421954319544195451954619547195481954919550195511955219553195541955519556195571955819559195601956119562195631956419565195661956719568195691957019571195721957319574195751957619577195781957919580195811958219583195841958519586195871958819589195901959119592195931959419595195961959719598195991960019601196021960319604196051960619607196081960919610196111961219613196141961519616196171961819619196201962119622196231962419625196261962719628196291963019631196321963319634196351963619637196381963919640196411964219643196441964519646196471964819649196501965119652196531965419655196561965719658196591966019661196621966319664196651966619667196681966919670196711967219673196741967519676196771967819679196801968119682196831968419685196861968719688196891969019691196921969319694196951969619697196981969919700197011970219703197041970519706197071970819709197101971119712197131971419715197161971719718197191972019721197221972319724197251972619727197281972919730197311973219733197341973519736197371973819739197401974119742197431974419745197461974719748197491975019751197521975319754197551975619757197581975919760197611976219763197641976519766197671976819769197701977119772197731977419775197761977719778197791978019781197821978319784197851978619787197881978919790197911979219793197941979519796197971979819799198001980119802198031980419805198061980719808198091981019811198121981319814198151981619817198181981919820198211982219823198241982519826198271982819829198301983119832198331983419835198361983719838198391984019841198421984319844198451984619847198481984919850198511985219853198541985519856198571985819859198601986119862198631986419865198661986719868198691987019871198721987319874198751987619877198781987919880198811988219883198841988519886198871988819889198901989119892198931989419895198961989719898198991990019901199021990319904199051990619907199081990919910199111991219913199141991519916199171991819919199201992119922199231992419925199261992719928199291993019931199321993319934199351993619937199381993919940199411994219943199441994519946199471994819949199501995119952199531995419955199561995719958199591996019961199621996319964199651996619967199681996919970199711997219973199741997519976199771997819979199801998119982199831998419985199861998719988199891999019991199921999319994199951999619997199981999920000200012000220003200042000520006200072000820009200102001120012200132001420015200162001720018200192002020021200222002320024200252002620027200282002920030200312003220033200342003520036200372003820039200402004120042200432004420045200462004720048200492005020051200522005320054200552005620057200582005920060200612006220063200642006520066200672006820069200702007120072200732007420075200762007720078200792008020081200822008320084200852008620087200882008920090200912009220093200942009520096200972009820099201002010120102201032010420105201062010720108201092011020111201122011320114201152011620117201182011920120201212012220123201242012520126201272012820129201302013120132201332013420135201362013720138201392014020141201422014320144201452014620147201482014920150201512015220153201542015520156201572015820159201602016120162201632016420165201662016720168201692017020171201722017320174201752017620177201782017920180201812018220183201842018520186201872018820189201902019120192201932019420195201962019720198201992020020201202022020320204202052020620207202082020920210202112021220213202142021520216202172021820219202202022120222202232022420225202262022720228202292023020231202322023320234202352023620237202382023920240202412024220243202442024520246202472024820249202502025120252202532025420255202562025720258202592026020261202622026320264202652026620267202682026920270202712027220273202742027520276202772027820279202802028120282202832028420285202862028720288202892029020291202922029320294202952029620297202982029920300203012030220303203042030520306203072030820309203102031120312203132031420315203162031720318203192032020321203222032320324203252032620327203282032920330203312033220333203342033520336203372033820339203402034120342203432034420345203462034720348203492035020351203522035320354203552035620357203582035920360203612036220363203642036520366203672036820369203702037120372203732037420375203762037720378203792038020381203822038320384203852038620387203882038920390203912039220393203942039520396203972039820399204002040120402204032040420405204062040720408204092041020411204122041320414204152041620417204182041920420204212042220423204242042520426204272042820429204302043120432204332043420435204362043720438204392044020441204422044320444204452044620447204482044920450204512045220453204542045520456204572045820459204602046120462204632046420465204662046720468204692047020471204722047320474204752047620477204782047920480204812048220483204842048520486204872048820489204902049120492204932049420495204962049720498204992050020501205022050320504205052050620507205082050920510205112051220513205142051520516205172051820519205202052120522205232052420525205262052720528205292053020531205322053320534205352053620537205382053920540205412054220543205442054520546205472054820549205502055120552205532055420555205562055720558205592056020561205622056320564205652056620567205682056920570205712057220573205742057520576205772057820579205802058120582205832058420585205862058720588205892059020591205922059320594205952059620597205982059920600206012060220603206042060520606206072060820609206102061120612206132061420615206162061720618206192062020621206222062320624206252062620627206282062920630206312063220633206342063520636206372063820639206402064120642206432064420645206462064720648206492065020651206522065320654206552065620657206582065920660206612066220663206642066520666206672066820669206702067120672206732067420675206762067720678206792068020681206822068320684206852068620687206882068920690206912069220693206942069520696206972069820699207002070120702207032070420705207062070720708207092071020711207122071320714207152071620717207182071920720207212072220723207242072520726207272072820729207302073120732207332073420735207362073720738207392074020741207422074320744207452074620747207482074920750207512075220753207542075520756207572075820759207602076120762207632076420765207662076720768207692077020771207722077320774207752077620777207782077920780207812078220783207842078520786207872078820789207902079120792207932079420795207962079720798207992080020801208022080320804208052080620807208082080920810208112081220813208142081520816208172081820819208202082120822208232082420825208262082720828208292083020831208322083320834208352083620837208382083920840208412084220843208442084520846208472084820849208502085120852208532085420855208562085720858208592086020861208622086320864208652086620867208682086920870208712087220873208742087520876208772087820879208802088120882208832088420885208862088720888208892089020891208922089320894208952089620897208982089920900209012090220903209042090520906209072090820909209102091120912209132091420915209162091720918209192092020921209222092320924209252092620927209282092920930209312093220933209342093520936209372093820939209402094120942209432094420945209462094720948209492095020951209522095320954209552095620957209582095920960209612096220963209642096520966209672096820969209702097120972209732097420975209762097720978209792098020981209822098320984209852098620987209882098920990209912099220993209942099520996209972099820999210002100121002210032100421005210062100721008210092101021011210122101321014210152101621017210182101921020210212102221023210242102521026210272102821029210302103121032210332103421035210362103721038210392104021041210422104321044210452104621047210482104921050210512105221053210542105521056210572105821059210602106121062210632106421065210662106721068210692107021071210722107321074210752107621077210782107921080210812108221083210842108521086210872108821089210902109121092210932109421095210962109721098210992110021101211022110321104211052110621107211082110921110211112111221113211142111521116211172111821119211202112121122211232112421125211262112721128211292113021131211322113321134211352113621137211382113921140211412114221143211442114521146211472114821149211502115121152211532115421155211562115721158211592116021161211622116321164211652116621167211682116921170211712117221173211742117521176211772117821179211802118121182211832118421185211862118721188211892119021191211922119321194211952119621197211982119921200212012120221203212042120521206212072120821209212102121121212212132121421215212162121721218212192122021221212222122321224212252122621227212282122921230212312123221233212342123521236212372123821239212402124121242212432124421245212462124721248212492125021251212522125321254212552125621257212582125921260212612126221263212642126521266212672126821269212702127121272212732127421275212762127721278212792128021281212822128321284212852128621287212882128921290212912129221293212942129521296212972129821299213002130121302213032130421305213062130721308213092131021311213122131321314213152131621317213182131921320213212132221323213242132521326213272132821329213302133121332213332133421335213362133721338213392134021341213422134321344213452134621347
  1. /******/ (function(modules) { // webpackBootstrap
  2. /******/ // The module cache
  3. /******/ var installedModules = {};
  4. /******/
  5. /******/ // The require function
  6. /******/ function __webpack_require__(moduleId) {
  7. /******/
  8. /******/ // Check if module is in cache
  9. /******/ if(installedModules[moduleId]) {
  10. /******/ return installedModules[moduleId].exports;
  11. /******/ }
  12. /******/ // Create a new module (and put it into the cache)
  13. /******/ var module = installedModules[moduleId] = {
  14. /******/ i: moduleId,
  15. /******/ l: false,
  16. /******/ exports: {}
  17. /******/ };
  18. /******/
  19. /******/ // Execute the module function
  20. /******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  21. /******/
  22. /******/ // Flag the module as loaded
  23. /******/ module.l = true;
  24. /******/
  25. /******/ // Return the exports of the module
  26. /******/ return module.exports;
  27. /******/ }
  28. /******/
  29. /******/
  30. /******/ // expose the modules object (__webpack_modules__)
  31. /******/ __webpack_require__.m = modules;
  32. /******/
  33. /******/ // expose the module cache
  34. /******/ __webpack_require__.c = installedModules;
  35. /******/
  36. /******/ // define getter function for harmony exports
  37. /******/ __webpack_require__.d = function(exports, name, getter) {
  38. /******/ if(!__webpack_require__.o(exports, name)) {
  39. /******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
  40. /******/ }
  41. /******/ };
  42. /******/
  43. /******/ // define __esModule on exports
  44. /******/ __webpack_require__.r = function(exports) {
  45. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  46. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  47. /******/ }
  48. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  49. /******/ };
  50. /******/
  51. /******/ // create a fake namespace object
  52. /******/ // mode & 1: value is a module id, require it
  53. /******/ // mode & 2: merge all properties of value into the ns
  54. /******/ // mode & 4: return value when already ns object
  55. /******/ // mode & 8|1: behave like require
  56. /******/ __webpack_require__.t = function(value, mode) {
  57. /******/ if(mode & 1) value = __webpack_require__(value);
  58. /******/ if(mode & 8) return value;
  59. /******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
  60. /******/ var ns = Object.create(null);
  61. /******/ __webpack_require__.r(ns);
  62. /******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
  63. /******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
  64. /******/ return ns;
  65. /******/ };
  66. /******/
  67. /******/ // getDefaultExport function for compatibility with non-harmony modules
  68. /******/ __webpack_require__.n = function(module) {
  69. /******/ var getter = module && module.__esModule ?
  70. /******/ function getDefault() { return module['default']; } :
  71. /******/ function getModuleExports() { return module; };
  72. /******/ __webpack_require__.d(getter, 'a', getter);
  73. /******/ return getter;
  74. /******/ };
  75. /******/
  76. /******/ // Object.prototype.hasOwnProperty.call
  77. /******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
  78. /******/
  79. /******/ // __webpack_public_path__
  80. /******/ __webpack_require__.p = "/";
  81. /******/
  82. /******/
  83. /******/ // Load entry module and return exports
  84. /******/ return __webpack_require__(__webpack_require__.s = 0);
  85. /******/ })
  86. /************************************************************************/
  87. /******/ ({
  88. /***/ "./node_modules/alpinejs/dist/alpine.js":
  89. /*!**********************************************!*\
  90. !*** ./node_modules/alpinejs/dist/alpine.js ***!
  91. \**********************************************/
  92. /*! no static exports found */
  93. /***/ (function(module, exports, __webpack_require__) {
  94. (function (global, factory) {
  95. true ? module.exports = factory() :
  96. undefined;
  97. }(this, (function () { 'use strict';
  98. function _defineProperty(obj, key, value) {
  99. if (key in obj) {
  100. Object.defineProperty(obj, key, {
  101. value: value,
  102. enumerable: true,
  103. configurable: true,
  104. writable: true
  105. });
  106. } else {
  107. obj[key] = value;
  108. }
  109. return obj;
  110. }
  111. function ownKeys(object, enumerableOnly) {
  112. var keys = Object.keys(object);
  113. if (Object.getOwnPropertySymbols) {
  114. var symbols = Object.getOwnPropertySymbols(object);
  115. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  116. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  117. });
  118. keys.push.apply(keys, symbols);
  119. }
  120. return keys;
  121. }
  122. function _objectSpread2(target) {
  123. for (var i = 1; i < arguments.length; i++) {
  124. var source = arguments[i] != null ? arguments[i] : {};
  125. if (i % 2) {
  126. ownKeys(Object(source), true).forEach(function (key) {
  127. _defineProperty(target, key, source[key]);
  128. });
  129. } else if (Object.getOwnPropertyDescriptors) {
  130. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  131. } else {
  132. ownKeys(Object(source)).forEach(function (key) {
  133. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  134. });
  135. }
  136. }
  137. return target;
  138. }
  139. // Thanks @stimulus:
  140. // https://github.com/stimulusjs/stimulus/blob/master/packages/%40stimulus/core/src/application.ts
  141. function domReady() {
  142. return new Promise(resolve => {
  143. if (document.readyState == "loading") {
  144. document.addEventListener("DOMContentLoaded", resolve);
  145. } else {
  146. resolve();
  147. }
  148. });
  149. }
  150. function arrayUnique(array) {
  151. return Array.from(new Set(array));
  152. }
  153. function isTesting() {
  154. return navigator.userAgent.includes("Node.js") || navigator.userAgent.includes("jsdom");
  155. }
  156. function checkedAttrLooseCompare(valueA, valueB) {
  157. return valueA == valueB;
  158. }
  159. function warnIfMalformedTemplate(el, directive) {
  160. if (el.tagName.toLowerCase() !== 'template') {
  161. console.warn(`Alpine: [${directive}] directive should only be added to <template> tags. See https://github.com/alpinejs/alpine#${directive}`);
  162. } else if (el.content.childElementCount !== 1) {
  163. console.warn(`Alpine: <template> tag with [${directive}] encountered with multiple element roots. Make sure <template> only has a single child element.`);
  164. }
  165. }
  166. function kebabCase(subject) {
  167. return subject.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/[_\s]/, '-').toLowerCase();
  168. }
  169. function camelCase(subject) {
  170. return subject.toLowerCase().replace(/-(\w)/g, (match, char) => char.toUpperCase());
  171. }
  172. function walk(el, callback) {
  173. if (callback(el) === false) return;
  174. let node = el.firstElementChild;
  175. while (node) {
  176. walk(node, callback);
  177. node = node.nextElementSibling;
  178. }
  179. }
  180. function debounce(func, wait) {
  181. var timeout;
  182. return function () {
  183. var context = this,
  184. args = arguments;
  185. var later = function later() {
  186. timeout = null;
  187. func.apply(context, args);
  188. };
  189. clearTimeout(timeout);
  190. timeout = setTimeout(later, wait);
  191. };
  192. }
  193. const handleError = (el, expression, error) => {
  194. console.warn(`Alpine Error: "${error}"\n\nExpression: "${expression}"\nElement:`, el);
  195. if (!isTesting()) {
  196. throw error;
  197. }
  198. };
  199. function tryCatch(cb, {
  200. el,
  201. expression
  202. }) {
  203. try {
  204. const value = cb();
  205. return value instanceof Promise ? value.catch(e => handleError(el, expression, e)) : value;
  206. } catch (e) {
  207. handleError(el, expression, e);
  208. }
  209. }
  210. function saferEval(el, expression, dataContext, additionalHelperVariables = {}) {
  211. return tryCatch(() => {
  212. if (typeof expression === 'function') {
  213. return expression.call(dataContext);
  214. }
  215. return new Function(['$data', ...Object.keys(additionalHelperVariables)], `var __alpine_result; with($data) { __alpine_result = ${expression} }; return __alpine_result`)(dataContext, ...Object.values(additionalHelperVariables));
  216. }, {
  217. el,
  218. expression
  219. });
  220. }
  221. function saferEvalNoReturn(el, expression, dataContext, additionalHelperVariables = {}) {
  222. return tryCatch(() => {
  223. if (typeof expression === 'function') {
  224. return Promise.resolve(expression.call(dataContext, additionalHelperVariables['$event']));
  225. }
  226. let AsyncFunction = Function;
  227. /* MODERN-ONLY:START */
  228. AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
  229. /* MODERN-ONLY:END */
  230. // For the cases when users pass only a function reference to the caller: `x-on:click="foo"`
  231. // Where "foo" is a function. Also, we'll pass the function the event instance when we call it.
  232. if (Object.keys(dataContext).includes(expression)) {
  233. let methodReference = new Function(['dataContext', ...Object.keys(additionalHelperVariables)], `with(dataContext) { return ${expression} }`)(dataContext, ...Object.values(additionalHelperVariables));
  234. if (typeof methodReference === 'function') {
  235. return Promise.resolve(methodReference.call(dataContext, additionalHelperVariables['$event']));
  236. } else {
  237. return Promise.resolve();
  238. }
  239. }
  240. return Promise.resolve(new AsyncFunction(['dataContext', ...Object.keys(additionalHelperVariables)], `with(dataContext) { ${expression} }`)(dataContext, ...Object.values(additionalHelperVariables)));
  241. }, {
  242. el,
  243. expression
  244. });
  245. }
  246. const xAttrRE = /^x-(on|bind|data|text|html|model|if|for|show|cloak|transition|ref|spread)\b/;
  247. function isXAttr(attr) {
  248. const name = replaceAtAndColonWithStandardSyntax(attr.name);
  249. return xAttrRE.test(name);
  250. }
  251. function getXAttrs(el, component, type) {
  252. let directives = Array.from(el.attributes).filter(isXAttr).map(parseHtmlAttribute); // Get an object of directives from x-spread.
  253. let spreadDirective = directives.filter(directive => directive.type === 'spread')[0];
  254. if (spreadDirective) {
  255. let spreadObject = saferEval(el, spreadDirective.expression, component.$data); // Add x-spread directives to the pile of existing directives.
  256. directives = directives.concat(Object.entries(spreadObject).map(([name, value]) => parseHtmlAttribute({
  257. name,
  258. value
  259. })));
  260. }
  261. if (type) return directives.filter(i => i.type === type);
  262. return sortDirectives(directives);
  263. }
  264. function sortDirectives(directives) {
  265. let directiveOrder = ['bind', 'model', 'show', 'catch-all'];
  266. return directives.sort((a, b) => {
  267. let typeA = directiveOrder.indexOf(a.type) === -1 ? 'catch-all' : a.type;
  268. let typeB = directiveOrder.indexOf(b.type) === -1 ? 'catch-all' : b.type;
  269. return directiveOrder.indexOf(typeA) - directiveOrder.indexOf(typeB);
  270. });
  271. }
  272. function parseHtmlAttribute({
  273. name,
  274. value
  275. }) {
  276. const normalizedName = replaceAtAndColonWithStandardSyntax(name);
  277. const typeMatch = normalizedName.match(xAttrRE);
  278. const valueMatch = normalizedName.match(/:([a-zA-Z0-9\-:]+)/);
  279. const modifiers = normalizedName.match(/\.[^.\]]+(?=[^\]]*$)/g) || [];
  280. return {
  281. type: typeMatch ? typeMatch[1] : null,
  282. value: valueMatch ? valueMatch[1] : null,
  283. modifiers: modifiers.map(i => i.replace('.', '')),
  284. expression: value
  285. };
  286. }
  287. function isBooleanAttr(attrName) {
  288. // As per HTML spec table https://html.spec.whatwg.org/multipage/indices.html#attributes-3:boolean-attribute
  289. // Array roughly ordered by estimated usage
  290. const booleanAttributes = ['disabled', 'checked', 'required', 'readonly', 'hidden', 'open', 'selected', 'autofocus', 'itemscope', 'multiple', 'novalidate', 'allowfullscreen', 'allowpaymentrequest', 'formnovalidate', 'autoplay', 'controls', 'loop', 'muted', 'playsinline', 'default', 'ismap', 'reversed', 'async', 'defer', 'nomodule'];
  291. return booleanAttributes.includes(attrName);
  292. }
  293. function replaceAtAndColonWithStandardSyntax(name) {
  294. if (name.startsWith('@')) {
  295. return name.replace('@', 'x-on:');
  296. } else if (name.startsWith(':')) {
  297. return name.replace(':', 'x-bind:');
  298. }
  299. return name;
  300. }
  301. function convertClassStringToArray(classList, filterFn = Boolean) {
  302. return classList.split(' ').filter(filterFn);
  303. }
  304. const TRANSITION_TYPE_IN = 'in';
  305. const TRANSITION_TYPE_OUT = 'out';
  306. const TRANSITION_CANCELLED = 'cancelled';
  307. function transitionIn(el, show, reject, component, forceSkip = false) {
  308. // We don't want to transition on the initial page load.
  309. if (forceSkip) return show();
  310. if (el.__x_transition && el.__x_transition.type === TRANSITION_TYPE_IN) {
  311. // there is already a similar transition going on, this was probably triggered by
  312. // a change in a different property, let's just leave the previous one doing its job
  313. return;
  314. }
  315. const attrs = getXAttrs(el, component, 'transition');
  316. const showAttr = getXAttrs(el, component, 'show')[0]; // If this is triggered by a x-show.transition.
  317. if (showAttr && showAttr.modifiers.includes('transition')) {
  318. let modifiers = showAttr.modifiers; // If x-show.transition.out, we'll skip the "in" transition.
  319. if (modifiers.includes('out') && !modifiers.includes('in')) return show();
  320. const settingBothSidesOfTransition = modifiers.includes('in') && modifiers.includes('out'); // If x-show.transition.in...out... only use "in" related modifiers for this transition.
  321. modifiers = settingBothSidesOfTransition ? modifiers.filter((i, index) => index < modifiers.indexOf('out')) : modifiers;
  322. transitionHelperIn(el, modifiers, show, reject); // Otherwise, we can assume x-transition:enter.
  323. } else if (attrs.some(attr => ['enter', 'enter-start', 'enter-end'].includes(attr.value))) {
  324. transitionClassesIn(el, component, attrs, show, reject);
  325. } else {
  326. // If neither, just show that damn thing.
  327. show();
  328. }
  329. }
  330. function transitionOut(el, hide, reject, component, forceSkip = false) {
  331. // We don't want to transition on the initial page load.
  332. if (forceSkip) return hide();
  333. if (el.__x_transition && el.__x_transition.type === TRANSITION_TYPE_OUT) {
  334. // there is already a similar transition going on, this was probably triggered by
  335. // a change in a different property, let's just leave the previous one doing its job
  336. return;
  337. }
  338. const attrs = getXAttrs(el, component, 'transition');
  339. const showAttr = getXAttrs(el, component, 'show')[0];
  340. if (showAttr && showAttr.modifiers.includes('transition')) {
  341. let modifiers = showAttr.modifiers;
  342. if (modifiers.includes('in') && !modifiers.includes('out')) return hide();
  343. const settingBothSidesOfTransition = modifiers.includes('in') && modifiers.includes('out');
  344. modifiers = settingBothSidesOfTransition ? modifiers.filter((i, index) => index > modifiers.indexOf('out')) : modifiers;
  345. transitionHelperOut(el, modifiers, settingBothSidesOfTransition, hide, reject);
  346. } else if (attrs.some(attr => ['leave', 'leave-start', 'leave-end'].includes(attr.value))) {
  347. transitionClassesOut(el, component, attrs, hide, reject);
  348. } else {
  349. hide();
  350. }
  351. }
  352. function transitionHelperIn(el, modifiers, showCallback, reject) {
  353. // Default values inspired by: https://material.io/design/motion/speed.html#duration
  354. const styleValues = {
  355. duration: modifierValue(modifiers, 'duration', 150),
  356. origin: modifierValue(modifiers, 'origin', 'center'),
  357. first: {
  358. opacity: 0,
  359. scale: modifierValue(modifiers, 'scale', 95)
  360. },
  361. second: {
  362. opacity: 1,
  363. scale: 100
  364. }
  365. };
  366. transitionHelper(el, modifiers, showCallback, () => {}, reject, styleValues, TRANSITION_TYPE_IN);
  367. }
  368. function transitionHelperOut(el, modifiers, settingBothSidesOfTransition, hideCallback, reject) {
  369. // Make the "out" transition .5x slower than the "in". (Visually better)
  370. // HOWEVER, if they explicitly set a duration for the "out" transition,
  371. // use that.
  372. const duration = settingBothSidesOfTransition ? modifierValue(modifiers, 'duration', 150) : modifierValue(modifiers, 'duration', 150) / 2;
  373. const styleValues = {
  374. duration: duration,
  375. origin: modifierValue(modifiers, 'origin', 'center'),
  376. first: {
  377. opacity: 1,
  378. scale: 100
  379. },
  380. second: {
  381. opacity: 0,
  382. scale: modifierValue(modifiers, 'scale', 95)
  383. }
  384. };
  385. transitionHelper(el, modifiers, () => {}, hideCallback, reject, styleValues, TRANSITION_TYPE_OUT);
  386. }
  387. function modifierValue(modifiers, key, fallback) {
  388. // If the modifier isn't present, use the default.
  389. if (modifiers.indexOf(key) === -1) return fallback; // If it IS present, grab the value after it: x-show.transition.duration.500ms
  390. const rawValue = modifiers[modifiers.indexOf(key) + 1];
  391. if (!rawValue) return fallback;
  392. if (key === 'scale') {
  393. // Check if the very next value is NOT a number and return the fallback.
  394. // If x-show.transition.scale, we'll use the default scale value.
  395. // That is how a user opts out of the opacity transition.
  396. if (!isNumeric(rawValue)) return fallback;
  397. }
  398. if (key === 'duration') {
  399. // Support x-show.transition.duration.500ms && duration.500
  400. let match = rawValue.match(/([0-9]+)ms/);
  401. if (match) return match[1];
  402. }
  403. if (key === 'origin') {
  404. // Support chaining origin directions: x-show.transition.top.right
  405. if (['top', 'right', 'left', 'center', 'bottom'].includes(modifiers[modifiers.indexOf(key) + 2])) {
  406. return [rawValue, modifiers[modifiers.indexOf(key) + 2]].join(' ');
  407. }
  408. }
  409. return rawValue;
  410. }
  411. function transitionHelper(el, modifiers, hook1, hook2, reject, styleValues, type) {
  412. // clear the previous transition if exists to avoid caching the wrong styles
  413. if (el.__x_transition) {
  414. el.__x_transition.cancel && el.__x_transition.cancel();
  415. } // If the user set these style values, we'll put them back when we're done with them.
  416. const opacityCache = el.style.opacity;
  417. const transformCache = el.style.transform;
  418. const transformOriginCache = el.style.transformOrigin; // If no modifiers are present: x-show.transition, we'll default to both opacity and scale.
  419. const noModifiers = !modifiers.includes('opacity') && !modifiers.includes('scale');
  420. const transitionOpacity = noModifiers || modifiers.includes('opacity');
  421. const transitionScale = noModifiers || modifiers.includes('scale'); // These are the explicit stages of a transition (same stages for in and for out).
  422. // This way you can get a birds eye view of the hooks, and the differences
  423. // between them.
  424. const stages = {
  425. start() {
  426. if (transitionOpacity) el.style.opacity = styleValues.first.opacity;
  427. if (transitionScale) el.style.transform = `scale(${styleValues.first.scale / 100})`;
  428. },
  429. during() {
  430. if (transitionScale) el.style.transformOrigin = styleValues.origin;
  431. el.style.transitionProperty = [transitionOpacity ? `opacity` : ``, transitionScale ? `transform` : ``].join(' ').trim();
  432. el.style.transitionDuration = `${styleValues.duration / 1000}s`;
  433. el.style.transitionTimingFunction = `cubic-bezier(0.4, 0.0, 0.2, 1)`;
  434. },
  435. show() {
  436. hook1();
  437. },
  438. end() {
  439. if (transitionOpacity) el.style.opacity = styleValues.second.opacity;
  440. if (transitionScale) el.style.transform = `scale(${styleValues.second.scale / 100})`;
  441. },
  442. hide() {
  443. hook2();
  444. },
  445. cleanup() {
  446. if (transitionOpacity) el.style.opacity = opacityCache;
  447. if (transitionScale) el.style.transform = transformCache;
  448. if (transitionScale) el.style.transformOrigin = transformOriginCache;
  449. el.style.transitionProperty = null;
  450. el.style.transitionDuration = null;
  451. el.style.transitionTimingFunction = null;
  452. }
  453. };
  454. transition(el, stages, type, reject);
  455. }
  456. const ensureStringExpression = (expression, el, component) => {
  457. return typeof expression === 'function' ? component.evaluateReturnExpression(el, expression) : expression;
  458. };
  459. function transitionClassesIn(el, component, directives, showCallback, reject) {
  460. const enter = convertClassStringToArray(ensureStringExpression((directives.find(i => i.value === 'enter') || {
  461. expression: ''
  462. }).expression, el, component));
  463. const enterStart = convertClassStringToArray(ensureStringExpression((directives.find(i => i.value === 'enter-start') || {
  464. expression: ''
  465. }).expression, el, component));
  466. const enterEnd = convertClassStringToArray(ensureStringExpression((directives.find(i => i.value === 'enter-end') || {
  467. expression: ''
  468. }).expression, el, component));
  469. transitionClasses(el, enter, enterStart, enterEnd, showCallback, () => {}, TRANSITION_TYPE_IN, reject);
  470. }
  471. function transitionClassesOut(el, component, directives, hideCallback, reject) {
  472. const leave = convertClassStringToArray(ensureStringExpression((directives.find(i => i.value === 'leave') || {
  473. expression: ''
  474. }).expression, el, component));
  475. const leaveStart = convertClassStringToArray(ensureStringExpression((directives.find(i => i.value === 'leave-start') || {
  476. expression: ''
  477. }).expression, el, component));
  478. const leaveEnd = convertClassStringToArray(ensureStringExpression((directives.find(i => i.value === 'leave-end') || {
  479. expression: ''
  480. }).expression, el, component));
  481. transitionClasses(el, leave, leaveStart, leaveEnd, () => {}, hideCallback, TRANSITION_TYPE_OUT, reject);
  482. }
  483. function transitionClasses(el, classesDuring, classesStart, classesEnd, hook1, hook2, type, reject) {
  484. // clear the previous transition if exists to avoid caching the wrong classes
  485. if (el.__x_transition) {
  486. el.__x_transition.cancel && el.__x_transition.cancel();
  487. }
  488. const originalClasses = el.__x_original_classes || [];
  489. const stages = {
  490. start() {
  491. el.classList.add(...classesStart);
  492. },
  493. during() {
  494. el.classList.add(...classesDuring);
  495. },
  496. show() {
  497. hook1();
  498. },
  499. end() {
  500. // Don't remove classes that were in the original class attribute.
  501. el.classList.remove(...classesStart.filter(i => !originalClasses.includes(i)));
  502. el.classList.add(...classesEnd);
  503. },
  504. hide() {
  505. hook2();
  506. },
  507. cleanup() {
  508. el.classList.remove(...classesDuring.filter(i => !originalClasses.includes(i)));
  509. el.classList.remove(...classesEnd.filter(i => !originalClasses.includes(i)));
  510. }
  511. };
  512. transition(el, stages, type, reject);
  513. }
  514. function transition(el, stages, type, reject) {
  515. const finish = once(() => {
  516. stages.hide(); // Adding an "isConnected" check, in case the callback
  517. // removed the element from the DOM.
  518. if (el.isConnected) {
  519. stages.cleanup();
  520. }
  521. delete el.__x_transition;
  522. });
  523. el.__x_transition = {
  524. // Set transition type so we can avoid clearing transition if the direction is the same
  525. type: type,
  526. // create a callback for the last stages of the transition so we can call it
  527. // from different point and early terminate it. Once will ensure that function
  528. // is only called one time.
  529. cancel: once(() => {
  530. reject(TRANSITION_CANCELLED);
  531. finish();
  532. }),
  533. finish,
  534. // This store the next animation frame so we can cancel it
  535. nextFrame: null
  536. };
  537. stages.start();
  538. stages.during();
  539. el.__x_transition.nextFrame = requestAnimationFrame(() => {
  540. // Note: Safari's transitionDuration property will list out comma separated transition durations
  541. // for every single transition property. Let's grab the first one and call it a day.
  542. let duration = Number(getComputedStyle(el).transitionDuration.replace(/,.*/, '').replace('s', '')) * 1000;
  543. if (duration === 0) {
  544. duration = Number(getComputedStyle(el).animationDuration.replace('s', '')) * 1000;
  545. }
  546. stages.show();
  547. el.__x_transition.nextFrame = requestAnimationFrame(() => {
  548. stages.end();
  549. setTimeout(el.__x_transition.finish, duration);
  550. });
  551. });
  552. }
  553. function isNumeric(subject) {
  554. return !Array.isArray(subject) && !isNaN(subject);
  555. } // Thanks @vuejs
  556. // https://github.com/vuejs/vue/blob/4de4649d9637262a9b007720b59f80ac72a5620c/src/shared/util.js
  557. function once(callback) {
  558. let called = false;
  559. return function () {
  560. if (!called) {
  561. called = true;
  562. callback.apply(this, arguments);
  563. }
  564. };
  565. }
  566. function handleForDirective(component, templateEl, expression, initialUpdate, extraVars) {
  567. warnIfMalformedTemplate(templateEl, 'x-for');
  568. let iteratorNames = typeof expression === 'function' ? parseForExpression(component.evaluateReturnExpression(templateEl, expression)) : parseForExpression(expression);
  569. let items = evaluateItemsAndReturnEmptyIfXIfIsPresentAndFalseOnElement(component, templateEl, iteratorNames, extraVars); // As we walk the array, we'll also walk the DOM (updating/creating as we go).
  570. let currentEl = templateEl;
  571. items.forEach((item, index) => {
  572. let iterationScopeVariables = getIterationScopeVariables(iteratorNames, item, index, items, extraVars());
  573. let currentKey = generateKeyForIteration(component, templateEl, index, iterationScopeVariables);
  574. let nextEl = lookAheadForMatchingKeyedElementAndMoveItIfFound(currentEl.nextElementSibling, currentKey); // If we haven't found a matching key, insert the element at the current position.
  575. if (!nextEl) {
  576. nextEl = addElementInLoopAfterCurrentEl(templateEl, currentEl); // And transition it in if it's not the first page load.
  577. transitionIn(nextEl, () => {}, () => {}, component, initialUpdate);
  578. nextEl.__x_for = iterationScopeVariables;
  579. component.initializeElements(nextEl, () => nextEl.__x_for); // Otherwise update the element we found.
  580. } else {
  581. // Temporarily remove the key indicator to allow the normal "updateElements" to work.
  582. delete nextEl.__x_for_key;
  583. nextEl.__x_for = iterationScopeVariables;
  584. component.updateElements(nextEl, () => nextEl.__x_for);
  585. }
  586. currentEl = nextEl;
  587. currentEl.__x_for_key = currentKey;
  588. });
  589. removeAnyLeftOverElementsFromPreviousUpdate(currentEl, component);
  590. } // This was taken from VueJS 2.* core. Thanks Vue!
  591. function parseForExpression(expression) {
  592. let forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  593. let stripParensRE = /^\(|\)$/g;
  594. let forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  595. let inMatch = expression.match(forAliasRE);
  596. if (!inMatch) return;
  597. let res = {};
  598. res.items = inMatch[2].trim();
  599. let item = inMatch[1].trim().replace(stripParensRE, '');
  600. let iteratorMatch = item.match(forIteratorRE);
  601. if (iteratorMatch) {
  602. res.item = item.replace(forIteratorRE, '').trim();
  603. res.index = iteratorMatch[1].trim();
  604. if (iteratorMatch[2]) {
  605. res.collection = iteratorMatch[2].trim();
  606. }
  607. } else {
  608. res.item = item;
  609. }
  610. return res;
  611. }
  612. function getIterationScopeVariables(iteratorNames, item, index, items, extraVars) {
  613. // We must create a new object, so each iteration has a new scope
  614. let scopeVariables = extraVars ? _objectSpread2({}, extraVars) : {};
  615. scopeVariables[iteratorNames.item] = item;
  616. if (iteratorNames.index) scopeVariables[iteratorNames.index] = index;
  617. if (iteratorNames.collection) scopeVariables[iteratorNames.collection] = items;
  618. return scopeVariables;
  619. }
  620. function generateKeyForIteration(component, el, index, iterationScopeVariables) {
  621. let bindKeyAttribute = getXAttrs(el, component, 'bind').filter(attr => attr.value === 'key')[0]; // If the dev hasn't specified a key, just return the index of the iteration.
  622. if (!bindKeyAttribute) return index;
  623. return component.evaluateReturnExpression(el, bindKeyAttribute.expression, () => iterationScopeVariables);
  624. }
  625. function evaluateItemsAndReturnEmptyIfXIfIsPresentAndFalseOnElement(component, el, iteratorNames, extraVars) {
  626. let ifAttribute = getXAttrs(el, component, 'if')[0];
  627. if (ifAttribute && !component.evaluateReturnExpression(el, ifAttribute.expression)) {
  628. return [];
  629. }
  630. let items = component.evaluateReturnExpression(el, iteratorNames.items, extraVars); // This adds support for the `i in n` syntax.
  631. if (isNumeric(items) && items > 0) {
  632. items = Array.from(Array(items).keys(), i => i + 1);
  633. }
  634. return items;
  635. }
  636. function addElementInLoopAfterCurrentEl(templateEl, currentEl) {
  637. let clone = document.importNode(templateEl.content, true);
  638. currentEl.parentElement.insertBefore(clone, currentEl.nextElementSibling);
  639. return currentEl.nextElementSibling;
  640. }
  641. function lookAheadForMatchingKeyedElementAndMoveItIfFound(nextEl, currentKey) {
  642. if (!nextEl) return; // If we are already past the x-for generated elements, we don't need to look ahead.
  643. if (nextEl.__x_for_key === undefined) return; // If the the key's DO match, no need to look ahead.
  644. if (nextEl.__x_for_key === currentKey) return nextEl; // If they don't, we'll look ahead for a match.
  645. // If we find it, we'll move it to the current position in the loop.
  646. let tmpNextEl = nextEl;
  647. while (tmpNextEl) {
  648. if (tmpNextEl.__x_for_key === currentKey) {
  649. return tmpNextEl.parentElement.insertBefore(tmpNextEl, nextEl);
  650. }
  651. tmpNextEl = tmpNextEl.nextElementSibling && tmpNextEl.nextElementSibling.__x_for_key !== undefined ? tmpNextEl.nextElementSibling : false;
  652. }
  653. }
  654. function removeAnyLeftOverElementsFromPreviousUpdate(currentEl, component) {
  655. var nextElementFromOldLoop = currentEl.nextElementSibling && currentEl.nextElementSibling.__x_for_key !== undefined ? currentEl.nextElementSibling : false;
  656. while (nextElementFromOldLoop) {
  657. let nextElementFromOldLoopImmutable = nextElementFromOldLoop;
  658. let nextSibling = nextElementFromOldLoop.nextElementSibling;
  659. transitionOut(nextElementFromOldLoop, () => {
  660. nextElementFromOldLoopImmutable.remove();
  661. }, () => {}, component);
  662. nextElementFromOldLoop = nextSibling && nextSibling.__x_for_key !== undefined ? nextSibling : false;
  663. }
  664. }
  665. function handleAttributeBindingDirective(component, el, attrName, expression, extraVars, attrType, modifiers) {
  666. var value = component.evaluateReturnExpression(el, expression, extraVars);
  667. if (attrName === 'value') {
  668. if (Alpine.ignoreFocusedForValueBinding && document.activeElement.isSameNode(el)) return; // If nested model key is undefined, set the default value to empty string.
  669. if (value === undefined && expression.match(/\./)) {
  670. value = '';
  671. }
  672. if (el.type === 'radio') {
  673. // Set radio value from x-bind:value, if no "value" attribute exists.
  674. // If there are any initial state values, radio will have a correct
  675. // "checked" value since x-bind:value is processed before x-model.
  676. if (el.attributes.value === undefined && attrType === 'bind') {
  677. el.value = value;
  678. } else if (attrType !== 'bind') {
  679. el.checked = checkedAttrLooseCompare(el.value, value);
  680. }
  681. } else if (el.type === 'checkbox') {
  682. // If we are explicitly binding a string to the :value, set the string,
  683. // If the value is a boolean, leave it alone, it will be set to "on"
  684. // automatically.
  685. if (typeof value !== 'boolean' && ![null, undefined].includes(value) && attrType === 'bind') {
  686. el.value = String(value);
  687. } else if (attrType !== 'bind') {
  688. if (Array.isArray(value)) {
  689. // I'm purposely not using Array.includes here because it's
  690. // strict, and because of Numeric/String mis-casting, I
  691. // want the "includes" to be "fuzzy".
  692. el.checked = value.some(val => checkedAttrLooseCompare(val, el.value));
  693. } else {
  694. el.checked = !!value;
  695. }
  696. }
  697. } else if (el.tagName === 'SELECT') {
  698. updateSelect(el, value);
  699. } else {
  700. if (el.value === value) return;
  701. el.value = value;
  702. }
  703. } else if (attrName === 'class') {
  704. if (Array.isArray(value)) {
  705. const originalClasses = el.__x_original_classes || [];
  706. el.setAttribute('class', arrayUnique(originalClasses.concat(value)).join(' '));
  707. } else if (typeof value === 'object') {
  708. // Sorting the keys / class names by their boolean value will ensure that
  709. // anything that evaluates to `false` and needs to remove classes is run first.
  710. const keysSortedByBooleanValue = Object.keys(value).sort((a, b) => value[a] - value[b]);
  711. keysSortedByBooleanValue.forEach(classNames => {
  712. if (value[classNames]) {
  713. convertClassStringToArray(classNames).forEach(className => el.classList.add(className));
  714. } else {
  715. convertClassStringToArray(classNames).forEach(className => el.classList.remove(className));
  716. }
  717. });
  718. } else {
  719. const originalClasses = el.__x_original_classes || [];
  720. const newClasses = value ? convertClassStringToArray(value) : [];
  721. el.setAttribute('class', arrayUnique(originalClasses.concat(newClasses)).join(' '));
  722. }
  723. } else {
  724. attrName = modifiers.includes('camel') ? camelCase(attrName) : attrName; // If an attribute's bound value is null, undefined or false, remove the attribute
  725. if ([null, undefined, false].includes(value)) {
  726. el.removeAttribute(attrName);
  727. } else {
  728. isBooleanAttr(attrName) ? setIfChanged(el, attrName, attrName) : setIfChanged(el, attrName, value);
  729. }
  730. }
  731. }
  732. function setIfChanged(el, attrName, value) {
  733. if (el.getAttribute(attrName) != value) {
  734. el.setAttribute(attrName, value);
  735. }
  736. }
  737. function updateSelect(el, value) {
  738. const arrayWrappedValue = [].concat(value).map(value => {
  739. return value + '';
  740. });
  741. Array.from(el.options).forEach(option => {
  742. option.selected = arrayWrappedValue.includes(option.value || option.text);
  743. });
  744. }
  745. function handleTextDirective(el, output, expression) {
  746. // If nested model key is undefined, set the default value to empty string.
  747. if (output === undefined && expression.match(/\./)) {
  748. output = '';
  749. }
  750. el.textContent = output;
  751. }
  752. function handleHtmlDirective(component, el, expression, extraVars) {
  753. el.innerHTML = component.evaluateReturnExpression(el, expression, extraVars);
  754. }
  755. function handleShowDirective(component, el, value, modifiers, initialUpdate = false) {
  756. const hide = () => {
  757. el.style.display = 'none';
  758. el.__x_is_shown = false;
  759. };
  760. const show = () => {
  761. if (el.style.length === 1 && el.style.display === 'none') {
  762. el.removeAttribute('style');
  763. } else {
  764. el.style.removeProperty('display');
  765. }
  766. el.__x_is_shown = true;
  767. };
  768. if (initialUpdate === true) {
  769. if (value) {
  770. show();
  771. } else {
  772. hide();
  773. }
  774. return;
  775. }
  776. const handle = (resolve, reject) => {
  777. if (value) {
  778. if (el.style.display === 'none' || el.__x_transition) {
  779. transitionIn(el, () => {
  780. show();
  781. }, reject, component);
  782. }
  783. resolve(() => {});
  784. } else {
  785. if (el.style.display !== 'none') {
  786. transitionOut(el, () => {
  787. resolve(() => {
  788. hide();
  789. });
  790. }, reject, component);
  791. } else {
  792. resolve(() => {});
  793. }
  794. }
  795. }; // The working of x-show is a bit complex because we need to
  796. // wait for any child transitions to finish before hiding
  797. // some element. Also, this has to be done recursively.
  798. // If x-show.immediate, foregoe the waiting.
  799. if (modifiers.includes('immediate')) {
  800. handle(finish => finish(), () => {});
  801. return;
  802. } // x-show is encountered during a DOM tree walk. If an element
  803. // we encounter is NOT a child of another x-show element we
  804. // can execute the previous x-show stack (if one exists).
  805. if (component.showDirectiveLastElement && !component.showDirectiveLastElement.contains(el)) {
  806. component.executeAndClearRemainingShowDirectiveStack();
  807. }
  808. component.showDirectiveStack.push(handle);
  809. component.showDirectiveLastElement = el;
  810. }
  811. function handleIfDirective(component, el, expressionResult, initialUpdate, extraVars) {
  812. warnIfMalformedTemplate(el, 'x-if');
  813. const elementHasAlreadyBeenAdded = el.nextElementSibling && el.nextElementSibling.__x_inserted_me === true;
  814. if (expressionResult && (!elementHasAlreadyBeenAdded || el.__x_transition)) {
  815. const clone = document.importNode(el.content, true);
  816. el.parentElement.insertBefore(clone, el.nextElementSibling);
  817. transitionIn(el.nextElementSibling, () => {}, () => {}, component, initialUpdate);
  818. component.initializeElements(el.nextElementSibling, extraVars);
  819. el.nextElementSibling.__x_inserted_me = true;
  820. } else if (!expressionResult && elementHasAlreadyBeenAdded) {
  821. transitionOut(el.nextElementSibling, () => {
  822. el.nextElementSibling.remove();
  823. }, () => {}, component, initialUpdate);
  824. }
  825. }
  826. function registerListener(component, el, event, modifiers, expression, extraVars = {}) {
  827. const options = {
  828. passive: modifiers.includes('passive')
  829. };
  830. if (modifiers.includes('camel')) {
  831. event = camelCase(event);
  832. }
  833. if (modifiers.includes('away')) {
  834. let handler = e => {
  835. // Don't do anything if the click came from the element or within it.
  836. if (el.contains(e.target)) return; // Don't do anything if this element isn't currently visible.
  837. if (el.offsetWidth < 1 && el.offsetHeight < 1) return; // Now that we are sure the element is visible, AND the click
  838. // is from outside it, let's run the expression.
  839. runListenerHandler(component, expression, e, extraVars);
  840. if (modifiers.includes('once')) {
  841. document.removeEventListener(event, handler, options);
  842. }
  843. }; // Listen for this event at the root level.
  844. document.addEventListener(event, handler, options);
  845. } else {
  846. let listenerTarget = modifiers.includes('window') ? window : modifiers.includes('document') ? document : el;
  847. let handler = e => {
  848. // Remove this global event handler if the element that declared it
  849. // has been removed. It's now stale.
  850. if (listenerTarget === window || listenerTarget === document) {
  851. if (!document.body.contains(el)) {
  852. listenerTarget.removeEventListener(event, handler, options);
  853. return;
  854. }
  855. }
  856. if (isKeyEvent(event)) {
  857. if (isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers)) {
  858. return;
  859. }
  860. }
  861. if (modifiers.includes('prevent')) e.preventDefault();
  862. if (modifiers.includes('stop')) e.stopPropagation(); // If the .self modifier isn't present, or if it is present and
  863. // the target element matches the element we are registering the
  864. // event on, run the handler
  865. if (!modifiers.includes('self') || e.target === el) {
  866. const returnValue = runListenerHandler(component, expression, e, extraVars);
  867. returnValue.then(value => {
  868. if (value === false) {
  869. e.preventDefault();
  870. } else {
  871. if (modifiers.includes('once')) {
  872. listenerTarget.removeEventListener(event, handler, options);
  873. }
  874. }
  875. });
  876. }
  877. };
  878. if (modifiers.includes('debounce')) {
  879. let nextModifier = modifiers[modifiers.indexOf('debounce') + 1] || 'invalid-wait';
  880. let wait = isNumeric(nextModifier.split('ms')[0]) ? Number(nextModifier.split('ms')[0]) : 250;
  881. handler = debounce(handler, wait);
  882. }
  883. listenerTarget.addEventListener(event, handler, options);
  884. }
  885. }
  886. function runListenerHandler(component, expression, e, extraVars) {
  887. return component.evaluateCommandExpression(e.target, expression, () => {
  888. return _objectSpread2(_objectSpread2({}, extraVars()), {}, {
  889. '$event': e
  890. });
  891. });
  892. }
  893. function isKeyEvent(event) {
  894. return ['keydown', 'keyup'].includes(event);
  895. }
  896. function isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers) {
  897. let keyModifiers = modifiers.filter(i => {
  898. return !['window', 'document', 'prevent', 'stop'].includes(i);
  899. });
  900. if (keyModifiers.includes('debounce')) {
  901. let debounceIndex = keyModifiers.indexOf('debounce');
  902. keyModifiers.splice(debounceIndex, isNumeric((keyModifiers[debounceIndex + 1] || 'invalid-wait').split('ms')[0]) ? 2 : 1);
  903. } // If no modifier is specified, we'll call it a press.
  904. if (keyModifiers.length === 0) return false; // If one is passed, AND it matches the key pressed, we'll call it a press.
  905. if (keyModifiers.length === 1 && keyModifiers[0] === keyToModifier(e.key)) return false; // The user is listening for key combinations.
  906. const systemKeyModifiers = ['ctrl', 'shift', 'alt', 'meta', 'cmd', 'super'];
  907. const selectedSystemKeyModifiers = systemKeyModifiers.filter(modifier => keyModifiers.includes(modifier));
  908. keyModifiers = keyModifiers.filter(i => !selectedSystemKeyModifiers.includes(i));
  909. if (selectedSystemKeyModifiers.length > 0) {
  910. const activelyPressedKeyModifiers = selectedSystemKeyModifiers.filter(modifier => {
  911. // Alias "cmd" and "super" to "meta"
  912. if (modifier === 'cmd' || modifier === 'super') modifier = 'meta';
  913. return e[`${modifier}Key`];
  914. }); // If all the modifiers selected are pressed, ...
  915. if (activelyPressedKeyModifiers.length === selectedSystemKeyModifiers.length) {
  916. // AND the remaining key is pressed as well. It's a press.
  917. if (keyModifiers[0] === keyToModifier(e.key)) return false;
  918. }
  919. } // We'll call it NOT a valid keypress.
  920. return true;
  921. }
  922. function keyToModifier(key) {
  923. switch (key) {
  924. case '/':
  925. return 'slash';
  926. case ' ':
  927. case 'Spacebar':
  928. return 'space';
  929. default:
  930. return key && kebabCase(key);
  931. }
  932. }
  933. function registerModelListener(component, el, modifiers, expression, extraVars) {
  934. // If the element we are binding to is a select, a radio, or checkbox
  935. // we'll listen for the change event instead of the "input" event.
  936. var event = el.tagName.toLowerCase() === 'select' || ['checkbox', 'radio'].includes(el.type) || modifiers.includes('lazy') ? 'change' : 'input';
  937. const listenerExpression = `${expression} = rightSideOfExpression($event, ${expression})`;
  938. registerListener(component, el, event, modifiers, listenerExpression, () => {
  939. return _objectSpread2(_objectSpread2({}, extraVars()), {}, {
  940. rightSideOfExpression: generateModelAssignmentFunction(el, modifiers, expression)
  941. });
  942. });
  943. }
  944. function generateModelAssignmentFunction(el, modifiers, expression) {
  945. if (el.type === 'radio') {
  946. // Radio buttons only work properly when they share a name attribute.
  947. // People might assume we take care of that for them, because
  948. // they already set a shared "x-model" attribute.
  949. if (!el.hasAttribute('name')) el.setAttribute('name', expression);
  950. }
  951. return (event, currentValue) => {
  952. // Check for event.detail due to an issue where IE11 handles other events as a CustomEvent.
  953. if (event instanceof CustomEvent && event.detail) {
  954. return event.detail;
  955. } else if (el.type === 'checkbox') {
  956. // If the data we are binding to is an array, toggle its value inside the array.
  957. if (Array.isArray(currentValue)) {
  958. const newValue = modifiers.includes('number') ? safeParseNumber(event.target.value) : event.target.value;
  959. return event.target.checked ? currentValue.concat([newValue]) : currentValue.filter(el => !checkedAttrLooseCompare(el, newValue));
  960. } else {
  961. return event.target.checked;
  962. }
  963. } else if (el.tagName.toLowerCase() === 'select' && el.multiple) {
  964. return modifiers.includes('number') ? Array.from(event.target.selectedOptions).map(option => {
  965. const rawValue = option.value || option.text;
  966. return safeParseNumber(rawValue);
  967. }) : Array.from(event.target.selectedOptions).map(option => {
  968. return option.value || option.text;
  969. });
  970. } else {
  971. const rawValue = event.target.value;
  972. return modifiers.includes('number') ? safeParseNumber(rawValue) : modifiers.includes('trim') ? rawValue.trim() : rawValue;
  973. }
  974. };
  975. }
  976. function safeParseNumber(rawValue) {
  977. const number = rawValue ? parseFloat(rawValue) : null;
  978. return isNumeric(number) ? number : rawValue;
  979. }
  980. /**
  981. * Copyright (C) 2017 salesforce.com, inc.
  982. */
  983. const { isArray } = Array;
  984. const { getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, defineProperties: ObjectDefineProperties, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
  985. const { push: ArrayPush, concat: ArrayConcat, map: ArrayMap, } = Array.prototype;
  986. function isUndefined(obj) {
  987. return obj === undefined;
  988. }
  989. function isFunction(obj) {
  990. return typeof obj === 'function';
  991. }
  992. function isObject(obj) {
  993. return typeof obj === 'object';
  994. }
  995. const proxyToValueMap = new WeakMap();
  996. function registerProxy(proxy, value) {
  997. proxyToValueMap.set(proxy, value);
  998. }
  999. const unwrap = (replicaOrAny) => proxyToValueMap.get(replicaOrAny) || replicaOrAny;
  1000. function wrapValue(membrane, value) {
  1001. return membrane.valueIsObservable(value) ? membrane.getProxy(value) : value;
  1002. }
  1003. /**
  1004. * Unwrap property descriptors will set value on original descriptor
  1005. * We only need to unwrap if value is specified
  1006. * @param descriptor external descrpitor provided to define new property on original value
  1007. */
  1008. function unwrapDescriptor(descriptor) {
  1009. if (hasOwnProperty.call(descriptor, 'value')) {
  1010. descriptor.value = unwrap(descriptor.value);
  1011. }
  1012. return descriptor;
  1013. }
  1014. function lockShadowTarget(membrane, shadowTarget, originalTarget) {
  1015. const targetKeys = ArrayConcat.call(getOwnPropertyNames(originalTarget), getOwnPropertySymbols(originalTarget));
  1016. targetKeys.forEach((key) => {
  1017. let descriptor = getOwnPropertyDescriptor(originalTarget, key);
  1018. // We do not need to wrap the descriptor if configurable
  1019. // Because we can deal with wrapping it when user goes through
  1020. // Get own property descriptor. There is also a chance that this descriptor
  1021. // could change sometime in the future, so we can defer wrapping
  1022. // until we need to
  1023. if (!descriptor.configurable) {
  1024. descriptor = wrapDescriptor(membrane, descriptor, wrapValue);
  1025. }
  1026. ObjectDefineProperty(shadowTarget, key, descriptor);
  1027. });
  1028. preventExtensions(shadowTarget);
  1029. }
  1030. class ReactiveProxyHandler {
  1031. constructor(membrane, value) {
  1032. this.originalTarget = value;
  1033. this.membrane = membrane;
  1034. }
  1035. get(shadowTarget, key) {
  1036. const { originalTarget, membrane } = this;
  1037. const value = originalTarget[key];
  1038. const { valueObserved } = membrane;
  1039. valueObserved(originalTarget, key);
  1040. return membrane.getProxy(value);
  1041. }
  1042. set(shadowTarget, key, value) {
  1043. const { originalTarget, membrane: { valueMutated } } = this;
  1044. const oldValue = originalTarget[key];
  1045. if (oldValue !== value) {
  1046. originalTarget[key] = value;
  1047. valueMutated(originalTarget, key);
  1048. }
  1049. else if (key === 'length' && isArray(originalTarget)) {
  1050. // fix for issue #236: push will add the new index, and by the time length
  1051. // is updated, the internal length is already equal to the new length value
  1052. // therefore, the oldValue is equal to the value. This is the forking logic
  1053. // to support this use case.
  1054. valueMutated(originalTarget, key);
  1055. }
  1056. return true;
  1057. }
  1058. deleteProperty(shadowTarget, key) {
  1059. const { originalTarget, membrane: { valueMutated } } = this;
  1060. delete originalTarget[key];
  1061. valueMutated(originalTarget, key);
  1062. return true;
  1063. }
  1064. apply(shadowTarget, thisArg, argArray) {
  1065. /* No op */
  1066. }
  1067. construct(target, argArray, newTarget) {
  1068. /* No op */
  1069. }
  1070. has(shadowTarget, key) {
  1071. const { originalTarget, membrane: { valueObserved } } = this;
  1072. valueObserved(originalTarget, key);
  1073. return key in originalTarget;
  1074. }
  1075. ownKeys(shadowTarget) {
  1076. const { originalTarget } = this;
  1077. return ArrayConcat.call(getOwnPropertyNames(originalTarget), getOwnPropertySymbols(originalTarget));
  1078. }
  1079. isExtensible(shadowTarget) {
  1080. const shadowIsExtensible = isExtensible(shadowTarget);
  1081. if (!shadowIsExtensible) {
  1082. return shadowIsExtensible;
  1083. }
  1084. const { originalTarget, membrane } = this;
  1085. const targetIsExtensible = isExtensible(originalTarget);
  1086. if (!targetIsExtensible) {
  1087. lockShadowTarget(membrane, shadowTarget, originalTarget);
  1088. }
  1089. return targetIsExtensible;
  1090. }
  1091. setPrototypeOf(shadowTarget, prototype) {
  1092. }
  1093. getPrototypeOf(shadowTarget) {
  1094. const { originalTarget } = this;
  1095. return getPrototypeOf(originalTarget);
  1096. }
  1097. getOwnPropertyDescriptor(shadowTarget, key) {
  1098. const { originalTarget, membrane } = this;
  1099. const { valueObserved } = this.membrane;
  1100. // keys looked up via hasOwnProperty need to be reactive
  1101. valueObserved(originalTarget, key);
  1102. let desc = getOwnPropertyDescriptor(originalTarget, key);
  1103. if (isUndefined(desc)) {
  1104. return desc;
  1105. }
  1106. const shadowDescriptor = getOwnPropertyDescriptor(shadowTarget, key);
  1107. if (!isUndefined(shadowDescriptor)) {
  1108. return shadowDescriptor;
  1109. }
  1110. // Note: by accessing the descriptor, the key is marked as observed
  1111. // but access to the value, setter or getter (if available) cannot observe
  1112. // mutations, just like regular methods, in which case we just do nothing.
  1113. desc = wrapDescriptor(membrane, desc, wrapValue);
  1114. if (!desc.configurable) {
  1115. // If descriptor from original target is not configurable,
  1116. // We must copy the wrapped descriptor over to the shadow target.
  1117. // Otherwise, proxy will throw an invariant error.
  1118. // This is our last chance to lock the value.
  1119. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/getOwnPropertyDescriptor#Invariants
  1120. ObjectDefineProperty(shadowTarget, key, desc);
  1121. }
  1122. return desc;
  1123. }
  1124. preventExtensions(shadowTarget) {
  1125. const { originalTarget, membrane } = this;
  1126. lockShadowTarget(membrane, shadowTarget, originalTarget);
  1127. preventExtensions(originalTarget);
  1128. return true;
  1129. }
  1130. defineProperty(shadowTarget, key, descriptor) {
  1131. const { originalTarget, membrane } = this;
  1132. const { valueMutated } = membrane;
  1133. const { configurable } = descriptor;
  1134. // We have to check for value in descriptor
  1135. // because Object.freeze(proxy) calls this method
  1136. // with only { configurable: false, writeable: false }
  1137. // Additionally, method will only be called with writeable:false
  1138. // if the descriptor has a value, as opposed to getter/setter
  1139. // So we can just check if writable is present and then see if
  1140. // value is present. This eliminates getter and setter descriptors
  1141. if (hasOwnProperty.call(descriptor, 'writable') && !hasOwnProperty.call(descriptor, 'value')) {
  1142. const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key);
  1143. descriptor.value = originalDescriptor.value;
  1144. }
  1145. ObjectDefineProperty(originalTarget, key, unwrapDescriptor(descriptor));
  1146. if (configurable === false) {
  1147. ObjectDefineProperty(shadowTarget, key, wrapDescriptor(membrane, descriptor, wrapValue));
  1148. }
  1149. valueMutated(originalTarget, key);
  1150. return true;
  1151. }
  1152. }
  1153. function wrapReadOnlyValue(membrane, value) {
  1154. return membrane.valueIsObservable(value) ? membrane.getReadOnlyProxy(value) : value;
  1155. }
  1156. class ReadOnlyHandler {
  1157. constructor(membrane, value) {
  1158. this.originalTarget = value;
  1159. this.membrane = membrane;
  1160. }
  1161. get(shadowTarget, key) {
  1162. const { membrane, originalTarget } = this;
  1163. const value = originalTarget[key];
  1164. const { valueObserved } = membrane;
  1165. valueObserved(originalTarget, key);
  1166. return membrane.getReadOnlyProxy(value);
  1167. }
  1168. set(shadowTarget, key, value) {
  1169. return false;
  1170. }
  1171. deleteProperty(shadowTarget, key) {
  1172. return false;
  1173. }
  1174. apply(shadowTarget, thisArg, argArray) {
  1175. /* No op */
  1176. }
  1177. construct(target, argArray, newTarget) {
  1178. /* No op */
  1179. }
  1180. has(shadowTarget, key) {
  1181. const { originalTarget, membrane: { valueObserved } } = this;
  1182. valueObserved(originalTarget, key);
  1183. return key in originalTarget;
  1184. }
  1185. ownKeys(shadowTarget) {
  1186. const { originalTarget } = this;
  1187. return ArrayConcat.call(getOwnPropertyNames(originalTarget), getOwnPropertySymbols(originalTarget));
  1188. }
  1189. setPrototypeOf(shadowTarget, prototype) {
  1190. }
  1191. getOwnPropertyDescriptor(shadowTarget, key) {
  1192. const { originalTarget, membrane } = this;
  1193. const { valueObserved } = membrane;
  1194. // keys looked up via hasOwnProperty need to be reactive
  1195. valueObserved(originalTarget, key);
  1196. let desc = getOwnPropertyDescriptor(originalTarget, key);
  1197. if (isUndefined(desc)) {
  1198. return desc;
  1199. }
  1200. const shadowDescriptor = getOwnPropertyDescriptor(shadowTarget, key);
  1201. if (!isUndefined(shadowDescriptor)) {
  1202. return shadowDescriptor;
  1203. }
  1204. // Note: by accessing the descriptor, the key is marked as observed
  1205. // but access to the value or getter (if available) cannot be observed,
  1206. // just like regular methods, in which case we just do nothing.
  1207. desc = wrapDescriptor(membrane, desc, wrapReadOnlyValue);
  1208. if (hasOwnProperty.call(desc, 'set')) {
  1209. desc.set = undefined; // readOnly membrane does not allow setters
  1210. }
  1211. if (!desc.configurable) {
  1212. // If descriptor from original target is not configurable,
  1213. // We must copy the wrapped descriptor over to the shadow target.
  1214. // Otherwise, proxy will throw an invariant error.
  1215. // This is our last chance to lock the value.
  1216. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/getOwnPropertyDescriptor#Invariants
  1217. ObjectDefineProperty(shadowTarget, key, desc);
  1218. }
  1219. return desc;
  1220. }
  1221. preventExtensions(shadowTarget) {
  1222. return false;
  1223. }
  1224. defineProperty(shadowTarget, key, descriptor) {
  1225. return false;
  1226. }
  1227. }
  1228. function createShadowTarget(value) {
  1229. let shadowTarget = undefined;
  1230. if (isArray(value)) {
  1231. shadowTarget = [];
  1232. }
  1233. else if (isObject(value)) {
  1234. shadowTarget = {};
  1235. }
  1236. return shadowTarget;
  1237. }
  1238. const ObjectDotPrototype = Object.prototype;
  1239. function defaultValueIsObservable(value) {
  1240. // intentionally checking for null
  1241. if (value === null) {
  1242. return false;
  1243. }
  1244. // treat all non-object types, including undefined, as non-observable values
  1245. if (typeof value !== 'object') {
  1246. return false;
  1247. }
  1248. if (isArray(value)) {
  1249. return true;
  1250. }
  1251. const proto = getPrototypeOf(value);
  1252. return (proto === ObjectDotPrototype || proto === null || getPrototypeOf(proto) === null);
  1253. }
  1254. const defaultValueObserved = (obj, key) => {
  1255. /* do nothing */
  1256. };
  1257. const defaultValueMutated = (obj, key) => {
  1258. /* do nothing */
  1259. };
  1260. const defaultValueDistortion = (value) => value;
  1261. function wrapDescriptor(membrane, descriptor, getValue) {
  1262. const { set, get } = descriptor;
  1263. if (hasOwnProperty.call(descriptor, 'value')) {
  1264. descriptor.value = getValue(membrane, descriptor.value);
  1265. }
  1266. else {
  1267. if (!isUndefined(get)) {
  1268. descriptor.get = function () {
  1269. // invoking the original getter with the original target
  1270. return getValue(membrane, get.call(unwrap(this)));
  1271. };
  1272. }
  1273. if (!isUndefined(set)) {
  1274. descriptor.set = function (value) {
  1275. // At this point we don't have a clear indication of whether
  1276. // or not a valid mutation will occur, we don't have the key,
  1277. // and we are not sure why and how they are invoking this setter.
  1278. // Nevertheless we preserve the original semantics by invoking the
  1279. // original setter with the original target and the unwrapped value
  1280. set.call(unwrap(this), membrane.unwrapProxy(value));
  1281. };
  1282. }
  1283. }
  1284. return descriptor;
  1285. }
  1286. class ReactiveMembrane {
  1287. constructor(options) {
  1288. this.valueDistortion = defaultValueDistortion;
  1289. this.valueMutated = defaultValueMutated;
  1290. this.valueObserved = defaultValueObserved;
  1291. this.valueIsObservable = defaultValueIsObservable;
  1292. this.objectGraph = new WeakMap();
  1293. if (!isUndefined(options)) {
  1294. const { valueDistortion, valueMutated, valueObserved, valueIsObservable } = options;
  1295. this.valueDistortion = isFunction(valueDistortion) ? valueDistortion : defaultValueDistortion;
  1296. this.valueMutated = isFunction(valueMutated) ? valueMutated : defaultValueMutated;
  1297. this.valueObserved = isFunction(valueObserved) ? valueObserved : defaultValueObserved;
  1298. this.valueIsObservable = isFunction(valueIsObservable) ? valueIsObservable : defaultValueIsObservable;
  1299. }
  1300. }
  1301. getProxy(value) {
  1302. const unwrappedValue = unwrap(value);
  1303. const distorted = this.valueDistortion(unwrappedValue);
  1304. if (this.valueIsObservable(distorted)) {
  1305. const o = this.getReactiveState(unwrappedValue, distorted);
  1306. // when trying to extract the writable version of a readonly
  1307. // we return the readonly.
  1308. return o.readOnly === value ? value : o.reactive;
  1309. }
  1310. return distorted;
  1311. }
  1312. getReadOnlyProxy(value) {
  1313. value = unwrap(value);
  1314. const distorted = this.valueDistortion(value);
  1315. if (this.valueIsObservable(distorted)) {
  1316. return this.getReactiveState(value, distorted).readOnly;
  1317. }
  1318. return distorted;
  1319. }
  1320. unwrapProxy(p) {
  1321. return unwrap(p);
  1322. }
  1323. getReactiveState(value, distortedValue) {
  1324. const { objectGraph, } = this;
  1325. let reactiveState = objectGraph.get(distortedValue);
  1326. if (reactiveState) {
  1327. return reactiveState;
  1328. }
  1329. const membrane = this;
  1330. reactiveState = {
  1331. get reactive() {
  1332. const reactiveHandler = new ReactiveProxyHandler(membrane, distortedValue);
  1333. // caching the reactive proxy after the first time it is accessed
  1334. const proxy = new Proxy(createShadowTarget(distortedValue), reactiveHandler);
  1335. registerProxy(proxy, value);
  1336. ObjectDefineProperty(this, 'reactive', { value: proxy });
  1337. return proxy;
  1338. },
  1339. get readOnly() {
  1340. const readOnlyHandler = new ReadOnlyHandler(membrane, distortedValue);
  1341. // caching the readOnly proxy after the first time it is accessed
  1342. const proxy = new Proxy(createShadowTarget(distortedValue), readOnlyHandler);
  1343. registerProxy(proxy, value);
  1344. ObjectDefineProperty(this, 'readOnly', { value: proxy });
  1345. return proxy;
  1346. }
  1347. };
  1348. objectGraph.set(distortedValue, reactiveState);
  1349. return reactiveState;
  1350. }
  1351. }
  1352. /** version: 0.26.0 */
  1353. function wrap(data, mutationCallback) {
  1354. let membrane = new ReactiveMembrane({
  1355. valueMutated(target, key) {
  1356. mutationCallback(target, key);
  1357. }
  1358. });
  1359. return {
  1360. data: membrane.getProxy(data),
  1361. membrane: membrane
  1362. };
  1363. }
  1364. function unwrap$1(membrane, observable) {
  1365. let unwrappedData = membrane.unwrapProxy(observable);
  1366. let copy = {};
  1367. Object.keys(unwrappedData).forEach(key => {
  1368. if (['$el', '$refs', '$nextTick', '$watch'].includes(key)) return;
  1369. copy[key] = unwrappedData[key];
  1370. });
  1371. return copy;
  1372. }
  1373. class Component {
  1374. constructor(el, componentForClone = null) {
  1375. this.$el = el;
  1376. const dataAttr = this.$el.getAttribute('x-data');
  1377. const dataExpression = dataAttr === '' ? '{}' : dataAttr;
  1378. const initExpression = this.$el.getAttribute('x-init');
  1379. let dataExtras = {
  1380. $el: this.$el
  1381. };
  1382. let canonicalComponentElementReference = componentForClone ? componentForClone.$el : this.$el;
  1383. Object.entries(Alpine.magicProperties).forEach(([name, callback]) => {
  1384. Object.defineProperty(dataExtras, `$${name}`, {
  1385. get: function get() {
  1386. return callback(canonicalComponentElementReference);
  1387. }
  1388. });
  1389. });
  1390. this.unobservedData = componentForClone ? componentForClone.getUnobservedData() : saferEval(el, dataExpression, dataExtras);
  1391. // Construct a Proxy-based observable. This will be used to handle reactivity.
  1392. let {
  1393. membrane,
  1394. data
  1395. } = this.wrapDataInObservable(this.unobservedData);
  1396. this.$data = data;
  1397. this.membrane = membrane; // After making user-supplied data methods reactive, we can now add
  1398. // our magic properties to the original data for access.
  1399. this.unobservedData.$el = this.$el;
  1400. this.unobservedData.$refs = this.getRefsProxy();
  1401. this.nextTickStack = [];
  1402. this.unobservedData.$nextTick = callback => {
  1403. this.nextTickStack.push(callback);
  1404. };
  1405. this.watchers = {};
  1406. this.unobservedData.$watch = (property, callback) => {
  1407. if (!this.watchers[property]) this.watchers[property] = [];
  1408. this.watchers[property].push(callback);
  1409. };
  1410. /* MODERN-ONLY:START */
  1411. // We remove this piece of code from the legacy build.
  1412. // In IE11, we have already defined our helpers at this point.
  1413. // Register custom magic properties.
  1414. Object.entries(Alpine.magicProperties).forEach(([name, callback]) => {
  1415. Object.defineProperty(this.unobservedData, `$${name}`, {
  1416. get: function get() {
  1417. return callback(canonicalComponentElementReference, this.$el);
  1418. }
  1419. });
  1420. });
  1421. /* MODERN-ONLY:END */
  1422. this.showDirectiveStack = [];
  1423. this.showDirectiveLastElement;
  1424. componentForClone || Alpine.onBeforeComponentInitializeds.forEach(callback => callback(this));
  1425. var initReturnedCallback; // If x-init is present AND we aren't cloning (skip x-init on clone)
  1426. if (initExpression && !componentForClone) {
  1427. // We want to allow data manipulation, but not trigger DOM updates just yet.
  1428. // We haven't even initialized the elements with their Alpine bindings. I mean c'mon.
  1429. this.pauseReactivity = true;
  1430. initReturnedCallback = this.evaluateReturnExpression(this.$el, initExpression);
  1431. this.pauseReactivity = false;
  1432. } // Register all our listeners and set all our attribute bindings.
  1433. this.initializeElements(this.$el); // Use mutation observer to detect new elements being added within this component at run-time.
  1434. // Alpine's just so darn flexible amirite?
  1435. this.listenForNewElementsToInitialize();
  1436. if (typeof initReturnedCallback === 'function') {
  1437. // Run the callback returned from the "x-init" hook to allow the user to do stuff after
  1438. // Alpine's got it's grubby little paws all over everything.
  1439. initReturnedCallback.call(this.$data);
  1440. }
  1441. componentForClone || setTimeout(() => {
  1442. Alpine.onComponentInitializeds.forEach(callback => callback(this));
  1443. }, 0);
  1444. }
  1445. getUnobservedData() {
  1446. return unwrap$1(this.membrane, this.$data);
  1447. }
  1448. wrapDataInObservable(data) {
  1449. var self = this;
  1450. let updateDom = debounce(function () {
  1451. self.updateElements(self.$el);
  1452. }, 0);
  1453. return wrap(data, (target, key) => {
  1454. if (self.watchers[key]) {
  1455. // If there's a watcher for this specific key, run it.
  1456. self.watchers[key].forEach(callback => callback(target[key]));
  1457. } else if (Array.isArray(target)) {
  1458. // Arrays are special cases, if any of the items change, we consider the array as mutated.
  1459. Object.keys(self.watchers).forEach(fullDotNotationKey => {
  1460. let dotNotationParts = fullDotNotationKey.split('.'); // Ignore length mutations since they would result in duplicate calls.
  1461. // For example, when calling push, we would get a mutation for the item's key
  1462. // and a second mutation for the length property.
  1463. if (key === 'length') return;
  1464. dotNotationParts.reduce((comparisonData, part) => {
  1465. if (Object.is(target, comparisonData[part])) {
  1466. self.watchers[fullDotNotationKey].forEach(callback => callback(target));
  1467. }
  1468. return comparisonData[part];
  1469. }, self.unobservedData);
  1470. });
  1471. } else {
  1472. // Let's walk through the watchers with "dot-notation" (foo.bar) and see
  1473. // if this mutation fits any of them.
  1474. Object.keys(self.watchers).filter(i => i.includes('.')).forEach(fullDotNotationKey => {
  1475. let dotNotationParts = fullDotNotationKey.split('.'); // If this dot-notation watcher's last "part" doesn't match the current
  1476. // key, then skip it early for performance reasons.
  1477. if (key !== dotNotationParts[dotNotationParts.length - 1]) return; // Now, walk through the dot-notation "parts" recursively to find
  1478. // a match, and call the watcher if one's found.
  1479. dotNotationParts.reduce((comparisonData, part) => {
  1480. if (Object.is(target, comparisonData)) {
  1481. // Run the watchers.
  1482. self.watchers[fullDotNotationKey].forEach(callback => callback(target[key]));
  1483. }
  1484. return comparisonData[part];
  1485. }, self.unobservedData);
  1486. });
  1487. } // Don't react to data changes for cases like the `x-created` hook.
  1488. if (self.pauseReactivity) return;
  1489. updateDom();
  1490. });
  1491. }
  1492. walkAndSkipNestedComponents(el, callback, initializeComponentCallback = () => {}) {
  1493. walk(el, el => {
  1494. // We've hit a component.
  1495. if (el.hasAttribute('x-data')) {
  1496. // If it's not the current one.
  1497. if (!el.isSameNode(this.$el)) {
  1498. // Initialize it if it's not.
  1499. if (!el.__x) initializeComponentCallback(el); // Now we'll let that sub-component deal with itself.
  1500. return false;
  1501. }
  1502. }
  1503. return callback(el);
  1504. });
  1505. }
  1506. initializeElements(rootEl, extraVars = () => {}) {
  1507. this.walkAndSkipNestedComponents(rootEl, el => {
  1508. // Don't touch spawns from for loop
  1509. if (el.__x_for_key !== undefined) return false; // Don't touch spawns from if directives
  1510. if (el.__x_inserted_me !== undefined) return false;
  1511. this.initializeElement(el, extraVars);
  1512. }, el => {
  1513. el.__x = new Component(el);
  1514. });
  1515. this.executeAndClearRemainingShowDirectiveStack();
  1516. this.executeAndClearNextTickStack(rootEl);
  1517. }
  1518. initializeElement(el, extraVars) {
  1519. // To support class attribute merging, we have to know what the element's
  1520. // original class attribute looked like for reference.
  1521. if (el.hasAttribute('class') && getXAttrs(el, this).length > 0) {
  1522. el.__x_original_classes = convertClassStringToArray(el.getAttribute('class'));
  1523. }
  1524. this.registerListeners(el, extraVars);
  1525. this.resolveBoundAttributes(el, true, extraVars);
  1526. }
  1527. updateElements(rootEl, extraVars = () => {}) {
  1528. this.walkAndSkipNestedComponents(rootEl, el => {
  1529. // Don't touch spawns from for loop (and check if the root is actually a for loop in a parent, don't skip it.)
  1530. if (el.__x_for_key !== undefined && !el.isSameNode(this.$el)) return false;
  1531. this.updateElement(el, extraVars);
  1532. }, el => {
  1533. el.__x = new Component(el);
  1534. });
  1535. this.executeAndClearRemainingShowDirectiveStack();
  1536. this.executeAndClearNextTickStack(rootEl);
  1537. }
  1538. executeAndClearNextTickStack(el) {
  1539. // Skip spawns from alpine directives
  1540. if (el === this.$el && this.nextTickStack.length > 0) {
  1541. // We run the tick stack after the next frame to allow any
  1542. // running transitions to pass the initial show stage.
  1543. requestAnimationFrame(() => {
  1544. while (this.nextTickStack.length > 0) {
  1545. this.nextTickStack.shift()();
  1546. }
  1547. });
  1548. }
  1549. }
  1550. executeAndClearRemainingShowDirectiveStack() {
  1551. // The goal here is to start all the x-show transitions
  1552. // and build a nested promise chain so that elements
  1553. // only hide when the children are finished hiding.
  1554. this.showDirectiveStack.reverse().map(handler => {
  1555. return new Promise((resolve, reject) => {
  1556. handler(resolve, reject);
  1557. });
  1558. }).reduce((promiseChain, promise) => {
  1559. return promiseChain.then(() => {
  1560. return promise.then(finishElement => {
  1561. finishElement();
  1562. });
  1563. });
  1564. }, Promise.resolve(() => {})).catch(e => {
  1565. if (e !== TRANSITION_CANCELLED) throw e;
  1566. }); // We've processed the handler stack. let's clear it.
  1567. this.showDirectiveStack = [];
  1568. this.showDirectiveLastElement = undefined;
  1569. }
  1570. updateElement(el, extraVars) {
  1571. this.resolveBoundAttributes(el, false, extraVars);
  1572. }
  1573. registerListeners(el, extraVars) {
  1574. getXAttrs(el, this).forEach(({
  1575. type,
  1576. value,
  1577. modifiers,
  1578. expression
  1579. }) => {
  1580. switch (type) {
  1581. case 'on':
  1582. registerListener(this, el, value, modifiers, expression, extraVars);
  1583. break;
  1584. case 'model':
  1585. registerModelListener(this, el, modifiers, expression, extraVars);
  1586. break;
  1587. }
  1588. });
  1589. }
  1590. resolveBoundAttributes(el, initialUpdate = false, extraVars) {
  1591. let attrs = getXAttrs(el, this);
  1592. attrs.forEach(({
  1593. type,
  1594. value,
  1595. modifiers,
  1596. expression
  1597. }) => {
  1598. switch (type) {
  1599. case 'model':
  1600. handleAttributeBindingDirective(this, el, 'value', expression, extraVars, type, modifiers);
  1601. break;
  1602. case 'bind':
  1603. // The :key binding on an x-for is special, ignore it.
  1604. if (el.tagName.toLowerCase() === 'template' && value === 'key') return;
  1605. handleAttributeBindingDirective(this, el, value, expression, extraVars, type, modifiers);
  1606. break;
  1607. case 'text':
  1608. var output = this.evaluateReturnExpression(el, expression, extraVars);
  1609. handleTextDirective(el, output, expression);
  1610. break;
  1611. case 'html':
  1612. handleHtmlDirective(this, el, expression, extraVars);
  1613. break;
  1614. case 'show':
  1615. var output = this.evaluateReturnExpression(el, expression, extraVars);
  1616. handleShowDirective(this, el, output, modifiers, initialUpdate);
  1617. break;
  1618. case 'if':
  1619. // If this element also has x-for on it, don't process x-if.
  1620. // We will let the "x-for" directive handle the "if"ing.
  1621. if (attrs.some(i => i.type === 'for')) return;
  1622. var output = this.evaluateReturnExpression(el, expression, extraVars);
  1623. handleIfDirective(this, el, output, initialUpdate, extraVars);
  1624. break;
  1625. case 'for':
  1626. handleForDirective(this, el, expression, initialUpdate, extraVars);
  1627. break;
  1628. case 'cloak':
  1629. el.removeAttribute('x-cloak');
  1630. break;
  1631. }
  1632. });
  1633. }
  1634. evaluateReturnExpression(el, expression, extraVars = () => {}) {
  1635. return saferEval(el, expression, this.$data, _objectSpread2(_objectSpread2({}, extraVars()), {}, {
  1636. $dispatch: this.getDispatchFunction(el)
  1637. }));
  1638. }
  1639. evaluateCommandExpression(el, expression, extraVars = () => {}) {
  1640. return saferEvalNoReturn(el, expression, this.$data, _objectSpread2(_objectSpread2({}, extraVars()), {}, {
  1641. $dispatch: this.getDispatchFunction(el)
  1642. }));
  1643. }
  1644. getDispatchFunction(el) {
  1645. return (event, detail = {}) => {
  1646. el.dispatchEvent(new CustomEvent(event, {
  1647. detail,
  1648. bubbles: true
  1649. }));
  1650. };
  1651. }
  1652. listenForNewElementsToInitialize() {
  1653. const targetNode = this.$el;
  1654. const observerOptions = {
  1655. childList: true,
  1656. attributes: true,
  1657. subtree: true
  1658. };
  1659. const observer = new MutationObserver(mutations => {
  1660. for (let i = 0; i < mutations.length; i++) {
  1661. // Filter out mutations triggered from child components.
  1662. const closestParentComponent = mutations[i].target.closest('[x-data]');
  1663. if (!(closestParentComponent && closestParentComponent.isSameNode(this.$el))) continue;
  1664. if (mutations[i].type === 'attributes' && mutations[i].attributeName === 'x-data') {
  1665. const xAttr = mutations[i].target.getAttribute('x-data') || '{}';
  1666. const rawData = saferEval(this.$el, xAttr, {
  1667. $el: this.$el
  1668. });
  1669. Object.keys(rawData).forEach(key => {
  1670. if (this.$data[key] !== rawData[key]) {
  1671. this.$data[key] = rawData[key];
  1672. }
  1673. });
  1674. }
  1675. if (mutations[i].addedNodes.length > 0) {
  1676. mutations[i].addedNodes.forEach(node => {
  1677. if (node.nodeType !== 1 || node.__x_inserted_me) return;
  1678. if (node.matches('[x-data]') && !node.__x) {
  1679. node.__x = new Component(node);
  1680. return;
  1681. }
  1682. this.initializeElements(node);
  1683. });
  1684. }
  1685. }
  1686. });
  1687. observer.observe(targetNode, observerOptions);
  1688. }
  1689. getRefsProxy() {
  1690. var self = this;
  1691. var refObj = {};
  1692. // One of the goals of this is to not hold elements in memory, but rather re-evaluate
  1693. // the DOM when the system needs something from it. This way, the framework is flexible and
  1694. // friendly to outside DOM changes from libraries like Vue/Livewire.
  1695. // For this reason, I'm using an "on-demand" proxy to fake a "$refs" object.
  1696. return new Proxy(refObj, {
  1697. get(object, property) {
  1698. if (property === '$isAlpineProxy') return true;
  1699. var ref; // We can't just query the DOM because it's hard to filter out refs in
  1700. // nested components.
  1701. self.walkAndSkipNestedComponents(self.$el, el => {
  1702. if (el.hasAttribute('x-ref') && el.getAttribute('x-ref') === property) {
  1703. ref = el;
  1704. }
  1705. });
  1706. return ref;
  1707. }
  1708. });
  1709. }
  1710. }
  1711. const Alpine = {
  1712. version: "2.8.0",
  1713. pauseMutationObserver: false,
  1714. magicProperties: {},
  1715. onComponentInitializeds: [],
  1716. onBeforeComponentInitializeds: [],
  1717. ignoreFocusedForValueBinding: false,
  1718. start: async function start() {
  1719. if (!isTesting()) {
  1720. await domReady();
  1721. }
  1722. this.discoverComponents(el => {
  1723. this.initializeComponent(el);
  1724. }); // It's easier and more performant to just support Turbolinks than listen
  1725. // to MutationObserver mutations at the document level.
  1726. document.addEventListener("turbolinks:load", () => {
  1727. this.discoverUninitializedComponents(el => {
  1728. this.initializeComponent(el);
  1729. });
  1730. });
  1731. this.listenForNewUninitializedComponentsAtRunTime();
  1732. },
  1733. discoverComponents: function discoverComponents(callback) {
  1734. const rootEls = document.querySelectorAll('[x-data]');
  1735. rootEls.forEach(rootEl => {
  1736. callback(rootEl);
  1737. });
  1738. },
  1739. discoverUninitializedComponents: function discoverUninitializedComponents(callback, el = null) {
  1740. const rootEls = (el || document).querySelectorAll('[x-data]');
  1741. Array.from(rootEls).filter(el => el.__x === undefined).forEach(rootEl => {
  1742. callback(rootEl);
  1743. });
  1744. },
  1745. listenForNewUninitializedComponentsAtRunTime: function listenForNewUninitializedComponentsAtRunTime() {
  1746. const targetNode = document.querySelector('body');
  1747. const observerOptions = {
  1748. childList: true,
  1749. attributes: true,
  1750. subtree: true
  1751. };
  1752. const observer = new MutationObserver(mutations => {
  1753. if (this.pauseMutationObserver) return;
  1754. for (let i = 0; i < mutations.length; i++) {
  1755. if (mutations[i].addedNodes.length > 0) {
  1756. mutations[i].addedNodes.forEach(node => {
  1757. // Discard non-element nodes (like line-breaks)
  1758. if (node.nodeType !== 1) return; // Discard any changes happening within an existing component.
  1759. // They will take care of themselves.
  1760. if (node.parentElement && node.parentElement.closest('[x-data]')) return;
  1761. this.discoverUninitializedComponents(el => {
  1762. this.initializeComponent(el);
  1763. }, node.parentElement);
  1764. });
  1765. }
  1766. }
  1767. });
  1768. observer.observe(targetNode, observerOptions);
  1769. },
  1770. initializeComponent: function initializeComponent(el) {
  1771. if (!el.__x) {
  1772. // Wrap in a try/catch so that we don't prevent other components
  1773. // from initializing when one component contains an error.
  1774. try {
  1775. el.__x = new Component(el);
  1776. } catch (error) {
  1777. setTimeout(() => {
  1778. throw error;
  1779. }, 0);
  1780. }
  1781. }
  1782. },
  1783. clone: function clone(component, newEl) {
  1784. if (!newEl.__x) {
  1785. newEl.__x = new Component(newEl, component);
  1786. }
  1787. },
  1788. addMagicProperty: function addMagicProperty(name, callback) {
  1789. this.magicProperties[name] = callback;
  1790. },
  1791. onComponentInitialized: function onComponentInitialized(callback) {
  1792. this.onComponentInitializeds.push(callback);
  1793. },
  1794. onBeforeComponentInitialized: function onBeforeComponentInitialized(callback) {
  1795. this.onBeforeComponentInitializeds.push(callback);
  1796. }
  1797. };
  1798. if (!isTesting()) {
  1799. window.Alpine = Alpine;
  1800. if (window.deferLoadingAlpine) {
  1801. window.deferLoadingAlpine(function () {
  1802. window.Alpine.start();
  1803. });
  1804. } else {
  1805. window.Alpine.start();
  1806. }
  1807. }
  1808. return Alpine;
  1809. })));
  1810. /***/ }),
  1811. /***/ "./node_modules/axios/index.js":
  1812. /*!*************************************!*\
  1813. !*** ./node_modules/axios/index.js ***!
  1814. \*************************************/
  1815. /*! no static exports found */
  1816. /***/ (function(module, exports, __webpack_require__) {
  1817. module.exports = __webpack_require__(/*! ./lib/axios */ "./node_modules/axios/lib/axios.js");
  1818. /***/ }),
  1819. /***/ "./node_modules/axios/lib/adapters/xhr.js":
  1820. /*!************************************************!*\
  1821. !*** ./node_modules/axios/lib/adapters/xhr.js ***!
  1822. \************************************************/
  1823. /*! no static exports found */
  1824. /***/ (function(module, exports, __webpack_require__) {
  1825. "use strict";
  1826. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1827. var settle = __webpack_require__(/*! ./../core/settle */ "./node_modules/axios/lib/core/settle.js");
  1828. var buildURL = __webpack_require__(/*! ./../helpers/buildURL */ "./node_modules/axios/lib/helpers/buildURL.js");
  1829. var buildFullPath = __webpack_require__(/*! ../core/buildFullPath */ "./node_modules/axios/lib/core/buildFullPath.js");
  1830. var parseHeaders = __webpack_require__(/*! ./../helpers/parseHeaders */ "./node_modules/axios/lib/helpers/parseHeaders.js");
  1831. var isURLSameOrigin = __webpack_require__(/*! ./../helpers/isURLSameOrigin */ "./node_modules/axios/lib/helpers/isURLSameOrigin.js");
  1832. var createError = __webpack_require__(/*! ../core/createError */ "./node_modules/axios/lib/core/createError.js");
  1833. module.exports = function xhrAdapter(config) {
  1834. return new Promise(function dispatchXhrRequest(resolve, reject) {
  1835. var requestData = config.data;
  1836. var requestHeaders = config.headers;
  1837. if (utils.isFormData(requestData)) {
  1838. delete requestHeaders['Content-Type']; // Let the browser set it
  1839. }
  1840. var request = new XMLHttpRequest();
  1841. // HTTP basic authentication
  1842. if (config.auth) {
  1843. var username = config.auth.username || '';
  1844. var password = config.auth.password || '';
  1845. requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
  1846. }
  1847. var fullPath = buildFullPath(config.baseURL, config.url);
  1848. request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
  1849. // Set the request timeout in MS
  1850. request.timeout = config.timeout;
  1851. // Listen for ready state
  1852. request.onreadystatechange = function handleLoad() {
  1853. if (!request || request.readyState !== 4) {
  1854. return;
  1855. }
  1856. // The request errored out and we didn't get a response, this will be
  1857. // handled by onerror instead
  1858. // With one exception: request that using file: protocol, most browsers
  1859. // will return status as 0 even though it's a successful request
  1860. if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
  1861. return;
  1862. }
  1863. // Prepare the response
  1864. var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
  1865. var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
  1866. var response = {
  1867. data: responseData,
  1868. status: request.status,
  1869. statusText: request.statusText,
  1870. headers: responseHeaders,
  1871. config: config,
  1872. request: request
  1873. };
  1874. settle(resolve, reject, response);
  1875. // Clean up request
  1876. request = null;
  1877. };
  1878. // Handle browser request cancellation (as opposed to a manual cancellation)
  1879. request.onabort = function handleAbort() {
  1880. if (!request) {
  1881. return;
  1882. }
  1883. reject(createError('Request aborted', config, 'ECONNABORTED', request));
  1884. // Clean up request
  1885. request = null;
  1886. };
  1887. // Handle low level network errors
  1888. request.onerror = function handleError() {
  1889. // Real errors are hidden from us by the browser
  1890. // onerror should only fire if it's a network error
  1891. reject(createError('Network Error', config, null, request));
  1892. // Clean up request
  1893. request = null;
  1894. };
  1895. // Handle timeout
  1896. request.ontimeout = function handleTimeout() {
  1897. var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
  1898. if (config.timeoutErrorMessage) {
  1899. timeoutErrorMessage = config.timeoutErrorMessage;
  1900. }
  1901. reject(createError(timeoutErrorMessage, config, 'ECONNABORTED',
  1902. request));
  1903. // Clean up request
  1904. request = null;
  1905. };
  1906. // Add xsrf header
  1907. // This is only done if running in a standard browser environment.
  1908. // Specifically not if we're in a web worker, or react-native.
  1909. if (utils.isStandardBrowserEnv()) {
  1910. var cookies = __webpack_require__(/*! ./../helpers/cookies */ "./node_modules/axios/lib/helpers/cookies.js");
  1911. // Add xsrf header
  1912. var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
  1913. cookies.read(config.xsrfCookieName) :
  1914. undefined;
  1915. if (xsrfValue) {
  1916. requestHeaders[config.xsrfHeaderName] = xsrfValue;
  1917. }
  1918. }
  1919. // Add headers to the request
  1920. if ('setRequestHeader' in request) {
  1921. utils.forEach(requestHeaders, function setRequestHeader(val, key) {
  1922. if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
  1923. // Remove Content-Type if data is undefined
  1924. delete requestHeaders[key];
  1925. } else {
  1926. // Otherwise add header to the request
  1927. request.setRequestHeader(key, val);
  1928. }
  1929. });
  1930. }
  1931. // Add withCredentials to request if needed
  1932. if (!utils.isUndefined(config.withCredentials)) {
  1933. request.withCredentials = !!config.withCredentials;
  1934. }
  1935. // Add responseType to request if needed
  1936. if (config.responseType) {
  1937. try {
  1938. request.responseType = config.responseType;
  1939. } catch (e) {
  1940. // Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.
  1941. // But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.
  1942. if (config.responseType !== 'json') {
  1943. throw e;
  1944. }
  1945. }
  1946. }
  1947. // Handle progress if needed
  1948. if (typeof config.onDownloadProgress === 'function') {
  1949. request.addEventListener('progress', config.onDownloadProgress);
  1950. }
  1951. // Not all browsers support upload events
  1952. if (typeof config.onUploadProgress === 'function' && request.upload) {
  1953. request.upload.addEventListener('progress', config.onUploadProgress);
  1954. }
  1955. if (config.cancelToken) {
  1956. // Handle cancellation
  1957. config.cancelToken.promise.then(function onCanceled(cancel) {
  1958. if (!request) {
  1959. return;
  1960. }
  1961. request.abort();
  1962. reject(cancel);
  1963. // Clean up request
  1964. request = null;
  1965. });
  1966. }
  1967. if (requestData === undefined) {
  1968. requestData = null;
  1969. }
  1970. // Send the request
  1971. request.send(requestData);
  1972. });
  1973. };
  1974. /***/ }),
  1975. /***/ "./node_modules/axios/lib/axios.js":
  1976. /*!*****************************************!*\
  1977. !*** ./node_modules/axios/lib/axios.js ***!
  1978. \*****************************************/
  1979. /*! no static exports found */
  1980. /***/ (function(module, exports, __webpack_require__) {
  1981. "use strict";
  1982. var utils = __webpack_require__(/*! ./utils */ "./node_modules/axios/lib/utils.js");
  1983. var bind = __webpack_require__(/*! ./helpers/bind */ "./node_modules/axios/lib/helpers/bind.js");
  1984. var Axios = __webpack_require__(/*! ./core/Axios */ "./node_modules/axios/lib/core/Axios.js");
  1985. var mergeConfig = __webpack_require__(/*! ./core/mergeConfig */ "./node_modules/axios/lib/core/mergeConfig.js");
  1986. var defaults = __webpack_require__(/*! ./defaults */ "./node_modules/axios/lib/defaults.js");
  1987. /**
  1988. * Create an instance of Axios
  1989. *
  1990. * @param {Object} defaultConfig The default config for the instance
  1991. * @return {Axios} A new instance of Axios
  1992. */
  1993. function createInstance(defaultConfig) {
  1994. var context = new Axios(defaultConfig);
  1995. var instance = bind(Axios.prototype.request, context);
  1996. // Copy axios.prototype to instance
  1997. utils.extend(instance, Axios.prototype, context);
  1998. // Copy context to instance
  1999. utils.extend(instance, context);
  2000. return instance;
  2001. }
  2002. // Create the default instance to be exported
  2003. var axios = createInstance(defaults);
  2004. // Expose Axios class to allow class inheritance
  2005. axios.Axios = Axios;
  2006. // Factory for creating new instances
  2007. axios.create = function create(instanceConfig) {
  2008. return createInstance(mergeConfig(axios.defaults, instanceConfig));
  2009. };
  2010. // Expose Cancel & CancelToken
  2011. axios.Cancel = __webpack_require__(/*! ./cancel/Cancel */ "./node_modules/axios/lib/cancel/Cancel.js");
  2012. axios.CancelToken = __webpack_require__(/*! ./cancel/CancelToken */ "./node_modules/axios/lib/cancel/CancelToken.js");
  2013. axios.isCancel = __webpack_require__(/*! ./cancel/isCancel */ "./node_modules/axios/lib/cancel/isCancel.js");
  2014. // Expose all/spread
  2015. axios.all = function all(promises) {
  2016. return Promise.all(promises);
  2017. };
  2018. axios.spread = __webpack_require__(/*! ./helpers/spread */ "./node_modules/axios/lib/helpers/spread.js");
  2019. module.exports = axios;
  2020. // Allow use of default import syntax in TypeScript
  2021. module.exports.default = axios;
  2022. /***/ }),
  2023. /***/ "./node_modules/axios/lib/cancel/Cancel.js":
  2024. /*!*************************************************!*\
  2025. !*** ./node_modules/axios/lib/cancel/Cancel.js ***!
  2026. \*************************************************/
  2027. /*! no static exports found */
  2028. /***/ (function(module, exports, __webpack_require__) {
  2029. "use strict";
  2030. /**
  2031. * A `Cancel` is an object that is thrown when an operation is canceled.
  2032. *
  2033. * @class
  2034. * @param {string=} message The message.
  2035. */
  2036. function Cancel(message) {
  2037. this.message = message;
  2038. }
  2039. Cancel.prototype.toString = function toString() {
  2040. return 'Cancel' + (this.message ? ': ' + this.message : '');
  2041. };
  2042. Cancel.prototype.__CANCEL__ = true;
  2043. module.exports = Cancel;
  2044. /***/ }),
  2045. /***/ "./node_modules/axios/lib/cancel/CancelToken.js":
  2046. /*!******************************************************!*\
  2047. !*** ./node_modules/axios/lib/cancel/CancelToken.js ***!
  2048. \******************************************************/
  2049. /*! no static exports found */
  2050. /***/ (function(module, exports, __webpack_require__) {
  2051. "use strict";
  2052. var Cancel = __webpack_require__(/*! ./Cancel */ "./node_modules/axios/lib/cancel/Cancel.js");
  2053. /**
  2054. * A `CancelToken` is an object that can be used to request cancellation of an operation.
  2055. *
  2056. * @class
  2057. * @param {Function} executor The executor function.
  2058. */
  2059. function CancelToken(executor) {
  2060. if (typeof executor !== 'function') {
  2061. throw new TypeError('executor must be a function.');
  2062. }
  2063. var resolvePromise;
  2064. this.promise = new Promise(function promiseExecutor(resolve) {
  2065. resolvePromise = resolve;
  2066. });
  2067. var token = this;
  2068. executor(function cancel(message) {
  2069. if (token.reason) {
  2070. // Cancellation has already been requested
  2071. return;
  2072. }
  2073. token.reason = new Cancel(message);
  2074. resolvePromise(token.reason);
  2075. });
  2076. }
  2077. /**
  2078. * Throws a `Cancel` if cancellation has been requested.
  2079. */
  2080. CancelToken.prototype.throwIfRequested = function throwIfRequested() {
  2081. if (this.reason) {
  2082. throw this.reason;
  2083. }
  2084. };
  2085. /**
  2086. * Returns an object that contains a new `CancelToken` and a function that, when called,
  2087. * cancels the `CancelToken`.
  2088. */
  2089. CancelToken.source = function source() {
  2090. var cancel;
  2091. var token = new CancelToken(function executor(c) {
  2092. cancel = c;
  2093. });
  2094. return {
  2095. token: token,
  2096. cancel: cancel
  2097. };
  2098. };
  2099. module.exports = CancelToken;
  2100. /***/ }),
  2101. /***/ "./node_modules/axios/lib/cancel/isCancel.js":
  2102. /*!***************************************************!*\
  2103. !*** ./node_modules/axios/lib/cancel/isCancel.js ***!
  2104. \***************************************************/
  2105. /*! no static exports found */
  2106. /***/ (function(module, exports, __webpack_require__) {
  2107. "use strict";
  2108. module.exports = function isCancel(value) {
  2109. return !!(value && value.__CANCEL__);
  2110. };
  2111. /***/ }),
  2112. /***/ "./node_modules/axios/lib/core/Axios.js":
  2113. /*!**********************************************!*\
  2114. !*** ./node_modules/axios/lib/core/Axios.js ***!
  2115. \**********************************************/
  2116. /*! no static exports found */
  2117. /***/ (function(module, exports, __webpack_require__) {
  2118. "use strict";
  2119. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2120. var buildURL = __webpack_require__(/*! ../helpers/buildURL */ "./node_modules/axios/lib/helpers/buildURL.js");
  2121. var InterceptorManager = __webpack_require__(/*! ./InterceptorManager */ "./node_modules/axios/lib/core/InterceptorManager.js");
  2122. var dispatchRequest = __webpack_require__(/*! ./dispatchRequest */ "./node_modules/axios/lib/core/dispatchRequest.js");
  2123. var mergeConfig = __webpack_require__(/*! ./mergeConfig */ "./node_modules/axios/lib/core/mergeConfig.js");
  2124. /**
  2125. * Create a new instance of Axios
  2126. *
  2127. * @param {Object} instanceConfig The default config for the instance
  2128. */
  2129. function Axios(instanceConfig) {
  2130. this.defaults = instanceConfig;
  2131. this.interceptors = {
  2132. request: new InterceptorManager(),
  2133. response: new InterceptorManager()
  2134. };
  2135. }
  2136. /**
  2137. * Dispatch a request
  2138. *
  2139. * @param {Object} config The config specific for this request (merged with this.defaults)
  2140. */
  2141. Axios.prototype.request = function request(config) {
  2142. /*eslint no-param-reassign:0*/
  2143. // Allow for axios('example/url'[, config]) a la fetch API
  2144. if (typeof config === 'string') {
  2145. config = arguments[1] || {};
  2146. config.url = arguments[0];
  2147. } else {
  2148. config = config || {};
  2149. }
  2150. config = mergeConfig(this.defaults, config);
  2151. // Set config.method
  2152. if (config.method) {
  2153. config.method = config.method.toLowerCase();
  2154. } else if (this.defaults.method) {
  2155. config.method = this.defaults.method.toLowerCase();
  2156. } else {
  2157. config.method = 'get';
  2158. }
  2159. // Hook up interceptors middleware
  2160. var chain = [dispatchRequest, undefined];
  2161. var promise = Promise.resolve(config);
  2162. this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
  2163. chain.unshift(interceptor.fulfilled, interceptor.rejected);
  2164. });
  2165. this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
  2166. chain.push(interceptor.fulfilled, interceptor.rejected);
  2167. });
  2168. while (chain.length) {
  2169. promise = promise.then(chain.shift(), chain.shift());
  2170. }
  2171. return promise;
  2172. };
  2173. Axios.prototype.getUri = function getUri(config) {
  2174. config = mergeConfig(this.defaults, config);
  2175. return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
  2176. };
  2177. // Provide aliases for supported request methods
  2178. utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
  2179. /*eslint func-names:0*/
  2180. Axios.prototype[method] = function(url, config) {
  2181. return this.request(utils.merge(config || {}, {
  2182. method: method,
  2183. url: url
  2184. }));
  2185. };
  2186. });
  2187. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  2188. /*eslint func-names:0*/
  2189. Axios.prototype[method] = function(url, data, config) {
  2190. return this.request(utils.merge(config || {}, {
  2191. method: method,
  2192. url: url,
  2193. data: data
  2194. }));
  2195. };
  2196. });
  2197. module.exports = Axios;
  2198. /***/ }),
  2199. /***/ "./node_modules/axios/lib/core/InterceptorManager.js":
  2200. /*!***********************************************************!*\
  2201. !*** ./node_modules/axios/lib/core/InterceptorManager.js ***!
  2202. \***********************************************************/
  2203. /*! no static exports found */
  2204. /***/ (function(module, exports, __webpack_require__) {
  2205. "use strict";
  2206. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2207. function InterceptorManager() {
  2208. this.handlers = [];
  2209. }
  2210. /**
  2211. * Add a new interceptor to the stack
  2212. *
  2213. * @param {Function} fulfilled The function to handle `then` for a `Promise`
  2214. * @param {Function} rejected The function to handle `reject` for a `Promise`
  2215. *
  2216. * @return {Number} An ID used to remove interceptor later
  2217. */
  2218. InterceptorManager.prototype.use = function use(fulfilled, rejected) {
  2219. this.handlers.push({
  2220. fulfilled: fulfilled,
  2221. rejected: rejected
  2222. });
  2223. return this.handlers.length - 1;
  2224. };
  2225. /**
  2226. * Remove an interceptor from the stack
  2227. *
  2228. * @param {Number} id The ID that was returned by `use`
  2229. */
  2230. InterceptorManager.prototype.eject = function eject(id) {
  2231. if (this.handlers[id]) {
  2232. this.handlers[id] = null;
  2233. }
  2234. };
  2235. /**
  2236. * Iterate over all the registered interceptors
  2237. *
  2238. * This method is particularly useful for skipping over any
  2239. * interceptors that may have become `null` calling `eject`.
  2240. *
  2241. * @param {Function} fn The function to call for each interceptor
  2242. */
  2243. InterceptorManager.prototype.forEach = function forEach(fn) {
  2244. utils.forEach(this.handlers, function forEachHandler(h) {
  2245. if (h !== null) {
  2246. fn(h);
  2247. }
  2248. });
  2249. };
  2250. module.exports = InterceptorManager;
  2251. /***/ }),
  2252. /***/ "./node_modules/axios/lib/core/buildFullPath.js":
  2253. /*!******************************************************!*\
  2254. !*** ./node_modules/axios/lib/core/buildFullPath.js ***!
  2255. \******************************************************/
  2256. /*! no static exports found */
  2257. /***/ (function(module, exports, __webpack_require__) {
  2258. "use strict";
  2259. var isAbsoluteURL = __webpack_require__(/*! ../helpers/isAbsoluteURL */ "./node_modules/axios/lib/helpers/isAbsoluteURL.js");
  2260. var combineURLs = __webpack_require__(/*! ../helpers/combineURLs */ "./node_modules/axios/lib/helpers/combineURLs.js");
  2261. /**
  2262. * Creates a new URL by combining the baseURL with the requestedURL,
  2263. * only when the requestedURL is not already an absolute URL.
  2264. * If the requestURL is absolute, this function returns the requestedURL untouched.
  2265. *
  2266. * @param {string} baseURL The base URL
  2267. * @param {string} requestedURL Absolute or relative URL to combine
  2268. * @returns {string} The combined full path
  2269. */
  2270. module.exports = function buildFullPath(baseURL, requestedURL) {
  2271. if (baseURL && !isAbsoluteURL(requestedURL)) {
  2272. return combineURLs(baseURL, requestedURL);
  2273. }
  2274. return requestedURL;
  2275. };
  2276. /***/ }),
  2277. /***/ "./node_modules/axios/lib/core/createError.js":
  2278. /*!****************************************************!*\
  2279. !*** ./node_modules/axios/lib/core/createError.js ***!
  2280. \****************************************************/
  2281. /*! no static exports found */
  2282. /***/ (function(module, exports, __webpack_require__) {
  2283. "use strict";
  2284. var enhanceError = __webpack_require__(/*! ./enhanceError */ "./node_modules/axios/lib/core/enhanceError.js");
  2285. /**
  2286. * Create an Error with the specified message, config, error code, request and response.
  2287. *
  2288. * @param {string} message The error message.
  2289. * @param {Object} config The config.
  2290. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  2291. * @param {Object} [request] The request.
  2292. * @param {Object} [response] The response.
  2293. * @returns {Error} The created error.
  2294. */
  2295. module.exports = function createError(message, config, code, request, response) {
  2296. var error = new Error(message);
  2297. return enhanceError(error, config, code, request, response);
  2298. };
  2299. /***/ }),
  2300. /***/ "./node_modules/axios/lib/core/dispatchRequest.js":
  2301. /*!********************************************************!*\
  2302. !*** ./node_modules/axios/lib/core/dispatchRequest.js ***!
  2303. \********************************************************/
  2304. /*! no static exports found */
  2305. /***/ (function(module, exports, __webpack_require__) {
  2306. "use strict";
  2307. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2308. var transformData = __webpack_require__(/*! ./transformData */ "./node_modules/axios/lib/core/transformData.js");
  2309. var isCancel = __webpack_require__(/*! ../cancel/isCancel */ "./node_modules/axios/lib/cancel/isCancel.js");
  2310. var defaults = __webpack_require__(/*! ../defaults */ "./node_modules/axios/lib/defaults.js");
  2311. /**
  2312. * Throws a `Cancel` if cancellation has been requested.
  2313. */
  2314. function throwIfCancellationRequested(config) {
  2315. if (config.cancelToken) {
  2316. config.cancelToken.throwIfRequested();
  2317. }
  2318. }
  2319. /**
  2320. * Dispatch a request to the server using the configured adapter.
  2321. *
  2322. * @param {object} config The config that is to be used for the request
  2323. * @returns {Promise} The Promise to be fulfilled
  2324. */
  2325. module.exports = function dispatchRequest(config) {
  2326. throwIfCancellationRequested(config);
  2327. // Ensure headers exist
  2328. config.headers = config.headers || {};
  2329. // Transform request data
  2330. config.data = transformData(
  2331. config.data,
  2332. config.headers,
  2333. config.transformRequest
  2334. );
  2335. // Flatten headers
  2336. config.headers = utils.merge(
  2337. config.headers.common || {},
  2338. config.headers[config.method] || {},
  2339. config.headers
  2340. );
  2341. utils.forEach(
  2342. ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
  2343. function cleanHeaderConfig(method) {
  2344. delete config.headers[method];
  2345. }
  2346. );
  2347. var adapter = config.adapter || defaults.adapter;
  2348. return adapter(config).then(function onAdapterResolution(response) {
  2349. throwIfCancellationRequested(config);
  2350. // Transform response data
  2351. response.data = transformData(
  2352. response.data,
  2353. response.headers,
  2354. config.transformResponse
  2355. );
  2356. return response;
  2357. }, function onAdapterRejection(reason) {
  2358. if (!isCancel(reason)) {
  2359. throwIfCancellationRequested(config);
  2360. // Transform response data
  2361. if (reason && reason.response) {
  2362. reason.response.data = transformData(
  2363. reason.response.data,
  2364. reason.response.headers,
  2365. config.transformResponse
  2366. );
  2367. }
  2368. }
  2369. return Promise.reject(reason);
  2370. });
  2371. };
  2372. /***/ }),
  2373. /***/ "./node_modules/axios/lib/core/enhanceError.js":
  2374. /*!*****************************************************!*\
  2375. !*** ./node_modules/axios/lib/core/enhanceError.js ***!
  2376. \*****************************************************/
  2377. /*! no static exports found */
  2378. /***/ (function(module, exports, __webpack_require__) {
  2379. "use strict";
  2380. /**
  2381. * Update an Error with the specified config, error code, and response.
  2382. *
  2383. * @param {Error} error The error to update.
  2384. * @param {Object} config The config.
  2385. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  2386. * @param {Object} [request] The request.
  2387. * @param {Object} [response] The response.
  2388. * @returns {Error} The error.
  2389. */
  2390. module.exports = function enhanceError(error, config, code, request, response) {
  2391. error.config = config;
  2392. if (code) {
  2393. error.code = code;
  2394. }
  2395. error.request = request;
  2396. error.response = response;
  2397. error.isAxiosError = true;
  2398. error.toJSON = function() {
  2399. return {
  2400. // Standard
  2401. message: this.message,
  2402. name: this.name,
  2403. // Microsoft
  2404. description: this.description,
  2405. number: this.number,
  2406. // Mozilla
  2407. fileName: this.fileName,
  2408. lineNumber: this.lineNumber,
  2409. columnNumber: this.columnNumber,
  2410. stack: this.stack,
  2411. // Axios
  2412. config: this.config,
  2413. code: this.code
  2414. };
  2415. };
  2416. return error;
  2417. };
  2418. /***/ }),
  2419. /***/ "./node_modules/axios/lib/core/mergeConfig.js":
  2420. /*!****************************************************!*\
  2421. !*** ./node_modules/axios/lib/core/mergeConfig.js ***!
  2422. \****************************************************/
  2423. /*! no static exports found */
  2424. /***/ (function(module, exports, __webpack_require__) {
  2425. "use strict";
  2426. var utils = __webpack_require__(/*! ../utils */ "./node_modules/axios/lib/utils.js");
  2427. /**
  2428. * Config-specific merge-function which creates a new config-object
  2429. * by merging two configuration objects together.
  2430. *
  2431. * @param {Object} config1
  2432. * @param {Object} config2
  2433. * @returns {Object} New object resulting from merging config2 to config1
  2434. */
  2435. module.exports = function mergeConfig(config1, config2) {
  2436. // eslint-disable-next-line no-param-reassign
  2437. config2 = config2 || {};
  2438. var config = {};
  2439. var valueFromConfig2Keys = ['url', 'method', 'params', 'data'];
  2440. var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy'];
  2441. var defaultToConfig2Keys = [
  2442. 'baseURL', 'url', 'transformRequest', 'transformResponse', 'paramsSerializer',
  2443. 'timeout', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
  2444. 'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress',
  2445. 'maxContentLength', 'validateStatus', 'maxRedirects', 'httpAgent',
  2446. 'httpsAgent', 'cancelToken', 'socketPath'
  2447. ];
  2448. utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) {
  2449. if (typeof config2[prop] !== 'undefined') {
  2450. config[prop] = config2[prop];
  2451. }
  2452. });
  2453. utils.forEach(mergeDeepPropertiesKeys, function mergeDeepProperties(prop) {
  2454. if (utils.isObject(config2[prop])) {
  2455. config[prop] = utils.deepMerge(config1[prop], config2[prop]);
  2456. } else if (typeof config2[prop] !== 'undefined') {
  2457. config[prop] = config2[prop];
  2458. } else if (utils.isObject(config1[prop])) {
  2459. config[prop] = utils.deepMerge(config1[prop]);
  2460. } else if (typeof config1[prop] !== 'undefined') {
  2461. config[prop] = config1[prop];
  2462. }
  2463. });
  2464. utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
  2465. if (typeof config2[prop] !== 'undefined') {
  2466. config[prop] = config2[prop];
  2467. } else if (typeof config1[prop] !== 'undefined') {
  2468. config[prop] = config1[prop];
  2469. }
  2470. });
  2471. var axiosKeys = valueFromConfig2Keys
  2472. .concat(mergeDeepPropertiesKeys)
  2473. .concat(defaultToConfig2Keys);
  2474. var otherKeys = Object
  2475. .keys(config2)
  2476. .filter(function filterAxiosKeys(key) {
  2477. return axiosKeys.indexOf(key) === -1;
  2478. });
  2479. utils.forEach(otherKeys, function otherKeysDefaultToConfig2(prop) {
  2480. if (typeof config2[prop] !== 'undefined') {
  2481. config[prop] = config2[prop];
  2482. } else if (typeof config1[prop] !== 'undefined') {
  2483. config[prop] = config1[prop];
  2484. }
  2485. });
  2486. return config;
  2487. };
  2488. /***/ }),
  2489. /***/ "./node_modules/axios/lib/core/settle.js":
  2490. /*!***********************************************!*\
  2491. !*** ./node_modules/axios/lib/core/settle.js ***!
  2492. \***********************************************/
  2493. /*! no static exports found */
  2494. /***/ (function(module, exports, __webpack_require__) {
  2495. "use strict";
  2496. var createError = __webpack_require__(/*! ./createError */ "./node_modules/axios/lib/core/createError.js");
  2497. /**
  2498. * Resolve or reject a Promise based on response status.
  2499. *
  2500. * @param {Function} resolve A function that resolves the promise.
  2501. * @param {Function} reject A function that rejects the promise.
  2502. * @param {object} response The response.
  2503. */
  2504. module.exports = function settle(resolve, reject, response) {
  2505. var validateStatus = response.config.validateStatus;
  2506. if (!validateStatus || validateStatus(response.status)) {
  2507. resolve(response);
  2508. } else {
  2509. reject(createError(
  2510. 'Request failed with status code ' + response.status,
  2511. response.config,
  2512. null,
  2513. response.request,
  2514. response
  2515. ));
  2516. }
  2517. };
  2518. /***/ }),
  2519. /***/ "./node_modules/axios/lib/core/transformData.js":
  2520. /*!******************************************************!*\
  2521. !*** ./node_modules/axios/lib/core/transformData.js ***!
  2522. \******************************************************/
  2523. /*! no static exports found */
  2524. /***/ (function(module, exports, __webpack_require__) {
  2525. "use strict";
  2526. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2527. /**
  2528. * Transform the data for a request or a response
  2529. *
  2530. * @param {Object|String} data The data to be transformed
  2531. * @param {Array} headers The headers for the request or response
  2532. * @param {Array|Function} fns A single function or Array of functions
  2533. * @returns {*} The resulting transformed data
  2534. */
  2535. module.exports = function transformData(data, headers, fns) {
  2536. /*eslint no-param-reassign:0*/
  2537. utils.forEach(fns, function transform(fn) {
  2538. data = fn(data, headers);
  2539. });
  2540. return data;
  2541. };
  2542. /***/ }),
  2543. /***/ "./node_modules/axios/lib/defaults.js":
  2544. /*!********************************************!*\
  2545. !*** ./node_modules/axios/lib/defaults.js ***!
  2546. \********************************************/
  2547. /*! no static exports found */
  2548. /***/ (function(module, exports, __webpack_require__) {
  2549. "use strict";
  2550. /* WEBPACK VAR INJECTION */(function(process) {
  2551. var utils = __webpack_require__(/*! ./utils */ "./node_modules/axios/lib/utils.js");
  2552. var normalizeHeaderName = __webpack_require__(/*! ./helpers/normalizeHeaderName */ "./node_modules/axios/lib/helpers/normalizeHeaderName.js");
  2553. var DEFAULT_CONTENT_TYPE = {
  2554. 'Content-Type': 'application/x-www-form-urlencoded'
  2555. };
  2556. function setContentTypeIfUnset(headers, value) {
  2557. if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
  2558. headers['Content-Type'] = value;
  2559. }
  2560. }
  2561. function getDefaultAdapter() {
  2562. var adapter;
  2563. if (typeof XMLHttpRequest !== 'undefined') {
  2564. // For browsers use XHR adapter
  2565. adapter = __webpack_require__(/*! ./adapters/xhr */ "./node_modules/axios/lib/adapters/xhr.js");
  2566. } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
  2567. // For node use HTTP adapter
  2568. adapter = __webpack_require__(/*! ./adapters/http */ "./node_modules/axios/lib/adapters/xhr.js");
  2569. }
  2570. return adapter;
  2571. }
  2572. var defaults = {
  2573. adapter: getDefaultAdapter(),
  2574. transformRequest: [function transformRequest(data, headers) {
  2575. normalizeHeaderName(headers, 'Accept');
  2576. normalizeHeaderName(headers, 'Content-Type');
  2577. if (utils.isFormData(data) ||
  2578. utils.isArrayBuffer(data) ||
  2579. utils.isBuffer(data) ||
  2580. utils.isStream(data) ||
  2581. utils.isFile(data) ||
  2582. utils.isBlob(data)
  2583. ) {
  2584. return data;
  2585. }
  2586. if (utils.isArrayBufferView(data)) {
  2587. return data.buffer;
  2588. }
  2589. if (utils.isURLSearchParams(data)) {
  2590. setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
  2591. return data.toString();
  2592. }
  2593. if (utils.isObject(data)) {
  2594. setContentTypeIfUnset(headers, 'application/json;charset=utf-8');
  2595. return JSON.stringify(data);
  2596. }
  2597. return data;
  2598. }],
  2599. transformResponse: [function transformResponse(data) {
  2600. /*eslint no-param-reassign:0*/
  2601. if (typeof data === 'string') {
  2602. try {
  2603. data = JSON.parse(data);
  2604. } catch (e) { /* Ignore */ }
  2605. }
  2606. return data;
  2607. }],
  2608. /**
  2609. * A timeout in milliseconds to abort a request. If set to 0 (default) a
  2610. * timeout is not created.
  2611. */
  2612. timeout: 0,
  2613. xsrfCookieName: 'XSRF-TOKEN',
  2614. xsrfHeaderName: 'X-XSRF-TOKEN',
  2615. maxContentLength: -1,
  2616. validateStatus: function validateStatus(status) {
  2617. return status >= 200 && status < 300;
  2618. }
  2619. };
  2620. defaults.headers = {
  2621. common: {
  2622. 'Accept': 'application/json, text/plain, */*'
  2623. }
  2624. };
  2625. utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
  2626. defaults.headers[method] = {};
  2627. });
  2628. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  2629. defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
  2630. });
  2631. module.exports = defaults;
  2632. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../../process/browser.js */ "./node_modules/process/browser.js")))
  2633. /***/ }),
  2634. /***/ "./node_modules/axios/lib/helpers/bind.js":
  2635. /*!************************************************!*\
  2636. !*** ./node_modules/axios/lib/helpers/bind.js ***!
  2637. \************************************************/
  2638. /*! no static exports found */
  2639. /***/ (function(module, exports, __webpack_require__) {
  2640. "use strict";
  2641. module.exports = function bind(fn, thisArg) {
  2642. return function wrap() {
  2643. var args = new Array(arguments.length);
  2644. for (var i = 0; i < args.length; i++) {
  2645. args[i] = arguments[i];
  2646. }
  2647. return fn.apply(thisArg, args);
  2648. };
  2649. };
  2650. /***/ }),
  2651. /***/ "./node_modules/axios/lib/helpers/buildURL.js":
  2652. /*!****************************************************!*\
  2653. !*** ./node_modules/axios/lib/helpers/buildURL.js ***!
  2654. \****************************************************/
  2655. /*! no static exports found */
  2656. /***/ (function(module, exports, __webpack_require__) {
  2657. "use strict";
  2658. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2659. function encode(val) {
  2660. return encodeURIComponent(val).
  2661. replace(/%40/gi, '@').
  2662. replace(/%3A/gi, ':').
  2663. replace(/%24/g, '$').
  2664. replace(/%2C/gi, ',').
  2665. replace(/%20/g, '+').
  2666. replace(/%5B/gi, '[').
  2667. replace(/%5D/gi, ']');
  2668. }
  2669. /**
  2670. * Build a URL by appending params to the end
  2671. *
  2672. * @param {string} url The base of the url (e.g., http://www.google.com)
  2673. * @param {object} [params] The params to be appended
  2674. * @returns {string} The formatted url
  2675. */
  2676. module.exports = function buildURL(url, params, paramsSerializer) {
  2677. /*eslint no-param-reassign:0*/
  2678. if (!params) {
  2679. return url;
  2680. }
  2681. var serializedParams;
  2682. if (paramsSerializer) {
  2683. serializedParams = paramsSerializer(params);
  2684. } else if (utils.isURLSearchParams(params)) {
  2685. serializedParams = params.toString();
  2686. } else {
  2687. var parts = [];
  2688. utils.forEach(params, function serialize(val, key) {
  2689. if (val === null || typeof val === 'undefined') {
  2690. return;
  2691. }
  2692. if (utils.isArray(val)) {
  2693. key = key + '[]';
  2694. } else {
  2695. val = [val];
  2696. }
  2697. utils.forEach(val, function parseValue(v) {
  2698. if (utils.isDate(v)) {
  2699. v = v.toISOString();
  2700. } else if (utils.isObject(v)) {
  2701. v = JSON.stringify(v);
  2702. }
  2703. parts.push(encode(key) + '=' + encode(v));
  2704. });
  2705. });
  2706. serializedParams = parts.join('&');
  2707. }
  2708. if (serializedParams) {
  2709. var hashmarkIndex = url.indexOf('#');
  2710. if (hashmarkIndex !== -1) {
  2711. url = url.slice(0, hashmarkIndex);
  2712. }
  2713. url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
  2714. }
  2715. return url;
  2716. };
  2717. /***/ }),
  2718. /***/ "./node_modules/axios/lib/helpers/combineURLs.js":
  2719. /*!*******************************************************!*\
  2720. !*** ./node_modules/axios/lib/helpers/combineURLs.js ***!
  2721. \*******************************************************/
  2722. /*! no static exports found */
  2723. /***/ (function(module, exports, __webpack_require__) {
  2724. "use strict";
  2725. /**
  2726. * Creates a new URL by combining the specified URLs
  2727. *
  2728. * @param {string} baseURL The base URL
  2729. * @param {string} relativeURL The relative URL
  2730. * @returns {string} The combined URL
  2731. */
  2732. module.exports = function combineURLs(baseURL, relativeURL) {
  2733. return relativeURL
  2734. ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
  2735. : baseURL;
  2736. };
  2737. /***/ }),
  2738. /***/ "./node_modules/axios/lib/helpers/cookies.js":
  2739. /*!***************************************************!*\
  2740. !*** ./node_modules/axios/lib/helpers/cookies.js ***!
  2741. \***************************************************/
  2742. /*! no static exports found */
  2743. /***/ (function(module, exports, __webpack_require__) {
  2744. "use strict";
  2745. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2746. module.exports = (
  2747. utils.isStandardBrowserEnv() ?
  2748. // Standard browser envs support document.cookie
  2749. (function standardBrowserEnv() {
  2750. return {
  2751. write: function write(name, value, expires, path, domain, secure) {
  2752. var cookie = [];
  2753. cookie.push(name + '=' + encodeURIComponent(value));
  2754. if (utils.isNumber(expires)) {
  2755. cookie.push('expires=' + new Date(expires).toGMTString());
  2756. }
  2757. if (utils.isString(path)) {
  2758. cookie.push('path=' + path);
  2759. }
  2760. if (utils.isString(domain)) {
  2761. cookie.push('domain=' + domain);
  2762. }
  2763. if (secure === true) {
  2764. cookie.push('secure');
  2765. }
  2766. document.cookie = cookie.join('; ');
  2767. },
  2768. read: function read(name) {
  2769. var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
  2770. return (match ? decodeURIComponent(match[3]) : null);
  2771. },
  2772. remove: function remove(name) {
  2773. this.write(name, '', Date.now() - 86400000);
  2774. }
  2775. };
  2776. })() :
  2777. // Non standard browser env (web workers, react-native) lack needed support.
  2778. (function nonStandardBrowserEnv() {
  2779. return {
  2780. write: function write() {},
  2781. read: function read() { return null; },
  2782. remove: function remove() {}
  2783. };
  2784. })()
  2785. );
  2786. /***/ }),
  2787. /***/ "./node_modules/axios/lib/helpers/isAbsoluteURL.js":
  2788. /*!*********************************************************!*\
  2789. !*** ./node_modules/axios/lib/helpers/isAbsoluteURL.js ***!
  2790. \*********************************************************/
  2791. /*! no static exports found */
  2792. /***/ (function(module, exports, __webpack_require__) {
  2793. "use strict";
  2794. /**
  2795. * Determines whether the specified URL is absolute
  2796. *
  2797. * @param {string} url The URL to test
  2798. * @returns {boolean} True if the specified URL is absolute, otherwise false
  2799. */
  2800. module.exports = function isAbsoluteURL(url) {
  2801. // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
  2802. // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
  2803. // by any combination of letters, digits, plus, period, or hyphen.
  2804. return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
  2805. };
  2806. /***/ }),
  2807. /***/ "./node_modules/axios/lib/helpers/isURLSameOrigin.js":
  2808. /*!***********************************************************!*\
  2809. !*** ./node_modules/axios/lib/helpers/isURLSameOrigin.js ***!
  2810. \***********************************************************/
  2811. /*! no static exports found */
  2812. /***/ (function(module, exports, __webpack_require__) {
  2813. "use strict";
  2814. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2815. module.exports = (
  2816. utils.isStandardBrowserEnv() ?
  2817. // Standard browser envs have full support of the APIs needed to test
  2818. // whether the request URL is of the same origin as current location.
  2819. (function standardBrowserEnv() {
  2820. var msie = /(msie|trident)/i.test(navigator.userAgent);
  2821. var urlParsingNode = document.createElement('a');
  2822. var originURL;
  2823. /**
  2824. * Parse a URL to discover it's components
  2825. *
  2826. * @param {String} url The URL to be parsed
  2827. * @returns {Object}
  2828. */
  2829. function resolveURL(url) {
  2830. var href = url;
  2831. if (msie) {
  2832. // IE needs attribute set twice to normalize properties
  2833. urlParsingNode.setAttribute('href', href);
  2834. href = urlParsingNode.href;
  2835. }
  2836. urlParsingNode.setAttribute('href', href);
  2837. // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
  2838. return {
  2839. href: urlParsingNode.href,
  2840. protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
  2841. host: urlParsingNode.host,
  2842. search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
  2843. hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
  2844. hostname: urlParsingNode.hostname,
  2845. port: urlParsingNode.port,
  2846. pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
  2847. urlParsingNode.pathname :
  2848. '/' + urlParsingNode.pathname
  2849. };
  2850. }
  2851. originURL = resolveURL(window.location.href);
  2852. /**
  2853. * Determine if a URL shares the same origin as the current location
  2854. *
  2855. * @param {String} requestURL The URL to test
  2856. * @returns {boolean} True if URL shares the same origin, otherwise false
  2857. */
  2858. return function isURLSameOrigin(requestURL) {
  2859. var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
  2860. return (parsed.protocol === originURL.protocol &&
  2861. parsed.host === originURL.host);
  2862. };
  2863. })() :
  2864. // Non standard browser envs (web workers, react-native) lack needed support.
  2865. (function nonStandardBrowserEnv() {
  2866. return function isURLSameOrigin() {
  2867. return true;
  2868. };
  2869. })()
  2870. );
  2871. /***/ }),
  2872. /***/ "./node_modules/axios/lib/helpers/normalizeHeaderName.js":
  2873. /*!***************************************************************!*\
  2874. !*** ./node_modules/axios/lib/helpers/normalizeHeaderName.js ***!
  2875. \***************************************************************/
  2876. /*! no static exports found */
  2877. /***/ (function(module, exports, __webpack_require__) {
  2878. "use strict";
  2879. var utils = __webpack_require__(/*! ../utils */ "./node_modules/axios/lib/utils.js");
  2880. module.exports = function normalizeHeaderName(headers, normalizedName) {
  2881. utils.forEach(headers, function processHeader(value, name) {
  2882. if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
  2883. headers[normalizedName] = value;
  2884. delete headers[name];
  2885. }
  2886. });
  2887. };
  2888. /***/ }),
  2889. /***/ "./node_modules/axios/lib/helpers/parseHeaders.js":
  2890. /*!********************************************************!*\
  2891. !*** ./node_modules/axios/lib/helpers/parseHeaders.js ***!
  2892. \********************************************************/
  2893. /*! no static exports found */
  2894. /***/ (function(module, exports, __webpack_require__) {
  2895. "use strict";
  2896. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2897. // Headers whose duplicates are ignored by node
  2898. // c.f. https://nodejs.org/api/http.html#http_message_headers
  2899. var ignoreDuplicateOf = [
  2900. 'age', 'authorization', 'content-length', 'content-type', 'etag',
  2901. 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
  2902. 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
  2903. 'referer', 'retry-after', 'user-agent'
  2904. ];
  2905. /**
  2906. * Parse headers into an object
  2907. *
  2908. * ```
  2909. * Date: Wed, 27 Aug 2014 08:58:49 GMT
  2910. * Content-Type: application/json
  2911. * Connection: keep-alive
  2912. * Transfer-Encoding: chunked
  2913. * ```
  2914. *
  2915. * @param {String} headers Headers needing to be parsed
  2916. * @returns {Object} Headers parsed into an object
  2917. */
  2918. module.exports = function parseHeaders(headers) {
  2919. var parsed = {};
  2920. var key;
  2921. var val;
  2922. var i;
  2923. if (!headers) { return parsed; }
  2924. utils.forEach(headers.split('\n'), function parser(line) {
  2925. i = line.indexOf(':');
  2926. key = utils.trim(line.substr(0, i)).toLowerCase();
  2927. val = utils.trim(line.substr(i + 1));
  2928. if (key) {
  2929. if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
  2930. return;
  2931. }
  2932. if (key === 'set-cookie') {
  2933. parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
  2934. } else {
  2935. parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
  2936. }
  2937. }
  2938. });
  2939. return parsed;
  2940. };
  2941. /***/ }),
  2942. /***/ "./node_modules/axios/lib/helpers/spread.js":
  2943. /*!**************************************************!*\
  2944. !*** ./node_modules/axios/lib/helpers/spread.js ***!
  2945. \**************************************************/
  2946. /*! no static exports found */
  2947. /***/ (function(module, exports, __webpack_require__) {
  2948. "use strict";
  2949. /**
  2950. * Syntactic sugar for invoking a function and expanding an array for arguments.
  2951. *
  2952. * Common use case would be to use `Function.prototype.apply`.
  2953. *
  2954. * ```js
  2955. * function f(x, y, z) {}
  2956. * var args = [1, 2, 3];
  2957. * f.apply(null, args);
  2958. * ```
  2959. *
  2960. * With `spread` this example can be re-written.
  2961. *
  2962. * ```js
  2963. * spread(function(x, y, z) {})([1, 2, 3]);
  2964. * ```
  2965. *
  2966. * @param {Function} callback
  2967. * @returns {Function}
  2968. */
  2969. module.exports = function spread(callback) {
  2970. return function wrap(arr) {
  2971. return callback.apply(null, arr);
  2972. };
  2973. };
  2974. /***/ }),
  2975. /***/ "./node_modules/axios/lib/utils.js":
  2976. /*!*****************************************!*\
  2977. !*** ./node_modules/axios/lib/utils.js ***!
  2978. \*****************************************/
  2979. /*! no static exports found */
  2980. /***/ (function(module, exports, __webpack_require__) {
  2981. "use strict";
  2982. var bind = __webpack_require__(/*! ./helpers/bind */ "./node_modules/axios/lib/helpers/bind.js");
  2983. /*global toString:true*/
  2984. // utils is a library of generic helper functions non-specific to axios
  2985. var toString = Object.prototype.toString;
  2986. /**
  2987. * Determine if a value is an Array
  2988. *
  2989. * @param {Object} val The value to test
  2990. * @returns {boolean} True if value is an Array, otherwise false
  2991. */
  2992. function isArray(val) {
  2993. return toString.call(val) === '[object Array]';
  2994. }
  2995. /**
  2996. * Determine if a value is undefined
  2997. *
  2998. * @param {Object} val The value to test
  2999. * @returns {boolean} True if the value is undefined, otherwise false
  3000. */
  3001. function isUndefined(val) {
  3002. return typeof val === 'undefined';
  3003. }
  3004. /**
  3005. * Determine if a value is a Buffer
  3006. *
  3007. * @param {Object} val The value to test
  3008. * @returns {boolean} True if value is a Buffer, otherwise false
  3009. */
  3010. function isBuffer(val) {
  3011. return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
  3012. && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
  3013. }
  3014. /**
  3015. * Determine if a value is an ArrayBuffer
  3016. *
  3017. * @param {Object} val The value to test
  3018. * @returns {boolean} True if value is an ArrayBuffer, otherwise false
  3019. */
  3020. function isArrayBuffer(val) {
  3021. return toString.call(val) === '[object ArrayBuffer]';
  3022. }
  3023. /**
  3024. * Determine if a value is a FormData
  3025. *
  3026. * @param {Object} val The value to test
  3027. * @returns {boolean} True if value is an FormData, otherwise false
  3028. */
  3029. function isFormData(val) {
  3030. return (typeof FormData !== 'undefined') && (val instanceof FormData);
  3031. }
  3032. /**
  3033. * Determine if a value is a view on an ArrayBuffer
  3034. *
  3035. * @param {Object} val The value to test
  3036. * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
  3037. */
  3038. function isArrayBufferView(val) {
  3039. var result;
  3040. if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
  3041. result = ArrayBuffer.isView(val);
  3042. } else {
  3043. result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
  3044. }
  3045. return result;
  3046. }
  3047. /**
  3048. * Determine if a value is a String
  3049. *
  3050. * @param {Object} val The value to test
  3051. * @returns {boolean} True if value is a String, otherwise false
  3052. */
  3053. function isString(val) {
  3054. return typeof val === 'string';
  3055. }
  3056. /**
  3057. * Determine if a value is a Number
  3058. *
  3059. * @param {Object} val The value to test
  3060. * @returns {boolean} True if value is a Number, otherwise false
  3061. */
  3062. function isNumber(val) {
  3063. return typeof val === 'number';
  3064. }
  3065. /**
  3066. * Determine if a value is an Object
  3067. *
  3068. * @param {Object} val The value to test
  3069. * @returns {boolean} True if value is an Object, otherwise false
  3070. */
  3071. function isObject(val) {
  3072. return val !== null && typeof val === 'object';
  3073. }
  3074. /**
  3075. * Determine if a value is a Date
  3076. *
  3077. * @param {Object} val The value to test
  3078. * @returns {boolean} True if value is a Date, otherwise false
  3079. */
  3080. function isDate(val) {
  3081. return toString.call(val) === '[object Date]';
  3082. }
  3083. /**
  3084. * Determine if a value is a File
  3085. *
  3086. * @param {Object} val The value to test
  3087. * @returns {boolean} True if value is a File, otherwise false
  3088. */
  3089. function isFile(val) {
  3090. return toString.call(val) === '[object File]';
  3091. }
  3092. /**
  3093. * Determine if a value is a Blob
  3094. *
  3095. * @param {Object} val The value to test
  3096. * @returns {boolean} True if value is a Blob, otherwise false
  3097. */
  3098. function isBlob(val) {
  3099. return toString.call(val) === '[object Blob]';
  3100. }
  3101. /**
  3102. * Determine if a value is a Function
  3103. *
  3104. * @param {Object} val The value to test
  3105. * @returns {boolean} True if value is a Function, otherwise false
  3106. */
  3107. function isFunction(val) {
  3108. return toString.call(val) === '[object Function]';
  3109. }
  3110. /**
  3111. * Determine if a value is a Stream
  3112. *
  3113. * @param {Object} val The value to test
  3114. * @returns {boolean} True if value is a Stream, otherwise false
  3115. */
  3116. function isStream(val) {
  3117. return isObject(val) && isFunction(val.pipe);
  3118. }
  3119. /**
  3120. * Determine if a value is a URLSearchParams object
  3121. *
  3122. * @param {Object} val The value to test
  3123. * @returns {boolean} True if value is a URLSearchParams object, otherwise false
  3124. */
  3125. function isURLSearchParams(val) {
  3126. return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
  3127. }
  3128. /**
  3129. * Trim excess whitespace off the beginning and end of a string
  3130. *
  3131. * @param {String} str The String to trim
  3132. * @returns {String} The String freed of excess whitespace
  3133. */
  3134. function trim(str) {
  3135. return str.replace(/^\s*/, '').replace(/\s*$/, '');
  3136. }
  3137. /**
  3138. * Determine if we're running in a standard browser environment
  3139. *
  3140. * This allows axios to run in a web worker, and react-native.
  3141. * Both environments support XMLHttpRequest, but not fully standard globals.
  3142. *
  3143. * web workers:
  3144. * typeof window -> undefined
  3145. * typeof document -> undefined
  3146. *
  3147. * react-native:
  3148. * navigator.product -> 'ReactNative'
  3149. * nativescript
  3150. * navigator.product -> 'NativeScript' or 'NS'
  3151. */
  3152. function isStandardBrowserEnv() {
  3153. if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||
  3154. navigator.product === 'NativeScript' ||
  3155. navigator.product === 'NS')) {
  3156. return false;
  3157. }
  3158. return (
  3159. typeof window !== 'undefined' &&
  3160. typeof document !== 'undefined'
  3161. );
  3162. }
  3163. /**
  3164. * Iterate over an Array or an Object invoking a function for each item.
  3165. *
  3166. * If `obj` is an Array callback will be called passing
  3167. * the value, index, and complete array for each item.
  3168. *
  3169. * If 'obj' is an Object callback will be called passing
  3170. * the value, key, and complete object for each property.
  3171. *
  3172. * @param {Object|Array} obj The object to iterate
  3173. * @param {Function} fn The callback to invoke for each item
  3174. */
  3175. function forEach(obj, fn) {
  3176. // Don't bother if no value provided
  3177. if (obj === null || typeof obj === 'undefined') {
  3178. return;
  3179. }
  3180. // Force an array if not already something iterable
  3181. if (typeof obj !== 'object') {
  3182. /*eslint no-param-reassign:0*/
  3183. obj = [obj];
  3184. }
  3185. if (isArray(obj)) {
  3186. // Iterate over array values
  3187. for (var i = 0, l = obj.length; i < l; i++) {
  3188. fn.call(null, obj[i], i, obj);
  3189. }
  3190. } else {
  3191. // Iterate over object keys
  3192. for (var key in obj) {
  3193. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  3194. fn.call(null, obj[key], key, obj);
  3195. }
  3196. }
  3197. }
  3198. }
  3199. /**
  3200. * Accepts varargs expecting each argument to be an object, then
  3201. * immutably merges the properties of each object and returns result.
  3202. *
  3203. * When multiple objects contain the same key the later object in
  3204. * the arguments list will take precedence.
  3205. *
  3206. * Example:
  3207. *
  3208. * ```js
  3209. * var result = merge({foo: 123}, {foo: 456});
  3210. * console.log(result.foo); // outputs 456
  3211. * ```
  3212. *
  3213. * @param {Object} obj1 Object to merge
  3214. * @returns {Object} Result of all merge properties
  3215. */
  3216. function merge(/* obj1, obj2, obj3, ... */) {
  3217. var result = {};
  3218. function assignValue(val, key) {
  3219. if (typeof result[key] === 'object' && typeof val === 'object') {
  3220. result[key] = merge(result[key], val);
  3221. } else {
  3222. result[key] = val;
  3223. }
  3224. }
  3225. for (var i = 0, l = arguments.length; i < l; i++) {
  3226. forEach(arguments[i], assignValue);
  3227. }
  3228. return result;
  3229. }
  3230. /**
  3231. * Function equal to merge with the difference being that no reference
  3232. * to original objects is kept.
  3233. *
  3234. * @see merge
  3235. * @param {Object} obj1 Object to merge
  3236. * @returns {Object} Result of all merge properties
  3237. */
  3238. function deepMerge(/* obj1, obj2, obj3, ... */) {
  3239. var result = {};
  3240. function assignValue(val, key) {
  3241. if (typeof result[key] === 'object' && typeof val === 'object') {
  3242. result[key] = deepMerge(result[key], val);
  3243. } else if (typeof val === 'object') {
  3244. result[key] = deepMerge({}, val);
  3245. } else {
  3246. result[key] = val;
  3247. }
  3248. }
  3249. for (var i = 0, l = arguments.length; i < l; i++) {
  3250. forEach(arguments[i], assignValue);
  3251. }
  3252. return result;
  3253. }
  3254. /**
  3255. * Extends object a by mutably adding to it the properties of object b.
  3256. *
  3257. * @param {Object} a The object to be extended
  3258. * @param {Object} b The object to copy properties from
  3259. * @param {Object} thisArg The object to bind function to
  3260. * @return {Object} The resulting value of object a
  3261. */
  3262. function extend(a, b, thisArg) {
  3263. forEach(b, function assignValue(val, key) {
  3264. if (thisArg && typeof val === 'function') {
  3265. a[key] = bind(val, thisArg);
  3266. } else {
  3267. a[key] = val;
  3268. }
  3269. });
  3270. return a;
  3271. }
  3272. module.exports = {
  3273. isArray: isArray,
  3274. isArrayBuffer: isArrayBuffer,
  3275. isBuffer: isBuffer,
  3276. isFormData: isFormData,
  3277. isArrayBufferView: isArrayBufferView,
  3278. isString: isString,
  3279. isNumber: isNumber,
  3280. isObject: isObject,
  3281. isUndefined: isUndefined,
  3282. isDate: isDate,
  3283. isFile: isFile,
  3284. isBlob: isBlob,
  3285. isFunction: isFunction,
  3286. isStream: isStream,
  3287. isURLSearchParams: isURLSearchParams,
  3288. isStandardBrowserEnv: isStandardBrowserEnv,
  3289. forEach: forEach,
  3290. merge: merge,
  3291. deepMerge: deepMerge,
  3292. extend: extend,
  3293. trim: trim
  3294. };
  3295. /***/ }),
  3296. /***/ "./node_modules/lodash/lodash.js":
  3297. /*!***************************************!*\
  3298. !*** ./node_modules/lodash/lodash.js ***!
  3299. \***************************************/
  3300. /*! no static exports found */
  3301. /***/ (function(module, exports, __webpack_require__) {
  3302. /* WEBPACK VAR INJECTION */(function(global, module) {var __WEBPACK_AMD_DEFINE_RESULT__;/**
  3303. * @license
  3304. * Lodash <https://lodash.com/>
  3305. * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
  3306. * Released under MIT license <https://lodash.com/license>
  3307. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  3308. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  3309. */
  3310. ;(function() {
  3311. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  3312. var undefined;
  3313. /** Used as the semantic version number. */
  3314. var VERSION = '4.17.20';
  3315. /** Used as the size to enable large array optimizations. */
  3316. var LARGE_ARRAY_SIZE = 200;
  3317. /** Error message constants. */
  3318. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  3319. FUNC_ERROR_TEXT = 'Expected a function';
  3320. /** Used to stand-in for `undefined` hash values. */
  3321. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  3322. /** Used as the maximum memoize cache size. */
  3323. var MAX_MEMOIZE_SIZE = 500;
  3324. /** Used as the internal argument placeholder. */
  3325. var PLACEHOLDER = '__lodash_placeholder__';
  3326. /** Used to compose bitmasks for cloning. */
  3327. var CLONE_DEEP_FLAG = 1,
  3328. CLONE_FLAT_FLAG = 2,
  3329. CLONE_SYMBOLS_FLAG = 4;
  3330. /** Used to compose bitmasks for value comparisons. */
  3331. var COMPARE_PARTIAL_FLAG = 1,
  3332. COMPARE_UNORDERED_FLAG = 2;
  3333. /** Used to compose bitmasks for function metadata. */
  3334. var WRAP_BIND_FLAG = 1,
  3335. WRAP_BIND_KEY_FLAG = 2,
  3336. WRAP_CURRY_BOUND_FLAG = 4,
  3337. WRAP_CURRY_FLAG = 8,
  3338. WRAP_CURRY_RIGHT_FLAG = 16,
  3339. WRAP_PARTIAL_FLAG = 32,
  3340. WRAP_PARTIAL_RIGHT_FLAG = 64,
  3341. WRAP_ARY_FLAG = 128,
  3342. WRAP_REARG_FLAG = 256,
  3343. WRAP_FLIP_FLAG = 512;
  3344. /** Used as default options for `_.truncate`. */
  3345. var DEFAULT_TRUNC_LENGTH = 30,
  3346. DEFAULT_TRUNC_OMISSION = '...';
  3347. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  3348. var HOT_COUNT = 800,
  3349. HOT_SPAN = 16;
  3350. /** Used to indicate the type of lazy iteratees. */
  3351. var LAZY_FILTER_FLAG = 1,
  3352. LAZY_MAP_FLAG = 2,
  3353. LAZY_WHILE_FLAG = 3;
  3354. /** Used as references for various `Number` constants. */
  3355. var INFINITY = 1 / 0,
  3356. MAX_SAFE_INTEGER = 9007199254740991,
  3357. MAX_INTEGER = 1.7976931348623157e+308,
  3358. NAN = 0 / 0;
  3359. /** Used as references for the maximum length and index of an array. */
  3360. var MAX_ARRAY_LENGTH = 4294967295,
  3361. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  3362. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  3363. /** Used to associate wrap methods with their bit flags. */
  3364. var wrapFlags = [
  3365. ['ary', WRAP_ARY_FLAG],
  3366. ['bind', WRAP_BIND_FLAG],
  3367. ['bindKey', WRAP_BIND_KEY_FLAG],
  3368. ['curry', WRAP_CURRY_FLAG],
  3369. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  3370. ['flip', WRAP_FLIP_FLAG],
  3371. ['partial', WRAP_PARTIAL_FLAG],
  3372. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  3373. ['rearg', WRAP_REARG_FLAG]
  3374. ];
  3375. /** `Object#toString` result references. */
  3376. var argsTag = '[object Arguments]',
  3377. arrayTag = '[object Array]',
  3378. asyncTag = '[object AsyncFunction]',
  3379. boolTag = '[object Boolean]',
  3380. dateTag = '[object Date]',
  3381. domExcTag = '[object DOMException]',
  3382. errorTag = '[object Error]',
  3383. funcTag = '[object Function]',
  3384. genTag = '[object GeneratorFunction]',
  3385. mapTag = '[object Map]',
  3386. numberTag = '[object Number]',
  3387. nullTag = '[object Null]',
  3388. objectTag = '[object Object]',
  3389. promiseTag = '[object Promise]',
  3390. proxyTag = '[object Proxy]',
  3391. regexpTag = '[object RegExp]',
  3392. setTag = '[object Set]',
  3393. stringTag = '[object String]',
  3394. symbolTag = '[object Symbol]',
  3395. undefinedTag = '[object Undefined]',
  3396. weakMapTag = '[object WeakMap]',
  3397. weakSetTag = '[object WeakSet]';
  3398. var arrayBufferTag = '[object ArrayBuffer]',
  3399. dataViewTag = '[object DataView]',
  3400. float32Tag = '[object Float32Array]',
  3401. float64Tag = '[object Float64Array]',
  3402. int8Tag = '[object Int8Array]',
  3403. int16Tag = '[object Int16Array]',
  3404. int32Tag = '[object Int32Array]',
  3405. uint8Tag = '[object Uint8Array]',
  3406. uint8ClampedTag = '[object Uint8ClampedArray]',
  3407. uint16Tag = '[object Uint16Array]',
  3408. uint32Tag = '[object Uint32Array]';
  3409. /** Used to match empty string literals in compiled template source. */
  3410. var reEmptyStringLeading = /\b__p \+= '';/g,
  3411. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  3412. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  3413. /** Used to match HTML entities and HTML characters. */
  3414. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  3415. reUnescapedHtml = /[&<>"']/g,
  3416. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  3417. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  3418. /** Used to match template delimiters. */
  3419. var reEscape = /<%-([\s\S]+?)%>/g,
  3420. reEvaluate = /<%([\s\S]+?)%>/g,
  3421. reInterpolate = /<%=([\s\S]+?)%>/g;
  3422. /** Used to match property names within property paths. */
  3423. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  3424. reIsPlainProp = /^\w*$/,
  3425. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  3426. /**
  3427. * Used to match `RegExp`
  3428. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  3429. */
  3430. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  3431. reHasRegExpChar = RegExp(reRegExpChar.source);
  3432. /** Used to match leading and trailing whitespace. */
  3433. var reTrim = /^\s+|\s+$/g,
  3434. reTrimStart = /^\s+/,
  3435. reTrimEnd = /\s+$/;
  3436. /** Used to match wrap detail comments. */
  3437. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  3438. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  3439. reSplitDetails = /,? & /;
  3440. /** Used to match words composed of alphanumeric characters. */
  3441. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  3442. /** Used to match backslashes in property paths. */
  3443. var reEscapeChar = /\\(\\)?/g;
  3444. /**
  3445. * Used to match
  3446. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  3447. */
  3448. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  3449. /** Used to match `RegExp` flags from their coerced string values. */
  3450. var reFlags = /\w*$/;
  3451. /** Used to detect bad signed hexadecimal string values. */
  3452. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  3453. /** Used to detect binary string values. */
  3454. var reIsBinary = /^0b[01]+$/i;
  3455. /** Used to detect host constructors (Safari). */
  3456. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  3457. /** Used to detect octal string values. */
  3458. var reIsOctal = /^0o[0-7]+$/i;
  3459. /** Used to detect unsigned integer values. */
  3460. var reIsUint = /^(?:0|[1-9]\d*)$/;
  3461. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  3462. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  3463. /** Used to ensure capturing order of template delimiters. */
  3464. var reNoMatch = /($^)/;
  3465. /** Used to match unescaped characters in compiled string literals. */
  3466. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  3467. /** Used to compose unicode character classes. */
  3468. var rsAstralRange = '\\ud800-\\udfff',
  3469. rsComboMarksRange = '\\u0300-\\u036f',
  3470. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  3471. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  3472. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  3473. rsDingbatRange = '\\u2700-\\u27bf',
  3474. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  3475. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  3476. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  3477. rsPunctuationRange = '\\u2000-\\u206f',
  3478. rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000',
  3479. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  3480. rsVarRange = '\\ufe0e\\ufe0f',
  3481. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  3482. /** Used to compose unicode capture groups. */
  3483. var rsApos = "['\u2019]",
  3484. rsAstral = '[' + rsAstralRange + ']',
  3485. rsBreak = '[' + rsBreakRange + ']',
  3486. rsCombo = '[' + rsComboRange + ']',
  3487. rsDigits = '\\d+',
  3488. rsDingbat = '[' + rsDingbatRange + ']',
  3489. rsLower = '[' + rsLowerRange + ']',
  3490. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  3491. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  3492. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  3493. rsNonAstral = '[^' + rsAstralRange + ']',
  3494. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  3495. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  3496. rsUpper = '[' + rsUpperRange + ']',
  3497. rsZWJ = '\\u200d';
  3498. /** Used to compose unicode regexes. */
  3499. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  3500. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  3501. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  3502. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  3503. reOptMod = rsModifier + '?',
  3504. rsOptVar = '[' + rsVarRange + ']?',
  3505. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  3506. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  3507. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  3508. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  3509. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  3510. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  3511. /** Used to match apostrophes. */
  3512. var reApos = RegExp(rsApos, 'g');
  3513. /**
  3514. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  3515. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  3516. */
  3517. var reComboMark = RegExp(rsCombo, 'g');
  3518. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  3519. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  3520. /** Used to match complex or compound words. */
  3521. var reUnicodeWord = RegExp([
  3522. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  3523. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  3524. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  3525. rsUpper + '+' + rsOptContrUpper,
  3526. rsOrdUpper,
  3527. rsOrdLower,
  3528. rsDigits,
  3529. rsEmoji
  3530. ].join('|'), 'g');
  3531. /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */
  3532. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  3533. /** Used to detect strings that need a more robust regexp to match words. */
  3534. var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/;
  3535. /** Used to assign default `context` object properties. */
  3536. var contextProps = [
  3537. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  3538. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  3539. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  3540. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  3541. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  3542. ];
  3543. /** Used to make template sourceURLs easier to identify. */
  3544. var templateCounter = -1;
  3545. /** Used to identify `toStringTag` values of typed arrays. */
  3546. var typedArrayTags = {};
  3547. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  3548. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  3549. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  3550. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  3551. typedArrayTags[uint32Tag] = true;
  3552. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  3553. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  3554. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  3555. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  3556. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  3557. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  3558. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  3559. typedArrayTags[weakMapTag] = false;
  3560. /** Used to identify `toStringTag` values supported by `_.clone`. */
  3561. var cloneableTags = {};
  3562. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  3563. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  3564. cloneableTags[boolTag] = cloneableTags[dateTag] =
  3565. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  3566. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  3567. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  3568. cloneableTags[numberTag] = cloneableTags[objectTag] =
  3569. cloneableTags[regexpTag] = cloneableTags[setTag] =
  3570. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  3571. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  3572. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  3573. cloneableTags[errorTag] = cloneableTags[funcTag] =
  3574. cloneableTags[weakMapTag] = false;
  3575. /** Used to map Latin Unicode letters to basic Latin letters. */
  3576. var deburredLetters = {
  3577. // Latin-1 Supplement block.
  3578. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  3579. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  3580. '\xc7': 'C', '\xe7': 'c',
  3581. '\xd0': 'D', '\xf0': 'd',
  3582. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  3583. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  3584. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  3585. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  3586. '\xd1': 'N', '\xf1': 'n',
  3587. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  3588. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  3589. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  3590. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  3591. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  3592. '\xc6': 'Ae', '\xe6': 'ae',
  3593. '\xde': 'Th', '\xfe': 'th',
  3594. '\xdf': 'ss',
  3595. // Latin Extended-A block.
  3596. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  3597. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  3598. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  3599. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  3600. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  3601. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  3602. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  3603. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  3604. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  3605. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  3606. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  3607. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  3608. '\u0134': 'J', '\u0135': 'j',
  3609. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  3610. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  3611. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  3612. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  3613. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  3614. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  3615. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  3616. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  3617. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  3618. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  3619. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  3620. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  3621. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  3622. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  3623. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  3624. '\u0174': 'W', '\u0175': 'w',
  3625. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  3626. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  3627. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  3628. '\u0132': 'IJ', '\u0133': 'ij',
  3629. '\u0152': 'Oe', '\u0153': 'oe',
  3630. '\u0149': "'n", '\u017f': 's'
  3631. };
  3632. /** Used to map characters to HTML entities. */
  3633. var htmlEscapes = {
  3634. '&': '&amp;',
  3635. '<': '&lt;',
  3636. '>': '&gt;',
  3637. '"': '&quot;',
  3638. "'": '&#39;'
  3639. };
  3640. /** Used to map HTML entities to characters. */
  3641. var htmlUnescapes = {
  3642. '&amp;': '&',
  3643. '&lt;': '<',
  3644. '&gt;': '>',
  3645. '&quot;': '"',
  3646. '&#39;': "'"
  3647. };
  3648. /** Used to escape characters for inclusion in compiled string literals. */
  3649. var stringEscapes = {
  3650. '\\': '\\',
  3651. "'": "'",
  3652. '\n': 'n',
  3653. '\r': 'r',
  3654. '\u2028': 'u2028',
  3655. '\u2029': 'u2029'
  3656. };
  3657. /** Built-in method references without a dependency on `root`. */
  3658. var freeParseFloat = parseFloat,
  3659. freeParseInt = parseInt;
  3660. /** Detect free variable `global` from Node.js. */
  3661. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  3662. /** Detect free variable `self`. */
  3663. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  3664. /** Used as a reference to the global object. */
  3665. var root = freeGlobal || freeSelf || Function('return this')();
  3666. /** Detect free variable `exports`. */
  3667. var freeExports = true && exports && !exports.nodeType && exports;
  3668. /** Detect free variable `module`. */
  3669. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  3670. /** Detect the popular CommonJS extension `module.exports`. */
  3671. var moduleExports = freeModule && freeModule.exports === freeExports;
  3672. /** Detect free variable `process` from Node.js. */
  3673. var freeProcess = moduleExports && freeGlobal.process;
  3674. /** Used to access faster Node.js helpers. */
  3675. var nodeUtil = (function() {
  3676. try {
  3677. // Use `util.types` for Node.js 10+.
  3678. var types = freeModule && freeModule.require && freeModule.require('util').types;
  3679. if (types) {
  3680. return types;
  3681. }
  3682. // Legacy `process.binding('util')` for Node.js < 10.
  3683. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  3684. } catch (e) {}
  3685. }());
  3686. /* Node.js helper references. */
  3687. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  3688. nodeIsDate = nodeUtil && nodeUtil.isDate,
  3689. nodeIsMap = nodeUtil && nodeUtil.isMap,
  3690. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  3691. nodeIsSet = nodeUtil && nodeUtil.isSet,
  3692. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  3693. /*--------------------------------------------------------------------------*/
  3694. /**
  3695. * A faster alternative to `Function#apply`, this function invokes `func`
  3696. * with the `this` binding of `thisArg` and the arguments of `args`.
  3697. *
  3698. * @private
  3699. * @param {Function} func The function to invoke.
  3700. * @param {*} thisArg The `this` binding of `func`.
  3701. * @param {Array} args The arguments to invoke `func` with.
  3702. * @returns {*} Returns the result of `func`.
  3703. */
  3704. function apply(func, thisArg, args) {
  3705. switch (args.length) {
  3706. case 0: return func.call(thisArg);
  3707. case 1: return func.call(thisArg, args[0]);
  3708. case 2: return func.call(thisArg, args[0], args[1]);
  3709. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  3710. }
  3711. return func.apply(thisArg, args);
  3712. }
  3713. /**
  3714. * A specialized version of `baseAggregator` for arrays.
  3715. *
  3716. * @private
  3717. * @param {Array} [array] The array to iterate over.
  3718. * @param {Function} setter The function to set `accumulator` values.
  3719. * @param {Function} iteratee The iteratee to transform keys.
  3720. * @param {Object} accumulator The initial aggregated object.
  3721. * @returns {Function} Returns `accumulator`.
  3722. */
  3723. function arrayAggregator(array, setter, iteratee, accumulator) {
  3724. var index = -1,
  3725. length = array == null ? 0 : array.length;
  3726. while (++index < length) {
  3727. var value = array[index];
  3728. setter(accumulator, value, iteratee(value), array);
  3729. }
  3730. return accumulator;
  3731. }
  3732. /**
  3733. * A specialized version of `_.forEach` for arrays without support for
  3734. * iteratee shorthands.
  3735. *
  3736. * @private
  3737. * @param {Array} [array] The array to iterate over.
  3738. * @param {Function} iteratee The function invoked per iteration.
  3739. * @returns {Array} Returns `array`.
  3740. */
  3741. function arrayEach(array, iteratee) {
  3742. var index = -1,
  3743. length = array == null ? 0 : array.length;
  3744. while (++index < length) {
  3745. if (iteratee(array[index], index, array) === false) {
  3746. break;
  3747. }
  3748. }
  3749. return array;
  3750. }
  3751. /**
  3752. * A specialized version of `_.forEachRight` for arrays without support for
  3753. * iteratee shorthands.
  3754. *
  3755. * @private
  3756. * @param {Array} [array] The array to iterate over.
  3757. * @param {Function} iteratee The function invoked per iteration.
  3758. * @returns {Array} Returns `array`.
  3759. */
  3760. function arrayEachRight(array, iteratee) {
  3761. var length = array == null ? 0 : array.length;
  3762. while (length--) {
  3763. if (iteratee(array[length], length, array) === false) {
  3764. break;
  3765. }
  3766. }
  3767. return array;
  3768. }
  3769. /**
  3770. * A specialized version of `_.every` for arrays without support for
  3771. * iteratee shorthands.
  3772. *
  3773. * @private
  3774. * @param {Array} [array] The array to iterate over.
  3775. * @param {Function} predicate The function invoked per iteration.
  3776. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  3777. * else `false`.
  3778. */
  3779. function arrayEvery(array, predicate) {
  3780. var index = -1,
  3781. length = array == null ? 0 : array.length;
  3782. while (++index < length) {
  3783. if (!predicate(array[index], index, array)) {
  3784. return false;
  3785. }
  3786. }
  3787. return true;
  3788. }
  3789. /**
  3790. * A specialized version of `_.filter` for arrays without support for
  3791. * iteratee shorthands.
  3792. *
  3793. * @private
  3794. * @param {Array} [array] The array to iterate over.
  3795. * @param {Function} predicate The function invoked per iteration.
  3796. * @returns {Array} Returns the new filtered array.
  3797. */
  3798. function arrayFilter(array, predicate) {
  3799. var index = -1,
  3800. length = array == null ? 0 : array.length,
  3801. resIndex = 0,
  3802. result = [];
  3803. while (++index < length) {
  3804. var value = array[index];
  3805. if (predicate(value, index, array)) {
  3806. result[resIndex++] = value;
  3807. }
  3808. }
  3809. return result;
  3810. }
  3811. /**
  3812. * A specialized version of `_.includes` for arrays without support for
  3813. * specifying an index to search from.
  3814. *
  3815. * @private
  3816. * @param {Array} [array] The array to inspect.
  3817. * @param {*} target The value to search for.
  3818. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  3819. */
  3820. function arrayIncludes(array, value) {
  3821. var length = array == null ? 0 : array.length;
  3822. return !!length && baseIndexOf(array, value, 0) > -1;
  3823. }
  3824. /**
  3825. * This function is like `arrayIncludes` except that it accepts a comparator.
  3826. *
  3827. * @private
  3828. * @param {Array} [array] The array to inspect.
  3829. * @param {*} target The value to search for.
  3830. * @param {Function} comparator The comparator invoked per element.
  3831. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  3832. */
  3833. function arrayIncludesWith(array, value, comparator) {
  3834. var index = -1,
  3835. length = array == null ? 0 : array.length;
  3836. while (++index < length) {
  3837. if (comparator(value, array[index])) {
  3838. return true;
  3839. }
  3840. }
  3841. return false;
  3842. }
  3843. /**
  3844. * A specialized version of `_.map` for arrays without support for iteratee
  3845. * shorthands.
  3846. *
  3847. * @private
  3848. * @param {Array} [array] The array to iterate over.
  3849. * @param {Function} iteratee The function invoked per iteration.
  3850. * @returns {Array} Returns the new mapped array.
  3851. */
  3852. function arrayMap(array, iteratee) {
  3853. var index = -1,
  3854. length = array == null ? 0 : array.length,
  3855. result = Array(length);
  3856. while (++index < length) {
  3857. result[index] = iteratee(array[index], index, array);
  3858. }
  3859. return result;
  3860. }
  3861. /**
  3862. * Appends the elements of `values` to `array`.
  3863. *
  3864. * @private
  3865. * @param {Array} array The array to modify.
  3866. * @param {Array} values The values to append.
  3867. * @returns {Array} Returns `array`.
  3868. */
  3869. function arrayPush(array, values) {
  3870. var index = -1,
  3871. length = values.length,
  3872. offset = array.length;
  3873. while (++index < length) {
  3874. array[offset + index] = values[index];
  3875. }
  3876. return array;
  3877. }
  3878. /**
  3879. * A specialized version of `_.reduce` for arrays without support for
  3880. * iteratee shorthands.
  3881. *
  3882. * @private
  3883. * @param {Array} [array] The array to iterate over.
  3884. * @param {Function} iteratee The function invoked per iteration.
  3885. * @param {*} [accumulator] The initial value.
  3886. * @param {boolean} [initAccum] Specify using the first element of `array` as
  3887. * the initial value.
  3888. * @returns {*} Returns the accumulated value.
  3889. */
  3890. function arrayReduce(array, iteratee, accumulator, initAccum) {
  3891. var index = -1,
  3892. length = array == null ? 0 : array.length;
  3893. if (initAccum && length) {
  3894. accumulator = array[++index];
  3895. }
  3896. while (++index < length) {
  3897. accumulator = iteratee(accumulator, array[index], index, array);
  3898. }
  3899. return accumulator;
  3900. }
  3901. /**
  3902. * A specialized version of `_.reduceRight` for arrays without support for
  3903. * iteratee shorthands.
  3904. *
  3905. * @private
  3906. * @param {Array} [array] The array to iterate over.
  3907. * @param {Function} iteratee The function invoked per iteration.
  3908. * @param {*} [accumulator] The initial value.
  3909. * @param {boolean} [initAccum] Specify using the last element of `array` as
  3910. * the initial value.
  3911. * @returns {*} Returns the accumulated value.
  3912. */
  3913. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  3914. var length = array == null ? 0 : array.length;
  3915. if (initAccum && length) {
  3916. accumulator = array[--length];
  3917. }
  3918. while (length--) {
  3919. accumulator = iteratee(accumulator, array[length], length, array);
  3920. }
  3921. return accumulator;
  3922. }
  3923. /**
  3924. * A specialized version of `_.some` for arrays without support for iteratee
  3925. * shorthands.
  3926. *
  3927. * @private
  3928. * @param {Array} [array] The array to iterate over.
  3929. * @param {Function} predicate The function invoked per iteration.
  3930. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3931. * else `false`.
  3932. */
  3933. function arraySome(array, predicate) {
  3934. var index = -1,
  3935. length = array == null ? 0 : array.length;
  3936. while (++index < length) {
  3937. if (predicate(array[index], index, array)) {
  3938. return true;
  3939. }
  3940. }
  3941. return false;
  3942. }
  3943. /**
  3944. * Gets the size of an ASCII `string`.
  3945. *
  3946. * @private
  3947. * @param {string} string The string inspect.
  3948. * @returns {number} Returns the string size.
  3949. */
  3950. var asciiSize = baseProperty('length');
  3951. /**
  3952. * Converts an ASCII `string` to an array.
  3953. *
  3954. * @private
  3955. * @param {string} string The string to convert.
  3956. * @returns {Array} Returns the converted array.
  3957. */
  3958. function asciiToArray(string) {
  3959. return string.split('');
  3960. }
  3961. /**
  3962. * Splits an ASCII `string` into an array of its words.
  3963. *
  3964. * @private
  3965. * @param {string} The string to inspect.
  3966. * @returns {Array} Returns the words of `string`.
  3967. */
  3968. function asciiWords(string) {
  3969. return string.match(reAsciiWord) || [];
  3970. }
  3971. /**
  3972. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  3973. * without support for iteratee shorthands, which iterates over `collection`
  3974. * using `eachFunc`.
  3975. *
  3976. * @private
  3977. * @param {Array|Object} collection The collection to inspect.
  3978. * @param {Function} predicate The function invoked per iteration.
  3979. * @param {Function} eachFunc The function to iterate over `collection`.
  3980. * @returns {*} Returns the found element or its key, else `undefined`.
  3981. */
  3982. function baseFindKey(collection, predicate, eachFunc) {
  3983. var result;
  3984. eachFunc(collection, function(value, key, collection) {
  3985. if (predicate(value, key, collection)) {
  3986. result = key;
  3987. return false;
  3988. }
  3989. });
  3990. return result;
  3991. }
  3992. /**
  3993. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  3994. * support for iteratee shorthands.
  3995. *
  3996. * @private
  3997. * @param {Array} array The array to inspect.
  3998. * @param {Function} predicate The function invoked per iteration.
  3999. * @param {number} fromIndex The index to search from.
  4000. * @param {boolean} [fromRight] Specify iterating from right to left.
  4001. * @returns {number} Returns the index of the matched value, else `-1`.
  4002. */
  4003. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  4004. var length = array.length,
  4005. index = fromIndex + (fromRight ? 1 : -1);
  4006. while ((fromRight ? index-- : ++index < length)) {
  4007. if (predicate(array[index], index, array)) {
  4008. return index;
  4009. }
  4010. }
  4011. return -1;
  4012. }
  4013. /**
  4014. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  4015. *
  4016. * @private
  4017. * @param {Array} array The array to inspect.
  4018. * @param {*} value The value to search for.
  4019. * @param {number} fromIndex The index to search from.
  4020. * @returns {number} Returns the index of the matched value, else `-1`.
  4021. */
  4022. function baseIndexOf(array, value, fromIndex) {
  4023. return value === value
  4024. ? strictIndexOf(array, value, fromIndex)
  4025. : baseFindIndex(array, baseIsNaN, fromIndex);
  4026. }
  4027. /**
  4028. * This function is like `baseIndexOf` except that it accepts a comparator.
  4029. *
  4030. * @private
  4031. * @param {Array} array The array to inspect.
  4032. * @param {*} value The value to search for.
  4033. * @param {number} fromIndex The index to search from.
  4034. * @param {Function} comparator The comparator invoked per element.
  4035. * @returns {number} Returns the index of the matched value, else `-1`.
  4036. */
  4037. function baseIndexOfWith(array, value, fromIndex, comparator) {
  4038. var index = fromIndex - 1,
  4039. length = array.length;
  4040. while (++index < length) {
  4041. if (comparator(array[index], value)) {
  4042. return index;
  4043. }
  4044. }
  4045. return -1;
  4046. }
  4047. /**
  4048. * The base implementation of `_.isNaN` without support for number objects.
  4049. *
  4050. * @private
  4051. * @param {*} value The value to check.
  4052. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  4053. */
  4054. function baseIsNaN(value) {
  4055. return value !== value;
  4056. }
  4057. /**
  4058. * The base implementation of `_.mean` and `_.meanBy` without support for
  4059. * iteratee shorthands.
  4060. *
  4061. * @private
  4062. * @param {Array} array The array to iterate over.
  4063. * @param {Function} iteratee The function invoked per iteration.
  4064. * @returns {number} Returns the mean.
  4065. */
  4066. function baseMean(array, iteratee) {
  4067. var length = array == null ? 0 : array.length;
  4068. return length ? (baseSum(array, iteratee) / length) : NAN;
  4069. }
  4070. /**
  4071. * The base implementation of `_.property` without support for deep paths.
  4072. *
  4073. * @private
  4074. * @param {string} key The key of the property to get.
  4075. * @returns {Function} Returns the new accessor function.
  4076. */
  4077. function baseProperty(key) {
  4078. return function(object) {
  4079. return object == null ? undefined : object[key];
  4080. };
  4081. }
  4082. /**
  4083. * The base implementation of `_.propertyOf` without support for deep paths.
  4084. *
  4085. * @private
  4086. * @param {Object} object The object to query.
  4087. * @returns {Function} Returns the new accessor function.
  4088. */
  4089. function basePropertyOf(object) {
  4090. return function(key) {
  4091. return object == null ? undefined : object[key];
  4092. };
  4093. }
  4094. /**
  4095. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  4096. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  4097. *
  4098. * @private
  4099. * @param {Array|Object} collection The collection to iterate over.
  4100. * @param {Function} iteratee The function invoked per iteration.
  4101. * @param {*} accumulator The initial value.
  4102. * @param {boolean} initAccum Specify using the first or last element of
  4103. * `collection` as the initial value.
  4104. * @param {Function} eachFunc The function to iterate over `collection`.
  4105. * @returns {*} Returns the accumulated value.
  4106. */
  4107. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  4108. eachFunc(collection, function(value, index, collection) {
  4109. accumulator = initAccum
  4110. ? (initAccum = false, value)
  4111. : iteratee(accumulator, value, index, collection);
  4112. });
  4113. return accumulator;
  4114. }
  4115. /**
  4116. * The base implementation of `_.sortBy` which uses `comparer` to define the
  4117. * sort order of `array` and replaces criteria objects with their corresponding
  4118. * values.
  4119. *
  4120. * @private
  4121. * @param {Array} array The array to sort.
  4122. * @param {Function} comparer The function to define sort order.
  4123. * @returns {Array} Returns `array`.
  4124. */
  4125. function baseSortBy(array, comparer) {
  4126. var length = array.length;
  4127. array.sort(comparer);
  4128. while (length--) {
  4129. array[length] = array[length].value;
  4130. }
  4131. return array;
  4132. }
  4133. /**
  4134. * The base implementation of `_.sum` and `_.sumBy` without support for
  4135. * iteratee shorthands.
  4136. *
  4137. * @private
  4138. * @param {Array} array The array to iterate over.
  4139. * @param {Function} iteratee The function invoked per iteration.
  4140. * @returns {number} Returns the sum.
  4141. */
  4142. function baseSum(array, iteratee) {
  4143. var result,
  4144. index = -1,
  4145. length = array.length;
  4146. while (++index < length) {
  4147. var current = iteratee(array[index]);
  4148. if (current !== undefined) {
  4149. result = result === undefined ? current : (result + current);
  4150. }
  4151. }
  4152. return result;
  4153. }
  4154. /**
  4155. * The base implementation of `_.times` without support for iteratee shorthands
  4156. * or max array length checks.
  4157. *
  4158. * @private
  4159. * @param {number} n The number of times to invoke `iteratee`.
  4160. * @param {Function} iteratee The function invoked per iteration.
  4161. * @returns {Array} Returns the array of results.
  4162. */
  4163. function baseTimes(n, iteratee) {
  4164. var index = -1,
  4165. result = Array(n);
  4166. while (++index < n) {
  4167. result[index] = iteratee(index);
  4168. }
  4169. return result;
  4170. }
  4171. /**
  4172. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  4173. * of key-value pairs for `object` corresponding to the property names of `props`.
  4174. *
  4175. * @private
  4176. * @param {Object} object The object to query.
  4177. * @param {Array} props The property names to get values for.
  4178. * @returns {Object} Returns the key-value pairs.
  4179. */
  4180. function baseToPairs(object, props) {
  4181. return arrayMap(props, function(key) {
  4182. return [key, object[key]];
  4183. });
  4184. }
  4185. /**
  4186. * The base implementation of `_.unary` without support for storing metadata.
  4187. *
  4188. * @private
  4189. * @param {Function} func The function to cap arguments for.
  4190. * @returns {Function} Returns the new capped function.
  4191. */
  4192. function baseUnary(func) {
  4193. return function(value) {
  4194. return func(value);
  4195. };
  4196. }
  4197. /**
  4198. * The base implementation of `_.values` and `_.valuesIn` which creates an
  4199. * array of `object` property values corresponding to the property names
  4200. * of `props`.
  4201. *
  4202. * @private
  4203. * @param {Object} object The object to query.
  4204. * @param {Array} props The property names to get values for.
  4205. * @returns {Object} Returns the array of property values.
  4206. */
  4207. function baseValues(object, props) {
  4208. return arrayMap(props, function(key) {
  4209. return object[key];
  4210. });
  4211. }
  4212. /**
  4213. * Checks if a `cache` value for `key` exists.
  4214. *
  4215. * @private
  4216. * @param {Object} cache The cache to query.
  4217. * @param {string} key The key of the entry to check.
  4218. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  4219. */
  4220. function cacheHas(cache, key) {
  4221. return cache.has(key);
  4222. }
  4223. /**
  4224. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  4225. * that is not found in the character symbols.
  4226. *
  4227. * @private
  4228. * @param {Array} strSymbols The string symbols to inspect.
  4229. * @param {Array} chrSymbols The character symbols to find.
  4230. * @returns {number} Returns the index of the first unmatched string symbol.
  4231. */
  4232. function charsStartIndex(strSymbols, chrSymbols) {
  4233. var index = -1,
  4234. length = strSymbols.length;
  4235. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  4236. return index;
  4237. }
  4238. /**
  4239. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  4240. * that is not found in the character symbols.
  4241. *
  4242. * @private
  4243. * @param {Array} strSymbols The string symbols to inspect.
  4244. * @param {Array} chrSymbols The character symbols to find.
  4245. * @returns {number} Returns the index of the last unmatched string symbol.
  4246. */
  4247. function charsEndIndex(strSymbols, chrSymbols) {
  4248. var index = strSymbols.length;
  4249. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  4250. return index;
  4251. }
  4252. /**
  4253. * Gets the number of `placeholder` occurrences in `array`.
  4254. *
  4255. * @private
  4256. * @param {Array} array The array to inspect.
  4257. * @param {*} placeholder The placeholder to search for.
  4258. * @returns {number} Returns the placeholder count.
  4259. */
  4260. function countHolders(array, placeholder) {
  4261. var length = array.length,
  4262. result = 0;
  4263. while (length--) {
  4264. if (array[length] === placeholder) {
  4265. ++result;
  4266. }
  4267. }
  4268. return result;
  4269. }
  4270. /**
  4271. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  4272. * letters to basic Latin letters.
  4273. *
  4274. * @private
  4275. * @param {string} letter The matched letter to deburr.
  4276. * @returns {string} Returns the deburred letter.
  4277. */
  4278. var deburrLetter = basePropertyOf(deburredLetters);
  4279. /**
  4280. * Used by `_.escape` to convert characters to HTML entities.
  4281. *
  4282. * @private
  4283. * @param {string} chr The matched character to escape.
  4284. * @returns {string} Returns the escaped character.
  4285. */
  4286. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  4287. /**
  4288. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  4289. *
  4290. * @private
  4291. * @param {string} chr The matched character to escape.
  4292. * @returns {string} Returns the escaped character.
  4293. */
  4294. function escapeStringChar(chr) {
  4295. return '\\' + stringEscapes[chr];
  4296. }
  4297. /**
  4298. * Gets the value at `key` of `object`.
  4299. *
  4300. * @private
  4301. * @param {Object} [object] The object to query.
  4302. * @param {string} key The key of the property to get.
  4303. * @returns {*} Returns the property value.
  4304. */
  4305. function getValue(object, key) {
  4306. return object == null ? undefined : object[key];
  4307. }
  4308. /**
  4309. * Checks if `string` contains Unicode symbols.
  4310. *
  4311. * @private
  4312. * @param {string} string The string to inspect.
  4313. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  4314. */
  4315. function hasUnicode(string) {
  4316. return reHasUnicode.test(string);
  4317. }
  4318. /**
  4319. * Checks if `string` contains a word composed of Unicode symbols.
  4320. *
  4321. * @private
  4322. * @param {string} string The string to inspect.
  4323. * @returns {boolean} Returns `true` if a word is found, else `false`.
  4324. */
  4325. function hasUnicodeWord(string) {
  4326. return reHasUnicodeWord.test(string);
  4327. }
  4328. /**
  4329. * Converts `iterator` to an array.
  4330. *
  4331. * @private
  4332. * @param {Object} iterator The iterator to convert.
  4333. * @returns {Array} Returns the converted array.
  4334. */
  4335. function iteratorToArray(iterator) {
  4336. var data,
  4337. result = [];
  4338. while (!(data = iterator.next()).done) {
  4339. result.push(data.value);
  4340. }
  4341. return result;
  4342. }
  4343. /**
  4344. * Converts `map` to its key-value pairs.
  4345. *
  4346. * @private
  4347. * @param {Object} map The map to convert.
  4348. * @returns {Array} Returns the key-value pairs.
  4349. */
  4350. function mapToArray(map) {
  4351. var index = -1,
  4352. result = Array(map.size);
  4353. map.forEach(function(value, key) {
  4354. result[++index] = [key, value];
  4355. });
  4356. return result;
  4357. }
  4358. /**
  4359. * Creates a unary function that invokes `func` with its argument transformed.
  4360. *
  4361. * @private
  4362. * @param {Function} func The function to wrap.
  4363. * @param {Function} transform The argument transform.
  4364. * @returns {Function} Returns the new function.
  4365. */
  4366. function overArg(func, transform) {
  4367. return function(arg) {
  4368. return func(transform(arg));
  4369. };
  4370. }
  4371. /**
  4372. * Replaces all `placeholder` elements in `array` with an internal placeholder
  4373. * and returns an array of their indexes.
  4374. *
  4375. * @private
  4376. * @param {Array} array The array to modify.
  4377. * @param {*} placeholder The placeholder to replace.
  4378. * @returns {Array} Returns the new array of placeholder indexes.
  4379. */
  4380. function replaceHolders(array, placeholder) {
  4381. var index = -1,
  4382. length = array.length,
  4383. resIndex = 0,
  4384. result = [];
  4385. while (++index < length) {
  4386. var value = array[index];
  4387. if (value === placeholder || value === PLACEHOLDER) {
  4388. array[index] = PLACEHOLDER;
  4389. result[resIndex++] = index;
  4390. }
  4391. }
  4392. return result;
  4393. }
  4394. /**
  4395. * Converts `set` to an array of its values.
  4396. *
  4397. * @private
  4398. * @param {Object} set The set to convert.
  4399. * @returns {Array} Returns the values.
  4400. */
  4401. function setToArray(set) {
  4402. var index = -1,
  4403. result = Array(set.size);
  4404. set.forEach(function(value) {
  4405. result[++index] = value;
  4406. });
  4407. return result;
  4408. }
  4409. /**
  4410. * Converts `set` to its value-value pairs.
  4411. *
  4412. * @private
  4413. * @param {Object} set The set to convert.
  4414. * @returns {Array} Returns the value-value pairs.
  4415. */
  4416. function setToPairs(set) {
  4417. var index = -1,
  4418. result = Array(set.size);
  4419. set.forEach(function(value) {
  4420. result[++index] = [value, value];
  4421. });
  4422. return result;
  4423. }
  4424. /**
  4425. * A specialized version of `_.indexOf` which performs strict equality
  4426. * comparisons of values, i.e. `===`.
  4427. *
  4428. * @private
  4429. * @param {Array} array The array to inspect.
  4430. * @param {*} value The value to search for.
  4431. * @param {number} fromIndex The index to search from.
  4432. * @returns {number} Returns the index of the matched value, else `-1`.
  4433. */
  4434. function strictIndexOf(array, value, fromIndex) {
  4435. var index = fromIndex - 1,
  4436. length = array.length;
  4437. while (++index < length) {
  4438. if (array[index] === value) {
  4439. return index;
  4440. }
  4441. }
  4442. return -1;
  4443. }
  4444. /**
  4445. * A specialized version of `_.lastIndexOf` which performs strict equality
  4446. * comparisons of values, i.e. `===`.
  4447. *
  4448. * @private
  4449. * @param {Array} array The array to inspect.
  4450. * @param {*} value The value to search for.
  4451. * @param {number} fromIndex The index to search from.
  4452. * @returns {number} Returns the index of the matched value, else `-1`.
  4453. */
  4454. function strictLastIndexOf(array, value, fromIndex) {
  4455. var index = fromIndex + 1;
  4456. while (index--) {
  4457. if (array[index] === value) {
  4458. return index;
  4459. }
  4460. }
  4461. return index;
  4462. }
  4463. /**
  4464. * Gets the number of symbols in `string`.
  4465. *
  4466. * @private
  4467. * @param {string} string The string to inspect.
  4468. * @returns {number} Returns the string size.
  4469. */
  4470. function stringSize(string) {
  4471. return hasUnicode(string)
  4472. ? unicodeSize(string)
  4473. : asciiSize(string);
  4474. }
  4475. /**
  4476. * Converts `string` to an array.
  4477. *
  4478. * @private
  4479. * @param {string} string The string to convert.
  4480. * @returns {Array} Returns the converted array.
  4481. */
  4482. function stringToArray(string) {
  4483. return hasUnicode(string)
  4484. ? unicodeToArray(string)
  4485. : asciiToArray(string);
  4486. }
  4487. /**
  4488. * Used by `_.unescape` to convert HTML entities to characters.
  4489. *
  4490. * @private
  4491. * @param {string} chr The matched character to unescape.
  4492. * @returns {string} Returns the unescaped character.
  4493. */
  4494. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  4495. /**
  4496. * Gets the size of a Unicode `string`.
  4497. *
  4498. * @private
  4499. * @param {string} string The string inspect.
  4500. * @returns {number} Returns the string size.
  4501. */
  4502. function unicodeSize(string) {
  4503. var result = reUnicode.lastIndex = 0;
  4504. while (reUnicode.test(string)) {
  4505. ++result;
  4506. }
  4507. return result;
  4508. }
  4509. /**
  4510. * Converts a Unicode `string` to an array.
  4511. *
  4512. * @private
  4513. * @param {string} string The string to convert.
  4514. * @returns {Array} Returns the converted array.
  4515. */
  4516. function unicodeToArray(string) {
  4517. return string.match(reUnicode) || [];
  4518. }
  4519. /**
  4520. * Splits a Unicode `string` into an array of its words.
  4521. *
  4522. * @private
  4523. * @param {string} The string to inspect.
  4524. * @returns {Array} Returns the words of `string`.
  4525. */
  4526. function unicodeWords(string) {
  4527. return string.match(reUnicodeWord) || [];
  4528. }
  4529. /*--------------------------------------------------------------------------*/
  4530. /**
  4531. * Create a new pristine `lodash` function using the `context` object.
  4532. *
  4533. * @static
  4534. * @memberOf _
  4535. * @since 1.1.0
  4536. * @category Util
  4537. * @param {Object} [context=root] The context object.
  4538. * @returns {Function} Returns a new `lodash` function.
  4539. * @example
  4540. *
  4541. * _.mixin({ 'foo': _.constant('foo') });
  4542. *
  4543. * var lodash = _.runInContext();
  4544. * lodash.mixin({ 'bar': lodash.constant('bar') });
  4545. *
  4546. * _.isFunction(_.foo);
  4547. * // => true
  4548. * _.isFunction(_.bar);
  4549. * // => false
  4550. *
  4551. * lodash.isFunction(lodash.foo);
  4552. * // => false
  4553. * lodash.isFunction(lodash.bar);
  4554. * // => true
  4555. *
  4556. * // Create a suped-up `defer` in Node.js.
  4557. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  4558. */
  4559. var runInContext = (function runInContext(context) {
  4560. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  4561. /** Built-in constructor references. */
  4562. var Array = context.Array,
  4563. Date = context.Date,
  4564. Error = context.Error,
  4565. Function = context.Function,
  4566. Math = context.Math,
  4567. Object = context.Object,
  4568. RegExp = context.RegExp,
  4569. String = context.String,
  4570. TypeError = context.TypeError;
  4571. /** Used for built-in method references. */
  4572. var arrayProto = Array.prototype,
  4573. funcProto = Function.prototype,
  4574. objectProto = Object.prototype;
  4575. /** Used to detect overreaching core-js shims. */
  4576. var coreJsData = context['__core-js_shared__'];
  4577. /** Used to resolve the decompiled source of functions. */
  4578. var funcToString = funcProto.toString;
  4579. /** Used to check objects for own properties. */
  4580. var hasOwnProperty = objectProto.hasOwnProperty;
  4581. /** Used to generate unique IDs. */
  4582. var idCounter = 0;
  4583. /** Used to detect methods masquerading as native. */
  4584. var maskSrcKey = (function() {
  4585. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  4586. return uid ? ('Symbol(src)_1.' + uid) : '';
  4587. }());
  4588. /**
  4589. * Used to resolve the
  4590. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  4591. * of values.
  4592. */
  4593. var nativeObjectToString = objectProto.toString;
  4594. /** Used to infer the `Object` constructor. */
  4595. var objectCtorString = funcToString.call(Object);
  4596. /** Used to restore the original `_` reference in `_.noConflict`. */
  4597. var oldDash = root._;
  4598. /** Used to detect if a method is native. */
  4599. var reIsNative = RegExp('^' +
  4600. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  4601. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  4602. );
  4603. /** Built-in value references. */
  4604. var Buffer = moduleExports ? context.Buffer : undefined,
  4605. Symbol = context.Symbol,
  4606. Uint8Array = context.Uint8Array,
  4607. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  4608. getPrototype = overArg(Object.getPrototypeOf, Object),
  4609. objectCreate = Object.create,
  4610. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  4611. splice = arrayProto.splice,
  4612. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  4613. symIterator = Symbol ? Symbol.iterator : undefined,
  4614. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  4615. var defineProperty = (function() {
  4616. try {
  4617. var func = getNative(Object, 'defineProperty');
  4618. func({}, '', {});
  4619. return func;
  4620. } catch (e) {}
  4621. }());
  4622. /** Mocked built-ins. */
  4623. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  4624. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  4625. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  4626. /* Built-in method references for those with the same name as other `lodash` methods. */
  4627. var nativeCeil = Math.ceil,
  4628. nativeFloor = Math.floor,
  4629. nativeGetSymbols = Object.getOwnPropertySymbols,
  4630. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  4631. nativeIsFinite = context.isFinite,
  4632. nativeJoin = arrayProto.join,
  4633. nativeKeys = overArg(Object.keys, Object),
  4634. nativeMax = Math.max,
  4635. nativeMin = Math.min,
  4636. nativeNow = Date.now,
  4637. nativeParseInt = context.parseInt,
  4638. nativeRandom = Math.random,
  4639. nativeReverse = arrayProto.reverse;
  4640. /* Built-in method references that are verified to be native. */
  4641. var DataView = getNative(context, 'DataView'),
  4642. Map = getNative(context, 'Map'),
  4643. Promise = getNative(context, 'Promise'),
  4644. Set = getNative(context, 'Set'),
  4645. WeakMap = getNative(context, 'WeakMap'),
  4646. nativeCreate = getNative(Object, 'create');
  4647. /** Used to store function metadata. */
  4648. var metaMap = WeakMap && new WeakMap;
  4649. /** Used to lookup unminified function names. */
  4650. var realNames = {};
  4651. /** Used to detect maps, sets, and weakmaps. */
  4652. var dataViewCtorString = toSource(DataView),
  4653. mapCtorString = toSource(Map),
  4654. promiseCtorString = toSource(Promise),
  4655. setCtorString = toSource(Set),
  4656. weakMapCtorString = toSource(WeakMap);
  4657. /** Used to convert symbols to primitives and strings. */
  4658. var symbolProto = Symbol ? Symbol.prototype : undefined,
  4659. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  4660. symbolToString = symbolProto ? symbolProto.toString : undefined;
  4661. /*------------------------------------------------------------------------*/
  4662. /**
  4663. * Creates a `lodash` object which wraps `value` to enable implicit method
  4664. * chain sequences. Methods that operate on and return arrays, collections,
  4665. * and functions can be chained together. Methods that retrieve a single value
  4666. * or may return a primitive value will automatically end the chain sequence
  4667. * and return the unwrapped value. Otherwise, the value must be unwrapped
  4668. * with `_#value`.
  4669. *
  4670. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  4671. * enabled using `_.chain`.
  4672. *
  4673. * The execution of chained methods is lazy, that is, it's deferred until
  4674. * `_#value` is implicitly or explicitly called.
  4675. *
  4676. * Lazy evaluation allows several methods to support shortcut fusion.
  4677. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  4678. * the creation of intermediate arrays and can greatly reduce the number of
  4679. * iteratee executions. Sections of a chain sequence qualify for shortcut
  4680. * fusion if the section is applied to an array and iteratees accept only
  4681. * one argument. The heuristic for whether a section qualifies for shortcut
  4682. * fusion is subject to change.
  4683. *
  4684. * Chaining is supported in custom builds as long as the `_#value` method is
  4685. * directly or indirectly included in the build.
  4686. *
  4687. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  4688. *
  4689. * The wrapper `Array` methods are:
  4690. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  4691. *
  4692. * The wrapper `String` methods are:
  4693. * `replace` and `split`
  4694. *
  4695. * The wrapper methods that support shortcut fusion are:
  4696. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  4697. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  4698. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  4699. *
  4700. * The chainable wrapper methods are:
  4701. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  4702. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  4703. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  4704. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  4705. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  4706. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  4707. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  4708. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  4709. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  4710. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  4711. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  4712. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  4713. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  4714. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  4715. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  4716. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  4717. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  4718. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  4719. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  4720. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  4721. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  4722. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  4723. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  4724. * `zipObject`, `zipObjectDeep`, and `zipWith`
  4725. *
  4726. * The wrapper methods that are **not** chainable by default are:
  4727. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  4728. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  4729. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  4730. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  4731. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  4732. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  4733. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  4734. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  4735. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  4736. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  4737. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  4738. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  4739. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  4740. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  4741. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  4742. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  4743. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  4744. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  4745. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  4746. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  4747. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  4748. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  4749. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  4750. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  4751. * `upperFirst`, `value`, and `words`
  4752. *
  4753. * @name _
  4754. * @constructor
  4755. * @category Seq
  4756. * @param {*} value The value to wrap in a `lodash` instance.
  4757. * @returns {Object} Returns the new `lodash` wrapper instance.
  4758. * @example
  4759. *
  4760. * function square(n) {
  4761. * return n * n;
  4762. * }
  4763. *
  4764. * var wrapped = _([1, 2, 3]);
  4765. *
  4766. * // Returns an unwrapped value.
  4767. * wrapped.reduce(_.add);
  4768. * // => 6
  4769. *
  4770. * // Returns a wrapped value.
  4771. * var squares = wrapped.map(square);
  4772. *
  4773. * _.isArray(squares);
  4774. * // => false
  4775. *
  4776. * _.isArray(squares.value());
  4777. * // => true
  4778. */
  4779. function lodash(value) {
  4780. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  4781. if (value instanceof LodashWrapper) {
  4782. return value;
  4783. }
  4784. if (hasOwnProperty.call(value, '__wrapped__')) {
  4785. return wrapperClone(value);
  4786. }
  4787. }
  4788. return new LodashWrapper(value);
  4789. }
  4790. /**
  4791. * The base implementation of `_.create` without support for assigning
  4792. * properties to the created object.
  4793. *
  4794. * @private
  4795. * @param {Object} proto The object to inherit from.
  4796. * @returns {Object} Returns the new object.
  4797. */
  4798. var baseCreate = (function() {
  4799. function object() {}
  4800. return function(proto) {
  4801. if (!isObject(proto)) {
  4802. return {};
  4803. }
  4804. if (objectCreate) {
  4805. return objectCreate(proto);
  4806. }
  4807. object.prototype = proto;
  4808. var result = new object;
  4809. object.prototype = undefined;
  4810. return result;
  4811. };
  4812. }());
  4813. /**
  4814. * The function whose prototype chain sequence wrappers inherit from.
  4815. *
  4816. * @private
  4817. */
  4818. function baseLodash() {
  4819. // No operation performed.
  4820. }
  4821. /**
  4822. * The base constructor for creating `lodash` wrapper objects.
  4823. *
  4824. * @private
  4825. * @param {*} value The value to wrap.
  4826. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  4827. */
  4828. function LodashWrapper(value, chainAll) {
  4829. this.__wrapped__ = value;
  4830. this.__actions__ = [];
  4831. this.__chain__ = !!chainAll;
  4832. this.__index__ = 0;
  4833. this.__values__ = undefined;
  4834. }
  4835. /**
  4836. * By default, the template delimiters used by lodash are like those in
  4837. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  4838. * following template settings to use alternative delimiters.
  4839. *
  4840. * @static
  4841. * @memberOf _
  4842. * @type {Object}
  4843. */
  4844. lodash.templateSettings = {
  4845. /**
  4846. * Used to detect `data` property values to be HTML-escaped.
  4847. *
  4848. * @memberOf _.templateSettings
  4849. * @type {RegExp}
  4850. */
  4851. 'escape': reEscape,
  4852. /**
  4853. * Used to detect code to be evaluated.
  4854. *
  4855. * @memberOf _.templateSettings
  4856. * @type {RegExp}
  4857. */
  4858. 'evaluate': reEvaluate,
  4859. /**
  4860. * Used to detect `data` property values to inject.
  4861. *
  4862. * @memberOf _.templateSettings
  4863. * @type {RegExp}
  4864. */
  4865. 'interpolate': reInterpolate,
  4866. /**
  4867. * Used to reference the data object in the template text.
  4868. *
  4869. * @memberOf _.templateSettings
  4870. * @type {string}
  4871. */
  4872. 'variable': '',
  4873. /**
  4874. * Used to import variables into the compiled template.
  4875. *
  4876. * @memberOf _.templateSettings
  4877. * @type {Object}
  4878. */
  4879. 'imports': {
  4880. /**
  4881. * A reference to the `lodash` function.
  4882. *
  4883. * @memberOf _.templateSettings.imports
  4884. * @type {Function}
  4885. */
  4886. '_': lodash
  4887. }
  4888. };
  4889. // Ensure wrappers are instances of `baseLodash`.
  4890. lodash.prototype = baseLodash.prototype;
  4891. lodash.prototype.constructor = lodash;
  4892. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  4893. LodashWrapper.prototype.constructor = LodashWrapper;
  4894. /*------------------------------------------------------------------------*/
  4895. /**
  4896. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  4897. *
  4898. * @private
  4899. * @constructor
  4900. * @param {*} value The value to wrap.
  4901. */
  4902. function LazyWrapper(value) {
  4903. this.__wrapped__ = value;
  4904. this.__actions__ = [];
  4905. this.__dir__ = 1;
  4906. this.__filtered__ = false;
  4907. this.__iteratees__ = [];
  4908. this.__takeCount__ = MAX_ARRAY_LENGTH;
  4909. this.__views__ = [];
  4910. }
  4911. /**
  4912. * Creates a clone of the lazy wrapper object.
  4913. *
  4914. * @private
  4915. * @name clone
  4916. * @memberOf LazyWrapper
  4917. * @returns {Object} Returns the cloned `LazyWrapper` object.
  4918. */
  4919. function lazyClone() {
  4920. var result = new LazyWrapper(this.__wrapped__);
  4921. result.__actions__ = copyArray(this.__actions__);
  4922. result.__dir__ = this.__dir__;
  4923. result.__filtered__ = this.__filtered__;
  4924. result.__iteratees__ = copyArray(this.__iteratees__);
  4925. result.__takeCount__ = this.__takeCount__;
  4926. result.__views__ = copyArray(this.__views__);
  4927. return result;
  4928. }
  4929. /**
  4930. * Reverses the direction of lazy iteration.
  4931. *
  4932. * @private
  4933. * @name reverse
  4934. * @memberOf LazyWrapper
  4935. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  4936. */
  4937. function lazyReverse() {
  4938. if (this.__filtered__) {
  4939. var result = new LazyWrapper(this);
  4940. result.__dir__ = -1;
  4941. result.__filtered__ = true;
  4942. } else {
  4943. result = this.clone();
  4944. result.__dir__ *= -1;
  4945. }
  4946. return result;
  4947. }
  4948. /**
  4949. * Extracts the unwrapped value from its lazy wrapper.
  4950. *
  4951. * @private
  4952. * @name value
  4953. * @memberOf LazyWrapper
  4954. * @returns {*} Returns the unwrapped value.
  4955. */
  4956. function lazyValue() {
  4957. var array = this.__wrapped__.value(),
  4958. dir = this.__dir__,
  4959. isArr = isArray(array),
  4960. isRight = dir < 0,
  4961. arrLength = isArr ? array.length : 0,
  4962. view = getView(0, arrLength, this.__views__),
  4963. start = view.start,
  4964. end = view.end,
  4965. length = end - start,
  4966. index = isRight ? end : (start - 1),
  4967. iteratees = this.__iteratees__,
  4968. iterLength = iteratees.length,
  4969. resIndex = 0,
  4970. takeCount = nativeMin(length, this.__takeCount__);
  4971. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  4972. return baseWrapperValue(array, this.__actions__);
  4973. }
  4974. var result = [];
  4975. outer:
  4976. while (length-- && resIndex < takeCount) {
  4977. index += dir;
  4978. var iterIndex = -1,
  4979. value = array[index];
  4980. while (++iterIndex < iterLength) {
  4981. var data = iteratees[iterIndex],
  4982. iteratee = data.iteratee,
  4983. type = data.type,
  4984. computed = iteratee(value);
  4985. if (type == LAZY_MAP_FLAG) {
  4986. value = computed;
  4987. } else if (!computed) {
  4988. if (type == LAZY_FILTER_FLAG) {
  4989. continue outer;
  4990. } else {
  4991. break outer;
  4992. }
  4993. }
  4994. }
  4995. result[resIndex++] = value;
  4996. }
  4997. return result;
  4998. }
  4999. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  5000. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  5001. LazyWrapper.prototype.constructor = LazyWrapper;
  5002. /*------------------------------------------------------------------------*/
  5003. /**
  5004. * Creates a hash object.
  5005. *
  5006. * @private
  5007. * @constructor
  5008. * @param {Array} [entries] The key-value pairs to cache.
  5009. */
  5010. function Hash(entries) {
  5011. var index = -1,
  5012. length = entries == null ? 0 : entries.length;
  5013. this.clear();
  5014. while (++index < length) {
  5015. var entry = entries[index];
  5016. this.set(entry[0], entry[1]);
  5017. }
  5018. }
  5019. /**
  5020. * Removes all key-value entries from the hash.
  5021. *
  5022. * @private
  5023. * @name clear
  5024. * @memberOf Hash
  5025. */
  5026. function hashClear() {
  5027. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  5028. this.size = 0;
  5029. }
  5030. /**
  5031. * Removes `key` and its value from the hash.
  5032. *
  5033. * @private
  5034. * @name delete
  5035. * @memberOf Hash
  5036. * @param {Object} hash The hash to modify.
  5037. * @param {string} key The key of the value to remove.
  5038. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  5039. */
  5040. function hashDelete(key) {
  5041. var result = this.has(key) && delete this.__data__[key];
  5042. this.size -= result ? 1 : 0;
  5043. return result;
  5044. }
  5045. /**
  5046. * Gets the hash value for `key`.
  5047. *
  5048. * @private
  5049. * @name get
  5050. * @memberOf Hash
  5051. * @param {string} key The key of the value to get.
  5052. * @returns {*} Returns the entry value.
  5053. */
  5054. function hashGet(key) {
  5055. var data = this.__data__;
  5056. if (nativeCreate) {
  5057. var result = data[key];
  5058. return result === HASH_UNDEFINED ? undefined : result;
  5059. }
  5060. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  5061. }
  5062. /**
  5063. * Checks if a hash value for `key` exists.
  5064. *
  5065. * @private
  5066. * @name has
  5067. * @memberOf Hash
  5068. * @param {string} key The key of the entry to check.
  5069. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  5070. */
  5071. function hashHas(key) {
  5072. var data = this.__data__;
  5073. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  5074. }
  5075. /**
  5076. * Sets the hash `key` to `value`.
  5077. *
  5078. * @private
  5079. * @name set
  5080. * @memberOf Hash
  5081. * @param {string} key The key of the value to set.
  5082. * @param {*} value The value to set.
  5083. * @returns {Object} Returns the hash instance.
  5084. */
  5085. function hashSet(key, value) {
  5086. var data = this.__data__;
  5087. this.size += this.has(key) ? 0 : 1;
  5088. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  5089. return this;
  5090. }
  5091. // Add methods to `Hash`.
  5092. Hash.prototype.clear = hashClear;
  5093. Hash.prototype['delete'] = hashDelete;
  5094. Hash.prototype.get = hashGet;
  5095. Hash.prototype.has = hashHas;
  5096. Hash.prototype.set = hashSet;
  5097. /*------------------------------------------------------------------------*/
  5098. /**
  5099. * Creates an list cache object.
  5100. *
  5101. * @private
  5102. * @constructor
  5103. * @param {Array} [entries] The key-value pairs to cache.
  5104. */
  5105. function ListCache(entries) {
  5106. var index = -1,
  5107. length = entries == null ? 0 : entries.length;
  5108. this.clear();
  5109. while (++index < length) {
  5110. var entry = entries[index];
  5111. this.set(entry[0], entry[1]);
  5112. }
  5113. }
  5114. /**
  5115. * Removes all key-value entries from the list cache.
  5116. *
  5117. * @private
  5118. * @name clear
  5119. * @memberOf ListCache
  5120. */
  5121. function listCacheClear() {
  5122. this.__data__ = [];
  5123. this.size = 0;
  5124. }
  5125. /**
  5126. * Removes `key` and its value from the list cache.
  5127. *
  5128. * @private
  5129. * @name delete
  5130. * @memberOf ListCache
  5131. * @param {string} key The key of the value to remove.
  5132. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  5133. */
  5134. function listCacheDelete(key) {
  5135. var data = this.__data__,
  5136. index = assocIndexOf(data, key);
  5137. if (index < 0) {
  5138. return false;
  5139. }
  5140. var lastIndex = data.length - 1;
  5141. if (index == lastIndex) {
  5142. data.pop();
  5143. } else {
  5144. splice.call(data, index, 1);
  5145. }
  5146. --this.size;
  5147. return true;
  5148. }
  5149. /**
  5150. * Gets the list cache value for `key`.
  5151. *
  5152. * @private
  5153. * @name get
  5154. * @memberOf ListCache
  5155. * @param {string} key The key of the value to get.
  5156. * @returns {*} Returns the entry value.
  5157. */
  5158. function listCacheGet(key) {
  5159. var data = this.__data__,
  5160. index = assocIndexOf(data, key);
  5161. return index < 0 ? undefined : data[index][1];
  5162. }
  5163. /**
  5164. * Checks if a list cache value for `key` exists.
  5165. *
  5166. * @private
  5167. * @name has
  5168. * @memberOf ListCache
  5169. * @param {string} key The key of the entry to check.
  5170. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  5171. */
  5172. function listCacheHas(key) {
  5173. return assocIndexOf(this.__data__, key) > -1;
  5174. }
  5175. /**
  5176. * Sets the list cache `key` to `value`.
  5177. *
  5178. * @private
  5179. * @name set
  5180. * @memberOf ListCache
  5181. * @param {string} key The key of the value to set.
  5182. * @param {*} value The value to set.
  5183. * @returns {Object} Returns the list cache instance.
  5184. */
  5185. function listCacheSet(key, value) {
  5186. var data = this.__data__,
  5187. index = assocIndexOf(data, key);
  5188. if (index < 0) {
  5189. ++this.size;
  5190. data.push([key, value]);
  5191. } else {
  5192. data[index][1] = value;
  5193. }
  5194. return this;
  5195. }
  5196. // Add methods to `ListCache`.
  5197. ListCache.prototype.clear = listCacheClear;
  5198. ListCache.prototype['delete'] = listCacheDelete;
  5199. ListCache.prototype.get = listCacheGet;
  5200. ListCache.prototype.has = listCacheHas;
  5201. ListCache.prototype.set = listCacheSet;
  5202. /*------------------------------------------------------------------------*/
  5203. /**
  5204. * Creates a map cache object to store key-value pairs.
  5205. *
  5206. * @private
  5207. * @constructor
  5208. * @param {Array} [entries] The key-value pairs to cache.
  5209. */
  5210. function MapCache(entries) {
  5211. var index = -1,
  5212. length = entries == null ? 0 : entries.length;
  5213. this.clear();
  5214. while (++index < length) {
  5215. var entry = entries[index];
  5216. this.set(entry[0], entry[1]);
  5217. }
  5218. }
  5219. /**
  5220. * Removes all key-value entries from the map.
  5221. *
  5222. * @private
  5223. * @name clear
  5224. * @memberOf MapCache
  5225. */
  5226. function mapCacheClear() {
  5227. this.size = 0;
  5228. this.__data__ = {
  5229. 'hash': new Hash,
  5230. 'map': new (Map || ListCache),
  5231. 'string': new Hash
  5232. };
  5233. }
  5234. /**
  5235. * Removes `key` and its value from the map.
  5236. *
  5237. * @private
  5238. * @name delete
  5239. * @memberOf MapCache
  5240. * @param {string} key The key of the value to remove.
  5241. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  5242. */
  5243. function mapCacheDelete(key) {
  5244. var result = getMapData(this, key)['delete'](key);
  5245. this.size -= result ? 1 : 0;
  5246. return result;
  5247. }
  5248. /**
  5249. * Gets the map value for `key`.
  5250. *
  5251. * @private
  5252. * @name get
  5253. * @memberOf MapCache
  5254. * @param {string} key The key of the value to get.
  5255. * @returns {*} Returns the entry value.
  5256. */
  5257. function mapCacheGet(key) {
  5258. return getMapData(this, key).get(key);
  5259. }
  5260. /**
  5261. * Checks if a map value for `key` exists.
  5262. *
  5263. * @private
  5264. * @name has
  5265. * @memberOf MapCache
  5266. * @param {string} key The key of the entry to check.
  5267. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  5268. */
  5269. function mapCacheHas(key) {
  5270. return getMapData(this, key).has(key);
  5271. }
  5272. /**
  5273. * Sets the map `key` to `value`.
  5274. *
  5275. * @private
  5276. * @name set
  5277. * @memberOf MapCache
  5278. * @param {string} key The key of the value to set.
  5279. * @param {*} value The value to set.
  5280. * @returns {Object} Returns the map cache instance.
  5281. */
  5282. function mapCacheSet(key, value) {
  5283. var data = getMapData(this, key),
  5284. size = data.size;
  5285. data.set(key, value);
  5286. this.size += data.size == size ? 0 : 1;
  5287. return this;
  5288. }
  5289. // Add methods to `MapCache`.
  5290. MapCache.prototype.clear = mapCacheClear;
  5291. MapCache.prototype['delete'] = mapCacheDelete;
  5292. MapCache.prototype.get = mapCacheGet;
  5293. MapCache.prototype.has = mapCacheHas;
  5294. MapCache.prototype.set = mapCacheSet;
  5295. /*------------------------------------------------------------------------*/
  5296. /**
  5297. *
  5298. * Creates an array cache object to store unique values.
  5299. *
  5300. * @private
  5301. * @constructor
  5302. * @param {Array} [values] The values to cache.
  5303. */
  5304. function SetCache(values) {
  5305. var index = -1,
  5306. length = values == null ? 0 : values.length;
  5307. this.__data__ = new MapCache;
  5308. while (++index < length) {
  5309. this.add(values[index]);
  5310. }
  5311. }
  5312. /**
  5313. * Adds `value` to the array cache.
  5314. *
  5315. * @private
  5316. * @name add
  5317. * @memberOf SetCache
  5318. * @alias push
  5319. * @param {*} value The value to cache.
  5320. * @returns {Object} Returns the cache instance.
  5321. */
  5322. function setCacheAdd(value) {
  5323. this.__data__.set(value, HASH_UNDEFINED);
  5324. return this;
  5325. }
  5326. /**
  5327. * Checks if `value` is in the array cache.
  5328. *
  5329. * @private
  5330. * @name has
  5331. * @memberOf SetCache
  5332. * @param {*} value The value to search for.
  5333. * @returns {number} Returns `true` if `value` is found, else `false`.
  5334. */
  5335. function setCacheHas(value) {
  5336. return this.__data__.has(value);
  5337. }
  5338. // Add methods to `SetCache`.
  5339. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  5340. SetCache.prototype.has = setCacheHas;
  5341. /*------------------------------------------------------------------------*/
  5342. /**
  5343. * Creates a stack cache object to store key-value pairs.
  5344. *
  5345. * @private
  5346. * @constructor
  5347. * @param {Array} [entries] The key-value pairs to cache.
  5348. */
  5349. function Stack(entries) {
  5350. var data = this.__data__ = new ListCache(entries);
  5351. this.size = data.size;
  5352. }
  5353. /**
  5354. * Removes all key-value entries from the stack.
  5355. *
  5356. * @private
  5357. * @name clear
  5358. * @memberOf Stack
  5359. */
  5360. function stackClear() {
  5361. this.__data__ = new ListCache;
  5362. this.size = 0;
  5363. }
  5364. /**
  5365. * Removes `key` and its value from the stack.
  5366. *
  5367. * @private
  5368. * @name delete
  5369. * @memberOf Stack
  5370. * @param {string} key The key of the value to remove.
  5371. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  5372. */
  5373. function stackDelete(key) {
  5374. var data = this.__data__,
  5375. result = data['delete'](key);
  5376. this.size = data.size;
  5377. return result;
  5378. }
  5379. /**
  5380. * Gets the stack value for `key`.
  5381. *
  5382. * @private
  5383. * @name get
  5384. * @memberOf Stack
  5385. * @param {string} key The key of the value to get.
  5386. * @returns {*} Returns the entry value.
  5387. */
  5388. function stackGet(key) {
  5389. return this.__data__.get(key);
  5390. }
  5391. /**
  5392. * Checks if a stack value for `key` exists.
  5393. *
  5394. * @private
  5395. * @name has
  5396. * @memberOf Stack
  5397. * @param {string} key The key of the entry to check.
  5398. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  5399. */
  5400. function stackHas(key) {
  5401. return this.__data__.has(key);
  5402. }
  5403. /**
  5404. * Sets the stack `key` to `value`.
  5405. *
  5406. * @private
  5407. * @name set
  5408. * @memberOf Stack
  5409. * @param {string} key The key of the value to set.
  5410. * @param {*} value The value to set.
  5411. * @returns {Object} Returns the stack cache instance.
  5412. */
  5413. function stackSet(key, value) {
  5414. var data = this.__data__;
  5415. if (data instanceof ListCache) {
  5416. var pairs = data.__data__;
  5417. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  5418. pairs.push([key, value]);
  5419. this.size = ++data.size;
  5420. return this;
  5421. }
  5422. data = this.__data__ = new MapCache(pairs);
  5423. }
  5424. data.set(key, value);
  5425. this.size = data.size;
  5426. return this;
  5427. }
  5428. // Add methods to `Stack`.
  5429. Stack.prototype.clear = stackClear;
  5430. Stack.prototype['delete'] = stackDelete;
  5431. Stack.prototype.get = stackGet;
  5432. Stack.prototype.has = stackHas;
  5433. Stack.prototype.set = stackSet;
  5434. /*------------------------------------------------------------------------*/
  5435. /**
  5436. * Creates an array of the enumerable property names of the array-like `value`.
  5437. *
  5438. * @private
  5439. * @param {*} value The value to query.
  5440. * @param {boolean} inherited Specify returning inherited property names.
  5441. * @returns {Array} Returns the array of property names.
  5442. */
  5443. function arrayLikeKeys(value, inherited) {
  5444. var isArr = isArray(value),
  5445. isArg = !isArr && isArguments(value),
  5446. isBuff = !isArr && !isArg && isBuffer(value),
  5447. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  5448. skipIndexes = isArr || isArg || isBuff || isType,
  5449. result = skipIndexes ? baseTimes(value.length, String) : [],
  5450. length = result.length;
  5451. for (var key in value) {
  5452. if ((inherited || hasOwnProperty.call(value, key)) &&
  5453. !(skipIndexes && (
  5454. // Safari 9 has enumerable `arguments.length` in strict mode.
  5455. key == 'length' ||
  5456. // Node.js 0.10 has enumerable non-index properties on buffers.
  5457. (isBuff && (key == 'offset' || key == 'parent')) ||
  5458. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  5459. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  5460. // Skip index properties.
  5461. isIndex(key, length)
  5462. ))) {
  5463. result.push(key);
  5464. }
  5465. }
  5466. return result;
  5467. }
  5468. /**
  5469. * A specialized version of `_.sample` for arrays.
  5470. *
  5471. * @private
  5472. * @param {Array} array The array to sample.
  5473. * @returns {*} Returns the random element.
  5474. */
  5475. function arraySample(array) {
  5476. var length = array.length;
  5477. return length ? array[baseRandom(0, length - 1)] : undefined;
  5478. }
  5479. /**
  5480. * A specialized version of `_.sampleSize` for arrays.
  5481. *
  5482. * @private
  5483. * @param {Array} array The array to sample.
  5484. * @param {number} n The number of elements to sample.
  5485. * @returns {Array} Returns the random elements.
  5486. */
  5487. function arraySampleSize(array, n) {
  5488. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  5489. }
  5490. /**
  5491. * A specialized version of `_.shuffle` for arrays.
  5492. *
  5493. * @private
  5494. * @param {Array} array The array to shuffle.
  5495. * @returns {Array} Returns the new shuffled array.
  5496. */
  5497. function arrayShuffle(array) {
  5498. return shuffleSelf(copyArray(array));
  5499. }
  5500. /**
  5501. * This function is like `assignValue` except that it doesn't assign
  5502. * `undefined` values.
  5503. *
  5504. * @private
  5505. * @param {Object} object The object to modify.
  5506. * @param {string} key The key of the property to assign.
  5507. * @param {*} value The value to assign.
  5508. */
  5509. function assignMergeValue(object, key, value) {
  5510. if ((value !== undefined && !eq(object[key], value)) ||
  5511. (value === undefined && !(key in object))) {
  5512. baseAssignValue(object, key, value);
  5513. }
  5514. }
  5515. /**
  5516. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  5517. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  5518. * for equality comparisons.
  5519. *
  5520. * @private
  5521. * @param {Object} object The object to modify.
  5522. * @param {string} key The key of the property to assign.
  5523. * @param {*} value The value to assign.
  5524. */
  5525. function assignValue(object, key, value) {
  5526. var objValue = object[key];
  5527. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  5528. (value === undefined && !(key in object))) {
  5529. baseAssignValue(object, key, value);
  5530. }
  5531. }
  5532. /**
  5533. * Gets the index at which the `key` is found in `array` of key-value pairs.
  5534. *
  5535. * @private
  5536. * @param {Array} array The array to inspect.
  5537. * @param {*} key The key to search for.
  5538. * @returns {number} Returns the index of the matched value, else `-1`.
  5539. */
  5540. function assocIndexOf(array, key) {
  5541. var length = array.length;
  5542. while (length--) {
  5543. if (eq(array[length][0], key)) {
  5544. return length;
  5545. }
  5546. }
  5547. return -1;
  5548. }
  5549. /**
  5550. * Aggregates elements of `collection` on `accumulator` with keys transformed
  5551. * by `iteratee` and values set by `setter`.
  5552. *
  5553. * @private
  5554. * @param {Array|Object} collection The collection to iterate over.
  5555. * @param {Function} setter The function to set `accumulator` values.
  5556. * @param {Function} iteratee The iteratee to transform keys.
  5557. * @param {Object} accumulator The initial aggregated object.
  5558. * @returns {Function} Returns `accumulator`.
  5559. */
  5560. function baseAggregator(collection, setter, iteratee, accumulator) {
  5561. baseEach(collection, function(value, key, collection) {
  5562. setter(accumulator, value, iteratee(value), collection);
  5563. });
  5564. return accumulator;
  5565. }
  5566. /**
  5567. * The base implementation of `_.assign` without support for multiple sources
  5568. * or `customizer` functions.
  5569. *
  5570. * @private
  5571. * @param {Object} object The destination object.
  5572. * @param {Object} source The source object.
  5573. * @returns {Object} Returns `object`.
  5574. */
  5575. function baseAssign(object, source) {
  5576. return object && copyObject(source, keys(source), object);
  5577. }
  5578. /**
  5579. * The base implementation of `_.assignIn` without support for multiple sources
  5580. * or `customizer` functions.
  5581. *
  5582. * @private
  5583. * @param {Object} object The destination object.
  5584. * @param {Object} source The source object.
  5585. * @returns {Object} Returns `object`.
  5586. */
  5587. function baseAssignIn(object, source) {
  5588. return object && copyObject(source, keysIn(source), object);
  5589. }
  5590. /**
  5591. * The base implementation of `assignValue` and `assignMergeValue` without
  5592. * value checks.
  5593. *
  5594. * @private
  5595. * @param {Object} object The object to modify.
  5596. * @param {string} key The key of the property to assign.
  5597. * @param {*} value The value to assign.
  5598. */
  5599. function baseAssignValue(object, key, value) {
  5600. if (key == '__proto__' && defineProperty) {
  5601. defineProperty(object, key, {
  5602. 'configurable': true,
  5603. 'enumerable': true,
  5604. 'value': value,
  5605. 'writable': true
  5606. });
  5607. } else {
  5608. object[key] = value;
  5609. }
  5610. }
  5611. /**
  5612. * The base implementation of `_.at` without support for individual paths.
  5613. *
  5614. * @private
  5615. * @param {Object} object The object to iterate over.
  5616. * @param {string[]} paths The property paths to pick.
  5617. * @returns {Array} Returns the picked elements.
  5618. */
  5619. function baseAt(object, paths) {
  5620. var index = -1,
  5621. length = paths.length,
  5622. result = Array(length),
  5623. skip = object == null;
  5624. while (++index < length) {
  5625. result[index] = skip ? undefined : get(object, paths[index]);
  5626. }
  5627. return result;
  5628. }
  5629. /**
  5630. * The base implementation of `_.clamp` which doesn't coerce arguments.
  5631. *
  5632. * @private
  5633. * @param {number} number The number to clamp.
  5634. * @param {number} [lower] The lower bound.
  5635. * @param {number} upper The upper bound.
  5636. * @returns {number} Returns the clamped number.
  5637. */
  5638. function baseClamp(number, lower, upper) {
  5639. if (number === number) {
  5640. if (upper !== undefined) {
  5641. number = number <= upper ? number : upper;
  5642. }
  5643. if (lower !== undefined) {
  5644. number = number >= lower ? number : lower;
  5645. }
  5646. }
  5647. return number;
  5648. }
  5649. /**
  5650. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  5651. * traversed objects.
  5652. *
  5653. * @private
  5654. * @param {*} value The value to clone.
  5655. * @param {boolean} bitmask The bitmask flags.
  5656. * 1 - Deep clone
  5657. * 2 - Flatten inherited properties
  5658. * 4 - Clone symbols
  5659. * @param {Function} [customizer] The function to customize cloning.
  5660. * @param {string} [key] The key of `value`.
  5661. * @param {Object} [object] The parent object of `value`.
  5662. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  5663. * @returns {*} Returns the cloned value.
  5664. */
  5665. function baseClone(value, bitmask, customizer, key, object, stack) {
  5666. var result,
  5667. isDeep = bitmask & CLONE_DEEP_FLAG,
  5668. isFlat = bitmask & CLONE_FLAT_FLAG,
  5669. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  5670. if (customizer) {
  5671. result = object ? customizer(value, key, object, stack) : customizer(value);
  5672. }
  5673. if (result !== undefined) {
  5674. return result;
  5675. }
  5676. if (!isObject(value)) {
  5677. return value;
  5678. }
  5679. var isArr = isArray(value);
  5680. if (isArr) {
  5681. result = initCloneArray(value);
  5682. if (!isDeep) {
  5683. return copyArray(value, result);
  5684. }
  5685. } else {
  5686. var tag = getTag(value),
  5687. isFunc = tag == funcTag || tag == genTag;
  5688. if (isBuffer(value)) {
  5689. return cloneBuffer(value, isDeep);
  5690. }
  5691. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  5692. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  5693. if (!isDeep) {
  5694. return isFlat
  5695. ? copySymbolsIn(value, baseAssignIn(result, value))
  5696. : copySymbols(value, baseAssign(result, value));
  5697. }
  5698. } else {
  5699. if (!cloneableTags[tag]) {
  5700. return object ? value : {};
  5701. }
  5702. result = initCloneByTag(value, tag, isDeep);
  5703. }
  5704. }
  5705. // Check for circular references and return its corresponding clone.
  5706. stack || (stack = new Stack);
  5707. var stacked = stack.get(value);
  5708. if (stacked) {
  5709. return stacked;
  5710. }
  5711. stack.set(value, result);
  5712. if (isSet(value)) {
  5713. value.forEach(function(subValue) {
  5714. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  5715. });
  5716. } else if (isMap(value)) {
  5717. value.forEach(function(subValue, key) {
  5718. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  5719. });
  5720. }
  5721. var keysFunc = isFull
  5722. ? (isFlat ? getAllKeysIn : getAllKeys)
  5723. : (isFlat ? keysIn : keys);
  5724. var props = isArr ? undefined : keysFunc(value);
  5725. arrayEach(props || value, function(subValue, key) {
  5726. if (props) {
  5727. key = subValue;
  5728. subValue = value[key];
  5729. }
  5730. // Recursively populate clone (susceptible to call stack limits).
  5731. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  5732. });
  5733. return result;
  5734. }
  5735. /**
  5736. * The base implementation of `_.conforms` which doesn't clone `source`.
  5737. *
  5738. * @private
  5739. * @param {Object} source The object of property predicates to conform to.
  5740. * @returns {Function} Returns the new spec function.
  5741. */
  5742. function baseConforms(source) {
  5743. var props = keys(source);
  5744. return function(object) {
  5745. return baseConformsTo(object, source, props);
  5746. };
  5747. }
  5748. /**
  5749. * The base implementation of `_.conformsTo` which accepts `props` to check.
  5750. *
  5751. * @private
  5752. * @param {Object} object The object to inspect.
  5753. * @param {Object} source The object of property predicates to conform to.
  5754. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  5755. */
  5756. function baseConformsTo(object, source, props) {
  5757. var length = props.length;
  5758. if (object == null) {
  5759. return !length;
  5760. }
  5761. object = Object(object);
  5762. while (length--) {
  5763. var key = props[length],
  5764. predicate = source[key],
  5765. value = object[key];
  5766. if ((value === undefined && !(key in object)) || !predicate(value)) {
  5767. return false;
  5768. }
  5769. }
  5770. return true;
  5771. }
  5772. /**
  5773. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  5774. * to provide to `func`.
  5775. *
  5776. * @private
  5777. * @param {Function} func The function to delay.
  5778. * @param {number} wait The number of milliseconds to delay invocation.
  5779. * @param {Array} args The arguments to provide to `func`.
  5780. * @returns {number|Object} Returns the timer id or timeout object.
  5781. */
  5782. function baseDelay(func, wait, args) {
  5783. if (typeof func != 'function') {
  5784. throw new TypeError(FUNC_ERROR_TEXT);
  5785. }
  5786. return setTimeout(function() { func.apply(undefined, args); }, wait);
  5787. }
  5788. /**
  5789. * The base implementation of methods like `_.difference` without support
  5790. * for excluding multiple arrays or iteratee shorthands.
  5791. *
  5792. * @private
  5793. * @param {Array} array The array to inspect.
  5794. * @param {Array} values The values to exclude.
  5795. * @param {Function} [iteratee] The iteratee invoked per element.
  5796. * @param {Function} [comparator] The comparator invoked per element.
  5797. * @returns {Array} Returns the new array of filtered values.
  5798. */
  5799. function baseDifference(array, values, iteratee, comparator) {
  5800. var index = -1,
  5801. includes = arrayIncludes,
  5802. isCommon = true,
  5803. length = array.length,
  5804. result = [],
  5805. valuesLength = values.length;
  5806. if (!length) {
  5807. return result;
  5808. }
  5809. if (iteratee) {
  5810. values = arrayMap(values, baseUnary(iteratee));
  5811. }
  5812. if (comparator) {
  5813. includes = arrayIncludesWith;
  5814. isCommon = false;
  5815. }
  5816. else if (values.length >= LARGE_ARRAY_SIZE) {
  5817. includes = cacheHas;
  5818. isCommon = false;
  5819. values = new SetCache(values);
  5820. }
  5821. outer:
  5822. while (++index < length) {
  5823. var value = array[index],
  5824. computed = iteratee == null ? value : iteratee(value);
  5825. value = (comparator || value !== 0) ? value : 0;
  5826. if (isCommon && computed === computed) {
  5827. var valuesIndex = valuesLength;
  5828. while (valuesIndex--) {
  5829. if (values[valuesIndex] === computed) {
  5830. continue outer;
  5831. }
  5832. }
  5833. result.push(value);
  5834. }
  5835. else if (!includes(values, computed, comparator)) {
  5836. result.push(value);
  5837. }
  5838. }
  5839. return result;
  5840. }
  5841. /**
  5842. * The base implementation of `_.forEach` without support for iteratee shorthands.
  5843. *
  5844. * @private
  5845. * @param {Array|Object} collection The collection to iterate over.
  5846. * @param {Function} iteratee The function invoked per iteration.
  5847. * @returns {Array|Object} Returns `collection`.
  5848. */
  5849. var baseEach = createBaseEach(baseForOwn);
  5850. /**
  5851. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  5852. *
  5853. * @private
  5854. * @param {Array|Object} collection The collection to iterate over.
  5855. * @param {Function} iteratee The function invoked per iteration.
  5856. * @returns {Array|Object} Returns `collection`.
  5857. */
  5858. var baseEachRight = createBaseEach(baseForOwnRight, true);
  5859. /**
  5860. * The base implementation of `_.every` without support for iteratee shorthands.
  5861. *
  5862. * @private
  5863. * @param {Array|Object} collection The collection to iterate over.
  5864. * @param {Function} predicate The function invoked per iteration.
  5865. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  5866. * else `false`
  5867. */
  5868. function baseEvery(collection, predicate) {
  5869. var result = true;
  5870. baseEach(collection, function(value, index, collection) {
  5871. result = !!predicate(value, index, collection);
  5872. return result;
  5873. });
  5874. return result;
  5875. }
  5876. /**
  5877. * The base implementation of methods like `_.max` and `_.min` which accepts a
  5878. * `comparator` to determine the extremum value.
  5879. *
  5880. * @private
  5881. * @param {Array} array The array to iterate over.
  5882. * @param {Function} iteratee The iteratee invoked per iteration.
  5883. * @param {Function} comparator The comparator used to compare values.
  5884. * @returns {*} Returns the extremum value.
  5885. */
  5886. function baseExtremum(array, iteratee, comparator) {
  5887. var index = -1,
  5888. length = array.length;
  5889. while (++index < length) {
  5890. var value = array[index],
  5891. current = iteratee(value);
  5892. if (current != null && (computed === undefined
  5893. ? (current === current && !isSymbol(current))
  5894. : comparator(current, computed)
  5895. )) {
  5896. var computed = current,
  5897. result = value;
  5898. }
  5899. }
  5900. return result;
  5901. }
  5902. /**
  5903. * The base implementation of `_.fill` without an iteratee call guard.
  5904. *
  5905. * @private
  5906. * @param {Array} array The array to fill.
  5907. * @param {*} value The value to fill `array` with.
  5908. * @param {number} [start=0] The start position.
  5909. * @param {number} [end=array.length] The end position.
  5910. * @returns {Array} Returns `array`.
  5911. */
  5912. function baseFill(array, value, start, end) {
  5913. var length = array.length;
  5914. start = toInteger(start);
  5915. if (start < 0) {
  5916. start = -start > length ? 0 : (length + start);
  5917. }
  5918. end = (end === undefined || end > length) ? length : toInteger(end);
  5919. if (end < 0) {
  5920. end += length;
  5921. }
  5922. end = start > end ? 0 : toLength(end);
  5923. while (start < end) {
  5924. array[start++] = value;
  5925. }
  5926. return array;
  5927. }
  5928. /**
  5929. * The base implementation of `_.filter` without support for iteratee shorthands.
  5930. *
  5931. * @private
  5932. * @param {Array|Object} collection The collection to iterate over.
  5933. * @param {Function} predicate The function invoked per iteration.
  5934. * @returns {Array} Returns the new filtered array.
  5935. */
  5936. function baseFilter(collection, predicate) {
  5937. var result = [];
  5938. baseEach(collection, function(value, index, collection) {
  5939. if (predicate(value, index, collection)) {
  5940. result.push(value);
  5941. }
  5942. });
  5943. return result;
  5944. }
  5945. /**
  5946. * The base implementation of `_.flatten` with support for restricting flattening.
  5947. *
  5948. * @private
  5949. * @param {Array} array The array to flatten.
  5950. * @param {number} depth The maximum recursion depth.
  5951. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  5952. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  5953. * @param {Array} [result=[]] The initial result value.
  5954. * @returns {Array} Returns the new flattened array.
  5955. */
  5956. function baseFlatten(array, depth, predicate, isStrict, result) {
  5957. var index = -1,
  5958. length = array.length;
  5959. predicate || (predicate = isFlattenable);
  5960. result || (result = []);
  5961. while (++index < length) {
  5962. var value = array[index];
  5963. if (depth > 0 && predicate(value)) {
  5964. if (depth > 1) {
  5965. // Recursively flatten arrays (susceptible to call stack limits).
  5966. baseFlatten(value, depth - 1, predicate, isStrict, result);
  5967. } else {
  5968. arrayPush(result, value);
  5969. }
  5970. } else if (!isStrict) {
  5971. result[result.length] = value;
  5972. }
  5973. }
  5974. return result;
  5975. }
  5976. /**
  5977. * The base implementation of `baseForOwn` which iterates over `object`
  5978. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  5979. * Iteratee functions may exit iteration early by explicitly returning `false`.
  5980. *
  5981. * @private
  5982. * @param {Object} object The object to iterate over.
  5983. * @param {Function} iteratee The function invoked per iteration.
  5984. * @param {Function} keysFunc The function to get the keys of `object`.
  5985. * @returns {Object} Returns `object`.
  5986. */
  5987. var baseFor = createBaseFor();
  5988. /**
  5989. * This function is like `baseFor` except that it iterates over properties
  5990. * in the opposite order.
  5991. *
  5992. * @private
  5993. * @param {Object} object The object to iterate over.
  5994. * @param {Function} iteratee The function invoked per iteration.
  5995. * @param {Function} keysFunc The function to get the keys of `object`.
  5996. * @returns {Object} Returns `object`.
  5997. */
  5998. var baseForRight = createBaseFor(true);
  5999. /**
  6000. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  6001. *
  6002. * @private
  6003. * @param {Object} object The object to iterate over.
  6004. * @param {Function} iteratee The function invoked per iteration.
  6005. * @returns {Object} Returns `object`.
  6006. */
  6007. function baseForOwn(object, iteratee) {
  6008. return object && baseFor(object, iteratee, keys);
  6009. }
  6010. /**
  6011. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  6012. *
  6013. * @private
  6014. * @param {Object} object The object to iterate over.
  6015. * @param {Function} iteratee The function invoked per iteration.
  6016. * @returns {Object} Returns `object`.
  6017. */
  6018. function baseForOwnRight(object, iteratee) {
  6019. return object && baseForRight(object, iteratee, keys);
  6020. }
  6021. /**
  6022. * The base implementation of `_.functions` which creates an array of
  6023. * `object` function property names filtered from `props`.
  6024. *
  6025. * @private
  6026. * @param {Object} object The object to inspect.
  6027. * @param {Array} props The property names to filter.
  6028. * @returns {Array} Returns the function names.
  6029. */
  6030. function baseFunctions(object, props) {
  6031. return arrayFilter(props, function(key) {
  6032. return isFunction(object[key]);
  6033. });
  6034. }
  6035. /**
  6036. * The base implementation of `_.get` without support for default values.
  6037. *
  6038. * @private
  6039. * @param {Object} object The object to query.
  6040. * @param {Array|string} path The path of the property to get.
  6041. * @returns {*} Returns the resolved value.
  6042. */
  6043. function baseGet(object, path) {
  6044. path = castPath(path, object);
  6045. var index = 0,
  6046. length = path.length;
  6047. while (object != null && index < length) {
  6048. object = object[toKey(path[index++])];
  6049. }
  6050. return (index && index == length) ? object : undefined;
  6051. }
  6052. /**
  6053. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  6054. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  6055. * symbols of `object`.
  6056. *
  6057. * @private
  6058. * @param {Object} object The object to query.
  6059. * @param {Function} keysFunc The function to get the keys of `object`.
  6060. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  6061. * @returns {Array} Returns the array of property names and symbols.
  6062. */
  6063. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  6064. var result = keysFunc(object);
  6065. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  6066. }
  6067. /**
  6068. * The base implementation of `getTag` without fallbacks for buggy environments.
  6069. *
  6070. * @private
  6071. * @param {*} value The value to query.
  6072. * @returns {string} Returns the `toStringTag`.
  6073. */
  6074. function baseGetTag(value) {
  6075. if (value == null) {
  6076. return value === undefined ? undefinedTag : nullTag;
  6077. }
  6078. return (symToStringTag && symToStringTag in Object(value))
  6079. ? getRawTag(value)
  6080. : objectToString(value);
  6081. }
  6082. /**
  6083. * The base implementation of `_.gt` which doesn't coerce arguments.
  6084. *
  6085. * @private
  6086. * @param {*} value The value to compare.
  6087. * @param {*} other The other value to compare.
  6088. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  6089. * else `false`.
  6090. */
  6091. function baseGt(value, other) {
  6092. return value > other;
  6093. }
  6094. /**
  6095. * The base implementation of `_.has` without support for deep paths.
  6096. *
  6097. * @private
  6098. * @param {Object} [object] The object to query.
  6099. * @param {Array|string} key The key to check.
  6100. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  6101. */
  6102. function baseHas(object, key) {
  6103. return object != null && hasOwnProperty.call(object, key);
  6104. }
  6105. /**
  6106. * The base implementation of `_.hasIn` without support for deep paths.
  6107. *
  6108. * @private
  6109. * @param {Object} [object] The object to query.
  6110. * @param {Array|string} key The key to check.
  6111. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  6112. */
  6113. function baseHasIn(object, key) {
  6114. return object != null && key in Object(object);
  6115. }
  6116. /**
  6117. * The base implementation of `_.inRange` which doesn't coerce arguments.
  6118. *
  6119. * @private
  6120. * @param {number} number The number to check.
  6121. * @param {number} start The start of the range.
  6122. * @param {number} end The end of the range.
  6123. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  6124. */
  6125. function baseInRange(number, start, end) {
  6126. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  6127. }
  6128. /**
  6129. * The base implementation of methods like `_.intersection`, without support
  6130. * for iteratee shorthands, that accepts an array of arrays to inspect.
  6131. *
  6132. * @private
  6133. * @param {Array} arrays The arrays to inspect.
  6134. * @param {Function} [iteratee] The iteratee invoked per element.
  6135. * @param {Function} [comparator] The comparator invoked per element.
  6136. * @returns {Array} Returns the new array of shared values.
  6137. */
  6138. function baseIntersection(arrays, iteratee, comparator) {
  6139. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  6140. length = arrays[0].length,
  6141. othLength = arrays.length,
  6142. othIndex = othLength,
  6143. caches = Array(othLength),
  6144. maxLength = Infinity,
  6145. result = [];
  6146. while (othIndex--) {
  6147. var array = arrays[othIndex];
  6148. if (othIndex && iteratee) {
  6149. array = arrayMap(array, baseUnary(iteratee));
  6150. }
  6151. maxLength = nativeMin(array.length, maxLength);
  6152. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  6153. ? new SetCache(othIndex && array)
  6154. : undefined;
  6155. }
  6156. array = arrays[0];
  6157. var index = -1,
  6158. seen = caches[0];
  6159. outer:
  6160. while (++index < length && result.length < maxLength) {
  6161. var value = array[index],
  6162. computed = iteratee ? iteratee(value) : value;
  6163. value = (comparator || value !== 0) ? value : 0;
  6164. if (!(seen
  6165. ? cacheHas(seen, computed)
  6166. : includes(result, computed, comparator)
  6167. )) {
  6168. othIndex = othLength;
  6169. while (--othIndex) {
  6170. var cache = caches[othIndex];
  6171. if (!(cache
  6172. ? cacheHas(cache, computed)
  6173. : includes(arrays[othIndex], computed, comparator))
  6174. ) {
  6175. continue outer;
  6176. }
  6177. }
  6178. if (seen) {
  6179. seen.push(computed);
  6180. }
  6181. result.push(value);
  6182. }
  6183. }
  6184. return result;
  6185. }
  6186. /**
  6187. * The base implementation of `_.invert` and `_.invertBy` which inverts
  6188. * `object` with values transformed by `iteratee` and set by `setter`.
  6189. *
  6190. * @private
  6191. * @param {Object} object The object to iterate over.
  6192. * @param {Function} setter The function to set `accumulator` values.
  6193. * @param {Function} iteratee The iteratee to transform values.
  6194. * @param {Object} accumulator The initial inverted object.
  6195. * @returns {Function} Returns `accumulator`.
  6196. */
  6197. function baseInverter(object, setter, iteratee, accumulator) {
  6198. baseForOwn(object, function(value, key, object) {
  6199. setter(accumulator, iteratee(value), key, object);
  6200. });
  6201. return accumulator;
  6202. }
  6203. /**
  6204. * The base implementation of `_.invoke` without support for individual
  6205. * method arguments.
  6206. *
  6207. * @private
  6208. * @param {Object} object The object to query.
  6209. * @param {Array|string} path The path of the method to invoke.
  6210. * @param {Array} args The arguments to invoke the method with.
  6211. * @returns {*} Returns the result of the invoked method.
  6212. */
  6213. function baseInvoke(object, path, args) {
  6214. path = castPath(path, object);
  6215. object = parent(object, path);
  6216. var func = object == null ? object : object[toKey(last(path))];
  6217. return func == null ? undefined : apply(func, object, args);
  6218. }
  6219. /**
  6220. * The base implementation of `_.isArguments`.
  6221. *
  6222. * @private
  6223. * @param {*} value The value to check.
  6224. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  6225. */
  6226. function baseIsArguments(value) {
  6227. return isObjectLike(value) && baseGetTag(value) == argsTag;
  6228. }
  6229. /**
  6230. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  6231. *
  6232. * @private
  6233. * @param {*} value The value to check.
  6234. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  6235. */
  6236. function baseIsArrayBuffer(value) {
  6237. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  6238. }
  6239. /**
  6240. * The base implementation of `_.isDate` without Node.js optimizations.
  6241. *
  6242. * @private
  6243. * @param {*} value The value to check.
  6244. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  6245. */
  6246. function baseIsDate(value) {
  6247. return isObjectLike(value) && baseGetTag(value) == dateTag;
  6248. }
  6249. /**
  6250. * The base implementation of `_.isEqual` which supports partial comparisons
  6251. * and tracks traversed objects.
  6252. *
  6253. * @private
  6254. * @param {*} value The value to compare.
  6255. * @param {*} other The other value to compare.
  6256. * @param {boolean} bitmask The bitmask flags.
  6257. * 1 - Unordered comparison
  6258. * 2 - Partial comparison
  6259. * @param {Function} [customizer] The function to customize comparisons.
  6260. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  6261. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  6262. */
  6263. function baseIsEqual(value, other, bitmask, customizer, stack) {
  6264. if (value === other) {
  6265. return true;
  6266. }
  6267. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  6268. return value !== value && other !== other;
  6269. }
  6270. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  6271. }
  6272. /**
  6273. * A specialized version of `baseIsEqual` for arrays and objects which performs
  6274. * deep comparisons and tracks traversed objects enabling objects with circular
  6275. * references to be compared.
  6276. *
  6277. * @private
  6278. * @param {Object} object The object to compare.
  6279. * @param {Object} other The other object to compare.
  6280. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  6281. * @param {Function} customizer The function to customize comparisons.
  6282. * @param {Function} equalFunc The function to determine equivalents of values.
  6283. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  6284. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  6285. */
  6286. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  6287. var objIsArr = isArray(object),
  6288. othIsArr = isArray(other),
  6289. objTag = objIsArr ? arrayTag : getTag(object),
  6290. othTag = othIsArr ? arrayTag : getTag(other);
  6291. objTag = objTag == argsTag ? objectTag : objTag;
  6292. othTag = othTag == argsTag ? objectTag : othTag;
  6293. var objIsObj = objTag == objectTag,
  6294. othIsObj = othTag == objectTag,
  6295. isSameTag = objTag == othTag;
  6296. if (isSameTag && isBuffer(object)) {
  6297. if (!isBuffer(other)) {
  6298. return false;
  6299. }
  6300. objIsArr = true;
  6301. objIsObj = false;
  6302. }
  6303. if (isSameTag && !objIsObj) {
  6304. stack || (stack = new Stack);
  6305. return (objIsArr || isTypedArray(object))
  6306. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  6307. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  6308. }
  6309. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  6310. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  6311. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  6312. if (objIsWrapped || othIsWrapped) {
  6313. var objUnwrapped = objIsWrapped ? object.value() : object,
  6314. othUnwrapped = othIsWrapped ? other.value() : other;
  6315. stack || (stack = new Stack);
  6316. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  6317. }
  6318. }
  6319. if (!isSameTag) {
  6320. return false;
  6321. }
  6322. stack || (stack = new Stack);
  6323. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  6324. }
  6325. /**
  6326. * The base implementation of `_.isMap` without Node.js optimizations.
  6327. *
  6328. * @private
  6329. * @param {*} value The value to check.
  6330. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  6331. */
  6332. function baseIsMap(value) {
  6333. return isObjectLike(value) && getTag(value) == mapTag;
  6334. }
  6335. /**
  6336. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  6337. *
  6338. * @private
  6339. * @param {Object} object The object to inspect.
  6340. * @param {Object} source The object of property values to match.
  6341. * @param {Array} matchData The property names, values, and compare flags to match.
  6342. * @param {Function} [customizer] The function to customize comparisons.
  6343. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  6344. */
  6345. function baseIsMatch(object, source, matchData, customizer) {
  6346. var index = matchData.length,
  6347. length = index,
  6348. noCustomizer = !customizer;
  6349. if (object == null) {
  6350. return !length;
  6351. }
  6352. object = Object(object);
  6353. while (index--) {
  6354. var data = matchData[index];
  6355. if ((noCustomizer && data[2])
  6356. ? data[1] !== object[data[0]]
  6357. : !(data[0] in object)
  6358. ) {
  6359. return false;
  6360. }
  6361. }
  6362. while (++index < length) {
  6363. data = matchData[index];
  6364. var key = data[0],
  6365. objValue = object[key],
  6366. srcValue = data[1];
  6367. if (noCustomizer && data[2]) {
  6368. if (objValue === undefined && !(key in object)) {
  6369. return false;
  6370. }
  6371. } else {
  6372. var stack = new Stack;
  6373. if (customizer) {
  6374. var result = customizer(objValue, srcValue, key, object, source, stack);
  6375. }
  6376. if (!(result === undefined
  6377. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  6378. : result
  6379. )) {
  6380. return false;
  6381. }
  6382. }
  6383. }
  6384. return true;
  6385. }
  6386. /**
  6387. * The base implementation of `_.isNative` without bad shim checks.
  6388. *
  6389. * @private
  6390. * @param {*} value The value to check.
  6391. * @returns {boolean} Returns `true` if `value` is a native function,
  6392. * else `false`.
  6393. */
  6394. function baseIsNative(value) {
  6395. if (!isObject(value) || isMasked(value)) {
  6396. return false;
  6397. }
  6398. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  6399. return pattern.test(toSource(value));
  6400. }
  6401. /**
  6402. * The base implementation of `_.isRegExp` without Node.js optimizations.
  6403. *
  6404. * @private
  6405. * @param {*} value The value to check.
  6406. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  6407. */
  6408. function baseIsRegExp(value) {
  6409. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  6410. }
  6411. /**
  6412. * The base implementation of `_.isSet` without Node.js optimizations.
  6413. *
  6414. * @private
  6415. * @param {*} value The value to check.
  6416. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  6417. */
  6418. function baseIsSet(value) {
  6419. return isObjectLike(value) && getTag(value) == setTag;
  6420. }
  6421. /**
  6422. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  6423. *
  6424. * @private
  6425. * @param {*} value The value to check.
  6426. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  6427. */
  6428. function baseIsTypedArray(value) {
  6429. return isObjectLike(value) &&
  6430. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  6431. }
  6432. /**
  6433. * The base implementation of `_.iteratee`.
  6434. *
  6435. * @private
  6436. * @param {*} [value=_.identity] The value to convert to an iteratee.
  6437. * @returns {Function} Returns the iteratee.
  6438. */
  6439. function baseIteratee(value) {
  6440. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  6441. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  6442. if (typeof value == 'function') {
  6443. return value;
  6444. }
  6445. if (value == null) {
  6446. return identity;
  6447. }
  6448. if (typeof value == 'object') {
  6449. return isArray(value)
  6450. ? baseMatchesProperty(value[0], value[1])
  6451. : baseMatches(value);
  6452. }
  6453. return property(value);
  6454. }
  6455. /**
  6456. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  6457. *
  6458. * @private
  6459. * @param {Object} object The object to query.
  6460. * @returns {Array} Returns the array of property names.
  6461. */
  6462. function baseKeys(object) {
  6463. if (!isPrototype(object)) {
  6464. return nativeKeys(object);
  6465. }
  6466. var result = [];
  6467. for (var key in Object(object)) {
  6468. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  6469. result.push(key);
  6470. }
  6471. }
  6472. return result;
  6473. }
  6474. /**
  6475. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  6476. *
  6477. * @private
  6478. * @param {Object} object The object to query.
  6479. * @returns {Array} Returns the array of property names.
  6480. */
  6481. function baseKeysIn(object) {
  6482. if (!isObject(object)) {
  6483. return nativeKeysIn(object);
  6484. }
  6485. var isProto = isPrototype(object),
  6486. result = [];
  6487. for (var key in object) {
  6488. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  6489. result.push(key);
  6490. }
  6491. }
  6492. return result;
  6493. }
  6494. /**
  6495. * The base implementation of `_.lt` which doesn't coerce arguments.
  6496. *
  6497. * @private
  6498. * @param {*} value The value to compare.
  6499. * @param {*} other The other value to compare.
  6500. * @returns {boolean} Returns `true` if `value` is less than `other`,
  6501. * else `false`.
  6502. */
  6503. function baseLt(value, other) {
  6504. return value < other;
  6505. }
  6506. /**
  6507. * The base implementation of `_.map` without support for iteratee shorthands.
  6508. *
  6509. * @private
  6510. * @param {Array|Object} collection The collection to iterate over.
  6511. * @param {Function} iteratee The function invoked per iteration.
  6512. * @returns {Array} Returns the new mapped array.
  6513. */
  6514. function baseMap(collection, iteratee) {
  6515. var index = -1,
  6516. result = isArrayLike(collection) ? Array(collection.length) : [];
  6517. baseEach(collection, function(value, key, collection) {
  6518. result[++index] = iteratee(value, key, collection);
  6519. });
  6520. return result;
  6521. }
  6522. /**
  6523. * The base implementation of `_.matches` which doesn't clone `source`.
  6524. *
  6525. * @private
  6526. * @param {Object} source The object of property values to match.
  6527. * @returns {Function} Returns the new spec function.
  6528. */
  6529. function baseMatches(source) {
  6530. var matchData = getMatchData(source);
  6531. if (matchData.length == 1 && matchData[0][2]) {
  6532. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  6533. }
  6534. return function(object) {
  6535. return object === source || baseIsMatch(object, source, matchData);
  6536. };
  6537. }
  6538. /**
  6539. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  6540. *
  6541. * @private
  6542. * @param {string} path The path of the property to get.
  6543. * @param {*} srcValue The value to match.
  6544. * @returns {Function} Returns the new spec function.
  6545. */
  6546. function baseMatchesProperty(path, srcValue) {
  6547. if (isKey(path) && isStrictComparable(srcValue)) {
  6548. return matchesStrictComparable(toKey(path), srcValue);
  6549. }
  6550. return function(object) {
  6551. var objValue = get(object, path);
  6552. return (objValue === undefined && objValue === srcValue)
  6553. ? hasIn(object, path)
  6554. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  6555. };
  6556. }
  6557. /**
  6558. * The base implementation of `_.merge` without support for multiple sources.
  6559. *
  6560. * @private
  6561. * @param {Object} object The destination object.
  6562. * @param {Object} source The source object.
  6563. * @param {number} srcIndex The index of `source`.
  6564. * @param {Function} [customizer] The function to customize merged values.
  6565. * @param {Object} [stack] Tracks traversed source values and their merged
  6566. * counterparts.
  6567. */
  6568. function baseMerge(object, source, srcIndex, customizer, stack) {
  6569. if (object === source) {
  6570. return;
  6571. }
  6572. baseFor(source, function(srcValue, key) {
  6573. stack || (stack = new Stack);
  6574. if (isObject(srcValue)) {
  6575. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  6576. }
  6577. else {
  6578. var newValue = customizer
  6579. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  6580. : undefined;
  6581. if (newValue === undefined) {
  6582. newValue = srcValue;
  6583. }
  6584. assignMergeValue(object, key, newValue);
  6585. }
  6586. }, keysIn);
  6587. }
  6588. /**
  6589. * A specialized version of `baseMerge` for arrays and objects which performs
  6590. * deep merges and tracks traversed objects enabling objects with circular
  6591. * references to be merged.
  6592. *
  6593. * @private
  6594. * @param {Object} object The destination object.
  6595. * @param {Object} source The source object.
  6596. * @param {string} key The key of the value to merge.
  6597. * @param {number} srcIndex The index of `source`.
  6598. * @param {Function} mergeFunc The function to merge values.
  6599. * @param {Function} [customizer] The function to customize assigned values.
  6600. * @param {Object} [stack] Tracks traversed source values and their merged
  6601. * counterparts.
  6602. */
  6603. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  6604. var objValue = safeGet(object, key),
  6605. srcValue = safeGet(source, key),
  6606. stacked = stack.get(srcValue);
  6607. if (stacked) {
  6608. assignMergeValue(object, key, stacked);
  6609. return;
  6610. }
  6611. var newValue = customizer
  6612. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  6613. : undefined;
  6614. var isCommon = newValue === undefined;
  6615. if (isCommon) {
  6616. var isArr = isArray(srcValue),
  6617. isBuff = !isArr && isBuffer(srcValue),
  6618. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  6619. newValue = srcValue;
  6620. if (isArr || isBuff || isTyped) {
  6621. if (isArray(objValue)) {
  6622. newValue = objValue;
  6623. }
  6624. else if (isArrayLikeObject(objValue)) {
  6625. newValue = copyArray(objValue);
  6626. }
  6627. else if (isBuff) {
  6628. isCommon = false;
  6629. newValue = cloneBuffer(srcValue, true);
  6630. }
  6631. else if (isTyped) {
  6632. isCommon = false;
  6633. newValue = cloneTypedArray(srcValue, true);
  6634. }
  6635. else {
  6636. newValue = [];
  6637. }
  6638. }
  6639. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  6640. newValue = objValue;
  6641. if (isArguments(objValue)) {
  6642. newValue = toPlainObject(objValue);
  6643. }
  6644. else if (!isObject(objValue) || isFunction(objValue)) {
  6645. newValue = initCloneObject(srcValue);
  6646. }
  6647. }
  6648. else {
  6649. isCommon = false;
  6650. }
  6651. }
  6652. if (isCommon) {
  6653. // Recursively merge objects and arrays (susceptible to call stack limits).
  6654. stack.set(srcValue, newValue);
  6655. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  6656. stack['delete'](srcValue);
  6657. }
  6658. assignMergeValue(object, key, newValue);
  6659. }
  6660. /**
  6661. * The base implementation of `_.nth` which doesn't coerce arguments.
  6662. *
  6663. * @private
  6664. * @param {Array} array The array to query.
  6665. * @param {number} n The index of the element to return.
  6666. * @returns {*} Returns the nth element of `array`.
  6667. */
  6668. function baseNth(array, n) {
  6669. var length = array.length;
  6670. if (!length) {
  6671. return;
  6672. }
  6673. n += n < 0 ? length : 0;
  6674. return isIndex(n, length) ? array[n] : undefined;
  6675. }
  6676. /**
  6677. * The base implementation of `_.orderBy` without param guards.
  6678. *
  6679. * @private
  6680. * @param {Array|Object} collection The collection to iterate over.
  6681. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  6682. * @param {string[]} orders The sort orders of `iteratees`.
  6683. * @returns {Array} Returns the new sorted array.
  6684. */
  6685. function baseOrderBy(collection, iteratees, orders) {
  6686. if (iteratees.length) {
  6687. iteratees = arrayMap(iteratees, function(iteratee) {
  6688. if (isArray(iteratee)) {
  6689. return function(value) {
  6690. return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
  6691. }
  6692. }
  6693. return iteratee;
  6694. });
  6695. } else {
  6696. iteratees = [identity];
  6697. }
  6698. var index = -1;
  6699. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  6700. var result = baseMap(collection, function(value, key, collection) {
  6701. var criteria = arrayMap(iteratees, function(iteratee) {
  6702. return iteratee(value);
  6703. });
  6704. return { 'criteria': criteria, 'index': ++index, 'value': value };
  6705. });
  6706. return baseSortBy(result, function(object, other) {
  6707. return compareMultiple(object, other, orders);
  6708. });
  6709. }
  6710. /**
  6711. * The base implementation of `_.pick` without support for individual
  6712. * property identifiers.
  6713. *
  6714. * @private
  6715. * @param {Object} object The source object.
  6716. * @param {string[]} paths The property paths to pick.
  6717. * @returns {Object} Returns the new object.
  6718. */
  6719. function basePick(object, paths) {
  6720. return basePickBy(object, paths, function(value, path) {
  6721. return hasIn(object, path);
  6722. });
  6723. }
  6724. /**
  6725. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  6726. *
  6727. * @private
  6728. * @param {Object} object The source object.
  6729. * @param {string[]} paths The property paths to pick.
  6730. * @param {Function} predicate The function invoked per property.
  6731. * @returns {Object} Returns the new object.
  6732. */
  6733. function basePickBy(object, paths, predicate) {
  6734. var index = -1,
  6735. length = paths.length,
  6736. result = {};
  6737. while (++index < length) {
  6738. var path = paths[index],
  6739. value = baseGet(object, path);
  6740. if (predicate(value, path)) {
  6741. baseSet(result, castPath(path, object), value);
  6742. }
  6743. }
  6744. return result;
  6745. }
  6746. /**
  6747. * A specialized version of `baseProperty` which supports deep paths.
  6748. *
  6749. * @private
  6750. * @param {Array|string} path The path of the property to get.
  6751. * @returns {Function} Returns the new accessor function.
  6752. */
  6753. function basePropertyDeep(path) {
  6754. return function(object) {
  6755. return baseGet(object, path);
  6756. };
  6757. }
  6758. /**
  6759. * The base implementation of `_.pullAllBy` without support for iteratee
  6760. * shorthands.
  6761. *
  6762. * @private
  6763. * @param {Array} array The array to modify.
  6764. * @param {Array} values The values to remove.
  6765. * @param {Function} [iteratee] The iteratee invoked per element.
  6766. * @param {Function} [comparator] The comparator invoked per element.
  6767. * @returns {Array} Returns `array`.
  6768. */
  6769. function basePullAll(array, values, iteratee, comparator) {
  6770. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  6771. index = -1,
  6772. length = values.length,
  6773. seen = array;
  6774. if (array === values) {
  6775. values = copyArray(values);
  6776. }
  6777. if (iteratee) {
  6778. seen = arrayMap(array, baseUnary(iteratee));
  6779. }
  6780. while (++index < length) {
  6781. var fromIndex = 0,
  6782. value = values[index],
  6783. computed = iteratee ? iteratee(value) : value;
  6784. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  6785. if (seen !== array) {
  6786. splice.call(seen, fromIndex, 1);
  6787. }
  6788. splice.call(array, fromIndex, 1);
  6789. }
  6790. }
  6791. return array;
  6792. }
  6793. /**
  6794. * The base implementation of `_.pullAt` without support for individual
  6795. * indexes or capturing the removed elements.
  6796. *
  6797. * @private
  6798. * @param {Array} array The array to modify.
  6799. * @param {number[]} indexes The indexes of elements to remove.
  6800. * @returns {Array} Returns `array`.
  6801. */
  6802. function basePullAt(array, indexes) {
  6803. var length = array ? indexes.length : 0,
  6804. lastIndex = length - 1;
  6805. while (length--) {
  6806. var index = indexes[length];
  6807. if (length == lastIndex || index !== previous) {
  6808. var previous = index;
  6809. if (isIndex(index)) {
  6810. splice.call(array, index, 1);
  6811. } else {
  6812. baseUnset(array, index);
  6813. }
  6814. }
  6815. }
  6816. return array;
  6817. }
  6818. /**
  6819. * The base implementation of `_.random` without support for returning
  6820. * floating-point numbers.
  6821. *
  6822. * @private
  6823. * @param {number} lower The lower bound.
  6824. * @param {number} upper The upper bound.
  6825. * @returns {number} Returns the random number.
  6826. */
  6827. function baseRandom(lower, upper) {
  6828. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  6829. }
  6830. /**
  6831. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  6832. * coerce arguments.
  6833. *
  6834. * @private
  6835. * @param {number} start The start of the range.
  6836. * @param {number} end The end of the range.
  6837. * @param {number} step The value to increment or decrement by.
  6838. * @param {boolean} [fromRight] Specify iterating from right to left.
  6839. * @returns {Array} Returns the range of numbers.
  6840. */
  6841. function baseRange(start, end, step, fromRight) {
  6842. var index = -1,
  6843. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  6844. result = Array(length);
  6845. while (length--) {
  6846. result[fromRight ? length : ++index] = start;
  6847. start += step;
  6848. }
  6849. return result;
  6850. }
  6851. /**
  6852. * The base implementation of `_.repeat` which doesn't coerce arguments.
  6853. *
  6854. * @private
  6855. * @param {string} string The string to repeat.
  6856. * @param {number} n The number of times to repeat the string.
  6857. * @returns {string} Returns the repeated string.
  6858. */
  6859. function baseRepeat(string, n) {
  6860. var result = '';
  6861. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  6862. return result;
  6863. }
  6864. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  6865. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  6866. do {
  6867. if (n % 2) {
  6868. result += string;
  6869. }
  6870. n = nativeFloor(n / 2);
  6871. if (n) {
  6872. string += string;
  6873. }
  6874. } while (n);
  6875. return result;
  6876. }
  6877. /**
  6878. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  6879. *
  6880. * @private
  6881. * @param {Function} func The function to apply a rest parameter to.
  6882. * @param {number} [start=func.length-1] The start position of the rest parameter.
  6883. * @returns {Function} Returns the new function.
  6884. */
  6885. function baseRest(func, start) {
  6886. return setToString(overRest(func, start, identity), func + '');
  6887. }
  6888. /**
  6889. * The base implementation of `_.sample`.
  6890. *
  6891. * @private
  6892. * @param {Array|Object} collection The collection to sample.
  6893. * @returns {*} Returns the random element.
  6894. */
  6895. function baseSample(collection) {
  6896. return arraySample(values(collection));
  6897. }
  6898. /**
  6899. * The base implementation of `_.sampleSize` without param guards.
  6900. *
  6901. * @private
  6902. * @param {Array|Object} collection The collection to sample.
  6903. * @param {number} n The number of elements to sample.
  6904. * @returns {Array} Returns the random elements.
  6905. */
  6906. function baseSampleSize(collection, n) {
  6907. var array = values(collection);
  6908. return shuffleSelf(array, baseClamp(n, 0, array.length));
  6909. }
  6910. /**
  6911. * The base implementation of `_.set`.
  6912. *
  6913. * @private
  6914. * @param {Object} object The object to modify.
  6915. * @param {Array|string} path The path of the property to set.
  6916. * @param {*} value The value to set.
  6917. * @param {Function} [customizer] The function to customize path creation.
  6918. * @returns {Object} Returns `object`.
  6919. */
  6920. function baseSet(object, path, value, customizer) {
  6921. if (!isObject(object)) {
  6922. return object;
  6923. }
  6924. path = castPath(path, object);
  6925. var index = -1,
  6926. length = path.length,
  6927. lastIndex = length - 1,
  6928. nested = object;
  6929. while (nested != null && ++index < length) {
  6930. var key = toKey(path[index]),
  6931. newValue = value;
  6932. if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
  6933. return object;
  6934. }
  6935. if (index != lastIndex) {
  6936. var objValue = nested[key];
  6937. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  6938. if (newValue === undefined) {
  6939. newValue = isObject(objValue)
  6940. ? objValue
  6941. : (isIndex(path[index + 1]) ? [] : {});
  6942. }
  6943. }
  6944. assignValue(nested, key, newValue);
  6945. nested = nested[key];
  6946. }
  6947. return object;
  6948. }
  6949. /**
  6950. * The base implementation of `setData` without support for hot loop shorting.
  6951. *
  6952. * @private
  6953. * @param {Function} func The function to associate metadata with.
  6954. * @param {*} data The metadata.
  6955. * @returns {Function} Returns `func`.
  6956. */
  6957. var baseSetData = !metaMap ? identity : function(func, data) {
  6958. metaMap.set(func, data);
  6959. return func;
  6960. };
  6961. /**
  6962. * The base implementation of `setToString` without support for hot loop shorting.
  6963. *
  6964. * @private
  6965. * @param {Function} func The function to modify.
  6966. * @param {Function} string The `toString` result.
  6967. * @returns {Function} Returns `func`.
  6968. */
  6969. var baseSetToString = !defineProperty ? identity : function(func, string) {
  6970. return defineProperty(func, 'toString', {
  6971. 'configurable': true,
  6972. 'enumerable': false,
  6973. 'value': constant(string),
  6974. 'writable': true
  6975. });
  6976. };
  6977. /**
  6978. * The base implementation of `_.shuffle`.
  6979. *
  6980. * @private
  6981. * @param {Array|Object} collection The collection to shuffle.
  6982. * @returns {Array} Returns the new shuffled array.
  6983. */
  6984. function baseShuffle(collection) {
  6985. return shuffleSelf(values(collection));
  6986. }
  6987. /**
  6988. * The base implementation of `_.slice` without an iteratee call guard.
  6989. *
  6990. * @private
  6991. * @param {Array} array The array to slice.
  6992. * @param {number} [start=0] The start position.
  6993. * @param {number} [end=array.length] The end position.
  6994. * @returns {Array} Returns the slice of `array`.
  6995. */
  6996. function baseSlice(array, start, end) {
  6997. var index = -1,
  6998. length = array.length;
  6999. if (start < 0) {
  7000. start = -start > length ? 0 : (length + start);
  7001. }
  7002. end = end > length ? length : end;
  7003. if (end < 0) {
  7004. end += length;
  7005. }
  7006. length = start > end ? 0 : ((end - start) >>> 0);
  7007. start >>>= 0;
  7008. var result = Array(length);
  7009. while (++index < length) {
  7010. result[index] = array[index + start];
  7011. }
  7012. return result;
  7013. }
  7014. /**
  7015. * The base implementation of `_.some` without support for iteratee shorthands.
  7016. *
  7017. * @private
  7018. * @param {Array|Object} collection The collection to iterate over.
  7019. * @param {Function} predicate The function invoked per iteration.
  7020. * @returns {boolean} Returns `true` if any element passes the predicate check,
  7021. * else `false`.
  7022. */
  7023. function baseSome(collection, predicate) {
  7024. var result;
  7025. baseEach(collection, function(value, index, collection) {
  7026. result = predicate(value, index, collection);
  7027. return !result;
  7028. });
  7029. return !!result;
  7030. }
  7031. /**
  7032. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  7033. * performs a binary search of `array` to determine the index at which `value`
  7034. * should be inserted into `array` in order to maintain its sort order.
  7035. *
  7036. * @private
  7037. * @param {Array} array The sorted array to inspect.
  7038. * @param {*} value The value to evaluate.
  7039. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  7040. * @returns {number} Returns the index at which `value` should be inserted
  7041. * into `array`.
  7042. */
  7043. function baseSortedIndex(array, value, retHighest) {
  7044. var low = 0,
  7045. high = array == null ? low : array.length;
  7046. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  7047. while (low < high) {
  7048. var mid = (low + high) >>> 1,
  7049. computed = array[mid];
  7050. if (computed !== null && !isSymbol(computed) &&
  7051. (retHighest ? (computed <= value) : (computed < value))) {
  7052. low = mid + 1;
  7053. } else {
  7054. high = mid;
  7055. }
  7056. }
  7057. return high;
  7058. }
  7059. return baseSortedIndexBy(array, value, identity, retHighest);
  7060. }
  7061. /**
  7062. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  7063. * which invokes `iteratee` for `value` and each element of `array` to compute
  7064. * their sort ranking. The iteratee is invoked with one argument; (value).
  7065. *
  7066. * @private
  7067. * @param {Array} array The sorted array to inspect.
  7068. * @param {*} value The value to evaluate.
  7069. * @param {Function} iteratee The iteratee invoked per element.
  7070. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  7071. * @returns {number} Returns the index at which `value` should be inserted
  7072. * into `array`.
  7073. */
  7074. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  7075. var low = 0,
  7076. high = array == null ? 0 : array.length;
  7077. if (high === 0) {
  7078. return 0;
  7079. }
  7080. value = iteratee(value);
  7081. var valIsNaN = value !== value,
  7082. valIsNull = value === null,
  7083. valIsSymbol = isSymbol(value),
  7084. valIsUndefined = value === undefined;
  7085. while (low < high) {
  7086. var mid = nativeFloor((low + high) / 2),
  7087. computed = iteratee(array[mid]),
  7088. othIsDefined = computed !== undefined,
  7089. othIsNull = computed === null,
  7090. othIsReflexive = computed === computed,
  7091. othIsSymbol = isSymbol(computed);
  7092. if (valIsNaN) {
  7093. var setLow = retHighest || othIsReflexive;
  7094. } else if (valIsUndefined) {
  7095. setLow = othIsReflexive && (retHighest || othIsDefined);
  7096. } else if (valIsNull) {
  7097. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  7098. } else if (valIsSymbol) {
  7099. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  7100. } else if (othIsNull || othIsSymbol) {
  7101. setLow = false;
  7102. } else {
  7103. setLow = retHighest ? (computed <= value) : (computed < value);
  7104. }
  7105. if (setLow) {
  7106. low = mid + 1;
  7107. } else {
  7108. high = mid;
  7109. }
  7110. }
  7111. return nativeMin(high, MAX_ARRAY_INDEX);
  7112. }
  7113. /**
  7114. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  7115. * support for iteratee shorthands.
  7116. *
  7117. * @private
  7118. * @param {Array} array The array to inspect.
  7119. * @param {Function} [iteratee] The iteratee invoked per element.
  7120. * @returns {Array} Returns the new duplicate free array.
  7121. */
  7122. function baseSortedUniq(array, iteratee) {
  7123. var index = -1,
  7124. length = array.length,
  7125. resIndex = 0,
  7126. result = [];
  7127. while (++index < length) {
  7128. var value = array[index],
  7129. computed = iteratee ? iteratee(value) : value;
  7130. if (!index || !eq(computed, seen)) {
  7131. var seen = computed;
  7132. result[resIndex++] = value === 0 ? 0 : value;
  7133. }
  7134. }
  7135. return result;
  7136. }
  7137. /**
  7138. * The base implementation of `_.toNumber` which doesn't ensure correct
  7139. * conversions of binary, hexadecimal, or octal string values.
  7140. *
  7141. * @private
  7142. * @param {*} value The value to process.
  7143. * @returns {number} Returns the number.
  7144. */
  7145. function baseToNumber(value) {
  7146. if (typeof value == 'number') {
  7147. return value;
  7148. }
  7149. if (isSymbol(value)) {
  7150. return NAN;
  7151. }
  7152. return +value;
  7153. }
  7154. /**
  7155. * The base implementation of `_.toString` which doesn't convert nullish
  7156. * values to empty strings.
  7157. *
  7158. * @private
  7159. * @param {*} value The value to process.
  7160. * @returns {string} Returns the string.
  7161. */
  7162. function baseToString(value) {
  7163. // Exit early for strings to avoid a performance hit in some environments.
  7164. if (typeof value == 'string') {
  7165. return value;
  7166. }
  7167. if (isArray(value)) {
  7168. // Recursively convert values (susceptible to call stack limits).
  7169. return arrayMap(value, baseToString) + '';
  7170. }
  7171. if (isSymbol(value)) {
  7172. return symbolToString ? symbolToString.call(value) : '';
  7173. }
  7174. var result = (value + '');
  7175. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  7176. }
  7177. /**
  7178. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  7179. *
  7180. * @private
  7181. * @param {Array} array The array to inspect.
  7182. * @param {Function} [iteratee] The iteratee invoked per element.
  7183. * @param {Function} [comparator] The comparator invoked per element.
  7184. * @returns {Array} Returns the new duplicate free array.
  7185. */
  7186. function baseUniq(array, iteratee, comparator) {
  7187. var index = -1,
  7188. includes = arrayIncludes,
  7189. length = array.length,
  7190. isCommon = true,
  7191. result = [],
  7192. seen = result;
  7193. if (comparator) {
  7194. isCommon = false;
  7195. includes = arrayIncludesWith;
  7196. }
  7197. else if (length >= LARGE_ARRAY_SIZE) {
  7198. var set = iteratee ? null : createSet(array);
  7199. if (set) {
  7200. return setToArray(set);
  7201. }
  7202. isCommon = false;
  7203. includes = cacheHas;
  7204. seen = new SetCache;
  7205. }
  7206. else {
  7207. seen = iteratee ? [] : result;
  7208. }
  7209. outer:
  7210. while (++index < length) {
  7211. var value = array[index],
  7212. computed = iteratee ? iteratee(value) : value;
  7213. value = (comparator || value !== 0) ? value : 0;
  7214. if (isCommon && computed === computed) {
  7215. var seenIndex = seen.length;
  7216. while (seenIndex--) {
  7217. if (seen[seenIndex] === computed) {
  7218. continue outer;
  7219. }
  7220. }
  7221. if (iteratee) {
  7222. seen.push(computed);
  7223. }
  7224. result.push(value);
  7225. }
  7226. else if (!includes(seen, computed, comparator)) {
  7227. if (seen !== result) {
  7228. seen.push(computed);
  7229. }
  7230. result.push(value);
  7231. }
  7232. }
  7233. return result;
  7234. }
  7235. /**
  7236. * The base implementation of `_.unset`.
  7237. *
  7238. * @private
  7239. * @param {Object} object The object to modify.
  7240. * @param {Array|string} path The property path to unset.
  7241. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  7242. */
  7243. function baseUnset(object, path) {
  7244. path = castPath(path, object);
  7245. object = parent(object, path);
  7246. return object == null || delete object[toKey(last(path))];
  7247. }
  7248. /**
  7249. * The base implementation of `_.update`.
  7250. *
  7251. * @private
  7252. * @param {Object} object The object to modify.
  7253. * @param {Array|string} path The path of the property to update.
  7254. * @param {Function} updater The function to produce the updated value.
  7255. * @param {Function} [customizer] The function to customize path creation.
  7256. * @returns {Object} Returns `object`.
  7257. */
  7258. function baseUpdate(object, path, updater, customizer) {
  7259. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  7260. }
  7261. /**
  7262. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  7263. * without support for iteratee shorthands.
  7264. *
  7265. * @private
  7266. * @param {Array} array The array to query.
  7267. * @param {Function} predicate The function invoked per iteration.
  7268. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  7269. * @param {boolean} [fromRight] Specify iterating from right to left.
  7270. * @returns {Array} Returns the slice of `array`.
  7271. */
  7272. function baseWhile(array, predicate, isDrop, fromRight) {
  7273. var length = array.length,
  7274. index = fromRight ? length : -1;
  7275. while ((fromRight ? index-- : ++index < length) &&
  7276. predicate(array[index], index, array)) {}
  7277. return isDrop
  7278. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  7279. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  7280. }
  7281. /**
  7282. * The base implementation of `wrapperValue` which returns the result of
  7283. * performing a sequence of actions on the unwrapped `value`, where each
  7284. * successive action is supplied the return value of the previous.
  7285. *
  7286. * @private
  7287. * @param {*} value The unwrapped value.
  7288. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  7289. * @returns {*} Returns the resolved value.
  7290. */
  7291. function baseWrapperValue(value, actions) {
  7292. var result = value;
  7293. if (result instanceof LazyWrapper) {
  7294. result = result.value();
  7295. }
  7296. return arrayReduce(actions, function(result, action) {
  7297. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  7298. }, result);
  7299. }
  7300. /**
  7301. * The base implementation of methods like `_.xor`, without support for
  7302. * iteratee shorthands, that accepts an array of arrays to inspect.
  7303. *
  7304. * @private
  7305. * @param {Array} arrays The arrays to inspect.
  7306. * @param {Function} [iteratee] The iteratee invoked per element.
  7307. * @param {Function} [comparator] The comparator invoked per element.
  7308. * @returns {Array} Returns the new array of values.
  7309. */
  7310. function baseXor(arrays, iteratee, comparator) {
  7311. var length = arrays.length;
  7312. if (length < 2) {
  7313. return length ? baseUniq(arrays[0]) : [];
  7314. }
  7315. var index = -1,
  7316. result = Array(length);
  7317. while (++index < length) {
  7318. var array = arrays[index],
  7319. othIndex = -1;
  7320. while (++othIndex < length) {
  7321. if (othIndex != index) {
  7322. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  7323. }
  7324. }
  7325. }
  7326. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  7327. }
  7328. /**
  7329. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  7330. *
  7331. * @private
  7332. * @param {Array} props The property identifiers.
  7333. * @param {Array} values The property values.
  7334. * @param {Function} assignFunc The function to assign values.
  7335. * @returns {Object} Returns the new object.
  7336. */
  7337. function baseZipObject(props, values, assignFunc) {
  7338. var index = -1,
  7339. length = props.length,
  7340. valsLength = values.length,
  7341. result = {};
  7342. while (++index < length) {
  7343. var value = index < valsLength ? values[index] : undefined;
  7344. assignFunc(result, props[index], value);
  7345. }
  7346. return result;
  7347. }
  7348. /**
  7349. * Casts `value` to an empty array if it's not an array like object.
  7350. *
  7351. * @private
  7352. * @param {*} value The value to inspect.
  7353. * @returns {Array|Object} Returns the cast array-like object.
  7354. */
  7355. function castArrayLikeObject(value) {
  7356. return isArrayLikeObject(value) ? value : [];
  7357. }
  7358. /**
  7359. * Casts `value` to `identity` if it's not a function.
  7360. *
  7361. * @private
  7362. * @param {*} value The value to inspect.
  7363. * @returns {Function} Returns cast function.
  7364. */
  7365. function castFunction(value) {
  7366. return typeof value == 'function' ? value : identity;
  7367. }
  7368. /**
  7369. * Casts `value` to a path array if it's not one.
  7370. *
  7371. * @private
  7372. * @param {*} value The value to inspect.
  7373. * @param {Object} [object] The object to query keys on.
  7374. * @returns {Array} Returns the cast property path array.
  7375. */
  7376. function castPath(value, object) {
  7377. if (isArray(value)) {
  7378. return value;
  7379. }
  7380. return isKey(value, object) ? [value] : stringToPath(toString(value));
  7381. }
  7382. /**
  7383. * A `baseRest` alias which can be replaced with `identity` by module
  7384. * replacement plugins.
  7385. *
  7386. * @private
  7387. * @type {Function}
  7388. * @param {Function} func The function to apply a rest parameter to.
  7389. * @returns {Function} Returns the new function.
  7390. */
  7391. var castRest = baseRest;
  7392. /**
  7393. * Casts `array` to a slice if it's needed.
  7394. *
  7395. * @private
  7396. * @param {Array} array The array to inspect.
  7397. * @param {number} start The start position.
  7398. * @param {number} [end=array.length] The end position.
  7399. * @returns {Array} Returns the cast slice.
  7400. */
  7401. function castSlice(array, start, end) {
  7402. var length = array.length;
  7403. end = end === undefined ? length : end;
  7404. return (!start && end >= length) ? array : baseSlice(array, start, end);
  7405. }
  7406. /**
  7407. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  7408. *
  7409. * @private
  7410. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  7411. */
  7412. var clearTimeout = ctxClearTimeout || function(id) {
  7413. return root.clearTimeout(id);
  7414. };
  7415. /**
  7416. * Creates a clone of `buffer`.
  7417. *
  7418. * @private
  7419. * @param {Buffer} buffer The buffer to clone.
  7420. * @param {boolean} [isDeep] Specify a deep clone.
  7421. * @returns {Buffer} Returns the cloned buffer.
  7422. */
  7423. function cloneBuffer(buffer, isDeep) {
  7424. if (isDeep) {
  7425. return buffer.slice();
  7426. }
  7427. var length = buffer.length,
  7428. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  7429. buffer.copy(result);
  7430. return result;
  7431. }
  7432. /**
  7433. * Creates a clone of `arrayBuffer`.
  7434. *
  7435. * @private
  7436. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  7437. * @returns {ArrayBuffer} Returns the cloned array buffer.
  7438. */
  7439. function cloneArrayBuffer(arrayBuffer) {
  7440. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  7441. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  7442. return result;
  7443. }
  7444. /**
  7445. * Creates a clone of `dataView`.
  7446. *
  7447. * @private
  7448. * @param {Object} dataView The data view to clone.
  7449. * @param {boolean} [isDeep] Specify a deep clone.
  7450. * @returns {Object} Returns the cloned data view.
  7451. */
  7452. function cloneDataView(dataView, isDeep) {
  7453. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  7454. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  7455. }
  7456. /**
  7457. * Creates a clone of `regexp`.
  7458. *
  7459. * @private
  7460. * @param {Object} regexp The regexp to clone.
  7461. * @returns {Object} Returns the cloned regexp.
  7462. */
  7463. function cloneRegExp(regexp) {
  7464. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  7465. result.lastIndex = regexp.lastIndex;
  7466. return result;
  7467. }
  7468. /**
  7469. * Creates a clone of the `symbol` object.
  7470. *
  7471. * @private
  7472. * @param {Object} symbol The symbol object to clone.
  7473. * @returns {Object} Returns the cloned symbol object.
  7474. */
  7475. function cloneSymbol(symbol) {
  7476. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  7477. }
  7478. /**
  7479. * Creates a clone of `typedArray`.
  7480. *
  7481. * @private
  7482. * @param {Object} typedArray The typed array to clone.
  7483. * @param {boolean} [isDeep] Specify a deep clone.
  7484. * @returns {Object} Returns the cloned typed array.
  7485. */
  7486. function cloneTypedArray(typedArray, isDeep) {
  7487. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  7488. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  7489. }
  7490. /**
  7491. * Compares values to sort them in ascending order.
  7492. *
  7493. * @private
  7494. * @param {*} value The value to compare.
  7495. * @param {*} other The other value to compare.
  7496. * @returns {number} Returns the sort order indicator for `value`.
  7497. */
  7498. function compareAscending(value, other) {
  7499. if (value !== other) {
  7500. var valIsDefined = value !== undefined,
  7501. valIsNull = value === null,
  7502. valIsReflexive = value === value,
  7503. valIsSymbol = isSymbol(value);
  7504. var othIsDefined = other !== undefined,
  7505. othIsNull = other === null,
  7506. othIsReflexive = other === other,
  7507. othIsSymbol = isSymbol(other);
  7508. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  7509. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  7510. (valIsNull && othIsDefined && othIsReflexive) ||
  7511. (!valIsDefined && othIsReflexive) ||
  7512. !valIsReflexive) {
  7513. return 1;
  7514. }
  7515. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  7516. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  7517. (othIsNull && valIsDefined && valIsReflexive) ||
  7518. (!othIsDefined && valIsReflexive) ||
  7519. !othIsReflexive) {
  7520. return -1;
  7521. }
  7522. }
  7523. return 0;
  7524. }
  7525. /**
  7526. * Used by `_.orderBy` to compare multiple properties of a value to another
  7527. * and stable sort them.
  7528. *
  7529. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  7530. * specify an order of "desc" for descending or "asc" for ascending sort order
  7531. * of corresponding values.
  7532. *
  7533. * @private
  7534. * @param {Object} object The object to compare.
  7535. * @param {Object} other The other object to compare.
  7536. * @param {boolean[]|string[]} orders The order to sort by for each property.
  7537. * @returns {number} Returns the sort order indicator for `object`.
  7538. */
  7539. function compareMultiple(object, other, orders) {
  7540. var index = -1,
  7541. objCriteria = object.criteria,
  7542. othCriteria = other.criteria,
  7543. length = objCriteria.length,
  7544. ordersLength = orders.length;
  7545. while (++index < length) {
  7546. var result = compareAscending(objCriteria[index], othCriteria[index]);
  7547. if (result) {
  7548. if (index >= ordersLength) {
  7549. return result;
  7550. }
  7551. var order = orders[index];
  7552. return result * (order == 'desc' ? -1 : 1);
  7553. }
  7554. }
  7555. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  7556. // that causes it, under certain circumstances, to provide the same value for
  7557. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  7558. // for more details.
  7559. //
  7560. // This also ensures a stable sort in V8 and other engines.
  7561. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  7562. return object.index - other.index;
  7563. }
  7564. /**
  7565. * Creates an array that is the composition of partially applied arguments,
  7566. * placeholders, and provided arguments into a single array of arguments.
  7567. *
  7568. * @private
  7569. * @param {Array} args The provided arguments.
  7570. * @param {Array} partials The arguments to prepend to those provided.
  7571. * @param {Array} holders The `partials` placeholder indexes.
  7572. * @params {boolean} [isCurried] Specify composing for a curried function.
  7573. * @returns {Array} Returns the new array of composed arguments.
  7574. */
  7575. function composeArgs(args, partials, holders, isCurried) {
  7576. var argsIndex = -1,
  7577. argsLength = args.length,
  7578. holdersLength = holders.length,
  7579. leftIndex = -1,
  7580. leftLength = partials.length,
  7581. rangeLength = nativeMax(argsLength - holdersLength, 0),
  7582. result = Array(leftLength + rangeLength),
  7583. isUncurried = !isCurried;
  7584. while (++leftIndex < leftLength) {
  7585. result[leftIndex] = partials[leftIndex];
  7586. }
  7587. while (++argsIndex < holdersLength) {
  7588. if (isUncurried || argsIndex < argsLength) {
  7589. result[holders[argsIndex]] = args[argsIndex];
  7590. }
  7591. }
  7592. while (rangeLength--) {
  7593. result[leftIndex++] = args[argsIndex++];
  7594. }
  7595. return result;
  7596. }
  7597. /**
  7598. * This function is like `composeArgs` except that the arguments composition
  7599. * is tailored for `_.partialRight`.
  7600. *
  7601. * @private
  7602. * @param {Array} args The provided arguments.
  7603. * @param {Array} partials The arguments to append to those provided.
  7604. * @param {Array} holders The `partials` placeholder indexes.
  7605. * @params {boolean} [isCurried] Specify composing for a curried function.
  7606. * @returns {Array} Returns the new array of composed arguments.
  7607. */
  7608. function composeArgsRight(args, partials, holders, isCurried) {
  7609. var argsIndex = -1,
  7610. argsLength = args.length,
  7611. holdersIndex = -1,
  7612. holdersLength = holders.length,
  7613. rightIndex = -1,
  7614. rightLength = partials.length,
  7615. rangeLength = nativeMax(argsLength - holdersLength, 0),
  7616. result = Array(rangeLength + rightLength),
  7617. isUncurried = !isCurried;
  7618. while (++argsIndex < rangeLength) {
  7619. result[argsIndex] = args[argsIndex];
  7620. }
  7621. var offset = argsIndex;
  7622. while (++rightIndex < rightLength) {
  7623. result[offset + rightIndex] = partials[rightIndex];
  7624. }
  7625. while (++holdersIndex < holdersLength) {
  7626. if (isUncurried || argsIndex < argsLength) {
  7627. result[offset + holders[holdersIndex]] = args[argsIndex++];
  7628. }
  7629. }
  7630. return result;
  7631. }
  7632. /**
  7633. * Copies the values of `source` to `array`.
  7634. *
  7635. * @private
  7636. * @param {Array} source The array to copy values from.
  7637. * @param {Array} [array=[]] The array to copy values to.
  7638. * @returns {Array} Returns `array`.
  7639. */
  7640. function copyArray(source, array) {
  7641. var index = -1,
  7642. length = source.length;
  7643. array || (array = Array(length));
  7644. while (++index < length) {
  7645. array[index] = source[index];
  7646. }
  7647. return array;
  7648. }
  7649. /**
  7650. * Copies properties of `source` to `object`.
  7651. *
  7652. * @private
  7653. * @param {Object} source The object to copy properties from.
  7654. * @param {Array} props The property identifiers to copy.
  7655. * @param {Object} [object={}] The object to copy properties to.
  7656. * @param {Function} [customizer] The function to customize copied values.
  7657. * @returns {Object} Returns `object`.
  7658. */
  7659. function copyObject(source, props, object, customizer) {
  7660. var isNew = !object;
  7661. object || (object = {});
  7662. var index = -1,
  7663. length = props.length;
  7664. while (++index < length) {
  7665. var key = props[index];
  7666. var newValue = customizer
  7667. ? customizer(object[key], source[key], key, object, source)
  7668. : undefined;
  7669. if (newValue === undefined) {
  7670. newValue = source[key];
  7671. }
  7672. if (isNew) {
  7673. baseAssignValue(object, key, newValue);
  7674. } else {
  7675. assignValue(object, key, newValue);
  7676. }
  7677. }
  7678. return object;
  7679. }
  7680. /**
  7681. * Copies own symbols of `source` to `object`.
  7682. *
  7683. * @private
  7684. * @param {Object} source The object to copy symbols from.
  7685. * @param {Object} [object={}] The object to copy symbols to.
  7686. * @returns {Object} Returns `object`.
  7687. */
  7688. function copySymbols(source, object) {
  7689. return copyObject(source, getSymbols(source), object);
  7690. }
  7691. /**
  7692. * Copies own and inherited symbols of `source` to `object`.
  7693. *
  7694. * @private
  7695. * @param {Object} source The object to copy symbols from.
  7696. * @param {Object} [object={}] The object to copy symbols to.
  7697. * @returns {Object} Returns `object`.
  7698. */
  7699. function copySymbolsIn(source, object) {
  7700. return copyObject(source, getSymbolsIn(source), object);
  7701. }
  7702. /**
  7703. * Creates a function like `_.groupBy`.
  7704. *
  7705. * @private
  7706. * @param {Function} setter The function to set accumulator values.
  7707. * @param {Function} [initializer] The accumulator object initializer.
  7708. * @returns {Function} Returns the new aggregator function.
  7709. */
  7710. function createAggregator(setter, initializer) {
  7711. return function(collection, iteratee) {
  7712. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  7713. accumulator = initializer ? initializer() : {};
  7714. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  7715. };
  7716. }
  7717. /**
  7718. * Creates a function like `_.assign`.
  7719. *
  7720. * @private
  7721. * @param {Function} assigner The function to assign values.
  7722. * @returns {Function} Returns the new assigner function.
  7723. */
  7724. function createAssigner(assigner) {
  7725. return baseRest(function(object, sources) {
  7726. var index = -1,
  7727. length = sources.length,
  7728. customizer = length > 1 ? sources[length - 1] : undefined,
  7729. guard = length > 2 ? sources[2] : undefined;
  7730. customizer = (assigner.length > 3 && typeof customizer == 'function')
  7731. ? (length--, customizer)
  7732. : undefined;
  7733. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  7734. customizer = length < 3 ? undefined : customizer;
  7735. length = 1;
  7736. }
  7737. object = Object(object);
  7738. while (++index < length) {
  7739. var source = sources[index];
  7740. if (source) {
  7741. assigner(object, source, index, customizer);
  7742. }
  7743. }
  7744. return object;
  7745. });
  7746. }
  7747. /**
  7748. * Creates a `baseEach` or `baseEachRight` function.
  7749. *
  7750. * @private
  7751. * @param {Function} eachFunc The function to iterate over a collection.
  7752. * @param {boolean} [fromRight] Specify iterating from right to left.
  7753. * @returns {Function} Returns the new base function.
  7754. */
  7755. function createBaseEach(eachFunc, fromRight) {
  7756. return function(collection, iteratee) {
  7757. if (collection == null) {
  7758. return collection;
  7759. }
  7760. if (!isArrayLike(collection)) {
  7761. return eachFunc(collection, iteratee);
  7762. }
  7763. var length = collection.length,
  7764. index = fromRight ? length : -1,
  7765. iterable = Object(collection);
  7766. while ((fromRight ? index-- : ++index < length)) {
  7767. if (iteratee(iterable[index], index, iterable) === false) {
  7768. break;
  7769. }
  7770. }
  7771. return collection;
  7772. };
  7773. }
  7774. /**
  7775. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  7776. *
  7777. * @private
  7778. * @param {boolean} [fromRight] Specify iterating from right to left.
  7779. * @returns {Function} Returns the new base function.
  7780. */
  7781. function createBaseFor(fromRight) {
  7782. return function(object, iteratee, keysFunc) {
  7783. var index = -1,
  7784. iterable = Object(object),
  7785. props = keysFunc(object),
  7786. length = props.length;
  7787. while (length--) {
  7788. var key = props[fromRight ? length : ++index];
  7789. if (iteratee(iterable[key], key, iterable) === false) {
  7790. break;
  7791. }
  7792. }
  7793. return object;
  7794. };
  7795. }
  7796. /**
  7797. * Creates a function that wraps `func` to invoke it with the optional `this`
  7798. * binding of `thisArg`.
  7799. *
  7800. * @private
  7801. * @param {Function} func The function to wrap.
  7802. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  7803. * @param {*} [thisArg] The `this` binding of `func`.
  7804. * @returns {Function} Returns the new wrapped function.
  7805. */
  7806. function createBind(func, bitmask, thisArg) {
  7807. var isBind = bitmask & WRAP_BIND_FLAG,
  7808. Ctor = createCtor(func);
  7809. function wrapper() {
  7810. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  7811. return fn.apply(isBind ? thisArg : this, arguments);
  7812. }
  7813. return wrapper;
  7814. }
  7815. /**
  7816. * Creates a function like `_.lowerFirst`.
  7817. *
  7818. * @private
  7819. * @param {string} methodName The name of the `String` case method to use.
  7820. * @returns {Function} Returns the new case function.
  7821. */
  7822. function createCaseFirst(methodName) {
  7823. return function(string) {
  7824. string = toString(string);
  7825. var strSymbols = hasUnicode(string)
  7826. ? stringToArray(string)
  7827. : undefined;
  7828. var chr = strSymbols
  7829. ? strSymbols[0]
  7830. : string.charAt(0);
  7831. var trailing = strSymbols
  7832. ? castSlice(strSymbols, 1).join('')
  7833. : string.slice(1);
  7834. return chr[methodName]() + trailing;
  7835. };
  7836. }
  7837. /**
  7838. * Creates a function like `_.camelCase`.
  7839. *
  7840. * @private
  7841. * @param {Function} callback The function to combine each word.
  7842. * @returns {Function} Returns the new compounder function.
  7843. */
  7844. function createCompounder(callback) {
  7845. return function(string) {
  7846. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  7847. };
  7848. }
  7849. /**
  7850. * Creates a function that produces an instance of `Ctor` regardless of
  7851. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  7852. *
  7853. * @private
  7854. * @param {Function} Ctor The constructor to wrap.
  7855. * @returns {Function} Returns the new wrapped function.
  7856. */
  7857. function createCtor(Ctor) {
  7858. return function() {
  7859. // Use a `switch` statement to work with class constructors. See
  7860. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  7861. // for more details.
  7862. var args = arguments;
  7863. switch (args.length) {
  7864. case 0: return new Ctor;
  7865. case 1: return new Ctor(args[0]);
  7866. case 2: return new Ctor(args[0], args[1]);
  7867. case 3: return new Ctor(args[0], args[1], args[2]);
  7868. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  7869. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  7870. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  7871. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  7872. }
  7873. var thisBinding = baseCreate(Ctor.prototype),
  7874. result = Ctor.apply(thisBinding, args);
  7875. // Mimic the constructor's `return` behavior.
  7876. // See https://es5.github.io/#x13.2.2 for more details.
  7877. return isObject(result) ? result : thisBinding;
  7878. };
  7879. }
  7880. /**
  7881. * Creates a function that wraps `func` to enable currying.
  7882. *
  7883. * @private
  7884. * @param {Function} func The function to wrap.
  7885. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  7886. * @param {number} arity The arity of `func`.
  7887. * @returns {Function} Returns the new wrapped function.
  7888. */
  7889. function createCurry(func, bitmask, arity) {
  7890. var Ctor = createCtor(func);
  7891. function wrapper() {
  7892. var length = arguments.length,
  7893. args = Array(length),
  7894. index = length,
  7895. placeholder = getHolder(wrapper);
  7896. while (index--) {
  7897. args[index] = arguments[index];
  7898. }
  7899. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  7900. ? []
  7901. : replaceHolders(args, placeholder);
  7902. length -= holders.length;
  7903. if (length < arity) {
  7904. return createRecurry(
  7905. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  7906. args, holders, undefined, undefined, arity - length);
  7907. }
  7908. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  7909. return apply(fn, this, args);
  7910. }
  7911. return wrapper;
  7912. }
  7913. /**
  7914. * Creates a `_.find` or `_.findLast` function.
  7915. *
  7916. * @private
  7917. * @param {Function} findIndexFunc The function to find the collection index.
  7918. * @returns {Function} Returns the new find function.
  7919. */
  7920. function createFind(findIndexFunc) {
  7921. return function(collection, predicate, fromIndex) {
  7922. var iterable = Object(collection);
  7923. if (!isArrayLike(collection)) {
  7924. var iteratee = getIteratee(predicate, 3);
  7925. collection = keys(collection);
  7926. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  7927. }
  7928. var index = findIndexFunc(collection, predicate, fromIndex);
  7929. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  7930. };
  7931. }
  7932. /**
  7933. * Creates a `_.flow` or `_.flowRight` function.
  7934. *
  7935. * @private
  7936. * @param {boolean} [fromRight] Specify iterating from right to left.
  7937. * @returns {Function} Returns the new flow function.
  7938. */
  7939. function createFlow(fromRight) {
  7940. return flatRest(function(funcs) {
  7941. var length = funcs.length,
  7942. index = length,
  7943. prereq = LodashWrapper.prototype.thru;
  7944. if (fromRight) {
  7945. funcs.reverse();
  7946. }
  7947. while (index--) {
  7948. var func = funcs[index];
  7949. if (typeof func != 'function') {
  7950. throw new TypeError(FUNC_ERROR_TEXT);
  7951. }
  7952. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  7953. var wrapper = new LodashWrapper([], true);
  7954. }
  7955. }
  7956. index = wrapper ? index : length;
  7957. while (++index < length) {
  7958. func = funcs[index];
  7959. var funcName = getFuncName(func),
  7960. data = funcName == 'wrapper' ? getData(func) : undefined;
  7961. if (data && isLaziable(data[0]) &&
  7962. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  7963. !data[4].length && data[9] == 1
  7964. ) {
  7965. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  7966. } else {
  7967. wrapper = (func.length == 1 && isLaziable(func))
  7968. ? wrapper[funcName]()
  7969. : wrapper.thru(func);
  7970. }
  7971. }
  7972. return function() {
  7973. var args = arguments,
  7974. value = args[0];
  7975. if (wrapper && args.length == 1 && isArray(value)) {
  7976. return wrapper.plant(value).value();
  7977. }
  7978. var index = 0,
  7979. result = length ? funcs[index].apply(this, args) : value;
  7980. while (++index < length) {
  7981. result = funcs[index].call(this, result);
  7982. }
  7983. return result;
  7984. };
  7985. });
  7986. }
  7987. /**
  7988. * Creates a function that wraps `func` to invoke it with optional `this`
  7989. * binding of `thisArg`, partial application, and currying.
  7990. *
  7991. * @private
  7992. * @param {Function|string} func The function or method name to wrap.
  7993. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  7994. * @param {*} [thisArg] The `this` binding of `func`.
  7995. * @param {Array} [partials] The arguments to prepend to those provided to
  7996. * the new function.
  7997. * @param {Array} [holders] The `partials` placeholder indexes.
  7998. * @param {Array} [partialsRight] The arguments to append to those provided
  7999. * to the new function.
  8000. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  8001. * @param {Array} [argPos] The argument positions of the new function.
  8002. * @param {number} [ary] The arity cap of `func`.
  8003. * @param {number} [arity] The arity of `func`.
  8004. * @returns {Function} Returns the new wrapped function.
  8005. */
  8006. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  8007. var isAry = bitmask & WRAP_ARY_FLAG,
  8008. isBind = bitmask & WRAP_BIND_FLAG,
  8009. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  8010. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  8011. isFlip = bitmask & WRAP_FLIP_FLAG,
  8012. Ctor = isBindKey ? undefined : createCtor(func);
  8013. function wrapper() {
  8014. var length = arguments.length,
  8015. args = Array(length),
  8016. index = length;
  8017. while (index--) {
  8018. args[index] = arguments[index];
  8019. }
  8020. if (isCurried) {
  8021. var placeholder = getHolder(wrapper),
  8022. holdersCount = countHolders(args, placeholder);
  8023. }
  8024. if (partials) {
  8025. args = composeArgs(args, partials, holders, isCurried);
  8026. }
  8027. if (partialsRight) {
  8028. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  8029. }
  8030. length -= holdersCount;
  8031. if (isCurried && length < arity) {
  8032. var newHolders = replaceHolders(args, placeholder);
  8033. return createRecurry(
  8034. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  8035. args, newHolders, argPos, ary, arity - length
  8036. );
  8037. }
  8038. var thisBinding = isBind ? thisArg : this,
  8039. fn = isBindKey ? thisBinding[func] : func;
  8040. length = args.length;
  8041. if (argPos) {
  8042. args = reorder(args, argPos);
  8043. } else if (isFlip && length > 1) {
  8044. args.reverse();
  8045. }
  8046. if (isAry && ary < length) {
  8047. args.length = ary;
  8048. }
  8049. if (this && this !== root && this instanceof wrapper) {
  8050. fn = Ctor || createCtor(fn);
  8051. }
  8052. return fn.apply(thisBinding, args);
  8053. }
  8054. return wrapper;
  8055. }
  8056. /**
  8057. * Creates a function like `_.invertBy`.
  8058. *
  8059. * @private
  8060. * @param {Function} setter The function to set accumulator values.
  8061. * @param {Function} toIteratee The function to resolve iteratees.
  8062. * @returns {Function} Returns the new inverter function.
  8063. */
  8064. function createInverter(setter, toIteratee) {
  8065. return function(object, iteratee) {
  8066. return baseInverter(object, setter, toIteratee(iteratee), {});
  8067. };
  8068. }
  8069. /**
  8070. * Creates a function that performs a mathematical operation on two values.
  8071. *
  8072. * @private
  8073. * @param {Function} operator The function to perform the operation.
  8074. * @param {number} [defaultValue] The value used for `undefined` arguments.
  8075. * @returns {Function} Returns the new mathematical operation function.
  8076. */
  8077. function createMathOperation(operator, defaultValue) {
  8078. return function(value, other) {
  8079. var result;
  8080. if (value === undefined && other === undefined) {
  8081. return defaultValue;
  8082. }
  8083. if (value !== undefined) {
  8084. result = value;
  8085. }
  8086. if (other !== undefined) {
  8087. if (result === undefined) {
  8088. return other;
  8089. }
  8090. if (typeof value == 'string' || typeof other == 'string') {
  8091. value = baseToString(value);
  8092. other = baseToString(other);
  8093. } else {
  8094. value = baseToNumber(value);
  8095. other = baseToNumber(other);
  8096. }
  8097. result = operator(value, other);
  8098. }
  8099. return result;
  8100. };
  8101. }
  8102. /**
  8103. * Creates a function like `_.over`.
  8104. *
  8105. * @private
  8106. * @param {Function} arrayFunc The function to iterate over iteratees.
  8107. * @returns {Function} Returns the new over function.
  8108. */
  8109. function createOver(arrayFunc) {
  8110. return flatRest(function(iteratees) {
  8111. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  8112. return baseRest(function(args) {
  8113. var thisArg = this;
  8114. return arrayFunc(iteratees, function(iteratee) {
  8115. return apply(iteratee, thisArg, args);
  8116. });
  8117. });
  8118. });
  8119. }
  8120. /**
  8121. * Creates the padding for `string` based on `length`. The `chars` string
  8122. * is truncated if the number of characters exceeds `length`.
  8123. *
  8124. * @private
  8125. * @param {number} length The padding length.
  8126. * @param {string} [chars=' '] The string used as padding.
  8127. * @returns {string} Returns the padding for `string`.
  8128. */
  8129. function createPadding(length, chars) {
  8130. chars = chars === undefined ? ' ' : baseToString(chars);
  8131. var charsLength = chars.length;
  8132. if (charsLength < 2) {
  8133. return charsLength ? baseRepeat(chars, length) : chars;
  8134. }
  8135. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  8136. return hasUnicode(chars)
  8137. ? castSlice(stringToArray(result), 0, length).join('')
  8138. : result.slice(0, length);
  8139. }
  8140. /**
  8141. * Creates a function that wraps `func` to invoke it with the `this` binding
  8142. * of `thisArg` and `partials` prepended to the arguments it receives.
  8143. *
  8144. * @private
  8145. * @param {Function} func The function to wrap.
  8146. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  8147. * @param {*} thisArg The `this` binding of `func`.
  8148. * @param {Array} partials The arguments to prepend to those provided to
  8149. * the new function.
  8150. * @returns {Function} Returns the new wrapped function.
  8151. */
  8152. function createPartial(func, bitmask, thisArg, partials) {
  8153. var isBind = bitmask & WRAP_BIND_FLAG,
  8154. Ctor = createCtor(func);
  8155. function wrapper() {
  8156. var argsIndex = -1,
  8157. argsLength = arguments.length,
  8158. leftIndex = -1,
  8159. leftLength = partials.length,
  8160. args = Array(leftLength + argsLength),
  8161. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  8162. while (++leftIndex < leftLength) {
  8163. args[leftIndex] = partials[leftIndex];
  8164. }
  8165. while (argsLength--) {
  8166. args[leftIndex++] = arguments[++argsIndex];
  8167. }
  8168. return apply(fn, isBind ? thisArg : this, args);
  8169. }
  8170. return wrapper;
  8171. }
  8172. /**
  8173. * Creates a `_.range` or `_.rangeRight` function.
  8174. *
  8175. * @private
  8176. * @param {boolean} [fromRight] Specify iterating from right to left.
  8177. * @returns {Function} Returns the new range function.
  8178. */
  8179. function createRange(fromRight) {
  8180. return function(start, end, step) {
  8181. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  8182. end = step = undefined;
  8183. }
  8184. // Ensure the sign of `-0` is preserved.
  8185. start = toFinite(start);
  8186. if (end === undefined) {
  8187. end = start;
  8188. start = 0;
  8189. } else {
  8190. end = toFinite(end);
  8191. }
  8192. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  8193. return baseRange(start, end, step, fromRight);
  8194. };
  8195. }
  8196. /**
  8197. * Creates a function that performs a relational operation on two values.
  8198. *
  8199. * @private
  8200. * @param {Function} operator The function to perform the operation.
  8201. * @returns {Function} Returns the new relational operation function.
  8202. */
  8203. function createRelationalOperation(operator) {
  8204. return function(value, other) {
  8205. if (!(typeof value == 'string' && typeof other == 'string')) {
  8206. value = toNumber(value);
  8207. other = toNumber(other);
  8208. }
  8209. return operator(value, other);
  8210. };
  8211. }
  8212. /**
  8213. * Creates a function that wraps `func` to continue currying.
  8214. *
  8215. * @private
  8216. * @param {Function} func The function to wrap.
  8217. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  8218. * @param {Function} wrapFunc The function to create the `func` wrapper.
  8219. * @param {*} placeholder The placeholder value.
  8220. * @param {*} [thisArg] The `this` binding of `func`.
  8221. * @param {Array} [partials] The arguments to prepend to those provided to
  8222. * the new function.
  8223. * @param {Array} [holders] The `partials` placeholder indexes.
  8224. * @param {Array} [argPos] The argument positions of the new function.
  8225. * @param {number} [ary] The arity cap of `func`.
  8226. * @param {number} [arity] The arity of `func`.
  8227. * @returns {Function} Returns the new wrapped function.
  8228. */
  8229. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  8230. var isCurry = bitmask & WRAP_CURRY_FLAG,
  8231. newHolders = isCurry ? holders : undefined,
  8232. newHoldersRight = isCurry ? undefined : holders,
  8233. newPartials = isCurry ? partials : undefined,
  8234. newPartialsRight = isCurry ? undefined : partials;
  8235. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  8236. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  8237. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  8238. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  8239. }
  8240. var newData = [
  8241. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  8242. newHoldersRight, argPos, ary, arity
  8243. ];
  8244. var result = wrapFunc.apply(undefined, newData);
  8245. if (isLaziable(func)) {
  8246. setData(result, newData);
  8247. }
  8248. result.placeholder = placeholder;
  8249. return setWrapToString(result, func, bitmask);
  8250. }
  8251. /**
  8252. * Creates a function like `_.round`.
  8253. *
  8254. * @private
  8255. * @param {string} methodName The name of the `Math` method to use when rounding.
  8256. * @returns {Function} Returns the new round function.
  8257. */
  8258. function createRound(methodName) {
  8259. var func = Math[methodName];
  8260. return function(number, precision) {
  8261. number = toNumber(number);
  8262. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  8263. if (precision && nativeIsFinite(number)) {
  8264. // Shift with exponential notation to avoid floating-point issues.
  8265. // See [MDN](https://mdn.io/round#Examples) for more details.
  8266. var pair = (toString(number) + 'e').split('e'),
  8267. value = func(pair[0] + 'e' + (+pair[1] + precision));
  8268. pair = (toString(value) + 'e').split('e');
  8269. return +(pair[0] + 'e' + (+pair[1] - precision));
  8270. }
  8271. return func(number);
  8272. };
  8273. }
  8274. /**
  8275. * Creates a set object of `values`.
  8276. *
  8277. * @private
  8278. * @param {Array} values The values to add to the set.
  8279. * @returns {Object} Returns the new set.
  8280. */
  8281. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  8282. return new Set(values);
  8283. };
  8284. /**
  8285. * Creates a `_.toPairs` or `_.toPairsIn` function.
  8286. *
  8287. * @private
  8288. * @param {Function} keysFunc The function to get the keys of a given object.
  8289. * @returns {Function} Returns the new pairs function.
  8290. */
  8291. function createToPairs(keysFunc) {
  8292. return function(object) {
  8293. var tag = getTag(object);
  8294. if (tag == mapTag) {
  8295. return mapToArray(object);
  8296. }
  8297. if (tag == setTag) {
  8298. return setToPairs(object);
  8299. }
  8300. return baseToPairs(object, keysFunc(object));
  8301. };
  8302. }
  8303. /**
  8304. * Creates a function that either curries or invokes `func` with optional
  8305. * `this` binding and partially applied arguments.
  8306. *
  8307. * @private
  8308. * @param {Function|string} func The function or method name to wrap.
  8309. * @param {number} bitmask The bitmask flags.
  8310. * 1 - `_.bind`
  8311. * 2 - `_.bindKey`
  8312. * 4 - `_.curry` or `_.curryRight` of a bound function
  8313. * 8 - `_.curry`
  8314. * 16 - `_.curryRight`
  8315. * 32 - `_.partial`
  8316. * 64 - `_.partialRight`
  8317. * 128 - `_.rearg`
  8318. * 256 - `_.ary`
  8319. * 512 - `_.flip`
  8320. * @param {*} [thisArg] The `this` binding of `func`.
  8321. * @param {Array} [partials] The arguments to be partially applied.
  8322. * @param {Array} [holders] The `partials` placeholder indexes.
  8323. * @param {Array} [argPos] The argument positions of the new function.
  8324. * @param {number} [ary] The arity cap of `func`.
  8325. * @param {number} [arity] The arity of `func`.
  8326. * @returns {Function} Returns the new wrapped function.
  8327. */
  8328. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  8329. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  8330. if (!isBindKey && typeof func != 'function') {
  8331. throw new TypeError(FUNC_ERROR_TEXT);
  8332. }
  8333. var length = partials ? partials.length : 0;
  8334. if (!length) {
  8335. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  8336. partials = holders = undefined;
  8337. }
  8338. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  8339. arity = arity === undefined ? arity : toInteger(arity);
  8340. length -= holders ? holders.length : 0;
  8341. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  8342. var partialsRight = partials,
  8343. holdersRight = holders;
  8344. partials = holders = undefined;
  8345. }
  8346. var data = isBindKey ? undefined : getData(func);
  8347. var newData = [
  8348. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  8349. argPos, ary, arity
  8350. ];
  8351. if (data) {
  8352. mergeData(newData, data);
  8353. }
  8354. func = newData[0];
  8355. bitmask = newData[1];
  8356. thisArg = newData[2];
  8357. partials = newData[3];
  8358. holders = newData[4];
  8359. arity = newData[9] = newData[9] === undefined
  8360. ? (isBindKey ? 0 : func.length)
  8361. : nativeMax(newData[9] - length, 0);
  8362. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  8363. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  8364. }
  8365. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  8366. var result = createBind(func, bitmask, thisArg);
  8367. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  8368. result = createCurry(func, bitmask, arity);
  8369. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  8370. result = createPartial(func, bitmask, thisArg, partials);
  8371. } else {
  8372. result = createHybrid.apply(undefined, newData);
  8373. }
  8374. var setter = data ? baseSetData : setData;
  8375. return setWrapToString(setter(result, newData), func, bitmask);
  8376. }
  8377. /**
  8378. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  8379. * of source objects to the destination object for all destination properties
  8380. * that resolve to `undefined`.
  8381. *
  8382. * @private
  8383. * @param {*} objValue The destination value.
  8384. * @param {*} srcValue The source value.
  8385. * @param {string} key The key of the property to assign.
  8386. * @param {Object} object The parent object of `objValue`.
  8387. * @returns {*} Returns the value to assign.
  8388. */
  8389. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  8390. if (objValue === undefined ||
  8391. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  8392. return srcValue;
  8393. }
  8394. return objValue;
  8395. }
  8396. /**
  8397. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  8398. * objects into destination objects that are passed thru.
  8399. *
  8400. * @private
  8401. * @param {*} objValue The destination value.
  8402. * @param {*} srcValue The source value.
  8403. * @param {string} key The key of the property to merge.
  8404. * @param {Object} object The parent object of `objValue`.
  8405. * @param {Object} source The parent object of `srcValue`.
  8406. * @param {Object} [stack] Tracks traversed source values and their merged
  8407. * counterparts.
  8408. * @returns {*} Returns the value to assign.
  8409. */
  8410. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  8411. if (isObject(objValue) && isObject(srcValue)) {
  8412. // Recursively merge objects and arrays (susceptible to call stack limits).
  8413. stack.set(srcValue, objValue);
  8414. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  8415. stack['delete'](srcValue);
  8416. }
  8417. return objValue;
  8418. }
  8419. /**
  8420. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  8421. * objects.
  8422. *
  8423. * @private
  8424. * @param {*} value The value to inspect.
  8425. * @param {string} key The key of the property to inspect.
  8426. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  8427. */
  8428. function customOmitClone(value) {
  8429. return isPlainObject(value) ? undefined : value;
  8430. }
  8431. /**
  8432. * A specialized version of `baseIsEqualDeep` for arrays with support for
  8433. * partial deep comparisons.
  8434. *
  8435. * @private
  8436. * @param {Array} array The array to compare.
  8437. * @param {Array} other The other array to compare.
  8438. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  8439. * @param {Function} customizer The function to customize comparisons.
  8440. * @param {Function} equalFunc The function to determine equivalents of values.
  8441. * @param {Object} stack Tracks traversed `array` and `other` objects.
  8442. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  8443. */
  8444. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  8445. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  8446. arrLength = array.length,
  8447. othLength = other.length;
  8448. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  8449. return false;
  8450. }
  8451. // Check that cyclic values are equal.
  8452. var arrStacked = stack.get(array);
  8453. var othStacked = stack.get(other);
  8454. if (arrStacked && othStacked) {
  8455. return arrStacked == other && othStacked == array;
  8456. }
  8457. var index = -1,
  8458. result = true,
  8459. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  8460. stack.set(array, other);
  8461. stack.set(other, array);
  8462. // Ignore non-index properties.
  8463. while (++index < arrLength) {
  8464. var arrValue = array[index],
  8465. othValue = other[index];
  8466. if (customizer) {
  8467. var compared = isPartial
  8468. ? customizer(othValue, arrValue, index, other, array, stack)
  8469. : customizer(arrValue, othValue, index, array, other, stack);
  8470. }
  8471. if (compared !== undefined) {
  8472. if (compared) {
  8473. continue;
  8474. }
  8475. result = false;
  8476. break;
  8477. }
  8478. // Recursively compare arrays (susceptible to call stack limits).
  8479. if (seen) {
  8480. if (!arraySome(other, function(othValue, othIndex) {
  8481. if (!cacheHas(seen, othIndex) &&
  8482. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  8483. return seen.push(othIndex);
  8484. }
  8485. })) {
  8486. result = false;
  8487. break;
  8488. }
  8489. } else if (!(
  8490. arrValue === othValue ||
  8491. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  8492. )) {
  8493. result = false;
  8494. break;
  8495. }
  8496. }
  8497. stack['delete'](array);
  8498. stack['delete'](other);
  8499. return result;
  8500. }
  8501. /**
  8502. * A specialized version of `baseIsEqualDeep` for comparing objects of
  8503. * the same `toStringTag`.
  8504. *
  8505. * **Note:** This function only supports comparing values with tags of
  8506. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  8507. *
  8508. * @private
  8509. * @param {Object} object The object to compare.
  8510. * @param {Object} other The other object to compare.
  8511. * @param {string} tag The `toStringTag` of the objects to compare.
  8512. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  8513. * @param {Function} customizer The function to customize comparisons.
  8514. * @param {Function} equalFunc The function to determine equivalents of values.
  8515. * @param {Object} stack Tracks traversed `object` and `other` objects.
  8516. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  8517. */
  8518. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  8519. switch (tag) {
  8520. case dataViewTag:
  8521. if ((object.byteLength != other.byteLength) ||
  8522. (object.byteOffset != other.byteOffset)) {
  8523. return false;
  8524. }
  8525. object = object.buffer;
  8526. other = other.buffer;
  8527. case arrayBufferTag:
  8528. if ((object.byteLength != other.byteLength) ||
  8529. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  8530. return false;
  8531. }
  8532. return true;
  8533. case boolTag:
  8534. case dateTag:
  8535. case numberTag:
  8536. // Coerce booleans to `1` or `0` and dates to milliseconds.
  8537. // Invalid dates are coerced to `NaN`.
  8538. return eq(+object, +other);
  8539. case errorTag:
  8540. return object.name == other.name && object.message == other.message;
  8541. case regexpTag:
  8542. case stringTag:
  8543. // Coerce regexes to strings and treat strings, primitives and objects,
  8544. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  8545. // for more details.
  8546. return object == (other + '');
  8547. case mapTag:
  8548. var convert = mapToArray;
  8549. case setTag:
  8550. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  8551. convert || (convert = setToArray);
  8552. if (object.size != other.size && !isPartial) {
  8553. return false;
  8554. }
  8555. // Assume cyclic values are equal.
  8556. var stacked = stack.get(object);
  8557. if (stacked) {
  8558. return stacked == other;
  8559. }
  8560. bitmask |= COMPARE_UNORDERED_FLAG;
  8561. // Recursively compare objects (susceptible to call stack limits).
  8562. stack.set(object, other);
  8563. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  8564. stack['delete'](object);
  8565. return result;
  8566. case symbolTag:
  8567. if (symbolValueOf) {
  8568. return symbolValueOf.call(object) == symbolValueOf.call(other);
  8569. }
  8570. }
  8571. return false;
  8572. }
  8573. /**
  8574. * A specialized version of `baseIsEqualDeep` for objects with support for
  8575. * partial deep comparisons.
  8576. *
  8577. * @private
  8578. * @param {Object} object The object to compare.
  8579. * @param {Object} other The other object to compare.
  8580. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  8581. * @param {Function} customizer The function to customize comparisons.
  8582. * @param {Function} equalFunc The function to determine equivalents of values.
  8583. * @param {Object} stack Tracks traversed `object` and `other` objects.
  8584. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  8585. */
  8586. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  8587. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  8588. objProps = getAllKeys(object),
  8589. objLength = objProps.length,
  8590. othProps = getAllKeys(other),
  8591. othLength = othProps.length;
  8592. if (objLength != othLength && !isPartial) {
  8593. return false;
  8594. }
  8595. var index = objLength;
  8596. while (index--) {
  8597. var key = objProps[index];
  8598. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  8599. return false;
  8600. }
  8601. }
  8602. // Check that cyclic values are equal.
  8603. var objStacked = stack.get(object);
  8604. var othStacked = stack.get(other);
  8605. if (objStacked && othStacked) {
  8606. return objStacked == other && othStacked == object;
  8607. }
  8608. var result = true;
  8609. stack.set(object, other);
  8610. stack.set(other, object);
  8611. var skipCtor = isPartial;
  8612. while (++index < objLength) {
  8613. key = objProps[index];
  8614. var objValue = object[key],
  8615. othValue = other[key];
  8616. if (customizer) {
  8617. var compared = isPartial
  8618. ? customizer(othValue, objValue, key, other, object, stack)
  8619. : customizer(objValue, othValue, key, object, other, stack);
  8620. }
  8621. // Recursively compare objects (susceptible to call stack limits).
  8622. if (!(compared === undefined
  8623. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  8624. : compared
  8625. )) {
  8626. result = false;
  8627. break;
  8628. }
  8629. skipCtor || (skipCtor = key == 'constructor');
  8630. }
  8631. if (result && !skipCtor) {
  8632. var objCtor = object.constructor,
  8633. othCtor = other.constructor;
  8634. // Non `Object` object instances with different constructors are not equal.
  8635. if (objCtor != othCtor &&
  8636. ('constructor' in object && 'constructor' in other) &&
  8637. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  8638. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  8639. result = false;
  8640. }
  8641. }
  8642. stack['delete'](object);
  8643. stack['delete'](other);
  8644. return result;
  8645. }
  8646. /**
  8647. * A specialized version of `baseRest` which flattens the rest array.
  8648. *
  8649. * @private
  8650. * @param {Function} func The function to apply a rest parameter to.
  8651. * @returns {Function} Returns the new function.
  8652. */
  8653. function flatRest(func) {
  8654. return setToString(overRest(func, undefined, flatten), func + '');
  8655. }
  8656. /**
  8657. * Creates an array of own enumerable property names and symbols of `object`.
  8658. *
  8659. * @private
  8660. * @param {Object} object The object to query.
  8661. * @returns {Array} Returns the array of property names and symbols.
  8662. */
  8663. function getAllKeys(object) {
  8664. return baseGetAllKeys(object, keys, getSymbols);
  8665. }
  8666. /**
  8667. * Creates an array of own and inherited enumerable property names and
  8668. * symbols of `object`.
  8669. *
  8670. * @private
  8671. * @param {Object} object The object to query.
  8672. * @returns {Array} Returns the array of property names and symbols.
  8673. */
  8674. function getAllKeysIn(object) {
  8675. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  8676. }
  8677. /**
  8678. * Gets metadata for `func`.
  8679. *
  8680. * @private
  8681. * @param {Function} func The function to query.
  8682. * @returns {*} Returns the metadata for `func`.
  8683. */
  8684. var getData = !metaMap ? noop : function(func) {
  8685. return metaMap.get(func);
  8686. };
  8687. /**
  8688. * Gets the name of `func`.
  8689. *
  8690. * @private
  8691. * @param {Function} func The function to query.
  8692. * @returns {string} Returns the function name.
  8693. */
  8694. function getFuncName(func) {
  8695. var result = (func.name + ''),
  8696. array = realNames[result],
  8697. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  8698. while (length--) {
  8699. var data = array[length],
  8700. otherFunc = data.func;
  8701. if (otherFunc == null || otherFunc == func) {
  8702. return data.name;
  8703. }
  8704. }
  8705. return result;
  8706. }
  8707. /**
  8708. * Gets the argument placeholder value for `func`.
  8709. *
  8710. * @private
  8711. * @param {Function} func The function to inspect.
  8712. * @returns {*} Returns the placeholder value.
  8713. */
  8714. function getHolder(func) {
  8715. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  8716. return object.placeholder;
  8717. }
  8718. /**
  8719. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  8720. * this function returns the custom method, otherwise it returns `baseIteratee`.
  8721. * If arguments are provided, the chosen function is invoked with them and
  8722. * its result is returned.
  8723. *
  8724. * @private
  8725. * @param {*} [value] The value to convert to an iteratee.
  8726. * @param {number} [arity] The arity of the created iteratee.
  8727. * @returns {Function} Returns the chosen function or its result.
  8728. */
  8729. function getIteratee() {
  8730. var result = lodash.iteratee || iteratee;
  8731. result = result === iteratee ? baseIteratee : result;
  8732. return arguments.length ? result(arguments[0], arguments[1]) : result;
  8733. }
  8734. /**
  8735. * Gets the data for `map`.
  8736. *
  8737. * @private
  8738. * @param {Object} map The map to query.
  8739. * @param {string} key The reference key.
  8740. * @returns {*} Returns the map data.
  8741. */
  8742. function getMapData(map, key) {
  8743. var data = map.__data__;
  8744. return isKeyable(key)
  8745. ? data[typeof key == 'string' ? 'string' : 'hash']
  8746. : data.map;
  8747. }
  8748. /**
  8749. * Gets the property names, values, and compare flags of `object`.
  8750. *
  8751. * @private
  8752. * @param {Object} object The object to query.
  8753. * @returns {Array} Returns the match data of `object`.
  8754. */
  8755. function getMatchData(object) {
  8756. var result = keys(object),
  8757. length = result.length;
  8758. while (length--) {
  8759. var key = result[length],
  8760. value = object[key];
  8761. result[length] = [key, value, isStrictComparable(value)];
  8762. }
  8763. return result;
  8764. }
  8765. /**
  8766. * Gets the native function at `key` of `object`.
  8767. *
  8768. * @private
  8769. * @param {Object} object The object to query.
  8770. * @param {string} key The key of the method to get.
  8771. * @returns {*} Returns the function if it's native, else `undefined`.
  8772. */
  8773. function getNative(object, key) {
  8774. var value = getValue(object, key);
  8775. return baseIsNative(value) ? value : undefined;
  8776. }
  8777. /**
  8778. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  8779. *
  8780. * @private
  8781. * @param {*} value The value to query.
  8782. * @returns {string} Returns the raw `toStringTag`.
  8783. */
  8784. function getRawTag(value) {
  8785. var isOwn = hasOwnProperty.call(value, symToStringTag),
  8786. tag = value[symToStringTag];
  8787. try {
  8788. value[symToStringTag] = undefined;
  8789. var unmasked = true;
  8790. } catch (e) {}
  8791. var result = nativeObjectToString.call(value);
  8792. if (unmasked) {
  8793. if (isOwn) {
  8794. value[symToStringTag] = tag;
  8795. } else {
  8796. delete value[symToStringTag];
  8797. }
  8798. }
  8799. return result;
  8800. }
  8801. /**
  8802. * Creates an array of the own enumerable symbols of `object`.
  8803. *
  8804. * @private
  8805. * @param {Object} object The object to query.
  8806. * @returns {Array} Returns the array of symbols.
  8807. */
  8808. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  8809. if (object == null) {
  8810. return [];
  8811. }
  8812. object = Object(object);
  8813. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  8814. return propertyIsEnumerable.call(object, symbol);
  8815. });
  8816. };
  8817. /**
  8818. * Creates an array of the own and inherited enumerable symbols of `object`.
  8819. *
  8820. * @private
  8821. * @param {Object} object The object to query.
  8822. * @returns {Array} Returns the array of symbols.
  8823. */
  8824. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  8825. var result = [];
  8826. while (object) {
  8827. arrayPush(result, getSymbols(object));
  8828. object = getPrototype(object);
  8829. }
  8830. return result;
  8831. };
  8832. /**
  8833. * Gets the `toStringTag` of `value`.
  8834. *
  8835. * @private
  8836. * @param {*} value The value to query.
  8837. * @returns {string} Returns the `toStringTag`.
  8838. */
  8839. var getTag = baseGetTag;
  8840. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  8841. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  8842. (Map && getTag(new Map) != mapTag) ||
  8843. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  8844. (Set && getTag(new Set) != setTag) ||
  8845. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  8846. getTag = function(value) {
  8847. var result = baseGetTag(value),
  8848. Ctor = result == objectTag ? value.constructor : undefined,
  8849. ctorString = Ctor ? toSource(Ctor) : '';
  8850. if (ctorString) {
  8851. switch (ctorString) {
  8852. case dataViewCtorString: return dataViewTag;
  8853. case mapCtorString: return mapTag;
  8854. case promiseCtorString: return promiseTag;
  8855. case setCtorString: return setTag;
  8856. case weakMapCtorString: return weakMapTag;
  8857. }
  8858. }
  8859. return result;
  8860. };
  8861. }
  8862. /**
  8863. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  8864. *
  8865. * @private
  8866. * @param {number} start The start of the view.
  8867. * @param {number} end The end of the view.
  8868. * @param {Array} transforms The transformations to apply to the view.
  8869. * @returns {Object} Returns an object containing the `start` and `end`
  8870. * positions of the view.
  8871. */
  8872. function getView(start, end, transforms) {
  8873. var index = -1,
  8874. length = transforms.length;
  8875. while (++index < length) {
  8876. var data = transforms[index],
  8877. size = data.size;
  8878. switch (data.type) {
  8879. case 'drop': start += size; break;
  8880. case 'dropRight': end -= size; break;
  8881. case 'take': end = nativeMin(end, start + size); break;
  8882. case 'takeRight': start = nativeMax(start, end - size); break;
  8883. }
  8884. }
  8885. return { 'start': start, 'end': end };
  8886. }
  8887. /**
  8888. * Extracts wrapper details from the `source` body comment.
  8889. *
  8890. * @private
  8891. * @param {string} source The source to inspect.
  8892. * @returns {Array} Returns the wrapper details.
  8893. */
  8894. function getWrapDetails(source) {
  8895. var match = source.match(reWrapDetails);
  8896. return match ? match[1].split(reSplitDetails) : [];
  8897. }
  8898. /**
  8899. * Checks if `path` exists on `object`.
  8900. *
  8901. * @private
  8902. * @param {Object} object The object to query.
  8903. * @param {Array|string} path The path to check.
  8904. * @param {Function} hasFunc The function to check properties.
  8905. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  8906. */
  8907. function hasPath(object, path, hasFunc) {
  8908. path = castPath(path, object);
  8909. var index = -1,
  8910. length = path.length,
  8911. result = false;
  8912. while (++index < length) {
  8913. var key = toKey(path[index]);
  8914. if (!(result = object != null && hasFunc(object, key))) {
  8915. break;
  8916. }
  8917. object = object[key];
  8918. }
  8919. if (result || ++index != length) {
  8920. return result;
  8921. }
  8922. length = object == null ? 0 : object.length;
  8923. return !!length && isLength(length) && isIndex(key, length) &&
  8924. (isArray(object) || isArguments(object));
  8925. }
  8926. /**
  8927. * Initializes an array clone.
  8928. *
  8929. * @private
  8930. * @param {Array} array The array to clone.
  8931. * @returns {Array} Returns the initialized clone.
  8932. */
  8933. function initCloneArray(array) {
  8934. var length = array.length,
  8935. result = new array.constructor(length);
  8936. // Add properties assigned by `RegExp#exec`.
  8937. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  8938. result.index = array.index;
  8939. result.input = array.input;
  8940. }
  8941. return result;
  8942. }
  8943. /**
  8944. * Initializes an object clone.
  8945. *
  8946. * @private
  8947. * @param {Object} object The object to clone.
  8948. * @returns {Object} Returns the initialized clone.
  8949. */
  8950. function initCloneObject(object) {
  8951. return (typeof object.constructor == 'function' && !isPrototype(object))
  8952. ? baseCreate(getPrototype(object))
  8953. : {};
  8954. }
  8955. /**
  8956. * Initializes an object clone based on its `toStringTag`.
  8957. *
  8958. * **Note:** This function only supports cloning values with tags of
  8959. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  8960. *
  8961. * @private
  8962. * @param {Object} object The object to clone.
  8963. * @param {string} tag The `toStringTag` of the object to clone.
  8964. * @param {boolean} [isDeep] Specify a deep clone.
  8965. * @returns {Object} Returns the initialized clone.
  8966. */
  8967. function initCloneByTag(object, tag, isDeep) {
  8968. var Ctor = object.constructor;
  8969. switch (tag) {
  8970. case arrayBufferTag:
  8971. return cloneArrayBuffer(object);
  8972. case boolTag:
  8973. case dateTag:
  8974. return new Ctor(+object);
  8975. case dataViewTag:
  8976. return cloneDataView(object, isDeep);
  8977. case float32Tag: case float64Tag:
  8978. case int8Tag: case int16Tag: case int32Tag:
  8979. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  8980. return cloneTypedArray(object, isDeep);
  8981. case mapTag:
  8982. return new Ctor;
  8983. case numberTag:
  8984. case stringTag:
  8985. return new Ctor(object);
  8986. case regexpTag:
  8987. return cloneRegExp(object);
  8988. case setTag:
  8989. return new Ctor;
  8990. case symbolTag:
  8991. return cloneSymbol(object);
  8992. }
  8993. }
  8994. /**
  8995. * Inserts wrapper `details` in a comment at the top of the `source` body.
  8996. *
  8997. * @private
  8998. * @param {string} source The source to modify.
  8999. * @returns {Array} details The details to insert.
  9000. * @returns {string} Returns the modified source.
  9001. */
  9002. function insertWrapDetails(source, details) {
  9003. var length = details.length;
  9004. if (!length) {
  9005. return source;
  9006. }
  9007. var lastIndex = length - 1;
  9008. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  9009. details = details.join(length > 2 ? ', ' : ' ');
  9010. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  9011. }
  9012. /**
  9013. * Checks if `value` is a flattenable `arguments` object or array.
  9014. *
  9015. * @private
  9016. * @param {*} value The value to check.
  9017. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  9018. */
  9019. function isFlattenable(value) {
  9020. return isArray(value) || isArguments(value) ||
  9021. !!(spreadableSymbol && value && value[spreadableSymbol]);
  9022. }
  9023. /**
  9024. * Checks if `value` is a valid array-like index.
  9025. *
  9026. * @private
  9027. * @param {*} value The value to check.
  9028. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  9029. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  9030. */
  9031. function isIndex(value, length) {
  9032. var type = typeof value;
  9033. length = length == null ? MAX_SAFE_INTEGER : length;
  9034. return !!length &&
  9035. (type == 'number' ||
  9036. (type != 'symbol' && reIsUint.test(value))) &&
  9037. (value > -1 && value % 1 == 0 && value < length);
  9038. }
  9039. /**
  9040. * Checks if the given arguments are from an iteratee call.
  9041. *
  9042. * @private
  9043. * @param {*} value The potential iteratee value argument.
  9044. * @param {*} index The potential iteratee index or key argument.
  9045. * @param {*} object The potential iteratee object argument.
  9046. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  9047. * else `false`.
  9048. */
  9049. function isIterateeCall(value, index, object) {
  9050. if (!isObject(object)) {
  9051. return false;
  9052. }
  9053. var type = typeof index;
  9054. if (type == 'number'
  9055. ? (isArrayLike(object) && isIndex(index, object.length))
  9056. : (type == 'string' && index in object)
  9057. ) {
  9058. return eq(object[index], value);
  9059. }
  9060. return false;
  9061. }
  9062. /**
  9063. * Checks if `value` is a property name and not a property path.
  9064. *
  9065. * @private
  9066. * @param {*} value The value to check.
  9067. * @param {Object} [object] The object to query keys on.
  9068. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  9069. */
  9070. function isKey(value, object) {
  9071. if (isArray(value)) {
  9072. return false;
  9073. }
  9074. var type = typeof value;
  9075. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  9076. value == null || isSymbol(value)) {
  9077. return true;
  9078. }
  9079. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  9080. (object != null && value in Object(object));
  9081. }
  9082. /**
  9083. * Checks if `value` is suitable for use as unique object key.
  9084. *
  9085. * @private
  9086. * @param {*} value The value to check.
  9087. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  9088. */
  9089. function isKeyable(value) {
  9090. var type = typeof value;
  9091. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  9092. ? (value !== '__proto__')
  9093. : (value === null);
  9094. }
  9095. /**
  9096. * Checks if `func` has a lazy counterpart.
  9097. *
  9098. * @private
  9099. * @param {Function} func The function to check.
  9100. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  9101. * else `false`.
  9102. */
  9103. function isLaziable(func) {
  9104. var funcName = getFuncName(func),
  9105. other = lodash[funcName];
  9106. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  9107. return false;
  9108. }
  9109. if (func === other) {
  9110. return true;
  9111. }
  9112. var data = getData(other);
  9113. return !!data && func === data[0];
  9114. }
  9115. /**
  9116. * Checks if `func` has its source masked.
  9117. *
  9118. * @private
  9119. * @param {Function} func The function to check.
  9120. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  9121. */
  9122. function isMasked(func) {
  9123. return !!maskSrcKey && (maskSrcKey in func);
  9124. }
  9125. /**
  9126. * Checks if `func` is capable of being masked.
  9127. *
  9128. * @private
  9129. * @param {*} value The value to check.
  9130. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  9131. */
  9132. var isMaskable = coreJsData ? isFunction : stubFalse;
  9133. /**
  9134. * Checks if `value` is likely a prototype object.
  9135. *
  9136. * @private
  9137. * @param {*} value The value to check.
  9138. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  9139. */
  9140. function isPrototype(value) {
  9141. var Ctor = value && value.constructor,
  9142. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  9143. return value === proto;
  9144. }
  9145. /**
  9146. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  9147. *
  9148. * @private
  9149. * @param {*} value The value to check.
  9150. * @returns {boolean} Returns `true` if `value` if suitable for strict
  9151. * equality comparisons, else `false`.
  9152. */
  9153. function isStrictComparable(value) {
  9154. return value === value && !isObject(value);
  9155. }
  9156. /**
  9157. * A specialized version of `matchesProperty` for source values suitable
  9158. * for strict equality comparisons, i.e. `===`.
  9159. *
  9160. * @private
  9161. * @param {string} key The key of the property to get.
  9162. * @param {*} srcValue The value to match.
  9163. * @returns {Function} Returns the new spec function.
  9164. */
  9165. function matchesStrictComparable(key, srcValue) {
  9166. return function(object) {
  9167. if (object == null) {
  9168. return false;
  9169. }
  9170. return object[key] === srcValue &&
  9171. (srcValue !== undefined || (key in Object(object)));
  9172. };
  9173. }
  9174. /**
  9175. * A specialized version of `_.memoize` which clears the memoized function's
  9176. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  9177. *
  9178. * @private
  9179. * @param {Function} func The function to have its output memoized.
  9180. * @returns {Function} Returns the new memoized function.
  9181. */
  9182. function memoizeCapped(func) {
  9183. var result = memoize(func, function(key) {
  9184. if (cache.size === MAX_MEMOIZE_SIZE) {
  9185. cache.clear();
  9186. }
  9187. return key;
  9188. });
  9189. var cache = result.cache;
  9190. return result;
  9191. }
  9192. /**
  9193. * Merges the function metadata of `source` into `data`.
  9194. *
  9195. * Merging metadata reduces the number of wrappers used to invoke a function.
  9196. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  9197. * may be applied regardless of execution order. Methods like `_.ary` and
  9198. * `_.rearg` modify function arguments, making the order in which they are
  9199. * executed important, preventing the merging of metadata. However, we make
  9200. * an exception for a safe combined case where curried functions have `_.ary`
  9201. * and or `_.rearg` applied.
  9202. *
  9203. * @private
  9204. * @param {Array} data The destination metadata.
  9205. * @param {Array} source The source metadata.
  9206. * @returns {Array} Returns `data`.
  9207. */
  9208. function mergeData(data, source) {
  9209. var bitmask = data[1],
  9210. srcBitmask = source[1],
  9211. newBitmask = bitmask | srcBitmask,
  9212. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  9213. var isCombo =
  9214. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  9215. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  9216. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  9217. // Exit early if metadata can't be merged.
  9218. if (!(isCommon || isCombo)) {
  9219. return data;
  9220. }
  9221. // Use source `thisArg` if available.
  9222. if (srcBitmask & WRAP_BIND_FLAG) {
  9223. data[2] = source[2];
  9224. // Set when currying a bound function.
  9225. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  9226. }
  9227. // Compose partial arguments.
  9228. var value = source[3];
  9229. if (value) {
  9230. var partials = data[3];
  9231. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  9232. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  9233. }
  9234. // Compose partial right arguments.
  9235. value = source[5];
  9236. if (value) {
  9237. partials = data[5];
  9238. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  9239. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  9240. }
  9241. // Use source `argPos` if available.
  9242. value = source[7];
  9243. if (value) {
  9244. data[7] = value;
  9245. }
  9246. // Use source `ary` if it's smaller.
  9247. if (srcBitmask & WRAP_ARY_FLAG) {
  9248. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  9249. }
  9250. // Use source `arity` if one is not provided.
  9251. if (data[9] == null) {
  9252. data[9] = source[9];
  9253. }
  9254. // Use source `func` and merge bitmasks.
  9255. data[0] = source[0];
  9256. data[1] = newBitmask;
  9257. return data;
  9258. }
  9259. /**
  9260. * This function is like
  9261. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  9262. * except that it includes inherited enumerable properties.
  9263. *
  9264. * @private
  9265. * @param {Object} object The object to query.
  9266. * @returns {Array} Returns the array of property names.
  9267. */
  9268. function nativeKeysIn(object) {
  9269. var result = [];
  9270. if (object != null) {
  9271. for (var key in Object(object)) {
  9272. result.push(key);
  9273. }
  9274. }
  9275. return result;
  9276. }
  9277. /**
  9278. * Converts `value` to a string using `Object.prototype.toString`.
  9279. *
  9280. * @private
  9281. * @param {*} value The value to convert.
  9282. * @returns {string} Returns the converted string.
  9283. */
  9284. function objectToString(value) {
  9285. return nativeObjectToString.call(value);
  9286. }
  9287. /**
  9288. * A specialized version of `baseRest` which transforms the rest array.
  9289. *
  9290. * @private
  9291. * @param {Function} func The function to apply a rest parameter to.
  9292. * @param {number} [start=func.length-1] The start position of the rest parameter.
  9293. * @param {Function} transform The rest array transform.
  9294. * @returns {Function} Returns the new function.
  9295. */
  9296. function overRest(func, start, transform) {
  9297. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  9298. return function() {
  9299. var args = arguments,
  9300. index = -1,
  9301. length = nativeMax(args.length - start, 0),
  9302. array = Array(length);
  9303. while (++index < length) {
  9304. array[index] = args[start + index];
  9305. }
  9306. index = -1;
  9307. var otherArgs = Array(start + 1);
  9308. while (++index < start) {
  9309. otherArgs[index] = args[index];
  9310. }
  9311. otherArgs[start] = transform(array);
  9312. return apply(func, this, otherArgs);
  9313. };
  9314. }
  9315. /**
  9316. * Gets the parent value at `path` of `object`.
  9317. *
  9318. * @private
  9319. * @param {Object} object The object to query.
  9320. * @param {Array} path The path to get the parent value of.
  9321. * @returns {*} Returns the parent value.
  9322. */
  9323. function parent(object, path) {
  9324. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  9325. }
  9326. /**
  9327. * Reorder `array` according to the specified indexes where the element at
  9328. * the first index is assigned as the first element, the element at
  9329. * the second index is assigned as the second element, and so on.
  9330. *
  9331. * @private
  9332. * @param {Array} array The array to reorder.
  9333. * @param {Array} indexes The arranged array indexes.
  9334. * @returns {Array} Returns `array`.
  9335. */
  9336. function reorder(array, indexes) {
  9337. var arrLength = array.length,
  9338. length = nativeMin(indexes.length, arrLength),
  9339. oldArray = copyArray(array);
  9340. while (length--) {
  9341. var index = indexes[length];
  9342. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  9343. }
  9344. return array;
  9345. }
  9346. /**
  9347. * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
  9348. *
  9349. * @private
  9350. * @param {Object} object The object to query.
  9351. * @param {string} key The key of the property to get.
  9352. * @returns {*} Returns the property value.
  9353. */
  9354. function safeGet(object, key) {
  9355. if (key === 'constructor' && typeof object[key] === 'function') {
  9356. return;
  9357. }
  9358. if (key == '__proto__') {
  9359. return;
  9360. }
  9361. return object[key];
  9362. }
  9363. /**
  9364. * Sets metadata for `func`.
  9365. *
  9366. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  9367. * period of time, it will trip its breaker and transition to an identity
  9368. * function to avoid garbage collection pauses in V8. See
  9369. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  9370. * for more details.
  9371. *
  9372. * @private
  9373. * @param {Function} func The function to associate metadata with.
  9374. * @param {*} data The metadata.
  9375. * @returns {Function} Returns `func`.
  9376. */
  9377. var setData = shortOut(baseSetData);
  9378. /**
  9379. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  9380. *
  9381. * @private
  9382. * @param {Function} func The function to delay.
  9383. * @param {number} wait The number of milliseconds to delay invocation.
  9384. * @returns {number|Object} Returns the timer id or timeout object.
  9385. */
  9386. var setTimeout = ctxSetTimeout || function(func, wait) {
  9387. return root.setTimeout(func, wait);
  9388. };
  9389. /**
  9390. * Sets the `toString` method of `func` to return `string`.
  9391. *
  9392. * @private
  9393. * @param {Function} func The function to modify.
  9394. * @param {Function} string The `toString` result.
  9395. * @returns {Function} Returns `func`.
  9396. */
  9397. var setToString = shortOut(baseSetToString);
  9398. /**
  9399. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  9400. * with wrapper details in a comment at the top of the source body.
  9401. *
  9402. * @private
  9403. * @param {Function} wrapper The function to modify.
  9404. * @param {Function} reference The reference function.
  9405. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  9406. * @returns {Function} Returns `wrapper`.
  9407. */
  9408. function setWrapToString(wrapper, reference, bitmask) {
  9409. var source = (reference + '');
  9410. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  9411. }
  9412. /**
  9413. * Creates a function that'll short out and invoke `identity` instead
  9414. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  9415. * milliseconds.
  9416. *
  9417. * @private
  9418. * @param {Function} func The function to restrict.
  9419. * @returns {Function} Returns the new shortable function.
  9420. */
  9421. function shortOut(func) {
  9422. var count = 0,
  9423. lastCalled = 0;
  9424. return function() {
  9425. var stamp = nativeNow(),
  9426. remaining = HOT_SPAN - (stamp - lastCalled);
  9427. lastCalled = stamp;
  9428. if (remaining > 0) {
  9429. if (++count >= HOT_COUNT) {
  9430. return arguments[0];
  9431. }
  9432. } else {
  9433. count = 0;
  9434. }
  9435. return func.apply(undefined, arguments);
  9436. };
  9437. }
  9438. /**
  9439. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  9440. *
  9441. * @private
  9442. * @param {Array} array The array to shuffle.
  9443. * @param {number} [size=array.length] The size of `array`.
  9444. * @returns {Array} Returns `array`.
  9445. */
  9446. function shuffleSelf(array, size) {
  9447. var index = -1,
  9448. length = array.length,
  9449. lastIndex = length - 1;
  9450. size = size === undefined ? length : size;
  9451. while (++index < size) {
  9452. var rand = baseRandom(index, lastIndex),
  9453. value = array[rand];
  9454. array[rand] = array[index];
  9455. array[index] = value;
  9456. }
  9457. array.length = size;
  9458. return array;
  9459. }
  9460. /**
  9461. * Converts `string` to a property path array.
  9462. *
  9463. * @private
  9464. * @param {string} string The string to convert.
  9465. * @returns {Array} Returns the property path array.
  9466. */
  9467. var stringToPath = memoizeCapped(function(string) {
  9468. var result = [];
  9469. if (string.charCodeAt(0) === 46 /* . */) {
  9470. result.push('');
  9471. }
  9472. string.replace(rePropName, function(match, number, quote, subString) {
  9473. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  9474. });
  9475. return result;
  9476. });
  9477. /**
  9478. * Converts `value` to a string key if it's not a string or symbol.
  9479. *
  9480. * @private
  9481. * @param {*} value The value to inspect.
  9482. * @returns {string|symbol} Returns the key.
  9483. */
  9484. function toKey(value) {
  9485. if (typeof value == 'string' || isSymbol(value)) {
  9486. return value;
  9487. }
  9488. var result = (value + '');
  9489. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  9490. }
  9491. /**
  9492. * Converts `func` to its source code.
  9493. *
  9494. * @private
  9495. * @param {Function} func The function to convert.
  9496. * @returns {string} Returns the source code.
  9497. */
  9498. function toSource(func) {
  9499. if (func != null) {
  9500. try {
  9501. return funcToString.call(func);
  9502. } catch (e) {}
  9503. try {
  9504. return (func + '');
  9505. } catch (e) {}
  9506. }
  9507. return '';
  9508. }
  9509. /**
  9510. * Updates wrapper `details` based on `bitmask` flags.
  9511. *
  9512. * @private
  9513. * @returns {Array} details The details to modify.
  9514. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  9515. * @returns {Array} Returns `details`.
  9516. */
  9517. function updateWrapDetails(details, bitmask) {
  9518. arrayEach(wrapFlags, function(pair) {
  9519. var value = '_.' + pair[0];
  9520. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  9521. details.push(value);
  9522. }
  9523. });
  9524. return details.sort();
  9525. }
  9526. /**
  9527. * Creates a clone of `wrapper`.
  9528. *
  9529. * @private
  9530. * @param {Object} wrapper The wrapper to clone.
  9531. * @returns {Object} Returns the cloned wrapper.
  9532. */
  9533. function wrapperClone(wrapper) {
  9534. if (wrapper instanceof LazyWrapper) {
  9535. return wrapper.clone();
  9536. }
  9537. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  9538. result.__actions__ = copyArray(wrapper.__actions__);
  9539. result.__index__ = wrapper.__index__;
  9540. result.__values__ = wrapper.__values__;
  9541. return result;
  9542. }
  9543. /*------------------------------------------------------------------------*/
  9544. /**
  9545. * Creates an array of elements split into groups the length of `size`.
  9546. * If `array` can't be split evenly, the final chunk will be the remaining
  9547. * elements.
  9548. *
  9549. * @static
  9550. * @memberOf _
  9551. * @since 3.0.0
  9552. * @category Array
  9553. * @param {Array} array The array to process.
  9554. * @param {number} [size=1] The length of each chunk
  9555. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9556. * @returns {Array} Returns the new array of chunks.
  9557. * @example
  9558. *
  9559. * _.chunk(['a', 'b', 'c', 'd'], 2);
  9560. * // => [['a', 'b'], ['c', 'd']]
  9561. *
  9562. * _.chunk(['a', 'b', 'c', 'd'], 3);
  9563. * // => [['a', 'b', 'c'], ['d']]
  9564. */
  9565. function chunk(array, size, guard) {
  9566. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  9567. size = 1;
  9568. } else {
  9569. size = nativeMax(toInteger(size), 0);
  9570. }
  9571. var length = array == null ? 0 : array.length;
  9572. if (!length || size < 1) {
  9573. return [];
  9574. }
  9575. var index = 0,
  9576. resIndex = 0,
  9577. result = Array(nativeCeil(length / size));
  9578. while (index < length) {
  9579. result[resIndex++] = baseSlice(array, index, (index += size));
  9580. }
  9581. return result;
  9582. }
  9583. /**
  9584. * Creates an array with all falsey values removed. The values `false`, `null`,
  9585. * `0`, `""`, `undefined`, and `NaN` are falsey.
  9586. *
  9587. * @static
  9588. * @memberOf _
  9589. * @since 0.1.0
  9590. * @category Array
  9591. * @param {Array} array The array to compact.
  9592. * @returns {Array} Returns the new array of filtered values.
  9593. * @example
  9594. *
  9595. * _.compact([0, 1, false, 2, '', 3]);
  9596. * // => [1, 2, 3]
  9597. */
  9598. function compact(array) {
  9599. var index = -1,
  9600. length = array == null ? 0 : array.length,
  9601. resIndex = 0,
  9602. result = [];
  9603. while (++index < length) {
  9604. var value = array[index];
  9605. if (value) {
  9606. result[resIndex++] = value;
  9607. }
  9608. }
  9609. return result;
  9610. }
  9611. /**
  9612. * Creates a new array concatenating `array` with any additional arrays
  9613. * and/or values.
  9614. *
  9615. * @static
  9616. * @memberOf _
  9617. * @since 4.0.0
  9618. * @category Array
  9619. * @param {Array} array The array to concatenate.
  9620. * @param {...*} [values] The values to concatenate.
  9621. * @returns {Array} Returns the new concatenated array.
  9622. * @example
  9623. *
  9624. * var array = [1];
  9625. * var other = _.concat(array, 2, [3], [[4]]);
  9626. *
  9627. * console.log(other);
  9628. * // => [1, 2, 3, [4]]
  9629. *
  9630. * console.log(array);
  9631. * // => [1]
  9632. */
  9633. function concat() {
  9634. var length = arguments.length;
  9635. if (!length) {
  9636. return [];
  9637. }
  9638. var args = Array(length - 1),
  9639. array = arguments[0],
  9640. index = length;
  9641. while (index--) {
  9642. args[index - 1] = arguments[index];
  9643. }
  9644. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  9645. }
  9646. /**
  9647. * Creates an array of `array` values not included in the other given arrays
  9648. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  9649. * for equality comparisons. The order and references of result values are
  9650. * determined by the first array.
  9651. *
  9652. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  9653. *
  9654. * @static
  9655. * @memberOf _
  9656. * @since 0.1.0
  9657. * @category Array
  9658. * @param {Array} array The array to inspect.
  9659. * @param {...Array} [values] The values to exclude.
  9660. * @returns {Array} Returns the new array of filtered values.
  9661. * @see _.without, _.xor
  9662. * @example
  9663. *
  9664. * _.difference([2, 1], [2, 3]);
  9665. * // => [1]
  9666. */
  9667. var difference = baseRest(function(array, values) {
  9668. return isArrayLikeObject(array)
  9669. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  9670. : [];
  9671. });
  9672. /**
  9673. * This method is like `_.difference` except that it accepts `iteratee` which
  9674. * is invoked for each element of `array` and `values` to generate the criterion
  9675. * by which they're compared. The order and references of result values are
  9676. * determined by the first array. The iteratee is invoked with one argument:
  9677. * (value).
  9678. *
  9679. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  9680. *
  9681. * @static
  9682. * @memberOf _
  9683. * @since 4.0.0
  9684. * @category Array
  9685. * @param {Array} array The array to inspect.
  9686. * @param {...Array} [values] The values to exclude.
  9687. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  9688. * @returns {Array} Returns the new array of filtered values.
  9689. * @example
  9690. *
  9691. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  9692. * // => [1.2]
  9693. *
  9694. * // The `_.property` iteratee shorthand.
  9695. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  9696. * // => [{ 'x': 2 }]
  9697. */
  9698. var differenceBy = baseRest(function(array, values) {
  9699. var iteratee = last(values);
  9700. if (isArrayLikeObject(iteratee)) {
  9701. iteratee = undefined;
  9702. }
  9703. return isArrayLikeObject(array)
  9704. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  9705. : [];
  9706. });
  9707. /**
  9708. * This method is like `_.difference` except that it accepts `comparator`
  9709. * which is invoked to compare elements of `array` to `values`. The order and
  9710. * references of result values are determined by the first array. The comparator
  9711. * is invoked with two arguments: (arrVal, othVal).
  9712. *
  9713. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  9714. *
  9715. * @static
  9716. * @memberOf _
  9717. * @since 4.0.0
  9718. * @category Array
  9719. * @param {Array} array The array to inspect.
  9720. * @param {...Array} [values] The values to exclude.
  9721. * @param {Function} [comparator] The comparator invoked per element.
  9722. * @returns {Array} Returns the new array of filtered values.
  9723. * @example
  9724. *
  9725. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  9726. *
  9727. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  9728. * // => [{ 'x': 2, 'y': 1 }]
  9729. */
  9730. var differenceWith = baseRest(function(array, values) {
  9731. var comparator = last(values);
  9732. if (isArrayLikeObject(comparator)) {
  9733. comparator = undefined;
  9734. }
  9735. return isArrayLikeObject(array)
  9736. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  9737. : [];
  9738. });
  9739. /**
  9740. * Creates a slice of `array` with `n` elements dropped from the beginning.
  9741. *
  9742. * @static
  9743. * @memberOf _
  9744. * @since 0.5.0
  9745. * @category Array
  9746. * @param {Array} array The array to query.
  9747. * @param {number} [n=1] The number of elements to drop.
  9748. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9749. * @returns {Array} Returns the slice of `array`.
  9750. * @example
  9751. *
  9752. * _.drop([1, 2, 3]);
  9753. * // => [2, 3]
  9754. *
  9755. * _.drop([1, 2, 3], 2);
  9756. * // => [3]
  9757. *
  9758. * _.drop([1, 2, 3], 5);
  9759. * // => []
  9760. *
  9761. * _.drop([1, 2, 3], 0);
  9762. * // => [1, 2, 3]
  9763. */
  9764. function drop(array, n, guard) {
  9765. var length = array == null ? 0 : array.length;
  9766. if (!length) {
  9767. return [];
  9768. }
  9769. n = (guard || n === undefined) ? 1 : toInteger(n);
  9770. return baseSlice(array, n < 0 ? 0 : n, length);
  9771. }
  9772. /**
  9773. * Creates a slice of `array` with `n` elements dropped from the end.
  9774. *
  9775. * @static
  9776. * @memberOf _
  9777. * @since 3.0.0
  9778. * @category Array
  9779. * @param {Array} array The array to query.
  9780. * @param {number} [n=1] The number of elements to drop.
  9781. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9782. * @returns {Array} Returns the slice of `array`.
  9783. * @example
  9784. *
  9785. * _.dropRight([1, 2, 3]);
  9786. * // => [1, 2]
  9787. *
  9788. * _.dropRight([1, 2, 3], 2);
  9789. * // => [1]
  9790. *
  9791. * _.dropRight([1, 2, 3], 5);
  9792. * // => []
  9793. *
  9794. * _.dropRight([1, 2, 3], 0);
  9795. * // => [1, 2, 3]
  9796. */
  9797. function dropRight(array, n, guard) {
  9798. var length = array == null ? 0 : array.length;
  9799. if (!length) {
  9800. return [];
  9801. }
  9802. n = (guard || n === undefined) ? 1 : toInteger(n);
  9803. n = length - n;
  9804. return baseSlice(array, 0, n < 0 ? 0 : n);
  9805. }
  9806. /**
  9807. * Creates a slice of `array` excluding elements dropped from the end.
  9808. * Elements are dropped until `predicate` returns falsey. The predicate is
  9809. * invoked with three arguments: (value, index, array).
  9810. *
  9811. * @static
  9812. * @memberOf _
  9813. * @since 3.0.0
  9814. * @category Array
  9815. * @param {Array} array The array to query.
  9816. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9817. * @returns {Array} Returns the slice of `array`.
  9818. * @example
  9819. *
  9820. * var users = [
  9821. * { 'user': 'barney', 'active': true },
  9822. * { 'user': 'fred', 'active': false },
  9823. * { 'user': 'pebbles', 'active': false }
  9824. * ];
  9825. *
  9826. * _.dropRightWhile(users, function(o) { return !o.active; });
  9827. * // => objects for ['barney']
  9828. *
  9829. * // The `_.matches` iteratee shorthand.
  9830. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  9831. * // => objects for ['barney', 'fred']
  9832. *
  9833. * // The `_.matchesProperty` iteratee shorthand.
  9834. * _.dropRightWhile(users, ['active', false]);
  9835. * // => objects for ['barney']
  9836. *
  9837. * // The `_.property` iteratee shorthand.
  9838. * _.dropRightWhile(users, 'active');
  9839. * // => objects for ['barney', 'fred', 'pebbles']
  9840. */
  9841. function dropRightWhile(array, predicate) {
  9842. return (array && array.length)
  9843. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  9844. : [];
  9845. }
  9846. /**
  9847. * Creates a slice of `array` excluding elements dropped from the beginning.
  9848. * Elements are dropped until `predicate` returns falsey. The predicate is
  9849. * invoked with three arguments: (value, index, array).
  9850. *
  9851. * @static
  9852. * @memberOf _
  9853. * @since 3.0.0
  9854. * @category Array
  9855. * @param {Array} array The array to query.
  9856. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9857. * @returns {Array} Returns the slice of `array`.
  9858. * @example
  9859. *
  9860. * var users = [
  9861. * { 'user': 'barney', 'active': false },
  9862. * { 'user': 'fred', 'active': false },
  9863. * { 'user': 'pebbles', 'active': true }
  9864. * ];
  9865. *
  9866. * _.dropWhile(users, function(o) { return !o.active; });
  9867. * // => objects for ['pebbles']
  9868. *
  9869. * // The `_.matches` iteratee shorthand.
  9870. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  9871. * // => objects for ['fred', 'pebbles']
  9872. *
  9873. * // The `_.matchesProperty` iteratee shorthand.
  9874. * _.dropWhile(users, ['active', false]);
  9875. * // => objects for ['pebbles']
  9876. *
  9877. * // The `_.property` iteratee shorthand.
  9878. * _.dropWhile(users, 'active');
  9879. * // => objects for ['barney', 'fred', 'pebbles']
  9880. */
  9881. function dropWhile(array, predicate) {
  9882. return (array && array.length)
  9883. ? baseWhile(array, getIteratee(predicate, 3), true)
  9884. : [];
  9885. }
  9886. /**
  9887. * Fills elements of `array` with `value` from `start` up to, but not
  9888. * including, `end`.
  9889. *
  9890. * **Note:** This method mutates `array`.
  9891. *
  9892. * @static
  9893. * @memberOf _
  9894. * @since 3.2.0
  9895. * @category Array
  9896. * @param {Array} array The array to fill.
  9897. * @param {*} value The value to fill `array` with.
  9898. * @param {number} [start=0] The start position.
  9899. * @param {number} [end=array.length] The end position.
  9900. * @returns {Array} Returns `array`.
  9901. * @example
  9902. *
  9903. * var array = [1, 2, 3];
  9904. *
  9905. * _.fill(array, 'a');
  9906. * console.log(array);
  9907. * // => ['a', 'a', 'a']
  9908. *
  9909. * _.fill(Array(3), 2);
  9910. * // => [2, 2, 2]
  9911. *
  9912. * _.fill([4, 6, 8, 10], '*', 1, 3);
  9913. * // => [4, '*', '*', 10]
  9914. */
  9915. function fill(array, value, start, end) {
  9916. var length = array == null ? 0 : array.length;
  9917. if (!length) {
  9918. return [];
  9919. }
  9920. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  9921. start = 0;
  9922. end = length;
  9923. }
  9924. return baseFill(array, value, start, end);
  9925. }
  9926. /**
  9927. * This method is like `_.find` except that it returns the index of the first
  9928. * element `predicate` returns truthy for instead of the element itself.
  9929. *
  9930. * @static
  9931. * @memberOf _
  9932. * @since 1.1.0
  9933. * @category Array
  9934. * @param {Array} array The array to inspect.
  9935. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9936. * @param {number} [fromIndex=0] The index to search from.
  9937. * @returns {number} Returns the index of the found element, else `-1`.
  9938. * @example
  9939. *
  9940. * var users = [
  9941. * { 'user': 'barney', 'active': false },
  9942. * { 'user': 'fred', 'active': false },
  9943. * { 'user': 'pebbles', 'active': true }
  9944. * ];
  9945. *
  9946. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  9947. * // => 0
  9948. *
  9949. * // The `_.matches` iteratee shorthand.
  9950. * _.findIndex(users, { 'user': 'fred', 'active': false });
  9951. * // => 1
  9952. *
  9953. * // The `_.matchesProperty` iteratee shorthand.
  9954. * _.findIndex(users, ['active', false]);
  9955. * // => 0
  9956. *
  9957. * // The `_.property` iteratee shorthand.
  9958. * _.findIndex(users, 'active');
  9959. * // => 2
  9960. */
  9961. function findIndex(array, predicate, fromIndex) {
  9962. var length = array == null ? 0 : array.length;
  9963. if (!length) {
  9964. return -1;
  9965. }
  9966. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  9967. if (index < 0) {
  9968. index = nativeMax(length + index, 0);
  9969. }
  9970. return baseFindIndex(array, getIteratee(predicate, 3), index);
  9971. }
  9972. /**
  9973. * This method is like `_.findIndex` except that it iterates over elements
  9974. * of `collection` from right to left.
  9975. *
  9976. * @static
  9977. * @memberOf _
  9978. * @since 2.0.0
  9979. * @category Array
  9980. * @param {Array} array The array to inspect.
  9981. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9982. * @param {number} [fromIndex=array.length-1] The index to search from.
  9983. * @returns {number} Returns the index of the found element, else `-1`.
  9984. * @example
  9985. *
  9986. * var users = [
  9987. * { 'user': 'barney', 'active': true },
  9988. * { 'user': 'fred', 'active': false },
  9989. * { 'user': 'pebbles', 'active': false }
  9990. * ];
  9991. *
  9992. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  9993. * // => 2
  9994. *
  9995. * // The `_.matches` iteratee shorthand.
  9996. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  9997. * // => 0
  9998. *
  9999. * // The `_.matchesProperty` iteratee shorthand.
  10000. * _.findLastIndex(users, ['active', false]);
  10001. * // => 2
  10002. *
  10003. * // The `_.property` iteratee shorthand.
  10004. * _.findLastIndex(users, 'active');
  10005. * // => 0
  10006. */
  10007. function findLastIndex(array, predicate, fromIndex) {
  10008. var length = array == null ? 0 : array.length;
  10009. if (!length) {
  10010. return -1;
  10011. }
  10012. var index = length - 1;
  10013. if (fromIndex !== undefined) {
  10014. index = toInteger(fromIndex);
  10015. index = fromIndex < 0
  10016. ? nativeMax(length + index, 0)
  10017. : nativeMin(index, length - 1);
  10018. }
  10019. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  10020. }
  10021. /**
  10022. * Flattens `array` a single level deep.
  10023. *
  10024. * @static
  10025. * @memberOf _
  10026. * @since 0.1.0
  10027. * @category Array
  10028. * @param {Array} array The array to flatten.
  10029. * @returns {Array} Returns the new flattened array.
  10030. * @example
  10031. *
  10032. * _.flatten([1, [2, [3, [4]], 5]]);
  10033. * // => [1, 2, [3, [4]], 5]
  10034. */
  10035. function flatten(array) {
  10036. var length = array == null ? 0 : array.length;
  10037. return length ? baseFlatten(array, 1) : [];
  10038. }
  10039. /**
  10040. * Recursively flattens `array`.
  10041. *
  10042. * @static
  10043. * @memberOf _
  10044. * @since 3.0.0
  10045. * @category Array
  10046. * @param {Array} array The array to flatten.
  10047. * @returns {Array} Returns the new flattened array.
  10048. * @example
  10049. *
  10050. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  10051. * // => [1, 2, 3, 4, 5]
  10052. */
  10053. function flattenDeep(array) {
  10054. var length = array == null ? 0 : array.length;
  10055. return length ? baseFlatten(array, INFINITY) : [];
  10056. }
  10057. /**
  10058. * Recursively flatten `array` up to `depth` times.
  10059. *
  10060. * @static
  10061. * @memberOf _
  10062. * @since 4.4.0
  10063. * @category Array
  10064. * @param {Array} array The array to flatten.
  10065. * @param {number} [depth=1] The maximum recursion depth.
  10066. * @returns {Array} Returns the new flattened array.
  10067. * @example
  10068. *
  10069. * var array = [1, [2, [3, [4]], 5]];
  10070. *
  10071. * _.flattenDepth(array, 1);
  10072. * // => [1, 2, [3, [4]], 5]
  10073. *
  10074. * _.flattenDepth(array, 2);
  10075. * // => [1, 2, 3, [4], 5]
  10076. */
  10077. function flattenDepth(array, depth) {
  10078. var length = array == null ? 0 : array.length;
  10079. if (!length) {
  10080. return [];
  10081. }
  10082. depth = depth === undefined ? 1 : toInteger(depth);
  10083. return baseFlatten(array, depth);
  10084. }
  10085. /**
  10086. * The inverse of `_.toPairs`; this method returns an object composed
  10087. * from key-value `pairs`.
  10088. *
  10089. * @static
  10090. * @memberOf _
  10091. * @since 4.0.0
  10092. * @category Array
  10093. * @param {Array} pairs The key-value pairs.
  10094. * @returns {Object} Returns the new object.
  10095. * @example
  10096. *
  10097. * _.fromPairs([['a', 1], ['b', 2]]);
  10098. * // => { 'a': 1, 'b': 2 }
  10099. */
  10100. function fromPairs(pairs) {
  10101. var index = -1,
  10102. length = pairs == null ? 0 : pairs.length,
  10103. result = {};
  10104. while (++index < length) {
  10105. var pair = pairs[index];
  10106. result[pair[0]] = pair[1];
  10107. }
  10108. return result;
  10109. }
  10110. /**
  10111. * Gets the first element of `array`.
  10112. *
  10113. * @static
  10114. * @memberOf _
  10115. * @since 0.1.0
  10116. * @alias first
  10117. * @category Array
  10118. * @param {Array} array The array to query.
  10119. * @returns {*} Returns the first element of `array`.
  10120. * @example
  10121. *
  10122. * _.head([1, 2, 3]);
  10123. * // => 1
  10124. *
  10125. * _.head([]);
  10126. * // => undefined
  10127. */
  10128. function head(array) {
  10129. return (array && array.length) ? array[0] : undefined;
  10130. }
  10131. /**
  10132. * Gets the index at which the first occurrence of `value` is found in `array`
  10133. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10134. * for equality comparisons. If `fromIndex` is negative, it's used as the
  10135. * offset from the end of `array`.
  10136. *
  10137. * @static
  10138. * @memberOf _
  10139. * @since 0.1.0
  10140. * @category Array
  10141. * @param {Array} array The array to inspect.
  10142. * @param {*} value The value to search for.
  10143. * @param {number} [fromIndex=0] The index to search from.
  10144. * @returns {number} Returns the index of the matched value, else `-1`.
  10145. * @example
  10146. *
  10147. * _.indexOf([1, 2, 1, 2], 2);
  10148. * // => 1
  10149. *
  10150. * // Search from the `fromIndex`.
  10151. * _.indexOf([1, 2, 1, 2], 2, 2);
  10152. * // => 3
  10153. */
  10154. function indexOf(array, value, fromIndex) {
  10155. var length = array == null ? 0 : array.length;
  10156. if (!length) {
  10157. return -1;
  10158. }
  10159. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  10160. if (index < 0) {
  10161. index = nativeMax(length + index, 0);
  10162. }
  10163. return baseIndexOf(array, value, index);
  10164. }
  10165. /**
  10166. * Gets all but the last element of `array`.
  10167. *
  10168. * @static
  10169. * @memberOf _
  10170. * @since 0.1.0
  10171. * @category Array
  10172. * @param {Array} array The array to query.
  10173. * @returns {Array} Returns the slice of `array`.
  10174. * @example
  10175. *
  10176. * _.initial([1, 2, 3]);
  10177. * // => [1, 2]
  10178. */
  10179. function initial(array) {
  10180. var length = array == null ? 0 : array.length;
  10181. return length ? baseSlice(array, 0, -1) : [];
  10182. }
  10183. /**
  10184. * Creates an array of unique values that are included in all given arrays
  10185. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10186. * for equality comparisons. The order and references of result values are
  10187. * determined by the first array.
  10188. *
  10189. * @static
  10190. * @memberOf _
  10191. * @since 0.1.0
  10192. * @category Array
  10193. * @param {...Array} [arrays] The arrays to inspect.
  10194. * @returns {Array} Returns the new array of intersecting values.
  10195. * @example
  10196. *
  10197. * _.intersection([2, 1], [2, 3]);
  10198. * // => [2]
  10199. */
  10200. var intersection = baseRest(function(arrays) {
  10201. var mapped = arrayMap(arrays, castArrayLikeObject);
  10202. return (mapped.length && mapped[0] === arrays[0])
  10203. ? baseIntersection(mapped)
  10204. : [];
  10205. });
  10206. /**
  10207. * This method is like `_.intersection` except that it accepts `iteratee`
  10208. * which is invoked for each element of each `arrays` to generate the criterion
  10209. * by which they're compared. The order and references of result values are
  10210. * determined by the first array. The iteratee is invoked with one argument:
  10211. * (value).
  10212. *
  10213. * @static
  10214. * @memberOf _
  10215. * @since 4.0.0
  10216. * @category Array
  10217. * @param {...Array} [arrays] The arrays to inspect.
  10218. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  10219. * @returns {Array} Returns the new array of intersecting values.
  10220. * @example
  10221. *
  10222. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  10223. * // => [2.1]
  10224. *
  10225. * // The `_.property` iteratee shorthand.
  10226. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  10227. * // => [{ 'x': 1 }]
  10228. */
  10229. var intersectionBy = baseRest(function(arrays) {
  10230. var iteratee = last(arrays),
  10231. mapped = arrayMap(arrays, castArrayLikeObject);
  10232. if (iteratee === last(mapped)) {
  10233. iteratee = undefined;
  10234. } else {
  10235. mapped.pop();
  10236. }
  10237. return (mapped.length && mapped[0] === arrays[0])
  10238. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  10239. : [];
  10240. });
  10241. /**
  10242. * This method is like `_.intersection` except that it accepts `comparator`
  10243. * which is invoked to compare elements of `arrays`. The order and references
  10244. * of result values are determined by the first array. The comparator is
  10245. * invoked with two arguments: (arrVal, othVal).
  10246. *
  10247. * @static
  10248. * @memberOf _
  10249. * @since 4.0.0
  10250. * @category Array
  10251. * @param {...Array} [arrays] The arrays to inspect.
  10252. * @param {Function} [comparator] The comparator invoked per element.
  10253. * @returns {Array} Returns the new array of intersecting values.
  10254. * @example
  10255. *
  10256. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  10257. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  10258. *
  10259. * _.intersectionWith(objects, others, _.isEqual);
  10260. * // => [{ 'x': 1, 'y': 2 }]
  10261. */
  10262. var intersectionWith = baseRest(function(arrays) {
  10263. var comparator = last(arrays),
  10264. mapped = arrayMap(arrays, castArrayLikeObject);
  10265. comparator = typeof comparator == 'function' ? comparator : undefined;
  10266. if (comparator) {
  10267. mapped.pop();
  10268. }
  10269. return (mapped.length && mapped[0] === arrays[0])
  10270. ? baseIntersection(mapped, undefined, comparator)
  10271. : [];
  10272. });
  10273. /**
  10274. * Converts all elements in `array` into a string separated by `separator`.
  10275. *
  10276. * @static
  10277. * @memberOf _
  10278. * @since 4.0.0
  10279. * @category Array
  10280. * @param {Array} array The array to convert.
  10281. * @param {string} [separator=','] The element separator.
  10282. * @returns {string} Returns the joined string.
  10283. * @example
  10284. *
  10285. * _.join(['a', 'b', 'c'], '~');
  10286. * // => 'a~b~c'
  10287. */
  10288. function join(array, separator) {
  10289. return array == null ? '' : nativeJoin.call(array, separator);
  10290. }
  10291. /**
  10292. * Gets the last element of `array`.
  10293. *
  10294. * @static
  10295. * @memberOf _
  10296. * @since 0.1.0
  10297. * @category Array
  10298. * @param {Array} array The array to query.
  10299. * @returns {*} Returns the last element of `array`.
  10300. * @example
  10301. *
  10302. * _.last([1, 2, 3]);
  10303. * // => 3
  10304. */
  10305. function last(array) {
  10306. var length = array == null ? 0 : array.length;
  10307. return length ? array[length - 1] : undefined;
  10308. }
  10309. /**
  10310. * This method is like `_.indexOf` except that it iterates over elements of
  10311. * `array` from right to left.
  10312. *
  10313. * @static
  10314. * @memberOf _
  10315. * @since 0.1.0
  10316. * @category Array
  10317. * @param {Array} array The array to inspect.
  10318. * @param {*} value The value to search for.
  10319. * @param {number} [fromIndex=array.length-1] The index to search from.
  10320. * @returns {number} Returns the index of the matched value, else `-1`.
  10321. * @example
  10322. *
  10323. * _.lastIndexOf([1, 2, 1, 2], 2);
  10324. * // => 3
  10325. *
  10326. * // Search from the `fromIndex`.
  10327. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  10328. * // => 1
  10329. */
  10330. function lastIndexOf(array, value, fromIndex) {
  10331. var length = array == null ? 0 : array.length;
  10332. if (!length) {
  10333. return -1;
  10334. }
  10335. var index = length;
  10336. if (fromIndex !== undefined) {
  10337. index = toInteger(fromIndex);
  10338. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  10339. }
  10340. return value === value
  10341. ? strictLastIndexOf(array, value, index)
  10342. : baseFindIndex(array, baseIsNaN, index, true);
  10343. }
  10344. /**
  10345. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  10346. * element from the end is returned.
  10347. *
  10348. * @static
  10349. * @memberOf _
  10350. * @since 4.11.0
  10351. * @category Array
  10352. * @param {Array} array The array to query.
  10353. * @param {number} [n=0] The index of the element to return.
  10354. * @returns {*} Returns the nth element of `array`.
  10355. * @example
  10356. *
  10357. * var array = ['a', 'b', 'c', 'd'];
  10358. *
  10359. * _.nth(array, 1);
  10360. * // => 'b'
  10361. *
  10362. * _.nth(array, -2);
  10363. * // => 'c';
  10364. */
  10365. function nth(array, n) {
  10366. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  10367. }
  10368. /**
  10369. * Removes all given values from `array` using
  10370. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10371. * for equality comparisons.
  10372. *
  10373. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  10374. * to remove elements from an array by predicate.
  10375. *
  10376. * @static
  10377. * @memberOf _
  10378. * @since 2.0.0
  10379. * @category Array
  10380. * @param {Array} array The array to modify.
  10381. * @param {...*} [values] The values to remove.
  10382. * @returns {Array} Returns `array`.
  10383. * @example
  10384. *
  10385. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  10386. *
  10387. * _.pull(array, 'a', 'c');
  10388. * console.log(array);
  10389. * // => ['b', 'b']
  10390. */
  10391. var pull = baseRest(pullAll);
  10392. /**
  10393. * This method is like `_.pull` except that it accepts an array of values to remove.
  10394. *
  10395. * **Note:** Unlike `_.difference`, this method mutates `array`.
  10396. *
  10397. * @static
  10398. * @memberOf _
  10399. * @since 4.0.0
  10400. * @category Array
  10401. * @param {Array} array The array to modify.
  10402. * @param {Array} values The values to remove.
  10403. * @returns {Array} Returns `array`.
  10404. * @example
  10405. *
  10406. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  10407. *
  10408. * _.pullAll(array, ['a', 'c']);
  10409. * console.log(array);
  10410. * // => ['b', 'b']
  10411. */
  10412. function pullAll(array, values) {
  10413. return (array && array.length && values && values.length)
  10414. ? basePullAll(array, values)
  10415. : array;
  10416. }
  10417. /**
  10418. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  10419. * invoked for each element of `array` and `values` to generate the criterion
  10420. * by which they're compared. The iteratee is invoked with one argument: (value).
  10421. *
  10422. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  10423. *
  10424. * @static
  10425. * @memberOf _
  10426. * @since 4.0.0
  10427. * @category Array
  10428. * @param {Array} array The array to modify.
  10429. * @param {Array} values The values to remove.
  10430. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  10431. * @returns {Array} Returns `array`.
  10432. * @example
  10433. *
  10434. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  10435. *
  10436. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  10437. * console.log(array);
  10438. * // => [{ 'x': 2 }]
  10439. */
  10440. function pullAllBy(array, values, iteratee) {
  10441. return (array && array.length && values && values.length)
  10442. ? basePullAll(array, values, getIteratee(iteratee, 2))
  10443. : array;
  10444. }
  10445. /**
  10446. * This method is like `_.pullAll` except that it accepts `comparator` which
  10447. * is invoked to compare elements of `array` to `values`. The comparator is
  10448. * invoked with two arguments: (arrVal, othVal).
  10449. *
  10450. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  10451. *
  10452. * @static
  10453. * @memberOf _
  10454. * @since 4.6.0
  10455. * @category Array
  10456. * @param {Array} array The array to modify.
  10457. * @param {Array} values The values to remove.
  10458. * @param {Function} [comparator] The comparator invoked per element.
  10459. * @returns {Array} Returns `array`.
  10460. * @example
  10461. *
  10462. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  10463. *
  10464. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  10465. * console.log(array);
  10466. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  10467. */
  10468. function pullAllWith(array, values, comparator) {
  10469. return (array && array.length && values && values.length)
  10470. ? basePullAll(array, values, undefined, comparator)
  10471. : array;
  10472. }
  10473. /**
  10474. * Removes elements from `array` corresponding to `indexes` and returns an
  10475. * array of removed elements.
  10476. *
  10477. * **Note:** Unlike `_.at`, this method mutates `array`.
  10478. *
  10479. * @static
  10480. * @memberOf _
  10481. * @since 3.0.0
  10482. * @category Array
  10483. * @param {Array} array The array to modify.
  10484. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  10485. * @returns {Array} Returns the new array of removed elements.
  10486. * @example
  10487. *
  10488. * var array = ['a', 'b', 'c', 'd'];
  10489. * var pulled = _.pullAt(array, [1, 3]);
  10490. *
  10491. * console.log(array);
  10492. * // => ['a', 'c']
  10493. *
  10494. * console.log(pulled);
  10495. * // => ['b', 'd']
  10496. */
  10497. var pullAt = flatRest(function(array, indexes) {
  10498. var length = array == null ? 0 : array.length,
  10499. result = baseAt(array, indexes);
  10500. basePullAt(array, arrayMap(indexes, function(index) {
  10501. return isIndex(index, length) ? +index : index;
  10502. }).sort(compareAscending));
  10503. return result;
  10504. });
  10505. /**
  10506. * Removes all elements from `array` that `predicate` returns truthy for
  10507. * and returns an array of the removed elements. The predicate is invoked
  10508. * with three arguments: (value, index, array).
  10509. *
  10510. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  10511. * to pull elements from an array by value.
  10512. *
  10513. * @static
  10514. * @memberOf _
  10515. * @since 2.0.0
  10516. * @category Array
  10517. * @param {Array} array The array to modify.
  10518. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10519. * @returns {Array} Returns the new array of removed elements.
  10520. * @example
  10521. *
  10522. * var array = [1, 2, 3, 4];
  10523. * var evens = _.remove(array, function(n) {
  10524. * return n % 2 == 0;
  10525. * });
  10526. *
  10527. * console.log(array);
  10528. * // => [1, 3]
  10529. *
  10530. * console.log(evens);
  10531. * // => [2, 4]
  10532. */
  10533. function remove(array, predicate) {
  10534. var result = [];
  10535. if (!(array && array.length)) {
  10536. return result;
  10537. }
  10538. var index = -1,
  10539. indexes = [],
  10540. length = array.length;
  10541. predicate = getIteratee(predicate, 3);
  10542. while (++index < length) {
  10543. var value = array[index];
  10544. if (predicate(value, index, array)) {
  10545. result.push(value);
  10546. indexes.push(index);
  10547. }
  10548. }
  10549. basePullAt(array, indexes);
  10550. return result;
  10551. }
  10552. /**
  10553. * Reverses `array` so that the first element becomes the last, the second
  10554. * element becomes the second to last, and so on.
  10555. *
  10556. * **Note:** This method mutates `array` and is based on
  10557. * [`Array#reverse`](https://mdn.io/Array/reverse).
  10558. *
  10559. * @static
  10560. * @memberOf _
  10561. * @since 4.0.0
  10562. * @category Array
  10563. * @param {Array} array The array to modify.
  10564. * @returns {Array} Returns `array`.
  10565. * @example
  10566. *
  10567. * var array = [1, 2, 3];
  10568. *
  10569. * _.reverse(array);
  10570. * // => [3, 2, 1]
  10571. *
  10572. * console.log(array);
  10573. * // => [3, 2, 1]
  10574. */
  10575. function reverse(array) {
  10576. return array == null ? array : nativeReverse.call(array);
  10577. }
  10578. /**
  10579. * Creates a slice of `array` from `start` up to, but not including, `end`.
  10580. *
  10581. * **Note:** This method is used instead of
  10582. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  10583. * returned.
  10584. *
  10585. * @static
  10586. * @memberOf _
  10587. * @since 3.0.0
  10588. * @category Array
  10589. * @param {Array} array The array to slice.
  10590. * @param {number} [start=0] The start position.
  10591. * @param {number} [end=array.length] The end position.
  10592. * @returns {Array} Returns the slice of `array`.
  10593. */
  10594. function slice(array, start, end) {
  10595. var length = array == null ? 0 : array.length;
  10596. if (!length) {
  10597. return [];
  10598. }
  10599. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  10600. start = 0;
  10601. end = length;
  10602. }
  10603. else {
  10604. start = start == null ? 0 : toInteger(start);
  10605. end = end === undefined ? length : toInteger(end);
  10606. }
  10607. return baseSlice(array, start, end);
  10608. }
  10609. /**
  10610. * Uses a binary search to determine the lowest index at which `value`
  10611. * should be inserted into `array` in order to maintain its sort order.
  10612. *
  10613. * @static
  10614. * @memberOf _
  10615. * @since 0.1.0
  10616. * @category Array
  10617. * @param {Array} array The sorted array to inspect.
  10618. * @param {*} value The value to evaluate.
  10619. * @returns {number} Returns the index at which `value` should be inserted
  10620. * into `array`.
  10621. * @example
  10622. *
  10623. * _.sortedIndex([30, 50], 40);
  10624. * // => 1
  10625. */
  10626. function sortedIndex(array, value) {
  10627. return baseSortedIndex(array, value);
  10628. }
  10629. /**
  10630. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  10631. * which is invoked for `value` and each element of `array` to compute their
  10632. * sort ranking. The iteratee is invoked with one argument: (value).
  10633. *
  10634. * @static
  10635. * @memberOf _
  10636. * @since 4.0.0
  10637. * @category Array
  10638. * @param {Array} array The sorted array to inspect.
  10639. * @param {*} value The value to evaluate.
  10640. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  10641. * @returns {number} Returns the index at which `value` should be inserted
  10642. * into `array`.
  10643. * @example
  10644. *
  10645. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  10646. *
  10647. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  10648. * // => 0
  10649. *
  10650. * // The `_.property` iteratee shorthand.
  10651. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  10652. * // => 0
  10653. */
  10654. function sortedIndexBy(array, value, iteratee) {
  10655. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  10656. }
  10657. /**
  10658. * This method is like `_.indexOf` except that it performs a binary
  10659. * search on a sorted `array`.
  10660. *
  10661. * @static
  10662. * @memberOf _
  10663. * @since 4.0.0
  10664. * @category Array
  10665. * @param {Array} array The array to inspect.
  10666. * @param {*} value The value to search for.
  10667. * @returns {number} Returns the index of the matched value, else `-1`.
  10668. * @example
  10669. *
  10670. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  10671. * // => 1
  10672. */
  10673. function sortedIndexOf(array, value) {
  10674. var length = array == null ? 0 : array.length;
  10675. if (length) {
  10676. var index = baseSortedIndex(array, value);
  10677. if (index < length && eq(array[index], value)) {
  10678. return index;
  10679. }
  10680. }
  10681. return -1;
  10682. }
  10683. /**
  10684. * This method is like `_.sortedIndex` except that it returns the highest
  10685. * index at which `value` should be inserted into `array` in order to
  10686. * maintain its sort order.
  10687. *
  10688. * @static
  10689. * @memberOf _
  10690. * @since 3.0.0
  10691. * @category Array
  10692. * @param {Array} array The sorted array to inspect.
  10693. * @param {*} value The value to evaluate.
  10694. * @returns {number} Returns the index at which `value` should be inserted
  10695. * into `array`.
  10696. * @example
  10697. *
  10698. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  10699. * // => 4
  10700. */
  10701. function sortedLastIndex(array, value) {
  10702. return baseSortedIndex(array, value, true);
  10703. }
  10704. /**
  10705. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  10706. * which is invoked for `value` and each element of `array` to compute their
  10707. * sort ranking. The iteratee is invoked with one argument: (value).
  10708. *
  10709. * @static
  10710. * @memberOf _
  10711. * @since 4.0.0
  10712. * @category Array
  10713. * @param {Array} array The sorted array to inspect.
  10714. * @param {*} value The value to evaluate.
  10715. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  10716. * @returns {number} Returns the index at which `value` should be inserted
  10717. * into `array`.
  10718. * @example
  10719. *
  10720. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  10721. *
  10722. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  10723. * // => 1
  10724. *
  10725. * // The `_.property` iteratee shorthand.
  10726. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  10727. * // => 1
  10728. */
  10729. function sortedLastIndexBy(array, value, iteratee) {
  10730. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  10731. }
  10732. /**
  10733. * This method is like `_.lastIndexOf` except that it performs a binary
  10734. * search on a sorted `array`.
  10735. *
  10736. * @static
  10737. * @memberOf _
  10738. * @since 4.0.0
  10739. * @category Array
  10740. * @param {Array} array The array to inspect.
  10741. * @param {*} value The value to search for.
  10742. * @returns {number} Returns the index of the matched value, else `-1`.
  10743. * @example
  10744. *
  10745. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  10746. * // => 3
  10747. */
  10748. function sortedLastIndexOf(array, value) {
  10749. var length = array == null ? 0 : array.length;
  10750. if (length) {
  10751. var index = baseSortedIndex(array, value, true) - 1;
  10752. if (eq(array[index], value)) {
  10753. return index;
  10754. }
  10755. }
  10756. return -1;
  10757. }
  10758. /**
  10759. * This method is like `_.uniq` except that it's designed and optimized
  10760. * for sorted arrays.
  10761. *
  10762. * @static
  10763. * @memberOf _
  10764. * @since 4.0.0
  10765. * @category Array
  10766. * @param {Array} array The array to inspect.
  10767. * @returns {Array} Returns the new duplicate free array.
  10768. * @example
  10769. *
  10770. * _.sortedUniq([1, 1, 2]);
  10771. * // => [1, 2]
  10772. */
  10773. function sortedUniq(array) {
  10774. return (array && array.length)
  10775. ? baseSortedUniq(array)
  10776. : [];
  10777. }
  10778. /**
  10779. * This method is like `_.uniqBy` except that it's designed and optimized
  10780. * for sorted arrays.
  10781. *
  10782. * @static
  10783. * @memberOf _
  10784. * @since 4.0.0
  10785. * @category Array
  10786. * @param {Array} array The array to inspect.
  10787. * @param {Function} [iteratee] The iteratee invoked per element.
  10788. * @returns {Array} Returns the new duplicate free array.
  10789. * @example
  10790. *
  10791. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  10792. * // => [1.1, 2.3]
  10793. */
  10794. function sortedUniqBy(array, iteratee) {
  10795. return (array && array.length)
  10796. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  10797. : [];
  10798. }
  10799. /**
  10800. * Gets all but the first element of `array`.
  10801. *
  10802. * @static
  10803. * @memberOf _
  10804. * @since 4.0.0
  10805. * @category Array
  10806. * @param {Array} array The array to query.
  10807. * @returns {Array} Returns the slice of `array`.
  10808. * @example
  10809. *
  10810. * _.tail([1, 2, 3]);
  10811. * // => [2, 3]
  10812. */
  10813. function tail(array) {
  10814. var length = array == null ? 0 : array.length;
  10815. return length ? baseSlice(array, 1, length) : [];
  10816. }
  10817. /**
  10818. * Creates a slice of `array` with `n` elements taken from the beginning.
  10819. *
  10820. * @static
  10821. * @memberOf _
  10822. * @since 0.1.0
  10823. * @category Array
  10824. * @param {Array} array The array to query.
  10825. * @param {number} [n=1] The number of elements to take.
  10826. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  10827. * @returns {Array} Returns the slice of `array`.
  10828. * @example
  10829. *
  10830. * _.take([1, 2, 3]);
  10831. * // => [1]
  10832. *
  10833. * _.take([1, 2, 3], 2);
  10834. * // => [1, 2]
  10835. *
  10836. * _.take([1, 2, 3], 5);
  10837. * // => [1, 2, 3]
  10838. *
  10839. * _.take([1, 2, 3], 0);
  10840. * // => []
  10841. */
  10842. function take(array, n, guard) {
  10843. if (!(array && array.length)) {
  10844. return [];
  10845. }
  10846. n = (guard || n === undefined) ? 1 : toInteger(n);
  10847. return baseSlice(array, 0, n < 0 ? 0 : n);
  10848. }
  10849. /**
  10850. * Creates a slice of `array` with `n` elements taken from the end.
  10851. *
  10852. * @static
  10853. * @memberOf _
  10854. * @since 3.0.0
  10855. * @category Array
  10856. * @param {Array} array The array to query.
  10857. * @param {number} [n=1] The number of elements to take.
  10858. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  10859. * @returns {Array} Returns the slice of `array`.
  10860. * @example
  10861. *
  10862. * _.takeRight([1, 2, 3]);
  10863. * // => [3]
  10864. *
  10865. * _.takeRight([1, 2, 3], 2);
  10866. * // => [2, 3]
  10867. *
  10868. * _.takeRight([1, 2, 3], 5);
  10869. * // => [1, 2, 3]
  10870. *
  10871. * _.takeRight([1, 2, 3], 0);
  10872. * // => []
  10873. */
  10874. function takeRight(array, n, guard) {
  10875. var length = array == null ? 0 : array.length;
  10876. if (!length) {
  10877. return [];
  10878. }
  10879. n = (guard || n === undefined) ? 1 : toInteger(n);
  10880. n = length - n;
  10881. return baseSlice(array, n < 0 ? 0 : n, length);
  10882. }
  10883. /**
  10884. * Creates a slice of `array` with elements taken from the end. Elements are
  10885. * taken until `predicate` returns falsey. The predicate is invoked with
  10886. * three arguments: (value, index, array).
  10887. *
  10888. * @static
  10889. * @memberOf _
  10890. * @since 3.0.0
  10891. * @category Array
  10892. * @param {Array} array The array to query.
  10893. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10894. * @returns {Array} Returns the slice of `array`.
  10895. * @example
  10896. *
  10897. * var users = [
  10898. * { 'user': 'barney', 'active': true },
  10899. * { 'user': 'fred', 'active': false },
  10900. * { 'user': 'pebbles', 'active': false }
  10901. * ];
  10902. *
  10903. * _.takeRightWhile(users, function(o) { return !o.active; });
  10904. * // => objects for ['fred', 'pebbles']
  10905. *
  10906. * // The `_.matches` iteratee shorthand.
  10907. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  10908. * // => objects for ['pebbles']
  10909. *
  10910. * // The `_.matchesProperty` iteratee shorthand.
  10911. * _.takeRightWhile(users, ['active', false]);
  10912. * // => objects for ['fred', 'pebbles']
  10913. *
  10914. * // The `_.property` iteratee shorthand.
  10915. * _.takeRightWhile(users, 'active');
  10916. * // => []
  10917. */
  10918. function takeRightWhile(array, predicate) {
  10919. return (array && array.length)
  10920. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  10921. : [];
  10922. }
  10923. /**
  10924. * Creates a slice of `array` with elements taken from the beginning. Elements
  10925. * are taken until `predicate` returns falsey. The predicate is invoked with
  10926. * three arguments: (value, index, array).
  10927. *
  10928. * @static
  10929. * @memberOf _
  10930. * @since 3.0.0
  10931. * @category Array
  10932. * @param {Array} array The array to query.
  10933. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10934. * @returns {Array} Returns the slice of `array`.
  10935. * @example
  10936. *
  10937. * var users = [
  10938. * { 'user': 'barney', 'active': false },
  10939. * { 'user': 'fred', 'active': false },
  10940. * { 'user': 'pebbles', 'active': true }
  10941. * ];
  10942. *
  10943. * _.takeWhile(users, function(o) { return !o.active; });
  10944. * // => objects for ['barney', 'fred']
  10945. *
  10946. * // The `_.matches` iteratee shorthand.
  10947. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  10948. * // => objects for ['barney']
  10949. *
  10950. * // The `_.matchesProperty` iteratee shorthand.
  10951. * _.takeWhile(users, ['active', false]);
  10952. * // => objects for ['barney', 'fred']
  10953. *
  10954. * // The `_.property` iteratee shorthand.
  10955. * _.takeWhile(users, 'active');
  10956. * // => []
  10957. */
  10958. function takeWhile(array, predicate) {
  10959. return (array && array.length)
  10960. ? baseWhile(array, getIteratee(predicate, 3))
  10961. : [];
  10962. }
  10963. /**
  10964. * Creates an array of unique values, in order, from all given arrays using
  10965. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10966. * for equality comparisons.
  10967. *
  10968. * @static
  10969. * @memberOf _
  10970. * @since 0.1.0
  10971. * @category Array
  10972. * @param {...Array} [arrays] The arrays to inspect.
  10973. * @returns {Array} Returns the new array of combined values.
  10974. * @example
  10975. *
  10976. * _.union([2], [1, 2]);
  10977. * // => [2, 1]
  10978. */
  10979. var union = baseRest(function(arrays) {
  10980. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  10981. });
  10982. /**
  10983. * This method is like `_.union` except that it accepts `iteratee` which is
  10984. * invoked for each element of each `arrays` to generate the criterion by
  10985. * which uniqueness is computed. Result values are chosen from the first
  10986. * array in which the value occurs. The iteratee is invoked with one argument:
  10987. * (value).
  10988. *
  10989. * @static
  10990. * @memberOf _
  10991. * @since 4.0.0
  10992. * @category Array
  10993. * @param {...Array} [arrays] The arrays to inspect.
  10994. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  10995. * @returns {Array} Returns the new array of combined values.
  10996. * @example
  10997. *
  10998. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  10999. * // => [2.1, 1.2]
  11000. *
  11001. * // The `_.property` iteratee shorthand.
  11002. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  11003. * // => [{ 'x': 1 }, { 'x': 2 }]
  11004. */
  11005. var unionBy = baseRest(function(arrays) {
  11006. var iteratee = last(arrays);
  11007. if (isArrayLikeObject(iteratee)) {
  11008. iteratee = undefined;
  11009. }
  11010. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  11011. });
  11012. /**
  11013. * This method is like `_.union` except that it accepts `comparator` which
  11014. * is invoked to compare elements of `arrays`. Result values are chosen from
  11015. * the first array in which the value occurs. The comparator is invoked
  11016. * with two arguments: (arrVal, othVal).
  11017. *
  11018. * @static
  11019. * @memberOf _
  11020. * @since 4.0.0
  11021. * @category Array
  11022. * @param {...Array} [arrays] The arrays to inspect.
  11023. * @param {Function} [comparator] The comparator invoked per element.
  11024. * @returns {Array} Returns the new array of combined values.
  11025. * @example
  11026. *
  11027. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  11028. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  11029. *
  11030. * _.unionWith(objects, others, _.isEqual);
  11031. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  11032. */
  11033. var unionWith = baseRest(function(arrays) {
  11034. var comparator = last(arrays);
  11035. comparator = typeof comparator == 'function' ? comparator : undefined;
  11036. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  11037. });
  11038. /**
  11039. * Creates a duplicate-free version of an array, using
  11040. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  11041. * for equality comparisons, in which only the first occurrence of each element
  11042. * is kept. The order of result values is determined by the order they occur
  11043. * in the array.
  11044. *
  11045. * @static
  11046. * @memberOf _
  11047. * @since 0.1.0
  11048. * @category Array
  11049. * @param {Array} array The array to inspect.
  11050. * @returns {Array} Returns the new duplicate free array.
  11051. * @example
  11052. *
  11053. * _.uniq([2, 1, 2]);
  11054. * // => [2, 1]
  11055. */
  11056. function uniq(array) {
  11057. return (array && array.length) ? baseUniq(array) : [];
  11058. }
  11059. /**
  11060. * This method is like `_.uniq` except that it accepts `iteratee` which is
  11061. * invoked for each element in `array` to generate the criterion by which
  11062. * uniqueness is computed. The order of result values is determined by the
  11063. * order they occur in the array. The iteratee is invoked with one argument:
  11064. * (value).
  11065. *
  11066. * @static
  11067. * @memberOf _
  11068. * @since 4.0.0
  11069. * @category Array
  11070. * @param {Array} array The array to inspect.
  11071. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  11072. * @returns {Array} Returns the new duplicate free array.
  11073. * @example
  11074. *
  11075. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  11076. * // => [2.1, 1.2]
  11077. *
  11078. * // The `_.property` iteratee shorthand.
  11079. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  11080. * // => [{ 'x': 1 }, { 'x': 2 }]
  11081. */
  11082. function uniqBy(array, iteratee) {
  11083. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  11084. }
  11085. /**
  11086. * This method is like `_.uniq` except that it accepts `comparator` which
  11087. * is invoked to compare elements of `array`. The order of result values is
  11088. * determined by the order they occur in the array.The comparator is invoked
  11089. * with two arguments: (arrVal, othVal).
  11090. *
  11091. * @static
  11092. * @memberOf _
  11093. * @since 4.0.0
  11094. * @category Array
  11095. * @param {Array} array The array to inspect.
  11096. * @param {Function} [comparator] The comparator invoked per element.
  11097. * @returns {Array} Returns the new duplicate free array.
  11098. * @example
  11099. *
  11100. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  11101. *
  11102. * _.uniqWith(objects, _.isEqual);
  11103. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  11104. */
  11105. function uniqWith(array, comparator) {
  11106. comparator = typeof comparator == 'function' ? comparator : undefined;
  11107. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  11108. }
  11109. /**
  11110. * This method is like `_.zip` except that it accepts an array of grouped
  11111. * elements and creates an array regrouping the elements to their pre-zip
  11112. * configuration.
  11113. *
  11114. * @static
  11115. * @memberOf _
  11116. * @since 1.2.0
  11117. * @category Array
  11118. * @param {Array} array The array of grouped elements to process.
  11119. * @returns {Array} Returns the new array of regrouped elements.
  11120. * @example
  11121. *
  11122. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  11123. * // => [['a', 1, true], ['b', 2, false]]
  11124. *
  11125. * _.unzip(zipped);
  11126. * // => [['a', 'b'], [1, 2], [true, false]]
  11127. */
  11128. function unzip(array) {
  11129. if (!(array && array.length)) {
  11130. return [];
  11131. }
  11132. var length = 0;
  11133. array = arrayFilter(array, function(group) {
  11134. if (isArrayLikeObject(group)) {
  11135. length = nativeMax(group.length, length);
  11136. return true;
  11137. }
  11138. });
  11139. return baseTimes(length, function(index) {
  11140. return arrayMap(array, baseProperty(index));
  11141. });
  11142. }
  11143. /**
  11144. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  11145. * how regrouped values should be combined. The iteratee is invoked with the
  11146. * elements of each group: (...group).
  11147. *
  11148. * @static
  11149. * @memberOf _
  11150. * @since 3.8.0
  11151. * @category Array
  11152. * @param {Array} array The array of grouped elements to process.
  11153. * @param {Function} [iteratee=_.identity] The function to combine
  11154. * regrouped values.
  11155. * @returns {Array} Returns the new array of regrouped elements.
  11156. * @example
  11157. *
  11158. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  11159. * // => [[1, 10, 100], [2, 20, 200]]
  11160. *
  11161. * _.unzipWith(zipped, _.add);
  11162. * // => [3, 30, 300]
  11163. */
  11164. function unzipWith(array, iteratee) {
  11165. if (!(array && array.length)) {
  11166. return [];
  11167. }
  11168. var result = unzip(array);
  11169. if (iteratee == null) {
  11170. return result;
  11171. }
  11172. return arrayMap(result, function(group) {
  11173. return apply(iteratee, undefined, group);
  11174. });
  11175. }
  11176. /**
  11177. * Creates an array excluding all given values using
  11178. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  11179. * for equality comparisons.
  11180. *
  11181. * **Note:** Unlike `_.pull`, this method returns a new array.
  11182. *
  11183. * @static
  11184. * @memberOf _
  11185. * @since 0.1.0
  11186. * @category Array
  11187. * @param {Array} array The array to inspect.
  11188. * @param {...*} [values] The values to exclude.
  11189. * @returns {Array} Returns the new array of filtered values.
  11190. * @see _.difference, _.xor
  11191. * @example
  11192. *
  11193. * _.without([2, 1, 2, 3], 1, 2);
  11194. * // => [3]
  11195. */
  11196. var without = baseRest(function(array, values) {
  11197. return isArrayLikeObject(array)
  11198. ? baseDifference(array, values)
  11199. : [];
  11200. });
  11201. /**
  11202. * Creates an array of unique values that is the
  11203. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  11204. * of the given arrays. The order of result values is determined by the order
  11205. * they occur in the arrays.
  11206. *
  11207. * @static
  11208. * @memberOf _
  11209. * @since 2.4.0
  11210. * @category Array
  11211. * @param {...Array} [arrays] The arrays to inspect.
  11212. * @returns {Array} Returns the new array of filtered values.
  11213. * @see _.difference, _.without
  11214. * @example
  11215. *
  11216. * _.xor([2, 1], [2, 3]);
  11217. * // => [1, 3]
  11218. */
  11219. var xor = baseRest(function(arrays) {
  11220. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  11221. });
  11222. /**
  11223. * This method is like `_.xor` except that it accepts `iteratee` which is
  11224. * invoked for each element of each `arrays` to generate the criterion by
  11225. * which by which they're compared. The order of result values is determined
  11226. * by the order they occur in the arrays. The iteratee is invoked with one
  11227. * argument: (value).
  11228. *
  11229. * @static
  11230. * @memberOf _
  11231. * @since 4.0.0
  11232. * @category Array
  11233. * @param {...Array} [arrays] The arrays to inspect.
  11234. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  11235. * @returns {Array} Returns the new array of filtered values.
  11236. * @example
  11237. *
  11238. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  11239. * // => [1.2, 3.4]
  11240. *
  11241. * // The `_.property` iteratee shorthand.
  11242. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  11243. * // => [{ 'x': 2 }]
  11244. */
  11245. var xorBy = baseRest(function(arrays) {
  11246. var iteratee = last(arrays);
  11247. if (isArrayLikeObject(iteratee)) {
  11248. iteratee = undefined;
  11249. }
  11250. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  11251. });
  11252. /**
  11253. * This method is like `_.xor` except that it accepts `comparator` which is
  11254. * invoked to compare elements of `arrays`. The order of result values is
  11255. * determined by the order they occur in the arrays. The comparator is invoked
  11256. * with two arguments: (arrVal, othVal).
  11257. *
  11258. * @static
  11259. * @memberOf _
  11260. * @since 4.0.0
  11261. * @category Array
  11262. * @param {...Array} [arrays] The arrays to inspect.
  11263. * @param {Function} [comparator] The comparator invoked per element.
  11264. * @returns {Array} Returns the new array of filtered values.
  11265. * @example
  11266. *
  11267. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  11268. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  11269. *
  11270. * _.xorWith(objects, others, _.isEqual);
  11271. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  11272. */
  11273. var xorWith = baseRest(function(arrays) {
  11274. var comparator = last(arrays);
  11275. comparator = typeof comparator == 'function' ? comparator : undefined;
  11276. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  11277. });
  11278. /**
  11279. * Creates an array of grouped elements, the first of which contains the
  11280. * first elements of the given arrays, the second of which contains the
  11281. * second elements of the given arrays, and so on.
  11282. *
  11283. * @static
  11284. * @memberOf _
  11285. * @since 0.1.0
  11286. * @category Array
  11287. * @param {...Array} [arrays] The arrays to process.
  11288. * @returns {Array} Returns the new array of grouped elements.
  11289. * @example
  11290. *
  11291. * _.zip(['a', 'b'], [1, 2], [true, false]);
  11292. * // => [['a', 1, true], ['b', 2, false]]
  11293. */
  11294. var zip = baseRest(unzip);
  11295. /**
  11296. * This method is like `_.fromPairs` except that it accepts two arrays,
  11297. * one of property identifiers and one of corresponding values.
  11298. *
  11299. * @static
  11300. * @memberOf _
  11301. * @since 0.4.0
  11302. * @category Array
  11303. * @param {Array} [props=[]] The property identifiers.
  11304. * @param {Array} [values=[]] The property values.
  11305. * @returns {Object} Returns the new object.
  11306. * @example
  11307. *
  11308. * _.zipObject(['a', 'b'], [1, 2]);
  11309. * // => { 'a': 1, 'b': 2 }
  11310. */
  11311. function zipObject(props, values) {
  11312. return baseZipObject(props || [], values || [], assignValue);
  11313. }
  11314. /**
  11315. * This method is like `_.zipObject` except that it supports property paths.
  11316. *
  11317. * @static
  11318. * @memberOf _
  11319. * @since 4.1.0
  11320. * @category Array
  11321. * @param {Array} [props=[]] The property identifiers.
  11322. * @param {Array} [values=[]] The property values.
  11323. * @returns {Object} Returns the new object.
  11324. * @example
  11325. *
  11326. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  11327. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  11328. */
  11329. function zipObjectDeep(props, values) {
  11330. return baseZipObject(props || [], values || [], baseSet);
  11331. }
  11332. /**
  11333. * This method is like `_.zip` except that it accepts `iteratee` to specify
  11334. * how grouped values should be combined. The iteratee is invoked with the
  11335. * elements of each group: (...group).
  11336. *
  11337. * @static
  11338. * @memberOf _
  11339. * @since 3.8.0
  11340. * @category Array
  11341. * @param {...Array} [arrays] The arrays to process.
  11342. * @param {Function} [iteratee=_.identity] The function to combine
  11343. * grouped values.
  11344. * @returns {Array} Returns the new array of grouped elements.
  11345. * @example
  11346. *
  11347. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  11348. * return a + b + c;
  11349. * });
  11350. * // => [111, 222]
  11351. */
  11352. var zipWith = baseRest(function(arrays) {
  11353. var length = arrays.length,
  11354. iteratee = length > 1 ? arrays[length - 1] : undefined;
  11355. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  11356. return unzipWith(arrays, iteratee);
  11357. });
  11358. /*------------------------------------------------------------------------*/
  11359. /**
  11360. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  11361. * chain sequences enabled. The result of such sequences must be unwrapped
  11362. * with `_#value`.
  11363. *
  11364. * @static
  11365. * @memberOf _
  11366. * @since 1.3.0
  11367. * @category Seq
  11368. * @param {*} value The value to wrap.
  11369. * @returns {Object} Returns the new `lodash` wrapper instance.
  11370. * @example
  11371. *
  11372. * var users = [
  11373. * { 'user': 'barney', 'age': 36 },
  11374. * { 'user': 'fred', 'age': 40 },
  11375. * { 'user': 'pebbles', 'age': 1 }
  11376. * ];
  11377. *
  11378. * var youngest = _
  11379. * .chain(users)
  11380. * .sortBy('age')
  11381. * .map(function(o) {
  11382. * return o.user + ' is ' + o.age;
  11383. * })
  11384. * .head()
  11385. * .value();
  11386. * // => 'pebbles is 1'
  11387. */
  11388. function chain(value) {
  11389. var result = lodash(value);
  11390. result.__chain__ = true;
  11391. return result;
  11392. }
  11393. /**
  11394. * This method invokes `interceptor` and returns `value`. The interceptor
  11395. * is invoked with one argument; (value). The purpose of this method is to
  11396. * "tap into" a method chain sequence in order to modify intermediate results.
  11397. *
  11398. * @static
  11399. * @memberOf _
  11400. * @since 0.1.0
  11401. * @category Seq
  11402. * @param {*} value The value to provide to `interceptor`.
  11403. * @param {Function} interceptor The function to invoke.
  11404. * @returns {*} Returns `value`.
  11405. * @example
  11406. *
  11407. * _([1, 2, 3])
  11408. * .tap(function(array) {
  11409. * // Mutate input array.
  11410. * array.pop();
  11411. * })
  11412. * .reverse()
  11413. * .value();
  11414. * // => [2, 1]
  11415. */
  11416. function tap(value, interceptor) {
  11417. interceptor(value);
  11418. return value;
  11419. }
  11420. /**
  11421. * This method is like `_.tap` except that it returns the result of `interceptor`.
  11422. * The purpose of this method is to "pass thru" values replacing intermediate
  11423. * results in a method chain sequence.
  11424. *
  11425. * @static
  11426. * @memberOf _
  11427. * @since 3.0.0
  11428. * @category Seq
  11429. * @param {*} value The value to provide to `interceptor`.
  11430. * @param {Function} interceptor The function to invoke.
  11431. * @returns {*} Returns the result of `interceptor`.
  11432. * @example
  11433. *
  11434. * _(' abc ')
  11435. * .chain()
  11436. * .trim()
  11437. * .thru(function(value) {
  11438. * return [value];
  11439. * })
  11440. * .value();
  11441. * // => ['abc']
  11442. */
  11443. function thru(value, interceptor) {
  11444. return interceptor(value);
  11445. }
  11446. /**
  11447. * This method is the wrapper version of `_.at`.
  11448. *
  11449. * @name at
  11450. * @memberOf _
  11451. * @since 1.0.0
  11452. * @category Seq
  11453. * @param {...(string|string[])} [paths] The property paths to pick.
  11454. * @returns {Object} Returns the new `lodash` wrapper instance.
  11455. * @example
  11456. *
  11457. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11458. *
  11459. * _(object).at(['a[0].b.c', 'a[1]']).value();
  11460. * // => [3, 4]
  11461. */
  11462. var wrapperAt = flatRest(function(paths) {
  11463. var length = paths.length,
  11464. start = length ? paths[0] : 0,
  11465. value = this.__wrapped__,
  11466. interceptor = function(object) { return baseAt(object, paths); };
  11467. if (length > 1 || this.__actions__.length ||
  11468. !(value instanceof LazyWrapper) || !isIndex(start)) {
  11469. return this.thru(interceptor);
  11470. }
  11471. value = value.slice(start, +start + (length ? 1 : 0));
  11472. value.__actions__.push({
  11473. 'func': thru,
  11474. 'args': [interceptor],
  11475. 'thisArg': undefined
  11476. });
  11477. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  11478. if (length && !array.length) {
  11479. array.push(undefined);
  11480. }
  11481. return array;
  11482. });
  11483. });
  11484. /**
  11485. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  11486. *
  11487. * @name chain
  11488. * @memberOf _
  11489. * @since 0.1.0
  11490. * @category Seq
  11491. * @returns {Object} Returns the new `lodash` wrapper instance.
  11492. * @example
  11493. *
  11494. * var users = [
  11495. * { 'user': 'barney', 'age': 36 },
  11496. * { 'user': 'fred', 'age': 40 }
  11497. * ];
  11498. *
  11499. * // A sequence without explicit chaining.
  11500. * _(users).head();
  11501. * // => { 'user': 'barney', 'age': 36 }
  11502. *
  11503. * // A sequence with explicit chaining.
  11504. * _(users)
  11505. * .chain()
  11506. * .head()
  11507. * .pick('user')
  11508. * .value();
  11509. * // => { 'user': 'barney' }
  11510. */
  11511. function wrapperChain() {
  11512. return chain(this);
  11513. }
  11514. /**
  11515. * Executes the chain sequence and returns the wrapped result.
  11516. *
  11517. * @name commit
  11518. * @memberOf _
  11519. * @since 3.2.0
  11520. * @category Seq
  11521. * @returns {Object} Returns the new `lodash` wrapper instance.
  11522. * @example
  11523. *
  11524. * var array = [1, 2];
  11525. * var wrapped = _(array).push(3);
  11526. *
  11527. * console.log(array);
  11528. * // => [1, 2]
  11529. *
  11530. * wrapped = wrapped.commit();
  11531. * console.log(array);
  11532. * // => [1, 2, 3]
  11533. *
  11534. * wrapped.last();
  11535. * // => 3
  11536. *
  11537. * console.log(array);
  11538. * // => [1, 2, 3]
  11539. */
  11540. function wrapperCommit() {
  11541. return new LodashWrapper(this.value(), this.__chain__);
  11542. }
  11543. /**
  11544. * Gets the next value on a wrapped object following the
  11545. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  11546. *
  11547. * @name next
  11548. * @memberOf _
  11549. * @since 4.0.0
  11550. * @category Seq
  11551. * @returns {Object} Returns the next iterator value.
  11552. * @example
  11553. *
  11554. * var wrapped = _([1, 2]);
  11555. *
  11556. * wrapped.next();
  11557. * // => { 'done': false, 'value': 1 }
  11558. *
  11559. * wrapped.next();
  11560. * // => { 'done': false, 'value': 2 }
  11561. *
  11562. * wrapped.next();
  11563. * // => { 'done': true, 'value': undefined }
  11564. */
  11565. function wrapperNext() {
  11566. if (this.__values__ === undefined) {
  11567. this.__values__ = toArray(this.value());
  11568. }
  11569. var done = this.__index__ >= this.__values__.length,
  11570. value = done ? undefined : this.__values__[this.__index__++];
  11571. return { 'done': done, 'value': value };
  11572. }
  11573. /**
  11574. * Enables the wrapper to be iterable.
  11575. *
  11576. * @name Symbol.iterator
  11577. * @memberOf _
  11578. * @since 4.0.0
  11579. * @category Seq
  11580. * @returns {Object} Returns the wrapper object.
  11581. * @example
  11582. *
  11583. * var wrapped = _([1, 2]);
  11584. *
  11585. * wrapped[Symbol.iterator]() === wrapped;
  11586. * // => true
  11587. *
  11588. * Array.from(wrapped);
  11589. * // => [1, 2]
  11590. */
  11591. function wrapperToIterator() {
  11592. return this;
  11593. }
  11594. /**
  11595. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  11596. *
  11597. * @name plant
  11598. * @memberOf _
  11599. * @since 3.2.0
  11600. * @category Seq
  11601. * @param {*} value The value to plant.
  11602. * @returns {Object} Returns the new `lodash` wrapper instance.
  11603. * @example
  11604. *
  11605. * function square(n) {
  11606. * return n * n;
  11607. * }
  11608. *
  11609. * var wrapped = _([1, 2]).map(square);
  11610. * var other = wrapped.plant([3, 4]);
  11611. *
  11612. * other.value();
  11613. * // => [9, 16]
  11614. *
  11615. * wrapped.value();
  11616. * // => [1, 4]
  11617. */
  11618. function wrapperPlant(value) {
  11619. var result,
  11620. parent = this;
  11621. while (parent instanceof baseLodash) {
  11622. var clone = wrapperClone(parent);
  11623. clone.__index__ = 0;
  11624. clone.__values__ = undefined;
  11625. if (result) {
  11626. previous.__wrapped__ = clone;
  11627. } else {
  11628. result = clone;
  11629. }
  11630. var previous = clone;
  11631. parent = parent.__wrapped__;
  11632. }
  11633. previous.__wrapped__ = value;
  11634. return result;
  11635. }
  11636. /**
  11637. * This method is the wrapper version of `_.reverse`.
  11638. *
  11639. * **Note:** This method mutates the wrapped array.
  11640. *
  11641. * @name reverse
  11642. * @memberOf _
  11643. * @since 0.1.0
  11644. * @category Seq
  11645. * @returns {Object} Returns the new `lodash` wrapper instance.
  11646. * @example
  11647. *
  11648. * var array = [1, 2, 3];
  11649. *
  11650. * _(array).reverse().value()
  11651. * // => [3, 2, 1]
  11652. *
  11653. * console.log(array);
  11654. * // => [3, 2, 1]
  11655. */
  11656. function wrapperReverse() {
  11657. var value = this.__wrapped__;
  11658. if (value instanceof LazyWrapper) {
  11659. var wrapped = value;
  11660. if (this.__actions__.length) {
  11661. wrapped = new LazyWrapper(this);
  11662. }
  11663. wrapped = wrapped.reverse();
  11664. wrapped.__actions__.push({
  11665. 'func': thru,
  11666. 'args': [reverse],
  11667. 'thisArg': undefined
  11668. });
  11669. return new LodashWrapper(wrapped, this.__chain__);
  11670. }
  11671. return this.thru(reverse);
  11672. }
  11673. /**
  11674. * Executes the chain sequence to resolve the unwrapped value.
  11675. *
  11676. * @name value
  11677. * @memberOf _
  11678. * @since 0.1.0
  11679. * @alias toJSON, valueOf
  11680. * @category Seq
  11681. * @returns {*} Returns the resolved unwrapped value.
  11682. * @example
  11683. *
  11684. * _([1, 2, 3]).value();
  11685. * // => [1, 2, 3]
  11686. */
  11687. function wrapperValue() {
  11688. return baseWrapperValue(this.__wrapped__, this.__actions__);
  11689. }
  11690. /*------------------------------------------------------------------------*/
  11691. /**
  11692. * Creates an object composed of keys generated from the results of running
  11693. * each element of `collection` thru `iteratee`. The corresponding value of
  11694. * each key is the number of times the key was returned by `iteratee`. The
  11695. * iteratee is invoked with one argument: (value).
  11696. *
  11697. * @static
  11698. * @memberOf _
  11699. * @since 0.5.0
  11700. * @category Collection
  11701. * @param {Array|Object} collection The collection to iterate over.
  11702. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  11703. * @returns {Object} Returns the composed aggregate object.
  11704. * @example
  11705. *
  11706. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  11707. * // => { '4': 1, '6': 2 }
  11708. *
  11709. * // The `_.property` iteratee shorthand.
  11710. * _.countBy(['one', 'two', 'three'], 'length');
  11711. * // => { '3': 2, '5': 1 }
  11712. */
  11713. var countBy = createAggregator(function(result, value, key) {
  11714. if (hasOwnProperty.call(result, key)) {
  11715. ++result[key];
  11716. } else {
  11717. baseAssignValue(result, key, 1);
  11718. }
  11719. });
  11720. /**
  11721. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  11722. * Iteration is stopped once `predicate` returns falsey. The predicate is
  11723. * invoked with three arguments: (value, index|key, collection).
  11724. *
  11725. * **Note:** This method returns `true` for
  11726. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  11727. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  11728. * elements of empty collections.
  11729. *
  11730. * @static
  11731. * @memberOf _
  11732. * @since 0.1.0
  11733. * @category Collection
  11734. * @param {Array|Object} collection The collection to iterate over.
  11735. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11736. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  11737. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  11738. * else `false`.
  11739. * @example
  11740. *
  11741. * _.every([true, 1, null, 'yes'], Boolean);
  11742. * // => false
  11743. *
  11744. * var users = [
  11745. * { 'user': 'barney', 'age': 36, 'active': false },
  11746. * { 'user': 'fred', 'age': 40, 'active': false }
  11747. * ];
  11748. *
  11749. * // The `_.matches` iteratee shorthand.
  11750. * _.every(users, { 'user': 'barney', 'active': false });
  11751. * // => false
  11752. *
  11753. * // The `_.matchesProperty` iteratee shorthand.
  11754. * _.every(users, ['active', false]);
  11755. * // => true
  11756. *
  11757. * // The `_.property` iteratee shorthand.
  11758. * _.every(users, 'active');
  11759. * // => false
  11760. */
  11761. function every(collection, predicate, guard) {
  11762. var func = isArray(collection) ? arrayEvery : baseEvery;
  11763. if (guard && isIterateeCall(collection, predicate, guard)) {
  11764. predicate = undefined;
  11765. }
  11766. return func(collection, getIteratee(predicate, 3));
  11767. }
  11768. /**
  11769. * Iterates over elements of `collection`, returning an array of all elements
  11770. * `predicate` returns truthy for. The predicate is invoked with three
  11771. * arguments: (value, index|key, collection).
  11772. *
  11773. * **Note:** Unlike `_.remove`, this method returns a new array.
  11774. *
  11775. * @static
  11776. * @memberOf _
  11777. * @since 0.1.0
  11778. * @category Collection
  11779. * @param {Array|Object} collection The collection to iterate over.
  11780. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11781. * @returns {Array} Returns the new filtered array.
  11782. * @see _.reject
  11783. * @example
  11784. *
  11785. * var users = [
  11786. * { 'user': 'barney', 'age': 36, 'active': true },
  11787. * { 'user': 'fred', 'age': 40, 'active': false }
  11788. * ];
  11789. *
  11790. * _.filter(users, function(o) { return !o.active; });
  11791. * // => objects for ['fred']
  11792. *
  11793. * // The `_.matches` iteratee shorthand.
  11794. * _.filter(users, { 'age': 36, 'active': true });
  11795. * // => objects for ['barney']
  11796. *
  11797. * // The `_.matchesProperty` iteratee shorthand.
  11798. * _.filter(users, ['active', false]);
  11799. * // => objects for ['fred']
  11800. *
  11801. * // The `_.property` iteratee shorthand.
  11802. * _.filter(users, 'active');
  11803. * // => objects for ['barney']
  11804. *
  11805. * // Combining several predicates using `_.overEvery` or `_.overSome`.
  11806. * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
  11807. * // => objects for ['fred', 'barney']
  11808. */
  11809. function filter(collection, predicate) {
  11810. var func = isArray(collection) ? arrayFilter : baseFilter;
  11811. return func(collection, getIteratee(predicate, 3));
  11812. }
  11813. /**
  11814. * Iterates over elements of `collection`, returning the first element
  11815. * `predicate` returns truthy for. The predicate is invoked with three
  11816. * arguments: (value, index|key, collection).
  11817. *
  11818. * @static
  11819. * @memberOf _
  11820. * @since 0.1.0
  11821. * @category Collection
  11822. * @param {Array|Object} collection The collection to inspect.
  11823. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11824. * @param {number} [fromIndex=0] The index to search from.
  11825. * @returns {*} Returns the matched element, else `undefined`.
  11826. * @example
  11827. *
  11828. * var users = [
  11829. * { 'user': 'barney', 'age': 36, 'active': true },
  11830. * { 'user': 'fred', 'age': 40, 'active': false },
  11831. * { 'user': 'pebbles', 'age': 1, 'active': true }
  11832. * ];
  11833. *
  11834. * _.find(users, function(o) { return o.age < 40; });
  11835. * // => object for 'barney'
  11836. *
  11837. * // The `_.matches` iteratee shorthand.
  11838. * _.find(users, { 'age': 1, 'active': true });
  11839. * // => object for 'pebbles'
  11840. *
  11841. * // The `_.matchesProperty` iteratee shorthand.
  11842. * _.find(users, ['active', false]);
  11843. * // => object for 'fred'
  11844. *
  11845. * // The `_.property` iteratee shorthand.
  11846. * _.find(users, 'active');
  11847. * // => object for 'barney'
  11848. */
  11849. var find = createFind(findIndex);
  11850. /**
  11851. * This method is like `_.find` except that it iterates over elements of
  11852. * `collection` from right to left.
  11853. *
  11854. * @static
  11855. * @memberOf _
  11856. * @since 2.0.0
  11857. * @category Collection
  11858. * @param {Array|Object} collection The collection to inspect.
  11859. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11860. * @param {number} [fromIndex=collection.length-1] The index to search from.
  11861. * @returns {*} Returns the matched element, else `undefined`.
  11862. * @example
  11863. *
  11864. * _.findLast([1, 2, 3, 4], function(n) {
  11865. * return n % 2 == 1;
  11866. * });
  11867. * // => 3
  11868. */
  11869. var findLast = createFind(findLastIndex);
  11870. /**
  11871. * Creates a flattened array of values by running each element in `collection`
  11872. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  11873. * with three arguments: (value, index|key, collection).
  11874. *
  11875. * @static
  11876. * @memberOf _
  11877. * @since 4.0.0
  11878. * @category Collection
  11879. * @param {Array|Object} collection The collection to iterate over.
  11880. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11881. * @returns {Array} Returns the new flattened array.
  11882. * @example
  11883. *
  11884. * function duplicate(n) {
  11885. * return [n, n];
  11886. * }
  11887. *
  11888. * _.flatMap([1, 2], duplicate);
  11889. * // => [1, 1, 2, 2]
  11890. */
  11891. function flatMap(collection, iteratee) {
  11892. return baseFlatten(map(collection, iteratee), 1);
  11893. }
  11894. /**
  11895. * This method is like `_.flatMap` except that it recursively flattens the
  11896. * mapped results.
  11897. *
  11898. * @static
  11899. * @memberOf _
  11900. * @since 4.7.0
  11901. * @category Collection
  11902. * @param {Array|Object} collection The collection to iterate over.
  11903. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11904. * @returns {Array} Returns the new flattened array.
  11905. * @example
  11906. *
  11907. * function duplicate(n) {
  11908. * return [[[n, n]]];
  11909. * }
  11910. *
  11911. * _.flatMapDeep([1, 2], duplicate);
  11912. * // => [1, 1, 2, 2]
  11913. */
  11914. function flatMapDeep(collection, iteratee) {
  11915. return baseFlatten(map(collection, iteratee), INFINITY);
  11916. }
  11917. /**
  11918. * This method is like `_.flatMap` except that it recursively flattens the
  11919. * mapped results up to `depth` times.
  11920. *
  11921. * @static
  11922. * @memberOf _
  11923. * @since 4.7.0
  11924. * @category Collection
  11925. * @param {Array|Object} collection The collection to iterate over.
  11926. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11927. * @param {number} [depth=1] The maximum recursion depth.
  11928. * @returns {Array} Returns the new flattened array.
  11929. * @example
  11930. *
  11931. * function duplicate(n) {
  11932. * return [[[n, n]]];
  11933. * }
  11934. *
  11935. * _.flatMapDepth([1, 2], duplicate, 2);
  11936. * // => [[1, 1], [2, 2]]
  11937. */
  11938. function flatMapDepth(collection, iteratee, depth) {
  11939. depth = depth === undefined ? 1 : toInteger(depth);
  11940. return baseFlatten(map(collection, iteratee), depth);
  11941. }
  11942. /**
  11943. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  11944. * The iteratee is invoked with three arguments: (value, index|key, collection).
  11945. * Iteratee functions may exit iteration early by explicitly returning `false`.
  11946. *
  11947. * **Note:** As with other "Collections" methods, objects with a "length"
  11948. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  11949. * or `_.forOwn` for object iteration.
  11950. *
  11951. * @static
  11952. * @memberOf _
  11953. * @since 0.1.0
  11954. * @alias each
  11955. * @category Collection
  11956. * @param {Array|Object} collection The collection to iterate over.
  11957. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11958. * @returns {Array|Object} Returns `collection`.
  11959. * @see _.forEachRight
  11960. * @example
  11961. *
  11962. * _.forEach([1, 2], function(value) {
  11963. * console.log(value);
  11964. * });
  11965. * // => Logs `1` then `2`.
  11966. *
  11967. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  11968. * console.log(key);
  11969. * });
  11970. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  11971. */
  11972. function forEach(collection, iteratee) {
  11973. var func = isArray(collection) ? arrayEach : baseEach;
  11974. return func(collection, getIteratee(iteratee, 3));
  11975. }
  11976. /**
  11977. * This method is like `_.forEach` except that it iterates over elements of
  11978. * `collection` from right to left.
  11979. *
  11980. * @static
  11981. * @memberOf _
  11982. * @since 2.0.0
  11983. * @alias eachRight
  11984. * @category Collection
  11985. * @param {Array|Object} collection The collection to iterate over.
  11986. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11987. * @returns {Array|Object} Returns `collection`.
  11988. * @see _.forEach
  11989. * @example
  11990. *
  11991. * _.forEachRight([1, 2], function(value) {
  11992. * console.log(value);
  11993. * });
  11994. * // => Logs `2` then `1`.
  11995. */
  11996. function forEachRight(collection, iteratee) {
  11997. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  11998. return func(collection, getIteratee(iteratee, 3));
  11999. }
  12000. /**
  12001. * Creates an object composed of keys generated from the results of running
  12002. * each element of `collection` thru `iteratee`. The order of grouped values
  12003. * is determined by the order they occur in `collection`. The corresponding
  12004. * value of each key is an array of elements responsible for generating the
  12005. * key. The iteratee is invoked with one argument: (value).
  12006. *
  12007. * @static
  12008. * @memberOf _
  12009. * @since 0.1.0
  12010. * @category Collection
  12011. * @param {Array|Object} collection The collection to iterate over.
  12012. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  12013. * @returns {Object} Returns the composed aggregate object.
  12014. * @example
  12015. *
  12016. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  12017. * // => { '4': [4.2], '6': [6.1, 6.3] }
  12018. *
  12019. * // The `_.property` iteratee shorthand.
  12020. * _.groupBy(['one', 'two', 'three'], 'length');
  12021. * // => { '3': ['one', 'two'], '5': ['three'] }
  12022. */
  12023. var groupBy = createAggregator(function(result, value, key) {
  12024. if (hasOwnProperty.call(result, key)) {
  12025. result[key].push(value);
  12026. } else {
  12027. baseAssignValue(result, key, [value]);
  12028. }
  12029. });
  12030. /**
  12031. * Checks if `value` is in `collection`. If `collection` is a string, it's
  12032. * checked for a substring of `value`, otherwise
  12033. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  12034. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  12035. * the offset from the end of `collection`.
  12036. *
  12037. * @static
  12038. * @memberOf _
  12039. * @since 0.1.0
  12040. * @category Collection
  12041. * @param {Array|Object|string} collection The collection to inspect.
  12042. * @param {*} value The value to search for.
  12043. * @param {number} [fromIndex=0] The index to search from.
  12044. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  12045. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  12046. * @example
  12047. *
  12048. * _.includes([1, 2, 3], 1);
  12049. * // => true
  12050. *
  12051. * _.includes([1, 2, 3], 1, 2);
  12052. * // => false
  12053. *
  12054. * _.includes({ 'a': 1, 'b': 2 }, 1);
  12055. * // => true
  12056. *
  12057. * _.includes('abcd', 'bc');
  12058. * // => true
  12059. */
  12060. function includes(collection, value, fromIndex, guard) {
  12061. collection = isArrayLike(collection) ? collection : values(collection);
  12062. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  12063. var length = collection.length;
  12064. if (fromIndex < 0) {
  12065. fromIndex = nativeMax(length + fromIndex, 0);
  12066. }
  12067. return isString(collection)
  12068. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  12069. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  12070. }
  12071. /**
  12072. * Invokes the method at `path` of each element in `collection`, returning
  12073. * an array of the results of each invoked method. Any additional arguments
  12074. * are provided to each invoked method. If `path` is a function, it's invoked
  12075. * for, and `this` bound to, each element in `collection`.
  12076. *
  12077. * @static
  12078. * @memberOf _
  12079. * @since 4.0.0
  12080. * @category Collection
  12081. * @param {Array|Object} collection The collection to iterate over.
  12082. * @param {Array|Function|string} path The path of the method to invoke or
  12083. * the function invoked per iteration.
  12084. * @param {...*} [args] The arguments to invoke each method with.
  12085. * @returns {Array} Returns the array of results.
  12086. * @example
  12087. *
  12088. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  12089. * // => [[1, 5, 7], [1, 2, 3]]
  12090. *
  12091. * _.invokeMap([123, 456], String.prototype.split, '');
  12092. * // => [['1', '2', '3'], ['4', '5', '6']]
  12093. */
  12094. var invokeMap = baseRest(function(collection, path, args) {
  12095. var index = -1,
  12096. isFunc = typeof path == 'function',
  12097. result = isArrayLike(collection) ? Array(collection.length) : [];
  12098. baseEach(collection, function(value) {
  12099. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  12100. });
  12101. return result;
  12102. });
  12103. /**
  12104. * Creates an object composed of keys generated from the results of running
  12105. * each element of `collection` thru `iteratee`. The corresponding value of
  12106. * each key is the last element responsible for generating the key. The
  12107. * iteratee is invoked with one argument: (value).
  12108. *
  12109. * @static
  12110. * @memberOf _
  12111. * @since 4.0.0
  12112. * @category Collection
  12113. * @param {Array|Object} collection The collection to iterate over.
  12114. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  12115. * @returns {Object} Returns the composed aggregate object.
  12116. * @example
  12117. *
  12118. * var array = [
  12119. * { 'dir': 'left', 'code': 97 },
  12120. * { 'dir': 'right', 'code': 100 }
  12121. * ];
  12122. *
  12123. * _.keyBy(array, function(o) {
  12124. * return String.fromCharCode(o.code);
  12125. * });
  12126. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  12127. *
  12128. * _.keyBy(array, 'dir');
  12129. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  12130. */
  12131. var keyBy = createAggregator(function(result, value, key) {
  12132. baseAssignValue(result, key, value);
  12133. });
  12134. /**
  12135. * Creates an array of values by running each element in `collection` thru
  12136. * `iteratee`. The iteratee is invoked with three arguments:
  12137. * (value, index|key, collection).
  12138. *
  12139. * Many lodash methods are guarded to work as iteratees for methods like
  12140. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  12141. *
  12142. * The guarded methods are:
  12143. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  12144. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  12145. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  12146. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  12147. *
  12148. * @static
  12149. * @memberOf _
  12150. * @since 0.1.0
  12151. * @category Collection
  12152. * @param {Array|Object} collection The collection to iterate over.
  12153. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12154. * @returns {Array} Returns the new mapped array.
  12155. * @example
  12156. *
  12157. * function square(n) {
  12158. * return n * n;
  12159. * }
  12160. *
  12161. * _.map([4, 8], square);
  12162. * // => [16, 64]
  12163. *
  12164. * _.map({ 'a': 4, 'b': 8 }, square);
  12165. * // => [16, 64] (iteration order is not guaranteed)
  12166. *
  12167. * var users = [
  12168. * { 'user': 'barney' },
  12169. * { 'user': 'fred' }
  12170. * ];
  12171. *
  12172. * // The `_.property` iteratee shorthand.
  12173. * _.map(users, 'user');
  12174. * // => ['barney', 'fred']
  12175. */
  12176. function map(collection, iteratee) {
  12177. var func = isArray(collection) ? arrayMap : baseMap;
  12178. return func(collection, getIteratee(iteratee, 3));
  12179. }
  12180. /**
  12181. * This method is like `_.sortBy` except that it allows specifying the sort
  12182. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  12183. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  12184. * descending or "asc" for ascending sort order of corresponding values.
  12185. *
  12186. * @static
  12187. * @memberOf _
  12188. * @since 4.0.0
  12189. * @category Collection
  12190. * @param {Array|Object} collection The collection to iterate over.
  12191. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  12192. * The iteratees to sort by.
  12193. * @param {string[]} [orders] The sort orders of `iteratees`.
  12194. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  12195. * @returns {Array} Returns the new sorted array.
  12196. * @example
  12197. *
  12198. * var users = [
  12199. * { 'user': 'fred', 'age': 48 },
  12200. * { 'user': 'barney', 'age': 34 },
  12201. * { 'user': 'fred', 'age': 40 },
  12202. * { 'user': 'barney', 'age': 36 }
  12203. * ];
  12204. *
  12205. * // Sort by `user` in ascending order and by `age` in descending order.
  12206. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  12207. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  12208. */
  12209. function orderBy(collection, iteratees, orders, guard) {
  12210. if (collection == null) {
  12211. return [];
  12212. }
  12213. if (!isArray(iteratees)) {
  12214. iteratees = iteratees == null ? [] : [iteratees];
  12215. }
  12216. orders = guard ? undefined : orders;
  12217. if (!isArray(orders)) {
  12218. orders = orders == null ? [] : [orders];
  12219. }
  12220. return baseOrderBy(collection, iteratees, orders);
  12221. }
  12222. /**
  12223. * Creates an array of elements split into two groups, the first of which
  12224. * contains elements `predicate` returns truthy for, the second of which
  12225. * contains elements `predicate` returns falsey for. The predicate is
  12226. * invoked with one argument: (value).
  12227. *
  12228. * @static
  12229. * @memberOf _
  12230. * @since 3.0.0
  12231. * @category Collection
  12232. * @param {Array|Object} collection The collection to iterate over.
  12233. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12234. * @returns {Array} Returns the array of grouped elements.
  12235. * @example
  12236. *
  12237. * var users = [
  12238. * { 'user': 'barney', 'age': 36, 'active': false },
  12239. * { 'user': 'fred', 'age': 40, 'active': true },
  12240. * { 'user': 'pebbles', 'age': 1, 'active': false }
  12241. * ];
  12242. *
  12243. * _.partition(users, function(o) { return o.active; });
  12244. * // => objects for [['fred'], ['barney', 'pebbles']]
  12245. *
  12246. * // The `_.matches` iteratee shorthand.
  12247. * _.partition(users, { 'age': 1, 'active': false });
  12248. * // => objects for [['pebbles'], ['barney', 'fred']]
  12249. *
  12250. * // The `_.matchesProperty` iteratee shorthand.
  12251. * _.partition(users, ['active', false]);
  12252. * // => objects for [['barney', 'pebbles'], ['fred']]
  12253. *
  12254. * // The `_.property` iteratee shorthand.
  12255. * _.partition(users, 'active');
  12256. * // => objects for [['fred'], ['barney', 'pebbles']]
  12257. */
  12258. var partition = createAggregator(function(result, value, key) {
  12259. result[key ? 0 : 1].push(value);
  12260. }, function() { return [[], []]; });
  12261. /**
  12262. * Reduces `collection` to a value which is the accumulated result of running
  12263. * each element in `collection` thru `iteratee`, where each successive
  12264. * invocation is supplied the return value of the previous. If `accumulator`
  12265. * is not given, the first element of `collection` is used as the initial
  12266. * value. The iteratee is invoked with four arguments:
  12267. * (accumulator, value, index|key, collection).
  12268. *
  12269. * Many lodash methods are guarded to work as iteratees for methods like
  12270. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  12271. *
  12272. * The guarded methods are:
  12273. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  12274. * and `sortBy`
  12275. *
  12276. * @static
  12277. * @memberOf _
  12278. * @since 0.1.0
  12279. * @category Collection
  12280. * @param {Array|Object} collection The collection to iterate over.
  12281. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12282. * @param {*} [accumulator] The initial value.
  12283. * @returns {*} Returns the accumulated value.
  12284. * @see _.reduceRight
  12285. * @example
  12286. *
  12287. * _.reduce([1, 2], function(sum, n) {
  12288. * return sum + n;
  12289. * }, 0);
  12290. * // => 3
  12291. *
  12292. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12293. * (result[value] || (result[value] = [])).push(key);
  12294. * return result;
  12295. * }, {});
  12296. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  12297. */
  12298. function reduce(collection, iteratee, accumulator) {
  12299. var func = isArray(collection) ? arrayReduce : baseReduce,
  12300. initAccum = arguments.length < 3;
  12301. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  12302. }
  12303. /**
  12304. * This method is like `_.reduce` except that it iterates over elements of
  12305. * `collection` from right to left.
  12306. *
  12307. * @static
  12308. * @memberOf _
  12309. * @since 0.1.0
  12310. * @category Collection
  12311. * @param {Array|Object} collection The collection to iterate over.
  12312. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12313. * @param {*} [accumulator] The initial value.
  12314. * @returns {*} Returns the accumulated value.
  12315. * @see _.reduce
  12316. * @example
  12317. *
  12318. * var array = [[0, 1], [2, 3], [4, 5]];
  12319. *
  12320. * _.reduceRight(array, function(flattened, other) {
  12321. * return flattened.concat(other);
  12322. * }, []);
  12323. * // => [4, 5, 2, 3, 0, 1]
  12324. */
  12325. function reduceRight(collection, iteratee, accumulator) {
  12326. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  12327. initAccum = arguments.length < 3;
  12328. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  12329. }
  12330. /**
  12331. * The opposite of `_.filter`; this method returns the elements of `collection`
  12332. * that `predicate` does **not** return truthy for.
  12333. *
  12334. * @static
  12335. * @memberOf _
  12336. * @since 0.1.0
  12337. * @category Collection
  12338. * @param {Array|Object} collection The collection to iterate over.
  12339. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12340. * @returns {Array} Returns the new filtered array.
  12341. * @see _.filter
  12342. * @example
  12343. *
  12344. * var users = [
  12345. * { 'user': 'barney', 'age': 36, 'active': false },
  12346. * { 'user': 'fred', 'age': 40, 'active': true }
  12347. * ];
  12348. *
  12349. * _.reject(users, function(o) { return !o.active; });
  12350. * // => objects for ['fred']
  12351. *
  12352. * // The `_.matches` iteratee shorthand.
  12353. * _.reject(users, { 'age': 40, 'active': true });
  12354. * // => objects for ['barney']
  12355. *
  12356. * // The `_.matchesProperty` iteratee shorthand.
  12357. * _.reject(users, ['active', false]);
  12358. * // => objects for ['fred']
  12359. *
  12360. * // The `_.property` iteratee shorthand.
  12361. * _.reject(users, 'active');
  12362. * // => objects for ['barney']
  12363. */
  12364. function reject(collection, predicate) {
  12365. var func = isArray(collection) ? arrayFilter : baseFilter;
  12366. return func(collection, negate(getIteratee(predicate, 3)));
  12367. }
  12368. /**
  12369. * Gets a random element from `collection`.
  12370. *
  12371. * @static
  12372. * @memberOf _
  12373. * @since 2.0.0
  12374. * @category Collection
  12375. * @param {Array|Object} collection The collection to sample.
  12376. * @returns {*} Returns the random element.
  12377. * @example
  12378. *
  12379. * _.sample([1, 2, 3, 4]);
  12380. * // => 2
  12381. */
  12382. function sample(collection) {
  12383. var func = isArray(collection) ? arraySample : baseSample;
  12384. return func(collection);
  12385. }
  12386. /**
  12387. * Gets `n` random elements at unique keys from `collection` up to the
  12388. * size of `collection`.
  12389. *
  12390. * @static
  12391. * @memberOf _
  12392. * @since 4.0.0
  12393. * @category Collection
  12394. * @param {Array|Object} collection The collection to sample.
  12395. * @param {number} [n=1] The number of elements to sample.
  12396. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  12397. * @returns {Array} Returns the random elements.
  12398. * @example
  12399. *
  12400. * _.sampleSize([1, 2, 3], 2);
  12401. * // => [3, 1]
  12402. *
  12403. * _.sampleSize([1, 2, 3], 4);
  12404. * // => [2, 3, 1]
  12405. */
  12406. function sampleSize(collection, n, guard) {
  12407. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  12408. n = 1;
  12409. } else {
  12410. n = toInteger(n);
  12411. }
  12412. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  12413. return func(collection, n);
  12414. }
  12415. /**
  12416. * Creates an array of shuffled values, using a version of the
  12417. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  12418. *
  12419. * @static
  12420. * @memberOf _
  12421. * @since 0.1.0
  12422. * @category Collection
  12423. * @param {Array|Object} collection The collection to shuffle.
  12424. * @returns {Array} Returns the new shuffled array.
  12425. * @example
  12426. *
  12427. * _.shuffle([1, 2, 3, 4]);
  12428. * // => [4, 1, 3, 2]
  12429. */
  12430. function shuffle(collection) {
  12431. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  12432. return func(collection);
  12433. }
  12434. /**
  12435. * Gets the size of `collection` by returning its length for array-like
  12436. * values or the number of own enumerable string keyed properties for objects.
  12437. *
  12438. * @static
  12439. * @memberOf _
  12440. * @since 0.1.0
  12441. * @category Collection
  12442. * @param {Array|Object|string} collection The collection to inspect.
  12443. * @returns {number} Returns the collection size.
  12444. * @example
  12445. *
  12446. * _.size([1, 2, 3]);
  12447. * // => 3
  12448. *
  12449. * _.size({ 'a': 1, 'b': 2 });
  12450. * // => 2
  12451. *
  12452. * _.size('pebbles');
  12453. * // => 7
  12454. */
  12455. function size(collection) {
  12456. if (collection == null) {
  12457. return 0;
  12458. }
  12459. if (isArrayLike(collection)) {
  12460. return isString(collection) ? stringSize(collection) : collection.length;
  12461. }
  12462. var tag = getTag(collection);
  12463. if (tag == mapTag || tag == setTag) {
  12464. return collection.size;
  12465. }
  12466. return baseKeys(collection).length;
  12467. }
  12468. /**
  12469. * Checks if `predicate` returns truthy for **any** element of `collection`.
  12470. * Iteration is stopped once `predicate` returns truthy. The predicate is
  12471. * invoked with three arguments: (value, index|key, collection).
  12472. *
  12473. * @static
  12474. * @memberOf _
  12475. * @since 0.1.0
  12476. * @category Collection
  12477. * @param {Array|Object} collection The collection to iterate over.
  12478. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12479. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  12480. * @returns {boolean} Returns `true` if any element passes the predicate check,
  12481. * else `false`.
  12482. * @example
  12483. *
  12484. * _.some([null, 0, 'yes', false], Boolean);
  12485. * // => true
  12486. *
  12487. * var users = [
  12488. * { 'user': 'barney', 'active': true },
  12489. * { 'user': 'fred', 'active': false }
  12490. * ];
  12491. *
  12492. * // The `_.matches` iteratee shorthand.
  12493. * _.some(users, { 'user': 'barney', 'active': false });
  12494. * // => false
  12495. *
  12496. * // The `_.matchesProperty` iteratee shorthand.
  12497. * _.some(users, ['active', false]);
  12498. * // => true
  12499. *
  12500. * // The `_.property` iteratee shorthand.
  12501. * _.some(users, 'active');
  12502. * // => true
  12503. */
  12504. function some(collection, predicate, guard) {
  12505. var func = isArray(collection) ? arraySome : baseSome;
  12506. if (guard && isIterateeCall(collection, predicate, guard)) {
  12507. predicate = undefined;
  12508. }
  12509. return func(collection, getIteratee(predicate, 3));
  12510. }
  12511. /**
  12512. * Creates an array of elements, sorted in ascending order by the results of
  12513. * running each element in a collection thru each iteratee. This method
  12514. * performs a stable sort, that is, it preserves the original sort order of
  12515. * equal elements. The iteratees are invoked with one argument: (value).
  12516. *
  12517. * @static
  12518. * @memberOf _
  12519. * @since 0.1.0
  12520. * @category Collection
  12521. * @param {Array|Object} collection The collection to iterate over.
  12522. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  12523. * The iteratees to sort by.
  12524. * @returns {Array} Returns the new sorted array.
  12525. * @example
  12526. *
  12527. * var users = [
  12528. * { 'user': 'fred', 'age': 48 },
  12529. * { 'user': 'barney', 'age': 36 },
  12530. * { 'user': 'fred', 'age': 30 },
  12531. * { 'user': 'barney', 'age': 34 }
  12532. * ];
  12533. *
  12534. * _.sortBy(users, [function(o) { return o.user; }]);
  12535. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
  12536. *
  12537. * _.sortBy(users, ['user', 'age']);
  12538. * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
  12539. */
  12540. var sortBy = baseRest(function(collection, iteratees) {
  12541. if (collection == null) {
  12542. return [];
  12543. }
  12544. var length = iteratees.length;
  12545. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  12546. iteratees = [];
  12547. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  12548. iteratees = [iteratees[0]];
  12549. }
  12550. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  12551. });
  12552. /*------------------------------------------------------------------------*/
  12553. /**
  12554. * Gets the timestamp of the number of milliseconds that have elapsed since
  12555. * the Unix epoch (1 January 1970 00:00:00 UTC).
  12556. *
  12557. * @static
  12558. * @memberOf _
  12559. * @since 2.4.0
  12560. * @category Date
  12561. * @returns {number} Returns the timestamp.
  12562. * @example
  12563. *
  12564. * _.defer(function(stamp) {
  12565. * console.log(_.now() - stamp);
  12566. * }, _.now());
  12567. * // => Logs the number of milliseconds it took for the deferred invocation.
  12568. */
  12569. var now = ctxNow || function() {
  12570. return root.Date.now();
  12571. };
  12572. /*------------------------------------------------------------------------*/
  12573. /**
  12574. * The opposite of `_.before`; this method creates a function that invokes
  12575. * `func` once it's called `n` or more times.
  12576. *
  12577. * @static
  12578. * @memberOf _
  12579. * @since 0.1.0
  12580. * @category Function
  12581. * @param {number} n The number of calls before `func` is invoked.
  12582. * @param {Function} func The function to restrict.
  12583. * @returns {Function} Returns the new restricted function.
  12584. * @example
  12585. *
  12586. * var saves = ['profile', 'settings'];
  12587. *
  12588. * var done = _.after(saves.length, function() {
  12589. * console.log('done saving!');
  12590. * });
  12591. *
  12592. * _.forEach(saves, function(type) {
  12593. * asyncSave({ 'type': type, 'complete': done });
  12594. * });
  12595. * // => Logs 'done saving!' after the two async saves have completed.
  12596. */
  12597. function after(n, func) {
  12598. if (typeof func != 'function') {
  12599. throw new TypeError(FUNC_ERROR_TEXT);
  12600. }
  12601. n = toInteger(n);
  12602. return function() {
  12603. if (--n < 1) {
  12604. return func.apply(this, arguments);
  12605. }
  12606. };
  12607. }
  12608. /**
  12609. * Creates a function that invokes `func`, with up to `n` arguments,
  12610. * ignoring any additional arguments.
  12611. *
  12612. * @static
  12613. * @memberOf _
  12614. * @since 3.0.0
  12615. * @category Function
  12616. * @param {Function} func The function to cap arguments for.
  12617. * @param {number} [n=func.length] The arity cap.
  12618. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  12619. * @returns {Function} Returns the new capped function.
  12620. * @example
  12621. *
  12622. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  12623. * // => [6, 8, 10]
  12624. */
  12625. function ary(func, n, guard) {
  12626. n = guard ? undefined : n;
  12627. n = (func && n == null) ? func.length : n;
  12628. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  12629. }
  12630. /**
  12631. * Creates a function that invokes `func`, with the `this` binding and arguments
  12632. * of the created function, while it's called less than `n` times. Subsequent
  12633. * calls to the created function return the result of the last `func` invocation.
  12634. *
  12635. * @static
  12636. * @memberOf _
  12637. * @since 3.0.0
  12638. * @category Function
  12639. * @param {number} n The number of calls at which `func` is no longer invoked.
  12640. * @param {Function} func The function to restrict.
  12641. * @returns {Function} Returns the new restricted function.
  12642. * @example
  12643. *
  12644. * jQuery(element).on('click', _.before(5, addContactToList));
  12645. * // => Allows adding up to 4 contacts to the list.
  12646. */
  12647. function before(n, func) {
  12648. var result;
  12649. if (typeof func != 'function') {
  12650. throw new TypeError(FUNC_ERROR_TEXT);
  12651. }
  12652. n = toInteger(n);
  12653. return function() {
  12654. if (--n > 0) {
  12655. result = func.apply(this, arguments);
  12656. }
  12657. if (n <= 1) {
  12658. func = undefined;
  12659. }
  12660. return result;
  12661. };
  12662. }
  12663. /**
  12664. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  12665. * and `partials` prepended to the arguments it receives.
  12666. *
  12667. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  12668. * may be used as a placeholder for partially applied arguments.
  12669. *
  12670. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  12671. * property of bound functions.
  12672. *
  12673. * @static
  12674. * @memberOf _
  12675. * @since 0.1.0
  12676. * @category Function
  12677. * @param {Function} func The function to bind.
  12678. * @param {*} thisArg The `this` binding of `func`.
  12679. * @param {...*} [partials] The arguments to be partially applied.
  12680. * @returns {Function} Returns the new bound function.
  12681. * @example
  12682. *
  12683. * function greet(greeting, punctuation) {
  12684. * return greeting + ' ' + this.user + punctuation;
  12685. * }
  12686. *
  12687. * var object = { 'user': 'fred' };
  12688. *
  12689. * var bound = _.bind(greet, object, 'hi');
  12690. * bound('!');
  12691. * // => 'hi fred!'
  12692. *
  12693. * // Bound with placeholders.
  12694. * var bound = _.bind(greet, object, _, '!');
  12695. * bound('hi');
  12696. * // => 'hi fred!'
  12697. */
  12698. var bind = baseRest(function(func, thisArg, partials) {
  12699. var bitmask = WRAP_BIND_FLAG;
  12700. if (partials.length) {
  12701. var holders = replaceHolders(partials, getHolder(bind));
  12702. bitmask |= WRAP_PARTIAL_FLAG;
  12703. }
  12704. return createWrap(func, bitmask, thisArg, partials, holders);
  12705. });
  12706. /**
  12707. * Creates a function that invokes the method at `object[key]` with `partials`
  12708. * prepended to the arguments it receives.
  12709. *
  12710. * This method differs from `_.bind` by allowing bound functions to reference
  12711. * methods that may be redefined or don't yet exist. See
  12712. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  12713. * for more details.
  12714. *
  12715. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  12716. * builds, may be used as a placeholder for partially applied arguments.
  12717. *
  12718. * @static
  12719. * @memberOf _
  12720. * @since 0.10.0
  12721. * @category Function
  12722. * @param {Object} object The object to invoke the method on.
  12723. * @param {string} key The key of the method.
  12724. * @param {...*} [partials] The arguments to be partially applied.
  12725. * @returns {Function} Returns the new bound function.
  12726. * @example
  12727. *
  12728. * var object = {
  12729. * 'user': 'fred',
  12730. * 'greet': function(greeting, punctuation) {
  12731. * return greeting + ' ' + this.user + punctuation;
  12732. * }
  12733. * };
  12734. *
  12735. * var bound = _.bindKey(object, 'greet', 'hi');
  12736. * bound('!');
  12737. * // => 'hi fred!'
  12738. *
  12739. * object.greet = function(greeting, punctuation) {
  12740. * return greeting + 'ya ' + this.user + punctuation;
  12741. * };
  12742. *
  12743. * bound('!');
  12744. * // => 'hiya fred!'
  12745. *
  12746. * // Bound with placeholders.
  12747. * var bound = _.bindKey(object, 'greet', _, '!');
  12748. * bound('hi');
  12749. * // => 'hiya fred!'
  12750. */
  12751. var bindKey = baseRest(function(object, key, partials) {
  12752. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  12753. if (partials.length) {
  12754. var holders = replaceHolders(partials, getHolder(bindKey));
  12755. bitmask |= WRAP_PARTIAL_FLAG;
  12756. }
  12757. return createWrap(key, bitmask, object, partials, holders);
  12758. });
  12759. /**
  12760. * Creates a function that accepts arguments of `func` and either invokes
  12761. * `func` returning its result, if at least `arity` number of arguments have
  12762. * been provided, or returns a function that accepts the remaining `func`
  12763. * arguments, and so on. The arity of `func` may be specified if `func.length`
  12764. * is not sufficient.
  12765. *
  12766. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  12767. * may be used as a placeholder for provided arguments.
  12768. *
  12769. * **Note:** This method doesn't set the "length" property of curried functions.
  12770. *
  12771. * @static
  12772. * @memberOf _
  12773. * @since 2.0.0
  12774. * @category Function
  12775. * @param {Function} func The function to curry.
  12776. * @param {number} [arity=func.length] The arity of `func`.
  12777. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  12778. * @returns {Function} Returns the new curried function.
  12779. * @example
  12780. *
  12781. * var abc = function(a, b, c) {
  12782. * return [a, b, c];
  12783. * };
  12784. *
  12785. * var curried = _.curry(abc);
  12786. *
  12787. * curried(1)(2)(3);
  12788. * // => [1, 2, 3]
  12789. *
  12790. * curried(1, 2)(3);
  12791. * // => [1, 2, 3]
  12792. *
  12793. * curried(1, 2, 3);
  12794. * // => [1, 2, 3]
  12795. *
  12796. * // Curried with placeholders.
  12797. * curried(1)(_, 3)(2);
  12798. * // => [1, 2, 3]
  12799. */
  12800. function curry(func, arity, guard) {
  12801. arity = guard ? undefined : arity;
  12802. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  12803. result.placeholder = curry.placeholder;
  12804. return result;
  12805. }
  12806. /**
  12807. * This method is like `_.curry` except that arguments are applied to `func`
  12808. * in the manner of `_.partialRight` instead of `_.partial`.
  12809. *
  12810. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  12811. * builds, may be used as a placeholder for provided arguments.
  12812. *
  12813. * **Note:** This method doesn't set the "length" property of curried functions.
  12814. *
  12815. * @static
  12816. * @memberOf _
  12817. * @since 3.0.0
  12818. * @category Function
  12819. * @param {Function} func The function to curry.
  12820. * @param {number} [arity=func.length] The arity of `func`.
  12821. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  12822. * @returns {Function} Returns the new curried function.
  12823. * @example
  12824. *
  12825. * var abc = function(a, b, c) {
  12826. * return [a, b, c];
  12827. * };
  12828. *
  12829. * var curried = _.curryRight(abc);
  12830. *
  12831. * curried(3)(2)(1);
  12832. * // => [1, 2, 3]
  12833. *
  12834. * curried(2, 3)(1);
  12835. * // => [1, 2, 3]
  12836. *
  12837. * curried(1, 2, 3);
  12838. * // => [1, 2, 3]
  12839. *
  12840. * // Curried with placeholders.
  12841. * curried(3)(1, _)(2);
  12842. * // => [1, 2, 3]
  12843. */
  12844. function curryRight(func, arity, guard) {
  12845. arity = guard ? undefined : arity;
  12846. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  12847. result.placeholder = curryRight.placeholder;
  12848. return result;
  12849. }
  12850. /**
  12851. * Creates a debounced function that delays invoking `func` until after `wait`
  12852. * milliseconds have elapsed since the last time the debounced function was
  12853. * invoked. The debounced function comes with a `cancel` method to cancel
  12854. * delayed `func` invocations and a `flush` method to immediately invoke them.
  12855. * Provide `options` to indicate whether `func` should be invoked on the
  12856. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  12857. * with the last arguments provided to the debounced function. Subsequent
  12858. * calls to the debounced function return the result of the last `func`
  12859. * invocation.
  12860. *
  12861. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  12862. * invoked on the trailing edge of the timeout only if the debounced function
  12863. * is invoked more than once during the `wait` timeout.
  12864. *
  12865. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  12866. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  12867. *
  12868. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  12869. * for details over the differences between `_.debounce` and `_.throttle`.
  12870. *
  12871. * @static
  12872. * @memberOf _
  12873. * @since 0.1.0
  12874. * @category Function
  12875. * @param {Function} func The function to debounce.
  12876. * @param {number} [wait=0] The number of milliseconds to delay.
  12877. * @param {Object} [options={}] The options object.
  12878. * @param {boolean} [options.leading=false]
  12879. * Specify invoking on the leading edge of the timeout.
  12880. * @param {number} [options.maxWait]
  12881. * The maximum time `func` is allowed to be delayed before it's invoked.
  12882. * @param {boolean} [options.trailing=true]
  12883. * Specify invoking on the trailing edge of the timeout.
  12884. * @returns {Function} Returns the new debounced function.
  12885. * @example
  12886. *
  12887. * // Avoid costly calculations while the window size is in flux.
  12888. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  12889. *
  12890. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  12891. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  12892. * 'leading': true,
  12893. * 'trailing': false
  12894. * }));
  12895. *
  12896. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  12897. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  12898. * var source = new EventSource('/stream');
  12899. * jQuery(source).on('message', debounced);
  12900. *
  12901. * // Cancel the trailing debounced invocation.
  12902. * jQuery(window).on('popstate', debounced.cancel);
  12903. */
  12904. function debounce(func, wait, options) {
  12905. var lastArgs,
  12906. lastThis,
  12907. maxWait,
  12908. result,
  12909. timerId,
  12910. lastCallTime,
  12911. lastInvokeTime = 0,
  12912. leading = false,
  12913. maxing = false,
  12914. trailing = true;
  12915. if (typeof func != 'function') {
  12916. throw new TypeError(FUNC_ERROR_TEXT);
  12917. }
  12918. wait = toNumber(wait) || 0;
  12919. if (isObject(options)) {
  12920. leading = !!options.leading;
  12921. maxing = 'maxWait' in options;
  12922. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  12923. trailing = 'trailing' in options ? !!options.trailing : trailing;
  12924. }
  12925. function invokeFunc(time) {
  12926. var args = lastArgs,
  12927. thisArg = lastThis;
  12928. lastArgs = lastThis = undefined;
  12929. lastInvokeTime = time;
  12930. result = func.apply(thisArg, args);
  12931. return result;
  12932. }
  12933. function leadingEdge(time) {
  12934. // Reset any `maxWait` timer.
  12935. lastInvokeTime = time;
  12936. // Start the timer for the trailing edge.
  12937. timerId = setTimeout(timerExpired, wait);
  12938. // Invoke the leading edge.
  12939. return leading ? invokeFunc(time) : result;
  12940. }
  12941. function remainingWait(time) {
  12942. var timeSinceLastCall = time - lastCallTime,
  12943. timeSinceLastInvoke = time - lastInvokeTime,
  12944. timeWaiting = wait - timeSinceLastCall;
  12945. return maxing
  12946. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  12947. : timeWaiting;
  12948. }
  12949. function shouldInvoke(time) {
  12950. var timeSinceLastCall = time - lastCallTime,
  12951. timeSinceLastInvoke = time - lastInvokeTime;
  12952. // Either this is the first call, activity has stopped and we're at the
  12953. // trailing edge, the system time has gone backwards and we're treating
  12954. // it as the trailing edge, or we've hit the `maxWait` limit.
  12955. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  12956. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  12957. }
  12958. function timerExpired() {
  12959. var time = now();
  12960. if (shouldInvoke(time)) {
  12961. return trailingEdge(time);
  12962. }
  12963. // Restart the timer.
  12964. timerId = setTimeout(timerExpired, remainingWait(time));
  12965. }
  12966. function trailingEdge(time) {
  12967. timerId = undefined;
  12968. // Only invoke if we have `lastArgs` which means `func` has been
  12969. // debounced at least once.
  12970. if (trailing && lastArgs) {
  12971. return invokeFunc(time);
  12972. }
  12973. lastArgs = lastThis = undefined;
  12974. return result;
  12975. }
  12976. function cancel() {
  12977. if (timerId !== undefined) {
  12978. clearTimeout(timerId);
  12979. }
  12980. lastInvokeTime = 0;
  12981. lastArgs = lastCallTime = lastThis = timerId = undefined;
  12982. }
  12983. function flush() {
  12984. return timerId === undefined ? result : trailingEdge(now());
  12985. }
  12986. function debounced() {
  12987. var time = now(),
  12988. isInvoking = shouldInvoke(time);
  12989. lastArgs = arguments;
  12990. lastThis = this;
  12991. lastCallTime = time;
  12992. if (isInvoking) {
  12993. if (timerId === undefined) {
  12994. return leadingEdge(lastCallTime);
  12995. }
  12996. if (maxing) {
  12997. // Handle invocations in a tight loop.
  12998. clearTimeout(timerId);
  12999. timerId = setTimeout(timerExpired, wait);
  13000. return invokeFunc(lastCallTime);
  13001. }
  13002. }
  13003. if (timerId === undefined) {
  13004. timerId = setTimeout(timerExpired, wait);
  13005. }
  13006. return result;
  13007. }
  13008. debounced.cancel = cancel;
  13009. debounced.flush = flush;
  13010. return debounced;
  13011. }
  13012. /**
  13013. * Defers invoking the `func` until the current call stack has cleared. Any
  13014. * additional arguments are provided to `func` when it's invoked.
  13015. *
  13016. * @static
  13017. * @memberOf _
  13018. * @since 0.1.0
  13019. * @category Function
  13020. * @param {Function} func The function to defer.
  13021. * @param {...*} [args] The arguments to invoke `func` with.
  13022. * @returns {number} Returns the timer id.
  13023. * @example
  13024. *
  13025. * _.defer(function(text) {
  13026. * console.log(text);
  13027. * }, 'deferred');
  13028. * // => Logs 'deferred' after one millisecond.
  13029. */
  13030. var defer = baseRest(function(func, args) {
  13031. return baseDelay(func, 1, args);
  13032. });
  13033. /**
  13034. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  13035. * provided to `func` when it's invoked.
  13036. *
  13037. * @static
  13038. * @memberOf _
  13039. * @since 0.1.0
  13040. * @category Function
  13041. * @param {Function} func The function to delay.
  13042. * @param {number} wait The number of milliseconds to delay invocation.
  13043. * @param {...*} [args] The arguments to invoke `func` with.
  13044. * @returns {number} Returns the timer id.
  13045. * @example
  13046. *
  13047. * _.delay(function(text) {
  13048. * console.log(text);
  13049. * }, 1000, 'later');
  13050. * // => Logs 'later' after one second.
  13051. */
  13052. var delay = baseRest(function(func, wait, args) {
  13053. return baseDelay(func, toNumber(wait) || 0, args);
  13054. });
  13055. /**
  13056. * Creates a function that invokes `func` with arguments reversed.
  13057. *
  13058. * @static
  13059. * @memberOf _
  13060. * @since 4.0.0
  13061. * @category Function
  13062. * @param {Function} func The function to flip arguments for.
  13063. * @returns {Function} Returns the new flipped function.
  13064. * @example
  13065. *
  13066. * var flipped = _.flip(function() {
  13067. * return _.toArray(arguments);
  13068. * });
  13069. *
  13070. * flipped('a', 'b', 'c', 'd');
  13071. * // => ['d', 'c', 'b', 'a']
  13072. */
  13073. function flip(func) {
  13074. return createWrap(func, WRAP_FLIP_FLAG);
  13075. }
  13076. /**
  13077. * Creates a function that memoizes the result of `func`. If `resolver` is
  13078. * provided, it determines the cache key for storing the result based on the
  13079. * arguments provided to the memoized function. By default, the first argument
  13080. * provided to the memoized function is used as the map cache key. The `func`
  13081. * is invoked with the `this` binding of the memoized function.
  13082. *
  13083. * **Note:** The cache is exposed as the `cache` property on the memoized
  13084. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  13085. * constructor with one whose instances implement the
  13086. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  13087. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  13088. *
  13089. * @static
  13090. * @memberOf _
  13091. * @since 0.1.0
  13092. * @category Function
  13093. * @param {Function} func The function to have its output memoized.
  13094. * @param {Function} [resolver] The function to resolve the cache key.
  13095. * @returns {Function} Returns the new memoized function.
  13096. * @example
  13097. *
  13098. * var object = { 'a': 1, 'b': 2 };
  13099. * var other = { 'c': 3, 'd': 4 };
  13100. *
  13101. * var values = _.memoize(_.values);
  13102. * values(object);
  13103. * // => [1, 2]
  13104. *
  13105. * values(other);
  13106. * // => [3, 4]
  13107. *
  13108. * object.a = 2;
  13109. * values(object);
  13110. * // => [1, 2]
  13111. *
  13112. * // Modify the result cache.
  13113. * values.cache.set(object, ['a', 'b']);
  13114. * values(object);
  13115. * // => ['a', 'b']
  13116. *
  13117. * // Replace `_.memoize.Cache`.
  13118. * _.memoize.Cache = WeakMap;
  13119. */
  13120. function memoize(func, resolver) {
  13121. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  13122. throw new TypeError(FUNC_ERROR_TEXT);
  13123. }
  13124. var memoized = function() {
  13125. var args = arguments,
  13126. key = resolver ? resolver.apply(this, args) : args[0],
  13127. cache = memoized.cache;
  13128. if (cache.has(key)) {
  13129. return cache.get(key);
  13130. }
  13131. var result = func.apply(this, args);
  13132. memoized.cache = cache.set(key, result) || cache;
  13133. return result;
  13134. };
  13135. memoized.cache = new (memoize.Cache || MapCache);
  13136. return memoized;
  13137. }
  13138. // Expose `MapCache`.
  13139. memoize.Cache = MapCache;
  13140. /**
  13141. * Creates a function that negates the result of the predicate `func`. The
  13142. * `func` predicate is invoked with the `this` binding and arguments of the
  13143. * created function.
  13144. *
  13145. * @static
  13146. * @memberOf _
  13147. * @since 3.0.0
  13148. * @category Function
  13149. * @param {Function} predicate The predicate to negate.
  13150. * @returns {Function} Returns the new negated function.
  13151. * @example
  13152. *
  13153. * function isEven(n) {
  13154. * return n % 2 == 0;
  13155. * }
  13156. *
  13157. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  13158. * // => [1, 3, 5]
  13159. */
  13160. function negate(predicate) {
  13161. if (typeof predicate != 'function') {
  13162. throw new TypeError(FUNC_ERROR_TEXT);
  13163. }
  13164. return function() {
  13165. var args = arguments;
  13166. switch (args.length) {
  13167. case 0: return !predicate.call(this);
  13168. case 1: return !predicate.call(this, args[0]);
  13169. case 2: return !predicate.call(this, args[0], args[1]);
  13170. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  13171. }
  13172. return !predicate.apply(this, args);
  13173. };
  13174. }
  13175. /**
  13176. * Creates a function that is restricted to invoking `func` once. Repeat calls
  13177. * to the function return the value of the first invocation. The `func` is
  13178. * invoked with the `this` binding and arguments of the created function.
  13179. *
  13180. * @static
  13181. * @memberOf _
  13182. * @since 0.1.0
  13183. * @category Function
  13184. * @param {Function} func The function to restrict.
  13185. * @returns {Function} Returns the new restricted function.
  13186. * @example
  13187. *
  13188. * var initialize = _.once(createApplication);
  13189. * initialize();
  13190. * initialize();
  13191. * // => `createApplication` is invoked once
  13192. */
  13193. function once(func) {
  13194. return before(2, func);
  13195. }
  13196. /**
  13197. * Creates a function that invokes `func` with its arguments transformed.
  13198. *
  13199. * @static
  13200. * @since 4.0.0
  13201. * @memberOf _
  13202. * @category Function
  13203. * @param {Function} func The function to wrap.
  13204. * @param {...(Function|Function[])} [transforms=[_.identity]]
  13205. * The argument transforms.
  13206. * @returns {Function} Returns the new function.
  13207. * @example
  13208. *
  13209. * function doubled(n) {
  13210. * return n * 2;
  13211. * }
  13212. *
  13213. * function square(n) {
  13214. * return n * n;
  13215. * }
  13216. *
  13217. * var func = _.overArgs(function(x, y) {
  13218. * return [x, y];
  13219. * }, [square, doubled]);
  13220. *
  13221. * func(9, 3);
  13222. * // => [81, 6]
  13223. *
  13224. * func(10, 5);
  13225. * // => [100, 10]
  13226. */
  13227. var overArgs = castRest(function(func, transforms) {
  13228. transforms = (transforms.length == 1 && isArray(transforms[0]))
  13229. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  13230. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  13231. var funcsLength = transforms.length;
  13232. return baseRest(function(args) {
  13233. var index = -1,
  13234. length = nativeMin(args.length, funcsLength);
  13235. while (++index < length) {
  13236. args[index] = transforms[index].call(this, args[index]);
  13237. }
  13238. return apply(func, this, args);
  13239. });
  13240. });
  13241. /**
  13242. * Creates a function that invokes `func` with `partials` prepended to the
  13243. * arguments it receives. This method is like `_.bind` except it does **not**
  13244. * alter the `this` binding.
  13245. *
  13246. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  13247. * builds, may be used as a placeholder for partially applied arguments.
  13248. *
  13249. * **Note:** This method doesn't set the "length" property of partially
  13250. * applied functions.
  13251. *
  13252. * @static
  13253. * @memberOf _
  13254. * @since 0.2.0
  13255. * @category Function
  13256. * @param {Function} func The function to partially apply arguments to.
  13257. * @param {...*} [partials] The arguments to be partially applied.
  13258. * @returns {Function} Returns the new partially applied function.
  13259. * @example
  13260. *
  13261. * function greet(greeting, name) {
  13262. * return greeting + ' ' + name;
  13263. * }
  13264. *
  13265. * var sayHelloTo = _.partial(greet, 'hello');
  13266. * sayHelloTo('fred');
  13267. * // => 'hello fred'
  13268. *
  13269. * // Partially applied with placeholders.
  13270. * var greetFred = _.partial(greet, _, 'fred');
  13271. * greetFred('hi');
  13272. * // => 'hi fred'
  13273. */
  13274. var partial = baseRest(function(func, partials) {
  13275. var holders = replaceHolders(partials, getHolder(partial));
  13276. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  13277. });
  13278. /**
  13279. * This method is like `_.partial` except that partially applied arguments
  13280. * are appended to the arguments it receives.
  13281. *
  13282. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  13283. * builds, may be used as a placeholder for partially applied arguments.
  13284. *
  13285. * **Note:** This method doesn't set the "length" property of partially
  13286. * applied functions.
  13287. *
  13288. * @static
  13289. * @memberOf _
  13290. * @since 1.0.0
  13291. * @category Function
  13292. * @param {Function} func The function to partially apply arguments to.
  13293. * @param {...*} [partials] The arguments to be partially applied.
  13294. * @returns {Function} Returns the new partially applied function.
  13295. * @example
  13296. *
  13297. * function greet(greeting, name) {
  13298. * return greeting + ' ' + name;
  13299. * }
  13300. *
  13301. * var greetFred = _.partialRight(greet, 'fred');
  13302. * greetFred('hi');
  13303. * // => 'hi fred'
  13304. *
  13305. * // Partially applied with placeholders.
  13306. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  13307. * sayHelloTo('fred');
  13308. * // => 'hello fred'
  13309. */
  13310. var partialRight = baseRest(function(func, partials) {
  13311. var holders = replaceHolders(partials, getHolder(partialRight));
  13312. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  13313. });
  13314. /**
  13315. * Creates a function that invokes `func` with arguments arranged according
  13316. * to the specified `indexes` where the argument value at the first index is
  13317. * provided as the first argument, the argument value at the second index is
  13318. * provided as the second argument, and so on.
  13319. *
  13320. * @static
  13321. * @memberOf _
  13322. * @since 3.0.0
  13323. * @category Function
  13324. * @param {Function} func The function to rearrange arguments for.
  13325. * @param {...(number|number[])} indexes The arranged argument indexes.
  13326. * @returns {Function} Returns the new function.
  13327. * @example
  13328. *
  13329. * var rearged = _.rearg(function(a, b, c) {
  13330. * return [a, b, c];
  13331. * }, [2, 0, 1]);
  13332. *
  13333. * rearged('b', 'c', 'a')
  13334. * // => ['a', 'b', 'c']
  13335. */
  13336. var rearg = flatRest(function(func, indexes) {
  13337. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  13338. });
  13339. /**
  13340. * Creates a function that invokes `func` with the `this` binding of the
  13341. * created function and arguments from `start` and beyond provided as
  13342. * an array.
  13343. *
  13344. * **Note:** This method is based on the
  13345. * [rest parameter](https://mdn.io/rest_parameters).
  13346. *
  13347. * @static
  13348. * @memberOf _
  13349. * @since 4.0.0
  13350. * @category Function
  13351. * @param {Function} func The function to apply a rest parameter to.
  13352. * @param {number} [start=func.length-1] The start position of the rest parameter.
  13353. * @returns {Function} Returns the new function.
  13354. * @example
  13355. *
  13356. * var say = _.rest(function(what, names) {
  13357. * return what + ' ' + _.initial(names).join(', ') +
  13358. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  13359. * });
  13360. *
  13361. * say('hello', 'fred', 'barney', 'pebbles');
  13362. * // => 'hello fred, barney, & pebbles'
  13363. */
  13364. function rest(func, start) {
  13365. if (typeof func != 'function') {
  13366. throw new TypeError(FUNC_ERROR_TEXT);
  13367. }
  13368. start = start === undefined ? start : toInteger(start);
  13369. return baseRest(func, start);
  13370. }
  13371. /**
  13372. * Creates a function that invokes `func` with the `this` binding of the
  13373. * create function and an array of arguments much like
  13374. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  13375. *
  13376. * **Note:** This method is based on the
  13377. * [spread operator](https://mdn.io/spread_operator).
  13378. *
  13379. * @static
  13380. * @memberOf _
  13381. * @since 3.2.0
  13382. * @category Function
  13383. * @param {Function} func The function to spread arguments over.
  13384. * @param {number} [start=0] The start position of the spread.
  13385. * @returns {Function} Returns the new function.
  13386. * @example
  13387. *
  13388. * var say = _.spread(function(who, what) {
  13389. * return who + ' says ' + what;
  13390. * });
  13391. *
  13392. * say(['fred', 'hello']);
  13393. * // => 'fred says hello'
  13394. *
  13395. * var numbers = Promise.all([
  13396. * Promise.resolve(40),
  13397. * Promise.resolve(36)
  13398. * ]);
  13399. *
  13400. * numbers.then(_.spread(function(x, y) {
  13401. * return x + y;
  13402. * }));
  13403. * // => a Promise of 76
  13404. */
  13405. function spread(func, start) {
  13406. if (typeof func != 'function') {
  13407. throw new TypeError(FUNC_ERROR_TEXT);
  13408. }
  13409. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  13410. return baseRest(function(args) {
  13411. var array = args[start],
  13412. otherArgs = castSlice(args, 0, start);
  13413. if (array) {
  13414. arrayPush(otherArgs, array);
  13415. }
  13416. return apply(func, this, otherArgs);
  13417. });
  13418. }
  13419. /**
  13420. * Creates a throttled function that only invokes `func` at most once per
  13421. * every `wait` milliseconds. The throttled function comes with a `cancel`
  13422. * method to cancel delayed `func` invocations and a `flush` method to
  13423. * immediately invoke them. Provide `options` to indicate whether `func`
  13424. * should be invoked on the leading and/or trailing edge of the `wait`
  13425. * timeout. The `func` is invoked with the last arguments provided to the
  13426. * throttled function. Subsequent calls to the throttled function return the
  13427. * result of the last `func` invocation.
  13428. *
  13429. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  13430. * invoked on the trailing edge of the timeout only if the throttled function
  13431. * is invoked more than once during the `wait` timeout.
  13432. *
  13433. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  13434. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  13435. *
  13436. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  13437. * for details over the differences between `_.throttle` and `_.debounce`.
  13438. *
  13439. * @static
  13440. * @memberOf _
  13441. * @since 0.1.0
  13442. * @category Function
  13443. * @param {Function} func The function to throttle.
  13444. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  13445. * @param {Object} [options={}] The options object.
  13446. * @param {boolean} [options.leading=true]
  13447. * Specify invoking on the leading edge of the timeout.
  13448. * @param {boolean} [options.trailing=true]
  13449. * Specify invoking on the trailing edge of the timeout.
  13450. * @returns {Function} Returns the new throttled function.
  13451. * @example
  13452. *
  13453. * // Avoid excessively updating the position while scrolling.
  13454. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  13455. *
  13456. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  13457. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  13458. * jQuery(element).on('click', throttled);
  13459. *
  13460. * // Cancel the trailing throttled invocation.
  13461. * jQuery(window).on('popstate', throttled.cancel);
  13462. */
  13463. function throttle(func, wait, options) {
  13464. var leading = true,
  13465. trailing = true;
  13466. if (typeof func != 'function') {
  13467. throw new TypeError(FUNC_ERROR_TEXT);
  13468. }
  13469. if (isObject(options)) {
  13470. leading = 'leading' in options ? !!options.leading : leading;
  13471. trailing = 'trailing' in options ? !!options.trailing : trailing;
  13472. }
  13473. return debounce(func, wait, {
  13474. 'leading': leading,
  13475. 'maxWait': wait,
  13476. 'trailing': trailing
  13477. });
  13478. }
  13479. /**
  13480. * Creates a function that accepts up to one argument, ignoring any
  13481. * additional arguments.
  13482. *
  13483. * @static
  13484. * @memberOf _
  13485. * @since 4.0.0
  13486. * @category Function
  13487. * @param {Function} func The function to cap arguments for.
  13488. * @returns {Function} Returns the new capped function.
  13489. * @example
  13490. *
  13491. * _.map(['6', '8', '10'], _.unary(parseInt));
  13492. * // => [6, 8, 10]
  13493. */
  13494. function unary(func) {
  13495. return ary(func, 1);
  13496. }
  13497. /**
  13498. * Creates a function that provides `value` to `wrapper` as its first
  13499. * argument. Any additional arguments provided to the function are appended
  13500. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  13501. * binding of the created function.
  13502. *
  13503. * @static
  13504. * @memberOf _
  13505. * @since 0.1.0
  13506. * @category Function
  13507. * @param {*} value The value to wrap.
  13508. * @param {Function} [wrapper=identity] The wrapper function.
  13509. * @returns {Function} Returns the new function.
  13510. * @example
  13511. *
  13512. * var p = _.wrap(_.escape, function(func, text) {
  13513. * return '<p>' + func(text) + '</p>';
  13514. * });
  13515. *
  13516. * p('fred, barney, & pebbles');
  13517. * // => '<p>fred, barney, &amp; pebbles</p>'
  13518. */
  13519. function wrap(value, wrapper) {
  13520. return partial(castFunction(wrapper), value);
  13521. }
  13522. /*------------------------------------------------------------------------*/
  13523. /**
  13524. * Casts `value` as an array if it's not one.
  13525. *
  13526. * @static
  13527. * @memberOf _
  13528. * @since 4.4.0
  13529. * @category Lang
  13530. * @param {*} value The value to inspect.
  13531. * @returns {Array} Returns the cast array.
  13532. * @example
  13533. *
  13534. * _.castArray(1);
  13535. * // => [1]
  13536. *
  13537. * _.castArray({ 'a': 1 });
  13538. * // => [{ 'a': 1 }]
  13539. *
  13540. * _.castArray('abc');
  13541. * // => ['abc']
  13542. *
  13543. * _.castArray(null);
  13544. * // => [null]
  13545. *
  13546. * _.castArray(undefined);
  13547. * // => [undefined]
  13548. *
  13549. * _.castArray();
  13550. * // => []
  13551. *
  13552. * var array = [1, 2, 3];
  13553. * console.log(_.castArray(array) === array);
  13554. * // => true
  13555. */
  13556. function castArray() {
  13557. if (!arguments.length) {
  13558. return [];
  13559. }
  13560. var value = arguments[0];
  13561. return isArray(value) ? value : [value];
  13562. }
  13563. /**
  13564. * Creates a shallow clone of `value`.
  13565. *
  13566. * **Note:** This method is loosely based on the
  13567. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  13568. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  13569. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  13570. * arrays. The own enumerable properties of `arguments` objects are cloned
  13571. * as plain objects. An empty object is returned for uncloneable values such
  13572. * as error objects, functions, DOM nodes, and WeakMaps.
  13573. *
  13574. * @static
  13575. * @memberOf _
  13576. * @since 0.1.0
  13577. * @category Lang
  13578. * @param {*} value The value to clone.
  13579. * @returns {*} Returns the cloned value.
  13580. * @see _.cloneDeep
  13581. * @example
  13582. *
  13583. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  13584. *
  13585. * var shallow = _.clone(objects);
  13586. * console.log(shallow[0] === objects[0]);
  13587. * // => true
  13588. */
  13589. function clone(value) {
  13590. return baseClone(value, CLONE_SYMBOLS_FLAG);
  13591. }
  13592. /**
  13593. * This method is like `_.clone` except that it accepts `customizer` which
  13594. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  13595. * cloning is handled by the method instead. The `customizer` is invoked with
  13596. * up to four arguments; (value [, index|key, object, stack]).
  13597. *
  13598. * @static
  13599. * @memberOf _
  13600. * @since 4.0.0
  13601. * @category Lang
  13602. * @param {*} value The value to clone.
  13603. * @param {Function} [customizer] The function to customize cloning.
  13604. * @returns {*} Returns the cloned value.
  13605. * @see _.cloneDeepWith
  13606. * @example
  13607. *
  13608. * function customizer(value) {
  13609. * if (_.isElement(value)) {
  13610. * return value.cloneNode(false);
  13611. * }
  13612. * }
  13613. *
  13614. * var el = _.cloneWith(document.body, customizer);
  13615. *
  13616. * console.log(el === document.body);
  13617. * // => false
  13618. * console.log(el.nodeName);
  13619. * // => 'BODY'
  13620. * console.log(el.childNodes.length);
  13621. * // => 0
  13622. */
  13623. function cloneWith(value, customizer) {
  13624. customizer = typeof customizer == 'function' ? customizer : undefined;
  13625. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  13626. }
  13627. /**
  13628. * This method is like `_.clone` except that it recursively clones `value`.
  13629. *
  13630. * @static
  13631. * @memberOf _
  13632. * @since 1.0.0
  13633. * @category Lang
  13634. * @param {*} value The value to recursively clone.
  13635. * @returns {*} Returns the deep cloned value.
  13636. * @see _.clone
  13637. * @example
  13638. *
  13639. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  13640. *
  13641. * var deep = _.cloneDeep(objects);
  13642. * console.log(deep[0] === objects[0]);
  13643. * // => false
  13644. */
  13645. function cloneDeep(value) {
  13646. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  13647. }
  13648. /**
  13649. * This method is like `_.cloneWith` except that it recursively clones `value`.
  13650. *
  13651. * @static
  13652. * @memberOf _
  13653. * @since 4.0.0
  13654. * @category Lang
  13655. * @param {*} value The value to recursively clone.
  13656. * @param {Function} [customizer] The function to customize cloning.
  13657. * @returns {*} Returns the deep cloned value.
  13658. * @see _.cloneWith
  13659. * @example
  13660. *
  13661. * function customizer(value) {
  13662. * if (_.isElement(value)) {
  13663. * return value.cloneNode(true);
  13664. * }
  13665. * }
  13666. *
  13667. * var el = _.cloneDeepWith(document.body, customizer);
  13668. *
  13669. * console.log(el === document.body);
  13670. * // => false
  13671. * console.log(el.nodeName);
  13672. * // => 'BODY'
  13673. * console.log(el.childNodes.length);
  13674. * // => 20
  13675. */
  13676. function cloneDeepWith(value, customizer) {
  13677. customizer = typeof customizer == 'function' ? customizer : undefined;
  13678. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  13679. }
  13680. /**
  13681. * Checks if `object` conforms to `source` by invoking the predicate
  13682. * properties of `source` with the corresponding property values of `object`.
  13683. *
  13684. * **Note:** This method is equivalent to `_.conforms` when `source` is
  13685. * partially applied.
  13686. *
  13687. * @static
  13688. * @memberOf _
  13689. * @since 4.14.0
  13690. * @category Lang
  13691. * @param {Object} object The object to inspect.
  13692. * @param {Object} source The object of property predicates to conform to.
  13693. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  13694. * @example
  13695. *
  13696. * var object = { 'a': 1, 'b': 2 };
  13697. *
  13698. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  13699. * // => true
  13700. *
  13701. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  13702. * // => false
  13703. */
  13704. function conformsTo(object, source) {
  13705. return source == null || baseConformsTo(object, source, keys(source));
  13706. }
  13707. /**
  13708. * Performs a
  13709. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  13710. * comparison between two values to determine if they are equivalent.
  13711. *
  13712. * @static
  13713. * @memberOf _
  13714. * @since 4.0.0
  13715. * @category Lang
  13716. * @param {*} value The value to compare.
  13717. * @param {*} other The other value to compare.
  13718. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  13719. * @example
  13720. *
  13721. * var object = { 'a': 1 };
  13722. * var other = { 'a': 1 };
  13723. *
  13724. * _.eq(object, object);
  13725. * // => true
  13726. *
  13727. * _.eq(object, other);
  13728. * // => false
  13729. *
  13730. * _.eq('a', 'a');
  13731. * // => true
  13732. *
  13733. * _.eq('a', Object('a'));
  13734. * // => false
  13735. *
  13736. * _.eq(NaN, NaN);
  13737. * // => true
  13738. */
  13739. function eq(value, other) {
  13740. return value === other || (value !== value && other !== other);
  13741. }
  13742. /**
  13743. * Checks if `value` is greater than `other`.
  13744. *
  13745. * @static
  13746. * @memberOf _
  13747. * @since 3.9.0
  13748. * @category Lang
  13749. * @param {*} value The value to compare.
  13750. * @param {*} other The other value to compare.
  13751. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  13752. * else `false`.
  13753. * @see _.lt
  13754. * @example
  13755. *
  13756. * _.gt(3, 1);
  13757. * // => true
  13758. *
  13759. * _.gt(3, 3);
  13760. * // => false
  13761. *
  13762. * _.gt(1, 3);
  13763. * // => false
  13764. */
  13765. var gt = createRelationalOperation(baseGt);
  13766. /**
  13767. * Checks if `value` is greater than or equal to `other`.
  13768. *
  13769. * @static
  13770. * @memberOf _
  13771. * @since 3.9.0
  13772. * @category Lang
  13773. * @param {*} value The value to compare.
  13774. * @param {*} other The other value to compare.
  13775. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  13776. * `other`, else `false`.
  13777. * @see _.lte
  13778. * @example
  13779. *
  13780. * _.gte(3, 1);
  13781. * // => true
  13782. *
  13783. * _.gte(3, 3);
  13784. * // => true
  13785. *
  13786. * _.gte(1, 3);
  13787. * // => false
  13788. */
  13789. var gte = createRelationalOperation(function(value, other) {
  13790. return value >= other;
  13791. });
  13792. /**
  13793. * Checks if `value` is likely an `arguments` object.
  13794. *
  13795. * @static
  13796. * @memberOf _
  13797. * @since 0.1.0
  13798. * @category Lang
  13799. * @param {*} value The value to check.
  13800. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  13801. * else `false`.
  13802. * @example
  13803. *
  13804. * _.isArguments(function() { return arguments; }());
  13805. * // => true
  13806. *
  13807. * _.isArguments([1, 2, 3]);
  13808. * // => false
  13809. */
  13810. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  13811. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  13812. !propertyIsEnumerable.call(value, 'callee');
  13813. };
  13814. /**
  13815. * Checks if `value` is classified as an `Array` object.
  13816. *
  13817. * @static
  13818. * @memberOf _
  13819. * @since 0.1.0
  13820. * @category Lang
  13821. * @param {*} value The value to check.
  13822. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  13823. * @example
  13824. *
  13825. * _.isArray([1, 2, 3]);
  13826. * // => true
  13827. *
  13828. * _.isArray(document.body.children);
  13829. * // => false
  13830. *
  13831. * _.isArray('abc');
  13832. * // => false
  13833. *
  13834. * _.isArray(_.noop);
  13835. * // => false
  13836. */
  13837. var isArray = Array.isArray;
  13838. /**
  13839. * Checks if `value` is classified as an `ArrayBuffer` object.
  13840. *
  13841. * @static
  13842. * @memberOf _
  13843. * @since 4.3.0
  13844. * @category Lang
  13845. * @param {*} value The value to check.
  13846. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  13847. * @example
  13848. *
  13849. * _.isArrayBuffer(new ArrayBuffer(2));
  13850. * // => true
  13851. *
  13852. * _.isArrayBuffer(new Array(2));
  13853. * // => false
  13854. */
  13855. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  13856. /**
  13857. * Checks if `value` is array-like. A value is considered array-like if it's
  13858. * not a function and has a `value.length` that's an integer greater than or
  13859. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  13860. *
  13861. * @static
  13862. * @memberOf _
  13863. * @since 4.0.0
  13864. * @category Lang
  13865. * @param {*} value The value to check.
  13866. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  13867. * @example
  13868. *
  13869. * _.isArrayLike([1, 2, 3]);
  13870. * // => true
  13871. *
  13872. * _.isArrayLike(document.body.children);
  13873. * // => true
  13874. *
  13875. * _.isArrayLike('abc');
  13876. * // => true
  13877. *
  13878. * _.isArrayLike(_.noop);
  13879. * // => false
  13880. */
  13881. function isArrayLike(value) {
  13882. return value != null && isLength(value.length) && !isFunction(value);
  13883. }
  13884. /**
  13885. * This method is like `_.isArrayLike` except that it also checks if `value`
  13886. * is an object.
  13887. *
  13888. * @static
  13889. * @memberOf _
  13890. * @since 4.0.0
  13891. * @category Lang
  13892. * @param {*} value The value to check.
  13893. * @returns {boolean} Returns `true` if `value` is an array-like object,
  13894. * else `false`.
  13895. * @example
  13896. *
  13897. * _.isArrayLikeObject([1, 2, 3]);
  13898. * // => true
  13899. *
  13900. * _.isArrayLikeObject(document.body.children);
  13901. * // => true
  13902. *
  13903. * _.isArrayLikeObject('abc');
  13904. * // => false
  13905. *
  13906. * _.isArrayLikeObject(_.noop);
  13907. * // => false
  13908. */
  13909. function isArrayLikeObject(value) {
  13910. return isObjectLike(value) && isArrayLike(value);
  13911. }
  13912. /**
  13913. * Checks if `value` is classified as a boolean primitive or object.
  13914. *
  13915. * @static
  13916. * @memberOf _
  13917. * @since 0.1.0
  13918. * @category Lang
  13919. * @param {*} value The value to check.
  13920. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  13921. * @example
  13922. *
  13923. * _.isBoolean(false);
  13924. * // => true
  13925. *
  13926. * _.isBoolean(null);
  13927. * // => false
  13928. */
  13929. function isBoolean(value) {
  13930. return value === true || value === false ||
  13931. (isObjectLike(value) && baseGetTag(value) == boolTag);
  13932. }
  13933. /**
  13934. * Checks if `value` is a buffer.
  13935. *
  13936. * @static
  13937. * @memberOf _
  13938. * @since 4.3.0
  13939. * @category Lang
  13940. * @param {*} value The value to check.
  13941. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  13942. * @example
  13943. *
  13944. * _.isBuffer(new Buffer(2));
  13945. * // => true
  13946. *
  13947. * _.isBuffer(new Uint8Array(2));
  13948. * // => false
  13949. */
  13950. var isBuffer = nativeIsBuffer || stubFalse;
  13951. /**
  13952. * Checks if `value` is classified as a `Date` object.
  13953. *
  13954. * @static
  13955. * @memberOf _
  13956. * @since 0.1.0
  13957. * @category Lang
  13958. * @param {*} value The value to check.
  13959. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  13960. * @example
  13961. *
  13962. * _.isDate(new Date);
  13963. * // => true
  13964. *
  13965. * _.isDate('Mon April 23 2012');
  13966. * // => false
  13967. */
  13968. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  13969. /**
  13970. * Checks if `value` is likely a DOM element.
  13971. *
  13972. * @static
  13973. * @memberOf _
  13974. * @since 0.1.0
  13975. * @category Lang
  13976. * @param {*} value The value to check.
  13977. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  13978. * @example
  13979. *
  13980. * _.isElement(document.body);
  13981. * // => true
  13982. *
  13983. * _.isElement('<body>');
  13984. * // => false
  13985. */
  13986. function isElement(value) {
  13987. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  13988. }
  13989. /**
  13990. * Checks if `value` is an empty object, collection, map, or set.
  13991. *
  13992. * Objects are considered empty if they have no own enumerable string keyed
  13993. * properties.
  13994. *
  13995. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  13996. * jQuery-like collections are considered empty if they have a `length` of `0`.
  13997. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  13998. *
  13999. * @static
  14000. * @memberOf _
  14001. * @since 0.1.0
  14002. * @category Lang
  14003. * @param {*} value The value to check.
  14004. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  14005. * @example
  14006. *
  14007. * _.isEmpty(null);
  14008. * // => true
  14009. *
  14010. * _.isEmpty(true);
  14011. * // => true
  14012. *
  14013. * _.isEmpty(1);
  14014. * // => true
  14015. *
  14016. * _.isEmpty([1, 2, 3]);
  14017. * // => false
  14018. *
  14019. * _.isEmpty({ 'a': 1 });
  14020. * // => false
  14021. */
  14022. function isEmpty(value) {
  14023. if (value == null) {
  14024. return true;
  14025. }
  14026. if (isArrayLike(value) &&
  14027. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  14028. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  14029. return !value.length;
  14030. }
  14031. var tag = getTag(value);
  14032. if (tag == mapTag || tag == setTag) {
  14033. return !value.size;
  14034. }
  14035. if (isPrototype(value)) {
  14036. return !baseKeys(value).length;
  14037. }
  14038. for (var key in value) {
  14039. if (hasOwnProperty.call(value, key)) {
  14040. return false;
  14041. }
  14042. }
  14043. return true;
  14044. }
  14045. /**
  14046. * Performs a deep comparison between two values to determine if they are
  14047. * equivalent.
  14048. *
  14049. * **Note:** This method supports comparing arrays, array buffers, booleans,
  14050. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  14051. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  14052. * by their own, not inherited, enumerable properties. Functions and DOM
  14053. * nodes are compared by strict equality, i.e. `===`.
  14054. *
  14055. * @static
  14056. * @memberOf _
  14057. * @since 0.1.0
  14058. * @category Lang
  14059. * @param {*} value The value to compare.
  14060. * @param {*} other The other value to compare.
  14061. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  14062. * @example
  14063. *
  14064. * var object = { 'a': 1 };
  14065. * var other = { 'a': 1 };
  14066. *
  14067. * _.isEqual(object, other);
  14068. * // => true
  14069. *
  14070. * object === other;
  14071. * // => false
  14072. */
  14073. function isEqual(value, other) {
  14074. return baseIsEqual(value, other);
  14075. }
  14076. /**
  14077. * This method is like `_.isEqual` except that it accepts `customizer` which
  14078. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  14079. * are handled by the method instead. The `customizer` is invoked with up to
  14080. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  14081. *
  14082. * @static
  14083. * @memberOf _
  14084. * @since 4.0.0
  14085. * @category Lang
  14086. * @param {*} value The value to compare.
  14087. * @param {*} other The other value to compare.
  14088. * @param {Function} [customizer] The function to customize comparisons.
  14089. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  14090. * @example
  14091. *
  14092. * function isGreeting(value) {
  14093. * return /^h(?:i|ello)$/.test(value);
  14094. * }
  14095. *
  14096. * function customizer(objValue, othValue) {
  14097. * if (isGreeting(objValue) && isGreeting(othValue)) {
  14098. * return true;
  14099. * }
  14100. * }
  14101. *
  14102. * var array = ['hello', 'goodbye'];
  14103. * var other = ['hi', 'goodbye'];
  14104. *
  14105. * _.isEqualWith(array, other, customizer);
  14106. * // => true
  14107. */
  14108. function isEqualWith(value, other, customizer) {
  14109. customizer = typeof customizer == 'function' ? customizer : undefined;
  14110. var result = customizer ? customizer(value, other) : undefined;
  14111. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  14112. }
  14113. /**
  14114. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  14115. * `SyntaxError`, `TypeError`, or `URIError` object.
  14116. *
  14117. * @static
  14118. * @memberOf _
  14119. * @since 3.0.0
  14120. * @category Lang
  14121. * @param {*} value The value to check.
  14122. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  14123. * @example
  14124. *
  14125. * _.isError(new Error);
  14126. * // => true
  14127. *
  14128. * _.isError(Error);
  14129. * // => false
  14130. */
  14131. function isError(value) {
  14132. if (!isObjectLike(value)) {
  14133. return false;
  14134. }
  14135. var tag = baseGetTag(value);
  14136. return tag == errorTag || tag == domExcTag ||
  14137. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  14138. }
  14139. /**
  14140. * Checks if `value` is a finite primitive number.
  14141. *
  14142. * **Note:** This method is based on
  14143. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  14144. *
  14145. * @static
  14146. * @memberOf _
  14147. * @since 0.1.0
  14148. * @category Lang
  14149. * @param {*} value The value to check.
  14150. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  14151. * @example
  14152. *
  14153. * _.isFinite(3);
  14154. * // => true
  14155. *
  14156. * _.isFinite(Number.MIN_VALUE);
  14157. * // => true
  14158. *
  14159. * _.isFinite(Infinity);
  14160. * // => false
  14161. *
  14162. * _.isFinite('3');
  14163. * // => false
  14164. */
  14165. function isFinite(value) {
  14166. return typeof value == 'number' && nativeIsFinite(value);
  14167. }
  14168. /**
  14169. * Checks if `value` is classified as a `Function` object.
  14170. *
  14171. * @static
  14172. * @memberOf _
  14173. * @since 0.1.0
  14174. * @category Lang
  14175. * @param {*} value The value to check.
  14176. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  14177. * @example
  14178. *
  14179. * _.isFunction(_);
  14180. * // => true
  14181. *
  14182. * _.isFunction(/abc/);
  14183. * // => false
  14184. */
  14185. function isFunction(value) {
  14186. if (!isObject(value)) {
  14187. return false;
  14188. }
  14189. // The use of `Object#toString` avoids issues with the `typeof` operator
  14190. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  14191. var tag = baseGetTag(value);
  14192. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  14193. }
  14194. /**
  14195. * Checks if `value` is an integer.
  14196. *
  14197. * **Note:** This method is based on
  14198. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  14199. *
  14200. * @static
  14201. * @memberOf _
  14202. * @since 4.0.0
  14203. * @category Lang
  14204. * @param {*} value The value to check.
  14205. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  14206. * @example
  14207. *
  14208. * _.isInteger(3);
  14209. * // => true
  14210. *
  14211. * _.isInteger(Number.MIN_VALUE);
  14212. * // => false
  14213. *
  14214. * _.isInteger(Infinity);
  14215. * // => false
  14216. *
  14217. * _.isInteger('3');
  14218. * // => false
  14219. */
  14220. function isInteger(value) {
  14221. return typeof value == 'number' && value == toInteger(value);
  14222. }
  14223. /**
  14224. * Checks if `value` is a valid array-like length.
  14225. *
  14226. * **Note:** This method is loosely based on
  14227. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  14228. *
  14229. * @static
  14230. * @memberOf _
  14231. * @since 4.0.0
  14232. * @category Lang
  14233. * @param {*} value The value to check.
  14234. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  14235. * @example
  14236. *
  14237. * _.isLength(3);
  14238. * // => true
  14239. *
  14240. * _.isLength(Number.MIN_VALUE);
  14241. * // => false
  14242. *
  14243. * _.isLength(Infinity);
  14244. * // => false
  14245. *
  14246. * _.isLength('3');
  14247. * // => false
  14248. */
  14249. function isLength(value) {
  14250. return typeof value == 'number' &&
  14251. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  14252. }
  14253. /**
  14254. * Checks if `value` is the
  14255. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  14256. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  14257. *
  14258. * @static
  14259. * @memberOf _
  14260. * @since 0.1.0
  14261. * @category Lang
  14262. * @param {*} value The value to check.
  14263. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  14264. * @example
  14265. *
  14266. * _.isObject({});
  14267. * // => true
  14268. *
  14269. * _.isObject([1, 2, 3]);
  14270. * // => true
  14271. *
  14272. * _.isObject(_.noop);
  14273. * // => true
  14274. *
  14275. * _.isObject(null);
  14276. * // => false
  14277. */
  14278. function isObject(value) {
  14279. var type = typeof value;
  14280. return value != null && (type == 'object' || type == 'function');
  14281. }
  14282. /**
  14283. * Checks if `value` is object-like. A value is object-like if it's not `null`
  14284. * and has a `typeof` result of "object".
  14285. *
  14286. * @static
  14287. * @memberOf _
  14288. * @since 4.0.0
  14289. * @category Lang
  14290. * @param {*} value The value to check.
  14291. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  14292. * @example
  14293. *
  14294. * _.isObjectLike({});
  14295. * // => true
  14296. *
  14297. * _.isObjectLike([1, 2, 3]);
  14298. * // => true
  14299. *
  14300. * _.isObjectLike(_.noop);
  14301. * // => false
  14302. *
  14303. * _.isObjectLike(null);
  14304. * // => false
  14305. */
  14306. function isObjectLike(value) {
  14307. return value != null && typeof value == 'object';
  14308. }
  14309. /**
  14310. * Checks if `value` is classified as a `Map` object.
  14311. *
  14312. * @static
  14313. * @memberOf _
  14314. * @since 4.3.0
  14315. * @category Lang
  14316. * @param {*} value The value to check.
  14317. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  14318. * @example
  14319. *
  14320. * _.isMap(new Map);
  14321. * // => true
  14322. *
  14323. * _.isMap(new WeakMap);
  14324. * // => false
  14325. */
  14326. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  14327. /**
  14328. * Performs a partial deep comparison between `object` and `source` to
  14329. * determine if `object` contains equivalent property values.
  14330. *
  14331. * **Note:** This method is equivalent to `_.matches` when `source` is
  14332. * partially applied.
  14333. *
  14334. * Partial comparisons will match empty array and empty object `source`
  14335. * values against any array or object value, respectively. See `_.isEqual`
  14336. * for a list of supported value comparisons.
  14337. *
  14338. * @static
  14339. * @memberOf _
  14340. * @since 3.0.0
  14341. * @category Lang
  14342. * @param {Object} object The object to inspect.
  14343. * @param {Object} source The object of property values to match.
  14344. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  14345. * @example
  14346. *
  14347. * var object = { 'a': 1, 'b': 2 };
  14348. *
  14349. * _.isMatch(object, { 'b': 2 });
  14350. * // => true
  14351. *
  14352. * _.isMatch(object, { 'b': 1 });
  14353. * // => false
  14354. */
  14355. function isMatch(object, source) {
  14356. return object === source || baseIsMatch(object, source, getMatchData(source));
  14357. }
  14358. /**
  14359. * This method is like `_.isMatch` except that it accepts `customizer` which
  14360. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  14361. * are handled by the method instead. The `customizer` is invoked with five
  14362. * arguments: (objValue, srcValue, index|key, object, source).
  14363. *
  14364. * @static
  14365. * @memberOf _
  14366. * @since 4.0.0
  14367. * @category Lang
  14368. * @param {Object} object The object to inspect.
  14369. * @param {Object} source The object of property values to match.
  14370. * @param {Function} [customizer] The function to customize comparisons.
  14371. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  14372. * @example
  14373. *
  14374. * function isGreeting(value) {
  14375. * return /^h(?:i|ello)$/.test(value);
  14376. * }
  14377. *
  14378. * function customizer(objValue, srcValue) {
  14379. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  14380. * return true;
  14381. * }
  14382. * }
  14383. *
  14384. * var object = { 'greeting': 'hello' };
  14385. * var source = { 'greeting': 'hi' };
  14386. *
  14387. * _.isMatchWith(object, source, customizer);
  14388. * // => true
  14389. */
  14390. function isMatchWith(object, source, customizer) {
  14391. customizer = typeof customizer == 'function' ? customizer : undefined;
  14392. return baseIsMatch(object, source, getMatchData(source), customizer);
  14393. }
  14394. /**
  14395. * Checks if `value` is `NaN`.
  14396. *
  14397. * **Note:** This method is based on
  14398. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  14399. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  14400. * `undefined` and other non-number values.
  14401. *
  14402. * @static
  14403. * @memberOf _
  14404. * @since 0.1.0
  14405. * @category Lang
  14406. * @param {*} value The value to check.
  14407. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  14408. * @example
  14409. *
  14410. * _.isNaN(NaN);
  14411. * // => true
  14412. *
  14413. * _.isNaN(new Number(NaN));
  14414. * // => true
  14415. *
  14416. * isNaN(undefined);
  14417. * // => true
  14418. *
  14419. * _.isNaN(undefined);
  14420. * // => false
  14421. */
  14422. function isNaN(value) {
  14423. // An `NaN` primitive is the only value that is not equal to itself.
  14424. // Perform the `toStringTag` check first to avoid errors with some
  14425. // ActiveX objects in IE.
  14426. return isNumber(value) && value != +value;
  14427. }
  14428. /**
  14429. * Checks if `value` is a pristine native function.
  14430. *
  14431. * **Note:** This method can't reliably detect native functions in the presence
  14432. * of the core-js package because core-js circumvents this kind of detection.
  14433. * Despite multiple requests, the core-js maintainer has made it clear: any
  14434. * attempt to fix the detection will be obstructed. As a result, we're left
  14435. * with little choice but to throw an error. Unfortunately, this also affects
  14436. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  14437. * which rely on core-js.
  14438. *
  14439. * @static
  14440. * @memberOf _
  14441. * @since 3.0.0
  14442. * @category Lang
  14443. * @param {*} value The value to check.
  14444. * @returns {boolean} Returns `true` if `value` is a native function,
  14445. * else `false`.
  14446. * @example
  14447. *
  14448. * _.isNative(Array.prototype.push);
  14449. * // => true
  14450. *
  14451. * _.isNative(_);
  14452. * // => false
  14453. */
  14454. function isNative(value) {
  14455. if (isMaskable(value)) {
  14456. throw new Error(CORE_ERROR_TEXT);
  14457. }
  14458. return baseIsNative(value);
  14459. }
  14460. /**
  14461. * Checks if `value` is `null`.
  14462. *
  14463. * @static
  14464. * @memberOf _
  14465. * @since 0.1.0
  14466. * @category Lang
  14467. * @param {*} value The value to check.
  14468. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  14469. * @example
  14470. *
  14471. * _.isNull(null);
  14472. * // => true
  14473. *
  14474. * _.isNull(void 0);
  14475. * // => false
  14476. */
  14477. function isNull(value) {
  14478. return value === null;
  14479. }
  14480. /**
  14481. * Checks if `value` is `null` or `undefined`.
  14482. *
  14483. * @static
  14484. * @memberOf _
  14485. * @since 4.0.0
  14486. * @category Lang
  14487. * @param {*} value The value to check.
  14488. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  14489. * @example
  14490. *
  14491. * _.isNil(null);
  14492. * // => true
  14493. *
  14494. * _.isNil(void 0);
  14495. * // => true
  14496. *
  14497. * _.isNil(NaN);
  14498. * // => false
  14499. */
  14500. function isNil(value) {
  14501. return value == null;
  14502. }
  14503. /**
  14504. * Checks if `value` is classified as a `Number` primitive or object.
  14505. *
  14506. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  14507. * classified as numbers, use the `_.isFinite` method.
  14508. *
  14509. * @static
  14510. * @memberOf _
  14511. * @since 0.1.0
  14512. * @category Lang
  14513. * @param {*} value The value to check.
  14514. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  14515. * @example
  14516. *
  14517. * _.isNumber(3);
  14518. * // => true
  14519. *
  14520. * _.isNumber(Number.MIN_VALUE);
  14521. * // => true
  14522. *
  14523. * _.isNumber(Infinity);
  14524. * // => true
  14525. *
  14526. * _.isNumber('3');
  14527. * // => false
  14528. */
  14529. function isNumber(value) {
  14530. return typeof value == 'number' ||
  14531. (isObjectLike(value) && baseGetTag(value) == numberTag);
  14532. }
  14533. /**
  14534. * Checks if `value` is a plain object, that is, an object created by the
  14535. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  14536. *
  14537. * @static
  14538. * @memberOf _
  14539. * @since 0.8.0
  14540. * @category Lang
  14541. * @param {*} value The value to check.
  14542. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  14543. * @example
  14544. *
  14545. * function Foo() {
  14546. * this.a = 1;
  14547. * }
  14548. *
  14549. * _.isPlainObject(new Foo);
  14550. * // => false
  14551. *
  14552. * _.isPlainObject([1, 2, 3]);
  14553. * // => false
  14554. *
  14555. * _.isPlainObject({ 'x': 0, 'y': 0 });
  14556. * // => true
  14557. *
  14558. * _.isPlainObject(Object.create(null));
  14559. * // => true
  14560. */
  14561. function isPlainObject(value) {
  14562. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  14563. return false;
  14564. }
  14565. var proto = getPrototype(value);
  14566. if (proto === null) {
  14567. return true;
  14568. }
  14569. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  14570. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  14571. funcToString.call(Ctor) == objectCtorString;
  14572. }
  14573. /**
  14574. * Checks if `value` is classified as a `RegExp` object.
  14575. *
  14576. * @static
  14577. * @memberOf _
  14578. * @since 0.1.0
  14579. * @category Lang
  14580. * @param {*} value The value to check.
  14581. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  14582. * @example
  14583. *
  14584. * _.isRegExp(/abc/);
  14585. * // => true
  14586. *
  14587. * _.isRegExp('/abc/');
  14588. * // => false
  14589. */
  14590. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  14591. /**
  14592. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  14593. * double precision number which isn't the result of a rounded unsafe integer.
  14594. *
  14595. * **Note:** This method is based on
  14596. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  14597. *
  14598. * @static
  14599. * @memberOf _
  14600. * @since 4.0.0
  14601. * @category Lang
  14602. * @param {*} value The value to check.
  14603. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  14604. * @example
  14605. *
  14606. * _.isSafeInteger(3);
  14607. * // => true
  14608. *
  14609. * _.isSafeInteger(Number.MIN_VALUE);
  14610. * // => false
  14611. *
  14612. * _.isSafeInteger(Infinity);
  14613. * // => false
  14614. *
  14615. * _.isSafeInteger('3');
  14616. * // => false
  14617. */
  14618. function isSafeInteger(value) {
  14619. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  14620. }
  14621. /**
  14622. * Checks if `value` is classified as a `Set` object.
  14623. *
  14624. * @static
  14625. * @memberOf _
  14626. * @since 4.3.0
  14627. * @category Lang
  14628. * @param {*} value The value to check.
  14629. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  14630. * @example
  14631. *
  14632. * _.isSet(new Set);
  14633. * // => true
  14634. *
  14635. * _.isSet(new WeakSet);
  14636. * // => false
  14637. */
  14638. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  14639. /**
  14640. * Checks if `value` is classified as a `String` primitive or object.
  14641. *
  14642. * @static
  14643. * @since 0.1.0
  14644. * @memberOf _
  14645. * @category Lang
  14646. * @param {*} value The value to check.
  14647. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  14648. * @example
  14649. *
  14650. * _.isString('abc');
  14651. * // => true
  14652. *
  14653. * _.isString(1);
  14654. * // => false
  14655. */
  14656. function isString(value) {
  14657. return typeof value == 'string' ||
  14658. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  14659. }
  14660. /**
  14661. * Checks if `value` is classified as a `Symbol` primitive or object.
  14662. *
  14663. * @static
  14664. * @memberOf _
  14665. * @since 4.0.0
  14666. * @category Lang
  14667. * @param {*} value The value to check.
  14668. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  14669. * @example
  14670. *
  14671. * _.isSymbol(Symbol.iterator);
  14672. * // => true
  14673. *
  14674. * _.isSymbol('abc');
  14675. * // => false
  14676. */
  14677. function isSymbol(value) {
  14678. return typeof value == 'symbol' ||
  14679. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  14680. }
  14681. /**
  14682. * Checks if `value` is classified as a typed array.
  14683. *
  14684. * @static
  14685. * @memberOf _
  14686. * @since 3.0.0
  14687. * @category Lang
  14688. * @param {*} value The value to check.
  14689. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  14690. * @example
  14691. *
  14692. * _.isTypedArray(new Uint8Array);
  14693. * // => true
  14694. *
  14695. * _.isTypedArray([]);
  14696. * // => false
  14697. */
  14698. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  14699. /**
  14700. * Checks if `value` is `undefined`.
  14701. *
  14702. * @static
  14703. * @since 0.1.0
  14704. * @memberOf _
  14705. * @category Lang
  14706. * @param {*} value The value to check.
  14707. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  14708. * @example
  14709. *
  14710. * _.isUndefined(void 0);
  14711. * // => true
  14712. *
  14713. * _.isUndefined(null);
  14714. * // => false
  14715. */
  14716. function isUndefined(value) {
  14717. return value === undefined;
  14718. }
  14719. /**
  14720. * Checks if `value` is classified as a `WeakMap` object.
  14721. *
  14722. * @static
  14723. * @memberOf _
  14724. * @since 4.3.0
  14725. * @category Lang
  14726. * @param {*} value The value to check.
  14727. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  14728. * @example
  14729. *
  14730. * _.isWeakMap(new WeakMap);
  14731. * // => true
  14732. *
  14733. * _.isWeakMap(new Map);
  14734. * // => false
  14735. */
  14736. function isWeakMap(value) {
  14737. return isObjectLike(value) && getTag(value) == weakMapTag;
  14738. }
  14739. /**
  14740. * Checks if `value` is classified as a `WeakSet` object.
  14741. *
  14742. * @static
  14743. * @memberOf _
  14744. * @since 4.3.0
  14745. * @category Lang
  14746. * @param {*} value The value to check.
  14747. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  14748. * @example
  14749. *
  14750. * _.isWeakSet(new WeakSet);
  14751. * // => true
  14752. *
  14753. * _.isWeakSet(new Set);
  14754. * // => false
  14755. */
  14756. function isWeakSet(value) {
  14757. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  14758. }
  14759. /**
  14760. * Checks if `value` is less than `other`.
  14761. *
  14762. * @static
  14763. * @memberOf _
  14764. * @since 3.9.0
  14765. * @category Lang
  14766. * @param {*} value The value to compare.
  14767. * @param {*} other The other value to compare.
  14768. * @returns {boolean} Returns `true` if `value` is less than `other`,
  14769. * else `false`.
  14770. * @see _.gt
  14771. * @example
  14772. *
  14773. * _.lt(1, 3);
  14774. * // => true
  14775. *
  14776. * _.lt(3, 3);
  14777. * // => false
  14778. *
  14779. * _.lt(3, 1);
  14780. * // => false
  14781. */
  14782. var lt = createRelationalOperation(baseLt);
  14783. /**
  14784. * Checks if `value` is less than or equal to `other`.
  14785. *
  14786. * @static
  14787. * @memberOf _
  14788. * @since 3.9.0
  14789. * @category Lang
  14790. * @param {*} value The value to compare.
  14791. * @param {*} other The other value to compare.
  14792. * @returns {boolean} Returns `true` if `value` is less than or equal to
  14793. * `other`, else `false`.
  14794. * @see _.gte
  14795. * @example
  14796. *
  14797. * _.lte(1, 3);
  14798. * // => true
  14799. *
  14800. * _.lte(3, 3);
  14801. * // => true
  14802. *
  14803. * _.lte(3, 1);
  14804. * // => false
  14805. */
  14806. var lte = createRelationalOperation(function(value, other) {
  14807. return value <= other;
  14808. });
  14809. /**
  14810. * Converts `value` to an array.
  14811. *
  14812. * @static
  14813. * @since 0.1.0
  14814. * @memberOf _
  14815. * @category Lang
  14816. * @param {*} value The value to convert.
  14817. * @returns {Array} Returns the converted array.
  14818. * @example
  14819. *
  14820. * _.toArray({ 'a': 1, 'b': 2 });
  14821. * // => [1, 2]
  14822. *
  14823. * _.toArray('abc');
  14824. * // => ['a', 'b', 'c']
  14825. *
  14826. * _.toArray(1);
  14827. * // => []
  14828. *
  14829. * _.toArray(null);
  14830. * // => []
  14831. */
  14832. function toArray(value) {
  14833. if (!value) {
  14834. return [];
  14835. }
  14836. if (isArrayLike(value)) {
  14837. return isString(value) ? stringToArray(value) : copyArray(value);
  14838. }
  14839. if (symIterator && value[symIterator]) {
  14840. return iteratorToArray(value[symIterator]());
  14841. }
  14842. var tag = getTag(value),
  14843. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  14844. return func(value);
  14845. }
  14846. /**
  14847. * Converts `value` to a finite number.
  14848. *
  14849. * @static
  14850. * @memberOf _
  14851. * @since 4.12.0
  14852. * @category Lang
  14853. * @param {*} value The value to convert.
  14854. * @returns {number} Returns the converted number.
  14855. * @example
  14856. *
  14857. * _.toFinite(3.2);
  14858. * // => 3.2
  14859. *
  14860. * _.toFinite(Number.MIN_VALUE);
  14861. * // => 5e-324
  14862. *
  14863. * _.toFinite(Infinity);
  14864. * // => 1.7976931348623157e+308
  14865. *
  14866. * _.toFinite('3.2');
  14867. * // => 3.2
  14868. */
  14869. function toFinite(value) {
  14870. if (!value) {
  14871. return value === 0 ? value : 0;
  14872. }
  14873. value = toNumber(value);
  14874. if (value === INFINITY || value === -INFINITY) {
  14875. var sign = (value < 0 ? -1 : 1);
  14876. return sign * MAX_INTEGER;
  14877. }
  14878. return value === value ? value : 0;
  14879. }
  14880. /**
  14881. * Converts `value` to an integer.
  14882. *
  14883. * **Note:** This method is loosely based on
  14884. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  14885. *
  14886. * @static
  14887. * @memberOf _
  14888. * @since 4.0.0
  14889. * @category Lang
  14890. * @param {*} value The value to convert.
  14891. * @returns {number} Returns the converted integer.
  14892. * @example
  14893. *
  14894. * _.toInteger(3.2);
  14895. * // => 3
  14896. *
  14897. * _.toInteger(Number.MIN_VALUE);
  14898. * // => 0
  14899. *
  14900. * _.toInteger(Infinity);
  14901. * // => 1.7976931348623157e+308
  14902. *
  14903. * _.toInteger('3.2');
  14904. * // => 3
  14905. */
  14906. function toInteger(value) {
  14907. var result = toFinite(value),
  14908. remainder = result % 1;
  14909. return result === result ? (remainder ? result - remainder : result) : 0;
  14910. }
  14911. /**
  14912. * Converts `value` to an integer suitable for use as the length of an
  14913. * array-like object.
  14914. *
  14915. * **Note:** This method is based on
  14916. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  14917. *
  14918. * @static
  14919. * @memberOf _
  14920. * @since 4.0.0
  14921. * @category Lang
  14922. * @param {*} value The value to convert.
  14923. * @returns {number} Returns the converted integer.
  14924. * @example
  14925. *
  14926. * _.toLength(3.2);
  14927. * // => 3
  14928. *
  14929. * _.toLength(Number.MIN_VALUE);
  14930. * // => 0
  14931. *
  14932. * _.toLength(Infinity);
  14933. * // => 4294967295
  14934. *
  14935. * _.toLength('3.2');
  14936. * // => 3
  14937. */
  14938. function toLength(value) {
  14939. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  14940. }
  14941. /**
  14942. * Converts `value` to a number.
  14943. *
  14944. * @static
  14945. * @memberOf _
  14946. * @since 4.0.0
  14947. * @category Lang
  14948. * @param {*} value The value to process.
  14949. * @returns {number} Returns the number.
  14950. * @example
  14951. *
  14952. * _.toNumber(3.2);
  14953. * // => 3.2
  14954. *
  14955. * _.toNumber(Number.MIN_VALUE);
  14956. * // => 5e-324
  14957. *
  14958. * _.toNumber(Infinity);
  14959. * // => Infinity
  14960. *
  14961. * _.toNumber('3.2');
  14962. * // => 3.2
  14963. */
  14964. function toNumber(value) {
  14965. if (typeof value == 'number') {
  14966. return value;
  14967. }
  14968. if (isSymbol(value)) {
  14969. return NAN;
  14970. }
  14971. if (isObject(value)) {
  14972. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  14973. value = isObject(other) ? (other + '') : other;
  14974. }
  14975. if (typeof value != 'string') {
  14976. return value === 0 ? value : +value;
  14977. }
  14978. value = value.replace(reTrim, '');
  14979. var isBinary = reIsBinary.test(value);
  14980. return (isBinary || reIsOctal.test(value))
  14981. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  14982. : (reIsBadHex.test(value) ? NAN : +value);
  14983. }
  14984. /**
  14985. * Converts `value` to a plain object flattening inherited enumerable string
  14986. * keyed properties of `value` to own properties of the plain object.
  14987. *
  14988. * @static
  14989. * @memberOf _
  14990. * @since 3.0.0
  14991. * @category Lang
  14992. * @param {*} value The value to convert.
  14993. * @returns {Object} Returns the converted plain object.
  14994. * @example
  14995. *
  14996. * function Foo() {
  14997. * this.b = 2;
  14998. * }
  14999. *
  15000. * Foo.prototype.c = 3;
  15001. *
  15002. * _.assign({ 'a': 1 }, new Foo);
  15003. * // => { 'a': 1, 'b': 2 }
  15004. *
  15005. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  15006. * // => { 'a': 1, 'b': 2, 'c': 3 }
  15007. */
  15008. function toPlainObject(value) {
  15009. return copyObject(value, keysIn(value));
  15010. }
  15011. /**
  15012. * Converts `value` to a safe integer. A safe integer can be compared and
  15013. * represented correctly.
  15014. *
  15015. * @static
  15016. * @memberOf _
  15017. * @since 4.0.0
  15018. * @category Lang
  15019. * @param {*} value The value to convert.
  15020. * @returns {number} Returns the converted integer.
  15021. * @example
  15022. *
  15023. * _.toSafeInteger(3.2);
  15024. * // => 3
  15025. *
  15026. * _.toSafeInteger(Number.MIN_VALUE);
  15027. * // => 0
  15028. *
  15029. * _.toSafeInteger(Infinity);
  15030. * // => 9007199254740991
  15031. *
  15032. * _.toSafeInteger('3.2');
  15033. * // => 3
  15034. */
  15035. function toSafeInteger(value) {
  15036. return value
  15037. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  15038. : (value === 0 ? value : 0);
  15039. }
  15040. /**
  15041. * Converts `value` to a string. An empty string is returned for `null`
  15042. * and `undefined` values. The sign of `-0` is preserved.
  15043. *
  15044. * @static
  15045. * @memberOf _
  15046. * @since 4.0.0
  15047. * @category Lang
  15048. * @param {*} value The value to convert.
  15049. * @returns {string} Returns the converted string.
  15050. * @example
  15051. *
  15052. * _.toString(null);
  15053. * // => ''
  15054. *
  15055. * _.toString(-0);
  15056. * // => '-0'
  15057. *
  15058. * _.toString([1, 2, 3]);
  15059. * // => '1,2,3'
  15060. */
  15061. function toString(value) {
  15062. return value == null ? '' : baseToString(value);
  15063. }
  15064. /*------------------------------------------------------------------------*/
  15065. /**
  15066. * Assigns own enumerable string keyed properties of source objects to the
  15067. * destination object. Source objects are applied from left to right.
  15068. * Subsequent sources overwrite property assignments of previous sources.
  15069. *
  15070. * **Note:** This method mutates `object` and is loosely based on
  15071. * [`Object.assign`](https://mdn.io/Object/assign).
  15072. *
  15073. * @static
  15074. * @memberOf _
  15075. * @since 0.10.0
  15076. * @category Object
  15077. * @param {Object} object The destination object.
  15078. * @param {...Object} [sources] The source objects.
  15079. * @returns {Object} Returns `object`.
  15080. * @see _.assignIn
  15081. * @example
  15082. *
  15083. * function Foo() {
  15084. * this.a = 1;
  15085. * }
  15086. *
  15087. * function Bar() {
  15088. * this.c = 3;
  15089. * }
  15090. *
  15091. * Foo.prototype.b = 2;
  15092. * Bar.prototype.d = 4;
  15093. *
  15094. * _.assign({ 'a': 0 }, new Foo, new Bar);
  15095. * // => { 'a': 1, 'c': 3 }
  15096. */
  15097. var assign = createAssigner(function(object, source) {
  15098. if (isPrototype(source) || isArrayLike(source)) {
  15099. copyObject(source, keys(source), object);
  15100. return;
  15101. }
  15102. for (var key in source) {
  15103. if (hasOwnProperty.call(source, key)) {
  15104. assignValue(object, key, source[key]);
  15105. }
  15106. }
  15107. });
  15108. /**
  15109. * This method is like `_.assign` except that it iterates over own and
  15110. * inherited source properties.
  15111. *
  15112. * **Note:** This method mutates `object`.
  15113. *
  15114. * @static
  15115. * @memberOf _
  15116. * @since 4.0.0
  15117. * @alias extend
  15118. * @category Object
  15119. * @param {Object} object The destination object.
  15120. * @param {...Object} [sources] The source objects.
  15121. * @returns {Object} Returns `object`.
  15122. * @see _.assign
  15123. * @example
  15124. *
  15125. * function Foo() {
  15126. * this.a = 1;
  15127. * }
  15128. *
  15129. * function Bar() {
  15130. * this.c = 3;
  15131. * }
  15132. *
  15133. * Foo.prototype.b = 2;
  15134. * Bar.prototype.d = 4;
  15135. *
  15136. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  15137. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  15138. */
  15139. var assignIn = createAssigner(function(object, source) {
  15140. copyObject(source, keysIn(source), object);
  15141. });
  15142. /**
  15143. * This method is like `_.assignIn` except that it accepts `customizer`
  15144. * which is invoked to produce the assigned values. If `customizer` returns
  15145. * `undefined`, assignment is handled by the method instead. The `customizer`
  15146. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  15147. *
  15148. * **Note:** This method mutates `object`.
  15149. *
  15150. * @static
  15151. * @memberOf _
  15152. * @since 4.0.0
  15153. * @alias extendWith
  15154. * @category Object
  15155. * @param {Object} object The destination object.
  15156. * @param {...Object} sources The source objects.
  15157. * @param {Function} [customizer] The function to customize assigned values.
  15158. * @returns {Object} Returns `object`.
  15159. * @see _.assignWith
  15160. * @example
  15161. *
  15162. * function customizer(objValue, srcValue) {
  15163. * return _.isUndefined(objValue) ? srcValue : objValue;
  15164. * }
  15165. *
  15166. * var defaults = _.partialRight(_.assignInWith, customizer);
  15167. *
  15168. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  15169. * // => { 'a': 1, 'b': 2 }
  15170. */
  15171. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  15172. copyObject(source, keysIn(source), object, customizer);
  15173. });
  15174. /**
  15175. * This method is like `_.assign` except that it accepts `customizer`
  15176. * which is invoked to produce the assigned values. If `customizer` returns
  15177. * `undefined`, assignment is handled by the method instead. The `customizer`
  15178. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  15179. *
  15180. * **Note:** This method mutates `object`.
  15181. *
  15182. * @static
  15183. * @memberOf _
  15184. * @since 4.0.0
  15185. * @category Object
  15186. * @param {Object} object The destination object.
  15187. * @param {...Object} sources The source objects.
  15188. * @param {Function} [customizer] The function to customize assigned values.
  15189. * @returns {Object} Returns `object`.
  15190. * @see _.assignInWith
  15191. * @example
  15192. *
  15193. * function customizer(objValue, srcValue) {
  15194. * return _.isUndefined(objValue) ? srcValue : objValue;
  15195. * }
  15196. *
  15197. * var defaults = _.partialRight(_.assignWith, customizer);
  15198. *
  15199. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  15200. * // => { 'a': 1, 'b': 2 }
  15201. */
  15202. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  15203. copyObject(source, keys(source), object, customizer);
  15204. });
  15205. /**
  15206. * Creates an array of values corresponding to `paths` of `object`.
  15207. *
  15208. * @static
  15209. * @memberOf _
  15210. * @since 1.0.0
  15211. * @category Object
  15212. * @param {Object} object The object to iterate over.
  15213. * @param {...(string|string[])} [paths] The property paths to pick.
  15214. * @returns {Array} Returns the picked values.
  15215. * @example
  15216. *
  15217. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  15218. *
  15219. * _.at(object, ['a[0].b.c', 'a[1]']);
  15220. * // => [3, 4]
  15221. */
  15222. var at = flatRest(baseAt);
  15223. /**
  15224. * Creates an object that inherits from the `prototype` object. If a
  15225. * `properties` object is given, its own enumerable string keyed properties
  15226. * are assigned to the created object.
  15227. *
  15228. * @static
  15229. * @memberOf _
  15230. * @since 2.3.0
  15231. * @category Object
  15232. * @param {Object} prototype The object to inherit from.
  15233. * @param {Object} [properties] The properties to assign to the object.
  15234. * @returns {Object} Returns the new object.
  15235. * @example
  15236. *
  15237. * function Shape() {
  15238. * this.x = 0;
  15239. * this.y = 0;
  15240. * }
  15241. *
  15242. * function Circle() {
  15243. * Shape.call(this);
  15244. * }
  15245. *
  15246. * Circle.prototype = _.create(Shape.prototype, {
  15247. * 'constructor': Circle
  15248. * });
  15249. *
  15250. * var circle = new Circle;
  15251. * circle instanceof Circle;
  15252. * // => true
  15253. *
  15254. * circle instanceof Shape;
  15255. * // => true
  15256. */
  15257. function create(prototype, properties) {
  15258. var result = baseCreate(prototype);
  15259. return properties == null ? result : baseAssign(result, properties);
  15260. }
  15261. /**
  15262. * Assigns own and inherited enumerable string keyed properties of source
  15263. * objects to the destination object for all destination properties that
  15264. * resolve to `undefined`. Source objects are applied from left to right.
  15265. * Once a property is set, additional values of the same property are ignored.
  15266. *
  15267. * **Note:** This method mutates `object`.
  15268. *
  15269. * @static
  15270. * @since 0.1.0
  15271. * @memberOf _
  15272. * @category Object
  15273. * @param {Object} object The destination object.
  15274. * @param {...Object} [sources] The source objects.
  15275. * @returns {Object} Returns `object`.
  15276. * @see _.defaultsDeep
  15277. * @example
  15278. *
  15279. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  15280. * // => { 'a': 1, 'b': 2 }
  15281. */
  15282. var defaults = baseRest(function(object, sources) {
  15283. object = Object(object);
  15284. var index = -1;
  15285. var length = sources.length;
  15286. var guard = length > 2 ? sources[2] : undefined;
  15287. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  15288. length = 1;
  15289. }
  15290. while (++index < length) {
  15291. var source = sources[index];
  15292. var props = keysIn(source);
  15293. var propsIndex = -1;
  15294. var propsLength = props.length;
  15295. while (++propsIndex < propsLength) {
  15296. var key = props[propsIndex];
  15297. var value = object[key];
  15298. if (value === undefined ||
  15299. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  15300. object[key] = source[key];
  15301. }
  15302. }
  15303. }
  15304. return object;
  15305. });
  15306. /**
  15307. * This method is like `_.defaults` except that it recursively assigns
  15308. * default properties.
  15309. *
  15310. * **Note:** This method mutates `object`.
  15311. *
  15312. * @static
  15313. * @memberOf _
  15314. * @since 3.10.0
  15315. * @category Object
  15316. * @param {Object} object The destination object.
  15317. * @param {...Object} [sources] The source objects.
  15318. * @returns {Object} Returns `object`.
  15319. * @see _.defaults
  15320. * @example
  15321. *
  15322. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  15323. * // => { 'a': { 'b': 2, 'c': 3 } }
  15324. */
  15325. var defaultsDeep = baseRest(function(args) {
  15326. args.push(undefined, customDefaultsMerge);
  15327. return apply(mergeWith, undefined, args);
  15328. });
  15329. /**
  15330. * This method is like `_.find` except that it returns the key of the first
  15331. * element `predicate` returns truthy for instead of the element itself.
  15332. *
  15333. * @static
  15334. * @memberOf _
  15335. * @since 1.1.0
  15336. * @category Object
  15337. * @param {Object} object The object to inspect.
  15338. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  15339. * @returns {string|undefined} Returns the key of the matched element,
  15340. * else `undefined`.
  15341. * @example
  15342. *
  15343. * var users = {
  15344. * 'barney': { 'age': 36, 'active': true },
  15345. * 'fred': { 'age': 40, 'active': false },
  15346. * 'pebbles': { 'age': 1, 'active': true }
  15347. * };
  15348. *
  15349. * _.findKey(users, function(o) { return o.age < 40; });
  15350. * // => 'barney' (iteration order is not guaranteed)
  15351. *
  15352. * // The `_.matches` iteratee shorthand.
  15353. * _.findKey(users, { 'age': 1, 'active': true });
  15354. * // => 'pebbles'
  15355. *
  15356. * // The `_.matchesProperty` iteratee shorthand.
  15357. * _.findKey(users, ['active', false]);
  15358. * // => 'fred'
  15359. *
  15360. * // The `_.property` iteratee shorthand.
  15361. * _.findKey(users, 'active');
  15362. * // => 'barney'
  15363. */
  15364. function findKey(object, predicate) {
  15365. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  15366. }
  15367. /**
  15368. * This method is like `_.findKey` except that it iterates over elements of
  15369. * a collection in the opposite order.
  15370. *
  15371. * @static
  15372. * @memberOf _
  15373. * @since 2.0.0
  15374. * @category Object
  15375. * @param {Object} object The object to inspect.
  15376. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  15377. * @returns {string|undefined} Returns the key of the matched element,
  15378. * else `undefined`.
  15379. * @example
  15380. *
  15381. * var users = {
  15382. * 'barney': { 'age': 36, 'active': true },
  15383. * 'fred': { 'age': 40, 'active': false },
  15384. * 'pebbles': { 'age': 1, 'active': true }
  15385. * };
  15386. *
  15387. * _.findLastKey(users, function(o) { return o.age < 40; });
  15388. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  15389. *
  15390. * // The `_.matches` iteratee shorthand.
  15391. * _.findLastKey(users, { 'age': 36, 'active': true });
  15392. * // => 'barney'
  15393. *
  15394. * // The `_.matchesProperty` iteratee shorthand.
  15395. * _.findLastKey(users, ['active', false]);
  15396. * // => 'fred'
  15397. *
  15398. * // The `_.property` iteratee shorthand.
  15399. * _.findLastKey(users, 'active');
  15400. * // => 'pebbles'
  15401. */
  15402. function findLastKey(object, predicate) {
  15403. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  15404. }
  15405. /**
  15406. * Iterates over own and inherited enumerable string keyed properties of an
  15407. * object and invokes `iteratee` for each property. The iteratee is invoked
  15408. * with three arguments: (value, key, object). Iteratee functions may exit
  15409. * iteration early by explicitly returning `false`.
  15410. *
  15411. * @static
  15412. * @memberOf _
  15413. * @since 0.3.0
  15414. * @category Object
  15415. * @param {Object} object The object to iterate over.
  15416. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15417. * @returns {Object} Returns `object`.
  15418. * @see _.forInRight
  15419. * @example
  15420. *
  15421. * function Foo() {
  15422. * this.a = 1;
  15423. * this.b = 2;
  15424. * }
  15425. *
  15426. * Foo.prototype.c = 3;
  15427. *
  15428. * _.forIn(new Foo, function(value, key) {
  15429. * console.log(key);
  15430. * });
  15431. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  15432. */
  15433. function forIn(object, iteratee) {
  15434. return object == null
  15435. ? object
  15436. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  15437. }
  15438. /**
  15439. * This method is like `_.forIn` except that it iterates over properties of
  15440. * `object` in the opposite order.
  15441. *
  15442. * @static
  15443. * @memberOf _
  15444. * @since 2.0.0
  15445. * @category Object
  15446. * @param {Object} object The object to iterate over.
  15447. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15448. * @returns {Object} Returns `object`.
  15449. * @see _.forIn
  15450. * @example
  15451. *
  15452. * function Foo() {
  15453. * this.a = 1;
  15454. * this.b = 2;
  15455. * }
  15456. *
  15457. * Foo.prototype.c = 3;
  15458. *
  15459. * _.forInRight(new Foo, function(value, key) {
  15460. * console.log(key);
  15461. * });
  15462. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  15463. */
  15464. function forInRight(object, iteratee) {
  15465. return object == null
  15466. ? object
  15467. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  15468. }
  15469. /**
  15470. * Iterates over own enumerable string keyed properties of an object and
  15471. * invokes `iteratee` for each property. The iteratee is invoked with three
  15472. * arguments: (value, key, object). Iteratee functions may exit iteration
  15473. * early by explicitly returning `false`.
  15474. *
  15475. * @static
  15476. * @memberOf _
  15477. * @since 0.3.0
  15478. * @category Object
  15479. * @param {Object} object The object to iterate over.
  15480. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15481. * @returns {Object} Returns `object`.
  15482. * @see _.forOwnRight
  15483. * @example
  15484. *
  15485. * function Foo() {
  15486. * this.a = 1;
  15487. * this.b = 2;
  15488. * }
  15489. *
  15490. * Foo.prototype.c = 3;
  15491. *
  15492. * _.forOwn(new Foo, function(value, key) {
  15493. * console.log(key);
  15494. * });
  15495. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  15496. */
  15497. function forOwn(object, iteratee) {
  15498. return object && baseForOwn(object, getIteratee(iteratee, 3));
  15499. }
  15500. /**
  15501. * This method is like `_.forOwn` except that it iterates over properties of
  15502. * `object` in the opposite order.
  15503. *
  15504. * @static
  15505. * @memberOf _
  15506. * @since 2.0.0
  15507. * @category Object
  15508. * @param {Object} object The object to iterate over.
  15509. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15510. * @returns {Object} Returns `object`.
  15511. * @see _.forOwn
  15512. * @example
  15513. *
  15514. * function Foo() {
  15515. * this.a = 1;
  15516. * this.b = 2;
  15517. * }
  15518. *
  15519. * Foo.prototype.c = 3;
  15520. *
  15521. * _.forOwnRight(new Foo, function(value, key) {
  15522. * console.log(key);
  15523. * });
  15524. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  15525. */
  15526. function forOwnRight(object, iteratee) {
  15527. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  15528. }
  15529. /**
  15530. * Creates an array of function property names from own enumerable properties
  15531. * of `object`.
  15532. *
  15533. * @static
  15534. * @since 0.1.0
  15535. * @memberOf _
  15536. * @category Object
  15537. * @param {Object} object The object to inspect.
  15538. * @returns {Array} Returns the function names.
  15539. * @see _.functionsIn
  15540. * @example
  15541. *
  15542. * function Foo() {
  15543. * this.a = _.constant('a');
  15544. * this.b = _.constant('b');
  15545. * }
  15546. *
  15547. * Foo.prototype.c = _.constant('c');
  15548. *
  15549. * _.functions(new Foo);
  15550. * // => ['a', 'b']
  15551. */
  15552. function functions(object) {
  15553. return object == null ? [] : baseFunctions(object, keys(object));
  15554. }
  15555. /**
  15556. * Creates an array of function property names from own and inherited
  15557. * enumerable properties of `object`.
  15558. *
  15559. * @static
  15560. * @memberOf _
  15561. * @since 4.0.0
  15562. * @category Object
  15563. * @param {Object} object The object to inspect.
  15564. * @returns {Array} Returns the function names.
  15565. * @see _.functions
  15566. * @example
  15567. *
  15568. * function Foo() {
  15569. * this.a = _.constant('a');
  15570. * this.b = _.constant('b');
  15571. * }
  15572. *
  15573. * Foo.prototype.c = _.constant('c');
  15574. *
  15575. * _.functionsIn(new Foo);
  15576. * // => ['a', 'b', 'c']
  15577. */
  15578. function functionsIn(object) {
  15579. return object == null ? [] : baseFunctions(object, keysIn(object));
  15580. }
  15581. /**
  15582. * Gets the value at `path` of `object`. If the resolved value is
  15583. * `undefined`, the `defaultValue` is returned in its place.
  15584. *
  15585. * @static
  15586. * @memberOf _
  15587. * @since 3.7.0
  15588. * @category Object
  15589. * @param {Object} object The object to query.
  15590. * @param {Array|string} path The path of the property to get.
  15591. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  15592. * @returns {*} Returns the resolved value.
  15593. * @example
  15594. *
  15595. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  15596. *
  15597. * _.get(object, 'a[0].b.c');
  15598. * // => 3
  15599. *
  15600. * _.get(object, ['a', '0', 'b', 'c']);
  15601. * // => 3
  15602. *
  15603. * _.get(object, 'a.b.c', 'default');
  15604. * // => 'default'
  15605. */
  15606. function get(object, path, defaultValue) {
  15607. var result = object == null ? undefined : baseGet(object, path);
  15608. return result === undefined ? defaultValue : result;
  15609. }
  15610. /**
  15611. * Checks if `path` is a direct property of `object`.
  15612. *
  15613. * @static
  15614. * @since 0.1.0
  15615. * @memberOf _
  15616. * @category Object
  15617. * @param {Object} object The object to query.
  15618. * @param {Array|string} path The path to check.
  15619. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  15620. * @example
  15621. *
  15622. * var object = { 'a': { 'b': 2 } };
  15623. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  15624. *
  15625. * _.has(object, 'a');
  15626. * // => true
  15627. *
  15628. * _.has(object, 'a.b');
  15629. * // => true
  15630. *
  15631. * _.has(object, ['a', 'b']);
  15632. * // => true
  15633. *
  15634. * _.has(other, 'a');
  15635. * // => false
  15636. */
  15637. function has(object, path) {
  15638. return object != null && hasPath(object, path, baseHas);
  15639. }
  15640. /**
  15641. * Checks if `path` is a direct or inherited property of `object`.
  15642. *
  15643. * @static
  15644. * @memberOf _
  15645. * @since 4.0.0
  15646. * @category Object
  15647. * @param {Object} object The object to query.
  15648. * @param {Array|string} path The path to check.
  15649. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  15650. * @example
  15651. *
  15652. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  15653. *
  15654. * _.hasIn(object, 'a');
  15655. * // => true
  15656. *
  15657. * _.hasIn(object, 'a.b');
  15658. * // => true
  15659. *
  15660. * _.hasIn(object, ['a', 'b']);
  15661. * // => true
  15662. *
  15663. * _.hasIn(object, 'b');
  15664. * // => false
  15665. */
  15666. function hasIn(object, path) {
  15667. return object != null && hasPath(object, path, baseHasIn);
  15668. }
  15669. /**
  15670. * Creates an object composed of the inverted keys and values of `object`.
  15671. * If `object` contains duplicate values, subsequent values overwrite
  15672. * property assignments of previous values.
  15673. *
  15674. * @static
  15675. * @memberOf _
  15676. * @since 0.7.0
  15677. * @category Object
  15678. * @param {Object} object The object to invert.
  15679. * @returns {Object} Returns the new inverted object.
  15680. * @example
  15681. *
  15682. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  15683. *
  15684. * _.invert(object);
  15685. * // => { '1': 'c', '2': 'b' }
  15686. */
  15687. var invert = createInverter(function(result, value, key) {
  15688. if (value != null &&
  15689. typeof value.toString != 'function') {
  15690. value = nativeObjectToString.call(value);
  15691. }
  15692. result[value] = key;
  15693. }, constant(identity));
  15694. /**
  15695. * This method is like `_.invert` except that the inverted object is generated
  15696. * from the results of running each element of `object` thru `iteratee`. The
  15697. * corresponding inverted value of each inverted key is an array of keys
  15698. * responsible for generating the inverted value. The iteratee is invoked
  15699. * with one argument: (value).
  15700. *
  15701. * @static
  15702. * @memberOf _
  15703. * @since 4.1.0
  15704. * @category Object
  15705. * @param {Object} object The object to invert.
  15706. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15707. * @returns {Object} Returns the new inverted object.
  15708. * @example
  15709. *
  15710. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  15711. *
  15712. * _.invertBy(object);
  15713. * // => { '1': ['a', 'c'], '2': ['b'] }
  15714. *
  15715. * _.invertBy(object, function(value) {
  15716. * return 'group' + value;
  15717. * });
  15718. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  15719. */
  15720. var invertBy = createInverter(function(result, value, key) {
  15721. if (value != null &&
  15722. typeof value.toString != 'function') {
  15723. value = nativeObjectToString.call(value);
  15724. }
  15725. if (hasOwnProperty.call(result, value)) {
  15726. result[value].push(key);
  15727. } else {
  15728. result[value] = [key];
  15729. }
  15730. }, getIteratee);
  15731. /**
  15732. * Invokes the method at `path` of `object`.
  15733. *
  15734. * @static
  15735. * @memberOf _
  15736. * @since 4.0.0
  15737. * @category Object
  15738. * @param {Object} object The object to query.
  15739. * @param {Array|string} path The path of the method to invoke.
  15740. * @param {...*} [args] The arguments to invoke the method with.
  15741. * @returns {*} Returns the result of the invoked method.
  15742. * @example
  15743. *
  15744. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  15745. *
  15746. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  15747. * // => [2, 3]
  15748. */
  15749. var invoke = baseRest(baseInvoke);
  15750. /**
  15751. * Creates an array of the own enumerable property names of `object`.
  15752. *
  15753. * **Note:** Non-object values are coerced to objects. See the
  15754. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  15755. * for more details.
  15756. *
  15757. * @static
  15758. * @since 0.1.0
  15759. * @memberOf _
  15760. * @category Object
  15761. * @param {Object} object The object to query.
  15762. * @returns {Array} Returns the array of property names.
  15763. * @example
  15764. *
  15765. * function Foo() {
  15766. * this.a = 1;
  15767. * this.b = 2;
  15768. * }
  15769. *
  15770. * Foo.prototype.c = 3;
  15771. *
  15772. * _.keys(new Foo);
  15773. * // => ['a', 'b'] (iteration order is not guaranteed)
  15774. *
  15775. * _.keys('hi');
  15776. * // => ['0', '1']
  15777. */
  15778. function keys(object) {
  15779. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  15780. }
  15781. /**
  15782. * Creates an array of the own and inherited enumerable property names of `object`.
  15783. *
  15784. * **Note:** Non-object values are coerced to objects.
  15785. *
  15786. * @static
  15787. * @memberOf _
  15788. * @since 3.0.0
  15789. * @category Object
  15790. * @param {Object} object The object to query.
  15791. * @returns {Array} Returns the array of property names.
  15792. * @example
  15793. *
  15794. * function Foo() {
  15795. * this.a = 1;
  15796. * this.b = 2;
  15797. * }
  15798. *
  15799. * Foo.prototype.c = 3;
  15800. *
  15801. * _.keysIn(new Foo);
  15802. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  15803. */
  15804. function keysIn(object) {
  15805. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  15806. }
  15807. /**
  15808. * The opposite of `_.mapValues`; this method creates an object with the
  15809. * same values as `object` and keys generated by running each own enumerable
  15810. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  15811. * with three arguments: (value, key, object).
  15812. *
  15813. * @static
  15814. * @memberOf _
  15815. * @since 3.8.0
  15816. * @category Object
  15817. * @param {Object} object The object to iterate over.
  15818. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15819. * @returns {Object} Returns the new mapped object.
  15820. * @see _.mapValues
  15821. * @example
  15822. *
  15823. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  15824. * return key + value;
  15825. * });
  15826. * // => { 'a1': 1, 'b2': 2 }
  15827. */
  15828. function mapKeys(object, iteratee) {
  15829. var result = {};
  15830. iteratee = getIteratee(iteratee, 3);
  15831. baseForOwn(object, function(value, key, object) {
  15832. baseAssignValue(result, iteratee(value, key, object), value);
  15833. });
  15834. return result;
  15835. }
  15836. /**
  15837. * Creates an object with the same keys as `object` and values generated
  15838. * by running each own enumerable string keyed property of `object` thru
  15839. * `iteratee`. The iteratee is invoked with three arguments:
  15840. * (value, key, object).
  15841. *
  15842. * @static
  15843. * @memberOf _
  15844. * @since 2.4.0
  15845. * @category Object
  15846. * @param {Object} object The object to iterate over.
  15847. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15848. * @returns {Object} Returns the new mapped object.
  15849. * @see _.mapKeys
  15850. * @example
  15851. *
  15852. * var users = {
  15853. * 'fred': { 'user': 'fred', 'age': 40 },
  15854. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  15855. * };
  15856. *
  15857. * _.mapValues(users, function(o) { return o.age; });
  15858. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  15859. *
  15860. * // The `_.property` iteratee shorthand.
  15861. * _.mapValues(users, 'age');
  15862. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  15863. */
  15864. function mapValues(object, iteratee) {
  15865. var result = {};
  15866. iteratee = getIteratee(iteratee, 3);
  15867. baseForOwn(object, function(value, key, object) {
  15868. baseAssignValue(result, key, iteratee(value, key, object));
  15869. });
  15870. return result;
  15871. }
  15872. /**
  15873. * This method is like `_.assign` except that it recursively merges own and
  15874. * inherited enumerable string keyed properties of source objects into the
  15875. * destination object. Source properties that resolve to `undefined` are
  15876. * skipped if a destination value exists. Array and plain object properties
  15877. * are merged recursively. Other objects and value types are overridden by
  15878. * assignment. Source objects are applied from left to right. Subsequent
  15879. * sources overwrite property assignments of previous sources.
  15880. *
  15881. * **Note:** This method mutates `object`.
  15882. *
  15883. * @static
  15884. * @memberOf _
  15885. * @since 0.5.0
  15886. * @category Object
  15887. * @param {Object} object The destination object.
  15888. * @param {...Object} [sources] The source objects.
  15889. * @returns {Object} Returns `object`.
  15890. * @example
  15891. *
  15892. * var object = {
  15893. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  15894. * };
  15895. *
  15896. * var other = {
  15897. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  15898. * };
  15899. *
  15900. * _.merge(object, other);
  15901. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  15902. */
  15903. var merge = createAssigner(function(object, source, srcIndex) {
  15904. baseMerge(object, source, srcIndex);
  15905. });
  15906. /**
  15907. * This method is like `_.merge` except that it accepts `customizer` which
  15908. * is invoked to produce the merged values of the destination and source
  15909. * properties. If `customizer` returns `undefined`, merging is handled by the
  15910. * method instead. The `customizer` is invoked with six arguments:
  15911. * (objValue, srcValue, key, object, source, stack).
  15912. *
  15913. * **Note:** This method mutates `object`.
  15914. *
  15915. * @static
  15916. * @memberOf _
  15917. * @since 4.0.0
  15918. * @category Object
  15919. * @param {Object} object The destination object.
  15920. * @param {...Object} sources The source objects.
  15921. * @param {Function} customizer The function to customize assigned values.
  15922. * @returns {Object} Returns `object`.
  15923. * @example
  15924. *
  15925. * function customizer(objValue, srcValue) {
  15926. * if (_.isArray(objValue)) {
  15927. * return objValue.concat(srcValue);
  15928. * }
  15929. * }
  15930. *
  15931. * var object = { 'a': [1], 'b': [2] };
  15932. * var other = { 'a': [3], 'b': [4] };
  15933. *
  15934. * _.mergeWith(object, other, customizer);
  15935. * // => { 'a': [1, 3], 'b': [2, 4] }
  15936. */
  15937. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  15938. baseMerge(object, source, srcIndex, customizer);
  15939. });
  15940. /**
  15941. * The opposite of `_.pick`; this method creates an object composed of the
  15942. * own and inherited enumerable property paths of `object` that are not omitted.
  15943. *
  15944. * **Note:** This method is considerably slower than `_.pick`.
  15945. *
  15946. * @static
  15947. * @since 0.1.0
  15948. * @memberOf _
  15949. * @category Object
  15950. * @param {Object} object The source object.
  15951. * @param {...(string|string[])} [paths] The property paths to omit.
  15952. * @returns {Object} Returns the new object.
  15953. * @example
  15954. *
  15955. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  15956. *
  15957. * _.omit(object, ['a', 'c']);
  15958. * // => { 'b': '2' }
  15959. */
  15960. var omit = flatRest(function(object, paths) {
  15961. var result = {};
  15962. if (object == null) {
  15963. return result;
  15964. }
  15965. var isDeep = false;
  15966. paths = arrayMap(paths, function(path) {
  15967. path = castPath(path, object);
  15968. isDeep || (isDeep = path.length > 1);
  15969. return path;
  15970. });
  15971. copyObject(object, getAllKeysIn(object), result);
  15972. if (isDeep) {
  15973. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  15974. }
  15975. var length = paths.length;
  15976. while (length--) {
  15977. baseUnset(result, paths[length]);
  15978. }
  15979. return result;
  15980. });
  15981. /**
  15982. * The opposite of `_.pickBy`; this method creates an object composed of
  15983. * the own and inherited enumerable string keyed properties of `object` that
  15984. * `predicate` doesn't return truthy for. The predicate is invoked with two
  15985. * arguments: (value, key).
  15986. *
  15987. * @static
  15988. * @memberOf _
  15989. * @since 4.0.0
  15990. * @category Object
  15991. * @param {Object} object The source object.
  15992. * @param {Function} [predicate=_.identity] The function invoked per property.
  15993. * @returns {Object} Returns the new object.
  15994. * @example
  15995. *
  15996. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  15997. *
  15998. * _.omitBy(object, _.isNumber);
  15999. * // => { 'b': '2' }
  16000. */
  16001. function omitBy(object, predicate) {
  16002. return pickBy(object, negate(getIteratee(predicate)));
  16003. }
  16004. /**
  16005. * Creates an object composed of the picked `object` properties.
  16006. *
  16007. * @static
  16008. * @since 0.1.0
  16009. * @memberOf _
  16010. * @category Object
  16011. * @param {Object} object The source object.
  16012. * @param {...(string|string[])} [paths] The property paths to pick.
  16013. * @returns {Object} Returns the new object.
  16014. * @example
  16015. *
  16016. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  16017. *
  16018. * _.pick(object, ['a', 'c']);
  16019. * // => { 'a': 1, 'c': 3 }
  16020. */
  16021. var pick = flatRest(function(object, paths) {
  16022. return object == null ? {} : basePick(object, paths);
  16023. });
  16024. /**
  16025. * Creates an object composed of the `object` properties `predicate` returns
  16026. * truthy for. The predicate is invoked with two arguments: (value, key).
  16027. *
  16028. * @static
  16029. * @memberOf _
  16030. * @since 4.0.0
  16031. * @category Object
  16032. * @param {Object} object The source object.
  16033. * @param {Function} [predicate=_.identity] The function invoked per property.
  16034. * @returns {Object} Returns the new object.
  16035. * @example
  16036. *
  16037. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  16038. *
  16039. * _.pickBy(object, _.isNumber);
  16040. * // => { 'a': 1, 'c': 3 }
  16041. */
  16042. function pickBy(object, predicate) {
  16043. if (object == null) {
  16044. return {};
  16045. }
  16046. var props = arrayMap(getAllKeysIn(object), function(prop) {
  16047. return [prop];
  16048. });
  16049. predicate = getIteratee(predicate);
  16050. return basePickBy(object, props, function(value, path) {
  16051. return predicate(value, path[0]);
  16052. });
  16053. }
  16054. /**
  16055. * This method is like `_.get` except that if the resolved value is a
  16056. * function it's invoked with the `this` binding of its parent object and
  16057. * its result is returned.
  16058. *
  16059. * @static
  16060. * @since 0.1.0
  16061. * @memberOf _
  16062. * @category Object
  16063. * @param {Object} object The object to query.
  16064. * @param {Array|string} path The path of the property to resolve.
  16065. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  16066. * @returns {*} Returns the resolved value.
  16067. * @example
  16068. *
  16069. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  16070. *
  16071. * _.result(object, 'a[0].b.c1');
  16072. * // => 3
  16073. *
  16074. * _.result(object, 'a[0].b.c2');
  16075. * // => 4
  16076. *
  16077. * _.result(object, 'a[0].b.c3', 'default');
  16078. * // => 'default'
  16079. *
  16080. * _.result(object, 'a[0].b.c3', _.constant('default'));
  16081. * // => 'default'
  16082. */
  16083. function result(object, path, defaultValue) {
  16084. path = castPath(path, object);
  16085. var index = -1,
  16086. length = path.length;
  16087. // Ensure the loop is entered when path is empty.
  16088. if (!length) {
  16089. length = 1;
  16090. object = undefined;
  16091. }
  16092. while (++index < length) {
  16093. var value = object == null ? undefined : object[toKey(path[index])];
  16094. if (value === undefined) {
  16095. index = length;
  16096. value = defaultValue;
  16097. }
  16098. object = isFunction(value) ? value.call(object) : value;
  16099. }
  16100. return object;
  16101. }
  16102. /**
  16103. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  16104. * it's created. Arrays are created for missing index properties while objects
  16105. * are created for all other missing properties. Use `_.setWith` to customize
  16106. * `path` creation.
  16107. *
  16108. * **Note:** This method mutates `object`.
  16109. *
  16110. * @static
  16111. * @memberOf _
  16112. * @since 3.7.0
  16113. * @category Object
  16114. * @param {Object} object The object to modify.
  16115. * @param {Array|string} path The path of the property to set.
  16116. * @param {*} value The value to set.
  16117. * @returns {Object} Returns `object`.
  16118. * @example
  16119. *
  16120. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  16121. *
  16122. * _.set(object, 'a[0].b.c', 4);
  16123. * console.log(object.a[0].b.c);
  16124. * // => 4
  16125. *
  16126. * _.set(object, ['x', '0', 'y', 'z'], 5);
  16127. * console.log(object.x[0].y.z);
  16128. * // => 5
  16129. */
  16130. function set(object, path, value) {
  16131. return object == null ? object : baseSet(object, path, value);
  16132. }
  16133. /**
  16134. * This method is like `_.set` except that it accepts `customizer` which is
  16135. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  16136. * path creation is handled by the method instead. The `customizer` is invoked
  16137. * with three arguments: (nsValue, key, nsObject).
  16138. *
  16139. * **Note:** This method mutates `object`.
  16140. *
  16141. * @static
  16142. * @memberOf _
  16143. * @since 4.0.0
  16144. * @category Object
  16145. * @param {Object} object The object to modify.
  16146. * @param {Array|string} path The path of the property to set.
  16147. * @param {*} value The value to set.
  16148. * @param {Function} [customizer] The function to customize assigned values.
  16149. * @returns {Object} Returns `object`.
  16150. * @example
  16151. *
  16152. * var object = {};
  16153. *
  16154. * _.setWith(object, '[0][1]', 'a', Object);
  16155. * // => { '0': { '1': 'a' } }
  16156. */
  16157. function setWith(object, path, value, customizer) {
  16158. customizer = typeof customizer == 'function' ? customizer : undefined;
  16159. return object == null ? object : baseSet(object, path, value, customizer);
  16160. }
  16161. /**
  16162. * Creates an array of own enumerable string keyed-value pairs for `object`
  16163. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  16164. * entries are returned.
  16165. *
  16166. * @static
  16167. * @memberOf _
  16168. * @since 4.0.0
  16169. * @alias entries
  16170. * @category Object
  16171. * @param {Object} object The object to query.
  16172. * @returns {Array} Returns the key-value pairs.
  16173. * @example
  16174. *
  16175. * function Foo() {
  16176. * this.a = 1;
  16177. * this.b = 2;
  16178. * }
  16179. *
  16180. * Foo.prototype.c = 3;
  16181. *
  16182. * _.toPairs(new Foo);
  16183. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  16184. */
  16185. var toPairs = createToPairs(keys);
  16186. /**
  16187. * Creates an array of own and inherited enumerable string keyed-value pairs
  16188. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  16189. * or set, its entries are returned.
  16190. *
  16191. * @static
  16192. * @memberOf _
  16193. * @since 4.0.0
  16194. * @alias entriesIn
  16195. * @category Object
  16196. * @param {Object} object The object to query.
  16197. * @returns {Array} Returns the key-value pairs.
  16198. * @example
  16199. *
  16200. * function Foo() {
  16201. * this.a = 1;
  16202. * this.b = 2;
  16203. * }
  16204. *
  16205. * Foo.prototype.c = 3;
  16206. *
  16207. * _.toPairsIn(new Foo);
  16208. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  16209. */
  16210. var toPairsIn = createToPairs(keysIn);
  16211. /**
  16212. * An alternative to `_.reduce`; this method transforms `object` to a new
  16213. * `accumulator` object which is the result of running each of its own
  16214. * enumerable string keyed properties thru `iteratee`, with each invocation
  16215. * potentially mutating the `accumulator` object. If `accumulator` is not
  16216. * provided, a new object with the same `[[Prototype]]` will be used. The
  16217. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  16218. * Iteratee functions may exit iteration early by explicitly returning `false`.
  16219. *
  16220. * @static
  16221. * @memberOf _
  16222. * @since 1.3.0
  16223. * @category Object
  16224. * @param {Object} object The object to iterate over.
  16225. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  16226. * @param {*} [accumulator] The custom accumulator value.
  16227. * @returns {*} Returns the accumulated value.
  16228. * @example
  16229. *
  16230. * _.transform([2, 3, 4], function(result, n) {
  16231. * result.push(n *= n);
  16232. * return n % 2 == 0;
  16233. * }, []);
  16234. * // => [4, 9]
  16235. *
  16236. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  16237. * (result[value] || (result[value] = [])).push(key);
  16238. * }, {});
  16239. * // => { '1': ['a', 'c'], '2': ['b'] }
  16240. */
  16241. function transform(object, iteratee, accumulator) {
  16242. var isArr = isArray(object),
  16243. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  16244. iteratee = getIteratee(iteratee, 4);
  16245. if (accumulator == null) {
  16246. var Ctor = object && object.constructor;
  16247. if (isArrLike) {
  16248. accumulator = isArr ? new Ctor : [];
  16249. }
  16250. else if (isObject(object)) {
  16251. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  16252. }
  16253. else {
  16254. accumulator = {};
  16255. }
  16256. }
  16257. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  16258. return iteratee(accumulator, value, index, object);
  16259. });
  16260. return accumulator;
  16261. }
  16262. /**
  16263. * Removes the property at `path` of `object`.
  16264. *
  16265. * **Note:** This method mutates `object`.
  16266. *
  16267. * @static
  16268. * @memberOf _
  16269. * @since 4.0.0
  16270. * @category Object
  16271. * @param {Object} object The object to modify.
  16272. * @param {Array|string} path The path of the property to unset.
  16273. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  16274. * @example
  16275. *
  16276. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  16277. * _.unset(object, 'a[0].b.c');
  16278. * // => true
  16279. *
  16280. * console.log(object);
  16281. * // => { 'a': [{ 'b': {} }] };
  16282. *
  16283. * _.unset(object, ['a', '0', 'b', 'c']);
  16284. * // => true
  16285. *
  16286. * console.log(object);
  16287. * // => { 'a': [{ 'b': {} }] };
  16288. */
  16289. function unset(object, path) {
  16290. return object == null ? true : baseUnset(object, path);
  16291. }
  16292. /**
  16293. * This method is like `_.set` except that accepts `updater` to produce the
  16294. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  16295. * is invoked with one argument: (value).
  16296. *
  16297. * **Note:** This method mutates `object`.
  16298. *
  16299. * @static
  16300. * @memberOf _
  16301. * @since 4.6.0
  16302. * @category Object
  16303. * @param {Object} object The object to modify.
  16304. * @param {Array|string} path The path of the property to set.
  16305. * @param {Function} updater The function to produce the updated value.
  16306. * @returns {Object} Returns `object`.
  16307. * @example
  16308. *
  16309. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  16310. *
  16311. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  16312. * console.log(object.a[0].b.c);
  16313. * // => 9
  16314. *
  16315. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  16316. * console.log(object.x[0].y.z);
  16317. * // => 0
  16318. */
  16319. function update(object, path, updater) {
  16320. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  16321. }
  16322. /**
  16323. * This method is like `_.update` except that it accepts `customizer` which is
  16324. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  16325. * path creation is handled by the method instead. The `customizer` is invoked
  16326. * with three arguments: (nsValue, key, nsObject).
  16327. *
  16328. * **Note:** This method mutates `object`.
  16329. *
  16330. * @static
  16331. * @memberOf _
  16332. * @since 4.6.0
  16333. * @category Object
  16334. * @param {Object} object The object to modify.
  16335. * @param {Array|string} path The path of the property to set.
  16336. * @param {Function} updater The function to produce the updated value.
  16337. * @param {Function} [customizer] The function to customize assigned values.
  16338. * @returns {Object} Returns `object`.
  16339. * @example
  16340. *
  16341. * var object = {};
  16342. *
  16343. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  16344. * // => { '0': { '1': 'a' } }
  16345. */
  16346. function updateWith(object, path, updater, customizer) {
  16347. customizer = typeof customizer == 'function' ? customizer : undefined;
  16348. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  16349. }
  16350. /**
  16351. * Creates an array of the own enumerable string keyed property values of `object`.
  16352. *
  16353. * **Note:** Non-object values are coerced to objects.
  16354. *
  16355. * @static
  16356. * @since 0.1.0
  16357. * @memberOf _
  16358. * @category Object
  16359. * @param {Object} object The object to query.
  16360. * @returns {Array} Returns the array of property values.
  16361. * @example
  16362. *
  16363. * function Foo() {
  16364. * this.a = 1;
  16365. * this.b = 2;
  16366. * }
  16367. *
  16368. * Foo.prototype.c = 3;
  16369. *
  16370. * _.values(new Foo);
  16371. * // => [1, 2] (iteration order is not guaranteed)
  16372. *
  16373. * _.values('hi');
  16374. * // => ['h', 'i']
  16375. */
  16376. function values(object) {
  16377. return object == null ? [] : baseValues(object, keys(object));
  16378. }
  16379. /**
  16380. * Creates an array of the own and inherited enumerable string keyed property
  16381. * values of `object`.
  16382. *
  16383. * **Note:** Non-object values are coerced to objects.
  16384. *
  16385. * @static
  16386. * @memberOf _
  16387. * @since 3.0.0
  16388. * @category Object
  16389. * @param {Object} object The object to query.
  16390. * @returns {Array} Returns the array of property values.
  16391. * @example
  16392. *
  16393. * function Foo() {
  16394. * this.a = 1;
  16395. * this.b = 2;
  16396. * }
  16397. *
  16398. * Foo.prototype.c = 3;
  16399. *
  16400. * _.valuesIn(new Foo);
  16401. * // => [1, 2, 3] (iteration order is not guaranteed)
  16402. */
  16403. function valuesIn(object) {
  16404. return object == null ? [] : baseValues(object, keysIn(object));
  16405. }
  16406. /*------------------------------------------------------------------------*/
  16407. /**
  16408. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  16409. *
  16410. * @static
  16411. * @memberOf _
  16412. * @since 4.0.0
  16413. * @category Number
  16414. * @param {number} number The number to clamp.
  16415. * @param {number} [lower] The lower bound.
  16416. * @param {number} upper The upper bound.
  16417. * @returns {number} Returns the clamped number.
  16418. * @example
  16419. *
  16420. * _.clamp(-10, -5, 5);
  16421. * // => -5
  16422. *
  16423. * _.clamp(10, -5, 5);
  16424. * // => 5
  16425. */
  16426. function clamp(number, lower, upper) {
  16427. if (upper === undefined) {
  16428. upper = lower;
  16429. lower = undefined;
  16430. }
  16431. if (upper !== undefined) {
  16432. upper = toNumber(upper);
  16433. upper = upper === upper ? upper : 0;
  16434. }
  16435. if (lower !== undefined) {
  16436. lower = toNumber(lower);
  16437. lower = lower === lower ? lower : 0;
  16438. }
  16439. return baseClamp(toNumber(number), lower, upper);
  16440. }
  16441. /**
  16442. * Checks if `n` is between `start` and up to, but not including, `end`. If
  16443. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  16444. * If `start` is greater than `end` the params are swapped to support
  16445. * negative ranges.
  16446. *
  16447. * @static
  16448. * @memberOf _
  16449. * @since 3.3.0
  16450. * @category Number
  16451. * @param {number} number The number to check.
  16452. * @param {number} [start=0] The start of the range.
  16453. * @param {number} end The end of the range.
  16454. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  16455. * @see _.range, _.rangeRight
  16456. * @example
  16457. *
  16458. * _.inRange(3, 2, 4);
  16459. * // => true
  16460. *
  16461. * _.inRange(4, 8);
  16462. * // => true
  16463. *
  16464. * _.inRange(4, 2);
  16465. * // => false
  16466. *
  16467. * _.inRange(2, 2);
  16468. * // => false
  16469. *
  16470. * _.inRange(1.2, 2);
  16471. * // => true
  16472. *
  16473. * _.inRange(5.2, 4);
  16474. * // => false
  16475. *
  16476. * _.inRange(-3, -2, -6);
  16477. * // => true
  16478. */
  16479. function inRange(number, start, end) {
  16480. start = toFinite(start);
  16481. if (end === undefined) {
  16482. end = start;
  16483. start = 0;
  16484. } else {
  16485. end = toFinite(end);
  16486. }
  16487. number = toNumber(number);
  16488. return baseInRange(number, start, end);
  16489. }
  16490. /**
  16491. * Produces a random number between the inclusive `lower` and `upper` bounds.
  16492. * If only one argument is provided a number between `0` and the given number
  16493. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  16494. * floats, a floating-point number is returned instead of an integer.
  16495. *
  16496. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  16497. * floating-point values which can produce unexpected results.
  16498. *
  16499. * @static
  16500. * @memberOf _
  16501. * @since 0.7.0
  16502. * @category Number
  16503. * @param {number} [lower=0] The lower bound.
  16504. * @param {number} [upper=1] The upper bound.
  16505. * @param {boolean} [floating] Specify returning a floating-point number.
  16506. * @returns {number} Returns the random number.
  16507. * @example
  16508. *
  16509. * _.random(0, 5);
  16510. * // => an integer between 0 and 5
  16511. *
  16512. * _.random(5);
  16513. * // => also an integer between 0 and 5
  16514. *
  16515. * _.random(5, true);
  16516. * // => a floating-point number between 0 and 5
  16517. *
  16518. * _.random(1.2, 5.2);
  16519. * // => a floating-point number between 1.2 and 5.2
  16520. */
  16521. function random(lower, upper, floating) {
  16522. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  16523. upper = floating = undefined;
  16524. }
  16525. if (floating === undefined) {
  16526. if (typeof upper == 'boolean') {
  16527. floating = upper;
  16528. upper = undefined;
  16529. }
  16530. else if (typeof lower == 'boolean') {
  16531. floating = lower;
  16532. lower = undefined;
  16533. }
  16534. }
  16535. if (lower === undefined && upper === undefined) {
  16536. lower = 0;
  16537. upper = 1;
  16538. }
  16539. else {
  16540. lower = toFinite(lower);
  16541. if (upper === undefined) {
  16542. upper = lower;
  16543. lower = 0;
  16544. } else {
  16545. upper = toFinite(upper);
  16546. }
  16547. }
  16548. if (lower > upper) {
  16549. var temp = lower;
  16550. lower = upper;
  16551. upper = temp;
  16552. }
  16553. if (floating || lower % 1 || upper % 1) {
  16554. var rand = nativeRandom();
  16555. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  16556. }
  16557. return baseRandom(lower, upper);
  16558. }
  16559. /*------------------------------------------------------------------------*/
  16560. /**
  16561. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  16562. *
  16563. * @static
  16564. * @memberOf _
  16565. * @since 3.0.0
  16566. * @category String
  16567. * @param {string} [string=''] The string to convert.
  16568. * @returns {string} Returns the camel cased string.
  16569. * @example
  16570. *
  16571. * _.camelCase('Foo Bar');
  16572. * // => 'fooBar'
  16573. *
  16574. * _.camelCase('--foo-bar--');
  16575. * // => 'fooBar'
  16576. *
  16577. * _.camelCase('__FOO_BAR__');
  16578. * // => 'fooBar'
  16579. */
  16580. var camelCase = createCompounder(function(result, word, index) {
  16581. word = word.toLowerCase();
  16582. return result + (index ? capitalize(word) : word);
  16583. });
  16584. /**
  16585. * Converts the first character of `string` to upper case and the remaining
  16586. * to lower case.
  16587. *
  16588. * @static
  16589. * @memberOf _
  16590. * @since 3.0.0
  16591. * @category String
  16592. * @param {string} [string=''] The string to capitalize.
  16593. * @returns {string} Returns the capitalized string.
  16594. * @example
  16595. *
  16596. * _.capitalize('FRED');
  16597. * // => 'Fred'
  16598. */
  16599. function capitalize(string) {
  16600. return upperFirst(toString(string).toLowerCase());
  16601. }
  16602. /**
  16603. * Deburrs `string` by converting
  16604. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  16605. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  16606. * letters to basic Latin letters and removing
  16607. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  16608. *
  16609. * @static
  16610. * @memberOf _
  16611. * @since 3.0.0
  16612. * @category String
  16613. * @param {string} [string=''] The string to deburr.
  16614. * @returns {string} Returns the deburred string.
  16615. * @example
  16616. *
  16617. * _.deburr('déjà vu');
  16618. * // => 'deja vu'
  16619. */
  16620. function deburr(string) {
  16621. string = toString(string);
  16622. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  16623. }
  16624. /**
  16625. * Checks if `string` ends with the given target string.
  16626. *
  16627. * @static
  16628. * @memberOf _
  16629. * @since 3.0.0
  16630. * @category String
  16631. * @param {string} [string=''] The string to inspect.
  16632. * @param {string} [target] The string to search for.
  16633. * @param {number} [position=string.length] The position to search up to.
  16634. * @returns {boolean} Returns `true` if `string` ends with `target`,
  16635. * else `false`.
  16636. * @example
  16637. *
  16638. * _.endsWith('abc', 'c');
  16639. * // => true
  16640. *
  16641. * _.endsWith('abc', 'b');
  16642. * // => false
  16643. *
  16644. * _.endsWith('abc', 'b', 2);
  16645. * // => true
  16646. */
  16647. function endsWith(string, target, position) {
  16648. string = toString(string);
  16649. target = baseToString(target);
  16650. var length = string.length;
  16651. position = position === undefined
  16652. ? length
  16653. : baseClamp(toInteger(position), 0, length);
  16654. var end = position;
  16655. position -= target.length;
  16656. return position >= 0 && string.slice(position, end) == target;
  16657. }
  16658. /**
  16659. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  16660. * corresponding HTML entities.
  16661. *
  16662. * **Note:** No other characters are escaped. To escape additional
  16663. * characters use a third-party library like [_he_](https://mths.be/he).
  16664. *
  16665. * Though the ">" character is escaped for symmetry, characters like
  16666. * ">" and "/" don't need escaping in HTML and have no special meaning
  16667. * unless they're part of a tag or unquoted attribute value. See
  16668. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  16669. * (under "semi-related fun fact") for more details.
  16670. *
  16671. * When working with HTML you should always
  16672. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  16673. * XSS vectors.
  16674. *
  16675. * @static
  16676. * @since 0.1.0
  16677. * @memberOf _
  16678. * @category String
  16679. * @param {string} [string=''] The string to escape.
  16680. * @returns {string} Returns the escaped string.
  16681. * @example
  16682. *
  16683. * _.escape('fred, barney, & pebbles');
  16684. * // => 'fred, barney, &amp; pebbles'
  16685. */
  16686. function escape(string) {
  16687. string = toString(string);
  16688. return (string && reHasUnescapedHtml.test(string))
  16689. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  16690. : string;
  16691. }
  16692. /**
  16693. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  16694. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  16695. *
  16696. * @static
  16697. * @memberOf _
  16698. * @since 3.0.0
  16699. * @category String
  16700. * @param {string} [string=''] The string to escape.
  16701. * @returns {string} Returns the escaped string.
  16702. * @example
  16703. *
  16704. * _.escapeRegExp('[lodash](https://lodash.com/)');
  16705. * // => '\[lodash\]\(https://lodash\.com/\)'
  16706. */
  16707. function escapeRegExp(string) {
  16708. string = toString(string);
  16709. return (string && reHasRegExpChar.test(string))
  16710. ? string.replace(reRegExpChar, '\\$&')
  16711. : string;
  16712. }
  16713. /**
  16714. * Converts `string` to
  16715. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  16716. *
  16717. * @static
  16718. * @memberOf _
  16719. * @since 3.0.0
  16720. * @category String
  16721. * @param {string} [string=''] The string to convert.
  16722. * @returns {string} Returns the kebab cased string.
  16723. * @example
  16724. *
  16725. * _.kebabCase('Foo Bar');
  16726. * // => 'foo-bar'
  16727. *
  16728. * _.kebabCase('fooBar');
  16729. * // => 'foo-bar'
  16730. *
  16731. * _.kebabCase('__FOO_BAR__');
  16732. * // => 'foo-bar'
  16733. */
  16734. var kebabCase = createCompounder(function(result, word, index) {
  16735. return result + (index ? '-' : '') + word.toLowerCase();
  16736. });
  16737. /**
  16738. * Converts `string`, as space separated words, to lower case.
  16739. *
  16740. * @static
  16741. * @memberOf _
  16742. * @since 4.0.0
  16743. * @category String
  16744. * @param {string} [string=''] The string to convert.
  16745. * @returns {string} Returns the lower cased string.
  16746. * @example
  16747. *
  16748. * _.lowerCase('--Foo-Bar--');
  16749. * // => 'foo bar'
  16750. *
  16751. * _.lowerCase('fooBar');
  16752. * // => 'foo bar'
  16753. *
  16754. * _.lowerCase('__FOO_BAR__');
  16755. * // => 'foo bar'
  16756. */
  16757. var lowerCase = createCompounder(function(result, word, index) {
  16758. return result + (index ? ' ' : '') + word.toLowerCase();
  16759. });
  16760. /**
  16761. * Converts the first character of `string` to lower case.
  16762. *
  16763. * @static
  16764. * @memberOf _
  16765. * @since 4.0.0
  16766. * @category String
  16767. * @param {string} [string=''] The string to convert.
  16768. * @returns {string} Returns the converted string.
  16769. * @example
  16770. *
  16771. * _.lowerFirst('Fred');
  16772. * // => 'fred'
  16773. *
  16774. * _.lowerFirst('FRED');
  16775. * // => 'fRED'
  16776. */
  16777. var lowerFirst = createCaseFirst('toLowerCase');
  16778. /**
  16779. * Pads `string` on the left and right sides if it's shorter than `length`.
  16780. * Padding characters are truncated if they can't be evenly divided by `length`.
  16781. *
  16782. * @static
  16783. * @memberOf _
  16784. * @since 3.0.0
  16785. * @category String
  16786. * @param {string} [string=''] The string to pad.
  16787. * @param {number} [length=0] The padding length.
  16788. * @param {string} [chars=' '] The string used as padding.
  16789. * @returns {string} Returns the padded string.
  16790. * @example
  16791. *
  16792. * _.pad('abc', 8);
  16793. * // => ' abc '
  16794. *
  16795. * _.pad('abc', 8, '_-');
  16796. * // => '_-abc_-_'
  16797. *
  16798. * _.pad('abc', 3);
  16799. * // => 'abc'
  16800. */
  16801. function pad(string, length, chars) {
  16802. string = toString(string);
  16803. length = toInteger(length);
  16804. var strLength = length ? stringSize(string) : 0;
  16805. if (!length || strLength >= length) {
  16806. return string;
  16807. }
  16808. var mid = (length - strLength) / 2;
  16809. return (
  16810. createPadding(nativeFloor(mid), chars) +
  16811. string +
  16812. createPadding(nativeCeil(mid), chars)
  16813. );
  16814. }
  16815. /**
  16816. * Pads `string` on the right side if it's shorter than `length`. Padding
  16817. * characters are truncated if they exceed `length`.
  16818. *
  16819. * @static
  16820. * @memberOf _
  16821. * @since 4.0.0
  16822. * @category String
  16823. * @param {string} [string=''] The string to pad.
  16824. * @param {number} [length=0] The padding length.
  16825. * @param {string} [chars=' '] The string used as padding.
  16826. * @returns {string} Returns the padded string.
  16827. * @example
  16828. *
  16829. * _.padEnd('abc', 6);
  16830. * // => 'abc '
  16831. *
  16832. * _.padEnd('abc', 6, '_-');
  16833. * // => 'abc_-_'
  16834. *
  16835. * _.padEnd('abc', 3);
  16836. * // => 'abc'
  16837. */
  16838. function padEnd(string, length, chars) {
  16839. string = toString(string);
  16840. length = toInteger(length);
  16841. var strLength = length ? stringSize(string) : 0;
  16842. return (length && strLength < length)
  16843. ? (string + createPadding(length - strLength, chars))
  16844. : string;
  16845. }
  16846. /**
  16847. * Pads `string` on the left side if it's shorter than `length`. Padding
  16848. * characters are truncated if they exceed `length`.
  16849. *
  16850. * @static
  16851. * @memberOf _
  16852. * @since 4.0.0
  16853. * @category String
  16854. * @param {string} [string=''] The string to pad.
  16855. * @param {number} [length=0] The padding length.
  16856. * @param {string} [chars=' '] The string used as padding.
  16857. * @returns {string} Returns the padded string.
  16858. * @example
  16859. *
  16860. * _.padStart('abc', 6);
  16861. * // => ' abc'
  16862. *
  16863. * _.padStart('abc', 6, '_-');
  16864. * // => '_-_abc'
  16865. *
  16866. * _.padStart('abc', 3);
  16867. * // => 'abc'
  16868. */
  16869. function padStart(string, length, chars) {
  16870. string = toString(string);
  16871. length = toInteger(length);
  16872. var strLength = length ? stringSize(string) : 0;
  16873. return (length && strLength < length)
  16874. ? (createPadding(length - strLength, chars) + string)
  16875. : string;
  16876. }
  16877. /**
  16878. * Converts `string` to an integer of the specified radix. If `radix` is
  16879. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  16880. * hexadecimal, in which case a `radix` of `16` is used.
  16881. *
  16882. * **Note:** This method aligns with the
  16883. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  16884. *
  16885. * @static
  16886. * @memberOf _
  16887. * @since 1.1.0
  16888. * @category String
  16889. * @param {string} string The string to convert.
  16890. * @param {number} [radix=10] The radix to interpret `value` by.
  16891. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  16892. * @returns {number} Returns the converted integer.
  16893. * @example
  16894. *
  16895. * _.parseInt('08');
  16896. * // => 8
  16897. *
  16898. * _.map(['6', '08', '10'], _.parseInt);
  16899. * // => [6, 8, 10]
  16900. */
  16901. function parseInt(string, radix, guard) {
  16902. if (guard || radix == null) {
  16903. radix = 0;
  16904. } else if (radix) {
  16905. radix = +radix;
  16906. }
  16907. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  16908. }
  16909. /**
  16910. * Repeats the given string `n` times.
  16911. *
  16912. * @static
  16913. * @memberOf _
  16914. * @since 3.0.0
  16915. * @category String
  16916. * @param {string} [string=''] The string to repeat.
  16917. * @param {number} [n=1] The number of times to repeat the string.
  16918. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  16919. * @returns {string} Returns the repeated string.
  16920. * @example
  16921. *
  16922. * _.repeat('*', 3);
  16923. * // => '***'
  16924. *
  16925. * _.repeat('abc', 2);
  16926. * // => 'abcabc'
  16927. *
  16928. * _.repeat('abc', 0);
  16929. * // => ''
  16930. */
  16931. function repeat(string, n, guard) {
  16932. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  16933. n = 1;
  16934. } else {
  16935. n = toInteger(n);
  16936. }
  16937. return baseRepeat(toString(string), n);
  16938. }
  16939. /**
  16940. * Replaces matches for `pattern` in `string` with `replacement`.
  16941. *
  16942. * **Note:** This method is based on
  16943. * [`String#replace`](https://mdn.io/String/replace).
  16944. *
  16945. * @static
  16946. * @memberOf _
  16947. * @since 4.0.0
  16948. * @category String
  16949. * @param {string} [string=''] The string to modify.
  16950. * @param {RegExp|string} pattern The pattern to replace.
  16951. * @param {Function|string} replacement The match replacement.
  16952. * @returns {string} Returns the modified string.
  16953. * @example
  16954. *
  16955. * _.replace('Hi Fred', 'Fred', 'Barney');
  16956. * // => 'Hi Barney'
  16957. */
  16958. function replace() {
  16959. var args = arguments,
  16960. string = toString(args[0]);
  16961. return args.length < 3 ? string : string.replace(args[1], args[2]);
  16962. }
  16963. /**
  16964. * Converts `string` to
  16965. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  16966. *
  16967. * @static
  16968. * @memberOf _
  16969. * @since 3.0.0
  16970. * @category String
  16971. * @param {string} [string=''] The string to convert.
  16972. * @returns {string} Returns the snake cased string.
  16973. * @example
  16974. *
  16975. * _.snakeCase('Foo Bar');
  16976. * // => 'foo_bar'
  16977. *
  16978. * _.snakeCase('fooBar');
  16979. * // => 'foo_bar'
  16980. *
  16981. * _.snakeCase('--FOO-BAR--');
  16982. * // => 'foo_bar'
  16983. */
  16984. var snakeCase = createCompounder(function(result, word, index) {
  16985. return result + (index ? '_' : '') + word.toLowerCase();
  16986. });
  16987. /**
  16988. * Splits `string` by `separator`.
  16989. *
  16990. * **Note:** This method is based on
  16991. * [`String#split`](https://mdn.io/String/split).
  16992. *
  16993. * @static
  16994. * @memberOf _
  16995. * @since 4.0.0
  16996. * @category String
  16997. * @param {string} [string=''] The string to split.
  16998. * @param {RegExp|string} separator The separator pattern to split by.
  16999. * @param {number} [limit] The length to truncate results to.
  17000. * @returns {Array} Returns the string segments.
  17001. * @example
  17002. *
  17003. * _.split('a-b-c', '-', 2);
  17004. * // => ['a', 'b']
  17005. */
  17006. function split(string, separator, limit) {
  17007. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  17008. separator = limit = undefined;
  17009. }
  17010. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  17011. if (!limit) {
  17012. return [];
  17013. }
  17014. string = toString(string);
  17015. if (string && (
  17016. typeof separator == 'string' ||
  17017. (separator != null && !isRegExp(separator))
  17018. )) {
  17019. separator = baseToString(separator);
  17020. if (!separator && hasUnicode(string)) {
  17021. return castSlice(stringToArray(string), 0, limit);
  17022. }
  17023. }
  17024. return string.split(separator, limit);
  17025. }
  17026. /**
  17027. * Converts `string` to
  17028. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  17029. *
  17030. * @static
  17031. * @memberOf _
  17032. * @since 3.1.0
  17033. * @category String
  17034. * @param {string} [string=''] The string to convert.
  17035. * @returns {string} Returns the start cased string.
  17036. * @example
  17037. *
  17038. * _.startCase('--foo-bar--');
  17039. * // => 'Foo Bar'
  17040. *
  17041. * _.startCase('fooBar');
  17042. * // => 'Foo Bar'
  17043. *
  17044. * _.startCase('__FOO_BAR__');
  17045. * // => 'FOO BAR'
  17046. */
  17047. var startCase = createCompounder(function(result, word, index) {
  17048. return result + (index ? ' ' : '') + upperFirst(word);
  17049. });
  17050. /**
  17051. * Checks if `string` starts with the given target string.
  17052. *
  17053. * @static
  17054. * @memberOf _
  17055. * @since 3.0.0
  17056. * @category String
  17057. * @param {string} [string=''] The string to inspect.
  17058. * @param {string} [target] The string to search for.
  17059. * @param {number} [position=0] The position to search from.
  17060. * @returns {boolean} Returns `true` if `string` starts with `target`,
  17061. * else `false`.
  17062. * @example
  17063. *
  17064. * _.startsWith('abc', 'a');
  17065. * // => true
  17066. *
  17067. * _.startsWith('abc', 'b');
  17068. * // => false
  17069. *
  17070. * _.startsWith('abc', 'b', 1);
  17071. * // => true
  17072. */
  17073. function startsWith(string, target, position) {
  17074. string = toString(string);
  17075. position = position == null
  17076. ? 0
  17077. : baseClamp(toInteger(position), 0, string.length);
  17078. target = baseToString(target);
  17079. return string.slice(position, position + target.length) == target;
  17080. }
  17081. /**
  17082. * Creates a compiled template function that can interpolate data properties
  17083. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  17084. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  17085. * properties may be accessed as free variables in the template. If a setting
  17086. * object is given, it takes precedence over `_.templateSettings` values.
  17087. *
  17088. * **Note:** In the development build `_.template` utilizes
  17089. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  17090. * for easier debugging.
  17091. *
  17092. * For more information on precompiling templates see
  17093. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  17094. *
  17095. * For more information on Chrome extension sandboxes see
  17096. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  17097. *
  17098. * @static
  17099. * @since 0.1.0
  17100. * @memberOf _
  17101. * @category String
  17102. * @param {string} [string=''] The template string.
  17103. * @param {Object} [options={}] The options object.
  17104. * @param {RegExp} [options.escape=_.templateSettings.escape]
  17105. * The HTML "escape" delimiter.
  17106. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  17107. * The "evaluate" delimiter.
  17108. * @param {Object} [options.imports=_.templateSettings.imports]
  17109. * An object to import into the template as free variables.
  17110. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  17111. * The "interpolate" delimiter.
  17112. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  17113. * The sourceURL of the compiled template.
  17114. * @param {string} [options.variable='obj']
  17115. * The data object variable name.
  17116. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  17117. * @returns {Function} Returns the compiled template function.
  17118. * @example
  17119. *
  17120. * // Use the "interpolate" delimiter to create a compiled template.
  17121. * var compiled = _.template('hello <%= user %>!');
  17122. * compiled({ 'user': 'fred' });
  17123. * // => 'hello fred!'
  17124. *
  17125. * // Use the HTML "escape" delimiter to escape data property values.
  17126. * var compiled = _.template('<b><%- value %></b>');
  17127. * compiled({ 'value': '<script>' });
  17128. * // => '<b>&lt;script&gt;</b>'
  17129. *
  17130. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  17131. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  17132. * compiled({ 'users': ['fred', 'barney'] });
  17133. * // => '<li>fred</li><li>barney</li>'
  17134. *
  17135. * // Use the internal `print` function in "evaluate" delimiters.
  17136. * var compiled = _.template('<% print("hello " + user); %>!');
  17137. * compiled({ 'user': 'barney' });
  17138. * // => 'hello barney!'
  17139. *
  17140. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  17141. * // Disable support by replacing the "interpolate" delimiter.
  17142. * var compiled = _.template('hello ${ user }!');
  17143. * compiled({ 'user': 'pebbles' });
  17144. * // => 'hello pebbles!'
  17145. *
  17146. * // Use backslashes to treat delimiters as plain text.
  17147. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  17148. * compiled({ 'value': 'ignored' });
  17149. * // => '<%- value %>'
  17150. *
  17151. * // Use the `imports` option to import `jQuery` as `jq`.
  17152. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  17153. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  17154. * compiled({ 'users': ['fred', 'barney'] });
  17155. * // => '<li>fred</li><li>barney</li>'
  17156. *
  17157. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  17158. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  17159. * compiled(data);
  17160. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  17161. *
  17162. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  17163. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  17164. * compiled.source;
  17165. * // => function(data) {
  17166. * // var __t, __p = '';
  17167. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  17168. * // return __p;
  17169. * // }
  17170. *
  17171. * // Use custom template delimiters.
  17172. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  17173. * var compiled = _.template('hello {{ user }}!');
  17174. * compiled({ 'user': 'mustache' });
  17175. * // => 'hello mustache!'
  17176. *
  17177. * // Use the `source` property to inline compiled templates for meaningful
  17178. * // line numbers in error messages and stack traces.
  17179. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  17180. * var JST = {\
  17181. * "main": ' + _.template(mainText).source + '\
  17182. * };\
  17183. * ');
  17184. */
  17185. function template(string, options, guard) {
  17186. // Based on John Resig's `tmpl` implementation
  17187. // (http://ejohn.org/blog/javascript-micro-templating/)
  17188. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  17189. var settings = lodash.templateSettings;
  17190. if (guard && isIterateeCall(string, options, guard)) {
  17191. options = undefined;
  17192. }
  17193. string = toString(string);
  17194. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  17195. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  17196. importsKeys = keys(imports),
  17197. importsValues = baseValues(imports, importsKeys);
  17198. var isEscaping,
  17199. isEvaluating,
  17200. index = 0,
  17201. interpolate = options.interpolate || reNoMatch,
  17202. source = "__p += '";
  17203. // Compile the regexp to match each delimiter.
  17204. var reDelimiters = RegExp(
  17205. (options.escape || reNoMatch).source + '|' +
  17206. interpolate.source + '|' +
  17207. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  17208. (options.evaluate || reNoMatch).source + '|$'
  17209. , 'g');
  17210. // Use a sourceURL for easier debugging.
  17211. // The sourceURL gets injected into the source that's eval-ed, so be careful
  17212. // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
  17213. // and escape the comment, thus injecting code that gets evaled.
  17214. var sourceURL = '//# sourceURL=' +
  17215. (hasOwnProperty.call(options, 'sourceURL')
  17216. ? (options.sourceURL + '').replace(/\s/g, ' ')
  17217. : ('lodash.templateSources[' + (++templateCounter) + ']')
  17218. ) + '\n';
  17219. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  17220. interpolateValue || (interpolateValue = esTemplateValue);
  17221. // Escape characters that can't be included in string literals.
  17222. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  17223. // Replace delimiters with snippets.
  17224. if (escapeValue) {
  17225. isEscaping = true;
  17226. source += "' +\n__e(" + escapeValue + ") +\n'";
  17227. }
  17228. if (evaluateValue) {
  17229. isEvaluating = true;
  17230. source += "';\n" + evaluateValue + ";\n__p += '";
  17231. }
  17232. if (interpolateValue) {
  17233. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  17234. }
  17235. index = offset + match.length;
  17236. // The JS engine embedded in Adobe products needs `match` returned in
  17237. // order to produce the correct `offset` value.
  17238. return match;
  17239. });
  17240. source += "';\n";
  17241. // If `variable` is not specified wrap a with-statement around the generated
  17242. // code to add the data object to the top of the scope chain.
  17243. var variable = hasOwnProperty.call(options, 'variable') && options.variable;
  17244. if (!variable) {
  17245. source = 'with (obj) {\n' + source + '\n}\n';
  17246. }
  17247. // Cleanup code by stripping empty strings.
  17248. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  17249. .replace(reEmptyStringMiddle, '$1')
  17250. .replace(reEmptyStringTrailing, '$1;');
  17251. // Frame code as the function body.
  17252. source = 'function(' + (variable || 'obj') + ') {\n' +
  17253. (variable
  17254. ? ''
  17255. : 'obj || (obj = {});\n'
  17256. ) +
  17257. "var __t, __p = ''" +
  17258. (isEscaping
  17259. ? ', __e = _.escape'
  17260. : ''
  17261. ) +
  17262. (isEvaluating
  17263. ? ', __j = Array.prototype.join;\n' +
  17264. "function print() { __p += __j.call(arguments, '') }\n"
  17265. : ';\n'
  17266. ) +
  17267. source +
  17268. 'return __p\n}';
  17269. var result = attempt(function() {
  17270. return Function(importsKeys, sourceURL + 'return ' + source)
  17271. .apply(undefined, importsValues);
  17272. });
  17273. // Provide the compiled function's source by its `toString` method or
  17274. // the `source` property as a convenience for inlining compiled templates.
  17275. result.source = source;
  17276. if (isError(result)) {
  17277. throw result;
  17278. }
  17279. return result;
  17280. }
  17281. /**
  17282. * Converts `string`, as a whole, to lower case just like
  17283. * [String#toLowerCase](https://mdn.io/toLowerCase).
  17284. *
  17285. * @static
  17286. * @memberOf _
  17287. * @since 4.0.0
  17288. * @category String
  17289. * @param {string} [string=''] The string to convert.
  17290. * @returns {string} Returns the lower cased string.
  17291. * @example
  17292. *
  17293. * _.toLower('--Foo-Bar--');
  17294. * // => '--foo-bar--'
  17295. *
  17296. * _.toLower('fooBar');
  17297. * // => 'foobar'
  17298. *
  17299. * _.toLower('__FOO_BAR__');
  17300. * // => '__foo_bar__'
  17301. */
  17302. function toLower(value) {
  17303. return toString(value).toLowerCase();
  17304. }
  17305. /**
  17306. * Converts `string`, as a whole, to upper case just like
  17307. * [String#toUpperCase](https://mdn.io/toUpperCase).
  17308. *
  17309. * @static
  17310. * @memberOf _
  17311. * @since 4.0.0
  17312. * @category String
  17313. * @param {string} [string=''] The string to convert.
  17314. * @returns {string} Returns the upper cased string.
  17315. * @example
  17316. *
  17317. * _.toUpper('--foo-bar--');
  17318. * // => '--FOO-BAR--'
  17319. *
  17320. * _.toUpper('fooBar');
  17321. * // => 'FOOBAR'
  17322. *
  17323. * _.toUpper('__foo_bar__');
  17324. * // => '__FOO_BAR__'
  17325. */
  17326. function toUpper(value) {
  17327. return toString(value).toUpperCase();
  17328. }
  17329. /**
  17330. * Removes leading and trailing whitespace or specified characters from `string`.
  17331. *
  17332. * @static
  17333. * @memberOf _
  17334. * @since 3.0.0
  17335. * @category String
  17336. * @param {string} [string=''] The string to trim.
  17337. * @param {string} [chars=whitespace] The characters to trim.
  17338. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  17339. * @returns {string} Returns the trimmed string.
  17340. * @example
  17341. *
  17342. * _.trim(' abc ');
  17343. * // => 'abc'
  17344. *
  17345. * _.trim('-_-abc-_-', '_-');
  17346. * // => 'abc'
  17347. *
  17348. * _.map([' foo ', ' bar '], _.trim);
  17349. * // => ['foo', 'bar']
  17350. */
  17351. function trim(string, chars, guard) {
  17352. string = toString(string);
  17353. if (string && (guard || chars === undefined)) {
  17354. return string.replace(reTrim, '');
  17355. }
  17356. if (!string || !(chars = baseToString(chars))) {
  17357. return string;
  17358. }
  17359. var strSymbols = stringToArray(string),
  17360. chrSymbols = stringToArray(chars),
  17361. start = charsStartIndex(strSymbols, chrSymbols),
  17362. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  17363. return castSlice(strSymbols, start, end).join('');
  17364. }
  17365. /**
  17366. * Removes trailing whitespace or specified characters from `string`.
  17367. *
  17368. * @static
  17369. * @memberOf _
  17370. * @since 4.0.0
  17371. * @category String
  17372. * @param {string} [string=''] The string to trim.
  17373. * @param {string} [chars=whitespace] The characters to trim.
  17374. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  17375. * @returns {string} Returns the trimmed string.
  17376. * @example
  17377. *
  17378. * _.trimEnd(' abc ');
  17379. * // => ' abc'
  17380. *
  17381. * _.trimEnd('-_-abc-_-', '_-');
  17382. * // => '-_-abc'
  17383. */
  17384. function trimEnd(string, chars, guard) {
  17385. string = toString(string);
  17386. if (string && (guard || chars === undefined)) {
  17387. return string.replace(reTrimEnd, '');
  17388. }
  17389. if (!string || !(chars = baseToString(chars))) {
  17390. return string;
  17391. }
  17392. var strSymbols = stringToArray(string),
  17393. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  17394. return castSlice(strSymbols, 0, end).join('');
  17395. }
  17396. /**
  17397. * Removes leading whitespace or specified characters from `string`.
  17398. *
  17399. * @static
  17400. * @memberOf _
  17401. * @since 4.0.0
  17402. * @category String
  17403. * @param {string} [string=''] The string to trim.
  17404. * @param {string} [chars=whitespace] The characters to trim.
  17405. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  17406. * @returns {string} Returns the trimmed string.
  17407. * @example
  17408. *
  17409. * _.trimStart(' abc ');
  17410. * // => 'abc '
  17411. *
  17412. * _.trimStart('-_-abc-_-', '_-');
  17413. * // => 'abc-_-'
  17414. */
  17415. function trimStart(string, chars, guard) {
  17416. string = toString(string);
  17417. if (string && (guard || chars === undefined)) {
  17418. return string.replace(reTrimStart, '');
  17419. }
  17420. if (!string || !(chars = baseToString(chars))) {
  17421. return string;
  17422. }
  17423. var strSymbols = stringToArray(string),
  17424. start = charsStartIndex(strSymbols, stringToArray(chars));
  17425. return castSlice(strSymbols, start).join('');
  17426. }
  17427. /**
  17428. * Truncates `string` if it's longer than the given maximum string length.
  17429. * The last characters of the truncated string are replaced with the omission
  17430. * string which defaults to "...".
  17431. *
  17432. * @static
  17433. * @memberOf _
  17434. * @since 4.0.0
  17435. * @category String
  17436. * @param {string} [string=''] The string to truncate.
  17437. * @param {Object} [options={}] The options object.
  17438. * @param {number} [options.length=30] The maximum string length.
  17439. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  17440. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  17441. * @returns {string} Returns the truncated string.
  17442. * @example
  17443. *
  17444. * _.truncate('hi-diddly-ho there, neighborino');
  17445. * // => 'hi-diddly-ho there, neighbo...'
  17446. *
  17447. * _.truncate('hi-diddly-ho there, neighborino', {
  17448. * 'length': 24,
  17449. * 'separator': ' '
  17450. * });
  17451. * // => 'hi-diddly-ho there,...'
  17452. *
  17453. * _.truncate('hi-diddly-ho there, neighborino', {
  17454. * 'length': 24,
  17455. * 'separator': /,? +/
  17456. * });
  17457. * // => 'hi-diddly-ho there...'
  17458. *
  17459. * _.truncate('hi-diddly-ho there, neighborino', {
  17460. * 'omission': ' [...]'
  17461. * });
  17462. * // => 'hi-diddly-ho there, neig [...]'
  17463. */
  17464. function truncate(string, options) {
  17465. var length = DEFAULT_TRUNC_LENGTH,
  17466. omission = DEFAULT_TRUNC_OMISSION;
  17467. if (isObject(options)) {
  17468. var separator = 'separator' in options ? options.separator : separator;
  17469. length = 'length' in options ? toInteger(options.length) : length;
  17470. omission = 'omission' in options ? baseToString(options.omission) : omission;
  17471. }
  17472. string = toString(string);
  17473. var strLength = string.length;
  17474. if (hasUnicode(string)) {
  17475. var strSymbols = stringToArray(string);
  17476. strLength = strSymbols.length;
  17477. }
  17478. if (length >= strLength) {
  17479. return string;
  17480. }
  17481. var end = length - stringSize(omission);
  17482. if (end < 1) {
  17483. return omission;
  17484. }
  17485. var result = strSymbols
  17486. ? castSlice(strSymbols, 0, end).join('')
  17487. : string.slice(0, end);
  17488. if (separator === undefined) {
  17489. return result + omission;
  17490. }
  17491. if (strSymbols) {
  17492. end += (result.length - end);
  17493. }
  17494. if (isRegExp(separator)) {
  17495. if (string.slice(end).search(separator)) {
  17496. var match,
  17497. substring = result;
  17498. if (!separator.global) {
  17499. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  17500. }
  17501. separator.lastIndex = 0;
  17502. while ((match = separator.exec(substring))) {
  17503. var newEnd = match.index;
  17504. }
  17505. result = result.slice(0, newEnd === undefined ? end : newEnd);
  17506. }
  17507. } else if (string.indexOf(baseToString(separator), end) != end) {
  17508. var index = result.lastIndexOf(separator);
  17509. if (index > -1) {
  17510. result = result.slice(0, index);
  17511. }
  17512. }
  17513. return result + omission;
  17514. }
  17515. /**
  17516. * The inverse of `_.escape`; this method converts the HTML entities
  17517. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  17518. * their corresponding characters.
  17519. *
  17520. * **Note:** No other HTML entities are unescaped. To unescape additional
  17521. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  17522. *
  17523. * @static
  17524. * @memberOf _
  17525. * @since 0.6.0
  17526. * @category String
  17527. * @param {string} [string=''] The string to unescape.
  17528. * @returns {string} Returns the unescaped string.
  17529. * @example
  17530. *
  17531. * _.unescape('fred, barney, &amp; pebbles');
  17532. * // => 'fred, barney, & pebbles'
  17533. */
  17534. function unescape(string) {
  17535. string = toString(string);
  17536. return (string && reHasEscapedHtml.test(string))
  17537. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  17538. : string;
  17539. }
  17540. /**
  17541. * Converts `string`, as space separated words, to upper case.
  17542. *
  17543. * @static
  17544. * @memberOf _
  17545. * @since 4.0.0
  17546. * @category String
  17547. * @param {string} [string=''] The string to convert.
  17548. * @returns {string} Returns the upper cased string.
  17549. * @example
  17550. *
  17551. * _.upperCase('--foo-bar');
  17552. * // => 'FOO BAR'
  17553. *
  17554. * _.upperCase('fooBar');
  17555. * // => 'FOO BAR'
  17556. *
  17557. * _.upperCase('__foo_bar__');
  17558. * // => 'FOO BAR'
  17559. */
  17560. var upperCase = createCompounder(function(result, word, index) {
  17561. return result + (index ? ' ' : '') + word.toUpperCase();
  17562. });
  17563. /**
  17564. * Converts the first character of `string` to upper case.
  17565. *
  17566. * @static
  17567. * @memberOf _
  17568. * @since 4.0.0
  17569. * @category String
  17570. * @param {string} [string=''] The string to convert.
  17571. * @returns {string} Returns the converted string.
  17572. * @example
  17573. *
  17574. * _.upperFirst('fred');
  17575. * // => 'Fred'
  17576. *
  17577. * _.upperFirst('FRED');
  17578. * // => 'FRED'
  17579. */
  17580. var upperFirst = createCaseFirst('toUpperCase');
  17581. /**
  17582. * Splits `string` into an array of its words.
  17583. *
  17584. * @static
  17585. * @memberOf _
  17586. * @since 3.0.0
  17587. * @category String
  17588. * @param {string} [string=''] The string to inspect.
  17589. * @param {RegExp|string} [pattern] The pattern to match words.
  17590. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  17591. * @returns {Array} Returns the words of `string`.
  17592. * @example
  17593. *
  17594. * _.words('fred, barney, & pebbles');
  17595. * // => ['fred', 'barney', 'pebbles']
  17596. *
  17597. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  17598. * // => ['fred', 'barney', '&', 'pebbles']
  17599. */
  17600. function words(string, pattern, guard) {
  17601. string = toString(string);
  17602. pattern = guard ? undefined : pattern;
  17603. if (pattern === undefined) {
  17604. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  17605. }
  17606. return string.match(pattern) || [];
  17607. }
  17608. /*------------------------------------------------------------------------*/
  17609. /**
  17610. * Attempts to invoke `func`, returning either the result or the caught error
  17611. * object. Any additional arguments are provided to `func` when it's invoked.
  17612. *
  17613. * @static
  17614. * @memberOf _
  17615. * @since 3.0.0
  17616. * @category Util
  17617. * @param {Function} func The function to attempt.
  17618. * @param {...*} [args] The arguments to invoke `func` with.
  17619. * @returns {*} Returns the `func` result or error object.
  17620. * @example
  17621. *
  17622. * // Avoid throwing errors for invalid selectors.
  17623. * var elements = _.attempt(function(selector) {
  17624. * return document.querySelectorAll(selector);
  17625. * }, '>_>');
  17626. *
  17627. * if (_.isError(elements)) {
  17628. * elements = [];
  17629. * }
  17630. */
  17631. var attempt = baseRest(function(func, args) {
  17632. try {
  17633. return apply(func, undefined, args);
  17634. } catch (e) {
  17635. return isError(e) ? e : new Error(e);
  17636. }
  17637. });
  17638. /**
  17639. * Binds methods of an object to the object itself, overwriting the existing
  17640. * method.
  17641. *
  17642. * **Note:** This method doesn't set the "length" property of bound functions.
  17643. *
  17644. * @static
  17645. * @since 0.1.0
  17646. * @memberOf _
  17647. * @category Util
  17648. * @param {Object} object The object to bind and assign the bound methods to.
  17649. * @param {...(string|string[])} methodNames The object method names to bind.
  17650. * @returns {Object} Returns `object`.
  17651. * @example
  17652. *
  17653. * var view = {
  17654. * 'label': 'docs',
  17655. * 'click': function() {
  17656. * console.log('clicked ' + this.label);
  17657. * }
  17658. * };
  17659. *
  17660. * _.bindAll(view, ['click']);
  17661. * jQuery(element).on('click', view.click);
  17662. * // => Logs 'clicked docs' when clicked.
  17663. */
  17664. var bindAll = flatRest(function(object, methodNames) {
  17665. arrayEach(methodNames, function(key) {
  17666. key = toKey(key);
  17667. baseAssignValue(object, key, bind(object[key], object));
  17668. });
  17669. return object;
  17670. });
  17671. /**
  17672. * Creates a function that iterates over `pairs` and invokes the corresponding
  17673. * function of the first predicate to return truthy. The predicate-function
  17674. * pairs are invoked with the `this` binding and arguments of the created
  17675. * function.
  17676. *
  17677. * @static
  17678. * @memberOf _
  17679. * @since 4.0.0
  17680. * @category Util
  17681. * @param {Array} pairs The predicate-function pairs.
  17682. * @returns {Function} Returns the new composite function.
  17683. * @example
  17684. *
  17685. * var func = _.cond([
  17686. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  17687. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  17688. * [_.stubTrue, _.constant('no match')]
  17689. * ]);
  17690. *
  17691. * func({ 'a': 1, 'b': 2 });
  17692. * // => 'matches A'
  17693. *
  17694. * func({ 'a': 0, 'b': 1 });
  17695. * // => 'matches B'
  17696. *
  17697. * func({ 'a': '1', 'b': '2' });
  17698. * // => 'no match'
  17699. */
  17700. function cond(pairs) {
  17701. var length = pairs == null ? 0 : pairs.length,
  17702. toIteratee = getIteratee();
  17703. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  17704. if (typeof pair[1] != 'function') {
  17705. throw new TypeError(FUNC_ERROR_TEXT);
  17706. }
  17707. return [toIteratee(pair[0]), pair[1]];
  17708. });
  17709. return baseRest(function(args) {
  17710. var index = -1;
  17711. while (++index < length) {
  17712. var pair = pairs[index];
  17713. if (apply(pair[0], this, args)) {
  17714. return apply(pair[1], this, args);
  17715. }
  17716. }
  17717. });
  17718. }
  17719. /**
  17720. * Creates a function that invokes the predicate properties of `source` with
  17721. * the corresponding property values of a given object, returning `true` if
  17722. * all predicates return truthy, else `false`.
  17723. *
  17724. * **Note:** The created function is equivalent to `_.conformsTo` with
  17725. * `source` partially applied.
  17726. *
  17727. * @static
  17728. * @memberOf _
  17729. * @since 4.0.0
  17730. * @category Util
  17731. * @param {Object} source The object of property predicates to conform to.
  17732. * @returns {Function} Returns the new spec function.
  17733. * @example
  17734. *
  17735. * var objects = [
  17736. * { 'a': 2, 'b': 1 },
  17737. * { 'a': 1, 'b': 2 }
  17738. * ];
  17739. *
  17740. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  17741. * // => [{ 'a': 1, 'b': 2 }]
  17742. */
  17743. function conforms(source) {
  17744. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  17745. }
  17746. /**
  17747. * Creates a function that returns `value`.
  17748. *
  17749. * @static
  17750. * @memberOf _
  17751. * @since 2.4.0
  17752. * @category Util
  17753. * @param {*} value The value to return from the new function.
  17754. * @returns {Function} Returns the new constant function.
  17755. * @example
  17756. *
  17757. * var objects = _.times(2, _.constant({ 'a': 1 }));
  17758. *
  17759. * console.log(objects);
  17760. * // => [{ 'a': 1 }, { 'a': 1 }]
  17761. *
  17762. * console.log(objects[0] === objects[1]);
  17763. * // => true
  17764. */
  17765. function constant(value) {
  17766. return function() {
  17767. return value;
  17768. };
  17769. }
  17770. /**
  17771. * Checks `value` to determine whether a default value should be returned in
  17772. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  17773. * or `undefined`.
  17774. *
  17775. * @static
  17776. * @memberOf _
  17777. * @since 4.14.0
  17778. * @category Util
  17779. * @param {*} value The value to check.
  17780. * @param {*} defaultValue The default value.
  17781. * @returns {*} Returns the resolved value.
  17782. * @example
  17783. *
  17784. * _.defaultTo(1, 10);
  17785. * // => 1
  17786. *
  17787. * _.defaultTo(undefined, 10);
  17788. * // => 10
  17789. */
  17790. function defaultTo(value, defaultValue) {
  17791. return (value == null || value !== value) ? defaultValue : value;
  17792. }
  17793. /**
  17794. * Creates a function that returns the result of invoking the given functions
  17795. * with the `this` binding of the created function, where each successive
  17796. * invocation is supplied the return value of the previous.
  17797. *
  17798. * @static
  17799. * @memberOf _
  17800. * @since 3.0.0
  17801. * @category Util
  17802. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  17803. * @returns {Function} Returns the new composite function.
  17804. * @see _.flowRight
  17805. * @example
  17806. *
  17807. * function square(n) {
  17808. * return n * n;
  17809. * }
  17810. *
  17811. * var addSquare = _.flow([_.add, square]);
  17812. * addSquare(1, 2);
  17813. * // => 9
  17814. */
  17815. var flow = createFlow();
  17816. /**
  17817. * This method is like `_.flow` except that it creates a function that
  17818. * invokes the given functions from right to left.
  17819. *
  17820. * @static
  17821. * @since 3.0.0
  17822. * @memberOf _
  17823. * @category Util
  17824. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  17825. * @returns {Function} Returns the new composite function.
  17826. * @see _.flow
  17827. * @example
  17828. *
  17829. * function square(n) {
  17830. * return n * n;
  17831. * }
  17832. *
  17833. * var addSquare = _.flowRight([square, _.add]);
  17834. * addSquare(1, 2);
  17835. * // => 9
  17836. */
  17837. var flowRight = createFlow(true);
  17838. /**
  17839. * This method returns the first argument it receives.
  17840. *
  17841. * @static
  17842. * @since 0.1.0
  17843. * @memberOf _
  17844. * @category Util
  17845. * @param {*} value Any value.
  17846. * @returns {*} Returns `value`.
  17847. * @example
  17848. *
  17849. * var object = { 'a': 1 };
  17850. *
  17851. * console.log(_.identity(object) === object);
  17852. * // => true
  17853. */
  17854. function identity(value) {
  17855. return value;
  17856. }
  17857. /**
  17858. * Creates a function that invokes `func` with the arguments of the created
  17859. * function. If `func` is a property name, the created function returns the
  17860. * property value for a given element. If `func` is an array or object, the
  17861. * created function returns `true` for elements that contain the equivalent
  17862. * source properties, otherwise it returns `false`.
  17863. *
  17864. * @static
  17865. * @since 4.0.0
  17866. * @memberOf _
  17867. * @category Util
  17868. * @param {*} [func=_.identity] The value to convert to a callback.
  17869. * @returns {Function} Returns the callback.
  17870. * @example
  17871. *
  17872. * var users = [
  17873. * { 'user': 'barney', 'age': 36, 'active': true },
  17874. * { 'user': 'fred', 'age': 40, 'active': false }
  17875. * ];
  17876. *
  17877. * // The `_.matches` iteratee shorthand.
  17878. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  17879. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  17880. *
  17881. * // The `_.matchesProperty` iteratee shorthand.
  17882. * _.filter(users, _.iteratee(['user', 'fred']));
  17883. * // => [{ 'user': 'fred', 'age': 40 }]
  17884. *
  17885. * // The `_.property` iteratee shorthand.
  17886. * _.map(users, _.iteratee('user'));
  17887. * // => ['barney', 'fred']
  17888. *
  17889. * // Create custom iteratee shorthands.
  17890. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  17891. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  17892. * return func.test(string);
  17893. * };
  17894. * });
  17895. *
  17896. * _.filter(['abc', 'def'], /ef/);
  17897. * // => ['def']
  17898. */
  17899. function iteratee(func) {
  17900. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  17901. }
  17902. /**
  17903. * Creates a function that performs a partial deep comparison between a given
  17904. * object and `source`, returning `true` if the given object has equivalent
  17905. * property values, else `false`.
  17906. *
  17907. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  17908. * partially applied.
  17909. *
  17910. * Partial comparisons will match empty array and empty object `source`
  17911. * values against any array or object value, respectively. See `_.isEqual`
  17912. * for a list of supported value comparisons.
  17913. *
  17914. * **Note:** Multiple values can be checked by combining several matchers
  17915. * using `_.overSome`
  17916. *
  17917. * @static
  17918. * @memberOf _
  17919. * @since 3.0.0
  17920. * @category Util
  17921. * @param {Object} source The object of property values to match.
  17922. * @returns {Function} Returns the new spec function.
  17923. * @example
  17924. *
  17925. * var objects = [
  17926. * { 'a': 1, 'b': 2, 'c': 3 },
  17927. * { 'a': 4, 'b': 5, 'c': 6 }
  17928. * ];
  17929. *
  17930. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  17931. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  17932. *
  17933. * // Checking for several possible values
  17934. * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
  17935. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  17936. */
  17937. function matches(source) {
  17938. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  17939. }
  17940. /**
  17941. * Creates a function that performs a partial deep comparison between the
  17942. * value at `path` of a given object to `srcValue`, returning `true` if the
  17943. * object value is equivalent, else `false`.
  17944. *
  17945. * **Note:** Partial comparisons will match empty array and empty object
  17946. * `srcValue` values against any array or object value, respectively. See
  17947. * `_.isEqual` for a list of supported value comparisons.
  17948. *
  17949. * **Note:** Multiple values can be checked by combining several matchers
  17950. * using `_.overSome`
  17951. *
  17952. * @static
  17953. * @memberOf _
  17954. * @since 3.2.0
  17955. * @category Util
  17956. * @param {Array|string} path The path of the property to get.
  17957. * @param {*} srcValue The value to match.
  17958. * @returns {Function} Returns the new spec function.
  17959. * @example
  17960. *
  17961. * var objects = [
  17962. * { 'a': 1, 'b': 2, 'c': 3 },
  17963. * { 'a': 4, 'b': 5, 'c': 6 }
  17964. * ];
  17965. *
  17966. * _.find(objects, _.matchesProperty('a', 4));
  17967. * // => { 'a': 4, 'b': 5, 'c': 6 }
  17968. *
  17969. * // Checking for several possible values
  17970. * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
  17971. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  17972. */
  17973. function matchesProperty(path, srcValue) {
  17974. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  17975. }
  17976. /**
  17977. * Creates a function that invokes the method at `path` of a given object.
  17978. * Any additional arguments are provided to the invoked method.
  17979. *
  17980. * @static
  17981. * @memberOf _
  17982. * @since 3.7.0
  17983. * @category Util
  17984. * @param {Array|string} path The path of the method to invoke.
  17985. * @param {...*} [args] The arguments to invoke the method with.
  17986. * @returns {Function} Returns the new invoker function.
  17987. * @example
  17988. *
  17989. * var objects = [
  17990. * { 'a': { 'b': _.constant(2) } },
  17991. * { 'a': { 'b': _.constant(1) } }
  17992. * ];
  17993. *
  17994. * _.map(objects, _.method('a.b'));
  17995. * // => [2, 1]
  17996. *
  17997. * _.map(objects, _.method(['a', 'b']));
  17998. * // => [2, 1]
  17999. */
  18000. var method = baseRest(function(path, args) {
  18001. return function(object) {
  18002. return baseInvoke(object, path, args);
  18003. };
  18004. });
  18005. /**
  18006. * The opposite of `_.method`; this method creates a function that invokes
  18007. * the method at a given path of `object`. Any additional arguments are
  18008. * provided to the invoked method.
  18009. *
  18010. * @static
  18011. * @memberOf _
  18012. * @since 3.7.0
  18013. * @category Util
  18014. * @param {Object} object The object to query.
  18015. * @param {...*} [args] The arguments to invoke the method with.
  18016. * @returns {Function} Returns the new invoker function.
  18017. * @example
  18018. *
  18019. * var array = _.times(3, _.constant),
  18020. * object = { 'a': array, 'b': array, 'c': array };
  18021. *
  18022. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  18023. * // => [2, 0]
  18024. *
  18025. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  18026. * // => [2, 0]
  18027. */
  18028. var methodOf = baseRest(function(object, args) {
  18029. return function(path) {
  18030. return baseInvoke(object, path, args);
  18031. };
  18032. });
  18033. /**
  18034. * Adds all own enumerable string keyed function properties of a source
  18035. * object to the destination object. If `object` is a function, then methods
  18036. * are added to its prototype as well.
  18037. *
  18038. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  18039. * avoid conflicts caused by modifying the original.
  18040. *
  18041. * @static
  18042. * @since 0.1.0
  18043. * @memberOf _
  18044. * @category Util
  18045. * @param {Function|Object} [object=lodash] The destination object.
  18046. * @param {Object} source The object of functions to add.
  18047. * @param {Object} [options={}] The options object.
  18048. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  18049. * @returns {Function|Object} Returns `object`.
  18050. * @example
  18051. *
  18052. * function vowels(string) {
  18053. * return _.filter(string, function(v) {
  18054. * return /[aeiou]/i.test(v);
  18055. * });
  18056. * }
  18057. *
  18058. * _.mixin({ 'vowels': vowels });
  18059. * _.vowels('fred');
  18060. * // => ['e']
  18061. *
  18062. * _('fred').vowels().value();
  18063. * // => ['e']
  18064. *
  18065. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  18066. * _('fred').vowels();
  18067. * // => ['e']
  18068. */
  18069. function mixin(object, source, options) {
  18070. var props = keys(source),
  18071. methodNames = baseFunctions(source, props);
  18072. if (options == null &&
  18073. !(isObject(source) && (methodNames.length || !props.length))) {
  18074. options = source;
  18075. source = object;
  18076. object = this;
  18077. methodNames = baseFunctions(source, keys(source));
  18078. }
  18079. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  18080. isFunc = isFunction(object);
  18081. arrayEach(methodNames, function(methodName) {
  18082. var func = source[methodName];
  18083. object[methodName] = func;
  18084. if (isFunc) {
  18085. object.prototype[methodName] = function() {
  18086. var chainAll = this.__chain__;
  18087. if (chain || chainAll) {
  18088. var result = object(this.__wrapped__),
  18089. actions = result.__actions__ = copyArray(this.__actions__);
  18090. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  18091. result.__chain__ = chainAll;
  18092. return result;
  18093. }
  18094. return func.apply(object, arrayPush([this.value()], arguments));
  18095. };
  18096. }
  18097. });
  18098. return object;
  18099. }
  18100. /**
  18101. * Reverts the `_` variable to its previous value and returns a reference to
  18102. * the `lodash` function.
  18103. *
  18104. * @static
  18105. * @since 0.1.0
  18106. * @memberOf _
  18107. * @category Util
  18108. * @returns {Function} Returns the `lodash` function.
  18109. * @example
  18110. *
  18111. * var lodash = _.noConflict();
  18112. */
  18113. function noConflict() {
  18114. if (root._ === this) {
  18115. root._ = oldDash;
  18116. }
  18117. return this;
  18118. }
  18119. /**
  18120. * This method returns `undefined`.
  18121. *
  18122. * @static
  18123. * @memberOf _
  18124. * @since 2.3.0
  18125. * @category Util
  18126. * @example
  18127. *
  18128. * _.times(2, _.noop);
  18129. * // => [undefined, undefined]
  18130. */
  18131. function noop() {
  18132. // No operation performed.
  18133. }
  18134. /**
  18135. * Creates a function that gets the argument at index `n`. If `n` is negative,
  18136. * the nth argument from the end is returned.
  18137. *
  18138. * @static
  18139. * @memberOf _
  18140. * @since 4.0.0
  18141. * @category Util
  18142. * @param {number} [n=0] The index of the argument to return.
  18143. * @returns {Function} Returns the new pass-thru function.
  18144. * @example
  18145. *
  18146. * var func = _.nthArg(1);
  18147. * func('a', 'b', 'c', 'd');
  18148. * // => 'b'
  18149. *
  18150. * var func = _.nthArg(-2);
  18151. * func('a', 'b', 'c', 'd');
  18152. * // => 'c'
  18153. */
  18154. function nthArg(n) {
  18155. n = toInteger(n);
  18156. return baseRest(function(args) {
  18157. return baseNth(args, n);
  18158. });
  18159. }
  18160. /**
  18161. * Creates a function that invokes `iteratees` with the arguments it receives
  18162. * and returns their results.
  18163. *
  18164. * @static
  18165. * @memberOf _
  18166. * @since 4.0.0
  18167. * @category Util
  18168. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  18169. * The iteratees to invoke.
  18170. * @returns {Function} Returns the new function.
  18171. * @example
  18172. *
  18173. * var func = _.over([Math.max, Math.min]);
  18174. *
  18175. * func(1, 2, 3, 4);
  18176. * // => [4, 1]
  18177. */
  18178. var over = createOver(arrayMap);
  18179. /**
  18180. * Creates a function that checks if **all** of the `predicates` return
  18181. * truthy when invoked with the arguments it receives.
  18182. *
  18183. * Following shorthands are possible for providing predicates.
  18184. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  18185. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  18186. *
  18187. * @static
  18188. * @memberOf _
  18189. * @since 4.0.0
  18190. * @category Util
  18191. * @param {...(Function|Function[])} [predicates=[_.identity]]
  18192. * The predicates to check.
  18193. * @returns {Function} Returns the new function.
  18194. * @example
  18195. *
  18196. * var func = _.overEvery([Boolean, isFinite]);
  18197. *
  18198. * func('1');
  18199. * // => true
  18200. *
  18201. * func(null);
  18202. * // => false
  18203. *
  18204. * func(NaN);
  18205. * // => false
  18206. */
  18207. var overEvery = createOver(arrayEvery);
  18208. /**
  18209. * Creates a function that checks if **any** of the `predicates` return
  18210. * truthy when invoked with the arguments it receives.
  18211. *
  18212. * Following shorthands are possible for providing predicates.
  18213. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  18214. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  18215. *
  18216. * @static
  18217. * @memberOf _
  18218. * @since 4.0.0
  18219. * @category Util
  18220. * @param {...(Function|Function[])} [predicates=[_.identity]]
  18221. * The predicates to check.
  18222. * @returns {Function} Returns the new function.
  18223. * @example
  18224. *
  18225. * var func = _.overSome([Boolean, isFinite]);
  18226. *
  18227. * func('1');
  18228. * // => true
  18229. *
  18230. * func(null);
  18231. * // => true
  18232. *
  18233. * func(NaN);
  18234. * // => false
  18235. *
  18236. * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
  18237. * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
  18238. */
  18239. var overSome = createOver(arraySome);
  18240. /**
  18241. * Creates a function that returns the value at `path` of a given object.
  18242. *
  18243. * @static
  18244. * @memberOf _
  18245. * @since 2.4.0
  18246. * @category Util
  18247. * @param {Array|string} path The path of the property to get.
  18248. * @returns {Function} Returns the new accessor function.
  18249. * @example
  18250. *
  18251. * var objects = [
  18252. * { 'a': { 'b': 2 } },
  18253. * { 'a': { 'b': 1 } }
  18254. * ];
  18255. *
  18256. * _.map(objects, _.property('a.b'));
  18257. * // => [2, 1]
  18258. *
  18259. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  18260. * // => [1, 2]
  18261. */
  18262. function property(path) {
  18263. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  18264. }
  18265. /**
  18266. * The opposite of `_.property`; this method creates a function that returns
  18267. * the value at a given path of `object`.
  18268. *
  18269. * @static
  18270. * @memberOf _
  18271. * @since 3.0.0
  18272. * @category Util
  18273. * @param {Object} object The object to query.
  18274. * @returns {Function} Returns the new accessor function.
  18275. * @example
  18276. *
  18277. * var array = [0, 1, 2],
  18278. * object = { 'a': array, 'b': array, 'c': array };
  18279. *
  18280. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  18281. * // => [2, 0]
  18282. *
  18283. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  18284. * // => [2, 0]
  18285. */
  18286. function propertyOf(object) {
  18287. return function(path) {
  18288. return object == null ? undefined : baseGet(object, path);
  18289. };
  18290. }
  18291. /**
  18292. * Creates an array of numbers (positive and/or negative) progressing from
  18293. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  18294. * `start` is specified without an `end` or `step`. If `end` is not specified,
  18295. * it's set to `start` with `start` then set to `0`.
  18296. *
  18297. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  18298. * floating-point values which can produce unexpected results.
  18299. *
  18300. * @static
  18301. * @since 0.1.0
  18302. * @memberOf _
  18303. * @category Util
  18304. * @param {number} [start=0] The start of the range.
  18305. * @param {number} end The end of the range.
  18306. * @param {number} [step=1] The value to increment or decrement by.
  18307. * @returns {Array} Returns the range of numbers.
  18308. * @see _.inRange, _.rangeRight
  18309. * @example
  18310. *
  18311. * _.range(4);
  18312. * // => [0, 1, 2, 3]
  18313. *
  18314. * _.range(-4);
  18315. * // => [0, -1, -2, -3]
  18316. *
  18317. * _.range(1, 5);
  18318. * // => [1, 2, 3, 4]
  18319. *
  18320. * _.range(0, 20, 5);
  18321. * // => [0, 5, 10, 15]
  18322. *
  18323. * _.range(0, -4, -1);
  18324. * // => [0, -1, -2, -3]
  18325. *
  18326. * _.range(1, 4, 0);
  18327. * // => [1, 1, 1]
  18328. *
  18329. * _.range(0);
  18330. * // => []
  18331. */
  18332. var range = createRange();
  18333. /**
  18334. * This method is like `_.range` except that it populates values in
  18335. * descending order.
  18336. *
  18337. * @static
  18338. * @memberOf _
  18339. * @since 4.0.0
  18340. * @category Util
  18341. * @param {number} [start=0] The start of the range.
  18342. * @param {number} end The end of the range.
  18343. * @param {number} [step=1] The value to increment or decrement by.
  18344. * @returns {Array} Returns the range of numbers.
  18345. * @see _.inRange, _.range
  18346. * @example
  18347. *
  18348. * _.rangeRight(4);
  18349. * // => [3, 2, 1, 0]
  18350. *
  18351. * _.rangeRight(-4);
  18352. * // => [-3, -2, -1, 0]
  18353. *
  18354. * _.rangeRight(1, 5);
  18355. * // => [4, 3, 2, 1]
  18356. *
  18357. * _.rangeRight(0, 20, 5);
  18358. * // => [15, 10, 5, 0]
  18359. *
  18360. * _.rangeRight(0, -4, -1);
  18361. * // => [-3, -2, -1, 0]
  18362. *
  18363. * _.rangeRight(1, 4, 0);
  18364. * // => [1, 1, 1]
  18365. *
  18366. * _.rangeRight(0);
  18367. * // => []
  18368. */
  18369. var rangeRight = createRange(true);
  18370. /**
  18371. * This method returns a new empty array.
  18372. *
  18373. * @static
  18374. * @memberOf _
  18375. * @since 4.13.0
  18376. * @category Util
  18377. * @returns {Array} Returns the new empty array.
  18378. * @example
  18379. *
  18380. * var arrays = _.times(2, _.stubArray);
  18381. *
  18382. * console.log(arrays);
  18383. * // => [[], []]
  18384. *
  18385. * console.log(arrays[0] === arrays[1]);
  18386. * // => false
  18387. */
  18388. function stubArray() {
  18389. return [];
  18390. }
  18391. /**
  18392. * This method returns `false`.
  18393. *
  18394. * @static
  18395. * @memberOf _
  18396. * @since 4.13.0
  18397. * @category Util
  18398. * @returns {boolean} Returns `false`.
  18399. * @example
  18400. *
  18401. * _.times(2, _.stubFalse);
  18402. * // => [false, false]
  18403. */
  18404. function stubFalse() {
  18405. return false;
  18406. }
  18407. /**
  18408. * This method returns a new empty object.
  18409. *
  18410. * @static
  18411. * @memberOf _
  18412. * @since 4.13.0
  18413. * @category Util
  18414. * @returns {Object} Returns the new empty object.
  18415. * @example
  18416. *
  18417. * var objects = _.times(2, _.stubObject);
  18418. *
  18419. * console.log(objects);
  18420. * // => [{}, {}]
  18421. *
  18422. * console.log(objects[0] === objects[1]);
  18423. * // => false
  18424. */
  18425. function stubObject() {
  18426. return {};
  18427. }
  18428. /**
  18429. * This method returns an empty string.
  18430. *
  18431. * @static
  18432. * @memberOf _
  18433. * @since 4.13.0
  18434. * @category Util
  18435. * @returns {string} Returns the empty string.
  18436. * @example
  18437. *
  18438. * _.times(2, _.stubString);
  18439. * // => ['', '']
  18440. */
  18441. function stubString() {
  18442. return '';
  18443. }
  18444. /**
  18445. * This method returns `true`.
  18446. *
  18447. * @static
  18448. * @memberOf _
  18449. * @since 4.13.0
  18450. * @category Util
  18451. * @returns {boolean} Returns `true`.
  18452. * @example
  18453. *
  18454. * _.times(2, _.stubTrue);
  18455. * // => [true, true]
  18456. */
  18457. function stubTrue() {
  18458. return true;
  18459. }
  18460. /**
  18461. * Invokes the iteratee `n` times, returning an array of the results of
  18462. * each invocation. The iteratee is invoked with one argument; (index).
  18463. *
  18464. * @static
  18465. * @since 0.1.0
  18466. * @memberOf _
  18467. * @category Util
  18468. * @param {number} n The number of times to invoke `iteratee`.
  18469. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  18470. * @returns {Array} Returns the array of results.
  18471. * @example
  18472. *
  18473. * _.times(3, String);
  18474. * // => ['0', '1', '2']
  18475. *
  18476. * _.times(4, _.constant(0));
  18477. * // => [0, 0, 0, 0]
  18478. */
  18479. function times(n, iteratee) {
  18480. n = toInteger(n);
  18481. if (n < 1 || n > MAX_SAFE_INTEGER) {
  18482. return [];
  18483. }
  18484. var index = MAX_ARRAY_LENGTH,
  18485. length = nativeMin(n, MAX_ARRAY_LENGTH);
  18486. iteratee = getIteratee(iteratee);
  18487. n -= MAX_ARRAY_LENGTH;
  18488. var result = baseTimes(length, iteratee);
  18489. while (++index < n) {
  18490. iteratee(index);
  18491. }
  18492. return result;
  18493. }
  18494. /**
  18495. * Converts `value` to a property path array.
  18496. *
  18497. * @static
  18498. * @memberOf _
  18499. * @since 4.0.0
  18500. * @category Util
  18501. * @param {*} value The value to convert.
  18502. * @returns {Array} Returns the new property path array.
  18503. * @example
  18504. *
  18505. * _.toPath('a.b.c');
  18506. * // => ['a', 'b', 'c']
  18507. *
  18508. * _.toPath('a[0].b.c');
  18509. * // => ['a', '0', 'b', 'c']
  18510. */
  18511. function toPath(value) {
  18512. if (isArray(value)) {
  18513. return arrayMap(value, toKey);
  18514. }
  18515. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  18516. }
  18517. /**
  18518. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  18519. *
  18520. * @static
  18521. * @since 0.1.0
  18522. * @memberOf _
  18523. * @category Util
  18524. * @param {string} [prefix=''] The value to prefix the ID with.
  18525. * @returns {string} Returns the unique ID.
  18526. * @example
  18527. *
  18528. * _.uniqueId('contact_');
  18529. * // => 'contact_104'
  18530. *
  18531. * _.uniqueId();
  18532. * // => '105'
  18533. */
  18534. function uniqueId(prefix) {
  18535. var id = ++idCounter;
  18536. return toString(prefix) + id;
  18537. }
  18538. /*------------------------------------------------------------------------*/
  18539. /**
  18540. * Adds two numbers.
  18541. *
  18542. * @static
  18543. * @memberOf _
  18544. * @since 3.4.0
  18545. * @category Math
  18546. * @param {number} augend The first number in an addition.
  18547. * @param {number} addend The second number in an addition.
  18548. * @returns {number} Returns the total.
  18549. * @example
  18550. *
  18551. * _.add(6, 4);
  18552. * // => 10
  18553. */
  18554. var add = createMathOperation(function(augend, addend) {
  18555. return augend + addend;
  18556. }, 0);
  18557. /**
  18558. * Computes `number` rounded up to `precision`.
  18559. *
  18560. * @static
  18561. * @memberOf _
  18562. * @since 3.10.0
  18563. * @category Math
  18564. * @param {number} number The number to round up.
  18565. * @param {number} [precision=0] The precision to round up to.
  18566. * @returns {number} Returns the rounded up number.
  18567. * @example
  18568. *
  18569. * _.ceil(4.006);
  18570. * // => 5
  18571. *
  18572. * _.ceil(6.004, 2);
  18573. * // => 6.01
  18574. *
  18575. * _.ceil(6040, -2);
  18576. * // => 6100
  18577. */
  18578. var ceil = createRound('ceil');
  18579. /**
  18580. * Divide two numbers.
  18581. *
  18582. * @static
  18583. * @memberOf _
  18584. * @since 4.7.0
  18585. * @category Math
  18586. * @param {number} dividend The first number in a division.
  18587. * @param {number} divisor The second number in a division.
  18588. * @returns {number} Returns the quotient.
  18589. * @example
  18590. *
  18591. * _.divide(6, 4);
  18592. * // => 1.5
  18593. */
  18594. var divide = createMathOperation(function(dividend, divisor) {
  18595. return dividend / divisor;
  18596. }, 1);
  18597. /**
  18598. * Computes `number` rounded down to `precision`.
  18599. *
  18600. * @static
  18601. * @memberOf _
  18602. * @since 3.10.0
  18603. * @category Math
  18604. * @param {number} number The number to round down.
  18605. * @param {number} [precision=0] The precision to round down to.
  18606. * @returns {number} Returns the rounded down number.
  18607. * @example
  18608. *
  18609. * _.floor(4.006);
  18610. * // => 4
  18611. *
  18612. * _.floor(0.046, 2);
  18613. * // => 0.04
  18614. *
  18615. * _.floor(4060, -2);
  18616. * // => 4000
  18617. */
  18618. var floor = createRound('floor');
  18619. /**
  18620. * Computes the maximum value of `array`. If `array` is empty or falsey,
  18621. * `undefined` is returned.
  18622. *
  18623. * @static
  18624. * @since 0.1.0
  18625. * @memberOf _
  18626. * @category Math
  18627. * @param {Array} array The array to iterate over.
  18628. * @returns {*} Returns the maximum value.
  18629. * @example
  18630. *
  18631. * _.max([4, 2, 8, 6]);
  18632. * // => 8
  18633. *
  18634. * _.max([]);
  18635. * // => undefined
  18636. */
  18637. function max(array) {
  18638. return (array && array.length)
  18639. ? baseExtremum(array, identity, baseGt)
  18640. : undefined;
  18641. }
  18642. /**
  18643. * This method is like `_.max` except that it accepts `iteratee` which is
  18644. * invoked for each element in `array` to generate the criterion by which
  18645. * the value is ranked. The iteratee is invoked with one argument: (value).
  18646. *
  18647. * @static
  18648. * @memberOf _
  18649. * @since 4.0.0
  18650. * @category Math
  18651. * @param {Array} array The array to iterate over.
  18652. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  18653. * @returns {*} Returns the maximum value.
  18654. * @example
  18655. *
  18656. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  18657. *
  18658. * _.maxBy(objects, function(o) { return o.n; });
  18659. * // => { 'n': 2 }
  18660. *
  18661. * // The `_.property` iteratee shorthand.
  18662. * _.maxBy(objects, 'n');
  18663. * // => { 'n': 2 }
  18664. */
  18665. function maxBy(array, iteratee) {
  18666. return (array && array.length)
  18667. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  18668. : undefined;
  18669. }
  18670. /**
  18671. * Computes the mean of the values in `array`.
  18672. *
  18673. * @static
  18674. * @memberOf _
  18675. * @since 4.0.0
  18676. * @category Math
  18677. * @param {Array} array The array to iterate over.
  18678. * @returns {number} Returns the mean.
  18679. * @example
  18680. *
  18681. * _.mean([4, 2, 8, 6]);
  18682. * // => 5
  18683. */
  18684. function mean(array) {
  18685. return baseMean(array, identity);
  18686. }
  18687. /**
  18688. * This method is like `_.mean` except that it accepts `iteratee` which is
  18689. * invoked for each element in `array` to generate the value to be averaged.
  18690. * The iteratee is invoked with one argument: (value).
  18691. *
  18692. * @static
  18693. * @memberOf _
  18694. * @since 4.7.0
  18695. * @category Math
  18696. * @param {Array} array The array to iterate over.
  18697. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  18698. * @returns {number} Returns the mean.
  18699. * @example
  18700. *
  18701. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  18702. *
  18703. * _.meanBy(objects, function(o) { return o.n; });
  18704. * // => 5
  18705. *
  18706. * // The `_.property` iteratee shorthand.
  18707. * _.meanBy(objects, 'n');
  18708. * // => 5
  18709. */
  18710. function meanBy(array, iteratee) {
  18711. return baseMean(array, getIteratee(iteratee, 2));
  18712. }
  18713. /**
  18714. * Computes the minimum value of `array`. If `array` is empty or falsey,
  18715. * `undefined` is returned.
  18716. *
  18717. * @static
  18718. * @since 0.1.0
  18719. * @memberOf _
  18720. * @category Math
  18721. * @param {Array} array The array to iterate over.
  18722. * @returns {*} Returns the minimum value.
  18723. * @example
  18724. *
  18725. * _.min([4, 2, 8, 6]);
  18726. * // => 2
  18727. *
  18728. * _.min([]);
  18729. * // => undefined
  18730. */
  18731. function min(array) {
  18732. return (array && array.length)
  18733. ? baseExtremum(array, identity, baseLt)
  18734. : undefined;
  18735. }
  18736. /**
  18737. * This method is like `_.min` except that it accepts `iteratee` which is
  18738. * invoked for each element in `array` to generate the criterion by which
  18739. * the value is ranked. The iteratee is invoked with one argument: (value).
  18740. *
  18741. * @static
  18742. * @memberOf _
  18743. * @since 4.0.0
  18744. * @category Math
  18745. * @param {Array} array The array to iterate over.
  18746. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  18747. * @returns {*} Returns the minimum value.
  18748. * @example
  18749. *
  18750. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  18751. *
  18752. * _.minBy(objects, function(o) { return o.n; });
  18753. * // => { 'n': 1 }
  18754. *
  18755. * // The `_.property` iteratee shorthand.
  18756. * _.minBy(objects, 'n');
  18757. * // => { 'n': 1 }
  18758. */
  18759. function minBy(array, iteratee) {
  18760. return (array && array.length)
  18761. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  18762. : undefined;
  18763. }
  18764. /**
  18765. * Multiply two numbers.
  18766. *
  18767. * @static
  18768. * @memberOf _
  18769. * @since 4.7.0
  18770. * @category Math
  18771. * @param {number} multiplier The first number in a multiplication.
  18772. * @param {number} multiplicand The second number in a multiplication.
  18773. * @returns {number} Returns the product.
  18774. * @example
  18775. *
  18776. * _.multiply(6, 4);
  18777. * // => 24
  18778. */
  18779. var multiply = createMathOperation(function(multiplier, multiplicand) {
  18780. return multiplier * multiplicand;
  18781. }, 1);
  18782. /**
  18783. * Computes `number` rounded to `precision`.
  18784. *
  18785. * @static
  18786. * @memberOf _
  18787. * @since 3.10.0
  18788. * @category Math
  18789. * @param {number} number The number to round.
  18790. * @param {number} [precision=0] The precision to round to.
  18791. * @returns {number} Returns the rounded number.
  18792. * @example
  18793. *
  18794. * _.round(4.006);
  18795. * // => 4
  18796. *
  18797. * _.round(4.006, 2);
  18798. * // => 4.01
  18799. *
  18800. * _.round(4060, -2);
  18801. * // => 4100
  18802. */
  18803. var round = createRound('round');
  18804. /**
  18805. * Subtract two numbers.
  18806. *
  18807. * @static
  18808. * @memberOf _
  18809. * @since 4.0.0
  18810. * @category Math
  18811. * @param {number} minuend The first number in a subtraction.
  18812. * @param {number} subtrahend The second number in a subtraction.
  18813. * @returns {number} Returns the difference.
  18814. * @example
  18815. *
  18816. * _.subtract(6, 4);
  18817. * // => 2
  18818. */
  18819. var subtract = createMathOperation(function(minuend, subtrahend) {
  18820. return minuend - subtrahend;
  18821. }, 0);
  18822. /**
  18823. * Computes the sum of the values in `array`.
  18824. *
  18825. * @static
  18826. * @memberOf _
  18827. * @since 3.4.0
  18828. * @category Math
  18829. * @param {Array} array The array to iterate over.
  18830. * @returns {number} Returns the sum.
  18831. * @example
  18832. *
  18833. * _.sum([4, 2, 8, 6]);
  18834. * // => 20
  18835. */
  18836. function sum(array) {
  18837. return (array && array.length)
  18838. ? baseSum(array, identity)
  18839. : 0;
  18840. }
  18841. /**
  18842. * This method is like `_.sum` except that it accepts `iteratee` which is
  18843. * invoked for each element in `array` to generate the value to be summed.
  18844. * The iteratee is invoked with one argument: (value).
  18845. *
  18846. * @static
  18847. * @memberOf _
  18848. * @since 4.0.0
  18849. * @category Math
  18850. * @param {Array} array The array to iterate over.
  18851. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  18852. * @returns {number} Returns the sum.
  18853. * @example
  18854. *
  18855. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  18856. *
  18857. * _.sumBy(objects, function(o) { return o.n; });
  18858. * // => 20
  18859. *
  18860. * // The `_.property` iteratee shorthand.
  18861. * _.sumBy(objects, 'n');
  18862. * // => 20
  18863. */
  18864. function sumBy(array, iteratee) {
  18865. return (array && array.length)
  18866. ? baseSum(array, getIteratee(iteratee, 2))
  18867. : 0;
  18868. }
  18869. /*------------------------------------------------------------------------*/
  18870. // Add methods that return wrapped values in chain sequences.
  18871. lodash.after = after;
  18872. lodash.ary = ary;
  18873. lodash.assign = assign;
  18874. lodash.assignIn = assignIn;
  18875. lodash.assignInWith = assignInWith;
  18876. lodash.assignWith = assignWith;
  18877. lodash.at = at;
  18878. lodash.before = before;
  18879. lodash.bind = bind;
  18880. lodash.bindAll = bindAll;
  18881. lodash.bindKey = bindKey;
  18882. lodash.castArray = castArray;
  18883. lodash.chain = chain;
  18884. lodash.chunk = chunk;
  18885. lodash.compact = compact;
  18886. lodash.concat = concat;
  18887. lodash.cond = cond;
  18888. lodash.conforms = conforms;
  18889. lodash.constant = constant;
  18890. lodash.countBy = countBy;
  18891. lodash.create = create;
  18892. lodash.curry = curry;
  18893. lodash.curryRight = curryRight;
  18894. lodash.debounce = debounce;
  18895. lodash.defaults = defaults;
  18896. lodash.defaultsDeep = defaultsDeep;
  18897. lodash.defer = defer;
  18898. lodash.delay = delay;
  18899. lodash.difference = difference;
  18900. lodash.differenceBy = differenceBy;
  18901. lodash.differenceWith = differenceWith;
  18902. lodash.drop = drop;
  18903. lodash.dropRight = dropRight;
  18904. lodash.dropRightWhile = dropRightWhile;
  18905. lodash.dropWhile = dropWhile;
  18906. lodash.fill = fill;
  18907. lodash.filter = filter;
  18908. lodash.flatMap = flatMap;
  18909. lodash.flatMapDeep = flatMapDeep;
  18910. lodash.flatMapDepth = flatMapDepth;
  18911. lodash.flatten = flatten;
  18912. lodash.flattenDeep = flattenDeep;
  18913. lodash.flattenDepth = flattenDepth;
  18914. lodash.flip = flip;
  18915. lodash.flow = flow;
  18916. lodash.flowRight = flowRight;
  18917. lodash.fromPairs = fromPairs;
  18918. lodash.functions = functions;
  18919. lodash.functionsIn = functionsIn;
  18920. lodash.groupBy = groupBy;
  18921. lodash.initial = initial;
  18922. lodash.intersection = intersection;
  18923. lodash.intersectionBy = intersectionBy;
  18924. lodash.intersectionWith = intersectionWith;
  18925. lodash.invert = invert;
  18926. lodash.invertBy = invertBy;
  18927. lodash.invokeMap = invokeMap;
  18928. lodash.iteratee = iteratee;
  18929. lodash.keyBy = keyBy;
  18930. lodash.keys = keys;
  18931. lodash.keysIn = keysIn;
  18932. lodash.map = map;
  18933. lodash.mapKeys = mapKeys;
  18934. lodash.mapValues = mapValues;
  18935. lodash.matches = matches;
  18936. lodash.matchesProperty = matchesProperty;
  18937. lodash.memoize = memoize;
  18938. lodash.merge = merge;
  18939. lodash.mergeWith = mergeWith;
  18940. lodash.method = method;
  18941. lodash.methodOf = methodOf;
  18942. lodash.mixin = mixin;
  18943. lodash.negate = negate;
  18944. lodash.nthArg = nthArg;
  18945. lodash.omit = omit;
  18946. lodash.omitBy = omitBy;
  18947. lodash.once = once;
  18948. lodash.orderBy = orderBy;
  18949. lodash.over = over;
  18950. lodash.overArgs = overArgs;
  18951. lodash.overEvery = overEvery;
  18952. lodash.overSome = overSome;
  18953. lodash.partial = partial;
  18954. lodash.partialRight = partialRight;
  18955. lodash.partition = partition;
  18956. lodash.pick = pick;
  18957. lodash.pickBy = pickBy;
  18958. lodash.property = property;
  18959. lodash.propertyOf = propertyOf;
  18960. lodash.pull = pull;
  18961. lodash.pullAll = pullAll;
  18962. lodash.pullAllBy = pullAllBy;
  18963. lodash.pullAllWith = pullAllWith;
  18964. lodash.pullAt = pullAt;
  18965. lodash.range = range;
  18966. lodash.rangeRight = rangeRight;
  18967. lodash.rearg = rearg;
  18968. lodash.reject = reject;
  18969. lodash.remove = remove;
  18970. lodash.rest = rest;
  18971. lodash.reverse = reverse;
  18972. lodash.sampleSize = sampleSize;
  18973. lodash.set = set;
  18974. lodash.setWith = setWith;
  18975. lodash.shuffle = shuffle;
  18976. lodash.slice = slice;
  18977. lodash.sortBy = sortBy;
  18978. lodash.sortedUniq = sortedUniq;
  18979. lodash.sortedUniqBy = sortedUniqBy;
  18980. lodash.split = split;
  18981. lodash.spread = spread;
  18982. lodash.tail = tail;
  18983. lodash.take = take;
  18984. lodash.takeRight = takeRight;
  18985. lodash.takeRightWhile = takeRightWhile;
  18986. lodash.takeWhile = takeWhile;
  18987. lodash.tap = tap;
  18988. lodash.throttle = throttle;
  18989. lodash.thru = thru;
  18990. lodash.toArray = toArray;
  18991. lodash.toPairs = toPairs;
  18992. lodash.toPairsIn = toPairsIn;
  18993. lodash.toPath = toPath;
  18994. lodash.toPlainObject = toPlainObject;
  18995. lodash.transform = transform;
  18996. lodash.unary = unary;
  18997. lodash.union = union;
  18998. lodash.unionBy = unionBy;
  18999. lodash.unionWith = unionWith;
  19000. lodash.uniq = uniq;
  19001. lodash.uniqBy = uniqBy;
  19002. lodash.uniqWith = uniqWith;
  19003. lodash.unset = unset;
  19004. lodash.unzip = unzip;
  19005. lodash.unzipWith = unzipWith;
  19006. lodash.update = update;
  19007. lodash.updateWith = updateWith;
  19008. lodash.values = values;
  19009. lodash.valuesIn = valuesIn;
  19010. lodash.without = without;
  19011. lodash.words = words;
  19012. lodash.wrap = wrap;
  19013. lodash.xor = xor;
  19014. lodash.xorBy = xorBy;
  19015. lodash.xorWith = xorWith;
  19016. lodash.zip = zip;
  19017. lodash.zipObject = zipObject;
  19018. lodash.zipObjectDeep = zipObjectDeep;
  19019. lodash.zipWith = zipWith;
  19020. // Add aliases.
  19021. lodash.entries = toPairs;
  19022. lodash.entriesIn = toPairsIn;
  19023. lodash.extend = assignIn;
  19024. lodash.extendWith = assignInWith;
  19025. // Add methods to `lodash.prototype`.
  19026. mixin(lodash, lodash);
  19027. /*------------------------------------------------------------------------*/
  19028. // Add methods that return unwrapped values in chain sequences.
  19029. lodash.add = add;
  19030. lodash.attempt = attempt;
  19031. lodash.camelCase = camelCase;
  19032. lodash.capitalize = capitalize;
  19033. lodash.ceil = ceil;
  19034. lodash.clamp = clamp;
  19035. lodash.clone = clone;
  19036. lodash.cloneDeep = cloneDeep;
  19037. lodash.cloneDeepWith = cloneDeepWith;
  19038. lodash.cloneWith = cloneWith;
  19039. lodash.conformsTo = conformsTo;
  19040. lodash.deburr = deburr;
  19041. lodash.defaultTo = defaultTo;
  19042. lodash.divide = divide;
  19043. lodash.endsWith = endsWith;
  19044. lodash.eq = eq;
  19045. lodash.escape = escape;
  19046. lodash.escapeRegExp = escapeRegExp;
  19047. lodash.every = every;
  19048. lodash.find = find;
  19049. lodash.findIndex = findIndex;
  19050. lodash.findKey = findKey;
  19051. lodash.findLast = findLast;
  19052. lodash.findLastIndex = findLastIndex;
  19053. lodash.findLastKey = findLastKey;
  19054. lodash.floor = floor;
  19055. lodash.forEach = forEach;
  19056. lodash.forEachRight = forEachRight;
  19057. lodash.forIn = forIn;
  19058. lodash.forInRight = forInRight;
  19059. lodash.forOwn = forOwn;
  19060. lodash.forOwnRight = forOwnRight;
  19061. lodash.get = get;
  19062. lodash.gt = gt;
  19063. lodash.gte = gte;
  19064. lodash.has = has;
  19065. lodash.hasIn = hasIn;
  19066. lodash.head = head;
  19067. lodash.identity = identity;
  19068. lodash.includes = includes;
  19069. lodash.indexOf = indexOf;
  19070. lodash.inRange = inRange;
  19071. lodash.invoke = invoke;
  19072. lodash.isArguments = isArguments;
  19073. lodash.isArray = isArray;
  19074. lodash.isArrayBuffer = isArrayBuffer;
  19075. lodash.isArrayLike = isArrayLike;
  19076. lodash.isArrayLikeObject = isArrayLikeObject;
  19077. lodash.isBoolean = isBoolean;
  19078. lodash.isBuffer = isBuffer;
  19079. lodash.isDate = isDate;
  19080. lodash.isElement = isElement;
  19081. lodash.isEmpty = isEmpty;
  19082. lodash.isEqual = isEqual;
  19083. lodash.isEqualWith = isEqualWith;
  19084. lodash.isError = isError;
  19085. lodash.isFinite = isFinite;
  19086. lodash.isFunction = isFunction;
  19087. lodash.isInteger = isInteger;
  19088. lodash.isLength = isLength;
  19089. lodash.isMap = isMap;
  19090. lodash.isMatch = isMatch;
  19091. lodash.isMatchWith = isMatchWith;
  19092. lodash.isNaN = isNaN;
  19093. lodash.isNative = isNative;
  19094. lodash.isNil = isNil;
  19095. lodash.isNull = isNull;
  19096. lodash.isNumber = isNumber;
  19097. lodash.isObject = isObject;
  19098. lodash.isObjectLike = isObjectLike;
  19099. lodash.isPlainObject = isPlainObject;
  19100. lodash.isRegExp = isRegExp;
  19101. lodash.isSafeInteger = isSafeInteger;
  19102. lodash.isSet = isSet;
  19103. lodash.isString = isString;
  19104. lodash.isSymbol = isSymbol;
  19105. lodash.isTypedArray = isTypedArray;
  19106. lodash.isUndefined = isUndefined;
  19107. lodash.isWeakMap = isWeakMap;
  19108. lodash.isWeakSet = isWeakSet;
  19109. lodash.join = join;
  19110. lodash.kebabCase = kebabCase;
  19111. lodash.last = last;
  19112. lodash.lastIndexOf = lastIndexOf;
  19113. lodash.lowerCase = lowerCase;
  19114. lodash.lowerFirst = lowerFirst;
  19115. lodash.lt = lt;
  19116. lodash.lte = lte;
  19117. lodash.max = max;
  19118. lodash.maxBy = maxBy;
  19119. lodash.mean = mean;
  19120. lodash.meanBy = meanBy;
  19121. lodash.min = min;
  19122. lodash.minBy = minBy;
  19123. lodash.stubArray = stubArray;
  19124. lodash.stubFalse = stubFalse;
  19125. lodash.stubObject = stubObject;
  19126. lodash.stubString = stubString;
  19127. lodash.stubTrue = stubTrue;
  19128. lodash.multiply = multiply;
  19129. lodash.nth = nth;
  19130. lodash.noConflict = noConflict;
  19131. lodash.noop = noop;
  19132. lodash.now = now;
  19133. lodash.pad = pad;
  19134. lodash.padEnd = padEnd;
  19135. lodash.padStart = padStart;
  19136. lodash.parseInt = parseInt;
  19137. lodash.random = random;
  19138. lodash.reduce = reduce;
  19139. lodash.reduceRight = reduceRight;
  19140. lodash.repeat = repeat;
  19141. lodash.replace = replace;
  19142. lodash.result = result;
  19143. lodash.round = round;
  19144. lodash.runInContext = runInContext;
  19145. lodash.sample = sample;
  19146. lodash.size = size;
  19147. lodash.snakeCase = snakeCase;
  19148. lodash.some = some;
  19149. lodash.sortedIndex = sortedIndex;
  19150. lodash.sortedIndexBy = sortedIndexBy;
  19151. lodash.sortedIndexOf = sortedIndexOf;
  19152. lodash.sortedLastIndex = sortedLastIndex;
  19153. lodash.sortedLastIndexBy = sortedLastIndexBy;
  19154. lodash.sortedLastIndexOf = sortedLastIndexOf;
  19155. lodash.startCase = startCase;
  19156. lodash.startsWith = startsWith;
  19157. lodash.subtract = subtract;
  19158. lodash.sum = sum;
  19159. lodash.sumBy = sumBy;
  19160. lodash.template = template;
  19161. lodash.times = times;
  19162. lodash.toFinite = toFinite;
  19163. lodash.toInteger = toInteger;
  19164. lodash.toLength = toLength;
  19165. lodash.toLower = toLower;
  19166. lodash.toNumber = toNumber;
  19167. lodash.toSafeInteger = toSafeInteger;
  19168. lodash.toString = toString;
  19169. lodash.toUpper = toUpper;
  19170. lodash.trim = trim;
  19171. lodash.trimEnd = trimEnd;
  19172. lodash.trimStart = trimStart;
  19173. lodash.truncate = truncate;
  19174. lodash.unescape = unescape;
  19175. lodash.uniqueId = uniqueId;
  19176. lodash.upperCase = upperCase;
  19177. lodash.upperFirst = upperFirst;
  19178. // Add aliases.
  19179. lodash.each = forEach;
  19180. lodash.eachRight = forEachRight;
  19181. lodash.first = head;
  19182. mixin(lodash, (function() {
  19183. var source = {};
  19184. baseForOwn(lodash, function(func, methodName) {
  19185. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  19186. source[methodName] = func;
  19187. }
  19188. });
  19189. return source;
  19190. }()), { 'chain': false });
  19191. /*------------------------------------------------------------------------*/
  19192. /**
  19193. * The semantic version number.
  19194. *
  19195. * @static
  19196. * @memberOf _
  19197. * @type {string}
  19198. */
  19199. lodash.VERSION = VERSION;
  19200. // Assign default placeholders.
  19201. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  19202. lodash[methodName].placeholder = lodash;
  19203. });
  19204. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  19205. arrayEach(['drop', 'take'], function(methodName, index) {
  19206. LazyWrapper.prototype[methodName] = function(n) {
  19207. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  19208. var result = (this.__filtered__ && !index)
  19209. ? new LazyWrapper(this)
  19210. : this.clone();
  19211. if (result.__filtered__) {
  19212. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  19213. } else {
  19214. result.__views__.push({
  19215. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  19216. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  19217. });
  19218. }
  19219. return result;
  19220. };
  19221. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  19222. return this.reverse()[methodName](n).reverse();
  19223. };
  19224. });
  19225. // Add `LazyWrapper` methods that accept an `iteratee` value.
  19226. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  19227. var type = index + 1,
  19228. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  19229. LazyWrapper.prototype[methodName] = function(iteratee) {
  19230. var result = this.clone();
  19231. result.__iteratees__.push({
  19232. 'iteratee': getIteratee(iteratee, 3),
  19233. 'type': type
  19234. });
  19235. result.__filtered__ = result.__filtered__ || isFilter;
  19236. return result;
  19237. };
  19238. });
  19239. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  19240. arrayEach(['head', 'last'], function(methodName, index) {
  19241. var takeName = 'take' + (index ? 'Right' : '');
  19242. LazyWrapper.prototype[methodName] = function() {
  19243. return this[takeName](1).value()[0];
  19244. };
  19245. });
  19246. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  19247. arrayEach(['initial', 'tail'], function(methodName, index) {
  19248. var dropName = 'drop' + (index ? '' : 'Right');
  19249. LazyWrapper.prototype[methodName] = function() {
  19250. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  19251. };
  19252. });
  19253. LazyWrapper.prototype.compact = function() {
  19254. return this.filter(identity);
  19255. };
  19256. LazyWrapper.prototype.find = function(predicate) {
  19257. return this.filter(predicate).head();
  19258. };
  19259. LazyWrapper.prototype.findLast = function(predicate) {
  19260. return this.reverse().find(predicate);
  19261. };
  19262. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  19263. if (typeof path == 'function') {
  19264. return new LazyWrapper(this);
  19265. }
  19266. return this.map(function(value) {
  19267. return baseInvoke(value, path, args);
  19268. });
  19269. });
  19270. LazyWrapper.prototype.reject = function(predicate) {
  19271. return this.filter(negate(getIteratee(predicate)));
  19272. };
  19273. LazyWrapper.prototype.slice = function(start, end) {
  19274. start = toInteger(start);
  19275. var result = this;
  19276. if (result.__filtered__ && (start > 0 || end < 0)) {
  19277. return new LazyWrapper(result);
  19278. }
  19279. if (start < 0) {
  19280. result = result.takeRight(-start);
  19281. } else if (start) {
  19282. result = result.drop(start);
  19283. }
  19284. if (end !== undefined) {
  19285. end = toInteger(end);
  19286. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  19287. }
  19288. return result;
  19289. };
  19290. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  19291. return this.reverse().takeWhile(predicate).reverse();
  19292. };
  19293. LazyWrapper.prototype.toArray = function() {
  19294. return this.take(MAX_ARRAY_LENGTH);
  19295. };
  19296. // Add `LazyWrapper` methods to `lodash.prototype`.
  19297. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  19298. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  19299. isTaker = /^(?:head|last)$/.test(methodName),
  19300. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  19301. retUnwrapped = isTaker || /^find/.test(methodName);
  19302. if (!lodashFunc) {
  19303. return;
  19304. }
  19305. lodash.prototype[methodName] = function() {
  19306. var value = this.__wrapped__,
  19307. args = isTaker ? [1] : arguments,
  19308. isLazy = value instanceof LazyWrapper,
  19309. iteratee = args[0],
  19310. useLazy = isLazy || isArray(value);
  19311. var interceptor = function(value) {
  19312. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  19313. return (isTaker && chainAll) ? result[0] : result;
  19314. };
  19315. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  19316. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  19317. isLazy = useLazy = false;
  19318. }
  19319. var chainAll = this.__chain__,
  19320. isHybrid = !!this.__actions__.length,
  19321. isUnwrapped = retUnwrapped && !chainAll,
  19322. onlyLazy = isLazy && !isHybrid;
  19323. if (!retUnwrapped && useLazy) {
  19324. value = onlyLazy ? value : new LazyWrapper(this);
  19325. var result = func.apply(value, args);
  19326. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  19327. return new LodashWrapper(result, chainAll);
  19328. }
  19329. if (isUnwrapped && onlyLazy) {
  19330. return func.apply(this, args);
  19331. }
  19332. result = this.thru(interceptor);
  19333. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  19334. };
  19335. });
  19336. // Add `Array` methods to `lodash.prototype`.
  19337. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  19338. var func = arrayProto[methodName],
  19339. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  19340. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  19341. lodash.prototype[methodName] = function() {
  19342. var args = arguments;
  19343. if (retUnwrapped && !this.__chain__) {
  19344. var value = this.value();
  19345. return func.apply(isArray(value) ? value : [], args);
  19346. }
  19347. return this[chainName](function(value) {
  19348. return func.apply(isArray(value) ? value : [], args);
  19349. });
  19350. };
  19351. });
  19352. // Map minified method names to their real names.
  19353. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  19354. var lodashFunc = lodash[methodName];
  19355. if (lodashFunc) {
  19356. var key = lodashFunc.name + '';
  19357. if (!hasOwnProperty.call(realNames, key)) {
  19358. realNames[key] = [];
  19359. }
  19360. realNames[key].push({ 'name': methodName, 'func': lodashFunc });
  19361. }
  19362. });
  19363. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  19364. 'name': 'wrapper',
  19365. 'func': undefined
  19366. }];
  19367. // Add methods to `LazyWrapper`.
  19368. LazyWrapper.prototype.clone = lazyClone;
  19369. LazyWrapper.prototype.reverse = lazyReverse;
  19370. LazyWrapper.prototype.value = lazyValue;
  19371. // Add chain sequence methods to the `lodash` wrapper.
  19372. lodash.prototype.at = wrapperAt;
  19373. lodash.prototype.chain = wrapperChain;
  19374. lodash.prototype.commit = wrapperCommit;
  19375. lodash.prototype.next = wrapperNext;
  19376. lodash.prototype.plant = wrapperPlant;
  19377. lodash.prototype.reverse = wrapperReverse;
  19378. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  19379. // Add lazy aliases.
  19380. lodash.prototype.first = lodash.prototype.head;
  19381. if (symIterator) {
  19382. lodash.prototype[symIterator] = wrapperToIterator;
  19383. }
  19384. return lodash;
  19385. });
  19386. /*--------------------------------------------------------------------------*/
  19387. // Export lodash.
  19388. var _ = runInContext();
  19389. // Some AMD build optimizers, like r.js, check for condition patterns like:
  19390. if (true) {
  19391. // Expose Lodash on the global object to prevent errors when Lodash is
  19392. // loaded by a script tag in the presence of an AMD loader.
  19393. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  19394. // Use `_.noConflict` to remove Lodash from the global object.
  19395. root._ = _;
  19396. // Define as an anonymous module so, through path mapping, it can be
  19397. // referenced as the "underscore" module.
  19398. !(__WEBPACK_AMD_DEFINE_RESULT__ = (function() {
  19399. return _;
  19400. }).call(exports, __webpack_require__, exports, module),
  19401. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  19402. }
  19403. // Check for `exports` after `define` in case a build optimizer adds it.
  19404. else {}
  19405. }.call(this));
  19406. /* WEBPACK VAR INJECTION */}.call(this, __webpack_require__(/*! ./../webpack/buildin/global.js */ "./node_modules/webpack/buildin/global.js"), __webpack_require__(/*! ./../webpack/buildin/module.js */ "./node_modules/webpack/buildin/module.js")(module)))
  19407. /***/ }),
  19408. /***/ "./node_modules/process/browser.js":
  19409. /*!*****************************************!*\
  19410. !*** ./node_modules/process/browser.js ***!
  19411. \*****************************************/
  19412. /*! no static exports found */
  19413. /***/ (function(module, exports) {
  19414. // shim for using process in browser
  19415. var process = module.exports = {};
  19416. // cached from whatever global is present so that test runners that stub it
  19417. // don't break things. But we need to wrap it in a try catch in case it is
  19418. // wrapped in strict mode code which doesn't define any globals. It's inside a
  19419. // function because try/catches deoptimize in certain engines.
  19420. var cachedSetTimeout;
  19421. var cachedClearTimeout;
  19422. function defaultSetTimout() {
  19423. throw new Error('setTimeout has not been defined');
  19424. }
  19425. function defaultClearTimeout () {
  19426. throw new Error('clearTimeout has not been defined');
  19427. }
  19428. (function () {
  19429. try {
  19430. if (typeof setTimeout === 'function') {
  19431. cachedSetTimeout = setTimeout;
  19432. } else {
  19433. cachedSetTimeout = defaultSetTimout;
  19434. }
  19435. } catch (e) {
  19436. cachedSetTimeout = defaultSetTimout;
  19437. }
  19438. try {
  19439. if (typeof clearTimeout === 'function') {
  19440. cachedClearTimeout = clearTimeout;
  19441. } else {
  19442. cachedClearTimeout = defaultClearTimeout;
  19443. }
  19444. } catch (e) {
  19445. cachedClearTimeout = defaultClearTimeout;
  19446. }
  19447. } ())
  19448. function runTimeout(fun) {
  19449. if (cachedSetTimeout === setTimeout) {
  19450. //normal enviroments in sane situations
  19451. return setTimeout(fun, 0);
  19452. }
  19453. // if setTimeout wasn't available but was latter defined
  19454. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  19455. cachedSetTimeout = setTimeout;
  19456. return setTimeout(fun, 0);
  19457. }
  19458. try {
  19459. // when when somebody has screwed with setTimeout but no I.E. maddness
  19460. return cachedSetTimeout(fun, 0);
  19461. } catch(e){
  19462. try {
  19463. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  19464. return cachedSetTimeout.call(null, fun, 0);
  19465. } catch(e){
  19466. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error
  19467. return cachedSetTimeout.call(this, fun, 0);
  19468. }
  19469. }
  19470. }
  19471. function runClearTimeout(marker) {
  19472. if (cachedClearTimeout === clearTimeout) {
  19473. //normal enviroments in sane situations
  19474. return clearTimeout(marker);
  19475. }
  19476. // if clearTimeout wasn't available but was latter defined
  19477. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  19478. cachedClearTimeout = clearTimeout;
  19479. return clearTimeout(marker);
  19480. }
  19481. try {
  19482. // when when somebody has screwed with setTimeout but no I.E. maddness
  19483. return cachedClearTimeout(marker);
  19484. } catch (e){
  19485. try {
  19486. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  19487. return cachedClearTimeout.call(null, marker);
  19488. } catch (e){
  19489. // same as above but when it's a version of I.E. that must have the global object for 'this', hopfully our context correct otherwise it will throw a global error.
  19490. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  19491. return cachedClearTimeout.call(this, marker);
  19492. }
  19493. }
  19494. }
  19495. var queue = [];
  19496. var draining = false;
  19497. var currentQueue;
  19498. var queueIndex = -1;
  19499. function cleanUpNextTick() {
  19500. if (!draining || !currentQueue) {
  19501. return;
  19502. }
  19503. draining = false;
  19504. if (currentQueue.length) {
  19505. queue = currentQueue.concat(queue);
  19506. } else {
  19507. queueIndex = -1;
  19508. }
  19509. if (queue.length) {
  19510. drainQueue();
  19511. }
  19512. }
  19513. function drainQueue() {
  19514. if (draining) {
  19515. return;
  19516. }
  19517. var timeout = runTimeout(cleanUpNextTick);
  19518. draining = true;
  19519. var len = queue.length;
  19520. while(len) {
  19521. currentQueue = queue;
  19522. queue = [];
  19523. while (++queueIndex < len) {
  19524. if (currentQueue) {
  19525. currentQueue[queueIndex].run();
  19526. }
  19527. }
  19528. queueIndex = -1;
  19529. len = queue.length;
  19530. }
  19531. currentQueue = null;
  19532. draining = false;
  19533. runClearTimeout(timeout);
  19534. }
  19535. process.nextTick = function (fun) {
  19536. var args = new Array(arguments.length - 1);
  19537. if (arguments.length > 1) {
  19538. for (var i = 1; i < arguments.length; i++) {
  19539. args[i - 1] = arguments[i];
  19540. }
  19541. }
  19542. queue.push(new Item(fun, args));
  19543. if (queue.length === 1 && !draining) {
  19544. runTimeout(drainQueue);
  19545. }
  19546. };
  19547. // v8 likes predictible objects
  19548. function Item(fun, array) {
  19549. this.fun = fun;
  19550. this.array = array;
  19551. }
  19552. Item.prototype.run = function () {
  19553. this.fun.apply(null, this.array);
  19554. };
  19555. process.title = 'browser';
  19556. process.browser = true;
  19557. process.env = {};
  19558. process.argv = [];
  19559. process.version = ''; // empty string to avoid regexp issues
  19560. process.versions = {};
  19561. function noop() {}
  19562. process.on = noop;
  19563. process.addListener = noop;
  19564. process.once = noop;
  19565. process.off = noop;
  19566. process.removeListener = noop;
  19567. process.removeAllListeners = noop;
  19568. process.emit = noop;
  19569. process.prependListener = noop;
  19570. process.prependOnceListener = noop;
  19571. process.listeners = function (name) { return [] }
  19572. process.binding = function (name) {
  19573. throw new Error('process.binding is not supported');
  19574. };
  19575. process.cwd = function () { return '/' };
  19576. process.chdir = function (dir) {
  19577. throw new Error('process.chdir is not supported');
  19578. };
  19579. process.umask = function() { return 0; };
  19580. /***/ }),
  19581. /***/ "./node_modules/webpack/buildin/global.js":
  19582. /*!***********************************!*\
  19583. !*** (webpack)/buildin/global.js ***!
  19584. \***********************************/
  19585. /*! no static exports found */
  19586. /***/ (function(module, exports) {
  19587. var g;
  19588. // This works in non-strict mode
  19589. g = (function() {
  19590. return this;
  19591. })();
  19592. try {
  19593. // This works if eval is allowed (see CSP)
  19594. g = g || new Function("return this")();
  19595. } catch (e) {
  19596. // This works if the window reference is available
  19597. if (typeof window === "object") g = window;
  19598. }
  19599. // g can still be undefined, but nothing to do about it...
  19600. // We return undefined, instead of nothing here, so it's
  19601. // easier to handle this case. if(!global) { ...}
  19602. module.exports = g;
  19603. /***/ }),
  19604. /***/ "./node_modules/webpack/buildin/module.js":
  19605. /*!***********************************!*\
  19606. !*** (webpack)/buildin/module.js ***!
  19607. \***********************************/
  19608. /*! no static exports found */
  19609. /***/ (function(module, exports) {
  19610. module.exports = function(module) {
  19611. if (!module.webpackPolyfill) {
  19612. module.deprecate = function() {};
  19613. module.paths = [];
  19614. // module.parent = undefined by default
  19615. if (!module.children) module.children = [];
  19616. Object.defineProperty(module, "loaded", {
  19617. enumerable: true,
  19618. get: function() {
  19619. return module.l;
  19620. }
  19621. });
  19622. Object.defineProperty(module, "id", {
  19623. enumerable: true,
  19624. get: function() {
  19625. return module.i;
  19626. }
  19627. });
  19628. module.webpackPolyfill = 1;
  19629. }
  19630. return module;
  19631. };
  19632. /***/ }),
  19633. /***/ "./resources/css/app.css":
  19634. /*!*******************************!*\
  19635. !*** ./resources/css/app.css ***!
  19636. \*******************************/
  19637. /*! no static exports found */
  19638. /***/ (function(module, exports) {
  19639. // removed by extract-text-webpack-plugin
  19640. /***/ }),
  19641. /***/ "./resources/js/app.js":
  19642. /*!*****************************!*\
  19643. !*** ./resources/js/app.js ***!
  19644. \*****************************/
  19645. /*! no static exports found */
  19646. /***/ (function(module, exports, __webpack_require__) {
  19647. __webpack_require__(/*! ./bootstrap */ "./resources/js/bootstrap.js");
  19648. __webpack_require__(/*! alpinejs */ "./node_modules/alpinejs/dist/alpine.js");
  19649. /***/ }),
  19650. /***/ "./resources/js/bootstrap.js":
  19651. /*!***********************************!*\
  19652. !*** ./resources/js/bootstrap.js ***!
  19653. \***********************************/
  19654. /*! no static exports found */
  19655. /***/ (function(module, exports, __webpack_require__) {
  19656. window._ = __webpack_require__(/*! lodash */ "./node_modules/lodash/lodash.js");
  19657. /**
  19658. * We'll load the axios HTTP library which allows us to easily issue requests
  19659. * to our Laravel back-end. This library automatically handles sending the
  19660. * CSRF token as a header based on the value of the "XSRF" token cookie.
  19661. */
  19662. window.axios = __webpack_require__(/*! axios */ "./node_modules/axios/index.js");
  19663. window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
  19664. /**
  19665. * Echo exposes an expressive API for subscribing to channels and listening
  19666. * for events that are broadcast by Laravel. Echo and event broadcasting
  19667. * allows your team to easily build robust real-time web applications.
  19668. */
  19669. // import Echo from 'laravel-echo';
  19670. // window.Pusher = require('pusher-js');
  19671. // window.Echo = new Echo({
  19672. // broadcaster: 'pusher',
  19673. // key: process.env.MIX_PUSHER_APP_KEY,
  19674. // cluster: process.env.MIX_PUSHER_APP_CLUSTER,
  19675. // forceTLS: true
  19676. // });
  19677. /***/ }),
  19678. /***/ 0:
  19679. /*!***********************************************************!*\
  19680. !*** multi ./resources/js/app.js ./resources/css/app.css ***!
  19681. \***********************************************************/
  19682. /*! no static exports found */
  19683. /***/ (function(module, exports, __webpack_require__) {
  19684. __webpack_require__(/*! C:\Users\Admin\Downloads\laravel_project\resources\js\app.js */"./resources/js/app.js");
  19685. module.exports = __webpack_require__(/*! C:\Users\Admin\Downloads\laravel_project\resources\css\app.css */"./resources/css/app.css");
  19686. /***/ })
  19687. /******/ });