index.js 533 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222
  1. module.exports = (function() {
  2. var __MODS__ = {};
  3. var __DEFINE__ = function(modId, func, req) { var m = { exports: {}, _tempexports: {} }; __MODS__[modId] = { status: 0, func: func, req: req, m: m }; };
  4. var __REQUIRE__ = function(modId, source) { if(!__MODS__[modId]) return require(source); if(!__MODS__[modId].status) { var m = __MODS__[modId].m; m._exports = m._tempexports; var desp = Object.getOwnPropertyDescriptor(m, "exports"); if (desp && desp.configurable) Object.defineProperty(m, "exports", { set: function (val) { if(typeof val === "object" && val !== m._exports) { m._exports.__proto__ = val.__proto__; Object.keys(val).forEach(function (k) { m._exports[k] = val[k]; }); } m._tempexports = val }, get: function () { return m._tempexports; } }); __MODS__[modId].status = 1; __MODS__[modId].func(__MODS__[modId].req, m, m.exports); } return __MODS__[modId].m.exports; };
  5. var __REQUIRE_WILDCARD__ = function(obj) { if(obj && obj.__esModule) { return obj; } else { var newObj = {}; if(obj != null) { for(var k in obj) { if (Object.prototype.hasOwnProperty.call(obj, k)) newObj[k] = obj[k]; } } newObj.default = obj; return newObj; } };
  6. var __REQUIRE_DEFAULT__ = function(obj) { return obj && obj.__esModule ? obj.default : obj; };
  7. __DEFINE__(1758160678371, function(require, module, exports) {
  8. /**
  9. * @license
  10. * Lodash <https://lodash.com/>
  11. * Copyright OpenJS Foundation and other contributors <https://openjsf.org/>
  12. * Released under MIT license <https://lodash.com/license>
  13. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  14. * Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  15. */
  16. ;(function() {
  17. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  18. var undefined;
  19. /** Used as the semantic version number. */
  20. var VERSION = '4.17.21';
  21. /** Used as the size to enable large array optimizations. */
  22. var LARGE_ARRAY_SIZE = 200;
  23. /** Error message constants. */
  24. var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.',
  25. FUNC_ERROR_TEXT = 'Expected a function',
  26. INVALID_TEMPL_VAR_ERROR_TEXT = 'Invalid `variable` option passed into `_.template`';
  27. /** Used to stand-in for `undefined` hash values. */
  28. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  29. /** Used as the maximum memoize cache size. */
  30. var MAX_MEMOIZE_SIZE = 500;
  31. /** Used as the internal argument placeholder. */
  32. var PLACEHOLDER = '__lodash_placeholder__';
  33. /** Used to compose bitmasks for cloning. */
  34. var CLONE_DEEP_FLAG = 1,
  35. CLONE_FLAT_FLAG = 2,
  36. CLONE_SYMBOLS_FLAG = 4;
  37. /** Used to compose bitmasks for value comparisons. */
  38. var COMPARE_PARTIAL_FLAG = 1,
  39. COMPARE_UNORDERED_FLAG = 2;
  40. /** Used to compose bitmasks for function metadata. */
  41. var WRAP_BIND_FLAG = 1,
  42. WRAP_BIND_KEY_FLAG = 2,
  43. WRAP_CURRY_BOUND_FLAG = 4,
  44. WRAP_CURRY_FLAG = 8,
  45. WRAP_CURRY_RIGHT_FLAG = 16,
  46. WRAP_PARTIAL_FLAG = 32,
  47. WRAP_PARTIAL_RIGHT_FLAG = 64,
  48. WRAP_ARY_FLAG = 128,
  49. WRAP_REARG_FLAG = 256,
  50. WRAP_FLIP_FLAG = 512;
  51. /** Used as default options for `_.truncate`. */
  52. var DEFAULT_TRUNC_LENGTH = 30,
  53. DEFAULT_TRUNC_OMISSION = '...';
  54. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  55. var HOT_COUNT = 800,
  56. HOT_SPAN = 16;
  57. /** Used to indicate the type of lazy iteratees. */
  58. var LAZY_FILTER_FLAG = 1,
  59. LAZY_MAP_FLAG = 2,
  60. LAZY_WHILE_FLAG = 3;
  61. /** Used as references for various `Number` constants. */
  62. var INFINITY = 1 / 0,
  63. MAX_SAFE_INTEGER = 9007199254740991,
  64. MAX_INTEGER = 1.7976931348623157e+308,
  65. NAN = 0 / 0;
  66. /** Used as references for the maximum length and index of an array. */
  67. var MAX_ARRAY_LENGTH = 4294967295,
  68. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  69. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  70. /** Used to associate wrap methods with their bit flags. */
  71. var wrapFlags = [
  72. ['ary', WRAP_ARY_FLAG],
  73. ['bind', WRAP_BIND_FLAG],
  74. ['bindKey', WRAP_BIND_KEY_FLAG],
  75. ['curry', WRAP_CURRY_FLAG],
  76. ['curryRight', WRAP_CURRY_RIGHT_FLAG],
  77. ['flip', WRAP_FLIP_FLAG],
  78. ['partial', WRAP_PARTIAL_FLAG],
  79. ['partialRight', WRAP_PARTIAL_RIGHT_FLAG],
  80. ['rearg', WRAP_REARG_FLAG]
  81. ];
  82. /** `Object#toString` result references. */
  83. var argsTag = '[object Arguments]',
  84. arrayTag = '[object Array]',
  85. asyncTag = '[object AsyncFunction]',
  86. boolTag = '[object Boolean]',
  87. dateTag = '[object Date]',
  88. domExcTag = '[object DOMException]',
  89. errorTag = '[object Error]',
  90. funcTag = '[object Function]',
  91. genTag = '[object GeneratorFunction]',
  92. mapTag = '[object Map]',
  93. numberTag = '[object Number]',
  94. nullTag = '[object Null]',
  95. objectTag = '[object Object]',
  96. promiseTag = '[object Promise]',
  97. proxyTag = '[object Proxy]',
  98. regexpTag = '[object RegExp]',
  99. setTag = '[object Set]',
  100. stringTag = '[object String]',
  101. symbolTag = '[object Symbol]',
  102. undefinedTag = '[object Undefined]',
  103. weakMapTag = '[object WeakMap]',
  104. weakSetTag = '[object WeakSet]';
  105. var arrayBufferTag = '[object ArrayBuffer]',
  106. dataViewTag = '[object DataView]',
  107. float32Tag = '[object Float32Array]',
  108. float64Tag = '[object Float64Array]',
  109. int8Tag = '[object Int8Array]',
  110. int16Tag = '[object Int16Array]',
  111. int32Tag = '[object Int32Array]',
  112. uint8Tag = '[object Uint8Array]',
  113. uint8ClampedTag = '[object Uint8ClampedArray]',
  114. uint16Tag = '[object Uint16Array]',
  115. uint32Tag = '[object Uint32Array]';
  116. /** Used to match empty string literals in compiled template source. */
  117. var reEmptyStringLeading = /\b__p \+= '';/g,
  118. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  119. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  120. /** Used to match HTML entities and HTML characters. */
  121. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g,
  122. reUnescapedHtml = /[&<>"']/g,
  123. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  124. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  125. /** Used to match template delimiters. */
  126. var reEscape = /<%-([\s\S]+?)%>/g,
  127. reEvaluate = /<%([\s\S]+?)%>/g,
  128. reInterpolate = /<%=([\s\S]+?)%>/g;
  129. /** Used to match property names within property paths. */
  130. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  131. reIsPlainProp = /^\w*$/,
  132. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  133. /**
  134. * Used to match `RegExp`
  135. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  136. */
  137. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g,
  138. reHasRegExpChar = RegExp(reRegExpChar.source);
  139. /** Used to match leading whitespace. */
  140. var reTrimStart = /^\s+/;
  141. /** Used to match a single whitespace character. */
  142. var reWhitespace = /\s/;
  143. /** Used to match wrap detail comments. */
  144. var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/,
  145. reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/,
  146. reSplitDetails = /,? & /;
  147. /** Used to match words composed of alphanumeric characters. */
  148. var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g;
  149. /**
  150. * Used to validate the `validate` option in `_.template` variable.
  151. *
  152. * Forbids characters which could potentially change the meaning of the function argument definition:
  153. * - "()," (modification of function parameters)
  154. * - "=" (default value)
  155. * - "[]{}" (destructuring of function parameters)
  156. * - "/" (beginning of a comment)
  157. * - whitespace
  158. */
  159. var reForbiddenIdentifierChars = /[()=,{}\[\]\/\s]/;
  160. /** Used to match backslashes in property paths. */
  161. var reEscapeChar = /\\(\\)?/g;
  162. /**
  163. * Used to match
  164. * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components).
  165. */
  166. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  167. /** Used to match `RegExp` flags from their coerced string values. */
  168. var reFlags = /\w*$/;
  169. /** Used to detect bad signed hexadecimal string values. */
  170. var reIsBadHex = /^[-+]0x[0-9a-f]+$/i;
  171. /** Used to detect binary string values. */
  172. var reIsBinary = /^0b[01]+$/i;
  173. /** Used to detect host constructors (Safari). */
  174. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  175. /** Used to detect octal string values. */
  176. var reIsOctal = /^0o[0-7]+$/i;
  177. /** Used to detect unsigned integer values. */
  178. var reIsUint = /^(?:0|[1-9]\d*)$/;
  179. /** Used to match Latin Unicode letters (excluding mathematical operators). */
  180. var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g;
  181. /** Used to ensure capturing order of template delimiters. */
  182. var reNoMatch = /($^)/;
  183. /** Used to match unescaped characters in compiled string literals. */
  184. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  185. /** Used to compose unicode character classes. */
  186. var rsAstralRange = '\\ud800-\\udfff',
  187. rsComboMarksRange = '\\u0300-\\u036f',
  188. reComboHalfMarksRange = '\\ufe20-\\ufe2f',
  189. rsComboSymbolsRange = '\\u20d0-\\u20ff',
  190. rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange,
  191. rsDingbatRange = '\\u2700-\\u27bf',
  192. rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff',
  193. rsMathOpRange = '\\xac\\xb1\\xd7\\xf7',
  194. rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf',
  195. rsPunctuationRange = '\\u2000-\\u206f',
  196. 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',
  197. rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde',
  198. rsVarRange = '\\ufe0e\\ufe0f',
  199. rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange;
  200. /** Used to compose unicode capture groups. */
  201. var rsApos = "['\u2019]",
  202. rsAstral = '[' + rsAstralRange + ']',
  203. rsBreak = '[' + rsBreakRange + ']',
  204. rsCombo = '[' + rsComboRange + ']',
  205. rsDigits = '\\d+',
  206. rsDingbat = '[' + rsDingbatRange + ']',
  207. rsLower = '[' + rsLowerRange + ']',
  208. rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']',
  209. rsFitz = '\\ud83c[\\udffb-\\udfff]',
  210. rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')',
  211. rsNonAstral = '[^' + rsAstralRange + ']',
  212. rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}',
  213. rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]',
  214. rsUpper = '[' + rsUpperRange + ']',
  215. rsZWJ = '\\u200d';
  216. /** Used to compose unicode regexes. */
  217. var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')',
  218. rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')',
  219. rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?',
  220. rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?',
  221. reOptMod = rsModifier + '?',
  222. rsOptVar = '[' + rsVarRange + ']?',
  223. rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*',
  224. rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])',
  225. rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])',
  226. rsSeq = rsOptVar + reOptMod + rsOptJoin,
  227. rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq,
  228. rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')';
  229. /** Used to match apostrophes. */
  230. var reApos = RegExp(rsApos, 'g');
  231. /**
  232. * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and
  233. * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols).
  234. */
  235. var reComboMark = RegExp(rsCombo, 'g');
  236. /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */
  237. var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g');
  238. /** Used to match complex or compound words. */
  239. var reUnicodeWord = RegExp([
  240. rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')',
  241. rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')',
  242. rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower,
  243. rsUpper + '+' + rsOptContrUpper,
  244. rsOrdUpper,
  245. rsOrdLower,
  246. rsDigits,
  247. rsEmoji
  248. ].join('|'), 'g');
  249. /** 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/). */
  250. var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']');
  251. /** Used to detect strings that need a more robust regexp to match words. */
  252. 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 ]/;
  253. /** Used to assign default `context` object properties. */
  254. var contextProps = [
  255. 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array',
  256. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object',
  257. 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array',
  258. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap',
  259. '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout'
  260. ];
  261. /** Used to make template sourceURLs easier to identify. */
  262. var templateCounter = -1;
  263. /** Used to identify `toStringTag` values of typed arrays. */
  264. var typedArrayTags = {};
  265. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  266. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  267. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  268. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  269. typedArrayTags[uint32Tag] = true;
  270. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  271. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  272. typedArrayTags[dataViewTag] = typedArrayTags[dateTag] =
  273. typedArrayTags[errorTag] = typedArrayTags[funcTag] =
  274. typedArrayTags[mapTag] = typedArrayTags[numberTag] =
  275. typedArrayTags[objectTag] = typedArrayTags[regexpTag] =
  276. typedArrayTags[setTag] = typedArrayTags[stringTag] =
  277. typedArrayTags[weakMapTag] = false;
  278. /** Used to identify `toStringTag` values supported by `_.clone`. */
  279. var cloneableTags = {};
  280. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  281. cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] =
  282. cloneableTags[boolTag] = cloneableTags[dateTag] =
  283. cloneableTags[float32Tag] = cloneableTags[float64Tag] =
  284. cloneableTags[int8Tag] = cloneableTags[int16Tag] =
  285. cloneableTags[int32Tag] = cloneableTags[mapTag] =
  286. cloneableTags[numberTag] = cloneableTags[objectTag] =
  287. cloneableTags[regexpTag] = cloneableTags[setTag] =
  288. cloneableTags[stringTag] = cloneableTags[symbolTag] =
  289. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  290. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  291. cloneableTags[errorTag] = cloneableTags[funcTag] =
  292. cloneableTags[weakMapTag] = false;
  293. /** Used to map Latin Unicode letters to basic Latin letters. */
  294. var deburredLetters = {
  295. // Latin-1 Supplement block.
  296. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  297. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  298. '\xc7': 'C', '\xe7': 'c',
  299. '\xd0': 'D', '\xf0': 'd',
  300. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  301. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  302. '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  303. '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  304. '\xd1': 'N', '\xf1': 'n',
  305. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  306. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  307. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  308. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  309. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  310. '\xc6': 'Ae', '\xe6': 'ae',
  311. '\xde': 'Th', '\xfe': 'th',
  312. '\xdf': 'ss',
  313. // Latin Extended-A block.
  314. '\u0100': 'A', '\u0102': 'A', '\u0104': 'A',
  315. '\u0101': 'a', '\u0103': 'a', '\u0105': 'a',
  316. '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C',
  317. '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c',
  318. '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd',
  319. '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E',
  320. '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e',
  321. '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G',
  322. '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g',
  323. '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h',
  324. '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I',
  325. '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i',
  326. '\u0134': 'J', '\u0135': 'j',
  327. '\u0136': 'K', '\u0137': 'k', '\u0138': 'k',
  328. '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L',
  329. '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l',
  330. '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N',
  331. '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n',
  332. '\u014c': 'O', '\u014e': 'O', '\u0150': 'O',
  333. '\u014d': 'o', '\u014f': 'o', '\u0151': 'o',
  334. '\u0154': 'R', '\u0156': 'R', '\u0158': 'R',
  335. '\u0155': 'r', '\u0157': 'r', '\u0159': 'r',
  336. '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S',
  337. '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's',
  338. '\u0162': 'T', '\u0164': 'T', '\u0166': 'T',
  339. '\u0163': 't', '\u0165': 't', '\u0167': 't',
  340. '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U',
  341. '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u',
  342. '\u0174': 'W', '\u0175': 'w',
  343. '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y',
  344. '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z',
  345. '\u017a': 'z', '\u017c': 'z', '\u017e': 'z',
  346. '\u0132': 'IJ', '\u0133': 'ij',
  347. '\u0152': 'Oe', '\u0153': 'oe',
  348. '\u0149': "'n", '\u017f': 's'
  349. };
  350. /** Used to map characters to HTML entities. */
  351. var htmlEscapes = {
  352. '&': '&amp;',
  353. '<': '&lt;',
  354. '>': '&gt;',
  355. '"': '&quot;',
  356. "'": '&#39;'
  357. };
  358. /** Used to map HTML entities to characters. */
  359. var htmlUnescapes = {
  360. '&amp;': '&',
  361. '&lt;': '<',
  362. '&gt;': '>',
  363. '&quot;': '"',
  364. '&#39;': "'"
  365. };
  366. /** Used to escape characters for inclusion in compiled string literals. */
  367. var stringEscapes = {
  368. '\\': '\\',
  369. "'": "'",
  370. '\n': 'n',
  371. '\r': 'r',
  372. '\u2028': 'u2028',
  373. '\u2029': 'u2029'
  374. };
  375. /** Built-in method references without a dependency on `root`. */
  376. var freeParseFloat = parseFloat,
  377. freeParseInt = parseInt;
  378. /** Detect free variable `global` from Node.js. */
  379. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  380. /** Detect free variable `self`. */
  381. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  382. /** Used as a reference to the global object. */
  383. var root = freeGlobal || freeSelf || Function('return this')();
  384. /** Detect free variable `exports`. */
  385. var freeExports = typeof exports == 'object' && exports && !exports.nodeType && exports;
  386. /** Detect free variable `module`. */
  387. var freeModule = freeExports && typeof module == 'object' && module && !module.nodeType && module;
  388. /** Detect the popular CommonJS extension `module.exports`. */
  389. var moduleExports = freeModule && freeModule.exports === freeExports;
  390. /** Detect free variable `process` from Node.js. */
  391. var freeProcess = moduleExports && freeGlobal.process;
  392. /** Used to access faster Node.js helpers. */
  393. var nodeUtil = (function() {
  394. try {
  395. // Use `util.types` for Node.js 10+.
  396. var types = freeModule && freeModule.require && freeModule.require('util').types;
  397. if (types) {
  398. return types;
  399. }
  400. // Legacy `process.binding('util')` for Node.js < 10.
  401. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  402. } catch (e) {}
  403. }());
  404. /* Node.js helper references. */
  405. var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer,
  406. nodeIsDate = nodeUtil && nodeUtil.isDate,
  407. nodeIsMap = nodeUtil && nodeUtil.isMap,
  408. nodeIsRegExp = nodeUtil && nodeUtil.isRegExp,
  409. nodeIsSet = nodeUtil && nodeUtil.isSet,
  410. nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray;
  411. /*--------------------------------------------------------------------------*/
  412. /**
  413. * A faster alternative to `Function#apply`, this function invokes `func`
  414. * with the `this` binding of `thisArg` and the arguments of `args`.
  415. *
  416. * @private
  417. * @param {Function} func The function to invoke.
  418. * @param {*} thisArg The `this` binding of `func`.
  419. * @param {Array} args The arguments to invoke `func` with.
  420. * @returns {*} Returns the result of `func`.
  421. */
  422. function apply(func, thisArg, args) {
  423. switch (args.length) {
  424. case 0: return func.call(thisArg);
  425. case 1: return func.call(thisArg, args[0]);
  426. case 2: return func.call(thisArg, args[0], args[1]);
  427. case 3: return func.call(thisArg, args[0], args[1], args[2]);
  428. }
  429. return func.apply(thisArg, args);
  430. }
  431. /**
  432. * A specialized version of `baseAggregator` for arrays.
  433. *
  434. * @private
  435. * @param {Array} [array] The array to iterate over.
  436. * @param {Function} setter The function to set `accumulator` values.
  437. * @param {Function} iteratee The iteratee to transform keys.
  438. * @param {Object} accumulator The initial aggregated object.
  439. * @returns {Function} Returns `accumulator`.
  440. */
  441. function arrayAggregator(array, setter, iteratee, accumulator) {
  442. var index = -1,
  443. length = array == null ? 0 : array.length;
  444. while (++index < length) {
  445. var value = array[index];
  446. setter(accumulator, value, iteratee(value), array);
  447. }
  448. return accumulator;
  449. }
  450. /**
  451. * A specialized version of `_.forEach` for arrays without support for
  452. * iteratee shorthands.
  453. *
  454. * @private
  455. * @param {Array} [array] The array to iterate over.
  456. * @param {Function} iteratee The function invoked per iteration.
  457. * @returns {Array} Returns `array`.
  458. */
  459. function arrayEach(array, iteratee) {
  460. var index = -1,
  461. length = array == null ? 0 : array.length;
  462. while (++index < length) {
  463. if (iteratee(array[index], index, array) === false) {
  464. break;
  465. }
  466. }
  467. return array;
  468. }
  469. /**
  470. * A specialized version of `_.forEachRight` for arrays without support for
  471. * iteratee shorthands.
  472. *
  473. * @private
  474. * @param {Array} [array] The array to iterate over.
  475. * @param {Function} iteratee The function invoked per iteration.
  476. * @returns {Array} Returns `array`.
  477. */
  478. function arrayEachRight(array, iteratee) {
  479. var length = array == null ? 0 : array.length;
  480. while (length--) {
  481. if (iteratee(array[length], length, array) === false) {
  482. break;
  483. }
  484. }
  485. return array;
  486. }
  487. /**
  488. * A specialized version of `_.every` for arrays without support for
  489. * iteratee shorthands.
  490. *
  491. * @private
  492. * @param {Array} [array] The array to iterate over.
  493. * @param {Function} predicate The function invoked per iteration.
  494. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  495. * else `false`.
  496. */
  497. function arrayEvery(array, predicate) {
  498. var index = -1,
  499. length = array == null ? 0 : array.length;
  500. while (++index < length) {
  501. if (!predicate(array[index], index, array)) {
  502. return false;
  503. }
  504. }
  505. return true;
  506. }
  507. /**
  508. * A specialized version of `_.filter` for arrays without support for
  509. * iteratee shorthands.
  510. *
  511. * @private
  512. * @param {Array} [array] The array to iterate over.
  513. * @param {Function} predicate The function invoked per iteration.
  514. * @returns {Array} Returns the new filtered array.
  515. */
  516. function arrayFilter(array, predicate) {
  517. var index = -1,
  518. length = array == null ? 0 : array.length,
  519. resIndex = 0,
  520. result = [];
  521. while (++index < length) {
  522. var value = array[index];
  523. if (predicate(value, index, array)) {
  524. result[resIndex++] = value;
  525. }
  526. }
  527. return result;
  528. }
  529. /**
  530. * A specialized version of `_.includes` for arrays without support for
  531. * specifying an index to search from.
  532. *
  533. * @private
  534. * @param {Array} [array] The array to inspect.
  535. * @param {*} target The value to search for.
  536. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  537. */
  538. function arrayIncludes(array, value) {
  539. var length = array == null ? 0 : array.length;
  540. return !!length && baseIndexOf(array, value, 0) > -1;
  541. }
  542. /**
  543. * This function is like `arrayIncludes` except that it accepts a comparator.
  544. *
  545. * @private
  546. * @param {Array} [array] The array to inspect.
  547. * @param {*} target The value to search for.
  548. * @param {Function} comparator The comparator invoked per element.
  549. * @returns {boolean} Returns `true` if `target` is found, else `false`.
  550. */
  551. function arrayIncludesWith(array, value, comparator) {
  552. var index = -1,
  553. length = array == null ? 0 : array.length;
  554. while (++index < length) {
  555. if (comparator(value, array[index])) {
  556. return true;
  557. }
  558. }
  559. return false;
  560. }
  561. /**
  562. * A specialized version of `_.map` for arrays without support for iteratee
  563. * shorthands.
  564. *
  565. * @private
  566. * @param {Array} [array] The array to iterate over.
  567. * @param {Function} iteratee The function invoked per iteration.
  568. * @returns {Array} Returns the new mapped array.
  569. */
  570. function arrayMap(array, iteratee) {
  571. var index = -1,
  572. length = array == null ? 0 : array.length,
  573. result = Array(length);
  574. while (++index < length) {
  575. result[index] = iteratee(array[index], index, array);
  576. }
  577. return result;
  578. }
  579. /**
  580. * Appends the elements of `values` to `array`.
  581. *
  582. * @private
  583. * @param {Array} array The array to modify.
  584. * @param {Array} values The values to append.
  585. * @returns {Array} Returns `array`.
  586. */
  587. function arrayPush(array, values) {
  588. var index = -1,
  589. length = values.length,
  590. offset = array.length;
  591. while (++index < length) {
  592. array[offset + index] = values[index];
  593. }
  594. return array;
  595. }
  596. /**
  597. * A specialized version of `_.reduce` for arrays without support for
  598. * iteratee shorthands.
  599. *
  600. * @private
  601. * @param {Array} [array] The array to iterate over.
  602. * @param {Function} iteratee The function invoked per iteration.
  603. * @param {*} [accumulator] The initial value.
  604. * @param {boolean} [initAccum] Specify using the first element of `array` as
  605. * the initial value.
  606. * @returns {*} Returns the accumulated value.
  607. */
  608. function arrayReduce(array, iteratee, accumulator, initAccum) {
  609. var index = -1,
  610. length = array == null ? 0 : array.length;
  611. if (initAccum && length) {
  612. accumulator = array[++index];
  613. }
  614. while (++index < length) {
  615. accumulator = iteratee(accumulator, array[index], index, array);
  616. }
  617. return accumulator;
  618. }
  619. /**
  620. * A specialized version of `_.reduceRight` for arrays without support for
  621. * iteratee shorthands.
  622. *
  623. * @private
  624. * @param {Array} [array] The array to iterate over.
  625. * @param {Function} iteratee The function invoked per iteration.
  626. * @param {*} [accumulator] The initial value.
  627. * @param {boolean} [initAccum] Specify using the last element of `array` as
  628. * the initial value.
  629. * @returns {*} Returns the accumulated value.
  630. */
  631. function arrayReduceRight(array, iteratee, accumulator, initAccum) {
  632. var length = array == null ? 0 : array.length;
  633. if (initAccum && length) {
  634. accumulator = array[--length];
  635. }
  636. while (length--) {
  637. accumulator = iteratee(accumulator, array[length], length, array);
  638. }
  639. return accumulator;
  640. }
  641. /**
  642. * A specialized version of `_.some` for arrays without support for iteratee
  643. * shorthands.
  644. *
  645. * @private
  646. * @param {Array} [array] The array to iterate over.
  647. * @param {Function} predicate The function invoked per iteration.
  648. * @returns {boolean} Returns `true` if any element passes the predicate check,
  649. * else `false`.
  650. */
  651. function arraySome(array, predicate) {
  652. var index = -1,
  653. length = array == null ? 0 : array.length;
  654. while (++index < length) {
  655. if (predicate(array[index], index, array)) {
  656. return true;
  657. }
  658. }
  659. return false;
  660. }
  661. /**
  662. * Gets the size of an ASCII `string`.
  663. *
  664. * @private
  665. * @param {string} string The string inspect.
  666. * @returns {number} Returns the string size.
  667. */
  668. var asciiSize = baseProperty('length');
  669. /**
  670. * Converts an ASCII `string` to an array.
  671. *
  672. * @private
  673. * @param {string} string The string to convert.
  674. * @returns {Array} Returns the converted array.
  675. */
  676. function asciiToArray(string) {
  677. return string.split('');
  678. }
  679. /**
  680. * Splits an ASCII `string` into an array of its words.
  681. *
  682. * @private
  683. * @param {string} The string to inspect.
  684. * @returns {Array} Returns the words of `string`.
  685. */
  686. function asciiWords(string) {
  687. return string.match(reAsciiWord) || [];
  688. }
  689. /**
  690. * The base implementation of methods like `_.findKey` and `_.findLastKey`,
  691. * without support for iteratee shorthands, which iterates over `collection`
  692. * using `eachFunc`.
  693. *
  694. * @private
  695. * @param {Array|Object} collection The collection to inspect.
  696. * @param {Function} predicate The function invoked per iteration.
  697. * @param {Function} eachFunc The function to iterate over `collection`.
  698. * @returns {*} Returns the found element or its key, else `undefined`.
  699. */
  700. function baseFindKey(collection, predicate, eachFunc) {
  701. var result;
  702. eachFunc(collection, function(value, key, collection) {
  703. if (predicate(value, key, collection)) {
  704. result = key;
  705. return false;
  706. }
  707. });
  708. return result;
  709. }
  710. /**
  711. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  712. * support for iteratee shorthands.
  713. *
  714. * @private
  715. * @param {Array} array The array to inspect.
  716. * @param {Function} predicate The function invoked per iteration.
  717. * @param {number} fromIndex The index to search from.
  718. * @param {boolean} [fromRight] Specify iterating from right to left.
  719. * @returns {number} Returns the index of the matched value, else `-1`.
  720. */
  721. function baseFindIndex(array, predicate, fromIndex, fromRight) {
  722. var length = array.length,
  723. index = fromIndex + (fromRight ? 1 : -1);
  724. while ((fromRight ? index-- : ++index < length)) {
  725. if (predicate(array[index], index, array)) {
  726. return index;
  727. }
  728. }
  729. return -1;
  730. }
  731. /**
  732. * The base implementation of `_.indexOf` without `fromIndex` bounds checks.
  733. *
  734. * @private
  735. * @param {Array} array The array to inspect.
  736. * @param {*} value The value to search for.
  737. * @param {number} fromIndex The index to search from.
  738. * @returns {number} Returns the index of the matched value, else `-1`.
  739. */
  740. function baseIndexOf(array, value, fromIndex) {
  741. return value === value
  742. ? strictIndexOf(array, value, fromIndex)
  743. : baseFindIndex(array, baseIsNaN, fromIndex);
  744. }
  745. /**
  746. * This function is like `baseIndexOf` except that it accepts a comparator.
  747. *
  748. * @private
  749. * @param {Array} array The array to inspect.
  750. * @param {*} value The value to search for.
  751. * @param {number} fromIndex The index to search from.
  752. * @param {Function} comparator The comparator invoked per element.
  753. * @returns {number} Returns the index of the matched value, else `-1`.
  754. */
  755. function baseIndexOfWith(array, value, fromIndex, comparator) {
  756. var index = fromIndex - 1,
  757. length = array.length;
  758. while (++index < length) {
  759. if (comparator(array[index], value)) {
  760. return index;
  761. }
  762. }
  763. return -1;
  764. }
  765. /**
  766. * The base implementation of `_.isNaN` without support for number objects.
  767. *
  768. * @private
  769. * @param {*} value The value to check.
  770. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  771. */
  772. function baseIsNaN(value) {
  773. return value !== value;
  774. }
  775. /**
  776. * The base implementation of `_.mean` and `_.meanBy` without support for
  777. * iteratee shorthands.
  778. *
  779. * @private
  780. * @param {Array} array The array to iterate over.
  781. * @param {Function} iteratee The function invoked per iteration.
  782. * @returns {number} Returns the mean.
  783. */
  784. function baseMean(array, iteratee) {
  785. var length = array == null ? 0 : array.length;
  786. return length ? (baseSum(array, iteratee) / length) : NAN;
  787. }
  788. /**
  789. * The base implementation of `_.property` without support for deep paths.
  790. *
  791. * @private
  792. * @param {string} key The key of the property to get.
  793. * @returns {Function} Returns the new accessor function.
  794. */
  795. function baseProperty(key) {
  796. return function(object) {
  797. return object == null ? undefined : object[key];
  798. };
  799. }
  800. /**
  801. * The base implementation of `_.propertyOf` without support for deep paths.
  802. *
  803. * @private
  804. * @param {Object} object The object to query.
  805. * @returns {Function} Returns the new accessor function.
  806. */
  807. function basePropertyOf(object) {
  808. return function(key) {
  809. return object == null ? undefined : object[key];
  810. };
  811. }
  812. /**
  813. * The base implementation of `_.reduce` and `_.reduceRight`, without support
  814. * for iteratee shorthands, which iterates over `collection` using `eachFunc`.
  815. *
  816. * @private
  817. * @param {Array|Object} collection The collection to iterate over.
  818. * @param {Function} iteratee The function invoked per iteration.
  819. * @param {*} accumulator The initial value.
  820. * @param {boolean} initAccum Specify using the first or last element of
  821. * `collection` as the initial value.
  822. * @param {Function} eachFunc The function to iterate over `collection`.
  823. * @returns {*} Returns the accumulated value.
  824. */
  825. function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) {
  826. eachFunc(collection, function(value, index, collection) {
  827. accumulator = initAccum
  828. ? (initAccum = false, value)
  829. : iteratee(accumulator, value, index, collection);
  830. });
  831. return accumulator;
  832. }
  833. /**
  834. * The base implementation of `_.sortBy` which uses `comparer` to define the
  835. * sort order of `array` and replaces criteria objects with their corresponding
  836. * values.
  837. *
  838. * @private
  839. * @param {Array} array The array to sort.
  840. * @param {Function} comparer The function to define sort order.
  841. * @returns {Array} Returns `array`.
  842. */
  843. function baseSortBy(array, comparer) {
  844. var length = array.length;
  845. array.sort(comparer);
  846. while (length--) {
  847. array[length] = array[length].value;
  848. }
  849. return array;
  850. }
  851. /**
  852. * The base implementation of `_.sum` and `_.sumBy` without support for
  853. * iteratee shorthands.
  854. *
  855. * @private
  856. * @param {Array} array The array to iterate over.
  857. * @param {Function} iteratee The function invoked per iteration.
  858. * @returns {number} Returns the sum.
  859. */
  860. function baseSum(array, iteratee) {
  861. var result,
  862. index = -1,
  863. length = array.length;
  864. while (++index < length) {
  865. var current = iteratee(array[index]);
  866. if (current !== undefined) {
  867. result = result === undefined ? current : (result + current);
  868. }
  869. }
  870. return result;
  871. }
  872. /**
  873. * The base implementation of `_.times` without support for iteratee shorthands
  874. * or max array length checks.
  875. *
  876. * @private
  877. * @param {number} n The number of times to invoke `iteratee`.
  878. * @param {Function} iteratee The function invoked per iteration.
  879. * @returns {Array} Returns the array of results.
  880. */
  881. function baseTimes(n, iteratee) {
  882. var index = -1,
  883. result = Array(n);
  884. while (++index < n) {
  885. result[index] = iteratee(index);
  886. }
  887. return result;
  888. }
  889. /**
  890. * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array
  891. * of key-value pairs for `object` corresponding to the property names of `props`.
  892. *
  893. * @private
  894. * @param {Object} object The object to query.
  895. * @param {Array} props The property names to get values for.
  896. * @returns {Object} Returns the key-value pairs.
  897. */
  898. function baseToPairs(object, props) {
  899. return arrayMap(props, function(key) {
  900. return [key, object[key]];
  901. });
  902. }
  903. /**
  904. * The base implementation of `_.trim`.
  905. *
  906. * @private
  907. * @param {string} string The string to trim.
  908. * @returns {string} Returns the trimmed string.
  909. */
  910. function baseTrim(string) {
  911. return string
  912. ? string.slice(0, trimmedEndIndex(string) + 1).replace(reTrimStart, '')
  913. : string;
  914. }
  915. /**
  916. * The base implementation of `_.unary` without support for storing metadata.
  917. *
  918. * @private
  919. * @param {Function} func The function to cap arguments for.
  920. * @returns {Function} Returns the new capped function.
  921. */
  922. function baseUnary(func) {
  923. return function(value) {
  924. return func(value);
  925. };
  926. }
  927. /**
  928. * The base implementation of `_.values` and `_.valuesIn` which creates an
  929. * array of `object` property values corresponding to the property names
  930. * of `props`.
  931. *
  932. * @private
  933. * @param {Object} object The object to query.
  934. * @param {Array} props The property names to get values for.
  935. * @returns {Object} Returns the array of property values.
  936. */
  937. function baseValues(object, props) {
  938. return arrayMap(props, function(key) {
  939. return object[key];
  940. });
  941. }
  942. /**
  943. * Checks if a `cache` value for `key` exists.
  944. *
  945. * @private
  946. * @param {Object} cache The cache to query.
  947. * @param {string} key The key of the entry to check.
  948. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  949. */
  950. function cacheHas(cache, key) {
  951. return cache.has(key);
  952. }
  953. /**
  954. * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol
  955. * that is not found in the character symbols.
  956. *
  957. * @private
  958. * @param {Array} strSymbols The string symbols to inspect.
  959. * @param {Array} chrSymbols The character symbols to find.
  960. * @returns {number} Returns the index of the first unmatched string symbol.
  961. */
  962. function charsStartIndex(strSymbols, chrSymbols) {
  963. var index = -1,
  964. length = strSymbols.length;
  965. while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  966. return index;
  967. }
  968. /**
  969. * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol
  970. * that is not found in the character symbols.
  971. *
  972. * @private
  973. * @param {Array} strSymbols The string symbols to inspect.
  974. * @param {Array} chrSymbols The character symbols to find.
  975. * @returns {number} Returns the index of the last unmatched string symbol.
  976. */
  977. function charsEndIndex(strSymbols, chrSymbols) {
  978. var index = strSymbols.length;
  979. while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {}
  980. return index;
  981. }
  982. /**
  983. * Gets the number of `placeholder` occurrences in `array`.
  984. *
  985. * @private
  986. * @param {Array} array The array to inspect.
  987. * @param {*} placeholder The placeholder to search for.
  988. * @returns {number} Returns the placeholder count.
  989. */
  990. function countHolders(array, placeholder) {
  991. var length = array.length,
  992. result = 0;
  993. while (length--) {
  994. if (array[length] === placeholder) {
  995. ++result;
  996. }
  997. }
  998. return result;
  999. }
  1000. /**
  1001. * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A
  1002. * letters to basic Latin letters.
  1003. *
  1004. * @private
  1005. * @param {string} letter The matched letter to deburr.
  1006. * @returns {string} Returns the deburred letter.
  1007. */
  1008. var deburrLetter = basePropertyOf(deburredLetters);
  1009. /**
  1010. * Used by `_.escape` to convert characters to HTML entities.
  1011. *
  1012. * @private
  1013. * @param {string} chr The matched character to escape.
  1014. * @returns {string} Returns the escaped character.
  1015. */
  1016. var escapeHtmlChar = basePropertyOf(htmlEscapes);
  1017. /**
  1018. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  1019. *
  1020. * @private
  1021. * @param {string} chr The matched character to escape.
  1022. * @returns {string} Returns the escaped character.
  1023. */
  1024. function escapeStringChar(chr) {
  1025. return '\\' + stringEscapes[chr];
  1026. }
  1027. /**
  1028. * Gets the value at `key` of `object`.
  1029. *
  1030. * @private
  1031. * @param {Object} [object] The object to query.
  1032. * @param {string} key The key of the property to get.
  1033. * @returns {*} Returns the property value.
  1034. */
  1035. function getValue(object, key) {
  1036. return object == null ? undefined : object[key];
  1037. }
  1038. /**
  1039. * Checks if `string` contains Unicode symbols.
  1040. *
  1041. * @private
  1042. * @param {string} string The string to inspect.
  1043. * @returns {boolean} Returns `true` if a symbol is found, else `false`.
  1044. */
  1045. function hasUnicode(string) {
  1046. return reHasUnicode.test(string);
  1047. }
  1048. /**
  1049. * Checks if `string` contains a word composed of Unicode symbols.
  1050. *
  1051. * @private
  1052. * @param {string} string The string to inspect.
  1053. * @returns {boolean} Returns `true` if a word is found, else `false`.
  1054. */
  1055. function hasUnicodeWord(string) {
  1056. return reHasUnicodeWord.test(string);
  1057. }
  1058. /**
  1059. * Converts `iterator` to an array.
  1060. *
  1061. * @private
  1062. * @param {Object} iterator The iterator to convert.
  1063. * @returns {Array} Returns the converted array.
  1064. */
  1065. function iteratorToArray(iterator) {
  1066. var data,
  1067. result = [];
  1068. while (!(data = iterator.next()).done) {
  1069. result.push(data.value);
  1070. }
  1071. return result;
  1072. }
  1073. /**
  1074. * Converts `map` to its key-value pairs.
  1075. *
  1076. * @private
  1077. * @param {Object} map The map to convert.
  1078. * @returns {Array} Returns the key-value pairs.
  1079. */
  1080. function mapToArray(map) {
  1081. var index = -1,
  1082. result = Array(map.size);
  1083. map.forEach(function(value, key) {
  1084. result[++index] = [key, value];
  1085. });
  1086. return result;
  1087. }
  1088. /**
  1089. * Creates a unary function that invokes `func` with its argument transformed.
  1090. *
  1091. * @private
  1092. * @param {Function} func The function to wrap.
  1093. * @param {Function} transform The argument transform.
  1094. * @returns {Function} Returns the new function.
  1095. */
  1096. function overArg(func, transform) {
  1097. return function(arg) {
  1098. return func(transform(arg));
  1099. };
  1100. }
  1101. /**
  1102. * Replaces all `placeholder` elements in `array` with an internal placeholder
  1103. * and returns an array of their indexes.
  1104. *
  1105. * @private
  1106. * @param {Array} array The array to modify.
  1107. * @param {*} placeholder The placeholder to replace.
  1108. * @returns {Array} Returns the new array of placeholder indexes.
  1109. */
  1110. function replaceHolders(array, placeholder) {
  1111. var index = -1,
  1112. length = array.length,
  1113. resIndex = 0,
  1114. result = [];
  1115. while (++index < length) {
  1116. var value = array[index];
  1117. if (value === placeholder || value === PLACEHOLDER) {
  1118. array[index] = PLACEHOLDER;
  1119. result[resIndex++] = index;
  1120. }
  1121. }
  1122. return result;
  1123. }
  1124. /**
  1125. * Converts `set` to an array of its values.
  1126. *
  1127. * @private
  1128. * @param {Object} set The set to convert.
  1129. * @returns {Array} Returns the values.
  1130. */
  1131. function setToArray(set) {
  1132. var index = -1,
  1133. result = Array(set.size);
  1134. set.forEach(function(value) {
  1135. result[++index] = value;
  1136. });
  1137. return result;
  1138. }
  1139. /**
  1140. * Converts `set` to its value-value pairs.
  1141. *
  1142. * @private
  1143. * @param {Object} set The set to convert.
  1144. * @returns {Array} Returns the value-value pairs.
  1145. */
  1146. function setToPairs(set) {
  1147. var index = -1,
  1148. result = Array(set.size);
  1149. set.forEach(function(value) {
  1150. result[++index] = [value, value];
  1151. });
  1152. return result;
  1153. }
  1154. /**
  1155. * A specialized version of `_.indexOf` which performs strict equality
  1156. * comparisons of values, i.e. `===`.
  1157. *
  1158. * @private
  1159. * @param {Array} array The array to inspect.
  1160. * @param {*} value The value to search for.
  1161. * @param {number} fromIndex The index to search from.
  1162. * @returns {number} Returns the index of the matched value, else `-1`.
  1163. */
  1164. function strictIndexOf(array, value, fromIndex) {
  1165. var index = fromIndex - 1,
  1166. length = array.length;
  1167. while (++index < length) {
  1168. if (array[index] === value) {
  1169. return index;
  1170. }
  1171. }
  1172. return -1;
  1173. }
  1174. /**
  1175. * A specialized version of `_.lastIndexOf` which performs strict equality
  1176. * comparisons of values, i.e. `===`.
  1177. *
  1178. * @private
  1179. * @param {Array} array The array to inspect.
  1180. * @param {*} value The value to search for.
  1181. * @param {number} fromIndex The index to search from.
  1182. * @returns {number} Returns the index of the matched value, else `-1`.
  1183. */
  1184. function strictLastIndexOf(array, value, fromIndex) {
  1185. var index = fromIndex + 1;
  1186. while (index--) {
  1187. if (array[index] === value) {
  1188. return index;
  1189. }
  1190. }
  1191. return index;
  1192. }
  1193. /**
  1194. * Gets the number of symbols in `string`.
  1195. *
  1196. * @private
  1197. * @param {string} string The string to inspect.
  1198. * @returns {number} Returns the string size.
  1199. */
  1200. function stringSize(string) {
  1201. return hasUnicode(string)
  1202. ? unicodeSize(string)
  1203. : asciiSize(string);
  1204. }
  1205. /**
  1206. * Converts `string` to an array.
  1207. *
  1208. * @private
  1209. * @param {string} string The string to convert.
  1210. * @returns {Array} Returns the converted array.
  1211. */
  1212. function stringToArray(string) {
  1213. return hasUnicode(string)
  1214. ? unicodeToArray(string)
  1215. : asciiToArray(string);
  1216. }
  1217. /**
  1218. * Used by `_.trim` and `_.trimEnd` to get the index of the last non-whitespace
  1219. * character of `string`.
  1220. *
  1221. * @private
  1222. * @param {string} string The string to inspect.
  1223. * @returns {number} Returns the index of the last non-whitespace character.
  1224. */
  1225. function trimmedEndIndex(string) {
  1226. var index = string.length;
  1227. while (index-- && reWhitespace.test(string.charAt(index))) {}
  1228. return index;
  1229. }
  1230. /**
  1231. * Used by `_.unescape` to convert HTML entities to characters.
  1232. *
  1233. * @private
  1234. * @param {string} chr The matched character to unescape.
  1235. * @returns {string} Returns the unescaped character.
  1236. */
  1237. var unescapeHtmlChar = basePropertyOf(htmlUnescapes);
  1238. /**
  1239. * Gets the size of a Unicode `string`.
  1240. *
  1241. * @private
  1242. * @param {string} string The string inspect.
  1243. * @returns {number} Returns the string size.
  1244. */
  1245. function unicodeSize(string) {
  1246. var result = reUnicode.lastIndex = 0;
  1247. while (reUnicode.test(string)) {
  1248. ++result;
  1249. }
  1250. return result;
  1251. }
  1252. /**
  1253. * Converts a Unicode `string` to an array.
  1254. *
  1255. * @private
  1256. * @param {string} string The string to convert.
  1257. * @returns {Array} Returns the converted array.
  1258. */
  1259. function unicodeToArray(string) {
  1260. return string.match(reUnicode) || [];
  1261. }
  1262. /**
  1263. * Splits a Unicode `string` into an array of its words.
  1264. *
  1265. * @private
  1266. * @param {string} The string to inspect.
  1267. * @returns {Array} Returns the words of `string`.
  1268. */
  1269. function unicodeWords(string) {
  1270. return string.match(reUnicodeWord) || [];
  1271. }
  1272. /*--------------------------------------------------------------------------*/
  1273. /**
  1274. * Create a new pristine `lodash` function using the `context` object.
  1275. *
  1276. * @static
  1277. * @memberOf _
  1278. * @since 1.1.0
  1279. * @category Util
  1280. * @param {Object} [context=root] The context object.
  1281. * @returns {Function} Returns a new `lodash` function.
  1282. * @example
  1283. *
  1284. * _.mixin({ 'foo': _.constant('foo') });
  1285. *
  1286. * var lodash = _.runInContext();
  1287. * lodash.mixin({ 'bar': lodash.constant('bar') });
  1288. *
  1289. * _.isFunction(_.foo);
  1290. * // => true
  1291. * _.isFunction(_.bar);
  1292. * // => false
  1293. *
  1294. * lodash.isFunction(lodash.foo);
  1295. * // => false
  1296. * lodash.isFunction(lodash.bar);
  1297. * // => true
  1298. *
  1299. * // Create a suped-up `defer` in Node.js.
  1300. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  1301. */
  1302. var runInContext = (function runInContext(context) {
  1303. context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps));
  1304. /** Built-in constructor references. */
  1305. var Array = context.Array,
  1306. Date = context.Date,
  1307. Error = context.Error,
  1308. Function = context.Function,
  1309. Math = context.Math,
  1310. Object = context.Object,
  1311. RegExp = context.RegExp,
  1312. String = context.String,
  1313. TypeError = context.TypeError;
  1314. /** Used for built-in method references. */
  1315. var arrayProto = Array.prototype,
  1316. funcProto = Function.prototype,
  1317. objectProto = Object.prototype;
  1318. /** Used to detect overreaching core-js shims. */
  1319. var coreJsData = context['__core-js_shared__'];
  1320. /** Used to resolve the decompiled source of functions. */
  1321. var funcToString = funcProto.toString;
  1322. /** Used to check objects for own properties. */
  1323. var hasOwnProperty = objectProto.hasOwnProperty;
  1324. /** Used to generate unique IDs. */
  1325. var idCounter = 0;
  1326. /** Used to detect methods masquerading as native. */
  1327. var maskSrcKey = (function() {
  1328. var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || '');
  1329. return uid ? ('Symbol(src)_1.' + uid) : '';
  1330. }());
  1331. /**
  1332. * Used to resolve the
  1333. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  1334. * of values.
  1335. */
  1336. var nativeObjectToString = objectProto.toString;
  1337. /** Used to infer the `Object` constructor. */
  1338. var objectCtorString = funcToString.call(Object);
  1339. /** Used to restore the original `_` reference in `_.noConflict`. */
  1340. var oldDash = root._;
  1341. /** Used to detect if a method is native. */
  1342. var reIsNative = RegExp('^' +
  1343. funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&')
  1344. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  1345. );
  1346. /** Built-in value references. */
  1347. var Buffer = moduleExports ? context.Buffer : undefined,
  1348. Symbol = context.Symbol,
  1349. Uint8Array = context.Uint8Array,
  1350. allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined,
  1351. getPrototype = overArg(Object.getPrototypeOf, Object),
  1352. objectCreate = Object.create,
  1353. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  1354. splice = arrayProto.splice,
  1355. spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined,
  1356. symIterator = Symbol ? Symbol.iterator : undefined,
  1357. symToStringTag = Symbol ? Symbol.toStringTag : undefined;
  1358. var defineProperty = (function() {
  1359. try {
  1360. var func = getNative(Object, 'defineProperty');
  1361. func({}, '', {});
  1362. return func;
  1363. } catch (e) {}
  1364. }());
  1365. /** Mocked built-ins. */
  1366. var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout,
  1367. ctxNow = Date && Date.now !== root.Date.now && Date.now,
  1368. ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout;
  1369. /* Built-in method references for those with the same name as other `lodash` methods. */
  1370. var nativeCeil = Math.ceil,
  1371. nativeFloor = Math.floor,
  1372. nativeGetSymbols = Object.getOwnPropertySymbols,
  1373. nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined,
  1374. nativeIsFinite = context.isFinite,
  1375. nativeJoin = arrayProto.join,
  1376. nativeKeys = overArg(Object.keys, Object),
  1377. nativeMax = Math.max,
  1378. nativeMin = Math.min,
  1379. nativeNow = Date.now,
  1380. nativeParseInt = context.parseInt,
  1381. nativeRandom = Math.random,
  1382. nativeReverse = arrayProto.reverse;
  1383. /* Built-in method references that are verified to be native. */
  1384. var DataView = getNative(context, 'DataView'),
  1385. Map = getNative(context, 'Map'),
  1386. Promise = getNative(context, 'Promise'),
  1387. Set = getNative(context, 'Set'),
  1388. WeakMap = getNative(context, 'WeakMap'),
  1389. nativeCreate = getNative(Object, 'create');
  1390. /** Used to store function metadata. */
  1391. var metaMap = WeakMap && new WeakMap;
  1392. /** Used to lookup unminified function names. */
  1393. var realNames = {};
  1394. /** Used to detect maps, sets, and weakmaps. */
  1395. var dataViewCtorString = toSource(DataView),
  1396. mapCtorString = toSource(Map),
  1397. promiseCtorString = toSource(Promise),
  1398. setCtorString = toSource(Set),
  1399. weakMapCtorString = toSource(WeakMap);
  1400. /** Used to convert symbols to primitives and strings. */
  1401. var symbolProto = Symbol ? Symbol.prototype : undefined,
  1402. symbolValueOf = symbolProto ? symbolProto.valueOf : undefined,
  1403. symbolToString = symbolProto ? symbolProto.toString : undefined;
  1404. /*------------------------------------------------------------------------*/
  1405. /**
  1406. * Creates a `lodash` object which wraps `value` to enable implicit method
  1407. * chain sequences. Methods that operate on and return arrays, collections,
  1408. * and functions can be chained together. Methods that retrieve a single value
  1409. * or may return a primitive value will automatically end the chain sequence
  1410. * and return the unwrapped value. Otherwise, the value must be unwrapped
  1411. * with `_#value`.
  1412. *
  1413. * Explicit chain sequences, which must be unwrapped with `_#value`, may be
  1414. * enabled using `_.chain`.
  1415. *
  1416. * The execution of chained methods is lazy, that is, it's deferred until
  1417. * `_#value` is implicitly or explicitly called.
  1418. *
  1419. * Lazy evaluation allows several methods to support shortcut fusion.
  1420. * Shortcut fusion is an optimization to merge iteratee calls; this avoids
  1421. * the creation of intermediate arrays and can greatly reduce the number of
  1422. * iteratee executions. Sections of a chain sequence qualify for shortcut
  1423. * fusion if the section is applied to an array and iteratees accept only
  1424. * one argument. The heuristic for whether a section qualifies for shortcut
  1425. * fusion is subject to change.
  1426. *
  1427. * Chaining is supported in custom builds as long as the `_#value` method is
  1428. * directly or indirectly included in the build.
  1429. *
  1430. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  1431. *
  1432. * The wrapper `Array` methods are:
  1433. * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift`
  1434. *
  1435. * The wrapper `String` methods are:
  1436. * `replace` and `split`
  1437. *
  1438. * The wrapper methods that support shortcut fusion are:
  1439. * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`,
  1440. * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`,
  1441. * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray`
  1442. *
  1443. * The chainable wrapper methods are:
  1444. * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`,
  1445. * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`,
  1446. * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`,
  1447. * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`,
  1448. * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`,
  1449. * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`,
  1450. * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`,
  1451. * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`,
  1452. * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`,
  1453. * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`,
  1454. * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`,
  1455. * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`,
  1456. * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`,
  1457. * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`,
  1458. * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`,
  1459. * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`,
  1460. * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`,
  1461. * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`,
  1462. * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`,
  1463. * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`,
  1464. * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`,
  1465. * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`,
  1466. * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`,
  1467. * `zipObject`, `zipObjectDeep`, and `zipWith`
  1468. *
  1469. * The wrapper methods that are **not** chainable by default are:
  1470. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`,
  1471. * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`,
  1472. * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`,
  1473. * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`,
  1474. * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`,
  1475. * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`,
  1476. * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`,
  1477. * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`,
  1478. * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`,
  1479. * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`,
  1480. * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`,
  1481. * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`,
  1482. * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`,
  1483. * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`,
  1484. * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`,
  1485. * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`,
  1486. * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`,
  1487. * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`,
  1488. * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`,
  1489. * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`,
  1490. * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`,
  1491. * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`,
  1492. * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`,
  1493. * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`,
  1494. * `upperFirst`, `value`, and `words`
  1495. *
  1496. * @name _
  1497. * @constructor
  1498. * @category Seq
  1499. * @param {*} value The value to wrap in a `lodash` instance.
  1500. * @returns {Object} Returns the new `lodash` wrapper instance.
  1501. * @example
  1502. *
  1503. * function square(n) {
  1504. * return n * n;
  1505. * }
  1506. *
  1507. * var wrapped = _([1, 2, 3]);
  1508. *
  1509. * // Returns an unwrapped value.
  1510. * wrapped.reduce(_.add);
  1511. * // => 6
  1512. *
  1513. * // Returns a wrapped value.
  1514. * var squares = wrapped.map(square);
  1515. *
  1516. * _.isArray(squares);
  1517. * // => false
  1518. *
  1519. * _.isArray(squares.value());
  1520. * // => true
  1521. */
  1522. function lodash(value) {
  1523. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  1524. if (value instanceof LodashWrapper) {
  1525. return value;
  1526. }
  1527. if (hasOwnProperty.call(value, '__wrapped__')) {
  1528. return wrapperClone(value);
  1529. }
  1530. }
  1531. return new LodashWrapper(value);
  1532. }
  1533. /**
  1534. * The base implementation of `_.create` without support for assigning
  1535. * properties to the created object.
  1536. *
  1537. * @private
  1538. * @param {Object} proto The object to inherit from.
  1539. * @returns {Object} Returns the new object.
  1540. */
  1541. var baseCreate = (function() {
  1542. function object() {}
  1543. return function(proto) {
  1544. if (!isObject(proto)) {
  1545. return {};
  1546. }
  1547. if (objectCreate) {
  1548. return objectCreate(proto);
  1549. }
  1550. object.prototype = proto;
  1551. var result = new object;
  1552. object.prototype = undefined;
  1553. return result;
  1554. };
  1555. }());
  1556. /**
  1557. * The function whose prototype chain sequence wrappers inherit from.
  1558. *
  1559. * @private
  1560. */
  1561. function baseLodash() {
  1562. // No operation performed.
  1563. }
  1564. /**
  1565. * The base constructor for creating `lodash` wrapper objects.
  1566. *
  1567. * @private
  1568. * @param {*} value The value to wrap.
  1569. * @param {boolean} [chainAll] Enable explicit method chain sequences.
  1570. */
  1571. function LodashWrapper(value, chainAll) {
  1572. this.__wrapped__ = value;
  1573. this.__actions__ = [];
  1574. this.__chain__ = !!chainAll;
  1575. this.__index__ = 0;
  1576. this.__values__ = undefined;
  1577. }
  1578. /**
  1579. * By default, the template delimiters used by lodash are like those in
  1580. * embedded Ruby (ERB) as well as ES2015 template strings. Change the
  1581. * following template settings to use alternative delimiters.
  1582. *
  1583. * @static
  1584. * @memberOf _
  1585. * @type {Object}
  1586. */
  1587. lodash.templateSettings = {
  1588. /**
  1589. * Used to detect `data` property values to be HTML-escaped.
  1590. *
  1591. * @memberOf _.templateSettings
  1592. * @type {RegExp}
  1593. */
  1594. 'escape': reEscape,
  1595. /**
  1596. * Used to detect code to be evaluated.
  1597. *
  1598. * @memberOf _.templateSettings
  1599. * @type {RegExp}
  1600. */
  1601. 'evaluate': reEvaluate,
  1602. /**
  1603. * Used to detect `data` property values to inject.
  1604. *
  1605. * @memberOf _.templateSettings
  1606. * @type {RegExp}
  1607. */
  1608. 'interpolate': reInterpolate,
  1609. /**
  1610. * Used to reference the data object in the template text.
  1611. *
  1612. * @memberOf _.templateSettings
  1613. * @type {string}
  1614. */
  1615. 'variable': '',
  1616. /**
  1617. * Used to import variables into the compiled template.
  1618. *
  1619. * @memberOf _.templateSettings
  1620. * @type {Object}
  1621. */
  1622. 'imports': {
  1623. /**
  1624. * A reference to the `lodash` function.
  1625. *
  1626. * @memberOf _.templateSettings.imports
  1627. * @type {Function}
  1628. */
  1629. '_': lodash
  1630. }
  1631. };
  1632. // Ensure wrappers are instances of `baseLodash`.
  1633. lodash.prototype = baseLodash.prototype;
  1634. lodash.prototype.constructor = lodash;
  1635. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  1636. LodashWrapper.prototype.constructor = LodashWrapper;
  1637. /*------------------------------------------------------------------------*/
  1638. /**
  1639. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1640. *
  1641. * @private
  1642. * @constructor
  1643. * @param {*} value The value to wrap.
  1644. */
  1645. function LazyWrapper(value) {
  1646. this.__wrapped__ = value;
  1647. this.__actions__ = [];
  1648. this.__dir__ = 1;
  1649. this.__filtered__ = false;
  1650. this.__iteratees__ = [];
  1651. this.__takeCount__ = MAX_ARRAY_LENGTH;
  1652. this.__views__ = [];
  1653. }
  1654. /**
  1655. * Creates a clone of the lazy wrapper object.
  1656. *
  1657. * @private
  1658. * @name clone
  1659. * @memberOf LazyWrapper
  1660. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1661. */
  1662. function lazyClone() {
  1663. var result = new LazyWrapper(this.__wrapped__);
  1664. result.__actions__ = copyArray(this.__actions__);
  1665. result.__dir__ = this.__dir__;
  1666. result.__filtered__ = this.__filtered__;
  1667. result.__iteratees__ = copyArray(this.__iteratees__);
  1668. result.__takeCount__ = this.__takeCount__;
  1669. result.__views__ = copyArray(this.__views__);
  1670. return result;
  1671. }
  1672. /**
  1673. * Reverses the direction of lazy iteration.
  1674. *
  1675. * @private
  1676. * @name reverse
  1677. * @memberOf LazyWrapper
  1678. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1679. */
  1680. function lazyReverse() {
  1681. if (this.__filtered__) {
  1682. var result = new LazyWrapper(this);
  1683. result.__dir__ = -1;
  1684. result.__filtered__ = true;
  1685. } else {
  1686. result = this.clone();
  1687. result.__dir__ *= -1;
  1688. }
  1689. return result;
  1690. }
  1691. /**
  1692. * Extracts the unwrapped value from its lazy wrapper.
  1693. *
  1694. * @private
  1695. * @name value
  1696. * @memberOf LazyWrapper
  1697. * @returns {*} Returns the unwrapped value.
  1698. */
  1699. function lazyValue() {
  1700. var array = this.__wrapped__.value(),
  1701. dir = this.__dir__,
  1702. isArr = isArray(array),
  1703. isRight = dir < 0,
  1704. arrLength = isArr ? array.length : 0,
  1705. view = getView(0, arrLength, this.__views__),
  1706. start = view.start,
  1707. end = view.end,
  1708. length = end - start,
  1709. index = isRight ? end : (start - 1),
  1710. iteratees = this.__iteratees__,
  1711. iterLength = iteratees.length,
  1712. resIndex = 0,
  1713. takeCount = nativeMin(length, this.__takeCount__);
  1714. if (!isArr || (!isRight && arrLength == length && takeCount == length)) {
  1715. return baseWrapperValue(array, this.__actions__);
  1716. }
  1717. var result = [];
  1718. outer:
  1719. while (length-- && resIndex < takeCount) {
  1720. index += dir;
  1721. var iterIndex = -1,
  1722. value = array[index];
  1723. while (++iterIndex < iterLength) {
  1724. var data = iteratees[iterIndex],
  1725. iteratee = data.iteratee,
  1726. type = data.type,
  1727. computed = iteratee(value);
  1728. if (type == LAZY_MAP_FLAG) {
  1729. value = computed;
  1730. } else if (!computed) {
  1731. if (type == LAZY_FILTER_FLAG) {
  1732. continue outer;
  1733. } else {
  1734. break outer;
  1735. }
  1736. }
  1737. }
  1738. result[resIndex++] = value;
  1739. }
  1740. return result;
  1741. }
  1742. // Ensure `LazyWrapper` is an instance of `baseLodash`.
  1743. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  1744. LazyWrapper.prototype.constructor = LazyWrapper;
  1745. /*------------------------------------------------------------------------*/
  1746. /**
  1747. * Creates a hash object.
  1748. *
  1749. * @private
  1750. * @constructor
  1751. * @param {Array} [entries] The key-value pairs to cache.
  1752. */
  1753. function Hash(entries) {
  1754. var index = -1,
  1755. length = entries == null ? 0 : entries.length;
  1756. this.clear();
  1757. while (++index < length) {
  1758. var entry = entries[index];
  1759. this.set(entry[0], entry[1]);
  1760. }
  1761. }
  1762. /**
  1763. * Removes all key-value entries from the hash.
  1764. *
  1765. * @private
  1766. * @name clear
  1767. * @memberOf Hash
  1768. */
  1769. function hashClear() {
  1770. this.__data__ = nativeCreate ? nativeCreate(null) : {};
  1771. this.size = 0;
  1772. }
  1773. /**
  1774. * Removes `key` and its value from the hash.
  1775. *
  1776. * @private
  1777. * @name delete
  1778. * @memberOf Hash
  1779. * @param {Object} hash The hash to modify.
  1780. * @param {string} key The key of the value to remove.
  1781. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1782. */
  1783. function hashDelete(key) {
  1784. var result = this.has(key) && delete this.__data__[key];
  1785. this.size -= result ? 1 : 0;
  1786. return result;
  1787. }
  1788. /**
  1789. * Gets the hash value for `key`.
  1790. *
  1791. * @private
  1792. * @name get
  1793. * @memberOf Hash
  1794. * @param {string} key The key of the value to get.
  1795. * @returns {*} Returns the entry value.
  1796. */
  1797. function hashGet(key) {
  1798. var data = this.__data__;
  1799. if (nativeCreate) {
  1800. var result = data[key];
  1801. return result === HASH_UNDEFINED ? undefined : result;
  1802. }
  1803. return hasOwnProperty.call(data, key) ? data[key] : undefined;
  1804. }
  1805. /**
  1806. * Checks if a hash value for `key` exists.
  1807. *
  1808. * @private
  1809. * @name has
  1810. * @memberOf Hash
  1811. * @param {string} key The key of the entry to check.
  1812. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1813. */
  1814. function hashHas(key) {
  1815. var data = this.__data__;
  1816. return nativeCreate ? (data[key] !== undefined) : hasOwnProperty.call(data, key);
  1817. }
  1818. /**
  1819. * Sets the hash `key` to `value`.
  1820. *
  1821. * @private
  1822. * @name set
  1823. * @memberOf Hash
  1824. * @param {string} key The key of the value to set.
  1825. * @param {*} value The value to set.
  1826. * @returns {Object} Returns the hash instance.
  1827. */
  1828. function hashSet(key, value) {
  1829. var data = this.__data__;
  1830. this.size += this.has(key) ? 0 : 1;
  1831. data[key] = (nativeCreate && value === undefined) ? HASH_UNDEFINED : value;
  1832. return this;
  1833. }
  1834. // Add methods to `Hash`.
  1835. Hash.prototype.clear = hashClear;
  1836. Hash.prototype['delete'] = hashDelete;
  1837. Hash.prototype.get = hashGet;
  1838. Hash.prototype.has = hashHas;
  1839. Hash.prototype.set = hashSet;
  1840. /*------------------------------------------------------------------------*/
  1841. /**
  1842. * Creates an list cache object.
  1843. *
  1844. * @private
  1845. * @constructor
  1846. * @param {Array} [entries] The key-value pairs to cache.
  1847. */
  1848. function ListCache(entries) {
  1849. var index = -1,
  1850. length = entries == null ? 0 : entries.length;
  1851. this.clear();
  1852. while (++index < length) {
  1853. var entry = entries[index];
  1854. this.set(entry[0], entry[1]);
  1855. }
  1856. }
  1857. /**
  1858. * Removes all key-value entries from the list cache.
  1859. *
  1860. * @private
  1861. * @name clear
  1862. * @memberOf ListCache
  1863. */
  1864. function listCacheClear() {
  1865. this.__data__ = [];
  1866. this.size = 0;
  1867. }
  1868. /**
  1869. * Removes `key` and its value from the list cache.
  1870. *
  1871. * @private
  1872. * @name delete
  1873. * @memberOf ListCache
  1874. * @param {string} key The key of the value to remove.
  1875. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1876. */
  1877. function listCacheDelete(key) {
  1878. var data = this.__data__,
  1879. index = assocIndexOf(data, key);
  1880. if (index < 0) {
  1881. return false;
  1882. }
  1883. var lastIndex = data.length - 1;
  1884. if (index == lastIndex) {
  1885. data.pop();
  1886. } else {
  1887. splice.call(data, index, 1);
  1888. }
  1889. --this.size;
  1890. return true;
  1891. }
  1892. /**
  1893. * Gets the list cache value for `key`.
  1894. *
  1895. * @private
  1896. * @name get
  1897. * @memberOf ListCache
  1898. * @param {string} key The key of the value to get.
  1899. * @returns {*} Returns the entry value.
  1900. */
  1901. function listCacheGet(key) {
  1902. var data = this.__data__,
  1903. index = assocIndexOf(data, key);
  1904. return index < 0 ? undefined : data[index][1];
  1905. }
  1906. /**
  1907. * Checks if a list cache value for `key` exists.
  1908. *
  1909. * @private
  1910. * @name has
  1911. * @memberOf ListCache
  1912. * @param {string} key The key of the entry to check.
  1913. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1914. */
  1915. function listCacheHas(key) {
  1916. return assocIndexOf(this.__data__, key) > -1;
  1917. }
  1918. /**
  1919. * Sets the list cache `key` to `value`.
  1920. *
  1921. * @private
  1922. * @name set
  1923. * @memberOf ListCache
  1924. * @param {string} key The key of the value to set.
  1925. * @param {*} value The value to set.
  1926. * @returns {Object} Returns the list cache instance.
  1927. */
  1928. function listCacheSet(key, value) {
  1929. var data = this.__data__,
  1930. index = assocIndexOf(data, key);
  1931. if (index < 0) {
  1932. ++this.size;
  1933. data.push([key, value]);
  1934. } else {
  1935. data[index][1] = value;
  1936. }
  1937. return this;
  1938. }
  1939. // Add methods to `ListCache`.
  1940. ListCache.prototype.clear = listCacheClear;
  1941. ListCache.prototype['delete'] = listCacheDelete;
  1942. ListCache.prototype.get = listCacheGet;
  1943. ListCache.prototype.has = listCacheHas;
  1944. ListCache.prototype.set = listCacheSet;
  1945. /*------------------------------------------------------------------------*/
  1946. /**
  1947. * Creates a map cache object to store key-value pairs.
  1948. *
  1949. * @private
  1950. * @constructor
  1951. * @param {Array} [entries] The key-value pairs to cache.
  1952. */
  1953. function MapCache(entries) {
  1954. var index = -1,
  1955. length = entries == null ? 0 : entries.length;
  1956. this.clear();
  1957. while (++index < length) {
  1958. var entry = entries[index];
  1959. this.set(entry[0], entry[1]);
  1960. }
  1961. }
  1962. /**
  1963. * Removes all key-value entries from the map.
  1964. *
  1965. * @private
  1966. * @name clear
  1967. * @memberOf MapCache
  1968. */
  1969. function mapCacheClear() {
  1970. this.size = 0;
  1971. this.__data__ = {
  1972. 'hash': new Hash,
  1973. 'map': new (Map || ListCache),
  1974. 'string': new Hash
  1975. };
  1976. }
  1977. /**
  1978. * Removes `key` and its value from the map.
  1979. *
  1980. * @private
  1981. * @name delete
  1982. * @memberOf MapCache
  1983. * @param {string} key The key of the value to remove.
  1984. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  1985. */
  1986. function mapCacheDelete(key) {
  1987. var result = getMapData(this, key)['delete'](key);
  1988. this.size -= result ? 1 : 0;
  1989. return result;
  1990. }
  1991. /**
  1992. * Gets the map value for `key`.
  1993. *
  1994. * @private
  1995. * @name get
  1996. * @memberOf MapCache
  1997. * @param {string} key The key of the value to get.
  1998. * @returns {*} Returns the entry value.
  1999. */
  2000. function mapCacheGet(key) {
  2001. return getMapData(this, key).get(key);
  2002. }
  2003. /**
  2004. * Checks if a map value for `key` exists.
  2005. *
  2006. * @private
  2007. * @name has
  2008. * @memberOf MapCache
  2009. * @param {string} key The key of the entry to check.
  2010. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2011. */
  2012. function mapCacheHas(key) {
  2013. return getMapData(this, key).has(key);
  2014. }
  2015. /**
  2016. * Sets the map `key` to `value`.
  2017. *
  2018. * @private
  2019. * @name set
  2020. * @memberOf MapCache
  2021. * @param {string} key The key of the value to set.
  2022. * @param {*} value The value to set.
  2023. * @returns {Object} Returns the map cache instance.
  2024. */
  2025. function mapCacheSet(key, value) {
  2026. var data = getMapData(this, key),
  2027. size = data.size;
  2028. data.set(key, value);
  2029. this.size += data.size == size ? 0 : 1;
  2030. return this;
  2031. }
  2032. // Add methods to `MapCache`.
  2033. MapCache.prototype.clear = mapCacheClear;
  2034. MapCache.prototype['delete'] = mapCacheDelete;
  2035. MapCache.prototype.get = mapCacheGet;
  2036. MapCache.prototype.has = mapCacheHas;
  2037. MapCache.prototype.set = mapCacheSet;
  2038. /*------------------------------------------------------------------------*/
  2039. /**
  2040. *
  2041. * Creates an array cache object to store unique values.
  2042. *
  2043. * @private
  2044. * @constructor
  2045. * @param {Array} [values] The values to cache.
  2046. */
  2047. function SetCache(values) {
  2048. var index = -1,
  2049. length = values == null ? 0 : values.length;
  2050. this.__data__ = new MapCache;
  2051. while (++index < length) {
  2052. this.add(values[index]);
  2053. }
  2054. }
  2055. /**
  2056. * Adds `value` to the array cache.
  2057. *
  2058. * @private
  2059. * @name add
  2060. * @memberOf SetCache
  2061. * @alias push
  2062. * @param {*} value The value to cache.
  2063. * @returns {Object} Returns the cache instance.
  2064. */
  2065. function setCacheAdd(value) {
  2066. this.__data__.set(value, HASH_UNDEFINED);
  2067. return this;
  2068. }
  2069. /**
  2070. * Checks if `value` is in the array cache.
  2071. *
  2072. * @private
  2073. * @name has
  2074. * @memberOf SetCache
  2075. * @param {*} value The value to search for.
  2076. * @returns {number} Returns `true` if `value` is found, else `false`.
  2077. */
  2078. function setCacheHas(value) {
  2079. return this.__data__.has(value);
  2080. }
  2081. // Add methods to `SetCache`.
  2082. SetCache.prototype.add = SetCache.prototype.push = setCacheAdd;
  2083. SetCache.prototype.has = setCacheHas;
  2084. /*------------------------------------------------------------------------*/
  2085. /**
  2086. * Creates a stack cache object to store key-value pairs.
  2087. *
  2088. * @private
  2089. * @constructor
  2090. * @param {Array} [entries] The key-value pairs to cache.
  2091. */
  2092. function Stack(entries) {
  2093. var data = this.__data__ = new ListCache(entries);
  2094. this.size = data.size;
  2095. }
  2096. /**
  2097. * Removes all key-value entries from the stack.
  2098. *
  2099. * @private
  2100. * @name clear
  2101. * @memberOf Stack
  2102. */
  2103. function stackClear() {
  2104. this.__data__ = new ListCache;
  2105. this.size = 0;
  2106. }
  2107. /**
  2108. * Removes `key` and its value from the stack.
  2109. *
  2110. * @private
  2111. * @name delete
  2112. * @memberOf Stack
  2113. * @param {string} key The key of the value to remove.
  2114. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  2115. */
  2116. function stackDelete(key) {
  2117. var data = this.__data__,
  2118. result = data['delete'](key);
  2119. this.size = data.size;
  2120. return result;
  2121. }
  2122. /**
  2123. * Gets the stack value for `key`.
  2124. *
  2125. * @private
  2126. * @name get
  2127. * @memberOf Stack
  2128. * @param {string} key The key of the value to get.
  2129. * @returns {*} Returns the entry value.
  2130. */
  2131. function stackGet(key) {
  2132. return this.__data__.get(key);
  2133. }
  2134. /**
  2135. * Checks if a stack value for `key` exists.
  2136. *
  2137. * @private
  2138. * @name has
  2139. * @memberOf Stack
  2140. * @param {string} key The key of the entry to check.
  2141. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  2142. */
  2143. function stackHas(key) {
  2144. return this.__data__.has(key);
  2145. }
  2146. /**
  2147. * Sets the stack `key` to `value`.
  2148. *
  2149. * @private
  2150. * @name set
  2151. * @memberOf Stack
  2152. * @param {string} key The key of the value to set.
  2153. * @param {*} value The value to set.
  2154. * @returns {Object} Returns the stack cache instance.
  2155. */
  2156. function stackSet(key, value) {
  2157. var data = this.__data__;
  2158. if (data instanceof ListCache) {
  2159. var pairs = data.__data__;
  2160. if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) {
  2161. pairs.push([key, value]);
  2162. this.size = ++data.size;
  2163. return this;
  2164. }
  2165. data = this.__data__ = new MapCache(pairs);
  2166. }
  2167. data.set(key, value);
  2168. this.size = data.size;
  2169. return this;
  2170. }
  2171. // Add methods to `Stack`.
  2172. Stack.prototype.clear = stackClear;
  2173. Stack.prototype['delete'] = stackDelete;
  2174. Stack.prototype.get = stackGet;
  2175. Stack.prototype.has = stackHas;
  2176. Stack.prototype.set = stackSet;
  2177. /*------------------------------------------------------------------------*/
  2178. /**
  2179. * Creates an array of the enumerable property names of the array-like `value`.
  2180. *
  2181. * @private
  2182. * @param {*} value The value to query.
  2183. * @param {boolean} inherited Specify returning inherited property names.
  2184. * @returns {Array} Returns the array of property names.
  2185. */
  2186. function arrayLikeKeys(value, inherited) {
  2187. var isArr = isArray(value),
  2188. isArg = !isArr && isArguments(value),
  2189. isBuff = !isArr && !isArg && isBuffer(value),
  2190. isType = !isArr && !isArg && !isBuff && isTypedArray(value),
  2191. skipIndexes = isArr || isArg || isBuff || isType,
  2192. result = skipIndexes ? baseTimes(value.length, String) : [],
  2193. length = result.length;
  2194. for (var key in value) {
  2195. if ((inherited || hasOwnProperty.call(value, key)) &&
  2196. !(skipIndexes && (
  2197. // Safari 9 has enumerable `arguments.length` in strict mode.
  2198. key == 'length' ||
  2199. // Node.js 0.10 has enumerable non-index properties on buffers.
  2200. (isBuff && (key == 'offset' || key == 'parent')) ||
  2201. // PhantomJS 2 has enumerable non-index properties on typed arrays.
  2202. (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) ||
  2203. // Skip index properties.
  2204. isIndex(key, length)
  2205. ))) {
  2206. result.push(key);
  2207. }
  2208. }
  2209. return result;
  2210. }
  2211. /**
  2212. * A specialized version of `_.sample` for arrays.
  2213. *
  2214. * @private
  2215. * @param {Array} array The array to sample.
  2216. * @returns {*} Returns the random element.
  2217. */
  2218. function arraySample(array) {
  2219. var length = array.length;
  2220. return length ? array[baseRandom(0, length - 1)] : undefined;
  2221. }
  2222. /**
  2223. * A specialized version of `_.sampleSize` for arrays.
  2224. *
  2225. * @private
  2226. * @param {Array} array The array to sample.
  2227. * @param {number} n The number of elements to sample.
  2228. * @returns {Array} Returns the random elements.
  2229. */
  2230. function arraySampleSize(array, n) {
  2231. return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length));
  2232. }
  2233. /**
  2234. * A specialized version of `_.shuffle` for arrays.
  2235. *
  2236. * @private
  2237. * @param {Array} array The array to shuffle.
  2238. * @returns {Array} Returns the new shuffled array.
  2239. */
  2240. function arrayShuffle(array) {
  2241. return shuffleSelf(copyArray(array));
  2242. }
  2243. /**
  2244. * This function is like `assignValue` except that it doesn't assign
  2245. * `undefined` values.
  2246. *
  2247. * @private
  2248. * @param {Object} object The object to modify.
  2249. * @param {string} key The key of the property to assign.
  2250. * @param {*} value The value to assign.
  2251. */
  2252. function assignMergeValue(object, key, value) {
  2253. if ((value !== undefined && !eq(object[key], value)) ||
  2254. (value === undefined && !(key in object))) {
  2255. baseAssignValue(object, key, value);
  2256. }
  2257. }
  2258. /**
  2259. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  2260. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  2261. * for equality comparisons.
  2262. *
  2263. * @private
  2264. * @param {Object} object The object to modify.
  2265. * @param {string} key The key of the property to assign.
  2266. * @param {*} value The value to assign.
  2267. */
  2268. function assignValue(object, key, value) {
  2269. var objValue = object[key];
  2270. if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) ||
  2271. (value === undefined && !(key in object))) {
  2272. baseAssignValue(object, key, value);
  2273. }
  2274. }
  2275. /**
  2276. * Gets the index at which the `key` is found in `array` of key-value pairs.
  2277. *
  2278. * @private
  2279. * @param {Array} array The array to inspect.
  2280. * @param {*} key The key to search for.
  2281. * @returns {number} Returns the index of the matched value, else `-1`.
  2282. */
  2283. function assocIndexOf(array, key) {
  2284. var length = array.length;
  2285. while (length--) {
  2286. if (eq(array[length][0], key)) {
  2287. return length;
  2288. }
  2289. }
  2290. return -1;
  2291. }
  2292. /**
  2293. * Aggregates elements of `collection` on `accumulator` with keys transformed
  2294. * by `iteratee` and values set by `setter`.
  2295. *
  2296. * @private
  2297. * @param {Array|Object} collection The collection to iterate over.
  2298. * @param {Function} setter The function to set `accumulator` values.
  2299. * @param {Function} iteratee The iteratee to transform keys.
  2300. * @param {Object} accumulator The initial aggregated object.
  2301. * @returns {Function} Returns `accumulator`.
  2302. */
  2303. function baseAggregator(collection, setter, iteratee, accumulator) {
  2304. baseEach(collection, function(value, key, collection) {
  2305. setter(accumulator, value, iteratee(value), collection);
  2306. });
  2307. return accumulator;
  2308. }
  2309. /**
  2310. * The base implementation of `_.assign` without support for multiple sources
  2311. * or `customizer` functions.
  2312. *
  2313. * @private
  2314. * @param {Object} object The destination object.
  2315. * @param {Object} source The source object.
  2316. * @returns {Object} Returns `object`.
  2317. */
  2318. function baseAssign(object, source) {
  2319. return object && copyObject(source, keys(source), object);
  2320. }
  2321. /**
  2322. * The base implementation of `_.assignIn` without support for multiple sources
  2323. * or `customizer` functions.
  2324. *
  2325. * @private
  2326. * @param {Object} object The destination object.
  2327. * @param {Object} source The source object.
  2328. * @returns {Object} Returns `object`.
  2329. */
  2330. function baseAssignIn(object, source) {
  2331. return object && copyObject(source, keysIn(source), object);
  2332. }
  2333. /**
  2334. * The base implementation of `assignValue` and `assignMergeValue` without
  2335. * value checks.
  2336. *
  2337. * @private
  2338. * @param {Object} object The object to modify.
  2339. * @param {string} key The key of the property to assign.
  2340. * @param {*} value The value to assign.
  2341. */
  2342. function baseAssignValue(object, key, value) {
  2343. if (key == '__proto__' && defineProperty) {
  2344. defineProperty(object, key, {
  2345. 'configurable': true,
  2346. 'enumerable': true,
  2347. 'value': value,
  2348. 'writable': true
  2349. });
  2350. } else {
  2351. object[key] = value;
  2352. }
  2353. }
  2354. /**
  2355. * The base implementation of `_.at` without support for individual paths.
  2356. *
  2357. * @private
  2358. * @param {Object} object The object to iterate over.
  2359. * @param {string[]} paths The property paths to pick.
  2360. * @returns {Array} Returns the picked elements.
  2361. */
  2362. function baseAt(object, paths) {
  2363. var index = -1,
  2364. length = paths.length,
  2365. result = Array(length),
  2366. skip = object == null;
  2367. while (++index < length) {
  2368. result[index] = skip ? undefined : get(object, paths[index]);
  2369. }
  2370. return result;
  2371. }
  2372. /**
  2373. * The base implementation of `_.clamp` which doesn't coerce arguments.
  2374. *
  2375. * @private
  2376. * @param {number} number The number to clamp.
  2377. * @param {number} [lower] The lower bound.
  2378. * @param {number} upper The upper bound.
  2379. * @returns {number} Returns the clamped number.
  2380. */
  2381. function baseClamp(number, lower, upper) {
  2382. if (number === number) {
  2383. if (upper !== undefined) {
  2384. number = number <= upper ? number : upper;
  2385. }
  2386. if (lower !== undefined) {
  2387. number = number >= lower ? number : lower;
  2388. }
  2389. }
  2390. return number;
  2391. }
  2392. /**
  2393. * The base implementation of `_.clone` and `_.cloneDeep` which tracks
  2394. * traversed objects.
  2395. *
  2396. * @private
  2397. * @param {*} value The value to clone.
  2398. * @param {boolean} bitmask The bitmask flags.
  2399. * 1 - Deep clone
  2400. * 2 - Flatten inherited properties
  2401. * 4 - Clone symbols
  2402. * @param {Function} [customizer] The function to customize cloning.
  2403. * @param {string} [key] The key of `value`.
  2404. * @param {Object} [object] The parent object of `value`.
  2405. * @param {Object} [stack] Tracks traversed objects and their clone counterparts.
  2406. * @returns {*} Returns the cloned value.
  2407. */
  2408. function baseClone(value, bitmask, customizer, key, object, stack) {
  2409. var result,
  2410. isDeep = bitmask & CLONE_DEEP_FLAG,
  2411. isFlat = bitmask & CLONE_FLAT_FLAG,
  2412. isFull = bitmask & CLONE_SYMBOLS_FLAG;
  2413. if (customizer) {
  2414. result = object ? customizer(value, key, object, stack) : customizer(value);
  2415. }
  2416. if (result !== undefined) {
  2417. return result;
  2418. }
  2419. if (!isObject(value)) {
  2420. return value;
  2421. }
  2422. var isArr = isArray(value);
  2423. if (isArr) {
  2424. result = initCloneArray(value);
  2425. if (!isDeep) {
  2426. return copyArray(value, result);
  2427. }
  2428. } else {
  2429. var tag = getTag(value),
  2430. isFunc = tag == funcTag || tag == genTag;
  2431. if (isBuffer(value)) {
  2432. return cloneBuffer(value, isDeep);
  2433. }
  2434. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  2435. result = (isFlat || isFunc) ? {} : initCloneObject(value);
  2436. if (!isDeep) {
  2437. return isFlat
  2438. ? copySymbolsIn(value, baseAssignIn(result, value))
  2439. : copySymbols(value, baseAssign(result, value));
  2440. }
  2441. } else {
  2442. if (!cloneableTags[tag]) {
  2443. return object ? value : {};
  2444. }
  2445. result = initCloneByTag(value, tag, isDeep);
  2446. }
  2447. }
  2448. // Check for circular references and return its corresponding clone.
  2449. stack || (stack = new Stack);
  2450. var stacked = stack.get(value);
  2451. if (stacked) {
  2452. return stacked;
  2453. }
  2454. stack.set(value, result);
  2455. if (isSet(value)) {
  2456. value.forEach(function(subValue) {
  2457. result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack));
  2458. });
  2459. } else if (isMap(value)) {
  2460. value.forEach(function(subValue, key) {
  2461. result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2462. });
  2463. }
  2464. var keysFunc = isFull
  2465. ? (isFlat ? getAllKeysIn : getAllKeys)
  2466. : (isFlat ? keysIn : keys);
  2467. var props = isArr ? undefined : keysFunc(value);
  2468. arrayEach(props || value, function(subValue, key) {
  2469. if (props) {
  2470. key = subValue;
  2471. subValue = value[key];
  2472. }
  2473. // Recursively populate clone (susceptible to call stack limits).
  2474. assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack));
  2475. });
  2476. return result;
  2477. }
  2478. /**
  2479. * The base implementation of `_.conforms` which doesn't clone `source`.
  2480. *
  2481. * @private
  2482. * @param {Object} source The object of property predicates to conform to.
  2483. * @returns {Function} Returns the new spec function.
  2484. */
  2485. function baseConforms(source) {
  2486. var props = keys(source);
  2487. return function(object) {
  2488. return baseConformsTo(object, source, props);
  2489. };
  2490. }
  2491. /**
  2492. * The base implementation of `_.conformsTo` which accepts `props` to check.
  2493. *
  2494. * @private
  2495. * @param {Object} object The object to inspect.
  2496. * @param {Object} source The object of property predicates to conform to.
  2497. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  2498. */
  2499. function baseConformsTo(object, source, props) {
  2500. var length = props.length;
  2501. if (object == null) {
  2502. return !length;
  2503. }
  2504. object = Object(object);
  2505. while (length--) {
  2506. var key = props[length],
  2507. predicate = source[key],
  2508. value = object[key];
  2509. if ((value === undefined && !(key in object)) || !predicate(value)) {
  2510. return false;
  2511. }
  2512. }
  2513. return true;
  2514. }
  2515. /**
  2516. * The base implementation of `_.delay` and `_.defer` which accepts `args`
  2517. * to provide to `func`.
  2518. *
  2519. * @private
  2520. * @param {Function} func The function to delay.
  2521. * @param {number} wait The number of milliseconds to delay invocation.
  2522. * @param {Array} args The arguments to provide to `func`.
  2523. * @returns {number|Object} Returns the timer id or timeout object.
  2524. */
  2525. function baseDelay(func, wait, args) {
  2526. if (typeof func != 'function') {
  2527. throw new TypeError(FUNC_ERROR_TEXT);
  2528. }
  2529. return setTimeout(function() { func.apply(undefined, args); }, wait);
  2530. }
  2531. /**
  2532. * The base implementation of methods like `_.difference` without support
  2533. * for excluding multiple arrays or iteratee shorthands.
  2534. *
  2535. * @private
  2536. * @param {Array} array The array to inspect.
  2537. * @param {Array} values The values to exclude.
  2538. * @param {Function} [iteratee] The iteratee invoked per element.
  2539. * @param {Function} [comparator] The comparator invoked per element.
  2540. * @returns {Array} Returns the new array of filtered values.
  2541. */
  2542. function baseDifference(array, values, iteratee, comparator) {
  2543. var index = -1,
  2544. includes = arrayIncludes,
  2545. isCommon = true,
  2546. length = array.length,
  2547. result = [],
  2548. valuesLength = values.length;
  2549. if (!length) {
  2550. return result;
  2551. }
  2552. if (iteratee) {
  2553. values = arrayMap(values, baseUnary(iteratee));
  2554. }
  2555. if (comparator) {
  2556. includes = arrayIncludesWith;
  2557. isCommon = false;
  2558. }
  2559. else if (values.length >= LARGE_ARRAY_SIZE) {
  2560. includes = cacheHas;
  2561. isCommon = false;
  2562. values = new SetCache(values);
  2563. }
  2564. outer:
  2565. while (++index < length) {
  2566. var value = array[index],
  2567. computed = iteratee == null ? value : iteratee(value);
  2568. value = (comparator || value !== 0) ? value : 0;
  2569. if (isCommon && computed === computed) {
  2570. var valuesIndex = valuesLength;
  2571. while (valuesIndex--) {
  2572. if (values[valuesIndex] === computed) {
  2573. continue outer;
  2574. }
  2575. }
  2576. result.push(value);
  2577. }
  2578. else if (!includes(values, computed, comparator)) {
  2579. result.push(value);
  2580. }
  2581. }
  2582. return result;
  2583. }
  2584. /**
  2585. * The base implementation of `_.forEach` without support for iteratee shorthands.
  2586. *
  2587. * @private
  2588. * @param {Array|Object} collection The collection to iterate over.
  2589. * @param {Function} iteratee The function invoked per iteration.
  2590. * @returns {Array|Object} Returns `collection`.
  2591. */
  2592. var baseEach = createBaseEach(baseForOwn);
  2593. /**
  2594. * The base implementation of `_.forEachRight` without support for iteratee shorthands.
  2595. *
  2596. * @private
  2597. * @param {Array|Object} collection The collection to iterate over.
  2598. * @param {Function} iteratee The function invoked per iteration.
  2599. * @returns {Array|Object} Returns `collection`.
  2600. */
  2601. var baseEachRight = createBaseEach(baseForOwnRight, true);
  2602. /**
  2603. * The base implementation of `_.every` without support for iteratee shorthands.
  2604. *
  2605. * @private
  2606. * @param {Array|Object} collection The collection to iterate over.
  2607. * @param {Function} predicate The function invoked per iteration.
  2608. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  2609. * else `false`
  2610. */
  2611. function baseEvery(collection, predicate) {
  2612. var result = true;
  2613. baseEach(collection, function(value, index, collection) {
  2614. result = !!predicate(value, index, collection);
  2615. return result;
  2616. });
  2617. return result;
  2618. }
  2619. /**
  2620. * The base implementation of methods like `_.max` and `_.min` which accepts a
  2621. * `comparator` to determine the extremum value.
  2622. *
  2623. * @private
  2624. * @param {Array} array The array to iterate over.
  2625. * @param {Function} iteratee The iteratee invoked per iteration.
  2626. * @param {Function} comparator The comparator used to compare values.
  2627. * @returns {*} Returns the extremum value.
  2628. */
  2629. function baseExtremum(array, iteratee, comparator) {
  2630. var index = -1,
  2631. length = array.length;
  2632. while (++index < length) {
  2633. var value = array[index],
  2634. current = iteratee(value);
  2635. if (current != null && (computed === undefined
  2636. ? (current === current && !isSymbol(current))
  2637. : comparator(current, computed)
  2638. )) {
  2639. var computed = current,
  2640. result = value;
  2641. }
  2642. }
  2643. return result;
  2644. }
  2645. /**
  2646. * The base implementation of `_.fill` without an iteratee call guard.
  2647. *
  2648. * @private
  2649. * @param {Array} array The array to fill.
  2650. * @param {*} value The value to fill `array` with.
  2651. * @param {number} [start=0] The start position.
  2652. * @param {number} [end=array.length] The end position.
  2653. * @returns {Array} Returns `array`.
  2654. */
  2655. function baseFill(array, value, start, end) {
  2656. var length = array.length;
  2657. start = toInteger(start);
  2658. if (start < 0) {
  2659. start = -start > length ? 0 : (length + start);
  2660. }
  2661. end = (end === undefined || end > length) ? length : toInteger(end);
  2662. if (end < 0) {
  2663. end += length;
  2664. }
  2665. end = start > end ? 0 : toLength(end);
  2666. while (start < end) {
  2667. array[start++] = value;
  2668. }
  2669. return array;
  2670. }
  2671. /**
  2672. * The base implementation of `_.filter` without support for iteratee shorthands.
  2673. *
  2674. * @private
  2675. * @param {Array|Object} collection The collection to iterate over.
  2676. * @param {Function} predicate The function invoked per iteration.
  2677. * @returns {Array} Returns the new filtered array.
  2678. */
  2679. function baseFilter(collection, predicate) {
  2680. var result = [];
  2681. baseEach(collection, function(value, index, collection) {
  2682. if (predicate(value, index, collection)) {
  2683. result.push(value);
  2684. }
  2685. });
  2686. return result;
  2687. }
  2688. /**
  2689. * The base implementation of `_.flatten` with support for restricting flattening.
  2690. *
  2691. * @private
  2692. * @param {Array} array The array to flatten.
  2693. * @param {number} depth The maximum recursion depth.
  2694. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  2695. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  2696. * @param {Array} [result=[]] The initial result value.
  2697. * @returns {Array} Returns the new flattened array.
  2698. */
  2699. function baseFlatten(array, depth, predicate, isStrict, result) {
  2700. var index = -1,
  2701. length = array.length;
  2702. predicate || (predicate = isFlattenable);
  2703. result || (result = []);
  2704. while (++index < length) {
  2705. var value = array[index];
  2706. if (depth > 0 && predicate(value)) {
  2707. if (depth > 1) {
  2708. // Recursively flatten arrays (susceptible to call stack limits).
  2709. baseFlatten(value, depth - 1, predicate, isStrict, result);
  2710. } else {
  2711. arrayPush(result, value);
  2712. }
  2713. } else if (!isStrict) {
  2714. result[result.length] = value;
  2715. }
  2716. }
  2717. return result;
  2718. }
  2719. /**
  2720. * The base implementation of `baseForOwn` which iterates over `object`
  2721. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  2722. * Iteratee functions may exit iteration early by explicitly returning `false`.
  2723. *
  2724. * @private
  2725. * @param {Object} object The object to iterate over.
  2726. * @param {Function} iteratee The function invoked per iteration.
  2727. * @param {Function} keysFunc The function to get the keys of `object`.
  2728. * @returns {Object} Returns `object`.
  2729. */
  2730. var baseFor = createBaseFor();
  2731. /**
  2732. * This function is like `baseFor` except that it iterates over properties
  2733. * in the opposite order.
  2734. *
  2735. * @private
  2736. * @param {Object} object The object to iterate over.
  2737. * @param {Function} iteratee The function invoked per iteration.
  2738. * @param {Function} keysFunc The function to get the keys of `object`.
  2739. * @returns {Object} Returns `object`.
  2740. */
  2741. var baseForRight = createBaseFor(true);
  2742. /**
  2743. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  2744. *
  2745. * @private
  2746. * @param {Object} object The object to iterate over.
  2747. * @param {Function} iteratee The function invoked per iteration.
  2748. * @returns {Object} Returns `object`.
  2749. */
  2750. function baseForOwn(object, iteratee) {
  2751. return object && baseFor(object, iteratee, keys);
  2752. }
  2753. /**
  2754. * The base implementation of `_.forOwnRight` without support for iteratee shorthands.
  2755. *
  2756. * @private
  2757. * @param {Object} object The object to iterate over.
  2758. * @param {Function} iteratee The function invoked per iteration.
  2759. * @returns {Object} Returns `object`.
  2760. */
  2761. function baseForOwnRight(object, iteratee) {
  2762. return object && baseForRight(object, iteratee, keys);
  2763. }
  2764. /**
  2765. * The base implementation of `_.functions` which creates an array of
  2766. * `object` function property names filtered from `props`.
  2767. *
  2768. * @private
  2769. * @param {Object} object The object to inspect.
  2770. * @param {Array} props The property names to filter.
  2771. * @returns {Array} Returns the function names.
  2772. */
  2773. function baseFunctions(object, props) {
  2774. return arrayFilter(props, function(key) {
  2775. return isFunction(object[key]);
  2776. });
  2777. }
  2778. /**
  2779. * The base implementation of `_.get` without support for default values.
  2780. *
  2781. * @private
  2782. * @param {Object} object The object to query.
  2783. * @param {Array|string} path The path of the property to get.
  2784. * @returns {*} Returns the resolved value.
  2785. */
  2786. function baseGet(object, path) {
  2787. path = castPath(path, object);
  2788. var index = 0,
  2789. length = path.length;
  2790. while (object != null && index < length) {
  2791. object = object[toKey(path[index++])];
  2792. }
  2793. return (index && index == length) ? object : undefined;
  2794. }
  2795. /**
  2796. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  2797. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  2798. * symbols of `object`.
  2799. *
  2800. * @private
  2801. * @param {Object} object The object to query.
  2802. * @param {Function} keysFunc The function to get the keys of `object`.
  2803. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  2804. * @returns {Array} Returns the array of property names and symbols.
  2805. */
  2806. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  2807. var result = keysFunc(object);
  2808. return isArray(object) ? result : arrayPush(result, symbolsFunc(object));
  2809. }
  2810. /**
  2811. * The base implementation of `getTag` without fallbacks for buggy environments.
  2812. *
  2813. * @private
  2814. * @param {*} value The value to query.
  2815. * @returns {string} Returns the `toStringTag`.
  2816. */
  2817. function baseGetTag(value) {
  2818. if (value == null) {
  2819. return value === undefined ? undefinedTag : nullTag;
  2820. }
  2821. return (symToStringTag && symToStringTag in Object(value))
  2822. ? getRawTag(value)
  2823. : objectToString(value);
  2824. }
  2825. /**
  2826. * The base implementation of `_.gt` which doesn't coerce arguments.
  2827. *
  2828. * @private
  2829. * @param {*} value The value to compare.
  2830. * @param {*} other The other value to compare.
  2831. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  2832. * else `false`.
  2833. */
  2834. function baseGt(value, other) {
  2835. return value > other;
  2836. }
  2837. /**
  2838. * The base implementation of `_.has` without support for deep paths.
  2839. *
  2840. * @private
  2841. * @param {Object} [object] The object to query.
  2842. * @param {Array|string} key The key to check.
  2843. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2844. */
  2845. function baseHas(object, key) {
  2846. return object != null && hasOwnProperty.call(object, key);
  2847. }
  2848. /**
  2849. * The base implementation of `_.hasIn` without support for deep paths.
  2850. *
  2851. * @private
  2852. * @param {Object} [object] The object to query.
  2853. * @param {Array|string} key The key to check.
  2854. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  2855. */
  2856. function baseHasIn(object, key) {
  2857. return object != null && key in Object(object);
  2858. }
  2859. /**
  2860. * The base implementation of `_.inRange` which doesn't coerce arguments.
  2861. *
  2862. * @private
  2863. * @param {number} number The number to check.
  2864. * @param {number} start The start of the range.
  2865. * @param {number} end The end of the range.
  2866. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  2867. */
  2868. function baseInRange(number, start, end) {
  2869. return number >= nativeMin(start, end) && number < nativeMax(start, end);
  2870. }
  2871. /**
  2872. * The base implementation of methods like `_.intersection`, without support
  2873. * for iteratee shorthands, that accepts an array of arrays to inspect.
  2874. *
  2875. * @private
  2876. * @param {Array} arrays The arrays to inspect.
  2877. * @param {Function} [iteratee] The iteratee invoked per element.
  2878. * @param {Function} [comparator] The comparator invoked per element.
  2879. * @returns {Array} Returns the new array of shared values.
  2880. */
  2881. function baseIntersection(arrays, iteratee, comparator) {
  2882. var includes = comparator ? arrayIncludesWith : arrayIncludes,
  2883. length = arrays[0].length,
  2884. othLength = arrays.length,
  2885. othIndex = othLength,
  2886. caches = Array(othLength),
  2887. maxLength = Infinity,
  2888. result = [];
  2889. while (othIndex--) {
  2890. var array = arrays[othIndex];
  2891. if (othIndex && iteratee) {
  2892. array = arrayMap(array, baseUnary(iteratee));
  2893. }
  2894. maxLength = nativeMin(array.length, maxLength);
  2895. caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120))
  2896. ? new SetCache(othIndex && array)
  2897. : undefined;
  2898. }
  2899. array = arrays[0];
  2900. var index = -1,
  2901. seen = caches[0];
  2902. outer:
  2903. while (++index < length && result.length < maxLength) {
  2904. var value = array[index],
  2905. computed = iteratee ? iteratee(value) : value;
  2906. value = (comparator || value !== 0) ? value : 0;
  2907. if (!(seen
  2908. ? cacheHas(seen, computed)
  2909. : includes(result, computed, comparator)
  2910. )) {
  2911. othIndex = othLength;
  2912. while (--othIndex) {
  2913. var cache = caches[othIndex];
  2914. if (!(cache
  2915. ? cacheHas(cache, computed)
  2916. : includes(arrays[othIndex], computed, comparator))
  2917. ) {
  2918. continue outer;
  2919. }
  2920. }
  2921. if (seen) {
  2922. seen.push(computed);
  2923. }
  2924. result.push(value);
  2925. }
  2926. }
  2927. return result;
  2928. }
  2929. /**
  2930. * The base implementation of `_.invert` and `_.invertBy` which inverts
  2931. * `object` with values transformed by `iteratee` and set by `setter`.
  2932. *
  2933. * @private
  2934. * @param {Object} object The object to iterate over.
  2935. * @param {Function} setter The function to set `accumulator` values.
  2936. * @param {Function} iteratee The iteratee to transform values.
  2937. * @param {Object} accumulator The initial inverted object.
  2938. * @returns {Function} Returns `accumulator`.
  2939. */
  2940. function baseInverter(object, setter, iteratee, accumulator) {
  2941. baseForOwn(object, function(value, key, object) {
  2942. setter(accumulator, iteratee(value), key, object);
  2943. });
  2944. return accumulator;
  2945. }
  2946. /**
  2947. * The base implementation of `_.invoke` without support for individual
  2948. * method arguments.
  2949. *
  2950. * @private
  2951. * @param {Object} object The object to query.
  2952. * @param {Array|string} path The path of the method to invoke.
  2953. * @param {Array} args The arguments to invoke the method with.
  2954. * @returns {*} Returns the result of the invoked method.
  2955. */
  2956. function baseInvoke(object, path, args) {
  2957. path = castPath(path, object);
  2958. object = parent(object, path);
  2959. var func = object == null ? object : object[toKey(last(path))];
  2960. return func == null ? undefined : apply(func, object, args);
  2961. }
  2962. /**
  2963. * The base implementation of `_.isArguments`.
  2964. *
  2965. * @private
  2966. * @param {*} value The value to check.
  2967. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  2968. */
  2969. function baseIsArguments(value) {
  2970. return isObjectLike(value) && baseGetTag(value) == argsTag;
  2971. }
  2972. /**
  2973. * The base implementation of `_.isArrayBuffer` without Node.js optimizations.
  2974. *
  2975. * @private
  2976. * @param {*} value The value to check.
  2977. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  2978. */
  2979. function baseIsArrayBuffer(value) {
  2980. return isObjectLike(value) && baseGetTag(value) == arrayBufferTag;
  2981. }
  2982. /**
  2983. * The base implementation of `_.isDate` without Node.js optimizations.
  2984. *
  2985. * @private
  2986. * @param {*} value The value to check.
  2987. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  2988. */
  2989. function baseIsDate(value) {
  2990. return isObjectLike(value) && baseGetTag(value) == dateTag;
  2991. }
  2992. /**
  2993. * The base implementation of `_.isEqual` which supports partial comparisons
  2994. * and tracks traversed objects.
  2995. *
  2996. * @private
  2997. * @param {*} value The value to compare.
  2998. * @param {*} other The other value to compare.
  2999. * @param {boolean} bitmask The bitmask flags.
  3000. * 1 - Unordered comparison
  3001. * 2 - Partial comparison
  3002. * @param {Function} [customizer] The function to customize comparisons.
  3003. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  3004. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  3005. */
  3006. function baseIsEqual(value, other, bitmask, customizer, stack) {
  3007. if (value === other) {
  3008. return true;
  3009. }
  3010. if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) {
  3011. return value !== value && other !== other;
  3012. }
  3013. return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  3014. }
  3015. /**
  3016. * A specialized version of `baseIsEqual` for arrays and objects which performs
  3017. * deep comparisons and tracks traversed objects enabling objects with circular
  3018. * references to be compared.
  3019. *
  3020. * @private
  3021. * @param {Object} object The object to compare.
  3022. * @param {Object} other The other object to compare.
  3023. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  3024. * @param {Function} customizer The function to customize comparisons.
  3025. * @param {Function} equalFunc The function to determine equivalents of values.
  3026. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  3027. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3028. */
  3029. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  3030. var objIsArr = isArray(object),
  3031. othIsArr = isArray(other),
  3032. objTag = objIsArr ? arrayTag : getTag(object),
  3033. othTag = othIsArr ? arrayTag : getTag(other);
  3034. objTag = objTag == argsTag ? objectTag : objTag;
  3035. othTag = othTag == argsTag ? objectTag : othTag;
  3036. var objIsObj = objTag == objectTag,
  3037. othIsObj = othTag == objectTag,
  3038. isSameTag = objTag == othTag;
  3039. if (isSameTag && isBuffer(object)) {
  3040. if (!isBuffer(other)) {
  3041. return false;
  3042. }
  3043. objIsArr = true;
  3044. objIsObj = false;
  3045. }
  3046. if (isSameTag && !objIsObj) {
  3047. stack || (stack = new Stack);
  3048. return (objIsArr || isTypedArray(object))
  3049. ? equalArrays(object, other, bitmask, customizer, equalFunc, stack)
  3050. : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  3051. }
  3052. if (!(bitmask & COMPARE_PARTIAL_FLAG)) {
  3053. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  3054. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  3055. if (objIsWrapped || othIsWrapped) {
  3056. var objUnwrapped = objIsWrapped ? object.value() : object,
  3057. othUnwrapped = othIsWrapped ? other.value() : other;
  3058. stack || (stack = new Stack);
  3059. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  3060. }
  3061. }
  3062. if (!isSameTag) {
  3063. return false;
  3064. }
  3065. stack || (stack = new Stack);
  3066. return equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  3067. }
  3068. /**
  3069. * The base implementation of `_.isMap` without Node.js optimizations.
  3070. *
  3071. * @private
  3072. * @param {*} value The value to check.
  3073. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  3074. */
  3075. function baseIsMap(value) {
  3076. return isObjectLike(value) && getTag(value) == mapTag;
  3077. }
  3078. /**
  3079. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  3080. *
  3081. * @private
  3082. * @param {Object} object The object to inspect.
  3083. * @param {Object} source The object of property values to match.
  3084. * @param {Array} matchData The property names, values, and compare flags to match.
  3085. * @param {Function} [customizer] The function to customize comparisons.
  3086. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  3087. */
  3088. function baseIsMatch(object, source, matchData, customizer) {
  3089. var index = matchData.length,
  3090. length = index,
  3091. noCustomizer = !customizer;
  3092. if (object == null) {
  3093. return !length;
  3094. }
  3095. object = Object(object);
  3096. while (index--) {
  3097. var data = matchData[index];
  3098. if ((noCustomizer && data[2])
  3099. ? data[1] !== object[data[0]]
  3100. : !(data[0] in object)
  3101. ) {
  3102. return false;
  3103. }
  3104. }
  3105. while (++index < length) {
  3106. data = matchData[index];
  3107. var key = data[0],
  3108. objValue = object[key],
  3109. srcValue = data[1];
  3110. if (noCustomizer && data[2]) {
  3111. if (objValue === undefined && !(key in object)) {
  3112. return false;
  3113. }
  3114. } else {
  3115. var stack = new Stack;
  3116. if (customizer) {
  3117. var result = customizer(objValue, srcValue, key, object, source, stack);
  3118. }
  3119. if (!(result === undefined
  3120. ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack)
  3121. : result
  3122. )) {
  3123. return false;
  3124. }
  3125. }
  3126. }
  3127. return true;
  3128. }
  3129. /**
  3130. * The base implementation of `_.isNative` without bad shim checks.
  3131. *
  3132. * @private
  3133. * @param {*} value The value to check.
  3134. * @returns {boolean} Returns `true` if `value` is a native function,
  3135. * else `false`.
  3136. */
  3137. function baseIsNative(value) {
  3138. if (!isObject(value) || isMasked(value)) {
  3139. return false;
  3140. }
  3141. var pattern = isFunction(value) ? reIsNative : reIsHostCtor;
  3142. return pattern.test(toSource(value));
  3143. }
  3144. /**
  3145. * The base implementation of `_.isRegExp` without Node.js optimizations.
  3146. *
  3147. * @private
  3148. * @param {*} value The value to check.
  3149. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  3150. */
  3151. function baseIsRegExp(value) {
  3152. return isObjectLike(value) && baseGetTag(value) == regexpTag;
  3153. }
  3154. /**
  3155. * The base implementation of `_.isSet` without Node.js optimizations.
  3156. *
  3157. * @private
  3158. * @param {*} value The value to check.
  3159. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  3160. */
  3161. function baseIsSet(value) {
  3162. return isObjectLike(value) && getTag(value) == setTag;
  3163. }
  3164. /**
  3165. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  3166. *
  3167. * @private
  3168. * @param {*} value The value to check.
  3169. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  3170. */
  3171. function baseIsTypedArray(value) {
  3172. return isObjectLike(value) &&
  3173. isLength(value.length) && !!typedArrayTags[baseGetTag(value)];
  3174. }
  3175. /**
  3176. * The base implementation of `_.iteratee`.
  3177. *
  3178. * @private
  3179. * @param {*} [value=_.identity] The value to convert to an iteratee.
  3180. * @returns {Function} Returns the iteratee.
  3181. */
  3182. function baseIteratee(value) {
  3183. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  3184. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  3185. if (typeof value == 'function') {
  3186. return value;
  3187. }
  3188. if (value == null) {
  3189. return identity;
  3190. }
  3191. if (typeof value == 'object') {
  3192. return isArray(value)
  3193. ? baseMatchesProperty(value[0], value[1])
  3194. : baseMatches(value);
  3195. }
  3196. return property(value);
  3197. }
  3198. /**
  3199. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  3200. *
  3201. * @private
  3202. * @param {Object} object The object to query.
  3203. * @returns {Array} Returns the array of property names.
  3204. */
  3205. function baseKeys(object) {
  3206. if (!isPrototype(object)) {
  3207. return nativeKeys(object);
  3208. }
  3209. var result = [];
  3210. for (var key in Object(object)) {
  3211. if (hasOwnProperty.call(object, key) && key != 'constructor') {
  3212. result.push(key);
  3213. }
  3214. }
  3215. return result;
  3216. }
  3217. /**
  3218. * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense.
  3219. *
  3220. * @private
  3221. * @param {Object} object The object to query.
  3222. * @returns {Array} Returns the array of property names.
  3223. */
  3224. function baseKeysIn(object) {
  3225. if (!isObject(object)) {
  3226. return nativeKeysIn(object);
  3227. }
  3228. var isProto = isPrototype(object),
  3229. result = [];
  3230. for (var key in object) {
  3231. if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  3232. result.push(key);
  3233. }
  3234. }
  3235. return result;
  3236. }
  3237. /**
  3238. * The base implementation of `_.lt` which doesn't coerce arguments.
  3239. *
  3240. * @private
  3241. * @param {*} value The value to compare.
  3242. * @param {*} other The other value to compare.
  3243. * @returns {boolean} Returns `true` if `value` is less than `other`,
  3244. * else `false`.
  3245. */
  3246. function baseLt(value, other) {
  3247. return value < other;
  3248. }
  3249. /**
  3250. * The base implementation of `_.map` without support for iteratee shorthands.
  3251. *
  3252. * @private
  3253. * @param {Array|Object} collection The collection to iterate over.
  3254. * @param {Function} iteratee The function invoked per iteration.
  3255. * @returns {Array} Returns the new mapped array.
  3256. */
  3257. function baseMap(collection, iteratee) {
  3258. var index = -1,
  3259. result = isArrayLike(collection) ? Array(collection.length) : [];
  3260. baseEach(collection, function(value, key, collection) {
  3261. result[++index] = iteratee(value, key, collection);
  3262. });
  3263. return result;
  3264. }
  3265. /**
  3266. * The base implementation of `_.matches` which doesn't clone `source`.
  3267. *
  3268. * @private
  3269. * @param {Object} source The object of property values to match.
  3270. * @returns {Function} Returns the new spec function.
  3271. */
  3272. function baseMatches(source) {
  3273. var matchData = getMatchData(source);
  3274. if (matchData.length == 1 && matchData[0][2]) {
  3275. return matchesStrictComparable(matchData[0][0], matchData[0][1]);
  3276. }
  3277. return function(object) {
  3278. return object === source || baseIsMatch(object, source, matchData);
  3279. };
  3280. }
  3281. /**
  3282. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  3283. *
  3284. * @private
  3285. * @param {string} path The path of the property to get.
  3286. * @param {*} srcValue The value to match.
  3287. * @returns {Function} Returns the new spec function.
  3288. */
  3289. function baseMatchesProperty(path, srcValue) {
  3290. if (isKey(path) && isStrictComparable(srcValue)) {
  3291. return matchesStrictComparable(toKey(path), srcValue);
  3292. }
  3293. return function(object) {
  3294. var objValue = get(object, path);
  3295. return (objValue === undefined && objValue === srcValue)
  3296. ? hasIn(object, path)
  3297. : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  3298. };
  3299. }
  3300. /**
  3301. * The base implementation of `_.merge` without support for multiple sources.
  3302. *
  3303. * @private
  3304. * @param {Object} object The destination object.
  3305. * @param {Object} source The source object.
  3306. * @param {number} srcIndex The index of `source`.
  3307. * @param {Function} [customizer] The function to customize merged values.
  3308. * @param {Object} [stack] Tracks traversed source values and their merged
  3309. * counterparts.
  3310. */
  3311. function baseMerge(object, source, srcIndex, customizer, stack) {
  3312. if (object === source) {
  3313. return;
  3314. }
  3315. baseFor(source, function(srcValue, key) {
  3316. stack || (stack = new Stack);
  3317. if (isObject(srcValue)) {
  3318. baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack);
  3319. }
  3320. else {
  3321. var newValue = customizer
  3322. ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack)
  3323. : undefined;
  3324. if (newValue === undefined) {
  3325. newValue = srcValue;
  3326. }
  3327. assignMergeValue(object, key, newValue);
  3328. }
  3329. }, keysIn);
  3330. }
  3331. /**
  3332. * A specialized version of `baseMerge` for arrays and objects which performs
  3333. * deep merges and tracks traversed objects enabling objects with circular
  3334. * references to be merged.
  3335. *
  3336. * @private
  3337. * @param {Object} object The destination object.
  3338. * @param {Object} source The source object.
  3339. * @param {string} key The key of the value to merge.
  3340. * @param {number} srcIndex The index of `source`.
  3341. * @param {Function} mergeFunc The function to merge values.
  3342. * @param {Function} [customizer] The function to customize assigned values.
  3343. * @param {Object} [stack] Tracks traversed source values and their merged
  3344. * counterparts.
  3345. */
  3346. function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) {
  3347. var objValue = safeGet(object, key),
  3348. srcValue = safeGet(source, key),
  3349. stacked = stack.get(srcValue);
  3350. if (stacked) {
  3351. assignMergeValue(object, key, stacked);
  3352. return;
  3353. }
  3354. var newValue = customizer
  3355. ? customizer(objValue, srcValue, (key + ''), object, source, stack)
  3356. : undefined;
  3357. var isCommon = newValue === undefined;
  3358. if (isCommon) {
  3359. var isArr = isArray(srcValue),
  3360. isBuff = !isArr && isBuffer(srcValue),
  3361. isTyped = !isArr && !isBuff && isTypedArray(srcValue);
  3362. newValue = srcValue;
  3363. if (isArr || isBuff || isTyped) {
  3364. if (isArray(objValue)) {
  3365. newValue = objValue;
  3366. }
  3367. else if (isArrayLikeObject(objValue)) {
  3368. newValue = copyArray(objValue);
  3369. }
  3370. else if (isBuff) {
  3371. isCommon = false;
  3372. newValue = cloneBuffer(srcValue, true);
  3373. }
  3374. else if (isTyped) {
  3375. isCommon = false;
  3376. newValue = cloneTypedArray(srcValue, true);
  3377. }
  3378. else {
  3379. newValue = [];
  3380. }
  3381. }
  3382. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  3383. newValue = objValue;
  3384. if (isArguments(objValue)) {
  3385. newValue = toPlainObject(objValue);
  3386. }
  3387. else if (!isObject(objValue) || isFunction(objValue)) {
  3388. newValue = initCloneObject(srcValue);
  3389. }
  3390. }
  3391. else {
  3392. isCommon = false;
  3393. }
  3394. }
  3395. if (isCommon) {
  3396. // Recursively merge objects and arrays (susceptible to call stack limits).
  3397. stack.set(srcValue, newValue);
  3398. mergeFunc(newValue, srcValue, srcIndex, customizer, stack);
  3399. stack['delete'](srcValue);
  3400. }
  3401. assignMergeValue(object, key, newValue);
  3402. }
  3403. /**
  3404. * The base implementation of `_.nth` which doesn't coerce arguments.
  3405. *
  3406. * @private
  3407. * @param {Array} array The array to query.
  3408. * @param {number} n The index of the element to return.
  3409. * @returns {*} Returns the nth element of `array`.
  3410. */
  3411. function baseNth(array, n) {
  3412. var length = array.length;
  3413. if (!length) {
  3414. return;
  3415. }
  3416. n += n < 0 ? length : 0;
  3417. return isIndex(n, length) ? array[n] : undefined;
  3418. }
  3419. /**
  3420. * The base implementation of `_.orderBy` without param guards.
  3421. *
  3422. * @private
  3423. * @param {Array|Object} collection The collection to iterate over.
  3424. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  3425. * @param {string[]} orders The sort orders of `iteratees`.
  3426. * @returns {Array} Returns the new sorted array.
  3427. */
  3428. function baseOrderBy(collection, iteratees, orders) {
  3429. if (iteratees.length) {
  3430. iteratees = arrayMap(iteratees, function(iteratee) {
  3431. if (isArray(iteratee)) {
  3432. return function(value) {
  3433. return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee);
  3434. }
  3435. }
  3436. return iteratee;
  3437. });
  3438. } else {
  3439. iteratees = [identity];
  3440. }
  3441. var index = -1;
  3442. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  3443. var result = baseMap(collection, function(value, key, collection) {
  3444. var criteria = arrayMap(iteratees, function(iteratee) {
  3445. return iteratee(value);
  3446. });
  3447. return { 'criteria': criteria, 'index': ++index, 'value': value };
  3448. });
  3449. return baseSortBy(result, function(object, other) {
  3450. return compareMultiple(object, other, orders);
  3451. });
  3452. }
  3453. /**
  3454. * The base implementation of `_.pick` without support for individual
  3455. * property identifiers.
  3456. *
  3457. * @private
  3458. * @param {Object} object The source object.
  3459. * @param {string[]} paths The property paths to pick.
  3460. * @returns {Object} Returns the new object.
  3461. */
  3462. function basePick(object, paths) {
  3463. return basePickBy(object, paths, function(value, path) {
  3464. return hasIn(object, path);
  3465. });
  3466. }
  3467. /**
  3468. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  3469. *
  3470. * @private
  3471. * @param {Object} object The source object.
  3472. * @param {string[]} paths The property paths to pick.
  3473. * @param {Function} predicate The function invoked per property.
  3474. * @returns {Object} Returns the new object.
  3475. */
  3476. function basePickBy(object, paths, predicate) {
  3477. var index = -1,
  3478. length = paths.length,
  3479. result = {};
  3480. while (++index < length) {
  3481. var path = paths[index],
  3482. value = baseGet(object, path);
  3483. if (predicate(value, path)) {
  3484. baseSet(result, castPath(path, object), value);
  3485. }
  3486. }
  3487. return result;
  3488. }
  3489. /**
  3490. * A specialized version of `baseProperty` which supports deep paths.
  3491. *
  3492. * @private
  3493. * @param {Array|string} path The path of the property to get.
  3494. * @returns {Function} Returns the new accessor function.
  3495. */
  3496. function basePropertyDeep(path) {
  3497. return function(object) {
  3498. return baseGet(object, path);
  3499. };
  3500. }
  3501. /**
  3502. * The base implementation of `_.pullAllBy` without support for iteratee
  3503. * shorthands.
  3504. *
  3505. * @private
  3506. * @param {Array} array The array to modify.
  3507. * @param {Array} values The values to remove.
  3508. * @param {Function} [iteratee] The iteratee invoked per element.
  3509. * @param {Function} [comparator] The comparator invoked per element.
  3510. * @returns {Array} Returns `array`.
  3511. */
  3512. function basePullAll(array, values, iteratee, comparator) {
  3513. var indexOf = comparator ? baseIndexOfWith : baseIndexOf,
  3514. index = -1,
  3515. length = values.length,
  3516. seen = array;
  3517. if (array === values) {
  3518. values = copyArray(values);
  3519. }
  3520. if (iteratee) {
  3521. seen = arrayMap(array, baseUnary(iteratee));
  3522. }
  3523. while (++index < length) {
  3524. var fromIndex = 0,
  3525. value = values[index],
  3526. computed = iteratee ? iteratee(value) : value;
  3527. while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) {
  3528. if (seen !== array) {
  3529. splice.call(seen, fromIndex, 1);
  3530. }
  3531. splice.call(array, fromIndex, 1);
  3532. }
  3533. }
  3534. return array;
  3535. }
  3536. /**
  3537. * The base implementation of `_.pullAt` without support for individual
  3538. * indexes or capturing the removed elements.
  3539. *
  3540. * @private
  3541. * @param {Array} array The array to modify.
  3542. * @param {number[]} indexes The indexes of elements to remove.
  3543. * @returns {Array} Returns `array`.
  3544. */
  3545. function basePullAt(array, indexes) {
  3546. var length = array ? indexes.length : 0,
  3547. lastIndex = length - 1;
  3548. while (length--) {
  3549. var index = indexes[length];
  3550. if (length == lastIndex || index !== previous) {
  3551. var previous = index;
  3552. if (isIndex(index)) {
  3553. splice.call(array, index, 1);
  3554. } else {
  3555. baseUnset(array, index);
  3556. }
  3557. }
  3558. }
  3559. return array;
  3560. }
  3561. /**
  3562. * The base implementation of `_.random` without support for returning
  3563. * floating-point numbers.
  3564. *
  3565. * @private
  3566. * @param {number} lower The lower bound.
  3567. * @param {number} upper The upper bound.
  3568. * @returns {number} Returns the random number.
  3569. */
  3570. function baseRandom(lower, upper) {
  3571. return lower + nativeFloor(nativeRandom() * (upper - lower + 1));
  3572. }
  3573. /**
  3574. * The base implementation of `_.range` and `_.rangeRight` which doesn't
  3575. * coerce arguments.
  3576. *
  3577. * @private
  3578. * @param {number} start The start of the range.
  3579. * @param {number} end The end of the range.
  3580. * @param {number} step The value to increment or decrement by.
  3581. * @param {boolean} [fromRight] Specify iterating from right to left.
  3582. * @returns {Array} Returns the range of numbers.
  3583. */
  3584. function baseRange(start, end, step, fromRight) {
  3585. var index = -1,
  3586. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  3587. result = Array(length);
  3588. while (length--) {
  3589. result[fromRight ? length : ++index] = start;
  3590. start += step;
  3591. }
  3592. return result;
  3593. }
  3594. /**
  3595. * The base implementation of `_.repeat` which doesn't coerce arguments.
  3596. *
  3597. * @private
  3598. * @param {string} string The string to repeat.
  3599. * @param {number} n The number of times to repeat the string.
  3600. * @returns {string} Returns the repeated string.
  3601. */
  3602. function baseRepeat(string, n) {
  3603. var result = '';
  3604. if (!string || n < 1 || n > MAX_SAFE_INTEGER) {
  3605. return result;
  3606. }
  3607. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  3608. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  3609. do {
  3610. if (n % 2) {
  3611. result += string;
  3612. }
  3613. n = nativeFloor(n / 2);
  3614. if (n) {
  3615. string += string;
  3616. }
  3617. } while (n);
  3618. return result;
  3619. }
  3620. /**
  3621. * The base implementation of `_.rest` which doesn't validate or coerce arguments.
  3622. *
  3623. * @private
  3624. * @param {Function} func The function to apply a rest parameter to.
  3625. * @param {number} [start=func.length-1] The start position of the rest parameter.
  3626. * @returns {Function} Returns the new function.
  3627. */
  3628. function baseRest(func, start) {
  3629. return setToString(overRest(func, start, identity), func + '');
  3630. }
  3631. /**
  3632. * The base implementation of `_.sample`.
  3633. *
  3634. * @private
  3635. * @param {Array|Object} collection The collection to sample.
  3636. * @returns {*} Returns the random element.
  3637. */
  3638. function baseSample(collection) {
  3639. return arraySample(values(collection));
  3640. }
  3641. /**
  3642. * The base implementation of `_.sampleSize` without param guards.
  3643. *
  3644. * @private
  3645. * @param {Array|Object} collection The collection to sample.
  3646. * @param {number} n The number of elements to sample.
  3647. * @returns {Array} Returns the random elements.
  3648. */
  3649. function baseSampleSize(collection, n) {
  3650. var array = values(collection);
  3651. return shuffleSelf(array, baseClamp(n, 0, array.length));
  3652. }
  3653. /**
  3654. * The base implementation of `_.set`.
  3655. *
  3656. * @private
  3657. * @param {Object} object The object to modify.
  3658. * @param {Array|string} path The path of the property to set.
  3659. * @param {*} value The value to set.
  3660. * @param {Function} [customizer] The function to customize path creation.
  3661. * @returns {Object} Returns `object`.
  3662. */
  3663. function baseSet(object, path, value, customizer) {
  3664. if (!isObject(object)) {
  3665. return object;
  3666. }
  3667. path = castPath(path, object);
  3668. var index = -1,
  3669. length = path.length,
  3670. lastIndex = length - 1,
  3671. nested = object;
  3672. while (nested != null && ++index < length) {
  3673. var key = toKey(path[index]),
  3674. newValue = value;
  3675. if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
  3676. return object;
  3677. }
  3678. if (index != lastIndex) {
  3679. var objValue = nested[key];
  3680. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  3681. if (newValue === undefined) {
  3682. newValue = isObject(objValue)
  3683. ? objValue
  3684. : (isIndex(path[index + 1]) ? [] : {});
  3685. }
  3686. }
  3687. assignValue(nested, key, newValue);
  3688. nested = nested[key];
  3689. }
  3690. return object;
  3691. }
  3692. /**
  3693. * The base implementation of `setData` without support for hot loop shorting.
  3694. *
  3695. * @private
  3696. * @param {Function} func The function to associate metadata with.
  3697. * @param {*} data The metadata.
  3698. * @returns {Function} Returns `func`.
  3699. */
  3700. var baseSetData = !metaMap ? identity : function(func, data) {
  3701. metaMap.set(func, data);
  3702. return func;
  3703. };
  3704. /**
  3705. * The base implementation of `setToString` without support for hot loop shorting.
  3706. *
  3707. * @private
  3708. * @param {Function} func The function to modify.
  3709. * @param {Function} string The `toString` result.
  3710. * @returns {Function} Returns `func`.
  3711. */
  3712. var baseSetToString = !defineProperty ? identity : function(func, string) {
  3713. return defineProperty(func, 'toString', {
  3714. 'configurable': true,
  3715. 'enumerable': false,
  3716. 'value': constant(string),
  3717. 'writable': true
  3718. });
  3719. };
  3720. /**
  3721. * The base implementation of `_.shuffle`.
  3722. *
  3723. * @private
  3724. * @param {Array|Object} collection The collection to shuffle.
  3725. * @returns {Array} Returns the new shuffled array.
  3726. */
  3727. function baseShuffle(collection) {
  3728. return shuffleSelf(values(collection));
  3729. }
  3730. /**
  3731. * The base implementation of `_.slice` without an iteratee call guard.
  3732. *
  3733. * @private
  3734. * @param {Array} array The array to slice.
  3735. * @param {number} [start=0] The start position.
  3736. * @param {number} [end=array.length] The end position.
  3737. * @returns {Array} Returns the slice of `array`.
  3738. */
  3739. function baseSlice(array, start, end) {
  3740. var index = -1,
  3741. length = array.length;
  3742. if (start < 0) {
  3743. start = -start > length ? 0 : (length + start);
  3744. }
  3745. end = end > length ? length : end;
  3746. if (end < 0) {
  3747. end += length;
  3748. }
  3749. length = start > end ? 0 : ((end - start) >>> 0);
  3750. start >>>= 0;
  3751. var result = Array(length);
  3752. while (++index < length) {
  3753. result[index] = array[index + start];
  3754. }
  3755. return result;
  3756. }
  3757. /**
  3758. * The base implementation of `_.some` without support for iteratee shorthands.
  3759. *
  3760. * @private
  3761. * @param {Array|Object} collection The collection to iterate over.
  3762. * @param {Function} predicate The function invoked per iteration.
  3763. * @returns {boolean} Returns `true` if any element passes the predicate check,
  3764. * else `false`.
  3765. */
  3766. function baseSome(collection, predicate) {
  3767. var result;
  3768. baseEach(collection, function(value, index, collection) {
  3769. result = predicate(value, index, collection);
  3770. return !result;
  3771. });
  3772. return !!result;
  3773. }
  3774. /**
  3775. * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which
  3776. * performs a binary search of `array` to determine the index at which `value`
  3777. * should be inserted into `array` in order to maintain its sort order.
  3778. *
  3779. * @private
  3780. * @param {Array} array The sorted array to inspect.
  3781. * @param {*} value The value to evaluate.
  3782. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3783. * @returns {number} Returns the index at which `value` should be inserted
  3784. * into `array`.
  3785. */
  3786. function baseSortedIndex(array, value, retHighest) {
  3787. var low = 0,
  3788. high = array == null ? low : array.length;
  3789. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  3790. while (low < high) {
  3791. var mid = (low + high) >>> 1,
  3792. computed = array[mid];
  3793. if (computed !== null && !isSymbol(computed) &&
  3794. (retHighest ? (computed <= value) : (computed < value))) {
  3795. low = mid + 1;
  3796. } else {
  3797. high = mid;
  3798. }
  3799. }
  3800. return high;
  3801. }
  3802. return baseSortedIndexBy(array, value, identity, retHighest);
  3803. }
  3804. /**
  3805. * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy`
  3806. * which invokes `iteratee` for `value` and each element of `array` to compute
  3807. * their sort ranking. The iteratee is invoked with one argument; (value).
  3808. *
  3809. * @private
  3810. * @param {Array} array The sorted array to inspect.
  3811. * @param {*} value The value to evaluate.
  3812. * @param {Function} iteratee The iteratee invoked per element.
  3813. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3814. * @returns {number} Returns the index at which `value` should be inserted
  3815. * into `array`.
  3816. */
  3817. function baseSortedIndexBy(array, value, iteratee, retHighest) {
  3818. var low = 0,
  3819. high = array == null ? 0 : array.length;
  3820. if (high === 0) {
  3821. return 0;
  3822. }
  3823. value = iteratee(value);
  3824. var valIsNaN = value !== value,
  3825. valIsNull = value === null,
  3826. valIsSymbol = isSymbol(value),
  3827. valIsUndefined = value === undefined;
  3828. while (low < high) {
  3829. var mid = nativeFloor((low + high) / 2),
  3830. computed = iteratee(array[mid]),
  3831. othIsDefined = computed !== undefined,
  3832. othIsNull = computed === null,
  3833. othIsReflexive = computed === computed,
  3834. othIsSymbol = isSymbol(computed);
  3835. if (valIsNaN) {
  3836. var setLow = retHighest || othIsReflexive;
  3837. } else if (valIsUndefined) {
  3838. setLow = othIsReflexive && (retHighest || othIsDefined);
  3839. } else if (valIsNull) {
  3840. setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull);
  3841. } else if (valIsSymbol) {
  3842. setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol);
  3843. } else if (othIsNull || othIsSymbol) {
  3844. setLow = false;
  3845. } else {
  3846. setLow = retHighest ? (computed <= value) : (computed < value);
  3847. }
  3848. if (setLow) {
  3849. low = mid + 1;
  3850. } else {
  3851. high = mid;
  3852. }
  3853. }
  3854. return nativeMin(high, MAX_ARRAY_INDEX);
  3855. }
  3856. /**
  3857. * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without
  3858. * support for iteratee shorthands.
  3859. *
  3860. * @private
  3861. * @param {Array} array The array to inspect.
  3862. * @param {Function} [iteratee] The iteratee invoked per element.
  3863. * @returns {Array} Returns the new duplicate free array.
  3864. */
  3865. function baseSortedUniq(array, iteratee) {
  3866. var index = -1,
  3867. length = array.length,
  3868. resIndex = 0,
  3869. result = [];
  3870. while (++index < length) {
  3871. var value = array[index],
  3872. computed = iteratee ? iteratee(value) : value;
  3873. if (!index || !eq(computed, seen)) {
  3874. var seen = computed;
  3875. result[resIndex++] = value === 0 ? 0 : value;
  3876. }
  3877. }
  3878. return result;
  3879. }
  3880. /**
  3881. * The base implementation of `_.toNumber` which doesn't ensure correct
  3882. * conversions of binary, hexadecimal, or octal string values.
  3883. *
  3884. * @private
  3885. * @param {*} value The value to process.
  3886. * @returns {number} Returns the number.
  3887. */
  3888. function baseToNumber(value) {
  3889. if (typeof value == 'number') {
  3890. return value;
  3891. }
  3892. if (isSymbol(value)) {
  3893. return NAN;
  3894. }
  3895. return +value;
  3896. }
  3897. /**
  3898. * The base implementation of `_.toString` which doesn't convert nullish
  3899. * values to empty strings.
  3900. *
  3901. * @private
  3902. * @param {*} value The value to process.
  3903. * @returns {string} Returns the string.
  3904. */
  3905. function baseToString(value) {
  3906. // Exit early for strings to avoid a performance hit in some environments.
  3907. if (typeof value == 'string') {
  3908. return value;
  3909. }
  3910. if (isArray(value)) {
  3911. // Recursively convert values (susceptible to call stack limits).
  3912. return arrayMap(value, baseToString) + '';
  3913. }
  3914. if (isSymbol(value)) {
  3915. return symbolToString ? symbolToString.call(value) : '';
  3916. }
  3917. var result = (value + '');
  3918. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  3919. }
  3920. /**
  3921. * The base implementation of `_.uniqBy` without support for iteratee shorthands.
  3922. *
  3923. * @private
  3924. * @param {Array} array The array to inspect.
  3925. * @param {Function} [iteratee] The iteratee invoked per element.
  3926. * @param {Function} [comparator] The comparator invoked per element.
  3927. * @returns {Array} Returns the new duplicate free array.
  3928. */
  3929. function baseUniq(array, iteratee, comparator) {
  3930. var index = -1,
  3931. includes = arrayIncludes,
  3932. length = array.length,
  3933. isCommon = true,
  3934. result = [],
  3935. seen = result;
  3936. if (comparator) {
  3937. isCommon = false;
  3938. includes = arrayIncludesWith;
  3939. }
  3940. else if (length >= LARGE_ARRAY_SIZE) {
  3941. var set = iteratee ? null : createSet(array);
  3942. if (set) {
  3943. return setToArray(set);
  3944. }
  3945. isCommon = false;
  3946. includes = cacheHas;
  3947. seen = new SetCache;
  3948. }
  3949. else {
  3950. seen = iteratee ? [] : result;
  3951. }
  3952. outer:
  3953. while (++index < length) {
  3954. var value = array[index],
  3955. computed = iteratee ? iteratee(value) : value;
  3956. value = (comparator || value !== 0) ? value : 0;
  3957. if (isCommon && computed === computed) {
  3958. var seenIndex = seen.length;
  3959. while (seenIndex--) {
  3960. if (seen[seenIndex] === computed) {
  3961. continue outer;
  3962. }
  3963. }
  3964. if (iteratee) {
  3965. seen.push(computed);
  3966. }
  3967. result.push(value);
  3968. }
  3969. else if (!includes(seen, computed, comparator)) {
  3970. if (seen !== result) {
  3971. seen.push(computed);
  3972. }
  3973. result.push(value);
  3974. }
  3975. }
  3976. return result;
  3977. }
  3978. /**
  3979. * The base implementation of `_.unset`.
  3980. *
  3981. * @private
  3982. * @param {Object} object The object to modify.
  3983. * @param {Array|string} path The property path to unset.
  3984. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  3985. */
  3986. function baseUnset(object, path) {
  3987. path = castPath(path, object);
  3988. object = parent(object, path);
  3989. return object == null || delete object[toKey(last(path))];
  3990. }
  3991. /**
  3992. * The base implementation of `_.update`.
  3993. *
  3994. * @private
  3995. * @param {Object} object The object to modify.
  3996. * @param {Array|string} path The path of the property to update.
  3997. * @param {Function} updater The function to produce the updated value.
  3998. * @param {Function} [customizer] The function to customize path creation.
  3999. * @returns {Object} Returns `object`.
  4000. */
  4001. function baseUpdate(object, path, updater, customizer) {
  4002. return baseSet(object, path, updater(baseGet(object, path)), customizer);
  4003. }
  4004. /**
  4005. * The base implementation of methods like `_.dropWhile` and `_.takeWhile`
  4006. * without support for iteratee shorthands.
  4007. *
  4008. * @private
  4009. * @param {Array} array The array to query.
  4010. * @param {Function} predicate The function invoked per iteration.
  4011. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  4012. * @param {boolean} [fromRight] Specify iterating from right to left.
  4013. * @returns {Array} Returns the slice of `array`.
  4014. */
  4015. function baseWhile(array, predicate, isDrop, fromRight) {
  4016. var length = array.length,
  4017. index = fromRight ? length : -1;
  4018. while ((fromRight ? index-- : ++index < length) &&
  4019. predicate(array[index], index, array)) {}
  4020. return isDrop
  4021. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  4022. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  4023. }
  4024. /**
  4025. * The base implementation of `wrapperValue` which returns the result of
  4026. * performing a sequence of actions on the unwrapped `value`, where each
  4027. * successive action is supplied the return value of the previous.
  4028. *
  4029. * @private
  4030. * @param {*} value The unwrapped value.
  4031. * @param {Array} actions Actions to perform to resolve the unwrapped value.
  4032. * @returns {*} Returns the resolved value.
  4033. */
  4034. function baseWrapperValue(value, actions) {
  4035. var result = value;
  4036. if (result instanceof LazyWrapper) {
  4037. result = result.value();
  4038. }
  4039. return arrayReduce(actions, function(result, action) {
  4040. return action.func.apply(action.thisArg, arrayPush([result], action.args));
  4041. }, result);
  4042. }
  4043. /**
  4044. * The base implementation of methods like `_.xor`, without support for
  4045. * iteratee shorthands, that accepts an array of arrays to inspect.
  4046. *
  4047. * @private
  4048. * @param {Array} arrays The arrays to inspect.
  4049. * @param {Function} [iteratee] The iteratee invoked per element.
  4050. * @param {Function} [comparator] The comparator invoked per element.
  4051. * @returns {Array} Returns the new array of values.
  4052. */
  4053. function baseXor(arrays, iteratee, comparator) {
  4054. var length = arrays.length;
  4055. if (length < 2) {
  4056. return length ? baseUniq(arrays[0]) : [];
  4057. }
  4058. var index = -1,
  4059. result = Array(length);
  4060. while (++index < length) {
  4061. var array = arrays[index],
  4062. othIndex = -1;
  4063. while (++othIndex < length) {
  4064. if (othIndex != index) {
  4065. result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator);
  4066. }
  4067. }
  4068. }
  4069. return baseUniq(baseFlatten(result, 1), iteratee, comparator);
  4070. }
  4071. /**
  4072. * This base implementation of `_.zipObject` which assigns values using `assignFunc`.
  4073. *
  4074. * @private
  4075. * @param {Array} props The property identifiers.
  4076. * @param {Array} values The property values.
  4077. * @param {Function} assignFunc The function to assign values.
  4078. * @returns {Object} Returns the new object.
  4079. */
  4080. function baseZipObject(props, values, assignFunc) {
  4081. var index = -1,
  4082. length = props.length,
  4083. valsLength = values.length,
  4084. result = {};
  4085. while (++index < length) {
  4086. var value = index < valsLength ? values[index] : undefined;
  4087. assignFunc(result, props[index], value);
  4088. }
  4089. return result;
  4090. }
  4091. /**
  4092. * Casts `value` to an empty array if it's not an array like object.
  4093. *
  4094. * @private
  4095. * @param {*} value The value to inspect.
  4096. * @returns {Array|Object} Returns the cast array-like object.
  4097. */
  4098. function castArrayLikeObject(value) {
  4099. return isArrayLikeObject(value) ? value : [];
  4100. }
  4101. /**
  4102. * Casts `value` to `identity` if it's not a function.
  4103. *
  4104. * @private
  4105. * @param {*} value The value to inspect.
  4106. * @returns {Function} Returns cast function.
  4107. */
  4108. function castFunction(value) {
  4109. return typeof value == 'function' ? value : identity;
  4110. }
  4111. /**
  4112. * Casts `value` to a path array if it's not one.
  4113. *
  4114. * @private
  4115. * @param {*} value The value to inspect.
  4116. * @param {Object} [object] The object to query keys on.
  4117. * @returns {Array} Returns the cast property path array.
  4118. */
  4119. function castPath(value, object) {
  4120. if (isArray(value)) {
  4121. return value;
  4122. }
  4123. return isKey(value, object) ? [value] : stringToPath(toString(value));
  4124. }
  4125. /**
  4126. * A `baseRest` alias which can be replaced with `identity` by module
  4127. * replacement plugins.
  4128. *
  4129. * @private
  4130. * @type {Function}
  4131. * @param {Function} func The function to apply a rest parameter to.
  4132. * @returns {Function} Returns the new function.
  4133. */
  4134. var castRest = baseRest;
  4135. /**
  4136. * Casts `array` to a slice if it's needed.
  4137. *
  4138. * @private
  4139. * @param {Array} array The array to inspect.
  4140. * @param {number} start The start position.
  4141. * @param {number} [end=array.length] The end position.
  4142. * @returns {Array} Returns the cast slice.
  4143. */
  4144. function castSlice(array, start, end) {
  4145. var length = array.length;
  4146. end = end === undefined ? length : end;
  4147. return (!start && end >= length) ? array : baseSlice(array, start, end);
  4148. }
  4149. /**
  4150. * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout).
  4151. *
  4152. * @private
  4153. * @param {number|Object} id The timer id or timeout object of the timer to clear.
  4154. */
  4155. var clearTimeout = ctxClearTimeout || function(id) {
  4156. return root.clearTimeout(id);
  4157. };
  4158. /**
  4159. * Creates a clone of `buffer`.
  4160. *
  4161. * @private
  4162. * @param {Buffer} buffer The buffer to clone.
  4163. * @param {boolean} [isDeep] Specify a deep clone.
  4164. * @returns {Buffer} Returns the cloned buffer.
  4165. */
  4166. function cloneBuffer(buffer, isDeep) {
  4167. if (isDeep) {
  4168. return buffer.slice();
  4169. }
  4170. var length = buffer.length,
  4171. result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length);
  4172. buffer.copy(result);
  4173. return result;
  4174. }
  4175. /**
  4176. * Creates a clone of `arrayBuffer`.
  4177. *
  4178. * @private
  4179. * @param {ArrayBuffer} arrayBuffer The array buffer to clone.
  4180. * @returns {ArrayBuffer} Returns the cloned array buffer.
  4181. */
  4182. function cloneArrayBuffer(arrayBuffer) {
  4183. var result = new arrayBuffer.constructor(arrayBuffer.byteLength);
  4184. new Uint8Array(result).set(new Uint8Array(arrayBuffer));
  4185. return result;
  4186. }
  4187. /**
  4188. * Creates a clone of `dataView`.
  4189. *
  4190. * @private
  4191. * @param {Object} dataView The data view to clone.
  4192. * @param {boolean} [isDeep] Specify a deep clone.
  4193. * @returns {Object} Returns the cloned data view.
  4194. */
  4195. function cloneDataView(dataView, isDeep) {
  4196. var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer;
  4197. return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength);
  4198. }
  4199. /**
  4200. * Creates a clone of `regexp`.
  4201. *
  4202. * @private
  4203. * @param {Object} regexp The regexp to clone.
  4204. * @returns {Object} Returns the cloned regexp.
  4205. */
  4206. function cloneRegExp(regexp) {
  4207. var result = new regexp.constructor(regexp.source, reFlags.exec(regexp));
  4208. result.lastIndex = regexp.lastIndex;
  4209. return result;
  4210. }
  4211. /**
  4212. * Creates a clone of the `symbol` object.
  4213. *
  4214. * @private
  4215. * @param {Object} symbol The symbol object to clone.
  4216. * @returns {Object} Returns the cloned symbol object.
  4217. */
  4218. function cloneSymbol(symbol) {
  4219. return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {};
  4220. }
  4221. /**
  4222. * Creates a clone of `typedArray`.
  4223. *
  4224. * @private
  4225. * @param {Object} typedArray The typed array to clone.
  4226. * @param {boolean} [isDeep] Specify a deep clone.
  4227. * @returns {Object} Returns the cloned typed array.
  4228. */
  4229. function cloneTypedArray(typedArray, isDeep) {
  4230. var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer;
  4231. return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length);
  4232. }
  4233. /**
  4234. * Compares values to sort them in ascending order.
  4235. *
  4236. * @private
  4237. * @param {*} value The value to compare.
  4238. * @param {*} other The other value to compare.
  4239. * @returns {number} Returns the sort order indicator for `value`.
  4240. */
  4241. function compareAscending(value, other) {
  4242. if (value !== other) {
  4243. var valIsDefined = value !== undefined,
  4244. valIsNull = value === null,
  4245. valIsReflexive = value === value,
  4246. valIsSymbol = isSymbol(value);
  4247. var othIsDefined = other !== undefined,
  4248. othIsNull = other === null,
  4249. othIsReflexive = other === other,
  4250. othIsSymbol = isSymbol(other);
  4251. if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) ||
  4252. (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) ||
  4253. (valIsNull && othIsDefined && othIsReflexive) ||
  4254. (!valIsDefined && othIsReflexive) ||
  4255. !valIsReflexive) {
  4256. return 1;
  4257. }
  4258. if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) ||
  4259. (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) ||
  4260. (othIsNull && valIsDefined && valIsReflexive) ||
  4261. (!othIsDefined && valIsReflexive) ||
  4262. !othIsReflexive) {
  4263. return -1;
  4264. }
  4265. }
  4266. return 0;
  4267. }
  4268. /**
  4269. * Used by `_.orderBy` to compare multiple properties of a value to another
  4270. * and stable sort them.
  4271. *
  4272. * If `orders` is unspecified, all values are sorted in ascending order. Otherwise,
  4273. * specify an order of "desc" for descending or "asc" for ascending sort order
  4274. * of corresponding values.
  4275. *
  4276. * @private
  4277. * @param {Object} object The object to compare.
  4278. * @param {Object} other The other object to compare.
  4279. * @param {boolean[]|string[]} orders The order to sort by for each property.
  4280. * @returns {number} Returns the sort order indicator for `object`.
  4281. */
  4282. function compareMultiple(object, other, orders) {
  4283. var index = -1,
  4284. objCriteria = object.criteria,
  4285. othCriteria = other.criteria,
  4286. length = objCriteria.length,
  4287. ordersLength = orders.length;
  4288. while (++index < length) {
  4289. var result = compareAscending(objCriteria[index], othCriteria[index]);
  4290. if (result) {
  4291. if (index >= ordersLength) {
  4292. return result;
  4293. }
  4294. var order = orders[index];
  4295. return result * (order == 'desc' ? -1 : 1);
  4296. }
  4297. }
  4298. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  4299. // that causes it, under certain circumstances, to provide the same value for
  4300. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  4301. // for more details.
  4302. //
  4303. // This also ensures a stable sort in V8 and other engines.
  4304. // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details.
  4305. return object.index - other.index;
  4306. }
  4307. /**
  4308. * Creates an array that is the composition of partially applied arguments,
  4309. * placeholders, and provided arguments into a single array of arguments.
  4310. *
  4311. * @private
  4312. * @param {Array} args The provided arguments.
  4313. * @param {Array} partials The arguments to prepend to those provided.
  4314. * @param {Array} holders The `partials` placeholder indexes.
  4315. * @params {boolean} [isCurried] Specify composing for a curried function.
  4316. * @returns {Array} Returns the new array of composed arguments.
  4317. */
  4318. function composeArgs(args, partials, holders, isCurried) {
  4319. var argsIndex = -1,
  4320. argsLength = args.length,
  4321. holdersLength = holders.length,
  4322. leftIndex = -1,
  4323. leftLength = partials.length,
  4324. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4325. result = Array(leftLength + rangeLength),
  4326. isUncurried = !isCurried;
  4327. while (++leftIndex < leftLength) {
  4328. result[leftIndex] = partials[leftIndex];
  4329. }
  4330. while (++argsIndex < holdersLength) {
  4331. if (isUncurried || argsIndex < argsLength) {
  4332. result[holders[argsIndex]] = args[argsIndex];
  4333. }
  4334. }
  4335. while (rangeLength--) {
  4336. result[leftIndex++] = args[argsIndex++];
  4337. }
  4338. return result;
  4339. }
  4340. /**
  4341. * This function is like `composeArgs` except that the arguments composition
  4342. * is tailored for `_.partialRight`.
  4343. *
  4344. * @private
  4345. * @param {Array} args The provided arguments.
  4346. * @param {Array} partials The arguments to append to those provided.
  4347. * @param {Array} holders The `partials` placeholder indexes.
  4348. * @params {boolean} [isCurried] Specify composing for a curried function.
  4349. * @returns {Array} Returns the new array of composed arguments.
  4350. */
  4351. function composeArgsRight(args, partials, holders, isCurried) {
  4352. var argsIndex = -1,
  4353. argsLength = args.length,
  4354. holdersIndex = -1,
  4355. holdersLength = holders.length,
  4356. rightIndex = -1,
  4357. rightLength = partials.length,
  4358. rangeLength = nativeMax(argsLength - holdersLength, 0),
  4359. result = Array(rangeLength + rightLength),
  4360. isUncurried = !isCurried;
  4361. while (++argsIndex < rangeLength) {
  4362. result[argsIndex] = args[argsIndex];
  4363. }
  4364. var offset = argsIndex;
  4365. while (++rightIndex < rightLength) {
  4366. result[offset + rightIndex] = partials[rightIndex];
  4367. }
  4368. while (++holdersIndex < holdersLength) {
  4369. if (isUncurried || argsIndex < argsLength) {
  4370. result[offset + holders[holdersIndex]] = args[argsIndex++];
  4371. }
  4372. }
  4373. return result;
  4374. }
  4375. /**
  4376. * Copies the values of `source` to `array`.
  4377. *
  4378. * @private
  4379. * @param {Array} source The array to copy values from.
  4380. * @param {Array} [array=[]] The array to copy values to.
  4381. * @returns {Array} Returns `array`.
  4382. */
  4383. function copyArray(source, array) {
  4384. var index = -1,
  4385. length = source.length;
  4386. array || (array = Array(length));
  4387. while (++index < length) {
  4388. array[index] = source[index];
  4389. }
  4390. return array;
  4391. }
  4392. /**
  4393. * Copies properties of `source` to `object`.
  4394. *
  4395. * @private
  4396. * @param {Object} source The object to copy properties from.
  4397. * @param {Array} props The property identifiers to copy.
  4398. * @param {Object} [object={}] The object to copy properties to.
  4399. * @param {Function} [customizer] The function to customize copied values.
  4400. * @returns {Object} Returns `object`.
  4401. */
  4402. function copyObject(source, props, object, customizer) {
  4403. var isNew = !object;
  4404. object || (object = {});
  4405. var index = -1,
  4406. length = props.length;
  4407. while (++index < length) {
  4408. var key = props[index];
  4409. var newValue = customizer
  4410. ? customizer(object[key], source[key], key, object, source)
  4411. : undefined;
  4412. if (newValue === undefined) {
  4413. newValue = source[key];
  4414. }
  4415. if (isNew) {
  4416. baseAssignValue(object, key, newValue);
  4417. } else {
  4418. assignValue(object, key, newValue);
  4419. }
  4420. }
  4421. return object;
  4422. }
  4423. /**
  4424. * Copies own symbols of `source` to `object`.
  4425. *
  4426. * @private
  4427. * @param {Object} source The object to copy symbols from.
  4428. * @param {Object} [object={}] The object to copy symbols to.
  4429. * @returns {Object} Returns `object`.
  4430. */
  4431. function copySymbols(source, object) {
  4432. return copyObject(source, getSymbols(source), object);
  4433. }
  4434. /**
  4435. * Copies own and inherited symbols of `source` to `object`.
  4436. *
  4437. * @private
  4438. * @param {Object} source The object to copy symbols from.
  4439. * @param {Object} [object={}] The object to copy symbols to.
  4440. * @returns {Object} Returns `object`.
  4441. */
  4442. function copySymbolsIn(source, object) {
  4443. return copyObject(source, getSymbolsIn(source), object);
  4444. }
  4445. /**
  4446. * Creates a function like `_.groupBy`.
  4447. *
  4448. * @private
  4449. * @param {Function} setter The function to set accumulator values.
  4450. * @param {Function} [initializer] The accumulator object initializer.
  4451. * @returns {Function} Returns the new aggregator function.
  4452. */
  4453. function createAggregator(setter, initializer) {
  4454. return function(collection, iteratee) {
  4455. var func = isArray(collection) ? arrayAggregator : baseAggregator,
  4456. accumulator = initializer ? initializer() : {};
  4457. return func(collection, setter, getIteratee(iteratee, 2), accumulator);
  4458. };
  4459. }
  4460. /**
  4461. * Creates a function like `_.assign`.
  4462. *
  4463. * @private
  4464. * @param {Function} assigner The function to assign values.
  4465. * @returns {Function} Returns the new assigner function.
  4466. */
  4467. function createAssigner(assigner) {
  4468. return baseRest(function(object, sources) {
  4469. var index = -1,
  4470. length = sources.length,
  4471. customizer = length > 1 ? sources[length - 1] : undefined,
  4472. guard = length > 2 ? sources[2] : undefined;
  4473. customizer = (assigner.length > 3 && typeof customizer == 'function')
  4474. ? (length--, customizer)
  4475. : undefined;
  4476. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  4477. customizer = length < 3 ? undefined : customizer;
  4478. length = 1;
  4479. }
  4480. object = Object(object);
  4481. while (++index < length) {
  4482. var source = sources[index];
  4483. if (source) {
  4484. assigner(object, source, index, customizer);
  4485. }
  4486. }
  4487. return object;
  4488. });
  4489. }
  4490. /**
  4491. * Creates a `baseEach` or `baseEachRight` function.
  4492. *
  4493. * @private
  4494. * @param {Function} eachFunc The function to iterate over a collection.
  4495. * @param {boolean} [fromRight] Specify iterating from right to left.
  4496. * @returns {Function} Returns the new base function.
  4497. */
  4498. function createBaseEach(eachFunc, fromRight) {
  4499. return function(collection, iteratee) {
  4500. if (collection == null) {
  4501. return collection;
  4502. }
  4503. if (!isArrayLike(collection)) {
  4504. return eachFunc(collection, iteratee);
  4505. }
  4506. var length = collection.length,
  4507. index = fromRight ? length : -1,
  4508. iterable = Object(collection);
  4509. while ((fromRight ? index-- : ++index < length)) {
  4510. if (iteratee(iterable[index], index, iterable) === false) {
  4511. break;
  4512. }
  4513. }
  4514. return collection;
  4515. };
  4516. }
  4517. /**
  4518. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  4519. *
  4520. * @private
  4521. * @param {boolean} [fromRight] Specify iterating from right to left.
  4522. * @returns {Function} Returns the new base function.
  4523. */
  4524. function createBaseFor(fromRight) {
  4525. return function(object, iteratee, keysFunc) {
  4526. var index = -1,
  4527. iterable = Object(object),
  4528. props = keysFunc(object),
  4529. length = props.length;
  4530. while (length--) {
  4531. var key = props[fromRight ? length : ++index];
  4532. if (iteratee(iterable[key], key, iterable) === false) {
  4533. break;
  4534. }
  4535. }
  4536. return object;
  4537. };
  4538. }
  4539. /**
  4540. * Creates a function that wraps `func` to invoke it with the optional `this`
  4541. * binding of `thisArg`.
  4542. *
  4543. * @private
  4544. * @param {Function} func The function to wrap.
  4545. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4546. * @param {*} [thisArg] The `this` binding of `func`.
  4547. * @returns {Function} Returns the new wrapped function.
  4548. */
  4549. function createBind(func, bitmask, thisArg) {
  4550. var isBind = bitmask & WRAP_BIND_FLAG,
  4551. Ctor = createCtor(func);
  4552. function wrapper() {
  4553. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4554. return fn.apply(isBind ? thisArg : this, arguments);
  4555. }
  4556. return wrapper;
  4557. }
  4558. /**
  4559. * Creates a function like `_.lowerFirst`.
  4560. *
  4561. * @private
  4562. * @param {string} methodName The name of the `String` case method to use.
  4563. * @returns {Function} Returns the new case function.
  4564. */
  4565. function createCaseFirst(methodName) {
  4566. return function(string) {
  4567. string = toString(string);
  4568. var strSymbols = hasUnicode(string)
  4569. ? stringToArray(string)
  4570. : undefined;
  4571. var chr = strSymbols
  4572. ? strSymbols[0]
  4573. : string.charAt(0);
  4574. var trailing = strSymbols
  4575. ? castSlice(strSymbols, 1).join('')
  4576. : string.slice(1);
  4577. return chr[methodName]() + trailing;
  4578. };
  4579. }
  4580. /**
  4581. * Creates a function like `_.camelCase`.
  4582. *
  4583. * @private
  4584. * @param {Function} callback The function to combine each word.
  4585. * @returns {Function} Returns the new compounder function.
  4586. */
  4587. function createCompounder(callback) {
  4588. return function(string) {
  4589. return arrayReduce(words(deburr(string).replace(reApos, '')), callback, '');
  4590. };
  4591. }
  4592. /**
  4593. * Creates a function that produces an instance of `Ctor` regardless of
  4594. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  4595. *
  4596. * @private
  4597. * @param {Function} Ctor The constructor to wrap.
  4598. * @returns {Function} Returns the new wrapped function.
  4599. */
  4600. function createCtor(Ctor) {
  4601. return function() {
  4602. // Use a `switch` statement to work with class constructors. See
  4603. // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  4604. // for more details.
  4605. var args = arguments;
  4606. switch (args.length) {
  4607. case 0: return new Ctor;
  4608. case 1: return new Ctor(args[0]);
  4609. case 2: return new Ctor(args[0], args[1]);
  4610. case 3: return new Ctor(args[0], args[1], args[2]);
  4611. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  4612. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  4613. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  4614. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  4615. }
  4616. var thisBinding = baseCreate(Ctor.prototype),
  4617. result = Ctor.apply(thisBinding, args);
  4618. // Mimic the constructor's `return` behavior.
  4619. // See https://es5.github.io/#x13.2.2 for more details.
  4620. return isObject(result) ? result : thisBinding;
  4621. };
  4622. }
  4623. /**
  4624. * Creates a function that wraps `func` to enable currying.
  4625. *
  4626. * @private
  4627. * @param {Function} func The function to wrap.
  4628. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4629. * @param {number} arity The arity of `func`.
  4630. * @returns {Function} Returns the new wrapped function.
  4631. */
  4632. function createCurry(func, bitmask, arity) {
  4633. var Ctor = createCtor(func);
  4634. function wrapper() {
  4635. var length = arguments.length,
  4636. args = Array(length),
  4637. index = length,
  4638. placeholder = getHolder(wrapper);
  4639. while (index--) {
  4640. args[index] = arguments[index];
  4641. }
  4642. var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder)
  4643. ? []
  4644. : replaceHolders(args, placeholder);
  4645. length -= holders.length;
  4646. if (length < arity) {
  4647. return createRecurry(
  4648. func, bitmask, createHybrid, wrapper.placeholder, undefined,
  4649. args, holders, undefined, undefined, arity - length);
  4650. }
  4651. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4652. return apply(fn, this, args);
  4653. }
  4654. return wrapper;
  4655. }
  4656. /**
  4657. * Creates a `_.find` or `_.findLast` function.
  4658. *
  4659. * @private
  4660. * @param {Function} findIndexFunc The function to find the collection index.
  4661. * @returns {Function} Returns the new find function.
  4662. */
  4663. function createFind(findIndexFunc) {
  4664. return function(collection, predicate, fromIndex) {
  4665. var iterable = Object(collection);
  4666. if (!isArrayLike(collection)) {
  4667. var iteratee = getIteratee(predicate, 3);
  4668. collection = keys(collection);
  4669. predicate = function(key) { return iteratee(iterable[key], key, iterable); };
  4670. }
  4671. var index = findIndexFunc(collection, predicate, fromIndex);
  4672. return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined;
  4673. };
  4674. }
  4675. /**
  4676. * Creates a `_.flow` or `_.flowRight` function.
  4677. *
  4678. * @private
  4679. * @param {boolean} [fromRight] Specify iterating from right to left.
  4680. * @returns {Function} Returns the new flow function.
  4681. */
  4682. function createFlow(fromRight) {
  4683. return flatRest(function(funcs) {
  4684. var length = funcs.length,
  4685. index = length,
  4686. prereq = LodashWrapper.prototype.thru;
  4687. if (fromRight) {
  4688. funcs.reverse();
  4689. }
  4690. while (index--) {
  4691. var func = funcs[index];
  4692. if (typeof func != 'function') {
  4693. throw new TypeError(FUNC_ERROR_TEXT);
  4694. }
  4695. if (prereq && !wrapper && getFuncName(func) == 'wrapper') {
  4696. var wrapper = new LodashWrapper([], true);
  4697. }
  4698. }
  4699. index = wrapper ? index : length;
  4700. while (++index < length) {
  4701. func = funcs[index];
  4702. var funcName = getFuncName(func),
  4703. data = funcName == 'wrapper' ? getData(func) : undefined;
  4704. if (data && isLaziable(data[0]) &&
  4705. data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) &&
  4706. !data[4].length && data[9] == 1
  4707. ) {
  4708. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  4709. } else {
  4710. wrapper = (func.length == 1 && isLaziable(func))
  4711. ? wrapper[funcName]()
  4712. : wrapper.thru(func);
  4713. }
  4714. }
  4715. return function() {
  4716. var args = arguments,
  4717. value = args[0];
  4718. if (wrapper && args.length == 1 && isArray(value)) {
  4719. return wrapper.plant(value).value();
  4720. }
  4721. var index = 0,
  4722. result = length ? funcs[index].apply(this, args) : value;
  4723. while (++index < length) {
  4724. result = funcs[index].call(this, result);
  4725. }
  4726. return result;
  4727. };
  4728. });
  4729. }
  4730. /**
  4731. * Creates a function that wraps `func` to invoke it with optional `this`
  4732. * binding of `thisArg`, partial application, and currying.
  4733. *
  4734. * @private
  4735. * @param {Function|string} func The function or method name to wrap.
  4736. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4737. * @param {*} [thisArg] The `this` binding of `func`.
  4738. * @param {Array} [partials] The arguments to prepend to those provided to
  4739. * the new function.
  4740. * @param {Array} [holders] The `partials` placeholder indexes.
  4741. * @param {Array} [partialsRight] The arguments to append to those provided
  4742. * to the new function.
  4743. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  4744. * @param {Array} [argPos] The argument positions of the new function.
  4745. * @param {number} [ary] The arity cap of `func`.
  4746. * @param {number} [arity] The arity of `func`.
  4747. * @returns {Function} Returns the new wrapped function.
  4748. */
  4749. function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  4750. var isAry = bitmask & WRAP_ARY_FLAG,
  4751. isBind = bitmask & WRAP_BIND_FLAG,
  4752. isBindKey = bitmask & WRAP_BIND_KEY_FLAG,
  4753. isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG),
  4754. isFlip = bitmask & WRAP_FLIP_FLAG,
  4755. Ctor = isBindKey ? undefined : createCtor(func);
  4756. function wrapper() {
  4757. var length = arguments.length,
  4758. args = Array(length),
  4759. index = length;
  4760. while (index--) {
  4761. args[index] = arguments[index];
  4762. }
  4763. if (isCurried) {
  4764. var placeholder = getHolder(wrapper),
  4765. holdersCount = countHolders(args, placeholder);
  4766. }
  4767. if (partials) {
  4768. args = composeArgs(args, partials, holders, isCurried);
  4769. }
  4770. if (partialsRight) {
  4771. args = composeArgsRight(args, partialsRight, holdersRight, isCurried);
  4772. }
  4773. length -= holdersCount;
  4774. if (isCurried && length < arity) {
  4775. var newHolders = replaceHolders(args, placeholder);
  4776. return createRecurry(
  4777. func, bitmask, createHybrid, wrapper.placeholder, thisArg,
  4778. args, newHolders, argPos, ary, arity - length
  4779. );
  4780. }
  4781. var thisBinding = isBind ? thisArg : this,
  4782. fn = isBindKey ? thisBinding[func] : func;
  4783. length = args.length;
  4784. if (argPos) {
  4785. args = reorder(args, argPos);
  4786. } else if (isFlip && length > 1) {
  4787. args.reverse();
  4788. }
  4789. if (isAry && ary < length) {
  4790. args.length = ary;
  4791. }
  4792. if (this && this !== root && this instanceof wrapper) {
  4793. fn = Ctor || createCtor(fn);
  4794. }
  4795. return fn.apply(thisBinding, args);
  4796. }
  4797. return wrapper;
  4798. }
  4799. /**
  4800. * Creates a function like `_.invertBy`.
  4801. *
  4802. * @private
  4803. * @param {Function} setter The function to set accumulator values.
  4804. * @param {Function} toIteratee The function to resolve iteratees.
  4805. * @returns {Function} Returns the new inverter function.
  4806. */
  4807. function createInverter(setter, toIteratee) {
  4808. return function(object, iteratee) {
  4809. return baseInverter(object, setter, toIteratee(iteratee), {});
  4810. };
  4811. }
  4812. /**
  4813. * Creates a function that performs a mathematical operation on two values.
  4814. *
  4815. * @private
  4816. * @param {Function} operator The function to perform the operation.
  4817. * @param {number} [defaultValue] The value used for `undefined` arguments.
  4818. * @returns {Function} Returns the new mathematical operation function.
  4819. */
  4820. function createMathOperation(operator, defaultValue) {
  4821. return function(value, other) {
  4822. var result;
  4823. if (value === undefined && other === undefined) {
  4824. return defaultValue;
  4825. }
  4826. if (value !== undefined) {
  4827. result = value;
  4828. }
  4829. if (other !== undefined) {
  4830. if (result === undefined) {
  4831. return other;
  4832. }
  4833. if (typeof value == 'string' || typeof other == 'string') {
  4834. value = baseToString(value);
  4835. other = baseToString(other);
  4836. } else {
  4837. value = baseToNumber(value);
  4838. other = baseToNumber(other);
  4839. }
  4840. result = operator(value, other);
  4841. }
  4842. return result;
  4843. };
  4844. }
  4845. /**
  4846. * Creates a function like `_.over`.
  4847. *
  4848. * @private
  4849. * @param {Function} arrayFunc The function to iterate over iteratees.
  4850. * @returns {Function} Returns the new over function.
  4851. */
  4852. function createOver(arrayFunc) {
  4853. return flatRest(function(iteratees) {
  4854. iteratees = arrayMap(iteratees, baseUnary(getIteratee()));
  4855. return baseRest(function(args) {
  4856. var thisArg = this;
  4857. return arrayFunc(iteratees, function(iteratee) {
  4858. return apply(iteratee, thisArg, args);
  4859. });
  4860. });
  4861. });
  4862. }
  4863. /**
  4864. * Creates the padding for `string` based on `length`. The `chars` string
  4865. * is truncated if the number of characters exceeds `length`.
  4866. *
  4867. * @private
  4868. * @param {number} length The padding length.
  4869. * @param {string} [chars=' '] The string used as padding.
  4870. * @returns {string} Returns the padding for `string`.
  4871. */
  4872. function createPadding(length, chars) {
  4873. chars = chars === undefined ? ' ' : baseToString(chars);
  4874. var charsLength = chars.length;
  4875. if (charsLength < 2) {
  4876. return charsLength ? baseRepeat(chars, length) : chars;
  4877. }
  4878. var result = baseRepeat(chars, nativeCeil(length / stringSize(chars)));
  4879. return hasUnicode(chars)
  4880. ? castSlice(stringToArray(result), 0, length).join('')
  4881. : result.slice(0, length);
  4882. }
  4883. /**
  4884. * Creates a function that wraps `func` to invoke it with the `this` binding
  4885. * of `thisArg` and `partials` prepended to the arguments it receives.
  4886. *
  4887. * @private
  4888. * @param {Function} func The function to wrap.
  4889. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4890. * @param {*} thisArg The `this` binding of `func`.
  4891. * @param {Array} partials The arguments to prepend to those provided to
  4892. * the new function.
  4893. * @returns {Function} Returns the new wrapped function.
  4894. */
  4895. function createPartial(func, bitmask, thisArg, partials) {
  4896. var isBind = bitmask & WRAP_BIND_FLAG,
  4897. Ctor = createCtor(func);
  4898. function wrapper() {
  4899. var argsIndex = -1,
  4900. argsLength = arguments.length,
  4901. leftIndex = -1,
  4902. leftLength = partials.length,
  4903. args = Array(leftLength + argsLength),
  4904. fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  4905. while (++leftIndex < leftLength) {
  4906. args[leftIndex] = partials[leftIndex];
  4907. }
  4908. while (argsLength--) {
  4909. args[leftIndex++] = arguments[++argsIndex];
  4910. }
  4911. return apply(fn, isBind ? thisArg : this, args);
  4912. }
  4913. return wrapper;
  4914. }
  4915. /**
  4916. * Creates a `_.range` or `_.rangeRight` function.
  4917. *
  4918. * @private
  4919. * @param {boolean} [fromRight] Specify iterating from right to left.
  4920. * @returns {Function} Returns the new range function.
  4921. */
  4922. function createRange(fromRight) {
  4923. return function(start, end, step) {
  4924. if (step && typeof step != 'number' && isIterateeCall(start, end, step)) {
  4925. end = step = undefined;
  4926. }
  4927. // Ensure the sign of `-0` is preserved.
  4928. start = toFinite(start);
  4929. if (end === undefined) {
  4930. end = start;
  4931. start = 0;
  4932. } else {
  4933. end = toFinite(end);
  4934. }
  4935. step = step === undefined ? (start < end ? 1 : -1) : toFinite(step);
  4936. return baseRange(start, end, step, fromRight);
  4937. };
  4938. }
  4939. /**
  4940. * Creates a function that performs a relational operation on two values.
  4941. *
  4942. * @private
  4943. * @param {Function} operator The function to perform the operation.
  4944. * @returns {Function} Returns the new relational operation function.
  4945. */
  4946. function createRelationalOperation(operator) {
  4947. return function(value, other) {
  4948. if (!(typeof value == 'string' && typeof other == 'string')) {
  4949. value = toNumber(value);
  4950. other = toNumber(other);
  4951. }
  4952. return operator(value, other);
  4953. };
  4954. }
  4955. /**
  4956. * Creates a function that wraps `func` to continue currying.
  4957. *
  4958. * @private
  4959. * @param {Function} func The function to wrap.
  4960. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  4961. * @param {Function} wrapFunc The function to create the `func` wrapper.
  4962. * @param {*} placeholder The placeholder value.
  4963. * @param {*} [thisArg] The `this` binding of `func`.
  4964. * @param {Array} [partials] The arguments to prepend to those provided to
  4965. * the new function.
  4966. * @param {Array} [holders] The `partials` placeholder indexes.
  4967. * @param {Array} [argPos] The argument positions of the new function.
  4968. * @param {number} [ary] The arity cap of `func`.
  4969. * @param {number} [arity] The arity of `func`.
  4970. * @returns {Function} Returns the new wrapped function.
  4971. */
  4972. function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) {
  4973. var isCurry = bitmask & WRAP_CURRY_FLAG,
  4974. newHolders = isCurry ? holders : undefined,
  4975. newHoldersRight = isCurry ? undefined : holders,
  4976. newPartials = isCurry ? partials : undefined,
  4977. newPartialsRight = isCurry ? undefined : partials;
  4978. bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG);
  4979. bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG);
  4980. if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) {
  4981. bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG);
  4982. }
  4983. var newData = [
  4984. func, bitmask, thisArg, newPartials, newHolders, newPartialsRight,
  4985. newHoldersRight, argPos, ary, arity
  4986. ];
  4987. var result = wrapFunc.apply(undefined, newData);
  4988. if (isLaziable(func)) {
  4989. setData(result, newData);
  4990. }
  4991. result.placeholder = placeholder;
  4992. return setWrapToString(result, func, bitmask);
  4993. }
  4994. /**
  4995. * Creates a function like `_.round`.
  4996. *
  4997. * @private
  4998. * @param {string} methodName The name of the `Math` method to use when rounding.
  4999. * @returns {Function} Returns the new round function.
  5000. */
  5001. function createRound(methodName) {
  5002. var func = Math[methodName];
  5003. return function(number, precision) {
  5004. number = toNumber(number);
  5005. precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
  5006. if (precision && nativeIsFinite(number)) {
  5007. // Shift with exponential notation to avoid floating-point issues.
  5008. // See [MDN](https://mdn.io/round#Examples) for more details.
  5009. var pair = (toString(number) + 'e').split('e'),
  5010. value = func(pair[0] + 'e' + (+pair[1] + precision));
  5011. pair = (toString(value) + 'e').split('e');
  5012. return +(pair[0] + 'e' + (+pair[1] - precision));
  5013. }
  5014. return func(number);
  5015. };
  5016. }
  5017. /**
  5018. * Creates a set object of `values`.
  5019. *
  5020. * @private
  5021. * @param {Array} values The values to add to the set.
  5022. * @returns {Object} Returns the new set.
  5023. */
  5024. var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) {
  5025. return new Set(values);
  5026. };
  5027. /**
  5028. * Creates a `_.toPairs` or `_.toPairsIn` function.
  5029. *
  5030. * @private
  5031. * @param {Function} keysFunc The function to get the keys of a given object.
  5032. * @returns {Function} Returns the new pairs function.
  5033. */
  5034. function createToPairs(keysFunc) {
  5035. return function(object) {
  5036. var tag = getTag(object);
  5037. if (tag == mapTag) {
  5038. return mapToArray(object);
  5039. }
  5040. if (tag == setTag) {
  5041. return setToPairs(object);
  5042. }
  5043. return baseToPairs(object, keysFunc(object));
  5044. };
  5045. }
  5046. /**
  5047. * Creates a function that either curries or invokes `func` with optional
  5048. * `this` binding and partially applied arguments.
  5049. *
  5050. * @private
  5051. * @param {Function|string} func The function or method name to wrap.
  5052. * @param {number} bitmask The bitmask flags.
  5053. * 1 - `_.bind`
  5054. * 2 - `_.bindKey`
  5055. * 4 - `_.curry` or `_.curryRight` of a bound function
  5056. * 8 - `_.curry`
  5057. * 16 - `_.curryRight`
  5058. * 32 - `_.partial`
  5059. * 64 - `_.partialRight`
  5060. * 128 - `_.rearg`
  5061. * 256 - `_.ary`
  5062. * 512 - `_.flip`
  5063. * @param {*} [thisArg] The `this` binding of `func`.
  5064. * @param {Array} [partials] The arguments to be partially applied.
  5065. * @param {Array} [holders] The `partials` placeholder indexes.
  5066. * @param {Array} [argPos] The argument positions of the new function.
  5067. * @param {number} [ary] The arity cap of `func`.
  5068. * @param {number} [arity] The arity of `func`.
  5069. * @returns {Function} Returns the new wrapped function.
  5070. */
  5071. function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  5072. var isBindKey = bitmask & WRAP_BIND_KEY_FLAG;
  5073. if (!isBindKey && typeof func != 'function') {
  5074. throw new TypeError(FUNC_ERROR_TEXT);
  5075. }
  5076. var length = partials ? partials.length : 0;
  5077. if (!length) {
  5078. bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG);
  5079. partials = holders = undefined;
  5080. }
  5081. ary = ary === undefined ? ary : nativeMax(toInteger(ary), 0);
  5082. arity = arity === undefined ? arity : toInteger(arity);
  5083. length -= holders ? holders.length : 0;
  5084. if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) {
  5085. var partialsRight = partials,
  5086. holdersRight = holders;
  5087. partials = holders = undefined;
  5088. }
  5089. var data = isBindKey ? undefined : getData(func);
  5090. var newData = [
  5091. func, bitmask, thisArg, partials, holders, partialsRight, holdersRight,
  5092. argPos, ary, arity
  5093. ];
  5094. if (data) {
  5095. mergeData(newData, data);
  5096. }
  5097. func = newData[0];
  5098. bitmask = newData[1];
  5099. thisArg = newData[2];
  5100. partials = newData[3];
  5101. holders = newData[4];
  5102. arity = newData[9] = newData[9] === undefined
  5103. ? (isBindKey ? 0 : func.length)
  5104. : nativeMax(newData[9] - length, 0);
  5105. if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) {
  5106. bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG);
  5107. }
  5108. if (!bitmask || bitmask == WRAP_BIND_FLAG) {
  5109. var result = createBind(func, bitmask, thisArg);
  5110. } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) {
  5111. result = createCurry(func, bitmask, arity);
  5112. } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) {
  5113. result = createPartial(func, bitmask, thisArg, partials);
  5114. } else {
  5115. result = createHybrid.apply(undefined, newData);
  5116. }
  5117. var setter = data ? baseSetData : setData;
  5118. return setWrapToString(setter(result, newData), func, bitmask);
  5119. }
  5120. /**
  5121. * Used by `_.defaults` to customize its `_.assignIn` use to assign properties
  5122. * of source objects to the destination object for all destination properties
  5123. * that resolve to `undefined`.
  5124. *
  5125. * @private
  5126. * @param {*} objValue The destination value.
  5127. * @param {*} srcValue The source value.
  5128. * @param {string} key The key of the property to assign.
  5129. * @param {Object} object The parent object of `objValue`.
  5130. * @returns {*} Returns the value to assign.
  5131. */
  5132. function customDefaultsAssignIn(objValue, srcValue, key, object) {
  5133. if (objValue === undefined ||
  5134. (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  5135. return srcValue;
  5136. }
  5137. return objValue;
  5138. }
  5139. /**
  5140. * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source
  5141. * objects into destination objects that are passed thru.
  5142. *
  5143. * @private
  5144. * @param {*} objValue The destination value.
  5145. * @param {*} srcValue The source value.
  5146. * @param {string} key The key of the property to merge.
  5147. * @param {Object} object The parent object of `objValue`.
  5148. * @param {Object} source The parent object of `srcValue`.
  5149. * @param {Object} [stack] Tracks traversed source values and their merged
  5150. * counterparts.
  5151. * @returns {*} Returns the value to assign.
  5152. */
  5153. function customDefaultsMerge(objValue, srcValue, key, object, source, stack) {
  5154. if (isObject(objValue) && isObject(srcValue)) {
  5155. // Recursively merge objects and arrays (susceptible to call stack limits).
  5156. stack.set(srcValue, objValue);
  5157. baseMerge(objValue, srcValue, undefined, customDefaultsMerge, stack);
  5158. stack['delete'](srcValue);
  5159. }
  5160. return objValue;
  5161. }
  5162. /**
  5163. * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain
  5164. * objects.
  5165. *
  5166. * @private
  5167. * @param {*} value The value to inspect.
  5168. * @param {string} key The key of the property to inspect.
  5169. * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`.
  5170. */
  5171. function customOmitClone(value) {
  5172. return isPlainObject(value) ? undefined : value;
  5173. }
  5174. /**
  5175. * A specialized version of `baseIsEqualDeep` for arrays with support for
  5176. * partial deep comparisons.
  5177. *
  5178. * @private
  5179. * @param {Array} array The array to compare.
  5180. * @param {Array} other The other array to compare.
  5181. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5182. * @param {Function} customizer The function to customize comparisons.
  5183. * @param {Function} equalFunc The function to determine equivalents of values.
  5184. * @param {Object} stack Tracks traversed `array` and `other` objects.
  5185. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  5186. */
  5187. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  5188. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5189. arrLength = array.length,
  5190. othLength = other.length;
  5191. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  5192. return false;
  5193. }
  5194. // Check that cyclic values are equal.
  5195. var arrStacked = stack.get(array);
  5196. var othStacked = stack.get(other);
  5197. if (arrStacked && othStacked) {
  5198. return arrStacked == other && othStacked == array;
  5199. }
  5200. var index = -1,
  5201. result = true,
  5202. seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined;
  5203. stack.set(array, other);
  5204. stack.set(other, array);
  5205. // Ignore non-index properties.
  5206. while (++index < arrLength) {
  5207. var arrValue = array[index],
  5208. othValue = other[index];
  5209. if (customizer) {
  5210. var compared = isPartial
  5211. ? customizer(othValue, arrValue, index, other, array, stack)
  5212. : customizer(arrValue, othValue, index, array, other, stack);
  5213. }
  5214. if (compared !== undefined) {
  5215. if (compared) {
  5216. continue;
  5217. }
  5218. result = false;
  5219. break;
  5220. }
  5221. // Recursively compare arrays (susceptible to call stack limits).
  5222. if (seen) {
  5223. if (!arraySome(other, function(othValue, othIndex) {
  5224. if (!cacheHas(seen, othIndex) &&
  5225. (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  5226. return seen.push(othIndex);
  5227. }
  5228. })) {
  5229. result = false;
  5230. break;
  5231. }
  5232. } else if (!(
  5233. arrValue === othValue ||
  5234. equalFunc(arrValue, othValue, bitmask, customizer, stack)
  5235. )) {
  5236. result = false;
  5237. break;
  5238. }
  5239. }
  5240. stack['delete'](array);
  5241. stack['delete'](other);
  5242. return result;
  5243. }
  5244. /**
  5245. * A specialized version of `baseIsEqualDeep` for comparing objects of
  5246. * the same `toStringTag`.
  5247. *
  5248. * **Note:** This function only supports comparing values with tags of
  5249. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  5250. *
  5251. * @private
  5252. * @param {Object} object The object to compare.
  5253. * @param {Object} other The other object to compare.
  5254. * @param {string} tag The `toStringTag` of the objects to compare.
  5255. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5256. * @param {Function} customizer The function to customize comparisons.
  5257. * @param {Function} equalFunc The function to determine equivalents of values.
  5258. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5259. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5260. */
  5261. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  5262. switch (tag) {
  5263. case dataViewTag:
  5264. if ((object.byteLength != other.byteLength) ||
  5265. (object.byteOffset != other.byteOffset)) {
  5266. return false;
  5267. }
  5268. object = object.buffer;
  5269. other = other.buffer;
  5270. case arrayBufferTag:
  5271. if ((object.byteLength != other.byteLength) ||
  5272. !equalFunc(new Uint8Array(object), new Uint8Array(other))) {
  5273. return false;
  5274. }
  5275. return true;
  5276. case boolTag:
  5277. case dateTag:
  5278. case numberTag:
  5279. // Coerce booleans to `1` or `0` and dates to milliseconds.
  5280. // Invalid dates are coerced to `NaN`.
  5281. return eq(+object, +other);
  5282. case errorTag:
  5283. return object.name == other.name && object.message == other.message;
  5284. case regexpTag:
  5285. case stringTag:
  5286. // Coerce regexes to strings and treat strings, primitives and objects,
  5287. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  5288. // for more details.
  5289. return object == (other + '');
  5290. case mapTag:
  5291. var convert = mapToArray;
  5292. case setTag:
  5293. var isPartial = bitmask & COMPARE_PARTIAL_FLAG;
  5294. convert || (convert = setToArray);
  5295. if (object.size != other.size && !isPartial) {
  5296. return false;
  5297. }
  5298. // Assume cyclic values are equal.
  5299. var stacked = stack.get(object);
  5300. if (stacked) {
  5301. return stacked == other;
  5302. }
  5303. bitmask |= COMPARE_UNORDERED_FLAG;
  5304. // Recursively compare objects (susceptible to call stack limits).
  5305. stack.set(object, other);
  5306. var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  5307. stack['delete'](object);
  5308. return result;
  5309. case symbolTag:
  5310. if (symbolValueOf) {
  5311. return symbolValueOf.call(object) == symbolValueOf.call(other);
  5312. }
  5313. }
  5314. return false;
  5315. }
  5316. /**
  5317. * A specialized version of `baseIsEqualDeep` for objects with support for
  5318. * partial deep comparisons.
  5319. *
  5320. * @private
  5321. * @param {Object} object The object to compare.
  5322. * @param {Object} other The other object to compare.
  5323. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  5324. * @param {Function} customizer The function to customize comparisons.
  5325. * @param {Function} equalFunc The function to determine equivalents of values.
  5326. * @param {Object} stack Tracks traversed `object` and `other` objects.
  5327. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  5328. */
  5329. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  5330. var isPartial = bitmask & COMPARE_PARTIAL_FLAG,
  5331. objProps = getAllKeys(object),
  5332. objLength = objProps.length,
  5333. othProps = getAllKeys(other),
  5334. othLength = othProps.length;
  5335. if (objLength != othLength && !isPartial) {
  5336. return false;
  5337. }
  5338. var index = objLength;
  5339. while (index--) {
  5340. var key = objProps[index];
  5341. if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) {
  5342. return false;
  5343. }
  5344. }
  5345. // Check that cyclic values are equal.
  5346. var objStacked = stack.get(object);
  5347. var othStacked = stack.get(other);
  5348. if (objStacked && othStacked) {
  5349. return objStacked == other && othStacked == object;
  5350. }
  5351. var result = true;
  5352. stack.set(object, other);
  5353. stack.set(other, object);
  5354. var skipCtor = isPartial;
  5355. while (++index < objLength) {
  5356. key = objProps[index];
  5357. var objValue = object[key],
  5358. othValue = other[key];
  5359. if (customizer) {
  5360. var compared = isPartial
  5361. ? customizer(othValue, objValue, key, other, object, stack)
  5362. : customizer(objValue, othValue, key, object, other, stack);
  5363. }
  5364. // Recursively compare objects (susceptible to call stack limits).
  5365. if (!(compared === undefined
  5366. ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack))
  5367. : compared
  5368. )) {
  5369. result = false;
  5370. break;
  5371. }
  5372. skipCtor || (skipCtor = key == 'constructor');
  5373. }
  5374. if (result && !skipCtor) {
  5375. var objCtor = object.constructor,
  5376. othCtor = other.constructor;
  5377. // Non `Object` object instances with different constructors are not equal.
  5378. if (objCtor != othCtor &&
  5379. ('constructor' in object && 'constructor' in other) &&
  5380. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  5381. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  5382. result = false;
  5383. }
  5384. }
  5385. stack['delete'](object);
  5386. stack['delete'](other);
  5387. return result;
  5388. }
  5389. /**
  5390. * A specialized version of `baseRest` which flattens the rest array.
  5391. *
  5392. * @private
  5393. * @param {Function} func The function to apply a rest parameter to.
  5394. * @returns {Function} Returns the new function.
  5395. */
  5396. function flatRest(func) {
  5397. return setToString(overRest(func, undefined, flatten), func + '');
  5398. }
  5399. /**
  5400. * Creates an array of own enumerable property names and symbols of `object`.
  5401. *
  5402. * @private
  5403. * @param {Object} object The object to query.
  5404. * @returns {Array} Returns the array of property names and symbols.
  5405. */
  5406. function getAllKeys(object) {
  5407. return baseGetAllKeys(object, keys, getSymbols);
  5408. }
  5409. /**
  5410. * Creates an array of own and inherited enumerable property names and
  5411. * symbols of `object`.
  5412. *
  5413. * @private
  5414. * @param {Object} object The object to query.
  5415. * @returns {Array} Returns the array of property names and symbols.
  5416. */
  5417. function getAllKeysIn(object) {
  5418. return baseGetAllKeys(object, keysIn, getSymbolsIn);
  5419. }
  5420. /**
  5421. * Gets metadata for `func`.
  5422. *
  5423. * @private
  5424. * @param {Function} func The function to query.
  5425. * @returns {*} Returns the metadata for `func`.
  5426. */
  5427. var getData = !metaMap ? noop : function(func) {
  5428. return metaMap.get(func);
  5429. };
  5430. /**
  5431. * Gets the name of `func`.
  5432. *
  5433. * @private
  5434. * @param {Function} func The function to query.
  5435. * @returns {string} Returns the function name.
  5436. */
  5437. function getFuncName(func) {
  5438. var result = (func.name + ''),
  5439. array = realNames[result],
  5440. length = hasOwnProperty.call(realNames, result) ? array.length : 0;
  5441. while (length--) {
  5442. var data = array[length],
  5443. otherFunc = data.func;
  5444. if (otherFunc == null || otherFunc == func) {
  5445. return data.name;
  5446. }
  5447. }
  5448. return result;
  5449. }
  5450. /**
  5451. * Gets the argument placeholder value for `func`.
  5452. *
  5453. * @private
  5454. * @param {Function} func The function to inspect.
  5455. * @returns {*} Returns the placeholder value.
  5456. */
  5457. function getHolder(func) {
  5458. var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func;
  5459. return object.placeholder;
  5460. }
  5461. /**
  5462. * Gets the appropriate "iteratee" function. If `_.iteratee` is customized,
  5463. * this function returns the custom method, otherwise it returns `baseIteratee`.
  5464. * If arguments are provided, the chosen function is invoked with them and
  5465. * its result is returned.
  5466. *
  5467. * @private
  5468. * @param {*} [value] The value to convert to an iteratee.
  5469. * @param {number} [arity] The arity of the created iteratee.
  5470. * @returns {Function} Returns the chosen function or its result.
  5471. */
  5472. function getIteratee() {
  5473. var result = lodash.iteratee || iteratee;
  5474. result = result === iteratee ? baseIteratee : result;
  5475. return arguments.length ? result(arguments[0], arguments[1]) : result;
  5476. }
  5477. /**
  5478. * Gets the data for `map`.
  5479. *
  5480. * @private
  5481. * @param {Object} map The map to query.
  5482. * @param {string} key The reference key.
  5483. * @returns {*} Returns the map data.
  5484. */
  5485. function getMapData(map, key) {
  5486. var data = map.__data__;
  5487. return isKeyable(key)
  5488. ? data[typeof key == 'string' ? 'string' : 'hash']
  5489. : data.map;
  5490. }
  5491. /**
  5492. * Gets the property names, values, and compare flags of `object`.
  5493. *
  5494. * @private
  5495. * @param {Object} object The object to query.
  5496. * @returns {Array} Returns the match data of `object`.
  5497. */
  5498. function getMatchData(object) {
  5499. var result = keys(object),
  5500. length = result.length;
  5501. while (length--) {
  5502. var key = result[length],
  5503. value = object[key];
  5504. result[length] = [key, value, isStrictComparable(value)];
  5505. }
  5506. return result;
  5507. }
  5508. /**
  5509. * Gets the native function at `key` of `object`.
  5510. *
  5511. * @private
  5512. * @param {Object} object The object to query.
  5513. * @param {string} key The key of the method to get.
  5514. * @returns {*} Returns the function if it's native, else `undefined`.
  5515. */
  5516. function getNative(object, key) {
  5517. var value = getValue(object, key);
  5518. return baseIsNative(value) ? value : undefined;
  5519. }
  5520. /**
  5521. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  5522. *
  5523. * @private
  5524. * @param {*} value The value to query.
  5525. * @returns {string} Returns the raw `toStringTag`.
  5526. */
  5527. function getRawTag(value) {
  5528. var isOwn = hasOwnProperty.call(value, symToStringTag),
  5529. tag = value[symToStringTag];
  5530. try {
  5531. value[symToStringTag] = undefined;
  5532. var unmasked = true;
  5533. } catch (e) {}
  5534. var result = nativeObjectToString.call(value);
  5535. if (unmasked) {
  5536. if (isOwn) {
  5537. value[symToStringTag] = tag;
  5538. } else {
  5539. delete value[symToStringTag];
  5540. }
  5541. }
  5542. return result;
  5543. }
  5544. /**
  5545. * Creates an array of the own enumerable symbols of `object`.
  5546. *
  5547. * @private
  5548. * @param {Object} object The object to query.
  5549. * @returns {Array} Returns the array of symbols.
  5550. */
  5551. var getSymbols = !nativeGetSymbols ? stubArray : function(object) {
  5552. if (object == null) {
  5553. return [];
  5554. }
  5555. object = Object(object);
  5556. return arrayFilter(nativeGetSymbols(object), function(symbol) {
  5557. return propertyIsEnumerable.call(object, symbol);
  5558. });
  5559. };
  5560. /**
  5561. * Creates an array of the own and inherited enumerable symbols of `object`.
  5562. *
  5563. * @private
  5564. * @param {Object} object The object to query.
  5565. * @returns {Array} Returns the array of symbols.
  5566. */
  5567. var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) {
  5568. var result = [];
  5569. while (object) {
  5570. arrayPush(result, getSymbols(object));
  5571. object = getPrototype(object);
  5572. }
  5573. return result;
  5574. };
  5575. /**
  5576. * Gets the `toStringTag` of `value`.
  5577. *
  5578. * @private
  5579. * @param {*} value The value to query.
  5580. * @returns {string} Returns the `toStringTag`.
  5581. */
  5582. var getTag = baseGetTag;
  5583. // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  5584. if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) ||
  5585. (Map && getTag(new Map) != mapTag) ||
  5586. (Promise && getTag(Promise.resolve()) != promiseTag) ||
  5587. (Set && getTag(new Set) != setTag) ||
  5588. (WeakMap && getTag(new WeakMap) != weakMapTag)) {
  5589. getTag = function(value) {
  5590. var result = baseGetTag(value),
  5591. Ctor = result == objectTag ? value.constructor : undefined,
  5592. ctorString = Ctor ? toSource(Ctor) : '';
  5593. if (ctorString) {
  5594. switch (ctorString) {
  5595. case dataViewCtorString: return dataViewTag;
  5596. case mapCtorString: return mapTag;
  5597. case promiseCtorString: return promiseTag;
  5598. case setCtorString: return setTag;
  5599. case weakMapCtorString: return weakMapTag;
  5600. }
  5601. }
  5602. return result;
  5603. };
  5604. }
  5605. /**
  5606. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  5607. *
  5608. * @private
  5609. * @param {number} start The start of the view.
  5610. * @param {number} end The end of the view.
  5611. * @param {Array} transforms The transformations to apply to the view.
  5612. * @returns {Object} Returns an object containing the `start` and `end`
  5613. * positions of the view.
  5614. */
  5615. function getView(start, end, transforms) {
  5616. var index = -1,
  5617. length = transforms.length;
  5618. while (++index < length) {
  5619. var data = transforms[index],
  5620. size = data.size;
  5621. switch (data.type) {
  5622. case 'drop': start += size; break;
  5623. case 'dropRight': end -= size; break;
  5624. case 'take': end = nativeMin(end, start + size); break;
  5625. case 'takeRight': start = nativeMax(start, end - size); break;
  5626. }
  5627. }
  5628. return { 'start': start, 'end': end };
  5629. }
  5630. /**
  5631. * Extracts wrapper details from the `source` body comment.
  5632. *
  5633. * @private
  5634. * @param {string} source The source to inspect.
  5635. * @returns {Array} Returns the wrapper details.
  5636. */
  5637. function getWrapDetails(source) {
  5638. var match = source.match(reWrapDetails);
  5639. return match ? match[1].split(reSplitDetails) : [];
  5640. }
  5641. /**
  5642. * Checks if `path` exists on `object`.
  5643. *
  5644. * @private
  5645. * @param {Object} object The object to query.
  5646. * @param {Array|string} path The path to check.
  5647. * @param {Function} hasFunc The function to check properties.
  5648. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  5649. */
  5650. function hasPath(object, path, hasFunc) {
  5651. path = castPath(path, object);
  5652. var index = -1,
  5653. length = path.length,
  5654. result = false;
  5655. while (++index < length) {
  5656. var key = toKey(path[index]);
  5657. if (!(result = object != null && hasFunc(object, key))) {
  5658. break;
  5659. }
  5660. object = object[key];
  5661. }
  5662. if (result || ++index != length) {
  5663. return result;
  5664. }
  5665. length = object == null ? 0 : object.length;
  5666. return !!length && isLength(length) && isIndex(key, length) &&
  5667. (isArray(object) || isArguments(object));
  5668. }
  5669. /**
  5670. * Initializes an array clone.
  5671. *
  5672. * @private
  5673. * @param {Array} array The array to clone.
  5674. * @returns {Array} Returns the initialized clone.
  5675. */
  5676. function initCloneArray(array) {
  5677. var length = array.length,
  5678. result = new array.constructor(length);
  5679. // Add properties assigned by `RegExp#exec`.
  5680. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  5681. result.index = array.index;
  5682. result.input = array.input;
  5683. }
  5684. return result;
  5685. }
  5686. /**
  5687. * Initializes an object clone.
  5688. *
  5689. * @private
  5690. * @param {Object} object The object to clone.
  5691. * @returns {Object} Returns the initialized clone.
  5692. */
  5693. function initCloneObject(object) {
  5694. return (typeof object.constructor == 'function' && !isPrototype(object))
  5695. ? baseCreate(getPrototype(object))
  5696. : {};
  5697. }
  5698. /**
  5699. * Initializes an object clone based on its `toStringTag`.
  5700. *
  5701. * **Note:** This function only supports cloning values with tags of
  5702. * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`.
  5703. *
  5704. * @private
  5705. * @param {Object} object The object to clone.
  5706. * @param {string} tag The `toStringTag` of the object to clone.
  5707. * @param {boolean} [isDeep] Specify a deep clone.
  5708. * @returns {Object} Returns the initialized clone.
  5709. */
  5710. function initCloneByTag(object, tag, isDeep) {
  5711. var Ctor = object.constructor;
  5712. switch (tag) {
  5713. case arrayBufferTag:
  5714. return cloneArrayBuffer(object);
  5715. case boolTag:
  5716. case dateTag:
  5717. return new Ctor(+object);
  5718. case dataViewTag:
  5719. return cloneDataView(object, isDeep);
  5720. case float32Tag: case float64Tag:
  5721. case int8Tag: case int16Tag: case int32Tag:
  5722. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  5723. return cloneTypedArray(object, isDeep);
  5724. case mapTag:
  5725. return new Ctor;
  5726. case numberTag:
  5727. case stringTag:
  5728. return new Ctor(object);
  5729. case regexpTag:
  5730. return cloneRegExp(object);
  5731. case setTag:
  5732. return new Ctor;
  5733. case symbolTag:
  5734. return cloneSymbol(object);
  5735. }
  5736. }
  5737. /**
  5738. * Inserts wrapper `details` in a comment at the top of the `source` body.
  5739. *
  5740. * @private
  5741. * @param {string} source The source to modify.
  5742. * @returns {Array} details The details to insert.
  5743. * @returns {string} Returns the modified source.
  5744. */
  5745. function insertWrapDetails(source, details) {
  5746. var length = details.length;
  5747. if (!length) {
  5748. return source;
  5749. }
  5750. var lastIndex = length - 1;
  5751. details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex];
  5752. details = details.join(length > 2 ? ', ' : ' ');
  5753. return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n');
  5754. }
  5755. /**
  5756. * Checks if `value` is a flattenable `arguments` object or array.
  5757. *
  5758. * @private
  5759. * @param {*} value The value to check.
  5760. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  5761. */
  5762. function isFlattenable(value) {
  5763. return isArray(value) || isArguments(value) ||
  5764. !!(spreadableSymbol && value && value[spreadableSymbol]);
  5765. }
  5766. /**
  5767. * Checks if `value` is a valid array-like index.
  5768. *
  5769. * @private
  5770. * @param {*} value The value to check.
  5771. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  5772. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  5773. */
  5774. function isIndex(value, length) {
  5775. var type = typeof value;
  5776. length = length == null ? MAX_SAFE_INTEGER : length;
  5777. return !!length &&
  5778. (type == 'number' ||
  5779. (type != 'symbol' && reIsUint.test(value))) &&
  5780. (value > -1 && value % 1 == 0 && value < length);
  5781. }
  5782. /**
  5783. * Checks if the given arguments are from an iteratee call.
  5784. *
  5785. * @private
  5786. * @param {*} value The potential iteratee value argument.
  5787. * @param {*} index The potential iteratee index or key argument.
  5788. * @param {*} object The potential iteratee object argument.
  5789. * @returns {boolean} Returns `true` if the arguments are from an iteratee call,
  5790. * else `false`.
  5791. */
  5792. function isIterateeCall(value, index, object) {
  5793. if (!isObject(object)) {
  5794. return false;
  5795. }
  5796. var type = typeof index;
  5797. if (type == 'number'
  5798. ? (isArrayLike(object) && isIndex(index, object.length))
  5799. : (type == 'string' && index in object)
  5800. ) {
  5801. return eq(object[index], value);
  5802. }
  5803. return false;
  5804. }
  5805. /**
  5806. * Checks if `value` is a property name and not a property path.
  5807. *
  5808. * @private
  5809. * @param {*} value The value to check.
  5810. * @param {Object} [object] The object to query keys on.
  5811. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  5812. */
  5813. function isKey(value, object) {
  5814. if (isArray(value)) {
  5815. return false;
  5816. }
  5817. var type = typeof value;
  5818. if (type == 'number' || type == 'symbol' || type == 'boolean' ||
  5819. value == null || isSymbol(value)) {
  5820. return true;
  5821. }
  5822. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) ||
  5823. (object != null && value in Object(object));
  5824. }
  5825. /**
  5826. * Checks if `value` is suitable for use as unique object key.
  5827. *
  5828. * @private
  5829. * @param {*} value The value to check.
  5830. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  5831. */
  5832. function isKeyable(value) {
  5833. var type = typeof value;
  5834. return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean')
  5835. ? (value !== '__proto__')
  5836. : (value === null);
  5837. }
  5838. /**
  5839. * Checks if `func` has a lazy counterpart.
  5840. *
  5841. * @private
  5842. * @param {Function} func The function to check.
  5843. * @returns {boolean} Returns `true` if `func` has a lazy counterpart,
  5844. * else `false`.
  5845. */
  5846. function isLaziable(func) {
  5847. var funcName = getFuncName(func),
  5848. other = lodash[funcName];
  5849. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  5850. return false;
  5851. }
  5852. if (func === other) {
  5853. return true;
  5854. }
  5855. var data = getData(other);
  5856. return !!data && func === data[0];
  5857. }
  5858. /**
  5859. * Checks if `func` has its source masked.
  5860. *
  5861. * @private
  5862. * @param {Function} func The function to check.
  5863. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  5864. */
  5865. function isMasked(func) {
  5866. return !!maskSrcKey && (maskSrcKey in func);
  5867. }
  5868. /**
  5869. * Checks if `func` is capable of being masked.
  5870. *
  5871. * @private
  5872. * @param {*} value The value to check.
  5873. * @returns {boolean} Returns `true` if `func` is maskable, else `false`.
  5874. */
  5875. var isMaskable = coreJsData ? isFunction : stubFalse;
  5876. /**
  5877. * Checks if `value` is likely a prototype object.
  5878. *
  5879. * @private
  5880. * @param {*} value The value to check.
  5881. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  5882. */
  5883. function isPrototype(value) {
  5884. var Ctor = value && value.constructor,
  5885. proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto;
  5886. return value === proto;
  5887. }
  5888. /**
  5889. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  5890. *
  5891. * @private
  5892. * @param {*} value The value to check.
  5893. * @returns {boolean} Returns `true` if `value` if suitable for strict
  5894. * equality comparisons, else `false`.
  5895. */
  5896. function isStrictComparable(value) {
  5897. return value === value && !isObject(value);
  5898. }
  5899. /**
  5900. * A specialized version of `matchesProperty` for source values suitable
  5901. * for strict equality comparisons, i.e. `===`.
  5902. *
  5903. * @private
  5904. * @param {string} key The key of the property to get.
  5905. * @param {*} srcValue The value to match.
  5906. * @returns {Function} Returns the new spec function.
  5907. */
  5908. function matchesStrictComparable(key, srcValue) {
  5909. return function(object) {
  5910. if (object == null) {
  5911. return false;
  5912. }
  5913. return object[key] === srcValue &&
  5914. (srcValue !== undefined || (key in Object(object)));
  5915. };
  5916. }
  5917. /**
  5918. * A specialized version of `_.memoize` which clears the memoized function's
  5919. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  5920. *
  5921. * @private
  5922. * @param {Function} func The function to have its output memoized.
  5923. * @returns {Function} Returns the new memoized function.
  5924. */
  5925. function memoizeCapped(func) {
  5926. var result = memoize(func, function(key) {
  5927. if (cache.size === MAX_MEMOIZE_SIZE) {
  5928. cache.clear();
  5929. }
  5930. return key;
  5931. });
  5932. var cache = result.cache;
  5933. return result;
  5934. }
  5935. /**
  5936. * Merges the function metadata of `source` into `data`.
  5937. *
  5938. * Merging metadata reduces the number of wrappers used to invoke a function.
  5939. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  5940. * may be applied regardless of execution order. Methods like `_.ary` and
  5941. * `_.rearg` modify function arguments, making the order in which they are
  5942. * executed important, preventing the merging of metadata. However, we make
  5943. * an exception for a safe combined case where curried functions have `_.ary`
  5944. * and or `_.rearg` applied.
  5945. *
  5946. * @private
  5947. * @param {Array} data The destination metadata.
  5948. * @param {Array} source The source metadata.
  5949. * @returns {Array} Returns `data`.
  5950. */
  5951. function mergeData(data, source) {
  5952. var bitmask = data[1],
  5953. srcBitmask = source[1],
  5954. newBitmask = bitmask | srcBitmask,
  5955. isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG);
  5956. var isCombo =
  5957. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) ||
  5958. ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) ||
  5959. ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG));
  5960. // Exit early if metadata can't be merged.
  5961. if (!(isCommon || isCombo)) {
  5962. return data;
  5963. }
  5964. // Use source `thisArg` if available.
  5965. if (srcBitmask & WRAP_BIND_FLAG) {
  5966. data[2] = source[2];
  5967. // Set when currying a bound function.
  5968. newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG;
  5969. }
  5970. // Compose partial arguments.
  5971. var value = source[3];
  5972. if (value) {
  5973. var partials = data[3];
  5974. data[3] = partials ? composeArgs(partials, value, source[4]) : value;
  5975. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4];
  5976. }
  5977. // Compose partial right arguments.
  5978. value = source[5];
  5979. if (value) {
  5980. partials = data[5];
  5981. data[5] = partials ? composeArgsRight(partials, value, source[6]) : value;
  5982. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6];
  5983. }
  5984. // Use source `argPos` if available.
  5985. value = source[7];
  5986. if (value) {
  5987. data[7] = value;
  5988. }
  5989. // Use source `ary` if it's smaller.
  5990. if (srcBitmask & WRAP_ARY_FLAG) {
  5991. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  5992. }
  5993. // Use source `arity` if one is not provided.
  5994. if (data[9] == null) {
  5995. data[9] = source[9];
  5996. }
  5997. // Use source `func` and merge bitmasks.
  5998. data[0] = source[0];
  5999. data[1] = newBitmask;
  6000. return data;
  6001. }
  6002. /**
  6003. * This function is like
  6004. * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  6005. * except that it includes inherited enumerable properties.
  6006. *
  6007. * @private
  6008. * @param {Object} object The object to query.
  6009. * @returns {Array} Returns the array of property names.
  6010. */
  6011. function nativeKeysIn(object) {
  6012. var result = [];
  6013. if (object != null) {
  6014. for (var key in Object(object)) {
  6015. result.push(key);
  6016. }
  6017. }
  6018. return result;
  6019. }
  6020. /**
  6021. * Converts `value` to a string using `Object.prototype.toString`.
  6022. *
  6023. * @private
  6024. * @param {*} value The value to convert.
  6025. * @returns {string} Returns the converted string.
  6026. */
  6027. function objectToString(value) {
  6028. return nativeObjectToString.call(value);
  6029. }
  6030. /**
  6031. * A specialized version of `baseRest` which transforms the rest array.
  6032. *
  6033. * @private
  6034. * @param {Function} func The function to apply a rest parameter to.
  6035. * @param {number} [start=func.length-1] The start position of the rest parameter.
  6036. * @param {Function} transform The rest array transform.
  6037. * @returns {Function} Returns the new function.
  6038. */
  6039. function overRest(func, start, transform) {
  6040. start = nativeMax(start === undefined ? (func.length - 1) : start, 0);
  6041. return function() {
  6042. var args = arguments,
  6043. index = -1,
  6044. length = nativeMax(args.length - start, 0),
  6045. array = Array(length);
  6046. while (++index < length) {
  6047. array[index] = args[start + index];
  6048. }
  6049. index = -1;
  6050. var otherArgs = Array(start + 1);
  6051. while (++index < start) {
  6052. otherArgs[index] = args[index];
  6053. }
  6054. otherArgs[start] = transform(array);
  6055. return apply(func, this, otherArgs);
  6056. };
  6057. }
  6058. /**
  6059. * Gets the parent value at `path` of `object`.
  6060. *
  6061. * @private
  6062. * @param {Object} object The object to query.
  6063. * @param {Array} path The path to get the parent value of.
  6064. * @returns {*} Returns the parent value.
  6065. */
  6066. function parent(object, path) {
  6067. return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1));
  6068. }
  6069. /**
  6070. * Reorder `array` according to the specified indexes where the element at
  6071. * the first index is assigned as the first element, the element at
  6072. * the second index is assigned as the second element, and so on.
  6073. *
  6074. * @private
  6075. * @param {Array} array The array to reorder.
  6076. * @param {Array} indexes The arranged array indexes.
  6077. * @returns {Array} Returns `array`.
  6078. */
  6079. function reorder(array, indexes) {
  6080. var arrLength = array.length,
  6081. length = nativeMin(indexes.length, arrLength),
  6082. oldArray = copyArray(array);
  6083. while (length--) {
  6084. var index = indexes[length];
  6085. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  6086. }
  6087. return array;
  6088. }
  6089. /**
  6090. * Gets the value at `key`, unless `key` is "__proto__" or "constructor".
  6091. *
  6092. * @private
  6093. * @param {Object} object The object to query.
  6094. * @param {string} key The key of the property to get.
  6095. * @returns {*} Returns the property value.
  6096. */
  6097. function safeGet(object, key) {
  6098. if (key === 'constructor' && typeof object[key] === 'function') {
  6099. return;
  6100. }
  6101. if (key == '__proto__') {
  6102. return;
  6103. }
  6104. return object[key];
  6105. }
  6106. /**
  6107. * Sets metadata for `func`.
  6108. *
  6109. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  6110. * period of time, it will trip its breaker and transition to an identity
  6111. * function to avoid garbage collection pauses in V8. See
  6112. * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070)
  6113. * for more details.
  6114. *
  6115. * @private
  6116. * @param {Function} func The function to associate metadata with.
  6117. * @param {*} data The metadata.
  6118. * @returns {Function} Returns `func`.
  6119. */
  6120. var setData = shortOut(baseSetData);
  6121. /**
  6122. * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout).
  6123. *
  6124. * @private
  6125. * @param {Function} func The function to delay.
  6126. * @param {number} wait The number of milliseconds to delay invocation.
  6127. * @returns {number|Object} Returns the timer id or timeout object.
  6128. */
  6129. var setTimeout = ctxSetTimeout || function(func, wait) {
  6130. return root.setTimeout(func, wait);
  6131. };
  6132. /**
  6133. * Sets the `toString` method of `func` to return `string`.
  6134. *
  6135. * @private
  6136. * @param {Function} func The function to modify.
  6137. * @param {Function} string The `toString` result.
  6138. * @returns {Function} Returns `func`.
  6139. */
  6140. var setToString = shortOut(baseSetToString);
  6141. /**
  6142. * Sets the `toString` method of `wrapper` to mimic the source of `reference`
  6143. * with wrapper details in a comment at the top of the source body.
  6144. *
  6145. * @private
  6146. * @param {Function} wrapper The function to modify.
  6147. * @param {Function} reference The reference function.
  6148. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6149. * @returns {Function} Returns `wrapper`.
  6150. */
  6151. function setWrapToString(wrapper, reference, bitmask) {
  6152. var source = (reference + '');
  6153. return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask)));
  6154. }
  6155. /**
  6156. * Creates a function that'll short out and invoke `identity` instead
  6157. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  6158. * milliseconds.
  6159. *
  6160. * @private
  6161. * @param {Function} func The function to restrict.
  6162. * @returns {Function} Returns the new shortable function.
  6163. */
  6164. function shortOut(func) {
  6165. var count = 0,
  6166. lastCalled = 0;
  6167. return function() {
  6168. var stamp = nativeNow(),
  6169. remaining = HOT_SPAN - (stamp - lastCalled);
  6170. lastCalled = stamp;
  6171. if (remaining > 0) {
  6172. if (++count >= HOT_COUNT) {
  6173. return arguments[0];
  6174. }
  6175. } else {
  6176. count = 0;
  6177. }
  6178. return func.apply(undefined, arguments);
  6179. };
  6180. }
  6181. /**
  6182. * A specialized version of `_.shuffle` which mutates and sets the size of `array`.
  6183. *
  6184. * @private
  6185. * @param {Array} array The array to shuffle.
  6186. * @param {number} [size=array.length] The size of `array`.
  6187. * @returns {Array} Returns `array`.
  6188. */
  6189. function shuffleSelf(array, size) {
  6190. var index = -1,
  6191. length = array.length,
  6192. lastIndex = length - 1;
  6193. size = size === undefined ? length : size;
  6194. while (++index < size) {
  6195. var rand = baseRandom(index, lastIndex),
  6196. value = array[rand];
  6197. array[rand] = array[index];
  6198. array[index] = value;
  6199. }
  6200. array.length = size;
  6201. return array;
  6202. }
  6203. /**
  6204. * Converts `string` to a property path array.
  6205. *
  6206. * @private
  6207. * @param {string} string The string to convert.
  6208. * @returns {Array} Returns the property path array.
  6209. */
  6210. var stringToPath = memoizeCapped(function(string) {
  6211. var result = [];
  6212. if (string.charCodeAt(0) === 46 /* . */) {
  6213. result.push('');
  6214. }
  6215. string.replace(rePropName, function(match, number, quote, subString) {
  6216. result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match));
  6217. });
  6218. return result;
  6219. });
  6220. /**
  6221. * Converts `value` to a string key if it's not a string or symbol.
  6222. *
  6223. * @private
  6224. * @param {*} value The value to inspect.
  6225. * @returns {string|symbol} Returns the key.
  6226. */
  6227. function toKey(value) {
  6228. if (typeof value == 'string' || isSymbol(value)) {
  6229. return value;
  6230. }
  6231. var result = (value + '');
  6232. return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result;
  6233. }
  6234. /**
  6235. * Converts `func` to its source code.
  6236. *
  6237. * @private
  6238. * @param {Function} func The function to convert.
  6239. * @returns {string} Returns the source code.
  6240. */
  6241. function toSource(func) {
  6242. if (func != null) {
  6243. try {
  6244. return funcToString.call(func);
  6245. } catch (e) {}
  6246. try {
  6247. return (func + '');
  6248. } catch (e) {}
  6249. }
  6250. return '';
  6251. }
  6252. /**
  6253. * Updates wrapper `details` based on `bitmask` flags.
  6254. *
  6255. * @private
  6256. * @returns {Array} details The details to modify.
  6257. * @param {number} bitmask The bitmask flags. See `createWrap` for more details.
  6258. * @returns {Array} Returns `details`.
  6259. */
  6260. function updateWrapDetails(details, bitmask) {
  6261. arrayEach(wrapFlags, function(pair) {
  6262. var value = '_.' + pair[0];
  6263. if ((bitmask & pair[1]) && !arrayIncludes(details, value)) {
  6264. details.push(value);
  6265. }
  6266. });
  6267. return details.sort();
  6268. }
  6269. /**
  6270. * Creates a clone of `wrapper`.
  6271. *
  6272. * @private
  6273. * @param {Object} wrapper The wrapper to clone.
  6274. * @returns {Object} Returns the cloned wrapper.
  6275. */
  6276. function wrapperClone(wrapper) {
  6277. if (wrapper instanceof LazyWrapper) {
  6278. return wrapper.clone();
  6279. }
  6280. var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__);
  6281. result.__actions__ = copyArray(wrapper.__actions__);
  6282. result.__index__ = wrapper.__index__;
  6283. result.__values__ = wrapper.__values__;
  6284. return result;
  6285. }
  6286. /*------------------------------------------------------------------------*/
  6287. /**
  6288. * Creates an array of elements split into groups the length of `size`.
  6289. * If `array` can't be split evenly, the final chunk will be the remaining
  6290. * elements.
  6291. *
  6292. * @static
  6293. * @memberOf _
  6294. * @since 3.0.0
  6295. * @category Array
  6296. * @param {Array} array The array to process.
  6297. * @param {number} [size=1] The length of each chunk
  6298. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6299. * @returns {Array} Returns the new array of chunks.
  6300. * @example
  6301. *
  6302. * _.chunk(['a', 'b', 'c', 'd'], 2);
  6303. * // => [['a', 'b'], ['c', 'd']]
  6304. *
  6305. * _.chunk(['a', 'b', 'c', 'd'], 3);
  6306. * // => [['a', 'b', 'c'], ['d']]
  6307. */
  6308. function chunk(array, size, guard) {
  6309. if ((guard ? isIterateeCall(array, size, guard) : size === undefined)) {
  6310. size = 1;
  6311. } else {
  6312. size = nativeMax(toInteger(size), 0);
  6313. }
  6314. var length = array == null ? 0 : array.length;
  6315. if (!length || size < 1) {
  6316. return [];
  6317. }
  6318. var index = 0,
  6319. resIndex = 0,
  6320. result = Array(nativeCeil(length / size));
  6321. while (index < length) {
  6322. result[resIndex++] = baseSlice(array, index, (index += size));
  6323. }
  6324. return result;
  6325. }
  6326. /**
  6327. * Creates an array with all falsey values removed. The values `false`, `null`,
  6328. * `0`, `""`, `undefined`, and `NaN` are falsey.
  6329. *
  6330. * @static
  6331. * @memberOf _
  6332. * @since 0.1.0
  6333. * @category Array
  6334. * @param {Array} array The array to compact.
  6335. * @returns {Array} Returns the new array of filtered values.
  6336. * @example
  6337. *
  6338. * _.compact([0, 1, false, 2, '', 3]);
  6339. * // => [1, 2, 3]
  6340. */
  6341. function compact(array) {
  6342. var index = -1,
  6343. length = array == null ? 0 : array.length,
  6344. resIndex = 0,
  6345. result = [];
  6346. while (++index < length) {
  6347. var value = array[index];
  6348. if (value) {
  6349. result[resIndex++] = value;
  6350. }
  6351. }
  6352. return result;
  6353. }
  6354. /**
  6355. * Creates a new array concatenating `array` with any additional arrays
  6356. * and/or values.
  6357. *
  6358. * @static
  6359. * @memberOf _
  6360. * @since 4.0.0
  6361. * @category Array
  6362. * @param {Array} array The array to concatenate.
  6363. * @param {...*} [values] The values to concatenate.
  6364. * @returns {Array} Returns the new concatenated array.
  6365. * @example
  6366. *
  6367. * var array = [1];
  6368. * var other = _.concat(array, 2, [3], [[4]]);
  6369. *
  6370. * console.log(other);
  6371. * // => [1, 2, 3, [4]]
  6372. *
  6373. * console.log(array);
  6374. * // => [1]
  6375. */
  6376. function concat() {
  6377. var length = arguments.length;
  6378. if (!length) {
  6379. return [];
  6380. }
  6381. var args = Array(length - 1),
  6382. array = arguments[0],
  6383. index = length;
  6384. while (index--) {
  6385. args[index - 1] = arguments[index];
  6386. }
  6387. return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1));
  6388. }
  6389. /**
  6390. * Creates an array of `array` values not included in the other given arrays
  6391. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6392. * for equality comparisons. The order and references of result values are
  6393. * determined by the first array.
  6394. *
  6395. * **Note:** Unlike `_.pullAll`, this method returns a new array.
  6396. *
  6397. * @static
  6398. * @memberOf _
  6399. * @since 0.1.0
  6400. * @category Array
  6401. * @param {Array} array The array to inspect.
  6402. * @param {...Array} [values] The values to exclude.
  6403. * @returns {Array} Returns the new array of filtered values.
  6404. * @see _.without, _.xor
  6405. * @example
  6406. *
  6407. * _.difference([2, 1], [2, 3]);
  6408. * // => [1]
  6409. */
  6410. var difference = baseRest(function(array, values) {
  6411. return isArrayLikeObject(array)
  6412. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true))
  6413. : [];
  6414. });
  6415. /**
  6416. * This method is like `_.difference` except that it accepts `iteratee` which
  6417. * is invoked for each element of `array` and `values` to generate the criterion
  6418. * by which they're compared. The order and references of result values are
  6419. * determined by the first array. The iteratee is invoked with one argument:
  6420. * (value).
  6421. *
  6422. * **Note:** Unlike `_.pullAllBy`, this method returns a new array.
  6423. *
  6424. * @static
  6425. * @memberOf _
  6426. * @since 4.0.0
  6427. * @category Array
  6428. * @param {Array} array The array to inspect.
  6429. * @param {...Array} [values] The values to exclude.
  6430. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6431. * @returns {Array} Returns the new array of filtered values.
  6432. * @example
  6433. *
  6434. * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6435. * // => [1.2]
  6436. *
  6437. * // The `_.property` iteratee shorthand.
  6438. * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x');
  6439. * // => [{ 'x': 2 }]
  6440. */
  6441. var differenceBy = baseRest(function(array, values) {
  6442. var iteratee = last(values);
  6443. if (isArrayLikeObject(iteratee)) {
  6444. iteratee = undefined;
  6445. }
  6446. return isArrayLikeObject(array)
  6447. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2))
  6448. : [];
  6449. });
  6450. /**
  6451. * This method is like `_.difference` except that it accepts `comparator`
  6452. * which is invoked to compare elements of `array` to `values`. The order and
  6453. * references of result values are determined by the first array. The comparator
  6454. * is invoked with two arguments: (arrVal, othVal).
  6455. *
  6456. * **Note:** Unlike `_.pullAllWith`, this method returns a new array.
  6457. *
  6458. * @static
  6459. * @memberOf _
  6460. * @since 4.0.0
  6461. * @category Array
  6462. * @param {Array} array The array to inspect.
  6463. * @param {...Array} [values] The values to exclude.
  6464. * @param {Function} [comparator] The comparator invoked per element.
  6465. * @returns {Array} Returns the new array of filtered values.
  6466. * @example
  6467. *
  6468. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  6469. *
  6470. * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual);
  6471. * // => [{ 'x': 2, 'y': 1 }]
  6472. */
  6473. var differenceWith = baseRest(function(array, values) {
  6474. var comparator = last(values);
  6475. if (isArrayLikeObject(comparator)) {
  6476. comparator = undefined;
  6477. }
  6478. return isArrayLikeObject(array)
  6479. ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined, comparator)
  6480. : [];
  6481. });
  6482. /**
  6483. * Creates a slice of `array` with `n` elements dropped from the beginning.
  6484. *
  6485. * @static
  6486. * @memberOf _
  6487. * @since 0.5.0
  6488. * @category Array
  6489. * @param {Array} array The array to query.
  6490. * @param {number} [n=1] The number of elements to drop.
  6491. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6492. * @returns {Array} Returns the slice of `array`.
  6493. * @example
  6494. *
  6495. * _.drop([1, 2, 3]);
  6496. * // => [2, 3]
  6497. *
  6498. * _.drop([1, 2, 3], 2);
  6499. * // => [3]
  6500. *
  6501. * _.drop([1, 2, 3], 5);
  6502. * // => []
  6503. *
  6504. * _.drop([1, 2, 3], 0);
  6505. * // => [1, 2, 3]
  6506. */
  6507. function drop(array, n, guard) {
  6508. var length = array == null ? 0 : array.length;
  6509. if (!length) {
  6510. return [];
  6511. }
  6512. n = (guard || n === undefined) ? 1 : toInteger(n);
  6513. return baseSlice(array, n < 0 ? 0 : n, length);
  6514. }
  6515. /**
  6516. * Creates a slice of `array` with `n` elements dropped from the end.
  6517. *
  6518. * @static
  6519. * @memberOf _
  6520. * @since 3.0.0
  6521. * @category Array
  6522. * @param {Array} array The array to query.
  6523. * @param {number} [n=1] The number of elements to drop.
  6524. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  6525. * @returns {Array} Returns the slice of `array`.
  6526. * @example
  6527. *
  6528. * _.dropRight([1, 2, 3]);
  6529. * // => [1, 2]
  6530. *
  6531. * _.dropRight([1, 2, 3], 2);
  6532. * // => [1]
  6533. *
  6534. * _.dropRight([1, 2, 3], 5);
  6535. * // => []
  6536. *
  6537. * _.dropRight([1, 2, 3], 0);
  6538. * // => [1, 2, 3]
  6539. */
  6540. function dropRight(array, n, guard) {
  6541. var length = array == null ? 0 : array.length;
  6542. if (!length) {
  6543. return [];
  6544. }
  6545. n = (guard || n === undefined) ? 1 : toInteger(n);
  6546. n = length - n;
  6547. return baseSlice(array, 0, n < 0 ? 0 : n);
  6548. }
  6549. /**
  6550. * Creates a slice of `array` excluding elements dropped from the end.
  6551. * Elements are dropped until `predicate` returns falsey. The predicate is
  6552. * invoked with three arguments: (value, index, array).
  6553. *
  6554. * @static
  6555. * @memberOf _
  6556. * @since 3.0.0
  6557. * @category Array
  6558. * @param {Array} array The array to query.
  6559. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6560. * @returns {Array} Returns the slice of `array`.
  6561. * @example
  6562. *
  6563. * var users = [
  6564. * { 'user': 'barney', 'active': true },
  6565. * { 'user': 'fred', 'active': false },
  6566. * { 'user': 'pebbles', 'active': false }
  6567. * ];
  6568. *
  6569. * _.dropRightWhile(users, function(o) { return !o.active; });
  6570. * // => objects for ['barney']
  6571. *
  6572. * // The `_.matches` iteratee shorthand.
  6573. * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false });
  6574. * // => objects for ['barney', 'fred']
  6575. *
  6576. * // The `_.matchesProperty` iteratee shorthand.
  6577. * _.dropRightWhile(users, ['active', false]);
  6578. * // => objects for ['barney']
  6579. *
  6580. * // The `_.property` iteratee shorthand.
  6581. * _.dropRightWhile(users, 'active');
  6582. * // => objects for ['barney', 'fred', 'pebbles']
  6583. */
  6584. function dropRightWhile(array, predicate) {
  6585. return (array && array.length)
  6586. ? baseWhile(array, getIteratee(predicate, 3), true, true)
  6587. : [];
  6588. }
  6589. /**
  6590. * Creates a slice of `array` excluding elements dropped from the beginning.
  6591. * Elements are dropped until `predicate` returns falsey. The predicate is
  6592. * invoked with three arguments: (value, index, array).
  6593. *
  6594. * @static
  6595. * @memberOf _
  6596. * @since 3.0.0
  6597. * @category Array
  6598. * @param {Array} array The array to query.
  6599. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6600. * @returns {Array} Returns the slice of `array`.
  6601. * @example
  6602. *
  6603. * var users = [
  6604. * { 'user': 'barney', 'active': false },
  6605. * { 'user': 'fred', 'active': false },
  6606. * { 'user': 'pebbles', 'active': true }
  6607. * ];
  6608. *
  6609. * _.dropWhile(users, function(o) { return !o.active; });
  6610. * // => objects for ['pebbles']
  6611. *
  6612. * // The `_.matches` iteratee shorthand.
  6613. * _.dropWhile(users, { 'user': 'barney', 'active': false });
  6614. * // => objects for ['fred', 'pebbles']
  6615. *
  6616. * // The `_.matchesProperty` iteratee shorthand.
  6617. * _.dropWhile(users, ['active', false]);
  6618. * // => objects for ['pebbles']
  6619. *
  6620. * // The `_.property` iteratee shorthand.
  6621. * _.dropWhile(users, 'active');
  6622. * // => objects for ['barney', 'fred', 'pebbles']
  6623. */
  6624. function dropWhile(array, predicate) {
  6625. return (array && array.length)
  6626. ? baseWhile(array, getIteratee(predicate, 3), true)
  6627. : [];
  6628. }
  6629. /**
  6630. * Fills elements of `array` with `value` from `start` up to, but not
  6631. * including, `end`.
  6632. *
  6633. * **Note:** This method mutates `array`.
  6634. *
  6635. * @static
  6636. * @memberOf _
  6637. * @since 3.2.0
  6638. * @category Array
  6639. * @param {Array} array The array to fill.
  6640. * @param {*} value The value to fill `array` with.
  6641. * @param {number} [start=0] The start position.
  6642. * @param {number} [end=array.length] The end position.
  6643. * @returns {Array} Returns `array`.
  6644. * @example
  6645. *
  6646. * var array = [1, 2, 3];
  6647. *
  6648. * _.fill(array, 'a');
  6649. * console.log(array);
  6650. * // => ['a', 'a', 'a']
  6651. *
  6652. * _.fill(Array(3), 2);
  6653. * // => [2, 2, 2]
  6654. *
  6655. * _.fill([4, 6, 8, 10], '*', 1, 3);
  6656. * // => [4, '*', '*', 10]
  6657. */
  6658. function fill(array, value, start, end) {
  6659. var length = array == null ? 0 : array.length;
  6660. if (!length) {
  6661. return [];
  6662. }
  6663. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  6664. start = 0;
  6665. end = length;
  6666. }
  6667. return baseFill(array, value, start, end);
  6668. }
  6669. /**
  6670. * This method is like `_.find` except that it returns the index of the first
  6671. * element `predicate` returns truthy for instead of the element itself.
  6672. *
  6673. * @static
  6674. * @memberOf _
  6675. * @since 1.1.0
  6676. * @category Array
  6677. * @param {Array} array The array to inspect.
  6678. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6679. * @param {number} [fromIndex=0] The index to search from.
  6680. * @returns {number} Returns the index of the found element, else `-1`.
  6681. * @example
  6682. *
  6683. * var users = [
  6684. * { 'user': 'barney', 'active': false },
  6685. * { 'user': 'fred', 'active': false },
  6686. * { 'user': 'pebbles', 'active': true }
  6687. * ];
  6688. *
  6689. * _.findIndex(users, function(o) { return o.user == 'barney'; });
  6690. * // => 0
  6691. *
  6692. * // The `_.matches` iteratee shorthand.
  6693. * _.findIndex(users, { 'user': 'fred', 'active': false });
  6694. * // => 1
  6695. *
  6696. * // The `_.matchesProperty` iteratee shorthand.
  6697. * _.findIndex(users, ['active', false]);
  6698. * // => 0
  6699. *
  6700. * // The `_.property` iteratee shorthand.
  6701. * _.findIndex(users, 'active');
  6702. * // => 2
  6703. */
  6704. function findIndex(array, predicate, fromIndex) {
  6705. var length = array == null ? 0 : array.length;
  6706. if (!length) {
  6707. return -1;
  6708. }
  6709. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6710. if (index < 0) {
  6711. index = nativeMax(length + index, 0);
  6712. }
  6713. return baseFindIndex(array, getIteratee(predicate, 3), index);
  6714. }
  6715. /**
  6716. * This method is like `_.findIndex` except that it iterates over elements
  6717. * of `collection` from right to left.
  6718. *
  6719. * @static
  6720. * @memberOf _
  6721. * @since 2.0.0
  6722. * @category Array
  6723. * @param {Array} array The array to inspect.
  6724. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  6725. * @param {number} [fromIndex=array.length-1] The index to search from.
  6726. * @returns {number} Returns the index of the found element, else `-1`.
  6727. * @example
  6728. *
  6729. * var users = [
  6730. * { 'user': 'barney', 'active': true },
  6731. * { 'user': 'fred', 'active': false },
  6732. * { 'user': 'pebbles', 'active': false }
  6733. * ];
  6734. *
  6735. * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; });
  6736. * // => 2
  6737. *
  6738. * // The `_.matches` iteratee shorthand.
  6739. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  6740. * // => 0
  6741. *
  6742. * // The `_.matchesProperty` iteratee shorthand.
  6743. * _.findLastIndex(users, ['active', false]);
  6744. * // => 2
  6745. *
  6746. * // The `_.property` iteratee shorthand.
  6747. * _.findLastIndex(users, 'active');
  6748. * // => 0
  6749. */
  6750. function findLastIndex(array, predicate, fromIndex) {
  6751. var length = array == null ? 0 : array.length;
  6752. if (!length) {
  6753. return -1;
  6754. }
  6755. var index = length - 1;
  6756. if (fromIndex !== undefined) {
  6757. index = toInteger(fromIndex);
  6758. index = fromIndex < 0
  6759. ? nativeMax(length + index, 0)
  6760. : nativeMin(index, length - 1);
  6761. }
  6762. return baseFindIndex(array, getIteratee(predicate, 3), index, true);
  6763. }
  6764. /**
  6765. * Flattens `array` a single level deep.
  6766. *
  6767. * @static
  6768. * @memberOf _
  6769. * @since 0.1.0
  6770. * @category Array
  6771. * @param {Array} array The array to flatten.
  6772. * @returns {Array} Returns the new flattened array.
  6773. * @example
  6774. *
  6775. * _.flatten([1, [2, [3, [4]], 5]]);
  6776. * // => [1, 2, [3, [4]], 5]
  6777. */
  6778. function flatten(array) {
  6779. var length = array == null ? 0 : array.length;
  6780. return length ? baseFlatten(array, 1) : [];
  6781. }
  6782. /**
  6783. * Recursively flattens `array`.
  6784. *
  6785. * @static
  6786. * @memberOf _
  6787. * @since 3.0.0
  6788. * @category Array
  6789. * @param {Array} array The array to flatten.
  6790. * @returns {Array} Returns the new flattened array.
  6791. * @example
  6792. *
  6793. * _.flattenDeep([1, [2, [3, [4]], 5]]);
  6794. * // => [1, 2, 3, 4, 5]
  6795. */
  6796. function flattenDeep(array) {
  6797. var length = array == null ? 0 : array.length;
  6798. return length ? baseFlatten(array, INFINITY) : [];
  6799. }
  6800. /**
  6801. * Recursively flatten `array` up to `depth` times.
  6802. *
  6803. * @static
  6804. * @memberOf _
  6805. * @since 4.4.0
  6806. * @category Array
  6807. * @param {Array} array The array to flatten.
  6808. * @param {number} [depth=1] The maximum recursion depth.
  6809. * @returns {Array} Returns the new flattened array.
  6810. * @example
  6811. *
  6812. * var array = [1, [2, [3, [4]], 5]];
  6813. *
  6814. * _.flattenDepth(array, 1);
  6815. * // => [1, 2, [3, [4]], 5]
  6816. *
  6817. * _.flattenDepth(array, 2);
  6818. * // => [1, 2, 3, [4], 5]
  6819. */
  6820. function flattenDepth(array, depth) {
  6821. var length = array == null ? 0 : array.length;
  6822. if (!length) {
  6823. return [];
  6824. }
  6825. depth = depth === undefined ? 1 : toInteger(depth);
  6826. return baseFlatten(array, depth);
  6827. }
  6828. /**
  6829. * The inverse of `_.toPairs`; this method returns an object composed
  6830. * from key-value `pairs`.
  6831. *
  6832. * @static
  6833. * @memberOf _
  6834. * @since 4.0.0
  6835. * @category Array
  6836. * @param {Array} pairs The key-value pairs.
  6837. * @returns {Object} Returns the new object.
  6838. * @example
  6839. *
  6840. * _.fromPairs([['a', 1], ['b', 2]]);
  6841. * // => { 'a': 1, 'b': 2 }
  6842. */
  6843. function fromPairs(pairs) {
  6844. var index = -1,
  6845. length = pairs == null ? 0 : pairs.length,
  6846. result = {};
  6847. while (++index < length) {
  6848. var pair = pairs[index];
  6849. result[pair[0]] = pair[1];
  6850. }
  6851. return result;
  6852. }
  6853. /**
  6854. * Gets the first element of `array`.
  6855. *
  6856. * @static
  6857. * @memberOf _
  6858. * @since 0.1.0
  6859. * @alias first
  6860. * @category Array
  6861. * @param {Array} array The array to query.
  6862. * @returns {*} Returns the first element of `array`.
  6863. * @example
  6864. *
  6865. * _.head([1, 2, 3]);
  6866. * // => 1
  6867. *
  6868. * _.head([]);
  6869. * // => undefined
  6870. */
  6871. function head(array) {
  6872. return (array && array.length) ? array[0] : undefined;
  6873. }
  6874. /**
  6875. * Gets the index at which the first occurrence of `value` is found in `array`
  6876. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6877. * for equality comparisons. If `fromIndex` is negative, it's used as the
  6878. * offset from the end of `array`.
  6879. *
  6880. * @static
  6881. * @memberOf _
  6882. * @since 0.1.0
  6883. * @category Array
  6884. * @param {Array} array The array to inspect.
  6885. * @param {*} value The value to search for.
  6886. * @param {number} [fromIndex=0] The index to search from.
  6887. * @returns {number} Returns the index of the matched value, else `-1`.
  6888. * @example
  6889. *
  6890. * _.indexOf([1, 2, 1, 2], 2);
  6891. * // => 1
  6892. *
  6893. * // Search from the `fromIndex`.
  6894. * _.indexOf([1, 2, 1, 2], 2, 2);
  6895. * // => 3
  6896. */
  6897. function indexOf(array, value, fromIndex) {
  6898. var length = array == null ? 0 : array.length;
  6899. if (!length) {
  6900. return -1;
  6901. }
  6902. var index = fromIndex == null ? 0 : toInteger(fromIndex);
  6903. if (index < 0) {
  6904. index = nativeMax(length + index, 0);
  6905. }
  6906. return baseIndexOf(array, value, index);
  6907. }
  6908. /**
  6909. * Gets all but the last element of `array`.
  6910. *
  6911. * @static
  6912. * @memberOf _
  6913. * @since 0.1.0
  6914. * @category Array
  6915. * @param {Array} array The array to query.
  6916. * @returns {Array} Returns the slice of `array`.
  6917. * @example
  6918. *
  6919. * _.initial([1, 2, 3]);
  6920. * // => [1, 2]
  6921. */
  6922. function initial(array) {
  6923. var length = array == null ? 0 : array.length;
  6924. return length ? baseSlice(array, 0, -1) : [];
  6925. }
  6926. /**
  6927. * Creates an array of unique values that are included in all given arrays
  6928. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  6929. * for equality comparisons. The order and references of result values are
  6930. * determined by the first array.
  6931. *
  6932. * @static
  6933. * @memberOf _
  6934. * @since 0.1.0
  6935. * @category Array
  6936. * @param {...Array} [arrays] The arrays to inspect.
  6937. * @returns {Array} Returns the new array of intersecting values.
  6938. * @example
  6939. *
  6940. * _.intersection([2, 1], [2, 3]);
  6941. * // => [2]
  6942. */
  6943. var intersection = baseRest(function(arrays) {
  6944. var mapped = arrayMap(arrays, castArrayLikeObject);
  6945. return (mapped.length && mapped[0] === arrays[0])
  6946. ? baseIntersection(mapped)
  6947. : [];
  6948. });
  6949. /**
  6950. * This method is like `_.intersection` except that it accepts `iteratee`
  6951. * which is invoked for each element of each `arrays` to generate the criterion
  6952. * by which they're compared. The order and references of result values are
  6953. * determined by the first array. The iteratee is invoked with one argument:
  6954. * (value).
  6955. *
  6956. * @static
  6957. * @memberOf _
  6958. * @since 4.0.0
  6959. * @category Array
  6960. * @param {...Array} [arrays] The arrays to inspect.
  6961. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  6962. * @returns {Array} Returns the new array of intersecting values.
  6963. * @example
  6964. *
  6965. * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  6966. * // => [2.1]
  6967. *
  6968. * // The `_.property` iteratee shorthand.
  6969. * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  6970. * // => [{ 'x': 1 }]
  6971. */
  6972. var intersectionBy = baseRest(function(arrays) {
  6973. var iteratee = last(arrays),
  6974. mapped = arrayMap(arrays, castArrayLikeObject);
  6975. if (iteratee === last(mapped)) {
  6976. iteratee = undefined;
  6977. } else {
  6978. mapped.pop();
  6979. }
  6980. return (mapped.length && mapped[0] === arrays[0])
  6981. ? baseIntersection(mapped, getIteratee(iteratee, 2))
  6982. : [];
  6983. });
  6984. /**
  6985. * This method is like `_.intersection` except that it accepts `comparator`
  6986. * which is invoked to compare elements of `arrays`. The order and references
  6987. * of result values are determined by the first array. The comparator is
  6988. * invoked with two arguments: (arrVal, othVal).
  6989. *
  6990. * @static
  6991. * @memberOf _
  6992. * @since 4.0.0
  6993. * @category Array
  6994. * @param {...Array} [arrays] The arrays to inspect.
  6995. * @param {Function} [comparator] The comparator invoked per element.
  6996. * @returns {Array} Returns the new array of intersecting values.
  6997. * @example
  6998. *
  6999. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7000. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7001. *
  7002. * _.intersectionWith(objects, others, _.isEqual);
  7003. * // => [{ 'x': 1, 'y': 2 }]
  7004. */
  7005. var intersectionWith = baseRest(function(arrays) {
  7006. var comparator = last(arrays),
  7007. mapped = arrayMap(arrays, castArrayLikeObject);
  7008. comparator = typeof comparator == 'function' ? comparator : undefined;
  7009. if (comparator) {
  7010. mapped.pop();
  7011. }
  7012. return (mapped.length && mapped[0] === arrays[0])
  7013. ? baseIntersection(mapped, undefined, comparator)
  7014. : [];
  7015. });
  7016. /**
  7017. * Converts all elements in `array` into a string separated by `separator`.
  7018. *
  7019. * @static
  7020. * @memberOf _
  7021. * @since 4.0.0
  7022. * @category Array
  7023. * @param {Array} array The array to convert.
  7024. * @param {string} [separator=','] The element separator.
  7025. * @returns {string} Returns the joined string.
  7026. * @example
  7027. *
  7028. * _.join(['a', 'b', 'c'], '~');
  7029. * // => 'a~b~c'
  7030. */
  7031. function join(array, separator) {
  7032. return array == null ? '' : nativeJoin.call(array, separator);
  7033. }
  7034. /**
  7035. * Gets the last element of `array`.
  7036. *
  7037. * @static
  7038. * @memberOf _
  7039. * @since 0.1.0
  7040. * @category Array
  7041. * @param {Array} array The array to query.
  7042. * @returns {*} Returns the last element of `array`.
  7043. * @example
  7044. *
  7045. * _.last([1, 2, 3]);
  7046. * // => 3
  7047. */
  7048. function last(array) {
  7049. var length = array == null ? 0 : array.length;
  7050. return length ? array[length - 1] : undefined;
  7051. }
  7052. /**
  7053. * This method is like `_.indexOf` except that it iterates over elements of
  7054. * `array` from right to left.
  7055. *
  7056. * @static
  7057. * @memberOf _
  7058. * @since 0.1.0
  7059. * @category Array
  7060. * @param {Array} array The array to inspect.
  7061. * @param {*} value The value to search for.
  7062. * @param {number} [fromIndex=array.length-1] The index to search from.
  7063. * @returns {number} Returns the index of the matched value, else `-1`.
  7064. * @example
  7065. *
  7066. * _.lastIndexOf([1, 2, 1, 2], 2);
  7067. * // => 3
  7068. *
  7069. * // Search from the `fromIndex`.
  7070. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  7071. * // => 1
  7072. */
  7073. function lastIndexOf(array, value, fromIndex) {
  7074. var length = array == null ? 0 : array.length;
  7075. if (!length) {
  7076. return -1;
  7077. }
  7078. var index = length;
  7079. if (fromIndex !== undefined) {
  7080. index = toInteger(fromIndex);
  7081. index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1);
  7082. }
  7083. return value === value
  7084. ? strictLastIndexOf(array, value, index)
  7085. : baseFindIndex(array, baseIsNaN, index, true);
  7086. }
  7087. /**
  7088. * Gets the element at index `n` of `array`. If `n` is negative, the nth
  7089. * element from the end is returned.
  7090. *
  7091. * @static
  7092. * @memberOf _
  7093. * @since 4.11.0
  7094. * @category Array
  7095. * @param {Array} array The array to query.
  7096. * @param {number} [n=0] The index of the element to return.
  7097. * @returns {*} Returns the nth element of `array`.
  7098. * @example
  7099. *
  7100. * var array = ['a', 'b', 'c', 'd'];
  7101. *
  7102. * _.nth(array, 1);
  7103. * // => 'b'
  7104. *
  7105. * _.nth(array, -2);
  7106. * // => 'c';
  7107. */
  7108. function nth(array, n) {
  7109. return (array && array.length) ? baseNth(array, toInteger(n)) : undefined;
  7110. }
  7111. /**
  7112. * Removes all given values from `array` using
  7113. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7114. * for equality comparisons.
  7115. *
  7116. * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove`
  7117. * to remove elements from an array by predicate.
  7118. *
  7119. * @static
  7120. * @memberOf _
  7121. * @since 2.0.0
  7122. * @category Array
  7123. * @param {Array} array The array to modify.
  7124. * @param {...*} [values] The values to remove.
  7125. * @returns {Array} Returns `array`.
  7126. * @example
  7127. *
  7128. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7129. *
  7130. * _.pull(array, 'a', 'c');
  7131. * console.log(array);
  7132. * // => ['b', 'b']
  7133. */
  7134. var pull = baseRest(pullAll);
  7135. /**
  7136. * This method is like `_.pull` except that it accepts an array of values to remove.
  7137. *
  7138. * **Note:** Unlike `_.difference`, this method mutates `array`.
  7139. *
  7140. * @static
  7141. * @memberOf _
  7142. * @since 4.0.0
  7143. * @category Array
  7144. * @param {Array} array The array to modify.
  7145. * @param {Array} values The values to remove.
  7146. * @returns {Array} Returns `array`.
  7147. * @example
  7148. *
  7149. * var array = ['a', 'b', 'c', 'a', 'b', 'c'];
  7150. *
  7151. * _.pullAll(array, ['a', 'c']);
  7152. * console.log(array);
  7153. * // => ['b', 'b']
  7154. */
  7155. function pullAll(array, values) {
  7156. return (array && array.length && values && values.length)
  7157. ? basePullAll(array, values)
  7158. : array;
  7159. }
  7160. /**
  7161. * This method is like `_.pullAll` except that it accepts `iteratee` which is
  7162. * invoked for each element of `array` and `values` to generate the criterion
  7163. * by which they're compared. The iteratee is invoked with one argument: (value).
  7164. *
  7165. * **Note:** Unlike `_.differenceBy`, this method mutates `array`.
  7166. *
  7167. * @static
  7168. * @memberOf _
  7169. * @since 4.0.0
  7170. * @category Array
  7171. * @param {Array} array The array to modify.
  7172. * @param {Array} values The values to remove.
  7173. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7174. * @returns {Array} Returns `array`.
  7175. * @example
  7176. *
  7177. * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }];
  7178. *
  7179. * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x');
  7180. * console.log(array);
  7181. * // => [{ 'x': 2 }]
  7182. */
  7183. function pullAllBy(array, values, iteratee) {
  7184. return (array && array.length && values && values.length)
  7185. ? basePullAll(array, values, getIteratee(iteratee, 2))
  7186. : array;
  7187. }
  7188. /**
  7189. * This method is like `_.pullAll` except that it accepts `comparator` which
  7190. * is invoked to compare elements of `array` to `values`. The comparator is
  7191. * invoked with two arguments: (arrVal, othVal).
  7192. *
  7193. * **Note:** Unlike `_.differenceWith`, this method mutates `array`.
  7194. *
  7195. * @static
  7196. * @memberOf _
  7197. * @since 4.6.0
  7198. * @category Array
  7199. * @param {Array} array The array to modify.
  7200. * @param {Array} values The values to remove.
  7201. * @param {Function} [comparator] The comparator invoked per element.
  7202. * @returns {Array} Returns `array`.
  7203. * @example
  7204. *
  7205. * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }];
  7206. *
  7207. * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual);
  7208. * console.log(array);
  7209. * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }]
  7210. */
  7211. function pullAllWith(array, values, comparator) {
  7212. return (array && array.length && values && values.length)
  7213. ? basePullAll(array, values, undefined, comparator)
  7214. : array;
  7215. }
  7216. /**
  7217. * Removes elements from `array` corresponding to `indexes` and returns an
  7218. * array of removed elements.
  7219. *
  7220. * **Note:** Unlike `_.at`, this method mutates `array`.
  7221. *
  7222. * @static
  7223. * @memberOf _
  7224. * @since 3.0.0
  7225. * @category Array
  7226. * @param {Array} array The array to modify.
  7227. * @param {...(number|number[])} [indexes] The indexes of elements to remove.
  7228. * @returns {Array} Returns the new array of removed elements.
  7229. * @example
  7230. *
  7231. * var array = ['a', 'b', 'c', 'd'];
  7232. * var pulled = _.pullAt(array, [1, 3]);
  7233. *
  7234. * console.log(array);
  7235. * // => ['a', 'c']
  7236. *
  7237. * console.log(pulled);
  7238. * // => ['b', 'd']
  7239. */
  7240. var pullAt = flatRest(function(array, indexes) {
  7241. var length = array == null ? 0 : array.length,
  7242. result = baseAt(array, indexes);
  7243. basePullAt(array, arrayMap(indexes, function(index) {
  7244. return isIndex(index, length) ? +index : index;
  7245. }).sort(compareAscending));
  7246. return result;
  7247. });
  7248. /**
  7249. * Removes all elements from `array` that `predicate` returns truthy for
  7250. * and returns an array of the removed elements. The predicate is invoked
  7251. * with three arguments: (value, index, array).
  7252. *
  7253. * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull`
  7254. * to pull elements from an array by value.
  7255. *
  7256. * @static
  7257. * @memberOf _
  7258. * @since 2.0.0
  7259. * @category Array
  7260. * @param {Array} array The array to modify.
  7261. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7262. * @returns {Array} Returns the new array of removed elements.
  7263. * @example
  7264. *
  7265. * var array = [1, 2, 3, 4];
  7266. * var evens = _.remove(array, function(n) {
  7267. * return n % 2 == 0;
  7268. * });
  7269. *
  7270. * console.log(array);
  7271. * // => [1, 3]
  7272. *
  7273. * console.log(evens);
  7274. * // => [2, 4]
  7275. */
  7276. function remove(array, predicate) {
  7277. var result = [];
  7278. if (!(array && array.length)) {
  7279. return result;
  7280. }
  7281. var index = -1,
  7282. indexes = [],
  7283. length = array.length;
  7284. predicate = getIteratee(predicate, 3);
  7285. while (++index < length) {
  7286. var value = array[index];
  7287. if (predicate(value, index, array)) {
  7288. result.push(value);
  7289. indexes.push(index);
  7290. }
  7291. }
  7292. basePullAt(array, indexes);
  7293. return result;
  7294. }
  7295. /**
  7296. * Reverses `array` so that the first element becomes the last, the second
  7297. * element becomes the second to last, and so on.
  7298. *
  7299. * **Note:** This method mutates `array` and is based on
  7300. * [`Array#reverse`](https://mdn.io/Array/reverse).
  7301. *
  7302. * @static
  7303. * @memberOf _
  7304. * @since 4.0.0
  7305. * @category Array
  7306. * @param {Array} array The array to modify.
  7307. * @returns {Array} Returns `array`.
  7308. * @example
  7309. *
  7310. * var array = [1, 2, 3];
  7311. *
  7312. * _.reverse(array);
  7313. * // => [3, 2, 1]
  7314. *
  7315. * console.log(array);
  7316. * // => [3, 2, 1]
  7317. */
  7318. function reverse(array) {
  7319. return array == null ? array : nativeReverse.call(array);
  7320. }
  7321. /**
  7322. * Creates a slice of `array` from `start` up to, but not including, `end`.
  7323. *
  7324. * **Note:** This method is used instead of
  7325. * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are
  7326. * returned.
  7327. *
  7328. * @static
  7329. * @memberOf _
  7330. * @since 3.0.0
  7331. * @category Array
  7332. * @param {Array} array The array to slice.
  7333. * @param {number} [start=0] The start position.
  7334. * @param {number} [end=array.length] The end position.
  7335. * @returns {Array} Returns the slice of `array`.
  7336. */
  7337. function slice(array, start, end) {
  7338. var length = array == null ? 0 : array.length;
  7339. if (!length) {
  7340. return [];
  7341. }
  7342. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  7343. start = 0;
  7344. end = length;
  7345. }
  7346. else {
  7347. start = start == null ? 0 : toInteger(start);
  7348. end = end === undefined ? length : toInteger(end);
  7349. }
  7350. return baseSlice(array, start, end);
  7351. }
  7352. /**
  7353. * Uses a binary search to determine the lowest index at which `value`
  7354. * should be inserted into `array` in order to maintain its sort order.
  7355. *
  7356. * @static
  7357. * @memberOf _
  7358. * @since 0.1.0
  7359. * @category Array
  7360. * @param {Array} array The sorted array to inspect.
  7361. * @param {*} value The value to evaluate.
  7362. * @returns {number} Returns the index at which `value` should be inserted
  7363. * into `array`.
  7364. * @example
  7365. *
  7366. * _.sortedIndex([30, 50], 40);
  7367. * // => 1
  7368. */
  7369. function sortedIndex(array, value) {
  7370. return baseSortedIndex(array, value);
  7371. }
  7372. /**
  7373. * This method is like `_.sortedIndex` except that it accepts `iteratee`
  7374. * which is invoked for `value` and each element of `array` to compute their
  7375. * sort ranking. The iteratee is invoked with one argument: (value).
  7376. *
  7377. * @static
  7378. * @memberOf _
  7379. * @since 4.0.0
  7380. * @category Array
  7381. * @param {Array} array The sorted array to inspect.
  7382. * @param {*} value The value to evaluate.
  7383. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7384. * @returns {number} Returns the index at which `value` should be inserted
  7385. * into `array`.
  7386. * @example
  7387. *
  7388. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7389. *
  7390. * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7391. * // => 0
  7392. *
  7393. * // The `_.property` iteratee shorthand.
  7394. * _.sortedIndexBy(objects, { 'x': 4 }, 'x');
  7395. * // => 0
  7396. */
  7397. function sortedIndexBy(array, value, iteratee) {
  7398. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2));
  7399. }
  7400. /**
  7401. * This method is like `_.indexOf` except that it performs a binary
  7402. * search on a sorted `array`.
  7403. *
  7404. * @static
  7405. * @memberOf _
  7406. * @since 4.0.0
  7407. * @category Array
  7408. * @param {Array} array The array to inspect.
  7409. * @param {*} value The value to search for.
  7410. * @returns {number} Returns the index of the matched value, else `-1`.
  7411. * @example
  7412. *
  7413. * _.sortedIndexOf([4, 5, 5, 5, 6], 5);
  7414. * // => 1
  7415. */
  7416. function sortedIndexOf(array, value) {
  7417. var length = array == null ? 0 : array.length;
  7418. if (length) {
  7419. var index = baseSortedIndex(array, value);
  7420. if (index < length && eq(array[index], value)) {
  7421. return index;
  7422. }
  7423. }
  7424. return -1;
  7425. }
  7426. /**
  7427. * This method is like `_.sortedIndex` except that it returns the highest
  7428. * index at which `value` should be inserted into `array` in order to
  7429. * maintain its sort order.
  7430. *
  7431. * @static
  7432. * @memberOf _
  7433. * @since 3.0.0
  7434. * @category Array
  7435. * @param {Array} array The sorted array to inspect.
  7436. * @param {*} value The value to evaluate.
  7437. * @returns {number} Returns the index at which `value` should be inserted
  7438. * into `array`.
  7439. * @example
  7440. *
  7441. * _.sortedLastIndex([4, 5, 5, 5, 6], 5);
  7442. * // => 4
  7443. */
  7444. function sortedLastIndex(array, value) {
  7445. return baseSortedIndex(array, value, true);
  7446. }
  7447. /**
  7448. * This method is like `_.sortedLastIndex` except that it accepts `iteratee`
  7449. * which is invoked for `value` and each element of `array` to compute their
  7450. * sort ranking. The iteratee is invoked with one argument: (value).
  7451. *
  7452. * @static
  7453. * @memberOf _
  7454. * @since 4.0.0
  7455. * @category Array
  7456. * @param {Array} array The sorted array to inspect.
  7457. * @param {*} value The value to evaluate.
  7458. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7459. * @returns {number} Returns the index at which `value` should be inserted
  7460. * into `array`.
  7461. * @example
  7462. *
  7463. * var objects = [{ 'x': 4 }, { 'x': 5 }];
  7464. *
  7465. * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; });
  7466. * // => 1
  7467. *
  7468. * // The `_.property` iteratee shorthand.
  7469. * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x');
  7470. * // => 1
  7471. */
  7472. function sortedLastIndexBy(array, value, iteratee) {
  7473. return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true);
  7474. }
  7475. /**
  7476. * This method is like `_.lastIndexOf` except that it performs a binary
  7477. * search on a sorted `array`.
  7478. *
  7479. * @static
  7480. * @memberOf _
  7481. * @since 4.0.0
  7482. * @category Array
  7483. * @param {Array} array The array to inspect.
  7484. * @param {*} value The value to search for.
  7485. * @returns {number} Returns the index of the matched value, else `-1`.
  7486. * @example
  7487. *
  7488. * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5);
  7489. * // => 3
  7490. */
  7491. function sortedLastIndexOf(array, value) {
  7492. var length = array == null ? 0 : array.length;
  7493. if (length) {
  7494. var index = baseSortedIndex(array, value, true) - 1;
  7495. if (eq(array[index], value)) {
  7496. return index;
  7497. }
  7498. }
  7499. return -1;
  7500. }
  7501. /**
  7502. * This method is like `_.uniq` except that it's designed and optimized
  7503. * for sorted arrays.
  7504. *
  7505. * @static
  7506. * @memberOf _
  7507. * @since 4.0.0
  7508. * @category Array
  7509. * @param {Array} array The array to inspect.
  7510. * @returns {Array} Returns the new duplicate free array.
  7511. * @example
  7512. *
  7513. * _.sortedUniq([1, 1, 2]);
  7514. * // => [1, 2]
  7515. */
  7516. function sortedUniq(array) {
  7517. return (array && array.length)
  7518. ? baseSortedUniq(array)
  7519. : [];
  7520. }
  7521. /**
  7522. * This method is like `_.uniqBy` except that it's designed and optimized
  7523. * for sorted arrays.
  7524. *
  7525. * @static
  7526. * @memberOf _
  7527. * @since 4.0.0
  7528. * @category Array
  7529. * @param {Array} array The array to inspect.
  7530. * @param {Function} [iteratee] The iteratee invoked per element.
  7531. * @returns {Array} Returns the new duplicate free array.
  7532. * @example
  7533. *
  7534. * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor);
  7535. * // => [1.1, 2.3]
  7536. */
  7537. function sortedUniqBy(array, iteratee) {
  7538. return (array && array.length)
  7539. ? baseSortedUniq(array, getIteratee(iteratee, 2))
  7540. : [];
  7541. }
  7542. /**
  7543. * Gets all but the first element of `array`.
  7544. *
  7545. * @static
  7546. * @memberOf _
  7547. * @since 4.0.0
  7548. * @category Array
  7549. * @param {Array} array The array to query.
  7550. * @returns {Array} Returns the slice of `array`.
  7551. * @example
  7552. *
  7553. * _.tail([1, 2, 3]);
  7554. * // => [2, 3]
  7555. */
  7556. function tail(array) {
  7557. var length = array == null ? 0 : array.length;
  7558. return length ? baseSlice(array, 1, length) : [];
  7559. }
  7560. /**
  7561. * Creates a slice of `array` with `n` elements taken from the beginning.
  7562. *
  7563. * @static
  7564. * @memberOf _
  7565. * @since 0.1.0
  7566. * @category Array
  7567. * @param {Array} array The array to query.
  7568. * @param {number} [n=1] The number of elements to take.
  7569. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7570. * @returns {Array} Returns the slice of `array`.
  7571. * @example
  7572. *
  7573. * _.take([1, 2, 3]);
  7574. * // => [1]
  7575. *
  7576. * _.take([1, 2, 3], 2);
  7577. * // => [1, 2]
  7578. *
  7579. * _.take([1, 2, 3], 5);
  7580. * // => [1, 2, 3]
  7581. *
  7582. * _.take([1, 2, 3], 0);
  7583. * // => []
  7584. */
  7585. function take(array, n, guard) {
  7586. if (!(array && array.length)) {
  7587. return [];
  7588. }
  7589. n = (guard || n === undefined) ? 1 : toInteger(n);
  7590. return baseSlice(array, 0, n < 0 ? 0 : n);
  7591. }
  7592. /**
  7593. * Creates a slice of `array` with `n` elements taken from the end.
  7594. *
  7595. * @static
  7596. * @memberOf _
  7597. * @since 3.0.0
  7598. * @category Array
  7599. * @param {Array} array The array to query.
  7600. * @param {number} [n=1] The number of elements to take.
  7601. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  7602. * @returns {Array} Returns the slice of `array`.
  7603. * @example
  7604. *
  7605. * _.takeRight([1, 2, 3]);
  7606. * // => [3]
  7607. *
  7608. * _.takeRight([1, 2, 3], 2);
  7609. * // => [2, 3]
  7610. *
  7611. * _.takeRight([1, 2, 3], 5);
  7612. * // => [1, 2, 3]
  7613. *
  7614. * _.takeRight([1, 2, 3], 0);
  7615. * // => []
  7616. */
  7617. function takeRight(array, n, guard) {
  7618. var length = array == null ? 0 : array.length;
  7619. if (!length) {
  7620. return [];
  7621. }
  7622. n = (guard || n === undefined) ? 1 : toInteger(n);
  7623. n = length - n;
  7624. return baseSlice(array, n < 0 ? 0 : n, length);
  7625. }
  7626. /**
  7627. * Creates a slice of `array` with elements taken from the end. Elements are
  7628. * taken until `predicate` returns falsey. The predicate is invoked with
  7629. * three arguments: (value, index, array).
  7630. *
  7631. * @static
  7632. * @memberOf _
  7633. * @since 3.0.0
  7634. * @category Array
  7635. * @param {Array} array The array to query.
  7636. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7637. * @returns {Array} Returns the slice of `array`.
  7638. * @example
  7639. *
  7640. * var users = [
  7641. * { 'user': 'barney', 'active': true },
  7642. * { 'user': 'fred', 'active': false },
  7643. * { 'user': 'pebbles', 'active': false }
  7644. * ];
  7645. *
  7646. * _.takeRightWhile(users, function(o) { return !o.active; });
  7647. * // => objects for ['fred', 'pebbles']
  7648. *
  7649. * // The `_.matches` iteratee shorthand.
  7650. * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false });
  7651. * // => objects for ['pebbles']
  7652. *
  7653. * // The `_.matchesProperty` iteratee shorthand.
  7654. * _.takeRightWhile(users, ['active', false]);
  7655. * // => objects for ['fred', 'pebbles']
  7656. *
  7657. * // The `_.property` iteratee shorthand.
  7658. * _.takeRightWhile(users, 'active');
  7659. * // => []
  7660. */
  7661. function takeRightWhile(array, predicate) {
  7662. return (array && array.length)
  7663. ? baseWhile(array, getIteratee(predicate, 3), false, true)
  7664. : [];
  7665. }
  7666. /**
  7667. * Creates a slice of `array` with elements taken from the beginning. Elements
  7668. * are taken until `predicate` returns falsey. The predicate is invoked with
  7669. * three arguments: (value, index, array).
  7670. *
  7671. * @static
  7672. * @memberOf _
  7673. * @since 3.0.0
  7674. * @category Array
  7675. * @param {Array} array The array to query.
  7676. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  7677. * @returns {Array} Returns the slice of `array`.
  7678. * @example
  7679. *
  7680. * var users = [
  7681. * { 'user': 'barney', 'active': false },
  7682. * { 'user': 'fred', 'active': false },
  7683. * { 'user': 'pebbles', 'active': true }
  7684. * ];
  7685. *
  7686. * _.takeWhile(users, function(o) { return !o.active; });
  7687. * // => objects for ['barney', 'fred']
  7688. *
  7689. * // The `_.matches` iteratee shorthand.
  7690. * _.takeWhile(users, { 'user': 'barney', 'active': false });
  7691. * // => objects for ['barney']
  7692. *
  7693. * // The `_.matchesProperty` iteratee shorthand.
  7694. * _.takeWhile(users, ['active', false]);
  7695. * // => objects for ['barney', 'fred']
  7696. *
  7697. * // The `_.property` iteratee shorthand.
  7698. * _.takeWhile(users, 'active');
  7699. * // => []
  7700. */
  7701. function takeWhile(array, predicate) {
  7702. return (array && array.length)
  7703. ? baseWhile(array, getIteratee(predicate, 3))
  7704. : [];
  7705. }
  7706. /**
  7707. * Creates an array of unique values, in order, from all given arrays using
  7708. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7709. * for equality comparisons.
  7710. *
  7711. * @static
  7712. * @memberOf _
  7713. * @since 0.1.0
  7714. * @category Array
  7715. * @param {...Array} [arrays] The arrays to inspect.
  7716. * @returns {Array} Returns the new array of combined values.
  7717. * @example
  7718. *
  7719. * _.union([2], [1, 2]);
  7720. * // => [2, 1]
  7721. */
  7722. var union = baseRest(function(arrays) {
  7723. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true));
  7724. });
  7725. /**
  7726. * This method is like `_.union` except that it accepts `iteratee` which is
  7727. * invoked for each element of each `arrays` to generate the criterion by
  7728. * which uniqueness is computed. Result values are chosen from the first
  7729. * array in which the value occurs. The iteratee is invoked with one argument:
  7730. * (value).
  7731. *
  7732. * @static
  7733. * @memberOf _
  7734. * @since 4.0.0
  7735. * @category Array
  7736. * @param {...Array} [arrays] The arrays to inspect.
  7737. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7738. * @returns {Array} Returns the new array of combined values.
  7739. * @example
  7740. *
  7741. * _.unionBy([2.1], [1.2, 2.3], Math.floor);
  7742. * // => [2.1, 1.2]
  7743. *
  7744. * // The `_.property` iteratee shorthand.
  7745. * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7746. * // => [{ 'x': 1 }, { 'x': 2 }]
  7747. */
  7748. var unionBy = baseRest(function(arrays) {
  7749. var iteratee = last(arrays);
  7750. if (isArrayLikeObject(iteratee)) {
  7751. iteratee = undefined;
  7752. }
  7753. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2));
  7754. });
  7755. /**
  7756. * This method is like `_.union` except that it accepts `comparator` which
  7757. * is invoked to compare elements of `arrays`. Result values are chosen from
  7758. * the first array in which the value occurs. The comparator is invoked
  7759. * with two arguments: (arrVal, othVal).
  7760. *
  7761. * @static
  7762. * @memberOf _
  7763. * @since 4.0.0
  7764. * @category Array
  7765. * @param {...Array} [arrays] The arrays to inspect.
  7766. * @param {Function} [comparator] The comparator invoked per element.
  7767. * @returns {Array} Returns the new array of combined values.
  7768. * @example
  7769. *
  7770. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  7771. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7772. *
  7773. * _.unionWith(objects, others, _.isEqual);
  7774. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  7775. */
  7776. var unionWith = baseRest(function(arrays) {
  7777. var comparator = last(arrays);
  7778. comparator = typeof comparator == 'function' ? comparator : undefined;
  7779. return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined, comparator);
  7780. });
  7781. /**
  7782. * Creates a duplicate-free version of an array, using
  7783. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7784. * for equality comparisons, in which only the first occurrence of each element
  7785. * is kept. The order of result values is determined by the order they occur
  7786. * in the array.
  7787. *
  7788. * @static
  7789. * @memberOf _
  7790. * @since 0.1.0
  7791. * @category Array
  7792. * @param {Array} array The array to inspect.
  7793. * @returns {Array} Returns the new duplicate free array.
  7794. * @example
  7795. *
  7796. * _.uniq([2, 1, 2]);
  7797. * // => [2, 1]
  7798. */
  7799. function uniq(array) {
  7800. return (array && array.length) ? baseUniq(array) : [];
  7801. }
  7802. /**
  7803. * This method is like `_.uniq` except that it accepts `iteratee` which is
  7804. * invoked for each element in `array` to generate the criterion by which
  7805. * uniqueness is computed. The order of result values is determined by the
  7806. * order they occur in the array. The iteratee is invoked with one argument:
  7807. * (value).
  7808. *
  7809. * @static
  7810. * @memberOf _
  7811. * @since 4.0.0
  7812. * @category Array
  7813. * @param {Array} array The array to inspect.
  7814. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7815. * @returns {Array} Returns the new duplicate free array.
  7816. * @example
  7817. *
  7818. * _.uniqBy([2.1, 1.2, 2.3], Math.floor);
  7819. * // => [2.1, 1.2]
  7820. *
  7821. * // The `_.property` iteratee shorthand.
  7822. * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  7823. * // => [{ 'x': 1 }, { 'x': 2 }]
  7824. */
  7825. function uniqBy(array, iteratee) {
  7826. return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : [];
  7827. }
  7828. /**
  7829. * This method is like `_.uniq` except that it accepts `comparator` which
  7830. * is invoked to compare elements of `array`. The order of result values is
  7831. * determined by the order they occur in the array.The comparator is invoked
  7832. * with two arguments: (arrVal, othVal).
  7833. *
  7834. * @static
  7835. * @memberOf _
  7836. * @since 4.0.0
  7837. * @category Array
  7838. * @param {Array} array The array to inspect.
  7839. * @param {Function} [comparator] The comparator invoked per element.
  7840. * @returns {Array} Returns the new duplicate free array.
  7841. * @example
  7842. *
  7843. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }];
  7844. *
  7845. * _.uniqWith(objects, _.isEqual);
  7846. * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]
  7847. */
  7848. function uniqWith(array, comparator) {
  7849. comparator = typeof comparator == 'function' ? comparator : undefined;
  7850. return (array && array.length) ? baseUniq(array, undefined, comparator) : [];
  7851. }
  7852. /**
  7853. * This method is like `_.zip` except that it accepts an array of grouped
  7854. * elements and creates an array regrouping the elements to their pre-zip
  7855. * configuration.
  7856. *
  7857. * @static
  7858. * @memberOf _
  7859. * @since 1.2.0
  7860. * @category Array
  7861. * @param {Array} array The array of grouped elements to process.
  7862. * @returns {Array} Returns the new array of regrouped elements.
  7863. * @example
  7864. *
  7865. * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]);
  7866. * // => [['a', 1, true], ['b', 2, false]]
  7867. *
  7868. * _.unzip(zipped);
  7869. * // => [['a', 'b'], [1, 2], [true, false]]
  7870. */
  7871. function unzip(array) {
  7872. if (!(array && array.length)) {
  7873. return [];
  7874. }
  7875. var length = 0;
  7876. array = arrayFilter(array, function(group) {
  7877. if (isArrayLikeObject(group)) {
  7878. length = nativeMax(group.length, length);
  7879. return true;
  7880. }
  7881. });
  7882. return baseTimes(length, function(index) {
  7883. return arrayMap(array, baseProperty(index));
  7884. });
  7885. }
  7886. /**
  7887. * This method is like `_.unzip` except that it accepts `iteratee` to specify
  7888. * how regrouped values should be combined. The iteratee is invoked with the
  7889. * elements of each group: (...group).
  7890. *
  7891. * @static
  7892. * @memberOf _
  7893. * @since 3.8.0
  7894. * @category Array
  7895. * @param {Array} array The array of grouped elements to process.
  7896. * @param {Function} [iteratee=_.identity] The function to combine
  7897. * regrouped values.
  7898. * @returns {Array} Returns the new array of regrouped elements.
  7899. * @example
  7900. *
  7901. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  7902. * // => [[1, 10, 100], [2, 20, 200]]
  7903. *
  7904. * _.unzipWith(zipped, _.add);
  7905. * // => [3, 30, 300]
  7906. */
  7907. function unzipWith(array, iteratee) {
  7908. if (!(array && array.length)) {
  7909. return [];
  7910. }
  7911. var result = unzip(array);
  7912. if (iteratee == null) {
  7913. return result;
  7914. }
  7915. return arrayMap(result, function(group) {
  7916. return apply(iteratee, undefined, group);
  7917. });
  7918. }
  7919. /**
  7920. * Creates an array excluding all given values using
  7921. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  7922. * for equality comparisons.
  7923. *
  7924. * **Note:** Unlike `_.pull`, this method returns a new array.
  7925. *
  7926. * @static
  7927. * @memberOf _
  7928. * @since 0.1.0
  7929. * @category Array
  7930. * @param {Array} array The array to inspect.
  7931. * @param {...*} [values] The values to exclude.
  7932. * @returns {Array} Returns the new array of filtered values.
  7933. * @see _.difference, _.xor
  7934. * @example
  7935. *
  7936. * _.without([2, 1, 2, 3], 1, 2);
  7937. * // => [3]
  7938. */
  7939. var without = baseRest(function(array, values) {
  7940. return isArrayLikeObject(array)
  7941. ? baseDifference(array, values)
  7942. : [];
  7943. });
  7944. /**
  7945. * Creates an array of unique values that is the
  7946. * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  7947. * of the given arrays. The order of result values is determined by the order
  7948. * they occur in the arrays.
  7949. *
  7950. * @static
  7951. * @memberOf _
  7952. * @since 2.4.0
  7953. * @category Array
  7954. * @param {...Array} [arrays] The arrays to inspect.
  7955. * @returns {Array} Returns the new array of filtered values.
  7956. * @see _.difference, _.without
  7957. * @example
  7958. *
  7959. * _.xor([2, 1], [2, 3]);
  7960. * // => [1, 3]
  7961. */
  7962. var xor = baseRest(function(arrays) {
  7963. return baseXor(arrayFilter(arrays, isArrayLikeObject));
  7964. });
  7965. /**
  7966. * This method is like `_.xor` except that it accepts `iteratee` which is
  7967. * invoked for each element of each `arrays` to generate the criterion by
  7968. * which by which they're compared. The order of result values is determined
  7969. * by the order they occur in the arrays. The iteratee is invoked with one
  7970. * argument: (value).
  7971. *
  7972. * @static
  7973. * @memberOf _
  7974. * @since 4.0.0
  7975. * @category Array
  7976. * @param {...Array} [arrays] The arrays to inspect.
  7977. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  7978. * @returns {Array} Returns the new array of filtered values.
  7979. * @example
  7980. *
  7981. * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor);
  7982. * // => [1.2, 3.4]
  7983. *
  7984. * // The `_.property` iteratee shorthand.
  7985. * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x');
  7986. * // => [{ 'x': 2 }]
  7987. */
  7988. var xorBy = baseRest(function(arrays) {
  7989. var iteratee = last(arrays);
  7990. if (isArrayLikeObject(iteratee)) {
  7991. iteratee = undefined;
  7992. }
  7993. return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2));
  7994. });
  7995. /**
  7996. * This method is like `_.xor` except that it accepts `comparator` which is
  7997. * invoked to compare elements of `arrays`. The order of result values is
  7998. * determined by the order they occur in the arrays. The comparator is invoked
  7999. * with two arguments: (arrVal, othVal).
  8000. *
  8001. * @static
  8002. * @memberOf _
  8003. * @since 4.0.0
  8004. * @category Array
  8005. * @param {...Array} [arrays] The arrays to inspect.
  8006. * @param {Function} [comparator] The comparator invoked per element.
  8007. * @returns {Array} Returns the new array of filtered values.
  8008. * @example
  8009. *
  8010. * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }];
  8011. * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }];
  8012. *
  8013. * _.xorWith(objects, others, _.isEqual);
  8014. * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }]
  8015. */
  8016. var xorWith = baseRest(function(arrays) {
  8017. var comparator = last(arrays);
  8018. comparator = typeof comparator == 'function' ? comparator : undefined;
  8019. return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined, comparator);
  8020. });
  8021. /**
  8022. * Creates an array of grouped elements, the first of which contains the
  8023. * first elements of the given arrays, the second of which contains the
  8024. * second elements of the given arrays, and so on.
  8025. *
  8026. * @static
  8027. * @memberOf _
  8028. * @since 0.1.0
  8029. * @category Array
  8030. * @param {...Array} [arrays] The arrays to process.
  8031. * @returns {Array} Returns the new array of grouped elements.
  8032. * @example
  8033. *
  8034. * _.zip(['a', 'b'], [1, 2], [true, false]);
  8035. * // => [['a', 1, true], ['b', 2, false]]
  8036. */
  8037. var zip = baseRest(unzip);
  8038. /**
  8039. * This method is like `_.fromPairs` except that it accepts two arrays,
  8040. * one of property identifiers and one of corresponding values.
  8041. *
  8042. * @static
  8043. * @memberOf _
  8044. * @since 0.4.0
  8045. * @category Array
  8046. * @param {Array} [props=[]] The property identifiers.
  8047. * @param {Array} [values=[]] The property values.
  8048. * @returns {Object} Returns the new object.
  8049. * @example
  8050. *
  8051. * _.zipObject(['a', 'b'], [1, 2]);
  8052. * // => { 'a': 1, 'b': 2 }
  8053. */
  8054. function zipObject(props, values) {
  8055. return baseZipObject(props || [], values || [], assignValue);
  8056. }
  8057. /**
  8058. * This method is like `_.zipObject` except that it supports property paths.
  8059. *
  8060. * @static
  8061. * @memberOf _
  8062. * @since 4.1.0
  8063. * @category Array
  8064. * @param {Array} [props=[]] The property identifiers.
  8065. * @param {Array} [values=[]] The property values.
  8066. * @returns {Object} Returns the new object.
  8067. * @example
  8068. *
  8069. * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]);
  8070. * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } }
  8071. */
  8072. function zipObjectDeep(props, values) {
  8073. return baseZipObject(props || [], values || [], baseSet);
  8074. }
  8075. /**
  8076. * This method is like `_.zip` except that it accepts `iteratee` to specify
  8077. * how grouped values should be combined. The iteratee is invoked with the
  8078. * elements of each group: (...group).
  8079. *
  8080. * @static
  8081. * @memberOf _
  8082. * @since 3.8.0
  8083. * @category Array
  8084. * @param {...Array} [arrays] The arrays to process.
  8085. * @param {Function} [iteratee=_.identity] The function to combine
  8086. * grouped values.
  8087. * @returns {Array} Returns the new array of grouped elements.
  8088. * @example
  8089. *
  8090. * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) {
  8091. * return a + b + c;
  8092. * });
  8093. * // => [111, 222]
  8094. */
  8095. var zipWith = baseRest(function(arrays) {
  8096. var length = arrays.length,
  8097. iteratee = length > 1 ? arrays[length - 1] : undefined;
  8098. iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined;
  8099. return unzipWith(arrays, iteratee);
  8100. });
  8101. /*------------------------------------------------------------------------*/
  8102. /**
  8103. * Creates a `lodash` wrapper instance that wraps `value` with explicit method
  8104. * chain sequences enabled. The result of such sequences must be unwrapped
  8105. * with `_#value`.
  8106. *
  8107. * @static
  8108. * @memberOf _
  8109. * @since 1.3.0
  8110. * @category Seq
  8111. * @param {*} value The value to wrap.
  8112. * @returns {Object} Returns the new `lodash` wrapper instance.
  8113. * @example
  8114. *
  8115. * var users = [
  8116. * { 'user': 'barney', 'age': 36 },
  8117. * { 'user': 'fred', 'age': 40 },
  8118. * { 'user': 'pebbles', 'age': 1 }
  8119. * ];
  8120. *
  8121. * var youngest = _
  8122. * .chain(users)
  8123. * .sortBy('age')
  8124. * .map(function(o) {
  8125. * return o.user + ' is ' + o.age;
  8126. * })
  8127. * .head()
  8128. * .value();
  8129. * // => 'pebbles is 1'
  8130. */
  8131. function chain(value) {
  8132. var result = lodash(value);
  8133. result.__chain__ = true;
  8134. return result;
  8135. }
  8136. /**
  8137. * This method invokes `interceptor` and returns `value`. The interceptor
  8138. * is invoked with one argument; (value). The purpose of this method is to
  8139. * "tap into" a method chain sequence in order to modify intermediate results.
  8140. *
  8141. * @static
  8142. * @memberOf _
  8143. * @since 0.1.0
  8144. * @category Seq
  8145. * @param {*} value The value to provide to `interceptor`.
  8146. * @param {Function} interceptor The function to invoke.
  8147. * @returns {*} Returns `value`.
  8148. * @example
  8149. *
  8150. * _([1, 2, 3])
  8151. * .tap(function(array) {
  8152. * // Mutate input array.
  8153. * array.pop();
  8154. * })
  8155. * .reverse()
  8156. * .value();
  8157. * // => [2, 1]
  8158. */
  8159. function tap(value, interceptor) {
  8160. interceptor(value);
  8161. return value;
  8162. }
  8163. /**
  8164. * This method is like `_.tap` except that it returns the result of `interceptor`.
  8165. * The purpose of this method is to "pass thru" values replacing intermediate
  8166. * results in a method chain sequence.
  8167. *
  8168. * @static
  8169. * @memberOf _
  8170. * @since 3.0.0
  8171. * @category Seq
  8172. * @param {*} value The value to provide to `interceptor`.
  8173. * @param {Function} interceptor The function to invoke.
  8174. * @returns {*} Returns the result of `interceptor`.
  8175. * @example
  8176. *
  8177. * _(' abc ')
  8178. * .chain()
  8179. * .trim()
  8180. * .thru(function(value) {
  8181. * return [value];
  8182. * })
  8183. * .value();
  8184. * // => ['abc']
  8185. */
  8186. function thru(value, interceptor) {
  8187. return interceptor(value);
  8188. }
  8189. /**
  8190. * This method is the wrapper version of `_.at`.
  8191. *
  8192. * @name at
  8193. * @memberOf _
  8194. * @since 1.0.0
  8195. * @category Seq
  8196. * @param {...(string|string[])} [paths] The property paths to pick.
  8197. * @returns {Object} Returns the new `lodash` wrapper instance.
  8198. * @example
  8199. *
  8200. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  8201. *
  8202. * _(object).at(['a[0].b.c', 'a[1]']).value();
  8203. * // => [3, 4]
  8204. */
  8205. var wrapperAt = flatRest(function(paths) {
  8206. var length = paths.length,
  8207. start = length ? paths[0] : 0,
  8208. value = this.__wrapped__,
  8209. interceptor = function(object) { return baseAt(object, paths); };
  8210. if (length > 1 || this.__actions__.length ||
  8211. !(value instanceof LazyWrapper) || !isIndex(start)) {
  8212. return this.thru(interceptor);
  8213. }
  8214. value = value.slice(start, +start + (length ? 1 : 0));
  8215. value.__actions__.push({
  8216. 'func': thru,
  8217. 'args': [interceptor],
  8218. 'thisArg': undefined
  8219. });
  8220. return new LodashWrapper(value, this.__chain__).thru(function(array) {
  8221. if (length && !array.length) {
  8222. array.push(undefined);
  8223. }
  8224. return array;
  8225. });
  8226. });
  8227. /**
  8228. * Creates a `lodash` wrapper instance with explicit method chain sequences enabled.
  8229. *
  8230. * @name chain
  8231. * @memberOf _
  8232. * @since 0.1.0
  8233. * @category Seq
  8234. * @returns {Object} Returns the new `lodash` wrapper instance.
  8235. * @example
  8236. *
  8237. * var users = [
  8238. * { 'user': 'barney', 'age': 36 },
  8239. * { 'user': 'fred', 'age': 40 }
  8240. * ];
  8241. *
  8242. * // A sequence without explicit chaining.
  8243. * _(users).head();
  8244. * // => { 'user': 'barney', 'age': 36 }
  8245. *
  8246. * // A sequence with explicit chaining.
  8247. * _(users)
  8248. * .chain()
  8249. * .head()
  8250. * .pick('user')
  8251. * .value();
  8252. * // => { 'user': 'barney' }
  8253. */
  8254. function wrapperChain() {
  8255. return chain(this);
  8256. }
  8257. /**
  8258. * Executes the chain sequence and returns the wrapped result.
  8259. *
  8260. * @name commit
  8261. * @memberOf _
  8262. * @since 3.2.0
  8263. * @category Seq
  8264. * @returns {Object} Returns the new `lodash` wrapper instance.
  8265. * @example
  8266. *
  8267. * var array = [1, 2];
  8268. * var wrapped = _(array).push(3);
  8269. *
  8270. * console.log(array);
  8271. * // => [1, 2]
  8272. *
  8273. * wrapped = wrapped.commit();
  8274. * console.log(array);
  8275. * // => [1, 2, 3]
  8276. *
  8277. * wrapped.last();
  8278. * // => 3
  8279. *
  8280. * console.log(array);
  8281. * // => [1, 2, 3]
  8282. */
  8283. function wrapperCommit() {
  8284. return new LodashWrapper(this.value(), this.__chain__);
  8285. }
  8286. /**
  8287. * Gets the next value on a wrapped object following the
  8288. * [iterator protocol](https://mdn.io/iteration_protocols#iterator).
  8289. *
  8290. * @name next
  8291. * @memberOf _
  8292. * @since 4.0.0
  8293. * @category Seq
  8294. * @returns {Object} Returns the next iterator value.
  8295. * @example
  8296. *
  8297. * var wrapped = _([1, 2]);
  8298. *
  8299. * wrapped.next();
  8300. * // => { 'done': false, 'value': 1 }
  8301. *
  8302. * wrapped.next();
  8303. * // => { 'done': false, 'value': 2 }
  8304. *
  8305. * wrapped.next();
  8306. * // => { 'done': true, 'value': undefined }
  8307. */
  8308. function wrapperNext() {
  8309. if (this.__values__ === undefined) {
  8310. this.__values__ = toArray(this.value());
  8311. }
  8312. var done = this.__index__ >= this.__values__.length,
  8313. value = done ? undefined : this.__values__[this.__index__++];
  8314. return { 'done': done, 'value': value };
  8315. }
  8316. /**
  8317. * Enables the wrapper to be iterable.
  8318. *
  8319. * @name Symbol.iterator
  8320. * @memberOf _
  8321. * @since 4.0.0
  8322. * @category Seq
  8323. * @returns {Object} Returns the wrapper object.
  8324. * @example
  8325. *
  8326. * var wrapped = _([1, 2]);
  8327. *
  8328. * wrapped[Symbol.iterator]() === wrapped;
  8329. * // => true
  8330. *
  8331. * Array.from(wrapped);
  8332. * // => [1, 2]
  8333. */
  8334. function wrapperToIterator() {
  8335. return this;
  8336. }
  8337. /**
  8338. * Creates a clone of the chain sequence planting `value` as the wrapped value.
  8339. *
  8340. * @name plant
  8341. * @memberOf _
  8342. * @since 3.2.0
  8343. * @category Seq
  8344. * @param {*} value The value to plant.
  8345. * @returns {Object} Returns the new `lodash` wrapper instance.
  8346. * @example
  8347. *
  8348. * function square(n) {
  8349. * return n * n;
  8350. * }
  8351. *
  8352. * var wrapped = _([1, 2]).map(square);
  8353. * var other = wrapped.plant([3, 4]);
  8354. *
  8355. * other.value();
  8356. * // => [9, 16]
  8357. *
  8358. * wrapped.value();
  8359. * // => [1, 4]
  8360. */
  8361. function wrapperPlant(value) {
  8362. var result,
  8363. parent = this;
  8364. while (parent instanceof baseLodash) {
  8365. var clone = wrapperClone(parent);
  8366. clone.__index__ = 0;
  8367. clone.__values__ = undefined;
  8368. if (result) {
  8369. previous.__wrapped__ = clone;
  8370. } else {
  8371. result = clone;
  8372. }
  8373. var previous = clone;
  8374. parent = parent.__wrapped__;
  8375. }
  8376. previous.__wrapped__ = value;
  8377. return result;
  8378. }
  8379. /**
  8380. * This method is the wrapper version of `_.reverse`.
  8381. *
  8382. * **Note:** This method mutates the wrapped array.
  8383. *
  8384. * @name reverse
  8385. * @memberOf _
  8386. * @since 0.1.0
  8387. * @category Seq
  8388. * @returns {Object} Returns the new `lodash` wrapper instance.
  8389. * @example
  8390. *
  8391. * var array = [1, 2, 3];
  8392. *
  8393. * _(array).reverse().value()
  8394. * // => [3, 2, 1]
  8395. *
  8396. * console.log(array);
  8397. * // => [3, 2, 1]
  8398. */
  8399. function wrapperReverse() {
  8400. var value = this.__wrapped__;
  8401. if (value instanceof LazyWrapper) {
  8402. var wrapped = value;
  8403. if (this.__actions__.length) {
  8404. wrapped = new LazyWrapper(this);
  8405. }
  8406. wrapped = wrapped.reverse();
  8407. wrapped.__actions__.push({
  8408. 'func': thru,
  8409. 'args': [reverse],
  8410. 'thisArg': undefined
  8411. });
  8412. return new LodashWrapper(wrapped, this.__chain__);
  8413. }
  8414. return this.thru(reverse);
  8415. }
  8416. /**
  8417. * Executes the chain sequence to resolve the unwrapped value.
  8418. *
  8419. * @name value
  8420. * @memberOf _
  8421. * @since 0.1.0
  8422. * @alias toJSON, valueOf
  8423. * @category Seq
  8424. * @returns {*} Returns the resolved unwrapped value.
  8425. * @example
  8426. *
  8427. * _([1, 2, 3]).value();
  8428. * // => [1, 2, 3]
  8429. */
  8430. function wrapperValue() {
  8431. return baseWrapperValue(this.__wrapped__, this.__actions__);
  8432. }
  8433. /*------------------------------------------------------------------------*/
  8434. /**
  8435. * Creates an object composed of keys generated from the results of running
  8436. * each element of `collection` thru `iteratee`. The corresponding value of
  8437. * each key is the number of times the key was returned by `iteratee`. The
  8438. * iteratee is invoked with one argument: (value).
  8439. *
  8440. * @static
  8441. * @memberOf _
  8442. * @since 0.5.0
  8443. * @category Collection
  8444. * @param {Array|Object} collection The collection to iterate over.
  8445. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8446. * @returns {Object} Returns the composed aggregate object.
  8447. * @example
  8448. *
  8449. * _.countBy([6.1, 4.2, 6.3], Math.floor);
  8450. * // => { '4': 1, '6': 2 }
  8451. *
  8452. * // The `_.property` iteratee shorthand.
  8453. * _.countBy(['one', 'two', 'three'], 'length');
  8454. * // => { '3': 2, '5': 1 }
  8455. */
  8456. var countBy = createAggregator(function(result, value, key) {
  8457. if (hasOwnProperty.call(result, key)) {
  8458. ++result[key];
  8459. } else {
  8460. baseAssignValue(result, key, 1);
  8461. }
  8462. });
  8463. /**
  8464. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  8465. * Iteration is stopped once `predicate` returns falsey. The predicate is
  8466. * invoked with three arguments: (value, index|key, collection).
  8467. *
  8468. * **Note:** This method returns `true` for
  8469. * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because
  8470. * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of
  8471. * elements of empty collections.
  8472. *
  8473. * @static
  8474. * @memberOf _
  8475. * @since 0.1.0
  8476. * @category Collection
  8477. * @param {Array|Object} collection The collection to iterate over.
  8478. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8479. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  8480. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  8481. * else `false`.
  8482. * @example
  8483. *
  8484. * _.every([true, 1, null, 'yes'], Boolean);
  8485. * // => false
  8486. *
  8487. * var users = [
  8488. * { 'user': 'barney', 'age': 36, 'active': false },
  8489. * { 'user': 'fred', 'age': 40, 'active': false }
  8490. * ];
  8491. *
  8492. * // The `_.matches` iteratee shorthand.
  8493. * _.every(users, { 'user': 'barney', 'active': false });
  8494. * // => false
  8495. *
  8496. * // The `_.matchesProperty` iteratee shorthand.
  8497. * _.every(users, ['active', false]);
  8498. * // => true
  8499. *
  8500. * // The `_.property` iteratee shorthand.
  8501. * _.every(users, 'active');
  8502. * // => false
  8503. */
  8504. function every(collection, predicate, guard) {
  8505. var func = isArray(collection) ? arrayEvery : baseEvery;
  8506. if (guard && isIterateeCall(collection, predicate, guard)) {
  8507. predicate = undefined;
  8508. }
  8509. return func(collection, getIteratee(predicate, 3));
  8510. }
  8511. /**
  8512. * Iterates over elements of `collection`, returning an array of all elements
  8513. * `predicate` returns truthy for. The predicate is invoked with three
  8514. * arguments: (value, index|key, collection).
  8515. *
  8516. * **Note:** Unlike `_.remove`, this method returns a new array.
  8517. *
  8518. * @static
  8519. * @memberOf _
  8520. * @since 0.1.0
  8521. * @category Collection
  8522. * @param {Array|Object} collection The collection to iterate over.
  8523. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8524. * @returns {Array} Returns the new filtered array.
  8525. * @see _.reject
  8526. * @example
  8527. *
  8528. * var users = [
  8529. * { 'user': 'barney', 'age': 36, 'active': true },
  8530. * { 'user': 'fred', 'age': 40, 'active': false }
  8531. * ];
  8532. *
  8533. * _.filter(users, function(o) { return !o.active; });
  8534. * // => objects for ['fred']
  8535. *
  8536. * // The `_.matches` iteratee shorthand.
  8537. * _.filter(users, { 'age': 36, 'active': true });
  8538. * // => objects for ['barney']
  8539. *
  8540. * // The `_.matchesProperty` iteratee shorthand.
  8541. * _.filter(users, ['active', false]);
  8542. * // => objects for ['fred']
  8543. *
  8544. * // The `_.property` iteratee shorthand.
  8545. * _.filter(users, 'active');
  8546. * // => objects for ['barney']
  8547. *
  8548. * // Combining several predicates using `_.overEvery` or `_.overSome`.
  8549. * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]]));
  8550. * // => objects for ['fred', 'barney']
  8551. */
  8552. function filter(collection, predicate) {
  8553. var func = isArray(collection) ? arrayFilter : baseFilter;
  8554. return func(collection, getIteratee(predicate, 3));
  8555. }
  8556. /**
  8557. * Iterates over elements of `collection`, returning the first element
  8558. * `predicate` returns truthy for. The predicate is invoked with three
  8559. * arguments: (value, index|key, collection).
  8560. *
  8561. * @static
  8562. * @memberOf _
  8563. * @since 0.1.0
  8564. * @category Collection
  8565. * @param {Array|Object} collection The collection to inspect.
  8566. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8567. * @param {number} [fromIndex=0] The index to search from.
  8568. * @returns {*} Returns the matched element, else `undefined`.
  8569. * @example
  8570. *
  8571. * var users = [
  8572. * { 'user': 'barney', 'age': 36, 'active': true },
  8573. * { 'user': 'fred', 'age': 40, 'active': false },
  8574. * { 'user': 'pebbles', 'age': 1, 'active': true }
  8575. * ];
  8576. *
  8577. * _.find(users, function(o) { return o.age < 40; });
  8578. * // => object for 'barney'
  8579. *
  8580. * // The `_.matches` iteratee shorthand.
  8581. * _.find(users, { 'age': 1, 'active': true });
  8582. * // => object for 'pebbles'
  8583. *
  8584. * // The `_.matchesProperty` iteratee shorthand.
  8585. * _.find(users, ['active', false]);
  8586. * // => object for 'fred'
  8587. *
  8588. * // The `_.property` iteratee shorthand.
  8589. * _.find(users, 'active');
  8590. * // => object for 'barney'
  8591. */
  8592. var find = createFind(findIndex);
  8593. /**
  8594. * This method is like `_.find` except that it iterates over elements of
  8595. * `collection` from right to left.
  8596. *
  8597. * @static
  8598. * @memberOf _
  8599. * @since 2.0.0
  8600. * @category Collection
  8601. * @param {Array|Object} collection The collection to inspect.
  8602. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8603. * @param {number} [fromIndex=collection.length-1] The index to search from.
  8604. * @returns {*} Returns the matched element, else `undefined`.
  8605. * @example
  8606. *
  8607. * _.findLast([1, 2, 3, 4], function(n) {
  8608. * return n % 2 == 1;
  8609. * });
  8610. * // => 3
  8611. */
  8612. var findLast = createFind(findLastIndex);
  8613. /**
  8614. * Creates a flattened array of values by running each element in `collection`
  8615. * thru `iteratee` and flattening the mapped results. The iteratee is invoked
  8616. * with three arguments: (value, index|key, collection).
  8617. *
  8618. * @static
  8619. * @memberOf _
  8620. * @since 4.0.0
  8621. * @category Collection
  8622. * @param {Array|Object} collection The collection to iterate over.
  8623. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8624. * @returns {Array} Returns the new flattened array.
  8625. * @example
  8626. *
  8627. * function duplicate(n) {
  8628. * return [n, n];
  8629. * }
  8630. *
  8631. * _.flatMap([1, 2], duplicate);
  8632. * // => [1, 1, 2, 2]
  8633. */
  8634. function flatMap(collection, iteratee) {
  8635. return baseFlatten(map(collection, iteratee), 1);
  8636. }
  8637. /**
  8638. * This method is like `_.flatMap` except that it recursively flattens the
  8639. * mapped results.
  8640. *
  8641. * @static
  8642. * @memberOf _
  8643. * @since 4.7.0
  8644. * @category Collection
  8645. * @param {Array|Object} collection The collection to iterate over.
  8646. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8647. * @returns {Array} Returns the new flattened array.
  8648. * @example
  8649. *
  8650. * function duplicate(n) {
  8651. * return [[[n, n]]];
  8652. * }
  8653. *
  8654. * _.flatMapDeep([1, 2], duplicate);
  8655. * // => [1, 1, 2, 2]
  8656. */
  8657. function flatMapDeep(collection, iteratee) {
  8658. return baseFlatten(map(collection, iteratee), INFINITY);
  8659. }
  8660. /**
  8661. * This method is like `_.flatMap` except that it recursively flattens the
  8662. * mapped results up to `depth` times.
  8663. *
  8664. * @static
  8665. * @memberOf _
  8666. * @since 4.7.0
  8667. * @category Collection
  8668. * @param {Array|Object} collection The collection to iterate over.
  8669. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8670. * @param {number} [depth=1] The maximum recursion depth.
  8671. * @returns {Array} Returns the new flattened array.
  8672. * @example
  8673. *
  8674. * function duplicate(n) {
  8675. * return [[[n, n]]];
  8676. * }
  8677. *
  8678. * _.flatMapDepth([1, 2], duplicate, 2);
  8679. * // => [[1, 1], [2, 2]]
  8680. */
  8681. function flatMapDepth(collection, iteratee, depth) {
  8682. depth = depth === undefined ? 1 : toInteger(depth);
  8683. return baseFlatten(map(collection, iteratee), depth);
  8684. }
  8685. /**
  8686. * Iterates over elements of `collection` and invokes `iteratee` for each element.
  8687. * The iteratee is invoked with three arguments: (value, index|key, collection).
  8688. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8689. *
  8690. * **Note:** As with other "Collections" methods, objects with a "length"
  8691. * property are iterated like arrays. To avoid this behavior use `_.forIn`
  8692. * or `_.forOwn` for object iteration.
  8693. *
  8694. * @static
  8695. * @memberOf _
  8696. * @since 0.1.0
  8697. * @alias each
  8698. * @category Collection
  8699. * @param {Array|Object} collection The collection to iterate over.
  8700. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8701. * @returns {Array|Object} Returns `collection`.
  8702. * @see _.forEachRight
  8703. * @example
  8704. *
  8705. * _.forEach([1, 2], function(value) {
  8706. * console.log(value);
  8707. * });
  8708. * // => Logs `1` then `2`.
  8709. *
  8710. * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) {
  8711. * console.log(key);
  8712. * });
  8713. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  8714. */
  8715. function forEach(collection, iteratee) {
  8716. var func = isArray(collection) ? arrayEach : baseEach;
  8717. return func(collection, getIteratee(iteratee, 3));
  8718. }
  8719. /**
  8720. * This method is like `_.forEach` except that it iterates over elements of
  8721. * `collection` from right to left.
  8722. *
  8723. * @static
  8724. * @memberOf _
  8725. * @since 2.0.0
  8726. * @alias eachRight
  8727. * @category Collection
  8728. * @param {Array|Object} collection The collection to iterate over.
  8729. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8730. * @returns {Array|Object} Returns `collection`.
  8731. * @see _.forEach
  8732. * @example
  8733. *
  8734. * _.forEachRight([1, 2], function(value) {
  8735. * console.log(value);
  8736. * });
  8737. * // => Logs `2` then `1`.
  8738. */
  8739. function forEachRight(collection, iteratee) {
  8740. var func = isArray(collection) ? arrayEachRight : baseEachRight;
  8741. return func(collection, getIteratee(iteratee, 3));
  8742. }
  8743. /**
  8744. * Creates an object composed of keys generated from the results of running
  8745. * each element of `collection` thru `iteratee`. The order of grouped values
  8746. * is determined by the order they occur in `collection`. The corresponding
  8747. * value of each key is an array of elements responsible for generating the
  8748. * key. The iteratee is invoked with one argument: (value).
  8749. *
  8750. * @static
  8751. * @memberOf _
  8752. * @since 0.1.0
  8753. * @category Collection
  8754. * @param {Array|Object} collection The collection to iterate over.
  8755. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8756. * @returns {Object} Returns the composed aggregate object.
  8757. * @example
  8758. *
  8759. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  8760. * // => { '4': [4.2], '6': [6.1, 6.3] }
  8761. *
  8762. * // The `_.property` iteratee shorthand.
  8763. * _.groupBy(['one', 'two', 'three'], 'length');
  8764. * // => { '3': ['one', 'two'], '5': ['three'] }
  8765. */
  8766. var groupBy = createAggregator(function(result, value, key) {
  8767. if (hasOwnProperty.call(result, key)) {
  8768. result[key].push(value);
  8769. } else {
  8770. baseAssignValue(result, key, [value]);
  8771. }
  8772. });
  8773. /**
  8774. * Checks if `value` is in `collection`. If `collection` is a string, it's
  8775. * checked for a substring of `value`, otherwise
  8776. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  8777. * is used for equality comparisons. If `fromIndex` is negative, it's used as
  8778. * the offset from the end of `collection`.
  8779. *
  8780. * @static
  8781. * @memberOf _
  8782. * @since 0.1.0
  8783. * @category Collection
  8784. * @param {Array|Object|string} collection The collection to inspect.
  8785. * @param {*} value The value to search for.
  8786. * @param {number} [fromIndex=0] The index to search from.
  8787. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8788. * @returns {boolean} Returns `true` if `value` is found, else `false`.
  8789. * @example
  8790. *
  8791. * _.includes([1, 2, 3], 1);
  8792. * // => true
  8793. *
  8794. * _.includes([1, 2, 3], 1, 2);
  8795. * // => false
  8796. *
  8797. * _.includes({ 'a': 1, 'b': 2 }, 1);
  8798. * // => true
  8799. *
  8800. * _.includes('abcd', 'bc');
  8801. * // => true
  8802. */
  8803. function includes(collection, value, fromIndex, guard) {
  8804. collection = isArrayLike(collection) ? collection : values(collection);
  8805. fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0;
  8806. var length = collection.length;
  8807. if (fromIndex < 0) {
  8808. fromIndex = nativeMax(length + fromIndex, 0);
  8809. }
  8810. return isString(collection)
  8811. ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1)
  8812. : (!!length && baseIndexOf(collection, value, fromIndex) > -1);
  8813. }
  8814. /**
  8815. * Invokes the method at `path` of each element in `collection`, returning
  8816. * an array of the results of each invoked method. Any additional arguments
  8817. * are provided to each invoked method. If `path` is a function, it's invoked
  8818. * for, and `this` bound to, each element in `collection`.
  8819. *
  8820. * @static
  8821. * @memberOf _
  8822. * @since 4.0.0
  8823. * @category Collection
  8824. * @param {Array|Object} collection The collection to iterate over.
  8825. * @param {Array|Function|string} path The path of the method to invoke or
  8826. * the function invoked per iteration.
  8827. * @param {...*} [args] The arguments to invoke each method with.
  8828. * @returns {Array} Returns the array of results.
  8829. * @example
  8830. *
  8831. * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort');
  8832. * // => [[1, 5, 7], [1, 2, 3]]
  8833. *
  8834. * _.invokeMap([123, 456], String.prototype.split, '');
  8835. * // => [['1', '2', '3'], ['4', '5', '6']]
  8836. */
  8837. var invokeMap = baseRest(function(collection, path, args) {
  8838. var index = -1,
  8839. isFunc = typeof path == 'function',
  8840. result = isArrayLike(collection) ? Array(collection.length) : [];
  8841. baseEach(collection, function(value) {
  8842. result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args);
  8843. });
  8844. return result;
  8845. });
  8846. /**
  8847. * Creates an object composed of keys generated from the results of running
  8848. * each element of `collection` thru `iteratee`. The corresponding value of
  8849. * each key is the last element responsible for generating the key. The
  8850. * iteratee is invoked with one argument: (value).
  8851. *
  8852. * @static
  8853. * @memberOf _
  8854. * @since 4.0.0
  8855. * @category Collection
  8856. * @param {Array|Object} collection The collection to iterate over.
  8857. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  8858. * @returns {Object} Returns the composed aggregate object.
  8859. * @example
  8860. *
  8861. * var array = [
  8862. * { 'dir': 'left', 'code': 97 },
  8863. * { 'dir': 'right', 'code': 100 }
  8864. * ];
  8865. *
  8866. * _.keyBy(array, function(o) {
  8867. * return String.fromCharCode(o.code);
  8868. * });
  8869. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  8870. *
  8871. * _.keyBy(array, 'dir');
  8872. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  8873. */
  8874. var keyBy = createAggregator(function(result, value, key) {
  8875. baseAssignValue(result, key, value);
  8876. });
  8877. /**
  8878. * Creates an array of values by running each element in `collection` thru
  8879. * `iteratee`. The iteratee is invoked with three arguments:
  8880. * (value, index|key, collection).
  8881. *
  8882. * Many lodash methods are guarded to work as iteratees for methods like
  8883. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  8884. *
  8885. * The guarded methods are:
  8886. * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`,
  8887. * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`,
  8888. * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`,
  8889. * `template`, `trim`, `trimEnd`, `trimStart`, and `words`
  8890. *
  8891. * @static
  8892. * @memberOf _
  8893. * @since 0.1.0
  8894. * @category Collection
  8895. * @param {Array|Object} collection The collection to iterate over.
  8896. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  8897. * @returns {Array} Returns the new mapped array.
  8898. * @example
  8899. *
  8900. * function square(n) {
  8901. * return n * n;
  8902. * }
  8903. *
  8904. * _.map([4, 8], square);
  8905. * // => [16, 64]
  8906. *
  8907. * _.map({ 'a': 4, 'b': 8 }, square);
  8908. * // => [16, 64] (iteration order is not guaranteed)
  8909. *
  8910. * var users = [
  8911. * { 'user': 'barney' },
  8912. * { 'user': 'fred' }
  8913. * ];
  8914. *
  8915. * // The `_.property` iteratee shorthand.
  8916. * _.map(users, 'user');
  8917. * // => ['barney', 'fred']
  8918. */
  8919. function map(collection, iteratee) {
  8920. var func = isArray(collection) ? arrayMap : baseMap;
  8921. return func(collection, getIteratee(iteratee, 3));
  8922. }
  8923. /**
  8924. * This method is like `_.sortBy` except that it allows specifying the sort
  8925. * orders of the iteratees to sort by. If `orders` is unspecified, all values
  8926. * are sorted in ascending order. Otherwise, specify an order of "desc" for
  8927. * descending or "asc" for ascending sort order of corresponding values.
  8928. *
  8929. * @static
  8930. * @memberOf _
  8931. * @since 4.0.0
  8932. * @category Collection
  8933. * @param {Array|Object} collection The collection to iterate over.
  8934. * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]]
  8935. * The iteratees to sort by.
  8936. * @param {string[]} [orders] The sort orders of `iteratees`.
  8937. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`.
  8938. * @returns {Array} Returns the new sorted array.
  8939. * @example
  8940. *
  8941. * var users = [
  8942. * { 'user': 'fred', 'age': 48 },
  8943. * { 'user': 'barney', 'age': 34 },
  8944. * { 'user': 'fred', 'age': 40 },
  8945. * { 'user': 'barney', 'age': 36 }
  8946. * ];
  8947. *
  8948. * // Sort by `user` in ascending order and by `age` in descending order.
  8949. * _.orderBy(users, ['user', 'age'], ['asc', 'desc']);
  8950. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]]
  8951. */
  8952. function orderBy(collection, iteratees, orders, guard) {
  8953. if (collection == null) {
  8954. return [];
  8955. }
  8956. if (!isArray(iteratees)) {
  8957. iteratees = iteratees == null ? [] : [iteratees];
  8958. }
  8959. orders = guard ? undefined : orders;
  8960. if (!isArray(orders)) {
  8961. orders = orders == null ? [] : [orders];
  8962. }
  8963. return baseOrderBy(collection, iteratees, orders);
  8964. }
  8965. /**
  8966. * Creates an array of elements split into two groups, the first of which
  8967. * contains elements `predicate` returns truthy for, the second of which
  8968. * contains elements `predicate` returns falsey for. The predicate is
  8969. * invoked with one argument: (value).
  8970. *
  8971. * @static
  8972. * @memberOf _
  8973. * @since 3.0.0
  8974. * @category Collection
  8975. * @param {Array|Object} collection The collection to iterate over.
  8976. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  8977. * @returns {Array} Returns the array of grouped elements.
  8978. * @example
  8979. *
  8980. * var users = [
  8981. * { 'user': 'barney', 'age': 36, 'active': false },
  8982. * { 'user': 'fred', 'age': 40, 'active': true },
  8983. * { 'user': 'pebbles', 'age': 1, 'active': false }
  8984. * ];
  8985. *
  8986. * _.partition(users, function(o) { return o.active; });
  8987. * // => objects for [['fred'], ['barney', 'pebbles']]
  8988. *
  8989. * // The `_.matches` iteratee shorthand.
  8990. * _.partition(users, { 'age': 1, 'active': false });
  8991. * // => objects for [['pebbles'], ['barney', 'fred']]
  8992. *
  8993. * // The `_.matchesProperty` iteratee shorthand.
  8994. * _.partition(users, ['active', false]);
  8995. * // => objects for [['barney', 'pebbles'], ['fred']]
  8996. *
  8997. * // The `_.property` iteratee shorthand.
  8998. * _.partition(users, 'active');
  8999. * // => objects for [['fred'], ['barney', 'pebbles']]
  9000. */
  9001. var partition = createAggregator(function(result, value, key) {
  9002. result[key ? 0 : 1].push(value);
  9003. }, function() { return [[], []]; });
  9004. /**
  9005. * Reduces `collection` to a value which is the accumulated result of running
  9006. * each element in `collection` thru `iteratee`, where each successive
  9007. * invocation is supplied the return value of the previous. If `accumulator`
  9008. * is not given, the first element of `collection` is used as the initial
  9009. * value. The iteratee is invoked with four arguments:
  9010. * (accumulator, value, index|key, collection).
  9011. *
  9012. * Many lodash methods are guarded to work as iteratees for methods like
  9013. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  9014. *
  9015. * The guarded methods are:
  9016. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`,
  9017. * and `sortBy`
  9018. *
  9019. * @static
  9020. * @memberOf _
  9021. * @since 0.1.0
  9022. * @category Collection
  9023. * @param {Array|Object} collection The collection to iterate over.
  9024. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9025. * @param {*} [accumulator] The initial value.
  9026. * @returns {*} Returns the accumulated value.
  9027. * @see _.reduceRight
  9028. * @example
  9029. *
  9030. * _.reduce([1, 2], function(sum, n) {
  9031. * return sum + n;
  9032. * }, 0);
  9033. * // => 3
  9034. *
  9035. * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  9036. * (result[value] || (result[value] = [])).push(key);
  9037. * return result;
  9038. * }, {});
  9039. * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed)
  9040. */
  9041. function reduce(collection, iteratee, accumulator) {
  9042. var func = isArray(collection) ? arrayReduce : baseReduce,
  9043. initAccum = arguments.length < 3;
  9044. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach);
  9045. }
  9046. /**
  9047. * This method is like `_.reduce` except that it iterates over elements of
  9048. * `collection` from right to left.
  9049. *
  9050. * @static
  9051. * @memberOf _
  9052. * @since 0.1.0
  9053. * @category Collection
  9054. * @param {Array|Object} collection The collection to iterate over.
  9055. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9056. * @param {*} [accumulator] The initial value.
  9057. * @returns {*} Returns the accumulated value.
  9058. * @see _.reduce
  9059. * @example
  9060. *
  9061. * var array = [[0, 1], [2, 3], [4, 5]];
  9062. *
  9063. * _.reduceRight(array, function(flattened, other) {
  9064. * return flattened.concat(other);
  9065. * }, []);
  9066. * // => [4, 5, 2, 3, 0, 1]
  9067. */
  9068. function reduceRight(collection, iteratee, accumulator) {
  9069. var func = isArray(collection) ? arrayReduceRight : baseReduce,
  9070. initAccum = arguments.length < 3;
  9071. return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight);
  9072. }
  9073. /**
  9074. * The opposite of `_.filter`; this method returns the elements of `collection`
  9075. * that `predicate` does **not** return truthy for.
  9076. *
  9077. * @static
  9078. * @memberOf _
  9079. * @since 0.1.0
  9080. * @category Collection
  9081. * @param {Array|Object} collection The collection to iterate over.
  9082. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9083. * @returns {Array} Returns the new filtered array.
  9084. * @see _.filter
  9085. * @example
  9086. *
  9087. * var users = [
  9088. * { 'user': 'barney', 'age': 36, 'active': false },
  9089. * { 'user': 'fred', 'age': 40, 'active': true }
  9090. * ];
  9091. *
  9092. * _.reject(users, function(o) { return !o.active; });
  9093. * // => objects for ['fred']
  9094. *
  9095. * // The `_.matches` iteratee shorthand.
  9096. * _.reject(users, { 'age': 40, 'active': true });
  9097. * // => objects for ['barney']
  9098. *
  9099. * // The `_.matchesProperty` iteratee shorthand.
  9100. * _.reject(users, ['active', false]);
  9101. * // => objects for ['fred']
  9102. *
  9103. * // The `_.property` iteratee shorthand.
  9104. * _.reject(users, 'active');
  9105. * // => objects for ['barney']
  9106. */
  9107. function reject(collection, predicate) {
  9108. var func = isArray(collection) ? arrayFilter : baseFilter;
  9109. return func(collection, negate(getIteratee(predicate, 3)));
  9110. }
  9111. /**
  9112. * Gets a random element from `collection`.
  9113. *
  9114. * @static
  9115. * @memberOf _
  9116. * @since 2.0.0
  9117. * @category Collection
  9118. * @param {Array|Object} collection The collection to sample.
  9119. * @returns {*} Returns the random element.
  9120. * @example
  9121. *
  9122. * _.sample([1, 2, 3, 4]);
  9123. * // => 2
  9124. */
  9125. function sample(collection) {
  9126. var func = isArray(collection) ? arraySample : baseSample;
  9127. return func(collection);
  9128. }
  9129. /**
  9130. * Gets `n` random elements at unique keys from `collection` up to the
  9131. * size of `collection`.
  9132. *
  9133. * @static
  9134. * @memberOf _
  9135. * @since 4.0.0
  9136. * @category Collection
  9137. * @param {Array|Object} collection The collection to sample.
  9138. * @param {number} [n=1] The number of elements to sample.
  9139. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9140. * @returns {Array} Returns the random elements.
  9141. * @example
  9142. *
  9143. * _.sampleSize([1, 2, 3], 2);
  9144. * // => [3, 1]
  9145. *
  9146. * _.sampleSize([1, 2, 3], 4);
  9147. * // => [2, 3, 1]
  9148. */
  9149. function sampleSize(collection, n, guard) {
  9150. if ((guard ? isIterateeCall(collection, n, guard) : n === undefined)) {
  9151. n = 1;
  9152. } else {
  9153. n = toInteger(n);
  9154. }
  9155. var func = isArray(collection) ? arraySampleSize : baseSampleSize;
  9156. return func(collection, n);
  9157. }
  9158. /**
  9159. * Creates an array of shuffled values, using a version of the
  9160. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  9161. *
  9162. * @static
  9163. * @memberOf _
  9164. * @since 0.1.0
  9165. * @category Collection
  9166. * @param {Array|Object} collection The collection to shuffle.
  9167. * @returns {Array} Returns the new shuffled array.
  9168. * @example
  9169. *
  9170. * _.shuffle([1, 2, 3, 4]);
  9171. * // => [4, 1, 3, 2]
  9172. */
  9173. function shuffle(collection) {
  9174. var func = isArray(collection) ? arrayShuffle : baseShuffle;
  9175. return func(collection);
  9176. }
  9177. /**
  9178. * Gets the size of `collection` by returning its length for array-like
  9179. * values or the number of own enumerable string keyed properties for objects.
  9180. *
  9181. * @static
  9182. * @memberOf _
  9183. * @since 0.1.0
  9184. * @category Collection
  9185. * @param {Array|Object|string} collection The collection to inspect.
  9186. * @returns {number} Returns the collection size.
  9187. * @example
  9188. *
  9189. * _.size([1, 2, 3]);
  9190. * // => 3
  9191. *
  9192. * _.size({ 'a': 1, 'b': 2 });
  9193. * // => 2
  9194. *
  9195. * _.size('pebbles');
  9196. * // => 7
  9197. */
  9198. function size(collection) {
  9199. if (collection == null) {
  9200. return 0;
  9201. }
  9202. if (isArrayLike(collection)) {
  9203. return isString(collection) ? stringSize(collection) : collection.length;
  9204. }
  9205. var tag = getTag(collection);
  9206. if (tag == mapTag || tag == setTag) {
  9207. return collection.size;
  9208. }
  9209. return baseKeys(collection).length;
  9210. }
  9211. /**
  9212. * Checks if `predicate` returns truthy for **any** element of `collection`.
  9213. * Iteration is stopped once `predicate` returns truthy. The predicate is
  9214. * invoked with three arguments: (value, index|key, collection).
  9215. *
  9216. * @static
  9217. * @memberOf _
  9218. * @since 0.1.0
  9219. * @category Collection
  9220. * @param {Array|Object} collection The collection to iterate over.
  9221. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  9222. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9223. * @returns {boolean} Returns `true` if any element passes the predicate check,
  9224. * else `false`.
  9225. * @example
  9226. *
  9227. * _.some([null, 0, 'yes', false], Boolean);
  9228. * // => true
  9229. *
  9230. * var users = [
  9231. * { 'user': 'barney', 'active': true },
  9232. * { 'user': 'fred', 'active': false }
  9233. * ];
  9234. *
  9235. * // The `_.matches` iteratee shorthand.
  9236. * _.some(users, { 'user': 'barney', 'active': false });
  9237. * // => false
  9238. *
  9239. * // The `_.matchesProperty` iteratee shorthand.
  9240. * _.some(users, ['active', false]);
  9241. * // => true
  9242. *
  9243. * // The `_.property` iteratee shorthand.
  9244. * _.some(users, 'active');
  9245. * // => true
  9246. */
  9247. function some(collection, predicate, guard) {
  9248. var func = isArray(collection) ? arraySome : baseSome;
  9249. if (guard && isIterateeCall(collection, predicate, guard)) {
  9250. predicate = undefined;
  9251. }
  9252. return func(collection, getIteratee(predicate, 3));
  9253. }
  9254. /**
  9255. * Creates an array of elements, sorted in ascending order by the results of
  9256. * running each element in a collection thru each iteratee. This method
  9257. * performs a stable sort, that is, it preserves the original sort order of
  9258. * equal elements. The iteratees are invoked with one argument: (value).
  9259. *
  9260. * @static
  9261. * @memberOf _
  9262. * @since 0.1.0
  9263. * @category Collection
  9264. * @param {Array|Object} collection The collection to iterate over.
  9265. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  9266. * The iteratees to sort by.
  9267. * @returns {Array} Returns the new sorted array.
  9268. * @example
  9269. *
  9270. * var users = [
  9271. * { 'user': 'fred', 'age': 48 },
  9272. * { 'user': 'barney', 'age': 36 },
  9273. * { 'user': 'fred', 'age': 30 },
  9274. * { 'user': 'barney', 'age': 34 }
  9275. * ];
  9276. *
  9277. * _.sortBy(users, [function(o) { return o.user; }]);
  9278. * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]]
  9279. *
  9280. * _.sortBy(users, ['user', 'age']);
  9281. * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]]
  9282. */
  9283. var sortBy = baseRest(function(collection, iteratees) {
  9284. if (collection == null) {
  9285. return [];
  9286. }
  9287. var length = iteratees.length;
  9288. if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) {
  9289. iteratees = [];
  9290. } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) {
  9291. iteratees = [iteratees[0]];
  9292. }
  9293. return baseOrderBy(collection, baseFlatten(iteratees, 1), []);
  9294. });
  9295. /*------------------------------------------------------------------------*/
  9296. /**
  9297. * Gets the timestamp of the number of milliseconds that have elapsed since
  9298. * the Unix epoch (1 January 1970 00:00:00 UTC).
  9299. *
  9300. * @static
  9301. * @memberOf _
  9302. * @since 2.4.0
  9303. * @category Date
  9304. * @returns {number} Returns the timestamp.
  9305. * @example
  9306. *
  9307. * _.defer(function(stamp) {
  9308. * console.log(_.now() - stamp);
  9309. * }, _.now());
  9310. * // => Logs the number of milliseconds it took for the deferred invocation.
  9311. */
  9312. var now = ctxNow || function() {
  9313. return root.Date.now();
  9314. };
  9315. /*------------------------------------------------------------------------*/
  9316. /**
  9317. * The opposite of `_.before`; this method creates a function that invokes
  9318. * `func` once it's called `n` or more times.
  9319. *
  9320. * @static
  9321. * @memberOf _
  9322. * @since 0.1.0
  9323. * @category Function
  9324. * @param {number} n The number of calls before `func` is invoked.
  9325. * @param {Function} func The function to restrict.
  9326. * @returns {Function} Returns the new restricted function.
  9327. * @example
  9328. *
  9329. * var saves = ['profile', 'settings'];
  9330. *
  9331. * var done = _.after(saves.length, function() {
  9332. * console.log('done saving!');
  9333. * });
  9334. *
  9335. * _.forEach(saves, function(type) {
  9336. * asyncSave({ 'type': type, 'complete': done });
  9337. * });
  9338. * // => Logs 'done saving!' after the two async saves have completed.
  9339. */
  9340. function after(n, func) {
  9341. if (typeof func != 'function') {
  9342. throw new TypeError(FUNC_ERROR_TEXT);
  9343. }
  9344. n = toInteger(n);
  9345. return function() {
  9346. if (--n < 1) {
  9347. return func.apply(this, arguments);
  9348. }
  9349. };
  9350. }
  9351. /**
  9352. * Creates a function that invokes `func`, with up to `n` arguments,
  9353. * ignoring any additional arguments.
  9354. *
  9355. * @static
  9356. * @memberOf _
  9357. * @since 3.0.0
  9358. * @category Function
  9359. * @param {Function} func The function to cap arguments for.
  9360. * @param {number} [n=func.length] The arity cap.
  9361. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9362. * @returns {Function} Returns the new capped function.
  9363. * @example
  9364. *
  9365. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  9366. * // => [6, 8, 10]
  9367. */
  9368. function ary(func, n, guard) {
  9369. n = guard ? undefined : n;
  9370. n = (func && n == null) ? func.length : n;
  9371. return createWrap(func, WRAP_ARY_FLAG, undefined, undefined, undefined, undefined, n);
  9372. }
  9373. /**
  9374. * Creates a function that invokes `func`, with the `this` binding and arguments
  9375. * of the created function, while it's called less than `n` times. Subsequent
  9376. * calls to the created function return the result of the last `func` invocation.
  9377. *
  9378. * @static
  9379. * @memberOf _
  9380. * @since 3.0.0
  9381. * @category Function
  9382. * @param {number} n The number of calls at which `func` is no longer invoked.
  9383. * @param {Function} func The function to restrict.
  9384. * @returns {Function} Returns the new restricted function.
  9385. * @example
  9386. *
  9387. * jQuery(element).on('click', _.before(5, addContactToList));
  9388. * // => Allows adding up to 4 contacts to the list.
  9389. */
  9390. function before(n, func) {
  9391. var result;
  9392. if (typeof func != 'function') {
  9393. throw new TypeError(FUNC_ERROR_TEXT);
  9394. }
  9395. n = toInteger(n);
  9396. return function() {
  9397. if (--n > 0) {
  9398. result = func.apply(this, arguments);
  9399. }
  9400. if (n <= 1) {
  9401. func = undefined;
  9402. }
  9403. return result;
  9404. };
  9405. }
  9406. /**
  9407. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  9408. * and `partials` prepended to the arguments it receives.
  9409. *
  9410. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  9411. * may be used as a placeholder for partially applied arguments.
  9412. *
  9413. * **Note:** Unlike native `Function#bind`, this method doesn't set the "length"
  9414. * property of bound functions.
  9415. *
  9416. * @static
  9417. * @memberOf _
  9418. * @since 0.1.0
  9419. * @category Function
  9420. * @param {Function} func The function to bind.
  9421. * @param {*} thisArg The `this` binding of `func`.
  9422. * @param {...*} [partials] The arguments to be partially applied.
  9423. * @returns {Function} Returns the new bound function.
  9424. * @example
  9425. *
  9426. * function greet(greeting, punctuation) {
  9427. * return greeting + ' ' + this.user + punctuation;
  9428. * }
  9429. *
  9430. * var object = { 'user': 'fred' };
  9431. *
  9432. * var bound = _.bind(greet, object, 'hi');
  9433. * bound('!');
  9434. * // => 'hi fred!'
  9435. *
  9436. * // Bound with placeholders.
  9437. * var bound = _.bind(greet, object, _, '!');
  9438. * bound('hi');
  9439. * // => 'hi fred!'
  9440. */
  9441. var bind = baseRest(function(func, thisArg, partials) {
  9442. var bitmask = WRAP_BIND_FLAG;
  9443. if (partials.length) {
  9444. var holders = replaceHolders(partials, getHolder(bind));
  9445. bitmask |= WRAP_PARTIAL_FLAG;
  9446. }
  9447. return createWrap(func, bitmask, thisArg, partials, holders);
  9448. });
  9449. /**
  9450. * Creates a function that invokes the method at `object[key]` with `partials`
  9451. * prepended to the arguments it receives.
  9452. *
  9453. * This method differs from `_.bind` by allowing bound functions to reference
  9454. * methods that may be redefined or don't yet exist. See
  9455. * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  9456. * for more details.
  9457. *
  9458. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  9459. * builds, may be used as a placeholder for partially applied arguments.
  9460. *
  9461. * @static
  9462. * @memberOf _
  9463. * @since 0.10.0
  9464. * @category Function
  9465. * @param {Object} object The object to invoke the method on.
  9466. * @param {string} key The key of the method.
  9467. * @param {...*} [partials] The arguments to be partially applied.
  9468. * @returns {Function} Returns the new bound function.
  9469. * @example
  9470. *
  9471. * var object = {
  9472. * 'user': 'fred',
  9473. * 'greet': function(greeting, punctuation) {
  9474. * return greeting + ' ' + this.user + punctuation;
  9475. * }
  9476. * };
  9477. *
  9478. * var bound = _.bindKey(object, 'greet', 'hi');
  9479. * bound('!');
  9480. * // => 'hi fred!'
  9481. *
  9482. * object.greet = function(greeting, punctuation) {
  9483. * return greeting + 'ya ' + this.user + punctuation;
  9484. * };
  9485. *
  9486. * bound('!');
  9487. * // => 'hiya fred!'
  9488. *
  9489. * // Bound with placeholders.
  9490. * var bound = _.bindKey(object, 'greet', _, '!');
  9491. * bound('hi');
  9492. * // => 'hiya fred!'
  9493. */
  9494. var bindKey = baseRest(function(object, key, partials) {
  9495. var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG;
  9496. if (partials.length) {
  9497. var holders = replaceHolders(partials, getHolder(bindKey));
  9498. bitmask |= WRAP_PARTIAL_FLAG;
  9499. }
  9500. return createWrap(key, bitmask, object, partials, holders);
  9501. });
  9502. /**
  9503. * Creates a function that accepts arguments of `func` and either invokes
  9504. * `func` returning its result, if at least `arity` number of arguments have
  9505. * been provided, or returns a function that accepts the remaining `func`
  9506. * arguments, and so on. The arity of `func` may be specified if `func.length`
  9507. * is not sufficient.
  9508. *
  9509. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  9510. * may be used as a placeholder for provided arguments.
  9511. *
  9512. * **Note:** This method doesn't set the "length" property of curried functions.
  9513. *
  9514. * @static
  9515. * @memberOf _
  9516. * @since 2.0.0
  9517. * @category Function
  9518. * @param {Function} func The function to curry.
  9519. * @param {number} [arity=func.length] The arity of `func`.
  9520. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9521. * @returns {Function} Returns the new curried function.
  9522. * @example
  9523. *
  9524. * var abc = function(a, b, c) {
  9525. * return [a, b, c];
  9526. * };
  9527. *
  9528. * var curried = _.curry(abc);
  9529. *
  9530. * curried(1)(2)(3);
  9531. * // => [1, 2, 3]
  9532. *
  9533. * curried(1, 2)(3);
  9534. * // => [1, 2, 3]
  9535. *
  9536. * curried(1, 2, 3);
  9537. * // => [1, 2, 3]
  9538. *
  9539. * // Curried with placeholders.
  9540. * curried(1)(_, 3)(2);
  9541. * // => [1, 2, 3]
  9542. */
  9543. function curry(func, arity, guard) {
  9544. arity = guard ? undefined : arity;
  9545. var result = createWrap(func, WRAP_CURRY_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9546. result.placeholder = curry.placeholder;
  9547. return result;
  9548. }
  9549. /**
  9550. * This method is like `_.curry` except that arguments are applied to `func`
  9551. * in the manner of `_.partialRight` instead of `_.partial`.
  9552. *
  9553. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  9554. * builds, may be used as a placeholder for provided arguments.
  9555. *
  9556. * **Note:** This method doesn't set the "length" property of curried functions.
  9557. *
  9558. * @static
  9559. * @memberOf _
  9560. * @since 3.0.0
  9561. * @category Function
  9562. * @param {Function} func The function to curry.
  9563. * @param {number} [arity=func.length] The arity of `func`.
  9564. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  9565. * @returns {Function} Returns the new curried function.
  9566. * @example
  9567. *
  9568. * var abc = function(a, b, c) {
  9569. * return [a, b, c];
  9570. * };
  9571. *
  9572. * var curried = _.curryRight(abc);
  9573. *
  9574. * curried(3)(2)(1);
  9575. * // => [1, 2, 3]
  9576. *
  9577. * curried(2, 3)(1);
  9578. * // => [1, 2, 3]
  9579. *
  9580. * curried(1, 2, 3);
  9581. * // => [1, 2, 3]
  9582. *
  9583. * // Curried with placeholders.
  9584. * curried(3)(1, _)(2);
  9585. * // => [1, 2, 3]
  9586. */
  9587. function curryRight(func, arity, guard) {
  9588. arity = guard ? undefined : arity;
  9589. var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined, undefined, undefined, undefined, undefined, arity);
  9590. result.placeholder = curryRight.placeholder;
  9591. return result;
  9592. }
  9593. /**
  9594. * Creates a debounced function that delays invoking `func` until after `wait`
  9595. * milliseconds have elapsed since the last time the debounced function was
  9596. * invoked. The debounced function comes with a `cancel` method to cancel
  9597. * delayed `func` invocations and a `flush` method to immediately invoke them.
  9598. * Provide `options` to indicate whether `func` should be invoked on the
  9599. * leading and/or trailing edge of the `wait` timeout. The `func` is invoked
  9600. * with the last arguments provided to the debounced function. Subsequent
  9601. * calls to the debounced function return the result of the last `func`
  9602. * invocation.
  9603. *
  9604. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  9605. * invoked on the trailing edge of the timeout only if the debounced function
  9606. * is invoked more than once during the `wait` timeout.
  9607. *
  9608. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  9609. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  9610. *
  9611. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  9612. * for details over the differences between `_.debounce` and `_.throttle`.
  9613. *
  9614. * @static
  9615. * @memberOf _
  9616. * @since 0.1.0
  9617. * @category Function
  9618. * @param {Function} func The function to debounce.
  9619. * @param {number} [wait=0] The number of milliseconds to delay.
  9620. * @param {Object} [options={}] The options object.
  9621. * @param {boolean} [options.leading=false]
  9622. * Specify invoking on the leading edge of the timeout.
  9623. * @param {number} [options.maxWait]
  9624. * The maximum time `func` is allowed to be delayed before it's invoked.
  9625. * @param {boolean} [options.trailing=true]
  9626. * Specify invoking on the trailing edge of the timeout.
  9627. * @returns {Function} Returns the new debounced function.
  9628. * @example
  9629. *
  9630. * // Avoid costly calculations while the window size is in flux.
  9631. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  9632. *
  9633. * // Invoke `sendMail` when clicked, debouncing subsequent calls.
  9634. * jQuery(element).on('click', _.debounce(sendMail, 300, {
  9635. * 'leading': true,
  9636. * 'trailing': false
  9637. * }));
  9638. *
  9639. * // Ensure `batchLog` is invoked once after 1 second of debounced calls.
  9640. * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 });
  9641. * var source = new EventSource('/stream');
  9642. * jQuery(source).on('message', debounced);
  9643. *
  9644. * // Cancel the trailing debounced invocation.
  9645. * jQuery(window).on('popstate', debounced.cancel);
  9646. */
  9647. function debounce(func, wait, options) {
  9648. var lastArgs,
  9649. lastThis,
  9650. maxWait,
  9651. result,
  9652. timerId,
  9653. lastCallTime,
  9654. lastInvokeTime = 0,
  9655. leading = false,
  9656. maxing = false,
  9657. trailing = true;
  9658. if (typeof func != 'function') {
  9659. throw new TypeError(FUNC_ERROR_TEXT);
  9660. }
  9661. wait = toNumber(wait) || 0;
  9662. if (isObject(options)) {
  9663. leading = !!options.leading;
  9664. maxing = 'maxWait' in options;
  9665. maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait;
  9666. trailing = 'trailing' in options ? !!options.trailing : trailing;
  9667. }
  9668. function invokeFunc(time) {
  9669. var args = lastArgs,
  9670. thisArg = lastThis;
  9671. lastArgs = lastThis = undefined;
  9672. lastInvokeTime = time;
  9673. result = func.apply(thisArg, args);
  9674. return result;
  9675. }
  9676. function leadingEdge(time) {
  9677. // Reset any `maxWait` timer.
  9678. lastInvokeTime = time;
  9679. // Start the timer for the trailing edge.
  9680. timerId = setTimeout(timerExpired, wait);
  9681. // Invoke the leading edge.
  9682. return leading ? invokeFunc(time) : result;
  9683. }
  9684. function remainingWait(time) {
  9685. var timeSinceLastCall = time - lastCallTime,
  9686. timeSinceLastInvoke = time - lastInvokeTime,
  9687. timeWaiting = wait - timeSinceLastCall;
  9688. return maxing
  9689. ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke)
  9690. : timeWaiting;
  9691. }
  9692. function shouldInvoke(time) {
  9693. var timeSinceLastCall = time - lastCallTime,
  9694. timeSinceLastInvoke = time - lastInvokeTime;
  9695. // Either this is the first call, activity has stopped and we're at the
  9696. // trailing edge, the system time has gone backwards and we're treating
  9697. // it as the trailing edge, or we've hit the `maxWait` limit.
  9698. return (lastCallTime === undefined || (timeSinceLastCall >= wait) ||
  9699. (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait));
  9700. }
  9701. function timerExpired() {
  9702. var time = now();
  9703. if (shouldInvoke(time)) {
  9704. return trailingEdge(time);
  9705. }
  9706. // Restart the timer.
  9707. timerId = setTimeout(timerExpired, remainingWait(time));
  9708. }
  9709. function trailingEdge(time) {
  9710. timerId = undefined;
  9711. // Only invoke if we have `lastArgs` which means `func` has been
  9712. // debounced at least once.
  9713. if (trailing && lastArgs) {
  9714. return invokeFunc(time);
  9715. }
  9716. lastArgs = lastThis = undefined;
  9717. return result;
  9718. }
  9719. function cancel() {
  9720. if (timerId !== undefined) {
  9721. clearTimeout(timerId);
  9722. }
  9723. lastInvokeTime = 0;
  9724. lastArgs = lastCallTime = lastThis = timerId = undefined;
  9725. }
  9726. function flush() {
  9727. return timerId === undefined ? result : trailingEdge(now());
  9728. }
  9729. function debounced() {
  9730. var time = now(),
  9731. isInvoking = shouldInvoke(time);
  9732. lastArgs = arguments;
  9733. lastThis = this;
  9734. lastCallTime = time;
  9735. if (isInvoking) {
  9736. if (timerId === undefined) {
  9737. return leadingEdge(lastCallTime);
  9738. }
  9739. if (maxing) {
  9740. // Handle invocations in a tight loop.
  9741. clearTimeout(timerId);
  9742. timerId = setTimeout(timerExpired, wait);
  9743. return invokeFunc(lastCallTime);
  9744. }
  9745. }
  9746. if (timerId === undefined) {
  9747. timerId = setTimeout(timerExpired, wait);
  9748. }
  9749. return result;
  9750. }
  9751. debounced.cancel = cancel;
  9752. debounced.flush = flush;
  9753. return debounced;
  9754. }
  9755. /**
  9756. * Defers invoking the `func` until the current call stack has cleared. Any
  9757. * additional arguments are provided to `func` when it's invoked.
  9758. *
  9759. * @static
  9760. * @memberOf _
  9761. * @since 0.1.0
  9762. * @category Function
  9763. * @param {Function} func The function to defer.
  9764. * @param {...*} [args] The arguments to invoke `func` with.
  9765. * @returns {number} Returns the timer id.
  9766. * @example
  9767. *
  9768. * _.defer(function(text) {
  9769. * console.log(text);
  9770. * }, 'deferred');
  9771. * // => Logs 'deferred' after one millisecond.
  9772. */
  9773. var defer = baseRest(function(func, args) {
  9774. return baseDelay(func, 1, args);
  9775. });
  9776. /**
  9777. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  9778. * provided to `func` when it's invoked.
  9779. *
  9780. * @static
  9781. * @memberOf _
  9782. * @since 0.1.0
  9783. * @category Function
  9784. * @param {Function} func The function to delay.
  9785. * @param {number} wait The number of milliseconds to delay invocation.
  9786. * @param {...*} [args] The arguments to invoke `func` with.
  9787. * @returns {number} Returns the timer id.
  9788. * @example
  9789. *
  9790. * _.delay(function(text) {
  9791. * console.log(text);
  9792. * }, 1000, 'later');
  9793. * // => Logs 'later' after one second.
  9794. */
  9795. var delay = baseRest(function(func, wait, args) {
  9796. return baseDelay(func, toNumber(wait) || 0, args);
  9797. });
  9798. /**
  9799. * Creates a function that invokes `func` with arguments reversed.
  9800. *
  9801. * @static
  9802. * @memberOf _
  9803. * @since 4.0.0
  9804. * @category Function
  9805. * @param {Function} func The function to flip arguments for.
  9806. * @returns {Function} Returns the new flipped function.
  9807. * @example
  9808. *
  9809. * var flipped = _.flip(function() {
  9810. * return _.toArray(arguments);
  9811. * });
  9812. *
  9813. * flipped('a', 'b', 'c', 'd');
  9814. * // => ['d', 'c', 'b', 'a']
  9815. */
  9816. function flip(func) {
  9817. return createWrap(func, WRAP_FLIP_FLAG);
  9818. }
  9819. /**
  9820. * Creates a function that memoizes the result of `func`. If `resolver` is
  9821. * provided, it determines the cache key for storing the result based on the
  9822. * arguments provided to the memoized function. By default, the first argument
  9823. * provided to the memoized function is used as the map cache key. The `func`
  9824. * is invoked with the `this` binding of the memoized function.
  9825. *
  9826. * **Note:** The cache is exposed as the `cache` property on the memoized
  9827. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  9828. * constructor with one whose instances implement the
  9829. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  9830. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  9831. *
  9832. * @static
  9833. * @memberOf _
  9834. * @since 0.1.0
  9835. * @category Function
  9836. * @param {Function} func The function to have its output memoized.
  9837. * @param {Function} [resolver] The function to resolve the cache key.
  9838. * @returns {Function} Returns the new memoized function.
  9839. * @example
  9840. *
  9841. * var object = { 'a': 1, 'b': 2 };
  9842. * var other = { 'c': 3, 'd': 4 };
  9843. *
  9844. * var values = _.memoize(_.values);
  9845. * values(object);
  9846. * // => [1, 2]
  9847. *
  9848. * values(other);
  9849. * // => [3, 4]
  9850. *
  9851. * object.a = 2;
  9852. * values(object);
  9853. * // => [1, 2]
  9854. *
  9855. * // Modify the result cache.
  9856. * values.cache.set(object, ['a', 'b']);
  9857. * values(object);
  9858. * // => ['a', 'b']
  9859. *
  9860. * // Replace `_.memoize.Cache`.
  9861. * _.memoize.Cache = WeakMap;
  9862. */
  9863. function memoize(func, resolver) {
  9864. if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) {
  9865. throw new TypeError(FUNC_ERROR_TEXT);
  9866. }
  9867. var memoized = function() {
  9868. var args = arguments,
  9869. key = resolver ? resolver.apply(this, args) : args[0],
  9870. cache = memoized.cache;
  9871. if (cache.has(key)) {
  9872. return cache.get(key);
  9873. }
  9874. var result = func.apply(this, args);
  9875. memoized.cache = cache.set(key, result) || cache;
  9876. return result;
  9877. };
  9878. memoized.cache = new (memoize.Cache || MapCache);
  9879. return memoized;
  9880. }
  9881. // Expose `MapCache`.
  9882. memoize.Cache = MapCache;
  9883. /**
  9884. * Creates a function that negates the result of the predicate `func`. The
  9885. * `func` predicate is invoked with the `this` binding and arguments of the
  9886. * created function.
  9887. *
  9888. * @static
  9889. * @memberOf _
  9890. * @since 3.0.0
  9891. * @category Function
  9892. * @param {Function} predicate The predicate to negate.
  9893. * @returns {Function} Returns the new negated function.
  9894. * @example
  9895. *
  9896. * function isEven(n) {
  9897. * return n % 2 == 0;
  9898. * }
  9899. *
  9900. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  9901. * // => [1, 3, 5]
  9902. */
  9903. function negate(predicate) {
  9904. if (typeof predicate != 'function') {
  9905. throw new TypeError(FUNC_ERROR_TEXT);
  9906. }
  9907. return function() {
  9908. var args = arguments;
  9909. switch (args.length) {
  9910. case 0: return !predicate.call(this);
  9911. case 1: return !predicate.call(this, args[0]);
  9912. case 2: return !predicate.call(this, args[0], args[1]);
  9913. case 3: return !predicate.call(this, args[0], args[1], args[2]);
  9914. }
  9915. return !predicate.apply(this, args);
  9916. };
  9917. }
  9918. /**
  9919. * Creates a function that is restricted to invoking `func` once. Repeat calls
  9920. * to the function return the value of the first invocation. The `func` is
  9921. * invoked with the `this` binding and arguments of the created function.
  9922. *
  9923. * @static
  9924. * @memberOf _
  9925. * @since 0.1.0
  9926. * @category Function
  9927. * @param {Function} func The function to restrict.
  9928. * @returns {Function} Returns the new restricted function.
  9929. * @example
  9930. *
  9931. * var initialize = _.once(createApplication);
  9932. * initialize();
  9933. * initialize();
  9934. * // => `createApplication` is invoked once
  9935. */
  9936. function once(func) {
  9937. return before(2, func);
  9938. }
  9939. /**
  9940. * Creates a function that invokes `func` with its arguments transformed.
  9941. *
  9942. * @static
  9943. * @since 4.0.0
  9944. * @memberOf _
  9945. * @category Function
  9946. * @param {Function} func The function to wrap.
  9947. * @param {...(Function|Function[])} [transforms=[_.identity]]
  9948. * The argument transforms.
  9949. * @returns {Function} Returns the new function.
  9950. * @example
  9951. *
  9952. * function doubled(n) {
  9953. * return n * 2;
  9954. * }
  9955. *
  9956. * function square(n) {
  9957. * return n * n;
  9958. * }
  9959. *
  9960. * var func = _.overArgs(function(x, y) {
  9961. * return [x, y];
  9962. * }, [square, doubled]);
  9963. *
  9964. * func(9, 3);
  9965. * // => [81, 6]
  9966. *
  9967. * func(10, 5);
  9968. * // => [100, 10]
  9969. */
  9970. var overArgs = castRest(function(func, transforms) {
  9971. transforms = (transforms.length == 1 && isArray(transforms[0]))
  9972. ? arrayMap(transforms[0], baseUnary(getIteratee()))
  9973. : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee()));
  9974. var funcsLength = transforms.length;
  9975. return baseRest(function(args) {
  9976. var index = -1,
  9977. length = nativeMin(args.length, funcsLength);
  9978. while (++index < length) {
  9979. args[index] = transforms[index].call(this, args[index]);
  9980. }
  9981. return apply(func, this, args);
  9982. });
  9983. });
  9984. /**
  9985. * Creates a function that invokes `func` with `partials` prepended to the
  9986. * arguments it receives. This method is like `_.bind` except it does **not**
  9987. * alter the `this` binding.
  9988. *
  9989. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  9990. * builds, may be used as a placeholder for partially applied arguments.
  9991. *
  9992. * **Note:** This method doesn't set the "length" property of partially
  9993. * applied functions.
  9994. *
  9995. * @static
  9996. * @memberOf _
  9997. * @since 0.2.0
  9998. * @category Function
  9999. * @param {Function} func The function to partially apply arguments to.
  10000. * @param {...*} [partials] The arguments to be partially applied.
  10001. * @returns {Function} Returns the new partially applied function.
  10002. * @example
  10003. *
  10004. * function greet(greeting, name) {
  10005. * return greeting + ' ' + name;
  10006. * }
  10007. *
  10008. * var sayHelloTo = _.partial(greet, 'hello');
  10009. * sayHelloTo('fred');
  10010. * // => 'hello fred'
  10011. *
  10012. * // Partially applied with placeholders.
  10013. * var greetFred = _.partial(greet, _, 'fred');
  10014. * greetFred('hi');
  10015. * // => 'hi fred'
  10016. */
  10017. var partial = baseRest(function(func, partials) {
  10018. var holders = replaceHolders(partials, getHolder(partial));
  10019. return createWrap(func, WRAP_PARTIAL_FLAG, undefined, partials, holders);
  10020. });
  10021. /**
  10022. * This method is like `_.partial` except that partially applied arguments
  10023. * are appended to the arguments it receives.
  10024. *
  10025. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  10026. * builds, may be used as a placeholder for partially applied arguments.
  10027. *
  10028. * **Note:** This method doesn't set the "length" property of partially
  10029. * applied functions.
  10030. *
  10031. * @static
  10032. * @memberOf _
  10033. * @since 1.0.0
  10034. * @category Function
  10035. * @param {Function} func The function to partially apply arguments to.
  10036. * @param {...*} [partials] The arguments to be partially applied.
  10037. * @returns {Function} Returns the new partially applied function.
  10038. * @example
  10039. *
  10040. * function greet(greeting, name) {
  10041. * return greeting + ' ' + name;
  10042. * }
  10043. *
  10044. * var greetFred = _.partialRight(greet, 'fred');
  10045. * greetFred('hi');
  10046. * // => 'hi fred'
  10047. *
  10048. * // Partially applied with placeholders.
  10049. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  10050. * sayHelloTo('fred');
  10051. * // => 'hello fred'
  10052. */
  10053. var partialRight = baseRest(function(func, partials) {
  10054. var holders = replaceHolders(partials, getHolder(partialRight));
  10055. return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined, partials, holders);
  10056. });
  10057. /**
  10058. * Creates a function that invokes `func` with arguments arranged according
  10059. * to the specified `indexes` where the argument value at the first index is
  10060. * provided as the first argument, the argument value at the second index is
  10061. * provided as the second argument, and so on.
  10062. *
  10063. * @static
  10064. * @memberOf _
  10065. * @since 3.0.0
  10066. * @category Function
  10067. * @param {Function} func The function to rearrange arguments for.
  10068. * @param {...(number|number[])} indexes The arranged argument indexes.
  10069. * @returns {Function} Returns the new function.
  10070. * @example
  10071. *
  10072. * var rearged = _.rearg(function(a, b, c) {
  10073. * return [a, b, c];
  10074. * }, [2, 0, 1]);
  10075. *
  10076. * rearged('b', 'c', 'a')
  10077. * // => ['a', 'b', 'c']
  10078. */
  10079. var rearg = flatRest(function(func, indexes) {
  10080. return createWrap(func, WRAP_REARG_FLAG, undefined, undefined, undefined, indexes);
  10081. });
  10082. /**
  10083. * Creates a function that invokes `func` with the `this` binding of the
  10084. * created function and arguments from `start` and beyond provided as
  10085. * an array.
  10086. *
  10087. * **Note:** This method is based on the
  10088. * [rest parameter](https://mdn.io/rest_parameters).
  10089. *
  10090. * @static
  10091. * @memberOf _
  10092. * @since 4.0.0
  10093. * @category Function
  10094. * @param {Function} func The function to apply a rest parameter to.
  10095. * @param {number} [start=func.length-1] The start position of the rest parameter.
  10096. * @returns {Function} Returns the new function.
  10097. * @example
  10098. *
  10099. * var say = _.rest(function(what, names) {
  10100. * return what + ' ' + _.initial(names).join(', ') +
  10101. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  10102. * });
  10103. *
  10104. * say('hello', 'fred', 'barney', 'pebbles');
  10105. * // => 'hello fred, barney, & pebbles'
  10106. */
  10107. function rest(func, start) {
  10108. if (typeof func != 'function') {
  10109. throw new TypeError(FUNC_ERROR_TEXT);
  10110. }
  10111. start = start === undefined ? start : toInteger(start);
  10112. return baseRest(func, start);
  10113. }
  10114. /**
  10115. * Creates a function that invokes `func` with the `this` binding of the
  10116. * create function and an array of arguments much like
  10117. * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply).
  10118. *
  10119. * **Note:** This method is based on the
  10120. * [spread operator](https://mdn.io/spread_operator).
  10121. *
  10122. * @static
  10123. * @memberOf _
  10124. * @since 3.2.0
  10125. * @category Function
  10126. * @param {Function} func The function to spread arguments over.
  10127. * @param {number} [start=0] The start position of the spread.
  10128. * @returns {Function} Returns the new function.
  10129. * @example
  10130. *
  10131. * var say = _.spread(function(who, what) {
  10132. * return who + ' says ' + what;
  10133. * });
  10134. *
  10135. * say(['fred', 'hello']);
  10136. * // => 'fred says hello'
  10137. *
  10138. * var numbers = Promise.all([
  10139. * Promise.resolve(40),
  10140. * Promise.resolve(36)
  10141. * ]);
  10142. *
  10143. * numbers.then(_.spread(function(x, y) {
  10144. * return x + y;
  10145. * }));
  10146. * // => a Promise of 76
  10147. */
  10148. function spread(func, start) {
  10149. if (typeof func != 'function') {
  10150. throw new TypeError(FUNC_ERROR_TEXT);
  10151. }
  10152. start = start == null ? 0 : nativeMax(toInteger(start), 0);
  10153. return baseRest(function(args) {
  10154. var array = args[start],
  10155. otherArgs = castSlice(args, 0, start);
  10156. if (array) {
  10157. arrayPush(otherArgs, array);
  10158. }
  10159. return apply(func, this, otherArgs);
  10160. });
  10161. }
  10162. /**
  10163. * Creates a throttled function that only invokes `func` at most once per
  10164. * every `wait` milliseconds. The throttled function comes with a `cancel`
  10165. * method to cancel delayed `func` invocations and a `flush` method to
  10166. * immediately invoke them. Provide `options` to indicate whether `func`
  10167. * should be invoked on the leading and/or trailing edge of the `wait`
  10168. * timeout. The `func` is invoked with the last arguments provided to the
  10169. * throttled function. Subsequent calls to the throttled function return the
  10170. * result of the last `func` invocation.
  10171. *
  10172. * **Note:** If `leading` and `trailing` options are `true`, `func` is
  10173. * invoked on the trailing edge of the timeout only if the throttled function
  10174. * is invoked more than once during the `wait` timeout.
  10175. *
  10176. * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
  10177. * until to the next tick, similar to `setTimeout` with a timeout of `0`.
  10178. *
  10179. * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/)
  10180. * for details over the differences between `_.throttle` and `_.debounce`.
  10181. *
  10182. * @static
  10183. * @memberOf _
  10184. * @since 0.1.0
  10185. * @category Function
  10186. * @param {Function} func The function to throttle.
  10187. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  10188. * @param {Object} [options={}] The options object.
  10189. * @param {boolean} [options.leading=true]
  10190. * Specify invoking on the leading edge of the timeout.
  10191. * @param {boolean} [options.trailing=true]
  10192. * Specify invoking on the trailing edge of the timeout.
  10193. * @returns {Function} Returns the new throttled function.
  10194. * @example
  10195. *
  10196. * // Avoid excessively updating the position while scrolling.
  10197. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  10198. *
  10199. * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes.
  10200. * var throttled = _.throttle(renewToken, 300000, { 'trailing': false });
  10201. * jQuery(element).on('click', throttled);
  10202. *
  10203. * // Cancel the trailing throttled invocation.
  10204. * jQuery(window).on('popstate', throttled.cancel);
  10205. */
  10206. function throttle(func, wait, options) {
  10207. var leading = true,
  10208. trailing = true;
  10209. if (typeof func != 'function') {
  10210. throw new TypeError(FUNC_ERROR_TEXT);
  10211. }
  10212. if (isObject(options)) {
  10213. leading = 'leading' in options ? !!options.leading : leading;
  10214. trailing = 'trailing' in options ? !!options.trailing : trailing;
  10215. }
  10216. return debounce(func, wait, {
  10217. 'leading': leading,
  10218. 'maxWait': wait,
  10219. 'trailing': trailing
  10220. });
  10221. }
  10222. /**
  10223. * Creates a function that accepts up to one argument, ignoring any
  10224. * additional arguments.
  10225. *
  10226. * @static
  10227. * @memberOf _
  10228. * @since 4.0.0
  10229. * @category Function
  10230. * @param {Function} func The function to cap arguments for.
  10231. * @returns {Function} Returns the new capped function.
  10232. * @example
  10233. *
  10234. * _.map(['6', '8', '10'], _.unary(parseInt));
  10235. * // => [6, 8, 10]
  10236. */
  10237. function unary(func) {
  10238. return ary(func, 1);
  10239. }
  10240. /**
  10241. * Creates a function that provides `value` to `wrapper` as its first
  10242. * argument. Any additional arguments provided to the function are appended
  10243. * to those provided to the `wrapper`. The wrapper is invoked with the `this`
  10244. * binding of the created function.
  10245. *
  10246. * @static
  10247. * @memberOf _
  10248. * @since 0.1.0
  10249. * @category Function
  10250. * @param {*} value The value to wrap.
  10251. * @param {Function} [wrapper=identity] The wrapper function.
  10252. * @returns {Function} Returns the new function.
  10253. * @example
  10254. *
  10255. * var p = _.wrap(_.escape, function(func, text) {
  10256. * return '<p>' + func(text) + '</p>';
  10257. * });
  10258. *
  10259. * p('fred, barney, & pebbles');
  10260. * // => '<p>fred, barney, &amp; pebbles</p>'
  10261. */
  10262. function wrap(value, wrapper) {
  10263. return partial(castFunction(wrapper), value);
  10264. }
  10265. /*------------------------------------------------------------------------*/
  10266. /**
  10267. * Casts `value` as an array if it's not one.
  10268. *
  10269. * @static
  10270. * @memberOf _
  10271. * @since 4.4.0
  10272. * @category Lang
  10273. * @param {*} value The value to inspect.
  10274. * @returns {Array} Returns the cast array.
  10275. * @example
  10276. *
  10277. * _.castArray(1);
  10278. * // => [1]
  10279. *
  10280. * _.castArray({ 'a': 1 });
  10281. * // => [{ 'a': 1 }]
  10282. *
  10283. * _.castArray('abc');
  10284. * // => ['abc']
  10285. *
  10286. * _.castArray(null);
  10287. * // => [null]
  10288. *
  10289. * _.castArray(undefined);
  10290. * // => [undefined]
  10291. *
  10292. * _.castArray();
  10293. * // => []
  10294. *
  10295. * var array = [1, 2, 3];
  10296. * console.log(_.castArray(array) === array);
  10297. * // => true
  10298. */
  10299. function castArray() {
  10300. if (!arguments.length) {
  10301. return [];
  10302. }
  10303. var value = arguments[0];
  10304. return isArray(value) ? value : [value];
  10305. }
  10306. /**
  10307. * Creates a shallow clone of `value`.
  10308. *
  10309. * **Note:** This method is loosely based on the
  10310. * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm)
  10311. * and supports cloning arrays, array buffers, booleans, date objects, maps,
  10312. * numbers, `Object` objects, regexes, sets, strings, symbols, and typed
  10313. * arrays. The own enumerable properties of `arguments` objects are cloned
  10314. * as plain objects. An empty object is returned for uncloneable values such
  10315. * as error objects, functions, DOM nodes, and WeakMaps.
  10316. *
  10317. * @static
  10318. * @memberOf _
  10319. * @since 0.1.0
  10320. * @category Lang
  10321. * @param {*} value The value to clone.
  10322. * @returns {*} Returns the cloned value.
  10323. * @see _.cloneDeep
  10324. * @example
  10325. *
  10326. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10327. *
  10328. * var shallow = _.clone(objects);
  10329. * console.log(shallow[0] === objects[0]);
  10330. * // => true
  10331. */
  10332. function clone(value) {
  10333. return baseClone(value, CLONE_SYMBOLS_FLAG);
  10334. }
  10335. /**
  10336. * This method is like `_.clone` except that it accepts `customizer` which
  10337. * is invoked to produce the cloned value. If `customizer` returns `undefined`,
  10338. * cloning is handled by the method instead. The `customizer` is invoked with
  10339. * up to four arguments; (value [, index|key, object, stack]).
  10340. *
  10341. * @static
  10342. * @memberOf _
  10343. * @since 4.0.0
  10344. * @category Lang
  10345. * @param {*} value The value to clone.
  10346. * @param {Function} [customizer] The function to customize cloning.
  10347. * @returns {*} Returns the cloned value.
  10348. * @see _.cloneDeepWith
  10349. * @example
  10350. *
  10351. * function customizer(value) {
  10352. * if (_.isElement(value)) {
  10353. * return value.cloneNode(false);
  10354. * }
  10355. * }
  10356. *
  10357. * var el = _.cloneWith(document.body, customizer);
  10358. *
  10359. * console.log(el === document.body);
  10360. * // => false
  10361. * console.log(el.nodeName);
  10362. * // => 'BODY'
  10363. * console.log(el.childNodes.length);
  10364. * // => 0
  10365. */
  10366. function cloneWith(value, customizer) {
  10367. customizer = typeof customizer == 'function' ? customizer : undefined;
  10368. return baseClone(value, CLONE_SYMBOLS_FLAG, customizer);
  10369. }
  10370. /**
  10371. * This method is like `_.clone` except that it recursively clones `value`.
  10372. *
  10373. * @static
  10374. * @memberOf _
  10375. * @since 1.0.0
  10376. * @category Lang
  10377. * @param {*} value The value to recursively clone.
  10378. * @returns {*} Returns the deep cloned value.
  10379. * @see _.clone
  10380. * @example
  10381. *
  10382. * var objects = [{ 'a': 1 }, { 'b': 2 }];
  10383. *
  10384. * var deep = _.cloneDeep(objects);
  10385. * console.log(deep[0] === objects[0]);
  10386. * // => false
  10387. */
  10388. function cloneDeep(value) {
  10389. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG);
  10390. }
  10391. /**
  10392. * This method is like `_.cloneWith` except that it recursively clones `value`.
  10393. *
  10394. * @static
  10395. * @memberOf _
  10396. * @since 4.0.0
  10397. * @category Lang
  10398. * @param {*} value The value to recursively clone.
  10399. * @param {Function} [customizer] The function to customize cloning.
  10400. * @returns {*} Returns the deep cloned value.
  10401. * @see _.cloneWith
  10402. * @example
  10403. *
  10404. * function customizer(value) {
  10405. * if (_.isElement(value)) {
  10406. * return value.cloneNode(true);
  10407. * }
  10408. * }
  10409. *
  10410. * var el = _.cloneDeepWith(document.body, customizer);
  10411. *
  10412. * console.log(el === document.body);
  10413. * // => false
  10414. * console.log(el.nodeName);
  10415. * // => 'BODY'
  10416. * console.log(el.childNodes.length);
  10417. * // => 20
  10418. */
  10419. function cloneDeepWith(value, customizer) {
  10420. customizer = typeof customizer == 'function' ? customizer : undefined;
  10421. return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer);
  10422. }
  10423. /**
  10424. * Checks if `object` conforms to `source` by invoking the predicate
  10425. * properties of `source` with the corresponding property values of `object`.
  10426. *
  10427. * **Note:** This method is equivalent to `_.conforms` when `source` is
  10428. * partially applied.
  10429. *
  10430. * @static
  10431. * @memberOf _
  10432. * @since 4.14.0
  10433. * @category Lang
  10434. * @param {Object} object The object to inspect.
  10435. * @param {Object} source The object of property predicates to conform to.
  10436. * @returns {boolean} Returns `true` if `object` conforms, else `false`.
  10437. * @example
  10438. *
  10439. * var object = { 'a': 1, 'b': 2 };
  10440. *
  10441. * _.conformsTo(object, { 'b': function(n) { return n > 1; } });
  10442. * // => true
  10443. *
  10444. * _.conformsTo(object, { 'b': function(n) { return n > 2; } });
  10445. * // => false
  10446. */
  10447. function conformsTo(object, source) {
  10448. return source == null || baseConformsTo(object, source, keys(source));
  10449. }
  10450. /**
  10451. * Performs a
  10452. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  10453. * comparison between two values to determine if they are equivalent.
  10454. *
  10455. * @static
  10456. * @memberOf _
  10457. * @since 4.0.0
  10458. * @category Lang
  10459. * @param {*} value The value to compare.
  10460. * @param {*} other The other value to compare.
  10461. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10462. * @example
  10463. *
  10464. * var object = { 'a': 1 };
  10465. * var other = { 'a': 1 };
  10466. *
  10467. * _.eq(object, object);
  10468. * // => true
  10469. *
  10470. * _.eq(object, other);
  10471. * // => false
  10472. *
  10473. * _.eq('a', 'a');
  10474. * // => true
  10475. *
  10476. * _.eq('a', Object('a'));
  10477. * // => false
  10478. *
  10479. * _.eq(NaN, NaN);
  10480. * // => true
  10481. */
  10482. function eq(value, other) {
  10483. return value === other || (value !== value && other !== other);
  10484. }
  10485. /**
  10486. * Checks if `value` is greater than `other`.
  10487. *
  10488. * @static
  10489. * @memberOf _
  10490. * @since 3.9.0
  10491. * @category Lang
  10492. * @param {*} value The value to compare.
  10493. * @param {*} other The other value to compare.
  10494. * @returns {boolean} Returns `true` if `value` is greater than `other`,
  10495. * else `false`.
  10496. * @see _.lt
  10497. * @example
  10498. *
  10499. * _.gt(3, 1);
  10500. * // => true
  10501. *
  10502. * _.gt(3, 3);
  10503. * // => false
  10504. *
  10505. * _.gt(1, 3);
  10506. * // => false
  10507. */
  10508. var gt = createRelationalOperation(baseGt);
  10509. /**
  10510. * Checks if `value` is greater than or equal to `other`.
  10511. *
  10512. * @static
  10513. * @memberOf _
  10514. * @since 3.9.0
  10515. * @category Lang
  10516. * @param {*} value The value to compare.
  10517. * @param {*} other The other value to compare.
  10518. * @returns {boolean} Returns `true` if `value` is greater than or equal to
  10519. * `other`, else `false`.
  10520. * @see _.lte
  10521. * @example
  10522. *
  10523. * _.gte(3, 1);
  10524. * // => true
  10525. *
  10526. * _.gte(3, 3);
  10527. * // => true
  10528. *
  10529. * _.gte(1, 3);
  10530. * // => false
  10531. */
  10532. var gte = createRelationalOperation(function(value, other) {
  10533. return value >= other;
  10534. });
  10535. /**
  10536. * Checks if `value` is likely an `arguments` object.
  10537. *
  10538. * @static
  10539. * @memberOf _
  10540. * @since 0.1.0
  10541. * @category Lang
  10542. * @param {*} value The value to check.
  10543. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  10544. * else `false`.
  10545. * @example
  10546. *
  10547. * _.isArguments(function() { return arguments; }());
  10548. * // => true
  10549. *
  10550. * _.isArguments([1, 2, 3]);
  10551. * // => false
  10552. */
  10553. var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) {
  10554. return isObjectLike(value) && hasOwnProperty.call(value, 'callee') &&
  10555. !propertyIsEnumerable.call(value, 'callee');
  10556. };
  10557. /**
  10558. * Checks if `value` is classified as an `Array` object.
  10559. *
  10560. * @static
  10561. * @memberOf _
  10562. * @since 0.1.0
  10563. * @category Lang
  10564. * @param {*} value The value to check.
  10565. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  10566. * @example
  10567. *
  10568. * _.isArray([1, 2, 3]);
  10569. * // => true
  10570. *
  10571. * _.isArray(document.body.children);
  10572. * // => false
  10573. *
  10574. * _.isArray('abc');
  10575. * // => false
  10576. *
  10577. * _.isArray(_.noop);
  10578. * // => false
  10579. */
  10580. var isArray = Array.isArray;
  10581. /**
  10582. * Checks if `value` is classified as an `ArrayBuffer` object.
  10583. *
  10584. * @static
  10585. * @memberOf _
  10586. * @since 4.3.0
  10587. * @category Lang
  10588. * @param {*} value The value to check.
  10589. * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`.
  10590. * @example
  10591. *
  10592. * _.isArrayBuffer(new ArrayBuffer(2));
  10593. * // => true
  10594. *
  10595. * _.isArrayBuffer(new Array(2));
  10596. * // => false
  10597. */
  10598. var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer;
  10599. /**
  10600. * Checks if `value` is array-like. A value is considered array-like if it's
  10601. * not a function and has a `value.length` that's an integer greater than or
  10602. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  10603. *
  10604. * @static
  10605. * @memberOf _
  10606. * @since 4.0.0
  10607. * @category Lang
  10608. * @param {*} value The value to check.
  10609. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  10610. * @example
  10611. *
  10612. * _.isArrayLike([1, 2, 3]);
  10613. * // => true
  10614. *
  10615. * _.isArrayLike(document.body.children);
  10616. * // => true
  10617. *
  10618. * _.isArrayLike('abc');
  10619. * // => true
  10620. *
  10621. * _.isArrayLike(_.noop);
  10622. * // => false
  10623. */
  10624. function isArrayLike(value) {
  10625. return value != null && isLength(value.length) && !isFunction(value);
  10626. }
  10627. /**
  10628. * This method is like `_.isArrayLike` except that it also checks if `value`
  10629. * is an object.
  10630. *
  10631. * @static
  10632. * @memberOf _
  10633. * @since 4.0.0
  10634. * @category Lang
  10635. * @param {*} value The value to check.
  10636. * @returns {boolean} Returns `true` if `value` is an array-like object,
  10637. * else `false`.
  10638. * @example
  10639. *
  10640. * _.isArrayLikeObject([1, 2, 3]);
  10641. * // => true
  10642. *
  10643. * _.isArrayLikeObject(document.body.children);
  10644. * // => true
  10645. *
  10646. * _.isArrayLikeObject('abc');
  10647. * // => false
  10648. *
  10649. * _.isArrayLikeObject(_.noop);
  10650. * // => false
  10651. */
  10652. function isArrayLikeObject(value) {
  10653. return isObjectLike(value) && isArrayLike(value);
  10654. }
  10655. /**
  10656. * Checks if `value` is classified as a boolean primitive or object.
  10657. *
  10658. * @static
  10659. * @memberOf _
  10660. * @since 0.1.0
  10661. * @category Lang
  10662. * @param {*} value The value to check.
  10663. * @returns {boolean} Returns `true` if `value` is a boolean, else `false`.
  10664. * @example
  10665. *
  10666. * _.isBoolean(false);
  10667. * // => true
  10668. *
  10669. * _.isBoolean(null);
  10670. * // => false
  10671. */
  10672. function isBoolean(value) {
  10673. return value === true || value === false ||
  10674. (isObjectLike(value) && baseGetTag(value) == boolTag);
  10675. }
  10676. /**
  10677. * Checks if `value` is a buffer.
  10678. *
  10679. * @static
  10680. * @memberOf _
  10681. * @since 4.3.0
  10682. * @category Lang
  10683. * @param {*} value The value to check.
  10684. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  10685. * @example
  10686. *
  10687. * _.isBuffer(new Buffer(2));
  10688. * // => true
  10689. *
  10690. * _.isBuffer(new Uint8Array(2));
  10691. * // => false
  10692. */
  10693. var isBuffer = nativeIsBuffer || stubFalse;
  10694. /**
  10695. * Checks if `value` is classified as a `Date` object.
  10696. *
  10697. * @static
  10698. * @memberOf _
  10699. * @since 0.1.0
  10700. * @category Lang
  10701. * @param {*} value The value to check.
  10702. * @returns {boolean} Returns `true` if `value` is a date object, else `false`.
  10703. * @example
  10704. *
  10705. * _.isDate(new Date);
  10706. * // => true
  10707. *
  10708. * _.isDate('Mon April 23 2012');
  10709. * // => false
  10710. */
  10711. var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate;
  10712. /**
  10713. * Checks if `value` is likely a DOM element.
  10714. *
  10715. * @static
  10716. * @memberOf _
  10717. * @since 0.1.0
  10718. * @category Lang
  10719. * @param {*} value The value to check.
  10720. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  10721. * @example
  10722. *
  10723. * _.isElement(document.body);
  10724. * // => true
  10725. *
  10726. * _.isElement('<body>');
  10727. * // => false
  10728. */
  10729. function isElement(value) {
  10730. return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value);
  10731. }
  10732. /**
  10733. * Checks if `value` is an empty object, collection, map, or set.
  10734. *
  10735. * Objects are considered empty if they have no own enumerable string keyed
  10736. * properties.
  10737. *
  10738. * Array-like values such as `arguments` objects, arrays, buffers, strings, or
  10739. * jQuery-like collections are considered empty if they have a `length` of `0`.
  10740. * Similarly, maps and sets are considered empty if they have a `size` of `0`.
  10741. *
  10742. * @static
  10743. * @memberOf _
  10744. * @since 0.1.0
  10745. * @category Lang
  10746. * @param {*} value The value to check.
  10747. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  10748. * @example
  10749. *
  10750. * _.isEmpty(null);
  10751. * // => true
  10752. *
  10753. * _.isEmpty(true);
  10754. * // => true
  10755. *
  10756. * _.isEmpty(1);
  10757. * // => true
  10758. *
  10759. * _.isEmpty([1, 2, 3]);
  10760. * // => false
  10761. *
  10762. * _.isEmpty({ 'a': 1 });
  10763. * // => false
  10764. */
  10765. function isEmpty(value) {
  10766. if (value == null) {
  10767. return true;
  10768. }
  10769. if (isArrayLike(value) &&
  10770. (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' ||
  10771. isBuffer(value) || isTypedArray(value) || isArguments(value))) {
  10772. return !value.length;
  10773. }
  10774. var tag = getTag(value);
  10775. if (tag == mapTag || tag == setTag) {
  10776. return !value.size;
  10777. }
  10778. if (isPrototype(value)) {
  10779. return !baseKeys(value).length;
  10780. }
  10781. for (var key in value) {
  10782. if (hasOwnProperty.call(value, key)) {
  10783. return false;
  10784. }
  10785. }
  10786. return true;
  10787. }
  10788. /**
  10789. * Performs a deep comparison between two values to determine if they are
  10790. * equivalent.
  10791. *
  10792. * **Note:** This method supports comparing arrays, array buffers, booleans,
  10793. * date objects, error objects, maps, numbers, `Object` objects, regexes,
  10794. * sets, strings, symbols, and typed arrays. `Object` objects are compared
  10795. * by their own, not inherited, enumerable properties. Functions and DOM
  10796. * nodes are compared by strict equality, i.e. `===`.
  10797. *
  10798. * @static
  10799. * @memberOf _
  10800. * @since 0.1.0
  10801. * @category Lang
  10802. * @param {*} value The value to compare.
  10803. * @param {*} other The other value to compare.
  10804. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10805. * @example
  10806. *
  10807. * var object = { 'a': 1 };
  10808. * var other = { 'a': 1 };
  10809. *
  10810. * _.isEqual(object, other);
  10811. * // => true
  10812. *
  10813. * object === other;
  10814. * // => false
  10815. */
  10816. function isEqual(value, other) {
  10817. return baseIsEqual(value, other);
  10818. }
  10819. /**
  10820. * This method is like `_.isEqual` except that it accepts `customizer` which
  10821. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  10822. * are handled by the method instead. The `customizer` is invoked with up to
  10823. * six arguments: (objValue, othValue [, index|key, object, other, stack]).
  10824. *
  10825. * @static
  10826. * @memberOf _
  10827. * @since 4.0.0
  10828. * @category Lang
  10829. * @param {*} value The value to compare.
  10830. * @param {*} other The other value to compare.
  10831. * @param {Function} [customizer] The function to customize comparisons.
  10832. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10833. * @example
  10834. *
  10835. * function isGreeting(value) {
  10836. * return /^h(?:i|ello)$/.test(value);
  10837. * }
  10838. *
  10839. * function customizer(objValue, othValue) {
  10840. * if (isGreeting(objValue) && isGreeting(othValue)) {
  10841. * return true;
  10842. * }
  10843. * }
  10844. *
  10845. * var array = ['hello', 'goodbye'];
  10846. * var other = ['hi', 'goodbye'];
  10847. *
  10848. * _.isEqualWith(array, other, customizer);
  10849. * // => true
  10850. */
  10851. function isEqualWith(value, other, customizer) {
  10852. customizer = typeof customizer == 'function' ? customizer : undefined;
  10853. var result = customizer ? customizer(value, other) : undefined;
  10854. return result === undefined ? baseIsEqual(value, other, undefined, customizer) : !!result;
  10855. }
  10856. /**
  10857. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  10858. * `SyntaxError`, `TypeError`, or `URIError` object.
  10859. *
  10860. * @static
  10861. * @memberOf _
  10862. * @since 3.0.0
  10863. * @category Lang
  10864. * @param {*} value The value to check.
  10865. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  10866. * @example
  10867. *
  10868. * _.isError(new Error);
  10869. * // => true
  10870. *
  10871. * _.isError(Error);
  10872. * // => false
  10873. */
  10874. function isError(value) {
  10875. if (!isObjectLike(value)) {
  10876. return false;
  10877. }
  10878. var tag = baseGetTag(value);
  10879. return tag == errorTag || tag == domExcTag ||
  10880. (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value));
  10881. }
  10882. /**
  10883. * Checks if `value` is a finite primitive number.
  10884. *
  10885. * **Note:** This method is based on
  10886. * [`Number.isFinite`](https://mdn.io/Number/isFinite).
  10887. *
  10888. * @static
  10889. * @memberOf _
  10890. * @since 0.1.0
  10891. * @category Lang
  10892. * @param {*} value The value to check.
  10893. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  10894. * @example
  10895. *
  10896. * _.isFinite(3);
  10897. * // => true
  10898. *
  10899. * _.isFinite(Number.MIN_VALUE);
  10900. * // => true
  10901. *
  10902. * _.isFinite(Infinity);
  10903. * // => false
  10904. *
  10905. * _.isFinite('3');
  10906. * // => false
  10907. */
  10908. function isFinite(value) {
  10909. return typeof value == 'number' && nativeIsFinite(value);
  10910. }
  10911. /**
  10912. * Checks if `value` is classified as a `Function` object.
  10913. *
  10914. * @static
  10915. * @memberOf _
  10916. * @since 0.1.0
  10917. * @category Lang
  10918. * @param {*} value The value to check.
  10919. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  10920. * @example
  10921. *
  10922. * _.isFunction(_);
  10923. * // => true
  10924. *
  10925. * _.isFunction(/abc/);
  10926. * // => false
  10927. */
  10928. function isFunction(value) {
  10929. if (!isObject(value)) {
  10930. return false;
  10931. }
  10932. // The use of `Object#toString` avoids issues with the `typeof` operator
  10933. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  10934. var tag = baseGetTag(value);
  10935. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  10936. }
  10937. /**
  10938. * Checks if `value` is an integer.
  10939. *
  10940. * **Note:** This method is based on
  10941. * [`Number.isInteger`](https://mdn.io/Number/isInteger).
  10942. *
  10943. * @static
  10944. * @memberOf _
  10945. * @since 4.0.0
  10946. * @category Lang
  10947. * @param {*} value The value to check.
  10948. * @returns {boolean} Returns `true` if `value` is an integer, else `false`.
  10949. * @example
  10950. *
  10951. * _.isInteger(3);
  10952. * // => true
  10953. *
  10954. * _.isInteger(Number.MIN_VALUE);
  10955. * // => false
  10956. *
  10957. * _.isInteger(Infinity);
  10958. * // => false
  10959. *
  10960. * _.isInteger('3');
  10961. * // => false
  10962. */
  10963. function isInteger(value) {
  10964. return typeof value == 'number' && value == toInteger(value);
  10965. }
  10966. /**
  10967. * Checks if `value` is a valid array-like length.
  10968. *
  10969. * **Note:** This method is loosely based on
  10970. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  10971. *
  10972. * @static
  10973. * @memberOf _
  10974. * @since 4.0.0
  10975. * @category Lang
  10976. * @param {*} value The value to check.
  10977. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  10978. * @example
  10979. *
  10980. * _.isLength(3);
  10981. * // => true
  10982. *
  10983. * _.isLength(Number.MIN_VALUE);
  10984. * // => false
  10985. *
  10986. * _.isLength(Infinity);
  10987. * // => false
  10988. *
  10989. * _.isLength('3');
  10990. * // => false
  10991. */
  10992. function isLength(value) {
  10993. return typeof value == 'number' &&
  10994. value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  10995. }
  10996. /**
  10997. * Checks if `value` is the
  10998. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  10999. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  11000. *
  11001. * @static
  11002. * @memberOf _
  11003. * @since 0.1.0
  11004. * @category Lang
  11005. * @param {*} value The value to check.
  11006. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  11007. * @example
  11008. *
  11009. * _.isObject({});
  11010. * // => true
  11011. *
  11012. * _.isObject([1, 2, 3]);
  11013. * // => true
  11014. *
  11015. * _.isObject(_.noop);
  11016. * // => true
  11017. *
  11018. * _.isObject(null);
  11019. * // => false
  11020. */
  11021. function isObject(value) {
  11022. var type = typeof value;
  11023. return value != null && (type == 'object' || type == 'function');
  11024. }
  11025. /**
  11026. * Checks if `value` is object-like. A value is object-like if it's not `null`
  11027. * and has a `typeof` result of "object".
  11028. *
  11029. * @static
  11030. * @memberOf _
  11031. * @since 4.0.0
  11032. * @category Lang
  11033. * @param {*} value The value to check.
  11034. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  11035. * @example
  11036. *
  11037. * _.isObjectLike({});
  11038. * // => true
  11039. *
  11040. * _.isObjectLike([1, 2, 3]);
  11041. * // => true
  11042. *
  11043. * _.isObjectLike(_.noop);
  11044. * // => false
  11045. *
  11046. * _.isObjectLike(null);
  11047. * // => false
  11048. */
  11049. function isObjectLike(value) {
  11050. return value != null && typeof value == 'object';
  11051. }
  11052. /**
  11053. * Checks if `value` is classified as a `Map` object.
  11054. *
  11055. * @static
  11056. * @memberOf _
  11057. * @since 4.3.0
  11058. * @category Lang
  11059. * @param {*} value The value to check.
  11060. * @returns {boolean} Returns `true` if `value` is a map, else `false`.
  11061. * @example
  11062. *
  11063. * _.isMap(new Map);
  11064. * // => true
  11065. *
  11066. * _.isMap(new WeakMap);
  11067. * // => false
  11068. */
  11069. var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap;
  11070. /**
  11071. * Performs a partial deep comparison between `object` and `source` to
  11072. * determine if `object` contains equivalent property values.
  11073. *
  11074. * **Note:** This method is equivalent to `_.matches` when `source` is
  11075. * partially applied.
  11076. *
  11077. * Partial comparisons will match empty array and empty object `source`
  11078. * values against any array or object value, respectively. See `_.isEqual`
  11079. * for a list of supported value comparisons.
  11080. *
  11081. * @static
  11082. * @memberOf _
  11083. * @since 3.0.0
  11084. * @category Lang
  11085. * @param {Object} object The object to inspect.
  11086. * @param {Object} source The object of property values to match.
  11087. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11088. * @example
  11089. *
  11090. * var object = { 'a': 1, 'b': 2 };
  11091. *
  11092. * _.isMatch(object, { 'b': 2 });
  11093. * // => true
  11094. *
  11095. * _.isMatch(object, { 'b': 1 });
  11096. * // => false
  11097. */
  11098. function isMatch(object, source) {
  11099. return object === source || baseIsMatch(object, source, getMatchData(source));
  11100. }
  11101. /**
  11102. * This method is like `_.isMatch` except that it accepts `customizer` which
  11103. * is invoked to compare values. If `customizer` returns `undefined`, comparisons
  11104. * are handled by the method instead. The `customizer` is invoked with five
  11105. * arguments: (objValue, srcValue, index|key, object, source).
  11106. *
  11107. * @static
  11108. * @memberOf _
  11109. * @since 4.0.0
  11110. * @category Lang
  11111. * @param {Object} object The object to inspect.
  11112. * @param {Object} source The object of property values to match.
  11113. * @param {Function} [customizer] The function to customize comparisons.
  11114. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  11115. * @example
  11116. *
  11117. * function isGreeting(value) {
  11118. * return /^h(?:i|ello)$/.test(value);
  11119. * }
  11120. *
  11121. * function customizer(objValue, srcValue) {
  11122. * if (isGreeting(objValue) && isGreeting(srcValue)) {
  11123. * return true;
  11124. * }
  11125. * }
  11126. *
  11127. * var object = { 'greeting': 'hello' };
  11128. * var source = { 'greeting': 'hi' };
  11129. *
  11130. * _.isMatchWith(object, source, customizer);
  11131. * // => true
  11132. */
  11133. function isMatchWith(object, source, customizer) {
  11134. customizer = typeof customizer == 'function' ? customizer : undefined;
  11135. return baseIsMatch(object, source, getMatchData(source), customizer);
  11136. }
  11137. /**
  11138. * Checks if `value` is `NaN`.
  11139. *
  11140. * **Note:** This method is based on
  11141. * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as
  11142. * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for
  11143. * `undefined` and other non-number values.
  11144. *
  11145. * @static
  11146. * @memberOf _
  11147. * @since 0.1.0
  11148. * @category Lang
  11149. * @param {*} value The value to check.
  11150. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  11151. * @example
  11152. *
  11153. * _.isNaN(NaN);
  11154. * // => true
  11155. *
  11156. * _.isNaN(new Number(NaN));
  11157. * // => true
  11158. *
  11159. * isNaN(undefined);
  11160. * // => true
  11161. *
  11162. * _.isNaN(undefined);
  11163. * // => false
  11164. */
  11165. function isNaN(value) {
  11166. // An `NaN` primitive is the only value that is not equal to itself.
  11167. // Perform the `toStringTag` check first to avoid errors with some
  11168. // ActiveX objects in IE.
  11169. return isNumber(value) && value != +value;
  11170. }
  11171. /**
  11172. * Checks if `value` is a pristine native function.
  11173. *
  11174. * **Note:** This method can't reliably detect native functions in the presence
  11175. * of the core-js package because core-js circumvents this kind of detection.
  11176. * Despite multiple requests, the core-js maintainer has made it clear: any
  11177. * attempt to fix the detection will be obstructed. As a result, we're left
  11178. * with little choice but to throw an error. Unfortunately, this also affects
  11179. * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill),
  11180. * which rely on core-js.
  11181. *
  11182. * @static
  11183. * @memberOf _
  11184. * @since 3.0.0
  11185. * @category Lang
  11186. * @param {*} value The value to check.
  11187. * @returns {boolean} Returns `true` if `value` is a native function,
  11188. * else `false`.
  11189. * @example
  11190. *
  11191. * _.isNative(Array.prototype.push);
  11192. * // => true
  11193. *
  11194. * _.isNative(_);
  11195. * // => false
  11196. */
  11197. function isNative(value) {
  11198. if (isMaskable(value)) {
  11199. throw new Error(CORE_ERROR_TEXT);
  11200. }
  11201. return baseIsNative(value);
  11202. }
  11203. /**
  11204. * Checks if `value` is `null`.
  11205. *
  11206. * @static
  11207. * @memberOf _
  11208. * @since 0.1.0
  11209. * @category Lang
  11210. * @param {*} value The value to check.
  11211. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  11212. * @example
  11213. *
  11214. * _.isNull(null);
  11215. * // => true
  11216. *
  11217. * _.isNull(void 0);
  11218. * // => false
  11219. */
  11220. function isNull(value) {
  11221. return value === null;
  11222. }
  11223. /**
  11224. * Checks if `value` is `null` or `undefined`.
  11225. *
  11226. * @static
  11227. * @memberOf _
  11228. * @since 4.0.0
  11229. * @category Lang
  11230. * @param {*} value The value to check.
  11231. * @returns {boolean} Returns `true` if `value` is nullish, else `false`.
  11232. * @example
  11233. *
  11234. * _.isNil(null);
  11235. * // => true
  11236. *
  11237. * _.isNil(void 0);
  11238. * // => true
  11239. *
  11240. * _.isNil(NaN);
  11241. * // => false
  11242. */
  11243. function isNil(value) {
  11244. return value == null;
  11245. }
  11246. /**
  11247. * Checks if `value` is classified as a `Number` primitive or object.
  11248. *
  11249. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are
  11250. * classified as numbers, use the `_.isFinite` method.
  11251. *
  11252. * @static
  11253. * @memberOf _
  11254. * @since 0.1.0
  11255. * @category Lang
  11256. * @param {*} value The value to check.
  11257. * @returns {boolean} Returns `true` if `value` is a number, else `false`.
  11258. * @example
  11259. *
  11260. * _.isNumber(3);
  11261. * // => true
  11262. *
  11263. * _.isNumber(Number.MIN_VALUE);
  11264. * // => true
  11265. *
  11266. * _.isNumber(Infinity);
  11267. * // => true
  11268. *
  11269. * _.isNumber('3');
  11270. * // => false
  11271. */
  11272. function isNumber(value) {
  11273. return typeof value == 'number' ||
  11274. (isObjectLike(value) && baseGetTag(value) == numberTag);
  11275. }
  11276. /**
  11277. * Checks if `value` is a plain object, that is, an object created by the
  11278. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  11279. *
  11280. * @static
  11281. * @memberOf _
  11282. * @since 0.8.0
  11283. * @category Lang
  11284. * @param {*} value The value to check.
  11285. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  11286. * @example
  11287. *
  11288. * function Foo() {
  11289. * this.a = 1;
  11290. * }
  11291. *
  11292. * _.isPlainObject(new Foo);
  11293. * // => false
  11294. *
  11295. * _.isPlainObject([1, 2, 3]);
  11296. * // => false
  11297. *
  11298. * _.isPlainObject({ 'x': 0, 'y': 0 });
  11299. * // => true
  11300. *
  11301. * _.isPlainObject(Object.create(null));
  11302. * // => true
  11303. */
  11304. function isPlainObject(value) {
  11305. if (!isObjectLike(value) || baseGetTag(value) != objectTag) {
  11306. return false;
  11307. }
  11308. var proto = getPrototype(value);
  11309. if (proto === null) {
  11310. return true;
  11311. }
  11312. var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor;
  11313. return typeof Ctor == 'function' && Ctor instanceof Ctor &&
  11314. funcToString.call(Ctor) == objectCtorString;
  11315. }
  11316. /**
  11317. * Checks if `value` is classified as a `RegExp` object.
  11318. *
  11319. * @static
  11320. * @memberOf _
  11321. * @since 0.1.0
  11322. * @category Lang
  11323. * @param {*} value The value to check.
  11324. * @returns {boolean} Returns `true` if `value` is a regexp, else `false`.
  11325. * @example
  11326. *
  11327. * _.isRegExp(/abc/);
  11328. * // => true
  11329. *
  11330. * _.isRegExp('/abc/');
  11331. * // => false
  11332. */
  11333. var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp;
  11334. /**
  11335. * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754
  11336. * double precision number which isn't the result of a rounded unsafe integer.
  11337. *
  11338. * **Note:** This method is based on
  11339. * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger).
  11340. *
  11341. * @static
  11342. * @memberOf _
  11343. * @since 4.0.0
  11344. * @category Lang
  11345. * @param {*} value The value to check.
  11346. * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`.
  11347. * @example
  11348. *
  11349. * _.isSafeInteger(3);
  11350. * // => true
  11351. *
  11352. * _.isSafeInteger(Number.MIN_VALUE);
  11353. * // => false
  11354. *
  11355. * _.isSafeInteger(Infinity);
  11356. * // => false
  11357. *
  11358. * _.isSafeInteger('3');
  11359. * // => false
  11360. */
  11361. function isSafeInteger(value) {
  11362. return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER;
  11363. }
  11364. /**
  11365. * Checks if `value` is classified as a `Set` object.
  11366. *
  11367. * @static
  11368. * @memberOf _
  11369. * @since 4.3.0
  11370. * @category Lang
  11371. * @param {*} value The value to check.
  11372. * @returns {boolean} Returns `true` if `value` is a set, else `false`.
  11373. * @example
  11374. *
  11375. * _.isSet(new Set);
  11376. * // => true
  11377. *
  11378. * _.isSet(new WeakSet);
  11379. * // => false
  11380. */
  11381. var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet;
  11382. /**
  11383. * Checks if `value` is classified as a `String` primitive or object.
  11384. *
  11385. * @static
  11386. * @since 0.1.0
  11387. * @memberOf _
  11388. * @category Lang
  11389. * @param {*} value The value to check.
  11390. * @returns {boolean} Returns `true` if `value` is a string, else `false`.
  11391. * @example
  11392. *
  11393. * _.isString('abc');
  11394. * // => true
  11395. *
  11396. * _.isString(1);
  11397. * // => false
  11398. */
  11399. function isString(value) {
  11400. return typeof value == 'string' ||
  11401. (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag);
  11402. }
  11403. /**
  11404. * Checks if `value` is classified as a `Symbol` primitive or object.
  11405. *
  11406. * @static
  11407. * @memberOf _
  11408. * @since 4.0.0
  11409. * @category Lang
  11410. * @param {*} value The value to check.
  11411. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  11412. * @example
  11413. *
  11414. * _.isSymbol(Symbol.iterator);
  11415. * // => true
  11416. *
  11417. * _.isSymbol('abc');
  11418. * // => false
  11419. */
  11420. function isSymbol(value) {
  11421. return typeof value == 'symbol' ||
  11422. (isObjectLike(value) && baseGetTag(value) == symbolTag);
  11423. }
  11424. /**
  11425. * Checks if `value` is classified as a typed array.
  11426. *
  11427. * @static
  11428. * @memberOf _
  11429. * @since 3.0.0
  11430. * @category Lang
  11431. * @param {*} value The value to check.
  11432. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  11433. * @example
  11434. *
  11435. * _.isTypedArray(new Uint8Array);
  11436. * // => true
  11437. *
  11438. * _.isTypedArray([]);
  11439. * // => false
  11440. */
  11441. var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray;
  11442. /**
  11443. * Checks if `value` is `undefined`.
  11444. *
  11445. * @static
  11446. * @since 0.1.0
  11447. * @memberOf _
  11448. * @category Lang
  11449. * @param {*} value The value to check.
  11450. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  11451. * @example
  11452. *
  11453. * _.isUndefined(void 0);
  11454. * // => true
  11455. *
  11456. * _.isUndefined(null);
  11457. * // => false
  11458. */
  11459. function isUndefined(value) {
  11460. return value === undefined;
  11461. }
  11462. /**
  11463. * Checks if `value` is classified as a `WeakMap` object.
  11464. *
  11465. * @static
  11466. * @memberOf _
  11467. * @since 4.3.0
  11468. * @category Lang
  11469. * @param {*} value The value to check.
  11470. * @returns {boolean} Returns `true` if `value` is a weak map, else `false`.
  11471. * @example
  11472. *
  11473. * _.isWeakMap(new WeakMap);
  11474. * // => true
  11475. *
  11476. * _.isWeakMap(new Map);
  11477. * // => false
  11478. */
  11479. function isWeakMap(value) {
  11480. return isObjectLike(value) && getTag(value) == weakMapTag;
  11481. }
  11482. /**
  11483. * Checks if `value` is classified as a `WeakSet` object.
  11484. *
  11485. * @static
  11486. * @memberOf _
  11487. * @since 4.3.0
  11488. * @category Lang
  11489. * @param {*} value The value to check.
  11490. * @returns {boolean} Returns `true` if `value` is a weak set, else `false`.
  11491. * @example
  11492. *
  11493. * _.isWeakSet(new WeakSet);
  11494. * // => true
  11495. *
  11496. * _.isWeakSet(new Set);
  11497. * // => false
  11498. */
  11499. function isWeakSet(value) {
  11500. return isObjectLike(value) && baseGetTag(value) == weakSetTag;
  11501. }
  11502. /**
  11503. * Checks if `value` is less than `other`.
  11504. *
  11505. * @static
  11506. * @memberOf _
  11507. * @since 3.9.0
  11508. * @category Lang
  11509. * @param {*} value The value to compare.
  11510. * @param {*} other The other value to compare.
  11511. * @returns {boolean} Returns `true` if `value` is less than `other`,
  11512. * else `false`.
  11513. * @see _.gt
  11514. * @example
  11515. *
  11516. * _.lt(1, 3);
  11517. * // => true
  11518. *
  11519. * _.lt(3, 3);
  11520. * // => false
  11521. *
  11522. * _.lt(3, 1);
  11523. * // => false
  11524. */
  11525. var lt = createRelationalOperation(baseLt);
  11526. /**
  11527. * Checks if `value` is less than or equal to `other`.
  11528. *
  11529. * @static
  11530. * @memberOf _
  11531. * @since 3.9.0
  11532. * @category Lang
  11533. * @param {*} value The value to compare.
  11534. * @param {*} other The other value to compare.
  11535. * @returns {boolean} Returns `true` if `value` is less than or equal to
  11536. * `other`, else `false`.
  11537. * @see _.gte
  11538. * @example
  11539. *
  11540. * _.lte(1, 3);
  11541. * // => true
  11542. *
  11543. * _.lte(3, 3);
  11544. * // => true
  11545. *
  11546. * _.lte(3, 1);
  11547. * // => false
  11548. */
  11549. var lte = createRelationalOperation(function(value, other) {
  11550. return value <= other;
  11551. });
  11552. /**
  11553. * Converts `value` to an array.
  11554. *
  11555. * @static
  11556. * @since 0.1.0
  11557. * @memberOf _
  11558. * @category Lang
  11559. * @param {*} value The value to convert.
  11560. * @returns {Array} Returns the converted array.
  11561. * @example
  11562. *
  11563. * _.toArray({ 'a': 1, 'b': 2 });
  11564. * // => [1, 2]
  11565. *
  11566. * _.toArray('abc');
  11567. * // => ['a', 'b', 'c']
  11568. *
  11569. * _.toArray(1);
  11570. * // => []
  11571. *
  11572. * _.toArray(null);
  11573. * // => []
  11574. */
  11575. function toArray(value) {
  11576. if (!value) {
  11577. return [];
  11578. }
  11579. if (isArrayLike(value)) {
  11580. return isString(value) ? stringToArray(value) : copyArray(value);
  11581. }
  11582. if (symIterator && value[symIterator]) {
  11583. return iteratorToArray(value[symIterator]());
  11584. }
  11585. var tag = getTag(value),
  11586. func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values);
  11587. return func(value);
  11588. }
  11589. /**
  11590. * Converts `value` to a finite number.
  11591. *
  11592. * @static
  11593. * @memberOf _
  11594. * @since 4.12.0
  11595. * @category Lang
  11596. * @param {*} value The value to convert.
  11597. * @returns {number} Returns the converted number.
  11598. * @example
  11599. *
  11600. * _.toFinite(3.2);
  11601. * // => 3.2
  11602. *
  11603. * _.toFinite(Number.MIN_VALUE);
  11604. * // => 5e-324
  11605. *
  11606. * _.toFinite(Infinity);
  11607. * // => 1.7976931348623157e+308
  11608. *
  11609. * _.toFinite('3.2');
  11610. * // => 3.2
  11611. */
  11612. function toFinite(value) {
  11613. if (!value) {
  11614. return value === 0 ? value : 0;
  11615. }
  11616. value = toNumber(value);
  11617. if (value === INFINITY || value === -INFINITY) {
  11618. var sign = (value < 0 ? -1 : 1);
  11619. return sign * MAX_INTEGER;
  11620. }
  11621. return value === value ? value : 0;
  11622. }
  11623. /**
  11624. * Converts `value` to an integer.
  11625. *
  11626. * **Note:** This method is loosely based on
  11627. * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger).
  11628. *
  11629. * @static
  11630. * @memberOf _
  11631. * @since 4.0.0
  11632. * @category Lang
  11633. * @param {*} value The value to convert.
  11634. * @returns {number} Returns the converted integer.
  11635. * @example
  11636. *
  11637. * _.toInteger(3.2);
  11638. * // => 3
  11639. *
  11640. * _.toInteger(Number.MIN_VALUE);
  11641. * // => 0
  11642. *
  11643. * _.toInteger(Infinity);
  11644. * // => 1.7976931348623157e+308
  11645. *
  11646. * _.toInteger('3.2');
  11647. * // => 3
  11648. */
  11649. function toInteger(value) {
  11650. var result = toFinite(value),
  11651. remainder = result % 1;
  11652. return result === result ? (remainder ? result - remainder : result) : 0;
  11653. }
  11654. /**
  11655. * Converts `value` to an integer suitable for use as the length of an
  11656. * array-like object.
  11657. *
  11658. * **Note:** This method is based on
  11659. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  11660. *
  11661. * @static
  11662. * @memberOf _
  11663. * @since 4.0.0
  11664. * @category Lang
  11665. * @param {*} value The value to convert.
  11666. * @returns {number} Returns the converted integer.
  11667. * @example
  11668. *
  11669. * _.toLength(3.2);
  11670. * // => 3
  11671. *
  11672. * _.toLength(Number.MIN_VALUE);
  11673. * // => 0
  11674. *
  11675. * _.toLength(Infinity);
  11676. * // => 4294967295
  11677. *
  11678. * _.toLength('3.2');
  11679. * // => 3
  11680. */
  11681. function toLength(value) {
  11682. return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0;
  11683. }
  11684. /**
  11685. * Converts `value` to a number.
  11686. *
  11687. * @static
  11688. * @memberOf _
  11689. * @since 4.0.0
  11690. * @category Lang
  11691. * @param {*} value The value to process.
  11692. * @returns {number} Returns the number.
  11693. * @example
  11694. *
  11695. * _.toNumber(3.2);
  11696. * // => 3.2
  11697. *
  11698. * _.toNumber(Number.MIN_VALUE);
  11699. * // => 5e-324
  11700. *
  11701. * _.toNumber(Infinity);
  11702. * // => Infinity
  11703. *
  11704. * _.toNumber('3.2');
  11705. * // => 3.2
  11706. */
  11707. function toNumber(value) {
  11708. if (typeof value == 'number') {
  11709. return value;
  11710. }
  11711. if (isSymbol(value)) {
  11712. return NAN;
  11713. }
  11714. if (isObject(value)) {
  11715. var other = typeof value.valueOf == 'function' ? value.valueOf() : value;
  11716. value = isObject(other) ? (other + '') : other;
  11717. }
  11718. if (typeof value != 'string') {
  11719. return value === 0 ? value : +value;
  11720. }
  11721. value = baseTrim(value);
  11722. var isBinary = reIsBinary.test(value);
  11723. return (isBinary || reIsOctal.test(value))
  11724. ? freeParseInt(value.slice(2), isBinary ? 2 : 8)
  11725. : (reIsBadHex.test(value) ? NAN : +value);
  11726. }
  11727. /**
  11728. * Converts `value` to a plain object flattening inherited enumerable string
  11729. * keyed properties of `value` to own properties of the plain object.
  11730. *
  11731. * @static
  11732. * @memberOf _
  11733. * @since 3.0.0
  11734. * @category Lang
  11735. * @param {*} value The value to convert.
  11736. * @returns {Object} Returns the converted plain object.
  11737. * @example
  11738. *
  11739. * function Foo() {
  11740. * this.b = 2;
  11741. * }
  11742. *
  11743. * Foo.prototype.c = 3;
  11744. *
  11745. * _.assign({ 'a': 1 }, new Foo);
  11746. * // => { 'a': 1, 'b': 2 }
  11747. *
  11748. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  11749. * // => { 'a': 1, 'b': 2, 'c': 3 }
  11750. */
  11751. function toPlainObject(value) {
  11752. return copyObject(value, keysIn(value));
  11753. }
  11754. /**
  11755. * Converts `value` to a safe integer. A safe integer can be compared and
  11756. * represented correctly.
  11757. *
  11758. * @static
  11759. * @memberOf _
  11760. * @since 4.0.0
  11761. * @category Lang
  11762. * @param {*} value The value to convert.
  11763. * @returns {number} Returns the converted integer.
  11764. * @example
  11765. *
  11766. * _.toSafeInteger(3.2);
  11767. * // => 3
  11768. *
  11769. * _.toSafeInteger(Number.MIN_VALUE);
  11770. * // => 0
  11771. *
  11772. * _.toSafeInteger(Infinity);
  11773. * // => 9007199254740991
  11774. *
  11775. * _.toSafeInteger('3.2');
  11776. * // => 3
  11777. */
  11778. function toSafeInteger(value) {
  11779. return value
  11780. ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER)
  11781. : (value === 0 ? value : 0);
  11782. }
  11783. /**
  11784. * Converts `value` to a string. An empty string is returned for `null`
  11785. * and `undefined` values. The sign of `-0` is preserved.
  11786. *
  11787. * @static
  11788. * @memberOf _
  11789. * @since 4.0.0
  11790. * @category Lang
  11791. * @param {*} value The value to convert.
  11792. * @returns {string} Returns the converted string.
  11793. * @example
  11794. *
  11795. * _.toString(null);
  11796. * // => ''
  11797. *
  11798. * _.toString(-0);
  11799. * // => '-0'
  11800. *
  11801. * _.toString([1, 2, 3]);
  11802. * // => '1,2,3'
  11803. */
  11804. function toString(value) {
  11805. return value == null ? '' : baseToString(value);
  11806. }
  11807. /*------------------------------------------------------------------------*/
  11808. /**
  11809. * Assigns own enumerable string keyed properties of source objects to the
  11810. * destination object. Source objects are applied from left to right.
  11811. * Subsequent sources overwrite property assignments of previous sources.
  11812. *
  11813. * **Note:** This method mutates `object` and is loosely based on
  11814. * [`Object.assign`](https://mdn.io/Object/assign).
  11815. *
  11816. * @static
  11817. * @memberOf _
  11818. * @since 0.10.0
  11819. * @category Object
  11820. * @param {Object} object The destination object.
  11821. * @param {...Object} [sources] The source objects.
  11822. * @returns {Object} Returns `object`.
  11823. * @see _.assignIn
  11824. * @example
  11825. *
  11826. * function Foo() {
  11827. * this.a = 1;
  11828. * }
  11829. *
  11830. * function Bar() {
  11831. * this.c = 3;
  11832. * }
  11833. *
  11834. * Foo.prototype.b = 2;
  11835. * Bar.prototype.d = 4;
  11836. *
  11837. * _.assign({ 'a': 0 }, new Foo, new Bar);
  11838. * // => { 'a': 1, 'c': 3 }
  11839. */
  11840. var assign = createAssigner(function(object, source) {
  11841. if (isPrototype(source) || isArrayLike(source)) {
  11842. copyObject(source, keys(source), object);
  11843. return;
  11844. }
  11845. for (var key in source) {
  11846. if (hasOwnProperty.call(source, key)) {
  11847. assignValue(object, key, source[key]);
  11848. }
  11849. }
  11850. });
  11851. /**
  11852. * This method is like `_.assign` except that it iterates over own and
  11853. * inherited source properties.
  11854. *
  11855. * **Note:** This method mutates `object`.
  11856. *
  11857. * @static
  11858. * @memberOf _
  11859. * @since 4.0.0
  11860. * @alias extend
  11861. * @category Object
  11862. * @param {Object} object The destination object.
  11863. * @param {...Object} [sources] The source objects.
  11864. * @returns {Object} Returns `object`.
  11865. * @see _.assign
  11866. * @example
  11867. *
  11868. * function Foo() {
  11869. * this.a = 1;
  11870. * }
  11871. *
  11872. * function Bar() {
  11873. * this.c = 3;
  11874. * }
  11875. *
  11876. * Foo.prototype.b = 2;
  11877. * Bar.prototype.d = 4;
  11878. *
  11879. * _.assignIn({ 'a': 0 }, new Foo, new Bar);
  11880. * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 }
  11881. */
  11882. var assignIn = createAssigner(function(object, source) {
  11883. copyObject(source, keysIn(source), object);
  11884. });
  11885. /**
  11886. * This method is like `_.assignIn` except that it accepts `customizer`
  11887. * which is invoked to produce the assigned values. If `customizer` returns
  11888. * `undefined`, assignment is handled by the method instead. The `customizer`
  11889. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11890. *
  11891. * **Note:** This method mutates `object`.
  11892. *
  11893. * @static
  11894. * @memberOf _
  11895. * @since 4.0.0
  11896. * @alias extendWith
  11897. * @category Object
  11898. * @param {Object} object The destination object.
  11899. * @param {...Object} sources The source objects.
  11900. * @param {Function} [customizer] The function to customize assigned values.
  11901. * @returns {Object} Returns `object`.
  11902. * @see _.assignWith
  11903. * @example
  11904. *
  11905. * function customizer(objValue, srcValue) {
  11906. * return _.isUndefined(objValue) ? srcValue : objValue;
  11907. * }
  11908. *
  11909. * var defaults = _.partialRight(_.assignInWith, customizer);
  11910. *
  11911. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11912. * // => { 'a': 1, 'b': 2 }
  11913. */
  11914. var assignInWith = createAssigner(function(object, source, srcIndex, customizer) {
  11915. copyObject(source, keysIn(source), object, customizer);
  11916. });
  11917. /**
  11918. * This method is like `_.assign` except that it accepts `customizer`
  11919. * which is invoked to produce the assigned values. If `customizer` returns
  11920. * `undefined`, assignment is handled by the method instead. The `customizer`
  11921. * is invoked with five arguments: (objValue, srcValue, key, object, source).
  11922. *
  11923. * **Note:** This method mutates `object`.
  11924. *
  11925. * @static
  11926. * @memberOf _
  11927. * @since 4.0.0
  11928. * @category Object
  11929. * @param {Object} object The destination object.
  11930. * @param {...Object} sources The source objects.
  11931. * @param {Function} [customizer] The function to customize assigned values.
  11932. * @returns {Object} Returns `object`.
  11933. * @see _.assignInWith
  11934. * @example
  11935. *
  11936. * function customizer(objValue, srcValue) {
  11937. * return _.isUndefined(objValue) ? srcValue : objValue;
  11938. * }
  11939. *
  11940. * var defaults = _.partialRight(_.assignWith, customizer);
  11941. *
  11942. * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  11943. * // => { 'a': 1, 'b': 2 }
  11944. */
  11945. var assignWith = createAssigner(function(object, source, srcIndex, customizer) {
  11946. copyObject(source, keys(source), object, customizer);
  11947. });
  11948. /**
  11949. * Creates an array of values corresponding to `paths` of `object`.
  11950. *
  11951. * @static
  11952. * @memberOf _
  11953. * @since 1.0.0
  11954. * @category Object
  11955. * @param {Object} object The object to iterate over.
  11956. * @param {...(string|string[])} [paths] The property paths to pick.
  11957. * @returns {Array} Returns the picked values.
  11958. * @example
  11959. *
  11960. * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] };
  11961. *
  11962. * _.at(object, ['a[0].b.c', 'a[1]']);
  11963. * // => [3, 4]
  11964. */
  11965. var at = flatRest(baseAt);
  11966. /**
  11967. * Creates an object that inherits from the `prototype` object. If a
  11968. * `properties` object is given, its own enumerable string keyed properties
  11969. * are assigned to the created object.
  11970. *
  11971. * @static
  11972. * @memberOf _
  11973. * @since 2.3.0
  11974. * @category Object
  11975. * @param {Object} prototype The object to inherit from.
  11976. * @param {Object} [properties] The properties to assign to the object.
  11977. * @returns {Object} Returns the new object.
  11978. * @example
  11979. *
  11980. * function Shape() {
  11981. * this.x = 0;
  11982. * this.y = 0;
  11983. * }
  11984. *
  11985. * function Circle() {
  11986. * Shape.call(this);
  11987. * }
  11988. *
  11989. * Circle.prototype = _.create(Shape.prototype, {
  11990. * 'constructor': Circle
  11991. * });
  11992. *
  11993. * var circle = new Circle;
  11994. * circle instanceof Circle;
  11995. * // => true
  11996. *
  11997. * circle instanceof Shape;
  11998. * // => true
  11999. */
  12000. function create(prototype, properties) {
  12001. var result = baseCreate(prototype);
  12002. return properties == null ? result : baseAssign(result, properties);
  12003. }
  12004. /**
  12005. * Assigns own and inherited enumerable string keyed properties of source
  12006. * objects to the destination object for all destination properties that
  12007. * resolve to `undefined`. Source objects are applied from left to right.
  12008. * Once a property is set, additional values of the same property are ignored.
  12009. *
  12010. * **Note:** This method mutates `object`.
  12011. *
  12012. * @static
  12013. * @since 0.1.0
  12014. * @memberOf _
  12015. * @category Object
  12016. * @param {Object} object The destination object.
  12017. * @param {...Object} [sources] The source objects.
  12018. * @returns {Object} Returns `object`.
  12019. * @see _.defaultsDeep
  12020. * @example
  12021. *
  12022. * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 });
  12023. * // => { 'a': 1, 'b': 2 }
  12024. */
  12025. var defaults = baseRest(function(object, sources) {
  12026. object = Object(object);
  12027. var index = -1;
  12028. var length = sources.length;
  12029. var guard = length > 2 ? sources[2] : undefined;
  12030. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  12031. length = 1;
  12032. }
  12033. while (++index < length) {
  12034. var source = sources[index];
  12035. var props = keysIn(source);
  12036. var propsIndex = -1;
  12037. var propsLength = props.length;
  12038. while (++propsIndex < propsLength) {
  12039. var key = props[propsIndex];
  12040. var value = object[key];
  12041. if (value === undefined ||
  12042. (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) {
  12043. object[key] = source[key];
  12044. }
  12045. }
  12046. }
  12047. return object;
  12048. });
  12049. /**
  12050. * This method is like `_.defaults` except that it recursively assigns
  12051. * default properties.
  12052. *
  12053. * **Note:** This method mutates `object`.
  12054. *
  12055. * @static
  12056. * @memberOf _
  12057. * @since 3.10.0
  12058. * @category Object
  12059. * @param {Object} object The destination object.
  12060. * @param {...Object} [sources] The source objects.
  12061. * @returns {Object} Returns `object`.
  12062. * @see _.defaults
  12063. * @example
  12064. *
  12065. * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } });
  12066. * // => { 'a': { 'b': 2, 'c': 3 } }
  12067. */
  12068. var defaultsDeep = baseRest(function(args) {
  12069. args.push(undefined, customDefaultsMerge);
  12070. return apply(mergeWith, undefined, args);
  12071. });
  12072. /**
  12073. * This method is like `_.find` except that it returns the key of the first
  12074. * element `predicate` returns truthy for instead of the element itself.
  12075. *
  12076. * @static
  12077. * @memberOf _
  12078. * @since 1.1.0
  12079. * @category Object
  12080. * @param {Object} object The object to inspect.
  12081. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12082. * @returns {string|undefined} Returns the key of the matched element,
  12083. * else `undefined`.
  12084. * @example
  12085. *
  12086. * var users = {
  12087. * 'barney': { 'age': 36, 'active': true },
  12088. * 'fred': { 'age': 40, 'active': false },
  12089. * 'pebbles': { 'age': 1, 'active': true }
  12090. * };
  12091. *
  12092. * _.findKey(users, function(o) { return o.age < 40; });
  12093. * // => 'barney' (iteration order is not guaranteed)
  12094. *
  12095. * // The `_.matches` iteratee shorthand.
  12096. * _.findKey(users, { 'age': 1, 'active': true });
  12097. * // => 'pebbles'
  12098. *
  12099. * // The `_.matchesProperty` iteratee shorthand.
  12100. * _.findKey(users, ['active', false]);
  12101. * // => 'fred'
  12102. *
  12103. * // The `_.property` iteratee shorthand.
  12104. * _.findKey(users, 'active');
  12105. * // => 'barney'
  12106. */
  12107. function findKey(object, predicate) {
  12108. return baseFindKey(object, getIteratee(predicate, 3), baseForOwn);
  12109. }
  12110. /**
  12111. * This method is like `_.findKey` except that it iterates over elements of
  12112. * a collection in the opposite order.
  12113. *
  12114. * @static
  12115. * @memberOf _
  12116. * @since 2.0.0
  12117. * @category Object
  12118. * @param {Object} object The object to inspect.
  12119. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  12120. * @returns {string|undefined} Returns the key of the matched element,
  12121. * else `undefined`.
  12122. * @example
  12123. *
  12124. * var users = {
  12125. * 'barney': { 'age': 36, 'active': true },
  12126. * 'fred': { 'age': 40, 'active': false },
  12127. * 'pebbles': { 'age': 1, 'active': true }
  12128. * };
  12129. *
  12130. * _.findLastKey(users, function(o) { return o.age < 40; });
  12131. * // => returns 'pebbles' assuming `_.findKey` returns 'barney'
  12132. *
  12133. * // The `_.matches` iteratee shorthand.
  12134. * _.findLastKey(users, { 'age': 36, 'active': true });
  12135. * // => 'barney'
  12136. *
  12137. * // The `_.matchesProperty` iteratee shorthand.
  12138. * _.findLastKey(users, ['active', false]);
  12139. * // => 'fred'
  12140. *
  12141. * // The `_.property` iteratee shorthand.
  12142. * _.findLastKey(users, 'active');
  12143. * // => 'pebbles'
  12144. */
  12145. function findLastKey(object, predicate) {
  12146. return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight);
  12147. }
  12148. /**
  12149. * Iterates over own and inherited enumerable string keyed properties of an
  12150. * object and invokes `iteratee` for each property. The iteratee is invoked
  12151. * with three arguments: (value, key, object). Iteratee functions may exit
  12152. * iteration early by explicitly returning `false`.
  12153. *
  12154. * @static
  12155. * @memberOf _
  12156. * @since 0.3.0
  12157. * @category Object
  12158. * @param {Object} object The object to iterate over.
  12159. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12160. * @returns {Object} Returns `object`.
  12161. * @see _.forInRight
  12162. * @example
  12163. *
  12164. * function Foo() {
  12165. * this.a = 1;
  12166. * this.b = 2;
  12167. * }
  12168. *
  12169. * Foo.prototype.c = 3;
  12170. *
  12171. * _.forIn(new Foo, function(value, key) {
  12172. * console.log(key);
  12173. * });
  12174. * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed).
  12175. */
  12176. function forIn(object, iteratee) {
  12177. return object == null
  12178. ? object
  12179. : baseFor(object, getIteratee(iteratee, 3), keysIn);
  12180. }
  12181. /**
  12182. * This method is like `_.forIn` except that it iterates over properties of
  12183. * `object` in the opposite order.
  12184. *
  12185. * @static
  12186. * @memberOf _
  12187. * @since 2.0.0
  12188. * @category Object
  12189. * @param {Object} object The object to iterate over.
  12190. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12191. * @returns {Object} Returns `object`.
  12192. * @see _.forIn
  12193. * @example
  12194. *
  12195. * function Foo() {
  12196. * this.a = 1;
  12197. * this.b = 2;
  12198. * }
  12199. *
  12200. * Foo.prototype.c = 3;
  12201. *
  12202. * _.forInRight(new Foo, function(value, key) {
  12203. * console.log(key);
  12204. * });
  12205. * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'.
  12206. */
  12207. function forInRight(object, iteratee) {
  12208. return object == null
  12209. ? object
  12210. : baseForRight(object, getIteratee(iteratee, 3), keysIn);
  12211. }
  12212. /**
  12213. * Iterates over own enumerable string keyed properties of an object and
  12214. * invokes `iteratee` for each property. The iteratee is invoked with three
  12215. * arguments: (value, key, object). Iteratee functions may exit iteration
  12216. * early by explicitly returning `false`.
  12217. *
  12218. * @static
  12219. * @memberOf _
  12220. * @since 0.3.0
  12221. * @category Object
  12222. * @param {Object} object The object to iterate over.
  12223. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12224. * @returns {Object} Returns `object`.
  12225. * @see _.forOwnRight
  12226. * @example
  12227. *
  12228. * function Foo() {
  12229. * this.a = 1;
  12230. * this.b = 2;
  12231. * }
  12232. *
  12233. * Foo.prototype.c = 3;
  12234. *
  12235. * _.forOwn(new Foo, function(value, key) {
  12236. * console.log(key);
  12237. * });
  12238. * // => Logs 'a' then 'b' (iteration order is not guaranteed).
  12239. */
  12240. function forOwn(object, iteratee) {
  12241. return object && baseForOwn(object, getIteratee(iteratee, 3));
  12242. }
  12243. /**
  12244. * This method is like `_.forOwn` except that it iterates over properties of
  12245. * `object` in the opposite order.
  12246. *
  12247. * @static
  12248. * @memberOf _
  12249. * @since 2.0.0
  12250. * @category Object
  12251. * @param {Object} object The object to iterate over.
  12252. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12253. * @returns {Object} Returns `object`.
  12254. * @see _.forOwn
  12255. * @example
  12256. *
  12257. * function Foo() {
  12258. * this.a = 1;
  12259. * this.b = 2;
  12260. * }
  12261. *
  12262. * Foo.prototype.c = 3;
  12263. *
  12264. * _.forOwnRight(new Foo, function(value, key) {
  12265. * console.log(key);
  12266. * });
  12267. * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'.
  12268. */
  12269. function forOwnRight(object, iteratee) {
  12270. return object && baseForOwnRight(object, getIteratee(iteratee, 3));
  12271. }
  12272. /**
  12273. * Creates an array of function property names from own enumerable properties
  12274. * of `object`.
  12275. *
  12276. * @static
  12277. * @since 0.1.0
  12278. * @memberOf _
  12279. * @category Object
  12280. * @param {Object} object The object to inspect.
  12281. * @returns {Array} Returns the function names.
  12282. * @see _.functionsIn
  12283. * @example
  12284. *
  12285. * function Foo() {
  12286. * this.a = _.constant('a');
  12287. * this.b = _.constant('b');
  12288. * }
  12289. *
  12290. * Foo.prototype.c = _.constant('c');
  12291. *
  12292. * _.functions(new Foo);
  12293. * // => ['a', 'b']
  12294. */
  12295. function functions(object) {
  12296. return object == null ? [] : baseFunctions(object, keys(object));
  12297. }
  12298. /**
  12299. * Creates an array of function property names from own and inherited
  12300. * enumerable properties of `object`.
  12301. *
  12302. * @static
  12303. * @memberOf _
  12304. * @since 4.0.0
  12305. * @category Object
  12306. * @param {Object} object The object to inspect.
  12307. * @returns {Array} Returns the function names.
  12308. * @see _.functions
  12309. * @example
  12310. *
  12311. * function Foo() {
  12312. * this.a = _.constant('a');
  12313. * this.b = _.constant('b');
  12314. * }
  12315. *
  12316. * Foo.prototype.c = _.constant('c');
  12317. *
  12318. * _.functionsIn(new Foo);
  12319. * // => ['a', 'b', 'c']
  12320. */
  12321. function functionsIn(object) {
  12322. return object == null ? [] : baseFunctions(object, keysIn(object));
  12323. }
  12324. /**
  12325. * Gets the value at `path` of `object`. If the resolved value is
  12326. * `undefined`, the `defaultValue` is returned in its place.
  12327. *
  12328. * @static
  12329. * @memberOf _
  12330. * @since 3.7.0
  12331. * @category Object
  12332. * @param {Object} object The object to query.
  12333. * @param {Array|string} path The path of the property to get.
  12334. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12335. * @returns {*} Returns the resolved value.
  12336. * @example
  12337. *
  12338. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12339. *
  12340. * _.get(object, 'a[0].b.c');
  12341. * // => 3
  12342. *
  12343. * _.get(object, ['a', '0', 'b', 'c']);
  12344. * // => 3
  12345. *
  12346. * _.get(object, 'a.b.c', 'default');
  12347. * // => 'default'
  12348. */
  12349. function get(object, path, defaultValue) {
  12350. var result = object == null ? undefined : baseGet(object, path);
  12351. return result === undefined ? defaultValue : result;
  12352. }
  12353. /**
  12354. * Checks if `path` is a direct property of `object`.
  12355. *
  12356. * @static
  12357. * @since 0.1.0
  12358. * @memberOf _
  12359. * @category Object
  12360. * @param {Object} object The object to query.
  12361. * @param {Array|string} path The path to check.
  12362. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12363. * @example
  12364. *
  12365. * var object = { 'a': { 'b': 2 } };
  12366. * var other = _.create({ 'a': _.create({ 'b': 2 }) });
  12367. *
  12368. * _.has(object, 'a');
  12369. * // => true
  12370. *
  12371. * _.has(object, 'a.b');
  12372. * // => true
  12373. *
  12374. * _.has(object, ['a', 'b']);
  12375. * // => true
  12376. *
  12377. * _.has(other, 'a');
  12378. * // => false
  12379. */
  12380. function has(object, path) {
  12381. return object != null && hasPath(object, path, baseHas);
  12382. }
  12383. /**
  12384. * Checks if `path` is a direct or inherited property of `object`.
  12385. *
  12386. * @static
  12387. * @memberOf _
  12388. * @since 4.0.0
  12389. * @category Object
  12390. * @param {Object} object The object to query.
  12391. * @param {Array|string} path The path to check.
  12392. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  12393. * @example
  12394. *
  12395. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  12396. *
  12397. * _.hasIn(object, 'a');
  12398. * // => true
  12399. *
  12400. * _.hasIn(object, 'a.b');
  12401. * // => true
  12402. *
  12403. * _.hasIn(object, ['a', 'b']);
  12404. * // => true
  12405. *
  12406. * _.hasIn(object, 'b');
  12407. * // => false
  12408. */
  12409. function hasIn(object, path) {
  12410. return object != null && hasPath(object, path, baseHasIn);
  12411. }
  12412. /**
  12413. * Creates an object composed of the inverted keys and values of `object`.
  12414. * If `object` contains duplicate values, subsequent values overwrite
  12415. * property assignments of previous values.
  12416. *
  12417. * @static
  12418. * @memberOf _
  12419. * @since 0.7.0
  12420. * @category Object
  12421. * @param {Object} object The object to invert.
  12422. * @returns {Object} Returns the new inverted object.
  12423. * @example
  12424. *
  12425. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12426. *
  12427. * _.invert(object);
  12428. * // => { '1': 'c', '2': 'b' }
  12429. */
  12430. var invert = createInverter(function(result, value, key) {
  12431. if (value != null &&
  12432. typeof value.toString != 'function') {
  12433. value = nativeObjectToString.call(value);
  12434. }
  12435. result[value] = key;
  12436. }, constant(identity));
  12437. /**
  12438. * This method is like `_.invert` except that the inverted object is generated
  12439. * from the results of running each element of `object` thru `iteratee`. The
  12440. * corresponding inverted value of each inverted key is an array of keys
  12441. * responsible for generating the inverted value. The iteratee is invoked
  12442. * with one argument: (value).
  12443. *
  12444. * @static
  12445. * @memberOf _
  12446. * @since 4.1.0
  12447. * @category Object
  12448. * @param {Object} object The object to invert.
  12449. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  12450. * @returns {Object} Returns the new inverted object.
  12451. * @example
  12452. *
  12453. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  12454. *
  12455. * _.invertBy(object);
  12456. * // => { '1': ['a', 'c'], '2': ['b'] }
  12457. *
  12458. * _.invertBy(object, function(value) {
  12459. * return 'group' + value;
  12460. * });
  12461. * // => { 'group1': ['a', 'c'], 'group2': ['b'] }
  12462. */
  12463. var invertBy = createInverter(function(result, value, key) {
  12464. if (value != null &&
  12465. typeof value.toString != 'function') {
  12466. value = nativeObjectToString.call(value);
  12467. }
  12468. if (hasOwnProperty.call(result, value)) {
  12469. result[value].push(key);
  12470. } else {
  12471. result[value] = [key];
  12472. }
  12473. }, getIteratee);
  12474. /**
  12475. * Invokes the method at `path` of `object`.
  12476. *
  12477. * @static
  12478. * @memberOf _
  12479. * @since 4.0.0
  12480. * @category Object
  12481. * @param {Object} object The object to query.
  12482. * @param {Array|string} path The path of the method to invoke.
  12483. * @param {...*} [args] The arguments to invoke the method with.
  12484. * @returns {*} Returns the result of the invoked method.
  12485. * @example
  12486. *
  12487. * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] };
  12488. *
  12489. * _.invoke(object, 'a[0].b.c.slice', 1, 3);
  12490. * // => [2, 3]
  12491. */
  12492. var invoke = baseRest(baseInvoke);
  12493. /**
  12494. * Creates an array of the own enumerable property names of `object`.
  12495. *
  12496. * **Note:** Non-object values are coerced to objects. See the
  12497. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  12498. * for more details.
  12499. *
  12500. * @static
  12501. * @since 0.1.0
  12502. * @memberOf _
  12503. * @category Object
  12504. * @param {Object} object The object to query.
  12505. * @returns {Array} Returns the array of property names.
  12506. * @example
  12507. *
  12508. * function Foo() {
  12509. * this.a = 1;
  12510. * this.b = 2;
  12511. * }
  12512. *
  12513. * Foo.prototype.c = 3;
  12514. *
  12515. * _.keys(new Foo);
  12516. * // => ['a', 'b'] (iteration order is not guaranteed)
  12517. *
  12518. * _.keys('hi');
  12519. * // => ['0', '1']
  12520. */
  12521. function keys(object) {
  12522. return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object);
  12523. }
  12524. /**
  12525. * Creates an array of the own and inherited enumerable property names of `object`.
  12526. *
  12527. * **Note:** Non-object values are coerced to objects.
  12528. *
  12529. * @static
  12530. * @memberOf _
  12531. * @since 3.0.0
  12532. * @category Object
  12533. * @param {Object} object The object to query.
  12534. * @returns {Array} Returns the array of property names.
  12535. * @example
  12536. *
  12537. * function Foo() {
  12538. * this.a = 1;
  12539. * this.b = 2;
  12540. * }
  12541. *
  12542. * Foo.prototype.c = 3;
  12543. *
  12544. * _.keysIn(new Foo);
  12545. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  12546. */
  12547. function keysIn(object) {
  12548. return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object);
  12549. }
  12550. /**
  12551. * The opposite of `_.mapValues`; this method creates an object with the
  12552. * same values as `object` and keys generated by running each own enumerable
  12553. * string keyed property of `object` thru `iteratee`. The iteratee is invoked
  12554. * with three arguments: (value, key, object).
  12555. *
  12556. * @static
  12557. * @memberOf _
  12558. * @since 3.8.0
  12559. * @category Object
  12560. * @param {Object} object The object to iterate over.
  12561. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12562. * @returns {Object} Returns the new mapped object.
  12563. * @see _.mapValues
  12564. * @example
  12565. *
  12566. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  12567. * return key + value;
  12568. * });
  12569. * // => { 'a1': 1, 'b2': 2 }
  12570. */
  12571. function mapKeys(object, iteratee) {
  12572. var result = {};
  12573. iteratee = getIteratee(iteratee, 3);
  12574. baseForOwn(object, function(value, key, object) {
  12575. baseAssignValue(result, iteratee(value, key, object), value);
  12576. });
  12577. return result;
  12578. }
  12579. /**
  12580. * Creates an object with the same keys as `object` and values generated
  12581. * by running each own enumerable string keyed property of `object` thru
  12582. * `iteratee`. The iteratee is invoked with three arguments:
  12583. * (value, key, object).
  12584. *
  12585. * @static
  12586. * @memberOf _
  12587. * @since 2.4.0
  12588. * @category Object
  12589. * @param {Object} object The object to iterate over.
  12590. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12591. * @returns {Object} Returns the new mapped object.
  12592. * @see _.mapKeys
  12593. * @example
  12594. *
  12595. * var users = {
  12596. * 'fred': { 'user': 'fred', 'age': 40 },
  12597. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  12598. * };
  12599. *
  12600. * _.mapValues(users, function(o) { return o.age; });
  12601. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12602. *
  12603. * // The `_.property` iteratee shorthand.
  12604. * _.mapValues(users, 'age');
  12605. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  12606. */
  12607. function mapValues(object, iteratee) {
  12608. var result = {};
  12609. iteratee = getIteratee(iteratee, 3);
  12610. baseForOwn(object, function(value, key, object) {
  12611. baseAssignValue(result, key, iteratee(value, key, object));
  12612. });
  12613. return result;
  12614. }
  12615. /**
  12616. * This method is like `_.assign` except that it recursively merges own and
  12617. * inherited enumerable string keyed properties of source objects into the
  12618. * destination object. Source properties that resolve to `undefined` are
  12619. * skipped if a destination value exists. Array and plain object properties
  12620. * are merged recursively. Other objects and value types are overridden by
  12621. * assignment. Source objects are applied from left to right. Subsequent
  12622. * sources overwrite property assignments of previous sources.
  12623. *
  12624. * **Note:** This method mutates `object`.
  12625. *
  12626. * @static
  12627. * @memberOf _
  12628. * @since 0.5.0
  12629. * @category Object
  12630. * @param {Object} object The destination object.
  12631. * @param {...Object} [sources] The source objects.
  12632. * @returns {Object} Returns `object`.
  12633. * @example
  12634. *
  12635. * var object = {
  12636. * 'a': [{ 'b': 2 }, { 'd': 4 }]
  12637. * };
  12638. *
  12639. * var other = {
  12640. * 'a': [{ 'c': 3 }, { 'e': 5 }]
  12641. * };
  12642. *
  12643. * _.merge(object, other);
  12644. * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] }
  12645. */
  12646. var merge = createAssigner(function(object, source, srcIndex) {
  12647. baseMerge(object, source, srcIndex);
  12648. });
  12649. /**
  12650. * This method is like `_.merge` except that it accepts `customizer` which
  12651. * is invoked to produce the merged values of the destination and source
  12652. * properties. If `customizer` returns `undefined`, merging is handled by the
  12653. * method instead. The `customizer` is invoked with six arguments:
  12654. * (objValue, srcValue, key, object, source, stack).
  12655. *
  12656. * **Note:** This method mutates `object`.
  12657. *
  12658. * @static
  12659. * @memberOf _
  12660. * @since 4.0.0
  12661. * @category Object
  12662. * @param {Object} object The destination object.
  12663. * @param {...Object} sources The source objects.
  12664. * @param {Function} customizer The function to customize assigned values.
  12665. * @returns {Object} Returns `object`.
  12666. * @example
  12667. *
  12668. * function customizer(objValue, srcValue) {
  12669. * if (_.isArray(objValue)) {
  12670. * return objValue.concat(srcValue);
  12671. * }
  12672. * }
  12673. *
  12674. * var object = { 'a': [1], 'b': [2] };
  12675. * var other = { 'a': [3], 'b': [4] };
  12676. *
  12677. * _.mergeWith(object, other, customizer);
  12678. * // => { 'a': [1, 3], 'b': [2, 4] }
  12679. */
  12680. var mergeWith = createAssigner(function(object, source, srcIndex, customizer) {
  12681. baseMerge(object, source, srcIndex, customizer);
  12682. });
  12683. /**
  12684. * The opposite of `_.pick`; this method creates an object composed of the
  12685. * own and inherited enumerable property paths of `object` that are not omitted.
  12686. *
  12687. * **Note:** This method is considerably slower than `_.pick`.
  12688. *
  12689. * @static
  12690. * @since 0.1.0
  12691. * @memberOf _
  12692. * @category Object
  12693. * @param {Object} object The source object.
  12694. * @param {...(string|string[])} [paths] The property paths to omit.
  12695. * @returns {Object} Returns the new object.
  12696. * @example
  12697. *
  12698. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12699. *
  12700. * _.omit(object, ['a', 'c']);
  12701. * // => { 'b': '2' }
  12702. */
  12703. var omit = flatRest(function(object, paths) {
  12704. var result = {};
  12705. if (object == null) {
  12706. return result;
  12707. }
  12708. var isDeep = false;
  12709. paths = arrayMap(paths, function(path) {
  12710. path = castPath(path, object);
  12711. isDeep || (isDeep = path.length > 1);
  12712. return path;
  12713. });
  12714. copyObject(object, getAllKeysIn(object), result);
  12715. if (isDeep) {
  12716. result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone);
  12717. }
  12718. var length = paths.length;
  12719. while (length--) {
  12720. baseUnset(result, paths[length]);
  12721. }
  12722. return result;
  12723. });
  12724. /**
  12725. * The opposite of `_.pickBy`; this method creates an object composed of
  12726. * the own and inherited enumerable string keyed properties of `object` that
  12727. * `predicate` doesn't return truthy for. The predicate is invoked with two
  12728. * arguments: (value, key).
  12729. *
  12730. * @static
  12731. * @memberOf _
  12732. * @since 4.0.0
  12733. * @category Object
  12734. * @param {Object} object The source object.
  12735. * @param {Function} [predicate=_.identity] The function invoked per property.
  12736. * @returns {Object} Returns the new object.
  12737. * @example
  12738. *
  12739. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12740. *
  12741. * _.omitBy(object, _.isNumber);
  12742. * // => { 'b': '2' }
  12743. */
  12744. function omitBy(object, predicate) {
  12745. return pickBy(object, negate(getIteratee(predicate)));
  12746. }
  12747. /**
  12748. * Creates an object composed of the picked `object` properties.
  12749. *
  12750. * @static
  12751. * @since 0.1.0
  12752. * @memberOf _
  12753. * @category Object
  12754. * @param {Object} object The source object.
  12755. * @param {...(string|string[])} [paths] The property paths to pick.
  12756. * @returns {Object} Returns the new object.
  12757. * @example
  12758. *
  12759. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12760. *
  12761. * _.pick(object, ['a', 'c']);
  12762. * // => { 'a': 1, 'c': 3 }
  12763. */
  12764. var pick = flatRest(function(object, paths) {
  12765. return object == null ? {} : basePick(object, paths);
  12766. });
  12767. /**
  12768. * Creates an object composed of the `object` properties `predicate` returns
  12769. * truthy for. The predicate is invoked with two arguments: (value, key).
  12770. *
  12771. * @static
  12772. * @memberOf _
  12773. * @since 4.0.0
  12774. * @category Object
  12775. * @param {Object} object The source object.
  12776. * @param {Function} [predicate=_.identity] The function invoked per property.
  12777. * @returns {Object} Returns the new object.
  12778. * @example
  12779. *
  12780. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  12781. *
  12782. * _.pickBy(object, _.isNumber);
  12783. * // => { 'a': 1, 'c': 3 }
  12784. */
  12785. function pickBy(object, predicate) {
  12786. if (object == null) {
  12787. return {};
  12788. }
  12789. var props = arrayMap(getAllKeysIn(object), function(prop) {
  12790. return [prop];
  12791. });
  12792. predicate = getIteratee(predicate);
  12793. return basePickBy(object, props, function(value, path) {
  12794. return predicate(value, path[0]);
  12795. });
  12796. }
  12797. /**
  12798. * This method is like `_.get` except that if the resolved value is a
  12799. * function it's invoked with the `this` binding of its parent object and
  12800. * its result is returned.
  12801. *
  12802. * @static
  12803. * @since 0.1.0
  12804. * @memberOf _
  12805. * @category Object
  12806. * @param {Object} object The object to query.
  12807. * @param {Array|string} path The path of the property to resolve.
  12808. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  12809. * @returns {*} Returns the resolved value.
  12810. * @example
  12811. *
  12812. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  12813. *
  12814. * _.result(object, 'a[0].b.c1');
  12815. * // => 3
  12816. *
  12817. * _.result(object, 'a[0].b.c2');
  12818. * // => 4
  12819. *
  12820. * _.result(object, 'a[0].b.c3', 'default');
  12821. * // => 'default'
  12822. *
  12823. * _.result(object, 'a[0].b.c3', _.constant('default'));
  12824. * // => 'default'
  12825. */
  12826. function result(object, path, defaultValue) {
  12827. path = castPath(path, object);
  12828. var index = -1,
  12829. length = path.length;
  12830. // Ensure the loop is entered when path is empty.
  12831. if (!length) {
  12832. length = 1;
  12833. object = undefined;
  12834. }
  12835. while (++index < length) {
  12836. var value = object == null ? undefined : object[toKey(path[index])];
  12837. if (value === undefined) {
  12838. index = length;
  12839. value = defaultValue;
  12840. }
  12841. object = isFunction(value) ? value.call(object) : value;
  12842. }
  12843. return object;
  12844. }
  12845. /**
  12846. * Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
  12847. * it's created. Arrays are created for missing index properties while objects
  12848. * are created for all other missing properties. Use `_.setWith` to customize
  12849. * `path` creation.
  12850. *
  12851. * **Note:** This method mutates `object`.
  12852. *
  12853. * @static
  12854. * @memberOf _
  12855. * @since 3.7.0
  12856. * @category Object
  12857. * @param {Object} object The object to modify.
  12858. * @param {Array|string} path The path of the property to set.
  12859. * @param {*} value The value to set.
  12860. * @returns {Object} Returns `object`.
  12861. * @example
  12862. *
  12863. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  12864. *
  12865. * _.set(object, 'a[0].b.c', 4);
  12866. * console.log(object.a[0].b.c);
  12867. * // => 4
  12868. *
  12869. * _.set(object, ['x', '0', 'y', 'z'], 5);
  12870. * console.log(object.x[0].y.z);
  12871. * // => 5
  12872. */
  12873. function set(object, path, value) {
  12874. return object == null ? object : baseSet(object, path, value);
  12875. }
  12876. /**
  12877. * This method is like `_.set` except that it accepts `customizer` which is
  12878. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  12879. * path creation is handled by the method instead. The `customizer` is invoked
  12880. * with three arguments: (nsValue, key, nsObject).
  12881. *
  12882. * **Note:** This method mutates `object`.
  12883. *
  12884. * @static
  12885. * @memberOf _
  12886. * @since 4.0.0
  12887. * @category Object
  12888. * @param {Object} object The object to modify.
  12889. * @param {Array|string} path The path of the property to set.
  12890. * @param {*} value The value to set.
  12891. * @param {Function} [customizer] The function to customize assigned values.
  12892. * @returns {Object} Returns `object`.
  12893. * @example
  12894. *
  12895. * var object = {};
  12896. *
  12897. * _.setWith(object, '[0][1]', 'a', Object);
  12898. * // => { '0': { '1': 'a' } }
  12899. */
  12900. function setWith(object, path, value, customizer) {
  12901. customizer = typeof customizer == 'function' ? customizer : undefined;
  12902. return object == null ? object : baseSet(object, path, value, customizer);
  12903. }
  12904. /**
  12905. * Creates an array of own enumerable string keyed-value pairs for `object`
  12906. * which can be consumed by `_.fromPairs`. If `object` is a map or set, its
  12907. * entries are returned.
  12908. *
  12909. * @static
  12910. * @memberOf _
  12911. * @since 4.0.0
  12912. * @alias entries
  12913. * @category Object
  12914. * @param {Object} object The object to query.
  12915. * @returns {Array} Returns the key-value pairs.
  12916. * @example
  12917. *
  12918. * function Foo() {
  12919. * this.a = 1;
  12920. * this.b = 2;
  12921. * }
  12922. *
  12923. * Foo.prototype.c = 3;
  12924. *
  12925. * _.toPairs(new Foo);
  12926. * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed)
  12927. */
  12928. var toPairs = createToPairs(keys);
  12929. /**
  12930. * Creates an array of own and inherited enumerable string keyed-value pairs
  12931. * for `object` which can be consumed by `_.fromPairs`. If `object` is a map
  12932. * or set, its entries are returned.
  12933. *
  12934. * @static
  12935. * @memberOf _
  12936. * @since 4.0.0
  12937. * @alias entriesIn
  12938. * @category Object
  12939. * @param {Object} object The object to query.
  12940. * @returns {Array} Returns the key-value pairs.
  12941. * @example
  12942. *
  12943. * function Foo() {
  12944. * this.a = 1;
  12945. * this.b = 2;
  12946. * }
  12947. *
  12948. * Foo.prototype.c = 3;
  12949. *
  12950. * _.toPairsIn(new Foo);
  12951. * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed)
  12952. */
  12953. var toPairsIn = createToPairs(keysIn);
  12954. /**
  12955. * An alternative to `_.reduce`; this method transforms `object` to a new
  12956. * `accumulator` object which is the result of running each of its own
  12957. * enumerable string keyed properties thru `iteratee`, with each invocation
  12958. * potentially mutating the `accumulator` object. If `accumulator` is not
  12959. * provided, a new object with the same `[[Prototype]]` will be used. The
  12960. * iteratee is invoked with four arguments: (accumulator, value, key, object).
  12961. * Iteratee functions may exit iteration early by explicitly returning `false`.
  12962. *
  12963. * @static
  12964. * @memberOf _
  12965. * @since 1.3.0
  12966. * @category Object
  12967. * @param {Object} object The object to iterate over.
  12968. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  12969. * @param {*} [accumulator] The custom accumulator value.
  12970. * @returns {*} Returns the accumulated value.
  12971. * @example
  12972. *
  12973. * _.transform([2, 3, 4], function(result, n) {
  12974. * result.push(n *= n);
  12975. * return n % 2 == 0;
  12976. * }, []);
  12977. * // => [4, 9]
  12978. *
  12979. * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) {
  12980. * (result[value] || (result[value] = [])).push(key);
  12981. * }, {});
  12982. * // => { '1': ['a', 'c'], '2': ['b'] }
  12983. */
  12984. function transform(object, iteratee, accumulator) {
  12985. var isArr = isArray(object),
  12986. isArrLike = isArr || isBuffer(object) || isTypedArray(object);
  12987. iteratee = getIteratee(iteratee, 4);
  12988. if (accumulator == null) {
  12989. var Ctor = object && object.constructor;
  12990. if (isArrLike) {
  12991. accumulator = isArr ? new Ctor : [];
  12992. }
  12993. else if (isObject(object)) {
  12994. accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {};
  12995. }
  12996. else {
  12997. accumulator = {};
  12998. }
  12999. }
  13000. (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) {
  13001. return iteratee(accumulator, value, index, object);
  13002. });
  13003. return accumulator;
  13004. }
  13005. /**
  13006. * Removes the property at `path` of `object`.
  13007. *
  13008. * **Note:** This method mutates `object`.
  13009. *
  13010. * @static
  13011. * @memberOf _
  13012. * @since 4.0.0
  13013. * @category Object
  13014. * @param {Object} object The object to modify.
  13015. * @param {Array|string} path The path of the property to unset.
  13016. * @returns {boolean} Returns `true` if the property is deleted, else `false`.
  13017. * @example
  13018. *
  13019. * var object = { 'a': [{ 'b': { 'c': 7 } }] };
  13020. * _.unset(object, 'a[0].b.c');
  13021. * // => true
  13022. *
  13023. * console.log(object);
  13024. * // => { 'a': [{ 'b': {} }] };
  13025. *
  13026. * _.unset(object, ['a', '0', 'b', 'c']);
  13027. * // => true
  13028. *
  13029. * console.log(object);
  13030. * // => { 'a': [{ 'b': {} }] };
  13031. */
  13032. function unset(object, path) {
  13033. return object == null ? true : baseUnset(object, path);
  13034. }
  13035. /**
  13036. * This method is like `_.set` except that accepts `updater` to produce the
  13037. * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
  13038. * is invoked with one argument: (value).
  13039. *
  13040. * **Note:** This method mutates `object`.
  13041. *
  13042. * @static
  13043. * @memberOf _
  13044. * @since 4.6.0
  13045. * @category Object
  13046. * @param {Object} object The object to modify.
  13047. * @param {Array|string} path The path of the property to set.
  13048. * @param {Function} updater The function to produce the updated value.
  13049. * @returns {Object} Returns `object`.
  13050. * @example
  13051. *
  13052. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  13053. *
  13054. * _.update(object, 'a[0].b.c', function(n) { return n * n; });
  13055. * console.log(object.a[0].b.c);
  13056. * // => 9
  13057. *
  13058. * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
  13059. * console.log(object.x[0].y.z);
  13060. * // => 0
  13061. */
  13062. function update(object, path, updater) {
  13063. return object == null ? object : baseUpdate(object, path, castFunction(updater));
  13064. }
  13065. /**
  13066. * This method is like `_.update` except that it accepts `customizer` which is
  13067. * invoked to produce the objects of `path`. If `customizer` returns `undefined`
  13068. * path creation is handled by the method instead. The `customizer` is invoked
  13069. * with three arguments: (nsValue, key, nsObject).
  13070. *
  13071. * **Note:** This method mutates `object`.
  13072. *
  13073. * @static
  13074. * @memberOf _
  13075. * @since 4.6.0
  13076. * @category Object
  13077. * @param {Object} object The object to modify.
  13078. * @param {Array|string} path The path of the property to set.
  13079. * @param {Function} updater The function to produce the updated value.
  13080. * @param {Function} [customizer] The function to customize assigned values.
  13081. * @returns {Object} Returns `object`.
  13082. * @example
  13083. *
  13084. * var object = {};
  13085. *
  13086. * _.updateWith(object, '[0][1]', _.constant('a'), Object);
  13087. * // => { '0': { '1': 'a' } }
  13088. */
  13089. function updateWith(object, path, updater, customizer) {
  13090. customizer = typeof customizer == 'function' ? customizer : undefined;
  13091. return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer);
  13092. }
  13093. /**
  13094. * Creates an array of the own enumerable string keyed property values of `object`.
  13095. *
  13096. * **Note:** Non-object values are coerced to objects.
  13097. *
  13098. * @static
  13099. * @since 0.1.0
  13100. * @memberOf _
  13101. * @category Object
  13102. * @param {Object} object The object to query.
  13103. * @returns {Array} Returns the array of property values.
  13104. * @example
  13105. *
  13106. * function Foo() {
  13107. * this.a = 1;
  13108. * this.b = 2;
  13109. * }
  13110. *
  13111. * Foo.prototype.c = 3;
  13112. *
  13113. * _.values(new Foo);
  13114. * // => [1, 2] (iteration order is not guaranteed)
  13115. *
  13116. * _.values('hi');
  13117. * // => ['h', 'i']
  13118. */
  13119. function values(object) {
  13120. return object == null ? [] : baseValues(object, keys(object));
  13121. }
  13122. /**
  13123. * Creates an array of the own and inherited enumerable string keyed property
  13124. * values of `object`.
  13125. *
  13126. * **Note:** Non-object values are coerced to objects.
  13127. *
  13128. * @static
  13129. * @memberOf _
  13130. * @since 3.0.0
  13131. * @category Object
  13132. * @param {Object} object The object to query.
  13133. * @returns {Array} Returns the array of property values.
  13134. * @example
  13135. *
  13136. * function Foo() {
  13137. * this.a = 1;
  13138. * this.b = 2;
  13139. * }
  13140. *
  13141. * Foo.prototype.c = 3;
  13142. *
  13143. * _.valuesIn(new Foo);
  13144. * // => [1, 2, 3] (iteration order is not guaranteed)
  13145. */
  13146. function valuesIn(object) {
  13147. return object == null ? [] : baseValues(object, keysIn(object));
  13148. }
  13149. /*------------------------------------------------------------------------*/
  13150. /**
  13151. * Clamps `number` within the inclusive `lower` and `upper` bounds.
  13152. *
  13153. * @static
  13154. * @memberOf _
  13155. * @since 4.0.0
  13156. * @category Number
  13157. * @param {number} number The number to clamp.
  13158. * @param {number} [lower] The lower bound.
  13159. * @param {number} upper The upper bound.
  13160. * @returns {number} Returns the clamped number.
  13161. * @example
  13162. *
  13163. * _.clamp(-10, -5, 5);
  13164. * // => -5
  13165. *
  13166. * _.clamp(10, -5, 5);
  13167. * // => 5
  13168. */
  13169. function clamp(number, lower, upper) {
  13170. if (upper === undefined) {
  13171. upper = lower;
  13172. lower = undefined;
  13173. }
  13174. if (upper !== undefined) {
  13175. upper = toNumber(upper);
  13176. upper = upper === upper ? upper : 0;
  13177. }
  13178. if (lower !== undefined) {
  13179. lower = toNumber(lower);
  13180. lower = lower === lower ? lower : 0;
  13181. }
  13182. return baseClamp(toNumber(number), lower, upper);
  13183. }
  13184. /**
  13185. * Checks if `n` is between `start` and up to, but not including, `end`. If
  13186. * `end` is not specified, it's set to `start` with `start` then set to `0`.
  13187. * If `start` is greater than `end` the params are swapped to support
  13188. * negative ranges.
  13189. *
  13190. * @static
  13191. * @memberOf _
  13192. * @since 3.3.0
  13193. * @category Number
  13194. * @param {number} number The number to check.
  13195. * @param {number} [start=0] The start of the range.
  13196. * @param {number} end The end of the range.
  13197. * @returns {boolean} Returns `true` if `number` is in the range, else `false`.
  13198. * @see _.range, _.rangeRight
  13199. * @example
  13200. *
  13201. * _.inRange(3, 2, 4);
  13202. * // => true
  13203. *
  13204. * _.inRange(4, 8);
  13205. * // => true
  13206. *
  13207. * _.inRange(4, 2);
  13208. * // => false
  13209. *
  13210. * _.inRange(2, 2);
  13211. * // => false
  13212. *
  13213. * _.inRange(1.2, 2);
  13214. * // => true
  13215. *
  13216. * _.inRange(5.2, 4);
  13217. * // => false
  13218. *
  13219. * _.inRange(-3, -2, -6);
  13220. * // => true
  13221. */
  13222. function inRange(number, start, end) {
  13223. start = toFinite(start);
  13224. if (end === undefined) {
  13225. end = start;
  13226. start = 0;
  13227. } else {
  13228. end = toFinite(end);
  13229. }
  13230. number = toNumber(number);
  13231. return baseInRange(number, start, end);
  13232. }
  13233. /**
  13234. * Produces a random number between the inclusive `lower` and `upper` bounds.
  13235. * If only one argument is provided a number between `0` and the given number
  13236. * is returned. If `floating` is `true`, or either `lower` or `upper` are
  13237. * floats, a floating-point number is returned instead of an integer.
  13238. *
  13239. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  13240. * floating-point values which can produce unexpected results.
  13241. *
  13242. * @static
  13243. * @memberOf _
  13244. * @since 0.7.0
  13245. * @category Number
  13246. * @param {number} [lower=0] The lower bound.
  13247. * @param {number} [upper=1] The upper bound.
  13248. * @param {boolean} [floating] Specify returning a floating-point number.
  13249. * @returns {number} Returns the random number.
  13250. * @example
  13251. *
  13252. * _.random(0, 5);
  13253. * // => an integer between 0 and 5
  13254. *
  13255. * _.random(5);
  13256. * // => also an integer between 0 and 5
  13257. *
  13258. * _.random(5, true);
  13259. * // => a floating-point number between 0 and 5
  13260. *
  13261. * _.random(1.2, 5.2);
  13262. * // => a floating-point number between 1.2 and 5.2
  13263. */
  13264. function random(lower, upper, floating) {
  13265. if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) {
  13266. upper = floating = undefined;
  13267. }
  13268. if (floating === undefined) {
  13269. if (typeof upper == 'boolean') {
  13270. floating = upper;
  13271. upper = undefined;
  13272. }
  13273. else if (typeof lower == 'boolean') {
  13274. floating = lower;
  13275. lower = undefined;
  13276. }
  13277. }
  13278. if (lower === undefined && upper === undefined) {
  13279. lower = 0;
  13280. upper = 1;
  13281. }
  13282. else {
  13283. lower = toFinite(lower);
  13284. if (upper === undefined) {
  13285. upper = lower;
  13286. lower = 0;
  13287. } else {
  13288. upper = toFinite(upper);
  13289. }
  13290. }
  13291. if (lower > upper) {
  13292. var temp = lower;
  13293. lower = upper;
  13294. upper = temp;
  13295. }
  13296. if (floating || lower % 1 || upper % 1) {
  13297. var rand = nativeRandom();
  13298. return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper);
  13299. }
  13300. return baseRandom(lower, upper);
  13301. }
  13302. /*------------------------------------------------------------------------*/
  13303. /**
  13304. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  13305. *
  13306. * @static
  13307. * @memberOf _
  13308. * @since 3.0.0
  13309. * @category String
  13310. * @param {string} [string=''] The string to convert.
  13311. * @returns {string} Returns the camel cased string.
  13312. * @example
  13313. *
  13314. * _.camelCase('Foo Bar');
  13315. * // => 'fooBar'
  13316. *
  13317. * _.camelCase('--foo-bar--');
  13318. * // => 'fooBar'
  13319. *
  13320. * _.camelCase('__FOO_BAR__');
  13321. * // => 'fooBar'
  13322. */
  13323. var camelCase = createCompounder(function(result, word, index) {
  13324. word = word.toLowerCase();
  13325. return result + (index ? capitalize(word) : word);
  13326. });
  13327. /**
  13328. * Converts the first character of `string` to upper case and the remaining
  13329. * to lower case.
  13330. *
  13331. * @static
  13332. * @memberOf _
  13333. * @since 3.0.0
  13334. * @category String
  13335. * @param {string} [string=''] The string to capitalize.
  13336. * @returns {string} Returns the capitalized string.
  13337. * @example
  13338. *
  13339. * _.capitalize('FRED');
  13340. * // => 'Fred'
  13341. */
  13342. function capitalize(string) {
  13343. return upperFirst(toString(string).toLowerCase());
  13344. }
  13345. /**
  13346. * Deburrs `string` by converting
  13347. * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  13348. * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A)
  13349. * letters to basic Latin letters and removing
  13350. * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  13351. *
  13352. * @static
  13353. * @memberOf _
  13354. * @since 3.0.0
  13355. * @category String
  13356. * @param {string} [string=''] The string to deburr.
  13357. * @returns {string} Returns the deburred string.
  13358. * @example
  13359. *
  13360. * _.deburr('déjà vu');
  13361. * // => 'deja vu'
  13362. */
  13363. function deburr(string) {
  13364. string = toString(string);
  13365. return string && string.replace(reLatin, deburrLetter).replace(reComboMark, '');
  13366. }
  13367. /**
  13368. * Checks if `string` ends with the given target string.
  13369. *
  13370. * @static
  13371. * @memberOf _
  13372. * @since 3.0.0
  13373. * @category String
  13374. * @param {string} [string=''] The string to inspect.
  13375. * @param {string} [target] The string to search for.
  13376. * @param {number} [position=string.length] The position to search up to.
  13377. * @returns {boolean} Returns `true` if `string` ends with `target`,
  13378. * else `false`.
  13379. * @example
  13380. *
  13381. * _.endsWith('abc', 'c');
  13382. * // => true
  13383. *
  13384. * _.endsWith('abc', 'b');
  13385. * // => false
  13386. *
  13387. * _.endsWith('abc', 'b', 2);
  13388. * // => true
  13389. */
  13390. function endsWith(string, target, position) {
  13391. string = toString(string);
  13392. target = baseToString(target);
  13393. var length = string.length;
  13394. position = position === undefined
  13395. ? length
  13396. : baseClamp(toInteger(position), 0, length);
  13397. var end = position;
  13398. position -= target.length;
  13399. return position >= 0 && string.slice(position, end) == target;
  13400. }
  13401. /**
  13402. * Converts the characters "&", "<", ">", '"', and "'" in `string` to their
  13403. * corresponding HTML entities.
  13404. *
  13405. * **Note:** No other characters are escaped. To escape additional
  13406. * characters use a third-party library like [_he_](https://mths.be/he).
  13407. *
  13408. * Though the ">" character is escaped for symmetry, characters like
  13409. * ">" and "/" don't need escaping in HTML and have no special meaning
  13410. * unless they're part of a tag or unquoted attribute value. See
  13411. * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  13412. * (under "semi-related fun fact") for more details.
  13413. *
  13414. * When working with HTML you should always
  13415. * [quote attribute values](http://wonko.com/post/html-escaping) to reduce
  13416. * XSS vectors.
  13417. *
  13418. * @static
  13419. * @since 0.1.0
  13420. * @memberOf _
  13421. * @category String
  13422. * @param {string} [string=''] The string to escape.
  13423. * @returns {string} Returns the escaped string.
  13424. * @example
  13425. *
  13426. * _.escape('fred, barney, & pebbles');
  13427. * // => 'fred, barney, &amp; pebbles'
  13428. */
  13429. function escape(string) {
  13430. string = toString(string);
  13431. return (string && reHasUnescapedHtml.test(string))
  13432. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  13433. : string;
  13434. }
  13435. /**
  13436. * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+",
  13437. * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`.
  13438. *
  13439. * @static
  13440. * @memberOf _
  13441. * @since 3.0.0
  13442. * @category String
  13443. * @param {string} [string=''] The string to escape.
  13444. * @returns {string} Returns the escaped string.
  13445. * @example
  13446. *
  13447. * _.escapeRegExp('[lodash](https://lodash.com/)');
  13448. * // => '\[lodash\]\(https://lodash\.com/\)'
  13449. */
  13450. function escapeRegExp(string) {
  13451. string = toString(string);
  13452. return (string && reHasRegExpChar.test(string))
  13453. ? string.replace(reRegExpChar, '\\$&')
  13454. : string;
  13455. }
  13456. /**
  13457. * Converts `string` to
  13458. * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  13459. *
  13460. * @static
  13461. * @memberOf _
  13462. * @since 3.0.0
  13463. * @category String
  13464. * @param {string} [string=''] The string to convert.
  13465. * @returns {string} Returns the kebab cased string.
  13466. * @example
  13467. *
  13468. * _.kebabCase('Foo Bar');
  13469. * // => 'foo-bar'
  13470. *
  13471. * _.kebabCase('fooBar');
  13472. * // => 'foo-bar'
  13473. *
  13474. * _.kebabCase('__FOO_BAR__');
  13475. * // => 'foo-bar'
  13476. */
  13477. var kebabCase = createCompounder(function(result, word, index) {
  13478. return result + (index ? '-' : '') + word.toLowerCase();
  13479. });
  13480. /**
  13481. * Converts `string`, as space separated words, to lower case.
  13482. *
  13483. * @static
  13484. * @memberOf _
  13485. * @since 4.0.0
  13486. * @category String
  13487. * @param {string} [string=''] The string to convert.
  13488. * @returns {string} Returns the lower cased string.
  13489. * @example
  13490. *
  13491. * _.lowerCase('--Foo-Bar--');
  13492. * // => 'foo bar'
  13493. *
  13494. * _.lowerCase('fooBar');
  13495. * // => 'foo bar'
  13496. *
  13497. * _.lowerCase('__FOO_BAR__');
  13498. * // => 'foo bar'
  13499. */
  13500. var lowerCase = createCompounder(function(result, word, index) {
  13501. return result + (index ? ' ' : '') + word.toLowerCase();
  13502. });
  13503. /**
  13504. * Converts the first character of `string` to lower case.
  13505. *
  13506. * @static
  13507. * @memberOf _
  13508. * @since 4.0.0
  13509. * @category String
  13510. * @param {string} [string=''] The string to convert.
  13511. * @returns {string} Returns the converted string.
  13512. * @example
  13513. *
  13514. * _.lowerFirst('Fred');
  13515. * // => 'fred'
  13516. *
  13517. * _.lowerFirst('FRED');
  13518. * // => 'fRED'
  13519. */
  13520. var lowerFirst = createCaseFirst('toLowerCase');
  13521. /**
  13522. * Pads `string` on the left and right sides if it's shorter than `length`.
  13523. * Padding characters are truncated if they can't be evenly divided by `length`.
  13524. *
  13525. * @static
  13526. * @memberOf _
  13527. * @since 3.0.0
  13528. * @category String
  13529. * @param {string} [string=''] The string to pad.
  13530. * @param {number} [length=0] The padding length.
  13531. * @param {string} [chars=' '] The string used as padding.
  13532. * @returns {string} Returns the padded string.
  13533. * @example
  13534. *
  13535. * _.pad('abc', 8);
  13536. * // => ' abc '
  13537. *
  13538. * _.pad('abc', 8, '_-');
  13539. * // => '_-abc_-_'
  13540. *
  13541. * _.pad('abc', 3);
  13542. * // => 'abc'
  13543. */
  13544. function pad(string, length, chars) {
  13545. string = toString(string);
  13546. length = toInteger(length);
  13547. var strLength = length ? stringSize(string) : 0;
  13548. if (!length || strLength >= length) {
  13549. return string;
  13550. }
  13551. var mid = (length - strLength) / 2;
  13552. return (
  13553. createPadding(nativeFloor(mid), chars) +
  13554. string +
  13555. createPadding(nativeCeil(mid), chars)
  13556. );
  13557. }
  13558. /**
  13559. * Pads `string` on the right side if it's shorter than `length`. Padding
  13560. * characters are truncated if they exceed `length`.
  13561. *
  13562. * @static
  13563. * @memberOf _
  13564. * @since 4.0.0
  13565. * @category String
  13566. * @param {string} [string=''] The string to pad.
  13567. * @param {number} [length=0] The padding length.
  13568. * @param {string} [chars=' '] The string used as padding.
  13569. * @returns {string} Returns the padded string.
  13570. * @example
  13571. *
  13572. * _.padEnd('abc', 6);
  13573. * // => 'abc '
  13574. *
  13575. * _.padEnd('abc', 6, '_-');
  13576. * // => 'abc_-_'
  13577. *
  13578. * _.padEnd('abc', 3);
  13579. * // => 'abc'
  13580. */
  13581. function padEnd(string, length, chars) {
  13582. string = toString(string);
  13583. length = toInteger(length);
  13584. var strLength = length ? stringSize(string) : 0;
  13585. return (length && strLength < length)
  13586. ? (string + createPadding(length - strLength, chars))
  13587. : string;
  13588. }
  13589. /**
  13590. * Pads `string` on the left side if it's shorter than `length`. Padding
  13591. * characters are truncated if they exceed `length`.
  13592. *
  13593. * @static
  13594. * @memberOf _
  13595. * @since 4.0.0
  13596. * @category String
  13597. * @param {string} [string=''] The string to pad.
  13598. * @param {number} [length=0] The padding length.
  13599. * @param {string} [chars=' '] The string used as padding.
  13600. * @returns {string} Returns the padded string.
  13601. * @example
  13602. *
  13603. * _.padStart('abc', 6);
  13604. * // => ' abc'
  13605. *
  13606. * _.padStart('abc', 6, '_-');
  13607. * // => '_-_abc'
  13608. *
  13609. * _.padStart('abc', 3);
  13610. * // => 'abc'
  13611. */
  13612. function padStart(string, length, chars) {
  13613. string = toString(string);
  13614. length = toInteger(length);
  13615. var strLength = length ? stringSize(string) : 0;
  13616. return (length && strLength < length)
  13617. ? (createPadding(length - strLength, chars) + string)
  13618. : string;
  13619. }
  13620. /**
  13621. * Converts `string` to an integer of the specified radix. If `radix` is
  13622. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a
  13623. * hexadecimal, in which case a `radix` of `16` is used.
  13624. *
  13625. * **Note:** This method aligns with the
  13626. * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`.
  13627. *
  13628. * @static
  13629. * @memberOf _
  13630. * @since 1.1.0
  13631. * @category String
  13632. * @param {string} string The string to convert.
  13633. * @param {number} [radix=10] The radix to interpret `value` by.
  13634. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13635. * @returns {number} Returns the converted integer.
  13636. * @example
  13637. *
  13638. * _.parseInt('08');
  13639. * // => 8
  13640. *
  13641. * _.map(['6', '08', '10'], _.parseInt);
  13642. * // => [6, 8, 10]
  13643. */
  13644. function parseInt(string, radix, guard) {
  13645. if (guard || radix == null) {
  13646. radix = 0;
  13647. } else if (radix) {
  13648. radix = +radix;
  13649. }
  13650. return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0);
  13651. }
  13652. /**
  13653. * Repeats the given string `n` times.
  13654. *
  13655. * @static
  13656. * @memberOf _
  13657. * @since 3.0.0
  13658. * @category String
  13659. * @param {string} [string=''] The string to repeat.
  13660. * @param {number} [n=1] The number of times to repeat the string.
  13661. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13662. * @returns {string} Returns the repeated string.
  13663. * @example
  13664. *
  13665. * _.repeat('*', 3);
  13666. * // => '***'
  13667. *
  13668. * _.repeat('abc', 2);
  13669. * // => 'abcabc'
  13670. *
  13671. * _.repeat('abc', 0);
  13672. * // => ''
  13673. */
  13674. function repeat(string, n, guard) {
  13675. if ((guard ? isIterateeCall(string, n, guard) : n === undefined)) {
  13676. n = 1;
  13677. } else {
  13678. n = toInteger(n);
  13679. }
  13680. return baseRepeat(toString(string), n);
  13681. }
  13682. /**
  13683. * Replaces matches for `pattern` in `string` with `replacement`.
  13684. *
  13685. * **Note:** This method is based on
  13686. * [`String#replace`](https://mdn.io/String/replace).
  13687. *
  13688. * @static
  13689. * @memberOf _
  13690. * @since 4.0.0
  13691. * @category String
  13692. * @param {string} [string=''] The string to modify.
  13693. * @param {RegExp|string} pattern The pattern to replace.
  13694. * @param {Function|string} replacement The match replacement.
  13695. * @returns {string} Returns the modified string.
  13696. * @example
  13697. *
  13698. * _.replace('Hi Fred', 'Fred', 'Barney');
  13699. * // => 'Hi Barney'
  13700. */
  13701. function replace() {
  13702. var args = arguments,
  13703. string = toString(args[0]);
  13704. return args.length < 3 ? string : string.replace(args[1], args[2]);
  13705. }
  13706. /**
  13707. * Converts `string` to
  13708. * [snake case](https://en.wikipedia.org/wiki/Snake_case).
  13709. *
  13710. * @static
  13711. * @memberOf _
  13712. * @since 3.0.0
  13713. * @category String
  13714. * @param {string} [string=''] The string to convert.
  13715. * @returns {string} Returns the snake cased string.
  13716. * @example
  13717. *
  13718. * _.snakeCase('Foo Bar');
  13719. * // => 'foo_bar'
  13720. *
  13721. * _.snakeCase('fooBar');
  13722. * // => 'foo_bar'
  13723. *
  13724. * _.snakeCase('--FOO-BAR--');
  13725. * // => 'foo_bar'
  13726. */
  13727. var snakeCase = createCompounder(function(result, word, index) {
  13728. return result + (index ? '_' : '') + word.toLowerCase();
  13729. });
  13730. /**
  13731. * Splits `string` by `separator`.
  13732. *
  13733. * **Note:** This method is based on
  13734. * [`String#split`](https://mdn.io/String/split).
  13735. *
  13736. * @static
  13737. * @memberOf _
  13738. * @since 4.0.0
  13739. * @category String
  13740. * @param {string} [string=''] The string to split.
  13741. * @param {RegExp|string} separator The separator pattern to split by.
  13742. * @param {number} [limit] The length to truncate results to.
  13743. * @returns {Array} Returns the string segments.
  13744. * @example
  13745. *
  13746. * _.split('a-b-c', '-', 2);
  13747. * // => ['a', 'b']
  13748. */
  13749. function split(string, separator, limit) {
  13750. if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) {
  13751. separator = limit = undefined;
  13752. }
  13753. limit = limit === undefined ? MAX_ARRAY_LENGTH : limit >>> 0;
  13754. if (!limit) {
  13755. return [];
  13756. }
  13757. string = toString(string);
  13758. if (string && (
  13759. typeof separator == 'string' ||
  13760. (separator != null && !isRegExp(separator))
  13761. )) {
  13762. separator = baseToString(separator);
  13763. if (!separator && hasUnicode(string)) {
  13764. return castSlice(stringToArray(string), 0, limit);
  13765. }
  13766. }
  13767. return string.split(separator, limit);
  13768. }
  13769. /**
  13770. * Converts `string` to
  13771. * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  13772. *
  13773. * @static
  13774. * @memberOf _
  13775. * @since 3.1.0
  13776. * @category String
  13777. * @param {string} [string=''] The string to convert.
  13778. * @returns {string} Returns the start cased string.
  13779. * @example
  13780. *
  13781. * _.startCase('--foo-bar--');
  13782. * // => 'Foo Bar'
  13783. *
  13784. * _.startCase('fooBar');
  13785. * // => 'Foo Bar'
  13786. *
  13787. * _.startCase('__FOO_BAR__');
  13788. * // => 'FOO BAR'
  13789. */
  13790. var startCase = createCompounder(function(result, word, index) {
  13791. return result + (index ? ' ' : '') + upperFirst(word);
  13792. });
  13793. /**
  13794. * Checks if `string` starts with the given target string.
  13795. *
  13796. * @static
  13797. * @memberOf _
  13798. * @since 3.0.0
  13799. * @category String
  13800. * @param {string} [string=''] The string to inspect.
  13801. * @param {string} [target] The string to search for.
  13802. * @param {number} [position=0] The position to search from.
  13803. * @returns {boolean} Returns `true` if `string` starts with `target`,
  13804. * else `false`.
  13805. * @example
  13806. *
  13807. * _.startsWith('abc', 'a');
  13808. * // => true
  13809. *
  13810. * _.startsWith('abc', 'b');
  13811. * // => false
  13812. *
  13813. * _.startsWith('abc', 'b', 1);
  13814. * // => true
  13815. */
  13816. function startsWith(string, target, position) {
  13817. string = toString(string);
  13818. position = position == null
  13819. ? 0
  13820. : baseClamp(toInteger(position), 0, string.length);
  13821. target = baseToString(target);
  13822. return string.slice(position, position + target.length) == target;
  13823. }
  13824. /**
  13825. * Creates a compiled template function that can interpolate data properties
  13826. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  13827. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  13828. * properties may be accessed as free variables in the template. If a setting
  13829. * object is given, it takes precedence over `_.templateSettings` values.
  13830. *
  13831. * **Note:** In the development build `_.template` utilizes
  13832. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  13833. * for easier debugging.
  13834. *
  13835. * For more information on precompiling templates see
  13836. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  13837. *
  13838. * For more information on Chrome extension sandboxes see
  13839. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  13840. *
  13841. * @static
  13842. * @since 0.1.0
  13843. * @memberOf _
  13844. * @category String
  13845. * @param {string} [string=''] The template string.
  13846. * @param {Object} [options={}] The options object.
  13847. * @param {RegExp} [options.escape=_.templateSettings.escape]
  13848. * The HTML "escape" delimiter.
  13849. * @param {RegExp} [options.evaluate=_.templateSettings.evaluate]
  13850. * The "evaluate" delimiter.
  13851. * @param {Object} [options.imports=_.templateSettings.imports]
  13852. * An object to import into the template as free variables.
  13853. * @param {RegExp} [options.interpolate=_.templateSettings.interpolate]
  13854. * The "interpolate" delimiter.
  13855. * @param {string} [options.sourceURL='lodash.templateSources[n]']
  13856. * The sourceURL of the compiled template.
  13857. * @param {string} [options.variable='obj']
  13858. * The data object variable name.
  13859. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  13860. * @returns {Function} Returns the compiled template function.
  13861. * @example
  13862. *
  13863. * // Use the "interpolate" delimiter to create a compiled template.
  13864. * var compiled = _.template('hello <%= user %>!');
  13865. * compiled({ 'user': 'fred' });
  13866. * // => 'hello fred!'
  13867. *
  13868. * // Use the HTML "escape" delimiter to escape data property values.
  13869. * var compiled = _.template('<b><%- value %></b>');
  13870. * compiled({ 'value': '<script>' });
  13871. * // => '<b>&lt;script&gt;</b>'
  13872. *
  13873. * // Use the "evaluate" delimiter to execute JavaScript and generate HTML.
  13874. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  13875. * compiled({ 'users': ['fred', 'barney'] });
  13876. * // => '<li>fred</li><li>barney</li>'
  13877. *
  13878. * // Use the internal `print` function in "evaluate" delimiters.
  13879. * var compiled = _.template('<% print("hello " + user); %>!');
  13880. * compiled({ 'user': 'barney' });
  13881. * // => 'hello barney!'
  13882. *
  13883. * // Use the ES template literal delimiter as an "interpolate" delimiter.
  13884. * // Disable support by replacing the "interpolate" delimiter.
  13885. * var compiled = _.template('hello ${ user }!');
  13886. * compiled({ 'user': 'pebbles' });
  13887. * // => 'hello pebbles!'
  13888. *
  13889. * // Use backslashes to treat delimiters as plain text.
  13890. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  13891. * compiled({ 'value': 'ignored' });
  13892. * // => '<%- value %>'
  13893. *
  13894. * // Use the `imports` option to import `jQuery` as `jq`.
  13895. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  13896. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  13897. * compiled({ 'users': ['fred', 'barney'] });
  13898. * // => '<li>fred</li><li>barney</li>'
  13899. *
  13900. * // Use the `sourceURL` option to specify a custom sourceURL for the template.
  13901. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  13902. * compiled(data);
  13903. * // => Find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector.
  13904. *
  13905. * // Use the `variable` option to ensure a with-statement isn't used in the compiled template.
  13906. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  13907. * compiled.source;
  13908. * // => function(data) {
  13909. * // var __t, __p = '';
  13910. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  13911. * // return __p;
  13912. * // }
  13913. *
  13914. * // Use custom template delimiters.
  13915. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  13916. * var compiled = _.template('hello {{ user }}!');
  13917. * compiled({ 'user': 'mustache' });
  13918. * // => 'hello mustache!'
  13919. *
  13920. * // Use the `source` property to inline compiled templates for meaningful
  13921. * // line numbers in error messages and stack traces.
  13922. * fs.writeFileSync(path.join(process.cwd(), 'jst.js'), '\
  13923. * var JST = {\
  13924. * "main": ' + _.template(mainText).source + '\
  13925. * };\
  13926. * ');
  13927. */
  13928. function template(string, options, guard) {
  13929. // Based on John Resig's `tmpl` implementation
  13930. // (http://ejohn.org/blog/javascript-micro-templating/)
  13931. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  13932. var settings = lodash.templateSettings;
  13933. if (guard && isIterateeCall(string, options, guard)) {
  13934. options = undefined;
  13935. }
  13936. string = toString(string);
  13937. options = assignInWith({}, options, settings, customDefaultsAssignIn);
  13938. var imports = assignInWith({}, options.imports, settings.imports, customDefaultsAssignIn),
  13939. importsKeys = keys(imports),
  13940. importsValues = baseValues(imports, importsKeys);
  13941. var isEscaping,
  13942. isEvaluating,
  13943. index = 0,
  13944. interpolate = options.interpolate || reNoMatch,
  13945. source = "__p += '";
  13946. // Compile the regexp to match each delimiter.
  13947. var reDelimiters = RegExp(
  13948. (options.escape || reNoMatch).source + '|' +
  13949. interpolate.source + '|' +
  13950. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  13951. (options.evaluate || reNoMatch).source + '|$'
  13952. , 'g');
  13953. // Use a sourceURL for easier debugging.
  13954. // The sourceURL gets injected into the source that's eval-ed, so be careful
  13955. // to normalize all kinds of whitespace, so e.g. newlines (and unicode versions of it) can't sneak in
  13956. // and escape the comment, thus injecting code that gets evaled.
  13957. var sourceURL = '//# sourceURL=' +
  13958. (hasOwnProperty.call(options, 'sourceURL')
  13959. ? (options.sourceURL + '').replace(/\s/g, ' ')
  13960. : ('lodash.templateSources[' + (++templateCounter) + ']')
  13961. ) + '\n';
  13962. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  13963. interpolateValue || (interpolateValue = esTemplateValue);
  13964. // Escape characters that can't be included in string literals.
  13965. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  13966. // Replace delimiters with snippets.
  13967. if (escapeValue) {
  13968. isEscaping = true;
  13969. source += "' +\n__e(" + escapeValue + ") +\n'";
  13970. }
  13971. if (evaluateValue) {
  13972. isEvaluating = true;
  13973. source += "';\n" + evaluateValue + ";\n__p += '";
  13974. }
  13975. if (interpolateValue) {
  13976. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  13977. }
  13978. index = offset + match.length;
  13979. // The JS engine embedded in Adobe products needs `match` returned in
  13980. // order to produce the correct `offset` value.
  13981. return match;
  13982. });
  13983. source += "';\n";
  13984. // If `variable` is not specified wrap a with-statement around the generated
  13985. // code to add the data object to the top of the scope chain.
  13986. var variable = hasOwnProperty.call(options, 'variable') && options.variable;
  13987. if (!variable) {
  13988. source = 'with (obj) {\n' + source + '\n}\n';
  13989. }
  13990. // Throw an error if a forbidden character was found in `variable`, to prevent
  13991. // potential command injection attacks.
  13992. else if (reForbiddenIdentifierChars.test(variable)) {
  13993. throw new Error(INVALID_TEMPL_VAR_ERROR_TEXT);
  13994. }
  13995. // Cleanup code by stripping empty strings.
  13996. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  13997. .replace(reEmptyStringMiddle, '$1')
  13998. .replace(reEmptyStringTrailing, '$1;');
  13999. // Frame code as the function body.
  14000. source = 'function(' + (variable || 'obj') + ') {\n' +
  14001. (variable
  14002. ? ''
  14003. : 'obj || (obj = {});\n'
  14004. ) +
  14005. "var __t, __p = ''" +
  14006. (isEscaping
  14007. ? ', __e = _.escape'
  14008. : ''
  14009. ) +
  14010. (isEvaluating
  14011. ? ', __j = Array.prototype.join;\n' +
  14012. "function print() { __p += __j.call(arguments, '') }\n"
  14013. : ';\n'
  14014. ) +
  14015. source +
  14016. 'return __p\n}';
  14017. var result = attempt(function() {
  14018. return Function(importsKeys, sourceURL + 'return ' + source)
  14019. .apply(undefined, importsValues);
  14020. });
  14021. // Provide the compiled function's source by its `toString` method or
  14022. // the `source` property as a convenience for inlining compiled templates.
  14023. result.source = source;
  14024. if (isError(result)) {
  14025. throw result;
  14026. }
  14027. return result;
  14028. }
  14029. /**
  14030. * Converts `string`, as a whole, to lower case just like
  14031. * [String#toLowerCase](https://mdn.io/toLowerCase).
  14032. *
  14033. * @static
  14034. * @memberOf _
  14035. * @since 4.0.0
  14036. * @category String
  14037. * @param {string} [string=''] The string to convert.
  14038. * @returns {string} Returns the lower cased string.
  14039. * @example
  14040. *
  14041. * _.toLower('--Foo-Bar--');
  14042. * // => '--foo-bar--'
  14043. *
  14044. * _.toLower('fooBar');
  14045. * // => 'foobar'
  14046. *
  14047. * _.toLower('__FOO_BAR__');
  14048. * // => '__foo_bar__'
  14049. */
  14050. function toLower(value) {
  14051. return toString(value).toLowerCase();
  14052. }
  14053. /**
  14054. * Converts `string`, as a whole, to upper case just like
  14055. * [String#toUpperCase](https://mdn.io/toUpperCase).
  14056. *
  14057. * @static
  14058. * @memberOf _
  14059. * @since 4.0.0
  14060. * @category String
  14061. * @param {string} [string=''] The string to convert.
  14062. * @returns {string} Returns the upper cased string.
  14063. * @example
  14064. *
  14065. * _.toUpper('--foo-bar--');
  14066. * // => '--FOO-BAR--'
  14067. *
  14068. * _.toUpper('fooBar');
  14069. * // => 'FOOBAR'
  14070. *
  14071. * _.toUpper('__foo_bar__');
  14072. * // => '__FOO_BAR__'
  14073. */
  14074. function toUpper(value) {
  14075. return toString(value).toUpperCase();
  14076. }
  14077. /**
  14078. * Removes leading and trailing whitespace or specified characters from `string`.
  14079. *
  14080. * @static
  14081. * @memberOf _
  14082. * @since 3.0.0
  14083. * @category String
  14084. * @param {string} [string=''] The string to trim.
  14085. * @param {string} [chars=whitespace] The characters to trim.
  14086. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14087. * @returns {string} Returns the trimmed string.
  14088. * @example
  14089. *
  14090. * _.trim(' abc ');
  14091. * // => 'abc'
  14092. *
  14093. * _.trim('-_-abc-_-', '_-');
  14094. * // => 'abc'
  14095. *
  14096. * _.map([' foo ', ' bar '], _.trim);
  14097. * // => ['foo', 'bar']
  14098. */
  14099. function trim(string, chars, guard) {
  14100. string = toString(string);
  14101. if (string && (guard || chars === undefined)) {
  14102. return baseTrim(string);
  14103. }
  14104. if (!string || !(chars = baseToString(chars))) {
  14105. return string;
  14106. }
  14107. var strSymbols = stringToArray(string),
  14108. chrSymbols = stringToArray(chars),
  14109. start = charsStartIndex(strSymbols, chrSymbols),
  14110. end = charsEndIndex(strSymbols, chrSymbols) + 1;
  14111. return castSlice(strSymbols, start, end).join('');
  14112. }
  14113. /**
  14114. * Removes trailing whitespace or specified characters from `string`.
  14115. *
  14116. * @static
  14117. * @memberOf _
  14118. * @since 4.0.0
  14119. * @category String
  14120. * @param {string} [string=''] The string to trim.
  14121. * @param {string} [chars=whitespace] The characters to trim.
  14122. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14123. * @returns {string} Returns the trimmed string.
  14124. * @example
  14125. *
  14126. * _.trimEnd(' abc ');
  14127. * // => ' abc'
  14128. *
  14129. * _.trimEnd('-_-abc-_-', '_-');
  14130. * // => '-_-abc'
  14131. */
  14132. function trimEnd(string, chars, guard) {
  14133. string = toString(string);
  14134. if (string && (guard || chars === undefined)) {
  14135. return string.slice(0, trimmedEndIndex(string) + 1);
  14136. }
  14137. if (!string || !(chars = baseToString(chars))) {
  14138. return string;
  14139. }
  14140. var strSymbols = stringToArray(string),
  14141. end = charsEndIndex(strSymbols, stringToArray(chars)) + 1;
  14142. return castSlice(strSymbols, 0, end).join('');
  14143. }
  14144. /**
  14145. * Removes leading whitespace or specified characters from `string`.
  14146. *
  14147. * @static
  14148. * @memberOf _
  14149. * @since 4.0.0
  14150. * @category String
  14151. * @param {string} [string=''] The string to trim.
  14152. * @param {string} [chars=whitespace] The characters to trim.
  14153. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14154. * @returns {string} Returns the trimmed string.
  14155. * @example
  14156. *
  14157. * _.trimStart(' abc ');
  14158. * // => 'abc '
  14159. *
  14160. * _.trimStart('-_-abc-_-', '_-');
  14161. * // => 'abc-_-'
  14162. */
  14163. function trimStart(string, chars, guard) {
  14164. string = toString(string);
  14165. if (string && (guard || chars === undefined)) {
  14166. return string.replace(reTrimStart, '');
  14167. }
  14168. if (!string || !(chars = baseToString(chars))) {
  14169. return string;
  14170. }
  14171. var strSymbols = stringToArray(string),
  14172. start = charsStartIndex(strSymbols, stringToArray(chars));
  14173. return castSlice(strSymbols, start).join('');
  14174. }
  14175. /**
  14176. * Truncates `string` if it's longer than the given maximum string length.
  14177. * The last characters of the truncated string are replaced with the omission
  14178. * string which defaults to "...".
  14179. *
  14180. * @static
  14181. * @memberOf _
  14182. * @since 4.0.0
  14183. * @category String
  14184. * @param {string} [string=''] The string to truncate.
  14185. * @param {Object} [options={}] The options object.
  14186. * @param {number} [options.length=30] The maximum string length.
  14187. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  14188. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  14189. * @returns {string} Returns the truncated string.
  14190. * @example
  14191. *
  14192. * _.truncate('hi-diddly-ho there, neighborino');
  14193. * // => 'hi-diddly-ho there, neighbo...'
  14194. *
  14195. * _.truncate('hi-diddly-ho there, neighborino', {
  14196. * 'length': 24,
  14197. * 'separator': ' '
  14198. * });
  14199. * // => 'hi-diddly-ho there,...'
  14200. *
  14201. * _.truncate('hi-diddly-ho there, neighborino', {
  14202. * 'length': 24,
  14203. * 'separator': /,? +/
  14204. * });
  14205. * // => 'hi-diddly-ho there...'
  14206. *
  14207. * _.truncate('hi-diddly-ho there, neighborino', {
  14208. * 'omission': ' [...]'
  14209. * });
  14210. * // => 'hi-diddly-ho there, neig [...]'
  14211. */
  14212. function truncate(string, options) {
  14213. var length = DEFAULT_TRUNC_LENGTH,
  14214. omission = DEFAULT_TRUNC_OMISSION;
  14215. if (isObject(options)) {
  14216. var separator = 'separator' in options ? options.separator : separator;
  14217. length = 'length' in options ? toInteger(options.length) : length;
  14218. omission = 'omission' in options ? baseToString(options.omission) : omission;
  14219. }
  14220. string = toString(string);
  14221. var strLength = string.length;
  14222. if (hasUnicode(string)) {
  14223. var strSymbols = stringToArray(string);
  14224. strLength = strSymbols.length;
  14225. }
  14226. if (length >= strLength) {
  14227. return string;
  14228. }
  14229. var end = length - stringSize(omission);
  14230. if (end < 1) {
  14231. return omission;
  14232. }
  14233. var result = strSymbols
  14234. ? castSlice(strSymbols, 0, end).join('')
  14235. : string.slice(0, end);
  14236. if (separator === undefined) {
  14237. return result + omission;
  14238. }
  14239. if (strSymbols) {
  14240. end += (result.length - end);
  14241. }
  14242. if (isRegExp(separator)) {
  14243. if (string.slice(end).search(separator)) {
  14244. var match,
  14245. substring = result;
  14246. if (!separator.global) {
  14247. separator = RegExp(separator.source, toString(reFlags.exec(separator)) + 'g');
  14248. }
  14249. separator.lastIndex = 0;
  14250. while ((match = separator.exec(substring))) {
  14251. var newEnd = match.index;
  14252. }
  14253. result = result.slice(0, newEnd === undefined ? end : newEnd);
  14254. }
  14255. } else if (string.indexOf(baseToString(separator), end) != end) {
  14256. var index = result.lastIndexOf(separator);
  14257. if (index > -1) {
  14258. result = result.slice(0, index);
  14259. }
  14260. }
  14261. return result + omission;
  14262. }
  14263. /**
  14264. * The inverse of `_.escape`; this method converts the HTML entities
  14265. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, and `&#39;` in `string` to
  14266. * their corresponding characters.
  14267. *
  14268. * **Note:** No other HTML entities are unescaped. To unescape additional
  14269. * HTML entities use a third-party library like [_he_](https://mths.be/he).
  14270. *
  14271. * @static
  14272. * @memberOf _
  14273. * @since 0.6.0
  14274. * @category String
  14275. * @param {string} [string=''] The string to unescape.
  14276. * @returns {string} Returns the unescaped string.
  14277. * @example
  14278. *
  14279. * _.unescape('fred, barney, &amp; pebbles');
  14280. * // => 'fred, barney, & pebbles'
  14281. */
  14282. function unescape(string) {
  14283. string = toString(string);
  14284. return (string && reHasEscapedHtml.test(string))
  14285. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  14286. : string;
  14287. }
  14288. /**
  14289. * Converts `string`, as space separated words, to upper case.
  14290. *
  14291. * @static
  14292. * @memberOf _
  14293. * @since 4.0.0
  14294. * @category String
  14295. * @param {string} [string=''] The string to convert.
  14296. * @returns {string} Returns the upper cased string.
  14297. * @example
  14298. *
  14299. * _.upperCase('--foo-bar');
  14300. * // => 'FOO BAR'
  14301. *
  14302. * _.upperCase('fooBar');
  14303. * // => 'FOO BAR'
  14304. *
  14305. * _.upperCase('__foo_bar__');
  14306. * // => 'FOO BAR'
  14307. */
  14308. var upperCase = createCompounder(function(result, word, index) {
  14309. return result + (index ? ' ' : '') + word.toUpperCase();
  14310. });
  14311. /**
  14312. * Converts the first character of `string` to upper case.
  14313. *
  14314. * @static
  14315. * @memberOf _
  14316. * @since 4.0.0
  14317. * @category String
  14318. * @param {string} [string=''] The string to convert.
  14319. * @returns {string} Returns the converted string.
  14320. * @example
  14321. *
  14322. * _.upperFirst('fred');
  14323. * // => 'Fred'
  14324. *
  14325. * _.upperFirst('FRED');
  14326. * // => 'FRED'
  14327. */
  14328. var upperFirst = createCaseFirst('toUpperCase');
  14329. /**
  14330. * Splits `string` into an array of its words.
  14331. *
  14332. * @static
  14333. * @memberOf _
  14334. * @since 3.0.0
  14335. * @category String
  14336. * @param {string} [string=''] The string to inspect.
  14337. * @param {RegExp|string} [pattern] The pattern to match words.
  14338. * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`.
  14339. * @returns {Array} Returns the words of `string`.
  14340. * @example
  14341. *
  14342. * _.words('fred, barney, & pebbles');
  14343. * // => ['fred', 'barney', 'pebbles']
  14344. *
  14345. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  14346. * // => ['fred', 'barney', '&', 'pebbles']
  14347. */
  14348. function words(string, pattern, guard) {
  14349. string = toString(string);
  14350. pattern = guard ? undefined : pattern;
  14351. if (pattern === undefined) {
  14352. return hasUnicodeWord(string) ? unicodeWords(string) : asciiWords(string);
  14353. }
  14354. return string.match(pattern) || [];
  14355. }
  14356. /*------------------------------------------------------------------------*/
  14357. /**
  14358. * Attempts to invoke `func`, returning either the result or the caught error
  14359. * object. Any additional arguments are provided to `func` when it's invoked.
  14360. *
  14361. * @static
  14362. * @memberOf _
  14363. * @since 3.0.0
  14364. * @category Util
  14365. * @param {Function} func The function to attempt.
  14366. * @param {...*} [args] The arguments to invoke `func` with.
  14367. * @returns {*} Returns the `func` result or error object.
  14368. * @example
  14369. *
  14370. * // Avoid throwing errors for invalid selectors.
  14371. * var elements = _.attempt(function(selector) {
  14372. * return document.querySelectorAll(selector);
  14373. * }, '>_>');
  14374. *
  14375. * if (_.isError(elements)) {
  14376. * elements = [];
  14377. * }
  14378. */
  14379. var attempt = baseRest(function(func, args) {
  14380. try {
  14381. return apply(func, undefined, args);
  14382. } catch (e) {
  14383. return isError(e) ? e : new Error(e);
  14384. }
  14385. });
  14386. /**
  14387. * Binds methods of an object to the object itself, overwriting the existing
  14388. * method.
  14389. *
  14390. * **Note:** This method doesn't set the "length" property of bound functions.
  14391. *
  14392. * @static
  14393. * @since 0.1.0
  14394. * @memberOf _
  14395. * @category Util
  14396. * @param {Object} object The object to bind and assign the bound methods to.
  14397. * @param {...(string|string[])} methodNames The object method names to bind.
  14398. * @returns {Object} Returns `object`.
  14399. * @example
  14400. *
  14401. * var view = {
  14402. * 'label': 'docs',
  14403. * 'click': function() {
  14404. * console.log('clicked ' + this.label);
  14405. * }
  14406. * };
  14407. *
  14408. * _.bindAll(view, ['click']);
  14409. * jQuery(element).on('click', view.click);
  14410. * // => Logs 'clicked docs' when clicked.
  14411. */
  14412. var bindAll = flatRest(function(object, methodNames) {
  14413. arrayEach(methodNames, function(key) {
  14414. key = toKey(key);
  14415. baseAssignValue(object, key, bind(object[key], object));
  14416. });
  14417. return object;
  14418. });
  14419. /**
  14420. * Creates a function that iterates over `pairs` and invokes the corresponding
  14421. * function of the first predicate to return truthy. The predicate-function
  14422. * pairs are invoked with the `this` binding and arguments of the created
  14423. * function.
  14424. *
  14425. * @static
  14426. * @memberOf _
  14427. * @since 4.0.0
  14428. * @category Util
  14429. * @param {Array} pairs The predicate-function pairs.
  14430. * @returns {Function} Returns the new composite function.
  14431. * @example
  14432. *
  14433. * var func = _.cond([
  14434. * [_.matches({ 'a': 1 }), _.constant('matches A')],
  14435. * [_.conforms({ 'b': _.isNumber }), _.constant('matches B')],
  14436. * [_.stubTrue, _.constant('no match')]
  14437. * ]);
  14438. *
  14439. * func({ 'a': 1, 'b': 2 });
  14440. * // => 'matches A'
  14441. *
  14442. * func({ 'a': 0, 'b': 1 });
  14443. * // => 'matches B'
  14444. *
  14445. * func({ 'a': '1', 'b': '2' });
  14446. * // => 'no match'
  14447. */
  14448. function cond(pairs) {
  14449. var length = pairs == null ? 0 : pairs.length,
  14450. toIteratee = getIteratee();
  14451. pairs = !length ? [] : arrayMap(pairs, function(pair) {
  14452. if (typeof pair[1] != 'function') {
  14453. throw new TypeError(FUNC_ERROR_TEXT);
  14454. }
  14455. return [toIteratee(pair[0]), pair[1]];
  14456. });
  14457. return baseRest(function(args) {
  14458. var index = -1;
  14459. while (++index < length) {
  14460. var pair = pairs[index];
  14461. if (apply(pair[0], this, args)) {
  14462. return apply(pair[1], this, args);
  14463. }
  14464. }
  14465. });
  14466. }
  14467. /**
  14468. * Creates a function that invokes the predicate properties of `source` with
  14469. * the corresponding property values of a given object, returning `true` if
  14470. * all predicates return truthy, else `false`.
  14471. *
  14472. * **Note:** The created function is equivalent to `_.conformsTo` with
  14473. * `source` partially applied.
  14474. *
  14475. * @static
  14476. * @memberOf _
  14477. * @since 4.0.0
  14478. * @category Util
  14479. * @param {Object} source The object of property predicates to conform to.
  14480. * @returns {Function} Returns the new spec function.
  14481. * @example
  14482. *
  14483. * var objects = [
  14484. * { 'a': 2, 'b': 1 },
  14485. * { 'a': 1, 'b': 2 }
  14486. * ];
  14487. *
  14488. * _.filter(objects, _.conforms({ 'b': function(n) { return n > 1; } }));
  14489. * // => [{ 'a': 1, 'b': 2 }]
  14490. */
  14491. function conforms(source) {
  14492. return baseConforms(baseClone(source, CLONE_DEEP_FLAG));
  14493. }
  14494. /**
  14495. * Creates a function that returns `value`.
  14496. *
  14497. * @static
  14498. * @memberOf _
  14499. * @since 2.4.0
  14500. * @category Util
  14501. * @param {*} value The value to return from the new function.
  14502. * @returns {Function} Returns the new constant function.
  14503. * @example
  14504. *
  14505. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14506. *
  14507. * console.log(objects);
  14508. * // => [{ 'a': 1 }, { 'a': 1 }]
  14509. *
  14510. * console.log(objects[0] === objects[1]);
  14511. * // => true
  14512. */
  14513. function constant(value) {
  14514. return function() {
  14515. return value;
  14516. };
  14517. }
  14518. /**
  14519. * Checks `value` to determine whether a default value should be returned in
  14520. * its place. The `defaultValue` is returned if `value` is `NaN`, `null`,
  14521. * or `undefined`.
  14522. *
  14523. * @static
  14524. * @memberOf _
  14525. * @since 4.14.0
  14526. * @category Util
  14527. * @param {*} value The value to check.
  14528. * @param {*} defaultValue The default value.
  14529. * @returns {*} Returns the resolved value.
  14530. * @example
  14531. *
  14532. * _.defaultTo(1, 10);
  14533. * // => 1
  14534. *
  14535. * _.defaultTo(undefined, 10);
  14536. * // => 10
  14537. */
  14538. function defaultTo(value, defaultValue) {
  14539. return (value == null || value !== value) ? defaultValue : value;
  14540. }
  14541. /**
  14542. * Creates a function that returns the result of invoking the given functions
  14543. * with the `this` binding of the created function, where each successive
  14544. * invocation is supplied the return value of the previous.
  14545. *
  14546. * @static
  14547. * @memberOf _
  14548. * @since 3.0.0
  14549. * @category Util
  14550. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14551. * @returns {Function} Returns the new composite function.
  14552. * @see _.flowRight
  14553. * @example
  14554. *
  14555. * function square(n) {
  14556. * return n * n;
  14557. * }
  14558. *
  14559. * var addSquare = _.flow([_.add, square]);
  14560. * addSquare(1, 2);
  14561. * // => 9
  14562. */
  14563. var flow = createFlow();
  14564. /**
  14565. * This method is like `_.flow` except that it creates a function that
  14566. * invokes the given functions from right to left.
  14567. *
  14568. * @static
  14569. * @since 3.0.0
  14570. * @memberOf _
  14571. * @category Util
  14572. * @param {...(Function|Function[])} [funcs] The functions to invoke.
  14573. * @returns {Function} Returns the new composite function.
  14574. * @see _.flow
  14575. * @example
  14576. *
  14577. * function square(n) {
  14578. * return n * n;
  14579. * }
  14580. *
  14581. * var addSquare = _.flowRight([square, _.add]);
  14582. * addSquare(1, 2);
  14583. * // => 9
  14584. */
  14585. var flowRight = createFlow(true);
  14586. /**
  14587. * This method returns the first argument it receives.
  14588. *
  14589. * @static
  14590. * @since 0.1.0
  14591. * @memberOf _
  14592. * @category Util
  14593. * @param {*} value Any value.
  14594. * @returns {*} Returns `value`.
  14595. * @example
  14596. *
  14597. * var object = { 'a': 1 };
  14598. *
  14599. * console.log(_.identity(object) === object);
  14600. * // => true
  14601. */
  14602. function identity(value) {
  14603. return value;
  14604. }
  14605. /**
  14606. * Creates a function that invokes `func` with the arguments of the created
  14607. * function. If `func` is a property name, the created function returns the
  14608. * property value for a given element. If `func` is an array or object, the
  14609. * created function returns `true` for elements that contain the equivalent
  14610. * source properties, otherwise it returns `false`.
  14611. *
  14612. * @static
  14613. * @since 4.0.0
  14614. * @memberOf _
  14615. * @category Util
  14616. * @param {*} [func=_.identity] The value to convert to a callback.
  14617. * @returns {Function} Returns the callback.
  14618. * @example
  14619. *
  14620. * var users = [
  14621. * { 'user': 'barney', 'age': 36, 'active': true },
  14622. * { 'user': 'fred', 'age': 40, 'active': false }
  14623. * ];
  14624. *
  14625. * // The `_.matches` iteratee shorthand.
  14626. * _.filter(users, _.iteratee({ 'user': 'barney', 'active': true }));
  14627. * // => [{ 'user': 'barney', 'age': 36, 'active': true }]
  14628. *
  14629. * // The `_.matchesProperty` iteratee shorthand.
  14630. * _.filter(users, _.iteratee(['user', 'fred']));
  14631. * // => [{ 'user': 'fred', 'age': 40 }]
  14632. *
  14633. * // The `_.property` iteratee shorthand.
  14634. * _.map(users, _.iteratee('user'));
  14635. * // => ['barney', 'fred']
  14636. *
  14637. * // Create custom iteratee shorthands.
  14638. * _.iteratee = _.wrap(_.iteratee, function(iteratee, func) {
  14639. * return !_.isRegExp(func) ? iteratee(func) : function(string) {
  14640. * return func.test(string);
  14641. * };
  14642. * });
  14643. *
  14644. * _.filter(['abc', 'def'], /ef/);
  14645. * // => ['def']
  14646. */
  14647. function iteratee(func) {
  14648. return baseIteratee(typeof func == 'function' ? func : baseClone(func, CLONE_DEEP_FLAG));
  14649. }
  14650. /**
  14651. * Creates a function that performs a partial deep comparison between a given
  14652. * object and `source`, returning `true` if the given object has equivalent
  14653. * property values, else `false`.
  14654. *
  14655. * **Note:** The created function is equivalent to `_.isMatch` with `source`
  14656. * partially applied.
  14657. *
  14658. * Partial comparisons will match empty array and empty object `source`
  14659. * values against any array or object value, respectively. See `_.isEqual`
  14660. * for a list of supported value comparisons.
  14661. *
  14662. * **Note:** Multiple values can be checked by combining several matchers
  14663. * using `_.overSome`
  14664. *
  14665. * @static
  14666. * @memberOf _
  14667. * @since 3.0.0
  14668. * @category Util
  14669. * @param {Object} source The object of property values to match.
  14670. * @returns {Function} Returns the new spec function.
  14671. * @example
  14672. *
  14673. * var objects = [
  14674. * { 'a': 1, 'b': 2, 'c': 3 },
  14675. * { 'a': 4, 'b': 5, 'c': 6 }
  14676. * ];
  14677. *
  14678. * _.filter(objects, _.matches({ 'a': 4, 'c': 6 }));
  14679. * // => [{ 'a': 4, 'b': 5, 'c': 6 }]
  14680. *
  14681. * // Checking for several possible values
  14682. * _.filter(objects, _.overSome([_.matches({ 'a': 1 }), _.matches({ 'a': 4 })]));
  14683. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  14684. */
  14685. function matches(source) {
  14686. return baseMatches(baseClone(source, CLONE_DEEP_FLAG));
  14687. }
  14688. /**
  14689. * Creates a function that performs a partial deep comparison between the
  14690. * value at `path` of a given object to `srcValue`, returning `true` if the
  14691. * object value is equivalent, else `false`.
  14692. *
  14693. * **Note:** Partial comparisons will match empty array and empty object
  14694. * `srcValue` values against any array or object value, respectively. See
  14695. * `_.isEqual` for a list of supported value comparisons.
  14696. *
  14697. * **Note:** Multiple values can be checked by combining several matchers
  14698. * using `_.overSome`
  14699. *
  14700. * @static
  14701. * @memberOf _
  14702. * @since 3.2.0
  14703. * @category Util
  14704. * @param {Array|string} path The path of the property to get.
  14705. * @param {*} srcValue The value to match.
  14706. * @returns {Function} Returns the new spec function.
  14707. * @example
  14708. *
  14709. * var objects = [
  14710. * { 'a': 1, 'b': 2, 'c': 3 },
  14711. * { 'a': 4, 'b': 5, 'c': 6 }
  14712. * ];
  14713. *
  14714. * _.find(objects, _.matchesProperty('a', 4));
  14715. * // => { 'a': 4, 'b': 5, 'c': 6 }
  14716. *
  14717. * // Checking for several possible values
  14718. * _.filter(objects, _.overSome([_.matchesProperty('a', 1), _.matchesProperty('a', 4)]));
  14719. * // => [{ 'a': 1, 'b': 2, 'c': 3 }, { 'a': 4, 'b': 5, 'c': 6 }]
  14720. */
  14721. function matchesProperty(path, srcValue) {
  14722. return baseMatchesProperty(path, baseClone(srcValue, CLONE_DEEP_FLAG));
  14723. }
  14724. /**
  14725. * Creates a function that invokes the method at `path` of a given object.
  14726. * Any additional arguments are provided to the invoked method.
  14727. *
  14728. * @static
  14729. * @memberOf _
  14730. * @since 3.7.0
  14731. * @category Util
  14732. * @param {Array|string} path The path of the method to invoke.
  14733. * @param {...*} [args] The arguments to invoke the method with.
  14734. * @returns {Function} Returns the new invoker function.
  14735. * @example
  14736. *
  14737. * var objects = [
  14738. * { 'a': { 'b': _.constant(2) } },
  14739. * { 'a': { 'b': _.constant(1) } }
  14740. * ];
  14741. *
  14742. * _.map(objects, _.method('a.b'));
  14743. * // => [2, 1]
  14744. *
  14745. * _.map(objects, _.method(['a', 'b']));
  14746. * // => [2, 1]
  14747. */
  14748. var method = baseRest(function(path, args) {
  14749. return function(object) {
  14750. return baseInvoke(object, path, args);
  14751. };
  14752. });
  14753. /**
  14754. * The opposite of `_.method`; this method creates a function that invokes
  14755. * the method at a given path of `object`. Any additional arguments are
  14756. * provided to the invoked method.
  14757. *
  14758. * @static
  14759. * @memberOf _
  14760. * @since 3.7.0
  14761. * @category Util
  14762. * @param {Object} object The object to query.
  14763. * @param {...*} [args] The arguments to invoke the method with.
  14764. * @returns {Function} Returns the new invoker function.
  14765. * @example
  14766. *
  14767. * var array = _.times(3, _.constant),
  14768. * object = { 'a': array, 'b': array, 'c': array };
  14769. *
  14770. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  14771. * // => [2, 0]
  14772. *
  14773. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  14774. * // => [2, 0]
  14775. */
  14776. var methodOf = baseRest(function(object, args) {
  14777. return function(path) {
  14778. return baseInvoke(object, path, args);
  14779. };
  14780. });
  14781. /**
  14782. * Adds all own enumerable string keyed function properties of a source
  14783. * object to the destination object. If `object` is a function, then methods
  14784. * are added to its prototype as well.
  14785. *
  14786. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  14787. * avoid conflicts caused by modifying the original.
  14788. *
  14789. * @static
  14790. * @since 0.1.0
  14791. * @memberOf _
  14792. * @category Util
  14793. * @param {Function|Object} [object=lodash] The destination object.
  14794. * @param {Object} source The object of functions to add.
  14795. * @param {Object} [options={}] The options object.
  14796. * @param {boolean} [options.chain=true] Specify whether mixins are chainable.
  14797. * @returns {Function|Object} Returns `object`.
  14798. * @example
  14799. *
  14800. * function vowels(string) {
  14801. * return _.filter(string, function(v) {
  14802. * return /[aeiou]/i.test(v);
  14803. * });
  14804. * }
  14805. *
  14806. * _.mixin({ 'vowels': vowels });
  14807. * _.vowels('fred');
  14808. * // => ['e']
  14809. *
  14810. * _('fred').vowels().value();
  14811. * // => ['e']
  14812. *
  14813. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  14814. * _('fred').vowels();
  14815. * // => ['e']
  14816. */
  14817. function mixin(object, source, options) {
  14818. var props = keys(source),
  14819. methodNames = baseFunctions(source, props);
  14820. if (options == null &&
  14821. !(isObject(source) && (methodNames.length || !props.length))) {
  14822. options = source;
  14823. source = object;
  14824. object = this;
  14825. methodNames = baseFunctions(source, keys(source));
  14826. }
  14827. var chain = !(isObject(options) && 'chain' in options) || !!options.chain,
  14828. isFunc = isFunction(object);
  14829. arrayEach(methodNames, function(methodName) {
  14830. var func = source[methodName];
  14831. object[methodName] = func;
  14832. if (isFunc) {
  14833. object.prototype[methodName] = function() {
  14834. var chainAll = this.__chain__;
  14835. if (chain || chainAll) {
  14836. var result = object(this.__wrapped__),
  14837. actions = result.__actions__ = copyArray(this.__actions__);
  14838. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  14839. result.__chain__ = chainAll;
  14840. return result;
  14841. }
  14842. return func.apply(object, arrayPush([this.value()], arguments));
  14843. };
  14844. }
  14845. });
  14846. return object;
  14847. }
  14848. /**
  14849. * Reverts the `_` variable to its previous value and returns a reference to
  14850. * the `lodash` function.
  14851. *
  14852. * @static
  14853. * @since 0.1.0
  14854. * @memberOf _
  14855. * @category Util
  14856. * @returns {Function} Returns the `lodash` function.
  14857. * @example
  14858. *
  14859. * var lodash = _.noConflict();
  14860. */
  14861. function noConflict() {
  14862. if (root._ === this) {
  14863. root._ = oldDash;
  14864. }
  14865. return this;
  14866. }
  14867. /**
  14868. * This method returns `undefined`.
  14869. *
  14870. * @static
  14871. * @memberOf _
  14872. * @since 2.3.0
  14873. * @category Util
  14874. * @example
  14875. *
  14876. * _.times(2, _.noop);
  14877. * // => [undefined, undefined]
  14878. */
  14879. function noop() {
  14880. // No operation performed.
  14881. }
  14882. /**
  14883. * Creates a function that gets the argument at index `n`. If `n` is negative,
  14884. * the nth argument from the end is returned.
  14885. *
  14886. * @static
  14887. * @memberOf _
  14888. * @since 4.0.0
  14889. * @category Util
  14890. * @param {number} [n=0] The index of the argument to return.
  14891. * @returns {Function} Returns the new pass-thru function.
  14892. * @example
  14893. *
  14894. * var func = _.nthArg(1);
  14895. * func('a', 'b', 'c', 'd');
  14896. * // => 'b'
  14897. *
  14898. * var func = _.nthArg(-2);
  14899. * func('a', 'b', 'c', 'd');
  14900. * // => 'c'
  14901. */
  14902. function nthArg(n) {
  14903. n = toInteger(n);
  14904. return baseRest(function(args) {
  14905. return baseNth(args, n);
  14906. });
  14907. }
  14908. /**
  14909. * Creates a function that invokes `iteratees` with the arguments it receives
  14910. * and returns their results.
  14911. *
  14912. * @static
  14913. * @memberOf _
  14914. * @since 4.0.0
  14915. * @category Util
  14916. * @param {...(Function|Function[])} [iteratees=[_.identity]]
  14917. * The iteratees to invoke.
  14918. * @returns {Function} Returns the new function.
  14919. * @example
  14920. *
  14921. * var func = _.over([Math.max, Math.min]);
  14922. *
  14923. * func(1, 2, 3, 4);
  14924. * // => [4, 1]
  14925. */
  14926. var over = createOver(arrayMap);
  14927. /**
  14928. * Creates a function that checks if **all** of the `predicates` return
  14929. * truthy when invoked with the arguments it receives.
  14930. *
  14931. * Following shorthands are possible for providing predicates.
  14932. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  14933. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  14934. *
  14935. * @static
  14936. * @memberOf _
  14937. * @since 4.0.0
  14938. * @category Util
  14939. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14940. * The predicates to check.
  14941. * @returns {Function} Returns the new function.
  14942. * @example
  14943. *
  14944. * var func = _.overEvery([Boolean, isFinite]);
  14945. *
  14946. * func('1');
  14947. * // => true
  14948. *
  14949. * func(null);
  14950. * // => false
  14951. *
  14952. * func(NaN);
  14953. * // => false
  14954. */
  14955. var overEvery = createOver(arrayEvery);
  14956. /**
  14957. * Creates a function that checks if **any** of the `predicates` return
  14958. * truthy when invoked with the arguments it receives.
  14959. *
  14960. * Following shorthands are possible for providing predicates.
  14961. * Pass an `Object` and it will be used as an parameter for `_.matches` to create the predicate.
  14962. * Pass an `Array` of parameters for `_.matchesProperty` and the predicate will be created using them.
  14963. *
  14964. * @static
  14965. * @memberOf _
  14966. * @since 4.0.0
  14967. * @category Util
  14968. * @param {...(Function|Function[])} [predicates=[_.identity]]
  14969. * The predicates to check.
  14970. * @returns {Function} Returns the new function.
  14971. * @example
  14972. *
  14973. * var func = _.overSome([Boolean, isFinite]);
  14974. *
  14975. * func('1');
  14976. * // => true
  14977. *
  14978. * func(null);
  14979. * // => true
  14980. *
  14981. * func(NaN);
  14982. * // => false
  14983. *
  14984. * var matchesFunc = _.overSome([{ 'a': 1 }, { 'a': 2 }])
  14985. * var matchesPropertyFunc = _.overSome([['a', 1], ['a', 2]])
  14986. */
  14987. var overSome = createOver(arraySome);
  14988. /**
  14989. * Creates a function that returns the value at `path` of a given object.
  14990. *
  14991. * @static
  14992. * @memberOf _
  14993. * @since 2.4.0
  14994. * @category Util
  14995. * @param {Array|string} path The path of the property to get.
  14996. * @returns {Function} Returns the new accessor function.
  14997. * @example
  14998. *
  14999. * var objects = [
  15000. * { 'a': { 'b': 2 } },
  15001. * { 'a': { 'b': 1 } }
  15002. * ];
  15003. *
  15004. * _.map(objects, _.property('a.b'));
  15005. * // => [2, 1]
  15006. *
  15007. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  15008. * // => [1, 2]
  15009. */
  15010. function property(path) {
  15011. return isKey(path) ? baseProperty(toKey(path)) : basePropertyDeep(path);
  15012. }
  15013. /**
  15014. * The opposite of `_.property`; this method creates a function that returns
  15015. * the value at a given path of `object`.
  15016. *
  15017. * @static
  15018. * @memberOf _
  15019. * @since 3.0.0
  15020. * @category Util
  15021. * @param {Object} object The object to query.
  15022. * @returns {Function} Returns the new accessor function.
  15023. * @example
  15024. *
  15025. * var array = [0, 1, 2],
  15026. * object = { 'a': array, 'b': array, 'c': array };
  15027. *
  15028. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  15029. * // => [2, 0]
  15030. *
  15031. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  15032. * // => [2, 0]
  15033. */
  15034. function propertyOf(object) {
  15035. return function(path) {
  15036. return object == null ? undefined : baseGet(object, path);
  15037. };
  15038. }
  15039. /**
  15040. * Creates an array of numbers (positive and/or negative) progressing from
  15041. * `start` up to, but not including, `end`. A step of `-1` is used if a negative
  15042. * `start` is specified without an `end` or `step`. If `end` is not specified,
  15043. * it's set to `start` with `start` then set to `0`.
  15044. *
  15045. * **Note:** JavaScript follows the IEEE-754 standard for resolving
  15046. * floating-point values which can produce unexpected results.
  15047. *
  15048. * @static
  15049. * @since 0.1.0
  15050. * @memberOf _
  15051. * @category Util
  15052. * @param {number} [start=0] The start of the range.
  15053. * @param {number} end The end of the range.
  15054. * @param {number} [step=1] The value to increment or decrement by.
  15055. * @returns {Array} Returns the range of numbers.
  15056. * @see _.inRange, _.rangeRight
  15057. * @example
  15058. *
  15059. * _.range(4);
  15060. * // => [0, 1, 2, 3]
  15061. *
  15062. * _.range(-4);
  15063. * // => [0, -1, -2, -3]
  15064. *
  15065. * _.range(1, 5);
  15066. * // => [1, 2, 3, 4]
  15067. *
  15068. * _.range(0, 20, 5);
  15069. * // => [0, 5, 10, 15]
  15070. *
  15071. * _.range(0, -4, -1);
  15072. * // => [0, -1, -2, -3]
  15073. *
  15074. * _.range(1, 4, 0);
  15075. * // => [1, 1, 1]
  15076. *
  15077. * _.range(0);
  15078. * // => []
  15079. */
  15080. var range = createRange();
  15081. /**
  15082. * This method is like `_.range` except that it populates values in
  15083. * descending order.
  15084. *
  15085. * @static
  15086. * @memberOf _
  15087. * @since 4.0.0
  15088. * @category Util
  15089. * @param {number} [start=0] The start of the range.
  15090. * @param {number} end The end of the range.
  15091. * @param {number} [step=1] The value to increment or decrement by.
  15092. * @returns {Array} Returns the range of numbers.
  15093. * @see _.inRange, _.range
  15094. * @example
  15095. *
  15096. * _.rangeRight(4);
  15097. * // => [3, 2, 1, 0]
  15098. *
  15099. * _.rangeRight(-4);
  15100. * // => [-3, -2, -1, 0]
  15101. *
  15102. * _.rangeRight(1, 5);
  15103. * // => [4, 3, 2, 1]
  15104. *
  15105. * _.rangeRight(0, 20, 5);
  15106. * // => [15, 10, 5, 0]
  15107. *
  15108. * _.rangeRight(0, -4, -1);
  15109. * // => [-3, -2, -1, 0]
  15110. *
  15111. * _.rangeRight(1, 4, 0);
  15112. * // => [1, 1, 1]
  15113. *
  15114. * _.rangeRight(0);
  15115. * // => []
  15116. */
  15117. var rangeRight = createRange(true);
  15118. /**
  15119. * This method returns a new empty array.
  15120. *
  15121. * @static
  15122. * @memberOf _
  15123. * @since 4.13.0
  15124. * @category Util
  15125. * @returns {Array} Returns the new empty array.
  15126. * @example
  15127. *
  15128. * var arrays = _.times(2, _.stubArray);
  15129. *
  15130. * console.log(arrays);
  15131. * // => [[], []]
  15132. *
  15133. * console.log(arrays[0] === arrays[1]);
  15134. * // => false
  15135. */
  15136. function stubArray() {
  15137. return [];
  15138. }
  15139. /**
  15140. * This method returns `false`.
  15141. *
  15142. * @static
  15143. * @memberOf _
  15144. * @since 4.13.0
  15145. * @category Util
  15146. * @returns {boolean} Returns `false`.
  15147. * @example
  15148. *
  15149. * _.times(2, _.stubFalse);
  15150. * // => [false, false]
  15151. */
  15152. function stubFalse() {
  15153. return false;
  15154. }
  15155. /**
  15156. * This method returns a new empty object.
  15157. *
  15158. * @static
  15159. * @memberOf _
  15160. * @since 4.13.0
  15161. * @category Util
  15162. * @returns {Object} Returns the new empty object.
  15163. * @example
  15164. *
  15165. * var objects = _.times(2, _.stubObject);
  15166. *
  15167. * console.log(objects);
  15168. * // => [{}, {}]
  15169. *
  15170. * console.log(objects[0] === objects[1]);
  15171. * // => false
  15172. */
  15173. function stubObject() {
  15174. return {};
  15175. }
  15176. /**
  15177. * This method returns an empty string.
  15178. *
  15179. * @static
  15180. * @memberOf _
  15181. * @since 4.13.0
  15182. * @category Util
  15183. * @returns {string} Returns the empty string.
  15184. * @example
  15185. *
  15186. * _.times(2, _.stubString);
  15187. * // => ['', '']
  15188. */
  15189. function stubString() {
  15190. return '';
  15191. }
  15192. /**
  15193. * This method returns `true`.
  15194. *
  15195. * @static
  15196. * @memberOf _
  15197. * @since 4.13.0
  15198. * @category Util
  15199. * @returns {boolean} Returns `true`.
  15200. * @example
  15201. *
  15202. * _.times(2, _.stubTrue);
  15203. * // => [true, true]
  15204. */
  15205. function stubTrue() {
  15206. return true;
  15207. }
  15208. /**
  15209. * Invokes the iteratee `n` times, returning an array of the results of
  15210. * each invocation. The iteratee is invoked with one argument; (index).
  15211. *
  15212. * @static
  15213. * @since 0.1.0
  15214. * @memberOf _
  15215. * @category Util
  15216. * @param {number} n The number of times to invoke `iteratee`.
  15217. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  15218. * @returns {Array} Returns the array of results.
  15219. * @example
  15220. *
  15221. * _.times(3, String);
  15222. * // => ['0', '1', '2']
  15223. *
  15224. * _.times(4, _.constant(0));
  15225. * // => [0, 0, 0, 0]
  15226. */
  15227. function times(n, iteratee) {
  15228. n = toInteger(n);
  15229. if (n < 1 || n > MAX_SAFE_INTEGER) {
  15230. return [];
  15231. }
  15232. var index = MAX_ARRAY_LENGTH,
  15233. length = nativeMin(n, MAX_ARRAY_LENGTH);
  15234. iteratee = getIteratee(iteratee);
  15235. n -= MAX_ARRAY_LENGTH;
  15236. var result = baseTimes(length, iteratee);
  15237. while (++index < n) {
  15238. iteratee(index);
  15239. }
  15240. return result;
  15241. }
  15242. /**
  15243. * Converts `value` to a property path array.
  15244. *
  15245. * @static
  15246. * @memberOf _
  15247. * @since 4.0.0
  15248. * @category Util
  15249. * @param {*} value The value to convert.
  15250. * @returns {Array} Returns the new property path array.
  15251. * @example
  15252. *
  15253. * _.toPath('a.b.c');
  15254. * // => ['a', 'b', 'c']
  15255. *
  15256. * _.toPath('a[0].b.c');
  15257. * // => ['a', '0', 'b', 'c']
  15258. */
  15259. function toPath(value) {
  15260. if (isArray(value)) {
  15261. return arrayMap(value, toKey);
  15262. }
  15263. return isSymbol(value) ? [value] : copyArray(stringToPath(toString(value)));
  15264. }
  15265. /**
  15266. * Generates a unique ID. If `prefix` is given, the ID is appended to it.
  15267. *
  15268. * @static
  15269. * @since 0.1.0
  15270. * @memberOf _
  15271. * @category Util
  15272. * @param {string} [prefix=''] The value to prefix the ID with.
  15273. * @returns {string} Returns the unique ID.
  15274. * @example
  15275. *
  15276. * _.uniqueId('contact_');
  15277. * // => 'contact_104'
  15278. *
  15279. * _.uniqueId();
  15280. * // => '105'
  15281. */
  15282. function uniqueId(prefix) {
  15283. var id = ++idCounter;
  15284. return toString(prefix) + id;
  15285. }
  15286. /*------------------------------------------------------------------------*/
  15287. /**
  15288. * Adds two numbers.
  15289. *
  15290. * @static
  15291. * @memberOf _
  15292. * @since 3.4.0
  15293. * @category Math
  15294. * @param {number} augend The first number in an addition.
  15295. * @param {number} addend The second number in an addition.
  15296. * @returns {number} Returns the total.
  15297. * @example
  15298. *
  15299. * _.add(6, 4);
  15300. * // => 10
  15301. */
  15302. var add = createMathOperation(function(augend, addend) {
  15303. return augend + addend;
  15304. }, 0);
  15305. /**
  15306. * Computes `number` rounded up to `precision`.
  15307. *
  15308. * @static
  15309. * @memberOf _
  15310. * @since 3.10.0
  15311. * @category Math
  15312. * @param {number} number The number to round up.
  15313. * @param {number} [precision=0] The precision to round up to.
  15314. * @returns {number} Returns the rounded up number.
  15315. * @example
  15316. *
  15317. * _.ceil(4.006);
  15318. * // => 5
  15319. *
  15320. * _.ceil(6.004, 2);
  15321. * // => 6.01
  15322. *
  15323. * _.ceil(6040, -2);
  15324. * // => 6100
  15325. */
  15326. var ceil = createRound('ceil');
  15327. /**
  15328. * Divide two numbers.
  15329. *
  15330. * @static
  15331. * @memberOf _
  15332. * @since 4.7.0
  15333. * @category Math
  15334. * @param {number} dividend The first number in a division.
  15335. * @param {number} divisor The second number in a division.
  15336. * @returns {number} Returns the quotient.
  15337. * @example
  15338. *
  15339. * _.divide(6, 4);
  15340. * // => 1.5
  15341. */
  15342. var divide = createMathOperation(function(dividend, divisor) {
  15343. return dividend / divisor;
  15344. }, 1);
  15345. /**
  15346. * Computes `number` rounded down to `precision`.
  15347. *
  15348. * @static
  15349. * @memberOf _
  15350. * @since 3.10.0
  15351. * @category Math
  15352. * @param {number} number The number to round down.
  15353. * @param {number} [precision=0] The precision to round down to.
  15354. * @returns {number} Returns the rounded down number.
  15355. * @example
  15356. *
  15357. * _.floor(4.006);
  15358. * // => 4
  15359. *
  15360. * _.floor(0.046, 2);
  15361. * // => 0.04
  15362. *
  15363. * _.floor(4060, -2);
  15364. * // => 4000
  15365. */
  15366. var floor = createRound('floor');
  15367. /**
  15368. * Computes the maximum value of `array`. If `array` is empty or falsey,
  15369. * `undefined` is returned.
  15370. *
  15371. * @static
  15372. * @since 0.1.0
  15373. * @memberOf _
  15374. * @category Math
  15375. * @param {Array} array The array to iterate over.
  15376. * @returns {*} Returns the maximum value.
  15377. * @example
  15378. *
  15379. * _.max([4, 2, 8, 6]);
  15380. * // => 8
  15381. *
  15382. * _.max([]);
  15383. * // => undefined
  15384. */
  15385. function max(array) {
  15386. return (array && array.length)
  15387. ? baseExtremum(array, identity, baseGt)
  15388. : undefined;
  15389. }
  15390. /**
  15391. * This method is like `_.max` except that it accepts `iteratee` which is
  15392. * invoked for each element in `array` to generate the criterion by which
  15393. * the value is ranked. The iteratee is invoked with one argument: (value).
  15394. *
  15395. * @static
  15396. * @memberOf _
  15397. * @since 4.0.0
  15398. * @category Math
  15399. * @param {Array} array The array to iterate over.
  15400. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15401. * @returns {*} Returns the maximum value.
  15402. * @example
  15403. *
  15404. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15405. *
  15406. * _.maxBy(objects, function(o) { return o.n; });
  15407. * // => { 'n': 2 }
  15408. *
  15409. * // The `_.property` iteratee shorthand.
  15410. * _.maxBy(objects, 'n');
  15411. * // => { 'n': 2 }
  15412. */
  15413. function maxBy(array, iteratee) {
  15414. return (array && array.length)
  15415. ? baseExtremum(array, getIteratee(iteratee, 2), baseGt)
  15416. : undefined;
  15417. }
  15418. /**
  15419. * Computes the mean of the values in `array`.
  15420. *
  15421. * @static
  15422. * @memberOf _
  15423. * @since 4.0.0
  15424. * @category Math
  15425. * @param {Array} array The array to iterate over.
  15426. * @returns {number} Returns the mean.
  15427. * @example
  15428. *
  15429. * _.mean([4, 2, 8, 6]);
  15430. * // => 5
  15431. */
  15432. function mean(array) {
  15433. return baseMean(array, identity);
  15434. }
  15435. /**
  15436. * This method is like `_.mean` except that it accepts `iteratee` which is
  15437. * invoked for each element in `array` to generate the value to be averaged.
  15438. * The iteratee is invoked with one argument: (value).
  15439. *
  15440. * @static
  15441. * @memberOf _
  15442. * @since 4.7.0
  15443. * @category Math
  15444. * @param {Array} array The array to iterate over.
  15445. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15446. * @returns {number} Returns the mean.
  15447. * @example
  15448. *
  15449. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15450. *
  15451. * _.meanBy(objects, function(o) { return o.n; });
  15452. * // => 5
  15453. *
  15454. * // The `_.property` iteratee shorthand.
  15455. * _.meanBy(objects, 'n');
  15456. * // => 5
  15457. */
  15458. function meanBy(array, iteratee) {
  15459. return baseMean(array, getIteratee(iteratee, 2));
  15460. }
  15461. /**
  15462. * Computes the minimum value of `array`. If `array` is empty or falsey,
  15463. * `undefined` is returned.
  15464. *
  15465. * @static
  15466. * @since 0.1.0
  15467. * @memberOf _
  15468. * @category Math
  15469. * @param {Array} array The array to iterate over.
  15470. * @returns {*} Returns the minimum value.
  15471. * @example
  15472. *
  15473. * _.min([4, 2, 8, 6]);
  15474. * // => 2
  15475. *
  15476. * _.min([]);
  15477. * // => undefined
  15478. */
  15479. function min(array) {
  15480. return (array && array.length)
  15481. ? baseExtremum(array, identity, baseLt)
  15482. : undefined;
  15483. }
  15484. /**
  15485. * This method is like `_.min` except that it accepts `iteratee` which is
  15486. * invoked for each element in `array` to generate the criterion by which
  15487. * the value is ranked. The iteratee is invoked with one argument: (value).
  15488. *
  15489. * @static
  15490. * @memberOf _
  15491. * @since 4.0.0
  15492. * @category Math
  15493. * @param {Array} array The array to iterate over.
  15494. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15495. * @returns {*} Returns the minimum value.
  15496. * @example
  15497. *
  15498. * var objects = [{ 'n': 1 }, { 'n': 2 }];
  15499. *
  15500. * _.minBy(objects, function(o) { return o.n; });
  15501. * // => { 'n': 1 }
  15502. *
  15503. * // The `_.property` iteratee shorthand.
  15504. * _.minBy(objects, 'n');
  15505. * // => { 'n': 1 }
  15506. */
  15507. function minBy(array, iteratee) {
  15508. return (array && array.length)
  15509. ? baseExtremum(array, getIteratee(iteratee, 2), baseLt)
  15510. : undefined;
  15511. }
  15512. /**
  15513. * Multiply two numbers.
  15514. *
  15515. * @static
  15516. * @memberOf _
  15517. * @since 4.7.0
  15518. * @category Math
  15519. * @param {number} multiplier The first number in a multiplication.
  15520. * @param {number} multiplicand The second number in a multiplication.
  15521. * @returns {number} Returns the product.
  15522. * @example
  15523. *
  15524. * _.multiply(6, 4);
  15525. * // => 24
  15526. */
  15527. var multiply = createMathOperation(function(multiplier, multiplicand) {
  15528. return multiplier * multiplicand;
  15529. }, 1);
  15530. /**
  15531. * Computes `number` rounded to `precision`.
  15532. *
  15533. * @static
  15534. * @memberOf _
  15535. * @since 3.10.0
  15536. * @category Math
  15537. * @param {number} number The number to round.
  15538. * @param {number} [precision=0] The precision to round to.
  15539. * @returns {number} Returns the rounded number.
  15540. * @example
  15541. *
  15542. * _.round(4.006);
  15543. * // => 4
  15544. *
  15545. * _.round(4.006, 2);
  15546. * // => 4.01
  15547. *
  15548. * _.round(4060, -2);
  15549. * // => 4100
  15550. */
  15551. var round = createRound('round');
  15552. /**
  15553. * Subtract two numbers.
  15554. *
  15555. * @static
  15556. * @memberOf _
  15557. * @since 4.0.0
  15558. * @category Math
  15559. * @param {number} minuend The first number in a subtraction.
  15560. * @param {number} subtrahend The second number in a subtraction.
  15561. * @returns {number} Returns the difference.
  15562. * @example
  15563. *
  15564. * _.subtract(6, 4);
  15565. * // => 2
  15566. */
  15567. var subtract = createMathOperation(function(minuend, subtrahend) {
  15568. return minuend - subtrahend;
  15569. }, 0);
  15570. /**
  15571. * Computes the sum of the values in `array`.
  15572. *
  15573. * @static
  15574. * @memberOf _
  15575. * @since 3.4.0
  15576. * @category Math
  15577. * @param {Array} array The array to iterate over.
  15578. * @returns {number} Returns the sum.
  15579. * @example
  15580. *
  15581. * _.sum([4, 2, 8, 6]);
  15582. * // => 20
  15583. */
  15584. function sum(array) {
  15585. return (array && array.length)
  15586. ? baseSum(array, identity)
  15587. : 0;
  15588. }
  15589. /**
  15590. * This method is like `_.sum` except that it accepts `iteratee` which is
  15591. * invoked for each element in `array` to generate the value to be summed.
  15592. * The iteratee is invoked with one argument: (value).
  15593. *
  15594. * @static
  15595. * @memberOf _
  15596. * @since 4.0.0
  15597. * @category Math
  15598. * @param {Array} array The array to iterate over.
  15599. * @param {Function} [iteratee=_.identity] The iteratee invoked per element.
  15600. * @returns {number} Returns the sum.
  15601. * @example
  15602. *
  15603. * var objects = [{ 'n': 4 }, { 'n': 2 }, { 'n': 8 }, { 'n': 6 }];
  15604. *
  15605. * _.sumBy(objects, function(o) { return o.n; });
  15606. * // => 20
  15607. *
  15608. * // The `_.property` iteratee shorthand.
  15609. * _.sumBy(objects, 'n');
  15610. * // => 20
  15611. */
  15612. function sumBy(array, iteratee) {
  15613. return (array && array.length)
  15614. ? baseSum(array, getIteratee(iteratee, 2))
  15615. : 0;
  15616. }
  15617. /*------------------------------------------------------------------------*/
  15618. // Add methods that return wrapped values in chain sequences.
  15619. lodash.after = after;
  15620. lodash.ary = ary;
  15621. lodash.assign = assign;
  15622. lodash.assignIn = assignIn;
  15623. lodash.assignInWith = assignInWith;
  15624. lodash.assignWith = assignWith;
  15625. lodash.at = at;
  15626. lodash.before = before;
  15627. lodash.bind = bind;
  15628. lodash.bindAll = bindAll;
  15629. lodash.bindKey = bindKey;
  15630. lodash.castArray = castArray;
  15631. lodash.chain = chain;
  15632. lodash.chunk = chunk;
  15633. lodash.compact = compact;
  15634. lodash.concat = concat;
  15635. lodash.cond = cond;
  15636. lodash.conforms = conforms;
  15637. lodash.constant = constant;
  15638. lodash.countBy = countBy;
  15639. lodash.create = create;
  15640. lodash.curry = curry;
  15641. lodash.curryRight = curryRight;
  15642. lodash.debounce = debounce;
  15643. lodash.defaults = defaults;
  15644. lodash.defaultsDeep = defaultsDeep;
  15645. lodash.defer = defer;
  15646. lodash.delay = delay;
  15647. lodash.difference = difference;
  15648. lodash.differenceBy = differenceBy;
  15649. lodash.differenceWith = differenceWith;
  15650. lodash.drop = drop;
  15651. lodash.dropRight = dropRight;
  15652. lodash.dropRightWhile = dropRightWhile;
  15653. lodash.dropWhile = dropWhile;
  15654. lodash.fill = fill;
  15655. lodash.filter = filter;
  15656. lodash.flatMap = flatMap;
  15657. lodash.flatMapDeep = flatMapDeep;
  15658. lodash.flatMapDepth = flatMapDepth;
  15659. lodash.flatten = flatten;
  15660. lodash.flattenDeep = flattenDeep;
  15661. lodash.flattenDepth = flattenDepth;
  15662. lodash.flip = flip;
  15663. lodash.flow = flow;
  15664. lodash.flowRight = flowRight;
  15665. lodash.fromPairs = fromPairs;
  15666. lodash.functions = functions;
  15667. lodash.functionsIn = functionsIn;
  15668. lodash.groupBy = groupBy;
  15669. lodash.initial = initial;
  15670. lodash.intersection = intersection;
  15671. lodash.intersectionBy = intersectionBy;
  15672. lodash.intersectionWith = intersectionWith;
  15673. lodash.invert = invert;
  15674. lodash.invertBy = invertBy;
  15675. lodash.invokeMap = invokeMap;
  15676. lodash.iteratee = iteratee;
  15677. lodash.keyBy = keyBy;
  15678. lodash.keys = keys;
  15679. lodash.keysIn = keysIn;
  15680. lodash.map = map;
  15681. lodash.mapKeys = mapKeys;
  15682. lodash.mapValues = mapValues;
  15683. lodash.matches = matches;
  15684. lodash.matchesProperty = matchesProperty;
  15685. lodash.memoize = memoize;
  15686. lodash.merge = merge;
  15687. lodash.mergeWith = mergeWith;
  15688. lodash.method = method;
  15689. lodash.methodOf = methodOf;
  15690. lodash.mixin = mixin;
  15691. lodash.negate = negate;
  15692. lodash.nthArg = nthArg;
  15693. lodash.omit = omit;
  15694. lodash.omitBy = omitBy;
  15695. lodash.once = once;
  15696. lodash.orderBy = orderBy;
  15697. lodash.over = over;
  15698. lodash.overArgs = overArgs;
  15699. lodash.overEvery = overEvery;
  15700. lodash.overSome = overSome;
  15701. lodash.partial = partial;
  15702. lodash.partialRight = partialRight;
  15703. lodash.partition = partition;
  15704. lodash.pick = pick;
  15705. lodash.pickBy = pickBy;
  15706. lodash.property = property;
  15707. lodash.propertyOf = propertyOf;
  15708. lodash.pull = pull;
  15709. lodash.pullAll = pullAll;
  15710. lodash.pullAllBy = pullAllBy;
  15711. lodash.pullAllWith = pullAllWith;
  15712. lodash.pullAt = pullAt;
  15713. lodash.range = range;
  15714. lodash.rangeRight = rangeRight;
  15715. lodash.rearg = rearg;
  15716. lodash.reject = reject;
  15717. lodash.remove = remove;
  15718. lodash.rest = rest;
  15719. lodash.reverse = reverse;
  15720. lodash.sampleSize = sampleSize;
  15721. lodash.set = set;
  15722. lodash.setWith = setWith;
  15723. lodash.shuffle = shuffle;
  15724. lodash.slice = slice;
  15725. lodash.sortBy = sortBy;
  15726. lodash.sortedUniq = sortedUniq;
  15727. lodash.sortedUniqBy = sortedUniqBy;
  15728. lodash.split = split;
  15729. lodash.spread = spread;
  15730. lodash.tail = tail;
  15731. lodash.take = take;
  15732. lodash.takeRight = takeRight;
  15733. lodash.takeRightWhile = takeRightWhile;
  15734. lodash.takeWhile = takeWhile;
  15735. lodash.tap = tap;
  15736. lodash.throttle = throttle;
  15737. lodash.thru = thru;
  15738. lodash.toArray = toArray;
  15739. lodash.toPairs = toPairs;
  15740. lodash.toPairsIn = toPairsIn;
  15741. lodash.toPath = toPath;
  15742. lodash.toPlainObject = toPlainObject;
  15743. lodash.transform = transform;
  15744. lodash.unary = unary;
  15745. lodash.union = union;
  15746. lodash.unionBy = unionBy;
  15747. lodash.unionWith = unionWith;
  15748. lodash.uniq = uniq;
  15749. lodash.uniqBy = uniqBy;
  15750. lodash.uniqWith = uniqWith;
  15751. lodash.unset = unset;
  15752. lodash.unzip = unzip;
  15753. lodash.unzipWith = unzipWith;
  15754. lodash.update = update;
  15755. lodash.updateWith = updateWith;
  15756. lodash.values = values;
  15757. lodash.valuesIn = valuesIn;
  15758. lodash.without = without;
  15759. lodash.words = words;
  15760. lodash.wrap = wrap;
  15761. lodash.xor = xor;
  15762. lodash.xorBy = xorBy;
  15763. lodash.xorWith = xorWith;
  15764. lodash.zip = zip;
  15765. lodash.zipObject = zipObject;
  15766. lodash.zipObjectDeep = zipObjectDeep;
  15767. lodash.zipWith = zipWith;
  15768. // Add aliases.
  15769. lodash.entries = toPairs;
  15770. lodash.entriesIn = toPairsIn;
  15771. lodash.extend = assignIn;
  15772. lodash.extendWith = assignInWith;
  15773. // Add methods to `lodash.prototype`.
  15774. mixin(lodash, lodash);
  15775. /*------------------------------------------------------------------------*/
  15776. // Add methods that return unwrapped values in chain sequences.
  15777. lodash.add = add;
  15778. lodash.attempt = attempt;
  15779. lodash.camelCase = camelCase;
  15780. lodash.capitalize = capitalize;
  15781. lodash.ceil = ceil;
  15782. lodash.clamp = clamp;
  15783. lodash.clone = clone;
  15784. lodash.cloneDeep = cloneDeep;
  15785. lodash.cloneDeepWith = cloneDeepWith;
  15786. lodash.cloneWith = cloneWith;
  15787. lodash.conformsTo = conformsTo;
  15788. lodash.deburr = deburr;
  15789. lodash.defaultTo = defaultTo;
  15790. lodash.divide = divide;
  15791. lodash.endsWith = endsWith;
  15792. lodash.eq = eq;
  15793. lodash.escape = escape;
  15794. lodash.escapeRegExp = escapeRegExp;
  15795. lodash.every = every;
  15796. lodash.find = find;
  15797. lodash.findIndex = findIndex;
  15798. lodash.findKey = findKey;
  15799. lodash.findLast = findLast;
  15800. lodash.findLastIndex = findLastIndex;
  15801. lodash.findLastKey = findLastKey;
  15802. lodash.floor = floor;
  15803. lodash.forEach = forEach;
  15804. lodash.forEachRight = forEachRight;
  15805. lodash.forIn = forIn;
  15806. lodash.forInRight = forInRight;
  15807. lodash.forOwn = forOwn;
  15808. lodash.forOwnRight = forOwnRight;
  15809. lodash.get = get;
  15810. lodash.gt = gt;
  15811. lodash.gte = gte;
  15812. lodash.has = has;
  15813. lodash.hasIn = hasIn;
  15814. lodash.head = head;
  15815. lodash.identity = identity;
  15816. lodash.includes = includes;
  15817. lodash.indexOf = indexOf;
  15818. lodash.inRange = inRange;
  15819. lodash.invoke = invoke;
  15820. lodash.isArguments = isArguments;
  15821. lodash.isArray = isArray;
  15822. lodash.isArrayBuffer = isArrayBuffer;
  15823. lodash.isArrayLike = isArrayLike;
  15824. lodash.isArrayLikeObject = isArrayLikeObject;
  15825. lodash.isBoolean = isBoolean;
  15826. lodash.isBuffer = isBuffer;
  15827. lodash.isDate = isDate;
  15828. lodash.isElement = isElement;
  15829. lodash.isEmpty = isEmpty;
  15830. lodash.isEqual = isEqual;
  15831. lodash.isEqualWith = isEqualWith;
  15832. lodash.isError = isError;
  15833. lodash.isFinite = isFinite;
  15834. lodash.isFunction = isFunction;
  15835. lodash.isInteger = isInteger;
  15836. lodash.isLength = isLength;
  15837. lodash.isMap = isMap;
  15838. lodash.isMatch = isMatch;
  15839. lodash.isMatchWith = isMatchWith;
  15840. lodash.isNaN = isNaN;
  15841. lodash.isNative = isNative;
  15842. lodash.isNil = isNil;
  15843. lodash.isNull = isNull;
  15844. lodash.isNumber = isNumber;
  15845. lodash.isObject = isObject;
  15846. lodash.isObjectLike = isObjectLike;
  15847. lodash.isPlainObject = isPlainObject;
  15848. lodash.isRegExp = isRegExp;
  15849. lodash.isSafeInteger = isSafeInteger;
  15850. lodash.isSet = isSet;
  15851. lodash.isString = isString;
  15852. lodash.isSymbol = isSymbol;
  15853. lodash.isTypedArray = isTypedArray;
  15854. lodash.isUndefined = isUndefined;
  15855. lodash.isWeakMap = isWeakMap;
  15856. lodash.isWeakSet = isWeakSet;
  15857. lodash.join = join;
  15858. lodash.kebabCase = kebabCase;
  15859. lodash.last = last;
  15860. lodash.lastIndexOf = lastIndexOf;
  15861. lodash.lowerCase = lowerCase;
  15862. lodash.lowerFirst = lowerFirst;
  15863. lodash.lt = lt;
  15864. lodash.lte = lte;
  15865. lodash.max = max;
  15866. lodash.maxBy = maxBy;
  15867. lodash.mean = mean;
  15868. lodash.meanBy = meanBy;
  15869. lodash.min = min;
  15870. lodash.minBy = minBy;
  15871. lodash.stubArray = stubArray;
  15872. lodash.stubFalse = stubFalse;
  15873. lodash.stubObject = stubObject;
  15874. lodash.stubString = stubString;
  15875. lodash.stubTrue = stubTrue;
  15876. lodash.multiply = multiply;
  15877. lodash.nth = nth;
  15878. lodash.noConflict = noConflict;
  15879. lodash.noop = noop;
  15880. lodash.now = now;
  15881. lodash.pad = pad;
  15882. lodash.padEnd = padEnd;
  15883. lodash.padStart = padStart;
  15884. lodash.parseInt = parseInt;
  15885. lodash.random = random;
  15886. lodash.reduce = reduce;
  15887. lodash.reduceRight = reduceRight;
  15888. lodash.repeat = repeat;
  15889. lodash.replace = replace;
  15890. lodash.result = result;
  15891. lodash.round = round;
  15892. lodash.runInContext = runInContext;
  15893. lodash.sample = sample;
  15894. lodash.size = size;
  15895. lodash.snakeCase = snakeCase;
  15896. lodash.some = some;
  15897. lodash.sortedIndex = sortedIndex;
  15898. lodash.sortedIndexBy = sortedIndexBy;
  15899. lodash.sortedIndexOf = sortedIndexOf;
  15900. lodash.sortedLastIndex = sortedLastIndex;
  15901. lodash.sortedLastIndexBy = sortedLastIndexBy;
  15902. lodash.sortedLastIndexOf = sortedLastIndexOf;
  15903. lodash.startCase = startCase;
  15904. lodash.startsWith = startsWith;
  15905. lodash.subtract = subtract;
  15906. lodash.sum = sum;
  15907. lodash.sumBy = sumBy;
  15908. lodash.template = template;
  15909. lodash.times = times;
  15910. lodash.toFinite = toFinite;
  15911. lodash.toInteger = toInteger;
  15912. lodash.toLength = toLength;
  15913. lodash.toLower = toLower;
  15914. lodash.toNumber = toNumber;
  15915. lodash.toSafeInteger = toSafeInteger;
  15916. lodash.toString = toString;
  15917. lodash.toUpper = toUpper;
  15918. lodash.trim = trim;
  15919. lodash.trimEnd = trimEnd;
  15920. lodash.trimStart = trimStart;
  15921. lodash.truncate = truncate;
  15922. lodash.unescape = unescape;
  15923. lodash.uniqueId = uniqueId;
  15924. lodash.upperCase = upperCase;
  15925. lodash.upperFirst = upperFirst;
  15926. // Add aliases.
  15927. lodash.each = forEach;
  15928. lodash.eachRight = forEachRight;
  15929. lodash.first = head;
  15930. mixin(lodash, (function() {
  15931. var source = {};
  15932. baseForOwn(lodash, function(func, methodName) {
  15933. if (!hasOwnProperty.call(lodash.prototype, methodName)) {
  15934. source[methodName] = func;
  15935. }
  15936. });
  15937. return source;
  15938. }()), { 'chain': false });
  15939. /*------------------------------------------------------------------------*/
  15940. /**
  15941. * The semantic version number.
  15942. *
  15943. * @static
  15944. * @memberOf _
  15945. * @type {string}
  15946. */
  15947. lodash.VERSION = VERSION;
  15948. // Assign default placeholders.
  15949. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  15950. lodash[methodName].placeholder = lodash;
  15951. });
  15952. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  15953. arrayEach(['drop', 'take'], function(methodName, index) {
  15954. LazyWrapper.prototype[methodName] = function(n) {
  15955. n = n === undefined ? 1 : nativeMax(toInteger(n), 0);
  15956. var result = (this.__filtered__ && !index)
  15957. ? new LazyWrapper(this)
  15958. : this.clone();
  15959. if (result.__filtered__) {
  15960. result.__takeCount__ = nativeMin(n, result.__takeCount__);
  15961. } else {
  15962. result.__views__.push({
  15963. 'size': nativeMin(n, MAX_ARRAY_LENGTH),
  15964. 'type': methodName + (result.__dir__ < 0 ? 'Right' : '')
  15965. });
  15966. }
  15967. return result;
  15968. };
  15969. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  15970. return this.reverse()[methodName](n).reverse();
  15971. };
  15972. });
  15973. // Add `LazyWrapper` methods that accept an `iteratee` value.
  15974. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  15975. var type = index + 1,
  15976. isFilter = type == LAZY_FILTER_FLAG || type == LAZY_WHILE_FLAG;
  15977. LazyWrapper.prototype[methodName] = function(iteratee) {
  15978. var result = this.clone();
  15979. result.__iteratees__.push({
  15980. 'iteratee': getIteratee(iteratee, 3),
  15981. 'type': type
  15982. });
  15983. result.__filtered__ = result.__filtered__ || isFilter;
  15984. return result;
  15985. };
  15986. });
  15987. // Add `LazyWrapper` methods for `_.head` and `_.last`.
  15988. arrayEach(['head', 'last'], function(methodName, index) {
  15989. var takeName = 'take' + (index ? 'Right' : '');
  15990. LazyWrapper.prototype[methodName] = function() {
  15991. return this[takeName](1).value()[0];
  15992. };
  15993. });
  15994. // Add `LazyWrapper` methods for `_.initial` and `_.tail`.
  15995. arrayEach(['initial', 'tail'], function(methodName, index) {
  15996. var dropName = 'drop' + (index ? '' : 'Right');
  15997. LazyWrapper.prototype[methodName] = function() {
  15998. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  15999. };
  16000. });
  16001. LazyWrapper.prototype.compact = function() {
  16002. return this.filter(identity);
  16003. };
  16004. LazyWrapper.prototype.find = function(predicate) {
  16005. return this.filter(predicate).head();
  16006. };
  16007. LazyWrapper.prototype.findLast = function(predicate) {
  16008. return this.reverse().find(predicate);
  16009. };
  16010. LazyWrapper.prototype.invokeMap = baseRest(function(path, args) {
  16011. if (typeof path == 'function') {
  16012. return new LazyWrapper(this);
  16013. }
  16014. return this.map(function(value) {
  16015. return baseInvoke(value, path, args);
  16016. });
  16017. });
  16018. LazyWrapper.prototype.reject = function(predicate) {
  16019. return this.filter(negate(getIteratee(predicate)));
  16020. };
  16021. LazyWrapper.prototype.slice = function(start, end) {
  16022. start = toInteger(start);
  16023. var result = this;
  16024. if (result.__filtered__ && (start > 0 || end < 0)) {
  16025. return new LazyWrapper(result);
  16026. }
  16027. if (start < 0) {
  16028. result = result.takeRight(-start);
  16029. } else if (start) {
  16030. result = result.drop(start);
  16031. }
  16032. if (end !== undefined) {
  16033. end = toInteger(end);
  16034. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  16035. }
  16036. return result;
  16037. };
  16038. LazyWrapper.prototype.takeRightWhile = function(predicate) {
  16039. return this.reverse().takeWhile(predicate).reverse();
  16040. };
  16041. LazyWrapper.prototype.toArray = function() {
  16042. return this.take(MAX_ARRAY_LENGTH);
  16043. };
  16044. // Add `LazyWrapper` methods to `lodash.prototype`.
  16045. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16046. var checkIteratee = /^(?:filter|find|map|reject)|While$/.test(methodName),
  16047. isTaker = /^(?:head|last)$/.test(methodName),
  16048. lodashFunc = lodash[isTaker ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName],
  16049. retUnwrapped = isTaker || /^find/.test(methodName);
  16050. if (!lodashFunc) {
  16051. return;
  16052. }
  16053. lodash.prototype[methodName] = function() {
  16054. var value = this.__wrapped__,
  16055. args = isTaker ? [1] : arguments,
  16056. isLazy = value instanceof LazyWrapper,
  16057. iteratee = args[0],
  16058. useLazy = isLazy || isArray(value);
  16059. var interceptor = function(value) {
  16060. var result = lodashFunc.apply(lodash, arrayPush([value], args));
  16061. return (isTaker && chainAll) ? result[0] : result;
  16062. };
  16063. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  16064. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  16065. isLazy = useLazy = false;
  16066. }
  16067. var chainAll = this.__chain__,
  16068. isHybrid = !!this.__actions__.length,
  16069. isUnwrapped = retUnwrapped && !chainAll,
  16070. onlyLazy = isLazy && !isHybrid;
  16071. if (!retUnwrapped && useLazy) {
  16072. value = onlyLazy ? value : new LazyWrapper(this);
  16073. var result = func.apply(value, args);
  16074. result.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  16075. return new LodashWrapper(result, chainAll);
  16076. }
  16077. if (isUnwrapped && onlyLazy) {
  16078. return func.apply(this, args);
  16079. }
  16080. result = this.thru(interceptor);
  16081. return isUnwrapped ? (isTaker ? result.value()[0] : result.value()) : result;
  16082. };
  16083. });
  16084. // Add `Array` methods to `lodash.prototype`.
  16085. arrayEach(['pop', 'push', 'shift', 'sort', 'splice', 'unshift'], function(methodName) {
  16086. var func = arrayProto[methodName],
  16087. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  16088. retUnwrapped = /^(?:pop|shift)$/.test(methodName);
  16089. lodash.prototype[methodName] = function() {
  16090. var args = arguments;
  16091. if (retUnwrapped && !this.__chain__) {
  16092. var value = this.value();
  16093. return func.apply(isArray(value) ? value : [], args);
  16094. }
  16095. return this[chainName](function(value) {
  16096. return func.apply(isArray(value) ? value : [], args);
  16097. });
  16098. };
  16099. });
  16100. // Map minified method names to their real names.
  16101. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  16102. var lodashFunc = lodash[methodName];
  16103. if (lodashFunc) {
  16104. var key = lodashFunc.name + '';
  16105. if (!hasOwnProperty.call(realNames, key)) {
  16106. realNames[key] = [];
  16107. }
  16108. realNames[key].push({ 'name': methodName, 'func': lodashFunc });
  16109. }
  16110. });
  16111. realNames[createHybrid(undefined, WRAP_BIND_KEY_FLAG).name] = [{
  16112. 'name': 'wrapper',
  16113. 'func': undefined
  16114. }];
  16115. // Add methods to `LazyWrapper`.
  16116. LazyWrapper.prototype.clone = lazyClone;
  16117. LazyWrapper.prototype.reverse = lazyReverse;
  16118. LazyWrapper.prototype.value = lazyValue;
  16119. // Add chain sequence methods to the `lodash` wrapper.
  16120. lodash.prototype.at = wrapperAt;
  16121. lodash.prototype.chain = wrapperChain;
  16122. lodash.prototype.commit = wrapperCommit;
  16123. lodash.prototype.next = wrapperNext;
  16124. lodash.prototype.plant = wrapperPlant;
  16125. lodash.prototype.reverse = wrapperReverse;
  16126. lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  16127. // Add lazy aliases.
  16128. lodash.prototype.first = lodash.prototype.head;
  16129. if (symIterator) {
  16130. lodash.prototype[symIterator] = wrapperToIterator;
  16131. }
  16132. return lodash;
  16133. });
  16134. /*--------------------------------------------------------------------------*/
  16135. // Export lodash.
  16136. var _ = runInContext();
  16137. // Some AMD build optimizers, like r.js, check for condition patterns like:
  16138. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  16139. // Expose Lodash on the global object to prevent errors when Lodash is
  16140. // loaded by a script tag in the presence of an AMD loader.
  16141. // See http://requirejs.org/docs/errors.html#mismatch for more details.
  16142. // Use `_.noConflict` to remove Lodash from the global object.
  16143. root._ = _;
  16144. // Define as an anonymous module so, through path mapping, it can be
  16145. // referenced as the "underscore" module.
  16146. define(function() {
  16147. return _;
  16148. });
  16149. }
  16150. // Check for `exports` after `define` in case a build optimizer adds it.
  16151. else if (freeModule) {
  16152. // Export for Node.js.
  16153. (freeModule.exports = _)._ = _;
  16154. // Export for CommonJS support.
  16155. freeExports._ = _;
  16156. }
  16157. else {
  16158. // Export to the global object.
  16159. root._ = _;
  16160. }
  16161. }.call(this));
  16162. }, function(modId) {var map = {}; return __REQUIRE__(map[modId], modId); })
  16163. return __REQUIRE__(1758160678371);
  16164. })()
  16165. //miniprogram-npm-outsideDeps=[]
  16166. //# sourceMappingURL=index.js.map