app.js 673 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314731573167317731873197320732173227323732473257326732773287329733073317332733373347335733673377338733973407341734273437344734573467347734873497350735173527353735473557356735773587359736073617362736373647365736673677368736973707371737273737374737573767377737873797380738173827383738473857386738773887389739073917392739373947395739673977398739974007401740274037404740574067407740874097410741174127413741474157416741774187419742074217422742374247425742674277428742974307431743274337434743574367437743874397440744174427443744474457446744774487449745074517452745374547455745674577458745974607461746274637464746574667467746874697470747174727473747474757476747774787479748074817482748374847485748674877488748974907491749274937494749574967497749874997500750175027503750475057506750775087509751075117512751375147515751675177518751975207521752275237524752575267527752875297530753175327533753475357536753775387539754075417542754375447545754675477548754975507551755275537554755575567557755875597560756175627563756475657566756775687569757075717572757375747575757675777578757975807581758275837584758575867587758875897590759175927593759475957596759775987599760076017602760376047605760676077608760976107611761276137614761576167617761876197620762176227623762476257626762776287629763076317632763376347635763676377638763976407641764276437644764576467647764876497650765176527653765476557656765776587659766076617662766376647665766676677668766976707671767276737674767576767677767876797680768176827683768476857686768776887689769076917692769376947695769676977698769977007701770277037704770577067707770877097710771177127713771477157716771777187719772077217722772377247725772677277728772977307731773277337734773577367737773877397740774177427743774477457746774777487749775077517752775377547755775677577758775977607761776277637764776577667767776877697770777177727773777477757776777777787779778077817782778377847785778677877788778977907791779277937794779577967797779877997800780178027803780478057806780778087809781078117812781378147815781678177818781978207821782278237824782578267827782878297830783178327833783478357836783778387839784078417842784378447845784678477848784978507851785278537854785578567857785878597860786178627863786478657866786778687869787078717872787378747875787678777878787978807881788278837884788578867887788878897890789178927893789478957896789778987899790079017902790379047905790679077908790979107911791279137914791579167917791879197920792179227923792479257926792779287929793079317932793379347935793679377938793979407941794279437944794579467947794879497950795179527953795479557956795779587959796079617962796379647965796679677968796979707971797279737974797579767977797879797980798179827983798479857986798779887989799079917992799379947995799679977998799980008001800280038004800580068007800880098010801180128013801480158016801780188019802080218022802380248025802680278028802980308031803280338034803580368037803880398040804180428043804480458046804780488049805080518052805380548055805680578058805980608061806280638064806580668067806880698070807180728073807480758076807780788079808080818082808380848085808680878088808980908091809280938094809580968097809880998100810181028103810481058106810781088109811081118112811381148115811681178118811981208121812281238124812581268127812881298130813181328133813481358136813781388139814081418142814381448145814681478148814981508151815281538154815581568157815881598160816181628163816481658166816781688169817081718172817381748175817681778178817981808181818281838184818581868187818881898190819181928193819481958196819781988199820082018202820382048205820682078208820982108211821282138214821582168217821882198220822182228223822482258226822782288229823082318232823382348235823682378238823982408241824282438244824582468247824882498250825182528253825482558256825782588259826082618262826382648265826682678268826982708271827282738274827582768277827882798280828182828283828482858286828782888289829082918292829382948295829682978298829983008301830283038304830583068307830883098310831183128313831483158316831783188319832083218322832383248325832683278328832983308331833283338334833583368337833883398340834183428343834483458346834783488349835083518352835383548355835683578358835983608361836283638364836583668367836883698370837183728373837483758376837783788379838083818382838383848385838683878388838983908391839283938394839583968397839883998400840184028403840484058406840784088409841084118412841384148415841684178418841984208421842284238424842584268427842884298430843184328433843484358436843784388439844084418442844384448445844684478448844984508451845284538454845584568457845884598460846184628463846484658466846784688469847084718472847384748475847684778478847984808481848284838484848584868487848884898490849184928493849484958496849784988499850085018502850385048505850685078508850985108511851285138514851585168517851885198520852185228523852485258526852785288529853085318532853385348535853685378538853985408541854285438544854585468547854885498550855185528553855485558556855785588559856085618562856385648565856685678568856985708571857285738574857585768577857885798580858185828583858485858586858785888589859085918592859385948595859685978598859986008601860286038604860586068607860886098610861186128613861486158616861786188619862086218622862386248625862686278628862986308631863286338634863586368637863886398640864186428643864486458646864786488649865086518652865386548655865686578658865986608661866286638664866586668667866886698670867186728673867486758676867786788679868086818682868386848685868686878688868986908691869286938694869586968697869886998700870187028703870487058706870787088709871087118712871387148715871687178718871987208721872287238724872587268727872887298730873187328733873487358736873787388739874087418742874387448745874687478748874987508751875287538754875587568757875887598760876187628763876487658766876787688769877087718772877387748775877687778778877987808781878287838784878587868787878887898790879187928793879487958796879787988799880088018802880388048805880688078808880988108811881288138814881588168817881888198820882188228823882488258826882788288829883088318832883388348835883688378838883988408841884288438844884588468847884888498850885188528853885488558856885788588859886088618862886388648865886688678868886988708871887288738874887588768877887888798880888188828883888488858886888788888889889088918892889388948895889688978898889989008901890289038904890589068907890889098910891189128913891489158916891789188919892089218922892389248925892689278928892989308931893289338934893589368937893889398940894189428943894489458946894789488949895089518952895389548955895689578958895989608961896289638964896589668967896889698970897189728973897489758976897789788979898089818982898389848985898689878988898989908991899289938994899589968997899889999000900190029003900490059006900790089009901090119012901390149015901690179018901990209021902290239024902590269027902890299030903190329033903490359036903790389039904090419042904390449045904690479048904990509051905290539054905590569057905890599060906190629063906490659066906790689069907090719072907390749075907690779078907990809081908290839084908590869087908890899090909190929093909490959096909790989099910091019102910391049105910691079108910991109111911291139114911591169117911891199120912191229123912491259126912791289129913091319132913391349135913691379138913991409141914291439144914591469147914891499150915191529153915491559156915791589159916091619162916391649165916691679168916991709171917291739174917591769177917891799180918191829183918491859186918791889189919091919192919391949195919691979198919992009201920292039204920592069207920892099210921192129213921492159216921792189219922092219222922392249225922692279228922992309231923292339234923592369237923892399240924192429243924492459246924792489249925092519252925392549255925692579258925992609261926292639264926592669267926892699270927192729273927492759276927792789279928092819282928392849285928692879288928992909291929292939294929592969297929892999300930193029303930493059306930793089309931093119312931393149315931693179318931993209321932293239324932593269327932893299330933193329333933493359336933793389339934093419342934393449345934693479348934993509351935293539354935593569357935893599360936193629363936493659366936793689369937093719372937393749375937693779378937993809381938293839384938593869387938893899390939193929393939493959396939793989399940094019402940394049405940694079408940994109411941294139414941594169417941894199420942194229423942494259426942794289429943094319432943394349435943694379438943994409441944294439444944594469447944894499450945194529453945494559456945794589459946094619462946394649465946694679468946994709471947294739474947594769477947894799480948194829483948494859486948794889489949094919492949394949495949694979498949995009501950295039504950595069507950895099510951195129513951495159516951795189519952095219522952395249525952695279528952995309531953295339534953595369537953895399540954195429543954495459546954795489549955095519552955395549555955695579558955995609561956295639564956595669567956895699570957195729573957495759576957795789579958095819582958395849585958695879588958995909591959295939594959595969597959895999600960196029603960496059606960796089609961096119612961396149615961696179618961996209621962296239624962596269627962896299630963196329633963496359636963796389639964096419642964396449645964696479648964996509651965296539654965596569657965896599660966196629663966496659666966796689669967096719672967396749675967696779678967996809681968296839684968596869687968896899690969196929693969496959696969796989699970097019702970397049705970697079708970997109711971297139714971597169717971897199720972197229723972497259726972797289729973097319732973397349735973697379738973997409741974297439744974597469747974897499750975197529753975497559756975797589759976097619762976397649765976697679768976997709771977297739774977597769777977897799780978197829783978497859786978797889789979097919792979397949795979697979798979998009801980298039804980598069807980898099810981198129813981498159816981798189819982098219822982398249825982698279828982998309831983298339834983598369837983898399840984198429843984498459846984798489849985098519852985398549855985698579858985998609861986298639864986598669867986898699870987198729873987498759876987798789879988098819882988398849885988698879888988998909891989298939894989598969897989898999900990199029903990499059906990799089909991099119912991399149915991699179918991999209921992299239924992599269927992899299930993199329933993499359936993799389939994099419942994399449945994699479948994999509951995299539954995599569957995899599960996199629963996499659966996799689969997099719972997399749975997699779978997999809981998299839984998599869987998899899990999199929993999499959996999799989999100001000110002100031000410005100061000710008100091001010011100121001310014100151001610017100181001910020100211002210023100241002510026100271002810029100301003110032100331003410035100361003710038100391004010041100421004310044100451004610047100481004910050100511005210053100541005510056100571005810059100601006110062100631006410065100661006710068100691007010071100721007310074100751007610077100781007910080100811008210083100841008510086100871008810089100901009110092100931009410095100961009710098100991010010101101021010310104101051010610107101081010910110101111011210113101141011510116101171011810119101201012110122101231012410125101261012710128101291013010131101321013310134101351013610137101381013910140101411014210143101441014510146101471014810149101501015110152101531015410155101561015710158101591016010161101621016310164101651016610167101681016910170101711017210173101741017510176101771017810179101801018110182101831018410185101861018710188101891019010191101921019310194101951019610197101981019910200102011020210203102041020510206102071020810209102101021110212102131021410215102161021710218102191022010221102221022310224102251022610227102281022910230102311023210233102341023510236102371023810239102401024110242102431024410245102461024710248102491025010251102521025310254102551025610257102581025910260102611026210263102641026510266102671026810269102701027110272102731027410275102761027710278102791028010281102821028310284102851028610287102881028910290102911029210293102941029510296102971029810299103001030110302103031030410305103061030710308103091031010311103121031310314103151031610317103181031910320103211032210323103241032510326103271032810329103301033110332103331033410335103361033710338103391034010341103421034310344103451034610347103481034910350103511035210353103541035510356103571035810359103601036110362103631036410365103661036710368103691037010371103721037310374103751037610377103781037910380103811038210383103841038510386103871038810389103901039110392103931039410395103961039710398103991040010401104021040310404104051040610407104081040910410104111041210413104141041510416104171041810419104201042110422104231042410425104261042710428104291043010431104321043310434104351043610437104381043910440104411044210443104441044510446104471044810449104501045110452104531045410455104561045710458104591046010461104621046310464104651046610467104681046910470104711047210473104741047510476104771047810479104801048110482104831048410485104861048710488104891049010491104921049310494104951049610497104981049910500105011050210503105041050510506105071050810509105101051110512105131051410515105161051710518105191052010521105221052310524105251052610527105281052910530105311053210533105341053510536105371053810539105401054110542105431054410545105461054710548105491055010551105521055310554105551055610557105581055910560105611056210563105641056510566105671056810569105701057110572105731057410575105761057710578105791058010581105821058310584105851058610587105881058910590105911059210593105941059510596105971059810599106001060110602106031060410605106061060710608106091061010611106121061310614106151061610617106181061910620106211062210623106241062510626106271062810629106301063110632106331063410635106361063710638106391064010641106421064310644106451064610647106481064910650106511065210653106541065510656106571065810659106601066110662106631066410665106661066710668106691067010671106721067310674106751067610677106781067910680106811068210683106841068510686106871068810689106901069110692106931069410695106961069710698106991070010701107021070310704107051070610707107081070910710107111071210713107141071510716107171071810719107201072110722107231072410725107261072710728107291073010731107321073310734107351073610737107381073910740107411074210743107441074510746107471074810749107501075110752107531075410755107561075710758107591076010761107621076310764107651076610767107681076910770107711077210773107741077510776107771077810779107801078110782107831078410785107861078710788107891079010791107921079310794107951079610797107981079910800108011080210803108041080510806108071080810809108101081110812108131081410815108161081710818108191082010821108221082310824108251082610827108281082910830108311083210833108341083510836108371083810839108401084110842108431084410845108461084710848108491085010851108521085310854108551085610857108581085910860108611086210863108641086510866108671086810869108701087110872108731087410875108761087710878108791088010881108821088310884108851088610887108881088910890108911089210893108941089510896108971089810899109001090110902109031090410905109061090710908109091091010911109121091310914109151091610917109181091910920109211092210923109241092510926109271092810929109301093110932109331093410935109361093710938109391094010941109421094310944109451094610947109481094910950109511095210953109541095510956109571095810959109601096110962109631096410965109661096710968109691097010971109721097310974109751097610977109781097910980109811098210983109841098510986109871098810989109901099110992109931099410995109961099710998109991100011001110021100311004110051100611007110081100911010110111101211013110141101511016110171101811019110201102111022110231102411025110261102711028110291103011031110321103311034110351103611037110381103911040110411104211043110441104511046110471104811049110501105111052110531105411055110561105711058110591106011061110621106311064110651106611067110681106911070110711107211073110741107511076110771107811079110801108111082110831108411085110861108711088110891109011091110921109311094110951109611097110981109911100111011110211103111041110511106111071110811109111101111111112111131111411115111161111711118111191112011121111221112311124111251112611127111281112911130111311113211133111341113511136111371113811139111401114111142111431114411145111461114711148111491115011151111521115311154111551115611157111581115911160111611116211163111641116511166111671116811169111701117111172111731117411175111761117711178111791118011181111821118311184111851118611187111881118911190111911119211193111941119511196111971119811199112001120111202112031120411205112061120711208112091121011211112121121311214112151121611217112181121911220112211122211223112241122511226112271122811229112301123111232112331123411235112361123711238112391124011241112421124311244112451124611247112481124911250112511125211253112541125511256112571125811259112601126111262112631126411265112661126711268112691127011271112721127311274112751127611277112781127911280112811128211283112841128511286112871128811289112901129111292112931129411295112961129711298112991130011301113021130311304113051130611307113081130911310113111131211313113141131511316113171131811319113201132111322113231132411325113261132711328113291133011331113321133311334113351133611337113381133911340113411134211343113441134511346113471134811349113501135111352113531135411355113561135711358113591136011361113621136311364113651136611367113681136911370113711137211373113741137511376113771137811379113801138111382113831138411385113861138711388113891139011391113921139311394113951139611397113981139911400114011140211403114041140511406114071140811409114101141111412114131141411415114161141711418114191142011421114221142311424114251142611427114281142911430114311143211433114341143511436114371143811439114401144111442114431144411445114461144711448114491145011451114521145311454114551145611457114581145911460114611146211463114641146511466114671146811469114701147111472114731147411475114761147711478114791148011481114821148311484114851148611487114881148911490114911149211493114941149511496114971149811499115001150111502115031150411505115061150711508115091151011511115121151311514115151151611517115181151911520115211152211523115241152511526115271152811529115301153111532115331153411535115361153711538115391154011541115421154311544115451154611547115481154911550115511155211553115541155511556115571155811559115601156111562115631156411565115661156711568115691157011571115721157311574115751157611577115781157911580115811158211583115841158511586115871158811589115901159111592115931159411595115961159711598115991160011601116021160311604116051160611607116081160911610116111161211613116141161511616116171161811619116201162111622116231162411625116261162711628116291163011631116321163311634116351163611637116381163911640116411164211643116441164511646116471164811649116501165111652116531165411655116561165711658116591166011661116621166311664116651166611667116681166911670116711167211673116741167511676116771167811679116801168111682116831168411685116861168711688116891169011691116921169311694116951169611697116981169911700117011170211703117041170511706117071170811709117101171111712117131171411715117161171711718117191172011721117221172311724117251172611727117281172911730117311173211733117341173511736117371173811739117401174111742117431174411745117461174711748117491175011751117521175311754117551175611757117581175911760117611176211763117641176511766117671176811769117701177111772117731177411775117761177711778117791178011781117821178311784117851178611787117881178911790117911179211793117941179511796117971179811799118001180111802118031180411805118061180711808118091181011811118121181311814118151181611817118181181911820118211182211823118241182511826118271182811829118301183111832118331183411835118361183711838118391184011841118421184311844118451184611847118481184911850118511185211853118541185511856118571185811859118601186111862118631186411865118661186711868118691187011871118721187311874118751187611877118781187911880118811188211883118841188511886118871188811889118901189111892118931189411895118961189711898118991190011901119021190311904119051190611907119081190911910119111191211913119141191511916119171191811919119201192111922119231192411925119261192711928119291193011931119321193311934119351193611937119381193911940119411194211943119441194511946119471194811949119501195111952119531195411955119561195711958119591196011961119621196311964119651196611967119681196911970119711197211973119741197511976119771197811979119801198111982119831198411985119861198711988119891199011991119921199311994119951199611997119981199912000120011200212003120041200512006120071200812009120101201112012120131201412015120161201712018120191202012021120221202312024120251202612027120281202912030120311203212033120341203512036120371203812039120401204112042120431204412045120461204712048120491205012051120521205312054120551205612057120581205912060120611206212063120641206512066120671206812069120701207112072120731207412075120761207712078120791208012081120821208312084120851208612087120881208912090120911209212093120941209512096120971209812099121001210112102121031210412105121061210712108121091211012111121121211312114121151211612117121181211912120121211212212123121241212512126121271212812129121301213112132121331213412135121361213712138121391214012141121421214312144121451214612147121481214912150121511215212153121541215512156121571215812159121601216112162121631216412165121661216712168121691217012171121721217312174121751217612177121781217912180121811218212183121841218512186121871218812189121901219112192121931219412195121961219712198121991220012201122021220312204122051220612207122081220912210122111221212213122141221512216122171221812219122201222112222122231222412225122261222712228122291223012231122321223312234122351223612237122381223912240122411224212243122441224512246122471224812249122501225112252122531225412255122561225712258122591226012261122621226312264122651226612267122681226912270122711227212273122741227512276122771227812279122801228112282122831228412285122861228712288122891229012291122921229312294122951229612297122981229912300123011230212303123041230512306123071230812309123101231112312123131231412315123161231712318123191232012321123221232312324123251232612327123281232912330123311233212333123341233512336123371233812339123401234112342123431234412345123461234712348123491235012351123521235312354123551235612357123581235912360123611236212363123641236512366123671236812369123701237112372123731237412375123761237712378123791238012381123821238312384123851238612387123881238912390123911239212393123941239512396123971239812399124001240112402124031240412405124061240712408124091241012411124121241312414124151241612417124181241912420124211242212423124241242512426124271242812429124301243112432124331243412435124361243712438124391244012441124421244312444124451244612447124481244912450124511245212453124541245512456124571245812459124601246112462124631246412465124661246712468124691247012471124721247312474124751247612477124781247912480124811248212483124841248512486124871248812489124901249112492124931249412495124961249712498124991250012501125021250312504125051250612507125081250912510125111251212513125141251512516125171251812519125201252112522125231252412525125261252712528125291253012531125321253312534125351253612537125381253912540125411254212543125441254512546125471254812549125501255112552125531255412555125561255712558125591256012561125621256312564125651256612567125681256912570125711257212573125741257512576125771257812579125801258112582125831258412585125861258712588125891259012591125921259312594125951259612597125981259912600126011260212603126041260512606126071260812609126101261112612126131261412615126161261712618126191262012621126221262312624126251262612627126281262912630126311263212633126341263512636126371263812639126401264112642126431264412645126461264712648126491265012651126521265312654126551265612657126581265912660126611266212663126641266512666126671266812669126701267112672126731267412675126761267712678126791268012681126821268312684126851268612687126881268912690126911269212693126941269512696126971269812699127001270112702127031270412705127061270712708127091271012711127121271312714127151271612717127181271912720127211272212723127241272512726127271272812729127301273112732127331273412735127361273712738127391274012741127421274312744127451274612747127481274912750127511275212753127541275512756127571275812759127601276112762127631276412765127661276712768127691277012771127721277312774127751277612777127781277912780127811278212783127841278512786127871278812789127901279112792127931279412795127961279712798127991280012801128021280312804128051280612807128081280912810128111281212813128141281512816128171281812819128201282112822128231282412825128261282712828128291283012831128321283312834128351283612837128381283912840128411284212843128441284512846128471284812849128501285112852128531285412855128561285712858128591286012861128621286312864128651286612867128681286912870128711287212873128741287512876128771287812879128801288112882128831288412885128861288712888128891289012891128921289312894128951289612897128981289912900129011290212903129041290512906129071290812909129101291112912129131291412915129161291712918129191292012921129221292312924129251292612927129281292912930129311293212933129341293512936129371293812939129401294112942129431294412945129461294712948129491295012951129521295312954129551295612957129581295912960129611296212963129641296512966129671296812969129701297112972129731297412975129761297712978129791298012981129821298312984129851298612987129881298912990129911299212993129941299512996129971299812999130001300113002130031300413005130061300713008130091301013011130121301313014130151301613017130181301913020130211302213023130241302513026130271302813029130301303113032130331303413035130361303713038130391304013041130421304313044130451304613047130481304913050130511305213053130541305513056130571305813059130601306113062130631306413065130661306713068130691307013071130721307313074130751307613077130781307913080130811308213083130841308513086130871308813089130901309113092130931309413095130961309713098130991310013101131021310313104131051310613107131081310913110131111311213113131141311513116131171311813119131201312113122131231312413125131261312713128131291313013131131321313313134131351313613137131381313913140131411314213143131441314513146131471314813149131501315113152131531315413155131561315713158131591316013161131621316313164131651316613167131681316913170131711317213173131741317513176131771317813179131801318113182131831318413185131861318713188131891319013191131921319313194131951319613197131981319913200132011320213203132041320513206132071320813209132101321113212132131321413215132161321713218132191322013221132221322313224132251322613227132281322913230132311323213233132341323513236132371323813239132401324113242132431324413245132461324713248132491325013251132521325313254132551325613257132581325913260132611326213263132641326513266132671326813269132701327113272132731327413275132761327713278132791328013281132821328313284132851328613287132881328913290132911329213293132941329513296132971329813299133001330113302133031330413305133061330713308133091331013311133121331313314133151331613317133181331913320133211332213323133241332513326133271332813329133301333113332133331333413335133361333713338133391334013341133421334313344133451334613347133481334913350133511335213353133541335513356133571335813359133601336113362133631336413365133661336713368133691337013371133721337313374133751337613377133781337913380133811338213383133841338513386133871338813389133901339113392133931339413395133961339713398133991340013401134021340313404134051340613407134081340913410134111341213413134141341513416134171341813419134201342113422134231342413425134261342713428134291343013431134321343313434134351343613437134381343913440134411344213443134441344513446134471344813449134501345113452134531345413455134561345713458134591346013461134621346313464134651346613467134681346913470134711347213473134741347513476134771347813479134801348113482134831348413485134861348713488134891349013491134921349313494134951349613497134981349913500135011350213503135041350513506135071350813509135101351113512135131351413515135161351713518135191352013521135221352313524135251352613527135281352913530135311353213533135341353513536135371353813539135401354113542135431354413545135461354713548135491355013551135521355313554135551355613557135581355913560135611356213563135641356513566135671356813569135701357113572135731357413575135761357713578135791358013581135821358313584135851358613587135881358913590135911359213593135941359513596135971359813599136001360113602136031360413605136061360713608136091361013611136121361313614136151361613617136181361913620136211362213623136241362513626136271362813629136301363113632136331363413635136361363713638136391364013641136421364313644136451364613647136481364913650136511365213653136541365513656136571365813659136601366113662136631366413665136661366713668136691367013671136721367313674136751367613677136781367913680136811368213683136841368513686136871368813689136901369113692136931369413695136961369713698136991370013701137021370313704137051370613707137081370913710137111371213713137141371513716137171371813719137201372113722137231372413725137261372713728137291373013731137321373313734137351373613737137381373913740137411374213743137441374513746137471374813749137501375113752137531375413755137561375713758137591376013761137621376313764137651376613767137681376913770137711377213773137741377513776137771377813779137801378113782137831378413785137861378713788137891379013791137921379313794137951379613797137981379913800138011380213803138041380513806138071380813809138101381113812138131381413815138161381713818138191382013821138221382313824138251382613827138281382913830138311383213833138341383513836138371383813839138401384113842138431384413845138461384713848138491385013851138521385313854138551385613857138581385913860138611386213863138641386513866138671386813869138701387113872138731387413875138761387713878138791388013881138821388313884138851388613887138881388913890138911389213893138941389513896138971389813899139001390113902139031390413905139061390713908139091391013911139121391313914139151391613917139181391913920139211392213923139241392513926139271392813929139301393113932139331393413935139361393713938139391394013941139421394313944139451394613947139481394913950139511395213953139541395513956139571395813959139601396113962139631396413965139661396713968139691397013971139721397313974139751397613977139781397913980139811398213983139841398513986139871398813989139901399113992139931399413995139961399713998139991400014001140021400314004140051400614007140081400914010140111401214013140141401514016140171401814019140201402114022140231402414025140261402714028140291403014031140321403314034140351403614037140381403914040140411404214043140441404514046140471404814049140501405114052140531405414055140561405714058140591406014061140621406314064140651406614067140681406914070140711407214073140741407514076140771407814079140801408114082140831408414085140861408714088140891409014091140921409314094140951409614097140981409914100141011410214103141041410514106141071410814109141101411114112141131411414115141161411714118141191412014121141221412314124141251412614127141281412914130141311413214133141341413514136141371413814139141401414114142141431414414145141461414714148141491415014151141521415314154141551415614157141581415914160141611416214163141641416514166141671416814169141701417114172141731417414175141761417714178141791418014181141821418314184141851418614187141881418914190141911419214193141941419514196141971419814199142001420114202142031420414205142061420714208142091421014211142121421314214142151421614217142181421914220142211422214223142241422514226142271422814229142301423114232142331423414235142361423714238142391424014241142421424314244142451424614247142481424914250142511425214253142541425514256142571425814259142601426114262142631426414265142661426714268142691427014271142721427314274142751427614277142781427914280142811428214283142841428514286142871428814289142901429114292142931429414295142961429714298142991430014301143021430314304143051430614307143081430914310143111431214313143141431514316143171431814319143201432114322143231432414325143261432714328143291433014331143321433314334143351433614337143381433914340143411434214343143441434514346143471434814349143501435114352143531435414355143561435714358143591436014361143621436314364143651436614367143681436914370143711437214373143741437514376143771437814379143801438114382143831438414385143861438714388143891439014391143921439314394143951439614397143981439914400144011440214403144041440514406144071440814409144101441114412144131441414415144161441714418144191442014421144221442314424144251442614427144281442914430144311443214433144341443514436144371443814439144401444114442144431444414445144461444714448144491445014451144521445314454144551445614457144581445914460144611446214463144641446514466144671446814469144701447114472144731447414475144761447714478144791448014481144821448314484144851448614487144881448914490144911449214493144941449514496144971449814499145001450114502145031450414505145061450714508145091451014511145121451314514145151451614517145181451914520145211452214523145241452514526145271452814529145301453114532145331453414535145361453714538145391454014541145421454314544145451454614547145481454914550145511455214553145541455514556145571455814559145601456114562145631456414565145661456714568145691457014571145721457314574145751457614577145781457914580145811458214583145841458514586145871458814589145901459114592145931459414595145961459714598145991460014601146021460314604146051460614607146081460914610146111461214613146141461514616146171461814619146201462114622146231462414625146261462714628146291463014631146321463314634146351463614637146381463914640146411464214643146441464514646146471464814649146501465114652146531465414655146561465714658146591466014661146621466314664146651466614667146681466914670146711467214673146741467514676146771467814679146801468114682146831468414685146861468714688146891469014691146921469314694146951469614697146981469914700147011470214703147041470514706147071470814709147101471114712147131471414715147161471714718147191472014721147221472314724147251472614727147281472914730147311473214733147341473514736147371473814739147401474114742147431474414745147461474714748147491475014751147521475314754147551475614757147581475914760147611476214763147641476514766147671476814769147701477114772147731477414775147761477714778147791478014781147821478314784147851478614787147881478914790147911479214793147941479514796147971479814799148001480114802148031480414805148061480714808148091481014811148121481314814148151481614817148181481914820148211482214823148241482514826148271482814829148301483114832148331483414835148361483714838148391484014841148421484314844148451484614847148481484914850148511485214853148541485514856148571485814859148601486114862148631486414865148661486714868148691487014871148721487314874148751487614877148781487914880148811488214883148841488514886148871488814889148901489114892148931489414895148961489714898148991490014901149021490314904149051490614907149081490914910149111491214913149141491514916149171491814919149201492114922149231492414925149261492714928149291493014931149321493314934149351493614937149381493914940149411494214943149441494514946149471494814949149501495114952149531495414955149561495714958149591496014961149621496314964149651496614967149681496914970149711497214973149741497514976149771497814979149801498114982149831498414985149861498714988149891499014991149921499314994149951499614997149981499915000150011500215003150041500515006150071500815009150101501115012150131501415015150161501715018150191502015021150221502315024150251502615027150281502915030150311503215033150341503515036150371503815039150401504115042150431504415045150461504715048150491505015051150521505315054150551505615057150581505915060150611506215063150641506515066150671506815069150701507115072150731507415075150761507715078150791508015081150821508315084150851508615087150881508915090150911509215093150941509515096150971509815099151001510115102151031510415105151061510715108151091511015111151121511315114151151511615117151181511915120151211512215123151241512515126151271512815129151301513115132151331513415135151361513715138151391514015141151421514315144151451514615147151481514915150151511515215153151541515515156151571515815159151601516115162151631516415165151661516715168151691517015171151721517315174151751517615177151781517915180151811518215183151841518515186151871518815189151901519115192151931519415195151961519715198151991520015201152021520315204152051520615207152081520915210152111521215213152141521515216152171521815219152201522115222152231522415225152261522715228152291523015231152321523315234152351523615237152381523915240152411524215243152441524515246152471524815249152501525115252152531525415255152561525715258152591526015261152621526315264152651526615267152681526915270152711527215273152741527515276152771527815279152801528115282152831528415285152861528715288152891529015291152921529315294152951529615297152981529915300153011530215303153041530515306153071530815309153101531115312153131531415315153161531715318153191532015321153221532315324153251532615327153281532915330153311533215333153341533515336153371533815339153401534115342153431534415345153461534715348153491535015351153521535315354153551535615357153581535915360153611536215363153641536515366153671536815369153701537115372153731537415375153761537715378153791538015381153821538315384153851538615387153881538915390153911539215393153941539515396153971539815399154001540115402154031540415405154061540715408154091541015411154121541315414154151541615417154181541915420154211542215423154241542515426154271542815429154301543115432154331543415435154361543715438154391544015441154421544315444154451544615447154481544915450154511545215453154541545515456154571545815459154601546115462154631546415465154661546715468154691547015471154721547315474154751547615477154781547915480154811548215483154841548515486154871548815489154901549115492154931549415495154961549715498154991550015501155021550315504155051550615507155081550915510155111551215513155141551515516155171551815519155201552115522155231552415525155261552715528155291553015531155321553315534155351553615537155381553915540155411554215543155441554515546155471554815549155501555115552155531555415555155561555715558155591556015561155621556315564155651556615567155681556915570155711557215573155741557515576155771557815579155801558115582155831558415585155861558715588155891559015591155921559315594155951559615597155981559915600156011560215603156041560515606156071560815609156101561115612156131561415615156161561715618156191562015621156221562315624156251562615627156281562915630156311563215633156341563515636156371563815639156401564115642156431564415645156461564715648156491565015651156521565315654156551565615657156581565915660156611566215663156641566515666156671566815669156701567115672156731567415675156761567715678156791568015681156821568315684156851568615687156881568915690156911569215693156941569515696156971569815699157001570115702157031570415705157061570715708157091571015711157121571315714157151571615717157181571915720157211572215723157241572515726157271572815729157301573115732157331573415735157361573715738157391574015741157421574315744157451574615747157481574915750157511575215753157541575515756157571575815759157601576115762157631576415765157661576715768157691577015771157721577315774157751577615777157781577915780157811578215783157841578515786157871578815789157901579115792157931579415795157961579715798157991580015801158021580315804158051580615807158081580915810158111581215813158141581515816158171581815819158201582115822158231582415825158261582715828158291583015831158321583315834158351583615837158381583915840158411584215843158441584515846158471584815849158501585115852158531585415855158561585715858158591586015861158621586315864158651586615867158681586915870158711587215873158741587515876158771587815879158801588115882158831588415885158861588715888158891589015891158921589315894158951589615897158981589915900159011590215903159041590515906159071590815909159101591115912159131591415915159161591715918159191592015921159221592315924159251592615927159281592915930159311593215933159341593515936159371593815939159401594115942159431594415945159461594715948159491595015951159521595315954159551595615957159581595915960159611596215963159641596515966159671596815969159701597115972159731597415975159761597715978159791598015981159821598315984159851598615987159881598915990159911599215993159941599515996159971599815999160001600116002160031600416005160061600716008160091601016011160121601316014160151601616017160181601916020160211602216023160241602516026160271602816029160301603116032160331603416035160361603716038160391604016041160421604316044160451604616047160481604916050160511605216053160541605516056160571605816059160601606116062160631606416065160661606716068160691607016071160721607316074160751607616077160781607916080160811608216083160841608516086160871608816089160901609116092160931609416095160961609716098160991610016101161021610316104161051610616107161081610916110161111611216113161141611516116161171611816119161201612116122161231612416125161261612716128161291613016131161321613316134161351613616137161381613916140161411614216143161441614516146161471614816149161501615116152161531615416155161561615716158161591616016161161621616316164161651616616167161681616916170161711617216173161741617516176161771617816179161801618116182161831618416185161861618716188161891619016191161921619316194161951619616197161981619916200162011620216203162041620516206162071620816209162101621116212162131621416215162161621716218162191622016221162221622316224162251622616227162281622916230162311623216233162341623516236162371623816239162401624116242162431624416245162461624716248162491625016251162521625316254162551625616257162581625916260162611626216263162641626516266162671626816269162701627116272162731627416275162761627716278162791628016281162821628316284162851628616287162881628916290162911629216293162941629516296162971629816299163001630116302163031630416305163061630716308163091631016311163121631316314163151631616317163181631916320163211632216323163241632516326163271632816329163301633116332163331633416335163361633716338163391634016341163421634316344163451634616347163481634916350163511635216353163541635516356163571635816359163601636116362163631636416365163661636716368163691637016371163721637316374163751637616377163781637916380163811638216383163841638516386163871638816389163901639116392163931639416395163961639716398163991640016401164021640316404164051640616407164081640916410164111641216413164141641516416164171641816419164201642116422164231642416425164261642716428164291643016431164321643316434164351643616437164381643916440164411644216443164441644516446164471644816449164501645116452164531645416455164561645716458164591646016461164621646316464164651646616467164681646916470164711647216473164741647516476164771647816479164801648116482164831648416485164861648716488164891649016491164921649316494164951649616497164981649916500165011650216503165041650516506165071650816509165101651116512165131651416515165161651716518165191652016521165221652316524165251652616527165281652916530165311653216533165341653516536165371653816539165401654116542165431654416545165461654716548165491655016551165521655316554165551655616557165581655916560165611656216563165641656516566165671656816569165701657116572165731657416575165761657716578165791658016581165821658316584165851658616587165881658916590165911659216593165941659516596165971659816599166001660116602166031660416605166061660716608166091661016611166121661316614166151661616617166181661916620166211662216623166241662516626166271662816629166301663116632166331663416635166361663716638166391664016641166421664316644166451664616647166481664916650166511665216653166541665516656166571665816659166601666116662166631666416665166661666716668166691667016671166721667316674166751667616677166781667916680166811668216683166841668516686166871668816689166901669116692166931669416695166961669716698166991670016701167021670316704167051670616707167081670916710167111671216713167141671516716167171671816719167201672116722167231672416725167261672716728167291673016731167321673316734167351673616737167381673916740167411674216743167441674516746167471674816749167501675116752167531675416755167561675716758167591676016761167621676316764167651676616767167681676916770167711677216773167741677516776167771677816779167801678116782167831678416785167861678716788167891679016791167921679316794167951679616797167981679916800168011680216803168041680516806168071680816809168101681116812168131681416815168161681716818168191682016821168221682316824168251682616827168281682916830168311683216833168341683516836168371683816839168401684116842168431684416845168461684716848168491685016851168521685316854168551685616857168581685916860168611686216863168641686516866168671686816869168701687116872168731687416875168761687716878168791688016881168821688316884168851688616887168881688916890168911689216893168941689516896168971689816899169001690116902169031690416905169061690716908169091691016911169121691316914169151691616917169181691916920169211692216923169241692516926169271692816929169301693116932169331693416935169361693716938169391694016941169421694316944169451694616947169481694916950169511695216953169541695516956169571695816959169601696116962169631696416965169661696716968169691697016971169721697316974169751697616977169781697916980169811698216983169841698516986169871698816989169901699116992169931699416995169961699716998169991700017001170021700317004170051700617007170081700917010170111701217013170141701517016170171701817019170201702117022170231702417025170261702717028170291703017031170321703317034170351703617037170381703917040170411704217043170441704517046170471704817049170501705117052170531705417055170561705717058170591706017061170621706317064170651706617067170681706917070170711707217073170741707517076170771707817079170801708117082170831708417085170861708717088170891709017091170921709317094170951709617097170981709917100171011710217103171041710517106171071710817109171101711117112171131711417115171161711717118171191712017121171221712317124171251712617127171281712917130171311713217133171341713517136171371713817139171401714117142171431714417145171461714717148171491715017151171521715317154171551715617157171581715917160171611716217163171641716517166171671716817169171701717117172171731717417175171761717717178171791718017181171821718317184171851718617187171881718917190171911719217193171941719517196171971719817199172001720117202172031720417205172061720717208172091721017211172121721317214172151721617217172181721917220172211722217223172241722517226172271722817229172301723117232172331723417235172361723717238172391724017241172421724317244172451724617247172481724917250172511725217253172541725517256172571725817259172601726117262172631726417265172661726717268172691727017271172721727317274172751727617277172781727917280172811728217283172841728517286172871728817289172901729117292172931729417295172961729717298172991730017301173021730317304173051730617307173081730917310173111731217313173141731517316173171731817319173201732117322173231732417325173261732717328173291733017331173321733317334173351733617337173381733917340173411734217343173441734517346173471734817349173501735117352173531735417355173561735717358173591736017361173621736317364173651736617367173681736917370173711737217373173741737517376173771737817379173801738117382173831738417385173861738717388173891739017391173921739317394173951739617397173981739917400174011740217403174041740517406174071740817409174101741117412174131741417415174161741717418174191742017421174221742317424174251742617427174281742917430174311743217433174341743517436174371743817439174401744117442174431744417445174461744717448174491745017451174521745317454174551745617457174581745917460174611746217463174641746517466174671746817469174701747117472174731747417475174761747717478174791748017481174821748317484174851748617487174881748917490174911749217493174941749517496174971749817499175001750117502175031750417505175061750717508175091751017511175121751317514175151751617517175181751917520175211752217523175241752517526175271752817529175301753117532175331753417535175361753717538175391754017541175421754317544175451754617547175481754917550175511755217553175541755517556175571755817559175601756117562175631756417565175661756717568175691757017571175721757317574175751757617577175781757917580175811758217583175841758517586175871758817589175901759117592175931759417595175961759717598175991760017601176021760317604176051760617607176081760917610176111761217613176141761517616176171761817619176201762117622176231762417625176261762717628176291763017631176321763317634176351763617637176381763917640176411764217643176441764517646176471764817649176501765117652176531765417655176561765717658176591766017661176621766317664176651766617667176681766917670176711767217673176741767517676176771767817679176801768117682176831768417685176861768717688176891769017691176921769317694176951769617697176981769917700177011770217703177041770517706177071770817709177101771117712177131771417715177161771717718177191772017721177221772317724177251772617727177281772917730177311773217733177341773517736177371773817739177401774117742177431774417745177461774717748177491775017751177521775317754177551775617757177581775917760177611776217763177641776517766177671776817769177701777117772177731777417775177761777717778177791778017781177821778317784177851778617787177881778917790177911779217793177941779517796177971779817799178001780117802178031780417805178061780717808178091781017811178121781317814178151781617817178181781917820178211782217823178241782517826178271782817829178301783117832178331783417835178361783717838178391784017841178421784317844178451784617847178481784917850178511785217853178541785517856178571785817859178601786117862178631786417865178661786717868178691787017871178721787317874178751787617877178781787917880178811788217883178841788517886178871788817889178901789117892178931789417895178961789717898178991790017901179021790317904179051790617907179081790917910179111791217913179141791517916179171791817919179201792117922179231792417925179261792717928179291793017931179321793317934179351793617937179381793917940179411794217943179441794517946179471794817949179501795117952179531795417955179561795717958179591796017961179621796317964179651796617967179681796917970179711797217973179741797517976179771797817979179801798117982179831798417985179861798717988179891799017991179921799317994179951799617997179981799918000180011800218003180041800518006180071800818009180101801118012180131801418015180161801718018180191802018021180221802318024180251802618027180281802918030180311803218033180341803518036180371803818039180401804118042180431804418045180461804718048180491805018051180521805318054180551805618057180581805918060180611806218063180641806518066180671806818069180701807118072180731807418075180761807718078180791808018081180821808318084180851808618087180881808918090180911809218093180941809518096180971809818099181001810118102181031810418105181061810718108181091811018111181121811318114181151811618117181181811918120181211812218123181241812518126181271812818129181301813118132181331813418135181361813718138181391814018141181421814318144181451814618147181481814918150181511815218153181541815518156181571815818159181601816118162181631816418165181661816718168181691817018171181721817318174181751817618177181781817918180181811818218183181841818518186181871818818189181901819118192181931819418195181961819718198181991820018201182021820318204182051820618207182081820918210182111821218213182141821518216182171821818219182201822118222182231822418225182261822718228182291823018231182321823318234182351823618237182381823918240182411824218243182441824518246182471824818249182501825118252182531825418255182561825718258182591826018261182621826318264182651826618267182681826918270182711827218273182741827518276182771827818279182801828118282182831828418285182861828718288182891829018291182921829318294182951829618297182981829918300183011830218303183041830518306183071830818309183101831118312183131831418315183161831718318183191832018321183221832318324183251832618327183281832918330183311833218333183341833518336183371833818339183401834118342183431834418345183461834718348183491835018351183521835318354183551835618357183581835918360183611836218363183641836518366183671836818369183701837118372183731837418375183761837718378183791838018381183821838318384183851838618387183881838918390183911839218393183941839518396183971839818399184001840118402184031840418405184061840718408184091841018411184121841318414184151841618417184181841918420184211842218423184241842518426184271842818429184301843118432184331843418435184361843718438184391844018441184421844318444184451844618447184481844918450184511845218453184541845518456184571845818459184601846118462184631846418465184661846718468184691847018471184721847318474184751847618477184781847918480184811848218483184841848518486184871848818489184901849118492184931849418495184961849718498184991850018501185021850318504185051850618507185081850918510185111851218513185141851518516185171851818519185201852118522185231852418525185261852718528185291853018531185321853318534185351853618537185381853918540185411854218543185441854518546185471854818549185501855118552185531855418555185561855718558185591856018561185621856318564185651856618567185681856918570185711857218573185741857518576185771857818579185801858118582185831858418585185861858718588185891859018591185921859318594185951859618597185981859918600186011860218603186041860518606186071860818609186101861118612186131861418615186161861718618186191862018621186221862318624186251862618627186281862918630186311863218633186341863518636186371863818639186401864118642186431864418645186461864718648186491865018651186521865318654186551865618657186581865918660186611866218663186641866518666186671866818669186701867118672186731867418675186761867718678186791868018681186821868318684186851868618687186881868918690186911869218693186941869518696186971869818699187001870118702187031870418705187061870718708187091871018711187121871318714187151871618717187181871918720187211872218723187241872518726187271872818729187301873118732187331873418735187361873718738187391874018741187421874318744187451874618747187481874918750187511875218753187541875518756187571875818759187601876118762187631876418765187661876718768187691877018771187721877318774187751877618777187781877918780187811878218783187841878518786187871878818789187901879118792187931879418795187961879718798187991880018801188021880318804188051880618807188081880918810188111881218813188141881518816188171881818819188201882118822188231882418825188261882718828188291883018831188321883318834188351883618837188381883918840188411884218843188441884518846188471884818849188501885118852188531885418855188561885718858188591886018861188621886318864188651886618867188681886918870188711887218873188741887518876188771887818879188801888118882188831888418885188861888718888188891889018891188921889318894188951889618897188981889918900189011890218903189041890518906189071890818909189101891118912189131891418915189161891718918189191892018921189221892318924189251892618927189281892918930189311893218933189341893518936189371893818939189401894118942189431894418945189461894718948189491895018951189521895318954189551895618957189581895918960189611896218963189641896518966189671896818969189701897118972189731897418975189761897718978189791898018981189821898318984189851898618987189881898918990189911899218993189941899518996189971899818999190001900119002190031900419005190061900719008190091901019011190121901319014190151901619017190181901919020190211902219023190241902519026190271902819029190301903119032190331903419035190361903719038190391904019041190421904319044190451904619047190481904919050190511905219053190541905519056190571905819059190601906119062190631906419065190661906719068190691907019071190721907319074190751907619077190781907919080190811908219083190841908519086190871908819089190901909119092190931909419095190961909719098190991910019101191021910319104191051910619107191081910919110191111911219113191141911519116191171911819119191201912119122191231912419125191261912719128191291913019131191321913319134191351913619137191381913919140191411914219143191441914519146191471914819149191501915119152191531915419155191561915719158191591916019161191621916319164191651916619167191681916919170191711917219173191741917519176191771917819179191801918119182191831918419185191861918719188191891919019191191921919319194191951919619197191981919919200192011920219203192041920519206192071920819209192101921119212192131921419215192161921719218192191922019221192221922319224192251922619227192281922919230192311923219233192341923519236192371923819239192401924119242192431924419245192461924719248192491925019251192521925319254192551925619257192581925919260192611926219263192641926519266192671926819269192701927119272192731927419275192761927719278192791928019281192821928319284192851928619287192881928919290192911929219293192941929519296192971929819299193001930119302193031930419305193061930719308193091931019311193121931319314193151931619317193181931919320193211932219323193241932519326193271932819329193301933119332193331933419335193361933719338193391934019341193421934319344193451934619347193481934919350193511935219353193541935519356193571935819359193601936119362193631936419365193661936719368193691937019371193721937319374193751937619377193781937919380193811938219383193841938519386193871938819389193901939119392193931939419395193961939719398193991940019401194021940319404194051940619407194081940919410194111941219413194141941519416194171941819419194201942119422194231942419425194261942719428194291943019431194321943319434194351943619437194381943919440194411944219443194441944519446194471944819449194501945119452194531945419455194561945719458194591946019461194621946319464194651946619467194681946919470194711947219473194741947519476194771947819479194801948119482194831948419485194861948719488194891949019491194921949319494194951949619497194981949919500195011950219503195041950519506195071950819509195101951119512195131951419515195161951719518195191952019521195221952319524195251952619527195281952919530195311953219533195341953519536195371953819539195401954119542195431954419545195461954719548195491955019551195521955319554195551955619557195581955919560195611956219563195641956519566195671956819569195701957119572195731957419575195761957719578195791958019581195821958319584195851958619587195881958919590195911959219593195941959519596195971959819599196001960119602196031960419605196061960719608196091961019611196121961319614196151961619617196181961919620196211962219623196241962519626196271962819629196301963119632196331963419635196361963719638196391964019641196421964319644196451964619647196481964919650196511965219653196541965519656196571965819659196601966119662196631966419665196661966719668196691967019671196721967319674196751967619677196781967919680196811968219683196841968519686196871968819689196901969119692196931969419695196961969719698196991970019701197021970319704197051970619707197081970919710197111971219713197141971519716197171971819719197201972119722197231972419725197261972719728197291973019731197321973319734197351973619737197381973919740197411974219743197441974519746197471974819749197501975119752197531975419755197561975719758197591976019761197621976319764197651976619767197681976919770197711977219773197741977519776197771977819779197801978119782197831978419785197861978719788197891979019791197921979319794197951979619797197981979919800198011980219803198041980519806198071980819809198101981119812198131981419815198161981719818198191982019821198221982319824198251982619827198281982919830198311983219833198341983519836198371983819839198401984119842198431984419845198461984719848198491985019851198521985319854198551985619857198581985919860198611986219863198641986519866198671986819869198701987119872198731987419875198761987719878198791988019881198821988319884198851988619887198881988919890198911989219893198941989519896198971989819899199001990119902199031990419905199061990719908199091991019911199121991319914199151991619917199181991919920199211992219923199241992519926199271992819929199301993119932199331993419935199361993719938199391994019941199421994319944199451994619947199481994919950199511995219953199541995519956199571995819959199601996119962199631996419965199661996719968199691997019971199721997319974199751997619977199781997919980199811998219983199841998519986199871998819989199901999119992199931999419995199961999719998199992000020001200022000320004200052000620007200082000920010200112001220013200142001520016200172001820019200202002120022200232002420025200262002720028200292003020031200322003320034200352003620037200382003920040200412004220043200442004520046200472004820049200502005120052200532005420055200562005720058200592006020061200622006320064200652006620067200682006920070200712007220073200742007520076200772007820079200802008120082200832008420085200862008720088200892009020091200922009320094200952009620097200982009920100201012010220103201042010520106201072010820109201102011120112201132011420115201162011720118201192012020121201222012320124201252012620127201282012920130201312013220133201342013520136201372013820139201402014120142201432014420145201462014720148201492015020151201522015320154201552015620157201582015920160201612016220163201642016520166201672016820169201702017120172201732017420175201762017720178201792018020181201822018320184201852018620187201882018920190201912019220193201942019520196201972019820199202002020120202202032020420205202062020720208202092021020211202122021320214202152021620217202182021920220202212022220223202242022520226202272022820229202302023120232202332023420235202362023720238202392024020241202422024320244202452024620247202482024920250202512025220253202542025520256202572025820259202602026120262202632026420265202662026720268202692027020271202722027320274202752027620277202782027920280202812028220283202842028520286202872028820289202902029120292202932029420295202962029720298202992030020301203022030320304203052030620307203082030920310203112031220313203142031520316203172031820319203202032120322203232032420325203262032720328203292033020331203322033320334203352033620337203382033920340203412034220343203442034520346203472034820349203502035120352203532035420355203562035720358203592036020361203622036320364203652036620367203682036920370203712037220373203742037520376203772037820379203802038120382203832038420385203862038720388203892039020391203922039320394203952039620397203982039920400204012040220403204042040520406204072040820409204102041120412204132041420415204162041720418204192042020421204222042320424204252042620427204282042920430204312043220433204342043520436204372043820439204402044120442204432044420445204462044720448204492045020451204522045320454204552045620457204582045920460204612046220463204642046520466204672046820469204702047120472204732047420475204762047720478204792048020481204822048320484204852048620487204882048920490204912049220493204942049520496204972049820499205002050120502205032050420505205062050720508205092051020511205122051320514205152051620517205182051920520205212052220523205242052520526205272052820529205302053120532205332053420535205362053720538205392054020541205422054320544205452054620547205482054920550205512055220553205542055520556205572055820559205602056120562205632056420565205662056720568205692057020571205722057320574205752057620577205782057920580205812058220583205842058520586205872058820589205902059120592205932059420595205962059720598205992060020601206022060320604206052060620607206082060920610206112061220613206142061520616206172061820619206202062120622206232062420625206262062720628206292063020631206322063320634206352063620637206382063920640206412064220643206442064520646206472064820649206502065120652206532065420655206562065720658206592066020661206622066320664206652066620667206682066920670206712067220673206742067520676206772067820679206802068120682206832068420685206862068720688206892069020691206922069320694206952069620697206982069920700207012070220703207042070520706207072070820709207102071120712207132071420715207162071720718207192072020721207222072320724207252072620727207282072920730207312073220733207342073520736207372073820739207402074120742207432074420745207462074720748207492075020751207522075320754207552075620757207582075920760207612076220763207642076520766207672076820769207702077120772207732077420775207762077720778207792078020781207822078320784207852078620787207882078920790207912079220793207942079520796207972079820799208002080120802208032080420805208062080720808208092081020811208122081320814208152081620817208182081920820208212082220823208242082520826208272082820829208302083120832208332083420835208362083720838208392084020841208422084320844208452084620847208482084920850208512085220853208542085520856208572085820859208602086120862208632086420865208662086720868208692087020871208722087320874208752087620877208782087920880208812088220883208842088520886208872088820889208902089120892208932089420895208962089720898208992090020901209022090320904209052090620907209082090920910209112091220913209142091520916209172091820919209202092120922209232092420925209262092720928209292093020931209322093320934209352093620937209382093920940209412094220943209442094520946209472094820949209502095120952209532095420955209562095720958209592096020961209622096320964209652096620967209682096920970209712097220973209742097520976209772097820979209802098120982209832098420985209862098720988209892099020991209922099320994209952099620997209982099921000210012100221003210042100521006210072100821009210102101121012210132101421015210162101721018210192102021021210222102321024210252102621027210282102921030210312103221033210342103521036210372103821039210402104121042210432104421045210462104721048210492105021051210522105321054210552105621057210582105921060210612106221063210642106521066210672106821069210702107121072210732107421075210762107721078210792108021081210822108321084210852108621087210882108921090210912109221093210942109521096210972109821099211002110121102211032110421105211062110721108211092111021111211122111321114211152111621117211182111921120211212112221123211242112521126211272112821129211302113121132211332113421135211362113721138211392114021141211422114321144211452114621147211482114921150211512115221153211542115521156211572115821159211602116121162211632116421165211662116721168211692117021171211722117321174211752117621177211782117921180211812118221183211842118521186211872118821189211902119121192211932119421195211962119721198211992120021201212022120321204212052120621207212082120921210212112121221213212142121521216212172121821219212202122121222212232122421225212262122721228212292123021231212322123321234212352123621237212382123921240212412124221243212442124521246212472124821249212502125121252212532125421255212562125721258212592126021261212622126321264212652126621267212682126921270212712127221273212742127521276212772127821279212802128121282212832128421285212862128721288212892129021291212922129321294212952129621297212982129921300213012130221303213042130521306213072130821309213102131121312213132131421315213162131721318213192132021321213222132321324213252132621327213282132921330213312133221333213342133521336213372133821339213402134121342213432134421345213462134721348213492135021351213522135321354213552135621357213582135921360213612136221363213642136521366213672136821369213702137121372213732137421375213762137721378213792138021381213822138321384213852138621387213882138921390213912139221393213942139521396213972139821399214002140121402214032140421405214062140721408214092141021411214122141321414214152141621417214182141921420
  1. /******/ (() => { // webpackBootstrap
  2. /******/ var __webpack_modules__ = ({
  3. /***/ "./node_modules/alpinejs/dist/alpine.js":
  4. /*!**********************************************!*\
  5. !*** ./node_modules/alpinejs/dist/alpine.js ***!
  6. \**********************************************/
  7. /***/ (function(module) {
  8. (function (global, factory) {
  9. true ? module.exports = factory() :
  10. 0;
  11. }(this, (function () { 'use strict';
  12. function _defineProperty(obj, key, value) {
  13. if (key in obj) {
  14. Object.defineProperty(obj, key, {
  15. value: value,
  16. enumerable: true,
  17. configurable: true,
  18. writable: true
  19. });
  20. } else {
  21. obj[key] = value;
  22. }
  23. return obj;
  24. }
  25. function ownKeys(object, enumerableOnly) {
  26. var keys = Object.keys(object);
  27. if (Object.getOwnPropertySymbols) {
  28. var symbols = Object.getOwnPropertySymbols(object);
  29. if (enumerableOnly) symbols = symbols.filter(function (sym) {
  30. return Object.getOwnPropertyDescriptor(object, sym).enumerable;
  31. });
  32. keys.push.apply(keys, symbols);
  33. }
  34. return keys;
  35. }
  36. function _objectSpread2(target) {
  37. for (var i = 1; i < arguments.length; i++) {
  38. var source = arguments[i] != null ? arguments[i] : {};
  39. if (i % 2) {
  40. ownKeys(Object(source), true).forEach(function (key) {
  41. _defineProperty(target, key, source[key]);
  42. });
  43. } else if (Object.getOwnPropertyDescriptors) {
  44. Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
  45. } else {
  46. ownKeys(Object(source)).forEach(function (key) {
  47. Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
  48. });
  49. }
  50. }
  51. return target;
  52. }
  53. // Thanks @stimulus:
  54. // https://github.com/stimulusjs/stimulus/blob/master/packages/%40stimulus/core/src/application.ts
  55. function domReady() {
  56. return new Promise(resolve => {
  57. if (document.readyState == "loading") {
  58. document.addEventListener("DOMContentLoaded", resolve);
  59. } else {
  60. resolve();
  61. }
  62. });
  63. }
  64. function arrayUnique(array) {
  65. return Array.from(new Set(array));
  66. }
  67. function isTesting() {
  68. return navigator.userAgent.includes("Node.js") || navigator.userAgent.includes("jsdom");
  69. }
  70. function checkedAttrLooseCompare(valueA, valueB) {
  71. return valueA == valueB;
  72. }
  73. function warnIfMalformedTemplate(el, directive) {
  74. if (el.tagName.toLowerCase() !== 'template') {
  75. console.warn(`Alpine: [${directive}] directive should only be added to <template> tags. See https://github.com/alpinejs/alpine#${directive}`);
  76. } else if (el.content.childElementCount !== 1) {
  77. console.warn(`Alpine: <template> tag with [${directive}] encountered with an unexpected number of root elements. Make sure <template> has a single root element. `);
  78. }
  79. }
  80. function kebabCase(subject) {
  81. return subject.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/[_\s]/, '-').toLowerCase();
  82. }
  83. function camelCase(subject) {
  84. return subject.toLowerCase().replace(/-(\w)/g, (match, char) => char.toUpperCase());
  85. }
  86. function walk(el, callback) {
  87. if (callback(el) === false) return;
  88. let node = el.firstElementChild;
  89. while (node) {
  90. walk(node, callback);
  91. node = node.nextElementSibling;
  92. }
  93. }
  94. function debounce(func, wait) {
  95. var timeout;
  96. return function () {
  97. var context = this,
  98. args = arguments;
  99. var later = function later() {
  100. timeout = null;
  101. func.apply(context, args);
  102. };
  103. clearTimeout(timeout);
  104. timeout = setTimeout(later, wait);
  105. };
  106. }
  107. const handleError = (el, expression, error) => {
  108. console.warn(`Alpine Error: "${error}"\n\nExpression: "${expression}"\nElement:`, el);
  109. if (!isTesting()) {
  110. Object.assign(error, {
  111. el,
  112. expression
  113. });
  114. throw error;
  115. }
  116. };
  117. function tryCatch(cb, {
  118. el,
  119. expression
  120. }) {
  121. try {
  122. const value = cb();
  123. return value instanceof Promise ? value.catch(e => handleError(el, expression, e)) : value;
  124. } catch (e) {
  125. handleError(el, expression, e);
  126. }
  127. }
  128. function saferEval(el, expression, dataContext, additionalHelperVariables = {}) {
  129. return tryCatch(() => {
  130. if (typeof expression === 'function') {
  131. return expression.call(dataContext);
  132. }
  133. return new Function(['$data', ...Object.keys(additionalHelperVariables)], `var __alpine_result; with($data) { __alpine_result = ${expression} }; return __alpine_result`)(dataContext, ...Object.values(additionalHelperVariables));
  134. }, {
  135. el,
  136. expression
  137. });
  138. }
  139. function saferEvalNoReturn(el, expression, dataContext, additionalHelperVariables = {}) {
  140. return tryCatch(() => {
  141. if (typeof expression === 'function') {
  142. return Promise.resolve(expression.call(dataContext, additionalHelperVariables['$event']));
  143. }
  144. let AsyncFunction = Function;
  145. /* MODERN-ONLY:START */
  146. AsyncFunction = Object.getPrototypeOf(async function () {}).constructor;
  147. /* MODERN-ONLY:END */
  148. // For the cases when users pass only a function reference to the caller: `x-on:click="foo"`
  149. // Where "foo" is a function. Also, we'll pass the function the event instance when we call it.
  150. if (Object.keys(dataContext).includes(expression)) {
  151. let methodReference = new Function(['dataContext', ...Object.keys(additionalHelperVariables)], `with(dataContext) { return ${expression} }`)(dataContext, ...Object.values(additionalHelperVariables));
  152. if (typeof methodReference === 'function') {
  153. return Promise.resolve(methodReference.call(dataContext, additionalHelperVariables['$event']));
  154. } else {
  155. return Promise.resolve();
  156. }
  157. }
  158. return Promise.resolve(new AsyncFunction(['dataContext', ...Object.keys(additionalHelperVariables)], `with(dataContext) { ${expression} }`)(dataContext, ...Object.values(additionalHelperVariables)));
  159. }, {
  160. el,
  161. expression
  162. });
  163. }
  164. const xAttrRE = /^x-(on|bind|data|text|html|model|if|for|show|cloak|transition|ref|spread)\b/;
  165. function isXAttr(attr) {
  166. const name = replaceAtAndColonWithStandardSyntax(attr.name);
  167. return xAttrRE.test(name);
  168. }
  169. function getXAttrs(el, component, type) {
  170. let directives = Array.from(el.attributes).filter(isXAttr).map(parseHtmlAttribute); // Get an object of directives from x-spread.
  171. let spreadDirective = directives.filter(directive => directive.type === 'spread')[0];
  172. if (spreadDirective) {
  173. let spreadObject = saferEval(el, spreadDirective.expression, component.$data); // Add x-spread directives to the pile of existing directives.
  174. directives = directives.concat(Object.entries(spreadObject).map(([name, value]) => parseHtmlAttribute({
  175. name,
  176. value
  177. })));
  178. }
  179. if (type) return directives.filter(i => i.type === type);
  180. return sortDirectives(directives);
  181. }
  182. function sortDirectives(directives) {
  183. let directiveOrder = ['bind', 'model', 'show', 'catch-all'];
  184. return directives.sort((a, b) => {
  185. let typeA = directiveOrder.indexOf(a.type) === -1 ? 'catch-all' : a.type;
  186. let typeB = directiveOrder.indexOf(b.type) === -1 ? 'catch-all' : b.type;
  187. return directiveOrder.indexOf(typeA) - directiveOrder.indexOf(typeB);
  188. });
  189. }
  190. function parseHtmlAttribute({
  191. name,
  192. value
  193. }) {
  194. const normalizedName = replaceAtAndColonWithStandardSyntax(name);
  195. const typeMatch = normalizedName.match(xAttrRE);
  196. const valueMatch = normalizedName.match(/:([a-zA-Z0-9\-:]+)/);
  197. const modifiers = normalizedName.match(/\.[^.\]]+(?=[^\]]*$)/g) || [];
  198. return {
  199. type: typeMatch ? typeMatch[1] : null,
  200. value: valueMatch ? valueMatch[1] : null,
  201. modifiers: modifiers.map(i => i.replace('.', '')),
  202. expression: value
  203. };
  204. }
  205. function isBooleanAttr(attrName) {
  206. // As per HTML spec table https://html.spec.whatwg.org/multipage/indices.html#attributes-3:boolean-attribute
  207. // Array roughly ordered by estimated usage
  208. 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'];
  209. return booleanAttributes.includes(attrName);
  210. }
  211. function replaceAtAndColonWithStandardSyntax(name) {
  212. if (name.startsWith('@')) {
  213. return name.replace('@', 'x-on:');
  214. } else if (name.startsWith(':')) {
  215. return name.replace(':', 'x-bind:');
  216. }
  217. return name;
  218. }
  219. function convertClassStringToArray(classList, filterFn = Boolean) {
  220. return classList.split(' ').filter(filterFn);
  221. }
  222. const TRANSITION_TYPE_IN = 'in';
  223. const TRANSITION_TYPE_OUT = 'out';
  224. const TRANSITION_CANCELLED = 'cancelled';
  225. function transitionIn(el, show, reject, component, forceSkip = false) {
  226. // We don't want to transition on the initial page load.
  227. if (forceSkip) return show();
  228. if (el.__x_transition && el.__x_transition.type === TRANSITION_TYPE_IN) {
  229. // there is already a similar transition going on, this was probably triggered by
  230. // a change in a different property, let's just leave the previous one doing its job
  231. return;
  232. }
  233. const attrs = getXAttrs(el, component, 'transition');
  234. const showAttr = getXAttrs(el, component, 'show')[0]; // If this is triggered by a x-show.transition.
  235. if (showAttr && showAttr.modifiers.includes('transition')) {
  236. let modifiers = showAttr.modifiers; // If x-show.transition.out, we'll skip the "in" transition.
  237. if (modifiers.includes('out') && !modifiers.includes('in')) return show();
  238. const settingBothSidesOfTransition = modifiers.includes('in') && modifiers.includes('out'); // If x-show.transition.in...out... only use "in" related modifiers for this transition.
  239. modifiers = settingBothSidesOfTransition ? modifiers.filter((i, index) => index < modifiers.indexOf('out')) : modifiers;
  240. transitionHelperIn(el, modifiers, show, reject); // Otherwise, we can assume x-transition:enter.
  241. } else if (attrs.some(attr => ['enter', 'enter-start', 'enter-end'].includes(attr.value))) {
  242. transitionClassesIn(el, component, attrs, show, reject);
  243. } else {
  244. // If neither, just show that damn thing.
  245. show();
  246. }
  247. }
  248. function transitionOut(el, hide, reject, component, forceSkip = false) {
  249. // We don't want to transition on the initial page load.
  250. if (forceSkip) return hide();
  251. if (el.__x_transition && el.__x_transition.type === TRANSITION_TYPE_OUT) {
  252. // there is already a similar transition going on, this was probably triggered by
  253. // a change in a different property, let's just leave the previous one doing its job
  254. return;
  255. }
  256. const attrs = getXAttrs(el, component, 'transition');
  257. const showAttr = getXAttrs(el, component, 'show')[0];
  258. if (showAttr && showAttr.modifiers.includes('transition')) {
  259. let modifiers = showAttr.modifiers;
  260. if (modifiers.includes('in') && !modifiers.includes('out')) return hide();
  261. const settingBothSidesOfTransition = modifiers.includes('in') && modifiers.includes('out');
  262. modifiers = settingBothSidesOfTransition ? modifiers.filter((i, index) => index > modifiers.indexOf('out')) : modifiers;
  263. transitionHelperOut(el, modifiers, settingBothSidesOfTransition, hide, reject);
  264. } else if (attrs.some(attr => ['leave', 'leave-start', 'leave-end'].includes(attr.value))) {
  265. transitionClassesOut(el, component, attrs, hide, reject);
  266. } else {
  267. hide();
  268. }
  269. }
  270. function transitionHelperIn(el, modifiers, showCallback, reject) {
  271. // Default values inspired by: https://material.io/design/motion/speed.html#duration
  272. const styleValues = {
  273. duration: modifierValue(modifiers, 'duration', 150),
  274. origin: modifierValue(modifiers, 'origin', 'center'),
  275. first: {
  276. opacity: 0,
  277. scale: modifierValue(modifiers, 'scale', 95)
  278. },
  279. second: {
  280. opacity: 1,
  281. scale: 100
  282. }
  283. };
  284. transitionHelper(el, modifiers, showCallback, () => {}, reject, styleValues, TRANSITION_TYPE_IN);
  285. }
  286. function transitionHelperOut(el, modifiers, settingBothSidesOfTransition, hideCallback, reject) {
  287. // Make the "out" transition .5x slower than the "in". (Visually better)
  288. // HOWEVER, if they explicitly set a duration for the "out" transition,
  289. // use that.
  290. const duration = settingBothSidesOfTransition ? modifierValue(modifiers, 'duration', 150) : modifierValue(modifiers, 'duration', 150) / 2;
  291. const styleValues = {
  292. duration: duration,
  293. origin: modifierValue(modifiers, 'origin', 'center'),
  294. first: {
  295. opacity: 1,
  296. scale: 100
  297. },
  298. second: {
  299. opacity: 0,
  300. scale: modifierValue(modifiers, 'scale', 95)
  301. }
  302. };
  303. transitionHelper(el, modifiers, () => {}, hideCallback, reject, styleValues, TRANSITION_TYPE_OUT);
  304. }
  305. function modifierValue(modifiers, key, fallback) {
  306. // If the modifier isn't present, use the default.
  307. if (modifiers.indexOf(key) === -1) return fallback; // If it IS present, grab the value after it: x-show.transition.duration.500ms
  308. const rawValue = modifiers[modifiers.indexOf(key) + 1];
  309. if (!rawValue) return fallback;
  310. if (key === 'scale') {
  311. // Check if the very next value is NOT a number and return the fallback.
  312. // If x-show.transition.scale, we'll use the default scale value.
  313. // That is how a user opts out of the opacity transition.
  314. if (!isNumeric(rawValue)) return fallback;
  315. }
  316. if (key === 'duration') {
  317. // Support x-show.transition.duration.500ms && duration.500
  318. let match = rawValue.match(/([0-9]+)ms/);
  319. if (match) return match[1];
  320. }
  321. if (key === 'origin') {
  322. // Support chaining origin directions: x-show.transition.top.right
  323. if (['top', 'right', 'left', 'center', 'bottom'].includes(modifiers[modifiers.indexOf(key) + 2])) {
  324. return [rawValue, modifiers[modifiers.indexOf(key) + 2]].join(' ');
  325. }
  326. }
  327. return rawValue;
  328. }
  329. function transitionHelper(el, modifiers, hook1, hook2, reject, styleValues, type) {
  330. // clear the previous transition if exists to avoid caching the wrong styles
  331. if (el.__x_transition) {
  332. el.__x_transition.cancel && el.__x_transition.cancel();
  333. } // If the user set these style values, we'll put them back when we're done with them.
  334. const opacityCache = el.style.opacity;
  335. const transformCache = el.style.transform;
  336. const transformOriginCache = el.style.transformOrigin; // If no modifiers are present: x-show.transition, we'll default to both opacity and scale.
  337. const noModifiers = !modifiers.includes('opacity') && !modifiers.includes('scale');
  338. const transitionOpacity = noModifiers || modifiers.includes('opacity');
  339. const transitionScale = noModifiers || modifiers.includes('scale'); // These are the explicit stages of a transition (same stages for in and for out).
  340. // This way you can get a birds eye view of the hooks, and the differences
  341. // between them.
  342. const stages = {
  343. start() {
  344. if (transitionOpacity) el.style.opacity = styleValues.first.opacity;
  345. if (transitionScale) el.style.transform = `scale(${styleValues.first.scale / 100})`;
  346. },
  347. during() {
  348. if (transitionScale) el.style.transformOrigin = styleValues.origin;
  349. el.style.transitionProperty = [transitionOpacity ? `opacity` : ``, transitionScale ? `transform` : ``].join(' ').trim();
  350. el.style.transitionDuration = `${styleValues.duration / 1000}s`;
  351. el.style.transitionTimingFunction = `cubic-bezier(0.4, 0.0, 0.2, 1)`;
  352. },
  353. show() {
  354. hook1();
  355. },
  356. end() {
  357. if (transitionOpacity) el.style.opacity = styleValues.second.opacity;
  358. if (transitionScale) el.style.transform = `scale(${styleValues.second.scale / 100})`;
  359. },
  360. hide() {
  361. hook2();
  362. },
  363. cleanup() {
  364. if (transitionOpacity) el.style.opacity = opacityCache;
  365. if (transitionScale) el.style.transform = transformCache;
  366. if (transitionScale) el.style.transformOrigin = transformOriginCache;
  367. el.style.transitionProperty = null;
  368. el.style.transitionDuration = null;
  369. el.style.transitionTimingFunction = null;
  370. }
  371. };
  372. transition(el, stages, type, reject);
  373. }
  374. const ensureStringExpression = (expression, el, component) => {
  375. return typeof expression === 'function' ? component.evaluateReturnExpression(el, expression) : expression;
  376. };
  377. function transitionClassesIn(el, component, directives, showCallback, reject) {
  378. const enter = convertClassStringToArray(ensureStringExpression((directives.find(i => i.value === 'enter') || {
  379. expression: ''
  380. }).expression, el, component));
  381. const enterStart = convertClassStringToArray(ensureStringExpression((directives.find(i => i.value === 'enter-start') || {
  382. expression: ''
  383. }).expression, el, component));
  384. const enterEnd = convertClassStringToArray(ensureStringExpression((directives.find(i => i.value === 'enter-end') || {
  385. expression: ''
  386. }).expression, el, component));
  387. transitionClasses(el, enter, enterStart, enterEnd, showCallback, () => {}, TRANSITION_TYPE_IN, reject);
  388. }
  389. function transitionClassesOut(el, component, directives, hideCallback, reject) {
  390. const leave = convertClassStringToArray(ensureStringExpression((directives.find(i => i.value === 'leave') || {
  391. expression: ''
  392. }).expression, el, component));
  393. const leaveStart = convertClassStringToArray(ensureStringExpression((directives.find(i => i.value === 'leave-start') || {
  394. expression: ''
  395. }).expression, el, component));
  396. const leaveEnd = convertClassStringToArray(ensureStringExpression((directives.find(i => i.value === 'leave-end') || {
  397. expression: ''
  398. }).expression, el, component));
  399. transitionClasses(el, leave, leaveStart, leaveEnd, () => {}, hideCallback, TRANSITION_TYPE_OUT, reject);
  400. }
  401. function transitionClasses(el, classesDuring, classesStart, classesEnd, hook1, hook2, type, reject) {
  402. // clear the previous transition if exists to avoid caching the wrong classes
  403. if (el.__x_transition) {
  404. el.__x_transition.cancel && el.__x_transition.cancel();
  405. }
  406. const originalClasses = el.__x_original_classes || [];
  407. const stages = {
  408. start() {
  409. el.classList.add(...classesStart);
  410. },
  411. during() {
  412. el.classList.add(...classesDuring);
  413. },
  414. show() {
  415. hook1();
  416. },
  417. end() {
  418. // Don't remove classes that were in the original class attribute.
  419. el.classList.remove(...classesStart.filter(i => !originalClasses.includes(i)));
  420. el.classList.add(...classesEnd);
  421. },
  422. hide() {
  423. hook2();
  424. },
  425. cleanup() {
  426. el.classList.remove(...classesDuring.filter(i => !originalClasses.includes(i)));
  427. el.classList.remove(...classesEnd.filter(i => !originalClasses.includes(i)));
  428. }
  429. };
  430. transition(el, stages, type, reject);
  431. }
  432. function transition(el, stages, type, reject) {
  433. const finish = once(() => {
  434. stages.hide(); // Adding an "isConnected" check, in case the callback
  435. // removed the element from the DOM.
  436. if (el.isConnected) {
  437. stages.cleanup();
  438. }
  439. delete el.__x_transition;
  440. });
  441. el.__x_transition = {
  442. // Set transition type so we can avoid clearing transition if the direction is the same
  443. type: type,
  444. // create a callback for the last stages of the transition so we can call it
  445. // from different point and early terminate it. Once will ensure that function
  446. // is only called one time.
  447. cancel: once(() => {
  448. reject(TRANSITION_CANCELLED);
  449. finish();
  450. }),
  451. finish,
  452. // This store the next animation frame so we can cancel it
  453. nextFrame: null
  454. };
  455. stages.start();
  456. stages.during();
  457. el.__x_transition.nextFrame = requestAnimationFrame(() => {
  458. // Note: Safari's transitionDuration property will list out comma separated transition durations
  459. // for every single transition property. Let's grab the first one and call it a day.
  460. let duration = Number(getComputedStyle(el).transitionDuration.replace(/,.*/, '').replace('s', '')) * 1000;
  461. if (duration === 0) {
  462. duration = Number(getComputedStyle(el).animationDuration.replace('s', '')) * 1000;
  463. }
  464. stages.show();
  465. el.__x_transition.nextFrame = requestAnimationFrame(() => {
  466. stages.end();
  467. setTimeout(el.__x_transition.finish, duration);
  468. });
  469. });
  470. }
  471. function isNumeric(subject) {
  472. return !Array.isArray(subject) && !isNaN(subject);
  473. } // Thanks @vuejs
  474. // https://github.com/vuejs/vue/blob/4de4649d9637262a9b007720b59f80ac72a5620c/src/shared/util.js
  475. function once(callback) {
  476. let called = false;
  477. return function () {
  478. if (!called) {
  479. called = true;
  480. callback.apply(this, arguments);
  481. }
  482. };
  483. }
  484. function handleForDirective(component, templateEl, expression, initialUpdate, extraVars) {
  485. warnIfMalformedTemplate(templateEl, 'x-for');
  486. let iteratorNames = typeof expression === 'function' ? parseForExpression(component.evaluateReturnExpression(templateEl, expression)) : parseForExpression(expression);
  487. let items = evaluateItemsAndReturnEmptyIfXIfIsPresentAndFalseOnElement(component, templateEl, iteratorNames, extraVars); // As we walk the array, we'll also walk the DOM (updating/creating as we go).
  488. let currentEl = templateEl;
  489. items.forEach((item, index) => {
  490. let iterationScopeVariables = getIterationScopeVariables(iteratorNames, item, index, items, extraVars());
  491. let currentKey = generateKeyForIteration(component, templateEl, index, iterationScopeVariables);
  492. let nextEl = lookAheadForMatchingKeyedElementAndMoveItIfFound(currentEl.nextElementSibling, currentKey); // If we haven't found a matching key, insert the element at the current position.
  493. if (!nextEl) {
  494. nextEl = addElementInLoopAfterCurrentEl(templateEl, currentEl); // And transition it in if it's not the first page load.
  495. transitionIn(nextEl, () => {}, () => {}, component, initialUpdate);
  496. nextEl.__x_for = iterationScopeVariables;
  497. component.initializeElements(nextEl, () => nextEl.__x_for); // Otherwise update the element we found.
  498. } else {
  499. // Temporarily remove the key indicator to allow the normal "updateElements" to work.
  500. delete nextEl.__x_for_key;
  501. nextEl.__x_for = iterationScopeVariables;
  502. component.updateElements(nextEl, () => nextEl.__x_for);
  503. }
  504. currentEl = nextEl;
  505. currentEl.__x_for_key = currentKey;
  506. });
  507. removeAnyLeftOverElementsFromPreviousUpdate(currentEl, component);
  508. } // This was taken from VueJS 2.* core. Thanks Vue!
  509. function parseForExpression(expression) {
  510. let forIteratorRE = /,([^,\}\]]*)(?:,([^,\}\]]*))?$/;
  511. let stripParensRE = /^\(|\)$/g;
  512. let forAliasRE = /([\s\S]*?)\s+(?:in|of)\s+([\s\S]*)/;
  513. let inMatch = String(expression).match(forAliasRE);
  514. if (!inMatch) return;
  515. let res = {};
  516. res.items = inMatch[2].trim();
  517. let item = inMatch[1].trim().replace(stripParensRE, '');
  518. let iteratorMatch = item.match(forIteratorRE);
  519. if (iteratorMatch) {
  520. res.item = item.replace(forIteratorRE, '').trim();
  521. res.index = iteratorMatch[1].trim();
  522. if (iteratorMatch[2]) {
  523. res.collection = iteratorMatch[2].trim();
  524. }
  525. } else {
  526. res.item = item;
  527. }
  528. return res;
  529. }
  530. function getIterationScopeVariables(iteratorNames, item, index, items, extraVars) {
  531. // We must create a new object, so each iteration has a new scope
  532. let scopeVariables = extraVars ? _objectSpread2({}, extraVars) : {};
  533. scopeVariables[iteratorNames.item] = item;
  534. if (iteratorNames.index) scopeVariables[iteratorNames.index] = index;
  535. if (iteratorNames.collection) scopeVariables[iteratorNames.collection] = items;
  536. return scopeVariables;
  537. }
  538. function generateKeyForIteration(component, el, index, iterationScopeVariables) {
  539. 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.
  540. if (!bindKeyAttribute) return index;
  541. return component.evaluateReturnExpression(el, bindKeyAttribute.expression, () => iterationScopeVariables);
  542. }
  543. function evaluateItemsAndReturnEmptyIfXIfIsPresentAndFalseOnElement(component, el, iteratorNames, extraVars) {
  544. let ifAttribute = getXAttrs(el, component, 'if')[0];
  545. if (ifAttribute && !component.evaluateReturnExpression(el, ifAttribute.expression)) {
  546. return [];
  547. }
  548. let items = component.evaluateReturnExpression(el, iteratorNames.items, extraVars); // This adds support for the `i in n` syntax.
  549. if (isNumeric(items) && items >= 0) {
  550. items = Array.from(Array(items).keys(), i => i + 1);
  551. }
  552. return items;
  553. }
  554. function addElementInLoopAfterCurrentEl(templateEl, currentEl) {
  555. let clone = document.importNode(templateEl.content, true);
  556. currentEl.parentElement.insertBefore(clone, currentEl.nextElementSibling);
  557. return currentEl.nextElementSibling;
  558. }
  559. function lookAheadForMatchingKeyedElementAndMoveItIfFound(nextEl, currentKey) {
  560. if (!nextEl) return; // If we are already past the x-for generated elements, we don't need to look ahead.
  561. if (nextEl.__x_for_key === undefined) return; // If the the key's DO match, no need to look ahead.
  562. if (nextEl.__x_for_key === currentKey) return nextEl; // If they don't, we'll look ahead for a match.
  563. // If we find it, we'll move it to the current position in the loop.
  564. let tmpNextEl = nextEl;
  565. while (tmpNextEl) {
  566. if (tmpNextEl.__x_for_key === currentKey) {
  567. return tmpNextEl.parentElement.insertBefore(tmpNextEl, nextEl);
  568. }
  569. tmpNextEl = tmpNextEl.nextElementSibling && tmpNextEl.nextElementSibling.__x_for_key !== undefined ? tmpNextEl.nextElementSibling : false;
  570. }
  571. }
  572. function removeAnyLeftOverElementsFromPreviousUpdate(currentEl, component) {
  573. var nextElementFromOldLoop = currentEl.nextElementSibling && currentEl.nextElementSibling.__x_for_key !== undefined ? currentEl.nextElementSibling : false;
  574. while (nextElementFromOldLoop) {
  575. let nextElementFromOldLoopImmutable = nextElementFromOldLoop;
  576. let nextSibling = nextElementFromOldLoop.nextElementSibling;
  577. transitionOut(nextElementFromOldLoop, () => {
  578. nextElementFromOldLoopImmutable.remove();
  579. }, () => {}, component);
  580. nextElementFromOldLoop = nextSibling && nextSibling.__x_for_key !== undefined ? nextSibling : false;
  581. }
  582. }
  583. function handleAttributeBindingDirective(component, el, attrName, expression, extraVars, attrType, modifiers) {
  584. var value = component.evaluateReturnExpression(el, expression, extraVars);
  585. if (attrName === 'value') {
  586. if (Alpine.ignoreFocusedForValueBinding && document.activeElement.isSameNode(el)) return; // If nested model key is undefined, set the default value to empty string.
  587. if (value === undefined && String(expression).match(/\./)) {
  588. value = '';
  589. }
  590. if (el.type === 'radio') {
  591. // Set radio value from x-bind:value, if no "value" attribute exists.
  592. // If there are any initial state values, radio will have a correct
  593. // "checked" value since x-bind:value is processed before x-model.
  594. if (el.attributes.value === undefined && attrType === 'bind') {
  595. el.value = value;
  596. } else if (attrType !== 'bind') {
  597. el.checked = checkedAttrLooseCompare(el.value, value);
  598. }
  599. } else if (el.type === 'checkbox') {
  600. // If we are explicitly binding a string to the :value, set the string,
  601. // If the value is a boolean, leave it alone, it will be set to "on"
  602. // automatically.
  603. if (typeof value !== 'boolean' && ![null, undefined].includes(value) && attrType === 'bind') {
  604. el.value = String(value);
  605. } else if (attrType !== 'bind') {
  606. if (Array.isArray(value)) {
  607. // I'm purposely not using Array.includes here because it's
  608. // strict, and because of Numeric/String mis-casting, I
  609. // want the "includes" to be "fuzzy".
  610. el.checked = value.some(val => checkedAttrLooseCompare(val, el.value));
  611. } else {
  612. el.checked = !!value;
  613. }
  614. }
  615. } else if (el.tagName === 'SELECT') {
  616. updateSelect(el, value);
  617. } else {
  618. if (el.value === value) return;
  619. el.value = value;
  620. }
  621. } else if (attrName === 'class') {
  622. if (Array.isArray(value)) {
  623. const originalClasses = el.__x_original_classes || [];
  624. el.setAttribute('class', arrayUnique(originalClasses.concat(value)).join(' '));
  625. } else if (typeof value === 'object') {
  626. // Sorting the keys / class names by their boolean value will ensure that
  627. // anything that evaluates to `false` and needs to remove classes is run first.
  628. const keysSortedByBooleanValue = Object.keys(value).sort((a, b) => value[a] - value[b]);
  629. keysSortedByBooleanValue.forEach(classNames => {
  630. if (value[classNames]) {
  631. convertClassStringToArray(classNames).forEach(className => el.classList.add(className));
  632. } else {
  633. convertClassStringToArray(classNames).forEach(className => el.classList.remove(className));
  634. }
  635. });
  636. } else {
  637. const originalClasses = el.__x_original_classes || [];
  638. const newClasses = value ? convertClassStringToArray(value) : [];
  639. el.setAttribute('class', arrayUnique(originalClasses.concat(newClasses)).join(' '));
  640. }
  641. } else {
  642. attrName = modifiers.includes('camel') ? camelCase(attrName) : attrName; // If an attribute's bound value is null, undefined or false, remove the attribute
  643. if ([null, undefined, false].includes(value)) {
  644. el.removeAttribute(attrName);
  645. } else {
  646. isBooleanAttr(attrName) ? setIfChanged(el, attrName, attrName) : setIfChanged(el, attrName, value);
  647. }
  648. }
  649. }
  650. function setIfChanged(el, attrName, value) {
  651. if (el.getAttribute(attrName) != value) {
  652. el.setAttribute(attrName, value);
  653. }
  654. }
  655. function updateSelect(el, value) {
  656. const arrayWrappedValue = [].concat(value).map(value => {
  657. return value + '';
  658. });
  659. Array.from(el.options).forEach(option => {
  660. option.selected = arrayWrappedValue.includes(option.value || option.text);
  661. });
  662. }
  663. function handleTextDirective(el, output, expression) {
  664. // If nested model key is undefined, set the default value to empty string.
  665. if (output === undefined && String(expression).match(/\./)) {
  666. output = '';
  667. }
  668. el.textContent = output;
  669. }
  670. function handleHtmlDirective(component, el, expression, extraVars) {
  671. el.innerHTML = component.evaluateReturnExpression(el, expression, extraVars);
  672. }
  673. function handleShowDirective(component, el, value, modifiers, initialUpdate = false) {
  674. const hide = () => {
  675. el.style.display = 'none';
  676. el.__x_is_shown = false;
  677. };
  678. const show = () => {
  679. if (el.style.length === 1 && el.style.display === 'none') {
  680. el.removeAttribute('style');
  681. } else {
  682. el.style.removeProperty('display');
  683. }
  684. el.__x_is_shown = true;
  685. };
  686. if (initialUpdate === true) {
  687. if (value) {
  688. show();
  689. } else {
  690. hide();
  691. }
  692. return;
  693. }
  694. const handle = (resolve, reject) => {
  695. if (value) {
  696. if (el.style.display === 'none' || el.__x_transition) {
  697. transitionIn(el, () => {
  698. show();
  699. }, reject, component);
  700. }
  701. resolve(() => {});
  702. } else {
  703. if (el.style.display !== 'none') {
  704. transitionOut(el, () => {
  705. resolve(() => {
  706. hide();
  707. });
  708. }, reject, component);
  709. } else {
  710. resolve(() => {});
  711. }
  712. }
  713. }; // The working of x-show is a bit complex because we need to
  714. // wait for any child transitions to finish before hiding
  715. // some element. Also, this has to be done recursively.
  716. // If x-show.immediate, foregoe the waiting.
  717. if (modifiers.includes('immediate')) {
  718. handle(finish => finish(), () => {});
  719. return;
  720. } // x-show is encountered during a DOM tree walk. If an element
  721. // we encounter is NOT a child of another x-show element we
  722. // can execute the previous x-show stack (if one exists).
  723. if (component.showDirectiveLastElement && !component.showDirectiveLastElement.contains(el)) {
  724. component.executeAndClearRemainingShowDirectiveStack();
  725. }
  726. component.showDirectiveStack.push(handle);
  727. component.showDirectiveLastElement = el;
  728. }
  729. function handleIfDirective(component, el, expressionResult, initialUpdate, extraVars) {
  730. warnIfMalformedTemplate(el, 'x-if');
  731. const elementHasAlreadyBeenAdded = el.nextElementSibling && el.nextElementSibling.__x_inserted_me === true;
  732. if (expressionResult && (!elementHasAlreadyBeenAdded || el.__x_transition)) {
  733. const clone = document.importNode(el.content, true);
  734. el.parentElement.insertBefore(clone, el.nextElementSibling);
  735. transitionIn(el.nextElementSibling, () => {}, () => {}, component, initialUpdate);
  736. component.initializeElements(el.nextElementSibling, extraVars);
  737. el.nextElementSibling.__x_inserted_me = true;
  738. } else if (!expressionResult && elementHasAlreadyBeenAdded) {
  739. transitionOut(el.nextElementSibling, () => {
  740. el.nextElementSibling.remove();
  741. }, () => {}, component, initialUpdate);
  742. }
  743. }
  744. function registerListener(component, el, event, modifiers, expression, extraVars = {}) {
  745. const options = {
  746. passive: modifiers.includes('passive')
  747. };
  748. if (modifiers.includes('camel')) {
  749. event = camelCase(event);
  750. }
  751. let handler, listenerTarget;
  752. if (modifiers.includes('away')) {
  753. listenerTarget = document;
  754. handler = e => {
  755. // Don't do anything if the click came from the element or within it.
  756. if (el.contains(e.target)) return; // Don't do anything if this element isn't currently visible.
  757. if (el.offsetWidth < 1 && el.offsetHeight < 1) return; // Now that we are sure the element is visible, AND the click
  758. // is from outside it, let's run the expression.
  759. runListenerHandler(component, expression, e, extraVars);
  760. if (modifiers.includes('once')) {
  761. document.removeEventListener(event, handler, options);
  762. }
  763. };
  764. } else {
  765. listenerTarget = modifiers.includes('window') ? window : modifiers.includes('document') ? document : el;
  766. handler = e => {
  767. // Remove this global event handler if the element that declared it
  768. // has been removed. It's now stale.
  769. if (listenerTarget === window || listenerTarget === document) {
  770. if (!document.body.contains(el)) {
  771. listenerTarget.removeEventListener(event, handler, options);
  772. return;
  773. }
  774. }
  775. if (isKeyEvent(event)) {
  776. if (isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers)) {
  777. return;
  778. }
  779. }
  780. if (modifiers.includes('prevent')) e.preventDefault();
  781. if (modifiers.includes('stop')) e.stopPropagation(); // If the .self modifier isn't present, or if it is present and
  782. // the target element matches the element we are registering the
  783. // event on, run the handler
  784. if (!modifiers.includes('self') || e.target === el) {
  785. const returnValue = runListenerHandler(component, expression, e, extraVars);
  786. returnValue.then(value => {
  787. if (value === false) {
  788. e.preventDefault();
  789. } else {
  790. if (modifiers.includes('once')) {
  791. listenerTarget.removeEventListener(event, handler, options);
  792. }
  793. }
  794. });
  795. }
  796. };
  797. }
  798. if (modifiers.includes('debounce')) {
  799. let nextModifier = modifiers[modifiers.indexOf('debounce') + 1] || 'invalid-wait';
  800. let wait = isNumeric(nextModifier.split('ms')[0]) ? Number(nextModifier.split('ms')[0]) : 250;
  801. handler = debounce(handler, wait);
  802. }
  803. listenerTarget.addEventListener(event, handler, options);
  804. }
  805. function runListenerHandler(component, expression, e, extraVars) {
  806. return component.evaluateCommandExpression(e.target, expression, () => {
  807. return _objectSpread2(_objectSpread2({}, extraVars()), {}, {
  808. '$event': e
  809. });
  810. });
  811. }
  812. function isKeyEvent(event) {
  813. return ['keydown', 'keyup'].includes(event);
  814. }
  815. function isListeningForASpecificKeyThatHasntBeenPressed(e, modifiers) {
  816. let keyModifiers = modifiers.filter(i => {
  817. return !['window', 'document', 'prevent', 'stop'].includes(i);
  818. });
  819. if (keyModifiers.includes('debounce')) {
  820. let debounceIndex = keyModifiers.indexOf('debounce');
  821. keyModifiers.splice(debounceIndex, isNumeric((keyModifiers[debounceIndex + 1] || 'invalid-wait').split('ms')[0]) ? 2 : 1);
  822. } // If no modifier is specified, we'll call it a press.
  823. if (keyModifiers.length === 0) return false; // If one is passed, AND it matches the key pressed, we'll call it a press.
  824. if (keyModifiers.length === 1 && keyModifiers[0] === keyToModifier(e.key)) return false; // The user is listening for key combinations.
  825. const systemKeyModifiers = ['ctrl', 'shift', 'alt', 'meta', 'cmd', 'super'];
  826. const selectedSystemKeyModifiers = systemKeyModifiers.filter(modifier => keyModifiers.includes(modifier));
  827. keyModifiers = keyModifiers.filter(i => !selectedSystemKeyModifiers.includes(i));
  828. if (selectedSystemKeyModifiers.length > 0) {
  829. const activelyPressedKeyModifiers = selectedSystemKeyModifiers.filter(modifier => {
  830. // Alias "cmd" and "super" to "meta"
  831. if (modifier === 'cmd' || modifier === 'super') modifier = 'meta';
  832. return e[`${modifier}Key`];
  833. }); // If all the modifiers selected are pressed, ...
  834. if (activelyPressedKeyModifiers.length === selectedSystemKeyModifiers.length) {
  835. // AND the remaining key is pressed as well. It's a press.
  836. if (keyModifiers[0] === keyToModifier(e.key)) return false;
  837. }
  838. } // We'll call it NOT a valid keypress.
  839. return true;
  840. }
  841. function keyToModifier(key) {
  842. switch (key) {
  843. case '/':
  844. return 'slash';
  845. case ' ':
  846. case 'Spacebar':
  847. return 'space';
  848. default:
  849. return key && kebabCase(key);
  850. }
  851. }
  852. function registerModelListener(component, el, modifiers, expression, extraVars) {
  853. // If the element we are binding to is a select, a radio, or checkbox
  854. // we'll listen for the change event instead of the "input" event.
  855. var event = el.tagName.toLowerCase() === 'select' || ['checkbox', 'radio'].includes(el.type) || modifiers.includes('lazy') ? 'change' : 'input';
  856. const listenerExpression = `${expression} = rightSideOfExpression($event, ${expression})`;
  857. registerListener(component, el, event, modifiers, listenerExpression, () => {
  858. return _objectSpread2(_objectSpread2({}, extraVars()), {}, {
  859. rightSideOfExpression: generateModelAssignmentFunction(el, modifiers, expression)
  860. });
  861. });
  862. }
  863. function generateModelAssignmentFunction(el, modifiers, expression) {
  864. if (el.type === 'radio') {
  865. // Radio buttons only work properly when they share a name attribute.
  866. // People might assume we take care of that for them, because
  867. // they already set a shared "x-model" attribute.
  868. if (!el.hasAttribute('name')) el.setAttribute('name', expression);
  869. }
  870. return (event, currentValue) => {
  871. // Check for event.detail due to an issue where IE11 handles other events as a CustomEvent.
  872. if (event instanceof CustomEvent && event.detail) {
  873. return event.detail;
  874. } else if (el.type === 'checkbox') {
  875. // If the data we are binding to is an array, toggle its value inside the array.
  876. if (Array.isArray(currentValue)) {
  877. const newValue = modifiers.includes('number') ? safeParseNumber(event.target.value) : event.target.value;
  878. return event.target.checked ? currentValue.concat([newValue]) : currentValue.filter(el => !checkedAttrLooseCompare(el, newValue));
  879. } else {
  880. return event.target.checked;
  881. }
  882. } else if (el.tagName.toLowerCase() === 'select' && el.multiple) {
  883. return modifiers.includes('number') ? Array.from(event.target.selectedOptions).map(option => {
  884. const rawValue = option.value || option.text;
  885. return safeParseNumber(rawValue);
  886. }) : Array.from(event.target.selectedOptions).map(option => {
  887. return option.value || option.text;
  888. });
  889. } else {
  890. const rawValue = event.target.value;
  891. return modifiers.includes('number') ? safeParseNumber(rawValue) : modifiers.includes('trim') ? rawValue.trim() : rawValue;
  892. }
  893. };
  894. }
  895. function safeParseNumber(rawValue) {
  896. const number = rawValue ? parseFloat(rawValue) : null;
  897. return isNumeric(number) ? number : rawValue;
  898. }
  899. /**
  900. * Copyright (C) 2017 salesforce.com, inc.
  901. */
  902. const { isArray } = Array;
  903. const { getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, defineProperties: ObjectDefineProperties, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
  904. const { push: ArrayPush, concat: ArrayConcat, map: ArrayMap, } = Array.prototype;
  905. function isUndefined(obj) {
  906. return obj === undefined;
  907. }
  908. function isFunction(obj) {
  909. return typeof obj === 'function';
  910. }
  911. function isObject(obj) {
  912. return typeof obj === 'object';
  913. }
  914. const proxyToValueMap = new WeakMap();
  915. function registerProxy(proxy, value) {
  916. proxyToValueMap.set(proxy, value);
  917. }
  918. const unwrap = (replicaOrAny) => proxyToValueMap.get(replicaOrAny) || replicaOrAny;
  919. function wrapValue(membrane, value) {
  920. return membrane.valueIsObservable(value) ? membrane.getProxy(value) : value;
  921. }
  922. /**
  923. * Unwrap property descriptors will set value on original descriptor
  924. * We only need to unwrap if value is specified
  925. * @param descriptor external descrpitor provided to define new property on original value
  926. */
  927. function unwrapDescriptor(descriptor) {
  928. if (hasOwnProperty.call(descriptor, 'value')) {
  929. descriptor.value = unwrap(descriptor.value);
  930. }
  931. return descriptor;
  932. }
  933. function lockShadowTarget(membrane, shadowTarget, originalTarget) {
  934. const targetKeys = ArrayConcat.call(getOwnPropertyNames(originalTarget), getOwnPropertySymbols(originalTarget));
  935. targetKeys.forEach((key) => {
  936. let descriptor = getOwnPropertyDescriptor(originalTarget, key);
  937. // We do not need to wrap the descriptor if configurable
  938. // Because we can deal with wrapping it when user goes through
  939. // Get own property descriptor. There is also a chance that this descriptor
  940. // could change sometime in the future, so we can defer wrapping
  941. // until we need to
  942. if (!descriptor.configurable) {
  943. descriptor = wrapDescriptor(membrane, descriptor, wrapValue);
  944. }
  945. ObjectDefineProperty(shadowTarget, key, descriptor);
  946. });
  947. preventExtensions(shadowTarget);
  948. }
  949. class ReactiveProxyHandler {
  950. constructor(membrane, value) {
  951. this.originalTarget = value;
  952. this.membrane = membrane;
  953. }
  954. get(shadowTarget, key) {
  955. const { originalTarget, membrane } = this;
  956. const value = originalTarget[key];
  957. const { valueObserved } = membrane;
  958. valueObserved(originalTarget, key);
  959. return membrane.getProxy(value);
  960. }
  961. set(shadowTarget, key, value) {
  962. const { originalTarget, membrane: { valueMutated } } = this;
  963. const oldValue = originalTarget[key];
  964. if (oldValue !== value) {
  965. originalTarget[key] = value;
  966. valueMutated(originalTarget, key);
  967. }
  968. else if (key === 'length' && isArray(originalTarget)) {
  969. // fix for issue #236: push will add the new index, and by the time length
  970. // is updated, the internal length is already equal to the new length value
  971. // therefore, the oldValue is equal to the value. This is the forking logic
  972. // to support this use case.
  973. valueMutated(originalTarget, key);
  974. }
  975. return true;
  976. }
  977. deleteProperty(shadowTarget, key) {
  978. const { originalTarget, membrane: { valueMutated } } = this;
  979. delete originalTarget[key];
  980. valueMutated(originalTarget, key);
  981. return true;
  982. }
  983. apply(shadowTarget, thisArg, argArray) {
  984. /* No op */
  985. }
  986. construct(target, argArray, newTarget) {
  987. /* No op */
  988. }
  989. has(shadowTarget, key) {
  990. const { originalTarget, membrane: { valueObserved } } = this;
  991. valueObserved(originalTarget, key);
  992. return key in originalTarget;
  993. }
  994. ownKeys(shadowTarget) {
  995. const { originalTarget } = this;
  996. return ArrayConcat.call(getOwnPropertyNames(originalTarget), getOwnPropertySymbols(originalTarget));
  997. }
  998. isExtensible(shadowTarget) {
  999. const shadowIsExtensible = isExtensible(shadowTarget);
  1000. if (!shadowIsExtensible) {
  1001. return shadowIsExtensible;
  1002. }
  1003. const { originalTarget, membrane } = this;
  1004. const targetIsExtensible = isExtensible(originalTarget);
  1005. if (!targetIsExtensible) {
  1006. lockShadowTarget(membrane, shadowTarget, originalTarget);
  1007. }
  1008. return targetIsExtensible;
  1009. }
  1010. setPrototypeOf(shadowTarget, prototype) {
  1011. }
  1012. getPrototypeOf(shadowTarget) {
  1013. const { originalTarget } = this;
  1014. return getPrototypeOf(originalTarget);
  1015. }
  1016. getOwnPropertyDescriptor(shadowTarget, key) {
  1017. const { originalTarget, membrane } = this;
  1018. const { valueObserved } = this.membrane;
  1019. // keys looked up via hasOwnProperty need to be reactive
  1020. valueObserved(originalTarget, key);
  1021. let desc = getOwnPropertyDescriptor(originalTarget, key);
  1022. if (isUndefined(desc)) {
  1023. return desc;
  1024. }
  1025. const shadowDescriptor = getOwnPropertyDescriptor(shadowTarget, key);
  1026. if (!isUndefined(shadowDescriptor)) {
  1027. return shadowDescriptor;
  1028. }
  1029. // Note: by accessing the descriptor, the key is marked as observed
  1030. // but access to the value, setter or getter (if available) cannot observe
  1031. // mutations, just like regular methods, in which case we just do nothing.
  1032. desc = wrapDescriptor(membrane, desc, wrapValue);
  1033. if (!desc.configurable) {
  1034. // If descriptor from original target is not configurable,
  1035. // We must copy the wrapped descriptor over to the shadow target.
  1036. // Otherwise, proxy will throw an invariant error.
  1037. // This is our last chance to lock the value.
  1038. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/getOwnPropertyDescriptor#Invariants
  1039. ObjectDefineProperty(shadowTarget, key, desc);
  1040. }
  1041. return desc;
  1042. }
  1043. preventExtensions(shadowTarget) {
  1044. const { originalTarget, membrane } = this;
  1045. lockShadowTarget(membrane, shadowTarget, originalTarget);
  1046. preventExtensions(originalTarget);
  1047. return true;
  1048. }
  1049. defineProperty(shadowTarget, key, descriptor) {
  1050. const { originalTarget, membrane } = this;
  1051. const { valueMutated } = membrane;
  1052. const { configurable } = descriptor;
  1053. // We have to check for value in descriptor
  1054. // because Object.freeze(proxy) calls this method
  1055. // with only { configurable: false, writeable: false }
  1056. // Additionally, method will only be called with writeable:false
  1057. // if the descriptor has a value, as opposed to getter/setter
  1058. // So we can just check if writable is present and then see if
  1059. // value is present. This eliminates getter and setter descriptors
  1060. if (hasOwnProperty.call(descriptor, 'writable') && !hasOwnProperty.call(descriptor, 'value')) {
  1061. const originalDescriptor = getOwnPropertyDescriptor(originalTarget, key);
  1062. descriptor.value = originalDescriptor.value;
  1063. }
  1064. ObjectDefineProperty(originalTarget, key, unwrapDescriptor(descriptor));
  1065. if (configurable === false) {
  1066. ObjectDefineProperty(shadowTarget, key, wrapDescriptor(membrane, descriptor, wrapValue));
  1067. }
  1068. valueMutated(originalTarget, key);
  1069. return true;
  1070. }
  1071. }
  1072. function wrapReadOnlyValue(membrane, value) {
  1073. return membrane.valueIsObservable(value) ? membrane.getReadOnlyProxy(value) : value;
  1074. }
  1075. class ReadOnlyHandler {
  1076. constructor(membrane, value) {
  1077. this.originalTarget = value;
  1078. this.membrane = membrane;
  1079. }
  1080. get(shadowTarget, key) {
  1081. const { membrane, originalTarget } = this;
  1082. const value = originalTarget[key];
  1083. const { valueObserved } = membrane;
  1084. valueObserved(originalTarget, key);
  1085. return membrane.getReadOnlyProxy(value);
  1086. }
  1087. set(shadowTarget, key, value) {
  1088. return false;
  1089. }
  1090. deleteProperty(shadowTarget, key) {
  1091. return false;
  1092. }
  1093. apply(shadowTarget, thisArg, argArray) {
  1094. /* No op */
  1095. }
  1096. construct(target, argArray, newTarget) {
  1097. /* No op */
  1098. }
  1099. has(shadowTarget, key) {
  1100. const { originalTarget, membrane: { valueObserved } } = this;
  1101. valueObserved(originalTarget, key);
  1102. return key in originalTarget;
  1103. }
  1104. ownKeys(shadowTarget) {
  1105. const { originalTarget } = this;
  1106. return ArrayConcat.call(getOwnPropertyNames(originalTarget), getOwnPropertySymbols(originalTarget));
  1107. }
  1108. setPrototypeOf(shadowTarget, prototype) {
  1109. }
  1110. getOwnPropertyDescriptor(shadowTarget, key) {
  1111. const { originalTarget, membrane } = this;
  1112. const { valueObserved } = membrane;
  1113. // keys looked up via hasOwnProperty need to be reactive
  1114. valueObserved(originalTarget, key);
  1115. let desc = getOwnPropertyDescriptor(originalTarget, key);
  1116. if (isUndefined(desc)) {
  1117. return desc;
  1118. }
  1119. const shadowDescriptor = getOwnPropertyDescriptor(shadowTarget, key);
  1120. if (!isUndefined(shadowDescriptor)) {
  1121. return shadowDescriptor;
  1122. }
  1123. // Note: by accessing the descriptor, the key is marked as observed
  1124. // but access to the value or getter (if available) cannot be observed,
  1125. // just like regular methods, in which case we just do nothing.
  1126. desc = wrapDescriptor(membrane, desc, wrapReadOnlyValue);
  1127. if (hasOwnProperty.call(desc, 'set')) {
  1128. desc.set = undefined; // readOnly membrane does not allow setters
  1129. }
  1130. if (!desc.configurable) {
  1131. // If descriptor from original target is not configurable,
  1132. // We must copy the wrapped descriptor over to the shadow target.
  1133. // Otherwise, proxy will throw an invariant error.
  1134. // This is our last chance to lock the value.
  1135. // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Proxy/handler/getOwnPropertyDescriptor#Invariants
  1136. ObjectDefineProperty(shadowTarget, key, desc);
  1137. }
  1138. return desc;
  1139. }
  1140. preventExtensions(shadowTarget) {
  1141. return false;
  1142. }
  1143. defineProperty(shadowTarget, key, descriptor) {
  1144. return false;
  1145. }
  1146. }
  1147. function createShadowTarget(value) {
  1148. let shadowTarget = undefined;
  1149. if (isArray(value)) {
  1150. shadowTarget = [];
  1151. }
  1152. else if (isObject(value)) {
  1153. shadowTarget = {};
  1154. }
  1155. return shadowTarget;
  1156. }
  1157. const ObjectDotPrototype = Object.prototype;
  1158. function defaultValueIsObservable(value) {
  1159. // intentionally checking for null
  1160. if (value === null) {
  1161. return false;
  1162. }
  1163. // treat all non-object types, including undefined, as non-observable values
  1164. if (typeof value !== 'object') {
  1165. return false;
  1166. }
  1167. if (isArray(value)) {
  1168. return true;
  1169. }
  1170. const proto = getPrototypeOf(value);
  1171. return (proto === ObjectDotPrototype || proto === null || getPrototypeOf(proto) === null);
  1172. }
  1173. const defaultValueObserved = (obj, key) => {
  1174. /* do nothing */
  1175. };
  1176. const defaultValueMutated = (obj, key) => {
  1177. /* do nothing */
  1178. };
  1179. const defaultValueDistortion = (value) => value;
  1180. function wrapDescriptor(membrane, descriptor, getValue) {
  1181. const { set, get } = descriptor;
  1182. if (hasOwnProperty.call(descriptor, 'value')) {
  1183. descriptor.value = getValue(membrane, descriptor.value);
  1184. }
  1185. else {
  1186. if (!isUndefined(get)) {
  1187. descriptor.get = function () {
  1188. // invoking the original getter with the original target
  1189. return getValue(membrane, get.call(unwrap(this)));
  1190. };
  1191. }
  1192. if (!isUndefined(set)) {
  1193. descriptor.set = function (value) {
  1194. // At this point we don't have a clear indication of whether
  1195. // or not a valid mutation will occur, we don't have the key,
  1196. // and we are not sure why and how they are invoking this setter.
  1197. // Nevertheless we preserve the original semantics by invoking the
  1198. // original setter with the original target and the unwrapped value
  1199. set.call(unwrap(this), membrane.unwrapProxy(value));
  1200. };
  1201. }
  1202. }
  1203. return descriptor;
  1204. }
  1205. class ReactiveMembrane {
  1206. constructor(options) {
  1207. this.valueDistortion = defaultValueDistortion;
  1208. this.valueMutated = defaultValueMutated;
  1209. this.valueObserved = defaultValueObserved;
  1210. this.valueIsObservable = defaultValueIsObservable;
  1211. this.objectGraph = new WeakMap();
  1212. if (!isUndefined(options)) {
  1213. const { valueDistortion, valueMutated, valueObserved, valueIsObservable } = options;
  1214. this.valueDistortion = isFunction(valueDistortion) ? valueDistortion : defaultValueDistortion;
  1215. this.valueMutated = isFunction(valueMutated) ? valueMutated : defaultValueMutated;
  1216. this.valueObserved = isFunction(valueObserved) ? valueObserved : defaultValueObserved;
  1217. this.valueIsObservable = isFunction(valueIsObservable) ? valueIsObservable : defaultValueIsObservable;
  1218. }
  1219. }
  1220. getProxy(value) {
  1221. const unwrappedValue = unwrap(value);
  1222. const distorted = this.valueDistortion(unwrappedValue);
  1223. if (this.valueIsObservable(distorted)) {
  1224. const o = this.getReactiveState(unwrappedValue, distorted);
  1225. // when trying to extract the writable version of a readonly
  1226. // we return the readonly.
  1227. return o.readOnly === value ? value : o.reactive;
  1228. }
  1229. return distorted;
  1230. }
  1231. getReadOnlyProxy(value) {
  1232. value = unwrap(value);
  1233. const distorted = this.valueDistortion(value);
  1234. if (this.valueIsObservable(distorted)) {
  1235. return this.getReactiveState(value, distorted).readOnly;
  1236. }
  1237. return distorted;
  1238. }
  1239. unwrapProxy(p) {
  1240. return unwrap(p);
  1241. }
  1242. getReactiveState(value, distortedValue) {
  1243. const { objectGraph, } = this;
  1244. let reactiveState = objectGraph.get(distortedValue);
  1245. if (reactiveState) {
  1246. return reactiveState;
  1247. }
  1248. const membrane = this;
  1249. reactiveState = {
  1250. get reactive() {
  1251. const reactiveHandler = new ReactiveProxyHandler(membrane, distortedValue);
  1252. // caching the reactive proxy after the first time it is accessed
  1253. const proxy = new Proxy(createShadowTarget(distortedValue), reactiveHandler);
  1254. registerProxy(proxy, value);
  1255. ObjectDefineProperty(this, 'reactive', { value: proxy });
  1256. return proxy;
  1257. },
  1258. get readOnly() {
  1259. const readOnlyHandler = new ReadOnlyHandler(membrane, distortedValue);
  1260. // caching the readOnly proxy after the first time it is accessed
  1261. const proxy = new Proxy(createShadowTarget(distortedValue), readOnlyHandler);
  1262. registerProxy(proxy, value);
  1263. ObjectDefineProperty(this, 'readOnly', { value: proxy });
  1264. return proxy;
  1265. }
  1266. };
  1267. objectGraph.set(distortedValue, reactiveState);
  1268. return reactiveState;
  1269. }
  1270. }
  1271. /** version: 0.26.0 */
  1272. function wrap(data, mutationCallback) {
  1273. let membrane = new ReactiveMembrane({
  1274. valueMutated(target, key) {
  1275. mutationCallback(target, key);
  1276. }
  1277. });
  1278. return {
  1279. data: membrane.getProxy(data),
  1280. membrane: membrane
  1281. };
  1282. }
  1283. function unwrap$1(membrane, observable) {
  1284. let unwrappedData = membrane.unwrapProxy(observable);
  1285. let copy = {};
  1286. Object.keys(unwrappedData).forEach(key => {
  1287. if (['$el', '$refs', '$nextTick', '$watch'].includes(key)) return;
  1288. copy[key] = unwrappedData[key];
  1289. });
  1290. return copy;
  1291. }
  1292. class Component {
  1293. constructor(el, componentForClone = null) {
  1294. this.$el = el;
  1295. const dataAttr = this.$el.getAttribute('x-data');
  1296. const dataExpression = dataAttr === '' ? '{}' : dataAttr;
  1297. const initExpression = this.$el.getAttribute('x-init');
  1298. let dataExtras = {
  1299. $el: this.$el
  1300. };
  1301. let canonicalComponentElementReference = componentForClone ? componentForClone.$el : this.$el;
  1302. Object.entries(Alpine.magicProperties).forEach(([name, callback]) => {
  1303. Object.defineProperty(dataExtras, `$${name}`, {
  1304. get: function get() {
  1305. return callback(canonicalComponentElementReference);
  1306. }
  1307. });
  1308. });
  1309. this.unobservedData = componentForClone ? componentForClone.getUnobservedData() : saferEval(el, dataExpression, dataExtras);
  1310. // Construct a Proxy-based observable. This will be used to handle reactivity.
  1311. let {
  1312. membrane,
  1313. data
  1314. } = this.wrapDataInObservable(this.unobservedData);
  1315. this.$data = data;
  1316. this.membrane = membrane; // After making user-supplied data methods reactive, we can now add
  1317. // our magic properties to the original data for access.
  1318. this.unobservedData.$el = this.$el;
  1319. this.unobservedData.$refs = this.getRefsProxy();
  1320. this.nextTickStack = [];
  1321. this.unobservedData.$nextTick = callback => {
  1322. this.nextTickStack.push(callback);
  1323. };
  1324. this.watchers = {};
  1325. this.unobservedData.$watch = (property, callback) => {
  1326. if (!this.watchers[property]) this.watchers[property] = [];
  1327. this.watchers[property].push(callback);
  1328. };
  1329. /* MODERN-ONLY:START */
  1330. // We remove this piece of code from the legacy build.
  1331. // In IE11, we have already defined our helpers at this point.
  1332. // Register custom magic properties.
  1333. Object.entries(Alpine.magicProperties).forEach(([name, callback]) => {
  1334. Object.defineProperty(this.unobservedData, `$${name}`, {
  1335. get: function get() {
  1336. return callback(canonicalComponentElementReference, this.$el);
  1337. }
  1338. });
  1339. });
  1340. /* MODERN-ONLY:END */
  1341. this.showDirectiveStack = [];
  1342. this.showDirectiveLastElement;
  1343. componentForClone || Alpine.onBeforeComponentInitializeds.forEach(callback => callback(this));
  1344. var initReturnedCallback; // If x-init is present AND we aren't cloning (skip x-init on clone)
  1345. if (initExpression && !componentForClone) {
  1346. // We want to allow data manipulation, but not trigger DOM updates just yet.
  1347. // We haven't even initialized the elements with their Alpine bindings. I mean c'mon.
  1348. this.pauseReactivity = true;
  1349. initReturnedCallback = this.evaluateReturnExpression(this.$el, initExpression);
  1350. this.pauseReactivity = false;
  1351. } // Register all our listeners and set all our attribute bindings.
  1352. // If we're cloning a component, the third parameter ensures no duplicate
  1353. // event listeners are registered (the mutation observer will take care of them)
  1354. this.initializeElements(this.$el, () => {}, componentForClone); // Use mutation observer to detect new elements being added within this component at run-time.
  1355. // Alpine's just so darn flexible amirite?
  1356. this.listenForNewElementsToInitialize();
  1357. if (typeof initReturnedCallback === 'function') {
  1358. // Run the callback returned from the "x-init" hook to allow the user to do stuff after
  1359. // Alpine's got it's grubby little paws all over everything.
  1360. initReturnedCallback.call(this.$data);
  1361. }
  1362. componentForClone || setTimeout(() => {
  1363. Alpine.onComponentInitializeds.forEach(callback => callback(this));
  1364. }, 0);
  1365. }
  1366. getUnobservedData() {
  1367. return unwrap$1(this.membrane, this.$data);
  1368. }
  1369. wrapDataInObservable(data) {
  1370. var self = this;
  1371. let updateDom = debounce(function () {
  1372. self.updateElements(self.$el);
  1373. }, 0);
  1374. return wrap(data, (target, key) => {
  1375. if (self.watchers[key]) {
  1376. // If there's a watcher for this specific key, run it.
  1377. self.watchers[key].forEach(callback => callback(target[key]));
  1378. } else if (Array.isArray(target)) {
  1379. // Arrays are special cases, if any of the items change, we consider the array as mutated.
  1380. Object.keys(self.watchers).forEach(fullDotNotationKey => {
  1381. let dotNotationParts = fullDotNotationKey.split('.'); // Ignore length mutations since they would result in duplicate calls.
  1382. // For example, when calling push, we would get a mutation for the item's key
  1383. // and a second mutation for the length property.
  1384. if (key === 'length') return;
  1385. dotNotationParts.reduce((comparisonData, part) => {
  1386. if (Object.is(target, comparisonData[part])) {
  1387. self.watchers[fullDotNotationKey].forEach(callback => callback(target));
  1388. }
  1389. return comparisonData[part];
  1390. }, self.unobservedData);
  1391. });
  1392. } else {
  1393. // Let's walk through the watchers with "dot-notation" (foo.bar) and see
  1394. // if this mutation fits any of them.
  1395. Object.keys(self.watchers).filter(i => i.includes('.')).forEach(fullDotNotationKey => {
  1396. let dotNotationParts = fullDotNotationKey.split('.'); // If this dot-notation watcher's last "part" doesn't match the current
  1397. // key, then skip it early for performance reasons.
  1398. if (key !== dotNotationParts[dotNotationParts.length - 1]) return; // Now, walk through the dot-notation "parts" recursively to find
  1399. // a match, and call the watcher if one's found.
  1400. dotNotationParts.reduce((comparisonData, part) => {
  1401. if (Object.is(target, comparisonData)) {
  1402. // Run the watchers.
  1403. self.watchers[fullDotNotationKey].forEach(callback => callback(target[key]));
  1404. }
  1405. return comparisonData[part];
  1406. }, self.unobservedData);
  1407. });
  1408. } // Don't react to data changes for cases like the `x-created` hook.
  1409. if (self.pauseReactivity) return;
  1410. updateDom();
  1411. });
  1412. }
  1413. walkAndSkipNestedComponents(el, callback, initializeComponentCallback = () => {}) {
  1414. walk(el, el => {
  1415. // We've hit a component.
  1416. if (el.hasAttribute('x-data')) {
  1417. // If it's not the current one.
  1418. if (!el.isSameNode(this.$el)) {
  1419. // Initialize it if it's not.
  1420. if (!el.__x) initializeComponentCallback(el); // Now we'll let that sub-component deal with itself.
  1421. return false;
  1422. }
  1423. }
  1424. return callback(el);
  1425. });
  1426. }
  1427. initializeElements(rootEl, extraVars = () => {}, componentForClone = false) {
  1428. this.walkAndSkipNestedComponents(rootEl, el => {
  1429. // Don't touch spawns from for loop
  1430. if (el.__x_for_key !== undefined) return false; // Don't touch spawns from if directives
  1431. if (el.__x_inserted_me !== undefined) return false;
  1432. this.initializeElement(el, extraVars, componentForClone ? false : true);
  1433. }, el => {
  1434. if (!componentForClone) el.__x = new Component(el);
  1435. });
  1436. this.executeAndClearRemainingShowDirectiveStack();
  1437. this.executeAndClearNextTickStack(rootEl);
  1438. }
  1439. initializeElement(el, extraVars, shouldRegisterListeners = true) {
  1440. // To support class attribute merging, we have to know what the element's
  1441. // original class attribute looked like for reference.
  1442. if (el.hasAttribute('class') && getXAttrs(el, this).length > 0) {
  1443. el.__x_original_classes = convertClassStringToArray(el.getAttribute('class'));
  1444. }
  1445. shouldRegisterListeners && this.registerListeners(el, extraVars);
  1446. this.resolveBoundAttributes(el, true, extraVars);
  1447. }
  1448. updateElements(rootEl, extraVars = () => {}) {
  1449. this.walkAndSkipNestedComponents(rootEl, el => {
  1450. // Don't touch spawns from for loop (and check if the root is actually a for loop in a parent, don't skip it.)
  1451. if (el.__x_for_key !== undefined && !el.isSameNode(this.$el)) return false;
  1452. this.updateElement(el, extraVars);
  1453. }, el => {
  1454. el.__x = new Component(el);
  1455. });
  1456. this.executeAndClearRemainingShowDirectiveStack();
  1457. this.executeAndClearNextTickStack(rootEl);
  1458. }
  1459. executeAndClearNextTickStack(el) {
  1460. // Skip spawns from alpine directives
  1461. if (el === this.$el && this.nextTickStack.length > 0) {
  1462. // We run the tick stack after the next frame to allow any
  1463. // running transitions to pass the initial show stage.
  1464. requestAnimationFrame(() => {
  1465. while (this.nextTickStack.length > 0) {
  1466. this.nextTickStack.shift()();
  1467. }
  1468. });
  1469. }
  1470. }
  1471. executeAndClearRemainingShowDirectiveStack() {
  1472. // The goal here is to start all the x-show transitions
  1473. // and build a nested promise chain so that elements
  1474. // only hide when the children are finished hiding.
  1475. this.showDirectiveStack.reverse().map(handler => {
  1476. return new Promise((resolve, reject) => {
  1477. handler(resolve, reject);
  1478. });
  1479. }).reduce((promiseChain, promise) => {
  1480. return promiseChain.then(() => {
  1481. return promise.then(finishElement => {
  1482. finishElement();
  1483. });
  1484. });
  1485. }, Promise.resolve(() => {})).catch(e => {
  1486. if (e !== TRANSITION_CANCELLED) throw e;
  1487. }); // We've processed the handler stack. let's clear it.
  1488. this.showDirectiveStack = [];
  1489. this.showDirectiveLastElement = undefined;
  1490. }
  1491. updateElement(el, extraVars) {
  1492. this.resolveBoundAttributes(el, false, extraVars);
  1493. }
  1494. registerListeners(el, extraVars) {
  1495. getXAttrs(el, this).forEach(({
  1496. type,
  1497. value,
  1498. modifiers,
  1499. expression
  1500. }) => {
  1501. switch (type) {
  1502. case 'on':
  1503. registerListener(this, el, value, modifiers, expression, extraVars);
  1504. break;
  1505. case 'model':
  1506. registerModelListener(this, el, modifiers, expression, extraVars);
  1507. break;
  1508. }
  1509. });
  1510. }
  1511. resolveBoundAttributes(el, initialUpdate = false, extraVars) {
  1512. let attrs = getXAttrs(el, this);
  1513. attrs.forEach(({
  1514. type,
  1515. value,
  1516. modifiers,
  1517. expression
  1518. }) => {
  1519. switch (type) {
  1520. case 'model':
  1521. handleAttributeBindingDirective(this, el, 'value', expression, extraVars, type, modifiers);
  1522. break;
  1523. case 'bind':
  1524. // The :key binding on an x-for is special, ignore it.
  1525. if (el.tagName.toLowerCase() === 'template' && value === 'key') return;
  1526. handleAttributeBindingDirective(this, el, value, expression, extraVars, type, modifiers);
  1527. break;
  1528. case 'text':
  1529. var output = this.evaluateReturnExpression(el, expression, extraVars);
  1530. handleTextDirective(el, output, expression);
  1531. break;
  1532. case 'html':
  1533. handleHtmlDirective(this, el, expression, extraVars);
  1534. break;
  1535. case 'show':
  1536. var output = this.evaluateReturnExpression(el, expression, extraVars);
  1537. handleShowDirective(this, el, output, modifiers, initialUpdate);
  1538. break;
  1539. case 'if':
  1540. // If this element also has x-for on it, don't process x-if.
  1541. // We will let the "x-for" directive handle the "if"ing.
  1542. if (attrs.some(i => i.type === 'for')) return;
  1543. var output = this.evaluateReturnExpression(el, expression, extraVars);
  1544. handleIfDirective(this, el, output, initialUpdate, extraVars);
  1545. break;
  1546. case 'for':
  1547. handleForDirective(this, el, expression, initialUpdate, extraVars);
  1548. break;
  1549. case 'cloak':
  1550. el.removeAttribute('x-cloak');
  1551. break;
  1552. }
  1553. });
  1554. }
  1555. evaluateReturnExpression(el, expression, extraVars = () => {}) {
  1556. return saferEval(el, expression, this.$data, _objectSpread2(_objectSpread2({}, extraVars()), {}, {
  1557. $dispatch: this.getDispatchFunction(el)
  1558. }));
  1559. }
  1560. evaluateCommandExpression(el, expression, extraVars = () => {}) {
  1561. return saferEvalNoReturn(el, expression, this.$data, _objectSpread2(_objectSpread2({}, extraVars()), {}, {
  1562. $dispatch: this.getDispatchFunction(el)
  1563. }));
  1564. }
  1565. getDispatchFunction(el) {
  1566. return (event, detail = {}) => {
  1567. el.dispatchEvent(new CustomEvent(event, {
  1568. detail,
  1569. bubbles: true
  1570. }));
  1571. };
  1572. }
  1573. listenForNewElementsToInitialize() {
  1574. const targetNode = this.$el;
  1575. const observerOptions = {
  1576. childList: true,
  1577. attributes: true,
  1578. subtree: true
  1579. };
  1580. const observer = new MutationObserver(mutations => {
  1581. for (let i = 0; i < mutations.length; i++) {
  1582. // Filter out mutations triggered from child components.
  1583. const closestParentComponent = mutations[i].target.closest('[x-data]');
  1584. if (!(closestParentComponent && closestParentComponent.isSameNode(this.$el))) continue;
  1585. if (mutations[i].type === 'attributes' && mutations[i].attributeName === 'x-data') {
  1586. const xAttr = mutations[i].target.getAttribute('x-data') || '{}';
  1587. const rawData = saferEval(this.$el, xAttr, {
  1588. $el: this.$el
  1589. });
  1590. Object.keys(rawData).forEach(key => {
  1591. if (this.$data[key] !== rawData[key]) {
  1592. this.$data[key] = rawData[key];
  1593. }
  1594. });
  1595. }
  1596. if (mutations[i].addedNodes.length > 0) {
  1597. mutations[i].addedNodes.forEach(node => {
  1598. if (node.nodeType !== 1 || node.__x_inserted_me) return;
  1599. if (node.matches('[x-data]') && !node.__x) {
  1600. node.__x = new Component(node);
  1601. return;
  1602. }
  1603. this.initializeElements(node);
  1604. });
  1605. }
  1606. }
  1607. });
  1608. observer.observe(targetNode, observerOptions);
  1609. }
  1610. getRefsProxy() {
  1611. var self = this;
  1612. var refObj = {};
  1613. // One of the goals of this is to not hold elements in memory, but rather re-evaluate
  1614. // the DOM when the system needs something from it. This way, the framework is flexible and
  1615. // friendly to outside DOM changes from libraries like Vue/Livewire.
  1616. // For this reason, I'm using an "on-demand" proxy to fake a "$refs" object.
  1617. return new Proxy(refObj, {
  1618. get(object, property) {
  1619. if (property === '$isAlpineProxy') return true;
  1620. var ref; // We can't just query the DOM because it's hard to filter out refs in
  1621. // nested components.
  1622. self.walkAndSkipNestedComponents(self.$el, el => {
  1623. if (el.hasAttribute('x-ref') && el.getAttribute('x-ref') === property) {
  1624. ref = el;
  1625. }
  1626. });
  1627. return ref;
  1628. }
  1629. });
  1630. }
  1631. }
  1632. const Alpine = {
  1633. version: "2.8.2",
  1634. pauseMutationObserver: false,
  1635. magicProperties: {},
  1636. onComponentInitializeds: [],
  1637. onBeforeComponentInitializeds: [],
  1638. ignoreFocusedForValueBinding: false,
  1639. start: async function start() {
  1640. if (!isTesting()) {
  1641. await domReady();
  1642. }
  1643. this.discoverComponents(el => {
  1644. this.initializeComponent(el);
  1645. }); // It's easier and more performant to just support Turbolinks than listen
  1646. // to MutationObserver mutations at the document level.
  1647. document.addEventListener("turbolinks:load", () => {
  1648. this.discoverUninitializedComponents(el => {
  1649. this.initializeComponent(el);
  1650. });
  1651. });
  1652. this.listenForNewUninitializedComponentsAtRunTime();
  1653. },
  1654. discoverComponents: function discoverComponents(callback) {
  1655. const rootEls = document.querySelectorAll('[x-data]');
  1656. rootEls.forEach(rootEl => {
  1657. callback(rootEl);
  1658. });
  1659. },
  1660. discoverUninitializedComponents: function discoverUninitializedComponents(callback, el = null) {
  1661. const rootEls = (el || document).querySelectorAll('[x-data]');
  1662. Array.from(rootEls).filter(el => el.__x === undefined).forEach(rootEl => {
  1663. callback(rootEl);
  1664. });
  1665. },
  1666. listenForNewUninitializedComponentsAtRunTime: function listenForNewUninitializedComponentsAtRunTime() {
  1667. const targetNode = document.querySelector('body');
  1668. const observerOptions = {
  1669. childList: true,
  1670. attributes: true,
  1671. subtree: true
  1672. };
  1673. const observer = new MutationObserver(mutations => {
  1674. if (this.pauseMutationObserver) return;
  1675. for (let i = 0; i < mutations.length; i++) {
  1676. if (mutations[i].addedNodes.length > 0) {
  1677. mutations[i].addedNodes.forEach(node => {
  1678. // Discard non-element nodes (like line-breaks)
  1679. if (node.nodeType !== 1) return; // Discard any changes happening within an existing component.
  1680. // They will take care of themselves.
  1681. if (node.parentElement && node.parentElement.closest('[x-data]')) return;
  1682. this.discoverUninitializedComponents(el => {
  1683. this.initializeComponent(el);
  1684. }, node.parentElement);
  1685. });
  1686. }
  1687. }
  1688. });
  1689. observer.observe(targetNode, observerOptions);
  1690. },
  1691. initializeComponent: function initializeComponent(el) {
  1692. if (!el.__x) {
  1693. // Wrap in a try/catch so that we don't prevent other components
  1694. // from initializing when one component contains an error.
  1695. try {
  1696. el.__x = new Component(el);
  1697. } catch (error) {
  1698. setTimeout(() => {
  1699. throw error;
  1700. }, 0);
  1701. }
  1702. }
  1703. },
  1704. clone: function clone(component, newEl) {
  1705. if (!newEl.__x) {
  1706. newEl.__x = new Component(newEl, component);
  1707. }
  1708. },
  1709. addMagicProperty: function addMagicProperty(name, callback) {
  1710. this.magicProperties[name] = callback;
  1711. },
  1712. onComponentInitialized: function onComponentInitialized(callback) {
  1713. this.onComponentInitializeds.push(callback);
  1714. },
  1715. onBeforeComponentInitialized: function onBeforeComponentInitialized(callback) {
  1716. this.onBeforeComponentInitializeds.push(callback);
  1717. }
  1718. };
  1719. if (!isTesting()) {
  1720. window.Alpine = Alpine;
  1721. if (window.deferLoadingAlpine) {
  1722. window.deferLoadingAlpine(function () {
  1723. window.Alpine.start();
  1724. });
  1725. } else {
  1726. window.Alpine.start();
  1727. }
  1728. }
  1729. return Alpine;
  1730. })));
  1731. /***/ }),
  1732. /***/ "./node_modules/axios/index.js":
  1733. /*!*************************************!*\
  1734. !*** ./node_modules/axios/index.js ***!
  1735. \*************************************/
  1736. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1737. module.exports = __webpack_require__(/*! ./lib/axios */ "./node_modules/axios/lib/axios.js");
  1738. /***/ }),
  1739. /***/ "./node_modules/axios/lib/adapters/xhr.js":
  1740. /*!************************************************!*\
  1741. !*** ./node_modules/axios/lib/adapters/xhr.js ***!
  1742. \************************************************/
  1743. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1744. "use strict";
  1745. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  1746. var settle = __webpack_require__(/*! ./../core/settle */ "./node_modules/axios/lib/core/settle.js");
  1747. var cookies = __webpack_require__(/*! ./../helpers/cookies */ "./node_modules/axios/lib/helpers/cookies.js");
  1748. var buildURL = __webpack_require__(/*! ./../helpers/buildURL */ "./node_modules/axios/lib/helpers/buildURL.js");
  1749. var buildFullPath = __webpack_require__(/*! ../core/buildFullPath */ "./node_modules/axios/lib/core/buildFullPath.js");
  1750. var parseHeaders = __webpack_require__(/*! ./../helpers/parseHeaders */ "./node_modules/axios/lib/helpers/parseHeaders.js");
  1751. var isURLSameOrigin = __webpack_require__(/*! ./../helpers/isURLSameOrigin */ "./node_modules/axios/lib/helpers/isURLSameOrigin.js");
  1752. var createError = __webpack_require__(/*! ../core/createError */ "./node_modules/axios/lib/core/createError.js");
  1753. module.exports = function xhrAdapter(config) {
  1754. return new Promise(function dispatchXhrRequest(resolve, reject) {
  1755. var requestData = config.data;
  1756. var requestHeaders = config.headers;
  1757. if (utils.isFormData(requestData)) {
  1758. delete requestHeaders['Content-Type']; // Let the browser set it
  1759. }
  1760. var request = new XMLHttpRequest();
  1761. // HTTP basic authentication
  1762. if (config.auth) {
  1763. var username = config.auth.username || '';
  1764. var password = config.auth.password ? unescape(encodeURIComponent(config.auth.password)) : '';
  1765. requestHeaders.Authorization = 'Basic ' + btoa(username + ':' + password);
  1766. }
  1767. var fullPath = buildFullPath(config.baseURL, config.url);
  1768. request.open(config.method.toUpperCase(), buildURL(fullPath, config.params, config.paramsSerializer), true);
  1769. // Set the request timeout in MS
  1770. request.timeout = config.timeout;
  1771. // Listen for ready state
  1772. request.onreadystatechange = function handleLoad() {
  1773. if (!request || request.readyState !== 4) {
  1774. return;
  1775. }
  1776. // The request errored out and we didn't get a response, this will be
  1777. // handled by onerror instead
  1778. // With one exception: request that using file: protocol, most browsers
  1779. // will return status as 0 even though it's a successful request
  1780. if (request.status === 0 && !(request.responseURL && request.responseURL.indexOf('file:') === 0)) {
  1781. return;
  1782. }
  1783. // Prepare the response
  1784. var responseHeaders = 'getAllResponseHeaders' in request ? parseHeaders(request.getAllResponseHeaders()) : null;
  1785. var responseData = !config.responseType || config.responseType === 'text' ? request.responseText : request.response;
  1786. var response = {
  1787. data: responseData,
  1788. status: request.status,
  1789. statusText: request.statusText,
  1790. headers: responseHeaders,
  1791. config: config,
  1792. request: request
  1793. };
  1794. settle(resolve, reject, response);
  1795. // Clean up request
  1796. request = null;
  1797. };
  1798. // Handle browser request cancellation (as opposed to a manual cancellation)
  1799. request.onabort = function handleAbort() {
  1800. if (!request) {
  1801. return;
  1802. }
  1803. reject(createError('Request aborted', config, 'ECONNABORTED', request));
  1804. // Clean up request
  1805. request = null;
  1806. };
  1807. // Handle low level network errors
  1808. request.onerror = function handleError() {
  1809. // Real errors are hidden from us by the browser
  1810. // onerror should only fire if it's a network error
  1811. reject(createError('Network Error', config, null, request));
  1812. // Clean up request
  1813. request = null;
  1814. };
  1815. // Handle timeout
  1816. request.ontimeout = function handleTimeout() {
  1817. var timeoutErrorMessage = 'timeout of ' + config.timeout + 'ms exceeded';
  1818. if (config.timeoutErrorMessage) {
  1819. timeoutErrorMessage = config.timeoutErrorMessage;
  1820. }
  1821. reject(createError(timeoutErrorMessage, config, 'ECONNABORTED',
  1822. request));
  1823. // Clean up request
  1824. request = null;
  1825. };
  1826. // Add xsrf header
  1827. // This is only done if running in a standard browser environment.
  1828. // Specifically not if we're in a web worker, or react-native.
  1829. if (utils.isStandardBrowserEnv()) {
  1830. // Add xsrf header
  1831. var xsrfValue = (config.withCredentials || isURLSameOrigin(fullPath)) && config.xsrfCookieName ?
  1832. cookies.read(config.xsrfCookieName) :
  1833. undefined;
  1834. if (xsrfValue) {
  1835. requestHeaders[config.xsrfHeaderName] = xsrfValue;
  1836. }
  1837. }
  1838. // Add headers to the request
  1839. if ('setRequestHeader' in request) {
  1840. utils.forEach(requestHeaders, function setRequestHeader(val, key) {
  1841. if (typeof requestData === 'undefined' && key.toLowerCase() === 'content-type') {
  1842. // Remove Content-Type if data is undefined
  1843. delete requestHeaders[key];
  1844. } else {
  1845. // Otherwise add header to the request
  1846. request.setRequestHeader(key, val);
  1847. }
  1848. });
  1849. }
  1850. // Add withCredentials to request if needed
  1851. if (!utils.isUndefined(config.withCredentials)) {
  1852. request.withCredentials = !!config.withCredentials;
  1853. }
  1854. // Add responseType to request if needed
  1855. if (config.responseType) {
  1856. try {
  1857. request.responseType = config.responseType;
  1858. } catch (e) {
  1859. // Expected DOMException thrown by browsers not compatible XMLHttpRequest Level 2.
  1860. // But, this can be suppressed for 'json' type as it can be parsed by default 'transformResponse' function.
  1861. if (config.responseType !== 'json') {
  1862. throw e;
  1863. }
  1864. }
  1865. }
  1866. // Handle progress if needed
  1867. if (typeof config.onDownloadProgress === 'function') {
  1868. request.addEventListener('progress', config.onDownloadProgress);
  1869. }
  1870. // Not all browsers support upload events
  1871. if (typeof config.onUploadProgress === 'function' && request.upload) {
  1872. request.upload.addEventListener('progress', config.onUploadProgress);
  1873. }
  1874. if (config.cancelToken) {
  1875. // Handle cancellation
  1876. config.cancelToken.promise.then(function onCanceled(cancel) {
  1877. if (!request) {
  1878. return;
  1879. }
  1880. request.abort();
  1881. reject(cancel);
  1882. // Clean up request
  1883. request = null;
  1884. });
  1885. }
  1886. if (!requestData) {
  1887. requestData = null;
  1888. }
  1889. // Send the request
  1890. request.send(requestData);
  1891. });
  1892. };
  1893. /***/ }),
  1894. /***/ "./node_modules/axios/lib/axios.js":
  1895. /*!*****************************************!*\
  1896. !*** ./node_modules/axios/lib/axios.js ***!
  1897. \*****************************************/
  1898. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1899. "use strict";
  1900. var utils = __webpack_require__(/*! ./utils */ "./node_modules/axios/lib/utils.js");
  1901. var bind = __webpack_require__(/*! ./helpers/bind */ "./node_modules/axios/lib/helpers/bind.js");
  1902. var Axios = __webpack_require__(/*! ./core/Axios */ "./node_modules/axios/lib/core/Axios.js");
  1903. var mergeConfig = __webpack_require__(/*! ./core/mergeConfig */ "./node_modules/axios/lib/core/mergeConfig.js");
  1904. var defaults = __webpack_require__(/*! ./defaults */ "./node_modules/axios/lib/defaults.js");
  1905. /**
  1906. * Create an instance of Axios
  1907. *
  1908. * @param {Object} defaultConfig The default config for the instance
  1909. * @return {Axios} A new instance of Axios
  1910. */
  1911. function createInstance(defaultConfig) {
  1912. var context = new Axios(defaultConfig);
  1913. var instance = bind(Axios.prototype.request, context);
  1914. // Copy axios.prototype to instance
  1915. utils.extend(instance, Axios.prototype, context);
  1916. // Copy context to instance
  1917. utils.extend(instance, context);
  1918. return instance;
  1919. }
  1920. // Create the default instance to be exported
  1921. var axios = createInstance(defaults);
  1922. // Expose Axios class to allow class inheritance
  1923. axios.Axios = Axios;
  1924. // Factory for creating new instances
  1925. axios.create = function create(instanceConfig) {
  1926. return createInstance(mergeConfig(axios.defaults, instanceConfig));
  1927. };
  1928. // Expose Cancel & CancelToken
  1929. axios.Cancel = __webpack_require__(/*! ./cancel/Cancel */ "./node_modules/axios/lib/cancel/Cancel.js");
  1930. axios.CancelToken = __webpack_require__(/*! ./cancel/CancelToken */ "./node_modules/axios/lib/cancel/CancelToken.js");
  1931. axios.isCancel = __webpack_require__(/*! ./cancel/isCancel */ "./node_modules/axios/lib/cancel/isCancel.js");
  1932. // Expose all/spread
  1933. axios.all = function all(promises) {
  1934. return Promise.all(promises);
  1935. };
  1936. axios.spread = __webpack_require__(/*! ./helpers/spread */ "./node_modules/axios/lib/helpers/spread.js");
  1937. // Expose isAxiosError
  1938. axios.isAxiosError = __webpack_require__(/*! ./helpers/isAxiosError */ "./node_modules/axios/lib/helpers/isAxiosError.js");
  1939. module.exports = axios;
  1940. // Allow use of default import syntax in TypeScript
  1941. module.exports.default = axios;
  1942. /***/ }),
  1943. /***/ "./node_modules/axios/lib/cancel/Cancel.js":
  1944. /*!*************************************************!*\
  1945. !*** ./node_modules/axios/lib/cancel/Cancel.js ***!
  1946. \*************************************************/
  1947. /***/ ((module) => {
  1948. "use strict";
  1949. /**
  1950. * A `Cancel` is an object that is thrown when an operation is canceled.
  1951. *
  1952. * @class
  1953. * @param {string=} message The message.
  1954. */
  1955. function Cancel(message) {
  1956. this.message = message;
  1957. }
  1958. Cancel.prototype.toString = function toString() {
  1959. return 'Cancel' + (this.message ? ': ' + this.message : '');
  1960. };
  1961. Cancel.prototype.__CANCEL__ = true;
  1962. module.exports = Cancel;
  1963. /***/ }),
  1964. /***/ "./node_modules/axios/lib/cancel/CancelToken.js":
  1965. /*!******************************************************!*\
  1966. !*** ./node_modules/axios/lib/cancel/CancelToken.js ***!
  1967. \******************************************************/
  1968. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  1969. "use strict";
  1970. var Cancel = __webpack_require__(/*! ./Cancel */ "./node_modules/axios/lib/cancel/Cancel.js");
  1971. /**
  1972. * A `CancelToken` is an object that can be used to request cancellation of an operation.
  1973. *
  1974. * @class
  1975. * @param {Function} executor The executor function.
  1976. */
  1977. function CancelToken(executor) {
  1978. if (typeof executor !== 'function') {
  1979. throw new TypeError('executor must be a function.');
  1980. }
  1981. var resolvePromise;
  1982. this.promise = new Promise(function promiseExecutor(resolve) {
  1983. resolvePromise = resolve;
  1984. });
  1985. var token = this;
  1986. executor(function cancel(message) {
  1987. if (token.reason) {
  1988. // Cancellation has already been requested
  1989. return;
  1990. }
  1991. token.reason = new Cancel(message);
  1992. resolvePromise(token.reason);
  1993. });
  1994. }
  1995. /**
  1996. * Throws a `Cancel` if cancellation has been requested.
  1997. */
  1998. CancelToken.prototype.throwIfRequested = function throwIfRequested() {
  1999. if (this.reason) {
  2000. throw this.reason;
  2001. }
  2002. };
  2003. /**
  2004. * Returns an object that contains a new `CancelToken` and a function that, when called,
  2005. * cancels the `CancelToken`.
  2006. */
  2007. CancelToken.source = function source() {
  2008. var cancel;
  2009. var token = new CancelToken(function executor(c) {
  2010. cancel = c;
  2011. });
  2012. return {
  2013. token: token,
  2014. cancel: cancel
  2015. };
  2016. };
  2017. module.exports = CancelToken;
  2018. /***/ }),
  2019. /***/ "./node_modules/axios/lib/cancel/isCancel.js":
  2020. /*!***************************************************!*\
  2021. !*** ./node_modules/axios/lib/cancel/isCancel.js ***!
  2022. \***************************************************/
  2023. /***/ ((module) => {
  2024. "use strict";
  2025. module.exports = function isCancel(value) {
  2026. return !!(value && value.__CANCEL__);
  2027. };
  2028. /***/ }),
  2029. /***/ "./node_modules/axios/lib/core/Axios.js":
  2030. /*!**********************************************!*\
  2031. !*** ./node_modules/axios/lib/core/Axios.js ***!
  2032. \**********************************************/
  2033. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2034. "use strict";
  2035. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2036. var buildURL = __webpack_require__(/*! ../helpers/buildURL */ "./node_modules/axios/lib/helpers/buildURL.js");
  2037. var InterceptorManager = __webpack_require__(/*! ./InterceptorManager */ "./node_modules/axios/lib/core/InterceptorManager.js");
  2038. var dispatchRequest = __webpack_require__(/*! ./dispatchRequest */ "./node_modules/axios/lib/core/dispatchRequest.js");
  2039. var mergeConfig = __webpack_require__(/*! ./mergeConfig */ "./node_modules/axios/lib/core/mergeConfig.js");
  2040. /**
  2041. * Create a new instance of Axios
  2042. *
  2043. * @param {Object} instanceConfig The default config for the instance
  2044. */
  2045. function Axios(instanceConfig) {
  2046. this.defaults = instanceConfig;
  2047. this.interceptors = {
  2048. request: new InterceptorManager(),
  2049. response: new InterceptorManager()
  2050. };
  2051. }
  2052. /**
  2053. * Dispatch a request
  2054. *
  2055. * @param {Object} config The config specific for this request (merged with this.defaults)
  2056. */
  2057. Axios.prototype.request = function request(config) {
  2058. /*eslint no-param-reassign:0*/
  2059. // Allow for axios('example/url'[, config]) a la fetch API
  2060. if (typeof config === 'string') {
  2061. config = arguments[1] || {};
  2062. config.url = arguments[0];
  2063. } else {
  2064. config = config || {};
  2065. }
  2066. config = mergeConfig(this.defaults, config);
  2067. // Set config.method
  2068. if (config.method) {
  2069. config.method = config.method.toLowerCase();
  2070. } else if (this.defaults.method) {
  2071. config.method = this.defaults.method.toLowerCase();
  2072. } else {
  2073. config.method = 'get';
  2074. }
  2075. // Hook up interceptors middleware
  2076. var chain = [dispatchRequest, undefined];
  2077. var promise = Promise.resolve(config);
  2078. this.interceptors.request.forEach(function unshiftRequestInterceptors(interceptor) {
  2079. chain.unshift(interceptor.fulfilled, interceptor.rejected);
  2080. });
  2081. this.interceptors.response.forEach(function pushResponseInterceptors(interceptor) {
  2082. chain.push(interceptor.fulfilled, interceptor.rejected);
  2083. });
  2084. while (chain.length) {
  2085. promise = promise.then(chain.shift(), chain.shift());
  2086. }
  2087. return promise;
  2088. };
  2089. Axios.prototype.getUri = function getUri(config) {
  2090. config = mergeConfig(this.defaults, config);
  2091. return buildURL(config.url, config.params, config.paramsSerializer).replace(/^\?/, '');
  2092. };
  2093. // Provide aliases for supported request methods
  2094. utils.forEach(['delete', 'get', 'head', 'options'], function forEachMethodNoData(method) {
  2095. /*eslint func-names:0*/
  2096. Axios.prototype[method] = function(url, config) {
  2097. return this.request(mergeConfig(config || {}, {
  2098. method: method,
  2099. url: url,
  2100. data: (config || {}).data
  2101. }));
  2102. };
  2103. });
  2104. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  2105. /*eslint func-names:0*/
  2106. Axios.prototype[method] = function(url, data, config) {
  2107. return this.request(mergeConfig(config || {}, {
  2108. method: method,
  2109. url: url,
  2110. data: data
  2111. }));
  2112. };
  2113. });
  2114. module.exports = Axios;
  2115. /***/ }),
  2116. /***/ "./node_modules/axios/lib/core/InterceptorManager.js":
  2117. /*!***********************************************************!*\
  2118. !*** ./node_modules/axios/lib/core/InterceptorManager.js ***!
  2119. \***********************************************************/
  2120. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2121. "use strict";
  2122. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2123. function InterceptorManager() {
  2124. this.handlers = [];
  2125. }
  2126. /**
  2127. * Add a new interceptor to the stack
  2128. *
  2129. * @param {Function} fulfilled The function to handle `then` for a `Promise`
  2130. * @param {Function} rejected The function to handle `reject` for a `Promise`
  2131. *
  2132. * @return {Number} An ID used to remove interceptor later
  2133. */
  2134. InterceptorManager.prototype.use = function use(fulfilled, rejected) {
  2135. this.handlers.push({
  2136. fulfilled: fulfilled,
  2137. rejected: rejected
  2138. });
  2139. return this.handlers.length - 1;
  2140. };
  2141. /**
  2142. * Remove an interceptor from the stack
  2143. *
  2144. * @param {Number} id The ID that was returned by `use`
  2145. */
  2146. InterceptorManager.prototype.eject = function eject(id) {
  2147. if (this.handlers[id]) {
  2148. this.handlers[id] = null;
  2149. }
  2150. };
  2151. /**
  2152. * Iterate over all the registered interceptors
  2153. *
  2154. * This method is particularly useful for skipping over any
  2155. * interceptors that may have become `null` calling `eject`.
  2156. *
  2157. * @param {Function} fn The function to call for each interceptor
  2158. */
  2159. InterceptorManager.prototype.forEach = function forEach(fn) {
  2160. utils.forEach(this.handlers, function forEachHandler(h) {
  2161. if (h !== null) {
  2162. fn(h);
  2163. }
  2164. });
  2165. };
  2166. module.exports = InterceptorManager;
  2167. /***/ }),
  2168. /***/ "./node_modules/axios/lib/core/buildFullPath.js":
  2169. /*!******************************************************!*\
  2170. !*** ./node_modules/axios/lib/core/buildFullPath.js ***!
  2171. \******************************************************/
  2172. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2173. "use strict";
  2174. var isAbsoluteURL = __webpack_require__(/*! ../helpers/isAbsoluteURL */ "./node_modules/axios/lib/helpers/isAbsoluteURL.js");
  2175. var combineURLs = __webpack_require__(/*! ../helpers/combineURLs */ "./node_modules/axios/lib/helpers/combineURLs.js");
  2176. /**
  2177. * Creates a new URL by combining the baseURL with the requestedURL,
  2178. * only when the requestedURL is not already an absolute URL.
  2179. * If the requestURL is absolute, this function returns the requestedURL untouched.
  2180. *
  2181. * @param {string} baseURL The base URL
  2182. * @param {string} requestedURL Absolute or relative URL to combine
  2183. * @returns {string} The combined full path
  2184. */
  2185. module.exports = function buildFullPath(baseURL, requestedURL) {
  2186. if (baseURL && !isAbsoluteURL(requestedURL)) {
  2187. return combineURLs(baseURL, requestedURL);
  2188. }
  2189. return requestedURL;
  2190. };
  2191. /***/ }),
  2192. /***/ "./node_modules/axios/lib/core/createError.js":
  2193. /*!****************************************************!*\
  2194. !*** ./node_modules/axios/lib/core/createError.js ***!
  2195. \****************************************************/
  2196. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2197. "use strict";
  2198. var enhanceError = __webpack_require__(/*! ./enhanceError */ "./node_modules/axios/lib/core/enhanceError.js");
  2199. /**
  2200. * Create an Error with the specified message, config, error code, request and response.
  2201. *
  2202. * @param {string} message The error message.
  2203. * @param {Object} config The config.
  2204. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  2205. * @param {Object} [request] The request.
  2206. * @param {Object} [response] The response.
  2207. * @returns {Error} The created error.
  2208. */
  2209. module.exports = function createError(message, config, code, request, response) {
  2210. var error = new Error(message);
  2211. return enhanceError(error, config, code, request, response);
  2212. };
  2213. /***/ }),
  2214. /***/ "./node_modules/axios/lib/core/dispatchRequest.js":
  2215. /*!********************************************************!*\
  2216. !*** ./node_modules/axios/lib/core/dispatchRequest.js ***!
  2217. \********************************************************/
  2218. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2219. "use strict";
  2220. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2221. var transformData = __webpack_require__(/*! ./transformData */ "./node_modules/axios/lib/core/transformData.js");
  2222. var isCancel = __webpack_require__(/*! ../cancel/isCancel */ "./node_modules/axios/lib/cancel/isCancel.js");
  2223. var defaults = __webpack_require__(/*! ../defaults */ "./node_modules/axios/lib/defaults.js");
  2224. /**
  2225. * Throws a `Cancel` if cancellation has been requested.
  2226. */
  2227. function throwIfCancellationRequested(config) {
  2228. if (config.cancelToken) {
  2229. config.cancelToken.throwIfRequested();
  2230. }
  2231. }
  2232. /**
  2233. * Dispatch a request to the server using the configured adapter.
  2234. *
  2235. * @param {object} config The config that is to be used for the request
  2236. * @returns {Promise} The Promise to be fulfilled
  2237. */
  2238. module.exports = function dispatchRequest(config) {
  2239. throwIfCancellationRequested(config);
  2240. // Ensure headers exist
  2241. config.headers = config.headers || {};
  2242. // Transform request data
  2243. config.data = transformData(
  2244. config.data,
  2245. config.headers,
  2246. config.transformRequest
  2247. );
  2248. // Flatten headers
  2249. config.headers = utils.merge(
  2250. config.headers.common || {},
  2251. config.headers[config.method] || {},
  2252. config.headers
  2253. );
  2254. utils.forEach(
  2255. ['delete', 'get', 'head', 'post', 'put', 'patch', 'common'],
  2256. function cleanHeaderConfig(method) {
  2257. delete config.headers[method];
  2258. }
  2259. );
  2260. var adapter = config.adapter || defaults.adapter;
  2261. return adapter(config).then(function onAdapterResolution(response) {
  2262. throwIfCancellationRequested(config);
  2263. // Transform response data
  2264. response.data = transformData(
  2265. response.data,
  2266. response.headers,
  2267. config.transformResponse
  2268. );
  2269. return response;
  2270. }, function onAdapterRejection(reason) {
  2271. if (!isCancel(reason)) {
  2272. throwIfCancellationRequested(config);
  2273. // Transform response data
  2274. if (reason && reason.response) {
  2275. reason.response.data = transformData(
  2276. reason.response.data,
  2277. reason.response.headers,
  2278. config.transformResponse
  2279. );
  2280. }
  2281. }
  2282. return Promise.reject(reason);
  2283. });
  2284. };
  2285. /***/ }),
  2286. /***/ "./node_modules/axios/lib/core/enhanceError.js":
  2287. /*!*****************************************************!*\
  2288. !*** ./node_modules/axios/lib/core/enhanceError.js ***!
  2289. \*****************************************************/
  2290. /***/ ((module) => {
  2291. "use strict";
  2292. /**
  2293. * Update an Error with the specified config, error code, and response.
  2294. *
  2295. * @param {Error} error The error to update.
  2296. * @param {Object} config The config.
  2297. * @param {string} [code] The error code (for example, 'ECONNABORTED').
  2298. * @param {Object} [request] The request.
  2299. * @param {Object} [response] The response.
  2300. * @returns {Error} The error.
  2301. */
  2302. module.exports = function enhanceError(error, config, code, request, response) {
  2303. error.config = config;
  2304. if (code) {
  2305. error.code = code;
  2306. }
  2307. error.request = request;
  2308. error.response = response;
  2309. error.isAxiosError = true;
  2310. error.toJSON = function toJSON() {
  2311. return {
  2312. // Standard
  2313. message: this.message,
  2314. name: this.name,
  2315. // Microsoft
  2316. description: this.description,
  2317. number: this.number,
  2318. // Mozilla
  2319. fileName: this.fileName,
  2320. lineNumber: this.lineNumber,
  2321. columnNumber: this.columnNumber,
  2322. stack: this.stack,
  2323. // Axios
  2324. config: this.config,
  2325. code: this.code
  2326. };
  2327. };
  2328. return error;
  2329. };
  2330. /***/ }),
  2331. /***/ "./node_modules/axios/lib/core/mergeConfig.js":
  2332. /*!****************************************************!*\
  2333. !*** ./node_modules/axios/lib/core/mergeConfig.js ***!
  2334. \****************************************************/
  2335. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2336. "use strict";
  2337. var utils = __webpack_require__(/*! ../utils */ "./node_modules/axios/lib/utils.js");
  2338. /**
  2339. * Config-specific merge-function which creates a new config-object
  2340. * by merging two configuration objects together.
  2341. *
  2342. * @param {Object} config1
  2343. * @param {Object} config2
  2344. * @returns {Object} New object resulting from merging config2 to config1
  2345. */
  2346. module.exports = function mergeConfig(config1, config2) {
  2347. // eslint-disable-next-line no-param-reassign
  2348. config2 = config2 || {};
  2349. var config = {};
  2350. var valueFromConfig2Keys = ['url', 'method', 'data'];
  2351. var mergeDeepPropertiesKeys = ['headers', 'auth', 'proxy', 'params'];
  2352. var defaultToConfig2Keys = [
  2353. 'baseURL', 'transformRequest', 'transformResponse', 'paramsSerializer',
  2354. 'timeout', 'timeoutMessage', 'withCredentials', 'adapter', 'responseType', 'xsrfCookieName',
  2355. 'xsrfHeaderName', 'onUploadProgress', 'onDownloadProgress', 'decompress',
  2356. 'maxContentLength', 'maxBodyLength', 'maxRedirects', 'transport', 'httpAgent',
  2357. 'httpsAgent', 'cancelToken', 'socketPath', 'responseEncoding'
  2358. ];
  2359. var directMergeKeys = ['validateStatus'];
  2360. function getMergedValue(target, source) {
  2361. if (utils.isPlainObject(target) && utils.isPlainObject(source)) {
  2362. return utils.merge(target, source);
  2363. } else if (utils.isPlainObject(source)) {
  2364. return utils.merge({}, source);
  2365. } else if (utils.isArray(source)) {
  2366. return source.slice();
  2367. }
  2368. return source;
  2369. }
  2370. function mergeDeepProperties(prop) {
  2371. if (!utils.isUndefined(config2[prop])) {
  2372. config[prop] = getMergedValue(config1[prop], config2[prop]);
  2373. } else if (!utils.isUndefined(config1[prop])) {
  2374. config[prop] = getMergedValue(undefined, config1[prop]);
  2375. }
  2376. }
  2377. utils.forEach(valueFromConfig2Keys, function valueFromConfig2(prop) {
  2378. if (!utils.isUndefined(config2[prop])) {
  2379. config[prop] = getMergedValue(undefined, config2[prop]);
  2380. }
  2381. });
  2382. utils.forEach(mergeDeepPropertiesKeys, mergeDeepProperties);
  2383. utils.forEach(defaultToConfig2Keys, function defaultToConfig2(prop) {
  2384. if (!utils.isUndefined(config2[prop])) {
  2385. config[prop] = getMergedValue(undefined, config2[prop]);
  2386. } else if (!utils.isUndefined(config1[prop])) {
  2387. config[prop] = getMergedValue(undefined, config1[prop]);
  2388. }
  2389. });
  2390. utils.forEach(directMergeKeys, function merge(prop) {
  2391. if (prop in config2) {
  2392. config[prop] = getMergedValue(config1[prop], config2[prop]);
  2393. } else if (prop in config1) {
  2394. config[prop] = getMergedValue(undefined, config1[prop]);
  2395. }
  2396. });
  2397. var axiosKeys = valueFromConfig2Keys
  2398. .concat(mergeDeepPropertiesKeys)
  2399. .concat(defaultToConfig2Keys)
  2400. .concat(directMergeKeys);
  2401. var otherKeys = Object
  2402. .keys(config1)
  2403. .concat(Object.keys(config2))
  2404. .filter(function filterAxiosKeys(key) {
  2405. return axiosKeys.indexOf(key) === -1;
  2406. });
  2407. utils.forEach(otherKeys, mergeDeepProperties);
  2408. return config;
  2409. };
  2410. /***/ }),
  2411. /***/ "./node_modules/axios/lib/core/settle.js":
  2412. /*!***********************************************!*\
  2413. !*** ./node_modules/axios/lib/core/settle.js ***!
  2414. \***********************************************/
  2415. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2416. "use strict";
  2417. var createError = __webpack_require__(/*! ./createError */ "./node_modules/axios/lib/core/createError.js");
  2418. /**
  2419. * Resolve or reject a Promise based on response status.
  2420. *
  2421. * @param {Function} resolve A function that resolves the promise.
  2422. * @param {Function} reject A function that rejects the promise.
  2423. * @param {object} response The response.
  2424. */
  2425. module.exports = function settle(resolve, reject, response) {
  2426. var validateStatus = response.config.validateStatus;
  2427. if (!response.status || !validateStatus || validateStatus(response.status)) {
  2428. resolve(response);
  2429. } else {
  2430. reject(createError(
  2431. 'Request failed with status code ' + response.status,
  2432. response.config,
  2433. null,
  2434. response.request,
  2435. response
  2436. ));
  2437. }
  2438. };
  2439. /***/ }),
  2440. /***/ "./node_modules/axios/lib/core/transformData.js":
  2441. /*!******************************************************!*\
  2442. !*** ./node_modules/axios/lib/core/transformData.js ***!
  2443. \******************************************************/
  2444. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2445. "use strict";
  2446. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2447. /**
  2448. * Transform the data for a request or a response
  2449. *
  2450. * @param {Object|String} data The data to be transformed
  2451. * @param {Array} headers The headers for the request or response
  2452. * @param {Array|Function} fns A single function or Array of functions
  2453. * @returns {*} The resulting transformed data
  2454. */
  2455. module.exports = function transformData(data, headers, fns) {
  2456. /*eslint no-param-reassign:0*/
  2457. utils.forEach(fns, function transform(fn) {
  2458. data = fn(data, headers);
  2459. });
  2460. return data;
  2461. };
  2462. /***/ }),
  2463. /***/ "./node_modules/axios/lib/defaults.js":
  2464. /*!********************************************!*\
  2465. !*** ./node_modules/axios/lib/defaults.js ***!
  2466. \********************************************/
  2467. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2468. "use strict";
  2469. /* provided dependency */ var process = __webpack_require__(/*! process/browser */ "./node_modules/process/browser.js");
  2470. var utils = __webpack_require__(/*! ./utils */ "./node_modules/axios/lib/utils.js");
  2471. var normalizeHeaderName = __webpack_require__(/*! ./helpers/normalizeHeaderName */ "./node_modules/axios/lib/helpers/normalizeHeaderName.js");
  2472. var DEFAULT_CONTENT_TYPE = {
  2473. 'Content-Type': 'application/x-www-form-urlencoded'
  2474. };
  2475. function setContentTypeIfUnset(headers, value) {
  2476. if (!utils.isUndefined(headers) && utils.isUndefined(headers['Content-Type'])) {
  2477. headers['Content-Type'] = value;
  2478. }
  2479. }
  2480. function getDefaultAdapter() {
  2481. var adapter;
  2482. if (typeof XMLHttpRequest !== 'undefined') {
  2483. // For browsers use XHR adapter
  2484. adapter = __webpack_require__(/*! ./adapters/xhr */ "./node_modules/axios/lib/adapters/xhr.js");
  2485. } else if (typeof process !== 'undefined' && Object.prototype.toString.call(process) === '[object process]') {
  2486. // For node use HTTP adapter
  2487. adapter = __webpack_require__(/*! ./adapters/http */ "./node_modules/axios/lib/adapters/xhr.js");
  2488. }
  2489. return adapter;
  2490. }
  2491. var defaults = {
  2492. adapter: getDefaultAdapter(),
  2493. transformRequest: [function transformRequest(data, headers) {
  2494. normalizeHeaderName(headers, 'Accept');
  2495. normalizeHeaderName(headers, 'Content-Type');
  2496. if (utils.isFormData(data) ||
  2497. utils.isArrayBuffer(data) ||
  2498. utils.isBuffer(data) ||
  2499. utils.isStream(data) ||
  2500. utils.isFile(data) ||
  2501. utils.isBlob(data)
  2502. ) {
  2503. return data;
  2504. }
  2505. if (utils.isArrayBufferView(data)) {
  2506. return data.buffer;
  2507. }
  2508. if (utils.isURLSearchParams(data)) {
  2509. setContentTypeIfUnset(headers, 'application/x-www-form-urlencoded;charset=utf-8');
  2510. return data.toString();
  2511. }
  2512. if (utils.isObject(data)) {
  2513. setContentTypeIfUnset(headers, 'application/json;charset=utf-8');
  2514. return JSON.stringify(data);
  2515. }
  2516. return data;
  2517. }],
  2518. transformResponse: [function transformResponse(data) {
  2519. /*eslint no-param-reassign:0*/
  2520. if (typeof data === 'string') {
  2521. try {
  2522. data = JSON.parse(data);
  2523. } catch (e) { /* Ignore */ }
  2524. }
  2525. return data;
  2526. }],
  2527. /**
  2528. * A timeout in milliseconds to abort a request. If set to 0 (default) a
  2529. * timeout is not created.
  2530. */
  2531. timeout: 0,
  2532. xsrfCookieName: 'XSRF-TOKEN',
  2533. xsrfHeaderName: 'X-XSRF-TOKEN',
  2534. maxContentLength: -1,
  2535. maxBodyLength: -1,
  2536. validateStatus: function validateStatus(status) {
  2537. return status >= 200 && status < 300;
  2538. }
  2539. };
  2540. defaults.headers = {
  2541. common: {
  2542. 'Accept': 'application/json, text/plain, */*'
  2543. }
  2544. };
  2545. utils.forEach(['delete', 'get', 'head'], function forEachMethodNoData(method) {
  2546. defaults.headers[method] = {};
  2547. });
  2548. utils.forEach(['post', 'put', 'patch'], function forEachMethodWithData(method) {
  2549. defaults.headers[method] = utils.merge(DEFAULT_CONTENT_TYPE);
  2550. });
  2551. module.exports = defaults;
  2552. /***/ }),
  2553. /***/ "./node_modules/axios/lib/helpers/bind.js":
  2554. /*!************************************************!*\
  2555. !*** ./node_modules/axios/lib/helpers/bind.js ***!
  2556. \************************************************/
  2557. /***/ ((module) => {
  2558. "use strict";
  2559. module.exports = function bind(fn, thisArg) {
  2560. return function wrap() {
  2561. var args = new Array(arguments.length);
  2562. for (var i = 0; i < args.length; i++) {
  2563. args[i] = arguments[i];
  2564. }
  2565. return fn.apply(thisArg, args);
  2566. };
  2567. };
  2568. /***/ }),
  2569. /***/ "./node_modules/axios/lib/helpers/buildURL.js":
  2570. /*!****************************************************!*\
  2571. !*** ./node_modules/axios/lib/helpers/buildURL.js ***!
  2572. \****************************************************/
  2573. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2574. "use strict";
  2575. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2576. function encode(val) {
  2577. return encodeURIComponent(val).
  2578. replace(/%3A/gi, ':').
  2579. replace(/%24/g, '$').
  2580. replace(/%2C/gi, ',').
  2581. replace(/%20/g, '+').
  2582. replace(/%5B/gi, '[').
  2583. replace(/%5D/gi, ']');
  2584. }
  2585. /**
  2586. * Build a URL by appending params to the end
  2587. *
  2588. * @param {string} url The base of the url (e.g., http://www.google.com)
  2589. * @param {object} [params] The params to be appended
  2590. * @returns {string} The formatted url
  2591. */
  2592. module.exports = function buildURL(url, params, paramsSerializer) {
  2593. /*eslint no-param-reassign:0*/
  2594. if (!params) {
  2595. return url;
  2596. }
  2597. var serializedParams;
  2598. if (paramsSerializer) {
  2599. serializedParams = paramsSerializer(params);
  2600. } else if (utils.isURLSearchParams(params)) {
  2601. serializedParams = params.toString();
  2602. } else {
  2603. var parts = [];
  2604. utils.forEach(params, function serialize(val, key) {
  2605. if (val === null || typeof val === 'undefined') {
  2606. return;
  2607. }
  2608. if (utils.isArray(val)) {
  2609. key = key + '[]';
  2610. } else {
  2611. val = [val];
  2612. }
  2613. utils.forEach(val, function parseValue(v) {
  2614. if (utils.isDate(v)) {
  2615. v = v.toISOString();
  2616. } else if (utils.isObject(v)) {
  2617. v = JSON.stringify(v);
  2618. }
  2619. parts.push(encode(key) + '=' + encode(v));
  2620. });
  2621. });
  2622. serializedParams = parts.join('&');
  2623. }
  2624. if (serializedParams) {
  2625. var hashmarkIndex = url.indexOf('#');
  2626. if (hashmarkIndex !== -1) {
  2627. url = url.slice(0, hashmarkIndex);
  2628. }
  2629. url += (url.indexOf('?') === -1 ? '?' : '&') + serializedParams;
  2630. }
  2631. return url;
  2632. };
  2633. /***/ }),
  2634. /***/ "./node_modules/axios/lib/helpers/combineURLs.js":
  2635. /*!*******************************************************!*\
  2636. !*** ./node_modules/axios/lib/helpers/combineURLs.js ***!
  2637. \*******************************************************/
  2638. /***/ ((module) => {
  2639. "use strict";
  2640. /**
  2641. * Creates a new URL by combining the specified URLs
  2642. *
  2643. * @param {string} baseURL The base URL
  2644. * @param {string} relativeURL The relative URL
  2645. * @returns {string} The combined URL
  2646. */
  2647. module.exports = function combineURLs(baseURL, relativeURL) {
  2648. return relativeURL
  2649. ? baseURL.replace(/\/+$/, '') + '/' + relativeURL.replace(/^\/+/, '')
  2650. : baseURL;
  2651. };
  2652. /***/ }),
  2653. /***/ "./node_modules/axios/lib/helpers/cookies.js":
  2654. /*!***************************************************!*\
  2655. !*** ./node_modules/axios/lib/helpers/cookies.js ***!
  2656. \***************************************************/
  2657. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2658. "use strict";
  2659. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2660. module.exports = (
  2661. utils.isStandardBrowserEnv() ?
  2662. // Standard browser envs support document.cookie
  2663. (function standardBrowserEnv() {
  2664. return {
  2665. write: function write(name, value, expires, path, domain, secure) {
  2666. var cookie = [];
  2667. cookie.push(name + '=' + encodeURIComponent(value));
  2668. if (utils.isNumber(expires)) {
  2669. cookie.push('expires=' + new Date(expires).toGMTString());
  2670. }
  2671. if (utils.isString(path)) {
  2672. cookie.push('path=' + path);
  2673. }
  2674. if (utils.isString(domain)) {
  2675. cookie.push('domain=' + domain);
  2676. }
  2677. if (secure === true) {
  2678. cookie.push('secure');
  2679. }
  2680. document.cookie = cookie.join('; ');
  2681. },
  2682. read: function read(name) {
  2683. var match = document.cookie.match(new RegExp('(^|;\\s*)(' + name + ')=([^;]*)'));
  2684. return (match ? decodeURIComponent(match[3]) : null);
  2685. },
  2686. remove: function remove(name) {
  2687. this.write(name, '', Date.now() - 86400000);
  2688. }
  2689. };
  2690. })() :
  2691. // Non standard browser env (web workers, react-native) lack needed support.
  2692. (function nonStandardBrowserEnv() {
  2693. return {
  2694. write: function write() {},
  2695. read: function read() { return null; },
  2696. remove: function remove() {}
  2697. };
  2698. })()
  2699. );
  2700. /***/ }),
  2701. /***/ "./node_modules/axios/lib/helpers/isAbsoluteURL.js":
  2702. /*!*********************************************************!*\
  2703. !*** ./node_modules/axios/lib/helpers/isAbsoluteURL.js ***!
  2704. \*********************************************************/
  2705. /***/ ((module) => {
  2706. "use strict";
  2707. /**
  2708. * Determines whether the specified URL is absolute
  2709. *
  2710. * @param {string} url The URL to test
  2711. * @returns {boolean} True if the specified URL is absolute, otherwise false
  2712. */
  2713. module.exports = function isAbsoluteURL(url) {
  2714. // A URL is considered absolute if it begins with "<scheme>://" or "//" (protocol-relative URL).
  2715. // RFC 3986 defines scheme name as a sequence of characters beginning with a letter and followed
  2716. // by any combination of letters, digits, plus, period, or hyphen.
  2717. return /^([a-z][a-z\d\+\-\.]*:)?\/\//i.test(url);
  2718. };
  2719. /***/ }),
  2720. /***/ "./node_modules/axios/lib/helpers/isAxiosError.js":
  2721. /*!********************************************************!*\
  2722. !*** ./node_modules/axios/lib/helpers/isAxiosError.js ***!
  2723. \********************************************************/
  2724. /***/ ((module) => {
  2725. "use strict";
  2726. /**
  2727. * Determines whether the payload is an error thrown by Axios
  2728. *
  2729. * @param {*} payload The value to test
  2730. * @returns {boolean} True if the payload is an error thrown by Axios, otherwise false
  2731. */
  2732. module.exports = function isAxiosError(payload) {
  2733. return (typeof payload === 'object') && (payload.isAxiosError === true);
  2734. };
  2735. /***/ }),
  2736. /***/ "./node_modules/axios/lib/helpers/isURLSameOrigin.js":
  2737. /*!***********************************************************!*\
  2738. !*** ./node_modules/axios/lib/helpers/isURLSameOrigin.js ***!
  2739. \***********************************************************/
  2740. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2741. "use strict";
  2742. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2743. module.exports = (
  2744. utils.isStandardBrowserEnv() ?
  2745. // Standard browser envs have full support of the APIs needed to test
  2746. // whether the request URL is of the same origin as current location.
  2747. (function standardBrowserEnv() {
  2748. var msie = /(msie|trident)/i.test(navigator.userAgent);
  2749. var urlParsingNode = document.createElement('a');
  2750. var originURL;
  2751. /**
  2752. * Parse a URL to discover it's components
  2753. *
  2754. * @param {String} url The URL to be parsed
  2755. * @returns {Object}
  2756. */
  2757. function resolveURL(url) {
  2758. var href = url;
  2759. if (msie) {
  2760. // IE needs attribute set twice to normalize properties
  2761. urlParsingNode.setAttribute('href', href);
  2762. href = urlParsingNode.href;
  2763. }
  2764. urlParsingNode.setAttribute('href', href);
  2765. // urlParsingNode provides the UrlUtils interface - http://url.spec.whatwg.org/#urlutils
  2766. return {
  2767. href: urlParsingNode.href,
  2768. protocol: urlParsingNode.protocol ? urlParsingNode.protocol.replace(/:$/, '') : '',
  2769. host: urlParsingNode.host,
  2770. search: urlParsingNode.search ? urlParsingNode.search.replace(/^\?/, '') : '',
  2771. hash: urlParsingNode.hash ? urlParsingNode.hash.replace(/^#/, '') : '',
  2772. hostname: urlParsingNode.hostname,
  2773. port: urlParsingNode.port,
  2774. pathname: (urlParsingNode.pathname.charAt(0) === '/') ?
  2775. urlParsingNode.pathname :
  2776. '/' + urlParsingNode.pathname
  2777. };
  2778. }
  2779. originURL = resolveURL(window.location.href);
  2780. /**
  2781. * Determine if a URL shares the same origin as the current location
  2782. *
  2783. * @param {String} requestURL The URL to test
  2784. * @returns {boolean} True if URL shares the same origin, otherwise false
  2785. */
  2786. return function isURLSameOrigin(requestURL) {
  2787. var parsed = (utils.isString(requestURL)) ? resolveURL(requestURL) : requestURL;
  2788. return (parsed.protocol === originURL.protocol &&
  2789. parsed.host === originURL.host);
  2790. };
  2791. })() :
  2792. // Non standard browser envs (web workers, react-native) lack needed support.
  2793. (function nonStandardBrowserEnv() {
  2794. return function isURLSameOrigin() {
  2795. return true;
  2796. };
  2797. })()
  2798. );
  2799. /***/ }),
  2800. /***/ "./node_modules/axios/lib/helpers/normalizeHeaderName.js":
  2801. /*!***************************************************************!*\
  2802. !*** ./node_modules/axios/lib/helpers/normalizeHeaderName.js ***!
  2803. \***************************************************************/
  2804. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2805. "use strict";
  2806. var utils = __webpack_require__(/*! ../utils */ "./node_modules/axios/lib/utils.js");
  2807. module.exports = function normalizeHeaderName(headers, normalizedName) {
  2808. utils.forEach(headers, function processHeader(value, name) {
  2809. if (name !== normalizedName && name.toUpperCase() === normalizedName.toUpperCase()) {
  2810. headers[normalizedName] = value;
  2811. delete headers[name];
  2812. }
  2813. });
  2814. };
  2815. /***/ }),
  2816. /***/ "./node_modules/axios/lib/helpers/parseHeaders.js":
  2817. /*!********************************************************!*\
  2818. !*** ./node_modules/axios/lib/helpers/parseHeaders.js ***!
  2819. \********************************************************/
  2820. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2821. "use strict";
  2822. var utils = __webpack_require__(/*! ./../utils */ "./node_modules/axios/lib/utils.js");
  2823. // Headers whose duplicates are ignored by node
  2824. // c.f. https://nodejs.org/api/http.html#http_message_headers
  2825. var ignoreDuplicateOf = [
  2826. 'age', 'authorization', 'content-length', 'content-type', 'etag',
  2827. 'expires', 'from', 'host', 'if-modified-since', 'if-unmodified-since',
  2828. 'last-modified', 'location', 'max-forwards', 'proxy-authorization',
  2829. 'referer', 'retry-after', 'user-agent'
  2830. ];
  2831. /**
  2832. * Parse headers into an object
  2833. *
  2834. * ```
  2835. * Date: Wed, 27 Aug 2014 08:58:49 GMT
  2836. * Content-Type: application/json
  2837. * Connection: keep-alive
  2838. * Transfer-Encoding: chunked
  2839. * ```
  2840. *
  2841. * @param {String} headers Headers needing to be parsed
  2842. * @returns {Object} Headers parsed into an object
  2843. */
  2844. module.exports = function parseHeaders(headers) {
  2845. var parsed = {};
  2846. var key;
  2847. var val;
  2848. var i;
  2849. if (!headers) { return parsed; }
  2850. utils.forEach(headers.split('\n'), function parser(line) {
  2851. i = line.indexOf(':');
  2852. key = utils.trim(line.substr(0, i)).toLowerCase();
  2853. val = utils.trim(line.substr(i + 1));
  2854. if (key) {
  2855. if (parsed[key] && ignoreDuplicateOf.indexOf(key) >= 0) {
  2856. return;
  2857. }
  2858. if (key === 'set-cookie') {
  2859. parsed[key] = (parsed[key] ? parsed[key] : []).concat([val]);
  2860. } else {
  2861. parsed[key] = parsed[key] ? parsed[key] + ', ' + val : val;
  2862. }
  2863. }
  2864. });
  2865. return parsed;
  2866. };
  2867. /***/ }),
  2868. /***/ "./node_modules/axios/lib/helpers/spread.js":
  2869. /*!**************************************************!*\
  2870. !*** ./node_modules/axios/lib/helpers/spread.js ***!
  2871. \**************************************************/
  2872. /***/ ((module) => {
  2873. "use strict";
  2874. /**
  2875. * Syntactic sugar for invoking a function and expanding an array for arguments.
  2876. *
  2877. * Common use case would be to use `Function.prototype.apply`.
  2878. *
  2879. * ```js
  2880. * function f(x, y, z) {}
  2881. * var args = [1, 2, 3];
  2882. * f.apply(null, args);
  2883. * ```
  2884. *
  2885. * With `spread` this example can be re-written.
  2886. *
  2887. * ```js
  2888. * spread(function(x, y, z) {})([1, 2, 3]);
  2889. * ```
  2890. *
  2891. * @param {Function} callback
  2892. * @returns {Function}
  2893. */
  2894. module.exports = function spread(callback) {
  2895. return function wrap(arr) {
  2896. return callback.apply(null, arr);
  2897. };
  2898. };
  2899. /***/ }),
  2900. /***/ "./node_modules/axios/lib/utils.js":
  2901. /*!*****************************************!*\
  2902. !*** ./node_modules/axios/lib/utils.js ***!
  2903. \*****************************************/
  2904. /***/ ((module, __unused_webpack_exports, __webpack_require__) => {
  2905. "use strict";
  2906. var bind = __webpack_require__(/*! ./helpers/bind */ "./node_modules/axios/lib/helpers/bind.js");
  2907. /*global toString:true*/
  2908. // utils is a library of generic helper functions non-specific to axios
  2909. var toString = Object.prototype.toString;
  2910. /**
  2911. * Determine if a value is an Array
  2912. *
  2913. * @param {Object} val The value to test
  2914. * @returns {boolean} True if value is an Array, otherwise false
  2915. */
  2916. function isArray(val) {
  2917. return toString.call(val) === '[object Array]';
  2918. }
  2919. /**
  2920. * Determine if a value is undefined
  2921. *
  2922. * @param {Object} val The value to test
  2923. * @returns {boolean} True if the value is undefined, otherwise false
  2924. */
  2925. function isUndefined(val) {
  2926. return typeof val === 'undefined';
  2927. }
  2928. /**
  2929. * Determine if a value is a Buffer
  2930. *
  2931. * @param {Object} val The value to test
  2932. * @returns {boolean} True if value is a Buffer, otherwise false
  2933. */
  2934. function isBuffer(val) {
  2935. return val !== null && !isUndefined(val) && val.constructor !== null && !isUndefined(val.constructor)
  2936. && typeof val.constructor.isBuffer === 'function' && val.constructor.isBuffer(val);
  2937. }
  2938. /**
  2939. * Determine if a value is an ArrayBuffer
  2940. *
  2941. * @param {Object} val The value to test
  2942. * @returns {boolean} True if value is an ArrayBuffer, otherwise false
  2943. */
  2944. function isArrayBuffer(val) {
  2945. return toString.call(val) === '[object ArrayBuffer]';
  2946. }
  2947. /**
  2948. * Determine if a value is a FormData
  2949. *
  2950. * @param {Object} val The value to test
  2951. * @returns {boolean} True if value is an FormData, otherwise false
  2952. */
  2953. function isFormData(val) {
  2954. return (typeof FormData !== 'undefined') && (val instanceof FormData);
  2955. }
  2956. /**
  2957. * Determine if a value is a view on an ArrayBuffer
  2958. *
  2959. * @param {Object} val The value to test
  2960. * @returns {boolean} True if value is a view on an ArrayBuffer, otherwise false
  2961. */
  2962. function isArrayBufferView(val) {
  2963. var result;
  2964. if ((typeof ArrayBuffer !== 'undefined') && (ArrayBuffer.isView)) {
  2965. result = ArrayBuffer.isView(val);
  2966. } else {
  2967. result = (val) && (val.buffer) && (val.buffer instanceof ArrayBuffer);
  2968. }
  2969. return result;
  2970. }
  2971. /**
  2972. * Determine if a value is a String
  2973. *
  2974. * @param {Object} val The value to test
  2975. * @returns {boolean} True if value is a String, otherwise false
  2976. */
  2977. function isString(val) {
  2978. return typeof val === 'string';
  2979. }
  2980. /**
  2981. * Determine if a value is a Number
  2982. *
  2983. * @param {Object} val The value to test
  2984. * @returns {boolean} True if value is a Number, otherwise false
  2985. */
  2986. function isNumber(val) {
  2987. return typeof val === 'number';
  2988. }
  2989. /**
  2990. * Determine if a value is an Object
  2991. *
  2992. * @param {Object} val The value to test
  2993. * @returns {boolean} True if value is an Object, otherwise false
  2994. */
  2995. function isObject(val) {
  2996. return val !== null && typeof val === 'object';
  2997. }
  2998. /**
  2999. * Determine if a value is a plain Object
  3000. *
  3001. * @param {Object} val The value to test
  3002. * @return {boolean} True if value is a plain Object, otherwise false
  3003. */
  3004. function isPlainObject(val) {
  3005. if (toString.call(val) !== '[object Object]') {
  3006. return false;
  3007. }
  3008. var prototype = Object.getPrototypeOf(val);
  3009. return prototype === null || prototype === Object.prototype;
  3010. }
  3011. /**
  3012. * Determine if a value is a Date
  3013. *
  3014. * @param {Object} val The value to test
  3015. * @returns {boolean} True if value is a Date, otherwise false
  3016. */
  3017. function isDate(val) {
  3018. return toString.call(val) === '[object Date]';
  3019. }
  3020. /**
  3021. * Determine if a value is a File
  3022. *
  3023. * @param {Object} val The value to test
  3024. * @returns {boolean} True if value is a File, otherwise false
  3025. */
  3026. function isFile(val) {
  3027. return toString.call(val) === '[object File]';
  3028. }
  3029. /**
  3030. * Determine if a value is a Blob
  3031. *
  3032. * @param {Object} val The value to test
  3033. * @returns {boolean} True if value is a Blob, otherwise false
  3034. */
  3035. function isBlob(val) {
  3036. return toString.call(val) === '[object Blob]';
  3037. }
  3038. /**
  3039. * Determine if a value is a Function
  3040. *
  3041. * @param {Object} val The value to test
  3042. * @returns {boolean} True if value is a Function, otherwise false
  3043. */
  3044. function isFunction(val) {
  3045. return toString.call(val) === '[object Function]';
  3046. }
  3047. /**
  3048. * Determine if a value is a Stream
  3049. *
  3050. * @param {Object} val The value to test
  3051. * @returns {boolean} True if value is a Stream, otherwise false
  3052. */
  3053. function isStream(val) {
  3054. return isObject(val) && isFunction(val.pipe);
  3055. }
  3056. /**
  3057. * Determine if a value is a URLSearchParams object
  3058. *
  3059. * @param {Object} val The value to test
  3060. * @returns {boolean} True if value is a URLSearchParams object, otherwise false
  3061. */
  3062. function isURLSearchParams(val) {
  3063. return typeof URLSearchParams !== 'undefined' && val instanceof URLSearchParams;
  3064. }
  3065. /**
  3066. * Trim excess whitespace off the beginning and end of a string
  3067. *
  3068. * @param {String} str The String to trim
  3069. * @returns {String} The String freed of excess whitespace
  3070. */
  3071. function trim(str) {
  3072. return str.replace(/^\s*/, '').replace(/\s*$/, '');
  3073. }
  3074. /**
  3075. * Determine if we're running in a standard browser environment
  3076. *
  3077. * This allows axios to run in a web worker, and react-native.
  3078. * Both environments support XMLHttpRequest, but not fully standard globals.
  3079. *
  3080. * web workers:
  3081. * typeof window -> undefined
  3082. * typeof document -> undefined
  3083. *
  3084. * react-native:
  3085. * navigator.product -> 'ReactNative'
  3086. * nativescript
  3087. * navigator.product -> 'NativeScript' or 'NS'
  3088. */
  3089. function isStandardBrowserEnv() {
  3090. if (typeof navigator !== 'undefined' && (navigator.product === 'ReactNative' ||
  3091. navigator.product === 'NativeScript' ||
  3092. navigator.product === 'NS')) {
  3093. return false;
  3094. }
  3095. return (
  3096. typeof window !== 'undefined' &&
  3097. typeof document !== 'undefined'
  3098. );
  3099. }
  3100. /**
  3101. * Iterate over an Array or an Object invoking a function for each item.
  3102. *
  3103. * If `obj` is an Array callback will be called passing
  3104. * the value, index, and complete array for each item.
  3105. *
  3106. * If 'obj' is an Object callback will be called passing
  3107. * the value, key, and complete object for each property.
  3108. *
  3109. * @param {Object|Array} obj The object to iterate
  3110. * @param {Function} fn The callback to invoke for each item
  3111. */
  3112. function forEach(obj, fn) {
  3113. // Don't bother if no value provided
  3114. if (obj === null || typeof obj === 'undefined') {
  3115. return;
  3116. }
  3117. // Force an array if not already something iterable
  3118. if (typeof obj !== 'object') {
  3119. /*eslint no-param-reassign:0*/
  3120. obj = [obj];
  3121. }
  3122. if (isArray(obj)) {
  3123. // Iterate over array values
  3124. for (var i = 0, l = obj.length; i < l; i++) {
  3125. fn.call(null, obj[i], i, obj);
  3126. }
  3127. } else {
  3128. // Iterate over object keys
  3129. for (var key in obj) {
  3130. if (Object.prototype.hasOwnProperty.call(obj, key)) {
  3131. fn.call(null, obj[key], key, obj);
  3132. }
  3133. }
  3134. }
  3135. }
  3136. /**
  3137. * Accepts varargs expecting each argument to be an object, then
  3138. * immutably merges the properties of each object and returns result.
  3139. *
  3140. * When multiple objects contain the same key the later object in
  3141. * the arguments list will take precedence.
  3142. *
  3143. * Example:
  3144. *
  3145. * ```js
  3146. * var result = merge({foo: 123}, {foo: 456});
  3147. * console.log(result.foo); // outputs 456
  3148. * ```
  3149. *
  3150. * @param {Object} obj1 Object to merge
  3151. * @returns {Object} Result of all merge properties
  3152. */
  3153. function merge(/* obj1, obj2, obj3, ... */) {
  3154. var result = {};
  3155. function assignValue(val, key) {
  3156. if (isPlainObject(result[key]) && isPlainObject(val)) {
  3157. result[key] = merge(result[key], val);
  3158. } else if (isPlainObject(val)) {
  3159. result[key] = merge({}, val);
  3160. } else if (isArray(val)) {
  3161. result[key] = val.slice();
  3162. } else {
  3163. result[key] = val;
  3164. }
  3165. }
  3166. for (var i = 0, l = arguments.length; i < l; i++) {
  3167. forEach(arguments[i], assignValue);
  3168. }
  3169. return result;
  3170. }
  3171. /**
  3172. * Extends object a by mutably adding to it the properties of object b.
  3173. *
  3174. * @param {Object} a The object to be extended
  3175. * @param {Object} b The object to copy properties from
  3176. * @param {Object} thisArg The object to bind function to
  3177. * @return {Object} The resulting value of object a
  3178. */
  3179. function extend(a, b, thisArg) {
  3180. forEach(b, function assignValue(val, key) {
  3181. if (thisArg && typeof val === 'function') {
  3182. a[key] = bind(val, thisArg);
  3183. } else {
  3184. a[key] = val;
  3185. }
  3186. });
  3187. return a;
  3188. }
  3189. /**
  3190. * Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
  3191. *
  3192. * @param {string} content with BOM
  3193. * @return {string} content value without BOM
  3194. */
  3195. function stripBOM(content) {
  3196. if (content.charCodeAt(0) === 0xFEFF) {
  3197. content = content.slice(1);
  3198. }
  3199. return content;
  3200. }
  3201. module.exports = {
  3202. isArray: isArray,
  3203. isArrayBuffer: isArrayBuffer,
  3204. isBuffer: isBuffer,
  3205. isFormData: isFormData,
  3206. isArrayBufferView: isArrayBufferView,
  3207. isString: isString,
  3208. isNumber: isNumber,
  3209. isObject: isObject,
  3210. isPlainObject: isPlainObject,
  3211. isUndefined: isUndefined,
  3212. isDate: isDate,
  3213. isFile: isFile,
  3214. isBlob: isBlob,
  3215. isFunction: isFunction,
  3216. isStream: isStream,
  3217. isURLSearchParams: isURLSearchParams,
  3218. isStandardBrowserEnv: isStandardBrowserEnv,
  3219. forEach: forEach,
  3220. merge: merge,
  3221. extend: extend,
  3222. trim: trim,
  3223. stripBOM: stripBOM
  3224. };
  3225. /***/ }),
  3226. /***/ "./resources/js/app.js":
  3227. /*!*****************************!*\
  3228. !*** ./resources/js/app.js ***!
  3229. \*****************************/
  3230. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  3231. __webpack_require__(/*! ./bootstrap */ "./resources/js/bootstrap.js");
  3232. __webpack_require__(/*! alpinejs */ "./node_modules/alpinejs/dist/alpine.js");
  3233. /***/ }),
  3234. /***/ "./resources/js/bootstrap.js":
  3235. /*!***********************************!*\
  3236. !*** ./resources/js/bootstrap.js ***!
  3237. \***********************************/
  3238. /***/ ((__unused_webpack_module, __unused_webpack_exports, __webpack_require__) => {
  3239. window._ = __webpack_require__(/*! lodash */ "./node_modules/lodash/lodash.js");
  3240. /**
  3241. * We'll load the axios HTTP library which allows us to easily issue requests
  3242. * to our Laravel back-end. This library automatically handles sending the
  3243. * CSRF token as a header based on the value of the "XSRF" token cookie.
  3244. */
  3245. window.axios = __webpack_require__(/*! axios */ "./node_modules/axios/index.js");
  3246. window.axios.defaults.headers.common['X-Requested-With'] = 'XMLHttpRequest';
  3247. /**
  3248. * Echo exposes an expressive API for subscribing to channels and listening
  3249. * for events that are broadcast by Laravel. Echo and event broadcasting
  3250. * allows your team to easily build robust real-time web applications.
  3251. */
  3252. // import Echo from 'laravel-echo';
  3253. // window.Pusher = require('pusher-js');
  3254. // window.Echo = new Echo({
  3255. // broadcaster: 'pusher',
  3256. // key: process.env.MIX_PUSHER_APP_KEY,
  3257. // cluster: process.env.MIX_PUSHER_APP_CLUSTER,
  3258. // forceTLS: true
  3259. // });
  3260. /***/ }),
  3261. /***/ "./node_modules/lodash/lodash.js":
  3262. /*!***************************************!*\
  3263. !*** ./node_modules/lodash/lodash.js ***!
  3264. \***************************************/
  3265. /***/ (function(module, exports, __webpack_require__) {
  3266. /* module decorator */ module = __webpack_require__.nmd(module);
  3267. var __WEBPACK_AMD_DEFINE_RESULT__;/**
  3268. * @license
  3269. * Lodash <https://lodash.com/>
  3270. * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
  3271. * Released under MIT license <https://lodash.com/license>
  3272. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  3273. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  3274. */
  3275. ;(function() {
  3276. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  3277. var undefined;
  3278. /** Used as the semantic version number. */
  3279. var VERSION = '4.17.21';
  3280. /** Used as the size to enable large array optimizations. */
  3281. var LARGE_ARRAY_SIZE = 200;
  3282. /** Error message constants. */
  3283. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  3284. FUNC_ERROR_TEXT = 'Expected a function',
  3285. INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`';
  3286. /** Used to stand-in for `undefined` hash values. */
  3287. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  3288. /** Used as the maximum memoize cache size. */
  3289. var MAX_MEMOIZE_SIZE = 500;
  3290. /** Used as the internal argument placeholder. */
  3291. var PLACEHOLDER = '__lodash_placeholder__';
  3292. /** Used to compose bitmasks for cloning. */
  3293. var CLONE_DEEP_FLAG = 1,
  3294. CLONE_FLAT_FLAG = 2,
  3295. CLONE_SYMBOLS_FLAG = 4;
  3296. /** Used to compose bitmasks for value comparisons. */
  3297. var COMPARE_PARTIAL_FLAG = 1,
  3298. COMPARE_UNORDERED_FLAG = 2;
  3299. /** Used to compose bitmasks for function metadata. */
  3300. var WRAP_BIND_FLAG = 1,
  3301. WRAP_BIND_KEY_FLAG = 2,
  3302. WRAP_CURRY_BOUND_FLAG = 4,
  3303. WRAP_CURRY_FLAG = 8,
  3304. WRAP_CURRY_RIGHT_FLAG = 16,
  3305. WRAP_PARTIAL_FLAG = 32,
  3306. WRAP_PARTIAL_RIGHT_FLAG = 64,
  3307. WRAP_ARY_FLAG = 128,
  3308. WRAP_REARG_FLAG = 256,
  3309. WRAP_FLIP_FLAG = 512;
  3310. /** Used as default options for `_.truncate`. */
  3311. var DEFAULT_TRUNC_LENGTH = 30,
  3312. DEFAULT_TRUNC_OMISSION = '...';
  3313. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  3314. var HOT_COUNT = 800,
  3315. HOT_SPAN = 16;
  3316. /** Used to indicate the type of lazy iteratees. */
  3317. var LAZY_FILTER_FLAG = 1,
  3318. LAZY_MAP_FLAG = 2,
  3319. LAZY_WHILE_FLAG = 3;
  3320. /** Used as references for various `Number` constants. */
  3321. var INFINITY = 1 / 0,
  3322. MAX_SAFE_INTEGER = 9007199254740991,
  3323. MAX_INTEGER = 1.7976931348623157e+308,
  3324. NAN = 0 / 0;
  3325. /** Used as references for the maximum length and index of an array. */
  3326. var MAX_ARRAY_LENGTH = 4294967295,
  3327. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  3328. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  3329. /** Used to associate wrap methods with their bit flags. */
  3330. var wrapFlags = [
  3331. ['ary', WRAP_ARY_FLAG],
  3332. ['bind', WRAP_BIND_FLAG],
  3333. ['bindKey', WRAP_BIND_KEY_FLAG],
  3334. ['curry', WRAP_CURRY_FLAG],
  3335. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  3336. ['flip', WRAP_FLIP_FLAG],
  3337. ['partial', WRAP_PARTIAL_FLAG],
  3338. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  3339. ['rearg', WRAP_REARG_FLAG]
  3340. ];
  3341. /** `Object#toString` result references. */
  3342. var argsTag = '[object Arguments]',
  3343. arrayTag = '[object Array]',
  3344. asyncTag = '[object AsyncFunction]',
  3345. boolTag = '[object Boolean]',
  3346. dateTag = '[object Date]',
  3347. domExcTag = '[object DOMException]',
  3348. errorTag = '[object Error]',
  3349. funcTag = '[object Function]',
  3350. genTag = '[object GeneratorFunction]',
  3351. mapTag = '[object Map]',
  3352. numberTag = '[object Number]',
  3353. nullTag = '[object Null]',
  3354. objectTag = '[object Object]',
  3355. promiseTag = '[object Promise]',
  3356. proxyTag = '[object Proxy]',
  3357. regexpTag = '[object RegExp]',
  3358. setTag = '[object Set]',
  3359. stringTag = '[object String]',
  3360. symbolTag = '[object Symbol]',
  3361. undefinedTag = '[object Undefined]',
  3362. weakMapTag = '[object WeakMap]',
  3363. weakSetTag = '[object WeakSet]';
  3364. var arrayBufferTag = '[object ArrayBuffer]',
  3365. dataViewTag = '[object DataView]',
  3366. float32Tag = '[object Float32Array]',
  3367. float64Tag = '[object Float64Array]',
  3368. int8Tag = '[object Int8Array]',
  3369. int16Tag = '[object Int16Array]',
  3370. int32Tag = '[object Int32Array]',
  3371. uint8Tag = '[object Uint8Array]',
  3372. uint8ClampedTag = '[object Uint8ClampedArray]',
  3373. uint16Tag = '[object Uint16Array]',
  3374. uint32Tag = '[object Uint32Array]';
  3375. /** Used to match empty string literals in compiled template source. */
  3376. var reEmptyStringLeading = /\b__p \+= '';/g,
  3377. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  3378. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  3379. /** Used to match HTML entities and HTML characters. */
  3380. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  3381. reUnescapedHtml = /[&<>"']/g,
  3382. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  3383. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  3384. /** Used to match template delimiters. */
  3385. var reEscape = /<%-([\s\S]+?)%>/g,
  3386. reEvaluate = /<%([\s\S]+?)%>/g,
  3387. reInterpolate = /<%=([\s\S]+?)%>/g;
  3388. /** Used to match property names within property paths. */
  3389. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  3390. reIsPlainProp = /^\w*$/,
  3391. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  3392. /**
  3393. * Used to match `RegExp`
  3394. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  3395. */
  3396. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  3397. reHasRegExpChar = RegExp(reRegExpChar.source);
  3398. /** Used to match leading whitespace. */
  3399. var reTrimStart = /^\s+/;
  3400. /** Used to match a single whitespace character. */
  3401. var reWhitespace = /\s/;
  3402. /** Used to match wrap detail comments. */
  3403. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  3404. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  3405. reSplitDetails = /,? & /;
  3406. /** Used to match words composed of alphanumeric characters. */
  3407. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  3408. /**
  3409. * Used to validate the `validate` option in `_.template` variable.
  3410. *
  3411. * Forbids characters which could potentially change the meaning of the function argument definition:
  3412. * - "()," (modification of function parameters)
  3413. * - "=" (default value)
  3414. * - "[]{}" (destructuring of function parameters)
  3415. * - "/" (beginning of a comment)
  3416. * - whitespace
  3417. */
  3418. var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
  3419. /** Used to match backslashes in property paths. */
  3420. var reEscapeChar = /\\(\\)?/g;
  3421. /**
  3422. * Used to match
  3423. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  3424. */
  3425. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  3426. /** Used to match `RegExp` flags from their coerced string values. */
  3427. var reFlags = /\w*$/;
  3428. /** Used to detect bad signed hexadecimal string values. */
  3429. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  3430. /** Used to detect binary string values. */
  3431. var reIsBinary = /^0b[01]+$/i;
  3432. /** Used to detect host constructors (Safari). */
  3433. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  3434. /** Used to detect octal string values. */
  3435. var reIsOctal = /^0o[0-7]+$/i;
  3436. /** Used to detect unsigned integer values. */
  3437. var reIsUint = /^(?:0|[1-9]\d*)$/;
  3438. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  3439. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  3440. /** Used to ensure capturing order of template delimiters. */
  3441. var reNoMatch = /($^)/;
  3442. /** Used to match unescaped characters in compiled string literals. */
  3443. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  3444. /** Used to compose unicode character classes. */
  3445. var rsAstralRange = '\\ud800-\\udfff',
  3446. rsComboMarksRange = '\\u0300-\\u036f',
  3447. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  3448. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  3449. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  3450. rsDingbatRange = '\\u2700-\\u27bf',
  3451. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  3452. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  3453. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  3454. rsPunctuationRange = '\\u2000-\\u206f',
  3455. 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',
  3456. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  3457. rsVarRange = '\\ufe0e\\ufe0f',
  3458. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  3459. /** Used to compose unicode capture groups. */
  3460. var rsApos = "['\u2019]",
  3461. rsAstral = '[' + rsAstralRange + ']',
  3462. rsBreak = '[' + rsBreakRange + ']',
  3463. rsCombo = '[' + rsComboRange + ']',
  3464. rsDigits = '\\d+',
  3465. rsDingbat = '[' + rsDingbatRange + ']',
  3466. rsLower = '[' + rsLowerRange + ']',
  3467. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  3468. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  3469. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  3470. rsNonAstral = '[^' + rsAstralRange + ']',
  3471. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  3472. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  3473. rsUpper = '[' + rsUpperRange + ']',
  3474. rsZWJ = '\\u200d';
  3475. /** Used to compose unicode regexes. */
  3476. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  3477. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  3478. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  3479. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  3480. reOptMod = rsModifier + '?',
  3481. rsOptVar = '[' + rsVarRange + ']?',
  3482. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  3483. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  3484. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  3485. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  3486. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  3487. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  3488. /** Used to match apostrophes. */
  3489. var reApos = RegExp(rsApos, 'g');
  3490. /**
  3491. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  3492. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  3493. */
  3494. var reComboMark = RegExp(rsCombo, 'g');
  3495. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  3496. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  3497. /** Used to match complex or compound words. */
  3498. var reUnicodeWord = RegExp([
  3499. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  3500. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  3501. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  3502. rsUpper + '+' + rsOptContrUpper,
  3503. rsOrdUpper,
  3504. rsOrdLower,
  3505. rsDigits,
  3506. rsEmoji
  3507. ].join('|'), 'g');
  3508. /** 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/). */
  3509. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  3510. /** Used to detect strings that need a more robust regexp to match words. */
  3511. 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 ]/;
  3512. /** Used to assign default `context` object properties. */
  3513. var contextProps = [
  3514. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  3515. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  3516. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  3517. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  3518. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  3519. ];
  3520. /** Used to make template sourceURLs easier to identify. */
  3521. var templateCounter = -1;
  3522. /** Used to identify `toStringTag` values of typed arrays. */
  3523. var typedArrayTags = {};
  3524. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  3525. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  3526. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  3527. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  3528. typedArrayTags[uint32Tag] = true;
  3529. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  3530. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  3531. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  3532. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  3533. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  3534. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  3535. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  3536. typedArrayTags[weakMapTag] = false;
  3537. /** Used to identify `toStringTag` values supported by `_.clone`. */
  3538. var cloneableTags = {};
  3539. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  3540. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  3541. cloneableTags[boolTag] = cloneableTags[dateTag] =
  3542. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  3543. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  3544. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  3545. cloneableTags[numberTag] = cloneableTags[objectTag] =
  3546. cloneableTags[regexpTag] = cloneableTags[setTag] =
  3547. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  3548. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  3549. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  3550. cloneableTags[errorTag] = cloneableTags[funcTag] =
  3551. cloneableTags[weakMapTag] = false;
  3552. /** Used to map Latin Unicode letters to basic Latin letters. */
  3553. var deburredLetters = {
  3554. // Latin-1 Supplement block.
  3555. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  3556. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  3557. '\xc7': 'C', '\xe7': 'c',
  3558. '\xd0': 'D', '\xf0': 'd',
  3559. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  3560. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  3561. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  3562. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  3563. '\xd1': 'N', '\xf1': 'n',
  3564. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  3565. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  3566. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  3567. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  3568. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  3569. '\xc6': 'Ae', '\xe6': 'ae',
  3570. '\xde': 'Th', '\xfe': 'th',
  3571. '\xdf': 'ss',
  3572. // Latin Extended-A block.
  3573. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  3574. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  3575. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  3576. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  3577. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  3578. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  3579. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  3580. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  3581. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  3582. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  3583. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  3584. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  3585. '\u0134': 'J', '\u0135': 'j',
  3586. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  3587. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  3588. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  3589. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  3590. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  3591. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  3592. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  3593. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  3594. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  3595. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  3596. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  3597. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  3598. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  3599. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  3600. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  3601. '\u0174': 'W', '\u0175': 'w',
  3602. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  3603. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  3604. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  3605. '\u0132': 'IJ', '\u0133': 'ij',
  3606. '\u0152': 'Oe', '\u0153': 'oe',
  3607. '\u0149': "'n", '\u017f': 's'
  3608. };
  3609. /** Used to map characters to HTML entities. */
  3610. var htmlEscapes = {
  3611. '&': '&amp;',
  3612. '<': '&lt;',
  3613. '>': '&gt;',
  3614. '"': '&quot;',
  3615. "'": '&#39;'
  3616. };
  3617. /** Used to map HTML entities to characters. */
  3618. var htmlUnescapes = {
  3619. '&amp;': '&',
  3620. '&lt;': '<',
  3621. '&gt;': '>',
  3622. '&quot;': '"',
  3623. '&#39;': "'"
  3624. };
  3625. /** Used to escape characters for inclusion in compiled string literals. */
  3626. var stringEscapes = {
  3627. '\\': '\\',
  3628. "'": "'",
  3629. '\n': 'n',
  3630. '\r': 'r',
  3631. '\u2028': 'u2028',
  3632. '\u2029': 'u2029'
  3633. };
  3634. /** Built-in method references without a dependency on `root`. */
  3635. var freeParseFloat = parseFloat,
  3636. freeParseInt = parseInt;
  3637. /** Detect free variable `global` from Node.js. */
  3638. var freeGlobal = typeof __webpack_require__.g == 'object' && __webpack_require__.g && __webpack_require__.g.Object === Object && __webpack_require__.g;
  3639. /** Detect free variable `self`. */
  3640. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  3641. /** Used as a reference to the global object. */
  3642. var root = freeGlobal || freeSelf || Function('return this')();
  3643. /** Detect free variable `exports`. */
  3644. var freeExports = true && exports && !exports.nodeType && exports;
  3645. /** Detect free variable `module`. */
  3646. var freeModule = freeExports && "object" == 'object' && module && !module.nodeType && module;
  3647. /** Detect the popular CommonJS extension `module.exports`. */
  3648. var moduleExports = freeModule && freeModule.exports === freeExports;
  3649. /** Detect free variable `process` from Node.js. */
  3650. var freeProcess = moduleExports && freeGlobal.process;
  3651. /** Used to access faster Node.js helpers. */
  3652. var nodeUtil = (function() {
  3653. try {
  3654. // Use `util.types` for Node.js 10+.
  3655. var types = freeModule && freeModule.require && freeModule.require('util').types;
  3656. if (types) {
  3657. return types;
  3658. }
  3659. // Legacy `process.binding('util')` for Node.js < 10.
  3660. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  3661. } catch (e) {}
  3662. }());
  3663. /* Node.js helper references. */
  3664. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  3665. nodeIsDate = nodeUtil && nodeUtil.isDate,
  3666. nodeIsMap = nodeUtil && nodeUtil.isMap,
  3667. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  3668. nodeIsSet = nodeUtil && nodeUtil.isSet,
  3669. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  3670. /*--------------------------------------------------------------------------*/
  3671. /**
  3672. * A faster alternative to `Function#apply`, this function invokes `func`
  3673. * with the `this` binding of `thisArg` and the arguments of `args`.
  3674. *
  3675. * @private
  3676. * @param {Function} func The function to invoke.
  3677. * @param {*} thisArg The `this` binding of `func`.
  3678. * @param {Array} args The arguments to invoke `func` with.
  3679. * @returns {*} Returns the result of `func`.
  3680. */
  3681. function apply(func, thisArg, args) {
  3682. switch (args.length) {
  3683. case 0: return func.call(thisArg);
  3684. case 1: return func.call(thisArg, args[0]);
  3685. case 2: return func.call(thisArg, args[0], args[1]);
  3686. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  3687. }
  3688. return func.apply(thisArg, args);
  3689. }
  3690. /**
  3691. * A specialized version of `baseAggregator` for arrays.
  3692. *
  3693. * @private
  3694. * @param {Array} [array] The array to iterate over.
  3695. * @param {Function} setter The function to set `accumulator` values.
  3696. * @param {Function} iteratee The iteratee to transform keys.
  3697. * @param {Object} accumulator The initial aggregated object.
  3698. * @returns {Function} Returns `accumulator`.
  3699. */
  3700. function arrayAggregator(array, setter, iteratee, accumulator) {
  3701. var index = -1,
  3702. length = array == null ? 0 : array.length;
  3703. while (++index < length) {
  3704. var value = array[index];
  3705. setter(accumulator, value, iteratee(value), array);
  3706. }
  3707. return accumulator;
  3708. }
  3709. /**
  3710. * A specialized version of `_.forEach` for arrays without support for
  3711. * iteratee shorthands.
  3712. *
  3713. * @private
  3714. * @param {Array} [array] The array to iterate over.
  3715. * @param {Function} iteratee The function invoked per iteration.
  3716. * @returns {Array} Returns `array`.
  3717. */
  3718. function arrayEach(array, iteratee) {
  3719. var index = -1,
  3720. length = array == null ? 0 : array.length;
  3721. while (++index < length) {
  3722. if (iteratee(array[index], index, array) === false) {
  3723. break;
  3724. }
  3725. }
  3726. return array;
  3727. }
  3728. /**
  3729. * A specialized version of `_.forEachRight` for arrays without support for
  3730. * iteratee shorthands.
  3731. *
  3732. * @private
  3733. * @param {Array} [array] The array to iterate over.
  3734. * @param {Function} iteratee The function invoked per iteration.
  3735. * @returns {Array} Returns `array`.
  3736. */
  3737. function arrayEachRight(array, iteratee) {
  3738. var length = array == null ? 0 : array.length;
  3739. while (length--) {
  3740. if (iteratee(array[length], length, array) === false) {
  3741. break;
  3742. }
  3743. }
  3744. return array;
  3745. }
  3746. /**
  3747. * A specialized version of `_.every` for arrays without support for
  3748. * iteratee shorthands.
  3749. *
  3750. * @private
  3751. * @param {Array} [array] The array to iterate over.
  3752. * @param {Function} predicate The function invoked per iteration.
  3753. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  3754. * else `false`.
  3755. */
  3756. function arrayEvery(array, predicate) {
  3757. var index = -1,
  3758. length = array == null ? 0 : array.length;
  3759. while (++index < length) {
  3760. if (!predicate(array[index], index, array)) {
  3761. return false;
  3762. }
  3763. }
  3764. return true;
  3765. }
  3766. /**
  3767. * A specialized version of `_.filter` for arrays without support for
  3768. * iteratee shorthands.
  3769. *
  3770. * @private
  3771. * @param {Array} [array] The array to iterate over.
  3772. * @param {Function} predicate The function invoked per iteration.
  3773. * @returns {Array} Returns the new filtered array.
  3774. */
  3775. function arrayFilter(array, predicate) {
  3776. var index = -1,
  3777. length = array == null ? 0 : array.length,
  3778. resIndex = 0,
  3779. result = [];
  3780. while (++index < length) {
  3781. var value = array[index];
  3782. if (predicate(value, index, array)) {
  3783. result[resIndex++] = value;
  3784. }
  3785. }
  3786. return result;
  3787. }
  3788. /**
  3789. * A specialized version of `_.includes` for arrays without support for
  3790. * specifying an index to search from.
  3791. *
  3792. * @private
  3793. * @param {Array} [array] The array to inspect.
  3794. * @param {*} target The value to search for.
  3795. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  3796. */
  3797. function arrayIncludes(array, value) {
  3798. var length = array == null ? 0 : array.length;
  3799. return !!length && baseIndexOf(array, value, 0) > -1;
  3800. }
  3801. /**
  3802. * This function is like `arrayIncludes` except that it accepts a comparator.
  3803. *
  3804. * @private
  3805. * @param {Array} [array] The array to inspect.
  3806. * @param {*} target The value to search for.
  3807. * @param {Function} comparator The comparator invoked per element.
  3808. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  3809. */
  3810. function arrayIncludesWith(array, value, comparator) {
  3811. var index = -1,
  3812. length = array == null ? 0 : array.length;
  3813. while (++index < length) {
  3814. if (comparator(value, array[index])) {
  3815. return true;
  3816. }
  3817. }
  3818. return false;
  3819. }
  3820. /**
  3821. * A specialized version of `_.map` for arrays without support for iteratee
  3822. * shorthands.
  3823. *
  3824. * @private
  3825. * @param {Array} [array] The array to iterate over.
  3826. * @param {Function} iteratee The function invoked per iteration.
  3827. * @returns {Array} Returns the new mapped array.
  3828. */
  3829. function arrayMap(array, iteratee) {
  3830. var index = -1,
  3831. length = array == null ? 0 : array.length,
  3832. result = Array(length);
  3833. while (++index < length) {
  3834. result[index] = iteratee(array[index], index, array);
  3835. }
  3836. return result;
  3837. }
  3838. /**
  3839. * Appends the elements of `values` to `array`.
  3840. *
  3841. * @private
  3842. * @param {Array} array The array to modify.
  3843. * @param {Array} values The values to append.
  3844. * @returns {Array} Returns `array`.
  3845. */
  3846. function arrayPush(array, values) {
  3847. var index = -1,
  3848. length = values.length,
  3849. offset = array.length;
  3850. while (++index < length) {
  3851. array[offset + index] = values[index];
  3852. }
  3853. return array;
  3854. }
  3855. /**
  3856. * A specialized version of `_.reduce` for arrays without support for
  3857. * iteratee shorthands.
  3858. *
  3859. * @private
  3860. * @param {Array} [array] The array to iterate over.
  3861. * @param {Function} iteratee The function invoked per iteration.
  3862. * @param {*} [accumulator] The initial value.
  3863. * @param {boolean} [initAccum] Specify using the first element of `array` as
  3864. * the initial value.
  3865. * @returns {*} Returns the accumulated value.
  3866. */
  3867. function arrayReduce(array, iteratee, accumulator, initAccum) {
  3868. var index = -1,
  3869. length = array == null ? 0 : array.length;
  3870. if (initAccum && length) {
  3871. accumulator = array[++index];
  3872. }
  3873. while (++index < length) {
  3874. accumulator = iteratee(accumulator, array[index], index, array);
  3875. }
  3876. return accumulator;
  3877. }
  3878. /**
  3879. * A specialized version of `_.reduceRight` 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 last element of `array` as
  3887. * the initial value.
  3888. * @returns {*} Returns the accumulated value.
  3889. */
  3890. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  3891. var length = array == null ? 0 : array.length;
  3892. if (initAccum && length) {
  3893. accumulator = array[--length];
  3894. }
  3895. while (length--) {
  3896. accumulator = iteratee(accumulator, array[length], length, array);
  3897. }
  3898. return accumulator;
  3899. }
  3900. /**
  3901. * A specialized version of `_.some` for arrays without support for iteratee
  3902. * shorthands.
  3903. *
  3904. * @private
  3905. * @param {Array} [array] The array to iterate over.
  3906. * @param {Function} predicate The function invoked per iteration.
  3907. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3908. * else `false`.
  3909. */
  3910. function arraySome(array, predicate) {
  3911. var index = -1,
  3912. length = array == null ? 0 : array.length;
  3913. while (++index < length) {
  3914. if (predicate(array[index], index, array)) {
  3915. return true;
  3916. }
  3917. }
  3918. return false;
  3919. }
  3920. /**
  3921. * Gets the size of an ASCII `string`.
  3922. *
  3923. * @private
  3924. * @param {string} string The string inspect.
  3925. * @returns {number} Returns the string size.
  3926. */
  3927. var asciiSize = baseProperty('length');
  3928. /**
  3929. * Converts an ASCII `string` to an array.
  3930. *
  3931. * @private
  3932. * @param {string} string The string to convert.
  3933. * @returns {Array} Returns the converted array.
  3934. */
  3935. function asciiToArray(string) {
  3936. return string.split('');
  3937. }
  3938. /**
  3939. * Splits an ASCII `string` into an array of its words.
  3940. *
  3941. * @private
  3942. * @param {string} The string to inspect.
  3943. * @returns {Array} Returns the words of `string`.
  3944. */
  3945. function asciiWords(string) {
  3946. return string.match(reAsciiWord) || [];
  3947. }
  3948. /**
  3949. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  3950. * without support for iteratee shorthands, which iterates over `collection`
  3951. * using `eachFunc`.
  3952. *
  3953. * @private
  3954. * @param {Array|Object} collection The collection to inspect.
  3955. * @param {Function} predicate The function invoked per iteration.
  3956. * @param {Function} eachFunc The function to iterate over `collection`.
  3957. * @returns {*} Returns the found element or its key, else `undefined`.
  3958. */
  3959. function baseFindKey(collection, predicate, eachFunc) {
  3960. var result;
  3961. eachFunc(collection, function(value, key, collection) {
  3962. if (predicate(value, key, collection)) {
  3963. result = key;
  3964. return false;
  3965. }
  3966. });
  3967. return result;
  3968. }
  3969. /**
  3970. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  3971. * support for iteratee shorthands.
  3972. *
  3973. * @private
  3974. * @param {Array} array The array to inspect.
  3975. * @param {Function} predicate The function invoked per iteration.
  3976. * @param {number} fromIndex The index to search from.
  3977. * @param {boolean} [fromRight] Specify iterating from right to left.
  3978. * @returns {number} Returns the index of the matched value, else `-1`.
  3979. */
  3980. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  3981. var length = array.length,
  3982. index = fromIndex + (fromRight ? 1 : -1);
  3983. while ((fromRight ? index-- : ++index < length)) {
  3984. if (predicate(array[index], index, array)) {
  3985. return index;
  3986. }
  3987. }
  3988. return -1;
  3989. }
  3990. /**
  3991. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  3992. *
  3993. * @private
  3994. * @param {Array} array The array to inspect.
  3995. * @param {*} value The value to search for.
  3996. * @param {number} fromIndex The index to search from.
  3997. * @returns {number} Returns the index of the matched value, else `-1`.
  3998. */
  3999. function baseIndexOf(array, value, fromIndex) {
  4000. return value === value
  4001. ? strictIndexOf(array, value, fromIndex)
  4002. : baseFindIndex(array, baseIsNaN, fromIndex);
  4003. }
  4004. /**
  4005. * This function is like `baseIndexOf` except that it accepts a comparator.
  4006. *
  4007. * @private
  4008. * @param {Array} array The array to inspect.
  4009. * @param {*} value The value to search for.
  4010. * @param {number} fromIndex The index to search from.
  4011. * @param {Function} comparator The comparator invoked per element.
  4012. * @returns {number} Returns the index of the matched value, else `-1`.
  4013. */
  4014. function baseIndexOfWith(array, value, fromIndex, comparator) {
  4015. var index = fromIndex - 1,
  4016. length = array.length;
  4017. while (++index < length) {
  4018. if (comparator(array[index], value)) {
  4019. return index;
  4020. }
  4021. }
  4022. return -1;
  4023. }
  4024. /**
  4025. * The base implementation of `_.isNaN` without support for number objects.
  4026. *
  4027. * @private
  4028. * @param {*} value The value to check.
  4029. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  4030. */
  4031. function baseIsNaN(value) {
  4032. return value !== value;
  4033. }
  4034. /**
  4035. * The base implementation of `_.mean` and `_.meanBy` without support for
  4036. * iteratee shorthands.
  4037. *
  4038. * @private
  4039. * @param {Array} array The array to iterate over.
  4040. * @param {Function} iteratee The function invoked per iteration.
  4041. * @returns {number} Returns the mean.
  4042. */
  4043. function baseMean(array, iteratee) {
  4044. var length = array == null ? 0 : array.length;
  4045. return length ? (baseSum(array, iteratee) / length) : NAN;
  4046. }
  4047. /**
  4048. * The base implementation of `_.property` without support for deep paths.
  4049. *
  4050. * @private
  4051. * @param {string} key The key of the property to get.
  4052. * @returns {Function} Returns the new accessor function.
  4053. */
  4054. function baseProperty(key) {
  4055. return function(object) {
  4056. return object == null ? undefined : object[key];
  4057. };
  4058. }
  4059. /**
  4060. * The base implementation of `_.propertyOf` without support for deep paths.
  4061. *
  4062. * @private
  4063. * @param {Object} object The object to query.
  4064. * @returns {Function} Returns the new accessor function.
  4065. */
  4066. function basePropertyOf(object) {
  4067. return function(key) {
  4068. return object == null ? undefined : object[key];
  4069. };
  4070. }
  4071. /**
  4072. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  4073. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  4074. *
  4075. * @private
  4076. * @param {Array|Object} collection The collection to iterate over.
  4077. * @param {Function} iteratee The function invoked per iteration.
  4078. * @param {*} accumulator The initial value.
  4079. * @param {boolean} initAccum Specify using the first or last element of
  4080. * `collection` as the initial value.
  4081. * @param {Function} eachFunc The function to iterate over `collection`.
  4082. * @returns {*} Returns the accumulated value.
  4083. */
  4084. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  4085. eachFunc(collection, function(value, index, collection) {
  4086. accumulator = initAccum
  4087. ? (initAccum = false, value)
  4088. : iteratee(accumulator, value, index, collection);
  4089. });
  4090. return accumulator;
  4091. }
  4092. /**
  4093. * The base implementation of `_.sortBy` which uses `comparer` to define the
  4094. * sort order of `array` and replaces criteria objects with their corresponding
  4095. * values.
  4096. *
  4097. * @private
  4098. * @param {Array} array The array to sort.
  4099. * @param {Function} comparer The function to define sort order.
  4100. * @returns {Array} Returns `array`.
  4101. */
  4102. function baseSortBy(array, comparer) {
  4103. var length = array.length;
  4104. array.sort(comparer);
  4105. while (length--) {
  4106. array[length] = array[length].value;
  4107. }
  4108. return array;
  4109. }
  4110. /**
  4111. * The base implementation of `_.sum` and `_.sumBy` without support for
  4112. * iteratee shorthands.
  4113. *
  4114. * @private
  4115. * @param {Array} array The array to iterate over.
  4116. * @param {Function} iteratee The function invoked per iteration.
  4117. * @returns {number} Returns the sum.
  4118. */
  4119. function baseSum(array, iteratee) {
  4120. var result,
  4121. index = -1,
  4122. length = array.length;
  4123. while (++index < length) {
  4124. var current = iteratee(array[index]);
  4125. if (current !== undefined) {
  4126. result = result === undefined ? current : (result + current);
  4127. }
  4128. }
  4129. return result;
  4130. }
  4131. /**
  4132. * The base implementation of `_.times` without support for iteratee shorthands
  4133. * or max array length checks.
  4134. *
  4135. * @private
  4136. * @param {number} n The number of times to invoke `iteratee`.
  4137. * @param {Function} iteratee The function invoked per iteration.
  4138. * @returns {Array} Returns the array of results.
  4139. */
  4140. function baseTimes(n, iteratee) {
  4141. var index = -1,
  4142. result = Array(n);
  4143. while (++index < n) {
  4144. result[index] = iteratee(index);
  4145. }
  4146. return result;
  4147. }
  4148. /**
  4149. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  4150. * of key-value pairs for `object` corresponding to the property names of `props`.
  4151. *
  4152. * @private
  4153. * @param {Object} object The object to query.
  4154. * @param {Array} props The property names to get values for.
  4155. * @returns {Object} Returns the key-value pairs.
  4156. */
  4157. function baseToPairs(object, props) {
  4158. return arrayMap(props, function(key) {
  4159. return [key, object[key]];
  4160. });
  4161. }
  4162. /**
  4163. * The base implementation of `_.trim`.
  4164. *
  4165. * @private
  4166. * @param {string} string The string to trim.
  4167. * @returns {string} Returns the trimmed string.
  4168. */
  4169. function baseTrim(string) {
  4170. return string
  4171. ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
  4172. : string;
  4173. }
  4174. /**
  4175. * The base implementation of `_.unary` without support for storing metadata.
  4176. *
  4177. * @private
  4178. * @param {Function} func The function to cap arguments for.
  4179. * @returns {Function} Returns the new capped function.
  4180. */
  4181. function baseUnary(func) {
  4182. return function(value) {
  4183. return func(value);
  4184. };
  4185. }
  4186. /**
  4187. * The base implementation of `_.values` and `_.valuesIn` which creates an
  4188. * array of `object` property values corresponding to the property names
  4189. * of `props`.
  4190. *
  4191. * @private
  4192. * @param {Object} object The object to query.
  4193. * @param {Array} props The property names to get values for.
  4194. * @returns {Object} Returns the array of property values.
  4195. */
  4196. function baseValues(object, props) {
  4197. return arrayMap(props, function(key) {
  4198. return object[key];
  4199. });
  4200. }
  4201. /**
  4202. * Checks if a `cache` value for `key` exists.
  4203. *
  4204. * @private
  4205. * @param {Object} cache The cache to query.
  4206. * @param {string} key The key of the entry to check.
  4207. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  4208. */
  4209. function cacheHas(cache, key) {
  4210. return cache.has(key);
  4211. }
  4212. /**
  4213. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  4214. * that is not found in the character symbols.
  4215. *
  4216. * @private
  4217. * @param {Array} strSymbols The string symbols to inspect.
  4218. * @param {Array} chrSymbols The character symbols to find.
  4219. * @returns {number} Returns the index of the first unmatched string symbol.
  4220. */
  4221. function charsStartIndex(strSymbols, chrSymbols) {
  4222. var index = -1,
  4223. length = strSymbols.length;
  4224. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  4225. return index;
  4226. }
  4227. /**
  4228. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  4229. * that is not found in the character symbols.
  4230. *
  4231. * @private
  4232. * @param {Array} strSymbols The string symbols to inspect.
  4233. * @param {Array} chrSymbols The character symbols to find.
  4234. * @returns {number} Returns the index of the last unmatched string symbol.
  4235. */
  4236. function charsEndIndex(strSymbols, chrSymbols) {
  4237. var index = strSymbols.length;
  4238. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  4239. return index;
  4240. }
  4241. /**
  4242. * Gets the number of `placeholder` occurrences in `array`.
  4243. *
  4244. * @private
  4245. * @param {Array} array The array to inspect.
  4246. * @param {*} placeholder The placeholder to search for.
  4247. * @returns {number} Returns the placeholder count.
  4248. */
  4249. function countHolders(array, placeholder) {
  4250. var length = array.length,
  4251. result = 0;
  4252. while (length--) {
  4253. if (array[length] === placeholder) {
  4254. ++result;
  4255. }
  4256. }
  4257. return result;
  4258. }
  4259. /**
  4260. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  4261. * letters to basic Latin letters.
  4262. *
  4263. * @private
  4264. * @param {string} letter The matched letter to deburr.
  4265. * @returns {string} Returns the deburred letter.
  4266. */
  4267. var deburrLetter = basePropertyOf(deburredLetters);
  4268. /**
  4269. * Used by `_.escape` to convert characters to HTML entities.
  4270. *
  4271. * @private
  4272. * @param {string} chr The matched character to escape.
  4273. * @returns {string} Returns the escaped character.
  4274. */
  4275. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  4276. /**
  4277. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  4278. *
  4279. * @private
  4280. * @param {string} chr The matched character to escape.
  4281. * @returns {string} Returns the escaped character.
  4282. */
  4283. function escapeStringChar(chr) {
  4284. return '\\' + stringEscapes[chr];
  4285. }
  4286. /**
  4287. * Gets the value at `key` of `object`.
  4288. *
  4289. * @private
  4290. * @param {Object} [object] The object to query.
  4291. * @param {string} key The key of the property to get.
  4292. * @returns {*} Returns the property value.
  4293. */
  4294. function getValue(object, key) {
  4295. return object == null ? undefined : object[key];
  4296. }
  4297. /**
  4298. * Checks if `string` contains Unicode symbols.
  4299. *
  4300. * @private
  4301. * @param {string} string The string to inspect.
  4302. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  4303. */
  4304. function hasUnicode(string) {
  4305. return reHasUnicode.test(string);
  4306. }
  4307. /**
  4308. * Checks if `string` contains a word composed of Unicode symbols.
  4309. *
  4310. * @private
  4311. * @param {string} string The string to inspect.
  4312. * @returns {boolean} Returns `true` if a word is found, else `false`.
  4313. */
  4314. function hasUnicodeWord(string) {
  4315. return reHasUnicodeWord.test(string);
  4316. }
  4317. /**
  4318. * Converts `iterator` to an array.
  4319. *
  4320. * @private
  4321. * @param {Object} iterator The iterator to convert.
  4322. * @returns {Array} Returns the converted array.
  4323. */
  4324. function iteratorToArray(iterator) {
  4325. var data,
  4326. result = [];
  4327. while (!(data = iterator.next()).done) {
  4328. result.push(data.value);
  4329. }
  4330. return result;
  4331. }
  4332. /**
  4333. * Converts `map` to its key-value pairs.
  4334. *
  4335. * @private
  4336. * @param {Object} map The map to convert.
  4337. * @returns {Array} Returns the key-value pairs.
  4338. */
  4339. function mapToArray(map) {
  4340. var index = -1,
  4341. result = Array(map.size);
  4342. map.forEach(function(value, key) {
  4343. result[++index] = [key, value];
  4344. });
  4345. return result;
  4346. }
  4347. /**
  4348. * Creates a unary function that invokes `func` with its argument transformed.
  4349. *
  4350. * @private
  4351. * @param {Function} func The function to wrap.
  4352. * @param {Function} transform The argument transform.
  4353. * @returns {Function} Returns the new function.
  4354. */
  4355. function overArg(func, transform) {
  4356. return function(arg) {
  4357. return func(transform(arg));
  4358. };
  4359. }
  4360. /**
  4361. * Replaces all `placeholder` elements in `array` with an internal placeholder
  4362. * and returns an array of their indexes.
  4363. *
  4364. * @private
  4365. * @param {Array} array The array to modify.
  4366. * @param {*} placeholder The placeholder to replace.
  4367. * @returns {Array} Returns the new array of placeholder indexes.
  4368. */
  4369. function replaceHolders(array, placeholder) {
  4370. var index = -1,
  4371. length = array.length,
  4372. resIndex = 0,
  4373. result = [];
  4374. while (++index < length) {
  4375. var value = array[index];
  4376. if (value === placeholder || value === PLACEHOLDER) {
  4377. array[index] = PLACEHOLDER;
  4378. result[resIndex++] = index;
  4379. }
  4380. }
  4381. return result;
  4382. }
  4383. /**
  4384. * Converts `set` to an array of its values.
  4385. *
  4386. * @private
  4387. * @param {Object} set The set to convert.
  4388. * @returns {Array} Returns the values.
  4389. */
  4390. function setToArray(set) {
  4391. var index = -1,
  4392. result = Array(set.size);
  4393. set.forEach(function(value) {
  4394. result[++index] = value;
  4395. });
  4396. return result;
  4397. }
  4398. /**
  4399. * Converts `set` to its value-value pairs.
  4400. *
  4401. * @private
  4402. * @param {Object} set The set to convert.
  4403. * @returns {Array} Returns the value-value pairs.
  4404. */
  4405. function setToPairs(set) {
  4406. var index = -1,
  4407. result = Array(set.size);
  4408. set.forEach(function(value) {
  4409. result[++index] = [value, value];
  4410. });
  4411. return result;
  4412. }
  4413. /**
  4414. * A specialized version of `_.indexOf` which performs strict equality
  4415. * comparisons of values, i.e. `===`.
  4416. *
  4417. * @private
  4418. * @param {Array} array The array to inspect.
  4419. * @param {*} value The value to search for.
  4420. * @param {number} fromIndex The index to search from.
  4421. * @returns {number} Returns the index of the matched value, else `-1`.
  4422. */
  4423. function strictIndexOf(array, value, fromIndex) {
  4424. var index = fromIndex - 1,
  4425. length = array.length;
  4426. while (++index < length) {
  4427. if (array[index] === value) {
  4428. return index;
  4429. }
  4430. }
  4431. return -1;
  4432. }
  4433. /**
  4434. * A specialized version of `_.lastIndexOf` which performs strict equality
  4435. * comparisons of values, i.e. `===`.
  4436. *
  4437. * @private
  4438. * @param {Array} array The array to inspect.
  4439. * @param {*} value The value to search for.
  4440. * @param {number} fromIndex The index to search from.
  4441. * @returns {number} Returns the index of the matched value, else `-1`.
  4442. */
  4443. function strictLastIndexOf(array, value, fromIndex) {
  4444. var index = fromIndex + 1;
  4445. while (index--) {
  4446. if (array[index] === value) {
  4447. return index;
  4448. }
  4449. }
  4450. return index;
  4451. }
  4452. /**
  4453. * Gets the number of symbols in `string`.
  4454. *
  4455. * @private
  4456. * @param {string} string The string to inspect.
  4457. * @returns {number} Returns the string size.
  4458. */
  4459. function stringSize(string) {
  4460. return hasUnicode(string)
  4461. ? unicodeSize(string)
  4462. : asciiSize(string);
  4463. }
  4464. /**
  4465. * Converts `string` to an array.
  4466. *
  4467. * @private
  4468. * @param {string} string The string to convert.
  4469. * @returns {Array} Returns the converted array.
  4470. */
  4471. function stringToArray(string) {
  4472. return hasUnicode(string)
  4473. ? unicodeToArray(string)
  4474. : asciiToArray(string);
  4475. }
  4476. /**
  4477. * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
  4478. * character of `string`.
  4479. *
  4480. * @private
  4481. * @param {string} string The string to inspect.
  4482. * @returns {number} Returns the index of the last non-whitespace character.
  4483. */
  4484. function trimmedEndIndex(string) {
  4485. var index = string.length;
  4486. while (index-- && reWhitespace.test(string.charAt(index))) {}
  4487. return index;
  4488. }
  4489. /**
  4490. * Used by `_.unescape` to convert HTML entities to characters.
  4491. *
  4492. * @private
  4493. * @param {string} chr The matched character to unescape.
  4494. * @returns {string} Returns the unescaped character.
  4495. */
  4496. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  4497. /**
  4498. * Gets the size of a Unicode `string`.
  4499. *
  4500. * @private
  4501. * @param {string} string The string inspect.
  4502. * @returns {number} Returns the string size.
  4503. */
  4504. function unicodeSize(string) {
  4505. var result = reUnicode.lastIndex = 0;
  4506. while (reUnicode.test(string)) {
  4507. ++result;
  4508. }
  4509. return result;
  4510. }
  4511. /**
  4512. * Converts a Unicode `string` to an array.
  4513. *
  4514. * @private
  4515. * @param {string} string The string to convert.
  4516. * @returns {Array} Returns the converted array.
  4517. */
  4518. function unicodeToArray(string) {
  4519. return string.match(reUnicode) || [];
  4520. }
  4521. /**
  4522. * Splits a Unicode `string` into an array of its words.
  4523. *
  4524. * @private
  4525. * @param {string} The string to inspect.
  4526. * @returns {Array} Returns the words of `string`.
  4527. */
  4528. function unicodeWords(string) {
  4529. return string.match(reUnicodeWord) || [];
  4530. }
  4531. /*--------------------------------------------------------------------------*/
  4532. /**
  4533. * Create a new pristine `lodash` function using the `context` object.
  4534. *
  4535. * @static
  4536. * @memberOf _
  4537. * @since 1.1.0
  4538. * @category Util
  4539. * @param {Object} [context=root] The context object.
  4540. * @returns {Function} Returns a new `lodash` function.
  4541. * @example
  4542. *
  4543. * _.mixin({ 'foo': _.constant('foo') });
  4544. *
  4545. * var lodash = _.runInContext();
  4546. * lodash.mixin({ 'bar': lodash.constant('bar') });
  4547. *
  4548. * _.isFunction(_.foo);
  4549. * // => true
  4550. * _.isFunction(_.bar);
  4551. * // => false
  4552. *
  4553. * lodash.isFunction(lodash.foo);
  4554. * // => false
  4555. * lodash.isFunction(lodash.bar);
  4556. * // => true
  4557. *
  4558. * // Create a suped-up `defer` in Node.js.
  4559. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  4560. */
  4561. var runInContext = (function runInContext(context) {
  4562. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  4563. /** Built-in constructor references. */
  4564. var Array = context.Array,
  4565. Date = context.Date,
  4566. Error = context.Error,
  4567. Function = context.Function,
  4568. Math = context.Math,
  4569. Object = context.Object,
  4570. RegExp = context.RegExp,
  4571. String = context.String,
  4572. TypeError = context.TypeError;
  4573. /** Used for built-in method references. */
  4574. var arrayProto = Array.prototype,
  4575. funcProto = Function.prototype,
  4576. objectProto = Object.prototype;
  4577. /** Used to detect overreaching core-js shims. */
  4578. var coreJsData = context['__core-js_shared__'];
  4579. /** Used to resolve the decompiled source of functions. */
  4580. var funcToString = funcProto.toString;
  4581. /** Used to check objects for own properties. */
  4582. var hasOwnProperty = objectProto.hasOwnProperty;
  4583. /** Used to generate unique IDs. */
  4584. var idCounter = 0;
  4585. /** Used to detect methods masquerading as native. */
  4586. var maskSrcKey = (function() {
  4587. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  4588. return uid ? ('Symbol(src)_1.' + uid) : '';
  4589. }());
  4590. /**
  4591. * Used to resolve the
  4592. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  4593. * of values.
  4594. */
  4595. var nativeObjectToString = objectProto.toString;
  4596. /** Used to infer the `Object` constructor. */
  4597. var objectCtorString = funcToString.call(Object);
  4598. /** Used to restore the original `_` reference in `_.noConflict`. */
  4599. var oldDash = root._;
  4600. /** Used to detect if a method is native. */
  4601. var reIsNative = RegExp('^' +
  4602. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  4603. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  4604. );
  4605. /** Built-in value references. */
  4606. var Buffer = moduleExports ? context.Buffer : undefined,
  4607. Symbol = context.Symbol,
  4608. Uint8Array = context.Uint8Array,
  4609. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  4610. getPrototype = overArg(Object.getPrototypeOf, Object),
  4611. objectCreate = Object.create,
  4612. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  4613. splice = arrayProto.splice,
  4614. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  4615. symIterator = Symbol ? Symbol.iterator : undefined,
  4616. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  4617. var defineProperty = (function() {
  4618. try {
  4619. var func = getNative(Object, 'defineProperty');
  4620. func({}, '', {});
  4621. return func;
  4622. } catch (e) {}
  4623. }());
  4624. /** Mocked built-ins. */
  4625. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  4626. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  4627. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  4628. /* Built-in method references for those with the same name as other `lodash` methods. */
  4629. var nativeCeil = Math.ceil,
  4630. nativeFloor = Math.floor,
  4631. nativeGetSymbols = Object.getOwnPropertySymbols,
  4632. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  4633. nativeIsFinite = context.isFinite,
  4634. nativeJoin = arrayProto.join,
  4635. nativeKeys = overArg(Object.keys, Object),
  4636. nativeMax = Math.max,
  4637. nativeMin = Math.min,
  4638. nativeNow = Date.now,
  4639. nativeParseInt = context.parseInt,
  4640. nativeRandom = Math.random,
  4641. nativeReverse = arrayProto.reverse;
  4642. /* Built-in method references that are verified to be native. */
  4643. var DataView = getNative(context, 'DataView'),
  4644. Map = getNative(context, 'Map'),
  4645. Promise = getNative(context, 'Promise'),
  4646. Set = getNative(context, 'Set'),
  4647. WeakMap = getNative(context, 'WeakMap'),
  4648. nativeCreate = getNative(Object, 'create');
  4649. /** Used to store function metadata. */
  4650. var metaMap = WeakMap && new WeakMap;
  4651. /** Used to lookup unminified function names. */
  4652. var realNames = {};
  4653. /** Used to detect maps, sets, and weakmaps. */
  4654. var dataViewCtorString = toSource(DataView),
  4655. mapCtorString = toSource(Map),
  4656. promiseCtorString = toSource(Promise),
  4657. setCtorString = toSource(Set),
  4658. weakMapCtorString = toSource(WeakMap);
  4659. /** Used to convert symbols to primitives and strings. */
  4660. var symbolProto = Symbol ? Symbol.prototype : undefined,
  4661. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  4662. symbolToString = symbolProto ? symbolProto.toString : undefined;
  4663. /*------------------------------------------------------------------------*/
  4664. /**
  4665. * Creates a `lodash` object which wraps `value` to enable implicit method
  4666. * chain sequences. Methods that operate on and return arrays, collections,
  4667. * and functions can be chained together. Methods that retrieve a single value
  4668. * or may return a primitive value will automatically end the chain sequence
  4669. * and return the unwrapped value. Otherwise, the value must be unwrapped
  4670. * with `_#value`.
  4671. *
  4672. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  4673. * enabled using `_.chain`.
  4674. *
  4675. * The execution of chained methods is lazy, that is, it's deferred until
  4676. * `_#value` is implicitly or explicitly called.
  4677. *
  4678. * Lazy evaluation allows several methods to support shortcut fusion.
  4679. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  4680. * the creation of intermediate arrays and can greatly reduce the number of
  4681. * iteratee executions. Sections of a chain sequence qualify for shortcut
  4682. * fusion if the section is applied to an array and iteratees accept only
  4683. * one argument. The heuristic for whether a section qualifies for shortcut
  4684. * fusion is subject to change.
  4685. *
  4686. * Chaining is supported in custom builds as long as the `_#value` method is
  4687. * directly or indirectly included in the build.
  4688. *
  4689. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  4690. *
  4691. * The wrapper `Array` methods are:
  4692. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  4693. *
  4694. * The wrapper `String` methods are:
  4695. * `replace` and `split`
  4696. *
  4697. * The wrapper methods that support shortcut fusion are:
  4698. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  4699. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  4700. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  4701. *
  4702. * The chainable wrapper methods are:
  4703. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  4704. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  4705. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  4706. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  4707. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  4708. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  4709. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  4710. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  4711. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  4712. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  4713. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  4714. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  4715. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  4716. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  4717. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  4718. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  4719. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  4720. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  4721. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  4722. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  4723. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  4724. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  4725. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  4726. * `zipObject`, `zipObjectDeep`, and `zipWith`
  4727. *
  4728. * The wrapper methods that are **not** chainable by default are:
  4729. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  4730. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  4731. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  4732. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  4733. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  4734. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  4735. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  4736. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  4737. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  4738. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  4739. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  4740. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  4741. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  4742. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  4743. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  4744. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  4745. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  4746. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  4747. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  4748. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  4749. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  4750. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  4751. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  4752. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  4753. * `upperFirst`, `value`, and `words`
  4754. *
  4755. * @name _
  4756. * @constructor
  4757. * @category Seq
  4758. * @param {*} value The value to wrap in a `lodash` instance.
  4759. * @returns {Object} Returns the new `lodash` wrapper instance.
  4760. * @example
  4761. *
  4762. * function square(n) {
  4763. * return n * n;
  4764. * }
  4765. *
  4766. * var wrapped = _([1, 2, 3]);
  4767. *
  4768. * // Returns an unwrapped value.
  4769. * wrapped.reduce(_.add);
  4770. * // => 6
  4771. *
  4772. * // Returns a wrapped value.
  4773. * var squares = wrapped.map(square);
  4774. *
  4775. * _.isArray(squares);
  4776. * // => false
  4777. *
  4778. * _.isArray(squares.value());
  4779. * // => true
  4780. */
  4781. function lodash(value) {
  4782. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  4783. if (value instanceof LodashWrapper) {
  4784. return value;
  4785. }
  4786. if (hasOwnProperty.call(value, '__wrapped__')) {
  4787. return wrapperClone(value);
  4788. }
  4789. }
  4790. return new LodashWrapper(value);
  4791. }
  4792. /**
  4793. * The base implementation of `_.create` without support for assigning
  4794. * properties to the created object.
  4795. *
  4796. * @private
  4797. * @param {Object} proto The object to inherit from.
  4798. * @returns {Object} Returns the new object.
  4799. */
  4800. var baseCreate = (function() {
  4801. function object() {}
  4802. return function(proto) {
  4803. if (!isObject(proto)) {
  4804. return {};
  4805. }
  4806. if (objectCreate) {
  4807. return objectCreate(proto);
  4808. }
  4809. object.prototype = proto;
  4810. var result = new object;
  4811. object.prototype = undefined;
  4812. return result;
  4813. };
  4814. }());
  4815. /**
  4816. * The function whose prototype chain sequence wrappers inherit from.
  4817. *
  4818. * @private
  4819. */
  4820. function baseLodash() {
  4821. // No operation performed.
  4822. }
  4823. /**
  4824. * The base constructor for creating `lodash` wrapper objects.
  4825. *
  4826. * @private
  4827. * @param {*} value The value to wrap.
  4828. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  4829. */
  4830. function LodashWrapper(value, chainAll) {
  4831. this.__wrapped__ = value;
  4832. this.__actions__ = [];
  4833. this.__chain__ = !!chainAll;
  4834. this.__index__ = 0;
  4835. this.__values__ = undefined;
  4836. }
  4837. /**
  4838. * By default, the template delimiters used by lodash are like those in
  4839. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  4840. * following template settings to use alternative delimiters.
  4841. *
  4842. * @static
  4843. * @memberOf _
  4844. * @type {Object}
  4845. */
  4846. lodash.templateSettings = {
  4847. /**
  4848. * Used to detect `data` property values to be HTML-escaped.
  4849. *
  4850. * @memberOf _.templateSettings
  4851. * @type {RegExp}
  4852. */
  4853. 'escape': reEscape,
  4854. /**
  4855. * Used to detect code to be evaluated.
  4856. *
  4857. * @memberOf _.templateSettings
  4858. * @type {RegExp}
  4859. */
  4860. 'evaluate': reEvaluate,
  4861. /**
  4862. * Used to detect `data` property values to inject.
  4863. *
  4864. * @memberOf _.templateSettings
  4865. * @type {RegExp}
  4866. */
  4867. 'interpolate': reInterpolate,
  4868. /**
  4869. * Used to reference the data object in the template text.
  4870. *
  4871. * @memberOf _.templateSettings
  4872. * @type {string}
  4873. */
  4874. 'variable': '',
  4875. /**
  4876. * Used to import variables into the compiled template.
  4877. *
  4878. * @memberOf _.templateSettings
  4879. * @type {Object}
  4880. */
  4881. 'imports': {
  4882. /**
  4883. * A reference to the `lodash` function.
  4884. *
  4885. * @memberOf _.templateSettings.imports
  4886. * @type {Function}
  4887. */
  4888. '_': lodash
  4889. }
  4890. };
  4891. // Ensure wrappers are instances of `baseLodash`.
  4892. lodash.prototype = baseLodash.prototype;
  4893. lodash.prototype.constructor = lodash;
  4894. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  4895. LodashWrapper.prototype.constructor = LodashWrapper;
  4896. /*------------------------------------------------------------------------*/
  4897. /**
  4898. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  4899. *
  4900. * @private
  4901. * @constructor
  4902. * @param {*} value The value to wrap.
  4903. */
  4904. function LazyWrapper(value) {
  4905. this.__wrapped__ = value;
  4906. this.__actions__ = [];
  4907. this.__dir__ = 1;
  4908. this.__filtered__ = false;
  4909. this.__iteratees__ = [];
  4910. this.__takeCount__ = MAX_ARRAY_LENGTH;
  4911. this.__views__ = [];
  4912. }
  4913. /**
  4914. * Creates a clone of the lazy wrapper object.
  4915. *
  4916. * @private
  4917. * @name clone
  4918. * @memberOf LazyWrapper
  4919. * @returns {Object} Returns the cloned `LazyWrapper` object.
  4920. */
  4921. function lazyClone() {
  4922. var result = new LazyWrapper(this.__wrapped__);
  4923. result.__actions__ = copyArray(this.__actions__);
  4924. result.__dir__ = this.__dir__;
  4925. result.__filtered__ = this.__filtered__;
  4926. result.__iteratees__ = copyArray(this.__iteratees__);
  4927. result.__takeCount__ = this.__takeCount__;
  4928. result.__views__ = copyArray(this.__views__);
  4929. return result;
  4930. }
  4931. /**
  4932. * Reverses the direction of lazy iteration.
  4933. *
  4934. * @private
  4935. * @name reverse
  4936. * @memberOf LazyWrapper
  4937. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  4938. */
  4939. function lazyReverse() {
  4940. if (this.__filtered__) {
  4941. var result = new LazyWrapper(this);
  4942. result.__dir__ = -1;
  4943. result.__filtered__ = true;
  4944. } else {
  4945. result = this.clone();
  4946. result.__dir__ *= -1;
  4947. }
  4948. return result;
  4949. }
  4950. /**
  4951. * Extracts the unwrapped value from its lazy wrapper.
  4952. *
  4953. * @private
  4954. * @name value
  4955. * @memberOf LazyWrapper
  4956. * @returns {*} Returns the unwrapped value.
  4957. */
  4958. function lazyValue() {
  4959. var array = this.__wrapped__.value(),
  4960. dir = this.__dir__,
  4961. isArr = isArray(array),
  4962. isRight = dir < 0,
  4963. arrLength = isArr ? array.length : 0,
  4964. view = getView(0, arrLength, this.__views__),
  4965. start = view.start,
  4966. end = view.end,
  4967. length = end - start,
  4968. index = isRight ? end : (start - 1),
  4969. iteratees = this.__iteratees__,
  4970. iterLength = iteratees.length,
  4971. resIndex = 0,
  4972. takeCount = nativeMin(length, this.__takeCount__);
  4973. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  4974. return baseWrapperValue(array, this.__actions__);
  4975. }
  4976. var result = [];
  4977. outer:
  4978. while (length-- && resIndex < takeCount) {
  4979. index += dir;
  4980. var iterIndex = -1,
  4981. value = array[index];
  4982. while (++iterIndex < iterLength) {
  4983. var data = iteratees[iterIndex],
  4984. iteratee = data.iteratee,
  4985. type = data.type,
  4986. computed = iteratee(value);
  4987. if (type == LAZY_MAP_FLAG) {
  4988. value = computed;
  4989. } else if (!computed) {
  4990. if (type == LAZY_FILTER_FLAG) {
  4991. continue outer;
  4992. } else {
  4993. break outer;
  4994. }
  4995. }
  4996. }
  4997. result[resIndex++] = value;
  4998. }
  4999. return result;
  5000. }
  5001. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  5002. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  5003. LazyWrapper.prototype.constructor = LazyWrapper;
  5004. /*------------------------------------------------------------------------*/
  5005. /**
  5006. * Creates a hash object.
  5007. *
  5008. * @private
  5009. * @constructor
  5010. * @param {Array} [entries] The key-value pairs to cache.
  5011. */
  5012. function Hash(entries) {
  5013. var index = -1,
  5014. length = entries == null ? 0 : entries.length;
  5015. this.clear();
  5016. while (++index < length) {
  5017. var entry = entries[index];
  5018. this.set(entry[0], entry[1]);
  5019. }
  5020. }
  5021. /**
  5022. * Removes all key-value entries from the hash.
  5023. *
  5024. * @private
  5025. * @name clear
  5026. * @memberOf Hash
  5027. */
  5028. function hashClear() {
  5029. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  5030. this.size = 0;
  5031. }
  5032. /**
  5033. * Removes `key` and its value from the hash.
  5034. *
  5035. * @private
  5036. * @name delete
  5037. * @memberOf Hash
  5038. * @param {Object} hash The hash to modify.
  5039. * @param {string} key The key of the value to remove.
  5040. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  5041. */
  5042. function hashDelete(key) {
  5043. var result = this.has(key) && delete this.__data__[key];
  5044. this.size -= result ? 1 : 0;
  5045. return result;
  5046. }
  5047. /**
  5048. * Gets the hash value for `key`.
  5049. *
  5050. * @private
  5051. * @name get
  5052. * @memberOf Hash
  5053. * @param {string} key The key of the value to get.
  5054. * @returns {*} Returns the entry value.
  5055. */
  5056. function hashGet(key) {
  5057. var data = this.__data__;
  5058. if (nativeCreate) {
  5059. var result = data[key];
  5060. return result === HASH_UNDEFINED ? undefined : result;
  5061. }
  5062. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  5063. }
  5064. /**
  5065. * Checks if a hash value for `key` exists.
  5066. *
  5067. * @private
  5068. * @name has
  5069. * @memberOf Hash
  5070. * @param {string} key The key of the entry to check.
  5071. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  5072. */
  5073. function hashHas(key) {
  5074. var data = this.__data__;
  5075. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  5076. }
  5077. /**
  5078. * Sets the hash `key` to `value`.
  5079. *
  5080. * @private
  5081. * @name set
  5082. * @memberOf Hash
  5083. * @param {string} key The key of the value to set.
  5084. * @param {*} value The value to set.
  5085. * @returns {Object} Returns the hash instance.
  5086. */
  5087. function hashSet(key, value) {
  5088. var data = this.__data__;
  5089. this.size += this.has(key) ? 0 : 1;
  5090. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  5091. return this;
  5092. }
  5093. // Add methods to `Hash`.
  5094. Hash.prototype.clear = hashClear;
  5095. Hash.prototype['delete'] = hashDelete;
  5096. Hash.prototype.get = hashGet;
  5097. Hash.prototype.has = hashHas;
  5098. Hash.prototype.set = hashSet;
  5099. /*------------------------------------------------------------------------*/
  5100. /**
  5101. * Creates an list cache object.
  5102. *
  5103. * @private
  5104. * @constructor
  5105. * @param {Array} [entries] The key-value pairs to cache.
  5106. */
  5107. function ListCache(entries) {
  5108. var index = -1,
  5109. length = entries == null ? 0 : entries.length;
  5110. this.clear();
  5111. while (++index < length) {
  5112. var entry = entries[index];
  5113. this.set(entry[0], entry[1]);
  5114. }
  5115. }
  5116. /**
  5117. * Removes all key-value entries from the list cache.
  5118. *
  5119. * @private
  5120. * @name clear
  5121. * @memberOf ListCache
  5122. */
  5123. function listCacheClear() {
  5124. this.__data__ = [];
  5125. this.size = 0;
  5126. }
  5127. /**
  5128. * Removes `key` and its value from the list cache.
  5129. *
  5130. * @private
  5131. * @name delete
  5132. * @memberOf ListCache
  5133. * @param {string} key The key of the value to remove.
  5134. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  5135. */
  5136. function listCacheDelete(key) {
  5137. var data = this.__data__,
  5138. index = assocIndexOf(data, key);
  5139. if (index < 0) {
  5140. return false;
  5141. }
  5142. var lastIndex = data.length - 1;
  5143. if (index == lastIndex) {
  5144. data.pop();
  5145. } else {
  5146. splice.call(data, index, 1);
  5147. }
  5148. --this.size;
  5149. return true;
  5150. }
  5151. /**
  5152. * Gets the list cache value for `key`.
  5153. *
  5154. * @private
  5155. * @name get
  5156. * @memberOf ListCache
  5157. * @param {string} key The key of the value to get.
  5158. * @returns {*} Returns the entry value.
  5159. */
  5160. function listCacheGet(key) {
  5161. var data = this.__data__,
  5162. index = assocIndexOf(data, key);
  5163. return index < 0 ? undefined : data[index][1];
  5164. }
  5165. /**
  5166. * Checks if a list cache value for `key` exists.
  5167. *
  5168. * @private
  5169. * @name has
  5170. * @memberOf ListCache
  5171. * @param {string} key The key of the entry to check.
  5172. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  5173. */
  5174. function listCacheHas(key) {
  5175. return assocIndexOf(this.__data__, key) > -1;
  5176. }
  5177. /**
  5178. * Sets the list cache `key` to `value`.
  5179. *
  5180. * @private
  5181. * @name set
  5182. * @memberOf ListCache
  5183. * @param {string} key The key of the value to set.
  5184. * @param {*} value The value to set.
  5185. * @returns {Object} Returns the list cache instance.
  5186. */
  5187. function listCacheSet(key, value) {
  5188. var data = this.__data__,
  5189. index = assocIndexOf(data, key);
  5190. if (index < 0) {
  5191. ++this.size;
  5192. data.push([key, value]);
  5193. } else {
  5194. data[index][1] = value;
  5195. }
  5196. return this;
  5197. }
  5198. // Add methods to `ListCache`.
  5199. ListCache.prototype.clear = listCacheClear;
  5200. ListCache.prototype['delete'] = listCacheDelete;
  5201. ListCache.prototype.get = listCacheGet;
  5202. ListCache.prototype.has = listCacheHas;
  5203. ListCache.prototype.set = listCacheSet;
  5204. /*------------------------------------------------------------------------*/
  5205. /**
  5206. * Creates a map cache object to store key-value pairs.
  5207. *
  5208. * @private
  5209. * @constructor
  5210. * @param {Array} [entries] The key-value pairs to cache.
  5211. */
  5212. function MapCache(entries) {
  5213. var index = -1,
  5214. length = entries == null ? 0 : entries.length;
  5215. this.clear();
  5216. while (++index < length) {
  5217. var entry = entries[index];
  5218. this.set(entry[0], entry[1]);
  5219. }
  5220. }
  5221. /**
  5222. * Removes all key-value entries from the map.
  5223. *
  5224. * @private
  5225. * @name clear
  5226. * @memberOf MapCache
  5227. */
  5228. function mapCacheClear() {
  5229. this.size = 0;
  5230. this.__data__ = {
  5231. 'hash': new Hash,
  5232. 'map': new (Map || ListCache),
  5233. 'string': new Hash
  5234. };
  5235. }
  5236. /**
  5237. * Removes `key` and its value from the map.
  5238. *
  5239. * @private
  5240. * @name delete
  5241. * @memberOf MapCache
  5242. * @param {string} key The key of the value to remove.
  5243. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  5244. */
  5245. function mapCacheDelete(key) {
  5246. var result = getMapData(this, key)['delete'](key);
  5247. this.size -= result ? 1 : 0;
  5248. return result;
  5249. }
  5250. /**
  5251. * Gets the map value for `key`.
  5252. *
  5253. * @private
  5254. * @name get
  5255. * @memberOf MapCache
  5256. * @param {string} key The key of the value to get.
  5257. * @returns {*} Returns the entry value.
  5258. */
  5259. function mapCacheGet(key) {
  5260. return getMapData(this, key).get(key);
  5261. }
  5262. /**
  5263. * Checks if a map value for `key` exists.
  5264. *
  5265. * @private
  5266. * @name has
  5267. * @memberOf MapCache
  5268. * @param {string} key The key of the entry to check.
  5269. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  5270. */
  5271. function mapCacheHas(key) {
  5272. return getMapData(this, key).has(key);
  5273. }
  5274. /**
  5275. * Sets the map `key` to `value`.
  5276. *
  5277. * @private
  5278. * @name set
  5279. * @memberOf MapCache
  5280. * @param {string} key The key of the value to set.
  5281. * @param {*} value The value to set.
  5282. * @returns {Object} Returns the map cache instance.
  5283. */
  5284. function mapCacheSet(key, value) {
  5285. var data = getMapData(this, key),
  5286. size = data.size;
  5287. data.set(key, value);
  5288. this.size += data.size == size ? 0 : 1;
  5289. return this;
  5290. }
  5291. // Add methods to `MapCache`.
  5292. MapCache.prototype.clear = mapCacheClear;
  5293. MapCache.prototype['delete'] = mapCacheDelete;
  5294. MapCache.prototype.get = mapCacheGet;
  5295. MapCache.prototype.has = mapCacheHas;
  5296. MapCache.prototype.set = mapCacheSet;
  5297. /*------------------------------------------------------------------------*/
  5298. /**
  5299. *
  5300. * Creates an array cache object to store unique values.
  5301. *
  5302. * @private
  5303. * @constructor
  5304. * @param {Array} [values] The values to cache.
  5305. */
  5306. function SetCache(values) {
  5307. var index = -1,
  5308. length = values == null ? 0 : values.length;
  5309. this.__data__ = new MapCache;
  5310. while (++index < length) {
  5311. this.add(values[index]);
  5312. }
  5313. }
  5314. /**
  5315. * Adds `value` to the array cache.
  5316. *
  5317. * @private
  5318. * @name add
  5319. * @memberOf SetCache
  5320. * @alias push
  5321. * @param {*} value The value to cache.
  5322. * @returns {Object} Returns the cache instance.
  5323. */
  5324. function setCacheAdd(value) {
  5325. this.__data__.set(value, HASH_UNDEFINED);
  5326. return this;
  5327. }
  5328. /**
  5329. * Checks if `value` is in the array cache.
  5330. *
  5331. * @private
  5332. * @name has
  5333. * @memberOf SetCache
  5334. * @param {*} value The value to search for.
  5335. * @returns {number} Returns `true` if `value` is found, else `false`.
  5336. */
  5337. function setCacheHas(value) {
  5338. return this.__data__.has(value);
  5339. }
  5340. // Add methods to `SetCache`.
  5341. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  5342. SetCache.prototype.has = setCacheHas;
  5343. /*------------------------------------------------------------------------*/
  5344. /**
  5345. * Creates a stack cache object to store key-value pairs.
  5346. *
  5347. * @private
  5348. * @constructor
  5349. * @param {Array} [entries] The key-value pairs to cache.
  5350. */
  5351. function Stack(entries) {
  5352. var data = this.__data__ = new ListCache(entries);
  5353. this.size = data.size;
  5354. }
  5355. /**
  5356. * Removes all key-value entries from the stack.
  5357. *
  5358. * @private
  5359. * @name clear
  5360. * @memberOf Stack
  5361. */
  5362. function stackClear() {
  5363. this.__data__ = new ListCache;
  5364. this.size = 0;
  5365. }
  5366. /**
  5367. * Removes `key` and its value from the stack.
  5368. *
  5369. * @private
  5370. * @name delete
  5371. * @memberOf Stack
  5372. * @param {string} key The key of the value to remove.
  5373. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  5374. */
  5375. function stackDelete(key) {
  5376. var data = this.__data__,
  5377. result = data['delete'](key);
  5378. this.size = data.size;
  5379. return result;
  5380. }
  5381. /**
  5382. * Gets the stack value for `key`.
  5383. *
  5384. * @private
  5385. * @name get
  5386. * @memberOf Stack
  5387. * @param {string} key The key of the value to get.
  5388. * @returns {*} Returns the entry value.
  5389. */
  5390. function stackGet(key) {
  5391. return this.__data__.get(key);
  5392. }
  5393. /**
  5394. * Checks if a stack value for `key` exists.
  5395. *
  5396. * @private
  5397. * @name has
  5398. * @memberOf Stack
  5399. * @param {string} key The key of the entry to check.
  5400. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  5401. */
  5402. function stackHas(key) {
  5403. return this.__data__.has(key);
  5404. }
  5405. /**
  5406. * Sets the stack `key` to `value`.
  5407. *
  5408. * @private
  5409. * @name set
  5410. * @memberOf Stack
  5411. * @param {string} key The key of the value to set.
  5412. * @param {*} value The value to set.
  5413. * @returns {Object} Returns the stack cache instance.
  5414. */
  5415. function stackSet(key, value) {
  5416. var data = this.__data__;
  5417. if (data instanceof ListCache) {
  5418. var pairs = data.__data__;
  5419. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  5420. pairs.push([key, value]);
  5421. this.size = ++data.size;
  5422. return this;
  5423. }
  5424. data = this.__data__ = new MapCache(pairs);
  5425. }
  5426. data.set(key, value);
  5427. this.size = data.size;
  5428. return this;
  5429. }
  5430. // Add methods to `Stack`.
  5431. Stack.prototype.clear = stackClear;
  5432. Stack.prototype['delete'] = stackDelete;
  5433. Stack.prototype.get = stackGet;
  5434. Stack.prototype.has = stackHas;
  5435. Stack.prototype.set = stackSet;
  5436. /*------------------------------------------------------------------------*/
  5437. /**
  5438. * Creates an array of the enumerable property names of the array-like `value`.
  5439. *
  5440. * @private
  5441. * @param {*} value The value to query.
  5442. * @param {boolean} inherited Specify returning inherited property names.
  5443. * @returns {Array} Returns the array of property names.
  5444. */
  5445. function arrayLikeKeys(value, inherited) {
  5446. var isArr = isArray(value),
  5447. isArg = !isArr && isArguments(value),
  5448. isBuff = !isArr && !isArg && isBuffer(value),
  5449. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  5450. skipIndexes = isArr || isArg || isBuff || isType,
  5451. result = skipIndexes ? baseTimes(value.length, String) : [],
  5452. length = result.length;
  5453. for (var key in value) {
  5454. if ((inherited || hasOwnProperty.call(value, key)) &&
  5455. !(skipIndexes && (
  5456. // Safari 9 has enumerable `arguments.length` in strict mode.
  5457. key == 'length' ||
  5458. // Node.js 0.10 has enumerable non-index properties on buffers.
  5459. (isBuff && (key == 'offset' || key == 'parent')) ||
  5460. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  5461. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  5462. // Skip index properties.
  5463. isIndex(key, length)
  5464. ))) {
  5465. result.push(key);
  5466. }
  5467. }
  5468. return result;
  5469. }
  5470. /**
  5471. * A specialized version of `_.sample` for arrays.
  5472. *
  5473. * @private
  5474. * @param {Array} array The array to sample.
  5475. * @returns {*} Returns the random element.
  5476. */
  5477. function arraySample(array) {
  5478. var length = array.length;
  5479. return length ? array[baseRandom(0, length - 1)] : undefined;
  5480. }
  5481. /**
  5482. * A specialized version of `_.sampleSize` for arrays.
  5483. *
  5484. * @private
  5485. * @param {Array} array The array to sample.
  5486. * @param {number} n The number of elements to sample.
  5487. * @returns {Array} Returns the random elements.
  5488. */
  5489. function arraySampleSize(array, n) {
  5490. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  5491. }
  5492. /**
  5493. * A specialized version of `_.shuffle` for arrays.
  5494. *
  5495. * @private
  5496. * @param {Array} array The array to shuffle.
  5497. * @returns {Array} Returns the new shuffled array.
  5498. */
  5499. function arrayShuffle(array) {
  5500. return shuffleSelf(copyArray(array));
  5501. }
  5502. /**
  5503. * This function is like `assignValue` except that it doesn't assign
  5504. * `undefined` values.
  5505. *
  5506. * @private
  5507. * @param {Object} object The object to modify.
  5508. * @param {string} key The key of the property to assign.
  5509. * @param {*} value The value to assign.
  5510. */
  5511. function assignMergeValue(object, key, value) {
  5512. if ((value !== undefined && !eq(object[key], value)) ||
  5513. (value === undefined && !(key in object))) {
  5514. baseAssignValue(object, key, value);
  5515. }
  5516. }
  5517. /**
  5518. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  5519. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  5520. * for equality comparisons.
  5521. *
  5522. * @private
  5523. * @param {Object} object The object to modify.
  5524. * @param {string} key The key of the property to assign.
  5525. * @param {*} value The value to assign.
  5526. */
  5527. function assignValue(object, key, value) {
  5528. var objValue = object[key];
  5529. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  5530. (value === undefined && !(key in object))) {
  5531. baseAssignValue(object, key, value);
  5532. }
  5533. }
  5534. /**
  5535. * Gets the index at which the `key` is found in `array` of key-value pairs.
  5536. *
  5537. * @private
  5538. * @param {Array} array The array to inspect.
  5539. * @param {*} key The key to search for.
  5540. * @returns {number} Returns the index of the matched value, else `-1`.
  5541. */
  5542. function assocIndexOf(array, key) {
  5543. var length = array.length;
  5544. while (length--) {
  5545. if (eq(array[length][0], key)) {
  5546. return length;
  5547. }
  5548. }
  5549. return -1;
  5550. }
  5551. /**
  5552. * Aggregates elements of `collection` on `accumulator` with keys transformed
  5553. * by `iteratee` and values set by `setter`.
  5554. *
  5555. * @private
  5556. * @param {Array|Object} collection The collection to iterate over.
  5557. * @param {Function} setter The function to set `accumulator` values.
  5558. * @param {Function} iteratee The iteratee to transform keys.
  5559. * @param {Object} accumulator The initial aggregated object.
  5560. * @returns {Function} Returns `accumulator`.
  5561. */
  5562. function baseAggregator(collection, setter, iteratee, accumulator) {
  5563. baseEach(collection, function(value, key, collection) {
  5564. setter(accumulator, value, iteratee(value), collection);
  5565. });
  5566. return accumulator;
  5567. }
  5568. /**
  5569. * The base implementation of `_.assign` without support for multiple sources
  5570. * or `customizer` functions.
  5571. *
  5572. * @private
  5573. * @param {Object} object The destination object.
  5574. * @param {Object} source The source object.
  5575. * @returns {Object} Returns `object`.
  5576. */
  5577. function baseAssign(object, source) {
  5578. return object && copyObject(source, keys(source), object);
  5579. }
  5580. /**
  5581. * The base implementation of `_.assignIn` without support for multiple sources
  5582. * or `customizer` functions.
  5583. *
  5584. * @private
  5585. * @param {Object} object The destination object.
  5586. * @param {Object} source The source object.
  5587. * @returns {Object} Returns `object`.
  5588. */
  5589. function baseAssignIn(object, source) {
  5590. return object && copyObject(source, keysIn(source), object);
  5591. }
  5592. /**
  5593. * The base implementation of `assignValue` and `assignMergeValue` without
  5594. * value checks.
  5595. *
  5596. * @private
  5597. * @param {Object} object The object to modify.
  5598. * @param {string} key The key of the property to assign.
  5599. * @param {*} value The value to assign.
  5600. */
  5601. function baseAssignValue(object, key, value) {
  5602. if (key == '__proto__' && defineProperty) {
  5603. defineProperty(object, key, {
  5604. 'configurable': true,
  5605. 'enumerable': true,
  5606. 'value': value,
  5607. 'writable': true
  5608. });
  5609. } else {
  5610. object[key] = value;
  5611. }
  5612. }
  5613. /**
  5614. * The base implementation of `_.at` without support for individual paths.
  5615. *
  5616. * @private
  5617. * @param {Object} object The object to iterate over.
  5618. * @param {string[]} paths The property paths to pick.
  5619. * @returns {Array} Returns the picked elements.
  5620. */
  5621. function baseAt(object, paths) {
  5622. var index = -1,
  5623. length = paths.length,
  5624. result = Array(length),
  5625. skip = object == null;
  5626. while (++index < length) {
  5627. result[index] = skip ? undefined : get(object, paths[index]);
  5628. }
  5629. return result;
  5630. }
  5631. /**
  5632. * The base implementation of `_.clamp` which doesn't coerce arguments.
  5633. *
  5634. * @private
  5635. * @param {number} number The number to clamp.
  5636. * @param {number} [lower] The lower bound.
  5637. * @param {number} upper The upper bound.
  5638. * @returns {number} Returns the clamped number.
  5639. */
  5640. function baseClamp(number, lower, upper) {
  5641. if (number === number) {
  5642. if (upper !== undefined) {
  5643. number = number <= upper ? number : upper;
  5644. }
  5645. if (lower !== undefined) {
  5646. number = number >= lower ? number : lower;
  5647. }
  5648. }
  5649. return number;
  5650. }
  5651. /**
  5652. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  5653. * traversed objects.
  5654. *
  5655. * @private
  5656. * @param {*} value The value to clone.
  5657. * @param {boolean} bitmask The bitmask flags.
  5658. * 1 - Deep clone
  5659. * 2 - Flatten inherited properties
  5660. * 4 - Clone symbols
  5661. * @param {Function} [customizer] The function to customize cloning.
  5662. * @param {string} [key] The key of `value`.
  5663. * @param {Object} [object] The parent object of `value`.
  5664. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  5665. * @returns {*} Returns the cloned value.
  5666. */
  5667. function baseClone(value, bitmask, customizer, key, object, stack) {
  5668. var result,
  5669. isDeep = bitmask & CLONE_DEEP_FLAG,
  5670. isFlat = bitmask & CLONE_FLAT_FLAG,
  5671. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  5672. if (customizer) {
  5673. result = object ? customizer(value, key, object, stack) : customizer(value);
  5674. }
  5675. if (result !== undefined) {
  5676. return result;
  5677. }
  5678. if (!isObject(value)) {
  5679. return value;
  5680. }
  5681. var isArr = isArray(value);
  5682. if (isArr) {
  5683. result = initCloneArray(value);
  5684. if (!isDeep) {
  5685. return copyArray(value, result);
  5686. }
  5687. } else {
  5688. var tag = getTag(value),
  5689. isFunc = tag == funcTag || tag == genTag;
  5690. if (isBuffer(value)) {
  5691. return cloneBuffer(value, isDeep);
  5692. }
  5693. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  5694. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  5695. if (!isDeep) {
  5696. return isFlat
  5697. ? copySymbolsIn(value, baseAssignIn(result, value))
  5698. : copySymbols(value, baseAssign(result, value));
  5699. }
  5700. } else {
  5701. if (!cloneableTags[tag]) {
  5702. return object ? value : {};
  5703. }
  5704. result = initCloneByTag(value, tag, isDeep);
  5705. }
  5706. }
  5707. // Check for circular references and return its corresponding clone.
  5708. stack || (stack = new Stack);
  5709. var stacked = stack.get(value);
  5710. if (stacked) {
  5711. return stacked;
  5712. }
  5713. stack.set(value, result);
  5714. if (isSet(value)) {
  5715. value.forEach(function(subValue) {
  5716. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  5717. });
  5718. } else if (isMap(value)) {
  5719. value.forEach(function(subValue, key) {
  5720. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  5721. });
  5722. }
  5723. var keysFunc = isFull
  5724. ? (isFlat ? getAllKeysIn : getAllKeys)
  5725. : (isFlat ? keysIn : keys);
  5726. var props = isArr ? undefined : keysFunc(value);
  5727. arrayEach(props || value, function(subValue, key) {
  5728. if (props) {
  5729. key = subValue;
  5730. subValue = value[key];
  5731. }
  5732. // Recursively populate clone (susceptible to call stack limits).
  5733. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  5734. });
  5735. return result;
  5736. }
  5737. /**
  5738. * The base implementation of `_.conforms` which doesn't clone `source`.
  5739. *
  5740. * @private
  5741. * @param {Object} source The object of property predicates to conform to.
  5742. * @returns {Function} Returns the new spec function.
  5743. */
  5744. function baseConforms(source) {
  5745. var props = keys(source);
  5746. return function(object) {
  5747. return baseConformsTo(object, source, props);
  5748. };
  5749. }
  5750. /**
  5751. * The base implementation of `_.conformsTo` which accepts `props` to check.
  5752. *
  5753. * @private
  5754. * @param {Object} object The object to inspect.
  5755. * @param {Object} source The object of property predicates to conform to.
  5756. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  5757. */
  5758. function baseConformsTo(object, source, props) {
  5759. var length = props.length;
  5760. if (object == null) {
  5761. return !length;
  5762. }
  5763. object = Object(object);
  5764. while (length--) {
  5765. var key = props[length],
  5766. predicate = source[key],
  5767. value = object[key];
  5768. if ((value === undefined && !(key in object)) || !predicate(value)) {
  5769. return false;
  5770. }
  5771. }
  5772. return true;
  5773. }
  5774. /**
  5775. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  5776. * to provide to `func`.
  5777. *
  5778. * @private
  5779. * @param {Function} func The function to delay.
  5780. * @param {number} wait The number of milliseconds to delay invocation.
  5781. * @param {Array} args The arguments to provide to `func`.
  5782. * @returns {number|Object} Returns the timer id or timeout object.
  5783. */
  5784. function baseDelay(func, wait, args) {
  5785. if (typeof func != 'function') {
  5786. throw new TypeError(FUNC_ERROR_TEXT);
  5787. }
  5788. return setTimeout(function() { func.apply(undefined, args); }, wait);
  5789. }
  5790. /**
  5791. * The base implementation of methods like `_.difference` without support
  5792. * for excluding multiple arrays or iteratee shorthands.
  5793. *
  5794. * @private
  5795. * @param {Array} array The array to inspect.
  5796. * @param {Array} values The values to exclude.
  5797. * @param {Function} [iteratee] The iteratee invoked per element.
  5798. * @param {Function} [comparator] The comparator invoked per element.
  5799. * @returns {Array} Returns the new array of filtered values.
  5800. */
  5801. function baseDifference(array, values, iteratee, comparator) {
  5802. var index = -1,
  5803. includes = arrayIncludes,
  5804. isCommon = true,
  5805. length = array.length,
  5806. result = [],
  5807. valuesLength = values.length;
  5808. if (!length) {
  5809. return result;
  5810. }
  5811. if (iteratee) {
  5812. values = arrayMap(values, baseUnary(iteratee));
  5813. }
  5814. if (comparator) {
  5815. includes = arrayIncludesWith;
  5816. isCommon = false;
  5817. }
  5818. else if (values.length >= LARGE_ARRAY_SIZE) {
  5819. includes = cacheHas;
  5820. isCommon = false;
  5821. values = new SetCache(values);
  5822. }
  5823. outer:
  5824. while (++index < length) {
  5825. var value = array[index],
  5826. computed = iteratee == null ? value : iteratee(value);
  5827. value = (comparator || value !== 0) ? value : 0;
  5828. if (isCommon && computed === computed) {
  5829. var valuesIndex = valuesLength;
  5830. while (valuesIndex--) {
  5831. if (values[valuesIndex] === computed) {
  5832. continue outer;
  5833. }
  5834. }
  5835. result.push(value);
  5836. }
  5837. else if (!includes(values, computed, comparator)) {
  5838. result.push(value);
  5839. }
  5840. }
  5841. return result;
  5842. }
  5843. /**
  5844. * The base implementation of `_.forEach` without support for iteratee shorthands.
  5845. *
  5846. * @private
  5847. * @param {Array|Object} collection The collection to iterate over.
  5848. * @param {Function} iteratee The function invoked per iteration.
  5849. * @returns {Array|Object} Returns `collection`.
  5850. */
  5851. var baseEach = createBaseEach(baseForOwn);
  5852. /**
  5853. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  5854. *
  5855. * @private
  5856. * @param {Array|Object} collection The collection to iterate over.
  5857. * @param {Function} iteratee The function invoked per iteration.
  5858. * @returns {Array|Object} Returns `collection`.
  5859. */
  5860. var baseEachRight = createBaseEach(baseForOwnRight, true);
  5861. /**
  5862. * The base implementation of `_.every` without support for iteratee shorthands.
  5863. *
  5864. * @private
  5865. * @param {Array|Object} collection The collection to iterate over.
  5866. * @param {Function} predicate The function invoked per iteration.
  5867. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  5868. * else `false`
  5869. */
  5870. function baseEvery(collection, predicate) {
  5871. var result = true;
  5872. baseEach(collection, function(value, index, collection) {
  5873. result = !!predicate(value, index, collection);
  5874. return result;
  5875. });
  5876. return result;
  5877. }
  5878. /**
  5879. * The base implementation of methods like `_.max` and `_.min` which accepts a
  5880. * `comparator` to determine the extremum value.
  5881. *
  5882. * @private
  5883. * @param {Array} array The array to iterate over.
  5884. * @param {Function} iteratee The iteratee invoked per iteration.
  5885. * @param {Function} comparator The comparator used to compare values.
  5886. * @returns {*} Returns the extremum value.
  5887. */
  5888. function baseExtremum(array, iteratee, comparator) {
  5889. var index = -1,
  5890. length = array.length;
  5891. while (++index < length) {
  5892. var value = array[index],
  5893. current = iteratee(value);
  5894. if (current != null && (computed === undefined
  5895. ? (current === current && !isSymbol(current))
  5896. : comparator(current, computed)
  5897. )) {
  5898. var computed = current,
  5899. result = value;
  5900. }
  5901. }
  5902. return result;
  5903. }
  5904. /**
  5905. * The base implementation of `_.fill` without an iteratee call guard.
  5906. *
  5907. * @private
  5908. * @param {Array} array The array to fill.
  5909. * @param {*} value The value to fill `array` with.
  5910. * @param {number} [start=0] The start position.
  5911. * @param {number} [end=array.length] The end position.
  5912. * @returns {Array} Returns `array`.
  5913. */
  5914. function baseFill(array, value, start, end) {
  5915. var length = array.length;
  5916. start = toInteger(start);
  5917. if (start < 0) {
  5918. start = -start > length ? 0 : (length + start);
  5919. }
  5920. end = (end === undefined || end > length) ? length : toInteger(end);
  5921. if (end < 0) {
  5922. end += length;
  5923. }
  5924. end = start > end ? 0 : toLength(end);
  5925. while (start < end) {
  5926. array[start++] = value;
  5927. }
  5928. return array;
  5929. }
  5930. /**
  5931. * The base implementation of `_.filter` without support for iteratee shorthands.
  5932. *
  5933. * @private
  5934. * @param {Array|Object} collection The collection to iterate over.
  5935. * @param {Function} predicate The function invoked per iteration.
  5936. * @returns {Array} Returns the new filtered array.
  5937. */
  5938. function baseFilter(collection, predicate) {
  5939. var result = [];
  5940. baseEach(collection, function(value, index, collection) {
  5941. if (predicate(value, index, collection)) {
  5942. result.push(value);
  5943. }
  5944. });
  5945. return result;
  5946. }
  5947. /**
  5948. * The base implementation of `_.flatten` with support for restricting flattening.
  5949. *
  5950. * @private
  5951. * @param {Array} array The array to flatten.
  5952. * @param {number} depth The maximum recursion depth.
  5953. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  5954. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  5955. * @param {Array} [result=[]] The initial result value.
  5956. * @returns {Array} Returns the new flattened array.
  5957. */
  5958. function baseFlatten(array, depth, predicate, isStrict, result) {
  5959. var index = -1,
  5960. length = array.length;
  5961. predicate || (predicate = isFlattenable);
  5962. result || (result = []);
  5963. while (++index < length) {
  5964. var value = array[index];
  5965. if (depth > 0 && predicate(value)) {
  5966. if (depth > 1) {
  5967. // Recursively flatten arrays (susceptible to call stack limits).
  5968. baseFlatten(value, depth - 1, predicate, isStrict, result);
  5969. } else {
  5970. arrayPush(result, value);
  5971. }
  5972. } else if (!isStrict) {
  5973. result[result.length] = value;
  5974. }
  5975. }
  5976. return result;
  5977. }
  5978. /**
  5979. * The base implementation of `baseForOwn` which iterates over `object`
  5980. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  5981. * Iteratee functions may exit iteration early by explicitly returning `false`.
  5982. *
  5983. * @private
  5984. * @param {Object} object The object to iterate over.
  5985. * @param {Function} iteratee The function invoked per iteration.
  5986. * @param {Function} keysFunc The function to get the keys of `object`.
  5987. * @returns {Object} Returns `object`.
  5988. */
  5989. var baseFor = createBaseFor();
  5990. /**
  5991. * This function is like `baseFor` except that it iterates over properties
  5992. * in the opposite order.
  5993. *
  5994. * @private
  5995. * @param {Object} object The object to iterate over.
  5996. * @param {Function} iteratee The function invoked per iteration.
  5997. * @param {Function} keysFunc The function to get the keys of `object`.
  5998. * @returns {Object} Returns `object`.
  5999. */
  6000. var baseForRight = createBaseFor(true);
  6001. /**
  6002. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  6003. *
  6004. * @private
  6005. * @param {Object} object The object to iterate over.
  6006. * @param {Function} iteratee The function invoked per iteration.
  6007. * @returns {Object} Returns `object`.
  6008. */
  6009. function baseForOwn(object, iteratee) {
  6010. return object && baseFor(object, iteratee, keys);
  6011. }
  6012. /**
  6013. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  6014. *
  6015. * @private
  6016. * @param {Object} object The object to iterate over.
  6017. * @param {Function} iteratee The function invoked per iteration.
  6018. * @returns {Object} Returns `object`.
  6019. */
  6020. function baseForOwnRight(object, iteratee) {
  6021. return object && baseForRight(object, iteratee, keys);
  6022. }
  6023. /**
  6024. * The base implementation of `_.functions` which creates an array of
  6025. * `object` function property names filtered from `props`.
  6026. *
  6027. * @private
  6028. * @param {Object} object The object to inspect.
  6029. * @param {Array} props The property names to filter.
  6030. * @returns {Array} Returns the function names.
  6031. */
  6032. function baseFunctions(object, props) {
  6033. return arrayFilter(props, function(key) {
  6034. return isFunction(object[key]);
  6035. });
  6036. }
  6037. /**
  6038. * The base implementation of `_.get` without support for default values.
  6039. *
  6040. * @private
  6041. * @param {Object} object The object to query.
  6042. * @param {Array|string} path The path of the property to get.
  6043. * @returns {*} Returns the resolved value.
  6044. */
  6045. function baseGet(object, path) {
  6046. path = castPath(path, object);
  6047. var index = 0,
  6048. length = path.length;
  6049. while (object != null && index < length) {
  6050. object = object[toKey(path[index++])];
  6051. }
  6052. return (index && index == length) ? object : undefined;
  6053. }
  6054. /**
  6055. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  6056. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  6057. * symbols of `object`.
  6058. *
  6059. * @private
  6060. * @param {Object} object The object to query.
  6061. * @param {Function} keysFunc The function to get the keys of `object`.
  6062. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  6063. * @returns {Array} Returns the array of property names and symbols.
  6064. */
  6065. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  6066. var result = keysFunc(object);
  6067. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  6068. }
  6069. /**
  6070. * The base implementation of `getTag` without fallbacks for buggy environments.
  6071. *
  6072. * @private
  6073. * @param {*} value The value to query.
  6074. * @returns {string} Returns the `toStringTag`.
  6075. */
  6076. function baseGetTag(value) {
  6077. if (value == null) {
  6078. return value === undefined ? undefinedTag : nullTag;
  6079. }
  6080. return (symToStringTag && symToStringTag in Object(value))
  6081. ? getRawTag(value)
  6082. : objectToString(value);
  6083. }
  6084. /**
  6085. * The base implementation of `_.gt` which doesn't coerce arguments.
  6086. *
  6087. * @private
  6088. * @param {*} value The value to compare.
  6089. * @param {*} other The other value to compare.
  6090. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  6091. * else `false`.
  6092. */
  6093. function baseGt(value, other) {
  6094. return value > other;
  6095. }
  6096. /**
  6097. * The base implementation of `_.has` without support for deep paths.
  6098. *
  6099. * @private
  6100. * @param {Object} [object] The object to query.
  6101. * @param {Array|string} key The key to check.
  6102. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  6103. */
  6104. function baseHas(object, key) {
  6105. return object != null && hasOwnProperty.call(object, key);
  6106. }
  6107. /**
  6108. * The base implementation of `_.hasIn` without support for deep paths.
  6109. *
  6110. * @private
  6111. * @param {Object} [object] The object to query.
  6112. * @param {Array|string} key The key to check.
  6113. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  6114. */
  6115. function baseHasIn(object, key) {
  6116. return object != null && key in Object(object);
  6117. }
  6118. /**
  6119. * The base implementation of `_.inRange` which doesn't coerce arguments.
  6120. *
  6121. * @private
  6122. * @param {number} number The number to check.
  6123. * @param {number} start The start of the range.
  6124. * @param {number} end The end of the range.
  6125. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  6126. */
  6127. function baseInRange(number, start, end) {
  6128. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  6129. }
  6130. /**
  6131. * The base implementation of methods like `_.intersection`, without support
  6132. * for iteratee shorthands, that accepts an array of arrays to inspect.
  6133. *
  6134. * @private
  6135. * @param {Array} arrays The arrays to inspect.
  6136. * @param {Function} [iteratee] The iteratee invoked per element.
  6137. * @param {Function} [comparator] The comparator invoked per element.
  6138. * @returns {Array} Returns the new array of shared values.
  6139. */
  6140. function baseIntersection(arrays, iteratee, comparator) {
  6141. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  6142. length = arrays[0].length,
  6143. othLength = arrays.length,
  6144. othIndex = othLength,
  6145. caches = Array(othLength),
  6146. maxLength = Infinity,
  6147. result = [];
  6148. while (othIndex--) {
  6149. var array = arrays[othIndex];
  6150. if (othIndex && iteratee) {
  6151. array = arrayMap(array, baseUnary(iteratee));
  6152. }
  6153. maxLength = nativeMin(array.length, maxLength);
  6154. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  6155. ? new SetCache(othIndex && array)
  6156. : undefined;
  6157. }
  6158. array = arrays[0];
  6159. var index = -1,
  6160. seen = caches[0];
  6161. outer:
  6162. while (++index < length && result.length < maxLength) {
  6163. var value = array[index],
  6164. computed = iteratee ? iteratee(value) : value;
  6165. value = (comparator || value !== 0) ? value : 0;
  6166. if (!(seen
  6167. ? cacheHas(seen, computed)
  6168. : includes(result, computed, comparator)
  6169. )) {
  6170. othIndex = othLength;
  6171. while (--othIndex) {
  6172. var cache = caches[othIndex];
  6173. if (!(cache
  6174. ? cacheHas(cache, computed)
  6175. : includes(arrays[othIndex], computed, comparator))
  6176. ) {
  6177. continue outer;
  6178. }
  6179. }
  6180. if (seen) {
  6181. seen.push(computed);
  6182. }
  6183. result.push(value);
  6184. }
  6185. }
  6186. return result;
  6187. }
  6188. /**
  6189. * The base implementation of `_.invert` and `_.invertBy` which inverts
  6190. * `object` with values transformed by `iteratee` and set by `setter`.
  6191. *
  6192. * @private
  6193. * @param {Object} object The object to iterate over.
  6194. * @param {Function} setter The function to set `accumulator` values.
  6195. * @param {Function} iteratee The iteratee to transform values.
  6196. * @param {Object} accumulator The initial inverted object.
  6197. * @returns {Function} Returns `accumulator`.
  6198. */
  6199. function baseInverter(object, setter, iteratee, accumulator) {
  6200. baseForOwn(object, function(value, key, object) {
  6201. setter(accumulator, iteratee(value), key, object);
  6202. });
  6203. return accumulator;
  6204. }
  6205. /**
  6206. * The base implementation of `_.invoke` without support for individual
  6207. * method arguments.
  6208. *
  6209. * @private
  6210. * @param {Object} object The object to query.
  6211. * @param {Array|string} path The path of the method to invoke.
  6212. * @param {Array} args The arguments to invoke the method with.
  6213. * @returns {*} Returns the result of the invoked method.
  6214. */
  6215. function baseInvoke(object, path, args) {
  6216. path = castPath(path, object);
  6217. object = parent(object, path);
  6218. var func = object == null ? object : object[toKey(last(path))];
  6219. return func == null ? undefined : apply(func, object, args);
  6220. }
  6221. /**
  6222. * The base implementation of `_.isArguments`.
  6223. *
  6224. * @private
  6225. * @param {*} value The value to check.
  6226. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  6227. */
  6228. function baseIsArguments(value) {
  6229. return isObjectLike(value) && baseGetTag(value) == argsTag;
  6230. }
  6231. /**
  6232. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  6233. *
  6234. * @private
  6235. * @param {*} value The value to check.
  6236. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  6237. */
  6238. function baseIsArrayBuffer(value) {
  6239. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  6240. }
  6241. /**
  6242. * The base implementation of `_.isDate` without Node.js optimizations.
  6243. *
  6244. * @private
  6245. * @param {*} value The value to check.
  6246. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  6247. */
  6248. function baseIsDate(value) {
  6249. return isObjectLike(value) && baseGetTag(value) == dateTag;
  6250. }
  6251. /**
  6252. * The base implementation of `_.isEqual` which supports partial comparisons
  6253. * and tracks traversed objects.
  6254. *
  6255. * @private
  6256. * @param {*} value The value to compare.
  6257. * @param {*} other The other value to compare.
  6258. * @param {boolean} bitmask The bitmask flags.
  6259. * 1 - Unordered comparison
  6260. * 2 - Partial comparison
  6261. * @param {Function} [customizer] The function to customize comparisons.
  6262. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  6263. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  6264. */
  6265. function baseIsEqual(value, other, bitmask, customizer, stack) {
  6266. if (value === other) {
  6267. return true;
  6268. }
  6269. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  6270. return value !== value && other !== other;
  6271. }
  6272. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  6273. }
  6274. /**
  6275. * A specialized version of `baseIsEqual` for arrays and objects which performs
  6276. * deep comparisons and tracks traversed objects enabling objects with circular
  6277. * references to be compared.
  6278. *
  6279. * @private
  6280. * @param {Object} object The object to compare.
  6281. * @param {Object} other The other object to compare.
  6282. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  6283. * @param {Function} customizer The function to customize comparisons.
  6284. * @param {Function} equalFunc The function to determine equivalents of values.
  6285. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  6286. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  6287. */
  6288. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  6289. var objIsArr = isArray(object),
  6290. othIsArr = isArray(other),
  6291. objTag = objIsArr ? arrayTag : getTag(object),
  6292. othTag = othIsArr ? arrayTag : getTag(other);
  6293. objTag = objTag == argsTag ? objectTag : objTag;
  6294. othTag = othTag == argsTag ? objectTag : othTag;
  6295. var objIsObj = objTag == objectTag,
  6296. othIsObj = othTag == objectTag,
  6297. isSameTag = objTag == othTag;
  6298. if (isSameTag && isBuffer(object)) {
  6299. if (!isBuffer(other)) {
  6300. return false;
  6301. }
  6302. objIsArr = true;
  6303. objIsObj = false;
  6304. }
  6305. if (isSameTag && !objIsObj) {
  6306. stack || (stack = new Stack);
  6307. return (objIsArr || isTypedArray(object))
  6308. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  6309. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  6310. }
  6311. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  6312. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  6313. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  6314. if (objIsWrapped || othIsWrapped) {
  6315. var objUnwrapped = objIsWrapped ? object.value() : object,
  6316. othUnwrapped = othIsWrapped ? other.value() : other;
  6317. stack || (stack = new Stack);
  6318. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  6319. }
  6320. }
  6321. if (!isSameTag) {
  6322. return false;
  6323. }
  6324. stack || (stack = new Stack);
  6325. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  6326. }
  6327. /**
  6328. * The base implementation of `_.isMap` without Node.js optimizations.
  6329. *
  6330. * @private
  6331. * @param {*} value The value to check.
  6332. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  6333. */
  6334. function baseIsMap(value) {
  6335. return isObjectLike(value) && getTag(value) == mapTag;
  6336. }
  6337. /**
  6338. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  6339. *
  6340. * @private
  6341. * @param {Object} object The object to inspect.
  6342. * @param {Object} source The object of property values to match.
  6343. * @param {Array} matchData The property names, values, and compare flags to match.
  6344. * @param {Function} [customizer] The function to customize comparisons.
  6345. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  6346. */
  6347. function baseIsMatch(object, source, matchData, customizer) {
  6348. var index = matchData.length,
  6349. length = index,
  6350. noCustomizer = !customizer;
  6351. if (object == null) {
  6352. return !length;
  6353. }
  6354. object = Object(object);
  6355. while (index--) {
  6356. var data = matchData[index];
  6357. if ((noCustomizer && data[2])
  6358. ? data[1] !== object[data[0]]
  6359. : !(data[0] in object)
  6360. ) {
  6361. return false;
  6362. }
  6363. }
  6364. while (++index < length) {
  6365. data = matchData[index];
  6366. var key = data[0],
  6367. objValue = object[key],
  6368. srcValue = data[1];
  6369. if (noCustomizer && data[2]) {
  6370. if (objValue === undefined && !(key in object)) {
  6371. return false;
  6372. }
  6373. } else {
  6374. var stack = new Stack;
  6375. if (customizer) {
  6376. var result = customizer(objValue, srcValue, key, object, source, stack);
  6377. }
  6378. if (!(result === undefined
  6379. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  6380. : result
  6381. )) {
  6382. return false;
  6383. }
  6384. }
  6385. }
  6386. return true;
  6387. }
  6388. /**
  6389. * The base implementation of `_.isNative` without bad shim checks.
  6390. *
  6391. * @private
  6392. * @param {*} value The value to check.
  6393. * @returns {boolean} Returns `true` if `value` is a native function,
  6394. * else `false`.
  6395. */
  6396. function baseIsNative(value) {
  6397. if (!isObject(value) || isMasked(value)) {
  6398. return false;
  6399. }
  6400. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  6401. return pattern.test(toSource(value));
  6402. }
  6403. /**
  6404. * The base implementation of `_.isRegExp` without Node.js optimizations.
  6405. *
  6406. * @private
  6407. * @param {*} value The value to check.
  6408. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  6409. */
  6410. function baseIsRegExp(value) {
  6411. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  6412. }
  6413. /**
  6414. * The base implementation of `_.isSet` without Node.js optimizations.
  6415. *
  6416. * @private
  6417. * @param {*} value The value to check.
  6418. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  6419. */
  6420. function baseIsSet(value) {
  6421. return isObjectLike(value) && getTag(value) == setTag;
  6422. }
  6423. /**
  6424. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  6425. *
  6426. * @private
  6427. * @param {*} value The value to check.
  6428. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  6429. */
  6430. function baseIsTypedArray(value) {
  6431. return isObjectLike(value) &&
  6432. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  6433. }
  6434. /**
  6435. * The base implementation of `_.iteratee`.
  6436. *
  6437. * @private
  6438. * @param {*} [value=_.identity] The value to convert to an iteratee.
  6439. * @returns {Function} Returns the iteratee.
  6440. */
  6441. function baseIteratee(value) {
  6442. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  6443. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  6444. if (typeof value == 'function') {
  6445. return value;
  6446. }
  6447. if (value == null) {
  6448. return identity;
  6449. }
  6450. if (typeof value == 'object') {
  6451. return isArray(value)
  6452. ? baseMatchesProperty(value[0], value[1])
  6453. : baseMatches(value);
  6454. }
  6455. return property(value);
  6456. }
  6457. /**
  6458. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  6459. *
  6460. * @private
  6461. * @param {Object} object The object to query.
  6462. * @returns {Array} Returns the array of property names.
  6463. */
  6464. function baseKeys(object) {
  6465. if (!isPrototype(object)) {
  6466. return nativeKeys(object);
  6467. }
  6468. var result = [];
  6469. for (var key in Object(object)) {
  6470. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  6471. result.push(key);
  6472. }
  6473. }
  6474. return result;
  6475. }
  6476. /**
  6477. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  6478. *
  6479. * @private
  6480. * @param {Object} object The object to query.
  6481. * @returns {Array} Returns the array of property names.
  6482. */
  6483. function baseKeysIn(object) {
  6484. if (!isObject(object)) {
  6485. return nativeKeysIn(object);
  6486. }
  6487. var isProto = isPrototype(object),
  6488. result = [];
  6489. for (var key in object) {
  6490. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  6491. result.push(key);
  6492. }
  6493. }
  6494. return result;
  6495. }
  6496. /**
  6497. * The base implementation of `_.lt` which doesn't coerce arguments.
  6498. *
  6499. * @private
  6500. * @param {*} value The value to compare.
  6501. * @param {*} other The other value to compare.
  6502. * @returns {boolean} Returns `true` if `value` is less than `other`,
  6503. * else `false`.
  6504. */
  6505. function baseLt(value, other) {
  6506. return value < other;
  6507. }
  6508. /**
  6509. * The base implementation of `_.map` without support for iteratee shorthands.
  6510. *
  6511. * @private
  6512. * @param {Array|Object} collection The collection to iterate over.
  6513. * @param {Function} iteratee The function invoked per iteration.
  6514. * @returns {Array} Returns the new mapped array.
  6515. */
  6516. function baseMap(collection, iteratee) {
  6517. var index = -1,
  6518. result = isArrayLike(collection) ? Array(collection.length) : [];
  6519. baseEach(collection, function(value, key, collection) {
  6520. result[++index] = iteratee(value, key, collection);
  6521. });
  6522. return result;
  6523. }
  6524. /**
  6525. * The base implementation of `_.matches` which doesn't clone `source`.
  6526. *
  6527. * @private
  6528. * @param {Object} source The object of property values to match.
  6529. * @returns {Function} Returns the new spec function.
  6530. */
  6531. function baseMatches(source) {
  6532. var matchData = getMatchData(source);
  6533. if (matchData.length == 1 && matchData[0][2]) {
  6534. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  6535. }
  6536. return function(object) {
  6537. return object === source || baseIsMatch(object, source, matchData);
  6538. };
  6539. }
  6540. /**
  6541. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  6542. *
  6543. * @private
  6544. * @param {string} path The path of the property to get.
  6545. * @param {*} srcValue The value to match.
  6546. * @returns {Function} Returns the new spec function.
  6547. */
  6548. function baseMatchesProperty(path, srcValue) {
  6549. if (isKey(path) && isStrictComparable(srcValue)) {
  6550. return matchesStrictComparable(toKey(path), srcValue);
  6551. }
  6552. return function(object) {
  6553. var objValue = get(object, path);
  6554. return (objValue === undefined && objValue === srcValue)
  6555. ? hasIn(object, path)
  6556. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  6557. };
  6558. }
  6559. /**
  6560. * The base implementation of `_.merge` without support for multiple sources.
  6561. *
  6562. * @private
  6563. * @param {Object} object The destination object.
  6564. * @param {Object} source The source object.
  6565. * @param {number} srcIndex The index of `source`.
  6566. * @param {Function} [customizer] The function to customize merged values.
  6567. * @param {Object} [stack] Tracks traversed source values and their merged
  6568. * counterparts.
  6569. */
  6570. function baseMerge(object, source, srcIndex, customizer, stack) {
  6571. if (object === source) {
  6572. return;
  6573. }
  6574. baseFor(source, function(srcValue, key) {
  6575. stack || (stack = new Stack);
  6576. if (isObject(srcValue)) {
  6577. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  6578. }
  6579. else {
  6580. var newValue = customizer
  6581. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  6582. : undefined;
  6583. if (newValue === undefined) {
  6584. newValue = srcValue;
  6585. }
  6586. assignMergeValue(object, key, newValue);
  6587. }
  6588. }, keysIn);
  6589. }
  6590. /**
  6591. * A specialized version of `baseMerge` for arrays and objects which performs
  6592. * deep merges and tracks traversed objects enabling objects with circular
  6593. * references to be merged.
  6594. *
  6595. * @private
  6596. * @param {Object} object The destination object.
  6597. * @param {Object} source The source object.
  6598. * @param {string} key The key of the value to merge.
  6599. * @param {number} srcIndex The index of `source`.
  6600. * @param {Function} mergeFunc The function to merge values.
  6601. * @param {Function} [customizer] The function to customize assigned values.
  6602. * @param {Object} [stack] Tracks traversed source values and their merged
  6603. * counterparts.
  6604. */
  6605. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  6606. var objValue = safeGet(object, key),
  6607. srcValue = safeGet(source, key),
  6608. stacked = stack.get(srcValue);
  6609. if (stacked) {
  6610. assignMergeValue(object, key, stacked);
  6611. return;
  6612. }
  6613. var newValue = customizer
  6614. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  6615. : undefined;
  6616. var isCommon = newValue === undefined;
  6617. if (isCommon) {
  6618. var isArr = isArray(srcValue),
  6619. isBuff = !isArr && isBuffer(srcValue),
  6620. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  6621. newValue = srcValue;
  6622. if (isArr || isBuff || isTyped) {
  6623. if (isArray(objValue)) {
  6624. newValue = objValue;
  6625. }
  6626. else if (isArrayLikeObject(objValue)) {
  6627. newValue = copyArray(objValue);
  6628. }
  6629. else if (isBuff) {
  6630. isCommon = false;
  6631. newValue = cloneBuffer(srcValue, true);
  6632. }
  6633. else if (isTyped) {
  6634. isCommon = false;
  6635. newValue = cloneTypedArray(srcValue, true);
  6636. }
  6637. else {
  6638. newValue = [];
  6639. }
  6640. }
  6641. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  6642. newValue = objValue;
  6643. if (isArguments(objValue)) {
  6644. newValue = toPlainObject(objValue);
  6645. }
  6646. else if (!isObject(objValue) || isFunction(objValue)) {
  6647. newValue = initCloneObject(srcValue);
  6648. }
  6649. }
  6650. else {
  6651. isCommon = false;
  6652. }
  6653. }
  6654. if (isCommon) {
  6655. // Recursively merge objects and arrays (susceptible to call stack limits).
  6656. stack.set(srcValue, newValue);
  6657. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  6658. stack['delete'](srcValue);
  6659. }
  6660. assignMergeValue(object, key, newValue);
  6661. }
  6662. /**
  6663. * The base implementation of `_.nth` which doesn't coerce arguments.
  6664. *
  6665. * @private
  6666. * @param {Array} array The array to query.
  6667. * @param {number} n The index of the element to return.
  6668. * @returns {*} Returns the nth element of `array`.
  6669. */
  6670. function baseNth(array, n) {
  6671. var length = array.length;
  6672. if (!length) {
  6673. return;
  6674. }
  6675. n += n < 0 ? length : 0;
  6676. return isIndex(n, length) ? array[n] : undefined;
  6677. }
  6678. /**
  6679. * The base implementation of `_.orderBy` without param guards.
  6680. *
  6681. * @private
  6682. * @param {Array|Object} collection The collection to iterate over.
  6683. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  6684. * @param {string[]} orders The sort orders of `iteratees`.
  6685. * @returns {Array} Returns the new sorted array.
  6686. */
  6687. function baseOrderBy(collection, iteratees, orders) {
  6688. if (iteratees.length) {
  6689. iteratees = arrayMap(iteratees, function(iteratee) {
  6690. if (isArray(iteratee)) {
  6691. return function(value) {
  6692. return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
  6693. }
  6694. }
  6695. return iteratee;
  6696. });
  6697. } else {
  6698. iteratees = [identity];
  6699. }
  6700. var index = -1;
  6701. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  6702. var result = baseMap(collection, function(value, key, collection) {
  6703. var criteria = arrayMap(iteratees, function(iteratee) {
  6704. return iteratee(value);
  6705. });
  6706. return { 'criteria': criteria, 'index': ++index, 'value': value };
  6707. });
  6708. return baseSortBy(result, function(object, other) {
  6709. return compareMultiple(object, other, orders);
  6710. });
  6711. }
  6712. /**
  6713. * The base implementation of `_.pick` without support for individual
  6714. * property identifiers.
  6715. *
  6716. * @private
  6717. * @param {Object} object The source object.
  6718. * @param {string[]} paths The property paths to pick.
  6719. * @returns {Object} Returns the new object.
  6720. */
  6721. function basePick(object, paths) {
  6722. return basePickBy(object, paths, function(value, path) {
  6723. return hasIn(object, path);
  6724. });
  6725. }
  6726. /**
  6727. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  6728. *
  6729. * @private
  6730. * @param {Object} object The source object.
  6731. * @param {string[]} paths The property paths to pick.
  6732. * @param {Function} predicate The function invoked per property.
  6733. * @returns {Object} Returns the new object.
  6734. */
  6735. function basePickBy(object, paths, predicate) {
  6736. var index = -1,
  6737. length = paths.length,
  6738. result = {};
  6739. while (++index < length) {
  6740. var path = paths[index],
  6741. value = baseGet(object, path);
  6742. if (predicate(value, path)) {
  6743. baseSet(result, castPath(path, object), value);
  6744. }
  6745. }
  6746. return result;
  6747. }
  6748. /**
  6749. * A specialized version of `baseProperty` which supports deep paths.
  6750. *
  6751. * @private
  6752. * @param {Array|string} path The path of the property to get.
  6753. * @returns {Function} Returns the new accessor function.
  6754. */
  6755. function basePropertyDeep(path) {
  6756. return function(object) {
  6757. return baseGet(object, path);
  6758. };
  6759. }
  6760. /**
  6761. * The base implementation of `_.pullAllBy` without support for iteratee
  6762. * shorthands.
  6763. *
  6764. * @private
  6765. * @param {Array} array The array to modify.
  6766. * @param {Array} values The values to remove.
  6767. * @param {Function} [iteratee] The iteratee invoked per element.
  6768. * @param {Function} [comparator] The comparator invoked per element.
  6769. * @returns {Array} Returns `array`.
  6770. */
  6771. function basePullAll(array, values, iteratee, comparator) {
  6772. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  6773. index = -1,
  6774. length = values.length,
  6775. seen = array;
  6776. if (array === values) {
  6777. values = copyArray(values);
  6778. }
  6779. if (iteratee) {
  6780. seen = arrayMap(array, baseUnary(iteratee));
  6781. }
  6782. while (++index < length) {
  6783. var fromIndex = 0,
  6784. value = values[index],
  6785. computed = iteratee ? iteratee(value) : value;
  6786. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  6787. if (seen !== array) {
  6788. splice.call(seen, fromIndex, 1);
  6789. }
  6790. splice.call(array, fromIndex, 1);
  6791. }
  6792. }
  6793. return array;
  6794. }
  6795. /**
  6796. * The base implementation of `_.pullAt` without support for individual
  6797. * indexes or capturing the removed elements.
  6798. *
  6799. * @private
  6800. * @param {Array} array The array to modify.
  6801. * @param {number[]} indexes The indexes of elements to remove.
  6802. * @returns {Array} Returns `array`.
  6803. */
  6804. function basePullAt(array, indexes) {
  6805. var length = array ? indexes.length : 0,
  6806. lastIndex = length - 1;
  6807. while (length--) {
  6808. var index = indexes[length];
  6809. if (length == lastIndex || index !== previous) {
  6810. var previous = index;
  6811. if (isIndex(index)) {
  6812. splice.call(array, index, 1);
  6813. } else {
  6814. baseUnset(array, index);
  6815. }
  6816. }
  6817. }
  6818. return array;
  6819. }
  6820. /**
  6821. * The base implementation of `_.random` without support for returning
  6822. * floating-point numbers.
  6823. *
  6824. * @private
  6825. * @param {number} lower The lower bound.
  6826. * @param {number} upper The upper bound.
  6827. * @returns {number} Returns the random number.
  6828. */
  6829. function baseRandom(lower, upper) {
  6830. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  6831. }
  6832. /**
  6833. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  6834. * coerce arguments.
  6835. *
  6836. * @private
  6837. * @param {number} start The start of the range.
  6838. * @param {number} end The end of the range.
  6839. * @param {number} step The value to increment or decrement by.
  6840. * @param {boolean} [fromRight] Specify iterating from right to left.
  6841. * @returns {Array} Returns the range of numbers.
  6842. */
  6843. function baseRange(start, end, step, fromRight) {
  6844. var index = -1,
  6845. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  6846. result = Array(length);
  6847. while (length--) {
  6848. result[fromRight ? length : ++index] = start;
  6849. start += step;
  6850. }
  6851. return result;
  6852. }
  6853. /**
  6854. * The base implementation of `_.repeat` which doesn't coerce arguments.
  6855. *
  6856. * @private
  6857. * @param {string} string The string to repeat.
  6858. * @param {number} n The number of times to repeat the string.
  6859. * @returns {string} Returns the repeated string.
  6860. */
  6861. function baseRepeat(string, n) {
  6862. var result = '';
  6863. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  6864. return result;
  6865. }
  6866. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  6867. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  6868. do {
  6869. if (n % 2) {
  6870. result += string;
  6871. }
  6872. n = nativeFloor(n / 2);
  6873. if (n) {
  6874. string += string;
  6875. }
  6876. } while (n);
  6877. return result;
  6878. }
  6879. /**
  6880. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  6881. *
  6882. * @private
  6883. * @param {Function} func The function to apply a rest parameter to.
  6884. * @param {number} [start=func.length-1] The start position of the rest parameter.
  6885. * @returns {Function} Returns the new function.
  6886. */
  6887. function baseRest(func, start) {
  6888. return setToString(overRest(func, start, identity), func + '');
  6889. }
  6890. /**
  6891. * The base implementation of `_.sample`.
  6892. *
  6893. * @private
  6894. * @param {Array|Object} collection The collection to sample.
  6895. * @returns {*} Returns the random element.
  6896. */
  6897. function baseSample(collection) {
  6898. return arraySample(values(collection));
  6899. }
  6900. /**
  6901. * The base implementation of `_.sampleSize` without param guards.
  6902. *
  6903. * @private
  6904. * @param {Array|Object} collection The collection to sample.
  6905. * @param {number} n The number of elements to sample.
  6906. * @returns {Array} Returns the random elements.
  6907. */
  6908. function baseSampleSize(collection, n) {
  6909. var array = values(collection);
  6910. return shuffleSelf(array, baseClamp(n, 0, array.length));
  6911. }
  6912. /**
  6913. * The base implementation of `_.set`.
  6914. *
  6915. * @private
  6916. * @param {Object} object The object to modify.
  6917. * @param {Array|string} path The path of the property to set.
  6918. * @param {*} value The value to set.
  6919. * @param {Function} [customizer] The function to customize path creation.
  6920. * @returns {Object} Returns `object`.
  6921. */
  6922. function baseSet(object, path, value, customizer) {
  6923. if (!isObject(object)) {
  6924. return object;
  6925. }
  6926. path = castPath(path, object);
  6927. var index = -1,
  6928. length = path.length,
  6929. lastIndex = length - 1,
  6930. nested = object;
  6931. while (nested != null && ++index < length) {
  6932. var key = toKey(path[index]),
  6933. newValue = value;
  6934. if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
  6935. return object;
  6936. }
  6937. if (index != lastIndex) {
  6938. var objValue = nested[key];
  6939. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  6940. if (newValue === undefined) {
  6941. newValue = isObject(objValue)
  6942. ? objValue
  6943. : (isIndex(path[index + 1]) ? [] : {});
  6944. }
  6945. }
  6946. assignValue(nested, key, newValue);
  6947. nested = nested[key];
  6948. }
  6949. return object;
  6950. }
  6951. /**
  6952. * The base implementation of `setData` without support for hot loop shorting.
  6953. *
  6954. * @private
  6955. * @param {Function} func The function to associate metadata with.
  6956. * @param {*} data The metadata.
  6957. * @returns {Function} Returns `func`.
  6958. */
  6959. var baseSetData = !metaMap ? identity : function(func, data) {
  6960. metaMap.set(func, data);
  6961. return func;
  6962. };
  6963. /**
  6964. * The base implementation of `setToString` without support for hot loop shorting.
  6965. *
  6966. * @private
  6967. * @param {Function} func The function to modify.
  6968. * @param {Function} string The `toString` result.
  6969. * @returns {Function} Returns `func`.
  6970. */
  6971. var baseSetToString = !defineProperty ? identity : function(func, string) {
  6972. return defineProperty(func, 'toString', {
  6973. 'configurable': true,
  6974. 'enumerable': false,
  6975. 'value': constant(string),
  6976. 'writable': true
  6977. });
  6978. };
  6979. /**
  6980. * The base implementation of `_.shuffle`.
  6981. *
  6982. * @private
  6983. * @param {Array|Object} collection The collection to shuffle.
  6984. * @returns {Array} Returns the new shuffled array.
  6985. */
  6986. function baseShuffle(collection) {
  6987. return shuffleSelf(values(collection));
  6988. }
  6989. /**
  6990. * The base implementation of `_.slice` without an iteratee call guard.
  6991. *
  6992. * @private
  6993. * @param {Array} array The array to slice.
  6994. * @param {number} [start=0] The start position.
  6995. * @param {number} [end=array.length] The end position.
  6996. * @returns {Array} Returns the slice of `array`.
  6997. */
  6998. function baseSlice(array, start, end) {
  6999. var index = -1,
  7000. length = array.length;
  7001. if (start < 0) {
  7002. start = -start > length ? 0 : (length + start);
  7003. }
  7004. end = end > length ? length : end;
  7005. if (end < 0) {
  7006. end += length;
  7007. }
  7008. length = start > end ? 0 : ((end - start) >>> 0);
  7009. start >>>= 0;
  7010. var result = Array(length);
  7011. while (++index < length) {
  7012. result[index] = array[index + start];
  7013. }
  7014. return result;
  7015. }
  7016. /**
  7017. * The base implementation of `_.some` without support for iteratee shorthands.
  7018. *
  7019. * @private
  7020. * @param {Array|Object} collection The collection to iterate over.
  7021. * @param {Function} predicate The function invoked per iteration.
  7022. * @returns {boolean} Returns `true` if any element passes the predicate check,
  7023. * else `false`.
  7024. */
  7025. function baseSome(collection, predicate) {
  7026. var result;
  7027. baseEach(collection, function(value, index, collection) {
  7028. result = predicate(value, index, collection);
  7029. return !result;
  7030. });
  7031. return !!result;
  7032. }
  7033. /**
  7034. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  7035. * performs a binary search of `array` to determine the index at which `value`
  7036. * should be inserted into `array` in order to maintain its sort order.
  7037. *
  7038. * @private
  7039. * @param {Array} array The sorted array to inspect.
  7040. * @param {*} value The value to evaluate.
  7041. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  7042. * @returns {number} Returns the index at which `value` should be inserted
  7043. * into `array`.
  7044. */
  7045. function baseSortedIndex(array, value, retHighest) {
  7046. var low = 0,
  7047. high = array == null ? low : array.length;
  7048. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  7049. while (low < high) {
  7050. var mid = (low + high) >>> 1,
  7051. computed = array[mid];
  7052. if (computed !== null && !isSymbol(computed) &&
  7053. (retHighest ? (computed <= value) : (computed < value))) {
  7054. low = mid + 1;
  7055. } else {
  7056. high = mid;
  7057. }
  7058. }
  7059. return high;
  7060. }
  7061. return baseSortedIndexBy(array, value, identity, retHighest);
  7062. }
  7063. /**
  7064. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  7065. * which invokes `iteratee` for `value` and each element of `array` to compute
  7066. * their sort ranking. The iteratee is invoked with one argument; (value).
  7067. *
  7068. * @private
  7069. * @param {Array} array The sorted array to inspect.
  7070. * @param {*} value The value to evaluate.
  7071. * @param {Function} iteratee The iteratee invoked per element.
  7072. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  7073. * @returns {number} Returns the index at which `value` should be inserted
  7074. * into `array`.
  7075. */
  7076. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  7077. var low = 0,
  7078. high = array == null ? 0 : array.length;
  7079. if (high === 0) {
  7080. return 0;
  7081. }
  7082. value = iteratee(value);
  7083. var valIsNaN = value !== value,
  7084. valIsNull = value === null,
  7085. valIsSymbol = isSymbol(value),
  7086. valIsUndefined = value === undefined;
  7087. while (low < high) {
  7088. var mid = nativeFloor((low + high) / 2),
  7089. computed = iteratee(array[mid]),
  7090. othIsDefined = computed !== undefined,
  7091. othIsNull = computed === null,
  7092. othIsReflexive = computed === computed,
  7093. othIsSymbol = isSymbol(computed);
  7094. if (valIsNaN) {
  7095. var setLow = retHighest || othIsReflexive;
  7096. } else if (valIsUndefined) {
  7097. setLow = othIsReflexive && (retHighest || othIsDefined);
  7098. } else if (valIsNull) {
  7099. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  7100. } else if (valIsSymbol) {
  7101. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  7102. } else if (othIsNull || othIsSymbol) {
  7103. setLow = false;
  7104. } else {
  7105. setLow = retHighest ? (computed <= value) : (computed < value);
  7106. }
  7107. if (setLow) {
  7108. low = mid + 1;
  7109. } else {
  7110. high = mid;
  7111. }
  7112. }
  7113. return nativeMin(high, MAX_ARRAY_INDEX);
  7114. }
  7115. /**
  7116. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  7117. * support for iteratee shorthands.
  7118. *
  7119. * @private
  7120. * @param {Array} array The array to inspect.
  7121. * @param {Function} [iteratee] The iteratee invoked per element.
  7122. * @returns {Array} Returns the new duplicate free array.
  7123. */
  7124. function baseSortedUniq(array, iteratee) {
  7125. var index = -1,
  7126. length = array.length,
  7127. resIndex = 0,
  7128. result = [];
  7129. while (++index < length) {
  7130. var value = array[index],
  7131. computed = iteratee ? iteratee(value) : value;
  7132. if (!index || !eq(computed, seen)) {
  7133. var seen = computed;
  7134. result[resIndex++] = value === 0 ? 0 : value;
  7135. }
  7136. }
  7137. return result;
  7138. }
  7139. /**
  7140. * The base implementation of `_.toNumber` which doesn't ensure correct
  7141. * conversions of binary, hexadecimal, or octal string values.
  7142. *
  7143. * @private
  7144. * @param {*} value The value to process.
  7145. * @returns {number} Returns the number.
  7146. */
  7147. function baseToNumber(value) {
  7148. if (typeof value == 'number') {
  7149. return value;
  7150. }
  7151. if (isSymbol(value)) {
  7152. return NAN;
  7153. }
  7154. return +value;
  7155. }
  7156. /**
  7157. * The base implementation of `_.toString` which doesn't convert nullish
  7158. * values to empty strings.
  7159. *
  7160. * @private
  7161. * @param {*} value The value to process.
  7162. * @returns {string} Returns the string.
  7163. */
  7164. function baseToString(value) {
  7165. // Exit early for strings to avoid a performance hit in some environments.
  7166. if (typeof value == 'string') {
  7167. return value;
  7168. }
  7169. if (isArray(value)) {
  7170. // Recursively convert values (susceptible to call stack limits).
  7171. return arrayMap(value, baseToString) + '';
  7172. }
  7173. if (isSymbol(value)) {
  7174. return symbolToString ? symbolToString.call(value) : '';
  7175. }
  7176. var result = (value + '');
  7177. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  7178. }
  7179. /**
  7180. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  7181. *
  7182. * @private
  7183. * @param {Array} array The array to inspect.
  7184. * @param {Function} [iteratee] The iteratee invoked per element.
  7185. * @param {Function} [comparator] The comparator invoked per element.
  7186. * @returns {Array} Returns the new duplicate free array.
  7187. */
  7188. function baseUniq(array, iteratee, comparator) {
  7189. var index = -1,
  7190. includes = arrayIncludes,
  7191. length = array.length,
  7192. isCommon = true,
  7193. result = [],
  7194. seen = result;
  7195. if (comparator) {
  7196. isCommon = false;
  7197. includes = arrayIncludesWith;
  7198. }
  7199. else if (length >= LARGE_ARRAY_SIZE) {
  7200. var set = iteratee ? null : createSet(array);
  7201. if (set) {
  7202. return setToArray(set);
  7203. }
  7204. isCommon = false;
  7205. includes = cacheHas;
  7206. seen = new SetCache;
  7207. }
  7208. else {
  7209. seen = iteratee ? [] : result;
  7210. }
  7211. outer:
  7212. while (++index < length) {
  7213. var value = array[index],
  7214. computed = iteratee ? iteratee(value) : value;
  7215. value = (comparator || value !== 0) ? value : 0;
  7216. if (isCommon && computed === computed) {
  7217. var seenIndex = seen.length;
  7218. while (seenIndex--) {
  7219. if (seen[seenIndex] === computed) {
  7220. continue outer;
  7221. }
  7222. }
  7223. if (iteratee) {
  7224. seen.push(computed);
  7225. }
  7226. result.push(value);
  7227. }
  7228. else if (!includes(seen, computed, comparator)) {
  7229. if (seen !== result) {
  7230. seen.push(computed);
  7231. }
  7232. result.push(value);
  7233. }
  7234. }
  7235. return result;
  7236. }
  7237. /**
  7238. * The base implementation of `_.unset`.
  7239. *
  7240. * @private
  7241. * @param {Object} object The object to modify.
  7242. * @param {Array|string} path The property path to unset.
  7243. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  7244. */
  7245. function baseUnset(object, path) {
  7246. path = castPath(path, object);
  7247. object = parent(object, path);
  7248. return object == null || delete object[toKey(last(path))];
  7249. }
  7250. /**
  7251. * The base implementation of `_.update`.
  7252. *
  7253. * @private
  7254. * @param {Object} object The object to modify.
  7255. * @param {Array|string} path The path of the property to update.
  7256. * @param {Function} updater The function to produce the updated value.
  7257. * @param {Function} [customizer] The function to customize path creation.
  7258. * @returns {Object} Returns `object`.
  7259. */
  7260. function baseUpdate(object, path, updater, customizer) {
  7261. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  7262. }
  7263. /**
  7264. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  7265. * without support for iteratee shorthands.
  7266. *
  7267. * @private
  7268. * @param {Array} array The array to query.
  7269. * @param {Function} predicate The function invoked per iteration.
  7270. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  7271. * @param {boolean} [fromRight] Specify iterating from right to left.
  7272. * @returns {Array} Returns the slice of `array`.
  7273. */
  7274. function baseWhile(array, predicate, isDrop, fromRight) {
  7275. var length = array.length,
  7276. index = fromRight ? length : -1;
  7277. while ((fromRight ? index-- : ++index < length) &&
  7278. predicate(array[index], index, array)) {}
  7279. return isDrop
  7280. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  7281. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  7282. }
  7283. /**
  7284. * The base implementation of `wrapperValue` which returns the result of
  7285. * performing a sequence of actions on the unwrapped `value`, where each
  7286. * successive action is supplied the return value of the previous.
  7287. *
  7288. * @private
  7289. * @param {*} value The unwrapped value.
  7290. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  7291. * @returns {*} Returns the resolved value.
  7292. */
  7293. function baseWrapperValue(value, actions) {
  7294. var result = value;
  7295. if (result instanceof LazyWrapper) {
  7296. result = result.value();
  7297. }
  7298. return arrayReduce(actions, function(result, action) {
  7299. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  7300. }, result);
  7301. }
  7302. /**
  7303. * The base implementation of methods like `_.xor`, without support for
  7304. * iteratee shorthands, that accepts an array of arrays to inspect.
  7305. *
  7306. * @private
  7307. * @param {Array} arrays The arrays to inspect.
  7308. * @param {Function} [iteratee] The iteratee invoked per element.
  7309. * @param {Function} [comparator] The comparator invoked per element.
  7310. * @returns {Array} Returns the new array of values.
  7311. */
  7312. function baseXor(arrays, iteratee, comparator) {
  7313. var length = arrays.length;
  7314. if (length < 2) {
  7315. return length ? baseUniq(arrays[0]) : [];
  7316. }
  7317. var index = -1,
  7318. result = Array(length);
  7319. while (++index < length) {
  7320. var array = arrays[index],
  7321. othIndex = -1;
  7322. while (++othIndex < length) {
  7323. if (othIndex != index) {
  7324. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  7325. }
  7326. }
  7327. }
  7328. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  7329. }
  7330. /**
  7331. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  7332. *
  7333. * @private
  7334. * @param {Array} props The property identifiers.
  7335. * @param {Array} values The property values.
  7336. * @param {Function} assignFunc The function to assign values.
  7337. * @returns {Object} Returns the new object.
  7338. */
  7339. function baseZipObject(props, values, assignFunc) {
  7340. var index = -1,
  7341. length = props.length,
  7342. valsLength = values.length,
  7343. result = {};
  7344. while (++index < length) {
  7345. var value = index < valsLength ? values[index] : undefined;
  7346. assignFunc(result, props[index], value);
  7347. }
  7348. return result;
  7349. }
  7350. /**
  7351. * Casts `value` to an empty array if it's not an array like object.
  7352. *
  7353. * @private
  7354. * @param {*} value The value to inspect.
  7355. * @returns {Array|Object} Returns the cast array-like object.
  7356. */
  7357. function castArrayLikeObject(value) {
  7358. return isArrayLikeObject(value) ? value : [];
  7359. }
  7360. /**
  7361. * Casts `value` to `identity` if it's not a function.
  7362. *
  7363. * @private
  7364. * @param {*} value The value to inspect.
  7365. * @returns {Function} Returns cast function.
  7366. */
  7367. function castFunction(value) {
  7368. return typeof value == 'function' ? value : identity;
  7369. }
  7370. /**
  7371. * Casts `value` to a path array if it's not one.
  7372. *
  7373. * @private
  7374. * @param {*} value The value to inspect.
  7375. * @param {Object} [object] The object to query keys on.
  7376. * @returns {Array} Returns the cast property path array.
  7377. */
  7378. function castPath(value, object) {
  7379. if (isArray(value)) {
  7380. return value;
  7381. }
  7382. return isKey(value, object) ? [value] : stringToPath(toString(value));
  7383. }
  7384. /**
  7385. * A `baseRest` alias which can be replaced with `identity` by module
  7386. * replacement plugins.
  7387. *
  7388. * @private
  7389. * @type {Function}
  7390. * @param {Function} func The function to apply a rest parameter to.
  7391. * @returns {Function} Returns the new function.
  7392. */
  7393. var castRest = baseRest;
  7394. /**
  7395. * Casts `array` to a slice if it's needed.
  7396. *
  7397. * @private
  7398. * @param {Array} array The array to inspect.
  7399. * @param {number} start The start position.
  7400. * @param {number} [end=array.length] The end position.
  7401. * @returns {Array} Returns the cast slice.
  7402. */
  7403. function castSlice(array, start, end) {
  7404. var length = array.length;
  7405. end = end === undefined ? length : end;
  7406. return (!start && end >= length) ? array : baseSlice(array, start, end);
  7407. }
  7408. /**
  7409. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  7410. *
  7411. * @private
  7412. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  7413. */
  7414. var clearTimeout = ctxClearTimeout || function(id) {
  7415. return root.clearTimeout(id);
  7416. };
  7417. /**
  7418. * Creates a clone of `buffer`.
  7419. *
  7420. * @private
  7421. * @param {Buffer} buffer The buffer to clone.
  7422. * @param {boolean} [isDeep] Specify a deep clone.
  7423. * @returns {Buffer} Returns the cloned buffer.
  7424. */
  7425. function cloneBuffer(buffer, isDeep) {
  7426. if (isDeep) {
  7427. return buffer.slice();
  7428. }
  7429. var length = buffer.length,
  7430. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  7431. buffer.copy(result);
  7432. return result;
  7433. }
  7434. /**
  7435. * Creates a clone of `arrayBuffer`.
  7436. *
  7437. * @private
  7438. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  7439. * @returns {ArrayBuffer} Returns the cloned array buffer.
  7440. */
  7441. function cloneArrayBuffer(arrayBuffer) {
  7442. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  7443. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  7444. return result;
  7445. }
  7446. /**
  7447. * Creates a clone of `dataView`.
  7448. *
  7449. * @private
  7450. * @param {Object} dataView The data view to clone.
  7451. * @param {boolean} [isDeep] Specify a deep clone.
  7452. * @returns {Object} Returns the cloned data view.
  7453. */
  7454. function cloneDataView(dataView, isDeep) {
  7455. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  7456. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  7457. }
  7458. /**
  7459. * Creates a clone of `regexp`.
  7460. *
  7461. * @private
  7462. * @param {Object} regexp The regexp to clone.
  7463. * @returns {Object} Returns the cloned regexp.
  7464. */
  7465. function cloneRegExp(regexp) {
  7466. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  7467. result.lastIndex = regexp.lastIndex;
  7468. return result;
  7469. }
  7470. /**
  7471. * Creates a clone of the `symbol` object.
  7472. *
  7473. * @private
  7474. * @param {Object} symbol The symbol object to clone.
  7475. * @returns {Object} Returns the cloned symbol object.
  7476. */
  7477. function cloneSymbol(symbol) {
  7478. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  7479. }
  7480. /**
  7481. * Creates a clone of `typedArray`.
  7482. *
  7483. * @private
  7484. * @param {Object} typedArray The typed array to clone.
  7485. * @param {boolean} [isDeep] Specify a deep clone.
  7486. * @returns {Object} Returns the cloned typed array.
  7487. */
  7488. function cloneTypedArray(typedArray, isDeep) {
  7489. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  7490. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  7491. }
  7492. /**
  7493. * Compares values to sort them in ascending order.
  7494. *
  7495. * @private
  7496. * @param {*} value The value to compare.
  7497. * @param {*} other The other value to compare.
  7498. * @returns {number} Returns the sort order indicator for `value`.
  7499. */
  7500. function compareAscending(value, other) {
  7501. if (value !== other) {
  7502. var valIsDefined = value !== undefined,
  7503. valIsNull = value === null,
  7504. valIsReflexive = value === value,
  7505. valIsSymbol = isSymbol(value);
  7506. var othIsDefined = other !== undefined,
  7507. othIsNull = other === null,
  7508. othIsReflexive = other === other,
  7509. othIsSymbol = isSymbol(other);
  7510. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  7511. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  7512. (valIsNull && othIsDefined && othIsReflexive) ||
  7513. (!valIsDefined && othIsReflexive) ||
  7514. !valIsReflexive) {
  7515. return 1;
  7516. }
  7517. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  7518. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  7519. (othIsNull && valIsDefined && valIsReflexive) ||
  7520. (!othIsDefined && valIsReflexive) ||
  7521. !othIsReflexive) {
  7522. return -1;
  7523. }
  7524. }
  7525. return 0;
  7526. }
  7527. /**
  7528. * Used by `_.orderBy` to compare multiple properties of a value to another
  7529. * and stable sort them.
  7530. *
  7531. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  7532. * specify an order of "desc" for descending or "asc" for ascending sort order
  7533. * of corresponding values.
  7534. *
  7535. * @private
  7536. * @param {Object} object The object to compare.
  7537. * @param {Object} other The other object to compare.
  7538. * @param {boolean[]|string[]} orders The order to sort by for each property.
  7539. * @returns {number} Returns the sort order indicator for `object`.
  7540. */
  7541. function compareMultiple(object, other, orders) {
  7542. var index = -1,
  7543. objCriteria = object.criteria,
  7544. othCriteria = other.criteria,
  7545. length = objCriteria.length,
  7546. ordersLength = orders.length;
  7547. while (++index < length) {
  7548. var result = compareAscending(objCriteria[index], othCriteria[index]);
  7549. if (result) {
  7550. if (index >= ordersLength) {
  7551. return result;
  7552. }
  7553. var order = orders[index];
  7554. return result * (order == 'desc' ? -1 : 1);
  7555. }
  7556. }
  7557. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  7558. // that causes it, under certain circumstances, to provide the same value for
  7559. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  7560. // for more details.
  7561. //
  7562. // This also ensures a stable sort in V8 and other engines.
  7563. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  7564. return object.index - other.index;
  7565. }
  7566. /**
  7567. * Creates an array that is the composition of partially applied arguments,
  7568. * placeholders, and provided arguments into a single array of arguments.
  7569. *
  7570. * @private
  7571. * @param {Array} args The provided arguments.
  7572. * @param {Array} partials The arguments to prepend to those provided.
  7573. * @param {Array} holders The `partials` placeholder indexes.
  7574. * @params {boolean} [isCurried] Specify composing for a curried function.
  7575. * @returns {Array} Returns the new array of composed arguments.
  7576. */
  7577. function composeArgs(args, partials, holders, isCurried) {
  7578. var argsIndex = -1,
  7579. argsLength = args.length,
  7580. holdersLength = holders.length,
  7581. leftIndex = -1,
  7582. leftLength = partials.length,
  7583. rangeLength = nativeMax(argsLength - holdersLength, 0),
  7584. result = Array(leftLength + rangeLength),
  7585. isUncurried = !isCurried;
  7586. while (++leftIndex < leftLength) {
  7587. result[leftIndex] = partials[leftIndex];
  7588. }
  7589. while (++argsIndex < holdersLength) {
  7590. if (isUncurried || argsIndex < argsLength) {
  7591. result[holders[argsIndex]] = args[argsIndex];
  7592. }
  7593. }
  7594. while (rangeLength--) {
  7595. result[leftIndex++] = args[argsIndex++];
  7596. }
  7597. return result;
  7598. }
  7599. /**
  7600. * This function is like `composeArgs` except that the arguments composition
  7601. * is tailored for `_.partialRight`.
  7602. *
  7603. * @private
  7604. * @param {Array} args The provided arguments.
  7605. * @param {Array} partials The arguments to append to those provided.
  7606. * @param {Array} holders The `partials` placeholder indexes.
  7607. * @params {boolean} [isCurried] Specify composing for a curried function.
  7608. * @returns {Array} Returns the new array of composed arguments.
  7609. */
  7610. function composeArgsRight(args, partials, holders, isCurried) {
  7611. var argsIndex = -1,
  7612. argsLength = args.length,
  7613. holdersIndex = -1,
  7614. holdersLength = holders.length,
  7615. rightIndex = -1,
  7616. rightLength = partials.length,
  7617. rangeLength = nativeMax(argsLength - holdersLength, 0),
  7618. result = Array(rangeLength + rightLength),
  7619. isUncurried = !isCurried;
  7620. while (++argsIndex < rangeLength) {
  7621. result[argsIndex] = args[argsIndex];
  7622. }
  7623. var offset = argsIndex;
  7624. while (++rightIndex < rightLength) {
  7625. result[offset + rightIndex] = partials[rightIndex];
  7626. }
  7627. while (++holdersIndex < holdersLength) {
  7628. if (isUncurried || argsIndex < argsLength) {
  7629. result[offset + holders[holdersIndex]] = args[argsIndex++];
  7630. }
  7631. }
  7632. return result;
  7633. }
  7634. /**
  7635. * Copies the values of `source` to `array`.
  7636. *
  7637. * @private
  7638. * @param {Array} source The array to copy values from.
  7639. * @param {Array} [array=[]] The array to copy values to.
  7640. * @returns {Array} Returns `array`.
  7641. */
  7642. function copyArray(source, array) {
  7643. var index = -1,
  7644. length = source.length;
  7645. array || (array = Array(length));
  7646. while (++index < length) {
  7647. array[index] = source[index];
  7648. }
  7649. return array;
  7650. }
  7651. /**
  7652. * Copies properties of `source` to `object`.
  7653. *
  7654. * @private
  7655. * @param {Object} source The object to copy properties from.
  7656. * @param {Array} props The property identifiers to copy.
  7657. * @param {Object} [object={}] The object to copy properties to.
  7658. * @param {Function} [customizer] The function to customize copied values.
  7659. * @returns {Object} Returns `object`.
  7660. */
  7661. function copyObject(source, props, object, customizer) {
  7662. var isNew = !object;
  7663. object || (object = {});
  7664. var index = -1,
  7665. length = props.length;
  7666. while (++index < length) {
  7667. var key = props[index];
  7668. var newValue = customizer
  7669. ? customizer(object[key], source[key], key, object, source)
  7670. : undefined;
  7671. if (newValue === undefined) {
  7672. newValue = source[key];
  7673. }
  7674. if (isNew) {
  7675. baseAssignValue(object, key, newValue);
  7676. } else {
  7677. assignValue(object, key, newValue);
  7678. }
  7679. }
  7680. return object;
  7681. }
  7682. /**
  7683. * Copies own symbols of `source` to `object`.
  7684. *
  7685. * @private
  7686. * @param {Object} source The object to copy symbols from.
  7687. * @param {Object} [object={}] The object to copy symbols to.
  7688. * @returns {Object} Returns `object`.
  7689. */
  7690. function copySymbols(source, object) {
  7691. return copyObject(source, getSymbols(source), object);
  7692. }
  7693. /**
  7694. * Copies own and inherited symbols of `source` to `object`.
  7695. *
  7696. * @private
  7697. * @param {Object} source The object to copy symbols from.
  7698. * @param {Object} [object={}] The object to copy symbols to.
  7699. * @returns {Object} Returns `object`.
  7700. */
  7701. function copySymbolsIn(source, object) {
  7702. return copyObject(source, getSymbolsIn(source), object);
  7703. }
  7704. /**
  7705. * Creates a function like `_.groupBy`.
  7706. *
  7707. * @private
  7708. * @param {Function} setter The function to set accumulator values.
  7709. * @param {Function} [initializer] The accumulator object initializer.
  7710. * @returns {Function} Returns the new aggregator function.
  7711. */
  7712. function createAggregator(setter, initializer) {
  7713. return function(collection, iteratee) {
  7714. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  7715. accumulator = initializer ? initializer() : {};
  7716. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  7717. };
  7718. }
  7719. /**
  7720. * Creates a function like `_.assign`.
  7721. *
  7722. * @private
  7723. * @param {Function} assigner The function to assign values.
  7724. * @returns {Function} Returns the new assigner function.
  7725. */
  7726. function createAssigner(assigner) {
  7727. return baseRest(function(object, sources) {
  7728. var index = -1,
  7729. length = sources.length,
  7730. customizer = length > 1 ? sources[length - 1] : undefined,
  7731. guard = length > 2 ? sources[2] : undefined;
  7732. customizer = (assigner.length > 3 && typeof customizer == 'function')
  7733. ? (length--, customizer)
  7734. : undefined;
  7735. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  7736. customizer = length < 3 ? undefined : customizer;
  7737. length = 1;
  7738. }
  7739. object = Object(object);
  7740. while (++index < length) {
  7741. var source = sources[index];
  7742. if (source) {
  7743. assigner(object, source, index, customizer);
  7744. }
  7745. }
  7746. return object;
  7747. });
  7748. }
  7749. /**
  7750. * Creates a `baseEach` or `baseEachRight` function.
  7751. *
  7752. * @private
  7753. * @param {Function} eachFunc The function to iterate over a collection.
  7754. * @param {boolean} [fromRight] Specify iterating from right to left.
  7755. * @returns {Function} Returns the new base function.
  7756. */
  7757. function createBaseEach(eachFunc, fromRight) {
  7758. return function(collection, iteratee) {
  7759. if (collection == null) {
  7760. return collection;
  7761. }
  7762. if (!isArrayLike(collection)) {
  7763. return eachFunc(collection, iteratee);
  7764. }
  7765. var length = collection.length,
  7766. index = fromRight ? length : -1,
  7767. iterable = Object(collection);
  7768. while ((fromRight ? index-- : ++index < length)) {
  7769. if (iteratee(iterable[index], index, iterable) === false) {
  7770. break;
  7771. }
  7772. }
  7773. return collection;
  7774. };
  7775. }
  7776. /**
  7777. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  7778. *
  7779. * @private
  7780. * @param {boolean} [fromRight] Specify iterating from right to left.
  7781. * @returns {Function} Returns the new base function.
  7782. */
  7783. function createBaseFor(fromRight) {
  7784. return function(object, iteratee, keysFunc) {
  7785. var index = -1,
  7786. iterable = Object(object),
  7787. props = keysFunc(object),
  7788. length = props.length;
  7789. while (length--) {
  7790. var key = props[fromRight ? length : ++index];
  7791. if (iteratee(iterable[key], key, iterable) === false) {
  7792. break;
  7793. }
  7794. }
  7795. return object;
  7796. };
  7797. }
  7798. /**
  7799. * Creates a function that wraps `func` to invoke it with the optional `this`
  7800. * binding of `thisArg`.
  7801. *
  7802. * @private
  7803. * @param {Function} func The function to wrap.
  7804. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  7805. * @param {*} [thisArg] The `this` binding of `func`.
  7806. * @returns {Function} Returns the new wrapped function.
  7807. */
  7808. function createBind(func, bitmask, thisArg) {
  7809. var isBind = bitmask & WRAP_BIND_FLAG,
  7810. Ctor = createCtor(func);
  7811. function wrapper() {
  7812. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  7813. return fn.apply(isBind ? thisArg : this, arguments);
  7814. }
  7815. return wrapper;
  7816. }
  7817. /**
  7818. * Creates a function like `_.lowerFirst`.
  7819. *
  7820. * @private
  7821. * @param {string} methodName The name of the `String` case method to use.
  7822. * @returns {Function} Returns the new case function.
  7823. */
  7824. function createCaseFirst(methodName) {
  7825. return function(string) {
  7826. string = toString(string);
  7827. var strSymbols = hasUnicode(string)
  7828. ? stringToArray(string)
  7829. : undefined;
  7830. var chr = strSymbols
  7831. ? strSymbols[0]
  7832. : string.charAt(0);
  7833. var trailing = strSymbols
  7834. ? castSlice(strSymbols, 1).join('')
  7835. : string.slice(1);
  7836. return chr[methodName]() + trailing;
  7837. };
  7838. }
  7839. /**
  7840. * Creates a function like `_.camelCase`.
  7841. *
  7842. * @private
  7843. * @param {Function} callback The function to combine each word.
  7844. * @returns {Function} Returns the new compounder function.
  7845. */
  7846. function createCompounder(callback) {
  7847. return function(string) {
  7848. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  7849. };
  7850. }
  7851. /**
  7852. * Creates a function that produces an instance of `Ctor` regardless of
  7853. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  7854. *
  7855. * @private
  7856. * @param {Function} Ctor The constructor to wrap.
  7857. * @returns {Function} Returns the new wrapped function.
  7858. */
  7859. function createCtor(Ctor) {
  7860. return function() {
  7861. // Use a `switch` statement to work with class constructors. See
  7862. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  7863. // for more details.
  7864. var args = arguments;
  7865. switch (args.length) {
  7866. case 0: return new Ctor;
  7867. case 1: return new Ctor(args[0]);
  7868. case 2: return new Ctor(args[0], args[1]);
  7869. case 3: return new Ctor(args[0], args[1], args[2]);
  7870. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  7871. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  7872. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  7873. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  7874. }
  7875. var thisBinding = baseCreate(Ctor.prototype),
  7876. result = Ctor.apply(thisBinding, args);
  7877. // Mimic the constructor's `return` behavior.
  7878. // See https://es5.github.io/#x13.2.2 for more details.
  7879. return isObject(result) ? result : thisBinding;
  7880. };
  7881. }
  7882. /**
  7883. * Creates a function that wraps `func` to enable currying.
  7884. *
  7885. * @private
  7886. * @param {Function} func The function to wrap.
  7887. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  7888. * @param {number} arity The arity of `func`.
  7889. * @returns {Function} Returns the new wrapped function.
  7890. */
  7891. function createCurry(func, bitmask, arity) {
  7892. var Ctor = createCtor(func);
  7893. function wrapper() {
  7894. var length = arguments.length,
  7895. args = Array(length),
  7896. index = length,
  7897. placeholder = getHolder(wrapper);
  7898. while (index--) {
  7899. args[index] = arguments[index];
  7900. }
  7901. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  7902. ? []
  7903. : replaceHolders(args, placeholder);
  7904. length -= holders.length;
  7905. if (length < arity) {
  7906. return createRecurry(
  7907. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  7908. args, holders, undefined, undefined, arity - length);
  7909. }
  7910. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  7911. return apply(fn, this, args);
  7912. }
  7913. return wrapper;
  7914. }
  7915. /**
  7916. * Creates a `_.find` or `_.findLast` function.
  7917. *
  7918. * @private
  7919. * @param {Function} findIndexFunc The function to find the collection index.
  7920. * @returns {Function} Returns the new find function.
  7921. */
  7922. function createFind(findIndexFunc) {
  7923. return function(collection, predicate, fromIndex) {
  7924. var iterable = Object(collection);
  7925. if (!isArrayLike(collection)) {
  7926. var iteratee = getIteratee(predicate, 3);
  7927. collection = keys(collection);
  7928. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  7929. }
  7930. var index = findIndexFunc(collection, predicate, fromIndex);
  7931. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  7932. };
  7933. }
  7934. /**
  7935. * Creates a `_.flow` or `_.flowRight` function.
  7936. *
  7937. * @private
  7938. * @param {boolean} [fromRight] Specify iterating from right to left.
  7939. * @returns {Function} Returns the new flow function.
  7940. */
  7941. function createFlow(fromRight) {
  7942. return flatRest(function(funcs) {
  7943. var length = funcs.length,
  7944. index = length,
  7945. prereq = LodashWrapper.prototype.thru;
  7946. if (fromRight) {
  7947. funcs.reverse();
  7948. }
  7949. while (index--) {
  7950. var func = funcs[index];
  7951. if (typeof func != 'function') {
  7952. throw new TypeError(FUNC_ERROR_TEXT);
  7953. }
  7954. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  7955. var wrapper = new LodashWrapper([], true);
  7956. }
  7957. }
  7958. index = wrapper ? index : length;
  7959. while (++index < length) {
  7960. func = funcs[index];
  7961. var funcName = getFuncName(func),
  7962. data = funcName == 'wrapper' ? getData(func) : undefined;
  7963. if (data && isLaziable(data[0]) &&
  7964. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  7965. !data[4].length && data[9] == 1
  7966. ) {
  7967. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  7968. } else {
  7969. wrapper = (func.length == 1 && isLaziable(func))
  7970. ? wrapper[funcName]()
  7971. : wrapper.thru(func);
  7972. }
  7973. }
  7974. return function() {
  7975. var args = arguments,
  7976. value = args[0];
  7977. if (wrapper && args.length == 1 && isArray(value)) {
  7978. return wrapper.plant(value).value();
  7979. }
  7980. var index = 0,
  7981. result = length ? funcs[index].apply(this, args) : value;
  7982. while (++index < length) {
  7983. result = funcs[index].call(this, result);
  7984. }
  7985. return result;
  7986. };
  7987. });
  7988. }
  7989. /**
  7990. * Creates a function that wraps `func` to invoke it with optional `this`
  7991. * binding of `thisArg`, partial application, and currying.
  7992. *
  7993. * @private
  7994. * @param {Function|string} func The function or method name to wrap.
  7995. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  7996. * @param {*} [thisArg] The `this` binding of `func`.
  7997. * @param {Array} [partials] The arguments to prepend to those provided to
  7998. * the new function.
  7999. * @param {Array} [holders] The `partials` placeholder indexes.
  8000. * @param {Array} [partialsRight] The arguments to append to those provided
  8001. * to the new function.
  8002. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  8003. * @param {Array} [argPos] The argument positions of the new function.
  8004. * @param {number} [ary] The arity cap of `func`.
  8005. * @param {number} [arity] The arity of `func`.
  8006. * @returns {Function} Returns the new wrapped function.
  8007. */
  8008. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  8009. var isAry = bitmask & WRAP_ARY_FLAG,
  8010. isBind = bitmask & WRAP_BIND_FLAG,
  8011. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  8012. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  8013. isFlip = bitmask & WRAP_FLIP_FLAG,
  8014. Ctor = isBindKey ? undefined : createCtor(func);
  8015. function wrapper() {
  8016. var length = arguments.length,
  8017. args = Array(length),
  8018. index = length;
  8019. while (index--) {
  8020. args[index] = arguments[index];
  8021. }
  8022. if (isCurried) {
  8023. var placeholder = getHolder(wrapper),
  8024. holdersCount = countHolders(args, placeholder);
  8025. }
  8026. if (partials) {
  8027. args = composeArgs(args, partials, holders, isCurried);
  8028. }
  8029. if (partialsRight) {
  8030. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  8031. }
  8032. length -= holdersCount;
  8033. if (isCurried && length < arity) {
  8034. var newHolders = replaceHolders(args, placeholder);
  8035. return createRecurry(
  8036. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  8037. args, newHolders, argPos, ary, arity - length
  8038. );
  8039. }
  8040. var thisBinding = isBind ? thisArg : this,
  8041. fn = isBindKey ? thisBinding[func] : func;
  8042. length = args.length;
  8043. if (argPos) {
  8044. args = reorder(args, argPos);
  8045. } else if (isFlip && length > 1) {
  8046. args.reverse();
  8047. }
  8048. if (isAry && ary < length) {
  8049. args.length = ary;
  8050. }
  8051. if (this && this !== root && this instanceof wrapper) {
  8052. fn = Ctor || createCtor(fn);
  8053. }
  8054. return fn.apply(thisBinding, args);
  8055. }
  8056. return wrapper;
  8057. }
  8058. /**
  8059. * Creates a function like `_.invertBy`.
  8060. *
  8061. * @private
  8062. * @param {Function} setter The function to set accumulator values.
  8063. * @param {Function} toIteratee The function to resolve iteratees.
  8064. * @returns {Function} Returns the new inverter function.
  8065. */
  8066. function createInverter(setter, toIteratee) {
  8067. return function(object, iteratee) {
  8068. return baseInverter(object, setter, toIteratee(iteratee), {});
  8069. };
  8070. }
  8071. /**
  8072. * Creates a function that performs a mathematical operation on two values.
  8073. *
  8074. * @private
  8075. * @param {Function} operator The function to perform the operation.
  8076. * @param {number} [defaultValue] The value used for `undefined` arguments.
  8077. * @returns {Function} Returns the new mathematical operation function.
  8078. */
  8079. function createMathOperation(operator, defaultValue) {
  8080. return function(value, other) {
  8081. var result;
  8082. if (value === undefined && other === undefined) {
  8083. return defaultValue;
  8084. }
  8085. if (value !== undefined) {
  8086. result = value;
  8087. }
  8088. if (other !== undefined) {
  8089. if (result === undefined) {
  8090. return other;
  8091. }
  8092. if (typeof value == 'string' || typeof other == 'string') {
  8093. value = baseToString(value);
  8094. other = baseToString(other);
  8095. } else {
  8096. value = baseToNumber(value);
  8097. other = baseToNumber(other);
  8098. }
  8099. result = operator(value, other);
  8100. }
  8101. return result;
  8102. };
  8103. }
  8104. /**
  8105. * Creates a function like `_.over`.
  8106. *
  8107. * @private
  8108. * @param {Function} arrayFunc The function to iterate over iteratees.
  8109. * @returns {Function} Returns the new over function.
  8110. */
  8111. function createOver(arrayFunc) {
  8112. return flatRest(function(iteratees) {
  8113. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  8114. return baseRest(function(args) {
  8115. var thisArg = this;
  8116. return arrayFunc(iteratees, function(iteratee) {
  8117. return apply(iteratee, thisArg, args);
  8118. });
  8119. });
  8120. });
  8121. }
  8122. /**
  8123. * Creates the padding for `string` based on `length`. The `chars` string
  8124. * is truncated if the number of characters exceeds `length`.
  8125. *
  8126. * @private
  8127. * @param {number} length The padding length.
  8128. * @param {string} [chars=' '] The string used as padding.
  8129. * @returns {string} Returns the padding for `string`.
  8130. */
  8131. function createPadding(length, chars) {
  8132. chars = chars === undefined ? ' ' : baseToString(chars);
  8133. var charsLength = chars.length;
  8134. if (charsLength < 2) {
  8135. return charsLength ? baseRepeat(chars, length) : chars;
  8136. }
  8137. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  8138. return hasUnicode(chars)
  8139. ? castSlice(stringToArray(result), 0, length).join('')
  8140. : result.slice(0, length);
  8141. }
  8142. /**
  8143. * Creates a function that wraps `func` to invoke it with the `this` binding
  8144. * of `thisArg` and `partials` prepended to the arguments it receives.
  8145. *
  8146. * @private
  8147. * @param {Function} func The function to wrap.
  8148. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  8149. * @param {*} thisArg The `this` binding of `func`.
  8150. * @param {Array} partials The arguments to prepend to those provided to
  8151. * the new function.
  8152. * @returns {Function} Returns the new wrapped function.
  8153. */
  8154. function createPartial(func, bitmask, thisArg, partials) {
  8155. var isBind = bitmask & WRAP_BIND_FLAG,
  8156. Ctor = createCtor(func);
  8157. function wrapper() {
  8158. var argsIndex = -1,
  8159. argsLength = arguments.length,
  8160. leftIndex = -1,
  8161. leftLength = partials.length,
  8162. args = Array(leftLength + argsLength),
  8163. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  8164. while (++leftIndex < leftLength) {
  8165. args[leftIndex] = partials[leftIndex];
  8166. }
  8167. while (argsLength--) {
  8168. args[leftIndex++] = arguments[++argsIndex];
  8169. }
  8170. return apply(fn, isBind ? thisArg : this, args);
  8171. }
  8172. return wrapper;
  8173. }
  8174. /**
  8175. * Creates a `_.range` or `_.rangeRight` function.
  8176. *
  8177. * @private
  8178. * @param {boolean} [fromRight] Specify iterating from right to left.
  8179. * @returns {Function} Returns the new range function.
  8180. */
  8181. function createRange(fromRight) {
  8182. return function(start, end, step) {
  8183. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  8184. end = step = undefined;
  8185. }
  8186. // Ensure the sign of `-0` is preserved.
  8187. start = toFinite(start);
  8188. if (end === undefined) {
  8189. end = start;
  8190. start = 0;
  8191. } else {
  8192. end = toFinite(end);
  8193. }
  8194. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  8195. return baseRange(start, end, step, fromRight);
  8196. };
  8197. }
  8198. /**
  8199. * Creates a function that performs a relational operation on two values.
  8200. *
  8201. * @private
  8202. * @param {Function} operator The function to perform the operation.
  8203. * @returns {Function} Returns the new relational operation function.
  8204. */
  8205. function createRelationalOperation(operator) {
  8206. return function(value, other) {
  8207. if (!(typeof value == 'string' && typeof other == 'string')) {
  8208. value = toNumber(value);
  8209. other = toNumber(other);
  8210. }
  8211. return operator(value, other);
  8212. };
  8213. }
  8214. /**
  8215. * Creates a function that wraps `func` to continue currying.
  8216. *
  8217. * @private
  8218. * @param {Function} func The function to wrap.
  8219. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  8220. * @param {Function} wrapFunc The function to create the `func` wrapper.
  8221. * @param {*} placeholder The placeholder value.
  8222. * @param {*} [thisArg] The `this` binding of `func`.
  8223. * @param {Array} [partials] The arguments to prepend to those provided to
  8224. * the new function.
  8225. * @param {Array} [holders] The `partials` placeholder indexes.
  8226. * @param {Array} [argPos] The argument positions of the new function.
  8227. * @param {number} [ary] The arity cap of `func`.
  8228. * @param {number} [arity] The arity of `func`.
  8229. * @returns {Function} Returns the new wrapped function.
  8230. */
  8231. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  8232. var isCurry = bitmask & WRAP_CURRY_FLAG,
  8233. newHolders = isCurry ? holders : undefined,
  8234. newHoldersRight = isCurry ? undefined : holders,
  8235. newPartials = isCurry ? partials : undefined,
  8236. newPartialsRight = isCurry ? undefined : partials;
  8237. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  8238. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  8239. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  8240. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  8241. }
  8242. var newData = [
  8243. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  8244. newHoldersRight, argPos, ary, arity
  8245. ];
  8246. var result = wrapFunc.apply(undefined, newData);
  8247. if (isLaziable(func)) {
  8248. setData(result, newData);
  8249. }
  8250. result.placeholder = placeholder;
  8251. return setWrapToString(result, func, bitmask);
  8252. }
  8253. /**
  8254. * Creates a function like `_.round`.
  8255. *
  8256. * @private
  8257. * @param {string} methodName The name of the `Math` method to use when rounding.
  8258. * @returns {Function} Returns the new round function.
  8259. */
  8260. function createRound(methodName) {
  8261. var func = Math[methodName];
  8262. return function(number, precision) {
  8263. number = toNumber(number);
  8264. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  8265. if (precision && nativeIsFinite(number)) {
  8266. // Shift with exponential notation to avoid floating-point issues.
  8267. // See [MDN](https://mdn.io/round#Examples) for more details.
  8268. var pair = (toString(number) + 'e').split('e'),
  8269. value = func(pair[0] + 'e' + (+pair[1] + precision));
  8270. pair = (toString(value) + 'e').split('e');
  8271. return +(pair[0] + 'e' + (+pair[1] - precision));
  8272. }
  8273. return func(number);
  8274. };
  8275. }
  8276. /**
  8277. * Creates a set object of `values`.
  8278. *
  8279. * @private
  8280. * @param {Array} values The values to add to the set.
  8281. * @returns {Object} Returns the new set.
  8282. */
  8283. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  8284. return new Set(values);
  8285. };
  8286. /**
  8287. * Creates a `_.toPairs` or `_.toPairsIn` function.
  8288. *
  8289. * @private
  8290. * @param {Function} keysFunc The function to get the keys of a given object.
  8291. * @returns {Function} Returns the new pairs function.
  8292. */
  8293. function createToPairs(keysFunc) {
  8294. return function(object) {
  8295. var tag = getTag(object);
  8296. if (tag == mapTag) {
  8297. return mapToArray(object);
  8298. }
  8299. if (tag == setTag) {
  8300. return setToPairs(object);
  8301. }
  8302. return baseToPairs(object, keysFunc(object));
  8303. };
  8304. }
  8305. /**
  8306. * Creates a function that either curries or invokes `func` with optional
  8307. * `this` binding and partially applied arguments.
  8308. *
  8309. * @private
  8310. * @param {Function|string} func The function or method name to wrap.
  8311. * @param {number} bitmask The bitmask flags.
  8312. * 1 - `_.bind`
  8313. * 2 - `_.bindKey`
  8314. * 4 - `_.curry` or `_.curryRight` of a bound function
  8315. * 8 - `_.curry`
  8316. * 16 - `_.curryRight`
  8317. * 32 - `_.partial`
  8318. * 64 - `_.partialRight`
  8319. * 128 - `_.rearg`
  8320. * 256 - `_.ary`
  8321. * 512 - `_.flip`
  8322. * @param {*} [thisArg] The `this` binding of `func`.
  8323. * @param {Array} [partials] The arguments to be partially applied.
  8324. * @param {Array} [holders] The `partials` placeholder indexes.
  8325. * @param {Array} [argPos] The argument positions of the new function.
  8326. * @param {number} [ary] The arity cap of `func`.
  8327. * @param {number} [arity] The arity of `func`.
  8328. * @returns {Function} Returns the new wrapped function.
  8329. */
  8330. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  8331. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  8332. if (!isBindKey && typeof func != 'function') {
  8333. throw new TypeError(FUNC_ERROR_TEXT);
  8334. }
  8335. var length = partials ? partials.length : 0;
  8336. if (!length) {
  8337. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  8338. partials = holders = undefined;
  8339. }
  8340. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  8341. arity = arity === undefined ? arity : toInteger(arity);
  8342. length -= holders ? holders.length : 0;
  8343. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  8344. var partialsRight = partials,
  8345. holdersRight = holders;
  8346. partials = holders = undefined;
  8347. }
  8348. var data = isBindKey ? undefined : getData(func);
  8349. var newData = [
  8350. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  8351. argPos, ary, arity
  8352. ];
  8353. if (data) {
  8354. mergeData(newData, data);
  8355. }
  8356. func = newData[0];
  8357. bitmask = newData[1];
  8358. thisArg = newData[2];
  8359. partials = newData[3];
  8360. holders = newData[4];
  8361. arity = newData[9] = newData[9] === undefined
  8362. ? (isBindKey ? 0 : func.length)
  8363. : nativeMax(newData[9] - length, 0);
  8364. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  8365. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  8366. }
  8367. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  8368. var result = createBind(func, bitmask, thisArg);
  8369. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  8370. result = createCurry(func, bitmask, arity);
  8371. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  8372. result = createPartial(func, bitmask, thisArg, partials);
  8373. } else {
  8374. result = createHybrid.apply(undefined, newData);
  8375. }
  8376. var setter = data ? baseSetData : setData;
  8377. return setWrapToString(setter(result, newData), func, bitmask);
  8378. }
  8379. /**
  8380. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  8381. * of source objects to the destination object for all destination properties
  8382. * that resolve to `undefined`.
  8383. *
  8384. * @private
  8385. * @param {*} objValue The destination value.
  8386. * @param {*} srcValue The source value.
  8387. * @param {string} key The key of the property to assign.
  8388. * @param {Object} object The parent object of `objValue`.
  8389. * @returns {*} Returns the value to assign.
  8390. */
  8391. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  8392. if (objValue === undefined ||
  8393. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  8394. return srcValue;
  8395. }
  8396. return objValue;
  8397. }
  8398. /**
  8399. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  8400. * objects into destination objects that are passed thru.
  8401. *
  8402. * @private
  8403. * @param {*} objValue The destination value.
  8404. * @param {*} srcValue The source value.
  8405. * @param {string} key The key of the property to merge.
  8406. * @param {Object} object The parent object of `objValue`.
  8407. * @param {Object} source The parent object of `srcValue`.
  8408. * @param {Object} [stack] Tracks traversed source values and their merged
  8409. * counterparts.
  8410. * @returns {*} Returns the value to assign.
  8411. */
  8412. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  8413. if (isObject(objValue) && isObject(srcValue)) {
  8414. // Recursively merge objects and arrays (susceptible to call stack limits).
  8415. stack.set(srcValue, objValue);
  8416. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  8417. stack['delete'](srcValue);
  8418. }
  8419. return objValue;
  8420. }
  8421. /**
  8422. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  8423. * objects.
  8424. *
  8425. * @private
  8426. * @param {*} value The value to inspect.
  8427. * @param {string} key The key of the property to inspect.
  8428. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  8429. */
  8430. function customOmitClone(value) {
  8431. return isPlainObject(value) ? undefined : value;
  8432. }
  8433. /**
  8434. * A specialized version of `baseIsEqualDeep` for arrays with support for
  8435. * partial deep comparisons.
  8436. *
  8437. * @private
  8438. * @param {Array} array The array to compare.
  8439. * @param {Array} other The other array to compare.
  8440. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  8441. * @param {Function} customizer The function to customize comparisons.
  8442. * @param {Function} equalFunc The function to determine equivalents of values.
  8443. * @param {Object} stack Tracks traversed `array` and `other` objects.
  8444. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  8445. */
  8446. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  8447. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  8448. arrLength = array.length,
  8449. othLength = other.length;
  8450. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  8451. return false;
  8452. }
  8453. // Check that cyclic values are equal.
  8454. var arrStacked = stack.get(array);
  8455. var othStacked = stack.get(other);
  8456. if (arrStacked && othStacked) {
  8457. return arrStacked == other && othStacked == array;
  8458. }
  8459. var index = -1,
  8460. result = true,
  8461. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  8462. stack.set(array, other);
  8463. stack.set(other, array);
  8464. // Ignore non-index properties.
  8465. while (++index < arrLength) {
  8466. var arrValue = array[index],
  8467. othValue = other[index];
  8468. if (customizer) {
  8469. var compared = isPartial
  8470. ? customizer(othValue, arrValue, index, other, array, stack)
  8471. : customizer(arrValue, othValue, index, array, other, stack);
  8472. }
  8473. if (compared !== undefined) {
  8474. if (compared) {
  8475. continue;
  8476. }
  8477. result = false;
  8478. break;
  8479. }
  8480. // Recursively compare arrays (susceptible to call stack limits).
  8481. if (seen) {
  8482. if (!arraySome(other, function(othValue, othIndex) {
  8483. if (!cacheHas(seen, othIndex) &&
  8484. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  8485. return seen.push(othIndex);
  8486. }
  8487. })) {
  8488. result = false;
  8489. break;
  8490. }
  8491. } else if (!(
  8492. arrValue === othValue ||
  8493. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  8494. )) {
  8495. result = false;
  8496. break;
  8497. }
  8498. }
  8499. stack['delete'](array);
  8500. stack['delete'](other);
  8501. return result;
  8502. }
  8503. /**
  8504. * A specialized version of `baseIsEqualDeep` for comparing objects of
  8505. * the same `toStringTag`.
  8506. *
  8507. * **Note:** This function only supports comparing values with tags of
  8508. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  8509. *
  8510. * @private
  8511. * @param {Object} object The object to compare.
  8512. * @param {Object} other The other object to compare.
  8513. * @param {string} tag The `toStringTag` of the objects to compare.
  8514. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  8515. * @param {Function} customizer The function to customize comparisons.
  8516. * @param {Function} equalFunc The function to determine equivalents of values.
  8517. * @param {Object} stack Tracks traversed `object` and `other` objects.
  8518. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  8519. */
  8520. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  8521. switch (tag) {
  8522. case dataViewTag:
  8523. if ((object.byteLength != other.byteLength) ||
  8524. (object.byteOffset != other.byteOffset)) {
  8525. return false;
  8526. }
  8527. object = object.buffer;
  8528. other = other.buffer;
  8529. case arrayBufferTag:
  8530. if ((object.byteLength != other.byteLength) ||
  8531. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  8532. return false;
  8533. }
  8534. return true;
  8535. case boolTag:
  8536. case dateTag:
  8537. case numberTag:
  8538. // Coerce booleans to `1` or `0` and dates to milliseconds.
  8539. // Invalid dates are coerced to `NaN`.
  8540. return eq(+object, +other);
  8541. case errorTag:
  8542. return object.name == other.name && object.message == other.message;
  8543. case regexpTag:
  8544. case stringTag:
  8545. // Coerce regexes to strings and treat strings, primitives and objects,
  8546. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  8547. // for more details.
  8548. return object == (other + '');
  8549. case mapTag:
  8550. var convert = mapToArray;
  8551. case setTag:
  8552. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  8553. convert || (convert = setToArray);
  8554. if (object.size != other.size && !isPartial) {
  8555. return false;
  8556. }
  8557. // Assume cyclic values are equal.
  8558. var stacked = stack.get(object);
  8559. if (stacked) {
  8560. return stacked == other;
  8561. }
  8562. bitmask |= COMPARE_UNORDERED_FLAG;
  8563. // Recursively compare objects (susceptible to call stack limits).
  8564. stack.set(object, other);
  8565. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  8566. stack['delete'](object);
  8567. return result;
  8568. case symbolTag:
  8569. if (symbolValueOf) {
  8570. return symbolValueOf.call(object) == symbolValueOf.call(other);
  8571. }
  8572. }
  8573. return false;
  8574. }
  8575. /**
  8576. * A specialized version of `baseIsEqualDeep` for objects with support for
  8577. * partial deep comparisons.
  8578. *
  8579. * @private
  8580. * @param {Object} object The object to compare.
  8581. * @param {Object} other The other object to compare.
  8582. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  8583. * @param {Function} customizer The function to customize comparisons.
  8584. * @param {Function} equalFunc The function to determine equivalents of values.
  8585. * @param {Object} stack Tracks traversed `object` and `other` objects.
  8586. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  8587. */
  8588. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  8589. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  8590. objProps = getAllKeys(object),
  8591. objLength = objProps.length,
  8592. othProps = getAllKeys(other),
  8593. othLength = othProps.length;
  8594. if (objLength != othLength && !isPartial) {
  8595. return false;
  8596. }
  8597. var index = objLength;
  8598. while (index--) {
  8599. var key = objProps[index];
  8600. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  8601. return false;
  8602. }
  8603. }
  8604. // Check that cyclic values are equal.
  8605. var objStacked = stack.get(object);
  8606. var othStacked = stack.get(other);
  8607. if (objStacked && othStacked) {
  8608. return objStacked == other && othStacked == object;
  8609. }
  8610. var result = true;
  8611. stack.set(object, other);
  8612. stack.set(other, object);
  8613. var skipCtor = isPartial;
  8614. while (++index < objLength) {
  8615. key = objProps[index];
  8616. var objValue = object[key],
  8617. othValue = other[key];
  8618. if (customizer) {
  8619. var compared = isPartial
  8620. ? customizer(othValue, objValue, key, other, object, stack)
  8621. : customizer(objValue, othValue, key, object, other, stack);
  8622. }
  8623. // Recursively compare objects (susceptible to call stack limits).
  8624. if (!(compared === undefined
  8625. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  8626. : compared
  8627. )) {
  8628. result = false;
  8629. break;
  8630. }
  8631. skipCtor || (skipCtor = key == 'constructor');
  8632. }
  8633. if (result && !skipCtor) {
  8634. var objCtor = object.constructor,
  8635. othCtor = other.constructor;
  8636. // Non `Object` object instances with different constructors are not equal.
  8637. if (objCtor != othCtor &&
  8638. ('constructor' in object && 'constructor' in other) &&
  8639. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  8640. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  8641. result = false;
  8642. }
  8643. }
  8644. stack['delete'](object);
  8645. stack['delete'](other);
  8646. return result;
  8647. }
  8648. /**
  8649. * A specialized version of `baseRest` which flattens the rest array.
  8650. *
  8651. * @private
  8652. * @param {Function} func The function to apply a rest parameter to.
  8653. * @returns {Function} Returns the new function.
  8654. */
  8655. function flatRest(func) {
  8656. return setToString(overRest(func, undefined, flatten), func + '');
  8657. }
  8658. /**
  8659. * Creates an array of own enumerable property names and symbols of `object`.
  8660. *
  8661. * @private
  8662. * @param {Object} object The object to query.
  8663. * @returns {Array} Returns the array of property names and symbols.
  8664. */
  8665. function getAllKeys(object) {
  8666. return baseGetAllKeys(object, keys, getSymbols);
  8667. }
  8668. /**
  8669. * Creates an array of own and inherited enumerable property names and
  8670. * symbols of `object`.
  8671. *
  8672. * @private
  8673. * @param {Object} object The object to query.
  8674. * @returns {Array} Returns the array of property names and symbols.
  8675. */
  8676. function getAllKeysIn(object) {
  8677. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  8678. }
  8679. /**
  8680. * Gets metadata for `func`.
  8681. *
  8682. * @private
  8683. * @param {Function} func The function to query.
  8684. * @returns {*} Returns the metadata for `func`.
  8685. */
  8686. var getData = !metaMap ? noop : function(func) {
  8687. return metaMap.get(func);
  8688. };
  8689. /**
  8690. * Gets the name of `func`.
  8691. *
  8692. * @private
  8693. * @param {Function} func The function to query.
  8694. * @returns {string} Returns the function name.
  8695. */
  8696. function getFuncName(func) {
  8697. var result = (func.name + ''),
  8698. array = realNames[result],
  8699. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  8700. while (length--) {
  8701. var data = array[length],
  8702. otherFunc = data.func;
  8703. if (otherFunc == null || otherFunc == func) {
  8704. return data.name;
  8705. }
  8706. }
  8707. return result;
  8708. }
  8709. /**
  8710. * Gets the argument placeholder value for `func`.
  8711. *
  8712. * @private
  8713. * @param {Function} func The function to inspect.
  8714. * @returns {*} Returns the placeholder value.
  8715. */
  8716. function getHolder(func) {
  8717. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  8718. return object.placeholder;
  8719. }
  8720. /**
  8721. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  8722. * this function returns the custom method, otherwise it returns `baseIteratee`.
  8723. * If arguments are provided, the chosen function is invoked with them and
  8724. * its result is returned.
  8725. *
  8726. * @private
  8727. * @param {*} [value] The value to convert to an iteratee.
  8728. * @param {number} [arity] The arity of the created iteratee.
  8729. * @returns {Function} Returns the chosen function or its result.
  8730. */
  8731. function getIteratee() {
  8732. var result = lodash.iteratee || iteratee;
  8733. result = result === iteratee ? baseIteratee : result;
  8734. return arguments.length ? result(arguments[0], arguments[1]) : result;
  8735. }
  8736. /**
  8737. * Gets the data for `map`.
  8738. *
  8739. * @private
  8740. * @param {Object} map The map to query.
  8741. * @param {string} key The reference key.
  8742. * @returns {*} Returns the map data.
  8743. */
  8744. function getMapData(map, key) {
  8745. var data = map.__data__;
  8746. return isKeyable(key)
  8747. ? data[typeof key == 'string' ? 'string' : 'hash']
  8748. : data.map;
  8749. }
  8750. /**
  8751. * Gets the property names, values, and compare flags of `object`.
  8752. *
  8753. * @private
  8754. * @param {Object} object The object to query.
  8755. * @returns {Array} Returns the match data of `object`.
  8756. */
  8757. function getMatchData(object) {
  8758. var result = keys(object),
  8759. length = result.length;
  8760. while (length--) {
  8761. var key = result[length],
  8762. value = object[key];
  8763. result[length] = [key, value, isStrictComparable(value)];
  8764. }
  8765. return result;
  8766. }
  8767. /**
  8768. * Gets the native function at `key` of `object`.
  8769. *
  8770. * @private
  8771. * @param {Object} object The object to query.
  8772. * @param {string} key The key of the method to get.
  8773. * @returns {*} Returns the function if it's native, else `undefined`.
  8774. */
  8775. function getNative(object, key) {
  8776. var value = getValue(object, key);
  8777. return baseIsNative(value) ? value : undefined;
  8778. }
  8779. /**
  8780. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  8781. *
  8782. * @private
  8783. * @param {*} value The value to query.
  8784. * @returns {string} Returns the raw `toStringTag`.
  8785. */
  8786. function getRawTag(value) {
  8787. var isOwn = hasOwnProperty.call(value, symToStringTag),
  8788. tag = value[symToStringTag];
  8789. try {
  8790. value[symToStringTag] = undefined;
  8791. var unmasked = true;
  8792. } catch (e) {}
  8793. var result = nativeObjectToString.call(value);
  8794. if (unmasked) {
  8795. if (isOwn) {
  8796. value[symToStringTag] = tag;
  8797. } else {
  8798. delete value[symToStringTag];
  8799. }
  8800. }
  8801. return result;
  8802. }
  8803. /**
  8804. * Creates an array of the own enumerable symbols of `object`.
  8805. *
  8806. * @private
  8807. * @param {Object} object The object to query.
  8808. * @returns {Array} Returns the array of symbols.
  8809. */
  8810. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  8811. if (object == null) {
  8812. return [];
  8813. }
  8814. object = Object(object);
  8815. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  8816. return propertyIsEnumerable.call(object, symbol);
  8817. });
  8818. };
  8819. /**
  8820. * Creates an array of the own and inherited enumerable symbols of `object`.
  8821. *
  8822. * @private
  8823. * @param {Object} object The object to query.
  8824. * @returns {Array} Returns the array of symbols.
  8825. */
  8826. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  8827. var result = [];
  8828. while (object) {
  8829. arrayPush(result, getSymbols(object));
  8830. object = getPrototype(object);
  8831. }
  8832. return result;
  8833. };
  8834. /**
  8835. * Gets the `toStringTag` of `value`.
  8836. *
  8837. * @private
  8838. * @param {*} value The value to query.
  8839. * @returns {string} Returns the `toStringTag`.
  8840. */
  8841. var getTag = baseGetTag;
  8842. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  8843. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  8844. (Map && getTag(new Map) != mapTag) ||
  8845. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  8846. (Set && getTag(new Set) != setTag) ||
  8847. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  8848. getTag = function(value) {
  8849. var result = baseGetTag(value),
  8850. Ctor = result == objectTag ? value.constructor : undefined,
  8851. ctorString = Ctor ? toSource(Ctor) : '';
  8852. if (ctorString) {
  8853. switch (ctorString) {
  8854. case dataViewCtorString: return dataViewTag;
  8855. case mapCtorString: return mapTag;
  8856. case promiseCtorString: return promiseTag;
  8857. case setCtorString: return setTag;
  8858. case weakMapCtorString: return weakMapTag;
  8859. }
  8860. }
  8861. return result;
  8862. };
  8863. }
  8864. /**
  8865. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  8866. *
  8867. * @private
  8868. * @param {number} start The start of the view.
  8869. * @param {number} end The end of the view.
  8870. * @param {Array} transforms The transformations to apply to the view.
  8871. * @returns {Object} Returns an object containing the `start` and `end`
  8872. * positions of the view.
  8873. */
  8874. function getView(start, end, transforms) {
  8875. var index = -1,
  8876. length = transforms.length;
  8877. while (++index < length) {
  8878. var data = transforms[index],
  8879. size = data.size;
  8880. switch (data.type) {
  8881. case 'drop': start += size; break;
  8882. case 'dropRight': end -= size; break;
  8883. case 'take': end = nativeMin(end, start + size); break;
  8884. case 'takeRight': start = nativeMax(start, end - size); break;
  8885. }
  8886. }
  8887. return { 'start': start, 'end': end };
  8888. }
  8889. /**
  8890. * Extracts wrapper details from the `source` body comment.
  8891. *
  8892. * @private
  8893. * @param {string} source The source to inspect.
  8894. * @returns {Array} Returns the wrapper details.
  8895. */
  8896. function getWrapDetails(source) {
  8897. var match = source.match(reWrapDetails);
  8898. return match ? match[1].split(reSplitDetails) : [];
  8899. }
  8900. /**
  8901. * Checks if `path` exists on `object`.
  8902. *
  8903. * @private
  8904. * @param {Object} object The object to query.
  8905. * @param {Array|string} path The path to check.
  8906. * @param {Function} hasFunc The function to check properties.
  8907. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  8908. */
  8909. function hasPath(object, path, hasFunc) {
  8910. path = castPath(path, object);
  8911. var index = -1,
  8912. length = path.length,
  8913. result = false;
  8914. while (++index < length) {
  8915. var key = toKey(path[index]);
  8916. if (!(result = object != null && hasFunc(object, key))) {
  8917. break;
  8918. }
  8919. object = object[key];
  8920. }
  8921. if (result || ++index != length) {
  8922. return result;
  8923. }
  8924. length = object == null ? 0 : object.length;
  8925. return !!length && isLength(length) && isIndex(key, length) &&
  8926. (isArray(object) || isArguments(object));
  8927. }
  8928. /**
  8929. * Initializes an array clone.
  8930. *
  8931. * @private
  8932. * @param {Array} array The array to clone.
  8933. * @returns {Array} Returns the initialized clone.
  8934. */
  8935. function initCloneArray(array) {
  8936. var length = array.length,
  8937. result = new array.constructor(length);
  8938. // Add properties assigned by `RegExp#exec`.
  8939. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  8940. result.index = array.index;
  8941. result.input = array.input;
  8942. }
  8943. return result;
  8944. }
  8945. /**
  8946. * Initializes an object clone.
  8947. *
  8948. * @private
  8949. * @param {Object} object The object to clone.
  8950. * @returns {Object} Returns the initialized clone.
  8951. */
  8952. function initCloneObject(object) {
  8953. return (typeof object.constructor == 'function' && !isPrototype(object))
  8954. ? baseCreate(getPrototype(object))
  8955. : {};
  8956. }
  8957. /**
  8958. * Initializes an object clone based on its `toStringTag`.
  8959. *
  8960. * **Note:** This function only supports cloning values with tags of
  8961. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  8962. *
  8963. * @private
  8964. * @param {Object} object The object to clone.
  8965. * @param {string} tag The `toStringTag` of the object to clone.
  8966. * @param {boolean} [isDeep] Specify a deep clone.
  8967. * @returns {Object} Returns the initialized clone.
  8968. */
  8969. function initCloneByTag(object, tag, isDeep) {
  8970. var Ctor = object.constructor;
  8971. switch (tag) {
  8972. case arrayBufferTag:
  8973. return cloneArrayBuffer(object);
  8974. case boolTag:
  8975. case dateTag:
  8976. return new Ctor(+object);
  8977. case dataViewTag:
  8978. return cloneDataView(object, isDeep);
  8979. case float32Tag: case float64Tag:
  8980. case int8Tag: case int16Tag: case int32Tag:
  8981. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  8982. return cloneTypedArray(object, isDeep);
  8983. case mapTag:
  8984. return new Ctor;
  8985. case numberTag:
  8986. case stringTag:
  8987. return new Ctor(object);
  8988. case regexpTag:
  8989. return cloneRegExp(object);
  8990. case setTag:
  8991. return new Ctor;
  8992. case symbolTag:
  8993. return cloneSymbol(object);
  8994. }
  8995. }
  8996. /**
  8997. * Inserts wrapper `details` in a comment at the top of the `source` body.
  8998. *
  8999. * @private
  9000. * @param {string} source The source to modify.
  9001. * @returns {Array} details The details to insert.
  9002. * @returns {string} Returns the modified source.
  9003. */
  9004. function insertWrapDetails(source, details) {
  9005. var length = details.length;
  9006. if (!length) {
  9007. return source;
  9008. }
  9009. var lastIndex = length - 1;
  9010. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  9011. details = details.join(length > 2 ? ', ' : ' ');
  9012. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  9013. }
  9014. /**
  9015. * Checks if `value` is a flattenable `arguments` object or array.
  9016. *
  9017. * @private
  9018. * @param {*} value The value to check.
  9019. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  9020. */
  9021. function isFlattenable(value) {
  9022. return isArray(value) || isArguments(value) ||
  9023. !!(spreadableSymbol && value && value[spreadableSymbol]);
  9024. }
  9025. /**
  9026. * Checks if `value` is a valid array-like index.
  9027. *
  9028. * @private
  9029. * @param {*} value The value to check.
  9030. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  9031. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  9032. */
  9033. function isIndex(value, length) {
  9034. var type = typeof value;
  9035. length = length == null ? MAX_SAFE_INTEGER : length;
  9036. return !!length &&
  9037. (type == 'number' ||
  9038. (type != 'symbol' && reIsUint.test(value))) &&
  9039. (value > -1 && value % 1 == 0 && value < length);
  9040. }
  9041. /**
  9042. * Checks if the given arguments are from an iteratee call.
  9043. *
  9044. * @private
  9045. * @param {*} value The potential iteratee value argument.
  9046. * @param {*} index The potential iteratee index or key argument.
  9047. * @param {*} object The potential iteratee object argument.
  9048. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  9049. * else `false`.
  9050. */
  9051. function isIterateeCall(value, index, object) {
  9052. if (!isObject(object)) {
  9053. return false;
  9054. }
  9055. var type = typeof index;
  9056. if (type == 'number'
  9057. ? (isArrayLike(object) && isIndex(index, object.length))
  9058. : (type == 'string' && index in object)
  9059. ) {
  9060. return eq(object[index], value);
  9061. }
  9062. return false;
  9063. }
  9064. /**
  9065. * Checks if `value` is a property name and not a property path.
  9066. *
  9067. * @private
  9068. * @param {*} value The value to check.
  9069. * @param {Object} [object] The object to query keys on.
  9070. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  9071. */
  9072. function isKey(value, object) {
  9073. if (isArray(value)) {
  9074. return false;
  9075. }
  9076. var type = typeof value;
  9077. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  9078. value == null || isSymbol(value)) {
  9079. return true;
  9080. }
  9081. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  9082. (object != null && value in Object(object));
  9083. }
  9084. /**
  9085. * Checks if `value` is suitable for use as unique object key.
  9086. *
  9087. * @private
  9088. * @param {*} value The value to check.
  9089. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  9090. */
  9091. function isKeyable(value) {
  9092. var type = typeof value;
  9093. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  9094. ? (value !== '__proto__')
  9095. : (value === null);
  9096. }
  9097. /**
  9098. * Checks if `func` has a lazy counterpart.
  9099. *
  9100. * @private
  9101. * @param {Function} func The function to check.
  9102. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  9103. * else `false`.
  9104. */
  9105. function isLaziable(func) {
  9106. var funcName = getFuncName(func),
  9107. other = lodash[funcName];
  9108. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  9109. return false;
  9110. }
  9111. if (func === other) {
  9112. return true;
  9113. }
  9114. var data = getData(other);
  9115. return !!data && func === data[0];
  9116. }
  9117. /**
  9118. * Checks if `func` has its source masked.
  9119. *
  9120. * @private
  9121. * @param {Function} func The function to check.
  9122. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  9123. */
  9124. function isMasked(func) {
  9125. return !!maskSrcKey && (maskSrcKey in func);
  9126. }
  9127. /**
  9128. * Checks if `func` is capable of being masked.
  9129. *
  9130. * @private
  9131. * @param {*} value The value to check.
  9132. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  9133. */
  9134. var isMaskable = coreJsData ? isFunction : stubFalse;
  9135. /**
  9136. * Checks if `value` is likely a prototype object.
  9137. *
  9138. * @private
  9139. * @param {*} value The value to check.
  9140. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  9141. */
  9142. function isPrototype(value) {
  9143. var Ctor = value && value.constructor,
  9144. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  9145. return value === proto;
  9146. }
  9147. /**
  9148. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  9149. *
  9150. * @private
  9151. * @param {*} value The value to check.
  9152. * @returns {boolean} Returns `true` if `value` if suitable for strict
  9153. * equality comparisons, else `false`.
  9154. */
  9155. function isStrictComparable(value) {
  9156. return value === value && !isObject(value);
  9157. }
  9158. /**
  9159. * A specialized version of `matchesProperty` for source values suitable
  9160. * for strict equality comparisons, i.e. `===`.
  9161. *
  9162. * @private
  9163. * @param {string} key The key of the property to get.
  9164. * @param {*} srcValue The value to match.
  9165. * @returns {Function} Returns the new spec function.
  9166. */
  9167. function matchesStrictComparable(key, srcValue) {
  9168. return function(object) {
  9169. if (object == null) {
  9170. return false;
  9171. }
  9172. return object[key] === srcValue &&
  9173. (srcValue !== undefined || (key in Object(object)));
  9174. };
  9175. }
  9176. /**
  9177. * A specialized version of `_.memoize` which clears the memoized function's
  9178. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  9179. *
  9180. * @private
  9181. * @param {Function} func The function to have its output memoized.
  9182. * @returns {Function} Returns the new memoized function.
  9183. */
  9184. function memoizeCapped(func) {
  9185. var result = memoize(func, function(key) {
  9186. if (cache.size === MAX_MEMOIZE_SIZE) {
  9187. cache.clear();
  9188. }
  9189. return key;
  9190. });
  9191. var cache = result.cache;
  9192. return result;
  9193. }
  9194. /**
  9195. * Merges the function metadata of `source` into `data`.
  9196. *
  9197. * Merging metadata reduces the number of wrappers used to invoke a function.
  9198. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  9199. * may be applied regardless of execution order. Methods like `_.ary` and
  9200. * `_.rearg` modify function arguments, making the order in which they are
  9201. * executed important, preventing the merging of metadata. However, we make
  9202. * an exception for a safe combined case where curried functions have `_.ary`
  9203. * and or `_.rearg` applied.
  9204. *
  9205. * @private
  9206. * @param {Array} data The destination metadata.
  9207. * @param {Array} source The source metadata.
  9208. * @returns {Array} Returns `data`.
  9209. */
  9210. function mergeData(data, source) {
  9211. var bitmask = data[1],
  9212. srcBitmask = source[1],
  9213. newBitmask = bitmask | srcBitmask,
  9214. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  9215. var isCombo =
  9216. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  9217. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  9218. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  9219. // Exit early if metadata can't be merged.
  9220. if (!(isCommon || isCombo)) {
  9221. return data;
  9222. }
  9223. // Use source `thisArg` if available.
  9224. if (srcBitmask & WRAP_BIND_FLAG) {
  9225. data[2] = source[2];
  9226. // Set when currying a bound function.
  9227. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  9228. }
  9229. // Compose partial arguments.
  9230. var value = source[3];
  9231. if (value) {
  9232. var partials = data[3];
  9233. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  9234. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  9235. }
  9236. // Compose partial right arguments.
  9237. value = source[5];
  9238. if (value) {
  9239. partials = data[5];
  9240. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  9241. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  9242. }
  9243. // Use source `argPos` if available.
  9244. value = source[7];
  9245. if (value) {
  9246. data[7] = value;
  9247. }
  9248. // Use source `ary` if it's smaller.
  9249. if (srcBitmask & WRAP_ARY_FLAG) {
  9250. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  9251. }
  9252. // Use source `arity` if one is not provided.
  9253. if (data[9] == null) {
  9254. data[9] = source[9];
  9255. }
  9256. // Use source `func` and merge bitmasks.
  9257. data[0] = source[0];
  9258. data[1] = newBitmask;
  9259. return data;
  9260. }
  9261. /**
  9262. * This function is like
  9263. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  9264. * except that it includes inherited enumerable properties.
  9265. *
  9266. * @private
  9267. * @param {Object} object The object to query.
  9268. * @returns {Array} Returns the array of property names.
  9269. */
  9270. function nativeKeysIn(object) {
  9271. var result = [];
  9272. if (object != null) {
  9273. for (var key in Object(object)) {
  9274. result.push(key);
  9275. }
  9276. }
  9277. return result;
  9278. }
  9279. /**
  9280. * Converts `value` to a string using `Object.prototype.toString`.
  9281. *
  9282. * @private
  9283. * @param {*} value The value to convert.
  9284. * @returns {string} Returns the converted string.
  9285. */
  9286. function objectToString(value) {
  9287. return nativeObjectToString.call(value);
  9288. }
  9289. /**
  9290. * A specialized version of `baseRest` which transforms the rest array.
  9291. *
  9292. * @private
  9293. * @param {Function} func The function to apply a rest parameter to.
  9294. * @param {number} [start=func.length-1] The start position of the rest parameter.
  9295. * @param {Function} transform The rest array transform.
  9296. * @returns {Function} Returns the new function.
  9297. */
  9298. function overRest(func, start, transform) {
  9299. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  9300. return function() {
  9301. var args = arguments,
  9302. index = -1,
  9303. length = nativeMax(args.length - start, 0),
  9304. array = Array(length);
  9305. while (++index < length) {
  9306. array[index] = args[start + index];
  9307. }
  9308. index = -1;
  9309. var otherArgs = Array(start + 1);
  9310. while (++index < start) {
  9311. otherArgs[index] = args[index];
  9312. }
  9313. otherArgs[start] = transform(array);
  9314. return apply(func, this, otherArgs);
  9315. };
  9316. }
  9317. /**
  9318. * Gets the parent value at `path` of `object`.
  9319. *
  9320. * @private
  9321. * @param {Object} object The object to query.
  9322. * @param {Array} path The path to get the parent value of.
  9323. * @returns {*} Returns the parent value.
  9324. */
  9325. function parent(object, path) {
  9326. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  9327. }
  9328. /**
  9329. * Reorder `array` according to the specified indexes where the element at
  9330. * the first index is assigned as the first element, the element at
  9331. * the second index is assigned as the second element, and so on.
  9332. *
  9333. * @private
  9334. * @param {Array} array The array to reorder.
  9335. * @param {Array} indexes The arranged array indexes.
  9336. * @returns {Array} Returns `array`.
  9337. */
  9338. function reorder(array, indexes) {
  9339. var arrLength = array.length,
  9340. length = nativeMin(indexes.length, arrLength),
  9341. oldArray = copyArray(array);
  9342. while (length--) {
  9343. var index = indexes[length];
  9344. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  9345. }
  9346. return array;
  9347. }
  9348. /**
  9349. * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
  9350. *
  9351. * @private
  9352. * @param {Object} object The object to query.
  9353. * @param {string} key The key of the property to get.
  9354. * @returns {*} Returns the property value.
  9355. */
  9356. function safeGet(object, key) {
  9357. if (key === 'constructor' && typeof object[key] === 'function') {
  9358. return;
  9359. }
  9360. if (key == '__proto__') {
  9361. return;
  9362. }
  9363. return object[key];
  9364. }
  9365. /**
  9366. * Sets metadata for `func`.
  9367. *
  9368. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  9369. * period of time, it will trip its breaker and transition to an identity
  9370. * function to avoid garbage collection pauses in V8. See
  9371. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  9372. * for more details.
  9373. *
  9374. * @private
  9375. * @param {Function} func The function to associate metadata with.
  9376. * @param {*} data The metadata.
  9377. * @returns {Function} Returns `func`.
  9378. */
  9379. var setData = shortOut(baseSetData);
  9380. /**
  9381. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  9382. *
  9383. * @private
  9384. * @param {Function} func The function to delay.
  9385. * @param {number} wait The number of milliseconds to delay invocation.
  9386. * @returns {number|Object} Returns the timer id or timeout object.
  9387. */
  9388. var setTimeout = ctxSetTimeout || function(func, wait) {
  9389. return root.setTimeout(func, wait);
  9390. };
  9391. /**
  9392. * Sets the `toString` method of `func` to return `string`.
  9393. *
  9394. * @private
  9395. * @param {Function} func The function to modify.
  9396. * @param {Function} string The `toString` result.
  9397. * @returns {Function} Returns `func`.
  9398. */
  9399. var setToString = shortOut(baseSetToString);
  9400. /**
  9401. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  9402. * with wrapper details in a comment at the top of the source body.
  9403. *
  9404. * @private
  9405. * @param {Function} wrapper The function to modify.
  9406. * @param {Function} reference The reference function.
  9407. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  9408. * @returns {Function} Returns `wrapper`.
  9409. */
  9410. function setWrapToString(wrapper, reference, bitmask) {
  9411. var source = (reference + '');
  9412. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  9413. }
  9414. /**
  9415. * Creates a function that'll short out and invoke `identity` instead
  9416. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  9417. * milliseconds.
  9418. *
  9419. * @private
  9420. * @param {Function} func The function to restrict.
  9421. * @returns {Function} Returns the new shortable function.
  9422. */
  9423. function shortOut(func) {
  9424. var count = 0,
  9425. lastCalled = 0;
  9426. return function() {
  9427. var stamp = nativeNow(),
  9428. remaining = HOT_SPAN - (stamp - lastCalled);
  9429. lastCalled = stamp;
  9430. if (remaining > 0) {
  9431. if (++count >= HOT_COUNT) {
  9432. return arguments[0];
  9433. }
  9434. } else {
  9435. count = 0;
  9436. }
  9437. return func.apply(undefined, arguments);
  9438. };
  9439. }
  9440. /**
  9441. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  9442. *
  9443. * @private
  9444. * @param {Array} array The array to shuffle.
  9445. * @param {number} [size=array.length] The size of `array`.
  9446. * @returns {Array} Returns `array`.
  9447. */
  9448. function shuffleSelf(array, size) {
  9449. var index = -1,
  9450. length = array.length,
  9451. lastIndex = length - 1;
  9452. size = size === undefined ? length : size;
  9453. while (++index < size) {
  9454. var rand = baseRandom(index, lastIndex),
  9455. value = array[rand];
  9456. array[rand] = array[index];
  9457. array[index] = value;
  9458. }
  9459. array.length = size;
  9460. return array;
  9461. }
  9462. /**
  9463. * Converts `string` to a property path array.
  9464. *
  9465. * @private
  9466. * @param {string} string The string to convert.
  9467. * @returns {Array} Returns the property path array.
  9468. */
  9469. var stringToPath = memoizeCapped(function(string) {
  9470. var result = [];
  9471. if (string.charCodeAt(0) === 46 /* . */) {
  9472. result.push('');
  9473. }
  9474. string.replace(rePropName, function(match, number, quote, subString) {
  9475. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  9476. });
  9477. return result;
  9478. });
  9479. /**
  9480. * Converts `value` to a string key if it's not a string or symbol.
  9481. *
  9482. * @private
  9483. * @param {*} value The value to inspect.
  9484. * @returns {string|symbol} Returns the key.
  9485. */
  9486. function toKey(value) {
  9487. if (typeof value == 'string' || isSymbol(value)) {
  9488. return value;
  9489. }
  9490. var result = (value + '');
  9491. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  9492. }
  9493. /**
  9494. * Converts `func` to its source code.
  9495. *
  9496. * @private
  9497. * @param {Function} func The function to convert.
  9498. * @returns {string} Returns the source code.
  9499. */
  9500. function toSource(func) {
  9501. if (func != null) {
  9502. try {
  9503. return funcToString.call(func);
  9504. } catch (e) {}
  9505. try {
  9506. return (func + '');
  9507. } catch (e) {}
  9508. }
  9509. return '';
  9510. }
  9511. /**
  9512. * Updates wrapper `details` based on `bitmask` flags.
  9513. *
  9514. * @private
  9515. * @returns {Array} details The details to modify.
  9516. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  9517. * @returns {Array} Returns `details`.
  9518. */
  9519. function updateWrapDetails(details, bitmask) {
  9520. arrayEach(wrapFlags, function(pair) {
  9521. var value = '_.' + pair[0];
  9522. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  9523. details.push(value);
  9524. }
  9525. });
  9526. return details.sort();
  9527. }
  9528. /**
  9529. * Creates a clone of `wrapper`.
  9530. *
  9531. * @private
  9532. * @param {Object} wrapper The wrapper to clone.
  9533. * @returns {Object} Returns the cloned wrapper.
  9534. */
  9535. function wrapperClone(wrapper) {
  9536. if (wrapper instanceof LazyWrapper) {
  9537. return wrapper.clone();
  9538. }
  9539. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  9540. result.__actions__ = copyArray(wrapper.__actions__);
  9541. result.__index__ = wrapper.__index__;
  9542. result.__values__ = wrapper.__values__;
  9543. return result;
  9544. }
  9545. /*------------------------------------------------------------------------*/
  9546. /**
  9547. * Creates an array of elements split into groups the length of `size`.
  9548. * If `array` can't be split evenly, the final chunk will be the remaining
  9549. * elements.
  9550. *
  9551. * @static
  9552. * @memberOf _
  9553. * @since 3.0.0
  9554. * @category Array
  9555. * @param {Array} array The array to process.
  9556. * @param {number} [size=1] The length of each chunk
  9557. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9558. * @returns {Array} Returns the new array of chunks.
  9559. * @example
  9560. *
  9561. * _.chunk(['a', 'b', 'c', 'd'], 2);
  9562. * // => [['a', 'b'], ['c', 'd']]
  9563. *
  9564. * _.chunk(['a', 'b', 'c', 'd'], 3);
  9565. * // => [['a', 'b', 'c'], ['d']]
  9566. */
  9567. function chunk(array, size, guard) {
  9568. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  9569. size = 1;
  9570. } else {
  9571. size = nativeMax(toInteger(size), 0);
  9572. }
  9573. var length = array == null ? 0 : array.length;
  9574. if (!length || size < 1) {
  9575. return [];
  9576. }
  9577. var index = 0,
  9578. resIndex = 0,
  9579. result = Array(nativeCeil(length / size));
  9580. while (index < length) {
  9581. result[resIndex++] = baseSlice(array, index, (index += size));
  9582. }
  9583. return result;
  9584. }
  9585. /**
  9586. * Creates an array with all falsey values removed. The values `false`, `null`,
  9587. * `0`, `""`, `undefined`, and `NaN` are falsey.
  9588. *
  9589. * @static
  9590. * @memberOf _
  9591. * @since 0.1.0
  9592. * @category Array
  9593. * @param {Array} array The array to compact.
  9594. * @returns {Array} Returns the new array of filtered values.
  9595. * @example
  9596. *
  9597. * _.compact([0, 1, false, 2, '', 3]);
  9598. * // => [1, 2, 3]
  9599. */
  9600. function compact(array) {
  9601. var index = -1,
  9602. length = array == null ? 0 : array.length,
  9603. resIndex = 0,
  9604. result = [];
  9605. while (++index < length) {
  9606. var value = array[index];
  9607. if (value) {
  9608. result[resIndex++] = value;
  9609. }
  9610. }
  9611. return result;
  9612. }
  9613. /**
  9614. * Creates a new array concatenating `array` with any additional arrays
  9615. * and/or values.
  9616. *
  9617. * @static
  9618. * @memberOf _
  9619. * @since 4.0.0
  9620. * @category Array
  9621. * @param {Array} array The array to concatenate.
  9622. * @param {...*} [values] The values to concatenate.
  9623. * @returns {Array} Returns the new concatenated array.
  9624. * @example
  9625. *
  9626. * var array = [1];
  9627. * var other = _.concat(array, 2, [3], [[4]]);
  9628. *
  9629. * console.log(other);
  9630. * // => [1, 2, 3, [4]]
  9631. *
  9632. * console.log(array);
  9633. * // => [1]
  9634. */
  9635. function concat() {
  9636. var length = arguments.length;
  9637. if (!length) {
  9638. return [];
  9639. }
  9640. var args = Array(length - 1),
  9641. array = arguments[0],
  9642. index = length;
  9643. while (index--) {
  9644. args[index - 1] = arguments[index];
  9645. }
  9646. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  9647. }
  9648. /**
  9649. * Creates an array of `array` values not included in the other given arrays
  9650. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  9651. * for equality comparisons. The order and references of result values are
  9652. * determined by the first array.
  9653. *
  9654. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  9655. *
  9656. * @static
  9657. * @memberOf _
  9658. * @since 0.1.0
  9659. * @category Array
  9660. * @param {Array} array The array to inspect.
  9661. * @param {...Array} [values] The values to exclude.
  9662. * @returns {Array} Returns the new array of filtered values.
  9663. * @see _.without, _.xor
  9664. * @example
  9665. *
  9666. * _.difference([2, 1], [2, 3]);
  9667. * // => [1]
  9668. */
  9669. var difference = baseRest(function(array, values) {
  9670. return isArrayLikeObject(array)
  9671. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  9672. : [];
  9673. });
  9674. /**
  9675. * This method is like `_.difference` except that it accepts `iteratee` which
  9676. * is invoked for each element of `array` and `values` to generate the criterion
  9677. * by which they're compared. The order and references of result values are
  9678. * determined by the first array. The iteratee is invoked with one argument:
  9679. * (value).
  9680. *
  9681. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  9682. *
  9683. * @static
  9684. * @memberOf _
  9685. * @since 4.0.0
  9686. * @category Array
  9687. * @param {Array} array The array to inspect.
  9688. * @param {...Array} [values] The values to exclude.
  9689. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  9690. * @returns {Array} Returns the new array of filtered values.
  9691. * @example
  9692. *
  9693. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  9694. * // => [1.2]
  9695. *
  9696. * // The `_.property` iteratee shorthand.
  9697. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  9698. * // => [{ 'x': 2 }]
  9699. */
  9700. var differenceBy = baseRest(function(array, values) {
  9701. var iteratee = last(values);
  9702. if (isArrayLikeObject(iteratee)) {
  9703. iteratee = undefined;
  9704. }
  9705. return isArrayLikeObject(array)
  9706. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  9707. : [];
  9708. });
  9709. /**
  9710. * This method is like `_.difference` except that it accepts `comparator`
  9711. * which is invoked to compare elements of `array` to `values`. The order and
  9712. * references of result values are determined by the first array. The comparator
  9713. * is invoked with two arguments: (arrVal, othVal).
  9714. *
  9715. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  9716. *
  9717. * @static
  9718. * @memberOf _
  9719. * @since 4.0.0
  9720. * @category Array
  9721. * @param {Array} array The array to inspect.
  9722. * @param {...Array} [values] The values to exclude.
  9723. * @param {Function} [comparator] The comparator invoked per element.
  9724. * @returns {Array} Returns the new array of filtered values.
  9725. * @example
  9726. *
  9727. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  9728. *
  9729. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  9730. * // => [{ 'x': 2, 'y': 1 }]
  9731. */
  9732. var differenceWith = baseRest(function(array, values) {
  9733. var comparator = last(values);
  9734. if (isArrayLikeObject(comparator)) {
  9735. comparator = undefined;
  9736. }
  9737. return isArrayLikeObject(array)
  9738. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  9739. : [];
  9740. });
  9741. /**
  9742. * Creates a slice of `array` with `n` elements dropped from the beginning.
  9743. *
  9744. * @static
  9745. * @memberOf _
  9746. * @since 0.5.0
  9747. * @category Array
  9748. * @param {Array} array The array to query.
  9749. * @param {number} [n=1] The number of elements to drop.
  9750. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9751. * @returns {Array} Returns the slice of `array`.
  9752. * @example
  9753. *
  9754. * _.drop([1, 2, 3]);
  9755. * // => [2, 3]
  9756. *
  9757. * _.drop([1, 2, 3], 2);
  9758. * // => [3]
  9759. *
  9760. * _.drop([1, 2, 3], 5);
  9761. * // => []
  9762. *
  9763. * _.drop([1, 2, 3], 0);
  9764. * // => [1, 2, 3]
  9765. */
  9766. function drop(array, n, guard) {
  9767. var length = array == null ? 0 : array.length;
  9768. if (!length) {
  9769. return [];
  9770. }
  9771. n = (guard || n === undefined) ? 1 : toInteger(n);
  9772. return baseSlice(array, n < 0 ? 0 : n, length);
  9773. }
  9774. /**
  9775. * Creates a slice of `array` with `n` elements dropped from the end.
  9776. *
  9777. * @static
  9778. * @memberOf _
  9779. * @since 3.0.0
  9780. * @category Array
  9781. * @param {Array} array The array to query.
  9782. * @param {number} [n=1] The number of elements to drop.
  9783. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9784. * @returns {Array} Returns the slice of `array`.
  9785. * @example
  9786. *
  9787. * _.dropRight([1, 2, 3]);
  9788. * // => [1, 2]
  9789. *
  9790. * _.dropRight([1, 2, 3], 2);
  9791. * // => [1]
  9792. *
  9793. * _.dropRight([1, 2, 3], 5);
  9794. * // => []
  9795. *
  9796. * _.dropRight([1, 2, 3], 0);
  9797. * // => [1, 2, 3]
  9798. */
  9799. function dropRight(array, n, guard) {
  9800. var length = array == null ? 0 : array.length;
  9801. if (!length) {
  9802. return [];
  9803. }
  9804. n = (guard || n === undefined) ? 1 : toInteger(n);
  9805. n = length - n;
  9806. return baseSlice(array, 0, n < 0 ? 0 : n);
  9807. }
  9808. /**
  9809. * Creates a slice of `array` excluding elements dropped from the end.
  9810. * Elements are dropped until `predicate` returns falsey. The predicate is
  9811. * invoked with three arguments: (value, index, array).
  9812. *
  9813. * @static
  9814. * @memberOf _
  9815. * @since 3.0.0
  9816. * @category Array
  9817. * @param {Array} array The array to query.
  9818. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9819. * @returns {Array} Returns the slice of `array`.
  9820. * @example
  9821. *
  9822. * var users = [
  9823. * { 'user': 'barney', 'active': true },
  9824. * { 'user': 'fred', 'active': false },
  9825. * { 'user': 'pebbles', 'active': false }
  9826. * ];
  9827. *
  9828. * _.dropRightWhile(users, function(o) { return !o.active; });
  9829. * // => objects for ['barney']
  9830. *
  9831. * // The `_.matches` iteratee shorthand.
  9832. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  9833. * // => objects for ['barney', 'fred']
  9834. *
  9835. * // The `_.matchesProperty` iteratee shorthand.
  9836. * _.dropRightWhile(users, ['active', false]);
  9837. * // => objects for ['barney']
  9838. *
  9839. * // The `_.property` iteratee shorthand.
  9840. * _.dropRightWhile(users, 'active');
  9841. * // => objects for ['barney', 'fred', 'pebbles']
  9842. */
  9843. function dropRightWhile(array, predicate) {
  9844. return (array && array.length)
  9845. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  9846. : [];
  9847. }
  9848. /**
  9849. * Creates a slice of `array` excluding elements dropped from the beginning.
  9850. * Elements are dropped until `predicate` returns falsey. The predicate is
  9851. * invoked with three arguments: (value, index, array).
  9852. *
  9853. * @static
  9854. * @memberOf _
  9855. * @since 3.0.0
  9856. * @category Array
  9857. * @param {Array} array The array to query.
  9858. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9859. * @returns {Array} Returns the slice of `array`.
  9860. * @example
  9861. *
  9862. * var users = [
  9863. * { 'user': 'barney', 'active': false },
  9864. * { 'user': 'fred', 'active': false },
  9865. * { 'user': 'pebbles', 'active': true }
  9866. * ];
  9867. *
  9868. * _.dropWhile(users, function(o) { return !o.active; });
  9869. * // => objects for ['pebbles']
  9870. *
  9871. * // The `_.matches` iteratee shorthand.
  9872. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  9873. * // => objects for ['fred', 'pebbles']
  9874. *
  9875. * // The `_.matchesProperty` iteratee shorthand.
  9876. * _.dropWhile(users, ['active', false]);
  9877. * // => objects for ['pebbles']
  9878. *
  9879. * // The `_.property` iteratee shorthand.
  9880. * _.dropWhile(users, 'active');
  9881. * // => objects for ['barney', 'fred', 'pebbles']
  9882. */
  9883. function dropWhile(array, predicate) {
  9884. return (array && array.length)
  9885. ? baseWhile(array, getIteratee(predicate, 3), true)
  9886. : [];
  9887. }
  9888. /**
  9889. * Fills elements of `array` with `value` from `start` up to, but not
  9890. * including, `end`.
  9891. *
  9892. * **Note:** This method mutates `array`.
  9893. *
  9894. * @static
  9895. * @memberOf _
  9896. * @since 3.2.0
  9897. * @category Array
  9898. * @param {Array} array The array to fill.
  9899. * @param {*} value The value to fill `array` with.
  9900. * @param {number} [start=0] The start position.
  9901. * @param {number} [end=array.length] The end position.
  9902. * @returns {Array} Returns `array`.
  9903. * @example
  9904. *
  9905. * var array = [1, 2, 3];
  9906. *
  9907. * _.fill(array, 'a');
  9908. * console.log(array);
  9909. * // => ['a', 'a', 'a']
  9910. *
  9911. * _.fill(Array(3), 2);
  9912. * // => [2, 2, 2]
  9913. *
  9914. * _.fill([4, 6, 8, 10], '*', 1, 3);
  9915. * // => [4, '*', '*', 10]
  9916. */
  9917. function fill(array, value, start, end) {
  9918. var length = array == null ? 0 : array.length;
  9919. if (!length) {
  9920. return [];
  9921. }
  9922. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  9923. start = 0;
  9924. end = length;
  9925. }
  9926. return baseFill(array, value, start, end);
  9927. }
  9928. /**
  9929. * This method is like `_.find` except that it returns the index of the first
  9930. * element `predicate` returns truthy for instead of the element itself.
  9931. *
  9932. * @static
  9933. * @memberOf _
  9934. * @since 1.1.0
  9935. * @category Array
  9936. * @param {Array} array The array to inspect.
  9937. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9938. * @param {number} [fromIndex=0] The index to search from.
  9939. * @returns {number} Returns the index of the found element, else `-1`.
  9940. * @example
  9941. *
  9942. * var users = [
  9943. * { 'user': 'barney', 'active': false },
  9944. * { 'user': 'fred', 'active': false },
  9945. * { 'user': 'pebbles', 'active': true }
  9946. * ];
  9947. *
  9948. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  9949. * // => 0
  9950. *
  9951. * // The `_.matches` iteratee shorthand.
  9952. * _.findIndex(users, { 'user': 'fred', 'active': false });
  9953. * // => 1
  9954. *
  9955. * // The `_.matchesProperty` iteratee shorthand.
  9956. * _.findIndex(users, ['active', false]);
  9957. * // => 0
  9958. *
  9959. * // The `_.property` iteratee shorthand.
  9960. * _.findIndex(users, 'active');
  9961. * // => 2
  9962. */
  9963. function findIndex(array, predicate, fromIndex) {
  9964. var length = array == null ? 0 : array.length;
  9965. if (!length) {
  9966. return -1;
  9967. }
  9968. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  9969. if (index < 0) {
  9970. index = nativeMax(length + index, 0);
  9971. }
  9972. return baseFindIndex(array, getIteratee(predicate, 3), index);
  9973. }
  9974. /**
  9975. * This method is like `_.findIndex` except that it iterates over elements
  9976. * of `collection` from right to left.
  9977. *
  9978. * @static
  9979. * @memberOf _
  9980. * @since 2.0.0
  9981. * @category Array
  9982. * @param {Array} array The array to inspect.
  9983. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9984. * @param {number} [fromIndex=array.length-1] The index to search from.
  9985. * @returns {number} Returns the index of the found element, else `-1`.
  9986. * @example
  9987. *
  9988. * var users = [
  9989. * { 'user': 'barney', 'active': true },
  9990. * { 'user': 'fred', 'active': false },
  9991. * { 'user': 'pebbles', 'active': false }
  9992. * ];
  9993. *
  9994. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  9995. * // => 2
  9996. *
  9997. * // The `_.matches` iteratee shorthand.
  9998. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  9999. * // => 0
  10000. *
  10001. * // The `_.matchesProperty` iteratee shorthand.
  10002. * _.findLastIndex(users, ['active', false]);
  10003. * // => 2
  10004. *
  10005. * // The `_.property` iteratee shorthand.
  10006. * _.findLastIndex(users, 'active');
  10007. * // => 0
  10008. */
  10009. function findLastIndex(array, predicate, fromIndex) {
  10010. var length = array == null ? 0 : array.length;
  10011. if (!length) {
  10012. return -1;
  10013. }
  10014. var index = length - 1;
  10015. if (fromIndex !== undefined) {
  10016. index = toInteger(fromIndex);
  10017. index = fromIndex < 0
  10018. ? nativeMax(length + index, 0)
  10019. : nativeMin(index, length - 1);
  10020. }
  10021. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  10022. }
  10023. /**
  10024. * Flattens `array` a single level deep.
  10025. *
  10026. * @static
  10027. * @memberOf _
  10028. * @since 0.1.0
  10029. * @category Array
  10030. * @param {Array} array The array to flatten.
  10031. * @returns {Array} Returns the new flattened array.
  10032. * @example
  10033. *
  10034. * _.flatten([1, [2, [3, [4]], 5]]);
  10035. * // => [1, 2, [3, [4]], 5]
  10036. */
  10037. function flatten(array) {
  10038. var length = array == null ? 0 : array.length;
  10039. return length ? baseFlatten(array, 1) : [];
  10040. }
  10041. /**
  10042. * Recursively flattens `array`.
  10043. *
  10044. * @static
  10045. * @memberOf _
  10046. * @since 3.0.0
  10047. * @category Array
  10048. * @param {Array} array The array to flatten.
  10049. * @returns {Array} Returns the new flattened array.
  10050. * @example
  10051. *
  10052. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  10053. * // => [1, 2, 3, 4, 5]
  10054. */
  10055. function flattenDeep(array) {
  10056. var length = array == null ? 0 : array.length;
  10057. return length ? baseFlatten(array, INFINITY) : [];
  10058. }
  10059. /**
  10060. * Recursively flatten `array` up to `depth` times.
  10061. *
  10062. * @static
  10063. * @memberOf _
  10064. * @since 4.4.0
  10065. * @category Array
  10066. * @param {Array} array The array to flatten.
  10067. * @param {number} [depth=1] The maximum recursion depth.
  10068. * @returns {Array} Returns the new flattened array.
  10069. * @example
  10070. *
  10071. * var array = [1, [2, [3, [4]], 5]];
  10072. *
  10073. * _.flattenDepth(array, 1);
  10074. * // => [1, 2, [3, [4]], 5]
  10075. *
  10076. * _.flattenDepth(array, 2);
  10077. * // => [1, 2, 3, [4], 5]
  10078. */
  10079. function flattenDepth(array, depth) {
  10080. var length = array == null ? 0 : array.length;
  10081. if (!length) {
  10082. return [];
  10083. }
  10084. depth = depth === undefined ? 1 : toInteger(depth);
  10085. return baseFlatten(array, depth);
  10086. }
  10087. /**
  10088. * The inverse of `_.toPairs`; this method returns an object composed
  10089. * from key-value `pairs`.
  10090. *
  10091. * @static
  10092. * @memberOf _
  10093. * @since 4.0.0
  10094. * @category Array
  10095. * @param {Array} pairs The key-value pairs.
  10096. * @returns {Object} Returns the new object.
  10097. * @example
  10098. *
  10099. * _.fromPairs([['a', 1], ['b', 2]]);
  10100. * // => { 'a': 1, 'b': 2 }
  10101. */
  10102. function fromPairs(pairs) {
  10103. var index = -1,
  10104. length = pairs == null ? 0 : pairs.length,
  10105. result = {};
  10106. while (++index < length) {
  10107. var pair = pairs[index];
  10108. result[pair[0]] = pair[1];
  10109. }
  10110. return result;
  10111. }
  10112. /**
  10113. * Gets the first element of `array`.
  10114. *
  10115. * @static
  10116. * @memberOf _
  10117. * @since 0.1.0
  10118. * @alias first
  10119. * @category Array
  10120. * @param {Array} array The array to query.
  10121. * @returns {*} Returns the first element of `array`.
  10122. * @example
  10123. *
  10124. * _.head([1, 2, 3]);
  10125. * // => 1
  10126. *
  10127. * _.head([]);
  10128. * // => undefined
  10129. */
  10130. function head(array) {
  10131. return (array && array.length) ? array[0] : undefined;
  10132. }
  10133. /**
  10134. * Gets the index at which the first occurrence of `value` is found in `array`
  10135. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10136. * for equality comparisons. If `fromIndex` is negative, it's used as the
  10137. * offset from the end of `array`.
  10138. *
  10139. * @static
  10140. * @memberOf _
  10141. * @since 0.1.0
  10142. * @category Array
  10143. * @param {Array} array The array to inspect.
  10144. * @param {*} value The value to search for.
  10145. * @param {number} [fromIndex=0] The index to search from.
  10146. * @returns {number} Returns the index of the matched value, else `-1`.
  10147. * @example
  10148. *
  10149. * _.indexOf([1, 2, 1, 2], 2);
  10150. * // => 1
  10151. *
  10152. * // Search from the `fromIndex`.
  10153. * _.indexOf([1, 2, 1, 2], 2, 2);
  10154. * // => 3
  10155. */
  10156. function indexOf(array, value, fromIndex) {
  10157. var length = array == null ? 0 : array.length;
  10158. if (!length) {
  10159. return -1;
  10160. }
  10161. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  10162. if (index < 0) {
  10163. index = nativeMax(length + index, 0);
  10164. }
  10165. return baseIndexOf(array, value, index);
  10166. }
  10167. /**
  10168. * Gets all but the last element of `array`.
  10169. *
  10170. * @static
  10171. * @memberOf _
  10172. * @since 0.1.0
  10173. * @category Array
  10174. * @param {Array} array The array to query.
  10175. * @returns {Array} Returns the slice of `array`.
  10176. * @example
  10177. *
  10178. * _.initial([1, 2, 3]);
  10179. * // => [1, 2]
  10180. */
  10181. function initial(array) {
  10182. var length = array == null ? 0 : array.length;
  10183. return length ? baseSlice(array, 0, -1) : [];
  10184. }
  10185. /**
  10186. * Creates an array of unique values that are included in all given arrays
  10187. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10188. * for equality comparisons. The order and references of result values are
  10189. * determined by the first array.
  10190. *
  10191. * @static
  10192. * @memberOf _
  10193. * @since 0.1.0
  10194. * @category Array
  10195. * @param {...Array} [arrays] The arrays to inspect.
  10196. * @returns {Array} Returns the new array of intersecting values.
  10197. * @example
  10198. *
  10199. * _.intersection([2, 1], [2, 3]);
  10200. * // => [2]
  10201. */
  10202. var intersection = baseRest(function(arrays) {
  10203. var mapped = arrayMap(arrays, castArrayLikeObject);
  10204. return (mapped.length && mapped[0] === arrays[0])
  10205. ? baseIntersection(mapped)
  10206. : [];
  10207. });
  10208. /**
  10209. * This method is like `_.intersection` except that it accepts `iteratee`
  10210. * which is invoked for each element of each `arrays` to generate the criterion
  10211. * by which they're compared. The order and references of result values are
  10212. * determined by the first array. The iteratee is invoked with one argument:
  10213. * (value).
  10214. *
  10215. * @static
  10216. * @memberOf _
  10217. * @since 4.0.0
  10218. * @category Array
  10219. * @param {...Array} [arrays] The arrays to inspect.
  10220. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  10221. * @returns {Array} Returns the new array of intersecting values.
  10222. * @example
  10223. *
  10224. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  10225. * // => [2.1]
  10226. *
  10227. * // The `_.property` iteratee shorthand.
  10228. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  10229. * // => [{ 'x': 1 }]
  10230. */
  10231. var intersectionBy = baseRest(function(arrays) {
  10232. var iteratee = last(arrays),
  10233. mapped = arrayMap(arrays, castArrayLikeObject);
  10234. if (iteratee === last(mapped)) {
  10235. iteratee = undefined;
  10236. } else {
  10237. mapped.pop();
  10238. }
  10239. return (mapped.length && mapped[0] === arrays[0])
  10240. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  10241. : [];
  10242. });
  10243. /**
  10244. * This method is like `_.intersection` except that it accepts `comparator`
  10245. * which is invoked to compare elements of `arrays`. The order and references
  10246. * of result values are determined by the first array. The comparator is
  10247. * invoked with two arguments: (arrVal, othVal).
  10248. *
  10249. * @static
  10250. * @memberOf _
  10251. * @since 4.0.0
  10252. * @category Array
  10253. * @param {...Array} [arrays] The arrays to inspect.
  10254. * @param {Function} [comparator] The comparator invoked per element.
  10255. * @returns {Array} Returns the new array of intersecting values.
  10256. * @example
  10257. *
  10258. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  10259. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  10260. *
  10261. * _.intersectionWith(objects, others, _.isEqual);
  10262. * // => [{ 'x': 1, 'y': 2 }]
  10263. */
  10264. var intersectionWith = baseRest(function(arrays) {
  10265. var comparator = last(arrays),
  10266. mapped = arrayMap(arrays, castArrayLikeObject);
  10267. comparator = typeof comparator == 'function' ? comparator : undefined;
  10268. if (comparator) {
  10269. mapped.pop();
  10270. }
  10271. return (mapped.length && mapped[0] === arrays[0])
  10272. ? baseIntersection(mapped, undefined, comparator)
  10273. : [];
  10274. });
  10275. /**
  10276. * Converts all elements in `array` into a string separated by `separator`.
  10277. *
  10278. * @static
  10279. * @memberOf _
  10280. * @since 4.0.0
  10281. * @category Array
  10282. * @param {Array} array The array to convert.
  10283. * @param {string} [separator=','] The element separator.
  10284. * @returns {string} Returns the joined string.
  10285. * @example
  10286. *
  10287. * _.join(['a', 'b', 'c'], '~');
  10288. * // => 'a~b~c'
  10289. */
  10290. function join(array, separator) {
  10291. return array == null ? '' : nativeJoin.call(array, separator);
  10292. }
  10293. /**
  10294. * Gets the last element of `array`.
  10295. *
  10296. * @static
  10297. * @memberOf _
  10298. * @since 0.1.0
  10299. * @category Array
  10300. * @param {Array} array The array to query.
  10301. * @returns {*} Returns the last element of `array`.
  10302. * @example
  10303. *
  10304. * _.last([1, 2, 3]);
  10305. * // => 3
  10306. */
  10307. function last(array) {
  10308. var length = array == null ? 0 : array.length;
  10309. return length ? array[length - 1] : undefined;
  10310. }
  10311. /**
  10312. * This method is like `_.indexOf` except that it iterates over elements of
  10313. * `array` from right to left.
  10314. *
  10315. * @static
  10316. * @memberOf _
  10317. * @since 0.1.0
  10318. * @category Array
  10319. * @param {Array} array The array to inspect.
  10320. * @param {*} value The value to search for.
  10321. * @param {number} [fromIndex=array.length-1] The index to search from.
  10322. * @returns {number} Returns the index of the matched value, else `-1`.
  10323. * @example
  10324. *
  10325. * _.lastIndexOf([1, 2, 1, 2], 2);
  10326. * // => 3
  10327. *
  10328. * // Search from the `fromIndex`.
  10329. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  10330. * // => 1
  10331. */
  10332. function lastIndexOf(array, value, fromIndex) {
  10333. var length = array == null ? 0 : array.length;
  10334. if (!length) {
  10335. return -1;
  10336. }
  10337. var index = length;
  10338. if (fromIndex !== undefined) {
  10339. index = toInteger(fromIndex);
  10340. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  10341. }
  10342. return value === value
  10343. ? strictLastIndexOf(array, value, index)
  10344. : baseFindIndex(array, baseIsNaN, index, true);
  10345. }
  10346. /**
  10347. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  10348. * element from the end is returned.
  10349. *
  10350. * @static
  10351. * @memberOf _
  10352. * @since 4.11.0
  10353. * @category Array
  10354. * @param {Array} array The array to query.
  10355. * @param {number} [n=0] The index of the element to return.
  10356. * @returns {*} Returns the nth element of `array`.
  10357. * @example
  10358. *
  10359. * var array = ['a', 'b', 'c', 'd'];
  10360. *
  10361. * _.nth(array, 1);
  10362. * // => 'b'
  10363. *
  10364. * _.nth(array, -2);
  10365. * // => 'c';
  10366. */
  10367. function nth(array, n) {
  10368. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  10369. }
  10370. /**
  10371. * Removes all given values from `array` using
  10372. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10373. * for equality comparisons.
  10374. *
  10375. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  10376. * to remove elements from an array by predicate.
  10377. *
  10378. * @static
  10379. * @memberOf _
  10380. * @since 2.0.0
  10381. * @category Array
  10382. * @param {Array} array The array to modify.
  10383. * @param {...*} [values] The values to remove.
  10384. * @returns {Array} Returns `array`.
  10385. * @example
  10386. *
  10387. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  10388. *
  10389. * _.pull(array, 'a', 'c');
  10390. * console.log(array);
  10391. * // => ['b', 'b']
  10392. */
  10393. var pull = baseRest(pullAll);
  10394. /**
  10395. * This method is like `_.pull` except that it accepts an array of values to remove.
  10396. *
  10397. * **Note:** Unlike `_.difference`, this method mutates `array`.
  10398. *
  10399. * @static
  10400. * @memberOf _
  10401. * @since 4.0.0
  10402. * @category Array
  10403. * @param {Array} array The array to modify.
  10404. * @param {Array} values The values to remove.
  10405. * @returns {Array} Returns `array`.
  10406. * @example
  10407. *
  10408. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  10409. *
  10410. * _.pullAll(array, ['a', 'c']);
  10411. * console.log(array);
  10412. * // => ['b', 'b']
  10413. */
  10414. function pullAll(array, values) {
  10415. return (array && array.length && values && values.length)
  10416. ? basePullAll(array, values)
  10417. : array;
  10418. }
  10419. /**
  10420. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  10421. * invoked for each element of `array` and `values` to generate the criterion
  10422. * by which they're compared. The iteratee is invoked with one argument: (value).
  10423. *
  10424. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  10425. *
  10426. * @static
  10427. * @memberOf _
  10428. * @since 4.0.0
  10429. * @category Array
  10430. * @param {Array} array The array to modify.
  10431. * @param {Array} values The values to remove.
  10432. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  10433. * @returns {Array} Returns `array`.
  10434. * @example
  10435. *
  10436. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  10437. *
  10438. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  10439. * console.log(array);
  10440. * // => [{ 'x': 2 }]
  10441. */
  10442. function pullAllBy(array, values, iteratee) {
  10443. return (array && array.length && values && values.length)
  10444. ? basePullAll(array, values, getIteratee(iteratee, 2))
  10445. : array;
  10446. }
  10447. /**
  10448. * This method is like `_.pullAll` except that it accepts `comparator` which
  10449. * is invoked to compare elements of `array` to `values`. The comparator is
  10450. * invoked with two arguments: (arrVal, othVal).
  10451. *
  10452. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  10453. *
  10454. * @static
  10455. * @memberOf _
  10456. * @since 4.6.0
  10457. * @category Array
  10458. * @param {Array} array The array to modify.
  10459. * @param {Array} values The values to remove.
  10460. * @param {Function} [comparator] The comparator invoked per element.
  10461. * @returns {Array} Returns `array`.
  10462. * @example
  10463. *
  10464. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  10465. *
  10466. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  10467. * console.log(array);
  10468. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  10469. */
  10470. function pullAllWith(array, values, comparator) {
  10471. return (array && array.length && values && values.length)
  10472. ? basePullAll(array, values, undefined, comparator)
  10473. : array;
  10474. }
  10475. /**
  10476. * Removes elements from `array` corresponding to `indexes` and returns an
  10477. * array of removed elements.
  10478. *
  10479. * **Note:** Unlike `_.at`, this method mutates `array`.
  10480. *
  10481. * @static
  10482. * @memberOf _
  10483. * @since 3.0.0
  10484. * @category Array
  10485. * @param {Array} array The array to modify.
  10486. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  10487. * @returns {Array} Returns the new array of removed elements.
  10488. * @example
  10489. *
  10490. * var array = ['a', 'b', 'c', 'd'];
  10491. * var pulled = _.pullAt(array, [1, 3]);
  10492. *
  10493. * console.log(array);
  10494. * // => ['a', 'c']
  10495. *
  10496. * console.log(pulled);
  10497. * // => ['b', 'd']
  10498. */
  10499. var pullAt = flatRest(function(array, indexes) {
  10500. var length = array == null ? 0 : array.length,
  10501. result = baseAt(array, indexes);
  10502. basePullAt(array, arrayMap(indexes, function(index) {
  10503. return isIndex(index, length) ? +index : index;
  10504. }).sort(compareAscending));
  10505. return result;
  10506. });
  10507. /**
  10508. * Removes all elements from `array` that `predicate` returns truthy for
  10509. * and returns an array of the removed elements. The predicate is invoked
  10510. * with three arguments: (value, index, array).
  10511. *
  10512. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  10513. * to pull elements from an array by value.
  10514. *
  10515. * @static
  10516. * @memberOf _
  10517. * @since 2.0.0
  10518. * @category Array
  10519. * @param {Array} array The array to modify.
  10520. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10521. * @returns {Array} Returns the new array of removed elements.
  10522. * @example
  10523. *
  10524. * var array = [1, 2, 3, 4];
  10525. * var evens = _.remove(array, function(n) {
  10526. * return n % 2 == 0;
  10527. * });
  10528. *
  10529. * console.log(array);
  10530. * // => [1, 3]
  10531. *
  10532. * console.log(evens);
  10533. * // => [2, 4]
  10534. */
  10535. function remove(array, predicate) {
  10536. var result = [];
  10537. if (!(array && array.length)) {
  10538. return result;
  10539. }
  10540. var index = -1,
  10541. indexes = [],
  10542. length = array.length;
  10543. predicate = getIteratee(predicate, 3);
  10544. while (++index < length) {
  10545. var value = array[index];
  10546. if (predicate(value, index, array)) {
  10547. result.push(value);
  10548. indexes.push(index);
  10549. }
  10550. }
  10551. basePullAt(array, indexes);
  10552. return result;
  10553. }
  10554. /**
  10555. * Reverses `array` so that the first element becomes the last, the second
  10556. * element becomes the second to last, and so on.
  10557. *
  10558. * **Note:** This method mutates `array` and is based on
  10559. * [`Array#reverse`](https://mdn.io/Array/reverse).
  10560. *
  10561. * @static
  10562. * @memberOf _
  10563. * @since 4.0.0
  10564. * @category Array
  10565. * @param {Array} array The array to modify.
  10566. * @returns {Array} Returns `array`.
  10567. * @example
  10568. *
  10569. * var array = [1, 2, 3];
  10570. *
  10571. * _.reverse(array);
  10572. * // => [3, 2, 1]
  10573. *
  10574. * console.log(array);
  10575. * // => [3, 2, 1]
  10576. */
  10577. function reverse(array) {
  10578. return array == null ? array : nativeReverse.call(array);
  10579. }
  10580. /**
  10581. * Creates a slice of `array` from `start` up to, but not including, `end`.
  10582. *
  10583. * **Note:** This method is used instead of
  10584. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  10585. * returned.
  10586. *
  10587. * @static
  10588. * @memberOf _
  10589. * @since 3.0.0
  10590. * @category Array
  10591. * @param {Array} array The array to slice.
  10592. * @param {number} [start=0] The start position.
  10593. * @param {number} [end=array.length] The end position.
  10594. * @returns {Array} Returns the slice of `array`.
  10595. */
  10596. function slice(array, start, end) {
  10597. var length = array == null ? 0 : array.length;
  10598. if (!length) {
  10599. return [];
  10600. }
  10601. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  10602. start = 0;
  10603. end = length;
  10604. }
  10605. else {
  10606. start = start == null ? 0 : toInteger(start);
  10607. end = end === undefined ? length : toInteger(end);
  10608. }
  10609. return baseSlice(array, start, end);
  10610. }
  10611. /**
  10612. * Uses a binary search to determine the lowest index at which `value`
  10613. * should be inserted into `array` in order to maintain its sort order.
  10614. *
  10615. * @static
  10616. * @memberOf _
  10617. * @since 0.1.0
  10618. * @category Array
  10619. * @param {Array} array The sorted array to inspect.
  10620. * @param {*} value The value to evaluate.
  10621. * @returns {number} Returns the index at which `value` should be inserted
  10622. * into `array`.
  10623. * @example
  10624. *
  10625. * _.sortedIndex([30, 50], 40);
  10626. * // => 1
  10627. */
  10628. function sortedIndex(array, value) {
  10629. return baseSortedIndex(array, value);
  10630. }
  10631. /**
  10632. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  10633. * which is invoked for `value` and each element of `array` to compute their
  10634. * sort ranking. The iteratee is invoked with one argument: (value).
  10635. *
  10636. * @static
  10637. * @memberOf _
  10638. * @since 4.0.0
  10639. * @category Array
  10640. * @param {Array} array The sorted array to inspect.
  10641. * @param {*} value The value to evaluate.
  10642. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  10643. * @returns {number} Returns the index at which `value` should be inserted
  10644. * into `array`.
  10645. * @example
  10646. *
  10647. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  10648. *
  10649. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  10650. * // => 0
  10651. *
  10652. * // The `_.property` iteratee shorthand.
  10653. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  10654. * // => 0
  10655. */
  10656. function sortedIndexBy(array, value, iteratee) {
  10657. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  10658. }
  10659. /**
  10660. * This method is like `_.indexOf` except that it performs a binary
  10661. * search on a sorted `array`.
  10662. *
  10663. * @static
  10664. * @memberOf _
  10665. * @since 4.0.0
  10666. * @category Array
  10667. * @param {Array} array The array to inspect.
  10668. * @param {*} value The value to search for.
  10669. * @returns {number} Returns the index of the matched value, else `-1`.
  10670. * @example
  10671. *
  10672. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  10673. * // => 1
  10674. */
  10675. function sortedIndexOf(array, value) {
  10676. var length = array == null ? 0 : array.length;
  10677. if (length) {
  10678. var index = baseSortedIndex(array, value);
  10679. if (index < length && eq(array[index], value)) {
  10680. return index;
  10681. }
  10682. }
  10683. return -1;
  10684. }
  10685. /**
  10686. * This method is like `_.sortedIndex` except that it returns the highest
  10687. * index at which `value` should be inserted into `array` in order to
  10688. * maintain its sort order.
  10689. *
  10690. * @static
  10691. * @memberOf _
  10692. * @since 3.0.0
  10693. * @category Array
  10694. * @param {Array} array The sorted array to inspect.
  10695. * @param {*} value The value to evaluate.
  10696. * @returns {number} Returns the index at which `value` should be inserted
  10697. * into `array`.
  10698. * @example
  10699. *
  10700. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  10701. * // => 4
  10702. */
  10703. function sortedLastIndex(array, value) {
  10704. return baseSortedIndex(array, value, true);
  10705. }
  10706. /**
  10707. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  10708. * which is invoked for `value` and each element of `array` to compute their
  10709. * sort ranking. The iteratee is invoked with one argument: (value).
  10710. *
  10711. * @static
  10712. * @memberOf _
  10713. * @since 4.0.0
  10714. * @category Array
  10715. * @param {Array} array The sorted array to inspect.
  10716. * @param {*} value The value to evaluate.
  10717. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  10718. * @returns {number} Returns the index at which `value` should be inserted
  10719. * into `array`.
  10720. * @example
  10721. *
  10722. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  10723. *
  10724. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  10725. * // => 1
  10726. *
  10727. * // The `_.property` iteratee shorthand.
  10728. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  10729. * // => 1
  10730. */
  10731. function sortedLastIndexBy(array, value, iteratee) {
  10732. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  10733. }
  10734. /**
  10735. * This method is like `_.lastIndexOf` except that it performs a binary
  10736. * search on a sorted `array`.
  10737. *
  10738. * @static
  10739. * @memberOf _
  10740. * @since 4.0.0
  10741. * @category Array
  10742. * @param {Array} array The array to inspect.
  10743. * @param {*} value The value to search for.
  10744. * @returns {number} Returns the index of the matched value, else `-1`.
  10745. * @example
  10746. *
  10747. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  10748. * // => 3
  10749. */
  10750. function sortedLastIndexOf(array, value) {
  10751. var length = array == null ? 0 : array.length;
  10752. if (length) {
  10753. var index = baseSortedIndex(array, value, true) - 1;
  10754. if (eq(array[index], value)) {
  10755. return index;
  10756. }
  10757. }
  10758. return -1;
  10759. }
  10760. /**
  10761. * This method is like `_.uniq` except that it's designed and optimized
  10762. * for sorted arrays.
  10763. *
  10764. * @static
  10765. * @memberOf _
  10766. * @since 4.0.0
  10767. * @category Array
  10768. * @param {Array} array The array to inspect.
  10769. * @returns {Array} Returns the new duplicate free array.
  10770. * @example
  10771. *
  10772. * _.sortedUniq([1, 1, 2]);
  10773. * // => [1, 2]
  10774. */
  10775. function sortedUniq(array) {
  10776. return (array && array.length)
  10777. ? baseSortedUniq(array)
  10778. : [];
  10779. }
  10780. /**
  10781. * This method is like `_.uniqBy` except that it's designed and optimized
  10782. * for sorted arrays.
  10783. *
  10784. * @static
  10785. * @memberOf _
  10786. * @since 4.0.0
  10787. * @category Array
  10788. * @param {Array} array The array to inspect.
  10789. * @param {Function} [iteratee] The iteratee invoked per element.
  10790. * @returns {Array} Returns the new duplicate free array.
  10791. * @example
  10792. *
  10793. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  10794. * // => [1.1, 2.3]
  10795. */
  10796. function sortedUniqBy(array, iteratee) {
  10797. return (array && array.length)
  10798. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  10799. : [];
  10800. }
  10801. /**
  10802. * Gets all but the first element of `array`.
  10803. *
  10804. * @static
  10805. * @memberOf _
  10806. * @since 4.0.0
  10807. * @category Array
  10808. * @param {Array} array The array to query.
  10809. * @returns {Array} Returns the slice of `array`.
  10810. * @example
  10811. *
  10812. * _.tail([1, 2, 3]);
  10813. * // => [2, 3]
  10814. */
  10815. function tail(array) {
  10816. var length = array == null ? 0 : array.length;
  10817. return length ? baseSlice(array, 1, length) : [];
  10818. }
  10819. /**
  10820. * Creates a slice of `array` with `n` elements taken from the beginning.
  10821. *
  10822. * @static
  10823. * @memberOf _
  10824. * @since 0.1.0
  10825. * @category Array
  10826. * @param {Array} array The array to query.
  10827. * @param {number} [n=1] The number of elements to take.
  10828. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  10829. * @returns {Array} Returns the slice of `array`.
  10830. * @example
  10831. *
  10832. * _.take([1, 2, 3]);
  10833. * // => [1]
  10834. *
  10835. * _.take([1, 2, 3], 2);
  10836. * // => [1, 2]
  10837. *
  10838. * _.take([1, 2, 3], 5);
  10839. * // => [1, 2, 3]
  10840. *
  10841. * _.take([1, 2, 3], 0);
  10842. * // => []
  10843. */
  10844. function take(array, n, guard) {
  10845. if (!(array && array.length)) {
  10846. return [];
  10847. }
  10848. n = (guard || n === undefined) ? 1 : toInteger(n);
  10849. return baseSlice(array, 0, n < 0 ? 0 : n);
  10850. }
  10851. /**
  10852. * Creates a slice of `array` with `n` elements taken from the end.
  10853. *
  10854. * @static
  10855. * @memberOf _
  10856. * @since 3.0.0
  10857. * @category Array
  10858. * @param {Array} array The array to query.
  10859. * @param {number} [n=1] The number of elements to take.
  10860. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  10861. * @returns {Array} Returns the slice of `array`.
  10862. * @example
  10863. *
  10864. * _.takeRight([1, 2, 3]);
  10865. * // => [3]
  10866. *
  10867. * _.takeRight([1, 2, 3], 2);
  10868. * // => [2, 3]
  10869. *
  10870. * _.takeRight([1, 2, 3], 5);
  10871. * // => [1, 2, 3]
  10872. *
  10873. * _.takeRight([1, 2, 3], 0);
  10874. * // => []
  10875. */
  10876. function takeRight(array, n, guard) {
  10877. var length = array == null ? 0 : array.length;
  10878. if (!length) {
  10879. return [];
  10880. }
  10881. n = (guard || n === undefined) ? 1 : toInteger(n);
  10882. n = length - n;
  10883. return baseSlice(array, n < 0 ? 0 : n, length);
  10884. }
  10885. /**
  10886. * Creates a slice of `array` with elements taken from the end. Elements are
  10887. * taken until `predicate` returns falsey. The predicate is invoked with
  10888. * three arguments: (value, index, array).
  10889. *
  10890. * @static
  10891. * @memberOf _
  10892. * @since 3.0.0
  10893. * @category Array
  10894. * @param {Array} array The array to query.
  10895. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10896. * @returns {Array} Returns the slice of `array`.
  10897. * @example
  10898. *
  10899. * var users = [
  10900. * { 'user': 'barney', 'active': true },
  10901. * { 'user': 'fred', 'active': false },
  10902. * { 'user': 'pebbles', 'active': false }
  10903. * ];
  10904. *
  10905. * _.takeRightWhile(users, function(o) { return !o.active; });
  10906. * // => objects for ['fred', 'pebbles']
  10907. *
  10908. * // The `_.matches` iteratee shorthand.
  10909. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  10910. * // => objects for ['pebbles']
  10911. *
  10912. * // The `_.matchesProperty` iteratee shorthand.
  10913. * _.takeRightWhile(users, ['active', false]);
  10914. * // => objects for ['fred', 'pebbles']
  10915. *
  10916. * // The `_.property` iteratee shorthand.
  10917. * _.takeRightWhile(users, 'active');
  10918. * // => []
  10919. */
  10920. function takeRightWhile(array, predicate) {
  10921. return (array && array.length)
  10922. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  10923. : [];
  10924. }
  10925. /**
  10926. * Creates a slice of `array` with elements taken from the beginning. Elements
  10927. * are taken until `predicate` returns falsey. The predicate is invoked with
  10928. * three arguments: (value, index, array).
  10929. *
  10930. * @static
  10931. * @memberOf _
  10932. * @since 3.0.0
  10933. * @category Array
  10934. * @param {Array} array The array to query.
  10935. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  10936. * @returns {Array} Returns the slice of `array`.
  10937. * @example
  10938. *
  10939. * var users = [
  10940. * { 'user': 'barney', 'active': false },
  10941. * { 'user': 'fred', 'active': false },
  10942. * { 'user': 'pebbles', 'active': true }
  10943. * ];
  10944. *
  10945. * _.takeWhile(users, function(o) { return !o.active; });
  10946. * // => objects for ['barney', 'fred']
  10947. *
  10948. * // The `_.matches` iteratee shorthand.
  10949. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  10950. * // => objects for ['barney']
  10951. *
  10952. * // The `_.matchesProperty` iteratee shorthand.
  10953. * _.takeWhile(users, ['active', false]);
  10954. * // => objects for ['barney', 'fred']
  10955. *
  10956. * // The `_.property` iteratee shorthand.
  10957. * _.takeWhile(users, 'active');
  10958. * // => []
  10959. */
  10960. function takeWhile(array, predicate) {
  10961. return (array && array.length)
  10962. ? baseWhile(array, getIteratee(predicate, 3))
  10963. : [];
  10964. }
  10965. /**
  10966. * Creates an array of unique values, in order, from all given arrays using
  10967. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10968. * for equality comparisons.
  10969. *
  10970. * @static
  10971. * @memberOf _
  10972. * @since 0.1.0
  10973. * @category Array
  10974. * @param {...Array} [arrays] The arrays to inspect.
  10975. * @returns {Array} Returns the new array of combined values.
  10976. * @example
  10977. *
  10978. * _.union([2], [1, 2]);
  10979. * // => [2, 1]
  10980. */
  10981. var union = baseRest(function(arrays) {
  10982. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  10983. });
  10984. /**
  10985. * This method is like `_.union` except that it accepts `iteratee` which is
  10986. * invoked for each element of each `arrays` to generate the criterion by
  10987. * which uniqueness is computed. Result values are chosen from the first
  10988. * array in which the value occurs. The iteratee is invoked with one argument:
  10989. * (value).
  10990. *
  10991. * @static
  10992. * @memberOf _
  10993. * @since 4.0.0
  10994. * @category Array
  10995. * @param {...Array} [arrays] The arrays to inspect.
  10996. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  10997. * @returns {Array} Returns the new array of combined values.
  10998. * @example
  10999. *
  11000. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  11001. * // => [2.1, 1.2]
  11002. *
  11003. * // The `_.property` iteratee shorthand.
  11004. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  11005. * // => [{ 'x': 1 }, { 'x': 2 }]
  11006. */
  11007. var unionBy = baseRest(function(arrays) {
  11008. var iteratee = last(arrays);
  11009. if (isArrayLikeObject(iteratee)) {
  11010. iteratee = undefined;
  11011. }
  11012. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  11013. });
  11014. /**
  11015. * This method is like `_.union` except that it accepts `comparator` which
  11016. * is invoked to compare elements of `arrays`. Result values are chosen from
  11017. * the first array in which the value occurs. The comparator is invoked
  11018. * with two arguments: (arrVal, othVal).
  11019. *
  11020. * @static
  11021. * @memberOf _
  11022. * @since 4.0.0
  11023. * @category Array
  11024. * @param {...Array} [arrays] The arrays to inspect.
  11025. * @param {Function} [comparator] The comparator invoked per element.
  11026. * @returns {Array} Returns the new array of combined values.
  11027. * @example
  11028. *
  11029. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  11030. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  11031. *
  11032. * _.unionWith(objects, others, _.isEqual);
  11033. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  11034. */
  11035. var unionWith = baseRest(function(arrays) {
  11036. var comparator = last(arrays);
  11037. comparator = typeof comparator == 'function' ? comparator : undefined;
  11038. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  11039. });
  11040. /**
  11041. * Creates a duplicate-free version of an array, using
  11042. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  11043. * for equality comparisons, in which only the first occurrence of each element
  11044. * is kept. The order of result values is determined by the order they occur
  11045. * in the array.
  11046. *
  11047. * @static
  11048. * @memberOf _
  11049. * @since 0.1.0
  11050. * @category Array
  11051. * @param {Array} array The array to inspect.
  11052. * @returns {Array} Returns the new duplicate free array.
  11053. * @example
  11054. *
  11055. * _.uniq([2, 1, 2]);
  11056. * // => [2, 1]
  11057. */
  11058. function uniq(array) {
  11059. return (array && array.length) ? baseUniq(array) : [];
  11060. }
  11061. /**
  11062. * This method is like `_.uniq` except that it accepts `iteratee` which is
  11063. * invoked for each element in `array` to generate the criterion by which
  11064. * uniqueness is computed. The order of result values is determined by the
  11065. * order they occur in the array. The iteratee is invoked with one argument:
  11066. * (value).
  11067. *
  11068. * @static
  11069. * @memberOf _
  11070. * @since 4.0.0
  11071. * @category Array
  11072. * @param {Array} array The array to inspect.
  11073. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  11074. * @returns {Array} Returns the new duplicate free array.
  11075. * @example
  11076. *
  11077. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  11078. * // => [2.1, 1.2]
  11079. *
  11080. * // The `_.property` iteratee shorthand.
  11081. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  11082. * // => [{ 'x': 1 }, { 'x': 2 }]
  11083. */
  11084. function uniqBy(array, iteratee) {
  11085. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  11086. }
  11087. /**
  11088. * This method is like `_.uniq` except that it accepts `comparator` which
  11089. * is invoked to compare elements of `array`. The order of result values is
  11090. * determined by the order they occur in the array.The comparator is invoked
  11091. * with two arguments: (arrVal, othVal).
  11092. *
  11093. * @static
  11094. * @memberOf _
  11095. * @since 4.0.0
  11096. * @category Array
  11097. * @param {Array} array The array to inspect.
  11098. * @param {Function} [comparator] The comparator invoked per element.
  11099. * @returns {Array} Returns the new duplicate free array.
  11100. * @example
  11101. *
  11102. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  11103. *
  11104. * _.uniqWith(objects, _.isEqual);
  11105. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  11106. */
  11107. function uniqWith(array, comparator) {
  11108. comparator = typeof comparator == 'function' ? comparator : undefined;
  11109. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  11110. }
  11111. /**
  11112. * This method is like `_.zip` except that it accepts an array of grouped
  11113. * elements and creates an array regrouping the elements to their pre-zip
  11114. * configuration.
  11115. *
  11116. * @static
  11117. * @memberOf _
  11118. * @since 1.2.0
  11119. * @category Array
  11120. * @param {Array} array The array of grouped elements to process.
  11121. * @returns {Array} Returns the new array of regrouped elements.
  11122. * @example
  11123. *
  11124. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  11125. * // => [['a', 1, true], ['b', 2, false]]
  11126. *
  11127. * _.unzip(zipped);
  11128. * // => [['a', 'b'], [1, 2], [true, false]]
  11129. */
  11130. function unzip(array) {
  11131. if (!(array && array.length)) {
  11132. return [];
  11133. }
  11134. var length = 0;
  11135. array = arrayFilter(array, function(group) {
  11136. if (isArrayLikeObject(group)) {
  11137. length = nativeMax(group.length, length);
  11138. return true;
  11139. }
  11140. });
  11141. return baseTimes(length, function(index) {
  11142. return arrayMap(array, baseProperty(index));
  11143. });
  11144. }
  11145. /**
  11146. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  11147. * how regrouped values should be combined. The iteratee is invoked with the
  11148. * elements of each group: (...group).
  11149. *
  11150. * @static
  11151. * @memberOf _
  11152. * @since 3.8.0
  11153. * @category Array
  11154. * @param {Array} array The array of grouped elements to process.
  11155. * @param {Function} [iteratee=_.identity] The function to combine
  11156. * regrouped values.
  11157. * @returns {Array} Returns the new array of regrouped elements.
  11158. * @example
  11159. *
  11160. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  11161. * // => [[1, 10, 100], [2, 20, 200]]
  11162. *
  11163. * _.unzipWith(zipped, _.add);
  11164. * // => [3, 30, 300]
  11165. */
  11166. function unzipWith(array, iteratee) {
  11167. if (!(array && array.length)) {
  11168. return [];
  11169. }
  11170. var result = unzip(array);
  11171. if (iteratee == null) {
  11172. return result;
  11173. }
  11174. return arrayMap(result, function(group) {
  11175. return apply(iteratee, undefined, group);
  11176. });
  11177. }
  11178. /**
  11179. * Creates an array excluding all given values using
  11180. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  11181. * for equality comparisons.
  11182. *
  11183. * **Note:** Unlike `_.pull`, this method returns a new array.
  11184. *
  11185. * @static
  11186. * @memberOf _
  11187. * @since 0.1.0
  11188. * @category Array
  11189. * @param {Array} array The array to inspect.
  11190. * @param {...*} [values] The values to exclude.
  11191. * @returns {Array} Returns the new array of filtered values.
  11192. * @see _.difference, _.xor
  11193. * @example
  11194. *
  11195. * _.without([2, 1, 2, 3], 1, 2);
  11196. * // => [3]
  11197. */
  11198. var without = baseRest(function(array, values) {
  11199. return isArrayLikeObject(array)
  11200. ? baseDifference(array, values)
  11201. : [];
  11202. });
  11203. /**
  11204. * Creates an array of unique values that is the
  11205. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  11206. * of the given arrays. The order of result values is determined by the order
  11207. * they occur in the arrays.
  11208. *
  11209. * @static
  11210. * @memberOf _
  11211. * @since 2.4.0
  11212. * @category Array
  11213. * @param {...Array} [arrays] The arrays to inspect.
  11214. * @returns {Array} Returns the new array of filtered values.
  11215. * @see _.difference, _.without
  11216. * @example
  11217. *
  11218. * _.xor([2, 1], [2, 3]);
  11219. * // => [1, 3]
  11220. */
  11221. var xor = baseRest(function(arrays) {
  11222. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  11223. });
  11224. /**
  11225. * This method is like `_.xor` except that it accepts `iteratee` which is
  11226. * invoked for each element of each `arrays` to generate the criterion by
  11227. * which by which they're compared. The order of result values is determined
  11228. * by the order they occur in the arrays. The iteratee is invoked with one
  11229. * argument: (value).
  11230. *
  11231. * @static
  11232. * @memberOf _
  11233. * @since 4.0.0
  11234. * @category Array
  11235. * @param {...Array} [arrays] The arrays to inspect.
  11236. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  11237. * @returns {Array} Returns the new array of filtered values.
  11238. * @example
  11239. *
  11240. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  11241. * // => [1.2, 3.4]
  11242. *
  11243. * // The `_.property` iteratee shorthand.
  11244. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  11245. * // => [{ 'x': 2 }]
  11246. */
  11247. var xorBy = baseRest(function(arrays) {
  11248. var iteratee = last(arrays);
  11249. if (isArrayLikeObject(iteratee)) {
  11250. iteratee = undefined;
  11251. }
  11252. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  11253. });
  11254. /**
  11255. * This method is like `_.xor` except that it accepts `comparator` which is
  11256. * invoked to compare elements of `arrays`. The order of result values is
  11257. * determined by the order they occur in the arrays. The comparator is invoked
  11258. * with two arguments: (arrVal, othVal).
  11259. *
  11260. * @static
  11261. * @memberOf _
  11262. * @since 4.0.0
  11263. * @category Array
  11264. * @param {...Array} [arrays] The arrays to inspect.
  11265. * @param {Function} [comparator] The comparator invoked per element.
  11266. * @returns {Array} Returns the new array of filtered values.
  11267. * @example
  11268. *
  11269. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  11270. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  11271. *
  11272. * _.xorWith(objects, others, _.isEqual);
  11273. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  11274. */
  11275. var xorWith = baseRest(function(arrays) {
  11276. var comparator = last(arrays);
  11277. comparator = typeof comparator == 'function' ? comparator : undefined;
  11278. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  11279. });
  11280. /**
  11281. * Creates an array of grouped elements, the first of which contains the
  11282. * first elements of the given arrays, the second of which contains the
  11283. * second elements of the given arrays, and so on.
  11284. *
  11285. * @static
  11286. * @memberOf _
  11287. * @since 0.1.0
  11288. * @category Array
  11289. * @param {...Array} [arrays] The arrays to process.
  11290. * @returns {Array} Returns the new array of grouped elements.
  11291. * @example
  11292. *
  11293. * _.zip(['a', 'b'], [1, 2], [true, false]);
  11294. * // => [['a', 1, true], ['b', 2, false]]
  11295. */
  11296. var zip = baseRest(unzip);
  11297. /**
  11298. * This method is like `_.fromPairs` except that it accepts two arrays,
  11299. * one of property identifiers and one of corresponding values.
  11300. *
  11301. * @static
  11302. * @memberOf _
  11303. * @since 0.4.0
  11304. * @category Array
  11305. * @param {Array} [props=[]] The property identifiers.
  11306. * @param {Array} [values=[]] The property values.
  11307. * @returns {Object} Returns the new object.
  11308. * @example
  11309. *
  11310. * _.zipObject(['a', 'b'], [1, 2]);
  11311. * // => { 'a': 1, 'b': 2 }
  11312. */
  11313. function zipObject(props, values) {
  11314. return baseZipObject(props || [], values || [], assignValue);
  11315. }
  11316. /**
  11317. * This method is like `_.zipObject` except that it supports property paths.
  11318. *
  11319. * @static
  11320. * @memberOf _
  11321. * @since 4.1.0
  11322. * @category Array
  11323. * @param {Array} [props=[]] The property identifiers.
  11324. * @param {Array} [values=[]] The property values.
  11325. * @returns {Object} Returns the new object.
  11326. * @example
  11327. *
  11328. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  11329. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  11330. */
  11331. function zipObjectDeep(props, values) {
  11332. return baseZipObject(props || [], values || [], baseSet);
  11333. }
  11334. /**
  11335. * This method is like `_.zip` except that it accepts `iteratee` to specify
  11336. * how grouped values should be combined. The iteratee is invoked with the
  11337. * elements of each group: (...group).
  11338. *
  11339. * @static
  11340. * @memberOf _
  11341. * @since 3.8.0
  11342. * @category Array
  11343. * @param {...Array} [arrays] The arrays to process.
  11344. * @param {Function} [iteratee=_.identity] The function to combine
  11345. * grouped values.
  11346. * @returns {Array} Returns the new array of grouped elements.
  11347. * @example
  11348. *
  11349. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  11350. * return a + b + c;
  11351. * });
  11352. * // => [111, 222]
  11353. */
  11354. var zipWith = baseRest(function(arrays) {
  11355. var length = arrays.length,
  11356. iteratee = length > 1 ? arrays[length - 1] : undefined;
  11357. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  11358. return unzipWith(arrays, iteratee);
  11359. });
  11360. /*------------------------------------------------------------------------*/
  11361. /**
  11362. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  11363. * chain sequences enabled. The result of such sequences must be unwrapped
  11364. * with `_#value`.
  11365. *
  11366. * @static
  11367. * @memberOf _
  11368. * @since 1.3.0
  11369. * @category Seq
  11370. * @param {*} value The value to wrap.
  11371. * @returns {Object} Returns the new `lodash` wrapper instance.
  11372. * @example
  11373. *
  11374. * var users = [
  11375. * { 'user': 'barney', 'age': 36 },
  11376. * { 'user': 'fred', 'age': 40 },
  11377. * { 'user': 'pebbles', 'age': 1 }
  11378. * ];
  11379. *
  11380. * var youngest = _
  11381. * .chain(users)
  11382. * .sortBy('age')
  11383. * .map(function(o) {
  11384. * return o.user + ' is ' + o.age;
  11385. * })
  11386. * .head()
  11387. * .value();
  11388. * // => 'pebbles is 1'
  11389. */
  11390. function chain(value) {
  11391. var result = lodash(value);
  11392. result.__chain__ = true;
  11393. return result;
  11394. }
  11395. /**
  11396. * This method invokes `interceptor` and returns `value`. The interceptor
  11397. * is invoked with one argument; (value). The purpose of this method is to
  11398. * "tap into" a method chain sequence in order to modify intermediate results.
  11399. *
  11400. * @static
  11401. * @memberOf _
  11402. * @since 0.1.0
  11403. * @category Seq
  11404. * @param {*} value The value to provide to `interceptor`.
  11405. * @param {Function} interceptor The function to invoke.
  11406. * @returns {*} Returns `value`.
  11407. * @example
  11408. *
  11409. * _([1, 2, 3])
  11410. * .tap(function(array) {
  11411. * // Mutate input array.
  11412. * array.pop();
  11413. * })
  11414. * .reverse()
  11415. * .value();
  11416. * // => [2, 1]
  11417. */
  11418. function tap(value, interceptor) {
  11419. interceptor(value);
  11420. return value;
  11421. }
  11422. /**
  11423. * This method is like `_.tap` except that it returns the result of `interceptor`.
  11424. * The purpose of this method is to "pass thru" values replacing intermediate
  11425. * results in a method chain sequence.
  11426. *
  11427. * @static
  11428. * @memberOf _
  11429. * @since 3.0.0
  11430. * @category Seq
  11431. * @param {*} value The value to provide to `interceptor`.
  11432. * @param {Function} interceptor The function to invoke.
  11433. * @returns {*} Returns the result of `interceptor`.
  11434. * @example
  11435. *
  11436. * _(' abc ')
  11437. * .chain()
  11438. * .trim()
  11439. * .thru(function(value) {
  11440. * return [value];
  11441. * })
  11442. * .value();
  11443. * // => ['abc']
  11444. */
  11445. function thru(value, interceptor) {
  11446. return interceptor(value);
  11447. }
  11448. /**
  11449. * This method is the wrapper version of `_.at`.
  11450. *
  11451. * @name at
  11452. * @memberOf _
  11453. * @since 1.0.0
  11454. * @category Seq
  11455. * @param {...(string|string[])} [paths] The property paths to pick.
  11456. * @returns {Object} Returns the new `lodash` wrapper instance.
  11457. * @example
  11458. *
  11459. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11460. *
  11461. * _(object).at(['a[0].b.c', 'a[1]']).value();
  11462. * // => [3, 4]
  11463. */
  11464. var wrapperAt = flatRest(function(paths) {
  11465. var length = paths.length,
  11466. start = length ? paths[0] : 0,
  11467. value = this.__wrapped__,
  11468. interceptor = function(object) { return baseAt(object, paths); };
  11469. if (length > 1 || this.__actions__.length ||
  11470. !(value instanceof LazyWrapper) || !isIndex(start)) {
  11471. return this.thru(interceptor);
  11472. }
  11473. value = value.slice(start, +start + (length ? 1 : 0));
  11474. value.__actions__.push({
  11475. 'func': thru,
  11476. 'args': [interceptor],
  11477. 'thisArg': undefined
  11478. });
  11479. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  11480. if (length && !array.length) {
  11481. array.push(undefined);
  11482. }
  11483. return array;
  11484. });
  11485. });
  11486. /**
  11487. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  11488. *
  11489. * @name chain
  11490. * @memberOf _
  11491. * @since 0.1.0
  11492. * @category Seq
  11493. * @returns {Object} Returns the new `lodash` wrapper instance.
  11494. * @example
  11495. *
  11496. * var users = [
  11497. * { 'user': 'barney', 'age': 36 },
  11498. * { 'user': 'fred', 'age': 40 }
  11499. * ];
  11500. *
  11501. * // A sequence without explicit chaining.
  11502. * _(users).head();
  11503. * // => { 'user': 'barney', 'age': 36 }
  11504. *
  11505. * // A sequence with explicit chaining.
  11506. * _(users)
  11507. * .chain()
  11508. * .head()
  11509. * .pick('user')
  11510. * .value();
  11511. * // => { 'user': 'barney' }
  11512. */
  11513. function wrapperChain() {
  11514. return chain(this);
  11515. }
  11516. /**
  11517. * Executes the chain sequence and returns the wrapped result.
  11518. *
  11519. * @name commit
  11520. * @memberOf _
  11521. * @since 3.2.0
  11522. * @category Seq
  11523. * @returns {Object} Returns the new `lodash` wrapper instance.
  11524. * @example
  11525. *
  11526. * var array = [1, 2];
  11527. * var wrapped = _(array).push(3);
  11528. *
  11529. * console.log(array);
  11530. * // => [1, 2]
  11531. *
  11532. * wrapped = wrapped.commit();
  11533. * console.log(array);
  11534. * // => [1, 2, 3]
  11535. *
  11536. * wrapped.last();
  11537. * // => 3
  11538. *
  11539. * console.log(array);
  11540. * // => [1, 2, 3]
  11541. */
  11542. function wrapperCommit() {
  11543. return new LodashWrapper(this.value(), this.__chain__);
  11544. }
  11545. /**
  11546. * Gets the next value on a wrapped object following the
  11547. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  11548. *
  11549. * @name next
  11550. * @memberOf _
  11551. * @since 4.0.0
  11552. * @category Seq
  11553. * @returns {Object} Returns the next iterator value.
  11554. * @example
  11555. *
  11556. * var wrapped = _([1, 2]);
  11557. *
  11558. * wrapped.next();
  11559. * // => { 'done': false, 'value': 1 }
  11560. *
  11561. * wrapped.next();
  11562. * // => { 'done': false, 'value': 2 }
  11563. *
  11564. * wrapped.next();
  11565. * // => { 'done': true, 'value': undefined }
  11566. */
  11567. function wrapperNext() {
  11568. if (this.__values__ === undefined) {
  11569. this.__values__ = toArray(this.value());
  11570. }
  11571. var done = this.__index__ >= this.__values__.length,
  11572. value = done ? undefined : this.__values__[this.__index__++];
  11573. return { 'done': done, 'value': value };
  11574. }
  11575. /**
  11576. * Enables the wrapper to be iterable.
  11577. *
  11578. * @name Symbol.iterator
  11579. * @memberOf _
  11580. * @since 4.0.0
  11581. * @category Seq
  11582. * @returns {Object} Returns the wrapper object.
  11583. * @example
  11584. *
  11585. * var wrapped = _([1, 2]);
  11586. *
  11587. * wrapped[Symbol.iterator]() === wrapped;
  11588. * // => true
  11589. *
  11590. * Array.from(wrapped);
  11591. * // => [1, 2]
  11592. */
  11593. function wrapperToIterator() {
  11594. return this;
  11595. }
  11596. /**
  11597. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  11598. *
  11599. * @name plant
  11600. * @memberOf _
  11601. * @since 3.2.0
  11602. * @category Seq
  11603. * @param {*} value The value to plant.
  11604. * @returns {Object} Returns the new `lodash` wrapper instance.
  11605. * @example
  11606. *
  11607. * function square(n) {
  11608. * return n * n;
  11609. * }
  11610. *
  11611. * var wrapped = _([1, 2]).map(square);
  11612. * var other = wrapped.plant([3, 4]);
  11613. *
  11614. * other.value();
  11615. * // => [9, 16]
  11616. *
  11617. * wrapped.value();
  11618. * // => [1, 4]
  11619. */
  11620. function wrapperPlant(value) {
  11621. var result,
  11622. parent = this;
  11623. while (parent instanceof baseLodash) {
  11624. var clone = wrapperClone(parent);
  11625. clone.__index__ = 0;
  11626. clone.__values__ = undefined;
  11627. if (result) {
  11628. previous.__wrapped__ = clone;
  11629. } else {
  11630. result = clone;
  11631. }
  11632. var previous = clone;
  11633. parent = parent.__wrapped__;
  11634. }
  11635. previous.__wrapped__ = value;
  11636. return result;
  11637. }
  11638. /**
  11639. * This method is the wrapper version of `_.reverse`.
  11640. *
  11641. * **Note:** This method mutates the wrapped array.
  11642. *
  11643. * @name reverse
  11644. * @memberOf _
  11645. * @since 0.1.0
  11646. * @category Seq
  11647. * @returns {Object} Returns the new `lodash` wrapper instance.
  11648. * @example
  11649. *
  11650. * var array = [1, 2, 3];
  11651. *
  11652. * _(array).reverse().value()
  11653. * // => [3, 2, 1]
  11654. *
  11655. * console.log(array);
  11656. * // => [3, 2, 1]
  11657. */
  11658. function wrapperReverse() {
  11659. var value = this.__wrapped__;
  11660. if (value instanceof LazyWrapper) {
  11661. var wrapped = value;
  11662. if (this.__actions__.length) {
  11663. wrapped = new LazyWrapper(this);
  11664. }
  11665. wrapped = wrapped.reverse();
  11666. wrapped.__actions__.push({
  11667. 'func': thru,
  11668. 'args': [reverse],
  11669. 'thisArg': undefined
  11670. });
  11671. return new LodashWrapper(wrapped, this.__chain__);
  11672. }
  11673. return this.thru(reverse);
  11674. }
  11675. /**
  11676. * Executes the chain sequence to resolve the unwrapped value.
  11677. *
  11678. * @name value
  11679. * @memberOf _
  11680. * @since 0.1.0
  11681. * @alias toJSON, valueOf
  11682. * @category Seq
  11683. * @returns {*} Returns the resolved unwrapped value.
  11684. * @example
  11685. *
  11686. * _([1, 2, 3]).value();
  11687. * // => [1, 2, 3]
  11688. */
  11689. function wrapperValue() {
  11690. return baseWrapperValue(this.__wrapped__, this.__actions__);
  11691. }
  11692. /*------------------------------------------------------------------------*/
  11693. /**
  11694. * Creates an object composed of keys generated from the results of running
  11695. * each element of `collection` thru `iteratee`. The corresponding value of
  11696. * each key is the number of times the key was returned by `iteratee`. The
  11697. * iteratee is invoked with one argument: (value).
  11698. *
  11699. * @static
  11700. * @memberOf _
  11701. * @since 0.5.0
  11702. * @category Collection
  11703. * @param {Array|Object} collection The collection to iterate over.
  11704. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  11705. * @returns {Object} Returns the composed aggregate object.
  11706. * @example
  11707. *
  11708. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  11709. * // => { '4': 1, '6': 2 }
  11710. *
  11711. * // The `_.property` iteratee shorthand.
  11712. * _.countBy(['one', 'two', 'three'], 'length');
  11713. * // => { '3': 2, '5': 1 }
  11714. */
  11715. var countBy = createAggregator(function(result, value, key) {
  11716. if (hasOwnProperty.call(result, key)) {
  11717. ++result[key];
  11718. } else {
  11719. baseAssignValue(result, key, 1);
  11720. }
  11721. });
  11722. /**
  11723. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  11724. * Iteration is stopped once `predicate` returns falsey. The predicate is
  11725. * invoked with three arguments: (value, index|key, collection).
  11726. *
  11727. * **Note:** This method returns `true` for
  11728. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  11729. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  11730. * elements of empty collections.
  11731. *
  11732. * @static
  11733. * @memberOf _
  11734. * @since 0.1.0
  11735. * @category Collection
  11736. * @param {Array|Object} collection The collection to iterate over.
  11737. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11738. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  11739. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  11740. * else `false`.
  11741. * @example
  11742. *
  11743. * _.every([true, 1, null, 'yes'], Boolean);
  11744. * // => false
  11745. *
  11746. * var users = [
  11747. * { 'user': 'barney', 'age': 36, 'active': false },
  11748. * { 'user': 'fred', 'age': 40, 'active': false }
  11749. * ];
  11750. *
  11751. * // The `_.matches` iteratee shorthand.
  11752. * _.every(users, { 'user': 'barney', 'active': false });
  11753. * // => false
  11754. *
  11755. * // The `_.matchesProperty` iteratee shorthand.
  11756. * _.every(users, ['active', false]);
  11757. * // => true
  11758. *
  11759. * // The `_.property` iteratee shorthand.
  11760. * _.every(users, 'active');
  11761. * // => false
  11762. */
  11763. function every(collection, predicate, guard) {
  11764. var func = isArray(collection) ? arrayEvery : baseEvery;
  11765. if (guard && isIterateeCall(collection, predicate, guard)) {
  11766. predicate = undefined;
  11767. }
  11768. return func(collection, getIteratee(predicate, 3));
  11769. }
  11770. /**
  11771. * Iterates over elements of `collection`, returning an array of all elements
  11772. * `predicate` returns truthy for. The predicate is invoked with three
  11773. * arguments: (value, index|key, collection).
  11774. *
  11775. * **Note:** Unlike `_.remove`, this method returns a new array.
  11776. *
  11777. * @static
  11778. * @memberOf _
  11779. * @since 0.1.0
  11780. * @category Collection
  11781. * @param {Array|Object} collection The collection to iterate over.
  11782. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11783. * @returns {Array} Returns the new filtered array.
  11784. * @see _.reject
  11785. * @example
  11786. *
  11787. * var users = [
  11788. * { 'user': 'barney', 'age': 36, 'active': true },
  11789. * { 'user': 'fred', 'age': 40, 'active': false }
  11790. * ];
  11791. *
  11792. * _.filter(users, function(o) { return !o.active; });
  11793. * // => objects for ['fred']
  11794. *
  11795. * // The `_.matches` iteratee shorthand.
  11796. * _.filter(users, { 'age': 36, 'active': true });
  11797. * // => objects for ['barney']
  11798. *
  11799. * // The `_.matchesProperty` iteratee shorthand.
  11800. * _.filter(users, ['active', false]);
  11801. * // => objects for ['fred']
  11802. *
  11803. * // The `_.property` iteratee shorthand.
  11804. * _.filter(users, 'active');
  11805. * // => objects for ['barney']
  11806. *
  11807. * // Combining several predicates using `_.overEvery` or `_.overSome`.
  11808. * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
  11809. * // => objects for ['fred', 'barney']
  11810. */
  11811. function filter(collection, predicate) {
  11812. var func = isArray(collection) ? arrayFilter : baseFilter;
  11813. return func(collection, getIteratee(predicate, 3));
  11814. }
  11815. /**
  11816. * Iterates over elements of `collection`, returning the first element
  11817. * `predicate` returns truthy for. The predicate is invoked with three
  11818. * arguments: (value, index|key, collection).
  11819. *
  11820. * @static
  11821. * @memberOf _
  11822. * @since 0.1.0
  11823. * @category Collection
  11824. * @param {Array|Object} collection The collection to inspect.
  11825. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11826. * @param {number} [fromIndex=0] The index to search from.
  11827. * @returns {*} Returns the matched element, else `undefined`.
  11828. * @example
  11829. *
  11830. * var users = [
  11831. * { 'user': 'barney', 'age': 36, 'active': true },
  11832. * { 'user': 'fred', 'age': 40, 'active': false },
  11833. * { 'user': 'pebbles', 'age': 1, 'active': true }
  11834. * ];
  11835. *
  11836. * _.find(users, function(o) { return o.age < 40; });
  11837. * // => object for 'barney'
  11838. *
  11839. * // The `_.matches` iteratee shorthand.
  11840. * _.find(users, { 'age': 1, 'active': true });
  11841. * // => object for 'pebbles'
  11842. *
  11843. * // The `_.matchesProperty` iteratee shorthand.
  11844. * _.find(users, ['active', false]);
  11845. * // => object for 'fred'
  11846. *
  11847. * // The `_.property` iteratee shorthand.
  11848. * _.find(users, 'active');
  11849. * // => object for 'barney'
  11850. */
  11851. var find = createFind(findIndex);
  11852. /**
  11853. * This method is like `_.find` except that it iterates over elements of
  11854. * `collection` from right to left.
  11855. *
  11856. * @static
  11857. * @memberOf _
  11858. * @since 2.0.0
  11859. * @category Collection
  11860. * @param {Array|Object} collection The collection to inspect.
  11861. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11862. * @param {number} [fromIndex=collection.length-1] The index to search from.
  11863. * @returns {*} Returns the matched element, else `undefined`.
  11864. * @example
  11865. *
  11866. * _.findLast([1, 2, 3, 4], function(n) {
  11867. * return n % 2 == 1;
  11868. * });
  11869. * // => 3
  11870. */
  11871. var findLast = createFind(findLastIndex);
  11872. /**
  11873. * Creates a flattened array of values by running each element in `collection`
  11874. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  11875. * with three arguments: (value, index|key, collection).
  11876. *
  11877. * @static
  11878. * @memberOf _
  11879. * @since 4.0.0
  11880. * @category Collection
  11881. * @param {Array|Object} collection The collection to iterate over.
  11882. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11883. * @returns {Array} Returns the new flattened array.
  11884. * @example
  11885. *
  11886. * function duplicate(n) {
  11887. * return [n, n];
  11888. * }
  11889. *
  11890. * _.flatMap([1, 2], duplicate);
  11891. * // => [1, 1, 2, 2]
  11892. */
  11893. function flatMap(collection, iteratee) {
  11894. return baseFlatten(map(collection, iteratee), 1);
  11895. }
  11896. /**
  11897. * This method is like `_.flatMap` except that it recursively flattens the
  11898. * mapped results.
  11899. *
  11900. * @static
  11901. * @memberOf _
  11902. * @since 4.7.0
  11903. * @category Collection
  11904. * @param {Array|Object} collection The collection to iterate over.
  11905. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11906. * @returns {Array} Returns the new flattened array.
  11907. * @example
  11908. *
  11909. * function duplicate(n) {
  11910. * return [[[n, n]]];
  11911. * }
  11912. *
  11913. * _.flatMapDeep([1, 2], duplicate);
  11914. * // => [1, 1, 2, 2]
  11915. */
  11916. function flatMapDeep(collection, iteratee) {
  11917. return baseFlatten(map(collection, iteratee), INFINITY);
  11918. }
  11919. /**
  11920. * This method is like `_.flatMap` except that it recursively flattens the
  11921. * mapped results up to `depth` times.
  11922. *
  11923. * @static
  11924. * @memberOf _
  11925. * @since 4.7.0
  11926. * @category Collection
  11927. * @param {Array|Object} collection The collection to iterate over.
  11928. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11929. * @param {number} [depth=1] The maximum recursion depth.
  11930. * @returns {Array} Returns the new flattened array.
  11931. * @example
  11932. *
  11933. * function duplicate(n) {
  11934. * return [[[n, n]]];
  11935. * }
  11936. *
  11937. * _.flatMapDepth([1, 2], duplicate, 2);
  11938. * // => [[1, 1], [2, 2]]
  11939. */
  11940. function flatMapDepth(collection, iteratee, depth) {
  11941. depth = depth === undefined ? 1 : toInteger(depth);
  11942. return baseFlatten(map(collection, iteratee), depth);
  11943. }
  11944. /**
  11945. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  11946. * The iteratee is invoked with three arguments: (value, index|key, collection).
  11947. * Iteratee functions may exit iteration early by explicitly returning `false`.
  11948. *
  11949. * **Note:** As with other "Collections" methods, objects with a "length"
  11950. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  11951. * or `_.forOwn` for object iteration.
  11952. *
  11953. * @static
  11954. * @memberOf _
  11955. * @since 0.1.0
  11956. * @alias each
  11957. * @category Collection
  11958. * @param {Array|Object} collection The collection to iterate over.
  11959. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11960. * @returns {Array|Object} Returns `collection`.
  11961. * @see _.forEachRight
  11962. * @example
  11963. *
  11964. * _.forEach([1, 2], function(value) {
  11965. * console.log(value);
  11966. * });
  11967. * // => Logs `1` then `2`.
  11968. *
  11969. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  11970. * console.log(key);
  11971. * });
  11972. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  11973. */
  11974. function forEach(collection, iteratee) {
  11975. var func = isArray(collection) ? arrayEach : baseEach;
  11976. return func(collection, getIteratee(iteratee, 3));
  11977. }
  11978. /**
  11979. * This method is like `_.forEach` except that it iterates over elements of
  11980. * `collection` from right to left.
  11981. *
  11982. * @static
  11983. * @memberOf _
  11984. * @since 2.0.0
  11985. * @alias eachRight
  11986. * @category Collection
  11987. * @param {Array|Object} collection The collection to iterate over.
  11988. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11989. * @returns {Array|Object} Returns `collection`.
  11990. * @see _.forEach
  11991. * @example
  11992. *
  11993. * _.forEachRight([1, 2], function(value) {
  11994. * console.log(value);
  11995. * });
  11996. * // => Logs `2` then `1`.
  11997. */
  11998. function forEachRight(collection, iteratee) {
  11999. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  12000. return func(collection, getIteratee(iteratee, 3));
  12001. }
  12002. /**
  12003. * Creates an object composed of keys generated from the results of running
  12004. * each element of `collection` thru `iteratee`. The order of grouped values
  12005. * is determined by the order they occur in `collection`. The corresponding
  12006. * value of each key is an array of elements responsible for generating the
  12007. * key. The iteratee is invoked with one argument: (value).
  12008. *
  12009. * @static
  12010. * @memberOf _
  12011. * @since 0.1.0
  12012. * @category Collection
  12013. * @param {Array|Object} collection The collection to iterate over.
  12014. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  12015. * @returns {Object} Returns the composed aggregate object.
  12016. * @example
  12017. *
  12018. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  12019. * // => { '4': [4.2], '6': [6.1, 6.3] }
  12020. *
  12021. * // The `_.property` iteratee shorthand.
  12022. * _.groupBy(['one', 'two', 'three'], 'length');
  12023. * // => { '3': ['one', 'two'], '5': ['three'] }
  12024. */
  12025. var groupBy = createAggregator(function(result, value, key) {
  12026. if (hasOwnProperty.call(result, key)) {
  12027. result[key].push(value);
  12028. } else {
  12029. baseAssignValue(result, key, [value]);
  12030. }
  12031. });
  12032. /**
  12033. * Checks if `value` is in `collection`. If `collection` is a string, it's
  12034. * checked for a substring of `value`, otherwise
  12035. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  12036. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  12037. * the offset from the end of `collection`.
  12038. *
  12039. * @static
  12040. * @memberOf _
  12041. * @since 0.1.0
  12042. * @category Collection
  12043. * @param {Array|Object|string} collection The collection to inspect.
  12044. * @param {*} value The value to search for.
  12045. * @param {number} [fromIndex=0] The index to search from.
  12046. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  12047. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  12048. * @example
  12049. *
  12050. * _.includes([1, 2, 3], 1);
  12051. * // => true
  12052. *
  12053. * _.includes([1, 2, 3], 1, 2);
  12054. * // => false
  12055. *
  12056. * _.includes({ 'a': 1, 'b': 2 }, 1);
  12057. * // => true
  12058. *
  12059. * _.includes('abcd', 'bc');
  12060. * // => true
  12061. */
  12062. function includes(collection, value, fromIndex, guard) {
  12063. collection = isArrayLike(collection) ? collection : values(collection);
  12064. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  12065. var length = collection.length;
  12066. if (fromIndex < 0) {
  12067. fromIndex = nativeMax(length + fromIndex, 0);
  12068. }
  12069. return isString(collection)
  12070. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  12071. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  12072. }
  12073. /**
  12074. * Invokes the method at `path` of each element in `collection`, returning
  12075. * an array of the results of each invoked method. Any additional arguments
  12076. * are provided to each invoked method. If `path` is a function, it's invoked
  12077. * for, and `this` bound to, each element in `collection`.
  12078. *
  12079. * @static
  12080. * @memberOf _
  12081. * @since 4.0.0
  12082. * @category Collection
  12083. * @param {Array|Object} collection The collection to iterate over.
  12084. * @param {Array|Function|string} path The path of the method to invoke or
  12085. * the function invoked per iteration.
  12086. * @param {...*} [args] The arguments to invoke each method with.
  12087. * @returns {Array} Returns the array of results.
  12088. * @example
  12089. *
  12090. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  12091. * // => [[1, 5, 7], [1, 2, 3]]
  12092. *
  12093. * _.invokeMap([123, 456], String.prototype.split, '');
  12094. * // => [['1', '2', '3'], ['4', '5', '6']]
  12095. */
  12096. var invokeMap = baseRest(function(collection, path, args) {
  12097. var index = -1,
  12098. isFunc = typeof path == 'function',
  12099. result = isArrayLike(collection) ? Array(collection.length) : [];
  12100. baseEach(collection, function(value) {
  12101. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  12102. });
  12103. return result;
  12104. });
  12105. /**
  12106. * Creates an object composed of keys generated from the results of running
  12107. * each element of `collection` thru `iteratee`. The corresponding value of
  12108. * each key is the last element responsible for generating the key. The
  12109. * iteratee is invoked with one argument: (value).
  12110. *
  12111. * @static
  12112. * @memberOf _
  12113. * @since 4.0.0
  12114. * @category Collection
  12115. * @param {Array|Object} collection The collection to iterate over.
  12116. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  12117. * @returns {Object} Returns the composed aggregate object.
  12118. * @example
  12119. *
  12120. * var array = [
  12121. * { 'dir': 'left', 'code': 97 },
  12122. * { 'dir': 'right', 'code': 100 }
  12123. * ];
  12124. *
  12125. * _.keyBy(array, function(o) {
  12126. * return String.fromCharCode(o.code);
  12127. * });
  12128. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  12129. *
  12130. * _.keyBy(array, 'dir');
  12131. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  12132. */
  12133. var keyBy = createAggregator(function(result, value, key) {
  12134. baseAssignValue(result, key, value);
  12135. });
  12136. /**
  12137. * Creates an array of values by running each element in `collection` thru
  12138. * `iteratee`. The iteratee is invoked with three arguments:
  12139. * (value, index|key, collection).
  12140. *
  12141. * Many lodash methods are guarded to work as iteratees for methods like
  12142. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  12143. *
  12144. * The guarded methods are:
  12145. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  12146. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  12147. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  12148. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  12149. *
  12150. * @static
  12151. * @memberOf _
  12152. * @since 0.1.0
  12153. * @category Collection
  12154. * @param {Array|Object} collection The collection to iterate over.
  12155. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12156. * @returns {Array} Returns the new mapped array.
  12157. * @example
  12158. *
  12159. * function square(n) {
  12160. * return n * n;
  12161. * }
  12162. *
  12163. * _.map([4, 8], square);
  12164. * // => [16, 64]
  12165. *
  12166. * _.map({ 'a': 4, 'b': 8 }, square);
  12167. * // => [16, 64] (iteration order is not guaranteed)
  12168. *
  12169. * var users = [
  12170. * { 'user': 'barney' },
  12171. * { 'user': 'fred' }
  12172. * ];
  12173. *
  12174. * // The `_.property` iteratee shorthand.
  12175. * _.map(users, 'user');
  12176. * // => ['barney', 'fred']
  12177. */
  12178. function map(collection, iteratee) {
  12179. var func = isArray(collection) ? arrayMap : baseMap;
  12180. return func(collection, getIteratee(iteratee, 3));
  12181. }
  12182. /**
  12183. * This method is like `_.sortBy` except that it allows specifying the sort
  12184. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  12185. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  12186. * descending or "asc" for ascending sort order of corresponding values.
  12187. *
  12188. * @static
  12189. * @memberOf _
  12190. * @since 4.0.0
  12191. * @category Collection
  12192. * @param {Array|Object} collection The collection to iterate over.
  12193. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  12194. * The iteratees to sort by.
  12195. * @param {string[]} [orders] The sort orders of `iteratees`.
  12196. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  12197. * @returns {Array} Returns the new sorted array.
  12198. * @example
  12199. *
  12200. * var users = [
  12201. * { 'user': 'fred', 'age': 48 },
  12202. * { 'user': 'barney', 'age': 34 },
  12203. * { 'user': 'fred', 'age': 40 },
  12204. * { 'user': 'barney', 'age': 36 }
  12205. * ];
  12206. *
  12207. * // Sort by `user` in ascending order and by `age` in descending order.
  12208. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  12209. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  12210. */
  12211. function orderBy(collection, iteratees, orders, guard) {
  12212. if (collection == null) {
  12213. return [];
  12214. }
  12215. if (!isArray(iteratees)) {
  12216. iteratees = iteratees == null ? [] : [iteratees];
  12217. }
  12218. orders = guard ? undefined : orders;
  12219. if (!isArray(orders)) {
  12220. orders = orders == null ? [] : [orders];
  12221. }
  12222. return baseOrderBy(collection, iteratees, orders);
  12223. }
  12224. /**
  12225. * Creates an array of elements split into two groups, the first of which
  12226. * contains elements `predicate` returns truthy for, the second of which
  12227. * contains elements `predicate` returns falsey for. The predicate is
  12228. * invoked with one argument: (value).
  12229. *
  12230. * @static
  12231. * @memberOf _
  12232. * @since 3.0.0
  12233. * @category Collection
  12234. * @param {Array|Object} collection The collection to iterate over.
  12235. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12236. * @returns {Array} Returns the array of grouped elements.
  12237. * @example
  12238. *
  12239. * var users = [
  12240. * { 'user': 'barney', 'age': 36, 'active': false },
  12241. * { 'user': 'fred', 'age': 40, 'active': true },
  12242. * { 'user': 'pebbles', 'age': 1, 'active': false }
  12243. * ];
  12244. *
  12245. * _.partition(users, function(o) { return o.active; });
  12246. * // => objects for [['fred'], ['barney', 'pebbles']]
  12247. *
  12248. * // The `_.matches` iteratee shorthand.
  12249. * _.partition(users, { 'age': 1, 'active': false });
  12250. * // => objects for [['pebbles'], ['barney', 'fred']]
  12251. *
  12252. * // The `_.matchesProperty` iteratee shorthand.
  12253. * _.partition(users, ['active', false]);
  12254. * // => objects for [['barney', 'pebbles'], ['fred']]
  12255. *
  12256. * // The `_.property` iteratee shorthand.
  12257. * _.partition(users, 'active');
  12258. * // => objects for [['fred'], ['barney', 'pebbles']]
  12259. */
  12260. var partition = createAggregator(function(result, value, key) {
  12261. result[key ? 0 : 1].push(value);
  12262. }, function() { return [[], []]; });
  12263. /**
  12264. * Reduces `collection` to a value which is the accumulated result of running
  12265. * each element in `collection` thru `iteratee`, where each successive
  12266. * invocation is supplied the return value of the previous. If `accumulator`
  12267. * is not given, the first element of `collection` is used as the initial
  12268. * value. The iteratee is invoked with four arguments:
  12269. * (accumulator, value, index|key, collection).
  12270. *
  12271. * Many lodash methods are guarded to work as iteratees for methods like
  12272. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  12273. *
  12274. * The guarded methods are:
  12275. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  12276. * and `sortBy`
  12277. *
  12278. * @static
  12279. * @memberOf _
  12280. * @since 0.1.0
  12281. * @category Collection
  12282. * @param {Array|Object} collection The collection to iterate over.
  12283. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12284. * @param {*} [accumulator] The initial value.
  12285. * @returns {*} Returns the accumulated value.
  12286. * @see _.reduceRight
  12287. * @example
  12288. *
  12289. * _.reduce([1, 2], function(sum, n) {
  12290. * return sum + n;
  12291. * }, 0);
  12292. * // => 3
  12293. *
  12294. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12295. * (result[value] || (result[value] = [])).push(key);
  12296. * return result;
  12297. * }, {});
  12298. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  12299. */
  12300. function reduce(collection, iteratee, accumulator) {
  12301. var func = isArray(collection) ? arrayReduce : baseReduce,
  12302. initAccum = arguments.length < 3;
  12303. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  12304. }
  12305. /**
  12306. * This method is like `_.reduce` except that it iterates over elements of
  12307. * `collection` from right to left.
  12308. *
  12309. * @static
  12310. * @memberOf _
  12311. * @since 0.1.0
  12312. * @category Collection
  12313. * @param {Array|Object} collection The collection to iterate over.
  12314. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12315. * @param {*} [accumulator] The initial value.
  12316. * @returns {*} Returns the accumulated value.
  12317. * @see _.reduce
  12318. * @example
  12319. *
  12320. * var array = [[0, 1], [2, 3], [4, 5]];
  12321. *
  12322. * _.reduceRight(array, function(flattened, other) {
  12323. * return flattened.concat(other);
  12324. * }, []);
  12325. * // => [4, 5, 2, 3, 0, 1]
  12326. */
  12327. function reduceRight(collection, iteratee, accumulator) {
  12328. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  12329. initAccum = arguments.length < 3;
  12330. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  12331. }
  12332. /**
  12333. * The opposite of `_.filter`; this method returns the elements of `collection`
  12334. * that `predicate` does **not** return truthy for.
  12335. *
  12336. * @static
  12337. * @memberOf _
  12338. * @since 0.1.0
  12339. * @category Collection
  12340. * @param {Array|Object} collection The collection to iterate over.
  12341. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12342. * @returns {Array} Returns the new filtered array.
  12343. * @see _.filter
  12344. * @example
  12345. *
  12346. * var users = [
  12347. * { 'user': 'barney', 'age': 36, 'active': false },
  12348. * { 'user': 'fred', 'age': 40, 'active': true }
  12349. * ];
  12350. *
  12351. * _.reject(users, function(o) { return !o.active; });
  12352. * // => objects for ['fred']
  12353. *
  12354. * // The `_.matches` iteratee shorthand.
  12355. * _.reject(users, { 'age': 40, 'active': true });
  12356. * // => objects for ['barney']
  12357. *
  12358. * // The `_.matchesProperty` iteratee shorthand.
  12359. * _.reject(users, ['active', false]);
  12360. * // => objects for ['fred']
  12361. *
  12362. * // The `_.property` iteratee shorthand.
  12363. * _.reject(users, 'active');
  12364. * // => objects for ['barney']
  12365. */
  12366. function reject(collection, predicate) {
  12367. var func = isArray(collection) ? arrayFilter : baseFilter;
  12368. return func(collection, negate(getIteratee(predicate, 3)));
  12369. }
  12370. /**
  12371. * Gets a random element from `collection`.
  12372. *
  12373. * @static
  12374. * @memberOf _
  12375. * @since 2.0.0
  12376. * @category Collection
  12377. * @param {Array|Object} collection The collection to sample.
  12378. * @returns {*} Returns the random element.
  12379. * @example
  12380. *
  12381. * _.sample([1, 2, 3, 4]);
  12382. * // => 2
  12383. */
  12384. function sample(collection) {
  12385. var func = isArray(collection) ? arraySample : baseSample;
  12386. return func(collection);
  12387. }
  12388. /**
  12389. * Gets `n` random elements at unique keys from `collection` up to the
  12390. * size of `collection`.
  12391. *
  12392. * @static
  12393. * @memberOf _
  12394. * @since 4.0.0
  12395. * @category Collection
  12396. * @param {Array|Object} collection The collection to sample.
  12397. * @param {number} [n=1] The number of elements to sample.
  12398. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  12399. * @returns {Array} Returns the random elements.
  12400. * @example
  12401. *
  12402. * _.sampleSize([1, 2, 3], 2);
  12403. * // => [3, 1]
  12404. *
  12405. * _.sampleSize([1, 2, 3], 4);
  12406. * // => [2, 3, 1]
  12407. */
  12408. function sampleSize(collection, n, guard) {
  12409. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  12410. n = 1;
  12411. } else {
  12412. n = toInteger(n);
  12413. }
  12414. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  12415. return func(collection, n);
  12416. }
  12417. /**
  12418. * Creates an array of shuffled values, using a version of the
  12419. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  12420. *
  12421. * @static
  12422. * @memberOf _
  12423. * @since 0.1.0
  12424. * @category Collection
  12425. * @param {Array|Object} collection The collection to shuffle.
  12426. * @returns {Array} Returns the new shuffled array.
  12427. * @example
  12428. *
  12429. * _.shuffle([1, 2, 3, 4]);
  12430. * // => [4, 1, 3, 2]
  12431. */
  12432. function shuffle(collection) {
  12433. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  12434. return func(collection);
  12435. }
  12436. /**
  12437. * Gets the size of `collection` by returning its length for array-like
  12438. * values or the number of own enumerable string keyed properties for objects.
  12439. *
  12440. * @static
  12441. * @memberOf _
  12442. * @since 0.1.0
  12443. * @category Collection
  12444. * @param {Array|Object|string} collection The collection to inspect.
  12445. * @returns {number} Returns the collection size.
  12446. * @example
  12447. *
  12448. * _.size([1, 2, 3]);
  12449. * // => 3
  12450. *
  12451. * _.size({ 'a': 1, 'b': 2 });
  12452. * // => 2
  12453. *
  12454. * _.size('pebbles');
  12455. * // => 7
  12456. */
  12457. function size(collection) {
  12458. if (collection == null) {
  12459. return 0;
  12460. }
  12461. if (isArrayLike(collection)) {
  12462. return isString(collection) ? stringSize(collection) : collection.length;
  12463. }
  12464. var tag = getTag(collection);
  12465. if (tag == mapTag || tag == setTag) {
  12466. return collection.size;
  12467. }
  12468. return baseKeys(collection).length;
  12469. }
  12470. /**
  12471. * Checks if `predicate` returns truthy for **any** element of `collection`.
  12472. * Iteration is stopped once `predicate` returns truthy. The predicate is
  12473. * invoked with three arguments: (value, index|key, collection).
  12474. *
  12475. * @static
  12476. * @memberOf _
  12477. * @since 0.1.0
  12478. * @category Collection
  12479. * @param {Array|Object} collection The collection to iterate over.
  12480. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12481. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  12482. * @returns {boolean} Returns `true` if any element passes the predicate check,
  12483. * else `false`.
  12484. * @example
  12485. *
  12486. * _.some([null, 0, 'yes', false], Boolean);
  12487. * // => true
  12488. *
  12489. * var users = [
  12490. * { 'user': 'barney', 'active': true },
  12491. * { 'user': 'fred', 'active': false }
  12492. * ];
  12493. *
  12494. * // The `_.matches` iteratee shorthand.
  12495. * _.some(users, { 'user': 'barney', 'active': false });
  12496. * // => false
  12497. *
  12498. * // The `_.matchesProperty` iteratee shorthand.
  12499. * _.some(users, ['active', false]);
  12500. * // => true
  12501. *
  12502. * // The `_.property` iteratee shorthand.
  12503. * _.some(users, 'active');
  12504. * // => true
  12505. */
  12506. function some(collection, predicate, guard) {
  12507. var func = isArray(collection) ? arraySome : baseSome;
  12508. if (guard && isIterateeCall(collection, predicate, guard)) {
  12509. predicate = undefined;
  12510. }
  12511. return func(collection, getIteratee(predicate, 3));
  12512. }
  12513. /**
  12514. * Creates an array of elements, sorted in ascending order by the results of
  12515. * running each element in a collection thru each iteratee. This method
  12516. * performs a stable sort, that is, it preserves the original sort order of
  12517. * equal elements. The iteratees are invoked with one argument: (value).
  12518. *
  12519. * @static
  12520. * @memberOf _
  12521. * @since 0.1.0
  12522. * @category Collection
  12523. * @param {Array|Object} collection The collection to iterate over.
  12524. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  12525. * The iteratees to sort by.
  12526. * @returns {Array} Returns the new sorted array.
  12527. * @example
  12528. *
  12529. * var users = [
  12530. * { 'user': 'fred', 'age': 48 },
  12531. * { 'user': 'barney', 'age': 36 },
  12532. * { 'user': 'fred', 'age': 30 },
  12533. * { 'user': 'barney', 'age': 34 }
  12534. * ];
  12535. *
  12536. * _.sortBy(users, [function(o) { return o.user; }]);
  12537. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
  12538. *
  12539. * _.sortBy(users, ['user', 'age']);
  12540. * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
  12541. */
  12542. var sortBy = baseRest(function(collection, iteratees) {
  12543. if (collection == null) {
  12544. return [];
  12545. }
  12546. var length = iteratees.length;
  12547. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  12548. iteratees = [];
  12549. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  12550. iteratees = [iteratees[0]];
  12551. }
  12552. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  12553. });
  12554. /*------------------------------------------------------------------------*/
  12555. /**
  12556. * Gets the timestamp of the number of milliseconds that have elapsed since
  12557. * the Unix epoch (1 January 1970 00:00:00 UTC).
  12558. *
  12559. * @static
  12560. * @memberOf _
  12561. * @since 2.4.0
  12562. * @category Date
  12563. * @returns {number} Returns the timestamp.
  12564. * @example
  12565. *
  12566. * _.defer(function(stamp) {
  12567. * console.log(_.now() - stamp);
  12568. * }, _.now());
  12569. * // => Logs the number of milliseconds it took for the deferred invocation.
  12570. */
  12571. var now = ctxNow || function() {
  12572. return root.Date.now();
  12573. };
  12574. /*------------------------------------------------------------------------*/
  12575. /**
  12576. * The opposite of `_.before`; this method creates a function that invokes
  12577. * `func` once it's called `n` or more times.
  12578. *
  12579. * @static
  12580. * @memberOf _
  12581. * @since 0.1.0
  12582. * @category Function
  12583. * @param {number} n The number of calls before `func` is invoked.
  12584. * @param {Function} func The function to restrict.
  12585. * @returns {Function} Returns the new restricted function.
  12586. * @example
  12587. *
  12588. * var saves = ['profile', 'settings'];
  12589. *
  12590. * var done = _.after(saves.length, function() {
  12591. * console.log('done saving!');
  12592. * });
  12593. *
  12594. * _.forEach(saves, function(type) {
  12595. * asyncSave({ 'type': type, 'complete': done });
  12596. * });
  12597. * // => Logs 'done saving!' after the two async saves have completed.
  12598. */
  12599. function after(n, func) {
  12600. if (typeof func != 'function') {
  12601. throw new TypeError(FUNC_ERROR_TEXT);
  12602. }
  12603. n = toInteger(n);
  12604. return function() {
  12605. if (--n < 1) {
  12606. return func.apply(this, arguments);
  12607. }
  12608. };
  12609. }
  12610. /**
  12611. * Creates a function that invokes `func`, with up to `n` arguments,
  12612. * ignoring any additional arguments.
  12613. *
  12614. * @static
  12615. * @memberOf _
  12616. * @since 3.0.0
  12617. * @category Function
  12618. * @param {Function} func The function to cap arguments for.
  12619. * @param {number} [n=func.length] The arity cap.
  12620. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  12621. * @returns {Function} Returns the new capped function.
  12622. * @example
  12623. *
  12624. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  12625. * // => [6, 8, 10]
  12626. */
  12627. function ary(func, n, guard) {
  12628. n = guard ? undefined : n;
  12629. n = (func && n == null) ? func.length : n;
  12630. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  12631. }
  12632. /**
  12633. * Creates a function that invokes `func`, with the `this` binding and arguments
  12634. * of the created function, while it's called less than `n` times. Subsequent
  12635. * calls to the created function return the result of the last `func` invocation.
  12636. *
  12637. * @static
  12638. * @memberOf _
  12639. * @since 3.0.0
  12640. * @category Function
  12641. * @param {number} n The number of calls at which `func` is no longer invoked.
  12642. * @param {Function} func The function to restrict.
  12643. * @returns {Function} Returns the new restricted function.
  12644. * @example
  12645. *
  12646. * jQuery(element).on('click', _.before(5, addContactToList));
  12647. * // => Allows adding up to 4 contacts to the list.
  12648. */
  12649. function before(n, func) {
  12650. var result;
  12651. if (typeof func != 'function') {
  12652. throw new TypeError(FUNC_ERROR_TEXT);
  12653. }
  12654. n = toInteger(n);
  12655. return function() {
  12656. if (--n > 0) {
  12657. result = func.apply(this, arguments);
  12658. }
  12659. if (n <= 1) {
  12660. func = undefined;
  12661. }
  12662. return result;
  12663. };
  12664. }
  12665. /**
  12666. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  12667. * and `partials` prepended to the arguments it receives.
  12668. *
  12669. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  12670. * may be used as a placeholder for partially applied arguments.
  12671. *
  12672. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  12673. * property of bound functions.
  12674. *
  12675. * @static
  12676. * @memberOf _
  12677. * @since 0.1.0
  12678. * @category Function
  12679. * @param {Function} func The function to bind.
  12680. * @param {*} thisArg The `this` binding of `func`.
  12681. * @param {...*} [partials] The arguments to be partially applied.
  12682. * @returns {Function} Returns the new bound function.
  12683. * @example
  12684. *
  12685. * function greet(greeting, punctuation) {
  12686. * return greeting + ' ' + this.user + punctuation;
  12687. * }
  12688. *
  12689. * var object = { 'user': 'fred' };
  12690. *
  12691. * var bound = _.bind(greet, object, 'hi');
  12692. * bound('!');
  12693. * // => 'hi fred!'
  12694. *
  12695. * // Bound with placeholders.
  12696. * var bound = _.bind(greet, object, _, '!');
  12697. * bound('hi');
  12698. * // => 'hi fred!'
  12699. */
  12700. var bind = baseRest(function(func, thisArg, partials) {
  12701. var bitmask = WRAP_BIND_FLAG;
  12702. if (partials.length) {
  12703. var holders = replaceHolders(partials, getHolder(bind));
  12704. bitmask |= WRAP_PARTIAL_FLAG;
  12705. }
  12706. return createWrap(func, bitmask, thisArg, partials, holders);
  12707. });
  12708. /**
  12709. * Creates a function that invokes the method at `object[key]` with `partials`
  12710. * prepended to the arguments it receives.
  12711. *
  12712. * This method differs from `_.bind` by allowing bound functions to reference
  12713. * methods that may be redefined or don't yet exist. See
  12714. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  12715. * for more details.
  12716. *
  12717. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  12718. * builds, may be used as a placeholder for partially applied arguments.
  12719. *
  12720. * @static
  12721. * @memberOf _
  12722. * @since 0.10.0
  12723. * @category Function
  12724. * @param {Object} object The object to invoke the method on.
  12725. * @param {string} key The key of the method.
  12726. * @param {...*} [partials] The arguments to be partially applied.
  12727. * @returns {Function} Returns the new bound function.
  12728. * @example
  12729. *
  12730. * var object = {
  12731. * 'user': 'fred',
  12732. * 'greet': function(greeting, punctuation) {
  12733. * return greeting + ' ' + this.user + punctuation;
  12734. * }
  12735. * };
  12736. *
  12737. * var bound = _.bindKey(object, 'greet', 'hi');
  12738. * bound('!');
  12739. * // => 'hi fred!'
  12740. *
  12741. * object.greet = function(greeting, punctuation) {
  12742. * return greeting + 'ya ' + this.user + punctuation;
  12743. * };
  12744. *
  12745. * bound('!');
  12746. * // => 'hiya fred!'
  12747. *
  12748. * // Bound with placeholders.
  12749. * var bound = _.bindKey(object, 'greet', _, '!');
  12750. * bound('hi');
  12751. * // => 'hiya fred!'
  12752. */
  12753. var bindKey = baseRest(function(object, key, partials) {
  12754. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  12755. if (partials.length) {
  12756. var holders = replaceHolders(partials, getHolder(bindKey));
  12757. bitmask |= WRAP_PARTIAL_FLAG;
  12758. }
  12759. return createWrap(key, bitmask, object, partials, holders);
  12760. });
  12761. /**
  12762. * Creates a function that accepts arguments of `func` and either invokes
  12763. * `func` returning its result, if at least `arity` number of arguments have
  12764. * been provided, or returns a function that accepts the remaining `func`
  12765. * arguments, and so on. The arity of `func` may be specified if `func.length`
  12766. * is not sufficient.
  12767. *
  12768. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  12769. * may be used as a placeholder for provided arguments.
  12770. *
  12771. * **Note:** This method doesn't set the "length" property of curried functions.
  12772. *
  12773. * @static
  12774. * @memberOf _
  12775. * @since 2.0.0
  12776. * @category Function
  12777. * @param {Function} func The function to curry.
  12778. * @param {number} [arity=func.length] The arity of `func`.
  12779. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  12780. * @returns {Function} Returns the new curried function.
  12781. * @example
  12782. *
  12783. * var abc = function(a, b, c) {
  12784. * return [a, b, c];
  12785. * };
  12786. *
  12787. * var curried = _.curry(abc);
  12788. *
  12789. * curried(1)(2)(3);
  12790. * // => [1, 2, 3]
  12791. *
  12792. * curried(1, 2)(3);
  12793. * // => [1, 2, 3]
  12794. *
  12795. * curried(1, 2, 3);
  12796. * // => [1, 2, 3]
  12797. *
  12798. * // Curried with placeholders.
  12799. * curried(1)(_, 3)(2);
  12800. * // => [1, 2, 3]
  12801. */
  12802. function curry(func, arity, guard) {
  12803. arity = guard ? undefined : arity;
  12804. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  12805. result.placeholder = curry.placeholder;
  12806. return result;
  12807. }
  12808. /**
  12809. * This method is like `_.curry` except that arguments are applied to `func`
  12810. * in the manner of `_.partialRight` instead of `_.partial`.
  12811. *
  12812. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  12813. * builds, may be used as a placeholder for provided arguments.
  12814. *
  12815. * **Note:** This method doesn't set the "length" property of curried functions.
  12816. *
  12817. * @static
  12818. * @memberOf _
  12819. * @since 3.0.0
  12820. * @category Function
  12821. * @param {Function} func The function to curry.
  12822. * @param {number} [arity=func.length] The arity of `func`.
  12823. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  12824. * @returns {Function} Returns the new curried function.
  12825. * @example
  12826. *
  12827. * var abc = function(a, b, c) {
  12828. * return [a, b, c];
  12829. * };
  12830. *
  12831. * var curried = _.curryRight(abc);
  12832. *
  12833. * curried(3)(2)(1);
  12834. * // => [1, 2, 3]
  12835. *
  12836. * curried(2, 3)(1);
  12837. * // => [1, 2, 3]
  12838. *
  12839. * curried(1, 2, 3);
  12840. * // => [1, 2, 3]
  12841. *
  12842. * // Curried with placeholders.
  12843. * curried(3)(1, _)(2);
  12844. * // => [1, 2, 3]
  12845. */
  12846. function curryRight(func, arity, guard) {
  12847. arity = guard ? undefined : arity;
  12848. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  12849. result.placeholder = curryRight.placeholder;
  12850. return result;
  12851. }
  12852. /**
  12853. * Creates a debounced function that delays invoking `func` until after `wait`
  12854. * milliseconds have elapsed since the last time the debounced function was
  12855. * invoked. The debounced function comes with a `cancel` method to cancel
  12856. * delayed `func` invocations and a `flush` method to immediately invoke them.
  12857. * Provide `options` to indicate whether `func` should be invoked on the
  12858. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  12859. * with the last arguments provided to the debounced function. Subsequent
  12860. * calls to the debounced function return the result of the last `func`
  12861. * invocation.
  12862. *
  12863. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  12864. * invoked on the trailing edge of the timeout only if the debounced function
  12865. * is invoked more than once during the `wait` timeout.
  12866. *
  12867. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  12868. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  12869. *
  12870. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  12871. * for details over the differences between `_.debounce` and `_.throttle`.
  12872. *
  12873. * @static
  12874. * @memberOf _
  12875. * @since 0.1.0
  12876. * @category Function
  12877. * @param {Function} func The function to debounce.
  12878. * @param {number} [wait=0] The number of milliseconds to delay.
  12879. * @param {Object} [options={}] The options object.
  12880. * @param {boolean} [options.leading=false]
  12881. * Specify invoking on the leading edge of the timeout.
  12882. * @param {number} [options.maxWait]
  12883. * The maximum time `func` is allowed to be delayed before it's invoked.
  12884. * @param {boolean} [options.trailing=true]
  12885. * Specify invoking on the trailing edge of the timeout.
  12886. * @returns {Function} Returns the new debounced function.
  12887. * @example
  12888. *
  12889. * // Avoid costly calculations while the window size is in flux.
  12890. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  12891. *
  12892. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  12893. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  12894. * 'leading': true,
  12895. * 'trailing': false
  12896. * }));
  12897. *
  12898. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  12899. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  12900. * var source = new EventSource('/stream');
  12901. * jQuery(source).on('message', debounced);
  12902. *
  12903. * // Cancel the trailing debounced invocation.
  12904. * jQuery(window).on('popstate', debounced.cancel);
  12905. */
  12906. function debounce(func, wait, options) {
  12907. var lastArgs,
  12908. lastThis,
  12909. maxWait,
  12910. result,
  12911. timerId,
  12912. lastCallTime,
  12913. lastInvokeTime = 0,
  12914. leading = false,
  12915. maxing = false,
  12916. trailing = true;
  12917. if (typeof func != 'function') {
  12918. throw new TypeError(FUNC_ERROR_TEXT);
  12919. }
  12920. wait = toNumber(wait) || 0;
  12921. if (isObject(options)) {
  12922. leading = !!options.leading;
  12923. maxing = 'maxWait' in options;
  12924. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  12925. trailing = 'trailing' in options ? !!options.trailing : trailing;
  12926. }
  12927. function invokeFunc(time) {
  12928. var args = lastArgs,
  12929. thisArg = lastThis;
  12930. lastArgs = lastThis = undefined;
  12931. lastInvokeTime = time;
  12932. result = func.apply(thisArg, args);
  12933. return result;
  12934. }
  12935. function leadingEdge(time) {
  12936. // Reset any `maxWait` timer.
  12937. lastInvokeTime = time;
  12938. // Start the timer for the trailing edge.
  12939. timerId = setTimeout(timerExpired, wait);
  12940. // Invoke the leading edge.
  12941. return leading ? invokeFunc(time) : result;
  12942. }
  12943. function remainingWait(time) {
  12944. var timeSinceLastCall = time - lastCallTime,
  12945. timeSinceLastInvoke = time - lastInvokeTime,
  12946. timeWaiting = wait - timeSinceLastCall;
  12947. return maxing
  12948. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  12949. : timeWaiting;
  12950. }
  12951. function shouldInvoke(time) {
  12952. var timeSinceLastCall = time - lastCallTime,
  12953. timeSinceLastInvoke = time - lastInvokeTime;
  12954. // Either this is the first call, activity has stopped and we're at the
  12955. // trailing edge, the system time has gone backwards and we're treating
  12956. // it as the trailing edge, or we've hit the `maxWait` limit.
  12957. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  12958. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  12959. }
  12960. function timerExpired() {
  12961. var time = now();
  12962. if (shouldInvoke(time)) {
  12963. return trailingEdge(time);
  12964. }
  12965. // Restart the timer.
  12966. timerId = setTimeout(timerExpired, remainingWait(time));
  12967. }
  12968. function trailingEdge(time) {
  12969. timerId = undefined;
  12970. // Only invoke if we have `lastArgs` which means `func` has been
  12971. // debounced at least once.
  12972. if (trailing && lastArgs) {
  12973. return invokeFunc(time);
  12974. }
  12975. lastArgs = lastThis = undefined;
  12976. return result;
  12977. }
  12978. function cancel() {
  12979. if (timerId !== undefined) {
  12980. clearTimeout(timerId);
  12981. }
  12982. lastInvokeTime = 0;
  12983. lastArgs = lastCallTime = lastThis = timerId = undefined;
  12984. }
  12985. function flush() {
  12986. return timerId === undefined ? result : trailingEdge(now());
  12987. }
  12988. function debounced() {
  12989. var time = now(),
  12990. isInvoking = shouldInvoke(time);
  12991. lastArgs = arguments;
  12992. lastThis = this;
  12993. lastCallTime = time;
  12994. if (isInvoking) {
  12995. if (timerId === undefined) {
  12996. return leadingEdge(lastCallTime);
  12997. }
  12998. if (maxing) {
  12999. // Handle invocations in a tight loop.
  13000. clearTimeout(timerId);
  13001. timerId = setTimeout(timerExpired, wait);
  13002. return invokeFunc(lastCallTime);
  13003. }
  13004. }
  13005. if (timerId === undefined) {
  13006. timerId = setTimeout(timerExpired, wait);
  13007. }
  13008. return result;
  13009. }
  13010. debounced.cancel = cancel;
  13011. debounced.flush = flush;
  13012. return debounced;
  13013. }
  13014. /**
  13015. * Defers invoking the `func` until the current call stack has cleared. Any
  13016. * additional arguments are provided to `func` when it's invoked.
  13017. *
  13018. * @static
  13019. * @memberOf _
  13020. * @since 0.1.0
  13021. * @category Function
  13022. * @param {Function} func The function to defer.
  13023. * @param {...*} [args] The arguments to invoke `func` with.
  13024. * @returns {number} Returns the timer id.
  13025. * @example
  13026. *
  13027. * _.defer(function(text) {
  13028. * console.log(text);
  13029. * }, 'deferred');
  13030. * // => Logs 'deferred' after one millisecond.
  13031. */
  13032. var defer = baseRest(function(func, args) {
  13033. return baseDelay(func, 1, args);
  13034. });
  13035. /**
  13036. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  13037. * provided to `func` when it's invoked.
  13038. *
  13039. * @static
  13040. * @memberOf _
  13041. * @since 0.1.0
  13042. * @category Function
  13043. * @param {Function} func The function to delay.
  13044. * @param {number} wait The number of milliseconds to delay invocation.
  13045. * @param {...*} [args] The arguments to invoke `func` with.
  13046. * @returns {number} Returns the timer id.
  13047. * @example
  13048. *
  13049. * _.delay(function(text) {
  13050. * console.log(text);
  13051. * }, 1000, 'later');
  13052. * // => Logs 'later' after one second.
  13053. */
  13054. var delay = baseRest(function(func, wait, args) {
  13055. return baseDelay(func, toNumber(wait) || 0, args);
  13056. });
  13057. /**
  13058. * Creates a function that invokes `func` with arguments reversed.
  13059. *
  13060. * @static
  13061. * @memberOf _
  13062. * @since 4.0.0
  13063. * @category Function
  13064. * @param {Function} func The function to flip arguments for.
  13065. * @returns {Function} Returns the new flipped function.
  13066. * @example
  13067. *
  13068. * var flipped = _.flip(function() {
  13069. * return _.toArray(arguments);
  13070. * });
  13071. *
  13072. * flipped('a', 'b', 'c', 'd');
  13073. * // => ['d', 'c', 'b', 'a']
  13074. */
  13075. function flip(func) {
  13076. return createWrap(func, WRAP_FLIP_FLAG);
  13077. }
  13078. /**
  13079. * Creates a function that memoizes the result of `func`. If `resolver` is
  13080. * provided, it determines the cache key for storing the result based on the
  13081. * arguments provided to the memoized function. By default, the first argument
  13082. * provided to the memoized function is used as the map cache key. The `func`
  13083. * is invoked with the `this` binding of the memoized function.
  13084. *
  13085. * **Note:** The cache is exposed as the `cache` property on the memoized
  13086. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  13087. * constructor with one whose instances implement the
  13088. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  13089. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  13090. *
  13091. * @static
  13092. * @memberOf _
  13093. * @since 0.1.0
  13094. * @category Function
  13095. * @param {Function} func The function to have its output memoized.
  13096. * @param {Function} [resolver] The function to resolve the cache key.
  13097. * @returns {Function} Returns the new memoized function.
  13098. * @example
  13099. *
  13100. * var object = { 'a': 1, 'b': 2 };
  13101. * var other = { 'c': 3, 'd': 4 };
  13102. *
  13103. * var values = _.memoize(_.values);
  13104. * values(object);
  13105. * // => [1, 2]
  13106. *
  13107. * values(other);
  13108. * // => [3, 4]
  13109. *
  13110. * object.a = 2;
  13111. * values(object);
  13112. * // => [1, 2]
  13113. *
  13114. * // Modify the result cache.
  13115. * values.cache.set(object, ['a', 'b']);
  13116. * values(object);
  13117. * // => ['a', 'b']
  13118. *
  13119. * // Replace `_.memoize.Cache`.
  13120. * _.memoize.Cache = WeakMap;
  13121. */
  13122. function memoize(func, resolver) {
  13123. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  13124. throw new TypeError(FUNC_ERROR_TEXT);
  13125. }
  13126. var memoized = function() {
  13127. var args = arguments,
  13128. key = resolver ? resolver.apply(this, args) : args[0],
  13129. cache = memoized.cache;
  13130. if (cache.has(key)) {
  13131. return cache.get(key);
  13132. }
  13133. var result = func.apply(this, args);
  13134. memoized.cache = cache.set(key, result) || cache;
  13135. return result;
  13136. };
  13137. memoized.cache = new (memoize.Cache || MapCache);
  13138. return memoized;
  13139. }
  13140. // Expose `MapCache`.
  13141. memoize.Cache = MapCache;
  13142. /**
  13143. * Creates a function that negates the result of the predicate `func`. The
  13144. * `func` predicate is invoked with the `this` binding and arguments of the
  13145. * created function.
  13146. *
  13147. * @static
  13148. * @memberOf _
  13149. * @since 3.0.0
  13150. * @category Function
  13151. * @param {Function} predicate The predicate to negate.
  13152. * @returns {Function} Returns the new negated function.
  13153. * @example
  13154. *
  13155. * function isEven(n) {
  13156. * return n % 2 == 0;
  13157. * }
  13158. *
  13159. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  13160. * // => [1, 3, 5]
  13161. */
  13162. function negate(predicate) {
  13163. if (typeof predicate != 'function') {
  13164. throw new TypeError(FUNC_ERROR_TEXT);
  13165. }
  13166. return function() {
  13167. var args = arguments;
  13168. switch (args.length) {
  13169. case 0: return !predicate.call(this);
  13170. case 1: return !predicate.call(this, args[0]);
  13171. case 2: return !predicate.call(this, args[0], args[1]);
  13172. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  13173. }
  13174. return !predicate.apply(this, args);
  13175. };
  13176. }
  13177. /**
  13178. * Creates a function that is restricted to invoking `func` once. Repeat calls
  13179. * to the function return the value of the first invocation. The `func` is
  13180. * invoked with the `this` binding and arguments of the created function.
  13181. *
  13182. * @static
  13183. * @memberOf _
  13184. * @since 0.1.0
  13185. * @category Function
  13186. * @param {Function} func The function to restrict.
  13187. * @returns {Function} Returns the new restricted function.
  13188. * @example
  13189. *
  13190. * var initialize = _.once(createApplication);
  13191. * initialize();
  13192. * initialize();
  13193. * // => `createApplication` is invoked once
  13194. */
  13195. function once(func) {
  13196. return before(2, func);
  13197. }
  13198. /**
  13199. * Creates a function that invokes `func` with its arguments transformed.
  13200. *
  13201. * @static
  13202. * @since 4.0.0
  13203. * @memberOf _
  13204. * @category Function
  13205. * @param {Function} func The function to wrap.
  13206. * @param {...(Function|Function[])} [transforms=[_.identity]]
  13207. * The argument transforms.
  13208. * @returns {Function} Returns the new function.
  13209. * @example
  13210. *
  13211. * function doubled(n) {
  13212. * return n * 2;
  13213. * }
  13214. *
  13215. * function square(n) {
  13216. * return n * n;
  13217. * }
  13218. *
  13219. * var func = _.overArgs(function(x, y) {
  13220. * return [x, y];
  13221. * }, [square, doubled]);
  13222. *
  13223. * func(9, 3);
  13224. * // => [81, 6]
  13225. *
  13226. * func(10, 5);
  13227. * // => [100, 10]
  13228. */
  13229. var overArgs = castRest(function(func, transforms) {
  13230. transforms = (transforms.length == 1 && isArray(transforms[0]))
  13231. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  13232. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  13233. var funcsLength = transforms.length;
  13234. return baseRest(function(args) {
  13235. var index = -1,
  13236. length = nativeMin(args.length, funcsLength);
  13237. while (++index < length) {
  13238. args[index] = transforms[index].call(this, args[index]);
  13239. }
  13240. return apply(func, this, args);
  13241. });
  13242. });
  13243. /**
  13244. * Creates a function that invokes `func` with `partials` prepended to the
  13245. * arguments it receives. This method is like `_.bind` except it does **not**
  13246. * alter the `this` binding.
  13247. *
  13248. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  13249. * builds, may be used as a placeholder for partially applied arguments.
  13250. *
  13251. * **Note:** This method doesn't set the "length" property of partially
  13252. * applied functions.
  13253. *
  13254. * @static
  13255. * @memberOf _
  13256. * @since 0.2.0
  13257. * @category Function
  13258. * @param {Function} func The function to partially apply arguments to.
  13259. * @param {...*} [partials] The arguments to be partially applied.
  13260. * @returns {Function} Returns the new partially applied function.
  13261. * @example
  13262. *
  13263. * function greet(greeting, name) {
  13264. * return greeting + ' ' + name;
  13265. * }
  13266. *
  13267. * var sayHelloTo = _.partial(greet, 'hello');
  13268. * sayHelloTo('fred');
  13269. * // => 'hello fred'
  13270. *
  13271. * // Partially applied with placeholders.
  13272. * var greetFred = _.partial(greet, _, 'fred');
  13273. * greetFred('hi');
  13274. * // => 'hi fred'
  13275. */
  13276. var partial = baseRest(function(func, partials) {
  13277. var holders = replaceHolders(partials, getHolder(partial));
  13278. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  13279. });
  13280. /**
  13281. * This method is like `_.partial` except that partially applied arguments
  13282. * are appended to the arguments it receives.
  13283. *
  13284. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  13285. * builds, may be used as a placeholder for partially applied arguments.
  13286. *
  13287. * **Note:** This method doesn't set the "length" property of partially
  13288. * applied functions.
  13289. *
  13290. * @static
  13291. * @memberOf _
  13292. * @since 1.0.0
  13293. * @category Function
  13294. * @param {Function} func The function to partially apply arguments to.
  13295. * @param {...*} [partials] The arguments to be partially applied.
  13296. * @returns {Function} Returns the new partially applied function.
  13297. * @example
  13298. *
  13299. * function greet(greeting, name) {
  13300. * return greeting + ' ' + name;
  13301. * }
  13302. *
  13303. * var greetFred = _.partialRight(greet, 'fred');
  13304. * greetFred('hi');
  13305. * // => 'hi fred'
  13306. *
  13307. * // Partially applied with placeholders.
  13308. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  13309. * sayHelloTo('fred');
  13310. * // => 'hello fred'
  13311. */
  13312. var partialRight = baseRest(function(func, partials) {
  13313. var holders = replaceHolders(partials, getHolder(partialRight));
  13314. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  13315. });
  13316. /**
  13317. * Creates a function that invokes `func` with arguments arranged according
  13318. * to the specified `indexes` where the argument value at the first index is
  13319. * provided as the first argument, the argument value at the second index is
  13320. * provided as the second argument, and so on.
  13321. *
  13322. * @static
  13323. * @memberOf _
  13324. * @since 3.0.0
  13325. * @category Function
  13326. * @param {Function} func The function to rearrange arguments for.
  13327. * @param {...(number|number[])} indexes The arranged argument indexes.
  13328. * @returns {Function} Returns the new function.
  13329. * @example
  13330. *
  13331. * var rearged = _.rearg(function(a, b, c) {
  13332. * return [a, b, c];
  13333. * }, [2, 0, 1]);
  13334. *
  13335. * rearged('b', 'c', 'a')
  13336. * // => ['a', 'b', 'c']
  13337. */
  13338. var rearg = flatRest(function(func, indexes) {
  13339. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  13340. });
  13341. /**
  13342. * Creates a function that invokes `func` with the `this` binding of the
  13343. * created function and arguments from `start` and beyond provided as
  13344. * an array.
  13345. *
  13346. * **Note:** This method is based on the
  13347. * [rest parameter](https://mdn.io/rest_parameters).
  13348. *
  13349. * @static
  13350. * @memberOf _
  13351. * @since 4.0.0
  13352. * @category Function
  13353. * @param {Function} func The function to apply a rest parameter to.
  13354. * @param {number} [start=func.length-1] The start position of the rest parameter.
  13355. * @returns {Function} Returns the new function.
  13356. * @example
  13357. *
  13358. * var say = _.rest(function(what, names) {
  13359. * return what + ' ' + _.initial(names).join(', ') +
  13360. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  13361. * });
  13362. *
  13363. * say('hello', 'fred', 'barney', 'pebbles');
  13364. * // => 'hello fred, barney, & pebbles'
  13365. */
  13366. function rest(func, start) {
  13367. if (typeof func != 'function') {
  13368. throw new TypeError(FUNC_ERROR_TEXT);
  13369. }
  13370. start = start === undefined ? start : toInteger(start);
  13371. return baseRest(func, start);
  13372. }
  13373. /**
  13374. * Creates a function that invokes `func` with the `this` binding of the
  13375. * create function and an array of arguments much like
  13376. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  13377. *
  13378. * **Note:** This method is based on the
  13379. * [spread operator](https://mdn.io/spread_operator).
  13380. *
  13381. * @static
  13382. * @memberOf _
  13383. * @since 3.2.0
  13384. * @category Function
  13385. * @param {Function} func The function to spread arguments over.
  13386. * @param {number} [start=0] The start position of the spread.
  13387. * @returns {Function} Returns the new function.
  13388. * @example
  13389. *
  13390. * var say = _.spread(function(who, what) {
  13391. * return who + ' says ' + what;
  13392. * });
  13393. *
  13394. * say(['fred', 'hello']);
  13395. * // => 'fred says hello'
  13396. *
  13397. * var numbers = Promise.all([
  13398. * Promise.resolve(40),
  13399. * Promise.resolve(36)
  13400. * ]);
  13401. *
  13402. * numbers.then(_.spread(function(x, y) {
  13403. * return x + y;
  13404. * }));
  13405. * // => a Promise of 76
  13406. */
  13407. function spread(func, start) {
  13408. if (typeof func != 'function') {
  13409. throw new TypeError(FUNC_ERROR_TEXT);
  13410. }
  13411. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  13412. return baseRest(function(args) {
  13413. var array = args[start],
  13414. otherArgs = castSlice(args, 0, start);
  13415. if (array) {
  13416. arrayPush(otherArgs, array);
  13417. }
  13418. return apply(func, this, otherArgs);
  13419. });
  13420. }
  13421. /**
  13422. * Creates a throttled function that only invokes `func` at most once per
  13423. * every `wait` milliseconds. The throttled function comes with a `cancel`
  13424. * method to cancel delayed `func` invocations and a `flush` method to
  13425. * immediately invoke them. Provide `options` to indicate whether `func`
  13426. * should be invoked on the leading and/or trailing edge of the `wait`
  13427. * timeout. The `func` is invoked with the last arguments provided to the
  13428. * throttled function. Subsequent calls to the throttled function return the
  13429. * result of the last `func` invocation.
  13430. *
  13431. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  13432. * invoked on the trailing edge of the timeout only if the throttled function
  13433. * is invoked more than once during the `wait` timeout.
  13434. *
  13435. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  13436. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  13437. *
  13438. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  13439. * for details over the differences between `_.throttle` and `_.debounce`.
  13440. *
  13441. * @static
  13442. * @memberOf _
  13443. * @since 0.1.0
  13444. * @category Function
  13445. * @param {Function} func The function to throttle.
  13446. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  13447. * @param {Object} [options={}] The options object.
  13448. * @param {boolean} [options.leading=true]
  13449. * Specify invoking on the leading edge of the timeout.
  13450. * @param {boolean} [options.trailing=true]
  13451. * Specify invoking on the trailing edge of the timeout.
  13452. * @returns {Function} Returns the new throttled function.
  13453. * @example
  13454. *
  13455. * // Avoid excessively updating the position while scrolling.
  13456. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  13457. *
  13458. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  13459. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  13460. * jQuery(element).on('click', throttled);
  13461. *
  13462. * // Cancel the trailing throttled invocation.
  13463. * jQuery(window).on('popstate', throttled.cancel);
  13464. */
  13465. function throttle(func, wait, options) {
  13466. var leading = true,
  13467. trailing = true;
  13468. if (typeof func != 'function') {
  13469. throw new TypeError(FUNC_ERROR_TEXT);
  13470. }
  13471. if (isObject(options)) {
  13472. leading = 'leading' in options ? !!options.leading : leading;
  13473. trailing = 'trailing' in options ? !!options.trailing : trailing;
  13474. }
  13475. return debounce(func, wait, {
  13476. 'leading': leading,
  13477. 'maxWait': wait,
  13478. 'trailing': trailing
  13479. });
  13480. }
  13481. /**
  13482. * Creates a function that accepts up to one argument, ignoring any
  13483. * additional arguments.
  13484. *
  13485. * @static
  13486. * @memberOf _
  13487. * @since 4.0.0
  13488. * @category Function
  13489. * @param {Function} func The function to cap arguments for.
  13490. * @returns {Function} Returns the new capped function.
  13491. * @example
  13492. *
  13493. * _.map(['6', '8', '10'], _.unary(parseInt));
  13494. * // => [6, 8, 10]
  13495. */
  13496. function unary(func) {
  13497. return ary(func, 1);
  13498. }
  13499. /**
  13500. * Creates a function that provides `value` to `wrapper` as its first
  13501. * argument. Any additional arguments provided to the function are appended
  13502. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  13503. * binding of the created function.
  13504. *
  13505. * @static
  13506. * @memberOf _
  13507. * @since 0.1.0
  13508. * @category Function
  13509. * @param {*} value The value to wrap.
  13510. * @param {Function} [wrapper=identity] The wrapper function.
  13511. * @returns {Function} Returns the new function.
  13512. * @example
  13513. *
  13514. * var p = _.wrap(_.escape, function(func, text) {
  13515. * return '<p>' + func(text) + '</p>';
  13516. * });
  13517. *
  13518. * p('fred, barney, & pebbles');
  13519. * // => '<p>fred, barney, &amp; pebbles</p>'
  13520. */
  13521. function wrap(value, wrapper) {
  13522. return partial(castFunction(wrapper), value);
  13523. }
  13524. /*------------------------------------------------------------------------*/
  13525. /**
  13526. * Casts `value` as an array if it's not one.
  13527. *
  13528. * @static
  13529. * @memberOf _
  13530. * @since 4.4.0
  13531. * @category Lang
  13532. * @param {*} value The value to inspect.
  13533. * @returns {Array} Returns the cast array.
  13534. * @example
  13535. *
  13536. * _.castArray(1);
  13537. * // => [1]
  13538. *
  13539. * _.castArray({ 'a': 1 });
  13540. * // => [{ 'a': 1 }]
  13541. *
  13542. * _.castArray('abc');
  13543. * // => ['abc']
  13544. *
  13545. * _.castArray(null);
  13546. * // => [null]
  13547. *
  13548. * _.castArray(undefined);
  13549. * // => [undefined]
  13550. *
  13551. * _.castArray();
  13552. * // => []
  13553. *
  13554. * var array = [1, 2, 3];
  13555. * console.log(_.castArray(array) === array);
  13556. * // => true
  13557. */
  13558. function castArray() {
  13559. if (!arguments.length) {
  13560. return [];
  13561. }
  13562. var value = arguments[0];
  13563. return isArray(value) ? value : [value];
  13564. }
  13565. /**
  13566. * Creates a shallow clone of `value`.
  13567. *
  13568. * **Note:** This method is loosely based on the
  13569. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  13570. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  13571. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  13572. * arrays. The own enumerable properties of `arguments` objects are cloned
  13573. * as plain objects. An empty object is returned for uncloneable values such
  13574. * as error objects, functions, DOM nodes, and WeakMaps.
  13575. *
  13576. * @static
  13577. * @memberOf _
  13578. * @since 0.1.0
  13579. * @category Lang
  13580. * @param {*} value The value to clone.
  13581. * @returns {*} Returns the cloned value.
  13582. * @see _.cloneDeep
  13583. * @example
  13584. *
  13585. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  13586. *
  13587. * var shallow = _.clone(objects);
  13588. * console.log(shallow[0] === objects[0]);
  13589. * // => true
  13590. */
  13591. function clone(value) {
  13592. return baseClone(value, CLONE_SYMBOLS_FLAG);
  13593. }
  13594. /**
  13595. * This method is like `_.clone` except that it accepts `customizer` which
  13596. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  13597. * cloning is handled by the method instead. The `customizer` is invoked with
  13598. * up to four arguments; (value [, index|key, object, stack]).
  13599. *
  13600. * @static
  13601. * @memberOf _
  13602. * @since 4.0.0
  13603. * @category Lang
  13604. * @param {*} value The value to clone.
  13605. * @param {Function} [customizer] The function to customize cloning.
  13606. * @returns {*} Returns the cloned value.
  13607. * @see _.cloneDeepWith
  13608. * @example
  13609. *
  13610. * function customizer(value) {
  13611. * if (_.isElement(value)) {
  13612. * return value.cloneNode(false);
  13613. * }
  13614. * }
  13615. *
  13616. * var el = _.cloneWith(document.body, customizer);
  13617. *
  13618. * console.log(el === document.body);
  13619. * // => false
  13620. * console.log(el.nodeName);
  13621. * // => 'BODY'
  13622. * console.log(el.childNodes.length);
  13623. * // => 0
  13624. */
  13625. function cloneWith(value, customizer) {
  13626. customizer = typeof customizer == 'function' ? customizer : undefined;
  13627. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  13628. }
  13629. /**
  13630. * This method is like `_.clone` except that it recursively clones `value`.
  13631. *
  13632. * @static
  13633. * @memberOf _
  13634. * @since 1.0.0
  13635. * @category Lang
  13636. * @param {*} value The value to recursively clone.
  13637. * @returns {*} Returns the deep cloned value.
  13638. * @see _.clone
  13639. * @example
  13640. *
  13641. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  13642. *
  13643. * var deep = _.cloneDeep(objects);
  13644. * console.log(deep[0] === objects[0]);
  13645. * // => false
  13646. */
  13647. function cloneDeep(value) {
  13648. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  13649. }
  13650. /**
  13651. * This method is like `_.cloneWith` except that it recursively clones `value`.
  13652. *
  13653. * @static
  13654. * @memberOf _
  13655. * @since 4.0.0
  13656. * @category Lang
  13657. * @param {*} value The value to recursively clone.
  13658. * @param {Function} [customizer] The function to customize cloning.
  13659. * @returns {*} Returns the deep cloned value.
  13660. * @see _.cloneWith
  13661. * @example
  13662. *
  13663. * function customizer(value) {
  13664. * if (_.isElement(value)) {
  13665. * return value.cloneNode(true);
  13666. * }
  13667. * }
  13668. *
  13669. * var el = _.cloneDeepWith(document.body, customizer);
  13670. *
  13671. * console.log(el === document.body);
  13672. * // => false
  13673. * console.log(el.nodeName);
  13674. * // => 'BODY'
  13675. * console.log(el.childNodes.length);
  13676. * // => 20
  13677. */
  13678. function cloneDeepWith(value, customizer) {
  13679. customizer = typeof customizer == 'function' ? customizer : undefined;
  13680. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  13681. }
  13682. /**
  13683. * Checks if `object` conforms to `source` by invoking the predicate
  13684. * properties of `source` with the corresponding property values of `object`.
  13685. *
  13686. * **Note:** This method is equivalent to `_.conforms` when `source` is
  13687. * partially applied.
  13688. *
  13689. * @static
  13690. * @memberOf _
  13691. * @since 4.14.0
  13692. * @category Lang
  13693. * @param {Object} object The object to inspect.
  13694. * @param {Object} source The object of property predicates to conform to.
  13695. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  13696. * @example
  13697. *
  13698. * var object = { 'a': 1, 'b': 2 };
  13699. *
  13700. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  13701. * // => true
  13702. *
  13703. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  13704. * // => false
  13705. */
  13706. function conformsTo(object, source) {
  13707. return source == null || baseConformsTo(object, source, keys(source));
  13708. }
  13709. /**
  13710. * Performs a
  13711. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  13712. * comparison between two values to determine if they are equivalent.
  13713. *
  13714. * @static
  13715. * @memberOf _
  13716. * @since 4.0.0
  13717. * @category Lang
  13718. * @param {*} value The value to compare.
  13719. * @param {*} other The other value to compare.
  13720. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  13721. * @example
  13722. *
  13723. * var object = { 'a': 1 };
  13724. * var other = { 'a': 1 };
  13725. *
  13726. * _.eq(object, object);
  13727. * // => true
  13728. *
  13729. * _.eq(object, other);
  13730. * // => false
  13731. *
  13732. * _.eq('a', 'a');
  13733. * // => true
  13734. *
  13735. * _.eq('a', Object('a'));
  13736. * // => false
  13737. *
  13738. * _.eq(NaN, NaN);
  13739. * // => true
  13740. */
  13741. function eq(value, other) {
  13742. return value === other || (value !== value && other !== other);
  13743. }
  13744. /**
  13745. * Checks if `value` is greater than `other`.
  13746. *
  13747. * @static
  13748. * @memberOf _
  13749. * @since 3.9.0
  13750. * @category Lang
  13751. * @param {*} value The value to compare.
  13752. * @param {*} other The other value to compare.
  13753. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  13754. * else `false`.
  13755. * @see _.lt
  13756. * @example
  13757. *
  13758. * _.gt(3, 1);
  13759. * // => true
  13760. *
  13761. * _.gt(3, 3);
  13762. * // => false
  13763. *
  13764. * _.gt(1, 3);
  13765. * // => false
  13766. */
  13767. var gt = createRelationalOperation(baseGt);
  13768. /**
  13769. * Checks if `value` is greater than or equal to `other`.
  13770. *
  13771. * @static
  13772. * @memberOf _
  13773. * @since 3.9.0
  13774. * @category Lang
  13775. * @param {*} value The value to compare.
  13776. * @param {*} other The other value to compare.
  13777. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  13778. * `other`, else `false`.
  13779. * @see _.lte
  13780. * @example
  13781. *
  13782. * _.gte(3, 1);
  13783. * // => true
  13784. *
  13785. * _.gte(3, 3);
  13786. * // => true
  13787. *
  13788. * _.gte(1, 3);
  13789. * // => false
  13790. */
  13791. var gte = createRelationalOperation(function(value, other) {
  13792. return value >= other;
  13793. });
  13794. /**
  13795. * Checks if `value` is likely an `arguments` object.
  13796. *
  13797. * @static
  13798. * @memberOf _
  13799. * @since 0.1.0
  13800. * @category Lang
  13801. * @param {*} value The value to check.
  13802. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  13803. * else `false`.
  13804. * @example
  13805. *
  13806. * _.isArguments(function() { return arguments; }());
  13807. * // => true
  13808. *
  13809. * _.isArguments([1, 2, 3]);
  13810. * // => false
  13811. */
  13812. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  13813. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  13814. !propertyIsEnumerable.call(value, 'callee');
  13815. };
  13816. /**
  13817. * Checks if `value` is classified as an `Array` object.
  13818. *
  13819. * @static
  13820. * @memberOf _
  13821. * @since 0.1.0
  13822. * @category Lang
  13823. * @param {*} value The value to check.
  13824. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  13825. * @example
  13826. *
  13827. * _.isArray([1, 2, 3]);
  13828. * // => true
  13829. *
  13830. * _.isArray(document.body.children);
  13831. * // => false
  13832. *
  13833. * _.isArray('abc');
  13834. * // => false
  13835. *
  13836. * _.isArray(_.noop);
  13837. * // => false
  13838. */
  13839. var isArray = Array.isArray;
  13840. /**
  13841. * Checks if `value` is classified as an `ArrayBuffer` object.
  13842. *
  13843. * @static
  13844. * @memberOf _
  13845. * @since 4.3.0
  13846. * @category Lang
  13847. * @param {*} value The value to check.
  13848. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  13849. * @example
  13850. *
  13851. * _.isArrayBuffer(new ArrayBuffer(2));
  13852. * // => true
  13853. *
  13854. * _.isArrayBuffer(new Array(2));
  13855. * // => false
  13856. */
  13857. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  13858. /**
  13859. * Checks if `value` is array-like. A value is considered array-like if it's
  13860. * not a function and has a `value.length` that's an integer greater than or
  13861. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  13862. *
  13863. * @static
  13864. * @memberOf _
  13865. * @since 4.0.0
  13866. * @category Lang
  13867. * @param {*} value The value to check.
  13868. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  13869. * @example
  13870. *
  13871. * _.isArrayLike([1, 2, 3]);
  13872. * // => true
  13873. *
  13874. * _.isArrayLike(document.body.children);
  13875. * // => true
  13876. *
  13877. * _.isArrayLike('abc');
  13878. * // => true
  13879. *
  13880. * _.isArrayLike(_.noop);
  13881. * // => false
  13882. */
  13883. function isArrayLike(value) {
  13884. return value != null && isLength(value.length) && !isFunction(value);
  13885. }
  13886. /**
  13887. * This method is like `_.isArrayLike` except that it also checks if `value`
  13888. * is an object.
  13889. *
  13890. * @static
  13891. * @memberOf _
  13892. * @since 4.0.0
  13893. * @category Lang
  13894. * @param {*} value The value to check.
  13895. * @returns {boolean} Returns `true` if `value` is an array-like object,
  13896. * else `false`.
  13897. * @example
  13898. *
  13899. * _.isArrayLikeObject([1, 2, 3]);
  13900. * // => true
  13901. *
  13902. * _.isArrayLikeObject(document.body.children);
  13903. * // => true
  13904. *
  13905. * _.isArrayLikeObject('abc');
  13906. * // => false
  13907. *
  13908. * _.isArrayLikeObject(_.noop);
  13909. * // => false
  13910. */
  13911. function isArrayLikeObject(value) {
  13912. return isObjectLike(value) && isArrayLike(value);
  13913. }
  13914. /**
  13915. * Checks if `value` is classified as a boolean primitive or object.
  13916. *
  13917. * @static
  13918. * @memberOf _
  13919. * @since 0.1.0
  13920. * @category Lang
  13921. * @param {*} value The value to check.
  13922. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  13923. * @example
  13924. *
  13925. * _.isBoolean(false);
  13926. * // => true
  13927. *
  13928. * _.isBoolean(null);
  13929. * // => false
  13930. */
  13931. function isBoolean(value) {
  13932. return value === true || value === false ||
  13933. (isObjectLike(value) && baseGetTag(value) == boolTag);
  13934. }
  13935. /**
  13936. * Checks if `value` is a buffer.
  13937. *
  13938. * @static
  13939. * @memberOf _
  13940. * @since 4.3.0
  13941. * @category Lang
  13942. * @param {*} value The value to check.
  13943. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  13944. * @example
  13945. *
  13946. * _.isBuffer(new Buffer(2));
  13947. * // => true
  13948. *
  13949. * _.isBuffer(new Uint8Array(2));
  13950. * // => false
  13951. */
  13952. var isBuffer = nativeIsBuffer || stubFalse;
  13953. /**
  13954. * Checks if `value` is classified as a `Date` object.
  13955. *
  13956. * @static
  13957. * @memberOf _
  13958. * @since 0.1.0
  13959. * @category Lang
  13960. * @param {*} value The value to check.
  13961. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  13962. * @example
  13963. *
  13964. * _.isDate(new Date);
  13965. * // => true
  13966. *
  13967. * _.isDate('Mon April 23 2012');
  13968. * // => false
  13969. */
  13970. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  13971. /**
  13972. * Checks if `value` is likely a DOM element.
  13973. *
  13974. * @static
  13975. * @memberOf _
  13976. * @since 0.1.0
  13977. * @category Lang
  13978. * @param {*} value The value to check.
  13979. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  13980. * @example
  13981. *
  13982. * _.isElement(document.body);
  13983. * // => true
  13984. *
  13985. * _.isElement('<body>');
  13986. * // => false
  13987. */
  13988. function isElement(value) {
  13989. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  13990. }
  13991. /**
  13992. * Checks if `value` is an empty object, collection, map, or set.
  13993. *
  13994. * Objects are considered empty if they have no own enumerable string keyed
  13995. * properties.
  13996. *
  13997. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  13998. * jQuery-like collections are considered empty if they have a `length` of `0`.
  13999. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  14000. *
  14001. * @static
  14002. * @memberOf _
  14003. * @since 0.1.0
  14004. * @category Lang
  14005. * @param {*} value The value to check.
  14006. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  14007. * @example
  14008. *
  14009. * _.isEmpty(null);
  14010. * // => true
  14011. *
  14012. * _.isEmpty(true);
  14013. * // => true
  14014. *
  14015. * _.isEmpty(1);
  14016. * // => true
  14017. *
  14018. * _.isEmpty([1, 2, 3]);
  14019. * // => false
  14020. *
  14021. * _.isEmpty({ 'a': 1 });
  14022. * // => false
  14023. */
  14024. function isEmpty(value) {
  14025. if (value == null) {
  14026. return true;
  14027. }
  14028. if (isArrayLike(value) &&
  14029. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  14030. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  14031. return !value.length;
  14032. }
  14033. var tag = getTag(value);
  14034. if (tag == mapTag || tag == setTag) {
  14035. return !value.size;
  14036. }
  14037. if (isPrototype(value)) {
  14038. return !baseKeys(value).length;
  14039. }
  14040. for (var key in value) {
  14041. if (hasOwnProperty.call(value, key)) {
  14042. return false;
  14043. }
  14044. }
  14045. return true;
  14046. }
  14047. /**
  14048. * Performs a deep comparison between two values to determine if they are
  14049. * equivalent.
  14050. *
  14051. * **Note:** This method supports comparing arrays, array buffers, booleans,
  14052. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  14053. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  14054. * by their own, not inherited, enumerable properties. Functions and DOM
  14055. * nodes are compared by strict equality, i.e. `===`.
  14056. *
  14057. * @static
  14058. * @memberOf _
  14059. * @since 0.1.0
  14060. * @category Lang
  14061. * @param {*} value The value to compare.
  14062. * @param {*} other The other value to compare.
  14063. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  14064. * @example
  14065. *
  14066. * var object = { 'a': 1 };
  14067. * var other = { 'a': 1 };
  14068. *
  14069. * _.isEqual(object, other);
  14070. * // => true
  14071. *
  14072. * object === other;
  14073. * // => false
  14074. */
  14075. function isEqual(value, other) {
  14076. return baseIsEqual(value, other);
  14077. }
  14078. /**
  14079. * This method is like `_.isEqual` except that it accepts `customizer` which
  14080. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  14081. * are handled by the method instead. The `customizer` is invoked with up to
  14082. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  14083. *
  14084. * @static
  14085. * @memberOf _
  14086. * @since 4.0.0
  14087. * @category Lang
  14088. * @param {*} value The value to compare.
  14089. * @param {*} other The other value to compare.
  14090. * @param {Function} [customizer] The function to customize comparisons.
  14091. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  14092. * @example
  14093. *
  14094. * function isGreeting(value) {
  14095. * return /^h(?:i|ello)$/.test(value);
  14096. * }
  14097. *
  14098. * function customizer(objValue, othValue) {
  14099. * if (isGreeting(objValue) && isGreeting(othValue)) {
  14100. * return true;
  14101. * }
  14102. * }
  14103. *
  14104. * var array = ['hello', 'goodbye'];
  14105. * var other = ['hi', 'goodbye'];
  14106. *
  14107. * _.isEqualWith(array, other, customizer);
  14108. * // => true
  14109. */
  14110. function isEqualWith(value, other, customizer) {
  14111. customizer = typeof customizer == 'function' ? customizer : undefined;
  14112. var result = customizer ? customizer(value, other) : undefined;
  14113. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  14114. }
  14115. /**
  14116. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  14117. * `SyntaxError`, `TypeError`, or `URIError` object.
  14118. *
  14119. * @static
  14120. * @memberOf _
  14121. * @since 3.0.0
  14122. * @category Lang
  14123. * @param {*} value The value to check.
  14124. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  14125. * @example
  14126. *
  14127. * _.isError(new Error);
  14128. * // => true
  14129. *
  14130. * _.isError(Error);
  14131. * // => false
  14132. */
  14133. function isError(value) {
  14134. if (!isObjectLike(value)) {
  14135. return false;
  14136. }
  14137. var tag = baseGetTag(value);
  14138. return tag == errorTag || tag == domExcTag ||
  14139. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  14140. }
  14141. /**
  14142. * Checks if `value` is a finite primitive number.
  14143. *
  14144. * **Note:** This method is based on
  14145. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  14146. *
  14147. * @static
  14148. * @memberOf _
  14149. * @since 0.1.0
  14150. * @category Lang
  14151. * @param {*} value The value to check.
  14152. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  14153. * @example
  14154. *
  14155. * _.isFinite(3);
  14156. * // => true
  14157. *
  14158. * _.isFinite(Number.MIN_VALUE);
  14159. * // => true
  14160. *
  14161. * _.isFinite(Infinity);
  14162. * // => false
  14163. *
  14164. * _.isFinite('3');
  14165. * // => false
  14166. */
  14167. function isFinite(value) {
  14168. return typeof value == 'number' && nativeIsFinite(value);
  14169. }
  14170. /**
  14171. * Checks if `value` is classified as a `Function` object.
  14172. *
  14173. * @static
  14174. * @memberOf _
  14175. * @since 0.1.0
  14176. * @category Lang
  14177. * @param {*} value The value to check.
  14178. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  14179. * @example
  14180. *
  14181. * _.isFunction(_);
  14182. * // => true
  14183. *
  14184. * _.isFunction(/abc/);
  14185. * // => false
  14186. */
  14187. function isFunction(value) {
  14188. if (!isObject(value)) {
  14189. return false;
  14190. }
  14191. // The use of `Object#toString` avoids issues with the `typeof` operator
  14192. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  14193. var tag = baseGetTag(value);
  14194. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  14195. }
  14196. /**
  14197. * Checks if `value` is an integer.
  14198. *
  14199. * **Note:** This method is based on
  14200. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  14201. *
  14202. * @static
  14203. * @memberOf _
  14204. * @since 4.0.0
  14205. * @category Lang
  14206. * @param {*} value The value to check.
  14207. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  14208. * @example
  14209. *
  14210. * _.isInteger(3);
  14211. * // => true
  14212. *
  14213. * _.isInteger(Number.MIN_VALUE);
  14214. * // => false
  14215. *
  14216. * _.isInteger(Infinity);
  14217. * // => false
  14218. *
  14219. * _.isInteger('3');
  14220. * // => false
  14221. */
  14222. function isInteger(value) {
  14223. return typeof value == 'number' && value == toInteger(value);
  14224. }
  14225. /**
  14226. * Checks if `value` is a valid array-like length.
  14227. *
  14228. * **Note:** This method is loosely based on
  14229. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  14230. *
  14231. * @static
  14232. * @memberOf _
  14233. * @since 4.0.0
  14234. * @category Lang
  14235. * @param {*} value The value to check.
  14236. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  14237. * @example
  14238. *
  14239. * _.isLength(3);
  14240. * // => true
  14241. *
  14242. * _.isLength(Number.MIN_VALUE);
  14243. * // => false
  14244. *
  14245. * _.isLength(Infinity);
  14246. * // => false
  14247. *
  14248. * _.isLength('3');
  14249. * // => false
  14250. */
  14251. function isLength(value) {
  14252. return typeof value == 'number' &&
  14253. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  14254. }
  14255. /**
  14256. * Checks if `value` is the
  14257. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  14258. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  14259. *
  14260. * @static
  14261. * @memberOf _
  14262. * @since 0.1.0
  14263. * @category Lang
  14264. * @param {*} value The value to check.
  14265. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  14266. * @example
  14267. *
  14268. * _.isObject({});
  14269. * // => true
  14270. *
  14271. * _.isObject([1, 2, 3]);
  14272. * // => true
  14273. *
  14274. * _.isObject(_.noop);
  14275. * // => true
  14276. *
  14277. * _.isObject(null);
  14278. * // => false
  14279. */
  14280. function isObject(value) {
  14281. var type = typeof value;
  14282. return value != null && (type == 'object' || type == 'function');
  14283. }
  14284. /**
  14285. * Checks if `value` is object-like. A value is object-like if it's not `null`
  14286. * and has a `typeof` result of "object".
  14287. *
  14288. * @static
  14289. * @memberOf _
  14290. * @since 4.0.0
  14291. * @category Lang
  14292. * @param {*} value The value to check.
  14293. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  14294. * @example
  14295. *
  14296. * _.isObjectLike({});
  14297. * // => true
  14298. *
  14299. * _.isObjectLike([1, 2, 3]);
  14300. * // => true
  14301. *
  14302. * _.isObjectLike(_.noop);
  14303. * // => false
  14304. *
  14305. * _.isObjectLike(null);
  14306. * // => false
  14307. */
  14308. function isObjectLike(value) {
  14309. return value != null && typeof value == 'object';
  14310. }
  14311. /**
  14312. * Checks if `value` is classified as a `Map` object.
  14313. *
  14314. * @static
  14315. * @memberOf _
  14316. * @since 4.3.0
  14317. * @category Lang
  14318. * @param {*} value The value to check.
  14319. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  14320. * @example
  14321. *
  14322. * _.isMap(new Map);
  14323. * // => true
  14324. *
  14325. * _.isMap(new WeakMap);
  14326. * // => false
  14327. */
  14328. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  14329. /**
  14330. * Performs a partial deep comparison between `object` and `source` to
  14331. * determine if `object` contains equivalent property values.
  14332. *
  14333. * **Note:** This method is equivalent to `_.matches` when `source` is
  14334. * partially applied.
  14335. *
  14336. * Partial comparisons will match empty array and empty object `source`
  14337. * values against any array or object value, respectively. See `_.isEqual`
  14338. * for a list of supported value comparisons.
  14339. *
  14340. * @static
  14341. * @memberOf _
  14342. * @since 3.0.0
  14343. * @category Lang
  14344. * @param {Object} object The object to inspect.
  14345. * @param {Object} source The object of property values to match.
  14346. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  14347. * @example
  14348. *
  14349. * var object = { 'a': 1, 'b': 2 };
  14350. *
  14351. * _.isMatch(object, { 'b': 2 });
  14352. * // => true
  14353. *
  14354. * _.isMatch(object, { 'b': 1 });
  14355. * // => false
  14356. */
  14357. function isMatch(object, source) {
  14358. return object === source || baseIsMatch(object, source, getMatchData(source));
  14359. }
  14360. /**
  14361. * This method is like `_.isMatch` except that it accepts `customizer` which
  14362. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  14363. * are handled by the method instead. The `customizer` is invoked with five
  14364. * arguments: (objValue, srcValue, index|key, object, source).
  14365. *
  14366. * @static
  14367. * @memberOf _
  14368. * @since 4.0.0
  14369. * @category Lang
  14370. * @param {Object} object The object to inspect.
  14371. * @param {Object} source The object of property values to match.
  14372. * @param {Function} [customizer] The function to customize comparisons.
  14373. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  14374. * @example
  14375. *
  14376. * function isGreeting(value) {
  14377. * return /^h(?:i|ello)$/.test(value);
  14378. * }
  14379. *
  14380. * function customizer(objValue, srcValue) {
  14381. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  14382. * return true;
  14383. * }
  14384. * }
  14385. *
  14386. * var object = { 'greeting': 'hello' };
  14387. * var source = { 'greeting': 'hi' };
  14388. *
  14389. * _.isMatchWith(object, source, customizer);
  14390. * // => true
  14391. */
  14392. function isMatchWith(object, source, customizer) {
  14393. customizer = typeof customizer == 'function' ? customizer : undefined;
  14394. return baseIsMatch(object, source, getMatchData(source), customizer);
  14395. }
  14396. /**
  14397. * Checks if `value` is `NaN`.
  14398. *
  14399. * **Note:** This method is based on
  14400. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  14401. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  14402. * `undefined` and other non-number values.
  14403. *
  14404. * @static
  14405. * @memberOf _
  14406. * @since 0.1.0
  14407. * @category Lang
  14408. * @param {*} value The value to check.
  14409. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  14410. * @example
  14411. *
  14412. * _.isNaN(NaN);
  14413. * // => true
  14414. *
  14415. * _.isNaN(new Number(NaN));
  14416. * // => true
  14417. *
  14418. * isNaN(undefined);
  14419. * // => true
  14420. *
  14421. * _.isNaN(undefined);
  14422. * // => false
  14423. */
  14424. function isNaN(value) {
  14425. // An `NaN` primitive is the only value that is not equal to itself.
  14426. // Perform the `toStringTag` check first to avoid errors with some
  14427. // ActiveX objects in IE.
  14428. return isNumber(value) && value != +value;
  14429. }
  14430. /**
  14431. * Checks if `value` is a pristine native function.
  14432. *
  14433. * **Note:** This method can't reliably detect native functions in the presence
  14434. * of the core-js package because core-js circumvents this kind of detection.
  14435. * Despite multiple requests, the core-js maintainer has made it clear: any
  14436. * attempt to fix the detection will be obstructed. As a result, we're left
  14437. * with little choice but to throw an error. Unfortunately, this also affects
  14438. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  14439. * which rely on core-js.
  14440. *
  14441. * @static
  14442. * @memberOf _
  14443. * @since 3.0.0
  14444. * @category Lang
  14445. * @param {*} value The value to check.
  14446. * @returns {boolean} Returns `true` if `value` is a native function,
  14447. * else `false`.
  14448. * @example
  14449. *
  14450. * _.isNative(Array.prototype.push);
  14451. * // => true
  14452. *
  14453. * _.isNative(_);
  14454. * // => false
  14455. */
  14456. function isNative(value) {
  14457. if (isMaskable(value)) {
  14458. throw new Error(CORE_ERROR_TEXT);
  14459. }
  14460. return baseIsNative(value);
  14461. }
  14462. /**
  14463. * Checks if `value` is `null`.
  14464. *
  14465. * @static
  14466. * @memberOf _
  14467. * @since 0.1.0
  14468. * @category Lang
  14469. * @param {*} value The value to check.
  14470. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  14471. * @example
  14472. *
  14473. * _.isNull(null);
  14474. * // => true
  14475. *
  14476. * _.isNull(void 0);
  14477. * // => false
  14478. */
  14479. function isNull(value) {
  14480. return value === null;
  14481. }
  14482. /**
  14483. * Checks if `value` is `null` or `undefined`.
  14484. *
  14485. * @static
  14486. * @memberOf _
  14487. * @since 4.0.0
  14488. * @category Lang
  14489. * @param {*} value The value to check.
  14490. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  14491. * @example
  14492. *
  14493. * _.isNil(null);
  14494. * // => true
  14495. *
  14496. * _.isNil(void 0);
  14497. * // => true
  14498. *
  14499. * _.isNil(NaN);
  14500. * // => false
  14501. */
  14502. function isNil(value) {
  14503. return value == null;
  14504. }
  14505. /**
  14506. * Checks if `value` is classified as a `Number` primitive or object.
  14507. *
  14508. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  14509. * classified as numbers, use the `_.isFinite` method.
  14510. *
  14511. * @static
  14512. * @memberOf _
  14513. * @since 0.1.0
  14514. * @category Lang
  14515. * @param {*} value The value to check.
  14516. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  14517. * @example
  14518. *
  14519. * _.isNumber(3);
  14520. * // => true
  14521. *
  14522. * _.isNumber(Number.MIN_VALUE);
  14523. * // => true
  14524. *
  14525. * _.isNumber(Infinity);
  14526. * // => true
  14527. *
  14528. * _.isNumber('3');
  14529. * // => false
  14530. */
  14531. function isNumber(value) {
  14532. return typeof value == 'number' ||
  14533. (isObjectLike(value) && baseGetTag(value) == numberTag);
  14534. }
  14535. /**
  14536. * Checks if `value` is a plain object, that is, an object created by the
  14537. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  14538. *
  14539. * @static
  14540. * @memberOf _
  14541. * @since 0.8.0
  14542. * @category Lang
  14543. * @param {*} value The value to check.
  14544. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  14545. * @example
  14546. *
  14547. * function Foo() {
  14548. * this.a = 1;
  14549. * }
  14550. *
  14551. * _.isPlainObject(new Foo);
  14552. * // => false
  14553. *
  14554. * _.isPlainObject([1, 2, 3]);
  14555. * // => false
  14556. *
  14557. * _.isPlainObject({ 'x': 0, 'y': 0 });
  14558. * // => true
  14559. *
  14560. * _.isPlainObject(Object.create(null));
  14561. * // => true
  14562. */
  14563. function isPlainObject(value) {
  14564. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  14565. return false;
  14566. }
  14567. var proto = getPrototype(value);
  14568. if (proto === null) {
  14569. return true;
  14570. }
  14571. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  14572. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  14573. funcToString.call(Ctor) == objectCtorString;
  14574. }
  14575. /**
  14576. * Checks if `value` is classified as a `RegExp` object.
  14577. *
  14578. * @static
  14579. * @memberOf _
  14580. * @since 0.1.0
  14581. * @category Lang
  14582. * @param {*} value The value to check.
  14583. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  14584. * @example
  14585. *
  14586. * _.isRegExp(/abc/);
  14587. * // => true
  14588. *
  14589. * _.isRegExp('/abc/');
  14590. * // => false
  14591. */
  14592. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  14593. /**
  14594. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  14595. * double precision number which isn't the result of a rounded unsafe integer.
  14596. *
  14597. * **Note:** This method is based on
  14598. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  14599. *
  14600. * @static
  14601. * @memberOf _
  14602. * @since 4.0.0
  14603. * @category Lang
  14604. * @param {*} value The value to check.
  14605. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  14606. * @example
  14607. *
  14608. * _.isSafeInteger(3);
  14609. * // => true
  14610. *
  14611. * _.isSafeInteger(Number.MIN_VALUE);
  14612. * // => false
  14613. *
  14614. * _.isSafeInteger(Infinity);
  14615. * // => false
  14616. *
  14617. * _.isSafeInteger('3');
  14618. * // => false
  14619. */
  14620. function isSafeInteger(value) {
  14621. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  14622. }
  14623. /**
  14624. * Checks if `value` is classified as a `Set` object.
  14625. *
  14626. * @static
  14627. * @memberOf _
  14628. * @since 4.3.0
  14629. * @category Lang
  14630. * @param {*} value The value to check.
  14631. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  14632. * @example
  14633. *
  14634. * _.isSet(new Set);
  14635. * // => true
  14636. *
  14637. * _.isSet(new WeakSet);
  14638. * // => false
  14639. */
  14640. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  14641. /**
  14642. * Checks if `value` is classified as a `String` primitive or object.
  14643. *
  14644. * @static
  14645. * @since 0.1.0
  14646. * @memberOf _
  14647. * @category Lang
  14648. * @param {*} value The value to check.
  14649. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  14650. * @example
  14651. *
  14652. * _.isString('abc');
  14653. * // => true
  14654. *
  14655. * _.isString(1);
  14656. * // => false
  14657. */
  14658. function isString(value) {
  14659. return typeof value == 'string' ||
  14660. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  14661. }
  14662. /**
  14663. * Checks if `value` is classified as a `Symbol` primitive or object.
  14664. *
  14665. * @static
  14666. * @memberOf _
  14667. * @since 4.0.0
  14668. * @category Lang
  14669. * @param {*} value The value to check.
  14670. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  14671. * @example
  14672. *
  14673. * _.isSymbol(Symbol.iterator);
  14674. * // => true
  14675. *
  14676. * _.isSymbol('abc');
  14677. * // => false
  14678. */
  14679. function isSymbol(value) {
  14680. return typeof value == 'symbol' ||
  14681. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  14682. }
  14683. /**
  14684. * Checks if `value` is classified as a typed array.
  14685. *
  14686. * @static
  14687. * @memberOf _
  14688. * @since 3.0.0
  14689. * @category Lang
  14690. * @param {*} value The value to check.
  14691. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  14692. * @example
  14693. *
  14694. * _.isTypedArray(new Uint8Array);
  14695. * // => true
  14696. *
  14697. * _.isTypedArray([]);
  14698. * // => false
  14699. */
  14700. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  14701. /**
  14702. * Checks if `value` is `undefined`.
  14703. *
  14704. * @static
  14705. * @since 0.1.0
  14706. * @memberOf _
  14707. * @category Lang
  14708. * @param {*} value The value to check.
  14709. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  14710. * @example
  14711. *
  14712. * _.isUndefined(void 0);
  14713. * // => true
  14714. *
  14715. * _.isUndefined(null);
  14716. * // => false
  14717. */
  14718. function isUndefined(value) {
  14719. return value === undefined;
  14720. }
  14721. /**
  14722. * Checks if `value` is classified as a `WeakMap` object.
  14723. *
  14724. * @static
  14725. * @memberOf _
  14726. * @since 4.3.0
  14727. * @category Lang
  14728. * @param {*} value The value to check.
  14729. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  14730. * @example
  14731. *
  14732. * _.isWeakMap(new WeakMap);
  14733. * // => true
  14734. *
  14735. * _.isWeakMap(new Map);
  14736. * // => false
  14737. */
  14738. function isWeakMap(value) {
  14739. return isObjectLike(value) && getTag(value) == weakMapTag;
  14740. }
  14741. /**
  14742. * Checks if `value` is classified as a `WeakSet` object.
  14743. *
  14744. * @static
  14745. * @memberOf _
  14746. * @since 4.3.0
  14747. * @category Lang
  14748. * @param {*} value The value to check.
  14749. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  14750. * @example
  14751. *
  14752. * _.isWeakSet(new WeakSet);
  14753. * // => true
  14754. *
  14755. * _.isWeakSet(new Set);
  14756. * // => false
  14757. */
  14758. function isWeakSet(value) {
  14759. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  14760. }
  14761. /**
  14762. * Checks if `value` is less than `other`.
  14763. *
  14764. * @static
  14765. * @memberOf _
  14766. * @since 3.9.0
  14767. * @category Lang
  14768. * @param {*} value The value to compare.
  14769. * @param {*} other The other value to compare.
  14770. * @returns {boolean} Returns `true` if `value` is less than `other`,
  14771. * else `false`.
  14772. * @see _.gt
  14773. * @example
  14774. *
  14775. * _.lt(1, 3);
  14776. * // => true
  14777. *
  14778. * _.lt(3, 3);
  14779. * // => false
  14780. *
  14781. * _.lt(3, 1);
  14782. * // => false
  14783. */
  14784. var lt = createRelationalOperation(baseLt);
  14785. /**
  14786. * Checks if `value` is less than or equal to `other`.
  14787. *
  14788. * @static
  14789. * @memberOf _
  14790. * @since 3.9.0
  14791. * @category Lang
  14792. * @param {*} value The value to compare.
  14793. * @param {*} other The other value to compare.
  14794. * @returns {boolean} Returns `true` if `value` is less than or equal to
  14795. * `other`, else `false`.
  14796. * @see _.gte
  14797. * @example
  14798. *
  14799. * _.lte(1, 3);
  14800. * // => true
  14801. *
  14802. * _.lte(3, 3);
  14803. * // => true
  14804. *
  14805. * _.lte(3, 1);
  14806. * // => false
  14807. */
  14808. var lte = createRelationalOperation(function(value, other) {
  14809. return value <= other;
  14810. });
  14811. /**
  14812. * Converts `value` to an array.
  14813. *
  14814. * @static
  14815. * @since 0.1.0
  14816. * @memberOf _
  14817. * @category Lang
  14818. * @param {*} value The value to convert.
  14819. * @returns {Array} Returns the converted array.
  14820. * @example
  14821. *
  14822. * _.toArray({ 'a': 1, 'b': 2 });
  14823. * // => [1, 2]
  14824. *
  14825. * _.toArray('abc');
  14826. * // => ['a', 'b', 'c']
  14827. *
  14828. * _.toArray(1);
  14829. * // => []
  14830. *
  14831. * _.toArray(null);
  14832. * // => []
  14833. */
  14834. function toArray(value) {
  14835. if (!value) {
  14836. return [];
  14837. }
  14838. if (isArrayLike(value)) {
  14839. return isString(value) ? stringToArray(value) : copyArray(value);
  14840. }
  14841. if (symIterator && value[symIterator]) {
  14842. return iteratorToArray(value[symIterator]());
  14843. }
  14844. var tag = getTag(value),
  14845. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  14846. return func(value);
  14847. }
  14848. /**
  14849. * Converts `value` to a finite number.
  14850. *
  14851. * @static
  14852. * @memberOf _
  14853. * @since 4.12.0
  14854. * @category Lang
  14855. * @param {*} value The value to convert.
  14856. * @returns {number} Returns the converted number.
  14857. * @example
  14858. *
  14859. * _.toFinite(3.2);
  14860. * // => 3.2
  14861. *
  14862. * _.toFinite(Number.MIN_VALUE);
  14863. * // => 5e-324
  14864. *
  14865. * _.toFinite(Infinity);
  14866. * // => 1.7976931348623157e+308
  14867. *
  14868. * _.toFinite('3.2');
  14869. * // => 3.2
  14870. */
  14871. function toFinite(value) {
  14872. if (!value) {
  14873. return value === 0 ? value : 0;
  14874. }
  14875. value = toNumber(value);
  14876. if (value === INFINITY || value === -INFINITY) {
  14877. var sign = (value < 0 ? -1 : 1);
  14878. return sign * MAX_INTEGER;
  14879. }
  14880. return value === value ? value : 0;
  14881. }
  14882. /**
  14883. * Converts `value` to an integer.
  14884. *
  14885. * **Note:** This method is loosely based on
  14886. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  14887. *
  14888. * @static
  14889. * @memberOf _
  14890. * @since 4.0.0
  14891. * @category Lang
  14892. * @param {*} value The value to convert.
  14893. * @returns {number} Returns the converted integer.
  14894. * @example
  14895. *
  14896. * _.toInteger(3.2);
  14897. * // => 3
  14898. *
  14899. * _.toInteger(Number.MIN_VALUE);
  14900. * // => 0
  14901. *
  14902. * _.toInteger(Infinity);
  14903. * // => 1.7976931348623157e+308
  14904. *
  14905. * _.toInteger('3.2');
  14906. * // => 3
  14907. */
  14908. function toInteger(value) {
  14909. var result = toFinite(value),
  14910. remainder = result % 1;
  14911. return result === result ? (remainder ? result - remainder : result) : 0;
  14912. }
  14913. /**
  14914. * Converts `value` to an integer suitable for use as the length of an
  14915. * array-like object.
  14916. *
  14917. * **Note:** This method is based on
  14918. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  14919. *
  14920. * @static
  14921. * @memberOf _
  14922. * @since 4.0.0
  14923. * @category Lang
  14924. * @param {*} value The value to convert.
  14925. * @returns {number} Returns the converted integer.
  14926. * @example
  14927. *
  14928. * _.toLength(3.2);
  14929. * // => 3
  14930. *
  14931. * _.toLength(Number.MIN_VALUE);
  14932. * // => 0
  14933. *
  14934. * _.toLength(Infinity);
  14935. * // => 4294967295
  14936. *
  14937. * _.toLength('3.2');
  14938. * // => 3
  14939. */
  14940. function toLength(value) {
  14941. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  14942. }
  14943. /**
  14944. * Converts `value` to a number.
  14945. *
  14946. * @static
  14947. * @memberOf _
  14948. * @since 4.0.0
  14949. * @category Lang
  14950. * @param {*} value The value to process.
  14951. * @returns {number} Returns the number.
  14952. * @example
  14953. *
  14954. * _.toNumber(3.2);
  14955. * // => 3.2
  14956. *
  14957. * _.toNumber(Number.MIN_VALUE);
  14958. * // => 5e-324
  14959. *
  14960. * _.toNumber(Infinity);
  14961. * // => Infinity
  14962. *
  14963. * _.toNumber('3.2');
  14964. * // => 3.2
  14965. */
  14966. function toNumber(value) {
  14967. if (typeof value == 'number') {
  14968. return value;
  14969. }
  14970. if (isSymbol(value)) {
  14971. return NAN;
  14972. }
  14973. if (isObject(value)) {
  14974. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  14975. value = isObject(other) ? (other + '') : other;
  14976. }
  14977. if (typeof value != 'string') {
  14978. return value === 0 ? value : +value;
  14979. }
  14980. value = baseTrim(value);
  14981. var isBinary = reIsBinary.test(value);
  14982. return (isBinary || reIsOctal.test(value))
  14983. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  14984. : (reIsBadHex.test(value) ? NAN : +value);
  14985. }
  14986. /**
  14987. * Converts `value` to a plain object flattening inherited enumerable string
  14988. * keyed properties of `value` to own properties of the plain object.
  14989. *
  14990. * @static
  14991. * @memberOf _
  14992. * @since 3.0.0
  14993. * @category Lang
  14994. * @param {*} value The value to convert.
  14995. * @returns {Object} Returns the converted plain object.
  14996. * @example
  14997. *
  14998. * function Foo() {
  14999. * this.b = 2;
  15000. * }
  15001. *
  15002. * Foo.prototype.c = 3;
  15003. *
  15004. * _.assign({ 'a': 1 }, new Foo);
  15005. * // => { 'a': 1, 'b': 2 }
  15006. *
  15007. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  15008. * // => { 'a': 1, 'b': 2, 'c': 3 }
  15009. */
  15010. function toPlainObject(value) {
  15011. return copyObject(value, keysIn(value));
  15012. }
  15013. /**
  15014. * Converts `value` to a safe integer. A safe integer can be compared and
  15015. * represented correctly.
  15016. *
  15017. * @static
  15018. * @memberOf _
  15019. * @since 4.0.0
  15020. * @category Lang
  15021. * @param {*} value The value to convert.
  15022. * @returns {number} Returns the converted integer.
  15023. * @example
  15024. *
  15025. * _.toSafeInteger(3.2);
  15026. * // => 3
  15027. *
  15028. * _.toSafeInteger(Number.MIN_VALUE);
  15029. * // => 0
  15030. *
  15031. * _.toSafeInteger(Infinity);
  15032. * // => 9007199254740991
  15033. *
  15034. * _.toSafeInteger('3.2');
  15035. * // => 3
  15036. */
  15037. function toSafeInteger(value) {
  15038. return value
  15039. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  15040. : (value === 0 ? value : 0);
  15041. }
  15042. /**
  15043. * Converts `value` to a string. An empty string is returned for `null`
  15044. * and `undefined` values. The sign of `-0` is preserved.
  15045. *
  15046. * @static
  15047. * @memberOf _
  15048. * @since 4.0.0
  15049. * @category Lang
  15050. * @param {*} value The value to convert.
  15051. * @returns {string} Returns the converted string.
  15052. * @example
  15053. *
  15054. * _.toString(null);
  15055. * // => ''
  15056. *
  15057. * _.toString(-0);
  15058. * // => '-0'
  15059. *
  15060. * _.toString([1, 2, 3]);
  15061. * // => '1,2,3'
  15062. */
  15063. function toString(value) {
  15064. return value == null ? '' : baseToString(value);
  15065. }
  15066. /*------------------------------------------------------------------------*/
  15067. /**
  15068. * Assigns own enumerable string keyed properties of source objects to the
  15069. * destination object. Source objects are applied from left to right.
  15070. * Subsequent sources overwrite property assignments of previous sources.
  15071. *
  15072. * **Note:** This method mutates `object` and is loosely based on
  15073. * [`Object.assign`](https://mdn.io/Object/assign).
  15074. *
  15075. * @static
  15076. * @memberOf _
  15077. * @since 0.10.0
  15078. * @category Object
  15079. * @param {Object} object The destination object.
  15080. * @param {...Object} [sources] The source objects.
  15081. * @returns {Object} Returns `object`.
  15082. * @see _.assignIn
  15083. * @example
  15084. *
  15085. * function Foo() {
  15086. * this.a = 1;
  15087. * }
  15088. *
  15089. * function Bar() {
  15090. * this.c = 3;
  15091. * }
  15092. *
  15093. * Foo.prototype.b = 2;
  15094. * Bar.prototype.d = 4;
  15095. *
  15096. * _.assign({ 'a': 0 }, new Foo, new Bar);
  15097. * // => { 'a': 1, 'c': 3 }
  15098. */
  15099. var assign = createAssigner(function(object, source) {
  15100. if (isPrototype(source) || isArrayLike(source)) {
  15101. copyObject(source, keys(source), object);
  15102. return;
  15103. }
  15104. for (var key in source) {
  15105. if (hasOwnProperty.call(source, key)) {
  15106. assignValue(object, key, source[key]);
  15107. }
  15108. }
  15109. });
  15110. /**
  15111. * This method is like `_.assign` except that it iterates over own and
  15112. * inherited source properties.
  15113. *
  15114. * **Note:** This method mutates `object`.
  15115. *
  15116. * @static
  15117. * @memberOf _
  15118. * @since 4.0.0
  15119. * @alias extend
  15120. * @category Object
  15121. * @param {Object} object The destination object.
  15122. * @param {...Object} [sources] The source objects.
  15123. * @returns {Object} Returns `object`.
  15124. * @see _.assign
  15125. * @example
  15126. *
  15127. * function Foo() {
  15128. * this.a = 1;
  15129. * }
  15130. *
  15131. * function Bar() {
  15132. * this.c = 3;
  15133. * }
  15134. *
  15135. * Foo.prototype.b = 2;
  15136. * Bar.prototype.d = 4;
  15137. *
  15138. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  15139. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  15140. */
  15141. var assignIn = createAssigner(function(object, source) {
  15142. copyObject(source, keysIn(source), object);
  15143. });
  15144. /**
  15145. * This method is like `_.assignIn` except that it accepts `customizer`
  15146. * which is invoked to produce the assigned values. If `customizer` returns
  15147. * `undefined`, assignment is handled by the method instead. The `customizer`
  15148. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  15149. *
  15150. * **Note:** This method mutates `object`.
  15151. *
  15152. * @static
  15153. * @memberOf _
  15154. * @since 4.0.0
  15155. * @alias extendWith
  15156. * @category Object
  15157. * @param {Object} object The destination object.
  15158. * @param {...Object} sources The source objects.
  15159. * @param {Function} [customizer] The function to customize assigned values.
  15160. * @returns {Object} Returns `object`.
  15161. * @see _.assignWith
  15162. * @example
  15163. *
  15164. * function customizer(objValue, srcValue) {
  15165. * return _.isUndefined(objValue) ? srcValue : objValue;
  15166. * }
  15167. *
  15168. * var defaults = _.partialRight(_.assignInWith, customizer);
  15169. *
  15170. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  15171. * // => { 'a': 1, 'b': 2 }
  15172. */
  15173. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  15174. copyObject(source, keysIn(source), object, customizer);
  15175. });
  15176. /**
  15177. * This method is like `_.assign` except that it accepts `customizer`
  15178. * which is invoked to produce the assigned values. If `customizer` returns
  15179. * `undefined`, assignment is handled by the method instead. The `customizer`
  15180. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  15181. *
  15182. * **Note:** This method mutates `object`.
  15183. *
  15184. * @static
  15185. * @memberOf _
  15186. * @since 4.0.0
  15187. * @category Object
  15188. * @param {Object} object The destination object.
  15189. * @param {...Object} sources The source objects.
  15190. * @param {Function} [customizer] The function to customize assigned values.
  15191. * @returns {Object} Returns `object`.
  15192. * @see _.assignInWith
  15193. * @example
  15194. *
  15195. * function customizer(objValue, srcValue) {
  15196. * return _.isUndefined(objValue) ? srcValue : objValue;
  15197. * }
  15198. *
  15199. * var defaults = _.partialRight(_.assignWith, customizer);
  15200. *
  15201. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  15202. * // => { 'a': 1, 'b': 2 }
  15203. */
  15204. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  15205. copyObject(source, keys(source), object, customizer);
  15206. });
  15207. /**
  15208. * Creates an array of values corresponding to `paths` of `object`.
  15209. *
  15210. * @static
  15211. * @memberOf _
  15212. * @since 1.0.0
  15213. * @category Object
  15214. * @param {Object} object The object to iterate over.
  15215. * @param {...(string|string[])} [paths] The property paths to pick.
  15216. * @returns {Array} Returns the picked values.
  15217. * @example
  15218. *
  15219. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  15220. *
  15221. * _.at(object, ['a[0].b.c', 'a[1]']);
  15222. * // => [3, 4]
  15223. */
  15224. var at = flatRest(baseAt);
  15225. /**
  15226. * Creates an object that inherits from the `prototype` object. If a
  15227. * `properties` object is given, its own enumerable string keyed properties
  15228. * are assigned to the created object.
  15229. *
  15230. * @static
  15231. * @memberOf _
  15232. * @since 2.3.0
  15233. * @category Object
  15234. * @param {Object} prototype The object to inherit from.
  15235. * @param {Object} [properties] The properties to assign to the object.
  15236. * @returns {Object} Returns the new object.
  15237. * @example
  15238. *
  15239. * function Shape() {
  15240. * this.x = 0;
  15241. * this.y = 0;
  15242. * }
  15243. *
  15244. * function Circle() {
  15245. * Shape.call(this);
  15246. * }
  15247. *
  15248. * Circle.prototype = _.create(Shape.prototype, {
  15249. * 'constructor': Circle
  15250. * });
  15251. *
  15252. * var circle = new Circle;
  15253. * circle instanceof Circle;
  15254. * // => true
  15255. *
  15256. * circle instanceof Shape;
  15257. * // => true
  15258. */
  15259. function create(prototype, properties) {
  15260. var result = baseCreate(prototype);
  15261. return properties == null ? result : baseAssign(result, properties);
  15262. }
  15263. /**
  15264. * Assigns own and inherited enumerable string keyed properties of source
  15265. * objects to the destination object for all destination properties that
  15266. * resolve to `undefined`. Source objects are applied from left to right.
  15267. * Once a property is set, additional values of the same property are ignored.
  15268. *
  15269. * **Note:** This method mutates `object`.
  15270. *
  15271. * @static
  15272. * @since 0.1.0
  15273. * @memberOf _
  15274. * @category Object
  15275. * @param {Object} object The destination object.
  15276. * @param {...Object} [sources] The source objects.
  15277. * @returns {Object} Returns `object`.
  15278. * @see _.defaultsDeep
  15279. * @example
  15280. *
  15281. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  15282. * // => { 'a': 1, 'b': 2 }
  15283. */
  15284. var defaults = baseRest(function(object, sources) {
  15285. object = Object(object);
  15286. var index = -1;
  15287. var length = sources.length;
  15288. var guard = length > 2 ? sources[2] : undefined;
  15289. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  15290. length = 1;
  15291. }
  15292. while (++index < length) {
  15293. var source = sources[index];
  15294. var props = keysIn(source);
  15295. var propsIndex = -1;
  15296. var propsLength = props.length;
  15297. while (++propsIndex < propsLength) {
  15298. var key = props[propsIndex];
  15299. var value = object[key];
  15300. if (value === undefined ||
  15301. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  15302. object[key] = source[key];
  15303. }
  15304. }
  15305. }
  15306. return object;
  15307. });
  15308. /**
  15309. * This method is like `_.defaults` except that it recursively assigns
  15310. * default properties.
  15311. *
  15312. * **Note:** This method mutates `object`.
  15313. *
  15314. * @static
  15315. * @memberOf _
  15316. * @since 3.10.0
  15317. * @category Object
  15318. * @param {Object} object The destination object.
  15319. * @param {...Object} [sources] The source objects.
  15320. * @returns {Object} Returns `object`.
  15321. * @see _.defaults
  15322. * @example
  15323. *
  15324. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  15325. * // => { 'a': { 'b': 2, 'c': 3 } }
  15326. */
  15327. var defaultsDeep = baseRest(function(args) {
  15328. args.push(undefined, customDefaultsMerge);
  15329. return apply(mergeWith, undefined, args);
  15330. });
  15331. /**
  15332. * This method is like `_.find` except that it returns the key of the first
  15333. * element `predicate` returns truthy for instead of the element itself.
  15334. *
  15335. * @static
  15336. * @memberOf _
  15337. * @since 1.1.0
  15338. * @category Object
  15339. * @param {Object} object The object to inspect.
  15340. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  15341. * @returns {string|undefined} Returns the key of the matched element,
  15342. * else `undefined`.
  15343. * @example
  15344. *
  15345. * var users = {
  15346. * 'barney': { 'age': 36, 'active': true },
  15347. * 'fred': { 'age': 40, 'active': false },
  15348. * 'pebbles': { 'age': 1, 'active': true }
  15349. * };
  15350. *
  15351. * _.findKey(users, function(o) { return o.age < 40; });
  15352. * // => 'barney' (iteration order is not guaranteed)
  15353. *
  15354. * // The `_.matches` iteratee shorthand.
  15355. * _.findKey(users, { 'age': 1, 'active': true });
  15356. * // => 'pebbles'
  15357. *
  15358. * // The `_.matchesProperty` iteratee shorthand.
  15359. * _.findKey(users, ['active', false]);
  15360. * // => 'fred'
  15361. *
  15362. * // The `_.property` iteratee shorthand.
  15363. * _.findKey(users, 'active');
  15364. * // => 'barney'
  15365. */
  15366. function findKey(object, predicate) {
  15367. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  15368. }
  15369. /**
  15370. * This method is like `_.findKey` except that it iterates over elements of
  15371. * a collection in the opposite order.
  15372. *
  15373. * @static
  15374. * @memberOf _
  15375. * @since 2.0.0
  15376. * @category Object
  15377. * @param {Object} object The object to inspect.
  15378. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  15379. * @returns {string|undefined} Returns the key of the matched element,
  15380. * else `undefined`.
  15381. * @example
  15382. *
  15383. * var users = {
  15384. * 'barney': { 'age': 36, 'active': true },
  15385. * 'fred': { 'age': 40, 'active': false },
  15386. * 'pebbles': { 'age': 1, 'active': true }
  15387. * };
  15388. *
  15389. * _.findLastKey(users, function(o) { return o.age < 40; });
  15390. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  15391. *
  15392. * // The `_.matches` iteratee shorthand.
  15393. * _.findLastKey(users, { 'age': 36, 'active': true });
  15394. * // => 'barney'
  15395. *
  15396. * // The `_.matchesProperty` iteratee shorthand.
  15397. * _.findLastKey(users, ['active', false]);
  15398. * // => 'fred'
  15399. *
  15400. * // The `_.property` iteratee shorthand.
  15401. * _.findLastKey(users, 'active');
  15402. * // => 'pebbles'
  15403. */
  15404. function findLastKey(object, predicate) {
  15405. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  15406. }
  15407. /**
  15408. * Iterates over own and inherited enumerable string keyed properties of an
  15409. * object and invokes `iteratee` for each property. The iteratee is invoked
  15410. * with three arguments: (value, key, object). Iteratee functions may exit
  15411. * iteration early by explicitly returning `false`.
  15412. *
  15413. * @static
  15414. * @memberOf _
  15415. * @since 0.3.0
  15416. * @category Object
  15417. * @param {Object} object The object to iterate over.
  15418. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15419. * @returns {Object} Returns `object`.
  15420. * @see _.forInRight
  15421. * @example
  15422. *
  15423. * function Foo() {
  15424. * this.a = 1;
  15425. * this.b = 2;
  15426. * }
  15427. *
  15428. * Foo.prototype.c = 3;
  15429. *
  15430. * _.forIn(new Foo, function(value, key) {
  15431. * console.log(key);
  15432. * });
  15433. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  15434. */
  15435. function forIn(object, iteratee) {
  15436. return object == null
  15437. ? object
  15438. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  15439. }
  15440. /**
  15441. * This method is like `_.forIn` except that it iterates over properties of
  15442. * `object` in the opposite order.
  15443. *
  15444. * @static
  15445. * @memberOf _
  15446. * @since 2.0.0
  15447. * @category Object
  15448. * @param {Object} object The object to iterate over.
  15449. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15450. * @returns {Object} Returns `object`.
  15451. * @see _.forIn
  15452. * @example
  15453. *
  15454. * function Foo() {
  15455. * this.a = 1;
  15456. * this.b = 2;
  15457. * }
  15458. *
  15459. * Foo.prototype.c = 3;
  15460. *
  15461. * _.forInRight(new Foo, function(value, key) {
  15462. * console.log(key);
  15463. * });
  15464. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  15465. */
  15466. function forInRight(object, iteratee) {
  15467. return object == null
  15468. ? object
  15469. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  15470. }
  15471. /**
  15472. * Iterates over own enumerable string keyed properties of an object and
  15473. * invokes `iteratee` for each property. The iteratee is invoked with three
  15474. * arguments: (value, key, object). Iteratee functions may exit iteration
  15475. * early by explicitly returning `false`.
  15476. *
  15477. * @static
  15478. * @memberOf _
  15479. * @since 0.3.0
  15480. * @category Object
  15481. * @param {Object} object The object to iterate over.
  15482. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15483. * @returns {Object} Returns `object`.
  15484. * @see _.forOwnRight
  15485. * @example
  15486. *
  15487. * function Foo() {
  15488. * this.a = 1;
  15489. * this.b = 2;
  15490. * }
  15491. *
  15492. * Foo.prototype.c = 3;
  15493. *
  15494. * _.forOwn(new Foo, function(value, key) {
  15495. * console.log(key);
  15496. * });
  15497. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  15498. */
  15499. function forOwn(object, iteratee) {
  15500. return object && baseForOwn(object, getIteratee(iteratee, 3));
  15501. }
  15502. /**
  15503. * This method is like `_.forOwn` except that it iterates over properties of
  15504. * `object` in the opposite order.
  15505. *
  15506. * @static
  15507. * @memberOf _
  15508. * @since 2.0.0
  15509. * @category Object
  15510. * @param {Object} object The object to iterate over.
  15511. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15512. * @returns {Object} Returns `object`.
  15513. * @see _.forOwn
  15514. * @example
  15515. *
  15516. * function Foo() {
  15517. * this.a = 1;
  15518. * this.b = 2;
  15519. * }
  15520. *
  15521. * Foo.prototype.c = 3;
  15522. *
  15523. * _.forOwnRight(new Foo, function(value, key) {
  15524. * console.log(key);
  15525. * });
  15526. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  15527. */
  15528. function forOwnRight(object, iteratee) {
  15529. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  15530. }
  15531. /**
  15532. * Creates an array of function property names from own enumerable properties
  15533. * of `object`.
  15534. *
  15535. * @static
  15536. * @since 0.1.0
  15537. * @memberOf _
  15538. * @category Object
  15539. * @param {Object} object The object to inspect.
  15540. * @returns {Array} Returns the function names.
  15541. * @see _.functionsIn
  15542. * @example
  15543. *
  15544. * function Foo() {
  15545. * this.a = _.constant('a');
  15546. * this.b = _.constant('b');
  15547. * }
  15548. *
  15549. * Foo.prototype.c = _.constant('c');
  15550. *
  15551. * _.functions(new Foo);
  15552. * // => ['a', 'b']
  15553. */
  15554. function functions(object) {
  15555. return object == null ? [] : baseFunctions(object, keys(object));
  15556. }
  15557. /**
  15558. * Creates an array of function property names from own and inherited
  15559. * enumerable properties of `object`.
  15560. *
  15561. * @static
  15562. * @memberOf _
  15563. * @since 4.0.0
  15564. * @category Object
  15565. * @param {Object} object The object to inspect.
  15566. * @returns {Array} Returns the function names.
  15567. * @see _.functions
  15568. * @example
  15569. *
  15570. * function Foo() {
  15571. * this.a = _.constant('a');
  15572. * this.b = _.constant('b');
  15573. * }
  15574. *
  15575. * Foo.prototype.c = _.constant('c');
  15576. *
  15577. * _.functionsIn(new Foo);
  15578. * // => ['a', 'b', 'c']
  15579. */
  15580. function functionsIn(object) {
  15581. return object == null ? [] : baseFunctions(object, keysIn(object));
  15582. }
  15583. /**
  15584. * Gets the value at `path` of `object`. If the resolved value is
  15585. * `undefined`, the `defaultValue` is returned in its place.
  15586. *
  15587. * @static
  15588. * @memberOf _
  15589. * @since 3.7.0
  15590. * @category Object
  15591. * @param {Object} object The object to query.
  15592. * @param {Array|string} path The path of the property to get.
  15593. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  15594. * @returns {*} Returns the resolved value.
  15595. * @example
  15596. *
  15597. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  15598. *
  15599. * _.get(object, 'a[0].b.c');
  15600. * // => 3
  15601. *
  15602. * _.get(object, ['a', '0', 'b', 'c']);
  15603. * // => 3
  15604. *
  15605. * _.get(object, 'a.b.c', 'default');
  15606. * // => 'default'
  15607. */
  15608. function get(object, path, defaultValue) {
  15609. var result = object == null ? undefined : baseGet(object, path);
  15610. return result === undefined ? defaultValue : result;
  15611. }
  15612. /**
  15613. * Checks if `path` is a direct property of `object`.
  15614. *
  15615. * @static
  15616. * @since 0.1.0
  15617. * @memberOf _
  15618. * @category Object
  15619. * @param {Object} object The object to query.
  15620. * @param {Array|string} path The path to check.
  15621. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  15622. * @example
  15623. *
  15624. * var object = { 'a': { 'b': 2 } };
  15625. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  15626. *
  15627. * _.has(object, 'a');
  15628. * // => true
  15629. *
  15630. * _.has(object, 'a.b');
  15631. * // => true
  15632. *
  15633. * _.has(object, ['a', 'b']);
  15634. * // => true
  15635. *
  15636. * _.has(other, 'a');
  15637. * // => false
  15638. */
  15639. function has(object, path) {
  15640. return object != null && hasPath(object, path, baseHas);
  15641. }
  15642. /**
  15643. * Checks if `path` is a direct or inherited property of `object`.
  15644. *
  15645. * @static
  15646. * @memberOf _
  15647. * @since 4.0.0
  15648. * @category Object
  15649. * @param {Object} object The object to query.
  15650. * @param {Array|string} path The path to check.
  15651. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  15652. * @example
  15653. *
  15654. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  15655. *
  15656. * _.hasIn(object, 'a');
  15657. * // => true
  15658. *
  15659. * _.hasIn(object, 'a.b');
  15660. * // => true
  15661. *
  15662. * _.hasIn(object, ['a', 'b']);
  15663. * // => true
  15664. *
  15665. * _.hasIn(object, 'b');
  15666. * // => false
  15667. */
  15668. function hasIn(object, path) {
  15669. return object != null && hasPath(object, path, baseHasIn);
  15670. }
  15671. /**
  15672. * Creates an object composed of the inverted keys and values of `object`.
  15673. * If `object` contains duplicate values, subsequent values overwrite
  15674. * property assignments of previous values.
  15675. *
  15676. * @static
  15677. * @memberOf _
  15678. * @since 0.7.0
  15679. * @category Object
  15680. * @param {Object} object The object to invert.
  15681. * @returns {Object} Returns the new inverted object.
  15682. * @example
  15683. *
  15684. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  15685. *
  15686. * _.invert(object);
  15687. * // => { '1': 'c', '2': 'b' }
  15688. */
  15689. var invert = createInverter(function(result, value, key) {
  15690. if (value != null &&
  15691. typeof value.toString != 'function') {
  15692. value = nativeObjectToString.call(value);
  15693. }
  15694. result[value] = key;
  15695. }, constant(identity));
  15696. /**
  15697. * This method is like `_.invert` except that the inverted object is generated
  15698. * from the results of running each element of `object` thru `iteratee`. The
  15699. * corresponding inverted value of each inverted key is an array of keys
  15700. * responsible for generating the inverted value. The iteratee is invoked
  15701. * with one argument: (value).
  15702. *
  15703. * @static
  15704. * @memberOf _
  15705. * @since 4.1.0
  15706. * @category Object
  15707. * @param {Object} object The object to invert.
  15708. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15709. * @returns {Object} Returns the new inverted object.
  15710. * @example
  15711. *
  15712. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  15713. *
  15714. * _.invertBy(object);
  15715. * // => { '1': ['a', 'c'], '2': ['b'] }
  15716. *
  15717. * _.invertBy(object, function(value) {
  15718. * return 'group' + value;
  15719. * });
  15720. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  15721. */
  15722. var invertBy = createInverter(function(result, value, key) {
  15723. if (value != null &&
  15724. typeof value.toString != 'function') {
  15725. value = nativeObjectToString.call(value);
  15726. }
  15727. if (hasOwnProperty.call(result, value)) {
  15728. result[value].push(key);
  15729. } else {
  15730. result[value] = [key];
  15731. }
  15732. }, getIteratee);
  15733. /**
  15734. * Invokes the method at `path` of `object`.
  15735. *
  15736. * @static
  15737. * @memberOf _
  15738. * @since 4.0.0
  15739. * @category Object
  15740. * @param {Object} object The object to query.
  15741. * @param {Array|string} path The path of the method to invoke.
  15742. * @param {...*} [args] The arguments to invoke the method with.
  15743. * @returns {*} Returns the result of the invoked method.
  15744. * @example
  15745. *
  15746. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  15747. *
  15748. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  15749. * // => [2, 3]
  15750. */
  15751. var invoke = baseRest(baseInvoke);
  15752. /**
  15753. * Creates an array of the own enumerable property names of `object`.
  15754. *
  15755. * **Note:** Non-object values are coerced to objects. See the
  15756. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  15757. * for more details.
  15758. *
  15759. * @static
  15760. * @since 0.1.0
  15761. * @memberOf _
  15762. * @category Object
  15763. * @param {Object} object The object to query.
  15764. * @returns {Array} Returns the array of property names.
  15765. * @example
  15766. *
  15767. * function Foo() {
  15768. * this.a = 1;
  15769. * this.b = 2;
  15770. * }
  15771. *
  15772. * Foo.prototype.c = 3;
  15773. *
  15774. * _.keys(new Foo);
  15775. * // => ['a', 'b'] (iteration order is not guaranteed)
  15776. *
  15777. * _.keys('hi');
  15778. * // => ['0', '1']
  15779. */
  15780. function keys(object) {
  15781. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  15782. }
  15783. /**
  15784. * Creates an array of the own and inherited enumerable property names of `object`.
  15785. *
  15786. * **Note:** Non-object values are coerced to objects.
  15787. *
  15788. * @static
  15789. * @memberOf _
  15790. * @since 3.0.0
  15791. * @category Object
  15792. * @param {Object} object The object to query.
  15793. * @returns {Array} Returns the array of property names.
  15794. * @example
  15795. *
  15796. * function Foo() {
  15797. * this.a = 1;
  15798. * this.b = 2;
  15799. * }
  15800. *
  15801. * Foo.prototype.c = 3;
  15802. *
  15803. * _.keysIn(new Foo);
  15804. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  15805. */
  15806. function keysIn(object) {
  15807. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  15808. }
  15809. /**
  15810. * The opposite of `_.mapValues`; this method creates an object with the
  15811. * same values as `object` and keys generated by running each own enumerable
  15812. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  15813. * with three arguments: (value, key, object).
  15814. *
  15815. * @static
  15816. * @memberOf _
  15817. * @since 3.8.0
  15818. * @category Object
  15819. * @param {Object} object The object to iterate over.
  15820. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15821. * @returns {Object} Returns the new mapped object.
  15822. * @see _.mapValues
  15823. * @example
  15824. *
  15825. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  15826. * return key + value;
  15827. * });
  15828. * // => { 'a1': 1, 'b2': 2 }
  15829. */
  15830. function mapKeys(object, iteratee) {
  15831. var result = {};
  15832. iteratee = getIteratee(iteratee, 3);
  15833. baseForOwn(object, function(value, key, object) {
  15834. baseAssignValue(result, iteratee(value, key, object), value);
  15835. });
  15836. return result;
  15837. }
  15838. /**
  15839. * Creates an object with the same keys as `object` and values generated
  15840. * by running each own enumerable string keyed property of `object` thru
  15841. * `iteratee`. The iteratee is invoked with three arguments:
  15842. * (value, key, object).
  15843. *
  15844. * @static
  15845. * @memberOf _
  15846. * @since 2.4.0
  15847. * @category Object
  15848. * @param {Object} object The object to iterate over.
  15849. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15850. * @returns {Object} Returns the new mapped object.
  15851. * @see _.mapKeys
  15852. * @example
  15853. *
  15854. * var users = {
  15855. * 'fred': { 'user': 'fred', 'age': 40 },
  15856. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  15857. * };
  15858. *
  15859. * _.mapValues(users, function(o) { return o.age; });
  15860. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  15861. *
  15862. * // The `_.property` iteratee shorthand.
  15863. * _.mapValues(users, 'age');
  15864. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  15865. */
  15866. function mapValues(object, iteratee) {
  15867. var result = {};
  15868. iteratee = getIteratee(iteratee, 3);
  15869. baseForOwn(object, function(value, key, object) {
  15870. baseAssignValue(result, key, iteratee(value, key, object));
  15871. });
  15872. return result;
  15873. }
  15874. /**
  15875. * This method is like `_.assign` except that it recursively merges own and
  15876. * inherited enumerable string keyed properties of source objects into the
  15877. * destination object. Source properties that resolve to `undefined` are
  15878. * skipped if a destination value exists. Array and plain object properties
  15879. * are merged recursively. Other objects and value types are overridden by
  15880. * assignment. Source objects are applied from left to right. Subsequent
  15881. * sources overwrite property assignments of previous sources.
  15882. *
  15883. * **Note:** This method mutates `object`.
  15884. *
  15885. * @static
  15886. * @memberOf _
  15887. * @since 0.5.0
  15888. * @category Object
  15889. * @param {Object} object The destination object.
  15890. * @param {...Object} [sources] The source objects.
  15891. * @returns {Object} Returns `object`.
  15892. * @example
  15893. *
  15894. * var object = {
  15895. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  15896. * };
  15897. *
  15898. * var other = {
  15899. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  15900. * };
  15901. *
  15902. * _.merge(object, other);
  15903. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  15904. */
  15905. var merge = createAssigner(function(object, source, srcIndex) {
  15906. baseMerge(object, source, srcIndex);
  15907. });
  15908. /**
  15909. * This method is like `_.merge` except that it accepts `customizer` which
  15910. * is invoked to produce the merged values of the destination and source
  15911. * properties. If `customizer` returns `undefined`, merging is handled by the
  15912. * method instead. The `customizer` is invoked with six arguments:
  15913. * (objValue, srcValue, key, object, source, stack).
  15914. *
  15915. * **Note:** This method mutates `object`.
  15916. *
  15917. * @static
  15918. * @memberOf _
  15919. * @since 4.0.0
  15920. * @category Object
  15921. * @param {Object} object The destination object.
  15922. * @param {...Object} sources The source objects.
  15923. * @param {Function} customizer The function to customize assigned values.
  15924. * @returns {Object} Returns `object`.
  15925. * @example
  15926. *
  15927. * function customizer(objValue, srcValue) {
  15928. * if (_.isArray(objValue)) {
  15929. * return objValue.concat(srcValue);
  15930. * }
  15931. * }
  15932. *
  15933. * var object = { 'a': [1], 'b': [2] };
  15934. * var other = { 'a': [3], 'b': [4] };
  15935. *
  15936. * _.mergeWith(object, other, customizer);
  15937. * // => { 'a': [1, 3], 'b': [2, 4] }
  15938. */
  15939. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  15940. baseMerge(object, source, srcIndex, customizer);
  15941. });
  15942. /**
  15943. * The opposite of `_.pick`; this method creates an object composed of the
  15944. * own and inherited enumerable property paths of `object` that are not omitted.
  15945. *
  15946. * **Note:** This method is considerably slower than `_.pick`.
  15947. *
  15948. * @static
  15949. * @since 0.1.0
  15950. * @memberOf _
  15951. * @category Object
  15952. * @param {Object} object The source object.
  15953. * @param {...(string|string[])} [paths] The property paths to omit.
  15954. * @returns {Object} Returns the new object.
  15955. * @example
  15956. *
  15957. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  15958. *
  15959. * _.omit(object, ['a', 'c']);
  15960. * // => { 'b': '2' }
  15961. */
  15962. var omit = flatRest(function(object, paths) {
  15963. var result = {};
  15964. if (object == null) {
  15965. return result;
  15966. }
  15967. var isDeep = false;
  15968. paths = arrayMap(paths, function(path) {
  15969. path = castPath(path, object);
  15970. isDeep || (isDeep = path.length > 1);
  15971. return path;
  15972. });
  15973. copyObject(object, getAllKeysIn(object), result);
  15974. if (isDeep) {
  15975. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  15976. }
  15977. var length = paths.length;
  15978. while (length--) {
  15979. baseUnset(result, paths[length]);
  15980. }
  15981. return result;
  15982. });
  15983. /**
  15984. * The opposite of `_.pickBy`; this method creates an object composed of
  15985. * the own and inherited enumerable string keyed properties of `object` that
  15986. * `predicate` doesn't return truthy for. The predicate is invoked with two
  15987. * arguments: (value, key).
  15988. *
  15989. * @static
  15990. * @memberOf _
  15991. * @since 4.0.0
  15992. * @category Object
  15993. * @param {Object} object The source object.
  15994. * @param {Function} [predicate=_.identity] The function invoked per property.
  15995. * @returns {Object} Returns the new object.
  15996. * @example
  15997. *
  15998. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  15999. *
  16000. * _.omitBy(object, _.isNumber);
  16001. * // => { 'b': '2' }
  16002. */
  16003. function omitBy(object, predicate) {
  16004. return pickBy(object, negate(getIteratee(predicate)));
  16005. }
  16006. /**
  16007. * Creates an object composed of the picked `object` properties.
  16008. *
  16009. * @static
  16010. * @since 0.1.0
  16011. * @memberOf _
  16012. * @category Object
  16013. * @param {Object} object The source object.
  16014. * @param {...(string|string[])} [paths] The property paths to pick.
  16015. * @returns {Object} Returns the new object.
  16016. * @example
  16017. *
  16018. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  16019. *
  16020. * _.pick(object, ['a', 'c']);
  16021. * // => { 'a': 1, 'c': 3 }
  16022. */
  16023. var pick = flatRest(function(object, paths) {
  16024. return object == null ? {} : basePick(object, paths);
  16025. });
  16026. /**
  16027. * Creates an object composed of the `object` properties `predicate` returns
  16028. * truthy for. The predicate is invoked with two arguments: (value, key).
  16029. *
  16030. * @static
  16031. * @memberOf _
  16032. * @since 4.0.0
  16033. * @category Object
  16034. * @param {Object} object The source object.
  16035. * @param {Function} [predicate=_.identity] The function invoked per property.
  16036. * @returns {Object} Returns the new object.
  16037. * @example
  16038. *
  16039. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  16040. *
  16041. * _.pickBy(object, _.isNumber);
  16042. * // => { 'a': 1, 'c': 3 }
  16043. */
  16044. function pickBy(object, predicate) {
  16045. if (object == null) {
  16046. return {};
  16047. }
  16048. var props = arrayMap(getAllKeysIn(object), function(prop) {
  16049. return [prop];
  16050. });
  16051. predicate = getIteratee(predicate);
  16052. return basePickBy(object, props, function(value, path) {
  16053. return predicate(value, path[0]);
  16054. });
  16055. }
  16056. /**
  16057. * This method is like `_.get` except that if the resolved value is a
  16058. * function it's invoked with the `this` binding of its parent object and
  16059. * its result is returned.
  16060. *
  16061. * @static
  16062. * @since 0.1.0
  16063. * @memberOf _
  16064. * @category Object
  16065. * @param {Object} object The object to query.
  16066. * @param {Array|string} path The path of the property to resolve.
  16067. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  16068. * @returns {*} Returns the resolved value.
  16069. * @example
  16070. *
  16071. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  16072. *
  16073. * _.result(object, 'a[0].b.c1');
  16074. * // => 3
  16075. *
  16076. * _.result(object, 'a[0].b.c2');
  16077. * // => 4
  16078. *
  16079. * _.result(object, 'a[0].b.c3', 'default');
  16080. * // => 'default'
  16081. *
  16082. * _.result(object, 'a[0].b.c3', _.constant('default'));
  16083. * // => 'default'
  16084. */
  16085. function result(object, path, defaultValue) {
  16086. path = castPath(path, object);
  16087. var index = -1,
  16088. length = path.length;
  16089. // Ensure the loop is entered when path is empty.
  16090. if (!length) {
  16091. length = 1;
  16092. object = undefined;
  16093. }
  16094. while (++index < length) {
  16095. var value = object == null ? undefined : object[toKey(path[index])];
  16096. if (value === undefined) {
  16097. index = length;
  16098. value = defaultValue;
  16099. }
  16100. object = isFunction(value) ? value.call(object) : value;
  16101. }
  16102. return object;
  16103. }
  16104. /**
  16105. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  16106. * it's created. Arrays are created for missing index properties while objects
  16107. * are created for all other missing properties. Use `_.setWith` to customize
  16108. * `path` creation.
  16109. *
  16110. * **Note:** This method mutates `object`.
  16111. *
  16112. * @static
  16113. * @memberOf _
  16114. * @since 3.7.0
  16115. * @category Object
  16116. * @param {Object} object The object to modify.
  16117. * @param {Array|string} path The path of the property to set.
  16118. * @param {*} value The value to set.
  16119. * @returns {Object} Returns `object`.
  16120. * @example
  16121. *
  16122. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  16123. *
  16124. * _.set(object, 'a[0].b.c', 4);
  16125. * console.log(object.a[0].b.c);
  16126. * // => 4
  16127. *
  16128. * _.set(object, ['x', '0', 'y', 'z'], 5);
  16129. * console.log(object.x[0].y.z);
  16130. * // => 5
  16131. */
  16132. function set(object, path, value) {
  16133. return object == null ? object : baseSet(object, path, value);
  16134. }
  16135. /**
  16136. * This method is like `_.set` except that it accepts `customizer` which is
  16137. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  16138. * path creation is handled by the method instead. The `customizer` is invoked
  16139. * with three arguments: (nsValue, key, nsObject).
  16140. *
  16141. * **Note:** This method mutates `object`.
  16142. *
  16143. * @static
  16144. * @memberOf _
  16145. * @since 4.0.0
  16146. * @category Object
  16147. * @param {Object} object The object to modify.
  16148. * @param {Array|string} path The path of the property to set.
  16149. * @param {*} value The value to set.
  16150. * @param {Function} [customizer] The function to customize assigned values.
  16151. * @returns {Object} Returns `object`.
  16152. * @example
  16153. *
  16154. * var object = {};
  16155. *
  16156. * _.setWith(object, '[0][1]', 'a', Object);
  16157. * // => { '0': { '1': 'a' } }
  16158. */
  16159. function setWith(object, path, value, customizer) {
  16160. customizer = typeof customizer == 'function' ? customizer : undefined;
  16161. return object == null ? object : baseSet(object, path, value, customizer);
  16162. }
  16163. /**
  16164. * Creates an array of own enumerable string keyed-value pairs for `object`
  16165. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  16166. * entries are returned.
  16167. *
  16168. * @static
  16169. * @memberOf _
  16170. * @since 4.0.0
  16171. * @alias entries
  16172. * @category Object
  16173. * @param {Object} object The object to query.
  16174. * @returns {Array} Returns the key-value pairs.
  16175. * @example
  16176. *
  16177. * function Foo() {
  16178. * this.a = 1;
  16179. * this.b = 2;
  16180. * }
  16181. *
  16182. * Foo.prototype.c = 3;
  16183. *
  16184. * _.toPairs(new Foo);
  16185. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  16186. */
  16187. var toPairs = createToPairs(keys);
  16188. /**
  16189. * Creates an array of own and inherited enumerable string keyed-value pairs
  16190. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  16191. * or set, its entries are returned.
  16192. *
  16193. * @static
  16194. * @memberOf _
  16195. * @since 4.0.0
  16196. * @alias entriesIn
  16197. * @category Object
  16198. * @param {Object} object The object to query.
  16199. * @returns {Array} Returns the key-value pairs.
  16200. * @example
  16201. *
  16202. * function Foo() {
  16203. * this.a = 1;
  16204. * this.b = 2;
  16205. * }
  16206. *
  16207. * Foo.prototype.c = 3;
  16208. *
  16209. * _.toPairsIn(new Foo);
  16210. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  16211. */
  16212. var toPairsIn = createToPairs(keysIn);
  16213. /**
  16214. * An alternative to `_.reduce`; this method transforms `object` to a new
  16215. * `accumulator` object which is the result of running each of its own
  16216. * enumerable string keyed properties thru `iteratee`, with each invocation
  16217. * potentially mutating the `accumulator` object. If `accumulator` is not
  16218. * provided, a new object with the same `[[Prototype]]` will be used. The
  16219. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  16220. * Iteratee functions may exit iteration early by explicitly returning `false`.
  16221. *
  16222. * @static
  16223. * @memberOf _
  16224. * @since 1.3.0
  16225. * @category Object
  16226. * @param {Object} object The object to iterate over.
  16227. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  16228. * @param {*} [accumulator] The custom accumulator value.
  16229. * @returns {*} Returns the accumulated value.
  16230. * @example
  16231. *
  16232. * _.transform([2, 3, 4], function(result, n) {
  16233. * result.push(n *= n);
  16234. * return n % 2 == 0;
  16235. * }, []);
  16236. * // => [4, 9]
  16237. *
  16238. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  16239. * (result[value] || (result[value] = [])).push(key);
  16240. * }, {});
  16241. * // => { '1': ['a', 'c'], '2': ['b'] }
  16242. */
  16243. function transform(object, iteratee, accumulator) {
  16244. var isArr = isArray(object),
  16245. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  16246. iteratee = getIteratee(iteratee, 4);
  16247. if (accumulator == null) {
  16248. var Ctor = object && object.constructor;
  16249. if (isArrLike) {
  16250. accumulator = isArr ? new Ctor : [];
  16251. }
  16252. else if (isObject(object)) {
  16253. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  16254. }
  16255. else {
  16256. accumulator = {};
  16257. }
  16258. }
  16259. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  16260. return iteratee(accumulator, value, index, object);
  16261. });
  16262. return accumulator;
  16263. }
  16264. /**
  16265. * Removes the property at `path` of `object`.
  16266. *
  16267. * **Note:** This method mutates `object`.
  16268. *
  16269. * @static
  16270. * @memberOf _
  16271. * @since 4.0.0
  16272. * @category Object
  16273. * @param {Object} object The object to modify.
  16274. * @param {Array|string} path The path of the property to unset.
  16275. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  16276. * @example
  16277. *
  16278. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  16279. * _.unset(object, 'a[0].b.c');
  16280. * // => true
  16281. *
  16282. * console.log(object);
  16283. * // => { 'a': [{ 'b': {} }] };
  16284. *
  16285. * _.unset(object, ['a', '0', 'b', 'c']);
  16286. * // => true
  16287. *
  16288. * console.log(object);
  16289. * // => { 'a': [{ 'b': {} }] };
  16290. */
  16291. function unset(object, path) {
  16292. return object == null ? true : baseUnset(object, path);
  16293. }
  16294. /**
  16295. * This method is like `_.set` except that accepts `updater` to produce the
  16296. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  16297. * is invoked with one argument: (value).
  16298. *
  16299. * **Note:** This method mutates `object`.
  16300. *
  16301. * @static
  16302. * @memberOf _
  16303. * @since 4.6.0
  16304. * @category Object
  16305. * @param {Object} object The object to modify.
  16306. * @param {Array|string} path The path of the property to set.
  16307. * @param {Function} updater The function to produce the updated value.
  16308. * @returns {Object} Returns `object`.
  16309. * @example
  16310. *
  16311. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  16312. *
  16313. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  16314. * console.log(object.a[0].b.c);
  16315. * // => 9
  16316. *
  16317. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  16318. * console.log(object.x[0].y.z);
  16319. * // => 0
  16320. */
  16321. function update(object, path, updater) {
  16322. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  16323. }
  16324. /**
  16325. * This method is like `_.update` except that it accepts `customizer` which is
  16326. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  16327. * path creation is handled by the method instead. The `customizer` is invoked
  16328. * with three arguments: (nsValue, key, nsObject).
  16329. *
  16330. * **Note:** This method mutates `object`.
  16331. *
  16332. * @static
  16333. * @memberOf _
  16334. * @since 4.6.0
  16335. * @category Object
  16336. * @param {Object} object The object to modify.
  16337. * @param {Array|string} path The path of the property to set.
  16338. * @param {Function} updater The function to produce the updated value.
  16339. * @param {Function} [customizer] The function to customize assigned values.
  16340. * @returns {Object} Returns `object`.
  16341. * @example
  16342. *
  16343. * var object = {};
  16344. *
  16345. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  16346. * // => { '0': { '1': 'a' } }
  16347. */
  16348. function updateWith(object, path, updater, customizer) {
  16349. customizer = typeof customizer == 'function' ? customizer : undefined;
  16350. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  16351. }
  16352. /**
  16353. * Creates an array of the own enumerable string keyed property values of `object`.
  16354. *
  16355. * **Note:** Non-object values are coerced to objects.
  16356. *
  16357. * @static
  16358. * @since 0.1.0
  16359. * @memberOf _
  16360. * @category Object
  16361. * @param {Object} object The object to query.
  16362. * @returns {Array} Returns the array of property values.
  16363. * @example
  16364. *
  16365. * function Foo() {
  16366. * this.a = 1;
  16367. * this.b = 2;
  16368. * }
  16369. *
  16370. * Foo.prototype.c = 3;
  16371. *
  16372. * _.values(new Foo);
  16373. * // => [1, 2] (iteration order is not guaranteed)
  16374. *
  16375. * _.values('hi');
  16376. * // => ['h', 'i']
  16377. */
  16378. function values(object) {
  16379. return object == null ? [] : baseValues(object, keys(object));
  16380. }
  16381. /**
  16382. * Creates an array of the own and inherited enumerable string keyed property
  16383. * values of `object`.
  16384. *
  16385. * **Note:** Non-object values are coerced to objects.
  16386. *
  16387. * @static
  16388. * @memberOf _
  16389. * @since 3.0.0
  16390. * @category Object
  16391. * @param {Object} object The object to query.
  16392. * @returns {Array} Returns the array of property values.
  16393. * @example
  16394. *
  16395. * function Foo() {
  16396. * this.a = 1;
  16397. * this.b = 2;
  16398. * }
  16399. *
  16400. * Foo.prototype.c = 3;
  16401. *
  16402. * _.valuesIn(new Foo);
  16403. * // => [1, 2, 3] (iteration order is not guaranteed)
  16404. */
  16405. function valuesIn(object) {
  16406. return object == null ? [] : baseValues(object, keysIn(object));
  16407. }
  16408. /*------------------------------------------------------------------------*/
  16409. /**
  16410. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  16411. *
  16412. * @static
  16413. * @memberOf _
  16414. * @since 4.0.0
  16415. * @category Number
  16416. * @param {number} number The number to clamp.
  16417. * @param {number} [lower] The lower bound.
  16418. * @param {number} upper The upper bound.
  16419. * @returns {number} Returns the clamped number.
  16420. * @example
  16421. *
  16422. * _.clamp(-10, -5, 5);
  16423. * // => -5
  16424. *
  16425. * _.clamp(10, -5, 5);
  16426. * // => 5
  16427. */
  16428. function clamp(number, lower, upper) {
  16429. if (upper === undefined) {
  16430. upper = lower;
  16431. lower = undefined;
  16432. }
  16433. if (upper !== undefined) {
  16434. upper = toNumber(upper);
  16435. upper = upper === upper ? upper : 0;
  16436. }
  16437. if (lower !== undefined) {
  16438. lower = toNumber(lower);
  16439. lower = lower === lower ? lower : 0;
  16440. }
  16441. return baseClamp(toNumber(number), lower, upper);
  16442. }
  16443. /**
  16444. * Checks if `n` is between `start` and up to, but not including, `end`. If
  16445. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  16446. * If `start` is greater than `end` the params are swapped to support
  16447. * negative ranges.
  16448. *
  16449. * @static
  16450. * @memberOf _
  16451. * @since 3.3.0
  16452. * @category Number
  16453. * @param {number} number The number to check.
  16454. * @param {number} [start=0] The start of the range.
  16455. * @param {number} end The end of the range.
  16456. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  16457. * @see _.range, _.rangeRight
  16458. * @example
  16459. *
  16460. * _.inRange(3, 2, 4);
  16461. * // => true
  16462. *
  16463. * _.inRange(4, 8);
  16464. * // => true
  16465. *
  16466. * _.inRange(4, 2);
  16467. * // => false
  16468. *
  16469. * _.inRange(2, 2);
  16470. * // => false
  16471. *
  16472. * _.inRange(1.2, 2);
  16473. * // => true
  16474. *
  16475. * _.inRange(5.2, 4);
  16476. * // => false
  16477. *
  16478. * _.inRange(-3, -2, -6);
  16479. * // => true
  16480. */
  16481. function inRange(number, start, end) {
  16482. start = toFinite(start);
  16483. if (end === undefined) {
  16484. end = start;
  16485. start = 0;
  16486. } else {
  16487. end = toFinite(end);
  16488. }
  16489. number = toNumber(number);
  16490. return baseInRange(number, start, end);
  16491. }
  16492. /**
  16493. * Produces a random number between the inclusive `lower` and `upper` bounds.
  16494. * If only one argument is provided a number between `0` and the given number
  16495. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  16496. * floats, a floating-point number is returned instead of an integer.
  16497. *
  16498. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  16499. * floating-point values which can produce unexpected results.
  16500. *
  16501. * @static
  16502. * @memberOf _
  16503. * @since 0.7.0
  16504. * @category Number
  16505. * @param {number} [lower=0] The lower bound.
  16506. * @param {number} [upper=1] The upper bound.
  16507. * @param {boolean} [floating] Specify returning a floating-point number.
  16508. * @returns {number} Returns the random number.
  16509. * @example
  16510. *
  16511. * _.random(0, 5);
  16512. * // => an integer between 0 and 5
  16513. *
  16514. * _.random(5);
  16515. * // => also an integer between 0 and 5
  16516. *
  16517. * _.random(5, true);
  16518. * // => a floating-point number between 0 and 5
  16519. *
  16520. * _.random(1.2, 5.2);
  16521. * // => a floating-point number between 1.2 and 5.2
  16522. */
  16523. function random(lower, upper, floating) {
  16524. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  16525. upper = floating = undefined;
  16526. }
  16527. if (floating === undefined) {
  16528. if (typeof upper == 'boolean') {
  16529. floating = upper;
  16530. upper = undefined;
  16531. }
  16532. else if (typeof lower == 'boolean') {
  16533. floating = lower;
  16534. lower = undefined;
  16535. }
  16536. }
  16537. if (lower === undefined && upper === undefined) {
  16538. lower = 0;
  16539. upper = 1;
  16540. }
  16541. else {
  16542. lower = toFinite(lower);
  16543. if (upper === undefined) {
  16544. upper = lower;
  16545. lower = 0;
  16546. } else {
  16547. upper = toFinite(upper);
  16548. }
  16549. }
  16550. if (lower > upper) {
  16551. var temp = lower;
  16552. lower = upper;
  16553. upper = temp;
  16554. }
  16555. if (floating || lower % 1 || upper % 1) {
  16556. var rand = nativeRandom();
  16557. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  16558. }
  16559. return baseRandom(lower, upper);
  16560. }
  16561. /*------------------------------------------------------------------------*/
  16562. /**
  16563. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  16564. *
  16565. * @static
  16566. * @memberOf _
  16567. * @since 3.0.0
  16568. * @category String
  16569. * @param {string} [string=''] The string to convert.
  16570. * @returns {string} Returns the camel cased string.
  16571. * @example
  16572. *
  16573. * _.camelCase('Foo Bar');
  16574. * // => 'fooBar'
  16575. *
  16576. * _.camelCase('--foo-bar--');
  16577. * // => 'fooBar'
  16578. *
  16579. * _.camelCase('__FOO_BAR__');
  16580. * // => 'fooBar'
  16581. */
  16582. var camelCase = createCompounder(function(result, word, index) {
  16583. word = word.toLowerCase();
  16584. return result + (index ? capitalize(word) : word);
  16585. });
  16586. /**
  16587. * Converts the first character of `string` to upper case and the remaining
  16588. * to lower case.
  16589. *
  16590. * @static
  16591. * @memberOf _
  16592. * @since 3.0.0
  16593. * @category String
  16594. * @param {string} [string=''] The string to capitalize.
  16595. * @returns {string} Returns the capitalized string.
  16596. * @example
  16597. *
  16598. * _.capitalize('FRED');
  16599. * // => 'Fred'
  16600. */
  16601. function capitalize(string) {
  16602. return upperFirst(toString(string).toLowerCase());
  16603. }
  16604. /**
  16605. * Deburrs `string` by converting
  16606. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  16607. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  16608. * letters to basic Latin letters and removing
  16609. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  16610. *
  16611. * @static
  16612. * @memberOf _
  16613. * @since 3.0.0
  16614. * @category String
  16615. * @param {string} [string=''] The string to deburr.
  16616. * @returns {string} Returns the deburred string.
  16617. * @example
  16618. *
  16619. * _.deburr('déjà vu');
  16620. * // => 'deja vu'
  16621. */
  16622. function deburr(string) {
  16623. string = toString(string);
  16624. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  16625. }
  16626. /**
  16627. * Checks if `string` ends with the given target string.
  16628. *
  16629. * @static
  16630. * @memberOf _
  16631. * @since 3.0.0
  16632. * @category String
  16633. * @param {string} [string=''] The string to inspect.
  16634. * @param {string} [target] The string to search for.
  16635. * @param {number} [position=string.length] The position to search up to.
  16636. * @returns {boolean} Returns `true` if `string` ends with `target`,
  16637. * else `false`.
  16638. * @example
  16639. *
  16640. * _.endsWith('abc', 'c');
  16641. * // => true
  16642. *
  16643. * _.endsWith('abc', 'b');
  16644. * // => false
  16645. *
  16646. * _.endsWith('abc', 'b', 2);
  16647. * // => true
  16648. */
  16649. function endsWith(string, target, position) {
  16650. string = toString(string);
  16651. target = baseToString(target);
  16652. var length = string.length;
  16653. position = position === undefined
  16654. ? length
  16655. : baseClamp(toInteger(position), 0, length);
  16656. var end = position;
  16657. position -= target.length;
  16658. return position >= 0 && string.slice(position, end) == target;
  16659. }
  16660. /**
  16661. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  16662. * corresponding HTML entities.
  16663. *
  16664. * **Note:** No other characters are escaped. To escape additional
  16665. * characters use a third-party library like [_he_](https://mths.be/he).
  16666. *
  16667. * Though the ">" character is escaped for symmetry, characters like
  16668. * ">" and "/" don't need escaping in HTML and have no special meaning
  16669. * unless they're part of a tag or unquoted attribute value. See
  16670. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  16671. * (under "semi-related fun fact") for more details.
  16672. *
  16673. * When working with HTML you should always
  16674. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  16675. * XSS vectors.
  16676. *
  16677. * @static
  16678. * @since 0.1.0
  16679. * @memberOf _
  16680. * @category String
  16681. * @param {string} [string=''] The string to escape.
  16682. * @returns {string} Returns the escaped string.
  16683. * @example
  16684. *
  16685. * _.escape('fred, barney, & pebbles');
  16686. * // => 'fred, barney, &amp; pebbles'
  16687. */
  16688. function escape(string) {
  16689. string = toString(string);
  16690. return (string && reHasUnescapedHtml.test(string))
  16691. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  16692. : string;
  16693. }
  16694. /**
  16695. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  16696. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  16697. *
  16698. * @static
  16699. * @memberOf _
  16700. * @since 3.0.0
  16701. * @category String
  16702. * @param {string} [string=''] The string to escape.
  16703. * @returns {string} Returns the escaped string.
  16704. * @example
  16705. *
  16706. * _.escapeRegExp('[lodash](https://lodash.com/)');
  16707. * // => '\[lodash\]\(https://lodash\.com/\)'
  16708. */
  16709. function escapeRegExp(string) {
  16710. string = toString(string);
  16711. return (string && reHasRegExpChar.test(string))
  16712. ? string.replace(reRegExpChar, '\\$&')
  16713. : string;
  16714. }
  16715. /**
  16716. * Converts `string` to
  16717. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  16718. *
  16719. * @static
  16720. * @memberOf _
  16721. * @since 3.0.0
  16722. * @category String
  16723. * @param {string} [string=''] The string to convert.
  16724. * @returns {string} Returns the kebab cased string.
  16725. * @example
  16726. *
  16727. * _.kebabCase('Foo Bar');
  16728. * // => 'foo-bar'
  16729. *
  16730. * _.kebabCase('fooBar');
  16731. * // => 'foo-bar'
  16732. *
  16733. * _.kebabCase('__FOO_BAR__');
  16734. * // => 'foo-bar'
  16735. */
  16736. var kebabCase = createCompounder(function(result, word, index) {
  16737. return result + (index ? '-' : '') + word.toLowerCase();
  16738. });
  16739. /**
  16740. * Converts `string`, as space separated words, to lower case.
  16741. *
  16742. * @static
  16743. * @memberOf _
  16744. * @since 4.0.0
  16745. * @category String
  16746. * @param {string} [string=''] The string to convert.
  16747. * @returns {string} Returns the lower cased string.
  16748. * @example
  16749. *
  16750. * _.lowerCase('--Foo-Bar--');
  16751. * // => 'foo bar'
  16752. *
  16753. * _.lowerCase('fooBar');
  16754. * // => 'foo bar'
  16755. *
  16756. * _.lowerCase('__FOO_BAR__');
  16757. * // => 'foo bar'
  16758. */
  16759. var lowerCase = createCompounder(function(result, word, index) {
  16760. return result + (index ? ' ' : '') + word.toLowerCase();
  16761. });
  16762. /**
  16763. * Converts the first character of `string` to lower case.
  16764. *
  16765. * @static
  16766. * @memberOf _
  16767. * @since 4.0.0
  16768. * @category String
  16769. * @param {string} [string=''] The string to convert.
  16770. * @returns {string} Returns the converted string.
  16771. * @example
  16772. *
  16773. * _.lowerFirst('Fred');
  16774. * // => 'fred'
  16775. *
  16776. * _.lowerFirst('FRED');
  16777. * // => 'fRED'
  16778. */
  16779. var lowerFirst = createCaseFirst('toLowerCase');
  16780. /**
  16781. * Pads `string` on the left and right sides if it's shorter than `length`.
  16782. * Padding characters are truncated if they can't be evenly divided by `length`.
  16783. *
  16784. * @static
  16785. * @memberOf _
  16786. * @since 3.0.0
  16787. * @category String
  16788. * @param {string} [string=''] The string to pad.
  16789. * @param {number} [length=0] The padding length.
  16790. * @param {string} [chars=' '] The string used as padding.
  16791. * @returns {string} Returns the padded string.
  16792. * @example
  16793. *
  16794. * _.pad('abc', 8);
  16795. * // => ' abc '
  16796. *
  16797. * _.pad('abc', 8, '_-');
  16798. * // => '_-abc_-_'
  16799. *
  16800. * _.pad('abc', 3);
  16801. * // => 'abc'
  16802. */
  16803. function pad(string, length, chars) {
  16804. string = toString(string);
  16805. length = toInteger(length);
  16806. var strLength = length ? stringSize(string) : 0;
  16807. if (!length || strLength >= length) {
  16808. return string;
  16809. }
  16810. var mid = (length - strLength) / 2;
  16811. return (
  16812. createPadding(nativeFloor(mid), chars) +
  16813. string +
  16814. createPadding(nativeCeil(mid), chars)
  16815. );
  16816. }
  16817. /**
  16818. * Pads `string` on the right side if it's shorter than `length`. Padding
  16819. * characters are truncated if they exceed `length`.
  16820. *
  16821. * @static
  16822. * @memberOf _
  16823. * @since 4.0.0
  16824. * @category String
  16825. * @param {string} [string=''] The string to pad.
  16826. * @param {number} [length=0] The padding length.
  16827. * @param {string} [chars=' '] The string used as padding.
  16828. * @returns {string} Returns the padded string.
  16829. * @example
  16830. *
  16831. * _.padEnd('abc', 6);
  16832. * // => 'abc '
  16833. *
  16834. * _.padEnd('abc', 6, '_-');
  16835. * // => 'abc_-_'
  16836. *
  16837. * _.padEnd('abc', 3);
  16838. * // => 'abc'
  16839. */
  16840. function padEnd(string, length, chars) {
  16841. string = toString(string);
  16842. length = toInteger(length);
  16843. var strLength = length ? stringSize(string) : 0;
  16844. return (length && strLength < length)
  16845. ? (string + createPadding(length - strLength, chars))
  16846. : string;
  16847. }
  16848. /**
  16849. * Pads `string` on the left side if it's shorter than `length`. Padding
  16850. * characters are truncated if they exceed `length`.
  16851. *
  16852. * @static
  16853. * @memberOf _
  16854. * @since 4.0.0
  16855. * @category String
  16856. * @param {string} [string=''] The string to pad.
  16857. * @param {number} [length=0] The padding length.
  16858. * @param {string} [chars=' '] The string used as padding.
  16859. * @returns {string} Returns the padded string.
  16860. * @example
  16861. *
  16862. * _.padStart('abc', 6);
  16863. * // => ' abc'
  16864. *
  16865. * _.padStart('abc', 6, '_-');
  16866. * // => '_-_abc'
  16867. *
  16868. * _.padStart('abc', 3);
  16869. * // => 'abc'
  16870. */
  16871. function padStart(string, length, chars) {
  16872. string = toString(string);
  16873. length = toInteger(length);
  16874. var strLength = length ? stringSize(string) : 0;
  16875. return (length && strLength < length)
  16876. ? (createPadding(length - strLength, chars) + string)
  16877. : string;
  16878. }
  16879. /**
  16880. * Converts `string` to an integer of the specified radix. If `radix` is
  16881. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  16882. * hexadecimal, in which case a `radix` of `16` is used.
  16883. *
  16884. * **Note:** This method aligns with the
  16885. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  16886. *
  16887. * @static
  16888. * @memberOf _
  16889. * @since 1.1.0
  16890. * @category String
  16891. * @param {string} string The string to convert.
  16892. * @param {number} [radix=10] The radix to interpret `value` by.
  16893. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  16894. * @returns {number} Returns the converted integer.
  16895. * @example
  16896. *
  16897. * _.parseInt('08');
  16898. * // => 8
  16899. *
  16900. * _.map(['6', '08', '10'], _.parseInt);
  16901. * // => [6, 8, 10]
  16902. */
  16903. function parseInt(string, radix, guard) {
  16904. if (guard || radix == null) {
  16905. radix = 0;
  16906. } else if (radix) {
  16907. radix = +radix;
  16908. }
  16909. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  16910. }
  16911. /**
  16912. * Repeats the given string `n` times.
  16913. *
  16914. * @static
  16915. * @memberOf _
  16916. * @since 3.0.0
  16917. * @category String
  16918. * @param {string} [string=''] The string to repeat.
  16919. * @param {number} [n=1] The number of times to repeat the string.
  16920. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  16921. * @returns {string} Returns the repeated string.
  16922. * @example
  16923. *
  16924. * _.repeat('*', 3);
  16925. * // => '***'
  16926. *
  16927. * _.repeat('abc', 2);
  16928. * // => 'abcabc'
  16929. *
  16930. * _.repeat('abc', 0);
  16931. * // => ''
  16932. */
  16933. function repeat(string, n, guard) {
  16934. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  16935. n = 1;
  16936. } else {
  16937. n = toInteger(n);
  16938. }
  16939. return baseRepeat(toString(string), n);
  16940. }
  16941. /**
  16942. * Replaces matches for `pattern` in `string` with `replacement`.
  16943. *
  16944. * **Note:** This method is based on
  16945. * [`String#replace`](https://mdn.io/String/replace).
  16946. *
  16947. * @static
  16948. * @memberOf _
  16949. * @since 4.0.0
  16950. * @category String
  16951. * @param {string} [string=''] The string to modify.
  16952. * @param {RegExp|string} pattern The pattern to replace.
  16953. * @param {Function|string} replacement The match replacement.
  16954. * @returns {string} Returns the modified string.
  16955. * @example
  16956. *
  16957. * _.replace('Hi Fred', 'Fred', 'Barney');
  16958. * // => 'Hi Barney'
  16959. */
  16960. function replace() {
  16961. var args = arguments,
  16962. string = toString(args[0]);
  16963. return args.length < 3 ? string : string.replace(args[1], args[2]);
  16964. }
  16965. /**
  16966. * Converts `string` to
  16967. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  16968. *
  16969. * @static
  16970. * @memberOf _
  16971. * @since 3.0.0
  16972. * @category String
  16973. * @param {string} [string=''] The string to convert.
  16974. * @returns {string} Returns the snake cased string.
  16975. * @example
  16976. *
  16977. * _.snakeCase('Foo Bar');
  16978. * // => 'foo_bar'
  16979. *
  16980. * _.snakeCase('fooBar');
  16981. * // => 'foo_bar'
  16982. *
  16983. * _.snakeCase('--FOO-BAR--');
  16984. * // => 'foo_bar'
  16985. */
  16986. var snakeCase = createCompounder(function(result, word, index) {
  16987. return result + (index ? '_' : '') + word.toLowerCase();
  16988. });
  16989. /**
  16990. * Splits `string` by `separator`.
  16991. *
  16992. * **Note:** This method is based on
  16993. * [`String#split`](https://mdn.io/String/split).
  16994. *
  16995. * @static
  16996. * @memberOf _
  16997. * @since 4.0.0
  16998. * @category String
  16999. * @param {string} [string=''] The string to split.
  17000. * @param {RegExp|string} separator The separator pattern to split by.
  17001. * @param {number} [limit] The length to truncate results to.
  17002. * @returns {Array} Returns the string segments.
  17003. * @example
  17004. *
  17005. * _.split('a-b-c', '-', 2);
  17006. * // => ['a', 'b']
  17007. */
  17008. function split(string, separator, limit) {
  17009. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  17010. separator = limit = undefined;
  17011. }
  17012. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  17013. if (!limit) {
  17014. return [];
  17015. }
  17016. string = toString(string);
  17017. if (string && (
  17018. typeof separator == 'string' ||
  17019. (separator != null && !isRegExp(separator))
  17020. )) {
  17021. separator = baseToString(separator);
  17022. if (!separator && hasUnicode(string)) {
  17023. return castSlice(stringToArray(string), 0, limit);
  17024. }
  17025. }
  17026. return string.split(separator, limit);
  17027. }
  17028. /**
  17029. * Converts `string` to
  17030. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  17031. *
  17032. * @static
  17033. * @memberOf _
  17034. * @since 3.1.0
  17035. * @category String
  17036. * @param {string} [string=''] The string to convert.
  17037. * @returns {string} Returns the start cased string.
  17038. * @example
  17039. *
  17040. * _.startCase('--foo-bar--');
  17041. * // => 'Foo Bar'
  17042. *
  17043. * _.startCase('fooBar');
  17044. * // => 'Foo Bar'
  17045. *
  17046. * _.startCase('__FOO_BAR__');
  17047. * // => 'FOO BAR'
  17048. */
  17049. var startCase = createCompounder(function(result, word, index) {
  17050. return result + (index ? ' ' : '') + upperFirst(word);
  17051. });
  17052. /**
  17053. * Checks if `string` starts with the given target string.
  17054. *
  17055. * @static
  17056. * @memberOf _
  17057. * @since 3.0.0
  17058. * @category String
  17059. * @param {string} [string=''] The string to inspect.
  17060. * @param {string} [target] The string to search for.
  17061. * @param {number} [position=0] The position to search from.
  17062. * @returns {boolean} Returns `true` if `string` starts with `target`,
  17063. * else `false`.
  17064. * @example
  17065. *
  17066. * _.startsWith('abc', 'a');
  17067. * // => true
  17068. *
  17069. * _.startsWith('abc', 'b');
  17070. * // => false
  17071. *
  17072. * _.startsWith('abc', 'b', 1);
  17073. * // => true
  17074. */
  17075. function startsWith(string, target, position) {
  17076. string = toString(string);
  17077. position = position == null
  17078. ? 0
  17079. : baseClamp(toInteger(position), 0, string.length);
  17080. target = baseToString(target);
  17081. return string.slice(position, position + target.length) == target;
  17082. }
  17083. /**
  17084. * Creates a compiled template function that can interpolate data properties
  17085. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  17086. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  17087. * properties may be accessed as free variables in the template. If a setting
  17088. * object is given, it takes precedence over `_.templateSettings` values.
  17089. *
  17090. * **Note:** In the development build `_.template` utilizes
  17091. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  17092. * for easier debugging.
  17093. *
  17094. * For more information on precompiling templates see
  17095. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  17096. *
  17097. * For more information on Chrome extension sandboxes see
  17098. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  17099. *
  17100. * @static
  17101. * @since 0.1.0
  17102. * @memberOf _
  17103. * @category String
  17104. * @param {string} [string=''] The template string.
  17105. * @param {Object} [options={}] The options object.
  17106. * @param {RegExp} [options.escape=_.templateSettings.escape]
  17107. * The HTML "escape" delimiter.
  17108. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  17109. * The "evaluate" delimiter.
  17110. * @param {Object} [options.imports=_.templateSettings.imports]
  17111. * An object to import into the template as free variables.
  17112. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  17113. * The "interpolate" delimiter.
  17114. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  17115. * The sourceURL of the compiled template.
  17116. * @param {string} [options.variable='obj']
  17117. * The data object variable name.
  17118. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  17119. * @returns {Function} Returns the compiled template function.
  17120. * @example
  17121. *
  17122. * // Use the "interpolate" delimiter to create a compiled template.
  17123. * var compiled = _.template('hello <%= user %>!');
  17124. * compiled({ 'user': 'fred' });
  17125. * // => 'hello fred!'
  17126. *
  17127. * // Use the HTML "escape" delimiter to escape data property values.
  17128. * var compiled = _.template('<b><%- value %></b>');
  17129. * compiled({ 'value': '<script>' });
  17130. * // => '<b>&lt;script&gt;</b>'
  17131. *
  17132. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  17133. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  17134. * compiled({ 'users': ['fred', 'barney'] });
  17135. * // => '<li>fred</li><li>barney</li>'
  17136. *
  17137. * // Use the internal `print` function in "evaluate" delimiters.
  17138. * var compiled = _.template('<% print("hello " + user); %>!');
  17139. * compiled({ 'user': 'barney' });
  17140. * // => 'hello barney!'
  17141. *
  17142. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  17143. * // Disable support by replacing the "interpolate" delimiter.
  17144. * var compiled = _.template('hello ${ user }!');
  17145. * compiled({ 'user': 'pebbles' });
  17146. * // => 'hello pebbles!'
  17147. *
  17148. * // Use backslashes to treat delimiters as plain text.
  17149. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  17150. * compiled({ 'value': 'ignored' });
  17151. * // => '<%- value %>'
  17152. *
  17153. * // Use the `imports` option to import `jQuery` as `jq`.
  17154. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  17155. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  17156. * compiled({ 'users': ['fred', 'barney'] });
  17157. * // => '<li>fred</li><li>barney</li>'
  17158. *
  17159. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  17160. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  17161. * compiled(data);
  17162. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  17163. *
  17164. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  17165. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  17166. * compiled.source;
  17167. * // => function(data) {
  17168. * // var __t, __p = '';
  17169. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  17170. * // return __p;
  17171. * // }
  17172. *
  17173. * // Use custom template delimiters.
  17174. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  17175. * var compiled = _.template('hello {{ user }}!');
  17176. * compiled({ 'user': 'mustache' });
  17177. * // => 'hello mustache!'
  17178. *
  17179. * // Use the `source` property to inline compiled templates for meaningful
  17180. * // line numbers in error messages and stack traces.
  17181. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  17182. * var JST = {\
  17183. * "main": ' + _.template(mainText).source + '\
  17184. * };\
  17185. * ');
  17186. */
  17187. function template(string, options, guard) {
  17188. // Based on John Resig's `tmpl` implementation
  17189. // (http://ejohn.org/blog/javascript-micro-templating/)
  17190. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  17191. var settings = lodash.templateSettings;
  17192. if (guard && isIterateeCall(string, options, guard)) {
  17193. options = undefined;
  17194. }
  17195. string = toString(string);
  17196. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  17197. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  17198. importsKeys = keys(imports),
  17199. importsValues = baseValues(imports, importsKeys);
  17200. var isEscaping,
  17201. isEvaluating,
  17202. index = 0,
  17203. interpolate = options.interpolate || reNoMatch,
  17204. source = "__p += '";
  17205. // Compile the regexp to match each delimiter.
  17206. var reDelimiters = RegExp(
  17207. (options.escape || reNoMatch).source + '|' +
  17208. interpolate.source + '|' +
  17209. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  17210. (options.evaluate || reNoMatch).source + '|$'
  17211. , 'g');
  17212. // Use a sourceURL for easier debugging.
  17213. // The sourceURL gets injected into the source that's eval-ed, so be careful
  17214. // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
  17215. // and escape the comment, thus injecting code that gets evaled.
  17216. var sourceURL = '//# sourceURL=' +
  17217. (hasOwnProperty.call(options, 'sourceURL')
  17218. ? (options.sourceURL + '').replace(/\s/g, ' ')
  17219. : ('lodash.templateSources[' + (++templateCounter) + ']')
  17220. ) + '\n';
  17221. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  17222. interpolateValue || (interpolateValue = esTemplateValue);
  17223. // Escape characters that can't be included in string literals.
  17224. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  17225. // Replace delimiters with snippets.
  17226. if (escapeValue) {
  17227. isEscaping = true;
  17228. source += "' +\n__e(" + escapeValue + ") +\n'";
  17229. }
  17230. if (evaluateValue) {
  17231. isEvaluating = true;
  17232. source += "';\n" + evaluateValue + ";\n__p += '";
  17233. }
  17234. if (interpolateValue) {
  17235. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  17236. }
  17237. index = offset + match.length;
  17238. // The JS engine embedded in Adobe products needs `match` returned in
  17239. // order to produce the correct `offset` value.
  17240. return match;
  17241. });
  17242. source += "';\n";
  17243. // If `variable` is not specified wrap a with-statement around the generated
  17244. // code to add the data object to the top of the scope chain.
  17245. var variable = hasOwnProperty.call(options, 'variable') && options.variable;
  17246. if (!variable) {
  17247. source = 'with (obj) {\n' + source + '\n}\n';
  17248. }
  17249. // Throw an error if a forbidden character was found in `variable`, to prevent
  17250. // potential command injection attacks.
  17251. else if (reForbiddenIdentifierChars.test(variable)) {
  17252. throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
  17253. }
  17254. // Cleanup code by stripping empty strings.
  17255. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  17256. .replace(reEmptyStringMiddle, '$1')
  17257. .replace(reEmptyStringTrailing, '$1;');
  17258. // Frame code as the function body.
  17259. source = 'function(' + (variable || 'obj') + ') {\n' +
  17260. (variable
  17261. ? ''
  17262. : 'obj || (obj = {});\n'
  17263. ) +
  17264. "var __t, __p = ''" +
  17265. (isEscaping
  17266. ? ', __e = _.escape'
  17267. : ''
  17268. ) +
  17269. (isEvaluating
  17270. ? ', __j = Array.prototype.join;\n' +
  17271. "function print() { __p += __j.call(arguments, '') }\n"
  17272. : ';\n'
  17273. ) +
  17274. source +
  17275. 'return __p\n}';
  17276. var result = attempt(function() {
  17277. return Function(importsKeys, sourceURL + 'return ' + source)
  17278. .apply(undefined, importsValues);
  17279. });
  17280. // Provide the compiled function's source by its `toString` method or
  17281. // the `source` property as a convenience for inlining compiled templates.
  17282. result.source = source;
  17283. if (isError(result)) {
  17284. throw result;
  17285. }
  17286. return result;
  17287. }
  17288. /**
  17289. * Converts `string`, as a whole, to lower case just like
  17290. * [String#toLowerCase](https://mdn.io/toLowerCase).
  17291. *
  17292. * @static
  17293. * @memberOf _
  17294. * @since 4.0.0
  17295. * @category String
  17296. * @param {string} [string=''] The string to convert.
  17297. * @returns {string} Returns the lower cased string.
  17298. * @example
  17299. *
  17300. * _.toLower('--Foo-Bar--');
  17301. * // => '--foo-bar--'
  17302. *
  17303. * _.toLower('fooBar');
  17304. * // => 'foobar'
  17305. *
  17306. * _.toLower('__FOO_BAR__');
  17307. * // => '__foo_bar__'
  17308. */
  17309. function toLower(value) {
  17310. return toString(value).toLowerCase();
  17311. }
  17312. /**
  17313. * Converts `string`, as a whole, to upper case just like
  17314. * [String#toUpperCase](https://mdn.io/toUpperCase).
  17315. *
  17316. * @static
  17317. * @memberOf _
  17318. * @since 4.0.0
  17319. * @category String
  17320. * @param {string} [string=''] The string to convert.
  17321. * @returns {string} Returns the upper cased string.
  17322. * @example
  17323. *
  17324. * _.toUpper('--foo-bar--');
  17325. * // => '--FOO-BAR--'
  17326. *
  17327. * _.toUpper('fooBar');
  17328. * // => 'FOOBAR'
  17329. *
  17330. * _.toUpper('__foo_bar__');
  17331. * // => '__FOO_BAR__'
  17332. */
  17333. function toUpper(value) {
  17334. return toString(value).toUpperCase();
  17335. }
  17336. /**
  17337. * Removes leading and trailing whitespace or specified characters from `string`.
  17338. *
  17339. * @static
  17340. * @memberOf _
  17341. * @since 3.0.0
  17342. * @category String
  17343. * @param {string} [string=''] The string to trim.
  17344. * @param {string} [chars=whitespace] The characters to trim.
  17345. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  17346. * @returns {string} Returns the trimmed string.
  17347. * @example
  17348. *
  17349. * _.trim(' abc ');
  17350. * // => 'abc'
  17351. *
  17352. * _.trim('-_-abc-_-', '_-');
  17353. * // => 'abc'
  17354. *
  17355. * _.map([' foo ', ' bar '], _.trim);
  17356. * // => ['foo', 'bar']
  17357. */
  17358. function trim(string, chars, guard) {
  17359. string = toString(string);
  17360. if (string && (guard || chars === undefined)) {
  17361. return baseTrim(string);
  17362. }
  17363. if (!string || !(chars = baseToString(chars))) {
  17364. return string;
  17365. }
  17366. var strSymbols = stringToArray(string),
  17367. chrSymbols = stringToArray(chars),
  17368. start = charsStartIndex(strSymbols, chrSymbols),
  17369. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  17370. return castSlice(strSymbols, start, end).join('');
  17371. }
  17372. /**
  17373. * Removes trailing whitespace or specified characters from `string`.
  17374. *
  17375. * @static
  17376. * @memberOf _
  17377. * @since 4.0.0
  17378. * @category String
  17379. * @param {string} [string=''] The string to trim.
  17380. * @param {string} [chars=whitespace] The characters to trim.
  17381. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  17382. * @returns {string} Returns the trimmed string.
  17383. * @example
  17384. *
  17385. * _.trimEnd(' abc ');
  17386. * // => ' abc'
  17387. *
  17388. * _.trimEnd('-_-abc-_-', '_-');
  17389. * // => '-_-abc'
  17390. */
  17391. function trimEnd(string, chars, guard) {
  17392. string = toString(string);
  17393. if (string && (guard || chars === undefined)) {
  17394. return string.slice(0, trimmedEndIndex(string) + 1);
  17395. }
  17396. if (!string || !(chars = baseToString(chars))) {
  17397. return string;
  17398. }
  17399. var strSymbols = stringToArray(string),
  17400. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  17401. return castSlice(strSymbols, 0, end).join('');
  17402. }
  17403. /**
  17404. * Removes leading whitespace or specified characters from `string`.
  17405. *
  17406. * @static
  17407. * @memberOf _
  17408. * @since 4.0.0
  17409. * @category String
  17410. * @param {string} [string=''] The string to trim.
  17411. * @param {string} [chars=whitespace] The characters to trim.
  17412. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  17413. * @returns {string} Returns the trimmed string.
  17414. * @example
  17415. *
  17416. * _.trimStart(' abc ');
  17417. * // => 'abc '
  17418. *
  17419. * _.trimStart('-_-abc-_-', '_-');
  17420. * // => 'abc-_-'
  17421. */
  17422. function trimStart(string, chars, guard) {
  17423. string = toString(string);
  17424. if (string && (guard || chars === undefined)) {
  17425. return string.replace(reTrimStart, '');
  17426. }
  17427. if (!string || !(chars = baseToString(chars))) {
  17428. return string;
  17429. }
  17430. var strSymbols = stringToArray(string),
  17431. start = charsStartIndex(strSymbols, stringToArray(chars));
  17432. return castSlice(strSymbols, start).join('');
  17433. }
  17434. /**
  17435. * Truncates `string` if it's longer than the given maximum string length.
  17436. * The last characters of the truncated string are replaced with the omission
  17437. * string which defaults to "...".
  17438. *
  17439. * @static
  17440. * @memberOf _
  17441. * @since 4.0.0
  17442. * @category String
  17443. * @param {string} [string=''] The string to truncate.
  17444. * @param {Object} [options={}] The options object.
  17445. * @param {number} [options.length=30] The maximum string length.
  17446. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  17447. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  17448. * @returns {string} Returns the truncated string.
  17449. * @example
  17450. *
  17451. * _.truncate('hi-diddly-ho there, neighborino');
  17452. * // => 'hi-diddly-ho there, neighbo...'
  17453. *
  17454. * _.truncate('hi-diddly-ho there, neighborino', {
  17455. * 'length': 24,
  17456. * 'separator': ' '
  17457. * });
  17458. * // => 'hi-diddly-ho there,...'
  17459. *
  17460. * _.truncate('hi-diddly-ho there, neighborino', {
  17461. * 'length': 24,
  17462. * 'separator': /,? +/
  17463. * });
  17464. * // => 'hi-diddly-ho there...'
  17465. *
  17466. * _.truncate('hi-diddly-ho there, neighborino', {
  17467. * 'omission': ' [...]'
  17468. * });
  17469. * // => 'hi-diddly-ho there, neig [...]'
  17470. */
  17471. function truncate(string, options) {
  17472. var length = DEFAULT_TRUNC_LENGTH,
  17473. omission = DEFAULT_TRUNC_OMISSION;
  17474. if (isObject(options)) {
  17475. var separator = 'separator' in options ? options.separator : separator;
  17476. length = 'length' in options ? toInteger(options.length) : length;
  17477. omission = 'omission' in options ? baseToString(options.omission) : omission;
  17478. }
  17479. string = toString(string);
  17480. var strLength = string.length;
  17481. if (hasUnicode(string)) {
  17482. var strSymbols = stringToArray(string);
  17483. strLength = strSymbols.length;
  17484. }
  17485. if (length >= strLength) {
  17486. return string;
  17487. }
  17488. var end = length - stringSize(omission);
  17489. if (end < 1) {
  17490. return omission;
  17491. }
  17492. var result = strSymbols
  17493. ? castSlice(strSymbols, 0, end).join('')
  17494. : string.slice(0, end);
  17495. if (separator === undefined) {
  17496. return result + omission;
  17497. }
  17498. if (strSymbols) {
  17499. end += (result.length - end);
  17500. }
  17501. if (isRegExp(separator)) {
  17502. if (string.slice(end).search(separator)) {
  17503. var match,
  17504. substring = result;
  17505. if (!separator.global) {
  17506. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  17507. }
  17508. separator.lastIndex = 0;
  17509. while ((match = separator.exec(substring))) {
  17510. var newEnd = match.index;
  17511. }
  17512. result = result.slice(0, newEnd === undefined ? end : newEnd);
  17513. }
  17514. } else if (string.indexOf(baseToString(separator), end) != end) {
  17515. var index = result.lastIndexOf(separator);
  17516. if (index > -1) {
  17517. result = result.slice(0, index);
  17518. }
  17519. }
  17520. return result + omission;
  17521. }
  17522. /**
  17523. * The inverse of `_.escape`; this method converts the HTML entities
  17524. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  17525. * their corresponding characters.
  17526. *
  17527. * **Note:** No other HTML entities are unescaped. To unescape additional
  17528. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  17529. *
  17530. * @static
  17531. * @memberOf _
  17532. * @since 0.6.0
  17533. * @category String
  17534. * @param {string} [string=''] The string to unescape.
  17535. * @returns {string} Returns the unescaped string.
  17536. * @example
  17537. *
  17538. * _.unescape('fred, barney, &amp; pebbles');
  17539. * // => 'fred, barney, & pebbles'
  17540. */
  17541. function unescape(string) {
  17542. string = toString(string);
  17543. return (string && reHasEscapedHtml.test(string))
  17544. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  17545. : string;
  17546. }
  17547. /**
  17548. * Converts `string`, as space separated words, to upper case.
  17549. *
  17550. * @static
  17551. * @memberOf _
  17552. * @since 4.0.0
  17553. * @category String
  17554. * @param {string} [string=''] The string to convert.
  17555. * @returns {string} Returns the upper cased string.
  17556. * @example
  17557. *
  17558. * _.upperCase('--foo-bar');
  17559. * // => 'FOO BAR'
  17560. *
  17561. * _.upperCase('fooBar');
  17562. * // => 'FOO BAR'
  17563. *
  17564. * _.upperCase('__foo_bar__');
  17565. * // => 'FOO BAR'
  17566. */
  17567. var upperCase = createCompounder(function(result, word, index) {
  17568. return result + (index ? ' ' : '') + word.toUpperCase();
  17569. });
  17570. /**
  17571. * Converts the first character of `string` to upper case.
  17572. *
  17573. * @static
  17574. * @memberOf _
  17575. * @since 4.0.0
  17576. * @category String
  17577. * @param {string} [string=''] The string to convert.
  17578. * @returns {string} Returns the converted string.
  17579. * @example
  17580. *
  17581. * _.upperFirst('fred');
  17582. * // => 'Fred'
  17583. *
  17584. * _.upperFirst('FRED');
  17585. * // => 'FRED'
  17586. */
  17587. var upperFirst = createCaseFirst('toUpperCase');
  17588. /**
  17589. * Splits `string` into an array of its words.
  17590. *
  17591. * @static
  17592. * @memberOf _
  17593. * @since 3.0.0
  17594. * @category String
  17595. * @param {string} [string=''] The string to inspect.
  17596. * @param {RegExp|string} [pattern] The pattern to match words.
  17597. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  17598. * @returns {Array} Returns the words of `string`.
  17599. * @example
  17600. *
  17601. * _.words('fred, barney, & pebbles');
  17602. * // => ['fred', 'barney', 'pebbles']
  17603. *
  17604. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  17605. * // => ['fred', 'barney', '&', 'pebbles']
  17606. */
  17607. function words(string, pattern, guard) {
  17608. string = toString(string);
  17609. pattern = guard ? undefined : pattern;
  17610. if (pattern === undefined) {
  17611. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  17612. }
  17613. return string.match(pattern) || [];
  17614. }
  17615. /*------------------------------------------------------------------------*/
  17616. /**
  17617. * Attempts to invoke `func`, returning either the result or the caught error
  17618. * object. Any additional arguments are provided to `func` when it's invoked.
  17619. *
  17620. * @static
  17621. * @memberOf _
  17622. * @since 3.0.0
  17623. * @category Util
  17624. * @param {Function} func The function to attempt.
  17625. * @param {...*} [args] The arguments to invoke `func` with.
  17626. * @returns {*} Returns the `func` result or error object.
  17627. * @example
  17628. *
  17629. * // Avoid throwing errors for invalid selectors.
  17630. * var elements = _.attempt(function(selector) {
  17631. * return document.querySelectorAll(selector);
  17632. * }, '>_>');
  17633. *
  17634. * if (_.isError(elements)) {
  17635. * elements = [];
  17636. * }
  17637. */
  17638. var attempt = baseRest(function(func, args) {
  17639. try {
  17640. return apply(func, undefined, args);
  17641. } catch (e) {
  17642. return isError(e) ? e : new Error(e);
  17643. }
  17644. });
  17645. /**
  17646. * Binds methods of an object to the object itself, overwriting the existing
  17647. * method.
  17648. *
  17649. * **Note:** This method doesn't set the "length" property of bound functions.
  17650. *
  17651. * @static
  17652. * @since 0.1.0
  17653. * @memberOf _
  17654. * @category Util
  17655. * @param {Object} object The object to bind and assign the bound methods to.
  17656. * @param {...(string|string[])} methodNames The object method names to bind.
  17657. * @returns {Object} Returns `object`.
  17658. * @example
  17659. *
  17660. * var view = {
  17661. * 'label': 'docs',
  17662. * 'click': function() {
  17663. * console.log('clicked ' + this.label);
  17664. * }
  17665. * };
  17666. *
  17667. * _.bindAll(view, ['click']);
  17668. * jQuery(element).on('click', view.click);
  17669. * // => Logs 'clicked docs' when clicked.
  17670. */
  17671. var bindAll = flatRest(function(object, methodNames) {
  17672. arrayEach(methodNames, function(key) {
  17673. key = toKey(key);
  17674. baseAssignValue(object, key, bind(object[key], object));
  17675. });
  17676. return object;
  17677. });
  17678. /**
  17679. * Creates a function that iterates over `pairs` and invokes the corresponding
  17680. * function of the first predicate to return truthy. The predicate-function
  17681. * pairs are invoked with the `this` binding and arguments of the created
  17682. * function.
  17683. *
  17684. * @static
  17685. * @memberOf _
  17686. * @since 4.0.0
  17687. * @category Util
  17688. * @param {Array} pairs The predicate-function pairs.
  17689. * @returns {Function} Returns the new composite function.
  17690. * @example
  17691. *
  17692. * var func = _.cond([
  17693. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  17694. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  17695. * [_.stubTrue, _.constant('no match')]
  17696. * ]);
  17697. *
  17698. * func({ 'a': 1, 'b': 2 });
  17699. * // => 'matches A'
  17700. *
  17701. * func({ 'a': 0, 'b': 1 });
  17702. * // => 'matches B'
  17703. *
  17704. * func({ 'a': '1', 'b': '2' });
  17705. * // => 'no match'
  17706. */
  17707. function cond(pairs) {
  17708. var length = pairs == null ? 0 : pairs.length,
  17709. toIteratee = getIteratee();
  17710. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  17711. if (typeof pair[1] != 'function') {
  17712. throw new TypeError(FUNC_ERROR_TEXT);
  17713. }
  17714. return [toIteratee(pair[0]), pair[1]];
  17715. });
  17716. return baseRest(function(args) {
  17717. var index = -1;
  17718. while (++index < length) {
  17719. var pair = pairs[index];
  17720. if (apply(pair[0], this, args)) {
  17721. return apply(pair[1], this, args);
  17722. }
  17723. }
  17724. });
  17725. }
  17726. /**
  17727. * Creates a function that invokes the predicate properties of `source` with
  17728. * the corresponding property values of a given object, returning `true` if
  17729. * all predicates return truthy, else `false`.
  17730. *
  17731. * **Note:** The created function is equivalent to `_.conformsTo` with
  17732. * `source` partially applied.
  17733. *
  17734. * @static
  17735. * @memberOf _
  17736. * @since 4.0.0
  17737. * @category Util
  17738. * @param {Object} source The object of property predicates to conform to.
  17739. * @returns {Function} Returns the new spec function.
  17740. * @example
  17741. *
  17742. * var objects = [
  17743. * { 'a': 2, 'b': 1 },
  17744. * { 'a': 1, 'b': 2 }
  17745. * ];
  17746. *
  17747. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  17748. * // => [{ 'a': 1, 'b': 2 }]
  17749. */
  17750. function conforms(source) {
  17751. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  17752. }
  17753. /**
  17754. * Creates a function that returns `value`.
  17755. *
  17756. * @static
  17757. * @memberOf _
  17758. * @since 2.4.0
  17759. * @category Util
  17760. * @param {*} value The value to return from the new function.
  17761. * @returns {Function} Returns the new constant function.
  17762. * @example
  17763. *
  17764. * var objects = _.times(2, _.constant({ 'a': 1 }));
  17765. *
  17766. * console.log(objects);
  17767. * // => [{ 'a': 1 }, { 'a': 1 }]
  17768. *
  17769. * console.log(objects[0] === objects[1]);
  17770. * // => true
  17771. */
  17772. function constant(value) {
  17773. return function() {
  17774. return value;
  17775. };
  17776. }
  17777. /**
  17778. * Checks `value` to determine whether a default value should be returned in
  17779. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  17780. * or `undefined`.
  17781. *
  17782. * @static
  17783. * @memberOf _
  17784. * @since 4.14.0
  17785. * @category Util
  17786. * @param {*} value The value to check.
  17787. * @param {*} defaultValue The default value.
  17788. * @returns {*} Returns the resolved value.
  17789. * @example
  17790. *
  17791. * _.defaultTo(1, 10);
  17792. * // => 1
  17793. *
  17794. * _.defaultTo(undefined, 10);
  17795. * // => 10
  17796. */
  17797. function defaultTo(value, defaultValue) {
  17798. return (value == null || value !== value) ? defaultValue : value;
  17799. }
  17800. /**
  17801. * Creates a function that returns the result of invoking the given functions
  17802. * with the `this` binding of the created function, where each successive
  17803. * invocation is supplied the return value of the previous.
  17804. *
  17805. * @static
  17806. * @memberOf _
  17807. * @since 3.0.0
  17808. * @category Util
  17809. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  17810. * @returns {Function} Returns the new composite function.
  17811. * @see _.flowRight
  17812. * @example
  17813. *
  17814. * function square(n) {
  17815. * return n * n;
  17816. * }
  17817. *
  17818. * var addSquare = _.flow([_.add, square]);
  17819. * addSquare(1, 2);
  17820. * // => 9
  17821. */
  17822. var flow = createFlow();
  17823. /**
  17824. * This method is like `_.flow` except that it creates a function that
  17825. * invokes the given functions from right to left.
  17826. *
  17827. * @static
  17828. * @since 3.0.0
  17829. * @memberOf _
  17830. * @category Util
  17831. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  17832. * @returns {Function} Returns the new composite function.
  17833. * @see _.flow
  17834. * @example
  17835. *
  17836. * function square(n) {
  17837. * return n * n;
  17838. * }
  17839. *
  17840. * var addSquare = _.flowRight([square, _.add]);
  17841. * addSquare(1, 2);
  17842. * // => 9
  17843. */
  17844. var flowRight = createFlow(true);
  17845. /**
  17846. * This method returns the first argument it receives.
  17847. *
  17848. * @static
  17849. * @since 0.1.0
  17850. * @memberOf _
  17851. * @category Util
  17852. * @param {*} value Any value.
  17853. * @returns {*} Returns `value`.
  17854. * @example
  17855. *
  17856. * var object = { 'a': 1 };
  17857. *
  17858. * console.log(_.identity(object) === object);
  17859. * // => true
  17860. */
  17861. function identity(value) {
  17862. return value;
  17863. }
  17864. /**
  17865. * Creates a function that invokes `func` with the arguments of the created
  17866. * function. If `func` is a property name, the created function returns the
  17867. * property value for a given element. If `func` is an array or object, the
  17868. * created function returns `true` for elements that contain the equivalent
  17869. * source properties, otherwise it returns `false`.
  17870. *
  17871. * @static
  17872. * @since 4.0.0
  17873. * @memberOf _
  17874. * @category Util
  17875. * @param {*} [func=_.identity] The value to convert to a callback.
  17876. * @returns {Function} Returns the callback.
  17877. * @example
  17878. *
  17879. * var users = [
  17880. * { 'user': 'barney', 'age': 36, 'active': true },
  17881. * { 'user': 'fred', 'age': 40, 'active': false }
  17882. * ];
  17883. *
  17884. * // The `_.matches` iteratee shorthand.
  17885. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  17886. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  17887. *
  17888. * // The `_.matchesProperty` iteratee shorthand.
  17889. * _.filter(users, _.iteratee(['user', 'fred']));
  17890. * // => [{ 'user': 'fred', 'age': 40 }]
  17891. *
  17892. * // The `_.property` iteratee shorthand.
  17893. * _.map(users, _.iteratee('user'));
  17894. * // => ['barney', 'fred']
  17895. *
  17896. * // Create custom iteratee shorthands.
  17897. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  17898. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  17899. * return func.test(string);
  17900. * };
  17901. * });
  17902. *
  17903. * _.filter(['abc', 'def'], /ef/);
  17904. * // => ['def']
  17905. */
  17906. function iteratee(func) {
  17907. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  17908. }
  17909. /**
  17910. * Creates a function that performs a partial deep comparison between a given
  17911. * object and `source`, returning `true` if the given object has equivalent
  17912. * property values, else `false`.
  17913. *
  17914. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  17915. * partially applied.
  17916. *
  17917. * Partial comparisons will match empty array and empty object `source`
  17918. * values against any array or object value, respectively. See `_.isEqual`
  17919. * for a list of supported value comparisons.
  17920. *
  17921. * **Note:** Multiple values can be checked by combining several matchers
  17922. * using `_.overSome`
  17923. *
  17924. * @static
  17925. * @memberOf _
  17926. * @since 3.0.0
  17927. * @category Util
  17928. * @param {Object} source The object of property values to match.
  17929. * @returns {Function} Returns the new spec function.
  17930. * @example
  17931. *
  17932. * var objects = [
  17933. * { 'a': 1, 'b': 2, 'c': 3 },
  17934. * { 'a': 4, 'b': 5, 'c': 6 }
  17935. * ];
  17936. *
  17937. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  17938. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  17939. *
  17940. * // Checking for several possible values
  17941. * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
  17942. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  17943. */
  17944. function matches(source) {
  17945. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  17946. }
  17947. /**
  17948. * Creates a function that performs a partial deep comparison between the
  17949. * value at `path` of a given object to `srcValue`, returning `true` if the
  17950. * object value is equivalent, else `false`.
  17951. *
  17952. * **Note:** Partial comparisons will match empty array and empty object
  17953. * `srcValue` values against any array or object value, respectively. See
  17954. * `_.isEqual` for a list of supported value comparisons.
  17955. *
  17956. * **Note:** Multiple values can be checked by combining several matchers
  17957. * using `_.overSome`
  17958. *
  17959. * @static
  17960. * @memberOf _
  17961. * @since 3.2.0
  17962. * @category Util
  17963. * @param {Array|string} path The path of the property to get.
  17964. * @param {*} srcValue The value to match.
  17965. * @returns {Function} Returns the new spec function.
  17966. * @example
  17967. *
  17968. * var objects = [
  17969. * { 'a': 1, 'b': 2, 'c': 3 },
  17970. * { 'a': 4, 'b': 5, 'c': 6 }
  17971. * ];
  17972. *
  17973. * _.find(objects, _.matchesProperty('a', 4));
  17974. * // => { 'a': 4, 'b': 5, 'c': 6 }
  17975. *
  17976. * // Checking for several possible values
  17977. * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
  17978. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  17979. */
  17980. function matchesProperty(path, srcValue) {
  17981. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  17982. }
  17983. /**
  17984. * Creates a function that invokes the method at `path` of a given object.
  17985. * Any additional arguments are provided to the invoked method.
  17986. *
  17987. * @static
  17988. * @memberOf _
  17989. * @since 3.7.0
  17990. * @category Util
  17991. * @param {Array|string} path The path of the method to invoke.
  17992. * @param {...*} [args] The arguments to invoke the method with.
  17993. * @returns {Function} Returns the new invoker function.
  17994. * @example
  17995. *
  17996. * var objects = [
  17997. * { 'a': { 'b': _.constant(2) } },
  17998. * { 'a': { 'b': _.constant(1) } }
  17999. * ];
  18000. *
  18001. * _.map(objects, _.method('a.b'));
  18002. * // => [2, 1]
  18003. *
  18004. * _.map(objects, _.method(['a', 'b']));
  18005. * // => [2, 1]
  18006. */
  18007. var method = baseRest(function(path, args) {
  18008. return function(object) {
  18009. return baseInvoke(object, path, args);
  18010. };
  18011. });
  18012. /**
  18013. * The opposite of `_.method`; this method creates a function that invokes
  18014. * the method at a given path of `object`. Any additional arguments are
  18015. * provided to the invoked method.
  18016. *
  18017. * @static
  18018. * @memberOf _
  18019. * @since 3.7.0
  18020. * @category Util
  18021. * @param {Object} object The object to query.
  18022. * @param {...*} [args] The arguments to invoke the method with.
  18023. * @returns {Function} Returns the new invoker function.
  18024. * @example
  18025. *
  18026. * var array = _.times(3, _.constant),
  18027. * object = { 'a': array, 'b': array, 'c': array };
  18028. *
  18029. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  18030. * // => [2, 0]
  18031. *
  18032. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  18033. * // => [2, 0]
  18034. */
  18035. var methodOf = baseRest(function(object, args) {
  18036. return function(path) {
  18037. return baseInvoke(object, path, args);
  18038. };
  18039. });
  18040. /**
  18041. * Adds all own enumerable string keyed function properties of a source
  18042. * object to the destination object. If `object` is a function, then methods
  18043. * are added to its prototype as well.
  18044. *
  18045. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  18046. * avoid conflicts caused by modifying the original.
  18047. *
  18048. * @static
  18049. * @since 0.1.0
  18050. * @memberOf _
  18051. * @category Util
  18052. * @param {Function|Object} [object=lodash] The destination object.
  18053. * @param {Object} source The object of functions to add.
  18054. * @param {Object} [options={}] The options object.
  18055. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  18056. * @returns {Function|Object} Returns `object`.
  18057. * @example
  18058. *
  18059. * function vowels(string) {
  18060. * return _.filter(string, function(v) {
  18061. * return /[aeiou]/i.test(v);
  18062. * });
  18063. * }
  18064. *
  18065. * _.mixin({ 'vowels': vowels });
  18066. * _.vowels('fred');
  18067. * // => ['e']
  18068. *
  18069. * _('fred').vowels().value();
  18070. * // => ['e']
  18071. *
  18072. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  18073. * _('fred').vowels();
  18074. * // => ['e']
  18075. */
  18076. function mixin(object, source, options) {
  18077. var props = keys(source),
  18078. methodNames = baseFunctions(source, props);
  18079. if (options == null &&
  18080. !(isObject(source) && (methodNames.length || !props.length))) {
  18081. options = source;
  18082. source = object;
  18083. object = this;
  18084. methodNames = baseFunctions(source, keys(source));
  18085. }
  18086. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  18087. isFunc = isFunction(object);
  18088. arrayEach(methodNames, function(methodName) {
  18089. var func = source[methodName];
  18090. object[methodName] = func;
  18091. if (isFunc) {
  18092. object.prototype[methodName] = function() {
  18093. var chainAll = this.__chain__;
  18094. if (chain || chainAll) {
  18095. var result = object(this.__wrapped__),
  18096. actions = result.__actions__ = copyArray(this.__actions__);
  18097. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  18098. result.__chain__ = chainAll;
  18099. return result;
  18100. }
  18101. return func.apply(object, arrayPush([this.value()], arguments));
  18102. };
  18103. }
  18104. });
  18105. return object;
  18106. }
  18107. /**
  18108. * Reverts the `_` variable to its previous value and returns a reference to
  18109. * the `lodash` function.
  18110. *
  18111. * @static
  18112. * @since 0.1.0
  18113. * @memberOf _
  18114. * @category Util
  18115. * @returns {Function} Returns the `lodash` function.
  18116. * @example
  18117. *
  18118. * var lodash = _.noConflict();
  18119. */
  18120. function noConflict() {
  18121. if (root._ === this) {
  18122. root._ = oldDash;
  18123. }
  18124. return this;
  18125. }
  18126. /**
  18127. * This method returns `undefined`.
  18128. *
  18129. * @static
  18130. * @memberOf _
  18131. * @since 2.3.0
  18132. * @category Util
  18133. * @example
  18134. *
  18135. * _.times(2, _.noop);
  18136. * // => [undefined, undefined]
  18137. */
  18138. function noop() {
  18139. // No operation performed.
  18140. }
  18141. /**
  18142. * Creates a function that gets the argument at index `n`. If `n` is negative,
  18143. * the nth argument from the end is returned.
  18144. *
  18145. * @static
  18146. * @memberOf _
  18147. * @since 4.0.0
  18148. * @category Util
  18149. * @param {number} [n=0] The index of the argument to return.
  18150. * @returns {Function} Returns the new pass-thru function.
  18151. * @example
  18152. *
  18153. * var func = _.nthArg(1);
  18154. * func('a', 'b', 'c', 'd');
  18155. * // => 'b'
  18156. *
  18157. * var func = _.nthArg(-2);
  18158. * func('a', 'b', 'c', 'd');
  18159. * // => 'c'
  18160. */
  18161. function nthArg(n) {
  18162. n = toInteger(n);
  18163. return baseRest(function(args) {
  18164. return baseNth(args, n);
  18165. });
  18166. }
  18167. /**
  18168. * Creates a function that invokes `iteratees` with the arguments it receives
  18169. * and returns their results.
  18170. *
  18171. * @static
  18172. * @memberOf _
  18173. * @since 4.0.0
  18174. * @category Util
  18175. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  18176. * The iteratees to invoke.
  18177. * @returns {Function} Returns the new function.
  18178. * @example
  18179. *
  18180. * var func = _.over([Math.max, Math.min]);
  18181. *
  18182. * func(1, 2, 3, 4);
  18183. * // => [4, 1]
  18184. */
  18185. var over = createOver(arrayMap);
  18186. /**
  18187. * Creates a function that checks if **all** of the `predicates` return
  18188. * truthy when invoked with the arguments it receives.
  18189. *
  18190. * Following shorthands are possible for providing predicates.
  18191. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  18192. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  18193. *
  18194. * @static
  18195. * @memberOf _
  18196. * @since 4.0.0
  18197. * @category Util
  18198. * @param {...(Function|Function[])} [predicates=[_.identity]]
  18199. * The predicates to check.
  18200. * @returns {Function} Returns the new function.
  18201. * @example
  18202. *
  18203. * var func = _.overEvery([Boolean, isFinite]);
  18204. *
  18205. * func('1');
  18206. * // => true
  18207. *
  18208. * func(null);
  18209. * // => false
  18210. *
  18211. * func(NaN);
  18212. * // => false
  18213. */
  18214. var overEvery = createOver(arrayEvery);
  18215. /**
  18216. * Creates a function that checks if **any** of the `predicates` return
  18217. * truthy when invoked with the arguments it receives.
  18218. *
  18219. * Following shorthands are possible for providing predicates.
  18220. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  18221. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  18222. *
  18223. * @static
  18224. * @memberOf _
  18225. * @since 4.0.0
  18226. * @category Util
  18227. * @param {...(Function|Function[])} [predicates=[_.identity]]
  18228. * The predicates to check.
  18229. * @returns {Function} Returns the new function.
  18230. * @example
  18231. *
  18232. * var func = _.overSome([Boolean, isFinite]);
  18233. *
  18234. * func('1');
  18235. * // => true
  18236. *
  18237. * func(null);
  18238. * // => true
  18239. *
  18240. * func(NaN);
  18241. * // => false
  18242. *
  18243. * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
  18244. * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
  18245. */
  18246. var overSome = createOver(arraySome);
  18247. /**
  18248. * Creates a function that returns the value at `path` of a given object.
  18249. *
  18250. * @static
  18251. * @memberOf _
  18252. * @since 2.4.0
  18253. * @category Util
  18254. * @param {Array|string} path The path of the property to get.
  18255. * @returns {Function} Returns the new accessor function.
  18256. * @example
  18257. *
  18258. * var objects = [
  18259. * { 'a': { 'b': 2 } },
  18260. * { 'a': { 'b': 1 } }
  18261. * ];
  18262. *
  18263. * _.map(objects, _.property('a.b'));
  18264. * // => [2, 1]
  18265. *
  18266. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  18267. * // => [1, 2]
  18268. */
  18269. function property(path) {
  18270. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  18271. }
  18272. /**
  18273. * The opposite of `_.property`; this method creates a function that returns
  18274. * the value at a given path of `object`.
  18275. *
  18276. * @static
  18277. * @memberOf _
  18278. * @since 3.0.0
  18279. * @category Util
  18280. * @param {Object} object The object to query.
  18281. * @returns {Function} Returns the new accessor function.
  18282. * @example
  18283. *
  18284. * var array = [0, 1, 2],
  18285. * object = { 'a': array, 'b': array, 'c': array };
  18286. *
  18287. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  18288. * // => [2, 0]
  18289. *
  18290. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  18291. * // => [2, 0]
  18292. */
  18293. function propertyOf(object) {
  18294. return function(path) {
  18295. return object == null ? undefined : baseGet(object, path);
  18296. };
  18297. }
  18298. /**
  18299. * Creates an array of numbers (positive and/or negative) progressing from
  18300. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  18301. * `start` is specified without an `end` or `step`. If `end` is not specified,
  18302. * it's set to `start` with `start` then set to `0`.
  18303. *
  18304. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  18305. * floating-point values which can produce unexpected results.
  18306. *
  18307. * @static
  18308. * @since 0.1.0
  18309. * @memberOf _
  18310. * @category Util
  18311. * @param {number} [start=0] The start of the range.
  18312. * @param {number} end The end of the range.
  18313. * @param {number} [step=1] The value to increment or decrement by.
  18314. * @returns {Array} Returns the range of numbers.
  18315. * @see _.inRange, _.rangeRight
  18316. * @example
  18317. *
  18318. * _.range(4);
  18319. * // => [0, 1, 2, 3]
  18320. *
  18321. * _.range(-4);
  18322. * // => [0, -1, -2, -3]
  18323. *
  18324. * _.range(1, 5);
  18325. * // => [1, 2, 3, 4]
  18326. *
  18327. * _.range(0, 20, 5);
  18328. * // => [0, 5, 10, 15]
  18329. *
  18330. * _.range(0, -4, -1);
  18331. * // => [0, -1, -2, -3]
  18332. *
  18333. * _.range(1, 4, 0);
  18334. * // => [1, 1, 1]
  18335. *
  18336. * _.range(0);
  18337. * // => []
  18338. */
  18339. var range = createRange();
  18340. /**
  18341. * This method is like `_.range` except that it populates values in
  18342. * descending order.
  18343. *
  18344. * @static
  18345. * @memberOf _
  18346. * @since 4.0.0
  18347. * @category Util
  18348. * @param {number} [start=0] The start of the range.
  18349. * @param {number} end The end of the range.
  18350. * @param {number} [step=1] The value to increment or decrement by.
  18351. * @returns {Array} Returns the range of numbers.
  18352. * @see _.inRange, _.range
  18353. * @example
  18354. *
  18355. * _.rangeRight(4);
  18356. * // => [3, 2, 1, 0]
  18357. *
  18358. * _.rangeRight(-4);
  18359. * // => [-3, -2, -1, 0]
  18360. *
  18361. * _.rangeRight(1, 5);
  18362. * // => [4, 3, 2, 1]
  18363. *
  18364. * _.rangeRight(0, 20, 5);
  18365. * // => [15, 10, 5, 0]
  18366. *
  18367. * _.rangeRight(0, -4, -1);
  18368. * // => [-3, -2, -1, 0]
  18369. *
  18370. * _.rangeRight(1, 4, 0);
  18371. * // => [1, 1, 1]
  18372. *
  18373. * _.rangeRight(0);
  18374. * // => []
  18375. */
  18376. var rangeRight = createRange(true);
  18377. /**
  18378. * This method returns a new empty array.
  18379. *
  18380. * @static
  18381. * @memberOf _
  18382. * @since 4.13.0
  18383. * @category Util
  18384. * @returns {Array} Returns the new empty array.
  18385. * @example
  18386. *
  18387. * var arrays = _.times(2, _.stubArray);
  18388. *
  18389. * console.log(arrays);
  18390. * // => [[], []]
  18391. *
  18392. * console.log(arrays[0] === arrays[1]);
  18393. * // => false
  18394. */
  18395. function stubArray() {
  18396. return [];
  18397. }
  18398. /**
  18399. * This method returns `false`.
  18400. *
  18401. * @static
  18402. * @memberOf _
  18403. * @since 4.13.0
  18404. * @category Util
  18405. * @returns {boolean} Returns `false`.
  18406. * @example
  18407. *
  18408. * _.times(2, _.stubFalse);
  18409. * // => [false, false]
  18410. */
  18411. function stubFalse() {
  18412. return false;
  18413. }
  18414. /**
  18415. * This method returns a new empty object.
  18416. *
  18417. * @static
  18418. * @memberOf _
  18419. * @since 4.13.0
  18420. * @category Util
  18421. * @returns {Object} Returns the new empty object.
  18422. * @example
  18423. *
  18424. * var objects = _.times(2, _.stubObject);
  18425. *
  18426. * console.log(objects);
  18427. * // => [{}, {}]
  18428. *
  18429. * console.log(objects[0] === objects[1]);
  18430. * // => false
  18431. */
  18432. function stubObject() {
  18433. return {};
  18434. }
  18435. /**
  18436. * This method returns an empty string.
  18437. *
  18438. * @static
  18439. * @memberOf _
  18440. * @since 4.13.0
  18441. * @category Util
  18442. * @returns {string} Returns the empty string.
  18443. * @example
  18444. *
  18445. * _.times(2, _.stubString);
  18446. * // => ['', '']
  18447. */
  18448. function stubString() {
  18449. return '';
  18450. }
  18451. /**
  18452. * This method returns `true`.
  18453. *
  18454. * @static
  18455. * @memberOf _
  18456. * @since 4.13.0
  18457. * @category Util
  18458. * @returns {boolean} Returns `true`.
  18459. * @example
  18460. *
  18461. * _.times(2, _.stubTrue);
  18462. * // => [true, true]
  18463. */
  18464. function stubTrue() {
  18465. return true;
  18466. }
  18467. /**
  18468. * Invokes the iteratee `n` times, returning an array of the results of
  18469. * each invocation. The iteratee is invoked with one argument; (index).
  18470. *
  18471. * @static
  18472. * @since 0.1.0
  18473. * @memberOf _
  18474. * @category Util
  18475. * @param {number} n The number of times to invoke `iteratee`.
  18476. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  18477. * @returns {Array} Returns the array of results.
  18478. * @example
  18479. *
  18480. * _.times(3, String);
  18481. * // => ['0', '1', '2']
  18482. *
  18483. * _.times(4, _.constant(0));
  18484. * // => [0, 0, 0, 0]
  18485. */
  18486. function times(n, iteratee) {
  18487. n = toInteger(n);
  18488. if (n < 1 || n > MAX_SAFE_INTEGER) {
  18489. return [];
  18490. }
  18491. var index = MAX_ARRAY_LENGTH,
  18492. length = nativeMin(n, MAX_ARRAY_LENGTH);
  18493. iteratee = getIteratee(iteratee);
  18494. n -= MAX_ARRAY_LENGTH;
  18495. var result = baseTimes(length, iteratee);
  18496. while (++index < n) {
  18497. iteratee(index);
  18498. }
  18499. return result;
  18500. }
  18501. /**
  18502. * Converts `value` to a property path array.
  18503. *
  18504. * @static
  18505. * @memberOf _
  18506. * @since 4.0.0
  18507. * @category Util
  18508. * @param {*} value The value to convert.
  18509. * @returns {Array} Returns the new property path array.
  18510. * @example
  18511. *
  18512. * _.toPath('a.b.c');
  18513. * // => ['a', 'b', 'c']
  18514. *
  18515. * _.toPath('a[0].b.c');
  18516. * // => ['a', '0', 'b', 'c']
  18517. */
  18518. function toPath(value) {
  18519. if (isArray(value)) {
  18520. return arrayMap(value, toKey);
  18521. }
  18522. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  18523. }
  18524. /**
  18525. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  18526. *
  18527. * @static
  18528. * @since 0.1.0
  18529. * @memberOf _
  18530. * @category Util
  18531. * @param {string} [prefix=''] The value to prefix the ID with.
  18532. * @returns {string} Returns the unique ID.
  18533. * @example
  18534. *
  18535. * _.uniqueId('contact_');
  18536. * // => 'contact_104'
  18537. *
  18538. * _.uniqueId();
  18539. * // => '105'
  18540. */
  18541. function uniqueId(prefix) {
  18542. var id = ++idCounter;
  18543. return toString(prefix) + id;
  18544. }
  18545. /*------------------------------------------------------------------------*/
  18546. /**
  18547. * Adds two numbers.
  18548. *
  18549. * @static
  18550. * @memberOf _
  18551. * @since 3.4.0
  18552. * @category Math
  18553. * @param {number} augend The first number in an addition.
  18554. * @param {number} addend The second number in an addition.
  18555. * @returns {number} Returns the total.
  18556. * @example
  18557. *
  18558. * _.add(6, 4);
  18559. * // => 10
  18560. */
  18561. var add = createMathOperation(function(augend, addend) {
  18562. return augend + addend;
  18563. }, 0);
  18564. /**
  18565. * Computes `number` rounded up to `precision`.
  18566. *
  18567. * @static
  18568. * @memberOf _
  18569. * @since 3.10.0
  18570. * @category Math
  18571. * @param {number} number The number to round up.
  18572. * @param {number} [precision=0] The precision to round up to.
  18573. * @returns {number} Returns the rounded up number.
  18574. * @example
  18575. *
  18576. * _.ceil(4.006);
  18577. * // => 5
  18578. *
  18579. * _.ceil(6.004, 2);
  18580. * // => 6.01
  18581. *
  18582. * _.ceil(6040, -2);
  18583. * // => 6100
  18584. */
  18585. var ceil = createRound('ceil');
  18586. /**
  18587. * Divide two numbers.
  18588. *
  18589. * @static
  18590. * @memberOf _
  18591. * @since 4.7.0
  18592. * @category Math
  18593. * @param {number} dividend The first number in a division.
  18594. * @param {number} divisor The second number in a division.
  18595. * @returns {number} Returns the quotient.
  18596. * @example
  18597. *
  18598. * _.divide(6, 4);
  18599. * // => 1.5
  18600. */
  18601. var divide = createMathOperation(function(dividend, divisor) {
  18602. return dividend / divisor;
  18603. }, 1);
  18604. /**
  18605. * Computes `number` rounded down to `precision`.
  18606. *
  18607. * @static
  18608. * @memberOf _
  18609. * @since 3.10.0
  18610. * @category Math
  18611. * @param {number} number The number to round down.
  18612. * @param {number} [precision=0] The precision to round down to.
  18613. * @returns {number} Returns the rounded down number.
  18614. * @example
  18615. *
  18616. * _.floor(4.006);
  18617. * // => 4
  18618. *
  18619. * _.floor(0.046, 2);
  18620. * // => 0.04
  18621. *
  18622. * _.floor(4060, -2);
  18623. * // => 4000
  18624. */
  18625. var floor = createRound('floor');
  18626. /**
  18627. * Computes the maximum value of `array`. If `array` is empty or falsey,
  18628. * `undefined` is returned.
  18629. *
  18630. * @static
  18631. * @since 0.1.0
  18632. * @memberOf _
  18633. * @category Math
  18634. * @param {Array} array The array to iterate over.
  18635. * @returns {*} Returns the maximum value.
  18636. * @example
  18637. *
  18638. * _.max([4, 2, 8, 6]);
  18639. * // => 8
  18640. *
  18641. * _.max([]);
  18642. * // => undefined
  18643. */
  18644. function max(array) {
  18645. return (array && array.length)
  18646. ? baseExtremum(array, identity, baseGt)
  18647. : undefined;
  18648. }
  18649. /**
  18650. * This method is like `_.max` except that it accepts `iteratee` which is
  18651. * invoked for each element in `array` to generate the criterion by which
  18652. * the value is ranked. The iteratee is invoked with one argument: (value).
  18653. *
  18654. * @static
  18655. * @memberOf _
  18656. * @since 4.0.0
  18657. * @category Math
  18658. * @param {Array} array The array to iterate over.
  18659. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  18660. * @returns {*} Returns the maximum value.
  18661. * @example
  18662. *
  18663. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  18664. *
  18665. * _.maxBy(objects, function(o) { return o.n; });
  18666. * // => { 'n': 2 }
  18667. *
  18668. * // The `_.property` iteratee shorthand.
  18669. * _.maxBy(objects, 'n');
  18670. * // => { 'n': 2 }
  18671. */
  18672. function maxBy(array, iteratee) {
  18673. return (array && array.length)
  18674. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  18675. : undefined;
  18676. }
  18677. /**
  18678. * Computes the mean of the values in `array`.
  18679. *
  18680. * @static
  18681. * @memberOf _
  18682. * @since 4.0.0
  18683. * @category Math
  18684. * @param {Array} array The array to iterate over.
  18685. * @returns {number} Returns the mean.
  18686. * @example
  18687. *
  18688. * _.mean([4, 2, 8, 6]);
  18689. * // => 5
  18690. */
  18691. function mean(array) {
  18692. return baseMean(array, identity);
  18693. }
  18694. /**
  18695. * This method is like `_.mean` except that it accepts `iteratee` which is
  18696. * invoked for each element in `array` to generate the value to be averaged.
  18697. * The iteratee is invoked with one argument: (value).
  18698. *
  18699. * @static
  18700. * @memberOf _
  18701. * @since 4.7.0
  18702. * @category Math
  18703. * @param {Array} array The array to iterate over.
  18704. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  18705. * @returns {number} Returns the mean.
  18706. * @example
  18707. *
  18708. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  18709. *
  18710. * _.meanBy(objects, function(o) { return o.n; });
  18711. * // => 5
  18712. *
  18713. * // The `_.property` iteratee shorthand.
  18714. * _.meanBy(objects, 'n');
  18715. * // => 5
  18716. */
  18717. function meanBy(array, iteratee) {
  18718. return baseMean(array, getIteratee(iteratee, 2));
  18719. }
  18720. /**
  18721. * Computes the minimum value of `array`. If `array` is empty or falsey,
  18722. * `undefined` is returned.
  18723. *
  18724. * @static
  18725. * @since 0.1.0
  18726. * @memberOf _
  18727. * @category Math
  18728. * @param {Array} array The array to iterate over.
  18729. * @returns {*} Returns the minimum value.
  18730. * @example
  18731. *
  18732. * _.min([4, 2, 8, 6]);
  18733. * // => 2
  18734. *
  18735. * _.min([]);
  18736. * // => undefined
  18737. */
  18738. function min(array) {
  18739. return (array && array.length)
  18740. ? baseExtremum(array, identity, baseLt)
  18741. : undefined;
  18742. }
  18743. /**
  18744. * This method is like `_.min` except that it accepts `iteratee` which is
  18745. * invoked for each element in `array` to generate the criterion by which
  18746. * the value is ranked. The iteratee is invoked with one argument: (value).
  18747. *
  18748. * @static
  18749. * @memberOf _
  18750. * @since 4.0.0
  18751. * @category Math
  18752. * @param {Array} array The array to iterate over.
  18753. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  18754. * @returns {*} Returns the minimum value.
  18755. * @example
  18756. *
  18757. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  18758. *
  18759. * _.minBy(objects, function(o) { return o.n; });
  18760. * // => { 'n': 1 }
  18761. *
  18762. * // The `_.property` iteratee shorthand.
  18763. * _.minBy(objects, 'n');
  18764. * // => { 'n': 1 }
  18765. */
  18766. function minBy(array, iteratee) {
  18767. return (array && array.length)
  18768. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  18769. : undefined;
  18770. }
  18771. /**
  18772. * Multiply two numbers.
  18773. *
  18774. * @static
  18775. * @memberOf _
  18776. * @since 4.7.0
  18777. * @category Math
  18778. * @param {number} multiplier The first number in a multiplication.
  18779. * @param {number} multiplicand The second number in a multiplication.
  18780. * @returns {number} Returns the product.
  18781. * @example
  18782. *
  18783. * _.multiply(6, 4);
  18784. * // => 24
  18785. */
  18786. var multiply = createMathOperation(function(multiplier, multiplicand) {
  18787. return multiplier * multiplicand;
  18788. }, 1);
  18789. /**
  18790. * Computes `number` rounded to `precision`.
  18791. *
  18792. * @static
  18793. * @memberOf _
  18794. * @since 3.10.0
  18795. * @category Math
  18796. * @param {number} number The number to round.
  18797. * @param {number} [precision=0] The precision to round to.
  18798. * @returns {number} Returns the rounded number.
  18799. * @example
  18800. *
  18801. * _.round(4.006);
  18802. * // => 4
  18803. *
  18804. * _.round(4.006, 2);
  18805. * // => 4.01
  18806. *
  18807. * _.round(4060, -2);
  18808. * // => 4100
  18809. */
  18810. var round = createRound('round');
  18811. /**
  18812. * Subtract two numbers.
  18813. *
  18814. * @static
  18815. * @memberOf _
  18816. * @since 4.0.0
  18817. * @category Math
  18818. * @param {number} minuend The first number in a subtraction.
  18819. * @param {number} subtrahend The second number in a subtraction.
  18820. * @returns {number} Returns the difference.
  18821. * @example
  18822. *
  18823. * _.subtract(6, 4);
  18824. * // => 2
  18825. */
  18826. var subtract = createMathOperation(function(minuend, subtrahend) {
  18827. return minuend - subtrahend;
  18828. }, 0);
  18829. /**
  18830. * Computes the sum of the values in `array`.
  18831. *
  18832. * @static
  18833. * @memberOf _
  18834. * @since 3.4.0
  18835. * @category Math
  18836. * @param {Array} array The array to iterate over.
  18837. * @returns {number} Returns the sum.
  18838. * @example
  18839. *
  18840. * _.sum([4, 2, 8, 6]);
  18841. * // => 20
  18842. */
  18843. function sum(array) {
  18844. return (array && array.length)
  18845. ? baseSum(array, identity)
  18846. : 0;
  18847. }
  18848. /**
  18849. * This method is like `_.sum` except that it accepts `iteratee` which is
  18850. * invoked for each element in `array` to generate the value to be summed.
  18851. * The iteratee is invoked with one argument: (value).
  18852. *
  18853. * @static
  18854. * @memberOf _
  18855. * @since 4.0.0
  18856. * @category Math
  18857. * @param {Array} array The array to iterate over.
  18858. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  18859. * @returns {number} Returns the sum.
  18860. * @example
  18861. *
  18862. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  18863. *
  18864. * _.sumBy(objects, function(o) { return o.n; });
  18865. * // => 20
  18866. *
  18867. * // The `_.property` iteratee shorthand.
  18868. * _.sumBy(objects, 'n');
  18869. * // => 20
  18870. */
  18871. function sumBy(array, iteratee) {
  18872. return (array && array.length)
  18873. ? baseSum(array, getIteratee(iteratee, 2))
  18874. : 0;
  18875. }
  18876. /*------------------------------------------------------------------------*/
  18877. // Add methods that return wrapped values in chain sequences.
  18878. lodash.after = after;
  18879. lodash.ary = ary;
  18880. lodash.assign = assign;
  18881. lodash.assignIn = assignIn;
  18882. lodash.assignInWith = assignInWith;
  18883. lodash.assignWith = assignWith;
  18884. lodash.at = at;
  18885. lodash.before = before;
  18886. lodash.bind = bind;
  18887. lodash.bindAll = bindAll;
  18888. lodash.bindKey = bindKey;
  18889. lodash.castArray = castArray;
  18890. lodash.chain = chain;
  18891. lodash.chunk = chunk;
  18892. lodash.compact = compact;
  18893. lodash.concat = concat;
  18894. lodash.cond = cond;
  18895. lodash.conforms = conforms;
  18896. lodash.constant = constant;
  18897. lodash.countBy = countBy;
  18898. lodash.create = create;
  18899. lodash.curry = curry;
  18900. lodash.curryRight = curryRight;
  18901. lodash.debounce = debounce;
  18902. lodash.defaults = defaults;
  18903. lodash.defaultsDeep = defaultsDeep;
  18904. lodash.defer = defer;
  18905. lodash.delay = delay;
  18906. lodash.difference = difference;
  18907. lodash.differenceBy = differenceBy;
  18908. lodash.differenceWith = differenceWith;
  18909. lodash.drop = drop;
  18910. lodash.dropRight = dropRight;
  18911. lodash.dropRightWhile = dropRightWhile;
  18912. lodash.dropWhile = dropWhile;
  18913. lodash.fill = fill;
  18914. lodash.filter = filter;
  18915. lodash.flatMap = flatMap;
  18916. lodash.flatMapDeep = flatMapDeep;
  18917. lodash.flatMapDepth = flatMapDepth;
  18918. lodash.flatten = flatten;
  18919. lodash.flattenDeep = flattenDeep;
  18920. lodash.flattenDepth = flattenDepth;
  18921. lodash.flip = flip;
  18922. lodash.flow = flow;
  18923. lodash.flowRight = flowRight;
  18924. lodash.fromPairs = fromPairs;
  18925. lodash.functions = functions;
  18926. lodash.functionsIn = functionsIn;
  18927. lodash.groupBy = groupBy;
  18928. lodash.initial = initial;
  18929. lodash.intersection = intersection;
  18930. lodash.intersectionBy = intersectionBy;
  18931. lodash.intersectionWith = intersectionWith;
  18932. lodash.invert = invert;
  18933. lodash.invertBy = invertBy;
  18934. lodash.invokeMap = invokeMap;
  18935. lodash.iteratee = iteratee;
  18936. lodash.keyBy = keyBy;
  18937. lodash.keys = keys;
  18938. lodash.keysIn = keysIn;
  18939. lodash.map = map;
  18940. lodash.mapKeys = mapKeys;
  18941. lodash.mapValues = mapValues;
  18942. lodash.matches = matches;
  18943. lodash.matchesProperty = matchesProperty;
  18944. lodash.memoize = memoize;
  18945. lodash.merge = merge;
  18946. lodash.mergeWith = mergeWith;
  18947. lodash.method = method;
  18948. lodash.methodOf = methodOf;
  18949. lodash.mixin = mixin;
  18950. lodash.negate = negate;
  18951. lodash.nthArg = nthArg;
  18952. lodash.omit = omit;
  18953. lodash.omitBy = omitBy;
  18954. lodash.once = once;
  18955. lodash.orderBy = orderBy;
  18956. lodash.over = over;
  18957. lodash.overArgs = overArgs;
  18958. lodash.overEvery = overEvery;
  18959. lodash.overSome = overSome;
  18960. lodash.partial = partial;
  18961. lodash.partialRight = partialRight;
  18962. lodash.partition = partition;
  18963. lodash.pick = pick;
  18964. lodash.pickBy = pickBy;
  18965. lodash.property = property;
  18966. lodash.propertyOf = propertyOf;
  18967. lodash.pull = pull;
  18968. lodash.pullAll = pullAll;
  18969. lodash.pullAllBy = pullAllBy;
  18970. lodash.pullAllWith = pullAllWith;
  18971. lodash.pullAt = pullAt;
  18972. lodash.range = range;
  18973. lodash.rangeRight = rangeRight;
  18974. lodash.rearg = rearg;
  18975. lodash.reject = reject;
  18976. lodash.remove = remove;
  18977. lodash.rest = rest;
  18978. lodash.reverse = reverse;
  18979. lodash.sampleSize = sampleSize;
  18980. lodash.set = set;
  18981. lodash.setWith = setWith;
  18982. lodash.shuffle = shuffle;
  18983. lodash.slice = slice;
  18984. lodash.sortBy = sortBy;
  18985. lodash.sortedUniq = sortedUniq;
  18986. lodash.sortedUniqBy = sortedUniqBy;
  18987. lodash.split = split;
  18988. lodash.spread = spread;
  18989. lodash.tail = tail;
  18990. lodash.take = take;
  18991. lodash.takeRight = takeRight;
  18992. lodash.takeRightWhile = takeRightWhile;
  18993. lodash.takeWhile = takeWhile;
  18994. lodash.tap = tap;
  18995. lodash.throttle = throttle;
  18996. lodash.thru = thru;
  18997. lodash.toArray = toArray;
  18998. lodash.toPairs = toPairs;
  18999. lodash.toPairsIn = toPairsIn;
  19000. lodash.toPath = toPath;
  19001. lodash.toPlainObject = toPlainObject;
  19002. lodash.transform = transform;
  19003. lodash.unary = unary;
  19004. lodash.union = union;
  19005. lodash.unionBy = unionBy;
  19006. lodash.unionWith = unionWith;
  19007. lodash.uniq = uniq;
  19008. lodash.uniqBy = uniqBy;
  19009. lodash.uniqWith = uniqWith;
  19010. lodash.unset = unset;
  19011. lodash.unzip = unzip;
  19012. lodash.unzipWith = unzipWith;
  19013. lodash.update = update;
  19014. lodash.updateWith = updateWith;
  19015. lodash.values = values;
  19016. lodash.valuesIn = valuesIn;
  19017. lodash.without = without;
  19018. lodash.words = words;
  19019. lodash.wrap = wrap;
  19020. lodash.xor = xor;
  19021. lodash.xorBy = xorBy;
  19022. lodash.xorWith = xorWith;
  19023. lodash.zip = zip;
  19024. lodash.zipObject = zipObject;
  19025. lodash.zipObjectDeep = zipObjectDeep;
  19026. lodash.zipWith = zipWith;
  19027. // Add aliases.
  19028. lodash.entries = toPairs;
  19029. lodash.entriesIn = toPairsIn;
  19030. lodash.extend = assignIn;
  19031. lodash.extendWith = assignInWith;
  19032. // Add methods to `lodash.prototype`.
  19033. mixin(lodash, lodash);
  19034. /*------------------------------------------------------------------------*/
  19035. // Add methods that return unwrapped values in chain sequences.
  19036. lodash.add = add;
  19037. lodash.attempt = attempt;
  19038. lodash.camelCase = camelCase;
  19039. lodash.capitalize = capitalize;
  19040. lodash.ceil = ceil;
  19041. lodash.clamp = clamp;
  19042. lodash.clone = clone;
  19043. lodash.cloneDeep = cloneDeep;
  19044. lodash.cloneDeepWith = cloneDeepWith;
  19045. lodash.cloneWith = cloneWith;
  19046. lodash.conformsTo = conformsTo;
  19047. lodash.deburr = deburr;
  19048. lodash.defaultTo = defaultTo;
  19049. lodash.divide = divide;
  19050. lodash.endsWith = endsWith;
  19051. lodash.eq = eq;
  19052. lodash.escape = escape;
  19053. lodash.escapeRegExp = escapeRegExp;
  19054. lodash.every = every;
  19055. lodash.find = find;
  19056. lodash.findIndex = findIndex;
  19057. lodash.findKey = findKey;
  19058. lodash.findLast = findLast;
  19059. lodash.findLastIndex = findLastIndex;
  19060. lodash.findLastKey = findLastKey;
  19061. lodash.floor = floor;
  19062. lodash.forEach = forEach;
  19063. lodash.forEachRight = forEachRight;
  19064. lodash.forIn = forIn;
  19065. lodash.forInRight = forInRight;
  19066. lodash.forOwn = forOwn;
  19067. lodash.forOwnRight = forOwnRight;
  19068. lodash.get = get;
  19069. lodash.gt = gt;
  19070. lodash.gte = gte;
  19071. lodash.has = has;
  19072. lodash.hasIn = hasIn;
  19073. lodash.head = head;
  19074. lodash.identity = identity;
  19075. lodash.includes = includes;
  19076. lodash.indexOf = indexOf;
  19077. lodash.inRange = inRange;
  19078. lodash.invoke = invoke;
  19079. lodash.isArguments = isArguments;
  19080. lodash.isArray = isArray;
  19081. lodash.isArrayBuffer = isArrayBuffer;
  19082. lodash.isArrayLike = isArrayLike;
  19083. lodash.isArrayLikeObject = isArrayLikeObject;
  19084. lodash.isBoolean = isBoolean;
  19085. lodash.isBuffer = isBuffer;
  19086. lodash.isDate = isDate;
  19087. lodash.isElement = isElement;
  19088. lodash.isEmpty = isEmpty;
  19089. lodash.isEqual = isEqual;
  19090. lodash.isEqualWith = isEqualWith;
  19091. lodash.isError = isError;
  19092. lodash.isFinite = isFinite;
  19093. lodash.isFunction = isFunction;
  19094. lodash.isInteger = isInteger;
  19095. lodash.isLength = isLength;
  19096. lodash.isMap = isMap;
  19097. lodash.isMatch = isMatch;
  19098. lodash.isMatchWith = isMatchWith;
  19099. lodash.isNaN = isNaN;
  19100. lodash.isNative = isNative;
  19101. lodash.isNil = isNil;
  19102. lodash.isNull = isNull;
  19103. lodash.isNumber = isNumber;
  19104. lodash.isObject = isObject;
  19105. lodash.isObjectLike = isObjectLike;
  19106. lodash.isPlainObject = isPlainObject;
  19107. lodash.isRegExp = isRegExp;
  19108. lodash.isSafeInteger = isSafeInteger;
  19109. lodash.isSet = isSet;
  19110. lodash.isString = isString;
  19111. lodash.isSymbol = isSymbol;
  19112. lodash.isTypedArray = isTypedArray;
  19113. lodash.isUndefined = isUndefined;
  19114. lodash.isWeakMap = isWeakMap;
  19115. lodash.isWeakSet = isWeakSet;
  19116. lodash.join = join;
  19117. lodash.kebabCase = kebabCase;
  19118. lodash.last = last;
  19119. lodash.lastIndexOf = lastIndexOf;
  19120. lodash.lowerCase = lowerCase;
  19121. lodash.lowerFirst = lowerFirst;
  19122. lodash.lt = lt;
  19123. lodash.lte = lte;
  19124. lodash.max = max;
  19125. lodash.maxBy = maxBy;
  19126. lodash.mean = mean;
  19127. lodash.meanBy = meanBy;
  19128. lodash.min = min;
  19129. lodash.minBy = minBy;
  19130. lodash.stubArray = stubArray;
  19131. lodash.stubFalse = stubFalse;
  19132. lodash.stubObject = stubObject;
  19133. lodash.stubString = stubString;
  19134. lodash.stubTrue = stubTrue;
  19135. lodash.multiply = multiply;
  19136. lodash.nth = nth;
  19137. lodash.noConflict = noConflict;
  19138. lodash.noop = noop;
  19139. lodash.now = now;
  19140. lodash.pad = pad;
  19141. lodash.padEnd = padEnd;
  19142. lodash.padStart = padStart;
  19143. lodash.parseInt = parseInt;
  19144. lodash.random = random;
  19145. lodash.reduce = reduce;
  19146. lodash.reduceRight = reduceRight;
  19147. lodash.repeat = repeat;
  19148. lodash.replace = replace;
  19149. lodash.result = result;
  19150. lodash.round = round;
  19151. lodash.runInContext = runInContext;
  19152. lodash.sample = sample;
  19153. lodash.size = size;
  19154. lodash.snakeCase = snakeCase;
  19155. lodash.some = some;
  19156. lodash.sortedIndex = sortedIndex;
  19157. lodash.sortedIndexBy = sortedIndexBy;
  19158. lodash.sortedIndexOf = sortedIndexOf;
  19159. lodash.sortedLastIndex = sortedLastIndex;
  19160. lodash.sortedLastIndexBy = sortedLastIndexBy;
  19161. lodash.sortedLastIndexOf = sortedLastIndexOf;
  19162. lodash.startCase = startCase;
  19163. lodash.startsWith = startsWith;
  19164. lodash.subtract = subtract;
  19165. lodash.sum = sum;
  19166. lodash.sumBy = sumBy;
  19167. lodash.template = template;
  19168. lodash.times = times;
  19169. lodash.toFinite = toFinite;
  19170. lodash.toInteger = toInteger;
  19171. lodash.toLength = toLength;
  19172. lodash.toLower = toLower;
  19173. lodash.toNumber = toNumber;
  19174. lodash.toSafeInteger = toSafeInteger;
  19175. lodash.toString = toString;
  19176. lodash.toUpper = toUpper;
  19177. lodash.trim = trim;
  19178. lodash.trimEnd = trimEnd;
  19179. lodash.trimStart = trimStart;
  19180. lodash.truncate = truncate;
  19181. lodash.unescape = unescape;
  19182. lodash.uniqueId = uniqueId;
  19183. lodash.upperCase = upperCase;
  19184. lodash.upperFirst = upperFirst;
  19185. // Add aliases.
  19186. lodash.each = forEach;
  19187. lodash.eachRight = forEachRight;
  19188. lodash.first = head;
  19189. mixin(lodash, (function() {
  19190. var source = {};
  19191. baseForOwn(lodash, function(func, methodName) {
  19192. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  19193. source[methodName] = func;
  19194. }
  19195. });
  19196. return source;
  19197. }()), { 'chain': false });
  19198. /*------------------------------------------------------------------------*/
  19199. /**
  19200. * The semantic version number.
  19201. *
  19202. * @static
  19203. * @memberOf _
  19204. * @type {string}
  19205. */
  19206. lodash.VERSION = VERSION;
  19207. // Assign default placeholders.
  19208. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  19209. lodash[methodName].placeholder = lodash;
  19210. });
  19211. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  19212. arrayEach(['drop', 'take'], function(methodName, index) {
  19213. LazyWrapper.prototype[methodName] = function(n) {
  19214. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  19215. var result = (this.__filtered__ && !index)
  19216. ? new LazyWrapper(this)
  19217. : this.clone();
  19218. if (result.__filtered__) {
  19219. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  19220. } else {
  19221. result.__views__.push({
  19222. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  19223. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  19224. });
  19225. }
  19226. return result;
  19227. };
  19228. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  19229. return this.reverse()[methodName](n).reverse();
  19230. };
  19231. });
  19232. // Add `LazyWrapper` methods that accept an `iteratee` value.
  19233. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  19234. var type = index + 1,
  19235. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  19236. LazyWrapper.prototype[methodName] = function(iteratee) {
  19237. var result = this.clone();
  19238. result.__iteratees__.push({
  19239. 'iteratee': getIteratee(iteratee, 3),
  19240. 'type': type
  19241. });
  19242. result.__filtered__ = result.__filtered__ || isFilter;
  19243. return result;
  19244. };
  19245. });
  19246. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  19247. arrayEach(['head', 'last'], function(methodName, index) {
  19248. var takeName = 'take' + (index ? 'Right' : '');
  19249. LazyWrapper.prototype[methodName] = function() {
  19250. return this[takeName](1).value()[0];
  19251. };
  19252. });
  19253. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  19254. arrayEach(['initial', 'tail'], function(methodName, index) {
  19255. var dropName = 'drop' + (index ? '' : 'Right');
  19256. LazyWrapper.prototype[methodName] = function() {
  19257. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  19258. };
  19259. });
  19260. LazyWrapper.prototype.compact = function() {
  19261. return this.filter(identity);
  19262. };
  19263. LazyWrapper.prototype.find = function(predicate) {
  19264. return this.filter(predicate).head();
  19265. };
  19266. LazyWrapper.prototype.findLast = function(predicate) {
  19267. return this.reverse().find(predicate);
  19268. };
  19269. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  19270. if (typeof path == 'function') {
  19271. return new LazyWrapper(this);
  19272. }
  19273. return this.map(function(value) {
  19274. return baseInvoke(value, path, args);
  19275. });
  19276. });
  19277. LazyWrapper.prototype.reject = function(predicate) {
  19278. return this.filter(negate(getIteratee(predicate)));
  19279. };
  19280. LazyWrapper.prototype.slice = function(start, end) {
  19281. start = toInteger(start);
  19282. var result = this;
  19283. if (result.__filtered__ && (start > 0 || end < 0)) {
  19284. return new LazyWrapper(result);
  19285. }
  19286. if (start < 0) {
  19287. result = result.takeRight(-start);
  19288. } else if (start) {
  19289. result = result.drop(start);
  19290. }
  19291. if (end !== undefined) {
  19292. end = toInteger(end);
  19293. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  19294. }
  19295. return result;
  19296. };
  19297. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  19298. return this.reverse().takeWhile(predicate).reverse();
  19299. };
  19300. LazyWrapper.prototype.toArray = function() {
  19301. return this.take(MAX_ARRAY_LENGTH);
  19302. };
  19303. // Add `LazyWrapper` methods to `lodash.prototype`.
  19304. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  19305. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  19306. isTaker = /^(?:head|last)$/.test(methodName),
  19307. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  19308. retUnwrapped = isTaker || /^find/.test(methodName);
  19309. if (!lodashFunc) {
  19310. return;
  19311. }
  19312. lodash.prototype[methodName] = function() {
  19313. var value = this.__wrapped__,
  19314. args = isTaker ? [1] : arguments,
  19315. isLazy = value instanceof LazyWrapper,
  19316. iteratee = args[0],
  19317. useLazy = isLazy || isArray(value);
  19318. var interceptor = function(value) {
  19319. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  19320. return (isTaker && chainAll) ? result[0] : result;
  19321. };
  19322. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  19323. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  19324. isLazy = useLazy = false;
  19325. }
  19326. var chainAll = this.__chain__,
  19327. isHybrid = !!this.__actions__.length,
  19328. isUnwrapped = retUnwrapped && !chainAll,
  19329. onlyLazy = isLazy && !isHybrid;
  19330. if (!retUnwrapped && useLazy) {
  19331. value = onlyLazy ? value : new LazyWrapper(this);
  19332. var result = func.apply(value, args);
  19333. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  19334. return new LodashWrapper(result, chainAll);
  19335. }
  19336. if (isUnwrapped && onlyLazy) {
  19337. return func.apply(this, args);
  19338. }
  19339. result = this.thru(interceptor);
  19340. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  19341. };
  19342. });
  19343. // Add `Array` methods to `lodash.prototype`.
  19344. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  19345. var func = arrayProto[methodName],
  19346. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  19347. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  19348. lodash.prototype[methodName] = function() {
  19349. var args = arguments;
  19350. if (retUnwrapped && !this.__chain__) {
  19351. var value = this.value();
  19352. return func.apply(isArray(value) ? value : [], args);
  19353. }
  19354. return this[chainName](function(value) {
  19355. return func.apply(isArray(value) ? value : [], args);
  19356. });
  19357. };
  19358. });
  19359. // Map minified method names to their real names.
  19360. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  19361. var lodashFunc = lodash[methodName];
  19362. if (lodashFunc) {
  19363. var key = lodashFunc.name + '';
  19364. if (!hasOwnProperty.call(realNames, key)) {
  19365. realNames[key] = [];
  19366. }
  19367. realNames[key].push({ 'name': methodName, 'func': lodashFunc });
  19368. }
  19369. });
  19370. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  19371. 'name': 'wrapper',
  19372. 'func': undefined
  19373. }];
  19374. // Add methods to `LazyWrapper`.
  19375. LazyWrapper.prototype.clone = lazyClone;
  19376. LazyWrapper.prototype.reverse = lazyReverse;
  19377. LazyWrapper.prototype.value = lazyValue;
  19378. // Add chain sequence methods to the `lodash` wrapper.
  19379. lodash.prototype.at = wrapperAt;
  19380. lodash.prototype.chain = wrapperChain;
  19381. lodash.prototype.commit = wrapperCommit;
  19382. lodash.prototype.next = wrapperNext;
  19383. lodash.prototype.plant = wrapperPlant;
  19384. lodash.prototype.reverse = wrapperReverse;
  19385. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  19386. // Add lazy aliases.
  19387. lodash.prototype.first = lodash.prototype.head;
  19388. if (symIterator) {
  19389. lodash.prototype[symIterator] = wrapperToIterator;
  19390. }
  19391. return lodash;
  19392. });
  19393. /*--------------------------------------------------------------------------*/
  19394. // Export lodash.
  19395. var _ = runInContext();
  19396. // Some AMD build optimizers, like r.js, check for condition patterns like:
  19397. if (true) {
  19398. // Expose Lodash on the global object to prevent errors when Lodash is
  19399. // loaded by a script tag in the presence of an AMD loader.
  19400. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  19401. // Use `_.noConflict` to remove Lodash from the global object.
  19402. root._ = _;
  19403. // Define as an anonymous module so, through path mapping, it can be
  19404. // referenced as the "underscore" module.
  19405. !(__WEBPACK_AMD_DEFINE_RESULT__ = (function() {
  19406. return _;
  19407. }).call(exports, __webpack_require__, exports, module),
  19408. __WEBPACK_AMD_DEFINE_RESULT__ !== undefined && (module.exports = __WEBPACK_AMD_DEFINE_RESULT__));
  19409. }
  19410. // Check for `exports` after `define` in case a build optimizer adds it.
  19411. else {}
  19412. }.call(this));
  19413. /***/ }),
  19414. /***/ "./resources/css/app.css":
  19415. /*!*******************************!*\
  19416. !*** ./resources/css/app.css ***!
  19417. \*******************************/
  19418. /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
  19419. "use strict";
  19420. __webpack_require__.r(__webpack_exports__);
  19421. // extracted by mini-css-extract-plugin
  19422. /***/ }),
  19423. /***/ "./node_modules/process/browser.js":
  19424. /*!*****************************************!*\
  19425. !*** ./node_modules/process/browser.js ***!
  19426. \*****************************************/
  19427. /***/ ((module) => {
  19428. // shim for using process in browser
  19429. var process = module.exports = {};
  19430. // cached from whatever global is present so that test runners that stub it
  19431. // don't break things. But we need to wrap it in a try catch in case it is
  19432. // wrapped in strict mode code which doesn't define any globals. It's inside a
  19433. // function because try/catches deoptimize in certain engines.
  19434. var cachedSetTimeout;
  19435. var cachedClearTimeout;
  19436. function defaultSetTimout() {
  19437. throw new Error('setTimeout has not been defined');
  19438. }
  19439. function defaultClearTimeout () {
  19440. throw new Error('clearTimeout has not been defined');
  19441. }
  19442. (function () {
  19443. try {
  19444. if (typeof setTimeout === 'function') {
  19445. cachedSetTimeout = setTimeout;
  19446. } else {
  19447. cachedSetTimeout = defaultSetTimout;
  19448. }
  19449. } catch (e) {
  19450. cachedSetTimeout = defaultSetTimout;
  19451. }
  19452. try {
  19453. if (typeof clearTimeout === 'function') {
  19454. cachedClearTimeout = clearTimeout;
  19455. } else {
  19456. cachedClearTimeout = defaultClearTimeout;
  19457. }
  19458. } catch (e) {
  19459. cachedClearTimeout = defaultClearTimeout;
  19460. }
  19461. } ())
  19462. function runTimeout(fun) {
  19463. if (cachedSetTimeout === setTimeout) {
  19464. //normal enviroments in sane situations
  19465. return setTimeout(fun, 0);
  19466. }
  19467. // if setTimeout wasn't available but was latter defined
  19468. if ((cachedSetTimeout === defaultSetTimout || !cachedSetTimeout) && setTimeout) {
  19469. cachedSetTimeout = setTimeout;
  19470. return setTimeout(fun, 0);
  19471. }
  19472. try {
  19473. // when when somebody has screwed with setTimeout but no I.E. maddness
  19474. return cachedSetTimeout(fun, 0);
  19475. } catch(e){
  19476. try {
  19477. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  19478. return cachedSetTimeout.call(null, fun, 0);
  19479. } catch(e){
  19480. // 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
  19481. return cachedSetTimeout.call(this, fun, 0);
  19482. }
  19483. }
  19484. }
  19485. function runClearTimeout(marker) {
  19486. if (cachedClearTimeout === clearTimeout) {
  19487. //normal enviroments in sane situations
  19488. return clearTimeout(marker);
  19489. }
  19490. // if clearTimeout wasn't available but was latter defined
  19491. if ((cachedClearTimeout === defaultClearTimeout || !cachedClearTimeout) && clearTimeout) {
  19492. cachedClearTimeout = clearTimeout;
  19493. return clearTimeout(marker);
  19494. }
  19495. try {
  19496. // when when somebody has screwed with setTimeout but no I.E. maddness
  19497. return cachedClearTimeout(marker);
  19498. } catch (e){
  19499. try {
  19500. // When we are in I.E. but the script has been evaled so I.E. doesn't trust the global object when called normally
  19501. return cachedClearTimeout.call(null, marker);
  19502. } catch (e){
  19503. // 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.
  19504. // Some versions of I.E. have different rules for clearTimeout vs setTimeout
  19505. return cachedClearTimeout.call(this, marker);
  19506. }
  19507. }
  19508. }
  19509. var queue = [];
  19510. var draining = false;
  19511. var currentQueue;
  19512. var queueIndex = -1;
  19513. function cleanUpNextTick() {
  19514. if (!draining || !currentQueue) {
  19515. return;
  19516. }
  19517. draining = false;
  19518. if (currentQueue.length) {
  19519. queue = currentQueue.concat(queue);
  19520. } else {
  19521. queueIndex = -1;
  19522. }
  19523. if (queue.length) {
  19524. drainQueue();
  19525. }
  19526. }
  19527. function drainQueue() {
  19528. if (draining) {
  19529. return;
  19530. }
  19531. var timeout = runTimeout(cleanUpNextTick);
  19532. draining = true;
  19533. var len = queue.length;
  19534. while(len) {
  19535. currentQueue = queue;
  19536. queue = [];
  19537. while (++queueIndex < len) {
  19538. if (currentQueue) {
  19539. currentQueue[queueIndex].run();
  19540. }
  19541. }
  19542. queueIndex = -1;
  19543. len = queue.length;
  19544. }
  19545. currentQueue = null;
  19546. draining = false;
  19547. runClearTimeout(timeout);
  19548. }
  19549. process.nextTick = function (fun) {
  19550. var args = new Array(arguments.length - 1);
  19551. if (arguments.length > 1) {
  19552. for (var i = 1; i < arguments.length; i++) {
  19553. args[i - 1] = arguments[i];
  19554. }
  19555. }
  19556. queue.push(new Item(fun, args));
  19557. if (queue.length === 1 && !draining) {
  19558. runTimeout(drainQueue);
  19559. }
  19560. };
  19561. // v8 likes predictible objects
  19562. function Item(fun, array) {
  19563. this.fun = fun;
  19564. this.array = array;
  19565. }
  19566. Item.prototype.run = function () {
  19567. this.fun.apply(null, this.array);
  19568. };
  19569. process.title = 'browser';
  19570. process.browser = true;
  19571. process.env = {};
  19572. process.argv = [];
  19573. process.version = ''; // empty string to avoid regexp issues
  19574. process.versions = {};
  19575. function noop() {}
  19576. process.on = noop;
  19577. process.addListener = noop;
  19578. process.once = noop;
  19579. process.off = noop;
  19580. process.removeListener = noop;
  19581. process.removeAllListeners = noop;
  19582. process.emit = noop;
  19583. process.prependListener = noop;
  19584. process.prependOnceListener = noop;
  19585. process.listeners = function (name) { return [] }
  19586. process.binding = function (name) {
  19587. throw new Error('process.binding is not supported');
  19588. };
  19589. process.cwd = function () { return '/' };
  19590. process.chdir = function (dir) {
  19591. throw new Error('process.chdir is not supported');
  19592. };
  19593. process.umask = function() { return 0; };
  19594. /***/ })
  19595. /******/ });
  19596. /************************************************************************/
  19597. /******/ // The module cache
  19598. /******/ var __webpack_module_cache__ = {};
  19599. /******/
  19600. /******/ // The require function
  19601. /******/ function __webpack_require__(moduleId) {
  19602. /******/ // Check if module is in cache
  19603. /******/ var cachedModule = __webpack_module_cache__[moduleId];
  19604. /******/ if (cachedModule !== undefined) {
  19605. /******/ return cachedModule.exports;
  19606. /******/ }
  19607. /******/ // Create a new module (and put it into the cache)
  19608. /******/ var module = __webpack_module_cache__[moduleId] = {
  19609. /******/ id: moduleId,
  19610. /******/ loaded: false,
  19611. /******/ exports: {}
  19612. /******/ };
  19613. /******/
  19614. /******/ // Execute the module function
  19615. /******/ __webpack_modules__[moduleId].call(module.exports, module, module.exports, __webpack_require__);
  19616. /******/
  19617. /******/ // Flag the module as loaded
  19618. /******/ module.loaded = true;
  19619. /******/
  19620. /******/ // Return the exports of the module
  19621. /******/ return module.exports;
  19622. /******/ }
  19623. /******/
  19624. /******/ // expose the modules object (__webpack_modules__)
  19625. /******/ __webpack_require__.m = __webpack_modules__;
  19626. /******/
  19627. /************************************************************************/
  19628. /******/ /* webpack/runtime/chunk loaded */
  19629. /******/ (() => {
  19630. /******/ var deferred = [];
  19631. /******/ __webpack_require__.O = (result, chunkIds, fn, priority) => {
  19632. /******/ if(chunkIds) {
  19633. /******/ priority = priority || 0;
  19634. /******/ for(var i = deferred.length; i > 0 && deferred[i - 1][2] > priority; i--) deferred[i] = deferred[i - 1];
  19635. /******/ deferred[i] = [chunkIds, fn, priority];
  19636. /******/ return;
  19637. /******/ }
  19638. /******/ var notFulfilled = Infinity;
  19639. /******/ for (var i = 0; i < deferred.length; i++) {
  19640. /******/ var [chunkIds, fn, priority] = deferred[i];
  19641. /******/ var fulfilled = true;
  19642. /******/ for (var j = 0; j < chunkIds.length; j++) {
  19643. /******/ if ((priority & 1 === 0 || notFulfilled >= priority) && Object.keys(__webpack_require__.O).every((key) => (__webpack_require__.O[key](chunkIds[j])))) {
  19644. /******/ chunkIds.splice(j--, 1);
  19645. /******/ } else {
  19646. /******/ fulfilled = false;
  19647. /******/ if(priority < notFulfilled) notFulfilled = priority;
  19648. /******/ }
  19649. /******/ }
  19650. /******/ if(fulfilled) {
  19651. /******/ deferred.splice(i--, 1)
  19652. /******/ result = fn();
  19653. /******/ }
  19654. /******/ }
  19655. /******/ return result;
  19656. /******/ };
  19657. /******/ })();
  19658. /******/
  19659. /******/ /* webpack/runtime/global */
  19660. /******/ (() => {
  19661. /******/ __webpack_require__.g = (function() {
  19662. /******/ if (typeof globalThis === 'object') return globalThis;
  19663. /******/ try {
  19664. /******/ return this || new Function('return this')();
  19665. /******/ } catch (e) {
  19666. /******/ if (typeof window === 'object') return window;
  19667. /******/ }
  19668. /******/ })();
  19669. /******/ })();
  19670. /******/
  19671. /******/ /* webpack/runtime/hasOwnProperty shorthand */
  19672. /******/ (() => {
  19673. /******/ __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
  19674. /******/ })();
  19675. /******/
  19676. /******/ /* webpack/runtime/make namespace object */
  19677. /******/ (() => {
  19678. /******/ // define __esModule on exports
  19679. /******/ __webpack_require__.r = (exports) => {
  19680. /******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
  19681. /******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
  19682. /******/ }
  19683. /******/ Object.defineProperty(exports, '__esModule', { value: true });
  19684. /******/ };
  19685. /******/ })();
  19686. /******/
  19687. /******/ /* webpack/runtime/node module decorator */
  19688. /******/ (() => {
  19689. /******/ __webpack_require__.nmd = (module) => {
  19690. /******/ module.paths = [];
  19691. /******/ if (!module.children) module.children = [];
  19692. /******/ return module;
  19693. /******/ };
  19694. /******/ })();
  19695. /******/
  19696. /******/ /* webpack/runtime/jsonp chunk loading */
  19697. /******/ (() => {
  19698. /******/ // no baseURI
  19699. /******/
  19700. /******/ // object to store loaded and loading chunks
  19701. /******/ // undefined = chunk not loaded, null = chunk preloaded/prefetched
  19702. /******/ // [resolve, reject, Promise] = chunk loading, 0 = chunk loaded
  19703. /******/ var installedChunks = {
  19704. /******/ "/js/app": 0,
  19705. /******/ "css/app": 0
  19706. /******/ };
  19707. /******/
  19708. /******/ // no chunk on demand loading
  19709. /******/
  19710. /******/ // no prefetching
  19711. /******/
  19712. /******/ // no preloaded
  19713. /******/
  19714. /******/ // no HMR
  19715. /******/
  19716. /******/ // no HMR manifest
  19717. /******/
  19718. /******/ __webpack_require__.O.j = (chunkId) => (installedChunks[chunkId] === 0);
  19719. /******/
  19720. /******/ // install a JSONP callback for chunk loading
  19721. /******/ var webpackJsonpCallback = (parentChunkLoadingFunction, data) => {
  19722. /******/ var [chunkIds, moreModules, runtime] = data;
  19723. /******/ // add "moreModules" to the modules object,
  19724. /******/ // then flag all "chunkIds" as loaded and fire callback
  19725. /******/ var moduleId, chunkId, i = 0;
  19726. /******/ for(moduleId in moreModules) {
  19727. /******/ if(__webpack_require__.o(moreModules, moduleId)) {
  19728. /******/ __webpack_require__.m[moduleId] = moreModules[moduleId];
  19729. /******/ }
  19730. /******/ }
  19731. /******/ if(runtime) var result = runtime(__webpack_require__);
  19732. /******/ if(parentChunkLoadingFunction) parentChunkLoadingFunction(data);
  19733. /******/ for(;i < chunkIds.length; i++) {
  19734. /******/ chunkId = chunkIds[i];
  19735. /******/ if(__webpack_require__.o(installedChunks, chunkId) && installedChunks[chunkId]) {
  19736. /******/ installedChunks[chunkId][0]();
  19737. /******/ }
  19738. /******/ installedChunks[chunkIds[i]] = 0;
  19739. /******/ }
  19740. /******/ return __webpack_require__.O(result);
  19741. /******/ }
  19742. /******/
  19743. /******/ var chunkLoadingGlobal = self["webpackChunk"] = self["webpackChunk"] || [];
  19744. /******/ chunkLoadingGlobal.forEach(webpackJsonpCallback.bind(null, 0));
  19745. /******/ chunkLoadingGlobal.push = webpackJsonpCallback.bind(null, chunkLoadingGlobal.push.bind(chunkLoadingGlobal));
  19746. /******/ })();
  19747. /******/
  19748. /************************************************************************/
  19749. /******/
  19750. /******/ // startup
  19751. /******/ // Load entry module and return exports
  19752. /******/ // This entry module depends on other loaded chunks and execution need to be delayed
  19753. /******/ __webpack_require__.O(undefined, ["css/app"], () => (__webpack_require__("./resources/js/app.js")))
  19754. /******/ var __webpack_exports__ = __webpack_require__.O(undefined, ["css/app"], () => (__webpack_require__("./resources/css/app.css")))
  19755. /******/ __webpack_exports__ = __webpack_require__.O(__webpack_exports__);
  19756. /******/
  19757. /******/ })()
  19758. ;