index.js 412 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281112821128311284112851128611287112881128911290112911129211293112941129511296112971129811299113001130111302113031130411305113061130711308113091131011311113121131311314113151131611317113181131911320113211132211323113241132511326113271132811329113301133111332113331133411335113361133711338113391134011341113421134311344113451134611347113481134911350113511135211353113541135511356113571135811359113601136111362113631136411365113661136711368113691137011371113721137311374113751137611377113781137911380113811138211383113841138511386113871138811389113901139111392113931139411395113961139711398113991140011401114021140311404114051140611407114081140911410114111141211413114141141511416114171141811419114201142111422114231142411425114261142711428114291143011431114321143311434114351143611437114381143911440114411144211443114441144511446114471144811449114501145111452114531145411455114561145711458114591146011461114621146311464114651146611467114681146911470114711147211473114741147511476114771147811479114801148111482114831148411485114861148711488114891149011491114921149311494114951149611497114981149911500115011150211503115041150511506115071150811509115101151111512115131151411515115161151711518115191152011521115221152311524115251152611527115281152911530115311153211533115341153511536115371153811539115401154111542115431154411545115461154711548115491155011551115521155311554115551155611557115581155911560115611156211563115641156511566115671156811569115701157111572115731157411575115761157711578115791158011581115821158311584115851158611587115881158911590115911159211593115941159511596115971159811599116001160111602116031160411605116061160711608116091161011611116121161311614116151161611617116181161911620116211162211623116241162511626116271162811629116301163111632116331163411635116361163711638116391164011641116421164311644116451164611647116481164911650116511165211653116541165511656116571165811659116601166111662116631166411665116661166711668116691167011671116721167311674116751167611677116781167911680116811168211683116841168511686116871168811689116901169111692116931169411695116961169711698116991170011701117021170311704117051170611707117081170911710117111171211713117141171511716117171171811719117201172111722117231172411725117261172711728117291173011731117321173311734117351173611737117381173911740117411174211743117441174511746117471174811749117501175111752117531175411755117561175711758117591176011761117621176311764117651176611767117681176911770117711177211773117741177511776117771177811779117801178111782117831178411785117861178711788117891179011791117921179311794117951179611797117981179911800118011180211803118041180511806118071180811809118101181111812118131181411815118161181711818118191182011821118221182311824118251182611827118281182911830118311183211833118341183511836118371183811839118401184111842118431184411845118461184711848118491185011851118521185311854118551185611857118581185911860118611186211863118641186511866118671186811869118701187111872118731187411875118761187711878118791188011881118821188311884118851188611887118881188911890118911189211893118941189511896118971189811899119001190111902119031190411905119061190711908119091191011911119121191311914119151191611917119181191911920119211192211923119241192511926119271192811929119301193111932119331193411935119361193711938119391194011941119421194311944119451194611947119481194911950119511195211953119541195511956119571195811959119601196111962119631196411965119661196711968119691197011971119721197311974119751197611977119781197911980119811198211983119841198511986119871198811989119901199111992119931199411995119961199711998119991200012001120021200312004120051200612007120081200912010120111201212013120141201512016120171201812019120201202112022120231202412025120261202712028120291203012031120321203312034120351203612037120381203912040120411204212043120441204512046120471204812049120501205112052120531205412055120561205712058120591206012061120621206312064120651206612067120681206912070120711207212073120741207512076120771207812079120801208112082120831208412085120861208712088120891209012091120921209312094120951209612097120981209912100121011210212103121041210512106121071210812109121101211112112121131211412115121161211712118121191212012121121221212312124121251212612127121281212912130121311213212133121341213512136121371213812139121401214112142121431214412145121461214712148121491215012151121521215312154121551215612157121581215912160121611216212163121641216512166121671216812169121701217112172121731217412175121761217712178121791218012181121821218312184121851218612187121881218912190121911219212193121941219512196121971219812199122001220112202122031220412205122061220712208122091221012211122121221312214122151221612217122181221912220122211222212223122241222512226122271222812229122301223112232122331223412235122361223712238122391224012241122421224312244122451224612247122481224912250122511225212253122541225512256122571225812259122601226112262122631226412265122661226712268122691227012271122721227312274122751227612277122781227912280122811228212283122841228512286122871228812289122901229112292122931229412295122961229712298122991230012301123021230312304123051230612307123081230912310123111231212313123141231512316123171231812319123201232112322123231232412325123261232712328123291233012331123321233312334123351233612337123381233912340123411234212343123441234512346123471234812349123501235112352123531235412355123561235712358123591236012361123621236312364123651236612367123681236912370123711237212373123741237512376123771237812379123801238112382123831238412385123861238712388123891239012391123921239312394123951239612397123981239912400124011240212403124041240512406124071240812409124101241112412124131241412415124161241712418124191242012421124221242312424124251242612427124281242912430124311243212433124341243512436124371243812439124401244112442124431244412445124461244712448124491245012451124521245312454124551245612457124581245912460124611246212463124641246512466124671246812469124701247112472124731247412475124761247712478124791248012481124821248312484124851248612487124881248912490124911249212493124941249512496124971249812499125001250112502125031250412505125061250712508125091251012511125121251312514125151251612517125181251912520125211252212523125241252512526125271252812529125301253112532125331253412535125361253712538125391254012541125421254312544125451254612547125481254912550125511255212553125541255512556125571255812559125601256112562125631256412565125661256712568125691257012571125721257312574125751257612577125781257912580125811258212583125841258512586125871258812589125901259112592125931259412595125961259712598125991260012601126021260312604126051260612607126081260912610126111261212613126141261512616
  1. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  2. // Originally from https://github.com/lodash/lodash/blob/3.10.1/lodash.src.js
  3. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  4. //
  5. // Patches:
  6. //
  7. // ### Wed Nov 2, 2016
  8. // I added a hotfix based on https://github.com/lodash/lodash/commit/95bc54a3ddc7a25f5e134f5b376a0d1d96118f49
  9. // in order to solve https://github.com/lodash/lodash/issues/2768.
  10. // -@mikermcneil
  11. //
  12. // ### Tue Apr 3, 2018
  13. // I added a patch based on https://github.com/lodash/lodash/commit/d8e069cc3410082e44eb18fcf8e7f3d08ebe1d4a
  14. // in order to resolve https://hackerone.com/reports/310443
  15. //
  16. /////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  17. /**
  18. * @license
  19. * lodash 3.10.2 <https://github.com/treelinehq/lodash>
  20. * A fork of Lodash 3.10.1 <https://lodash.com/> with minor patches made by Mike McNeil.
  21. * Copyright 2012-2015 The Dojo Foundation <http://dojofoundation.org/>
  22. * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
  23. * Copyright 2009-2015 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
  24. * Available under MIT license <https://lodash.com/license>
  25. */
  26. ;(function() {
  27. /** Used as a safe reference for `undefined` in pre-ES5 environments. */
  28. var undefined;
  29. /** Used as the semantic version number. */
  30. var VERSION = '3.10.2';
  31. /** Used to compose bitmasks for wrapper metadata. */
  32. var BIND_FLAG = 1,
  33. BIND_KEY_FLAG = 2,
  34. CURRY_BOUND_FLAG = 4,
  35. CURRY_FLAG = 8,
  36. CURRY_RIGHT_FLAG = 16,
  37. PARTIAL_FLAG = 32,
  38. PARTIAL_RIGHT_FLAG = 64,
  39. ARY_FLAG = 128,
  40. REARG_FLAG = 256;
  41. /** Used as default options for `_.trunc`. */
  42. var DEFAULT_TRUNC_LENGTH = 30,
  43. DEFAULT_TRUNC_OMISSION = '...';
  44. /** Used to detect when a function becomes hot. */
  45. var HOT_COUNT = 150,
  46. HOT_SPAN = 16;
  47. /** Used as the size to enable large array optimizations. */
  48. var LARGE_ARRAY_SIZE = 200;
  49. /** Used to indicate the type of lazy iteratees. */
  50. var LAZY_FILTER_FLAG = 1,
  51. LAZY_MAP_FLAG = 2;
  52. /** Used as the `TypeError` message for "Functions" methods. */
  53. var FUNC_ERROR_TEXT = 'Expected a function';
  54. /** Used as the internal argument placeholder. */
  55. var PLACEHOLDER = '__lodash_placeholder__';
  56. /** `Object#toString` result references. */
  57. var argsTag = '[object Arguments]',
  58. arrayTag = '[object Array]',
  59. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  60. // Patched from https://github.com/lodash/lodash/blob/95bc54a3ddc7a25f5e134f5b376a0d1d96118f49/lodash.js#L86-L108
  61. asyncTag = '[object AsyncFunction]',
  62. genTag = '[object GeneratorFunction]',
  63. proxyTag = '[object Proxy]',
  64. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  65. boolTag = '[object Boolean]',
  66. dateTag = '[object Date]',
  67. errorTag = '[object Error]',
  68. funcTag = '[object Function]',
  69. mapTag = '[object Map]',
  70. numberTag = '[object Number]',
  71. objectTag = '[object Object]',
  72. regexpTag = '[object RegExp]',
  73. setTag = '[object Set]',
  74. stringTag = '[object String]',
  75. weakMapTag = '[object WeakMap]';
  76. var arrayBufferTag = '[object ArrayBuffer]',
  77. float32Tag = '[object Float32Array]',
  78. float64Tag = '[object Float64Array]',
  79. int8Tag = '[object Int8Array]',
  80. int16Tag = '[object Int16Array]',
  81. int32Tag = '[object Int32Array]',
  82. uint8Tag = '[object Uint8Array]',
  83. uint8ClampedTag = '[object Uint8ClampedArray]',
  84. uint16Tag = '[object Uint16Array]',
  85. uint32Tag = '[object Uint32Array]';
  86. /** Used to match empty string literals in compiled template source. */
  87. var reEmptyStringLeading = /\b__p \+= '';/g,
  88. reEmptyStringMiddle = /\b(__p \+=) '' \+/g,
  89. reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g;
  90. /** Used to match HTML entities and HTML characters. */
  91. var reEscapedHtml = /&(?:amp|lt|gt|quot|#39|#96);/g,
  92. reUnescapedHtml = /[&<>"'`]/g,
  93. reHasEscapedHtml = RegExp(reEscapedHtml.source),
  94. reHasUnescapedHtml = RegExp(reUnescapedHtml.source);
  95. /** Used to match template delimiters. */
  96. var reEscape = /<%-([\s\S]+?)%>/g,
  97. reEvaluate = /<%([\s\S]+?)%>/g,
  98. reInterpolate = /<%=([\s\S]+?)%>/g;
  99. /** Used to match property names within property paths. */
  100. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\n\\]|\\.)*?\1)\]/,
  101. reIsPlainProp = /^\w*$/,
  102. rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\n\\]|\\.)*?)\2)\]/g;
  103. /**
  104. * Used to match `RegExp` [syntax characters](http://ecma-international.org/ecma-262/6.0/#sec-patterns)
  105. * and those outlined by [`EscapeRegExpPattern`](http://ecma-international.org/ecma-262/6.0/#sec-escaperegexppattern).
  106. */
  107. var reRegExpChars = /^[:!,]|[\\^$.*+?()[\]{}|\/]|(^[0-9a-fA-Fnrtuvx])|([\n\r\u2028\u2029])/g,
  108. reHasRegExpChars = RegExp(reRegExpChars.source);
  109. /** Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). */
  110. var reComboMark = /[\u0300-\u036f\ufe20-\ufe23]/g;
  111. /** Used to match backslashes in property paths. */
  112. var reEscapeChar = /\\(\\)?/g;
  113. /** Used to match [ES template delimiters](http://ecma-international.org/ecma-262/6.0/#sec-template-literal-lexical-components). */
  114. var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g;
  115. /** Used to match `RegExp` flags from their coerced string values. */
  116. var reFlags = /\w*$/;
  117. /** Used to detect hexadecimal string values. */
  118. var reHasHexPrefix = /^0[xX]/;
  119. /** Used to detect host constructors (Safari > 5). */
  120. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  121. /** Used to detect unsigned integer values. */
  122. var reIsUint = /^\d+$/;
  123. /** Used to match latin-1 supplementary letters (excluding mathematical operators). */
  124. var reLatin1 = /[\xc0-\xd6\xd8-\xde\xdf-\xf6\xf8-\xff]/g;
  125. /** Used to ensure capturing order of template delimiters. */
  126. var reNoMatch = /($^)/;
  127. /** Used to match unescaped characters in compiled string literals. */
  128. var reUnescapedString = /['\n\r\u2028\u2029\\]/g;
  129. /** Used to match words to create compound words. */
  130. var reWords = (function() {
  131. var upper = '[A-Z\\xc0-\\xd6\\xd8-\\xde]',
  132. lower = '[a-z\\xdf-\\xf6\\xf8-\\xff]+';
  133. return RegExp(upper + '+(?=' + upper + lower + ')|' + upper + '?' + lower + '|' + upper + '+|[0-9]+', 'g');
  134. }());
  135. /** Used to assign default `context` object properties. */
  136. var contextProps = [
  137. 'Array', 'ArrayBuffer', 'Date', 'Error', 'Float32Array', 'Float64Array',
  138. 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Math', 'Number',
  139. 'Object', 'RegExp', 'Set', 'String', '_', 'clearTimeout', 'isFinite',
  140. 'parseFloat', 'parseInt', 'setTimeout', 'TypeError', 'Uint8Array',
  141. 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap'
  142. ];
  143. /** Used to fix the JScript `[[DontEnum]]` bug. */
  144. var shadowProps = [
  145. 'constructor', 'hasOwnProperty', 'isPrototypeOf', 'propertyIsEnumerable',
  146. 'toLocaleString', 'toString', 'valueOf'
  147. ];
  148. /** Used to make template sourceURLs easier to identify. */
  149. var templateCounter = -1;
  150. /** Used to identify `toStringTag` values of typed arrays. */
  151. var typedArrayTags = {};
  152. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] =
  153. typedArrayTags[int8Tag] = typedArrayTags[int16Tag] =
  154. typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] =
  155. typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] =
  156. typedArrayTags[uint32Tag] = true;
  157. typedArrayTags[argsTag] = typedArrayTags[arrayTag] =
  158. typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] =
  159. typedArrayTags[dateTag] = typedArrayTags[errorTag] =
  160. typedArrayTags[funcTag] = typedArrayTags[mapTag] =
  161. typedArrayTags[numberTag] = typedArrayTags[objectTag] =
  162. typedArrayTags[regexpTag] = typedArrayTags[setTag] =
  163. typedArrayTags[stringTag] = typedArrayTags[weakMapTag] = false;
  164. /** Used to identify `toStringTag` values supported by `_.clone`. */
  165. var cloneableTags = {};
  166. cloneableTags[argsTag] = cloneableTags[arrayTag] =
  167. cloneableTags[arrayBufferTag] = cloneableTags[boolTag] =
  168. cloneableTags[dateTag] = cloneableTags[float32Tag] =
  169. cloneableTags[float64Tag] = cloneableTags[int8Tag] =
  170. cloneableTags[int16Tag] = cloneableTags[int32Tag] =
  171. cloneableTags[numberTag] = cloneableTags[objectTag] =
  172. cloneableTags[regexpTag] = cloneableTags[stringTag] =
  173. cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] =
  174. cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true;
  175. cloneableTags[errorTag] = cloneableTags[funcTag] =
  176. cloneableTags[mapTag] = cloneableTags[setTag] =
  177. cloneableTags[weakMapTag] = false;
  178. /** Used to map latin-1 supplementary letters to basic latin letters. */
  179. var deburredLetters = {
  180. '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A',
  181. '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a',
  182. '\xc7': 'C', '\xe7': 'c',
  183. '\xd0': 'D', '\xf0': 'd',
  184. '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E',
  185. '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e',
  186. '\xcC': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I',
  187. '\xeC': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i',
  188. '\xd1': 'N', '\xf1': 'n',
  189. '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O',
  190. '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o',
  191. '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U',
  192. '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u',
  193. '\xdd': 'Y', '\xfd': 'y', '\xff': 'y',
  194. '\xc6': 'Ae', '\xe6': 'ae',
  195. '\xde': 'Th', '\xfe': 'th',
  196. '\xdf': 'ss'
  197. };
  198. /** Used to map characters to HTML entities. */
  199. var htmlEscapes = {
  200. '&': '&amp;',
  201. '<': '&lt;',
  202. '>': '&gt;',
  203. '"': '&quot;',
  204. "'": '&#39;',
  205. '`': '&#96;'
  206. };
  207. /** Used to map HTML entities to characters. */
  208. var htmlUnescapes = {
  209. '&amp;': '&',
  210. '&lt;': '<',
  211. '&gt;': '>',
  212. '&quot;': '"',
  213. '&#39;': "'",
  214. '&#96;': '`'
  215. };
  216. /** Used to determine if values are of the language type `Object`. */
  217. var objectTypes = {
  218. 'function': true,
  219. 'object': true
  220. };
  221. /** Used to escape characters for inclusion in compiled regexes. */
  222. var regexpEscapes = {
  223. '0': 'x30', '1': 'x31', '2': 'x32', '3': 'x33', '4': 'x34',
  224. '5': 'x35', '6': 'x36', '7': 'x37', '8': 'x38', '9': 'x39',
  225. 'A': 'x41', 'B': 'x42', 'C': 'x43', 'D': 'x44', 'E': 'x45', 'F': 'x46',
  226. 'a': 'x61', 'b': 'x62', 'c': 'x63', 'd': 'x64', 'e': 'x65', 'f': 'x66',
  227. 'n': 'x6e', 'r': 'x72', 't': 'x74', 'u': 'x75', 'v': 'x76', 'x': 'x78'
  228. };
  229. /** Used to escape characters for inclusion in compiled string literals. */
  230. var stringEscapes = {
  231. '\\': '\\',
  232. "'": "'",
  233. '\n': 'n',
  234. '\r': 'r',
  235. '\u2028': 'u2028',
  236. '\u2029': 'u2029'
  237. };
  238. /** Detect free variable `exports`. */
  239. var freeExports = objectTypes[typeof exports] && exports && !exports.nodeType && exports;
  240. /** Detect free variable `module`. */
  241. var freeModule = objectTypes[typeof module] && module && !module.nodeType && module;
  242. /** Detect free variable `global` from Node.js. */
  243. var freeGlobal = freeExports && freeModule && typeof global == 'object' && global && global.Object && global;
  244. /** Detect free variable `self`. */
  245. var freeSelf = objectTypes[typeof self] && self && self.Object && self;
  246. /** Detect free variable `window`. */
  247. var freeWindow = objectTypes[typeof window] && window && window.Object && window;
  248. /** Detect the popular CommonJS extension `module.exports`. */
  249. var moduleExports = freeModule && freeModule.exports === freeExports && freeExports;
  250. /**
  251. * Used as a reference to the global object.
  252. *
  253. * The `this` value is used if it's the global object to avoid Greasemonkey's
  254. * restricted `window` object, otherwise the `window` object is used.
  255. */
  256. var root = freeGlobal || ((freeWindow !== (this && this.window)) && freeWindow) || freeSelf || this;
  257. /*--------------------------------------------------------------------------*/
  258. /**
  259. * The base implementation of `compareAscending` which compares values and
  260. * sorts them in ascending order without guaranteeing a stable sort.
  261. *
  262. * @private
  263. * @param {*} value The value to compare.
  264. * @param {*} other The other value to compare.
  265. * @returns {number} Returns the sort order indicator for `value`.
  266. */
  267. function baseCompareAscending(value, other) {
  268. if (value !== other) {
  269. var valIsNull = value === null,
  270. valIsUndef = value === undefined,
  271. valIsReflexive = value === value;
  272. var othIsNull = other === null,
  273. othIsUndef = other === undefined,
  274. othIsReflexive = other === other;
  275. if ((value > other && !othIsNull) || !valIsReflexive ||
  276. (valIsNull && !othIsUndef && othIsReflexive) ||
  277. (valIsUndef && othIsReflexive)) {
  278. return 1;
  279. }
  280. if ((value < other && !valIsNull) || !othIsReflexive ||
  281. (othIsNull && !valIsUndef && valIsReflexive) ||
  282. (othIsUndef && valIsReflexive)) {
  283. return -1;
  284. }
  285. }
  286. return 0;
  287. }
  288. /**
  289. * The base implementation of `_.findIndex` and `_.findLastIndex` without
  290. * support for callback shorthands and `this` binding.
  291. *
  292. * @private
  293. * @param {Array} array The array to search.
  294. * @param {Function} predicate The function invoked per iteration.
  295. * @param {boolean} [fromRight] Specify iterating from right to left.
  296. * @returns {number} Returns the index of the matched value, else `-1`.
  297. */
  298. function baseFindIndex(array, predicate, fromRight) {
  299. var length = array.length,
  300. index = fromRight ? length : -1;
  301. while ((fromRight ? index-- : ++index < length)) {
  302. if (predicate(array[index], index, array)) {
  303. return index;
  304. }
  305. }
  306. return -1;
  307. }
  308. /**
  309. * The base implementation of `_.indexOf` without support for binary searches.
  310. *
  311. * @private
  312. * @param {Array} array The array to search.
  313. * @param {*} value The value to search for.
  314. * @param {number} fromIndex The index to search from.
  315. * @returns {number} Returns the index of the matched value, else `-1`.
  316. */
  317. function baseIndexOf(array, value, fromIndex) {
  318. if (value !== value) {
  319. return indexOfNaN(array, fromIndex);
  320. }
  321. var index = fromIndex - 1,
  322. length = array.length;
  323. while (++index < length) {
  324. if (array[index] === value) {
  325. return index;
  326. }
  327. }
  328. return -1;
  329. }
  330. /**
  331. * The base implementation of `_.isFunction` without support for environments
  332. * with incorrect `typeof` results.
  333. *
  334. * @private
  335. * @param {*} value The value to check.
  336. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  337. */
  338. function baseIsFunction(value) {
  339. // Avoid a Chakra JIT bug in compatibility modes of IE 11.
  340. // See https://github.com/jashkenas/underscore/issues/1621 for more details.
  341. return typeof value == 'function' || false;
  342. }
  343. /**
  344. * Converts `value` to a string if it's not one. An empty string is returned
  345. * for `null` or `undefined` values.
  346. *
  347. * @private
  348. * @param {*} value The value to process.
  349. * @returns {string} Returns the string.
  350. */
  351. function baseToString(value) {
  352. return value == null ? '' : (value + '');
  353. }
  354. /**
  355. * Used by `_.trim` and `_.trimLeft` to get the index of the first character
  356. * of `string` that is not found in `chars`.
  357. *
  358. * @private
  359. * @param {string} string The string to inspect.
  360. * @param {string} chars The characters to find.
  361. * @returns {number} Returns the index of the first character not found in `chars`.
  362. */
  363. function charsLeftIndex(string, chars) {
  364. var index = -1,
  365. length = string.length;
  366. while (++index < length && chars.indexOf(string.charAt(index)) > -1) {}
  367. return index;
  368. }
  369. /**
  370. * Used by `_.trim` and `_.trimRight` to get the index of the last character
  371. * of `string` that is not found in `chars`.
  372. *
  373. * @private
  374. * @param {string} string The string to inspect.
  375. * @param {string} chars The characters to find.
  376. * @returns {number} Returns the index of the last character not found in `chars`.
  377. */
  378. function charsRightIndex(string, chars) {
  379. var index = string.length;
  380. while (index-- && chars.indexOf(string.charAt(index)) > -1) {}
  381. return index;
  382. }
  383. /**
  384. * Used by `_.sortBy` to compare transformed elements of a collection and stable
  385. * sort them in ascending order.
  386. *
  387. * @private
  388. * @param {Object} object The object to compare.
  389. * @param {Object} other The other object to compare.
  390. * @returns {number} Returns the sort order indicator for `object`.
  391. */
  392. function compareAscending(object, other) {
  393. return baseCompareAscending(object.criteria, other.criteria) || (object.index - other.index);
  394. }
  395. /**
  396. * Used by `_.sortByOrder` to compare multiple properties of a value to another
  397. * and stable sort them.
  398. *
  399. * If `orders` is unspecified, all valuess are sorted in ascending order. Otherwise,
  400. * a value is sorted in ascending order if its corresponding order is "asc", and
  401. * descending if "desc".
  402. *
  403. * @private
  404. * @param {Object} object The object to compare.
  405. * @param {Object} other The other object to compare.
  406. * @param {boolean[]} orders The order to sort by for each property.
  407. * @returns {number} Returns the sort order indicator for `object`.
  408. */
  409. function compareMultiple(object, other, orders) {
  410. var index = -1,
  411. objCriteria = object.criteria,
  412. othCriteria = other.criteria,
  413. length = objCriteria.length,
  414. ordersLength = orders.length;
  415. while (++index < length) {
  416. var result = baseCompareAscending(objCriteria[index], othCriteria[index]);
  417. if (result) {
  418. if (index >= ordersLength) {
  419. return result;
  420. }
  421. var order = orders[index];
  422. return result * ((order === 'asc' || order === true) ? 1 : -1);
  423. }
  424. }
  425. // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications
  426. // that causes it, under certain circumstances, to provide the same value for
  427. // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247
  428. // for more details.
  429. //
  430. // This also ensures a stable sort in V8 and other engines.
  431. // See https://code.google.com/p/v8/issues/detail?id=90 for more details.
  432. return object.index - other.index;
  433. }
  434. /**
  435. * Used by `_.deburr` to convert latin-1 supplementary letters to basic latin letters.
  436. *
  437. * @private
  438. * @param {string} letter The matched letter to deburr.
  439. * @returns {string} Returns the deburred letter.
  440. */
  441. function deburrLetter(letter) {
  442. return deburredLetters[letter];
  443. }
  444. /**
  445. * Used by `_.escape` to convert characters to HTML entities.
  446. *
  447. * @private
  448. * @param {string} chr The matched character to escape.
  449. * @returns {string} Returns the escaped character.
  450. */
  451. function escapeHtmlChar(chr) {
  452. return htmlEscapes[chr];
  453. }
  454. /**
  455. * Used by `_.escapeRegExp` to escape characters for inclusion in compiled regexes.
  456. *
  457. * @private
  458. * @param {string} chr The matched character to escape.
  459. * @param {string} leadingChar The capture group for a leading character.
  460. * @param {string} whitespaceChar The capture group for a whitespace character.
  461. * @returns {string} Returns the escaped character.
  462. */
  463. function escapeRegExpChar(chr, leadingChar, whitespaceChar) {
  464. if (leadingChar) {
  465. chr = regexpEscapes[chr];
  466. } else if (whitespaceChar) {
  467. chr = stringEscapes[chr];
  468. }
  469. return '\\' + chr;
  470. }
  471. /**
  472. * Used by `_.template` to escape characters for inclusion in compiled string literals.
  473. *
  474. * @private
  475. * @param {string} chr The matched character to escape.
  476. * @returns {string} Returns the escaped character.
  477. */
  478. function escapeStringChar(chr) {
  479. return '\\' + stringEscapes[chr];
  480. }
  481. /**
  482. * Gets the index at which the first occurrence of `NaN` is found in `array`.
  483. *
  484. * @private
  485. * @param {Array} array The array to search.
  486. * @param {number} fromIndex The index to search from.
  487. * @param {boolean} [fromRight] Specify iterating from right to left.
  488. * @returns {number} Returns the index of the matched `NaN`, else `-1`.
  489. */
  490. function indexOfNaN(array, fromIndex, fromRight) {
  491. var length = array.length,
  492. index = fromIndex + (fromRight ? 0 : -1);
  493. while ((fromRight ? index-- : ++index < length)) {
  494. var other = array[index];
  495. if (other !== other) {
  496. return index;
  497. }
  498. }
  499. return -1;
  500. }
  501. /**
  502. * Checks if `value` is a host object in IE < 9.
  503. *
  504. * @private
  505. * @param {*} value The value to check.
  506. * @returns {boolean} Returns `true` if `value` is a host object, else `false`.
  507. */
  508. var isHostObject = (function() {
  509. try {
  510. Object({ 'toString': 0 } + '');
  511. } catch(e) {
  512. return function() { return false; };
  513. }
  514. return function(value) {
  515. // IE < 9 presents many host objects as `Object` objects that can coerce
  516. // to strings despite having improperly defined `toString` methods.
  517. return typeof value.toString != 'function' && typeof (value + '') == 'string';
  518. };
  519. }());
  520. /**
  521. * Checks if `value` is object-like.
  522. *
  523. * @private
  524. * @param {*} value The value to check.
  525. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  526. */
  527. function isObjectLike(value) {
  528. return !!value && typeof value == 'object';
  529. }
  530. /**
  531. * Used by `trimmedLeftIndex` and `trimmedRightIndex` to determine if a
  532. * character code is whitespace.
  533. *
  534. * @private
  535. * @param {number} charCode The character code to inspect.
  536. * @returns {boolean} Returns `true` if `charCode` is whitespace, else `false`.
  537. */
  538. function isSpace(charCode) {
  539. return ((charCode <= 160 && (charCode >= 9 && charCode <= 13) || charCode == 32 || charCode == 160) || charCode == 5760 || charCode == 6158 ||
  540. (charCode >= 8192 && (charCode <= 8202 || charCode == 8232 || charCode == 8233 || charCode == 8239 || charCode == 8287 || charCode == 12288 || charCode == 65279)));
  541. }
  542. /**
  543. * Replaces all `placeholder` elements in `array` with an internal placeholder
  544. * and returns an array of their indexes.
  545. *
  546. * @private
  547. * @param {Array} array The array to modify.
  548. * @param {*} placeholder The placeholder to replace.
  549. * @returns {Array} Returns the new array of placeholder indexes.
  550. */
  551. function replaceHolders(array, placeholder) {
  552. var index = -1,
  553. length = array.length,
  554. resIndex = -1,
  555. result = [];
  556. while (++index < length) {
  557. if (array[index] === placeholder) {
  558. array[index] = PLACEHOLDER;
  559. result[++resIndex] = index;
  560. }
  561. }
  562. return result;
  563. }
  564. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  565. // Patched from https://github.com/lodash/lodash/commit/d8e069cc3410082e44eb18fcf8e7f3d08ebe1d4a#diff-001d0647fb00f8336795faccdec19a31R1249
  566. //```
  567. /**
  568. * Gets the value at `key`, unless `key` is "__proto__".
  569. *
  570. * @private
  571. * @param {Object} object The object to query.
  572. * @param {string} key The key of the property to get.
  573. * @returns {*} Returns the property value.
  574. */
  575. function safeGet(object, key) {
  576. return key == '__proto__'
  577. ? undefined
  578. : object[key];
  579. }
  580. //```
  581. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  582. /**
  583. * An implementation of `_.uniq` optimized for sorted arrays without support
  584. * for callback shorthands and `this` binding.
  585. *
  586. * @private
  587. * @param {Array} array The array to inspect.
  588. * @param {Function} [iteratee] The function invoked per iteration.
  589. * @returns {Array} Returns the new duplicate free array.
  590. */
  591. function sortedUniq(array, iteratee) {
  592. var seen,
  593. index = -1,
  594. length = array.length,
  595. resIndex = -1,
  596. result = [];
  597. while (++index < length) {
  598. var value = array[index],
  599. computed = iteratee ? iteratee(value, index, array) : value;
  600. if (!index || seen !== computed) {
  601. seen = computed;
  602. result[++resIndex] = value;
  603. }
  604. }
  605. return result;
  606. }
  607. /**
  608. * Used by `_.trim` and `_.trimLeft` to get the index of the first non-whitespace
  609. * character of `string`.
  610. *
  611. * @private
  612. * @param {string} string The string to inspect.
  613. * @returns {number} Returns the index of the first non-whitespace character.
  614. */
  615. function trimmedLeftIndex(string) {
  616. var index = -1,
  617. length = string.length;
  618. while (++index < length && isSpace(string.charCodeAt(index))) {}
  619. return index;
  620. }
  621. /**
  622. * Used by `_.trim` and `_.trimRight` to get the index of the last non-whitespace
  623. * character of `string`.
  624. *
  625. * @private
  626. * @param {string} string The string to inspect.
  627. * @returns {number} Returns the index of the last non-whitespace character.
  628. */
  629. function trimmedRightIndex(string) {
  630. var index = string.length;
  631. while (index-- && isSpace(string.charCodeAt(index))) {}
  632. return index;
  633. }
  634. /**
  635. * Used by `_.unescape` to convert HTML entities to characters.
  636. *
  637. * @private
  638. * @param {string} chr The matched character to unescape.
  639. * @returns {string} Returns the unescaped character.
  640. */
  641. function unescapeHtmlChar(chr) {
  642. return htmlUnescapes[chr];
  643. }
  644. /*--------------------------------------------------------------------------*/
  645. /**
  646. * Create a new pristine `lodash` function using the given `context` object.
  647. *
  648. * @static
  649. * @memberOf _
  650. * @category Utility
  651. * @param {Object} [context=root] The context object.
  652. * @returns {Function} Returns a new `lodash` function.
  653. * @example
  654. *
  655. * _.mixin({ 'foo': _.constant('foo') });
  656. *
  657. * var lodash = _.runInContext();
  658. * lodash.mixin({ 'bar': lodash.constant('bar') });
  659. *
  660. * _.isFunction(_.foo);
  661. * // => true
  662. * _.isFunction(_.bar);
  663. * // => false
  664. *
  665. * lodash.isFunction(lodash.foo);
  666. * // => false
  667. * lodash.isFunction(lodash.bar);
  668. * // => true
  669. *
  670. * // using `context` to mock `Date#getTime` use in `_.now`
  671. * var mock = _.runInContext({
  672. * 'Date': function() {
  673. * return { 'getTime': getTimeMock };
  674. * }
  675. * });
  676. *
  677. * // or creating a suped-up `defer` in Node.js
  678. * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer;
  679. */
  680. function runInContext(context) {
  681. // Avoid issues with some ES3 environments that attempt to use values, named
  682. // after built-in constructors like `Object`, for the creation of literals.
  683. // ES5 clears this up by stating that literals must use built-in constructors.
  684. // See https://es5.github.io/#x11.1.5 for more details.
  685. context = context ? _.defaults(root.Object(), context, _.pick(root, contextProps)) : root;
  686. /** Native constructor references. */
  687. var Array = context.Array,
  688. Date = context.Date,
  689. Error = context.Error,
  690. Function = context.Function,
  691. Math = context.Math,
  692. Number = context.Number,
  693. Object = context.Object,
  694. RegExp = context.RegExp,
  695. String = context.String,
  696. TypeError = context.TypeError;
  697. /** Used for native method references. */
  698. var arrayProto = Array.prototype,
  699. errorProto = Error.prototype,
  700. objectProto = Object.prototype,
  701. stringProto = String.prototype;
  702. /** Used to resolve the decompiled source of functions. */
  703. var fnToString = Function.prototype.toString;
  704. /** Used to check objects for own properties. */
  705. var hasOwnProperty = objectProto.hasOwnProperty;
  706. /** Used to generate unique IDs. */
  707. var idCounter = 0;
  708. /**
  709. * Used to resolve the [`toStringTag`](http://ecma-international.org/ecma-262/6.0/#sec-object.prototype.tostring)
  710. * of values.
  711. */
  712. var objToString = objectProto.toString;
  713. /** Used to restore the original `_` reference in `_.noConflict`. */
  714. var oldDash = root._;
  715. /** Used to detect if a method is native. */
  716. var reIsNative = RegExp('^' +
  717. fnToString.call(hasOwnProperty).replace(/[\\^$.*+?()[\]{}|]/g, '\\$&')
  718. .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$'
  719. );
  720. /** Native method references. */
  721. var ArrayBuffer = context.ArrayBuffer,
  722. clearTimeout = context.clearTimeout,
  723. parseFloat = context.parseFloat,
  724. pow = Math.pow,
  725. propertyIsEnumerable = objectProto.propertyIsEnumerable,
  726. Set = getNative(context, 'Set'),
  727. setTimeout = context.setTimeout,
  728. splice = arrayProto.splice,
  729. Uint8Array = context.Uint8Array,
  730. WeakMap = getNative(context, 'WeakMap');
  731. /* Native method references for those with the same name as other `lodash` methods. */
  732. var nativeCeil = Math.ceil,
  733. nativeCreate = getNative(Object, 'create'),
  734. nativeFloor = Math.floor,
  735. nativeIsArray = getNative(Array, 'isArray'),
  736. nativeIsFinite = context.isFinite,
  737. nativeKeys = getNative(Object, 'keys'),
  738. nativeMax = Math.max,
  739. nativeMin = Math.min,
  740. nativeNow = getNative(Date, 'now'),
  741. nativeParseInt = context.parseInt,
  742. nativeRandom = Math.random;
  743. /** Used as references for `-Infinity` and `Infinity`. */
  744. var NEGATIVE_INFINITY = Number.NEGATIVE_INFINITY,
  745. POSITIVE_INFINITY = Number.POSITIVE_INFINITY;
  746. /** Used as references for the maximum length and index of an array. */
  747. var MAX_ARRAY_LENGTH = 4294967295,
  748. MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1,
  749. HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1;
  750. /**
  751. * Used as the [maximum length](http://ecma-international.org/ecma-262/6.0/#sec-number.max_safe_integer)
  752. * of an array-like value.
  753. */
  754. var MAX_SAFE_INTEGER = 9007199254740991;
  755. /** Used to store function metadata. */
  756. var metaMap = WeakMap && new WeakMap;
  757. /** Used to lookup unminified function names. */
  758. var realNames = {};
  759. /** Used to lookup a type array constructors by `toStringTag`. */
  760. var ctorByTag = {};
  761. ctorByTag[float32Tag] = context.Float32Array;
  762. ctorByTag[float64Tag] = context.Float64Array;
  763. ctorByTag[int8Tag] = context.Int8Array;
  764. ctorByTag[int16Tag] = context.Int16Array;
  765. ctorByTag[int32Tag] = context.Int32Array;
  766. ctorByTag[uint8Tag] = Uint8Array;
  767. ctorByTag[uint8ClampedTag] = context.Uint8ClampedArray;
  768. ctorByTag[uint16Tag] = context.Uint16Array;
  769. ctorByTag[uint32Tag] = context.Uint32Array;
  770. /** Used to avoid iterating over non-enumerable properties in IE < 9. */
  771. var nonEnumProps = {};
  772. nonEnumProps[arrayTag] = nonEnumProps[dateTag] = nonEnumProps[numberTag] = { 'constructor': true, 'toLocaleString': true, 'toString': true, 'valueOf': true };
  773. nonEnumProps[boolTag] = nonEnumProps[stringTag] = { 'constructor': true, 'toString': true, 'valueOf': true };
  774. nonEnumProps[errorTag] = nonEnumProps[funcTag] = nonEnumProps[regexpTag] = { 'constructor': true, 'toString': true };
  775. nonEnumProps[objectTag] = { 'constructor': true };
  776. arrayEach(shadowProps, function(key) {
  777. for (var tag in nonEnumProps) {
  778. if (hasOwnProperty.call(nonEnumProps, tag)) {
  779. var props = nonEnumProps[tag];
  780. props[key] = hasOwnProperty.call(props, key);
  781. }
  782. }
  783. });
  784. /*------------------------------------------------------------------------*/
  785. /**
  786. * Creates a `lodash` object which wraps `value` to enable implicit chaining.
  787. * Methods that operate on and return arrays, collections, and functions can
  788. * be chained together. Methods that retrieve a single value or may return a
  789. * primitive value will automatically end the chain returning the unwrapped
  790. * value. Explicit chaining may be enabled using `_.chain`. The execution of
  791. * chained methods is lazy, that is, execution is deferred until `_#value`
  792. * is implicitly or explicitly called.
  793. *
  794. * Lazy evaluation allows several methods to support shortcut fusion. Shortcut
  795. * fusion is an optimization strategy which merge iteratee calls; this can help
  796. * to avoid the creation of intermediate data structures and greatly reduce the
  797. * number of iteratee executions.
  798. *
  799. * Chaining is supported in custom builds as long as the `_#value` method is
  800. * directly or indirectly included in the build.
  801. *
  802. * In addition to lodash methods, wrappers have `Array` and `String` methods.
  803. *
  804. * The wrapper `Array` methods are:
  805. * `concat`, `join`, `pop`, `push`, `reverse`, `shift`, `slice`, `sort`,
  806. * `splice`, and `unshift`
  807. *
  808. * The wrapper `String` methods are:
  809. * `replace` and `split`
  810. *
  811. * The wrapper methods that support shortcut fusion are:
  812. * `compact`, `drop`, `dropRight`, `dropRightWhile`, `dropWhile`, `filter`,
  813. * `first`, `initial`, `last`, `map`, `pluck`, `reject`, `rest`, `reverse`,
  814. * `slice`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, `toArray`,
  815. * and `where`
  816. *
  817. * The chainable wrapper methods are:
  818. * `after`, `ary`, `assign`, `at`, `before`, `bind`, `bindAll`, `bindKey`,
  819. * `callback`, `chain`, `chunk`, `commit`, `compact`, `concat`, `constant`,
  820. * `countBy`, `create`, `curry`, `debounce`, `defaults`, `defaultsDeep`,
  821. * `defer`, `delay`, `difference`, `drop`, `dropRight`, `dropRightWhile`,
  822. * `dropWhile`, `fill`, `filter`, `flatten`, `flattenDeep`, `flow`, `flowRight`,
  823. * `forEach`, `forEachRight`, `forIn`, `forInRight`, `forOwn`, `forOwnRight`,
  824. * `functions`, `groupBy`, `indexBy`, `initial`, `intersection`, `invert`,
  825. * `invoke`, `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`,
  826. * `matchesProperty`, `memoize`, `merge`, `method`, `methodOf`, `mixin`,
  827. * `modArgs`, `negate`, `omit`, `once`, `pairs`, `partial`, `partialRight`,
  828. * `partition`, `pick`, `plant`, `pluck`, `property`, `propertyOf`, `pull`,
  829. * `pullAt`, `push`, `range`, `rearg`, `reject`, `remove`, `rest`, `restParam`,
  830. * `reverse`, `set`, `shuffle`, `slice`, `sort`, `sortBy`, `sortByAll`,
  831. * `sortByOrder`, `splice`, `spread`, `take`, `takeRight`, `takeRightWhile`,
  832. * `takeWhile`, `tap`, `throttle`, `thru`, `times`, `toArray`, `toPlainObject`,
  833. * `transform`, `union`, `uniq`, `unshift`, `unzip`, `unzipWith`, `values`,
  834. * `valuesIn`, `where`, `without`, `wrap`, `xor`, `zip`, `zipObject`, `zipWith`
  835. *
  836. * The wrapper methods that are **not** chainable by default are:
  837. * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clone`, `cloneDeep`,
  838. * `deburr`, `endsWith`, `escape`, `escapeRegExp`, `every`, `find`, `findIndex`,
  839. * `findKey`, `findLast`, `findLastIndex`, `findLastKey`, `findWhere`, `first`,
  840. * `floor`, `get`, `gt`, `gte`, `has`, `identity`, `includes`, `indexOf`,
  841. * `inRange`, `isArguments`, `isArray`, `isBoolean`, `isDate`, `isElement`,
  842. * `isEmpty`, `isEqual`, `isError`, `isFinite` `isFunction`, `isMatch`,
  843. * `isNative`, `isNaN`, `isNull`, `isNumber`, `isObject`, `isPlainObject`,
  844. * `isRegExp`, `isString`, `isUndefined`, `isTypedArray`, `join`, `kebabCase`,
  845. * `last`, `lastIndexOf`, `lt`, `lte`, `max`, `min`, `noConflict`, `noop`,
  846. * `now`, `pad`, `padLeft`, `padRight`, `parseInt`, `pop`, `random`, `reduce`,
  847. * `reduceRight`, `repeat`, `result`, `round`, `runInContext`, `shift`, `size`,
  848. * `snakeCase`, `some`, `sortedIndex`, `sortedLastIndex`, `startCase`,
  849. * `startsWith`, `sum`, `template`, `trim`, `trimLeft`, `trimRight`, `trunc`,
  850. * `unescape`, `uniqueId`, `value`, and `words`
  851. *
  852. * The wrapper method `sample` will return a wrapped value when `n` is provided,
  853. * otherwise an unwrapped value is returned.
  854. *
  855. * @name _
  856. * @constructor
  857. * @category Chain
  858. * @param {*} value The value to wrap in a `lodash` instance.
  859. * @returns {Object} Returns the new `lodash` wrapper instance.
  860. * @example
  861. *
  862. * var wrapped = _([1, 2, 3]);
  863. *
  864. * // returns an unwrapped value
  865. * wrapped.reduce(function(total, n) {
  866. * return total + n;
  867. * });
  868. * // => 6
  869. *
  870. * // returns a wrapped value
  871. * var squares = wrapped.map(function(n) {
  872. * return n * n;
  873. * });
  874. *
  875. * _.isArray(squares);
  876. * // => false
  877. *
  878. * _.isArray(squares.value());
  879. * // => true
  880. */
  881. function lodash(value) {
  882. if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) {
  883. if (value instanceof LodashWrapper) {
  884. return value;
  885. }
  886. if (hasOwnProperty.call(value, '__chain__') && hasOwnProperty.call(value, '__wrapped__')) {
  887. return wrapperClone(value);
  888. }
  889. }
  890. return new LodashWrapper(value);
  891. }
  892. /**
  893. * The function whose prototype all chaining wrappers inherit from.
  894. *
  895. * @private
  896. */
  897. function baseLodash() {
  898. // No operation performed.
  899. }
  900. /**
  901. * The base constructor for creating `lodash` wrapper objects.
  902. *
  903. * @private
  904. * @param {*} value The value to wrap.
  905. * @param {boolean} [chainAll] Enable chaining for all wrapper methods.
  906. * @param {Array} [actions=[]] Actions to peform to resolve the unwrapped value.
  907. */
  908. function LodashWrapper(value, chainAll, actions) {
  909. this.__wrapped__ = value;
  910. this.__actions__ = actions || [];
  911. this.__chain__ = !!chainAll;
  912. }
  913. /**
  914. * An object environment feature flags.
  915. *
  916. * @static
  917. * @memberOf _
  918. * @type Object
  919. */
  920. var support = lodash.support = {};
  921. (function(x) {
  922. var Ctor = function() { this.x = x; },
  923. object = { '0': x, 'length': x },
  924. props = [];
  925. Ctor.prototype = { 'valueOf': x, 'y': x };
  926. for (var key in new Ctor) { props.push(key); }
  927. /**
  928. * Detect if `name` or `message` properties of `Error.prototype` are
  929. * enumerable by default (IE < 9, Safari < 5.1).
  930. *
  931. * @memberOf _.support
  932. * @type boolean
  933. */
  934. support.enumErrorProps = propertyIsEnumerable.call(errorProto, 'message') ||
  935. propertyIsEnumerable.call(errorProto, 'name');
  936. /**
  937. * Detect if `prototype` properties are enumerable by default.
  938. *
  939. * Firefox < 3.6, Opera > 9.50 - Opera < 11.60, and Safari < 5.1
  940. * (if the prototype or a property on the prototype has been set)
  941. * incorrectly set the `[[Enumerable]]` value of a function's `prototype`
  942. * property to `true`.
  943. *
  944. * @memberOf _.support
  945. * @type boolean
  946. */
  947. support.enumPrototypes = propertyIsEnumerable.call(Ctor, 'prototype');
  948. /**
  949. * Detect if properties shadowing those on `Object.prototype` are non-enumerable.
  950. *
  951. * In IE < 9 an object's own properties, shadowing non-enumerable ones,
  952. * are made non-enumerable as well (a.k.a the JScript `[[DontEnum]]` bug).
  953. *
  954. * @memberOf _.support
  955. * @type boolean
  956. */
  957. support.nonEnumShadows = !/valueOf/.test(props);
  958. /**
  959. * Detect if own properties are iterated after inherited properties (IE < 9).
  960. *
  961. * @memberOf _.support
  962. * @type boolean
  963. */
  964. support.ownLast = props[0] != 'x';
  965. /**
  966. * Detect if `Array#shift` and `Array#splice` augment array-like objects
  967. * correctly.
  968. *
  969. * Firefox < 10, compatibility modes of IE 8, and IE < 9 have buggy Array
  970. * `shift()` and `splice()` functions that fail to remove the last element,
  971. * `value[0]`, of array-like objects even though the "length" property is
  972. * set to `0`. The `shift()` method is buggy in compatibility modes of IE 8,
  973. * while `splice()` is buggy regardless of mode in IE < 9.
  974. *
  975. * @memberOf _.support
  976. * @type boolean
  977. */
  978. support.spliceObjects = (splice.call(object, 0, 1), !object[0]);
  979. /**
  980. * Detect lack of support for accessing string characters by index.
  981. *
  982. * IE < 8 can't access characters by index. IE 8 can only access characters
  983. * by index on string literals, not string objects.
  984. *
  985. * @memberOf _.support
  986. * @type boolean
  987. */
  988. support.unindexedChars = ('x'[0] + Object('x')[0]) != 'xx';
  989. }(1, 0));
  990. /**
  991. * By default, the template delimiters used by lodash are like those in
  992. * embedded Ruby (ERB). Change the following template settings to use
  993. * alternative delimiters.
  994. *
  995. * @static
  996. * @memberOf _
  997. * @type Object
  998. */
  999. lodash.templateSettings = {
  1000. /**
  1001. * Used to detect `data` property values to be HTML-escaped.
  1002. *
  1003. * @memberOf _.templateSettings
  1004. * @type RegExp
  1005. */
  1006. 'escape': reEscape,
  1007. /**
  1008. * Used to detect code to be evaluated.
  1009. *
  1010. * @memberOf _.templateSettings
  1011. * @type RegExp
  1012. */
  1013. 'evaluate': reEvaluate,
  1014. /**
  1015. * Used to detect `data` property values to inject.
  1016. *
  1017. * @memberOf _.templateSettings
  1018. * @type RegExp
  1019. */
  1020. 'interpolate': reInterpolate,
  1021. /**
  1022. * Used to reference the data object in the template text.
  1023. *
  1024. * @memberOf _.templateSettings
  1025. * @type string
  1026. */
  1027. 'variable': '',
  1028. /**
  1029. * Used to import variables into the compiled template.
  1030. *
  1031. * @memberOf _.templateSettings
  1032. * @type Object
  1033. */
  1034. 'imports': {
  1035. /**
  1036. * A reference to the `lodash` function.
  1037. *
  1038. * @memberOf _.templateSettings.imports
  1039. * @type Function
  1040. */
  1041. '_': lodash
  1042. }
  1043. };
  1044. /*------------------------------------------------------------------------*/
  1045. /**
  1046. * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation.
  1047. *
  1048. * @private
  1049. * @param {*} value The value to wrap.
  1050. */
  1051. function LazyWrapper(value) {
  1052. this.__wrapped__ = value;
  1053. this.__actions__ = [];
  1054. this.__dir__ = 1;
  1055. this.__filtered__ = false;
  1056. this.__iteratees__ = [];
  1057. this.__takeCount__ = POSITIVE_INFINITY;
  1058. this.__views__ = [];
  1059. }
  1060. /**
  1061. * Creates a clone of the lazy wrapper object.
  1062. *
  1063. * @private
  1064. * @name clone
  1065. * @memberOf LazyWrapper
  1066. * @returns {Object} Returns the cloned `LazyWrapper` object.
  1067. */
  1068. function lazyClone() {
  1069. var result = new LazyWrapper(this.__wrapped__);
  1070. result.__actions__ = arrayCopy(this.__actions__);
  1071. result.__dir__ = this.__dir__;
  1072. result.__filtered__ = this.__filtered__;
  1073. result.__iteratees__ = arrayCopy(this.__iteratees__);
  1074. result.__takeCount__ = this.__takeCount__;
  1075. result.__views__ = arrayCopy(this.__views__);
  1076. return result;
  1077. }
  1078. /**
  1079. * Reverses the direction of lazy iteration.
  1080. *
  1081. * @private
  1082. * @name reverse
  1083. * @memberOf LazyWrapper
  1084. * @returns {Object} Returns the new reversed `LazyWrapper` object.
  1085. */
  1086. function lazyReverse() {
  1087. if (this.__filtered__) {
  1088. var result = new LazyWrapper(this);
  1089. result.__dir__ = -1;
  1090. result.__filtered__ = true;
  1091. } else {
  1092. result = this.clone();
  1093. result.__dir__ *= -1;
  1094. }
  1095. return result;
  1096. }
  1097. /**
  1098. * Extracts the unwrapped value from its lazy wrapper.
  1099. *
  1100. * @private
  1101. * @name value
  1102. * @memberOf LazyWrapper
  1103. * @returns {*} Returns the unwrapped value.
  1104. */
  1105. function lazyValue() {
  1106. var array = this.__wrapped__.value(),
  1107. dir = this.__dir__,
  1108. isArr = isArray(array),
  1109. isRight = dir < 0,
  1110. arrLength = isArr ? array.length : 0,
  1111. view = getView(0, arrLength, this.__views__),
  1112. start = view.start,
  1113. end = view.end,
  1114. length = end - start,
  1115. index = isRight ? end : (start - 1),
  1116. iteratees = this.__iteratees__,
  1117. iterLength = iteratees.length,
  1118. resIndex = 0,
  1119. takeCount = nativeMin(length, this.__takeCount__);
  1120. if (!isArr || arrLength < LARGE_ARRAY_SIZE || (arrLength == length && takeCount == length)) {
  1121. return baseWrapperValue(array, this.__actions__);
  1122. }
  1123. var result = [];
  1124. outer:
  1125. while (length-- && resIndex < takeCount) {
  1126. index += dir;
  1127. var iterIndex = -1,
  1128. value = array[index];
  1129. while (++iterIndex < iterLength) {
  1130. var data = iteratees[iterIndex],
  1131. iteratee = data.iteratee,
  1132. type = data.type,
  1133. computed = iteratee(value);
  1134. if (type == LAZY_MAP_FLAG) {
  1135. value = computed;
  1136. } else if (!computed) {
  1137. if (type == LAZY_FILTER_FLAG) {
  1138. continue outer;
  1139. } else {
  1140. break outer;
  1141. }
  1142. }
  1143. }
  1144. result[resIndex++] = value;
  1145. }
  1146. return result;
  1147. }
  1148. /*------------------------------------------------------------------------*/
  1149. /**
  1150. * Creates a cache object to store key/value pairs.
  1151. *
  1152. * @private
  1153. * @static
  1154. * @name Cache
  1155. * @memberOf _.memoize
  1156. */
  1157. function MapCache() {
  1158. this.__data__ = {};
  1159. }
  1160. /**
  1161. * Removes `key` and its value from the cache.
  1162. *
  1163. * @private
  1164. * @name delete
  1165. * @memberOf _.memoize.Cache
  1166. * @param {string} key The key of the value to remove.
  1167. * @returns {boolean} Returns `true` if the entry was removed successfully, else `false`.
  1168. */
  1169. function mapDelete(key) {
  1170. return this.has(key) && delete this.__data__[key];
  1171. }
  1172. /**
  1173. * Gets the cached value for `key`.
  1174. *
  1175. * @private
  1176. * @name get
  1177. * @memberOf _.memoize.Cache
  1178. * @param {string} key The key of the value to get.
  1179. * @returns {*} Returns the cached value.
  1180. */
  1181. function mapGet(key) {
  1182. return key == '__proto__' ? undefined : this.__data__[key];
  1183. }
  1184. /**
  1185. * Checks if a cached value for `key` exists.
  1186. *
  1187. * @private
  1188. * @name has
  1189. * @memberOf _.memoize.Cache
  1190. * @param {string} key The key of the entry to check.
  1191. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  1192. */
  1193. function mapHas(key) {
  1194. return key != '__proto__' && hasOwnProperty.call(this.__data__, key);
  1195. }
  1196. /**
  1197. * Sets `value` to `key` of the cache.
  1198. *
  1199. * @private
  1200. * @name set
  1201. * @memberOf _.memoize.Cache
  1202. * @param {string} key The key of the value to cache.
  1203. * @param {*} value The value to cache.
  1204. * @returns {Object} Returns the cache object.
  1205. */
  1206. function mapSet(key, value) {
  1207. if (key != '__proto__') {
  1208. this.__data__[key] = value;
  1209. }
  1210. return this;
  1211. }
  1212. /*------------------------------------------------------------------------*/
  1213. /**
  1214. *
  1215. * Creates a cache object to store unique values.
  1216. *
  1217. * @private
  1218. * @param {Array} [values] The values to cache.
  1219. */
  1220. function SetCache(values) {
  1221. var length = values ? values.length : 0;
  1222. this.data = { 'hash': nativeCreate(null), 'set': new Set };
  1223. while (length--) {
  1224. this.push(values[length]);
  1225. }
  1226. }
  1227. /**
  1228. * Checks if `value` is in `cache` mimicking the return signature of
  1229. * `_.indexOf` by returning `0` if the value is found, else `-1`.
  1230. *
  1231. * @private
  1232. * @param {Object} cache The cache to search.
  1233. * @param {*} value The value to search for.
  1234. * @returns {number} Returns `0` if `value` is found, else `-1`.
  1235. */
  1236. function cacheIndexOf(cache, value) {
  1237. var data = cache.data,
  1238. result = (typeof value == 'string' || isObject(value)) ? data.set.has(value) : data.hash[value];
  1239. return result ? 0 : -1;
  1240. }
  1241. /**
  1242. * Adds `value` to the cache.
  1243. *
  1244. * @private
  1245. * @name push
  1246. * @memberOf SetCache
  1247. * @param {*} value The value to cache.
  1248. */
  1249. function cachePush(value) {
  1250. var data = this.data;
  1251. if (typeof value == 'string' || isObject(value)) {
  1252. data.set.add(value);
  1253. } else {
  1254. data.hash[value] = true;
  1255. }
  1256. }
  1257. /*------------------------------------------------------------------------*/
  1258. /**
  1259. * Creates a new array joining `array` with `other`.
  1260. *
  1261. * @private
  1262. * @param {Array} array The array to join.
  1263. * @param {Array} other The other array to join.
  1264. * @returns {Array} Returns the new concatenated array.
  1265. */
  1266. function arrayConcat(array, other) {
  1267. var index = -1,
  1268. length = array.length,
  1269. othIndex = -1,
  1270. othLength = other.length,
  1271. result = Array(length + othLength);
  1272. while (++index < length) {
  1273. result[index] = array[index];
  1274. }
  1275. while (++othIndex < othLength) {
  1276. result[index++] = other[othIndex];
  1277. }
  1278. return result;
  1279. }
  1280. /**
  1281. * Copies the values of `source` to `array`.
  1282. *
  1283. * @private
  1284. * @param {Array} source The array to copy values from.
  1285. * @param {Array} [array=[]] The array to copy values to.
  1286. * @returns {Array} Returns `array`.
  1287. */
  1288. function arrayCopy(source, array) {
  1289. var index = -1,
  1290. length = source.length;
  1291. array || (array = Array(length));
  1292. while (++index < length) {
  1293. array[index] = source[index];
  1294. }
  1295. return array;
  1296. }
  1297. /**
  1298. * A specialized version of `_.forEach` for arrays without support for callback
  1299. * shorthands and `this` binding.
  1300. *
  1301. * @private
  1302. * @param {Array} array The array to iterate over.
  1303. * @param {Function} iteratee The function invoked per iteration.
  1304. * @returns {Array} Returns `array`.
  1305. */
  1306. function arrayEach(array, iteratee) {
  1307. var index = -1,
  1308. length = array.length;
  1309. while (++index < length) {
  1310. if (iteratee(array[index], index, array) === false) {
  1311. break;
  1312. }
  1313. }
  1314. return array;
  1315. }
  1316. /**
  1317. * A specialized version of `_.forEachRight` for arrays without support for
  1318. * callback shorthands and `this` binding.
  1319. *
  1320. * @private
  1321. * @param {Array} array The array to iterate over.
  1322. * @param {Function} iteratee The function invoked per iteration.
  1323. * @returns {Array} Returns `array`.
  1324. */
  1325. function arrayEachRight(array, iteratee) {
  1326. var length = array.length;
  1327. while (length--) {
  1328. if (iteratee(array[length], length, array) === false) {
  1329. break;
  1330. }
  1331. }
  1332. return array;
  1333. }
  1334. /**
  1335. * A specialized version of `_.every` for arrays without support for callback
  1336. * shorthands and `this` binding.
  1337. *
  1338. * @private
  1339. * @param {Array} array The array to iterate over.
  1340. * @param {Function} predicate The function invoked per iteration.
  1341. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1342. * else `false`.
  1343. */
  1344. function arrayEvery(array, predicate) {
  1345. var index = -1,
  1346. length = array.length;
  1347. while (++index < length) {
  1348. if (!predicate(array[index], index, array)) {
  1349. return false;
  1350. }
  1351. }
  1352. return true;
  1353. }
  1354. /**
  1355. * A specialized version of `baseExtremum` for arrays which invokes `iteratee`
  1356. * with one argument: (value).
  1357. *
  1358. * @private
  1359. * @param {Array} array The array to iterate over.
  1360. * @param {Function} iteratee The function invoked per iteration.
  1361. * @param {Function} comparator The function used to compare values.
  1362. * @param {*} exValue The initial extremum value.
  1363. * @returns {*} Returns the extremum value.
  1364. */
  1365. function arrayExtremum(array, iteratee, comparator, exValue) {
  1366. var index = -1,
  1367. length = array.length,
  1368. computed = exValue,
  1369. result = computed;
  1370. while (++index < length) {
  1371. var value = array[index],
  1372. current = +iteratee(value);
  1373. if (comparator(current, computed)) {
  1374. computed = current;
  1375. result = value;
  1376. }
  1377. }
  1378. return result;
  1379. }
  1380. /**
  1381. * A specialized version of `_.filter` for arrays without support for callback
  1382. * shorthands and `this` binding.
  1383. *
  1384. * @private
  1385. * @param {Array} array The array to iterate over.
  1386. * @param {Function} predicate The function invoked per iteration.
  1387. * @returns {Array} Returns the new filtered array.
  1388. */
  1389. function arrayFilter(array, predicate) {
  1390. var index = -1,
  1391. length = array.length,
  1392. resIndex = -1,
  1393. result = [];
  1394. while (++index < length) {
  1395. var value = array[index];
  1396. if (predicate(value, index, array)) {
  1397. result[++resIndex] = value;
  1398. }
  1399. }
  1400. return result;
  1401. }
  1402. /**
  1403. * A specialized version of `_.map` for arrays without support for callback
  1404. * shorthands and `this` binding.
  1405. *
  1406. * @private
  1407. * @param {Array} array The array to iterate over.
  1408. * @param {Function} iteratee The function invoked per iteration.
  1409. * @returns {Array} Returns the new mapped array.
  1410. */
  1411. function arrayMap(array, iteratee) {
  1412. var index = -1,
  1413. length = array.length,
  1414. result = Array(length);
  1415. while (++index < length) {
  1416. result[index] = iteratee(array[index], index, array);
  1417. }
  1418. return result;
  1419. }
  1420. /**
  1421. * Appends the elements of `values` to `array`.
  1422. *
  1423. * @private
  1424. * @param {Array} array The array to modify.
  1425. * @param {Array} values The values to append.
  1426. * @returns {Array} Returns `array`.
  1427. */
  1428. function arrayPush(array, values) {
  1429. var index = -1,
  1430. length = values.length,
  1431. offset = array.length;
  1432. while (++index < length) {
  1433. array[offset + index] = values[index];
  1434. }
  1435. return array;
  1436. }
  1437. /**
  1438. * A specialized version of `_.reduce` for arrays without support for callback
  1439. * shorthands and `this` binding.
  1440. *
  1441. * @private
  1442. * @param {Array} array The array to iterate over.
  1443. * @param {Function} iteratee The function invoked per iteration.
  1444. * @param {*} [accumulator] The initial value.
  1445. * @param {boolean} [initFromArray] Specify using the first element of `array`
  1446. * as the initial value.
  1447. * @returns {*} Returns the accumulated value.
  1448. */
  1449. function arrayReduce(array, iteratee, accumulator, initFromArray) {
  1450. var index = -1,
  1451. length = array.length;
  1452. if (initFromArray && length) {
  1453. accumulator = array[++index];
  1454. }
  1455. while (++index < length) {
  1456. accumulator = iteratee(accumulator, array[index], index, array);
  1457. }
  1458. return accumulator;
  1459. }
  1460. /**
  1461. * A specialized version of `_.reduceRight` for arrays without support for
  1462. * callback shorthands and `this` binding.
  1463. *
  1464. * @private
  1465. * @param {Array} array The array to iterate over.
  1466. * @param {Function} iteratee The function invoked per iteration.
  1467. * @param {*} [accumulator] The initial value.
  1468. * @param {boolean} [initFromArray] Specify using the last element of `array`
  1469. * as the initial value.
  1470. * @returns {*} Returns the accumulated value.
  1471. */
  1472. function arrayReduceRight(array, iteratee, accumulator, initFromArray) {
  1473. var length = array.length;
  1474. if (initFromArray && length) {
  1475. accumulator = array[--length];
  1476. }
  1477. while (length--) {
  1478. accumulator = iteratee(accumulator, array[length], length, array);
  1479. }
  1480. return accumulator;
  1481. }
  1482. /**
  1483. * A specialized version of `_.some` for arrays without support for callback
  1484. * shorthands and `this` binding.
  1485. *
  1486. * @private
  1487. * @param {Array} array The array to iterate over.
  1488. * @param {Function} predicate The function invoked per iteration.
  1489. * @returns {boolean} Returns `true` if any element passes the predicate check,
  1490. * else `false`.
  1491. */
  1492. function arraySome(array, predicate) {
  1493. var index = -1,
  1494. length = array.length;
  1495. while (++index < length) {
  1496. if (predicate(array[index], index, array)) {
  1497. return true;
  1498. }
  1499. }
  1500. return false;
  1501. }
  1502. /**
  1503. * A specialized version of `_.sum` for arrays without support for callback
  1504. * shorthands and `this` binding..
  1505. *
  1506. * @private
  1507. * @param {Array} array The array to iterate over.
  1508. * @param {Function} iteratee The function invoked per iteration.
  1509. * @returns {number} Returns the sum.
  1510. */
  1511. function arraySum(array, iteratee) {
  1512. var length = array.length,
  1513. result = 0;
  1514. while (length--) {
  1515. result += +iteratee(array[length]) || 0;
  1516. }
  1517. return result;
  1518. }
  1519. /**
  1520. * Used by `_.defaults` to customize its `_.assign` use.
  1521. *
  1522. * @private
  1523. * @param {*} objectValue The destination object property value.
  1524. * @param {*} sourceValue The source object property value.
  1525. * @returns {*} Returns the value to assign to the destination object.
  1526. */
  1527. function assignDefaults(objectValue, sourceValue) {
  1528. return objectValue === undefined ? sourceValue : objectValue;
  1529. }
  1530. /**
  1531. * Used by `_.template` to customize its `_.assign` use.
  1532. *
  1533. * **Note:** This function is like `assignDefaults` except that it ignores
  1534. * inherited property values when checking if a property is `undefined`.
  1535. *
  1536. * @private
  1537. * @param {*} objectValue The destination object property value.
  1538. * @param {*} sourceValue The source object property value.
  1539. * @param {string} key The key associated with the object and source values.
  1540. * @param {Object} object The destination object.
  1541. * @returns {*} Returns the value to assign to the destination object.
  1542. */
  1543. function assignOwnDefaults(objectValue, sourceValue, key, object) {
  1544. return (objectValue === undefined || !hasOwnProperty.call(object, key))
  1545. ? sourceValue
  1546. : objectValue;
  1547. }
  1548. /**
  1549. * A specialized version of `_.assign` for customizing assigned values without
  1550. * support for argument juggling, multiple sources, and `this` binding `customizer`
  1551. * functions.
  1552. *
  1553. * @private
  1554. * @param {Object} object The destination object.
  1555. * @param {Object} source The source object.
  1556. * @param {Function} customizer The function to customize assigned values.
  1557. * @returns {Object} Returns `object`.
  1558. */
  1559. function assignWith(object, source, customizer) {
  1560. var index = -1,
  1561. props = keys(source),
  1562. length = props.length;
  1563. while (++index < length) {
  1564. var key = props[index],
  1565. value = object[key],
  1566. result = customizer(value, source[key], key, object, source);
  1567. if ((result === result ? (result !== value) : (value === value)) ||
  1568. (value === undefined && !(key in object))) {
  1569. object[key] = result;
  1570. }
  1571. }
  1572. return object;
  1573. }
  1574. /**
  1575. * The base implementation of `_.assign` without support for argument juggling,
  1576. * multiple sources, and `customizer` functions.
  1577. *
  1578. * @private
  1579. * @param {Object} object The destination object.
  1580. * @param {Object} source The source object.
  1581. * @returns {Object} Returns `object`.
  1582. */
  1583. function baseAssign(object, source) {
  1584. return source == null
  1585. ? object
  1586. : baseCopy(source, keys(source), object);
  1587. }
  1588. /**
  1589. * The base implementation of `_.at` without support for string collections
  1590. * and individual key arguments.
  1591. *
  1592. * @private
  1593. * @param {Array|Object} collection The collection to iterate over.
  1594. * @param {number[]|string[]} props The property names or indexes of elements to pick.
  1595. * @returns {Array} Returns the new array of picked elements.
  1596. */
  1597. function baseAt(collection, props) {
  1598. var index = -1,
  1599. isNil = collection == null,
  1600. isArr = !isNil && isArrayLike(collection),
  1601. length = isArr ? collection.length : 0,
  1602. propsLength = props.length,
  1603. result = Array(propsLength);
  1604. while(++index < propsLength) {
  1605. var key = props[index];
  1606. if (isArr) {
  1607. result[index] = isIndex(key, length) ? collection[key] : undefined;
  1608. } else {
  1609. result[index] = isNil ? undefined : collection[key];
  1610. }
  1611. }
  1612. return result;
  1613. }
  1614. /**
  1615. * Copies properties of `source` to `object`.
  1616. *
  1617. * @private
  1618. * @param {Object} source The object to copy properties from.
  1619. * @param {Array} props The property names to copy.
  1620. * @param {Object} [object={}] The object to copy properties to.
  1621. * @returns {Object} Returns `object`.
  1622. */
  1623. function baseCopy(source, props, object) {
  1624. object || (object = {});
  1625. var index = -1,
  1626. length = props.length;
  1627. while (++index < length) {
  1628. var key = props[index];
  1629. object[key] = source[key];
  1630. }
  1631. return object;
  1632. }
  1633. /**
  1634. * The base implementation of `_.callback` which supports specifying the
  1635. * number of arguments to provide to `func`.
  1636. *
  1637. * @private
  1638. * @param {*} [func=_.identity] The value to convert to a callback.
  1639. * @param {*} [thisArg] The `this` binding of `func`.
  1640. * @param {number} [argCount] The number of arguments to provide to `func`.
  1641. * @returns {Function} Returns the callback.
  1642. */
  1643. function baseCallback(func, thisArg, argCount) {
  1644. var type = typeof func;
  1645. if (type == 'function') {
  1646. return thisArg === undefined
  1647. ? func
  1648. : bindCallback(func, thisArg, argCount);
  1649. }
  1650. if (func == null) {
  1651. return identity;
  1652. }
  1653. if (type == 'object') {
  1654. return baseMatches(func);
  1655. }
  1656. return thisArg === undefined
  1657. ? property(func)
  1658. : baseMatchesProperty(func, thisArg);
  1659. }
  1660. /**
  1661. * The base implementation of `_.clone` without support for argument juggling
  1662. * and `this` binding `customizer` functions.
  1663. *
  1664. * @private
  1665. * @param {*} value The value to clone.
  1666. * @param {boolean} [isDeep] Specify a deep clone.
  1667. * @param {Function} [customizer] The function to customize cloning values.
  1668. * @param {string} [key] The key of `value`.
  1669. * @param {Object} [object] The object `value` belongs to.
  1670. * @param {Array} [stackA=[]] Tracks traversed source objects.
  1671. * @param {Array} [stackB=[]] Associates clones with source counterparts.
  1672. * @returns {*} Returns the cloned value.
  1673. */
  1674. function baseClone(value, isDeep, customizer, key, object, stackA, stackB) {
  1675. var result;
  1676. if (customizer) {
  1677. result = object ? customizer(value, key, object) : customizer(value);
  1678. }
  1679. if (result !== undefined) {
  1680. return result;
  1681. }
  1682. if (!isObject(value)) {
  1683. return value;
  1684. }
  1685. var isArr = isArray(value);
  1686. if (isArr) {
  1687. result = initCloneArray(value);
  1688. if (!isDeep) {
  1689. return arrayCopy(value, result);
  1690. }
  1691. } else {
  1692. var tag = objToString.call(value),
  1693. isFunc = tag == funcTag;
  1694. if (tag == objectTag || tag == argsTag || (isFunc && !object)) {
  1695. if (isHostObject(value)) {
  1696. return object ? value : {};
  1697. }
  1698. result = initCloneObject(isFunc ? {} : value);
  1699. if (!isDeep) {
  1700. return baseAssign(result, value);
  1701. }
  1702. } else {
  1703. return cloneableTags[tag]
  1704. ? initCloneByTag(value, tag, isDeep)
  1705. : (object ? value : {});
  1706. }
  1707. }
  1708. // Check for circular references and return its corresponding clone.
  1709. stackA || (stackA = []);
  1710. stackB || (stackB = []);
  1711. var length = stackA.length;
  1712. while (length--) {
  1713. if (stackA[length] == value) {
  1714. return stackB[length];
  1715. }
  1716. }
  1717. // Add the source value to the stack of traversed objects and associate it with its clone.
  1718. stackA.push(value);
  1719. stackB.push(result);
  1720. // Recursively populate clone (susceptible to call stack limits).
  1721. (isArr ? arrayEach : baseForOwn)(value, function(subValue, key) {
  1722. result[key] = baseClone(subValue, isDeep, customizer, key, value, stackA, stackB);
  1723. });
  1724. return result;
  1725. }
  1726. /**
  1727. * The base implementation of `_.create` without support for assigning
  1728. * properties to the created object.
  1729. *
  1730. * @private
  1731. * @param {Object} prototype The object to inherit from.
  1732. * @returns {Object} Returns the new object.
  1733. */
  1734. var baseCreate = (function() {
  1735. function object() {}
  1736. return function(prototype) {
  1737. if (isObject(prototype)) {
  1738. object.prototype = prototype;
  1739. var result = new object;
  1740. object.prototype = undefined;
  1741. }
  1742. return result || {};
  1743. };
  1744. }());
  1745. /**
  1746. * The base implementation of `_.delay` and `_.defer` which accepts an index
  1747. * of where to slice the arguments to provide to `func`.
  1748. *
  1749. * @private
  1750. * @param {Function} func The function to delay.
  1751. * @param {number} wait The number of milliseconds to delay invocation.
  1752. * @param {Object} args The arguments provide to `func`.
  1753. * @returns {number} Returns the timer id.
  1754. */
  1755. function baseDelay(func, wait, args) {
  1756. if (typeof func != 'function') {
  1757. throw new TypeError(FUNC_ERROR_TEXT);
  1758. }
  1759. return setTimeout(function() { func.apply(undefined, args); }, wait);
  1760. }
  1761. /**
  1762. * The base implementation of `_.difference` which accepts a single array
  1763. * of values to exclude.
  1764. *
  1765. * @private
  1766. * @param {Array} array The array to inspect.
  1767. * @param {Array} values The values to exclude.
  1768. * @returns {Array} Returns the new array of filtered values.
  1769. */
  1770. function baseDifference(array, values) {
  1771. var length = array ? array.length : 0,
  1772. result = [];
  1773. if (!length) {
  1774. return result;
  1775. }
  1776. var index = -1,
  1777. indexOf = getIndexOf(),
  1778. isCommon = indexOf === baseIndexOf,
  1779. cache = (isCommon && values.length >= LARGE_ARRAY_SIZE) ? createCache(values) : null,
  1780. valuesLength = values.length;
  1781. if (cache) {
  1782. indexOf = cacheIndexOf;
  1783. isCommon = false;
  1784. values = cache;
  1785. }
  1786. outer:
  1787. while (++index < length) {
  1788. var value = array[index];
  1789. if (isCommon && value === value) {
  1790. var valuesIndex = valuesLength;
  1791. while (valuesIndex--) {
  1792. if (values[valuesIndex] === value) {
  1793. continue outer;
  1794. }
  1795. }
  1796. result.push(value);
  1797. }
  1798. else if (indexOf(values, value, 0) < 0) {
  1799. result.push(value);
  1800. }
  1801. }
  1802. return result;
  1803. }
  1804. /**
  1805. * The base implementation of `_.forEach` without support for callback
  1806. * shorthands and `this` binding.
  1807. *
  1808. * @private
  1809. * @param {Array|Object|string} collection The collection to iterate over.
  1810. * @param {Function} iteratee The function invoked per iteration.
  1811. * @returns {Array|Object|string} Returns `collection`.
  1812. */
  1813. var baseEach = createBaseEach(baseForOwn);
  1814. /**
  1815. * The base implementation of `_.forEachRight` without support for callback
  1816. * shorthands and `this` binding.
  1817. *
  1818. * @private
  1819. * @param {Array|Object|string} collection The collection to iterate over.
  1820. * @param {Function} iteratee The function invoked per iteration.
  1821. * @returns {Array|Object|string} Returns `collection`.
  1822. */
  1823. var baseEachRight = createBaseEach(baseForOwnRight, true);
  1824. /**
  1825. * The base implementation of `_.every` without support for callback
  1826. * shorthands and `this` binding.
  1827. *
  1828. * @private
  1829. * @param {Array|Object|string} collection The collection to iterate over.
  1830. * @param {Function} predicate The function invoked per iteration.
  1831. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  1832. * else `false`
  1833. */
  1834. function baseEvery(collection, predicate) {
  1835. var result = true;
  1836. baseEach(collection, function(value, index, collection) {
  1837. result = !!predicate(value, index, collection);
  1838. return result;
  1839. });
  1840. return result;
  1841. }
  1842. /**
  1843. * Gets the extremum value of `collection` invoking `iteratee` for each value
  1844. * in `collection` to generate the criterion by which the value is ranked.
  1845. * The `iteratee` is invoked with three arguments: (value, index|key, collection).
  1846. *
  1847. * @private
  1848. * @param {Array|Object|string} collection The collection to iterate over.
  1849. * @param {Function} iteratee The function invoked per iteration.
  1850. * @param {Function} comparator The function used to compare values.
  1851. * @param {*} exValue The initial extremum value.
  1852. * @returns {*} Returns the extremum value.
  1853. */
  1854. function baseExtremum(collection, iteratee, comparator, exValue) {
  1855. var computed = exValue,
  1856. result = computed;
  1857. baseEach(collection, function(value, index, collection) {
  1858. var current = +iteratee(value, index, collection);
  1859. if (comparator(current, computed) || (current === exValue && current === result)) {
  1860. computed = current;
  1861. result = value;
  1862. }
  1863. });
  1864. return result;
  1865. }
  1866. /**
  1867. * The base implementation of `_.fill` without an iteratee call guard.
  1868. *
  1869. * @private
  1870. * @param {Array} array The array to fill.
  1871. * @param {*} value The value to fill `array` with.
  1872. * @param {number} [start=0] The start position.
  1873. * @param {number} [end=array.length] The end position.
  1874. * @returns {Array} Returns `array`.
  1875. */
  1876. function baseFill(array, value, start, end) {
  1877. var length = array.length;
  1878. start = start == null ? 0 : (+start || 0);
  1879. if (start < 0) {
  1880. start = -start > length ? 0 : (length + start);
  1881. }
  1882. end = (end === undefined || end > length) ? length : (+end || 0);
  1883. if (end < 0) {
  1884. end += length;
  1885. }
  1886. length = start > end ? 0 : (end >>> 0);
  1887. start >>>= 0;
  1888. while (start < length) {
  1889. array[start++] = value;
  1890. }
  1891. return array;
  1892. }
  1893. /**
  1894. * The base implementation of `_.filter` without support for callback
  1895. * shorthands and `this` binding.
  1896. *
  1897. * @private
  1898. * @param {Array|Object|string} collection The collection to iterate over.
  1899. * @param {Function} predicate The function invoked per iteration.
  1900. * @returns {Array} Returns the new filtered array.
  1901. */
  1902. function baseFilter(collection, predicate) {
  1903. var result = [];
  1904. baseEach(collection, function(value, index, collection) {
  1905. if (predicate(value, index, collection)) {
  1906. result.push(value);
  1907. }
  1908. });
  1909. return result;
  1910. }
  1911. /**
  1912. * The base implementation of `_.find`, `_.findLast`, `_.findKey`, and `_.findLastKey`,
  1913. * without support for callback shorthands and `this` binding, which iterates
  1914. * over `collection` using the provided `eachFunc`.
  1915. *
  1916. * @private
  1917. * @param {Array|Object|string} collection The collection to search.
  1918. * @param {Function} predicate The function invoked per iteration.
  1919. * @param {Function} eachFunc The function to iterate over `collection`.
  1920. * @param {boolean} [retKey] Specify returning the key of the found element
  1921. * instead of the element itself.
  1922. * @returns {*} Returns the found element or its key, else `undefined`.
  1923. */
  1924. function baseFind(collection, predicate, eachFunc, retKey) {
  1925. var result;
  1926. eachFunc(collection, function(value, key, collection) {
  1927. if (predicate(value, key, collection)) {
  1928. result = retKey ? key : value;
  1929. return false;
  1930. }
  1931. });
  1932. return result;
  1933. }
  1934. /**
  1935. * The base implementation of `_.flatten` with added support for restricting
  1936. * flattening and specifying the start index.
  1937. *
  1938. * @private
  1939. * @param {Array} array The array to flatten.
  1940. * @param {boolean} [isDeep] Specify a deep flatten.
  1941. * @param {boolean} [isStrict] Restrict flattening to arrays-like objects.
  1942. * @param {Array} [result=[]] The initial result value.
  1943. * @returns {Array} Returns the new flattened array.
  1944. */
  1945. function baseFlatten(array, isDeep, isStrict, result) {
  1946. result || (result = []);
  1947. var index = -1,
  1948. length = array.length;
  1949. while (++index < length) {
  1950. var value = array[index];
  1951. if (isObjectLike(value) && isArrayLike(value) &&
  1952. (isStrict || isArray(value) || isArguments(value))) {
  1953. if (isDeep) {
  1954. // Recursively flatten arrays (susceptible to call stack limits).
  1955. baseFlatten(value, isDeep, isStrict, result);
  1956. } else {
  1957. arrayPush(result, value);
  1958. }
  1959. } else if (!isStrict) {
  1960. result[result.length] = value;
  1961. }
  1962. }
  1963. return result;
  1964. }
  1965. /**
  1966. * The base implementation of `baseForIn` and `baseForOwn` which iterates
  1967. * over `object` properties returned by `keysFunc` invoking `iteratee` for
  1968. * each property. Iteratee functions may exit iteration early by explicitly
  1969. * returning `false`.
  1970. *
  1971. * @private
  1972. * @param {Object} object The object to iterate over.
  1973. * @param {Function} iteratee The function invoked per iteration.
  1974. * @param {Function} keysFunc The function to get the keys of `object`.
  1975. * @returns {Object} Returns `object`.
  1976. */
  1977. var baseFor = createBaseFor();
  1978. /**
  1979. * This function is like `baseFor` except that it iterates over properties
  1980. * in the opposite order.
  1981. *
  1982. * @private
  1983. * @param {Object} object The object to iterate over.
  1984. * @param {Function} iteratee The function invoked per iteration.
  1985. * @param {Function} keysFunc The function to get the keys of `object`.
  1986. * @returns {Object} Returns `object`.
  1987. */
  1988. var baseForRight = createBaseFor(true);
  1989. /**
  1990. * The base implementation of `_.forIn` without support for callback
  1991. * shorthands and `this` binding.
  1992. *
  1993. * @private
  1994. * @param {Object} object The object to iterate over.
  1995. * @param {Function} iteratee The function invoked per iteration.
  1996. * @returns {Object} Returns `object`.
  1997. */
  1998. function baseForIn(object, iteratee) {
  1999. return baseFor(object, iteratee, keysIn);
  2000. }
  2001. /**
  2002. * The base implementation of `_.forOwn` without support for callback
  2003. * shorthands and `this` binding.
  2004. *
  2005. * @private
  2006. * @param {Object} object The object to iterate over.
  2007. * @param {Function} iteratee The function invoked per iteration.
  2008. * @returns {Object} Returns `object`.
  2009. */
  2010. function baseForOwn(object, iteratee) {
  2011. return baseFor(object, iteratee, keys);
  2012. }
  2013. /**
  2014. * The base implementation of `_.forOwnRight` without support for callback
  2015. * shorthands and `this` binding.
  2016. *
  2017. * @private
  2018. * @param {Object} object The object to iterate over.
  2019. * @param {Function} iteratee The function invoked per iteration.
  2020. * @returns {Object} Returns `object`.
  2021. */
  2022. function baseForOwnRight(object, iteratee) {
  2023. return baseForRight(object, iteratee, keys);
  2024. }
  2025. /**
  2026. * The base implementation of `_.functions` which creates an array of
  2027. * `object` function property names filtered from those provided.
  2028. *
  2029. * @private
  2030. * @param {Object} object The object to inspect.
  2031. * @param {Array} props The property names to filter.
  2032. * @returns {Array} Returns the new array of filtered property names.
  2033. */
  2034. function baseFunctions(object, props) {
  2035. var index = -1,
  2036. length = props.length,
  2037. resIndex = -1,
  2038. result = [];
  2039. while (++index < length) {
  2040. var key = props[index];
  2041. if (isFunction(object[key])) {
  2042. result[++resIndex] = key;
  2043. }
  2044. }
  2045. return result;
  2046. }
  2047. /**
  2048. * The base implementation of `get` without support for string paths
  2049. * and default values.
  2050. *
  2051. * @private
  2052. * @param {Object} object The object to query.
  2053. * @param {Array} path The path of the property to get.
  2054. * @param {string} [pathKey] The key representation of path.
  2055. * @returns {*} Returns the resolved value.
  2056. */
  2057. function baseGet(object, path, pathKey) {
  2058. if (object == null) {
  2059. return;
  2060. }
  2061. object = toObject(object);
  2062. if (pathKey !== undefined && pathKey in object) {
  2063. path = [pathKey];
  2064. }
  2065. var index = 0,
  2066. length = path.length;
  2067. while (object != null && index < length) {
  2068. object = toObject(object)[path[index++]];
  2069. }
  2070. return (index && index == length) ? object : undefined;
  2071. }
  2072. /**
  2073. * The base implementation of `_.isEqual` without support for `this` binding
  2074. * `customizer` functions.
  2075. *
  2076. * @private
  2077. * @param {*} value The value to compare.
  2078. * @param {*} other The other value to compare.
  2079. * @param {Function} [customizer] The function to customize comparing values.
  2080. * @param {boolean} [isLoose] Specify performing partial comparisons.
  2081. * @param {Array} [stackA] Tracks traversed `value` objects.
  2082. * @param {Array} [stackB] Tracks traversed `other` objects.
  2083. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  2084. */
  2085. function baseIsEqual(value, other, customizer, isLoose, stackA, stackB) {
  2086. if (value === other) {
  2087. return true;
  2088. }
  2089. if (value == null || other == null || (!isObject(value) && !isObjectLike(other))) {
  2090. return value !== value && other !== other;
  2091. }
  2092. return baseIsEqualDeep(value, other, baseIsEqual, customizer, isLoose, stackA, stackB);
  2093. }
  2094. /**
  2095. * A specialized version of `baseIsEqual` for arrays and objects which performs
  2096. * deep comparisons and tracks traversed objects enabling objects with circular
  2097. * references to be compared.
  2098. *
  2099. * @private
  2100. * @param {Object} object The object to compare.
  2101. * @param {Object} other The other object to compare.
  2102. * @param {Function} equalFunc The function to determine equivalents of values.
  2103. * @param {Function} [customizer] The function to customize comparing objects.
  2104. * @param {boolean} [isLoose] Specify performing partial comparisons.
  2105. * @param {Array} [stackA=[]] Tracks traversed `value` objects.
  2106. * @param {Array} [stackB=[]] Tracks traversed `other` objects.
  2107. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2108. */
  2109. function baseIsEqualDeep(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
  2110. var objIsArr = isArray(object),
  2111. othIsArr = isArray(other),
  2112. objTag = arrayTag,
  2113. othTag = arrayTag;
  2114. if (!objIsArr) {
  2115. objTag = objToString.call(object);
  2116. if (objTag == argsTag) {
  2117. objTag = objectTag;
  2118. } else if (objTag != objectTag) {
  2119. objIsArr = isTypedArray(object);
  2120. }
  2121. }
  2122. if (!othIsArr) {
  2123. othTag = objToString.call(other);
  2124. if (othTag == argsTag) {
  2125. othTag = objectTag;
  2126. } else if (othTag != objectTag) {
  2127. othIsArr = isTypedArray(other);
  2128. }
  2129. }
  2130. var objIsObj = objTag == objectTag && !isHostObject(object),
  2131. othIsObj = othTag == objectTag && !isHostObject(other),
  2132. isSameTag = objTag == othTag;
  2133. if (isSameTag && !(objIsArr || objIsObj)) {
  2134. return equalByTag(object, other, objTag);
  2135. }
  2136. if (!isLoose) {
  2137. var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'),
  2138. othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__');
  2139. if (objIsWrapped || othIsWrapped) {
  2140. return equalFunc(objIsWrapped ? object.value() : object, othIsWrapped ? other.value() : other, customizer, isLoose, stackA, stackB);
  2141. }
  2142. }
  2143. if (!isSameTag) {
  2144. return false;
  2145. }
  2146. // Assume cyclic values are equal.
  2147. // For more information on detecting circular references see https://es5.github.io/#JO.
  2148. stackA || (stackA = []);
  2149. stackB || (stackB = []);
  2150. var length = stackA.length;
  2151. while (length--) {
  2152. if (stackA[length] == object) {
  2153. return stackB[length] == other;
  2154. }
  2155. }
  2156. // Add `object` and `other` to the stack of traversed objects.
  2157. stackA.push(object);
  2158. stackB.push(other);
  2159. var result = (objIsArr ? equalArrays : equalObjects)(object, other, equalFunc, customizer, isLoose, stackA, stackB);
  2160. stackA.pop();
  2161. stackB.pop();
  2162. return result;
  2163. }
  2164. /**
  2165. * The base implementation of `_.isMatch` without support for callback
  2166. * shorthands and `this` binding.
  2167. *
  2168. * @private
  2169. * @param {Object} object The object to inspect.
  2170. * @param {Array} matchData The propery names, values, and compare flags to match.
  2171. * @param {Function} [customizer] The function to customize comparing objects.
  2172. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  2173. */
  2174. function baseIsMatch(object, matchData, customizer) {
  2175. var index = matchData.length,
  2176. length = index,
  2177. noCustomizer = !customizer;
  2178. if (object == null) {
  2179. return !length;
  2180. }
  2181. object = toObject(object);
  2182. while (index--) {
  2183. var data = matchData[index];
  2184. if ((noCustomizer && data[2])
  2185. ? data[1] !== object[data[0]]
  2186. : !(data[0] in object)
  2187. ) {
  2188. return false;
  2189. }
  2190. }
  2191. while (++index < length) {
  2192. data = matchData[index];
  2193. var key = data[0],
  2194. objValue = object[key],
  2195. srcValue = data[1];
  2196. if (noCustomizer && data[2]) {
  2197. if (objValue === undefined && !(key in object)) {
  2198. return false;
  2199. }
  2200. } else {
  2201. var result = customizer ? customizer(objValue, srcValue, key) : undefined;
  2202. if (!(result === undefined ? baseIsEqual(srcValue, objValue, customizer, true) : result)) {
  2203. return false;
  2204. }
  2205. }
  2206. }
  2207. return true;
  2208. }
  2209. /**
  2210. * The base implementation of `_.map` without support for callback shorthands
  2211. * and `this` binding.
  2212. *
  2213. * @private
  2214. * @param {Array|Object|string} collection The collection to iterate over.
  2215. * @param {Function} iteratee The function invoked per iteration.
  2216. * @returns {Array} Returns the new mapped array.
  2217. */
  2218. function baseMap(collection, iteratee) {
  2219. var index = -1,
  2220. result = isArrayLike(collection) ? Array(collection.length) : [];
  2221. baseEach(collection, function(value, key, collection) {
  2222. result[++index] = iteratee(value, key, collection);
  2223. });
  2224. return result;
  2225. }
  2226. /**
  2227. * The base implementation of `_.matches` which does not clone `source`.
  2228. *
  2229. * @private
  2230. * @param {Object} source The object of property values to match.
  2231. * @returns {Function} Returns the new function.
  2232. */
  2233. function baseMatches(source) {
  2234. var matchData = getMatchData(source);
  2235. if (matchData.length == 1 && matchData[0][2]) {
  2236. var key = matchData[0][0],
  2237. value = matchData[0][1];
  2238. return function(object) {
  2239. if (object == null) {
  2240. return false;
  2241. }
  2242. object = toObject(object);
  2243. return object[key] === value && (value !== undefined || (key in object));
  2244. };
  2245. }
  2246. return function(object) {
  2247. return baseIsMatch(object, matchData);
  2248. };
  2249. }
  2250. /**
  2251. * The base implementation of `_.matchesProperty` which does not clone `srcValue`.
  2252. *
  2253. * @private
  2254. * @param {string} path The path of the property to get.
  2255. * @param {*} srcValue The value to compare.
  2256. * @returns {Function} Returns the new function.
  2257. */
  2258. function baseMatchesProperty(path, srcValue) {
  2259. var isArr = isArray(path),
  2260. isCommon = isKey(path) && isStrictComparable(srcValue),
  2261. pathKey = (path + '');
  2262. path = toPath(path);
  2263. return function(object) {
  2264. if (object == null) {
  2265. return false;
  2266. }
  2267. var key = pathKey;
  2268. object = toObject(object);
  2269. if ((isArr || !isCommon) && !(key in object)) {
  2270. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  2271. if (object == null) {
  2272. return false;
  2273. }
  2274. key = last(path);
  2275. object = toObject(object);
  2276. }
  2277. return object[key] === srcValue
  2278. ? (srcValue !== undefined || (key in object))
  2279. : baseIsEqual(srcValue, object[key], undefined, true);
  2280. };
  2281. }
  2282. /**
  2283. * The base implementation of `_.merge` without support for argument juggling,
  2284. * multiple sources, and `this` binding `customizer` functions.
  2285. *
  2286. * @private
  2287. * @param {Object} object The destination object.
  2288. * @param {Object} source The source object.
  2289. * @param {Function} [customizer] The function to customize merged values.
  2290. * @param {Array} [stackA=[]] Tracks traversed source objects.
  2291. * @param {Array} [stackB=[]] Associates values with source counterparts.
  2292. * @returns {Object} Returns `object`.
  2293. */
  2294. function baseMerge(object, source, customizer, stackA, stackB) {
  2295. if (!isObject(object)) {
  2296. return object;
  2297. }
  2298. var isSrcArr = isArrayLike(source) && (isArray(source) || isTypedArray(source)),
  2299. props = isSrcArr ? undefined : keys(source);
  2300. arrayEach(props || source, function(srcValue, key) {
  2301. if (props) {
  2302. key = srcValue;
  2303. srcValue = source[key];
  2304. }
  2305. if (isObjectLike(srcValue)) {
  2306. stackA || (stackA = []);
  2307. stackB || (stackB = []);
  2308. baseMergeDeep(object, source, key, baseMerge, customizer, stackA, stackB);
  2309. }
  2310. else {
  2311. var value = object[key],
  2312. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  2313. isCommon = result === undefined;
  2314. if (isCommon) {
  2315. result = srcValue;
  2316. }
  2317. if ((result !== undefined || (isSrcArr && !(key in object))) &&
  2318. (isCommon || (result === result ? (result !== value) : (value === value)))) {
  2319. object[key] = result;
  2320. }
  2321. }
  2322. });
  2323. return object;
  2324. }
  2325. /**
  2326. * A specialized version of `baseMerge` for arrays and objects which performs
  2327. * deep merges and tracks traversed objects enabling objects with circular
  2328. * references to be merged.
  2329. *
  2330. * @private
  2331. * @param {Object} object The destination object.
  2332. * @param {Object} source The source object.
  2333. * @param {string} key The key of the value to merge.
  2334. * @param {Function} mergeFunc The function to merge values.
  2335. * @param {Function} [customizer] The function to customize merged values.
  2336. * @param {Array} [stackA=[]] Tracks traversed source objects.
  2337. * @param {Array} [stackB=[]] Associates values with source counterparts.
  2338. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  2339. */
  2340. function baseMergeDeep(object, source, key, mergeFunc, customizer, stackA, stackB) {
  2341. var length = stackA.length,
  2342. // srcValue = source[key];
  2343. srcValue = safeGet(source, key);//« patched from https://github.com/lodash/lodash/commit/d8e069cc3410082e44eb18fcf8e7f3d08ebe1d4a#diff-001d0647fb00f8336795faccdec19a31R1249
  2344. while (length--) {
  2345. if (stackA[length] == srcValue) {
  2346. object[key] = stackB[length];
  2347. return;
  2348. }
  2349. }
  2350. var value = object[key],
  2351. result = customizer ? customizer(value, srcValue, key, object, source) : undefined,
  2352. isCommon = result === undefined;
  2353. if (isCommon) {
  2354. result = srcValue;
  2355. if (isArrayLike(srcValue) && (isArray(srcValue) || isTypedArray(srcValue))) {
  2356. result = isArray(value)
  2357. ? value
  2358. : (isArrayLike(value) ? arrayCopy(value) : []);
  2359. }
  2360. else if (isPlainObject(srcValue) || isArguments(srcValue)) {
  2361. result = isArguments(value)
  2362. ? toPlainObject(value)
  2363. : (isPlainObject(value) ? value : {});
  2364. }
  2365. else {
  2366. isCommon = false;
  2367. }
  2368. }
  2369. // Add the source value to the stack of traversed objects and associate
  2370. // it with its merged value.
  2371. stackA.push(srcValue);
  2372. stackB.push(result);
  2373. if (isCommon) {
  2374. // Recursively merge objects and arrays (susceptible to call stack limits).
  2375. object[key] = mergeFunc(result, srcValue, customizer, stackA, stackB);
  2376. } else if (result === result ? (result !== value) : (value === value)) {
  2377. object[key] = result;
  2378. }
  2379. }
  2380. /**
  2381. * The base implementation of `_.property` without support for deep paths.
  2382. *
  2383. * @private
  2384. * @param {string} key The key of the property to get.
  2385. * @returns {Function} Returns the new function.
  2386. */
  2387. function baseProperty(key) {
  2388. return function(object) {
  2389. return object == null ? undefined : toObject(object)[key];
  2390. };
  2391. }
  2392. /**
  2393. * A specialized version of `baseProperty` which supports deep paths.
  2394. *
  2395. * @private
  2396. * @param {Array|string} path The path of the property to get.
  2397. * @returns {Function} Returns the new function.
  2398. */
  2399. function basePropertyDeep(path) {
  2400. var pathKey = (path + '');
  2401. path = toPath(path);
  2402. return function(object) {
  2403. return baseGet(object, path, pathKey);
  2404. };
  2405. }
  2406. /**
  2407. * The base implementation of `_.pullAt` without support for individual
  2408. * index arguments and capturing the removed elements.
  2409. *
  2410. * @private
  2411. * @param {Array} array The array to modify.
  2412. * @param {number[]} indexes The indexes of elements to remove.
  2413. * @returns {Array} Returns `array`.
  2414. */
  2415. function basePullAt(array, indexes) {
  2416. var length = array ? indexes.length : 0;
  2417. while (length--) {
  2418. var index = indexes[length];
  2419. if (index != previous && isIndex(index)) {
  2420. var previous = index;
  2421. splice.call(array, index, 1);
  2422. }
  2423. }
  2424. return array;
  2425. }
  2426. /**
  2427. * The base implementation of `_.random` without support for argument juggling
  2428. * and returning floating-point numbers.
  2429. *
  2430. * @private
  2431. * @param {number} min The minimum possible value.
  2432. * @param {number} max The maximum possible value.
  2433. * @returns {number} Returns the random number.
  2434. */
  2435. function baseRandom(min, max) {
  2436. return min + nativeFloor(nativeRandom() * (max - min + 1));
  2437. }
  2438. /**
  2439. * The base implementation of `_.reduce` and `_.reduceRight` without support
  2440. * for callback shorthands and `this` binding, which iterates over `collection`
  2441. * using the provided `eachFunc`.
  2442. *
  2443. * @private
  2444. * @param {Array|Object|string} collection The collection to iterate over.
  2445. * @param {Function} iteratee The function invoked per iteration.
  2446. * @param {*} accumulator The initial value.
  2447. * @param {boolean} initFromCollection Specify using the first or last element
  2448. * of `collection` as the initial value.
  2449. * @param {Function} eachFunc The function to iterate over `collection`.
  2450. * @returns {*} Returns the accumulated value.
  2451. */
  2452. function baseReduce(collection, iteratee, accumulator, initFromCollection, eachFunc) {
  2453. eachFunc(collection, function(value, index, collection) {
  2454. accumulator = initFromCollection
  2455. ? (initFromCollection = false, value)
  2456. : iteratee(accumulator, value, index, collection);
  2457. });
  2458. return accumulator;
  2459. }
  2460. /**
  2461. * The base implementation of `setData` without support for hot loop detection.
  2462. *
  2463. * @private
  2464. * @param {Function} func The function to associate metadata with.
  2465. * @param {*} data The metadata.
  2466. * @returns {Function} Returns `func`.
  2467. */
  2468. var baseSetData = !metaMap ? identity : function(func, data) {
  2469. metaMap.set(func, data);
  2470. return func;
  2471. };
  2472. /**
  2473. * The base implementation of `_.slice` without an iteratee call guard.
  2474. *
  2475. * @private
  2476. * @param {Array} array The array to slice.
  2477. * @param {number} [start=0] The start position.
  2478. * @param {number} [end=array.length] The end position.
  2479. * @returns {Array} Returns the slice of `array`.
  2480. */
  2481. function baseSlice(array, start, end) {
  2482. var index = -1,
  2483. length = array.length;
  2484. start = start == null ? 0 : (+start || 0);
  2485. if (start < 0) {
  2486. start = -start > length ? 0 : (length + start);
  2487. }
  2488. end = (end === undefined || end > length) ? length : (+end || 0);
  2489. if (end < 0) {
  2490. end += length;
  2491. }
  2492. length = start > end ? 0 : ((end - start) >>> 0);
  2493. start >>>= 0;
  2494. var result = Array(length);
  2495. while (++index < length) {
  2496. result[index] = array[index + start];
  2497. }
  2498. return result;
  2499. }
  2500. /**
  2501. * The base implementation of `_.some` without support for callback shorthands
  2502. * and `this` binding.
  2503. *
  2504. * @private
  2505. * @param {Array|Object|string} collection The collection to iterate over.
  2506. * @param {Function} predicate The function invoked per iteration.
  2507. * @returns {boolean} Returns `true` if any element passes the predicate check,
  2508. * else `false`.
  2509. */
  2510. function baseSome(collection, predicate) {
  2511. var result;
  2512. baseEach(collection, function(value, index, collection) {
  2513. result = predicate(value, index, collection);
  2514. return !result;
  2515. });
  2516. return !!result;
  2517. }
  2518. /**
  2519. * The base implementation of `_.sortBy` which uses `comparer` to define
  2520. * the sort order of `array` and replaces criteria objects with their
  2521. * corresponding values.
  2522. *
  2523. * @private
  2524. * @param {Array} array The array to sort.
  2525. * @param {Function} comparer The function to define sort order.
  2526. * @returns {Array} Returns `array`.
  2527. */
  2528. function baseSortBy(array, comparer) {
  2529. var length = array.length;
  2530. array.sort(comparer);
  2531. while (length--) {
  2532. array[length] = array[length].value;
  2533. }
  2534. return array;
  2535. }
  2536. /**
  2537. * The base implementation of `_.sortByOrder` without param guards.
  2538. *
  2539. * @private
  2540. * @param {Array|Object|string} collection The collection to iterate over.
  2541. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  2542. * @param {boolean[]} orders The sort orders of `iteratees`.
  2543. * @returns {Array} Returns the new sorted array.
  2544. */
  2545. function baseSortByOrder(collection, iteratees, orders) {
  2546. var callback = getCallback(),
  2547. index = -1;
  2548. iteratees = arrayMap(iteratees, function(iteratee) { return callback(iteratee); });
  2549. var result = baseMap(collection, function(value) {
  2550. var criteria = arrayMap(iteratees, function(iteratee) { return iteratee(value); });
  2551. return { 'criteria': criteria, 'index': ++index, 'value': value };
  2552. });
  2553. return baseSortBy(result, function(object, other) {
  2554. return compareMultiple(object, other, orders);
  2555. });
  2556. }
  2557. /**
  2558. * The base implementation of `_.sum` without support for callback shorthands
  2559. * and `this` binding.
  2560. *
  2561. * @private
  2562. * @param {Array|Object|string} collection The collection to iterate over.
  2563. * @param {Function} iteratee The function invoked per iteration.
  2564. * @returns {number} Returns the sum.
  2565. */
  2566. function baseSum(collection, iteratee) {
  2567. var result = 0;
  2568. baseEach(collection, function(value, index, collection) {
  2569. result += +iteratee(value, index, collection) || 0;
  2570. });
  2571. return result;
  2572. }
  2573. /**
  2574. * The base implementation of `_.uniq` without support for callback shorthands
  2575. * and `this` binding.
  2576. *
  2577. * @private
  2578. * @param {Array} array The array to inspect.
  2579. * @param {Function} [iteratee] The function invoked per iteration.
  2580. * @returns {Array} Returns the new duplicate free array.
  2581. */
  2582. function baseUniq(array, iteratee) {
  2583. var index = -1,
  2584. indexOf = getIndexOf(),
  2585. length = array.length,
  2586. isCommon = indexOf === baseIndexOf,
  2587. isLarge = isCommon && length >= LARGE_ARRAY_SIZE,
  2588. seen = isLarge ? createCache() : null,
  2589. result = [];
  2590. if (seen) {
  2591. indexOf = cacheIndexOf;
  2592. isCommon = false;
  2593. } else {
  2594. isLarge = false;
  2595. seen = iteratee ? [] : result;
  2596. }
  2597. outer:
  2598. while (++index < length) {
  2599. var value = array[index],
  2600. computed = iteratee ? iteratee(value, index, array) : value;
  2601. if (isCommon && value === value) {
  2602. var seenIndex = seen.length;
  2603. while (seenIndex--) {
  2604. if (seen[seenIndex] === computed) {
  2605. continue outer;
  2606. }
  2607. }
  2608. if (iteratee) {
  2609. seen.push(computed);
  2610. }
  2611. result.push(value);
  2612. }
  2613. else if (indexOf(seen, computed, 0) < 0) {
  2614. if (iteratee || isLarge) {
  2615. seen.push(computed);
  2616. }
  2617. result.push(value);
  2618. }
  2619. }
  2620. return result;
  2621. }
  2622. /**
  2623. * The base implementation of `_.values` and `_.valuesIn` which creates an
  2624. * array of `object` property values corresponding to the property names
  2625. * of `props`.
  2626. *
  2627. * @private
  2628. * @param {Object} object The object to query.
  2629. * @param {Array} props The property names to get values for.
  2630. * @returns {Object} Returns the array of property values.
  2631. */
  2632. function baseValues(object, props) {
  2633. var index = -1,
  2634. length = props.length,
  2635. result = Array(length);
  2636. while (++index < length) {
  2637. result[index] = object[props[index]];
  2638. }
  2639. return result;
  2640. }
  2641. /**
  2642. * The base implementation of `_.dropRightWhile`, `_.dropWhile`, `_.takeRightWhile`,
  2643. * and `_.takeWhile` without support for callback shorthands and `this` binding.
  2644. *
  2645. * @private
  2646. * @param {Array} array The array to query.
  2647. * @param {Function} predicate The function invoked per iteration.
  2648. * @param {boolean} [isDrop] Specify dropping elements instead of taking them.
  2649. * @param {boolean} [fromRight] Specify iterating from right to left.
  2650. * @returns {Array} Returns the slice of `array`.
  2651. */
  2652. function baseWhile(array, predicate, isDrop, fromRight) {
  2653. var length = array.length,
  2654. index = fromRight ? length : -1;
  2655. while ((fromRight ? index-- : ++index < length) && predicate(array[index], index, array)) {}
  2656. return isDrop
  2657. ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length))
  2658. : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index));
  2659. }
  2660. /**
  2661. * The base implementation of `wrapperValue` which returns the result of
  2662. * performing a sequence of actions on the unwrapped `value`, where each
  2663. * successive action is supplied the return value of the previous.
  2664. *
  2665. * @private
  2666. * @param {*} value The unwrapped value.
  2667. * @param {Array} actions Actions to peform to resolve the unwrapped value.
  2668. * @returns {*} Returns the resolved value.
  2669. */
  2670. function baseWrapperValue(value, actions) {
  2671. var result = value;
  2672. if (result instanceof LazyWrapper) {
  2673. result = result.value();
  2674. }
  2675. var index = -1,
  2676. length = actions.length;
  2677. while (++index < length) {
  2678. var action = actions[index];
  2679. result = action.func.apply(action.thisArg, arrayPush([result], action.args));
  2680. }
  2681. return result;
  2682. }
  2683. /**
  2684. * Performs a binary search of `array` to determine the index at which `value`
  2685. * should be inserted into `array` in order to maintain its sort order.
  2686. *
  2687. * @private
  2688. * @param {Array} array The sorted array to inspect.
  2689. * @param {*} value The value to evaluate.
  2690. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  2691. * @returns {number} Returns the index at which `value` should be inserted
  2692. * into `array`.
  2693. */
  2694. function binaryIndex(array, value, retHighest) {
  2695. var low = 0,
  2696. high = array ? array.length : low;
  2697. if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) {
  2698. while (low < high) {
  2699. var mid = (low + high) >>> 1,
  2700. computed = array[mid];
  2701. if ((retHighest ? (computed <= value) : (computed < value)) && computed !== null) {
  2702. low = mid + 1;
  2703. } else {
  2704. high = mid;
  2705. }
  2706. }
  2707. return high;
  2708. }
  2709. return binaryIndexBy(array, value, identity, retHighest);
  2710. }
  2711. /**
  2712. * This function is like `binaryIndex` except that it invokes `iteratee` for
  2713. * `value` and each element of `array` to compute their sort ranking. The
  2714. * iteratee is invoked with one argument; (value).
  2715. *
  2716. * @private
  2717. * @param {Array} array The sorted array to inspect.
  2718. * @param {*} value The value to evaluate.
  2719. * @param {Function} iteratee The function invoked per iteration.
  2720. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  2721. * @returns {number} Returns the index at which `value` should be inserted
  2722. * into `array`.
  2723. */
  2724. function binaryIndexBy(array, value, iteratee, retHighest) {
  2725. value = iteratee(value);
  2726. var low = 0,
  2727. high = array ? array.length : 0,
  2728. valIsNaN = value !== value,
  2729. valIsNull = value === null,
  2730. valIsUndef = value === undefined;
  2731. while (low < high) {
  2732. var mid = nativeFloor((low + high) / 2),
  2733. computed = iteratee(array[mid]),
  2734. isDef = computed !== undefined,
  2735. isReflexive = computed === computed;
  2736. if (valIsNaN) {
  2737. var setLow = isReflexive || retHighest;
  2738. } else if (valIsNull) {
  2739. setLow = isReflexive && isDef && (retHighest || computed != null);
  2740. } else if (valIsUndef) {
  2741. setLow = isReflexive && (retHighest || isDef);
  2742. } else if (computed == null) {
  2743. setLow = false;
  2744. } else {
  2745. setLow = retHighest ? (computed <= value) : (computed < value);
  2746. }
  2747. if (setLow) {
  2748. low = mid + 1;
  2749. } else {
  2750. high = mid;
  2751. }
  2752. }
  2753. return nativeMin(high, MAX_ARRAY_INDEX);
  2754. }
  2755. /**
  2756. * A specialized version of `baseCallback` which only supports `this` binding
  2757. * and specifying the number of arguments to provide to `func`.
  2758. *
  2759. * @private
  2760. * @param {Function} func The function to bind.
  2761. * @param {*} thisArg The `this` binding of `func`.
  2762. * @param {number} [argCount] The number of arguments to provide to `func`.
  2763. * @returns {Function} Returns the callback.
  2764. */
  2765. function bindCallback(func, thisArg, argCount) {
  2766. if (typeof func != 'function') {
  2767. return identity;
  2768. }
  2769. if (thisArg === undefined) {
  2770. return func;
  2771. }
  2772. switch (argCount) {
  2773. case 1: return function(value) {
  2774. return func.call(thisArg, value);
  2775. };
  2776. case 3: return function(value, index, collection) {
  2777. return func.call(thisArg, value, index, collection);
  2778. };
  2779. case 4: return function(accumulator, value, index, collection) {
  2780. return func.call(thisArg, accumulator, value, index, collection);
  2781. };
  2782. case 5: return function(value, other, key, object, source) {
  2783. return func.call(thisArg, value, other, key, object, source);
  2784. };
  2785. }
  2786. return function() {
  2787. return func.apply(thisArg, arguments);
  2788. };
  2789. }
  2790. /**
  2791. * Creates a clone of the given array buffer.
  2792. *
  2793. * @private
  2794. * @param {ArrayBuffer} buffer The array buffer to clone.
  2795. * @returns {ArrayBuffer} Returns the cloned array buffer.
  2796. */
  2797. function bufferClone(buffer) {
  2798. var result = new ArrayBuffer(buffer.byteLength),
  2799. view = new Uint8Array(result);
  2800. view.set(new Uint8Array(buffer));
  2801. return result;
  2802. }
  2803. /**
  2804. * Creates an array that is the composition of partially applied arguments,
  2805. * placeholders, and provided arguments into a single array of arguments.
  2806. *
  2807. * @private
  2808. * @param {Array|Object} args The provided arguments.
  2809. * @param {Array} partials The arguments to prepend to those provided.
  2810. * @param {Array} holders The `partials` placeholder indexes.
  2811. * @returns {Array} Returns the new array of composed arguments.
  2812. */
  2813. function composeArgs(args, partials, holders) {
  2814. var holdersLength = holders.length,
  2815. argsIndex = -1,
  2816. argsLength = nativeMax(args.length - holdersLength, 0),
  2817. leftIndex = -1,
  2818. leftLength = partials.length,
  2819. result = Array(leftLength + argsLength);
  2820. while (++leftIndex < leftLength) {
  2821. result[leftIndex] = partials[leftIndex];
  2822. }
  2823. while (++argsIndex < holdersLength) {
  2824. result[holders[argsIndex]] = args[argsIndex];
  2825. }
  2826. while (argsLength--) {
  2827. result[leftIndex++] = args[argsIndex++];
  2828. }
  2829. return result;
  2830. }
  2831. /**
  2832. * This function is like `composeArgs` except that the arguments composition
  2833. * is tailored for `_.partialRight`.
  2834. *
  2835. * @private
  2836. * @param {Array|Object} args The provided arguments.
  2837. * @param {Array} partials The arguments to append to those provided.
  2838. * @param {Array} holders The `partials` placeholder indexes.
  2839. * @returns {Array} Returns the new array of composed arguments.
  2840. */
  2841. function composeArgsRight(args, partials, holders) {
  2842. var holdersIndex = -1,
  2843. holdersLength = holders.length,
  2844. argsIndex = -1,
  2845. argsLength = nativeMax(args.length - holdersLength, 0),
  2846. rightIndex = -1,
  2847. rightLength = partials.length,
  2848. result = Array(argsLength + rightLength);
  2849. while (++argsIndex < argsLength) {
  2850. result[argsIndex] = args[argsIndex];
  2851. }
  2852. var offset = argsIndex;
  2853. while (++rightIndex < rightLength) {
  2854. result[offset + rightIndex] = partials[rightIndex];
  2855. }
  2856. while (++holdersIndex < holdersLength) {
  2857. result[offset + holders[holdersIndex]] = args[argsIndex++];
  2858. }
  2859. return result;
  2860. }
  2861. /**
  2862. * Creates a `_.countBy`, `_.groupBy`, `_.indexBy`, or `_.partition` function.
  2863. *
  2864. * @private
  2865. * @param {Function} setter The function to set keys and values of the accumulator object.
  2866. * @param {Function} [initializer] The function to initialize the accumulator object.
  2867. * @returns {Function} Returns the new aggregator function.
  2868. */
  2869. function createAggregator(setter, initializer) {
  2870. return function(collection, iteratee, thisArg) {
  2871. var result = initializer ? initializer() : {};
  2872. iteratee = getCallback(iteratee, thisArg, 3);
  2873. if (isArray(collection)) {
  2874. var index = -1,
  2875. length = collection.length;
  2876. while (++index < length) {
  2877. var value = collection[index];
  2878. setter(result, value, iteratee(value, index, collection), collection);
  2879. }
  2880. } else {
  2881. baseEach(collection, function(value, key, collection) {
  2882. setter(result, value, iteratee(value, key, collection), collection);
  2883. });
  2884. }
  2885. return result;
  2886. };
  2887. }
  2888. /**
  2889. * Creates a `_.assign`, `_.defaults`, or `_.merge` function.
  2890. *
  2891. * @private
  2892. * @param {Function} assigner The function to assign values.
  2893. * @returns {Function} Returns the new assigner function.
  2894. */
  2895. function createAssigner(assigner) {
  2896. return restParam(function(object, sources) {
  2897. var index = -1,
  2898. length = object == null ? 0 : sources.length,
  2899. customizer = length > 2 ? sources[length - 2] : undefined,
  2900. guard = length > 2 ? sources[2] : undefined,
  2901. thisArg = length > 1 ? sources[length - 1] : undefined;
  2902. if (typeof customizer == 'function') {
  2903. customizer = bindCallback(customizer, thisArg, 5);
  2904. length -= 2;
  2905. } else {
  2906. customizer = typeof thisArg == 'function' ? thisArg : undefined;
  2907. length -= (customizer ? 1 : 0);
  2908. }
  2909. if (guard && isIterateeCall(sources[0], sources[1], guard)) {
  2910. customizer = length < 3 ? undefined : customizer;
  2911. length = 1;
  2912. }
  2913. while (++index < length) {
  2914. var source = sources[index];
  2915. if (source) {
  2916. assigner(object, source, customizer);
  2917. }
  2918. }
  2919. return object;
  2920. });
  2921. }
  2922. /**
  2923. * Creates a `baseEach` or `baseEachRight` function.
  2924. *
  2925. * @private
  2926. * @param {Function} eachFunc The function to iterate over a collection.
  2927. * @param {boolean} [fromRight] Specify iterating from right to left.
  2928. * @returns {Function} Returns the new base function.
  2929. */
  2930. function createBaseEach(eachFunc, fromRight) {
  2931. return function(collection, iteratee) {
  2932. var length = collection ? getLength(collection) : 0;
  2933. if (!isLength(length)) {
  2934. return eachFunc(collection, iteratee);
  2935. }
  2936. var index = fromRight ? length : -1,
  2937. iterable = toObject(collection);
  2938. while ((fromRight ? index-- : ++index < length)) {
  2939. if (iteratee(iterable[index], index, iterable) === false) {
  2940. break;
  2941. }
  2942. }
  2943. return collection;
  2944. };
  2945. }
  2946. /**
  2947. * Creates a base function for `_.forIn` or `_.forInRight`.
  2948. *
  2949. * @private
  2950. * @param {boolean} [fromRight] Specify iterating from right to left.
  2951. * @returns {Function} Returns the new base function.
  2952. */
  2953. function createBaseFor(fromRight) {
  2954. return function(object, iteratee, keysFunc) {
  2955. var iterable = toObject(object),
  2956. props = keysFunc(object),
  2957. length = props.length,
  2958. index = fromRight ? length : -1;
  2959. while ((fromRight ? index-- : ++index < length)) {
  2960. var key = props[index];
  2961. if (iteratee(iterable[key], key, iterable) === false) {
  2962. break;
  2963. }
  2964. }
  2965. return object;
  2966. };
  2967. }
  2968. /**
  2969. * Creates a function that wraps `func` and invokes it with the `this`
  2970. * binding of `thisArg`.
  2971. *
  2972. * @private
  2973. * @param {Function} func The function to bind.
  2974. * @param {*} [thisArg] The `this` binding of `func`.
  2975. * @returns {Function} Returns the new bound function.
  2976. */
  2977. function createBindWrapper(func, thisArg) {
  2978. var Ctor = createCtorWrapper(func);
  2979. function wrapper() {
  2980. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  2981. return fn.apply(thisArg, arguments);
  2982. }
  2983. return wrapper;
  2984. }
  2985. /**
  2986. * Creates a `Set` cache object to optimize linear searches of large arrays.
  2987. *
  2988. * @private
  2989. * @param {Array} [values] The values to cache.
  2990. * @returns {null|Object} Returns the new cache object if `Set` is supported, else `null`.
  2991. */
  2992. function createCache(values) {
  2993. return (nativeCreate && Set) ? new SetCache(values) : null;
  2994. }
  2995. /**
  2996. * Creates a function that produces compound words out of the words in a
  2997. * given string.
  2998. *
  2999. * @private
  3000. * @param {Function} callback The function to combine each word.
  3001. * @returns {Function} Returns the new compounder function.
  3002. */
  3003. function createCompounder(callback) {
  3004. return function(string) {
  3005. var index = -1,
  3006. array = words(deburr(string)),
  3007. length = array.length,
  3008. result = '';
  3009. while (++index < length) {
  3010. result = callback(result, array[index], index);
  3011. }
  3012. return result;
  3013. };
  3014. }
  3015. /**
  3016. * Creates a function that produces an instance of `Ctor` regardless of
  3017. * whether it was invoked as part of a `new` expression or by `call` or `apply`.
  3018. *
  3019. * @private
  3020. * @param {Function} Ctor The constructor to wrap.
  3021. * @returns {Function} Returns the new wrapped function.
  3022. */
  3023. function createCtorWrapper(Ctor) {
  3024. return function() {
  3025. // Use a `switch` statement to work with class constructors.
  3026. // See http://ecma-international.org/ecma-262/6.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist
  3027. // for more details.
  3028. var args = arguments;
  3029. switch (args.length) {
  3030. case 0: return new Ctor;
  3031. case 1: return new Ctor(args[0]);
  3032. case 2: return new Ctor(args[0], args[1]);
  3033. case 3: return new Ctor(args[0], args[1], args[2]);
  3034. case 4: return new Ctor(args[0], args[1], args[2], args[3]);
  3035. case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]);
  3036. case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]);
  3037. case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]);
  3038. }
  3039. var thisBinding = baseCreate(Ctor.prototype),
  3040. result = Ctor.apply(thisBinding, args);
  3041. // Mimic the constructor's `return` behavior.
  3042. // See https://es5.github.io/#x13.2.2 for more details.
  3043. return isObject(result) ? result : thisBinding;
  3044. };
  3045. }
  3046. /**
  3047. * Creates a `_.curry` or `_.curryRight` function.
  3048. *
  3049. * @private
  3050. * @param {boolean} flag The curry bit flag.
  3051. * @returns {Function} Returns the new curry function.
  3052. */
  3053. function createCurry(flag) {
  3054. function curryFunc(func, arity, guard) {
  3055. if (guard && isIterateeCall(func, arity, guard)) {
  3056. arity = undefined;
  3057. }
  3058. var result = createWrapper(func, flag, undefined, undefined, undefined, undefined, undefined, arity);
  3059. result.placeholder = curryFunc.placeholder;
  3060. return result;
  3061. }
  3062. return curryFunc;
  3063. }
  3064. /**
  3065. * Creates a `_.defaults` or `_.defaultsDeep` function.
  3066. *
  3067. * @private
  3068. * @param {Function} assigner The function to assign values.
  3069. * @param {Function} customizer The function to customize assigned values.
  3070. * @returns {Function} Returns the new defaults function.
  3071. */
  3072. function createDefaults(assigner, customizer) {
  3073. return restParam(function(args) {
  3074. var object = args[0];
  3075. if (object == null) {
  3076. return object;
  3077. }
  3078. args.push(customizer);
  3079. return assigner.apply(undefined, args);
  3080. });
  3081. }
  3082. /**
  3083. * Creates a `_.max` or `_.min` function.
  3084. *
  3085. * @private
  3086. * @param {Function} comparator The function used to compare values.
  3087. * @param {*} exValue The initial extremum value.
  3088. * @returns {Function} Returns the new extremum function.
  3089. */
  3090. function createExtremum(comparator, exValue) {
  3091. return function(collection, iteratee, thisArg) {
  3092. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  3093. iteratee = undefined;
  3094. }
  3095. iteratee = getCallback(iteratee, thisArg, 3);
  3096. if (iteratee.length == 1) {
  3097. collection = isArray(collection) ? collection : toIterable(collection);
  3098. var result = arrayExtremum(collection, iteratee, comparator, exValue);
  3099. if (!(collection.length && result === exValue)) {
  3100. return result;
  3101. }
  3102. }
  3103. return baseExtremum(collection, iteratee, comparator, exValue);
  3104. };
  3105. }
  3106. /**
  3107. * Creates a `_.find` or `_.findLast` function.
  3108. *
  3109. * @private
  3110. * @param {Function} eachFunc The function to iterate over a collection.
  3111. * @param {boolean} [fromRight] Specify iterating from right to left.
  3112. * @returns {Function} Returns the new find function.
  3113. */
  3114. function createFind(eachFunc, fromRight) {
  3115. return function(collection, predicate, thisArg) {
  3116. predicate = getCallback(predicate, thisArg, 3);
  3117. if (isArray(collection)) {
  3118. var index = baseFindIndex(collection, predicate, fromRight);
  3119. return index > -1 ? collection[index] : undefined;
  3120. }
  3121. return baseFind(collection, predicate, eachFunc);
  3122. };
  3123. }
  3124. /**
  3125. * Creates a `_.findIndex` or `_.findLastIndex` function.
  3126. *
  3127. * @private
  3128. * @param {boolean} [fromRight] Specify iterating from right to left.
  3129. * @returns {Function} Returns the new find function.
  3130. */
  3131. function createFindIndex(fromRight) {
  3132. return function(array, predicate, thisArg) {
  3133. if (!(array && array.length)) {
  3134. return -1;
  3135. }
  3136. predicate = getCallback(predicate, thisArg, 3);
  3137. return baseFindIndex(array, predicate, fromRight);
  3138. };
  3139. }
  3140. /**
  3141. * Creates a `_.findKey` or `_.findLastKey` function.
  3142. *
  3143. * @private
  3144. * @param {Function} objectFunc The function to iterate over an object.
  3145. * @returns {Function} Returns the new find function.
  3146. */
  3147. function createFindKey(objectFunc) {
  3148. return function(object, predicate, thisArg) {
  3149. predicate = getCallback(predicate, thisArg, 3);
  3150. return baseFind(object, predicate, objectFunc, true);
  3151. };
  3152. }
  3153. /**
  3154. * Creates a `_.flow` or `_.flowRight` function.
  3155. *
  3156. * @private
  3157. * @param {boolean} [fromRight] Specify iterating from right to left.
  3158. * @returns {Function} Returns the new flow function.
  3159. */
  3160. function createFlow(fromRight) {
  3161. return function() {
  3162. var wrapper,
  3163. length = arguments.length,
  3164. index = fromRight ? length : -1,
  3165. leftIndex = 0,
  3166. funcs = Array(length);
  3167. while ((fromRight ? index-- : ++index < length)) {
  3168. var func = funcs[leftIndex++] = arguments[index];
  3169. if (typeof func != 'function') {
  3170. throw new TypeError(FUNC_ERROR_TEXT);
  3171. }
  3172. if (!wrapper && LodashWrapper.prototype.thru && getFuncName(func) == 'wrapper') {
  3173. wrapper = new LodashWrapper([], true);
  3174. }
  3175. }
  3176. index = wrapper ? -1 : length;
  3177. while (++index < length) {
  3178. func = funcs[index];
  3179. var funcName = getFuncName(func),
  3180. data = funcName == 'wrapper' ? getData(func) : undefined;
  3181. if (data && isLaziable(data[0]) && data[1] == (ARY_FLAG | CURRY_FLAG | PARTIAL_FLAG | REARG_FLAG) && !data[4].length && data[9] == 1) {
  3182. wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]);
  3183. } else {
  3184. wrapper = (func.length == 1 && isLaziable(func)) ? wrapper[funcName]() : wrapper.thru(func);
  3185. }
  3186. }
  3187. return function() {
  3188. var args = arguments,
  3189. value = args[0];
  3190. if (wrapper && args.length == 1 && isArray(value) && value.length >= LARGE_ARRAY_SIZE) {
  3191. return wrapper.plant(value).value();
  3192. }
  3193. var index = 0,
  3194. result = length ? funcs[index].apply(this, args) : value;
  3195. while (++index < length) {
  3196. result = funcs[index].call(this, result);
  3197. }
  3198. return result;
  3199. };
  3200. };
  3201. }
  3202. /**
  3203. * Creates a function for `_.forEach` or `_.forEachRight`.
  3204. *
  3205. * @private
  3206. * @param {Function} arrayFunc The function to iterate over an array.
  3207. * @param {Function} eachFunc The function to iterate over a collection.
  3208. * @returns {Function} Returns the new each function.
  3209. */
  3210. function createForEach(arrayFunc, eachFunc) {
  3211. return function(collection, iteratee, thisArg) {
  3212. return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
  3213. ? arrayFunc(collection, iteratee)
  3214. : eachFunc(collection, bindCallback(iteratee, thisArg, 3));
  3215. };
  3216. }
  3217. /**
  3218. * Creates a function for `_.forIn` or `_.forInRight`.
  3219. *
  3220. * @private
  3221. * @param {Function} objectFunc The function to iterate over an object.
  3222. * @returns {Function} Returns the new each function.
  3223. */
  3224. function createForIn(objectFunc) {
  3225. return function(object, iteratee, thisArg) {
  3226. if (typeof iteratee != 'function' || thisArg !== undefined) {
  3227. iteratee = bindCallback(iteratee, thisArg, 3);
  3228. }
  3229. return objectFunc(object, iteratee, keysIn);
  3230. };
  3231. }
  3232. /**
  3233. * Creates a function for `_.forOwn` or `_.forOwnRight`.
  3234. *
  3235. * @private
  3236. * @param {Function} objectFunc The function to iterate over an object.
  3237. * @returns {Function} Returns the new each function.
  3238. */
  3239. function createForOwn(objectFunc) {
  3240. return function(object, iteratee, thisArg) {
  3241. if (typeof iteratee != 'function' || thisArg !== undefined) {
  3242. iteratee = bindCallback(iteratee, thisArg, 3);
  3243. }
  3244. return objectFunc(object, iteratee);
  3245. };
  3246. }
  3247. /**
  3248. * Creates a function for `_.mapKeys` or `_.mapValues`.
  3249. *
  3250. * @private
  3251. * @param {boolean} [isMapKeys] Specify mapping keys instead of values.
  3252. * @returns {Function} Returns the new map function.
  3253. */
  3254. function createObjectMapper(isMapKeys) {
  3255. return function(object, iteratee, thisArg) {
  3256. var result = {};
  3257. iteratee = getCallback(iteratee, thisArg, 3);
  3258. baseForOwn(object, function(value, key, object) {
  3259. var mapped = iteratee(value, key, object);
  3260. key = isMapKeys ? mapped : key;
  3261. value = isMapKeys ? value : mapped;
  3262. result[key] = value;
  3263. });
  3264. return result;
  3265. };
  3266. }
  3267. /**
  3268. * Creates a function for `_.padLeft` or `_.padRight`.
  3269. *
  3270. * @private
  3271. * @param {boolean} [fromRight] Specify padding from the right.
  3272. * @returns {Function} Returns the new pad function.
  3273. */
  3274. function createPadDir(fromRight) {
  3275. return function(string, length, chars) {
  3276. string = baseToString(string);
  3277. return (fromRight ? string : '') + createPadding(string, length, chars) + (fromRight ? '' : string);
  3278. };
  3279. }
  3280. /**
  3281. * Creates a `_.partial` or `_.partialRight` function.
  3282. *
  3283. * @private
  3284. * @param {boolean} flag The partial bit flag.
  3285. * @returns {Function} Returns the new partial function.
  3286. */
  3287. function createPartial(flag) {
  3288. var partialFunc = restParam(function(func, partials) {
  3289. var holders = replaceHolders(partials, partialFunc.placeholder);
  3290. return createWrapper(func, flag, undefined, partials, holders);
  3291. });
  3292. return partialFunc;
  3293. }
  3294. /**
  3295. * Creates a function for `_.reduce` or `_.reduceRight`.
  3296. *
  3297. * @private
  3298. * @param {Function} arrayFunc The function to iterate over an array.
  3299. * @param {Function} eachFunc The function to iterate over a collection.
  3300. * @returns {Function} Returns the new each function.
  3301. */
  3302. function createReduce(arrayFunc, eachFunc) {
  3303. return function(collection, iteratee, accumulator, thisArg) {
  3304. var initFromArray = arguments.length < 3;
  3305. return (typeof iteratee == 'function' && thisArg === undefined && isArray(collection))
  3306. ? arrayFunc(collection, iteratee, accumulator, initFromArray)
  3307. : baseReduce(collection, getCallback(iteratee, thisArg, 4), accumulator, initFromArray, eachFunc);
  3308. };
  3309. }
  3310. /**
  3311. * Creates a function that wraps `func` and invokes it with optional `this`
  3312. * binding of, partial application, and currying.
  3313. *
  3314. * @private
  3315. * @param {Function|string} func The function or method name to reference.
  3316. * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
  3317. * @param {*} [thisArg] The `this` binding of `func`.
  3318. * @param {Array} [partials] The arguments to prepend to those provided to the new function.
  3319. * @param {Array} [holders] The `partials` placeholder indexes.
  3320. * @param {Array} [partialsRight] The arguments to append to those provided to the new function.
  3321. * @param {Array} [holdersRight] The `partialsRight` placeholder indexes.
  3322. * @param {Array} [argPos] The argument positions of the new function.
  3323. * @param {number} [ary] The arity cap of `func`.
  3324. * @param {number} [arity] The arity of `func`.
  3325. * @returns {Function} Returns the new wrapped function.
  3326. */
  3327. function createHybridWrapper(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) {
  3328. var isAry = bitmask & ARY_FLAG,
  3329. isBind = bitmask & BIND_FLAG,
  3330. isBindKey = bitmask & BIND_KEY_FLAG,
  3331. isCurry = bitmask & CURRY_FLAG,
  3332. isCurryBound = bitmask & CURRY_BOUND_FLAG,
  3333. isCurryRight = bitmask & CURRY_RIGHT_FLAG,
  3334. Ctor = isBindKey ? undefined : createCtorWrapper(func);
  3335. function wrapper() {
  3336. // Avoid `arguments` object use disqualifying optimizations by
  3337. // converting it to an array before providing it to other functions.
  3338. var length = arguments.length,
  3339. index = length,
  3340. args = Array(length);
  3341. while (index--) {
  3342. args[index] = arguments[index];
  3343. }
  3344. if (partials) {
  3345. args = composeArgs(args, partials, holders);
  3346. }
  3347. if (partialsRight) {
  3348. args = composeArgsRight(args, partialsRight, holdersRight);
  3349. }
  3350. if (isCurry || isCurryRight) {
  3351. var placeholder = wrapper.placeholder,
  3352. argsHolders = replaceHolders(args, placeholder);
  3353. length -= argsHolders.length;
  3354. if (length < arity) {
  3355. var newArgPos = argPos ? arrayCopy(argPos) : undefined,
  3356. newArity = nativeMax(arity - length, 0),
  3357. newsHolders = isCurry ? argsHolders : undefined,
  3358. newHoldersRight = isCurry ? undefined : argsHolders,
  3359. newPartials = isCurry ? args : undefined,
  3360. newPartialsRight = isCurry ? undefined : args;
  3361. bitmask |= (isCurry ? PARTIAL_FLAG : PARTIAL_RIGHT_FLAG);
  3362. bitmask &= ~(isCurry ? PARTIAL_RIGHT_FLAG : PARTIAL_FLAG);
  3363. if (!isCurryBound) {
  3364. bitmask &= ~(BIND_FLAG | BIND_KEY_FLAG);
  3365. }
  3366. var newData = [func, bitmask, thisArg, newPartials, newsHolders, newPartialsRight, newHoldersRight, newArgPos, ary, newArity],
  3367. result = createHybridWrapper.apply(undefined, newData);
  3368. if (isLaziable(func)) {
  3369. setData(result, newData);
  3370. }
  3371. result.placeholder = placeholder;
  3372. return result;
  3373. }
  3374. }
  3375. var thisBinding = isBind ? thisArg : this,
  3376. fn = isBindKey ? thisBinding[func] : func;
  3377. if (argPos) {
  3378. args = reorder(args, argPos);
  3379. }
  3380. if (isAry && ary < args.length) {
  3381. args.length = ary;
  3382. }
  3383. if (this && this !== root && this instanceof wrapper) {
  3384. fn = Ctor || createCtorWrapper(func);
  3385. }
  3386. return fn.apply(thisBinding, args);
  3387. }
  3388. return wrapper;
  3389. }
  3390. /**
  3391. * Creates the padding required for `string` based on the given `length`.
  3392. * The `chars` string is truncated if the number of characters exceeds `length`.
  3393. *
  3394. * @private
  3395. * @param {string} string The string to create padding for.
  3396. * @param {number} [length=0] The padding length.
  3397. * @param {string} [chars=' '] The string used as padding.
  3398. * @returns {string} Returns the pad for `string`.
  3399. */
  3400. function createPadding(string, length, chars) {
  3401. var strLength = string.length;
  3402. length = +length;
  3403. if (strLength >= length || !nativeIsFinite(length)) {
  3404. return '';
  3405. }
  3406. var padLength = length - strLength;
  3407. chars = chars == null ? ' ' : (chars + '');
  3408. return repeat(chars, nativeCeil(padLength / chars.length)).slice(0, padLength);
  3409. }
  3410. /**
  3411. * Creates a function that wraps `func` and invokes it with the optional `this`
  3412. * binding of `thisArg` and the `partials` prepended to those provided to
  3413. * the wrapper.
  3414. *
  3415. * @private
  3416. * @param {Function} func The function to partially apply arguments to.
  3417. * @param {number} bitmask The bitmask of flags. See `createWrapper` for more details.
  3418. * @param {*} thisArg The `this` binding of `func`.
  3419. * @param {Array} partials The arguments to prepend to those provided to the new function.
  3420. * @returns {Function} Returns the new bound function.
  3421. */
  3422. function createPartialWrapper(func, bitmask, thisArg, partials) {
  3423. var isBind = bitmask & BIND_FLAG,
  3424. Ctor = createCtorWrapper(func);
  3425. function wrapper() {
  3426. // Avoid `arguments` object use disqualifying optimizations by
  3427. // converting it to an array before providing it `func`.
  3428. var argsIndex = -1,
  3429. argsLength = arguments.length,
  3430. leftIndex = -1,
  3431. leftLength = partials.length,
  3432. args = Array(leftLength + argsLength);
  3433. while (++leftIndex < leftLength) {
  3434. args[leftIndex] = partials[leftIndex];
  3435. }
  3436. while (argsLength--) {
  3437. args[leftIndex++] = arguments[++argsIndex];
  3438. }
  3439. var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func;
  3440. return fn.apply(isBind ? thisArg : this, args);
  3441. }
  3442. return wrapper;
  3443. }
  3444. /**
  3445. * Creates a `_.ceil`, `_.floor`, or `_.round` function.
  3446. *
  3447. * @private
  3448. * @param {string} methodName The name of the `Math` method to use when rounding.
  3449. * @returns {Function} Returns the new round function.
  3450. */
  3451. function createRound(methodName) {
  3452. var func = Math[methodName];
  3453. return function(number, precision) {
  3454. precision = precision === undefined ? 0 : (+precision || 0);
  3455. if (precision) {
  3456. precision = pow(10, precision);
  3457. return func(number * precision) / precision;
  3458. }
  3459. return func(number);
  3460. };
  3461. }
  3462. /**
  3463. * Creates a `_.sortedIndex` or `_.sortedLastIndex` function.
  3464. *
  3465. * @private
  3466. * @param {boolean} [retHighest] Specify returning the highest qualified index.
  3467. * @returns {Function} Returns the new index function.
  3468. */
  3469. function createSortedIndex(retHighest) {
  3470. return function(array, value, iteratee, thisArg) {
  3471. var callback = getCallback(iteratee);
  3472. return (iteratee == null && callback === baseCallback)
  3473. ? binaryIndex(array, value, retHighest)
  3474. : binaryIndexBy(array, value, callback(iteratee, thisArg, 1), retHighest);
  3475. };
  3476. }
  3477. /**
  3478. * Creates a function that either curries or invokes `func` with optional
  3479. * `this` binding and partially applied arguments.
  3480. *
  3481. * @private
  3482. * @param {Function|string} func The function or method name to reference.
  3483. * @param {number} bitmask The bitmask of flags.
  3484. * The bitmask may be composed of the following flags:
  3485. * 1 - `_.bind`
  3486. * 2 - `_.bindKey`
  3487. * 4 - `_.curry` or `_.curryRight` of a bound function
  3488. * 8 - `_.curry`
  3489. * 16 - `_.curryRight`
  3490. * 32 - `_.partial`
  3491. * 64 - `_.partialRight`
  3492. * 128 - `_.rearg`
  3493. * 256 - `_.ary`
  3494. * @param {*} [thisArg] The `this` binding of `func`.
  3495. * @param {Array} [partials] The arguments to be partially applied.
  3496. * @param {Array} [holders] The `partials` placeholder indexes.
  3497. * @param {Array} [argPos] The argument positions of the new function.
  3498. * @param {number} [ary] The arity cap of `func`.
  3499. * @param {number} [arity] The arity of `func`.
  3500. * @returns {Function} Returns the new wrapped function.
  3501. */
  3502. function createWrapper(func, bitmask, thisArg, partials, holders, argPos, ary, arity) {
  3503. var isBindKey = bitmask & BIND_KEY_FLAG;
  3504. if (!isBindKey && typeof func != 'function') {
  3505. throw new TypeError(FUNC_ERROR_TEXT);
  3506. }
  3507. var length = partials ? partials.length : 0;
  3508. if (!length) {
  3509. bitmask &= ~(PARTIAL_FLAG | PARTIAL_RIGHT_FLAG);
  3510. partials = holders = undefined;
  3511. }
  3512. length -= (holders ? holders.length : 0);
  3513. if (bitmask & PARTIAL_RIGHT_FLAG) {
  3514. var partialsRight = partials,
  3515. holdersRight = holders;
  3516. partials = holders = undefined;
  3517. }
  3518. var data = isBindKey ? undefined : getData(func),
  3519. newData = [func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity];
  3520. if (data) {
  3521. mergeData(newData, data);
  3522. bitmask = newData[1];
  3523. arity = newData[9];
  3524. }
  3525. newData[9] = arity == null
  3526. ? (isBindKey ? 0 : func.length)
  3527. : (nativeMax(arity - length, 0) || 0);
  3528. if (bitmask == BIND_FLAG) {
  3529. var result = createBindWrapper(newData[0], newData[2]);
  3530. } else if ((bitmask == PARTIAL_FLAG || bitmask == (BIND_FLAG | PARTIAL_FLAG)) && !newData[4].length) {
  3531. result = createPartialWrapper.apply(undefined, newData);
  3532. } else {
  3533. result = createHybridWrapper.apply(undefined, newData);
  3534. }
  3535. var setter = data ? baseSetData : setData;
  3536. return setter(result, newData);
  3537. }
  3538. /**
  3539. * A specialized version of `baseIsEqualDeep` for arrays with support for
  3540. * partial deep comparisons.
  3541. *
  3542. * @private
  3543. * @param {Array} array The array to compare.
  3544. * @param {Array} other The other array to compare.
  3545. * @param {Function} equalFunc The function to determine equivalents of values.
  3546. * @param {Function} [customizer] The function to customize comparing arrays.
  3547. * @param {boolean} [isLoose] Specify performing partial comparisons.
  3548. * @param {Array} [stackA] Tracks traversed `value` objects.
  3549. * @param {Array} [stackB] Tracks traversed `other` objects.
  3550. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  3551. */
  3552. function equalArrays(array, other, equalFunc, customizer, isLoose, stackA, stackB) {
  3553. var index = -1,
  3554. arrLength = array.length,
  3555. othLength = other.length;
  3556. if (arrLength != othLength && !(isLoose && othLength > arrLength)) {
  3557. return false;
  3558. }
  3559. // Ignore non-index properties.
  3560. while (++index < arrLength) {
  3561. var arrValue = array[index],
  3562. othValue = other[index],
  3563. result = customizer ? customizer(isLoose ? othValue : arrValue, isLoose ? arrValue : othValue, index) : undefined;
  3564. if (result !== undefined) {
  3565. if (result) {
  3566. continue;
  3567. }
  3568. return false;
  3569. }
  3570. // Recursively compare arrays (susceptible to call stack limits).
  3571. if (isLoose) {
  3572. if (!arraySome(other, function(othValue) {
  3573. return arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB);
  3574. })) {
  3575. return false;
  3576. }
  3577. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, customizer, isLoose, stackA, stackB))) {
  3578. return false;
  3579. }
  3580. }
  3581. return true;
  3582. }
  3583. /**
  3584. * A specialized version of `baseIsEqualDeep` for comparing objects of
  3585. * the same `toStringTag`.
  3586. *
  3587. * **Note:** This function only supports comparing values with tags of
  3588. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  3589. *
  3590. * @private
  3591. * @param {Object} object The object to compare.
  3592. * @param {Object} other The other object to compare.
  3593. * @param {string} tag The `toStringTag` of the objects to compare.
  3594. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3595. */
  3596. function equalByTag(object, other, tag) {
  3597. switch (tag) {
  3598. case boolTag:
  3599. case dateTag:
  3600. // Coerce dates and booleans to numbers, dates to milliseconds and booleans
  3601. // to `1` or `0` treating invalid dates coerced to `NaN` as not equal.
  3602. return +object == +other;
  3603. case errorTag:
  3604. return object.name == other.name && object.message == other.message;
  3605. case numberTag:
  3606. // Treat `NaN` vs. `NaN` as equal.
  3607. return (object != +object)
  3608. ? other != +other
  3609. : object == +other;
  3610. case regexpTag:
  3611. case stringTag:
  3612. // Coerce regexes to strings and treat strings primitives and string
  3613. // objects as equal. See https://es5.github.io/#x15.10.6.4 for more details.
  3614. return object == (other + '');
  3615. }
  3616. return false;
  3617. }
  3618. /**
  3619. * A specialized version of `baseIsEqualDeep` for objects with support for
  3620. * partial deep comparisons.
  3621. *
  3622. * @private
  3623. * @param {Object} object The object to compare.
  3624. * @param {Object} other The other object to compare.
  3625. * @param {Function} equalFunc The function to determine equivalents of values.
  3626. * @param {Function} [customizer] The function to customize comparing values.
  3627. * @param {boolean} [isLoose] Specify performing partial comparisons.
  3628. * @param {Array} [stackA] Tracks traversed `value` objects.
  3629. * @param {Array} [stackB] Tracks traversed `other` objects.
  3630. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  3631. */
  3632. function equalObjects(object, other, equalFunc, customizer, isLoose, stackA, stackB) {
  3633. var objProps = keys(object),
  3634. objLength = objProps.length,
  3635. othProps = keys(other),
  3636. othLength = othProps.length;
  3637. if (objLength != othLength && !isLoose) {
  3638. return false;
  3639. }
  3640. var index = objLength;
  3641. while (index--) {
  3642. var key = objProps[index];
  3643. if (!(isLoose ? key in other : hasOwnProperty.call(other, key))) {
  3644. return false;
  3645. }
  3646. }
  3647. var skipCtor = isLoose;
  3648. while (++index < objLength) {
  3649. key = objProps[index];
  3650. var objValue = object[key],
  3651. othValue = other[key],
  3652. result = customizer ? customizer(isLoose ? othValue : objValue, isLoose? objValue : othValue, key) : undefined;
  3653. // Recursively compare objects (susceptible to call stack limits).
  3654. if (!(result === undefined ? equalFunc(objValue, othValue, customizer, isLoose, stackA, stackB) : result)) {
  3655. return false;
  3656. }
  3657. skipCtor || (skipCtor = key == 'constructor');
  3658. }
  3659. if (!skipCtor) {
  3660. var objCtor = object.constructor,
  3661. othCtor = other.constructor;
  3662. // Non `Object` object instances with different constructors are not equal.
  3663. if (objCtor != othCtor &&
  3664. ('constructor' in object && 'constructor' in other) &&
  3665. !(typeof objCtor == 'function' && objCtor instanceof objCtor &&
  3666. typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  3667. return false;
  3668. }
  3669. }
  3670. return true;
  3671. }
  3672. /**
  3673. * Gets the appropriate "callback" function. If the `_.callback` method is
  3674. * customized this function returns the custom method, otherwise it returns
  3675. * the `baseCallback` function. If arguments are provided the chosen function
  3676. * is invoked with them and its result is returned.
  3677. *
  3678. * @private
  3679. * @returns {Function} Returns the chosen function or its result.
  3680. */
  3681. function getCallback(func, thisArg, argCount) {
  3682. var result = lodash.callback || callback;
  3683. result = result === callback ? baseCallback : result;
  3684. return argCount ? result(func, thisArg, argCount) : result;
  3685. }
  3686. /**
  3687. * Gets metadata for `func`.
  3688. *
  3689. * @private
  3690. * @param {Function} func The function to query.
  3691. * @returns {*} Returns the metadata for `func`.
  3692. */
  3693. var getData = !metaMap ? noop : function(func) {
  3694. return metaMap.get(func);
  3695. };
  3696. /**
  3697. * Gets the name of `func`.
  3698. *
  3699. * @private
  3700. * @param {Function} func The function to query.
  3701. * @returns {string} Returns the function name.
  3702. */
  3703. function getFuncName(func) {
  3704. var result = (func.name + ''),
  3705. array = realNames[result],
  3706. length = array ? array.length : 0;
  3707. while (length--) {
  3708. var data = array[length],
  3709. otherFunc = data.func;
  3710. if (otherFunc == null || otherFunc == func) {
  3711. return data.name;
  3712. }
  3713. }
  3714. return result;
  3715. }
  3716. /**
  3717. * Gets the appropriate "indexOf" function. If the `_.indexOf` method is
  3718. * customized this function returns the custom method, otherwise it returns
  3719. * the `baseIndexOf` function. If arguments are provided the chosen function
  3720. * is invoked with them and its result is returned.
  3721. *
  3722. * @private
  3723. * @returns {Function|number} Returns the chosen function or its result.
  3724. */
  3725. function getIndexOf(collection, target, fromIndex) {
  3726. var result = lodash.indexOf || indexOf;
  3727. result = result === indexOf ? baseIndexOf : result;
  3728. return collection ? result(collection, target, fromIndex) : result;
  3729. }
  3730. /**
  3731. * Gets the "length" property value of `object`.
  3732. *
  3733. * **Note:** This function is used to avoid a [JIT bug](https://bugs.webkit.org/show_bug.cgi?id=142792)
  3734. * that affects Safari on at least iOS 8.1-8.3 ARM64.
  3735. *
  3736. * @private
  3737. * @param {Object} object The object to query.
  3738. * @returns {*} Returns the "length" value.
  3739. */
  3740. var getLength = baseProperty('length');
  3741. /**
  3742. * Gets the propery names, values, and compare flags of `object`.
  3743. *
  3744. * @private
  3745. * @param {Object} object The object to query.
  3746. * @returns {Array} Returns the match data of `object`.
  3747. */
  3748. function getMatchData(object) {
  3749. var result = pairs(object),
  3750. length = result.length;
  3751. while (length--) {
  3752. result[length][2] = isStrictComparable(result[length][1]);
  3753. }
  3754. return result;
  3755. }
  3756. /**
  3757. * Gets the native function at `key` of `object`.
  3758. *
  3759. * @private
  3760. * @param {Object} object The object to query.
  3761. * @param {string} key The key of the method to get.
  3762. * @returns {*} Returns the function if it's native, else `undefined`.
  3763. */
  3764. function getNative(object, key) {
  3765. var value = object == null ? undefined : object[key];
  3766. return isNative(value) ? value : undefined;
  3767. }
  3768. /**
  3769. * Gets the view, applying any `transforms` to the `start` and `end` positions.
  3770. *
  3771. * @private
  3772. * @param {number} start The start of the view.
  3773. * @param {number} end The end of the view.
  3774. * @param {Array} transforms The transformations to apply to the view.
  3775. * @returns {Object} Returns an object containing the `start` and `end`
  3776. * positions of the view.
  3777. */
  3778. function getView(start, end, transforms) {
  3779. var index = -1,
  3780. length = transforms.length;
  3781. while (++index < length) {
  3782. var data = transforms[index],
  3783. size = data.size;
  3784. switch (data.type) {
  3785. case 'drop': start += size; break;
  3786. case 'dropRight': end -= size; break;
  3787. case 'take': end = nativeMin(end, start + size); break;
  3788. case 'takeRight': start = nativeMax(start, end - size); break;
  3789. }
  3790. }
  3791. return { 'start': start, 'end': end };
  3792. }
  3793. /**
  3794. * Initializes an array clone.
  3795. *
  3796. * @private
  3797. * @param {Array} array The array to clone.
  3798. * @returns {Array} Returns the initialized clone.
  3799. */
  3800. function initCloneArray(array) {
  3801. var length = array.length,
  3802. result = new array.constructor(length);
  3803. // Add array properties assigned by `RegExp#exec`.
  3804. if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) {
  3805. result.index = array.index;
  3806. result.input = array.input;
  3807. }
  3808. return result;
  3809. }
  3810. /**
  3811. * Initializes an object clone.
  3812. *
  3813. * @private
  3814. * @param {Object} object The object to clone.
  3815. * @returns {Object} Returns the initialized clone.
  3816. */
  3817. function initCloneObject(object) {
  3818. var Ctor = object.constructor;
  3819. if (!(typeof Ctor == 'function' && Ctor instanceof Ctor)) {
  3820. Ctor = Object;
  3821. }
  3822. return new Ctor;
  3823. }
  3824. /**
  3825. * Initializes an object clone based on its `toStringTag`.
  3826. *
  3827. * **Note:** This function only supports cloning values with tags of
  3828. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  3829. *
  3830. * @private
  3831. * @param {Object} object The object to clone.
  3832. * @param {string} tag The `toStringTag` of the object to clone.
  3833. * @param {boolean} [isDeep] Specify a deep clone.
  3834. * @returns {Object} Returns the initialized clone.
  3835. */
  3836. function initCloneByTag(object, tag, isDeep) {
  3837. var Ctor = object.constructor;
  3838. switch (tag) {
  3839. case arrayBufferTag:
  3840. return bufferClone(object);
  3841. case boolTag:
  3842. case dateTag:
  3843. return new Ctor(+object);
  3844. case float32Tag: case float64Tag:
  3845. case int8Tag: case int16Tag: case int32Tag:
  3846. case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag:
  3847. // Safari 5 mobile incorrectly has `Object` as the constructor of typed arrays.
  3848. if (Ctor instanceof Ctor) {
  3849. Ctor = ctorByTag[tag];
  3850. }
  3851. var buffer = object.buffer;
  3852. return new Ctor(isDeep ? bufferClone(buffer) : buffer, object.byteOffset, object.length);
  3853. case numberTag:
  3854. case stringTag:
  3855. return new Ctor(object);
  3856. case regexpTag:
  3857. var result = new Ctor(object.source, reFlags.exec(object));
  3858. result.lastIndex = object.lastIndex;
  3859. }
  3860. return result;
  3861. }
  3862. /**
  3863. * Invokes the method at `path` on `object`.
  3864. *
  3865. * @private
  3866. * @param {Object} object The object to query.
  3867. * @param {Array|string} path The path of the method to invoke.
  3868. * @param {Array} args The arguments to invoke the method with.
  3869. * @returns {*} Returns the result of the invoked method.
  3870. */
  3871. function invokePath(object, path, args) {
  3872. if (object != null && !isKey(path, object)) {
  3873. path = toPath(path);
  3874. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  3875. path = last(path);
  3876. }
  3877. var func = object == null ? object : object[path];
  3878. return func == null ? undefined : func.apply(object, args);
  3879. }
  3880. /**
  3881. * Checks if `value` is array-like.
  3882. *
  3883. * @private
  3884. * @param {*} value The value to check.
  3885. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  3886. */
  3887. function isArrayLike(value) {
  3888. return value != null && isLength(getLength(value));
  3889. }
  3890. /**
  3891. * Checks if `value` is a valid array-like index.
  3892. *
  3893. * @private
  3894. * @param {*} value The value to check.
  3895. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  3896. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  3897. */
  3898. function isIndex(value, length) {
  3899. value = (typeof value == 'number' || reIsUint.test(value)) ? +value : -1;
  3900. length = length == null ? MAX_SAFE_INTEGER : length;
  3901. return value > -1 && value % 1 == 0 && value < length;
  3902. }
  3903. /**
  3904. * Checks if the provided arguments are from an iteratee call.
  3905. *
  3906. * @private
  3907. * @param {*} value The potential iteratee value argument.
  3908. * @param {*} index The potential iteratee index or key argument.
  3909. * @param {*} object The potential iteratee object argument.
  3910. * @returns {boolean} Returns `true` if the arguments are from an iteratee call, else `false`.
  3911. */
  3912. function isIterateeCall(value, index, object) {
  3913. if (!isObject(object)) {
  3914. return false;
  3915. }
  3916. var type = typeof index;
  3917. if (type == 'number'
  3918. ? (isArrayLike(object) && isIndex(index, object.length))
  3919. : (type == 'string' && index in object)) {
  3920. var other = object[index];
  3921. return value === value ? (value === other) : (other !== other);
  3922. }
  3923. return false;
  3924. }
  3925. /**
  3926. * Checks if `value` is a property name and not a property path.
  3927. *
  3928. * @private
  3929. * @param {*} value The value to check.
  3930. * @param {Object} [object] The object to query keys on.
  3931. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  3932. */
  3933. function isKey(value, object) {
  3934. var type = typeof value;
  3935. if ((type == 'string' && reIsPlainProp.test(value)) || type == 'number') {
  3936. return true;
  3937. }
  3938. if (isArray(value)) {
  3939. return false;
  3940. }
  3941. var result = !reIsDeepProp.test(value);
  3942. return result || (object != null && value in toObject(object));
  3943. }
  3944. /**
  3945. * Checks if `func` has a lazy counterpart.
  3946. *
  3947. * @private
  3948. * @param {Function} func The function to check.
  3949. * @returns {boolean} Returns `true` if `func` has a lazy counterpart, else `false`.
  3950. */
  3951. function isLaziable(func) {
  3952. var funcName = getFuncName(func),
  3953. other = lodash[funcName];
  3954. if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) {
  3955. return false;
  3956. }
  3957. if (func === other) {
  3958. return true;
  3959. }
  3960. var data = getData(other);
  3961. return !!data && func === data[0];
  3962. }
  3963. /**
  3964. * Checks if `value` is a valid array-like length.
  3965. *
  3966. * **Note:** This function is based on [`ToLength`](http://ecma-international.org/ecma-262/6.0/#sec-tolength).
  3967. *
  3968. * @private
  3969. * @param {*} value The value to check.
  3970. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  3971. */
  3972. function isLength(value) {
  3973. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  3974. }
  3975. /**
  3976. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  3977. *
  3978. * @private
  3979. * @param {*} value The value to check.
  3980. * @returns {boolean} Returns `true` if `value` if suitable for strict
  3981. * equality comparisons, else `false`.
  3982. */
  3983. function isStrictComparable(value) {
  3984. return value === value && !isObject(value);
  3985. }
  3986. /**
  3987. * Merges the function metadata of `source` into `data`.
  3988. *
  3989. * Merging metadata reduces the number of wrappers required to invoke a function.
  3990. * This is possible because methods like `_.bind`, `_.curry`, and `_.partial`
  3991. * may be applied regardless of execution order. Methods like `_.ary` and `_.rearg`
  3992. * augment function arguments, making the order in which they are executed important,
  3993. * preventing the merging of metadata. However, we make an exception for a safe
  3994. * common case where curried functions have `_.ary` and or `_.rearg` applied.
  3995. *
  3996. * @private
  3997. * @param {Array} data The destination metadata.
  3998. * @param {Array} source The source metadata.
  3999. * @returns {Array} Returns `data`.
  4000. */
  4001. function mergeData(data, source) {
  4002. var bitmask = data[1],
  4003. srcBitmask = source[1],
  4004. newBitmask = bitmask | srcBitmask,
  4005. isCommon = newBitmask < ARY_FLAG;
  4006. var isCombo =
  4007. (srcBitmask == ARY_FLAG && bitmask == CURRY_FLAG) ||
  4008. (srcBitmask == ARY_FLAG && bitmask == REARG_FLAG && data[7].length <= source[8]) ||
  4009. (srcBitmask == (ARY_FLAG | REARG_FLAG) && bitmask == CURRY_FLAG);
  4010. // Exit early if metadata can't be merged.
  4011. if (!(isCommon || isCombo)) {
  4012. return data;
  4013. }
  4014. // Use source `thisArg` if available.
  4015. if (srcBitmask & BIND_FLAG) {
  4016. data[2] = source[2];
  4017. // Set when currying a bound function.
  4018. newBitmask |= (bitmask & BIND_FLAG) ? 0 : CURRY_BOUND_FLAG;
  4019. }
  4020. // Compose partial arguments.
  4021. var value = source[3];
  4022. if (value) {
  4023. var partials = data[3];
  4024. data[3] = partials ? composeArgs(partials, value, source[4]) : arrayCopy(value);
  4025. data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : arrayCopy(source[4]);
  4026. }
  4027. // Compose partial right arguments.
  4028. value = source[5];
  4029. if (value) {
  4030. partials = data[5];
  4031. data[5] = partials ? composeArgsRight(partials, value, source[6]) : arrayCopy(value);
  4032. data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : arrayCopy(source[6]);
  4033. }
  4034. // Use source `argPos` if available.
  4035. value = source[7];
  4036. if (value) {
  4037. data[7] = arrayCopy(value);
  4038. }
  4039. // Use source `ary` if it's smaller.
  4040. if (srcBitmask & ARY_FLAG) {
  4041. data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]);
  4042. }
  4043. // Use source `arity` if one is not provided.
  4044. if (data[9] == null) {
  4045. data[9] = source[9];
  4046. }
  4047. // Use source `func` and merge bitmasks.
  4048. data[0] = source[0];
  4049. data[1] = newBitmask;
  4050. return data;
  4051. }
  4052. /**
  4053. * Used by `_.defaultsDeep` to customize its `_.merge` use.
  4054. *
  4055. * @private
  4056. * @param {*} objectValue The destination object property value.
  4057. * @param {*} sourceValue The source object property value.
  4058. * @returns {*} Returns the value to assign to the destination object.
  4059. */
  4060. function mergeDefaults(objectValue, sourceValue) {
  4061. return objectValue === undefined ? sourceValue : merge(objectValue, sourceValue, mergeDefaults);
  4062. }
  4063. /**
  4064. * A specialized version of `_.pick` which picks `object` properties specified
  4065. * by `props`.
  4066. *
  4067. * @private
  4068. * @param {Object} object The source object.
  4069. * @param {string[]} props The property names to pick.
  4070. * @returns {Object} Returns the new object.
  4071. */
  4072. function pickByArray(object, props) {
  4073. object = toObject(object);
  4074. var index = -1,
  4075. length = props.length,
  4076. result = {};
  4077. while (++index < length) {
  4078. var key = props[index];
  4079. if (key in object) {
  4080. result[key] = object[key];
  4081. }
  4082. }
  4083. return result;
  4084. }
  4085. /**
  4086. * A specialized version of `_.pick` which picks `object` properties `predicate`
  4087. * returns truthy for.
  4088. *
  4089. * @private
  4090. * @param {Object} object The source object.
  4091. * @param {Function} predicate The function invoked per iteration.
  4092. * @returns {Object} Returns the new object.
  4093. */
  4094. function pickByCallback(object, predicate) {
  4095. var result = {};
  4096. baseForIn(object, function(value, key, object) {
  4097. if (predicate(value, key, object)) {
  4098. result[key] = value;
  4099. }
  4100. });
  4101. return result;
  4102. }
  4103. /**
  4104. * Reorder `array` according to the specified indexes where the element at
  4105. * the first index is assigned as the first element, the element at
  4106. * the second index is assigned as the second element, and so on.
  4107. *
  4108. * @private
  4109. * @param {Array} array The array to reorder.
  4110. * @param {Array} indexes The arranged array indexes.
  4111. * @returns {Array} Returns `array`.
  4112. */
  4113. function reorder(array, indexes) {
  4114. var arrLength = array.length,
  4115. length = nativeMin(indexes.length, arrLength),
  4116. oldArray = arrayCopy(array);
  4117. while (length--) {
  4118. var index = indexes[length];
  4119. array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined;
  4120. }
  4121. return array;
  4122. }
  4123. /**
  4124. * Sets metadata for `func`.
  4125. *
  4126. * **Note:** If this function becomes hot, i.e. is invoked a lot in a short
  4127. * period of time, it will trip its breaker and transition to an identity function
  4128. * to avoid garbage collection pauses in V8. See [V8 issue 2070](https://code.google.com/p/v8/issues/detail?id=2070)
  4129. * for more details.
  4130. *
  4131. * @private
  4132. * @param {Function} func The function to associate metadata with.
  4133. * @param {*} data The metadata.
  4134. * @returns {Function} Returns `func`.
  4135. */
  4136. var setData = (function() {
  4137. var count = 0,
  4138. lastCalled = 0;
  4139. return function(key, value) {
  4140. var stamp = now(),
  4141. remaining = HOT_SPAN - (stamp - lastCalled);
  4142. lastCalled = stamp;
  4143. if (remaining > 0) {
  4144. if (++count >= HOT_COUNT) {
  4145. return key;
  4146. }
  4147. } else {
  4148. count = 0;
  4149. }
  4150. return baseSetData(key, value);
  4151. };
  4152. }());
  4153. /**
  4154. * A fallback implementation of `Object.keys` which creates an array of the
  4155. * own enumerable property names of `object`.
  4156. *
  4157. * @private
  4158. * @param {Object} object The object to query.
  4159. * @returns {Array} Returns the array of property names.
  4160. */
  4161. function shimKeys(object) {
  4162. var props = keysIn(object),
  4163. propsLength = props.length,
  4164. length = propsLength && object.length;
  4165. var allowIndexes = !!length && isLength(length) &&
  4166. (isArray(object) || isArguments(object) || isString(object));
  4167. var index = -1,
  4168. result = [];
  4169. while (++index < propsLength) {
  4170. var key = props[index];
  4171. if ((allowIndexes && isIndex(key, length)) || hasOwnProperty.call(object, key)) {
  4172. result.push(key);
  4173. }
  4174. }
  4175. return result;
  4176. }
  4177. /**
  4178. * Converts `value` to an array-like object if it's not one.
  4179. *
  4180. * @private
  4181. * @param {*} value The value to process.
  4182. * @returns {Array|Object} Returns the array-like object.
  4183. */
  4184. function toIterable(value) {
  4185. if (value == null) {
  4186. return [];
  4187. }
  4188. if (!isArrayLike(value)) {
  4189. return values(value);
  4190. }
  4191. if (lodash.support.unindexedChars && isString(value)) {
  4192. return value.split('');
  4193. }
  4194. return isObject(value) ? value : Object(value);
  4195. }
  4196. /**
  4197. * Converts `value` to an object if it's not one.
  4198. *
  4199. * @private
  4200. * @param {*} value The value to process.
  4201. * @returns {Object} Returns the object.
  4202. */
  4203. function toObject(value) {
  4204. if (lodash.support.unindexedChars && isString(value)) {
  4205. var index = -1,
  4206. length = value.length,
  4207. result = Object(value);
  4208. while (++index < length) {
  4209. result[index] = value.charAt(index);
  4210. }
  4211. return result;
  4212. }
  4213. return isObject(value) ? value : Object(value);
  4214. }
  4215. /**
  4216. * Converts `value` to property path array if it's not one.
  4217. *
  4218. * @private
  4219. * @param {*} value The value to process.
  4220. * @returns {Array} Returns the property path array.
  4221. */
  4222. function toPath(value) {
  4223. if (isArray(value)) {
  4224. return value;
  4225. }
  4226. var result = [];
  4227. baseToString(value).replace(rePropName, function(match, number, quote, string) {
  4228. result.push(quote ? string.replace(reEscapeChar, '$1') : (number || match));
  4229. });
  4230. return result;
  4231. }
  4232. /**
  4233. * Creates a clone of `wrapper`.
  4234. *
  4235. * @private
  4236. * @param {Object} wrapper The wrapper to clone.
  4237. * @returns {Object} Returns the cloned wrapper.
  4238. */
  4239. function wrapperClone(wrapper) {
  4240. return wrapper instanceof LazyWrapper
  4241. ? wrapper.clone()
  4242. : new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__, arrayCopy(wrapper.__actions__));
  4243. }
  4244. /*------------------------------------------------------------------------*/
  4245. /**
  4246. * Creates an array of elements split into groups the length of `size`.
  4247. * If `collection` can't be split evenly, the final chunk will be the remaining
  4248. * elements.
  4249. *
  4250. * @static
  4251. * @memberOf _
  4252. * @category Array
  4253. * @param {Array} array The array to process.
  4254. * @param {number} [size=1] The length of each chunk.
  4255. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4256. * @returns {Array} Returns the new array containing chunks.
  4257. * @example
  4258. *
  4259. * _.chunk(['a', 'b', 'c', 'd'], 2);
  4260. * // => [['a', 'b'], ['c', 'd']]
  4261. *
  4262. * _.chunk(['a', 'b', 'c', 'd'], 3);
  4263. * // => [['a', 'b', 'c'], ['d']]
  4264. */
  4265. function chunk(array, size, guard) {
  4266. if (guard ? isIterateeCall(array, size, guard) : size == null) {
  4267. size = 1;
  4268. } else {
  4269. size = nativeMax(nativeFloor(size) || 1, 1);
  4270. }
  4271. var index = 0,
  4272. length = array ? array.length : 0,
  4273. resIndex = -1,
  4274. result = Array(nativeCeil(length / size));
  4275. while (index < length) {
  4276. result[++resIndex] = baseSlice(array, index, (index += size));
  4277. }
  4278. return result;
  4279. }
  4280. /**
  4281. * Creates an array with all falsey values removed. The values `false`, `null`,
  4282. * `0`, `""`, `undefined`, and `NaN` are falsey.
  4283. *
  4284. * @static
  4285. * @memberOf _
  4286. * @category Array
  4287. * @param {Array} array The array to compact.
  4288. * @returns {Array} Returns the new array of filtered values.
  4289. * @example
  4290. *
  4291. * _.compact([0, 1, false, 2, '', 3]);
  4292. * // => [1, 2, 3]
  4293. */
  4294. function compact(array) {
  4295. var index = -1,
  4296. length = array ? array.length : 0,
  4297. resIndex = -1,
  4298. result = [];
  4299. while (++index < length) {
  4300. var value = array[index];
  4301. if (value) {
  4302. result[++resIndex] = value;
  4303. }
  4304. }
  4305. return result;
  4306. }
  4307. /**
  4308. * Creates an array of unique `array` values not included in the other
  4309. * provided arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  4310. * for equality comparisons.
  4311. *
  4312. * @static
  4313. * @memberOf _
  4314. * @category Array
  4315. * @param {Array} array The array to inspect.
  4316. * @param {...Array} [values] The arrays of values to exclude.
  4317. * @returns {Array} Returns the new array of filtered values.
  4318. * @example
  4319. *
  4320. * _.difference([1, 2, 3], [4, 2]);
  4321. * // => [1, 3]
  4322. */
  4323. var difference = restParam(function(array, values) {
  4324. return (isObjectLike(array) && isArrayLike(array))
  4325. ? baseDifference(array, baseFlatten(values, false, true))
  4326. : [];
  4327. });
  4328. /**
  4329. * Creates a slice of `array` with `n` elements dropped from the beginning.
  4330. *
  4331. * @static
  4332. * @memberOf _
  4333. * @category Array
  4334. * @param {Array} array The array to query.
  4335. * @param {number} [n=1] The number of elements to drop.
  4336. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4337. * @returns {Array} Returns the slice of `array`.
  4338. * @example
  4339. *
  4340. * _.drop([1, 2, 3]);
  4341. * // => [2, 3]
  4342. *
  4343. * _.drop([1, 2, 3], 2);
  4344. * // => [3]
  4345. *
  4346. * _.drop([1, 2, 3], 5);
  4347. * // => []
  4348. *
  4349. * _.drop([1, 2, 3], 0);
  4350. * // => [1, 2, 3]
  4351. */
  4352. function drop(array, n, guard) {
  4353. var length = array ? array.length : 0;
  4354. if (!length) {
  4355. return [];
  4356. }
  4357. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  4358. n = 1;
  4359. }
  4360. return baseSlice(array, n < 0 ? 0 : n);
  4361. }
  4362. /**
  4363. * Creates a slice of `array` with `n` elements dropped from the end.
  4364. *
  4365. * @static
  4366. * @memberOf _
  4367. * @category Array
  4368. * @param {Array} array The array to query.
  4369. * @param {number} [n=1] The number of elements to drop.
  4370. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4371. * @returns {Array} Returns the slice of `array`.
  4372. * @example
  4373. *
  4374. * _.dropRight([1, 2, 3]);
  4375. * // => [1, 2]
  4376. *
  4377. * _.dropRight([1, 2, 3], 2);
  4378. * // => [1]
  4379. *
  4380. * _.dropRight([1, 2, 3], 5);
  4381. * // => []
  4382. *
  4383. * _.dropRight([1, 2, 3], 0);
  4384. * // => [1, 2, 3]
  4385. */
  4386. function dropRight(array, n, guard) {
  4387. var length = array ? array.length : 0;
  4388. if (!length) {
  4389. return [];
  4390. }
  4391. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  4392. n = 1;
  4393. }
  4394. n = length - (+n || 0);
  4395. return baseSlice(array, 0, n < 0 ? 0 : n);
  4396. }
  4397. /**
  4398. * Creates a slice of `array` excluding elements dropped from the end.
  4399. * Elements are dropped until `predicate` returns falsey. The predicate is
  4400. * bound to `thisArg` and invoked with three arguments: (value, index, array).
  4401. *
  4402. * If a property name is provided for `predicate` the created `_.property`
  4403. * style callback returns the property value of the given element.
  4404. *
  4405. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4406. * style callback returns `true` for elements that have a matching property
  4407. * value, else `false`.
  4408. *
  4409. * If an object is provided for `predicate` the created `_.matches` style
  4410. * callback returns `true` for elements that match the properties of the given
  4411. * object, else `false`.
  4412. *
  4413. * @static
  4414. * @memberOf _
  4415. * @category Array
  4416. * @param {Array} array The array to query.
  4417. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4418. * per iteration.
  4419. * @param {*} [thisArg] The `this` binding of `predicate`.
  4420. * @returns {Array} Returns the slice of `array`.
  4421. * @example
  4422. *
  4423. * _.dropRightWhile([1, 2, 3], function(n) {
  4424. * return n > 1;
  4425. * });
  4426. * // => [1]
  4427. *
  4428. * var users = [
  4429. * { 'user': 'barney', 'active': true },
  4430. * { 'user': 'fred', 'active': false },
  4431. * { 'user': 'pebbles', 'active': false }
  4432. * ];
  4433. *
  4434. * // using the `_.matches` callback shorthand
  4435. * _.pluck(_.dropRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
  4436. * // => ['barney', 'fred']
  4437. *
  4438. * // using the `_.matchesProperty` callback shorthand
  4439. * _.pluck(_.dropRightWhile(users, 'active', false), 'user');
  4440. * // => ['barney']
  4441. *
  4442. * // using the `_.property` callback shorthand
  4443. * _.pluck(_.dropRightWhile(users, 'active'), 'user');
  4444. * // => ['barney', 'fred', 'pebbles']
  4445. */
  4446. function dropRightWhile(array, predicate, thisArg) {
  4447. return (array && array.length)
  4448. ? baseWhile(array, getCallback(predicate, thisArg, 3), true, true)
  4449. : [];
  4450. }
  4451. /**
  4452. * Creates a slice of `array` excluding elements dropped from the beginning.
  4453. * Elements are dropped until `predicate` returns falsey. The predicate is
  4454. * bound to `thisArg` and invoked with three arguments: (value, index, array).
  4455. *
  4456. * If a property name is provided for `predicate` the created `_.property`
  4457. * style callback returns the property value of the given element.
  4458. *
  4459. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4460. * style callback returns `true` for elements that have a matching property
  4461. * value, else `false`.
  4462. *
  4463. * If an object is provided for `predicate` the created `_.matches` style
  4464. * callback returns `true` for elements that have the properties of the given
  4465. * object, else `false`.
  4466. *
  4467. * @static
  4468. * @memberOf _
  4469. * @category Array
  4470. * @param {Array} array The array to query.
  4471. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4472. * per iteration.
  4473. * @param {*} [thisArg] The `this` binding of `predicate`.
  4474. * @returns {Array} Returns the slice of `array`.
  4475. * @example
  4476. *
  4477. * _.dropWhile([1, 2, 3], function(n) {
  4478. * return n < 3;
  4479. * });
  4480. * // => [3]
  4481. *
  4482. * var users = [
  4483. * { 'user': 'barney', 'active': false },
  4484. * { 'user': 'fred', 'active': false },
  4485. * { 'user': 'pebbles', 'active': true }
  4486. * ];
  4487. *
  4488. * // using the `_.matches` callback shorthand
  4489. * _.pluck(_.dropWhile(users, { 'user': 'barney', 'active': false }), 'user');
  4490. * // => ['fred', 'pebbles']
  4491. *
  4492. * // using the `_.matchesProperty` callback shorthand
  4493. * _.pluck(_.dropWhile(users, 'active', false), 'user');
  4494. * // => ['pebbles']
  4495. *
  4496. * // using the `_.property` callback shorthand
  4497. * _.pluck(_.dropWhile(users, 'active'), 'user');
  4498. * // => ['barney', 'fred', 'pebbles']
  4499. */
  4500. function dropWhile(array, predicate, thisArg) {
  4501. return (array && array.length)
  4502. ? baseWhile(array, getCallback(predicate, thisArg, 3), true)
  4503. : [];
  4504. }
  4505. /**
  4506. * Fills elements of `array` with `value` from `start` up to, but not
  4507. * including, `end`.
  4508. *
  4509. * **Note:** This method mutates `array`.
  4510. *
  4511. * @static
  4512. * @memberOf _
  4513. * @category Array
  4514. * @param {Array} array The array to fill.
  4515. * @param {*} value The value to fill `array` with.
  4516. * @param {number} [start=0] The start position.
  4517. * @param {number} [end=array.length] The end position.
  4518. * @returns {Array} Returns `array`.
  4519. * @example
  4520. *
  4521. * var array = [1, 2, 3];
  4522. *
  4523. * _.fill(array, 'a');
  4524. * console.log(array);
  4525. * // => ['a', 'a', 'a']
  4526. *
  4527. * _.fill(Array(3), 2);
  4528. * // => [2, 2, 2]
  4529. *
  4530. * _.fill([4, 6, 8], '*', 1, 2);
  4531. * // => [4, '*', 8]
  4532. */
  4533. function fill(array, value, start, end) {
  4534. var length = array ? array.length : 0;
  4535. if (!length) {
  4536. return [];
  4537. }
  4538. if (start && typeof start != 'number' && isIterateeCall(array, value, start)) {
  4539. start = 0;
  4540. end = length;
  4541. }
  4542. return baseFill(array, value, start, end);
  4543. }
  4544. /**
  4545. * This method is like `_.find` except that it returns the index of the first
  4546. * element `predicate` returns truthy for instead of the element itself.
  4547. *
  4548. * If a property name is provided for `predicate` the created `_.property`
  4549. * style callback returns the property value of the given element.
  4550. *
  4551. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4552. * style callback returns `true` for elements that have a matching property
  4553. * value, else `false`.
  4554. *
  4555. * If an object is provided for `predicate` the created `_.matches` style
  4556. * callback returns `true` for elements that have the properties of the given
  4557. * object, else `false`.
  4558. *
  4559. * @static
  4560. * @memberOf _
  4561. * @category Array
  4562. * @param {Array} array The array to search.
  4563. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4564. * per iteration.
  4565. * @param {*} [thisArg] The `this` binding of `predicate`.
  4566. * @returns {number} Returns the index of the found element, else `-1`.
  4567. * @example
  4568. *
  4569. * var users = [
  4570. * { 'user': 'barney', 'active': false },
  4571. * { 'user': 'fred', 'active': false },
  4572. * { 'user': 'pebbles', 'active': true }
  4573. * ];
  4574. *
  4575. * _.findIndex(users, function(chr) {
  4576. * return chr.user == 'barney';
  4577. * });
  4578. * // => 0
  4579. *
  4580. * // using the `_.matches` callback shorthand
  4581. * _.findIndex(users, { 'user': 'fred', 'active': false });
  4582. * // => 1
  4583. *
  4584. * // using the `_.matchesProperty` callback shorthand
  4585. * _.findIndex(users, 'active', false);
  4586. * // => 0
  4587. *
  4588. * // using the `_.property` callback shorthand
  4589. * _.findIndex(users, 'active');
  4590. * // => 2
  4591. */
  4592. var findIndex = createFindIndex();
  4593. /**
  4594. * This method is like `_.findIndex` except that it iterates over elements
  4595. * of `collection` from right to left.
  4596. *
  4597. * If a property name is provided for `predicate` the created `_.property`
  4598. * style callback returns the property value of the given element.
  4599. *
  4600. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4601. * style callback returns `true` for elements that have a matching property
  4602. * value, else `false`.
  4603. *
  4604. * If an object is provided for `predicate` the created `_.matches` style
  4605. * callback returns `true` for elements that have the properties of the given
  4606. * object, else `false`.
  4607. *
  4608. * @static
  4609. * @memberOf _
  4610. * @category Array
  4611. * @param {Array} array The array to search.
  4612. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4613. * per iteration.
  4614. * @param {*} [thisArg] The `this` binding of `predicate`.
  4615. * @returns {number} Returns the index of the found element, else `-1`.
  4616. * @example
  4617. *
  4618. * var users = [
  4619. * { 'user': 'barney', 'active': true },
  4620. * { 'user': 'fred', 'active': false },
  4621. * { 'user': 'pebbles', 'active': false }
  4622. * ];
  4623. *
  4624. * _.findLastIndex(users, function(chr) {
  4625. * return chr.user == 'pebbles';
  4626. * });
  4627. * // => 2
  4628. *
  4629. * // using the `_.matches` callback shorthand
  4630. * _.findLastIndex(users, { 'user': 'barney', 'active': true });
  4631. * // => 0
  4632. *
  4633. * // using the `_.matchesProperty` callback shorthand
  4634. * _.findLastIndex(users, 'active', false);
  4635. * // => 2
  4636. *
  4637. * // using the `_.property` callback shorthand
  4638. * _.findLastIndex(users, 'active');
  4639. * // => 0
  4640. */
  4641. var findLastIndex = createFindIndex(true);
  4642. /**
  4643. * Gets the first element of `array`.
  4644. *
  4645. * @static
  4646. * @memberOf _
  4647. * @alias head
  4648. * @category Array
  4649. * @param {Array} array The array to query.
  4650. * @returns {*} Returns the first element of `array`.
  4651. * @example
  4652. *
  4653. * _.first([1, 2, 3]);
  4654. * // => 1
  4655. *
  4656. * _.first([]);
  4657. * // => undefined
  4658. */
  4659. function first(array) {
  4660. return array ? array[0] : undefined;
  4661. }
  4662. /**
  4663. * Flattens a nested array. If `isDeep` is `true` the array is recursively
  4664. * flattened, otherwise it's only flattened a single level.
  4665. *
  4666. * @static
  4667. * @memberOf _
  4668. * @category Array
  4669. * @param {Array} array The array to flatten.
  4670. * @param {boolean} [isDeep] Specify a deep flatten.
  4671. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  4672. * @returns {Array} Returns the new flattened array.
  4673. * @example
  4674. *
  4675. * _.flatten([1, [2, 3, [4]]]);
  4676. * // => [1, 2, 3, [4]]
  4677. *
  4678. * // using `isDeep`
  4679. * _.flatten([1, [2, 3, [4]]], true);
  4680. * // => [1, 2, 3, 4]
  4681. */
  4682. function flatten(array, isDeep, guard) {
  4683. var length = array ? array.length : 0;
  4684. if (guard && isIterateeCall(array, isDeep, guard)) {
  4685. isDeep = false;
  4686. }
  4687. return length ? baseFlatten(array, isDeep) : [];
  4688. }
  4689. /**
  4690. * Recursively flattens a nested array.
  4691. *
  4692. * @static
  4693. * @memberOf _
  4694. * @category Array
  4695. * @param {Array} array The array to recursively flatten.
  4696. * @returns {Array} Returns the new flattened array.
  4697. * @example
  4698. *
  4699. * _.flattenDeep([1, [2, 3, [4]]]);
  4700. * // => [1, 2, 3, 4]
  4701. */
  4702. function flattenDeep(array) {
  4703. var length = array ? array.length : 0;
  4704. return length ? baseFlatten(array, true) : [];
  4705. }
  4706. /**
  4707. * Gets the index at which the first occurrence of `value` is found in `array`
  4708. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  4709. * for equality comparisons. If `fromIndex` is negative, it's used as the offset
  4710. * from the end of `array`. If `array` is sorted providing `true` for `fromIndex`
  4711. * performs a faster binary search.
  4712. *
  4713. * @static
  4714. * @memberOf _
  4715. * @category Array
  4716. * @param {Array} array The array to search.
  4717. * @param {*} value The value to search for.
  4718. * @param {boolean|number} [fromIndex=0] The index to search from or `true`
  4719. * to perform a binary search on a sorted array.
  4720. * @returns {number} Returns the index of the matched value, else `-1`.
  4721. * @example
  4722. *
  4723. * _.indexOf([1, 2, 1, 2], 2);
  4724. * // => 1
  4725. *
  4726. * // using `fromIndex`
  4727. * _.indexOf([1, 2, 1, 2], 2, 2);
  4728. * // => 3
  4729. *
  4730. * // performing a binary search
  4731. * _.indexOf([1, 1, 2, 2], 2, true);
  4732. * // => 2
  4733. */
  4734. function indexOf(array, value, fromIndex) {
  4735. var length = array ? array.length : 0;
  4736. if (!length) {
  4737. return -1;
  4738. }
  4739. if (typeof fromIndex == 'number') {
  4740. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : fromIndex;
  4741. } else if (fromIndex) {
  4742. var index = binaryIndex(array, value);
  4743. if (index < length &&
  4744. (value === value ? (value === array[index]) : (array[index] !== array[index]))) {
  4745. return index;
  4746. }
  4747. return -1;
  4748. }
  4749. return baseIndexOf(array, value, fromIndex || 0);
  4750. }
  4751. /**
  4752. * Gets all but the last element of `array`.
  4753. *
  4754. * @static
  4755. * @memberOf _
  4756. * @category Array
  4757. * @param {Array} array The array to query.
  4758. * @returns {Array} Returns the slice of `array`.
  4759. * @example
  4760. *
  4761. * _.initial([1, 2, 3]);
  4762. * // => [1, 2]
  4763. */
  4764. function initial(array) {
  4765. return dropRight(array, 1);
  4766. }
  4767. /**
  4768. * Creates an array of unique values that are included in all of the provided
  4769. * arrays using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  4770. * for equality comparisons.
  4771. *
  4772. * @static
  4773. * @memberOf _
  4774. * @category Array
  4775. * @param {...Array} [arrays] The arrays to inspect.
  4776. * @returns {Array} Returns the new array of shared values.
  4777. * @example
  4778. * _.intersection([1, 2], [4, 2], [2, 1]);
  4779. * // => [2]
  4780. */
  4781. var intersection = restParam(function(arrays) {
  4782. var othLength = arrays.length,
  4783. othIndex = othLength,
  4784. caches = Array(length),
  4785. indexOf = getIndexOf(),
  4786. isCommon = indexOf === baseIndexOf,
  4787. result = [];
  4788. while (othIndex--) {
  4789. var value = arrays[othIndex] = isArrayLike(value = arrays[othIndex]) ? value : [];
  4790. caches[othIndex] = (isCommon && value.length >= 120) ? createCache(othIndex && value) : null;
  4791. }
  4792. var array = arrays[0],
  4793. index = -1,
  4794. length = array ? array.length : 0,
  4795. seen = caches[0];
  4796. outer:
  4797. while (++index < length) {
  4798. value = array[index];
  4799. if ((seen ? cacheIndexOf(seen, value) : indexOf(result, value, 0)) < 0) {
  4800. var othIndex = othLength;
  4801. while (--othIndex) {
  4802. var cache = caches[othIndex];
  4803. if ((cache ? cacheIndexOf(cache, value) : indexOf(arrays[othIndex], value, 0)) < 0) {
  4804. continue outer;
  4805. }
  4806. }
  4807. if (seen) {
  4808. seen.push(value);
  4809. }
  4810. result.push(value);
  4811. }
  4812. }
  4813. return result;
  4814. });
  4815. /**
  4816. * Gets the last element of `array`.
  4817. *
  4818. * @static
  4819. * @memberOf _
  4820. * @category Array
  4821. * @param {Array} array The array to query.
  4822. * @returns {*} Returns the last element of `array`.
  4823. * @example
  4824. *
  4825. * _.last([1, 2, 3]);
  4826. * // => 3
  4827. */
  4828. function last(array) {
  4829. var length = array ? array.length : 0;
  4830. return length ? array[length - 1] : undefined;
  4831. }
  4832. /**
  4833. * This method is like `_.indexOf` except that it iterates over elements of
  4834. * `array` from right to left.
  4835. *
  4836. * @static
  4837. * @memberOf _
  4838. * @category Array
  4839. * @param {Array} array The array to search.
  4840. * @param {*} value The value to search for.
  4841. * @param {boolean|number} [fromIndex=array.length-1] The index to search from
  4842. * or `true` to perform a binary search on a sorted array.
  4843. * @returns {number} Returns the index of the matched value, else `-1`.
  4844. * @example
  4845. *
  4846. * _.lastIndexOf([1, 2, 1, 2], 2);
  4847. * // => 3
  4848. *
  4849. * // using `fromIndex`
  4850. * _.lastIndexOf([1, 2, 1, 2], 2, 2);
  4851. * // => 1
  4852. *
  4853. * // performing a binary search
  4854. * _.lastIndexOf([1, 1, 2, 2], 2, true);
  4855. * // => 3
  4856. */
  4857. function lastIndexOf(array, value, fromIndex) {
  4858. var length = array ? array.length : 0;
  4859. if (!length) {
  4860. return -1;
  4861. }
  4862. var index = length;
  4863. if (typeof fromIndex == 'number') {
  4864. index = (fromIndex < 0 ? nativeMax(length + fromIndex, 0) : nativeMin(fromIndex || 0, length - 1)) + 1;
  4865. } else if (fromIndex) {
  4866. index = binaryIndex(array, value, true) - 1;
  4867. var other = array[index];
  4868. if (value === value ? (value === other) : (other !== other)) {
  4869. return index;
  4870. }
  4871. return -1;
  4872. }
  4873. if (value !== value) {
  4874. return indexOfNaN(array, index, true);
  4875. }
  4876. while (index--) {
  4877. if (array[index] === value) {
  4878. return index;
  4879. }
  4880. }
  4881. return -1;
  4882. }
  4883. /**
  4884. * Removes all provided values from `array` using
  4885. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  4886. * for equality comparisons.
  4887. *
  4888. * **Note:** Unlike `_.without`, this method mutates `array`.
  4889. *
  4890. * @static
  4891. * @memberOf _
  4892. * @category Array
  4893. * @param {Array} array The array to modify.
  4894. * @param {...*} [values] The values to remove.
  4895. * @returns {Array} Returns `array`.
  4896. * @example
  4897. *
  4898. * var array = [1, 2, 3, 1, 2, 3];
  4899. *
  4900. * _.pull(array, 2, 3);
  4901. * console.log(array);
  4902. * // => [1, 1]
  4903. */
  4904. function pull() {
  4905. var args = arguments,
  4906. array = args[0];
  4907. if (!(array && array.length)) {
  4908. return array;
  4909. }
  4910. var index = 0,
  4911. indexOf = getIndexOf(),
  4912. length = args.length;
  4913. while (++index < length) {
  4914. var fromIndex = 0,
  4915. value = args[index];
  4916. while ((fromIndex = indexOf(array, value, fromIndex)) > -1) {
  4917. splice.call(array, fromIndex, 1);
  4918. }
  4919. }
  4920. return array;
  4921. }
  4922. /**
  4923. * Removes elements from `array` corresponding to the given indexes and returns
  4924. * an array of the removed elements. Indexes may be specified as an array of
  4925. * indexes or as individual arguments.
  4926. *
  4927. * **Note:** Unlike `_.at`, this method mutates `array`.
  4928. *
  4929. * @static
  4930. * @memberOf _
  4931. * @category Array
  4932. * @param {Array} array The array to modify.
  4933. * @param {...(number|number[])} [indexes] The indexes of elements to remove,
  4934. * specified as individual indexes or arrays of indexes.
  4935. * @returns {Array} Returns the new array of removed elements.
  4936. * @example
  4937. *
  4938. * var array = [5, 10, 15, 20];
  4939. * var evens = _.pullAt(array, 1, 3);
  4940. *
  4941. * console.log(array);
  4942. * // => [5, 15]
  4943. *
  4944. * console.log(evens);
  4945. * // => [10, 20]
  4946. */
  4947. var pullAt = restParam(function(array, indexes) {
  4948. indexes = baseFlatten(indexes);
  4949. var result = baseAt(array, indexes);
  4950. basePullAt(array, indexes.sort(baseCompareAscending));
  4951. return result;
  4952. });
  4953. /**
  4954. * Removes all elements from `array` that `predicate` returns truthy for
  4955. * and returns an array of the removed elements. The predicate is bound to
  4956. * `thisArg` and invoked with three arguments: (value, index, array).
  4957. *
  4958. * If a property name is provided for `predicate` the created `_.property`
  4959. * style callback returns the property value of the given element.
  4960. *
  4961. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  4962. * style callback returns `true` for elements that have a matching property
  4963. * value, else `false`.
  4964. *
  4965. * If an object is provided for `predicate` the created `_.matches` style
  4966. * callback returns `true` for elements that have the properties of the given
  4967. * object, else `false`.
  4968. *
  4969. * **Note:** Unlike `_.filter`, this method mutates `array`.
  4970. *
  4971. * @static
  4972. * @memberOf _
  4973. * @category Array
  4974. * @param {Array} array The array to modify.
  4975. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  4976. * per iteration.
  4977. * @param {*} [thisArg] The `this` binding of `predicate`.
  4978. * @returns {Array} Returns the new array of removed elements.
  4979. * @example
  4980. *
  4981. * var array = [1, 2, 3, 4];
  4982. * var evens = _.remove(array, function(n) {
  4983. * return n % 2 == 0;
  4984. * });
  4985. *
  4986. * console.log(array);
  4987. * // => [1, 3]
  4988. *
  4989. * console.log(evens);
  4990. * // => [2, 4]
  4991. */
  4992. function remove(array, predicate, thisArg) {
  4993. var result = [];
  4994. if (!(array && array.length)) {
  4995. return result;
  4996. }
  4997. var index = -1,
  4998. indexes = [],
  4999. length = array.length;
  5000. predicate = getCallback(predicate, thisArg, 3);
  5001. while (++index < length) {
  5002. var value = array[index];
  5003. if (predicate(value, index, array)) {
  5004. result.push(value);
  5005. indexes.push(index);
  5006. }
  5007. }
  5008. basePullAt(array, indexes);
  5009. return result;
  5010. }
  5011. /**
  5012. * Gets all but the first element of `array`.
  5013. *
  5014. * @static
  5015. * @memberOf _
  5016. * @alias tail
  5017. * @category Array
  5018. * @param {Array} array The array to query.
  5019. * @returns {Array} Returns the slice of `array`.
  5020. * @example
  5021. *
  5022. * _.rest([1, 2, 3]);
  5023. * // => [2, 3]
  5024. */
  5025. function rest(array) {
  5026. return drop(array, 1);
  5027. }
  5028. /**
  5029. * Creates a slice of `array` from `start` up to, but not including, `end`.
  5030. *
  5031. * **Note:** This method is used instead of `Array#slice` to support node
  5032. * lists in IE < 9 and to ensure dense arrays are returned.
  5033. *
  5034. * @static
  5035. * @memberOf _
  5036. * @category Array
  5037. * @param {Array} array The array to slice.
  5038. * @param {number} [start=0] The start position.
  5039. * @param {number} [end=array.length] The end position.
  5040. * @returns {Array} Returns the slice of `array`.
  5041. */
  5042. function slice(array, start, end) {
  5043. var length = array ? array.length : 0;
  5044. if (!length) {
  5045. return [];
  5046. }
  5047. if (end && typeof end != 'number' && isIterateeCall(array, start, end)) {
  5048. start = 0;
  5049. end = length;
  5050. }
  5051. return baseSlice(array, start, end);
  5052. }
  5053. /**
  5054. * Uses a binary search to determine the lowest index at which `value` should
  5055. * be inserted into `array` in order to maintain its sort order. If an iteratee
  5056. * function is provided it's invoked for `value` and each element of `array`
  5057. * to compute their sort ranking. The iteratee is bound to `thisArg` and
  5058. * invoked with one argument; (value).
  5059. *
  5060. * If a property name is provided for `iteratee` the created `_.property`
  5061. * style callback returns the property value of the given element.
  5062. *
  5063. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5064. * style callback returns `true` for elements that have a matching property
  5065. * value, else `false`.
  5066. *
  5067. * If an object is provided for `iteratee` the created `_.matches` style
  5068. * callback returns `true` for elements that have the properties of the given
  5069. * object, else `false`.
  5070. *
  5071. * @static
  5072. * @memberOf _
  5073. * @category Array
  5074. * @param {Array} array The sorted array to inspect.
  5075. * @param {*} value The value to evaluate.
  5076. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5077. * per iteration.
  5078. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5079. * @returns {number} Returns the index at which `value` should be inserted
  5080. * into `array`.
  5081. * @example
  5082. *
  5083. * _.sortedIndex([30, 50], 40);
  5084. * // => 1
  5085. *
  5086. * _.sortedIndex([4, 4, 5, 5], 5);
  5087. * // => 2
  5088. *
  5089. * var dict = { 'data': { 'thirty': 30, 'forty': 40, 'fifty': 50 } };
  5090. *
  5091. * // using an iteratee function
  5092. * _.sortedIndex(['thirty', 'fifty'], 'forty', function(word) {
  5093. * return this.data[word];
  5094. * }, dict);
  5095. * // => 1
  5096. *
  5097. * // using the `_.property` callback shorthand
  5098. * _.sortedIndex([{ 'x': 30 }, { 'x': 50 }], { 'x': 40 }, 'x');
  5099. * // => 1
  5100. */
  5101. var sortedIndex = createSortedIndex();
  5102. /**
  5103. * This method is like `_.sortedIndex` except that it returns the highest
  5104. * index at which `value` should be inserted into `array` in order to
  5105. * maintain its sort order.
  5106. *
  5107. * @static
  5108. * @memberOf _
  5109. * @category Array
  5110. * @param {Array} array The sorted array to inspect.
  5111. * @param {*} value The value to evaluate.
  5112. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5113. * per iteration.
  5114. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5115. * @returns {number} Returns the index at which `value` should be inserted
  5116. * into `array`.
  5117. * @example
  5118. *
  5119. * _.sortedLastIndex([4, 4, 5, 5], 5);
  5120. * // => 4
  5121. */
  5122. var sortedLastIndex = createSortedIndex(true);
  5123. /**
  5124. * Creates a slice of `array` with `n` elements taken from the beginning.
  5125. *
  5126. * @static
  5127. * @memberOf _
  5128. * @category Array
  5129. * @param {Array} array The array to query.
  5130. * @param {number} [n=1] The number of elements to take.
  5131. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  5132. * @returns {Array} Returns the slice of `array`.
  5133. * @example
  5134. *
  5135. * _.take([1, 2, 3]);
  5136. * // => [1]
  5137. *
  5138. * _.take([1, 2, 3], 2);
  5139. * // => [1, 2]
  5140. *
  5141. * _.take([1, 2, 3], 5);
  5142. * // => [1, 2, 3]
  5143. *
  5144. * _.take([1, 2, 3], 0);
  5145. * // => []
  5146. */
  5147. function take(array, n, guard) {
  5148. var length = array ? array.length : 0;
  5149. if (!length) {
  5150. return [];
  5151. }
  5152. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  5153. n = 1;
  5154. }
  5155. return baseSlice(array, 0, n < 0 ? 0 : n);
  5156. }
  5157. /**
  5158. * Creates a slice of `array` with `n` elements taken from the end.
  5159. *
  5160. * @static
  5161. * @memberOf _
  5162. * @category Array
  5163. * @param {Array} array The array to query.
  5164. * @param {number} [n=1] The number of elements to take.
  5165. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  5166. * @returns {Array} Returns the slice of `array`.
  5167. * @example
  5168. *
  5169. * _.takeRight([1, 2, 3]);
  5170. * // => [3]
  5171. *
  5172. * _.takeRight([1, 2, 3], 2);
  5173. * // => [2, 3]
  5174. *
  5175. * _.takeRight([1, 2, 3], 5);
  5176. * // => [1, 2, 3]
  5177. *
  5178. * _.takeRight([1, 2, 3], 0);
  5179. * // => []
  5180. */
  5181. function takeRight(array, n, guard) {
  5182. var length = array ? array.length : 0;
  5183. if (!length) {
  5184. return [];
  5185. }
  5186. if (guard ? isIterateeCall(array, n, guard) : n == null) {
  5187. n = 1;
  5188. }
  5189. n = length - (+n || 0);
  5190. return baseSlice(array, n < 0 ? 0 : n);
  5191. }
  5192. /**
  5193. * Creates a slice of `array` with elements taken from the end. Elements are
  5194. * taken until `predicate` returns falsey. The predicate is bound to `thisArg`
  5195. * and invoked with three arguments: (value, index, array).
  5196. *
  5197. * If a property name is provided for `predicate` the created `_.property`
  5198. * style callback returns the property value of the given element.
  5199. *
  5200. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5201. * style callback returns `true` for elements that have a matching property
  5202. * value, else `false`.
  5203. *
  5204. * If an object is provided for `predicate` the created `_.matches` style
  5205. * callback returns `true` for elements that have the properties of the given
  5206. * object, else `false`.
  5207. *
  5208. * @static
  5209. * @memberOf _
  5210. * @category Array
  5211. * @param {Array} array The array to query.
  5212. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5213. * per iteration.
  5214. * @param {*} [thisArg] The `this` binding of `predicate`.
  5215. * @returns {Array} Returns the slice of `array`.
  5216. * @example
  5217. *
  5218. * _.takeRightWhile([1, 2, 3], function(n) {
  5219. * return n > 1;
  5220. * });
  5221. * // => [2, 3]
  5222. *
  5223. * var users = [
  5224. * { 'user': 'barney', 'active': true },
  5225. * { 'user': 'fred', 'active': false },
  5226. * { 'user': 'pebbles', 'active': false }
  5227. * ];
  5228. *
  5229. * // using the `_.matches` callback shorthand
  5230. * _.pluck(_.takeRightWhile(users, { 'user': 'pebbles', 'active': false }), 'user');
  5231. * // => ['pebbles']
  5232. *
  5233. * // using the `_.matchesProperty` callback shorthand
  5234. * _.pluck(_.takeRightWhile(users, 'active', false), 'user');
  5235. * // => ['fred', 'pebbles']
  5236. *
  5237. * // using the `_.property` callback shorthand
  5238. * _.pluck(_.takeRightWhile(users, 'active'), 'user');
  5239. * // => []
  5240. */
  5241. function takeRightWhile(array, predicate, thisArg) {
  5242. return (array && array.length)
  5243. ? baseWhile(array, getCallback(predicate, thisArg, 3), false, true)
  5244. : [];
  5245. }
  5246. /**
  5247. * Creates a slice of `array` with elements taken from the beginning. Elements
  5248. * are taken until `predicate` returns falsey. The predicate is bound to
  5249. * `thisArg` and invoked with three arguments: (value, index, array).
  5250. *
  5251. * If a property name is provided for `predicate` the created `_.property`
  5252. * style callback returns the property value of the given element.
  5253. *
  5254. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5255. * style callback returns `true` for elements that have a matching property
  5256. * value, else `false`.
  5257. *
  5258. * If an object is provided for `predicate` the created `_.matches` style
  5259. * callback returns `true` for elements that have the properties of the given
  5260. * object, else `false`.
  5261. *
  5262. * @static
  5263. * @memberOf _
  5264. * @category Array
  5265. * @param {Array} array The array to query.
  5266. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5267. * per iteration.
  5268. * @param {*} [thisArg] The `this` binding of `predicate`.
  5269. * @returns {Array} Returns the slice of `array`.
  5270. * @example
  5271. *
  5272. * _.takeWhile([1, 2, 3], function(n) {
  5273. * return n < 3;
  5274. * });
  5275. * // => [1, 2]
  5276. *
  5277. * var users = [
  5278. * { 'user': 'barney', 'active': false },
  5279. * { 'user': 'fred', 'active': false},
  5280. * { 'user': 'pebbles', 'active': true }
  5281. * ];
  5282. *
  5283. * // using the `_.matches` callback shorthand
  5284. * _.pluck(_.takeWhile(users, { 'user': 'barney', 'active': false }), 'user');
  5285. * // => ['barney']
  5286. *
  5287. * // using the `_.matchesProperty` callback shorthand
  5288. * _.pluck(_.takeWhile(users, 'active', false), 'user');
  5289. * // => ['barney', 'fred']
  5290. *
  5291. * // using the `_.property` callback shorthand
  5292. * _.pluck(_.takeWhile(users, 'active'), 'user');
  5293. * // => []
  5294. */
  5295. function takeWhile(array, predicate, thisArg) {
  5296. return (array && array.length)
  5297. ? baseWhile(array, getCallback(predicate, thisArg, 3))
  5298. : [];
  5299. }
  5300. /**
  5301. * Creates an array of unique values, in order, from all of the provided arrays
  5302. * using [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  5303. * for equality comparisons.
  5304. *
  5305. * @static
  5306. * @memberOf _
  5307. * @category Array
  5308. * @param {...Array} [arrays] The arrays to inspect.
  5309. * @returns {Array} Returns the new array of combined values.
  5310. * @example
  5311. *
  5312. * _.union([1, 2], [4, 2], [2, 1]);
  5313. * // => [1, 2, 4]
  5314. */
  5315. var union = restParam(function(arrays) {
  5316. return baseUniq(baseFlatten(arrays, false, true));
  5317. });
  5318. /**
  5319. * Creates a duplicate-free version of an array, using
  5320. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  5321. * for equality comparisons, in which only the first occurence of each element
  5322. * is kept. Providing `true` for `isSorted` performs a faster search algorithm
  5323. * for sorted arrays. If an iteratee function is provided it's invoked for
  5324. * each element in the array to generate the criterion by which uniqueness
  5325. * is computed. The `iteratee` is bound to `thisArg` and invoked with three
  5326. * arguments: (value, index, array).
  5327. *
  5328. * If a property name is provided for `iteratee` the created `_.property`
  5329. * style callback returns the property value of the given element.
  5330. *
  5331. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5332. * style callback returns `true` for elements that have a matching property
  5333. * value, else `false`.
  5334. *
  5335. * If an object is provided for `iteratee` the created `_.matches` style
  5336. * callback returns `true` for elements that have the properties of the given
  5337. * object, else `false`.
  5338. *
  5339. * @static
  5340. * @memberOf _
  5341. * @alias unique
  5342. * @category Array
  5343. * @param {Array} array The array to inspect.
  5344. * @param {boolean} [isSorted] Specify the array is sorted.
  5345. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  5346. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5347. * @returns {Array} Returns the new duplicate-value-free array.
  5348. * @example
  5349. *
  5350. * _.uniq([2, 1, 2]);
  5351. * // => [2, 1]
  5352. *
  5353. * // using `isSorted`
  5354. * _.uniq([1, 1, 2], true);
  5355. * // => [1, 2]
  5356. *
  5357. * // using an iteratee function
  5358. * _.uniq([1, 2.5, 1.5, 2], function(n) {
  5359. * return this.floor(n);
  5360. * }, Math);
  5361. * // => [1, 2.5]
  5362. *
  5363. * // using the `_.property` callback shorthand
  5364. * _.uniq([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x');
  5365. * // => [{ 'x': 1 }, { 'x': 2 }]
  5366. */
  5367. function uniq(array, isSorted, iteratee, thisArg) {
  5368. var length = array ? array.length : 0;
  5369. if (!length) {
  5370. return [];
  5371. }
  5372. if (isSorted != null && typeof isSorted != 'boolean') {
  5373. thisArg = iteratee;
  5374. iteratee = isIterateeCall(array, isSorted, thisArg) ? undefined : isSorted;
  5375. isSorted = false;
  5376. }
  5377. var callback = getCallback();
  5378. if (!(iteratee == null && callback === baseCallback)) {
  5379. iteratee = callback(iteratee, thisArg, 3);
  5380. }
  5381. return (isSorted && getIndexOf() === baseIndexOf)
  5382. ? sortedUniq(array, iteratee)
  5383. : baseUniq(array, iteratee);
  5384. }
  5385. /**
  5386. * This method is like `_.zip` except that it accepts an array of grouped
  5387. * elements and creates an array regrouping the elements to their pre-zip
  5388. * configuration.
  5389. *
  5390. * @static
  5391. * @memberOf _
  5392. * @category Array
  5393. * @param {Array} array The array of grouped elements to process.
  5394. * @returns {Array} Returns the new array of regrouped elements.
  5395. * @example
  5396. *
  5397. * var zipped = _.zip(['fred', 'barney'], [30, 40], [true, false]);
  5398. * // => [['fred', 30, true], ['barney', 40, false]]
  5399. *
  5400. * _.unzip(zipped);
  5401. * // => [['fred', 'barney'], [30, 40], [true, false]]
  5402. */
  5403. function unzip(array) {
  5404. if (!(array && array.length)) {
  5405. return [];
  5406. }
  5407. var index = -1,
  5408. length = 0;
  5409. array = arrayFilter(array, function(group) {
  5410. if (isArrayLike(group)) {
  5411. length = nativeMax(group.length, length);
  5412. return true;
  5413. }
  5414. });
  5415. var result = Array(length);
  5416. while (++index < length) {
  5417. result[index] = arrayMap(array, baseProperty(index));
  5418. }
  5419. return result;
  5420. }
  5421. /**
  5422. * This method is like `_.unzip` except that it accepts an iteratee to specify
  5423. * how regrouped values should be combined. The `iteratee` is bound to `thisArg`
  5424. * and invoked with four arguments: (accumulator, value, index, group).
  5425. *
  5426. * @static
  5427. * @memberOf _
  5428. * @category Array
  5429. * @param {Array} array The array of grouped elements to process.
  5430. * @param {Function} [iteratee] The function to combine regrouped values.
  5431. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5432. * @returns {Array} Returns the new array of regrouped elements.
  5433. * @example
  5434. *
  5435. * var zipped = _.zip([1, 2], [10, 20], [100, 200]);
  5436. * // => [[1, 10, 100], [2, 20, 200]]
  5437. *
  5438. * _.unzipWith(zipped, _.add);
  5439. * // => [3, 30, 300]
  5440. */
  5441. function unzipWith(array, iteratee, thisArg) {
  5442. var length = array ? array.length : 0;
  5443. if (!length) {
  5444. return [];
  5445. }
  5446. var result = unzip(array);
  5447. if (iteratee == null) {
  5448. return result;
  5449. }
  5450. iteratee = bindCallback(iteratee, thisArg, 4);
  5451. return arrayMap(result, function(group) {
  5452. return arrayReduce(group, iteratee, undefined, true);
  5453. });
  5454. }
  5455. /**
  5456. * Creates an array excluding all provided values using
  5457. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  5458. * for equality comparisons.
  5459. *
  5460. * @static
  5461. * @memberOf _
  5462. * @category Array
  5463. * @param {Array} array The array to filter.
  5464. * @param {...*} [values] The values to exclude.
  5465. * @returns {Array} Returns the new array of filtered values.
  5466. * @example
  5467. *
  5468. * _.without([1, 2, 1, 3], 1, 2);
  5469. * // => [3]
  5470. */
  5471. var without = restParam(function(array, values) {
  5472. return isArrayLike(array)
  5473. ? baseDifference(array, values)
  5474. : [];
  5475. });
  5476. /**
  5477. * Creates an array of unique values that is the [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference)
  5478. * of the provided arrays.
  5479. *
  5480. * @static
  5481. * @memberOf _
  5482. * @category Array
  5483. * @param {...Array} [arrays] The arrays to inspect.
  5484. * @returns {Array} Returns the new array of values.
  5485. * @example
  5486. *
  5487. * _.xor([1, 2], [4, 2]);
  5488. * // => [1, 4]
  5489. */
  5490. function xor() {
  5491. var index = -1,
  5492. length = arguments.length;
  5493. while (++index < length) {
  5494. var array = arguments[index];
  5495. if (isArrayLike(array)) {
  5496. var result = result
  5497. ? arrayPush(baseDifference(result, array), baseDifference(array, result))
  5498. : array;
  5499. }
  5500. }
  5501. return result ? baseUniq(result) : [];
  5502. }
  5503. /**
  5504. * Creates an array of grouped elements, the first of which contains the first
  5505. * elements of the given arrays, the second of which contains the second elements
  5506. * of the given arrays, and so on.
  5507. *
  5508. * @static
  5509. * @memberOf _
  5510. * @category Array
  5511. * @param {...Array} [arrays] The arrays to process.
  5512. * @returns {Array} Returns the new array of grouped elements.
  5513. * @example
  5514. *
  5515. * _.zip(['fred', 'barney'], [30, 40], [true, false]);
  5516. * // => [['fred', 30, true], ['barney', 40, false]]
  5517. */
  5518. var zip = restParam(unzip);
  5519. /**
  5520. * The inverse of `_.pairs`; this method returns an object composed from arrays
  5521. * of property names and values. Provide either a single two dimensional array,
  5522. * e.g. `[[key1, value1], [key2, value2]]` or two arrays, one of property names
  5523. * and one of corresponding values.
  5524. *
  5525. * @static
  5526. * @memberOf _
  5527. * @alias object
  5528. * @category Array
  5529. * @param {Array} props The property names.
  5530. * @param {Array} [values=[]] The property values.
  5531. * @returns {Object} Returns the new object.
  5532. * @example
  5533. *
  5534. * _.zipObject([['fred', 30], ['barney', 40]]);
  5535. * // => { 'fred': 30, 'barney': 40 }
  5536. *
  5537. * _.zipObject(['fred', 'barney'], [30, 40]);
  5538. * // => { 'fred': 30, 'barney': 40 }
  5539. */
  5540. function zipObject(props, values) {
  5541. var index = -1,
  5542. length = props ? props.length : 0,
  5543. result = {};
  5544. if (length && !values && !isArray(props[0])) {
  5545. values = [];
  5546. }
  5547. while (++index < length) {
  5548. var key = props[index];
  5549. if (values) {
  5550. result[key] = values[index];
  5551. } else if (key) {
  5552. result[key[0]] = key[1];
  5553. }
  5554. }
  5555. return result;
  5556. }
  5557. /**
  5558. * This method is like `_.zip` except that it accepts an iteratee to specify
  5559. * how grouped values should be combined. The `iteratee` is bound to `thisArg`
  5560. * and invoked with four arguments: (accumulator, value, index, group).
  5561. *
  5562. * @static
  5563. * @memberOf _
  5564. * @category Array
  5565. * @param {...Array} [arrays] The arrays to process.
  5566. * @param {Function} [iteratee] The function to combine grouped values.
  5567. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5568. * @returns {Array} Returns the new array of grouped elements.
  5569. * @example
  5570. *
  5571. * _.zipWith([1, 2], [10, 20], [100, 200], _.add);
  5572. * // => [111, 222]
  5573. */
  5574. var zipWith = restParam(function(arrays) {
  5575. var length = arrays.length,
  5576. iteratee = length > 2 ? arrays[length - 2] : undefined,
  5577. thisArg = length > 1 ? arrays[length - 1] : undefined;
  5578. if (length > 2 && typeof iteratee == 'function') {
  5579. length -= 2;
  5580. } else {
  5581. iteratee = (length > 1 && typeof thisArg == 'function') ? (--length, thisArg) : undefined;
  5582. thisArg = undefined;
  5583. }
  5584. arrays.length = length;
  5585. return unzipWith(arrays, iteratee, thisArg);
  5586. });
  5587. /*------------------------------------------------------------------------*/
  5588. /**
  5589. * Creates a `lodash` object that wraps `value` with explicit method
  5590. * chaining enabled.
  5591. *
  5592. * @static
  5593. * @memberOf _
  5594. * @category Chain
  5595. * @param {*} value The value to wrap.
  5596. * @returns {Object} Returns the new `lodash` wrapper instance.
  5597. * @example
  5598. *
  5599. * var users = [
  5600. * { 'user': 'barney', 'age': 36 },
  5601. * { 'user': 'fred', 'age': 40 },
  5602. * { 'user': 'pebbles', 'age': 1 }
  5603. * ];
  5604. *
  5605. * var youngest = _.chain(users)
  5606. * .sortBy('age')
  5607. * .map(function(chr) {
  5608. * return chr.user + ' is ' + chr.age;
  5609. * })
  5610. * .first()
  5611. * .value();
  5612. * // => 'pebbles is 1'
  5613. */
  5614. function chain(value) {
  5615. var result = lodash(value);
  5616. result.__chain__ = true;
  5617. return result;
  5618. }
  5619. /**
  5620. * This method invokes `interceptor` and returns `value`. The interceptor is
  5621. * bound to `thisArg` and invoked with one argument; (value). The purpose of
  5622. * this method is to "tap into" a method chain in order to perform operations
  5623. * on intermediate results within the chain.
  5624. *
  5625. * @static
  5626. * @memberOf _
  5627. * @category Chain
  5628. * @param {*} value The value to provide to `interceptor`.
  5629. * @param {Function} interceptor The function to invoke.
  5630. * @param {*} [thisArg] The `this` binding of `interceptor`.
  5631. * @returns {*} Returns `value`.
  5632. * @example
  5633. *
  5634. * _([1, 2, 3])
  5635. * .tap(function(array) {
  5636. * array.pop();
  5637. * })
  5638. * .reverse()
  5639. * .value();
  5640. * // => [2, 1]
  5641. */
  5642. function tap(value, interceptor, thisArg) {
  5643. interceptor.call(thisArg, value);
  5644. return value;
  5645. }
  5646. /**
  5647. * This method is like `_.tap` except that it returns the result of `interceptor`.
  5648. *
  5649. * @static
  5650. * @memberOf _
  5651. * @category Chain
  5652. * @param {*} value The value to provide to `interceptor`.
  5653. * @param {Function} interceptor The function to invoke.
  5654. * @param {*} [thisArg] The `this` binding of `interceptor`.
  5655. * @returns {*} Returns the result of `interceptor`.
  5656. * @example
  5657. *
  5658. * _(' abc ')
  5659. * .chain()
  5660. * .trim()
  5661. * .thru(function(value) {
  5662. * return [value];
  5663. * })
  5664. * .value();
  5665. * // => ['abc']
  5666. */
  5667. function thru(value, interceptor, thisArg) {
  5668. return interceptor.call(thisArg, value);
  5669. }
  5670. /**
  5671. * Enables explicit method chaining on the wrapper object.
  5672. *
  5673. * @name chain
  5674. * @memberOf _
  5675. * @category Chain
  5676. * @returns {Object} Returns the new `lodash` wrapper instance.
  5677. * @example
  5678. *
  5679. * var users = [
  5680. * { 'user': 'barney', 'age': 36 },
  5681. * { 'user': 'fred', 'age': 40 }
  5682. * ];
  5683. *
  5684. * // without explicit chaining
  5685. * _(users).first();
  5686. * // => { 'user': 'barney', 'age': 36 }
  5687. *
  5688. * // with explicit chaining
  5689. * _(users).chain()
  5690. * .first()
  5691. * .pick('user')
  5692. * .value();
  5693. * // => { 'user': 'barney' }
  5694. */
  5695. function wrapperChain() {
  5696. return chain(this);
  5697. }
  5698. /**
  5699. * Executes the chained sequence and returns the wrapped result.
  5700. *
  5701. * @name commit
  5702. * @memberOf _
  5703. * @category Chain
  5704. * @returns {Object} Returns the new `lodash` wrapper instance.
  5705. * @example
  5706. *
  5707. * var array = [1, 2];
  5708. * var wrapped = _(array).push(3);
  5709. *
  5710. * console.log(array);
  5711. * // => [1, 2]
  5712. *
  5713. * wrapped = wrapped.commit();
  5714. * console.log(array);
  5715. * // => [1, 2, 3]
  5716. *
  5717. * wrapped.last();
  5718. * // => 3
  5719. *
  5720. * console.log(array);
  5721. * // => [1, 2, 3]
  5722. */
  5723. function wrapperCommit() {
  5724. return new LodashWrapper(this.value(), this.__chain__);
  5725. }
  5726. /**
  5727. * Creates a new array joining a wrapped array with any additional arrays
  5728. * and/or values.
  5729. *
  5730. * @name concat
  5731. * @memberOf _
  5732. * @category Chain
  5733. * @param {...*} [values] The values to concatenate.
  5734. * @returns {Array} Returns the new concatenated array.
  5735. * @example
  5736. *
  5737. * var array = [1];
  5738. * var wrapped = _(array).concat(2, [3], [[4]]);
  5739. *
  5740. * console.log(wrapped.value());
  5741. * // => [1, 2, 3, [4]]
  5742. *
  5743. * console.log(array);
  5744. * // => [1]
  5745. */
  5746. var wrapperConcat = restParam(function(values) {
  5747. values = baseFlatten(values);
  5748. return this.thru(function(array) {
  5749. return arrayConcat(isArray(array) ? array : [toObject(array)], values);
  5750. });
  5751. });
  5752. /**
  5753. * Creates a clone of the chained sequence planting `value` as the wrapped value.
  5754. *
  5755. * @name plant
  5756. * @memberOf _
  5757. * @category Chain
  5758. * @returns {Object} Returns the new `lodash` wrapper instance.
  5759. * @example
  5760. *
  5761. * var array = [1, 2];
  5762. * var wrapped = _(array).map(function(value) {
  5763. * return Math.pow(value, 2);
  5764. * });
  5765. *
  5766. * var other = [3, 4];
  5767. * var otherWrapped = wrapped.plant(other);
  5768. *
  5769. * otherWrapped.value();
  5770. * // => [9, 16]
  5771. *
  5772. * wrapped.value();
  5773. * // => [1, 4]
  5774. */
  5775. function wrapperPlant(value) {
  5776. var result,
  5777. parent = this;
  5778. while (parent instanceof baseLodash) {
  5779. var clone = wrapperClone(parent);
  5780. if (result) {
  5781. previous.__wrapped__ = clone;
  5782. } else {
  5783. result = clone;
  5784. }
  5785. var previous = clone;
  5786. parent = parent.__wrapped__;
  5787. }
  5788. previous.__wrapped__ = value;
  5789. return result;
  5790. }
  5791. /**
  5792. * Reverses the wrapped array so the first element becomes the last, the
  5793. * second element becomes the second to last, and so on.
  5794. *
  5795. * **Note:** This method mutates the wrapped array.
  5796. *
  5797. * @name reverse
  5798. * @memberOf _
  5799. * @category Chain
  5800. * @returns {Object} Returns the new reversed `lodash` wrapper instance.
  5801. * @example
  5802. *
  5803. * var array = [1, 2, 3];
  5804. *
  5805. * _(array).reverse().value()
  5806. * // => [3, 2, 1]
  5807. *
  5808. * console.log(array);
  5809. * // => [3, 2, 1]
  5810. */
  5811. function wrapperReverse() {
  5812. var value = this.__wrapped__;
  5813. var interceptor = function(value) {
  5814. return value.reverse();
  5815. };
  5816. if (value instanceof LazyWrapper) {
  5817. var wrapped = value;
  5818. if (this.__actions__.length) {
  5819. wrapped = new LazyWrapper(this);
  5820. }
  5821. wrapped = wrapped.reverse();
  5822. wrapped.__actions__.push({ 'func': thru, 'args': [interceptor], 'thisArg': undefined });
  5823. return new LodashWrapper(wrapped, this.__chain__);
  5824. }
  5825. return this.thru(interceptor);
  5826. }
  5827. /**
  5828. * Produces the result of coercing the unwrapped value to a string.
  5829. *
  5830. * @name toString
  5831. * @memberOf _
  5832. * @category Chain
  5833. * @returns {string} Returns the coerced string value.
  5834. * @example
  5835. *
  5836. * _([1, 2, 3]).toString();
  5837. * // => '1,2,3'
  5838. */
  5839. function wrapperToString() {
  5840. return (this.value() + '');
  5841. }
  5842. /**
  5843. * Executes the chained sequence to extract the unwrapped value.
  5844. *
  5845. * @name value
  5846. * @memberOf _
  5847. * @alias run, toJSON, valueOf
  5848. * @category Chain
  5849. * @returns {*} Returns the resolved unwrapped value.
  5850. * @example
  5851. *
  5852. * _([1, 2, 3]).value();
  5853. * // => [1, 2, 3]
  5854. */
  5855. function wrapperValue() {
  5856. return baseWrapperValue(this.__wrapped__, this.__actions__);
  5857. }
  5858. /*------------------------------------------------------------------------*/
  5859. /**
  5860. * Creates an array of elements corresponding to the given keys, or indexes,
  5861. * of `collection`. Keys may be specified as individual arguments or as arrays
  5862. * of keys.
  5863. *
  5864. * @static
  5865. * @memberOf _
  5866. * @category Collection
  5867. * @param {Array|Object|string} collection The collection to iterate over.
  5868. * @param {...(number|number[]|string|string[])} [props] The property names
  5869. * or indexes of elements to pick, specified individually or in arrays.
  5870. * @returns {Array} Returns the new array of picked elements.
  5871. * @example
  5872. *
  5873. * _.at(['a', 'b', 'c'], [0, 2]);
  5874. * // => ['a', 'c']
  5875. *
  5876. * _.at(['barney', 'fred', 'pebbles'], 0, 2);
  5877. * // => ['barney', 'pebbles']
  5878. */
  5879. var at = restParam(function(collection, props) {
  5880. if (isArrayLike(collection)) {
  5881. collection = toIterable(collection);
  5882. }
  5883. return baseAt(collection, baseFlatten(props));
  5884. });
  5885. /**
  5886. * Creates an object composed of keys generated from the results of running
  5887. * each element of `collection` through `iteratee`. The corresponding value
  5888. * of each key is the number of times the key was returned by `iteratee`.
  5889. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  5890. * (value, index|key, collection).
  5891. *
  5892. * If a property name is provided for `iteratee` the created `_.property`
  5893. * style callback returns the property value of the given element.
  5894. *
  5895. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5896. * style callback returns `true` for elements that have a matching property
  5897. * value, else `false`.
  5898. *
  5899. * If an object is provided for `iteratee` the created `_.matches` style
  5900. * callback returns `true` for elements that have the properties of the given
  5901. * object, else `false`.
  5902. *
  5903. * @static
  5904. * @memberOf _
  5905. * @category Collection
  5906. * @param {Array|Object|string} collection The collection to iterate over.
  5907. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  5908. * per iteration.
  5909. * @param {*} [thisArg] The `this` binding of `iteratee`.
  5910. * @returns {Object} Returns the composed aggregate object.
  5911. * @example
  5912. *
  5913. * _.countBy([4.3, 6.1, 6.4], function(n) {
  5914. * return Math.floor(n);
  5915. * });
  5916. * // => { '4': 1, '6': 2 }
  5917. *
  5918. * _.countBy([4.3, 6.1, 6.4], function(n) {
  5919. * return this.floor(n);
  5920. * }, Math);
  5921. * // => { '4': 1, '6': 2 }
  5922. *
  5923. * _.countBy(['one', 'two', 'three'], 'length');
  5924. * // => { '3': 2, '5': 1 }
  5925. */
  5926. var countBy = createAggregator(function(result, value, key) {
  5927. hasOwnProperty.call(result, key) ? ++result[key] : (result[key] = 1);
  5928. });
  5929. /**
  5930. * Checks if `predicate` returns truthy for **all** elements of `collection`.
  5931. * The predicate is bound to `thisArg` and invoked with three arguments:
  5932. * (value, index|key, collection).
  5933. *
  5934. * If a property name is provided for `predicate` the created `_.property`
  5935. * style callback returns the property value of the given element.
  5936. *
  5937. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5938. * style callback returns `true` for elements that have a matching property
  5939. * value, else `false`.
  5940. *
  5941. * If an object is provided for `predicate` the created `_.matches` style
  5942. * callback returns `true` for elements that have the properties of the given
  5943. * object, else `false`.
  5944. *
  5945. * @static
  5946. * @memberOf _
  5947. * @alias all
  5948. * @category Collection
  5949. * @param {Array|Object|string} collection The collection to iterate over.
  5950. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  5951. * per iteration.
  5952. * @param {*} [thisArg] The `this` binding of `predicate`.
  5953. * @returns {boolean} Returns `true` if all elements pass the predicate check,
  5954. * else `false`.
  5955. * @example
  5956. *
  5957. * _.every([true, 1, null, 'yes'], Boolean);
  5958. * // => false
  5959. *
  5960. * var users = [
  5961. * { 'user': 'barney', 'active': false },
  5962. * { 'user': 'fred', 'active': false }
  5963. * ];
  5964. *
  5965. * // using the `_.matches` callback shorthand
  5966. * _.every(users, { 'user': 'barney', 'active': false });
  5967. * // => false
  5968. *
  5969. * // using the `_.matchesProperty` callback shorthand
  5970. * _.every(users, 'active', false);
  5971. * // => true
  5972. *
  5973. * // using the `_.property` callback shorthand
  5974. * _.every(users, 'active');
  5975. * // => false
  5976. */
  5977. function every(collection, predicate, thisArg) {
  5978. var func = isArray(collection) ? arrayEvery : baseEvery;
  5979. if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
  5980. predicate = undefined;
  5981. }
  5982. if (typeof predicate != 'function' || thisArg !== undefined) {
  5983. predicate = getCallback(predicate, thisArg, 3);
  5984. }
  5985. return func(collection, predicate);
  5986. }
  5987. /**
  5988. * Iterates over elements of `collection`, returning an array of all elements
  5989. * `predicate` returns truthy for. The predicate is bound to `thisArg` and
  5990. * invoked with three arguments: (value, index|key, collection).
  5991. *
  5992. * If a property name is provided for `predicate` the created `_.property`
  5993. * style callback returns the property value of the given element.
  5994. *
  5995. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  5996. * style callback returns `true` for elements that have a matching property
  5997. * value, else `false`.
  5998. *
  5999. * If an object is provided for `predicate` the created `_.matches` style
  6000. * callback returns `true` for elements that have the properties of the given
  6001. * object, else `false`.
  6002. *
  6003. * @static
  6004. * @memberOf _
  6005. * @alias select
  6006. * @category Collection
  6007. * @param {Array|Object|string} collection The collection to iterate over.
  6008. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6009. * per iteration.
  6010. * @param {*} [thisArg] The `this` binding of `predicate`.
  6011. * @returns {Array} Returns the new filtered array.
  6012. * @example
  6013. *
  6014. * _.filter([4, 5, 6], function(n) {
  6015. * return n % 2 == 0;
  6016. * });
  6017. * // => [4, 6]
  6018. *
  6019. * var users = [
  6020. * { 'user': 'barney', 'age': 36, 'active': true },
  6021. * { 'user': 'fred', 'age': 40, 'active': false }
  6022. * ];
  6023. *
  6024. * // using the `_.matches` callback shorthand
  6025. * _.pluck(_.filter(users, { 'age': 36, 'active': true }), 'user');
  6026. * // => ['barney']
  6027. *
  6028. * // using the `_.matchesProperty` callback shorthand
  6029. * _.pluck(_.filter(users, 'active', false), 'user');
  6030. * // => ['fred']
  6031. *
  6032. * // using the `_.property` callback shorthand
  6033. * _.pluck(_.filter(users, 'active'), 'user');
  6034. * // => ['barney']
  6035. */
  6036. function filter(collection, predicate, thisArg) {
  6037. var func = isArray(collection) ? arrayFilter : baseFilter;
  6038. predicate = getCallback(predicate, thisArg, 3);
  6039. return func(collection, predicate);
  6040. }
  6041. /**
  6042. * Iterates over elements of `collection`, returning the first element
  6043. * `predicate` returns truthy for. The predicate is bound to `thisArg` and
  6044. * invoked with three arguments: (value, index|key, collection).
  6045. *
  6046. * If a property name is provided for `predicate` the created `_.property`
  6047. * style callback returns the property value of the given element.
  6048. *
  6049. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6050. * style callback returns `true` for elements that have a matching property
  6051. * value, else `false`.
  6052. *
  6053. * If an object is provided for `predicate` the created `_.matches` style
  6054. * callback returns `true` for elements that have the properties of the given
  6055. * object, else `false`.
  6056. *
  6057. * @static
  6058. * @memberOf _
  6059. * @alias detect
  6060. * @category Collection
  6061. * @param {Array|Object|string} collection The collection to search.
  6062. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6063. * per iteration.
  6064. * @param {*} [thisArg] The `this` binding of `predicate`.
  6065. * @returns {*} Returns the matched element, else `undefined`.
  6066. * @example
  6067. *
  6068. * var users = [
  6069. * { 'user': 'barney', 'age': 36, 'active': true },
  6070. * { 'user': 'fred', 'age': 40, 'active': false },
  6071. * { 'user': 'pebbles', 'age': 1, 'active': true }
  6072. * ];
  6073. *
  6074. * _.result(_.find(users, function(chr) {
  6075. * return chr.age < 40;
  6076. * }), 'user');
  6077. * // => 'barney'
  6078. *
  6079. * // using the `_.matches` callback shorthand
  6080. * _.result(_.find(users, { 'age': 1, 'active': true }), 'user');
  6081. * // => 'pebbles'
  6082. *
  6083. * // using the `_.matchesProperty` callback shorthand
  6084. * _.result(_.find(users, 'active', false), 'user');
  6085. * // => 'fred'
  6086. *
  6087. * // using the `_.property` callback shorthand
  6088. * _.result(_.find(users, 'active'), 'user');
  6089. * // => 'barney'
  6090. */
  6091. var find = createFind(baseEach);
  6092. /**
  6093. * This method is like `_.find` except that it iterates over elements of
  6094. * `collection` from right to left.
  6095. *
  6096. * @static
  6097. * @memberOf _
  6098. * @category Collection
  6099. * @param {Array|Object|string} collection The collection to search.
  6100. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6101. * per iteration.
  6102. * @param {*} [thisArg] The `this` binding of `predicate`.
  6103. * @returns {*} Returns the matched element, else `undefined`.
  6104. * @example
  6105. *
  6106. * _.findLast([1, 2, 3, 4], function(n) {
  6107. * return n % 2 == 1;
  6108. * });
  6109. * // => 3
  6110. */
  6111. var findLast = createFind(baseEachRight, true);
  6112. /**
  6113. * Performs a deep comparison between each element in `collection` and the
  6114. * source object, returning the first element that has equivalent property
  6115. * values.
  6116. *
  6117. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  6118. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  6119. * their own, not inherited, enumerable properties. For comparing a single
  6120. * own or inherited property value see `_.matchesProperty`.
  6121. *
  6122. * @static
  6123. * @memberOf _
  6124. * @category Collection
  6125. * @param {Array|Object|string} collection The collection to search.
  6126. * @param {Object} source The object of property values to match.
  6127. * @returns {*} Returns the matched element, else `undefined`.
  6128. * @example
  6129. *
  6130. * var users = [
  6131. * { 'user': 'barney', 'age': 36, 'active': true },
  6132. * { 'user': 'fred', 'age': 40, 'active': false }
  6133. * ];
  6134. *
  6135. * _.result(_.findWhere(users, { 'age': 36, 'active': true }), 'user');
  6136. * // => 'barney'
  6137. *
  6138. * _.result(_.findWhere(users, { 'age': 40, 'active': false }), 'user');
  6139. * // => 'fred'
  6140. */
  6141. function findWhere(collection, source) {
  6142. return find(collection, baseMatches(source));
  6143. }
  6144. /**
  6145. * Iterates over elements of `collection` invoking `iteratee` for each element.
  6146. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  6147. * (value, index|key, collection). Iteratee functions may exit iteration early
  6148. * by explicitly returning `false`.
  6149. *
  6150. * **Note:** As with other "Collections" methods, objects with a "length" property
  6151. * are iterated like arrays. To avoid this behavior `_.forIn` or `_.forOwn`
  6152. * may be used for object iteration.
  6153. *
  6154. * @static
  6155. * @memberOf _
  6156. * @alias each
  6157. * @category Collection
  6158. * @param {Array|Object|string} collection The collection to iterate over.
  6159. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6160. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6161. * @returns {Array|Object|string} Returns `collection`.
  6162. * @example
  6163. *
  6164. * _([1, 2]).forEach(function(n) {
  6165. * console.log(n);
  6166. * }).value();
  6167. * // => logs each value from left to right and returns the array
  6168. *
  6169. * _.forEach({ 'a': 1, 'b': 2 }, function(n, key) {
  6170. * console.log(n, key);
  6171. * });
  6172. * // => logs each value-key pair and returns the object (iteration order is not guaranteed)
  6173. */
  6174. var forEach = createForEach(arrayEach, baseEach);
  6175. /**
  6176. * This method is like `_.forEach` except that it iterates over elements of
  6177. * `collection` from right to left.
  6178. *
  6179. * @static
  6180. * @memberOf _
  6181. * @alias eachRight
  6182. * @category Collection
  6183. * @param {Array|Object|string} collection The collection to iterate over.
  6184. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6185. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6186. * @returns {Array|Object|string} Returns `collection`.
  6187. * @example
  6188. *
  6189. * _([1, 2]).forEachRight(function(n) {
  6190. * console.log(n);
  6191. * }).value();
  6192. * // => logs each value from right to left and returns the array
  6193. */
  6194. var forEachRight = createForEach(arrayEachRight, baseEachRight);
  6195. /**
  6196. * Creates an object composed of keys generated from the results of running
  6197. * each element of `collection` through `iteratee`. The corresponding value
  6198. * of each key is an array of the elements responsible for generating the key.
  6199. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  6200. * (value, index|key, collection).
  6201. *
  6202. * If a property name is provided for `iteratee` the created `_.property`
  6203. * style callback returns the property value of the given element.
  6204. *
  6205. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6206. * style callback returns `true` for elements that have a matching property
  6207. * value, else `false`.
  6208. *
  6209. * If an object is provided for `iteratee` the created `_.matches` style
  6210. * callback returns `true` for elements that have the properties of the given
  6211. * object, else `false`.
  6212. *
  6213. * @static
  6214. * @memberOf _
  6215. * @category Collection
  6216. * @param {Array|Object|string} collection The collection to iterate over.
  6217. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6218. * per iteration.
  6219. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6220. * @returns {Object} Returns the composed aggregate object.
  6221. * @example
  6222. *
  6223. * _.groupBy([4.2, 6.1, 6.4], function(n) {
  6224. * return Math.floor(n);
  6225. * });
  6226. * // => { '4': [4.2], '6': [6.1, 6.4] }
  6227. *
  6228. * _.groupBy([4.2, 6.1, 6.4], function(n) {
  6229. * return this.floor(n);
  6230. * }, Math);
  6231. * // => { '4': [4.2], '6': [6.1, 6.4] }
  6232. *
  6233. * // using the `_.property` callback shorthand
  6234. * _.groupBy(['one', 'two', 'three'], 'length');
  6235. * // => { '3': ['one', 'two'], '5': ['three'] }
  6236. */
  6237. var groupBy = createAggregator(function(result, value, key) {
  6238. if (hasOwnProperty.call(result, key)) {
  6239. result[key].push(value);
  6240. } else {
  6241. result[key] = [value];
  6242. }
  6243. });
  6244. /**
  6245. * Checks if `target` is in `collection` using
  6246. * [`SameValueZero`](http://ecma-international.org/ecma-262/6.0/#sec-samevaluezero)
  6247. * for equality comparisons. If `fromIndex` is negative, it's used as the offset
  6248. * from the end of `collection`.
  6249. *
  6250. * @static
  6251. * @memberOf _
  6252. * @alias contains, include
  6253. * @category Collection
  6254. * @param {Array|Object|string} collection The collection to search.
  6255. * @param {*} target The value to search for.
  6256. * @param {number} [fromIndex=0] The index to search from.
  6257. * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
  6258. * @returns {boolean} Returns `true` if a matching element is found, else `false`.
  6259. * @example
  6260. *
  6261. * _.includes([1, 2, 3], 1);
  6262. * // => true
  6263. *
  6264. * _.includes([1, 2, 3], 1, 2);
  6265. * // => false
  6266. *
  6267. * _.includes({ 'user': 'fred', 'age': 40 }, 'fred');
  6268. * // => true
  6269. *
  6270. * _.includes('pebbles', 'eb');
  6271. * // => true
  6272. */
  6273. function includes(collection, target, fromIndex, guard) {
  6274. var length = collection ? getLength(collection) : 0;
  6275. if (!isLength(length)) {
  6276. collection = values(collection);
  6277. length = collection.length;
  6278. }
  6279. if (typeof fromIndex != 'number' || (guard && isIterateeCall(target, fromIndex, guard))) {
  6280. fromIndex = 0;
  6281. } else {
  6282. fromIndex = fromIndex < 0 ? nativeMax(length + fromIndex, 0) : (fromIndex || 0);
  6283. }
  6284. return (typeof collection == 'string' || !isArray(collection) && isString(collection))
  6285. ? (fromIndex <= length && collection.indexOf(target, fromIndex) > -1)
  6286. : (!!length && getIndexOf(collection, target, fromIndex) > -1);
  6287. }
  6288. /**
  6289. * Creates an object composed of keys generated from the results of running
  6290. * each element of `collection` through `iteratee`. The corresponding value
  6291. * of each key is the last element responsible for generating the key. The
  6292. * iteratee function is bound to `thisArg` and invoked with three arguments:
  6293. * (value, index|key, collection).
  6294. *
  6295. * If a property name is provided for `iteratee` the created `_.property`
  6296. * style callback returns the property value of the given element.
  6297. *
  6298. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6299. * style callback returns `true` for elements that have a matching property
  6300. * value, else `false`.
  6301. *
  6302. * If an object is provided for `iteratee` the created `_.matches` style
  6303. * callback returns `true` for elements that have the properties of the given
  6304. * object, else `false`.
  6305. *
  6306. * @static
  6307. * @memberOf _
  6308. * @category Collection
  6309. * @param {Array|Object|string} collection The collection to iterate over.
  6310. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6311. * per iteration.
  6312. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6313. * @returns {Object} Returns the composed aggregate object.
  6314. * @example
  6315. *
  6316. * var keyData = [
  6317. * { 'dir': 'left', 'code': 97 },
  6318. * { 'dir': 'right', 'code': 100 }
  6319. * ];
  6320. *
  6321. * _.indexBy(keyData, 'dir');
  6322. * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } }
  6323. *
  6324. * _.indexBy(keyData, function(object) {
  6325. * return String.fromCharCode(object.code);
  6326. * });
  6327. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  6328. *
  6329. * _.indexBy(keyData, function(object) {
  6330. * return this.fromCharCode(object.code);
  6331. * }, String);
  6332. * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } }
  6333. */
  6334. var indexBy = createAggregator(function(result, value, key) {
  6335. result[key] = value;
  6336. });
  6337. /**
  6338. * Invokes the method at `path` of each element in `collection`, returning
  6339. * an array of the results of each invoked method. Any additional arguments
  6340. * are provided to each invoked method. If `methodName` is a function it's
  6341. * invoked for, and `this` bound to, each element in `collection`.
  6342. *
  6343. * @static
  6344. * @memberOf _
  6345. * @category Collection
  6346. * @param {Array|Object|string} collection The collection to iterate over.
  6347. * @param {Array|Function|string} path The path of the method to invoke or
  6348. * the function invoked per iteration.
  6349. * @param {...*} [args] The arguments to invoke the method with.
  6350. * @returns {Array} Returns the array of results.
  6351. * @example
  6352. *
  6353. * _.invoke([[5, 1, 7], [3, 2, 1]], 'sort');
  6354. * // => [[1, 5, 7], [1, 2, 3]]
  6355. *
  6356. * _.invoke([123, 456], String.prototype.split, '');
  6357. * // => [['1', '2', '3'], ['4', '5', '6']]
  6358. */
  6359. var invoke = restParam(function(collection, path, args) {
  6360. var index = -1,
  6361. isFunc = typeof path == 'function',
  6362. isProp = isKey(path),
  6363. result = isArrayLike(collection) ? Array(collection.length) : [];
  6364. baseEach(collection, function(value) {
  6365. var func = isFunc ? path : ((isProp && value != null) ? value[path] : undefined);
  6366. result[++index] = func ? func.apply(value, args) : invokePath(value, path, args);
  6367. });
  6368. return result;
  6369. });
  6370. /**
  6371. * Creates an array of values by running each element in `collection` through
  6372. * `iteratee`. The `iteratee` is bound to `thisArg` and invoked with three
  6373. * arguments: (value, index|key, collection).
  6374. *
  6375. * If a property name is provided for `iteratee` the created `_.property`
  6376. * style callback returns the property value of the given element.
  6377. *
  6378. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6379. * style callback returns `true` for elements that have a matching property
  6380. * value, else `false`.
  6381. *
  6382. * If an object is provided for `iteratee` the created `_.matches` style
  6383. * callback returns `true` for elements that have the properties of the given
  6384. * object, else `false`.
  6385. *
  6386. * Many lodash methods are guarded to work as iteratees for methods like
  6387. * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`.
  6388. *
  6389. * The guarded methods are:
  6390. * `ary`, `callback`, `chunk`, `clone`, `create`, `curry`, `curryRight`,
  6391. * `drop`, `dropRight`, `every`, `fill`, `flatten`, `invert`, `max`, `min`,
  6392. * `parseInt`, `slice`, `sortBy`, `take`, `takeRight`, `template`, `trim`,
  6393. * `trimLeft`, `trimRight`, `trunc`, `random`, `range`, `sample`, `some`,
  6394. * `sum`, `uniq`, and `words`
  6395. *
  6396. * @static
  6397. * @memberOf _
  6398. * @alias collect
  6399. * @category Collection
  6400. * @param {Array|Object|string} collection The collection to iterate over.
  6401. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6402. * per iteration.
  6403. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6404. * @returns {Array} Returns the new mapped array.
  6405. * @example
  6406. *
  6407. * function timesThree(n) {
  6408. * return n * 3;
  6409. * }
  6410. *
  6411. * _.map([1, 2], timesThree);
  6412. * // => [3, 6]
  6413. *
  6414. * _.map({ 'a': 1, 'b': 2 }, timesThree);
  6415. * // => [3, 6] (iteration order is not guaranteed)
  6416. *
  6417. * var users = [
  6418. * { 'user': 'barney' },
  6419. * { 'user': 'fred' }
  6420. * ];
  6421. *
  6422. * // using the `_.property` callback shorthand
  6423. * _.map(users, 'user');
  6424. * // => ['barney', 'fred']
  6425. */
  6426. function map(collection, iteratee, thisArg) {
  6427. var func = isArray(collection) ? arrayMap : baseMap;
  6428. iteratee = getCallback(iteratee, thisArg, 3);
  6429. return func(collection, iteratee);
  6430. }
  6431. /**
  6432. * Creates an array of elements split into two groups, the first of which
  6433. * contains elements `predicate` returns truthy for, while the second of which
  6434. * contains elements `predicate` returns falsey for. The predicate is bound
  6435. * to `thisArg` and invoked with three arguments: (value, index|key, collection).
  6436. *
  6437. * If a property name is provided for `predicate` the created `_.property`
  6438. * style callback returns the property value of the given element.
  6439. *
  6440. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6441. * style callback returns `true` for elements that have a matching property
  6442. * value, else `false`.
  6443. *
  6444. * If an object is provided for `predicate` the created `_.matches` style
  6445. * callback returns `true` for elements that have the properties of the given
  6446. * object, else `false`.
  6447. *
  6448. * @static
  6449. * @memberOf _
  6450. * @category Collection
  6451. * @param {Array|Object|string} collection The collection to iterate over.
  6452. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6453. * per iteration.
  6454. * @param {*} [thisArg] The `this` binding of `predicate`.
  6455. * @returns {Array} Returns the array of grouped elements.
  6456. * @example
  6457. *
  6458. * _.partition([1, 2, 3], function(n) {
  6459. * return n % 2;
  6460. * });
  6461. * // => [[1, 3], [2]]
  6462. *
  6463. * _.partition([1.2, 2.3, 3.4], function(n) {
  6464. * return this.floor(n) % 2;
  6465. * }, Math);
  6466. * // => [[1.2, 3.4], [2.3]]
  6467. *
  6468. * var users = [
  6469. * { 'user': 'barney', 'age': 36, 'active': false },
  6470. * { 'user': 'fred', 'age': 40, 'active': true },
  6471. * { 'user': 'pebbles', 'age': 1, 'active': false }
  6472. * ];
  6473. *
  6474. * var mapper = function(array) {
  6475. * return _.pluck(array, 'user');
  6476. * };
  6477. *
  6478. * // using the `_.matches` callback shorthand
  6479. * _.map(_.partition(users, { 'age': 1, 'active': false }), mapper);
  6480. * // => [['pebbles'], ['barney', 'fred']]
  6481. *
  6482. * // using the `_.matchesProperty` callback shorthand
  6483. * _.map(_.partition(users, 'active', false), mapper);
  6484. * // => [['barney', 'pebbles'], ['fred']]
  6485. *
  6486. * // using the `_.property` callback shorthand
  6487. * _.map(_.partition(users, 'active'), mapper);
  6488. * // => [['fred'], ['barney', 'pebbles']]
  6489. */
  6490. var partition = createAggregator(function(result, value, key) {
  6491. result[key ? 0 : 1].push(value);
  6492. }, function() { return [[], []]; });
  6493. /**
  6494. * Gets the property value of `path` from all elements in `collection`.
  6495. *
  6496. * @static
  6497. * @memberOf _
  6498. * @category Collection
  6499. * @param {Array|Object|string} collection The collection to iterate over.
  6500. * @param {Array|string} path The path of the property to pluck.
  6501. * @returns {Array} Returns the property values.
  6502. * @example
  6503. *
  6504. * var users = [
  6505. * { 'user': 'barney', 'age': 36 },
  6506. * { 'user': 'fred', 'age': 40 }
  6507. * ];
  6508. *
  6509. * _.pluck(users, 'user');
  6510. * // => ['barney', 'fred']
  6511. *
  6512. * var userIndex = _.indexBy(users, 'user');
  6513. * _.pluck(userIndex, 'age');
  6514. * // => [36, 40] (iteration order is not guaranteed)
  6515. */
  6516. function pluck(collection, path) {
  6517. return map(collection, property(path));
  6518. }
  6519. /**
  6520. * Reduces `collection` to a value which is the accumulated result of running
  6521. * each element in `collection` through `iteratee`, where each successive
  6522. * invocation is supplied the return value of the previous. If `accumulator`
  6523. * is not provided the first element of `collection` is used as the initial
  6524. * value. The `iteratee` is bound to `thisArg` and invoked with four arguments:
  6525. * (accumulator, value, index|key, collection).
  6526. *
  6527. * Many lodash methods are guarded to work as iteratees for methods like
  6528. * `_.reduce`, `_.reduceRight`, and `_.transform`.
  6529. *
  6530. * The guarded methods are:
  6531. * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `sortByAll`,
  6532. * and `sortByOrder`
  6533. *
  6534. * @static
  6535. * @memberOf _
  6536. * @alias foldl, inject
  6537. * @category Collection
  6538. * @param {Array|Object|string} collection The collection to iterate over.
  6539. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6540. * @param {*} [accumulator] The initial value.
  6541. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6542. * @returns {*} Returns the accumulated value.
  6543. * @example
  6544. *
  6545. * _.reduce([1, 2], function(total, n) {
  6546. * return total + n;
  6547. * });
  6548. * // => 3
  6549. *
  6550. * _.reduce({ 'a': 1, 'b': 2 }, function(result, n, key) {
  6551. * result[key] = n * 3;
  6552. * return result;
  6553. * }, {});
  6554. * // => { 'a': 3, 'b': 6 } (iteration order is not guaranteed)
  6555. */
  6556. var reduce = createReduce(arrayReduce, baseEach);
  6557. /**
  6558. * This method is like `_.reduce` except that it iterates over elements of
  6559. * `collection` from right to left.
  6560. *
  6561. * @static
  6562. * @memberOf _
  6563. * @alias foldr
  6564. * @category Collection
  6565. * @param {Array|Object|string} collection The collection to iterate over.
  6566. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  6567. * @param {*} [accumulator] The initial value.
  6568. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6569. * @returns {*} Returns the accumulated value.
  6570. * @example
  6571. *
  6572. * var array = [[0, 1], [2, 3], [4, 5]];
  6573. *
  6574. * _.reduceRight(array, function(flattened, other) {
  6575. * return flattened.concat(other);
  6576. * }, []);
  6577. * // => [4, 5, 2, 3, 0, 1]
  6578. */
  6579. var reduceRight = createReduce(arrayReduceRight, baseEachRight);
  6580. /**
  6581. * The opposite of `_.filter`; this method returns the elements of `collection`
  6582. * that `predicate` does **not** return truthy for.
  6583. *
  6584. * @static
  6585. * @memberOf _
  6586. * @category Collection
  6587. * @param {Array|Object|string} collection The collection to iterate over.
  6588. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6589. * per iteration.
  6590. * @param {*} [thisArg] The `this` binding of `predicate`.
  6591. * @returns {Array} Returns the new filtered array.
  6592. * @example
  6593. *
  6594. * _.reject([1, 2, 3, 4], function(n) {
  6595. * return n % 2 == 0;
  6596. * });
  6597. * // => [1, 3]
  6598. *
  6599. * var users = [
  6600. * { 'user': 'barney', 'age': 36, 'active': false },
  6601. * { 'user': 'fred', 'age': 40, 'active': true }
  6602. * ];
  6603. *
  6604. * // using the `_.matches` callback shorthand
  6605. * _.pluck(_.reject(users, { 'age': 40, 'active': true }), 'user');
  6606. * // => ['barney']
  6607. *
  6608. * // using the `_.matchesProperty` callback shorthand
  6609. * _.pluck(_.reject(users, 'active', false), 'user');
  6610. * // => ['fred']
  6611. *
  6612. * // using the `_.property` callback shorthand
  6613. * _.pluck(_.reject(users, 'active'), 'user');
  6614. * // => ['barney']
  6615. */
  6616. function reject(collection, predicate, thisArg) {
  6617. var func = isArray(collection) ? arrayFilter : baseFilter;
  6618. predicate = getCallback(predicate, thisArg, 3);
  6619. return func(collection, function(value, index, collection) {
  6620. return !predicate(value, index, collection);
  6621. });
  6622. }
  6623. /**
  6624. * Gets a random element or `n` random elements from a collection.
  6625. *
  6626. * @static
  6627. * @memberOf _
  6628. * @category Collection
  6629. * @param {Array|Object|string} collection The collection to sample.
  6630. * @param {number} [n] The number of elements to sample.
  6631. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  6632. * @returns {*} Returns the random sample(s).
  6633. * @example
  6634. *
  6635. * _.sample([1, 2, 3, 4]);
  6636. * // => 2
  6637. *
  6638. * _.sample([1, 2, 3, 4], 2);
  6639. * // => [3, 1]
  6640. */
  6641. function sample(collection, n, guard) {
  6642. if (guard ? isIterateeCall(collection, n, guard) : n == null) {
  6643. collection = toIterable(collection);
  6644. var length = collection.length;
  6645. return length > 0 ? collection[baseRandom(0, length - 1)] : undefined;
  6646. }
  6647. var index = -1,
  6648. result = toArray(collection),
  6649. length = result.length,
  6650. lastIndex = length - 1;
  6651. n = nativeMin(n < 0 ? 0 : (+n || 0), length);
  6652. while (++index < n) {
  6653. var rand = baseRandom(index, lastIndex),
  6654. value = result[rand];
  6655. result[rand] = result[index];
  6656. result[index] = value;
  6657. }
  6658. result.length = n;
  6659. return result;
  6660. }
  6661. /**
  6662. * Creates an array of shuffled values, using a version of the
  6663. * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle).
  6664. *
  6665. * @static
  6666. * @memberOf _
  6667. * @category Collection
  6668. * @param {Array|Object|string} collection The collection to shuffle.
  6669. * @returns {Array} Returns the new shuffled array.
  6670. * @example
  6671. *
  6672. * _.shuffle([1, 2, 3, 4]);
  6673. * // => [4, 1, 3, 2]
  6674. */
  6675. function shuffle(collection) {
  6676. return sample(collection, POSITIVE_INFINITY);
  6677. }
  6678. /**
  6679. * Gets the size of `collection` by returning its length for array-like
  6680. * values or the number of own enumerable properties for objects.
  6681. *
  6682. * @static
  6683. * @memberOf _
  6684. * @category Collection
  6685. * @param {Array|Object|string} collection The collection to inspect.
  6686. * @returns {number} Returns the size of `collection`.
  6687. * @example
  6688. *
  6689. * _.size([1, 2, 3]);
  6690. * // => 3
  6691. *
  6692. * _.size({ 'a': 1, 'b': 2 });
  6693. * // => 2
  6694. *
  6695. * _.size('pebbles');
  6696. * // => 7
  6697. */
  6698. function size(collection) {
  6699. var length = collection ? getLength(collection) : 0;
  6700. return isLength(length) ? length : keys(collection).length;
  6701. }
  6702. /**
  6703. * Checks if `predicate` returns truthy for **any** element of `collection`.
  6704. * The function returns as soon as it finds a passing value and does not iterate
  6705. * over the entire collection. The predicate is bound to `thisArg` and invoked
  6706. * with three arguments: (value, index|key, collection).
  6707. *
  6708. * If a property name is provided for `predicate` the created `_.property`
  6709. * style callback returns the property value of the given element.
  6710. *
  6711. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6712. * style callback returns `true` for elements that have a matching property
  6713. * value, else `false`.
  6714. *
  6715. * If an object is provided for `predicate` the created `_.matches` style
  6716. * callback returns `true` for elements that have the properties of the given
  6717. * object, else `false`.
  6718. *
  6719. * @static
  6720. * @memberOf _
  6721. * @alias any
  6722. * @category Collection
  6723. * @param {Array|Object|string} collection The collection to iterate over.
  6724. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  6725. * per iteration.
  6726. * @param {*} [thisArg] The `this` binding of `predicate`.
  6727. * @returns {boolean} Returns `true` if any element passes the predicate check,
  6728. * else `false`.
  6729. * @example
  6730. *
  6731. * _.some([null, 0, 'yes', false], Boolean);
  6732. * // => true
  6733. *
  6734. * var users = [
  6735. * { 'user': 'barney', 'active': true },
  6736. * { 'user': 'fred', 'active': false }
  6737. * ];
  6738. *
  6739. * // using the `_.matches` callback shorthand
  6740. * _.some(users, { 'user': 'barney', 'active': false });
  6741. * // => false
  6742. *
  6743. * // using the `_.matchesProperty` callback shorthand
  6744. * _.some(users, 'active', false);
  6745. * // => true
  6746. *
  6747. * // using the `_.property` callback shorthand
  6748. * _.some(users, 'active');
  6749. * // => true
  6750. */
  6751. function some(collection, predicate, thisArg) {
  6752. var func = isArray(collection) ? arraySome : baseSome;
  6753. if (thisArg && isIterateeCall(collection, predicate, thisArg)) {
  6754. predicate = undefined;
  6755. }
  6756. if (typeof predicate != 'function' || thisArg !== undefined) {
  6757. predicate = getCallback(predicate, thisArg, 3);
  6758. }
  6759. return func(collection, predicate);
  6760. }
  6761. /**
  6762. * Creates an array of elements, sorted in ascending order by the results of
  6763. * running each element in a collection through `iteratee`. This method performs
  6764. * a stable sort, that is, it preserves the original sort order of equal elements.
  6765. * The `iteratee` is bound to `thisArg` and invoked with three arguments:
  6766. * (value, index|key, collection).
  6767. *
  6768. * If a property name is provided for `iteratee` the created `_.property`
  6769. * style callback returns the property value of the given element.
  6770. *
  6771. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  6772. * style callback returns `true` for elements that have a matching property
  6773. * value, else `false`.
  6774. *
  6775. * If an object is provided for `iteratee` the created `_.matches` style
  6776. * callback returns `true` for elements that have the properties of the given
  6777. * object, else `false`.
  6778. *
  6779. * @static
  6780. * @memberOf _
  6781. * @category Collection
  6782. * @param {Array|Object|string} collection The collection to iterate over.
  6783. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  6784. * per iteration.
  6785. * @param {*} [thisArg] The `this` binding of `iteratee`.
  6786. * @returns {Array} Returns the new sorted array.
  6787. * @example
  6788. *
  6789. * _.sortBy([1, 2, 3], function(n) {
  6790. * return Math.sin(n);
  6791. * });
  6792. * // => [3, 1, 2]
  6793. *
  6794. * _.sortBy([1, 2, 3], function(n) {
  6795. * return this.sin(n);
  6796. * }, Math);
  6797. * // => [3, 1, 2]
  6798. *
  6799. * var users = [
  6800. * { 'user': 'fred' },
  6801. * { 'user': 'pebbles' },
  6802. * { 'user': 'barney' }
  6803. * ];
  6804. *
  6805. * // using the `_.property` callback shorthand
  6806. * _.pluck(_.sortBy(users, 'user'), 'user');
  6807. * // => ['barney', 'fred', 'pebbles']
  6808. */
  6809. function sortBy(collection, iteratee, thisArg) {
  6810. if (collection == null) {
  6811. return [];
  6812. }
  6813. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  6814. iteratee = undefined;
  6815. }
  6816. var index = -1;
  6817. iteratee = getCallback(iteratee, thisArg, 3);
  6818. var result = baseMap(collection, function(value, key, collection) {
  6819. return { 'criteria': iteratee(value, key, collection), 'index': ++index, 'value': value };
  6820. });
  6821. return baseSortBy(result, compareAscending);
  6822. }
  6823. /**
  6824. * This method is like `_.sortBy` except that it can sort by multiple iteratees
  6825. * or property names.
  6826. *
  6827. * If a property name is provided for an iteratee the created `_.property`
  6828. * style callback returns the property value of the given element.
  6829. *
  6830. * If an object is provided for an iteratee the created `_.matches` style
  6831. * callback returns `true` for elements that have the properties of the given
  6832. * object, else `false`.
  6833. *
  6834. * @static
  6835. * @memberOf _
  6836. * @category Collection
  6837. * @param {Array|Object|string} collection The collection to iterate over.
  6838. * @param {...(Function|Function[]|Object|Object[]|string|string[])} iteratees
  6839. * The iteratees to sort by, specified as individual values or arrays of values.
  6840. * @returns {Array} Returns the new sorted array.
  6841. * @example
  6842. *
  6843. * var users = [
  6844. * { 'user': 'fred', 'age': 48 },
  6845. * { 'user': 'barney', 'age': 36 },
  6846. * { 'user': 'fred', 'age': 42 },
  6847. * { 'user': 'barney', 'age': 34 }
  6848. * ];
  6849. *
  6850. * _.map(_.sortByAll(users, ['user', 'age']), _.values);
  6851. * // => [['barney', 34], ['barney', 36], ['fred', 42], ['fred', 48]]
  6852. *
  6853. * _.map(_.sortByAll(users, 'user', function(chr) {
  6854. * return Math.floor(chr.age / 10);
  6855. * }), _.values);
  6856. * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
  6857. */
  6858. var sortByAll = restParam(function(collection, iteratees) {
  6859. if (collection == null) {
  6860. return [];
  6861. }
  6862. var guard = iteratees[2];
  6863. if (guard && isIterateeCall(iteratees[0], iteratees[1], guard)) {
  6864. iteratees.length = 1;
  6865. }
  6866. return baseSortByOrder(collection, baseFlatten(iteratees), []);
  6867. });
  6868. /**
  6869. * This method is like `_.sortByAll` except that it allows specifying the
  6870. * sort orders of the iteratees to sort by. If `orders` is unspecified, all
  6871. * values are sorted in ascending order. Otherwise, a value is sorted in
  6872. * ascending order if its corresponding order is "asc", and descending if "desc".
  6873. *
  6874. * If a property name is provided for an iteratee the created `_.property`
  6875. * style callback returns the property value of the given element.
  6876. *
  6877. * If an object is provided for an iteratee the created `_.matches` style
  6878. * callback returns `true` for elements that have the properties of the given
  6879. * object, else `false`.
  6880. *
  6881. * @static
  6882. * @memberOf _
  6883. * @category Collection
  6884. * @param {Array|Object|string} collection The collection to iterate over.
  6885. * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by.
  6886. * @param {boolean[]} [orders] The sort orders of `iteratees`.
  6887. * @param- {Object} [guard] Enables use as a callback for functions like `_.reduce`.
  6888. * @returns {Array} Returns the new sorted array.
  6889. * @example
  6890. *
  6891. * var users = [
  6892. * { 'user': 'fred', 'age': 48 },
  6893. * { 'user': 'barney', 'age': 34 },
  6894. * { 'user': 'fred', 'age': 42 },
  6895. * { 'user': 'barney', 'age': 36 }
  6896. * ];
  6897. *
  6898. * // sort by `user` in ascending order and by `age` in descending order
  6899. * _.map(_.sortByOrder(users, ['user', 'age'], ['asc', 'desc']), _.values);
  6900. * // => [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 42]]
  6901. */
  6902. function sortByOrder(collection, iteratees, orders, guard) {
  6903. if (collection == null) {
  6904. return [];
  6905. }
  6906. if (guard && isIterateeCall(iteratees, orders, guard)) {
  6907. orders = undefined;
  6908. }
  6909. if (!isArray(iteratees)) {
  6910. iteratees = iteratees == null ? [] : [iteratees];
  6911. }
  6912. if (!isArray(orders)) {
  6913. orders = orders == null ? [] : [orders];
  6914. }
  6915. return baseSortByOrder(collection, iteratees, orders);
  6916. }
  6917. /**
  6918. * Performs a deep comparison between each element in `collection` and the
  6919. * source object, returning an array of all elements that have equivalent
  6920. * property values.
  6921. *
  6922. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  6923. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  6924. * their own, not inherited, enumerable properties. For comparing a single
  6925. * own or inherited property value see `_.matchesProperty`.
  6926. *
  6927. * @static
  6928. * @memberOf _
  6929. * @category Collection
  6930. * @param {Array|Object|string} collection The collection to search.
  6931. * @param {Object} source The object of property values to match.
  6932. * @returns {Array} Returns the new filtered array.
  6933. * @example
  6934. *
  6935. * var users = [
  6936. * { 'user': 'barney', 'age': 36, 'active': false, 'pets': ['hoppy'] },
  6937. * { 'user': 'fred', 'age': 40, 'active': true, 'pets': ['baby puss', 'dino'] }
  6938. * ];
  6939. *
  6940. * _.pluck(_.where(users, { 'age': 36, 'active': false }), 'user');
  6941. * // => ['barney']
  6942. *
  6943. * _.pluck(_.where(users, { 'pets': ['dino'] }), 'user');
  6944. * // => ['fred']
  6945. */
  6946. function where(collection, source) {
  6947. return filter(collection, baseMatches(source));
  6948. }
  6949. /*------------------------------------------------------------------------*/
  6950. /**
  6951. * Gets the number of milliseconds that have elapsed since the Unix epoch
  6952. * (1 January 1970 00:00:00 UTC).
  6953. *
  6954. * @static
  6955. * @memberOf _
  6956. * @category Date
  6957. * @example
  6958. *
  6959. * _.defer(function(stamp) {
  6960. * console.log(_.now() - stamp);
  6961. * }, _.now());
  6962. * // => logs the number of milliseconds it took for the deferred function to be invoked
  6963. */
  6964. var now = nativeNow || function() {
  6965. return new Date().getTime();
  6966. };
  6967. /*------------------------------------------------------------------------*/
  6968. /**
  6969. * The opposite of `_.before`; this method creates a function that invokes
  6970. * `func` once it's called `n` or more times.
  6971. *
  6972. * @static
  6973. * @memberOf _
  6974. * @category Function
  6975. * @param {number} n The number of calls before `func` is invoked.
  6976. * @param {Function} func The function to restrict.
  6977. * @returns {Function} Returns the new restricted function.
  6978. * @example
  6979. *
  6980. * var saves = ['profile', 'settings'];
  6981. *
  6982. * var done = _.after(saves.length, function() {
  6983. * console.log('done saving!');
  6984. * });
  6985. *
  6986. * _.forEach(saves, function(type) {
  6987. * asyncSave({ 'type': type, 'complete': done });
  6988. * });
  6989. * // => logs 'done saving!' after the two async saves have completed
  6990. */
  6991. function after(n, func) {
  6992. if (typeof func != 'function') {
  6993. if (typeof n == 'function') {
  6994. var temp = n;
  6995. n = func;
  6996. func = temp;
  6997. } else {
  6998. throw new TypeError(FUNC_ERROR_TEXT);
  6999. }
  7000. }
  7001. n = nativeIsFinite(n = +n) ? n : 0;
  7002. return function() {
  7003. if (--n < 1) {
  7004. return func.apply(this, arguments);
  7005. }
  7006. };
  7007. }
  7008. /**
  7009. * Creates a function that accepts up to `n` arguments ignoring any
  7010. * additional arguments.
  7011. *
  7012. * @static
  7013. * @memberOf _
  7014. * @category Function
  7015. * @param {Function} func The function to cap arguments for.
  7016. * @param {number} [n=func.length] The arity cap.
  7017. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  7018. * @returns {Function} Returns the new function.
  7019. * @example
  7020. *
  7021. * _.map(['6', '8', '10'], _.ary(parseInt, 1));
  7022. * // => [6, 8, 10]
  7023. */
  7024. function ary(func, n, guard) {
  7025. if (guard && isIterateeCall(func, n, guard)) {
  7026. n = undefined;
  7027. }
  7028. n = (func && n == null) ? func.length : nativeMax(+n || 0, 0);
  7029. return createWrapper(func, ARY_FLAG, undefined, undefined, undefined, undefined, n);
  7030. }
  7031. /**
  7032. * Creates a function that invokes `func`, with the `this` binding and arguments
  7033. * of the created function, while it's called less than `n` times. Subsequent
  7034. * calls to the created function return the result of the last `func` invocation.
  7035. *
  7036. * @static
  7037. * @memberOf _
  7038. * @category Function
  7039. * @param {number} n The number of calls at which `func` is no longer invoked.
  7040. * @param {Function} func The function to restrict.
  7041. * @returns {Function} Returns the new restricted function.
  7042. * @example
  7043. *
  7044. * jQuery('#add').on('click', _.before(5, addContactToList));
  7045. * // => allows adding up to 4 contacts to the list
  7046. */
  7047. function before(n, func) {
  7048. var result;
  7049. if (typeof func != 'function') {
  7050. if (typeof n == 'function') {
  7051. var temp = n;
  7052. n = func;
  7053. func = temp;
  7054. } else {
  7055. throw new TypeError(FUNC_ERROR_TEXT);
  7056. }
  7057. }
  7058. return function() {
  7059. if (--n > 0) {
  7060. result = func.apply(this, arguments);
  7061. }
  7062. if (n <= 1) {
  7063. func = undefined;
  7064. }
  7065. return result;
  7066. };
  7067. }
  7068. /**
  7069. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  7070. * and prepends any additional `_.bind` arguments to those provided to the
  7071. * bound function.
  7072. *
  7073. * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds,
  7074. * may be used as a placeholder for partially applied arguments.
  7075. *
  7076. * **Note:** Unlike native `Function#bind` this method does not set the "length"
  7077. * property of bound functions.
  7078. *
  7079. * @static
  7080. * @memberOf _
  7081. * @category Function
  7082. * @param {Function} func The function to bind.
  7083. * @param {*} thisArg The `this` binding of `func`.
  7084. * @param {...*} [partials] The arguments to be partially applied.
  7085. * @returns {Function} Returns the new bound function.
  7086. * @example
  7087. *
  7088. * var greet = function(greeting, punctuation) {
  7089. * return greeting + ' ' + this.user + punctuation;
  7090. * };
  7091. *
  7092. * var object = { 'user': 'fred' };
  7093. *
  7094. * var bound = _.bind(greet, object, 'hi');
  7095. * bound('!');
  7096. * // => 'hi fred!'
  7097. *
  7098. * // using placeholders
  7099. * var bound = _.bind(greet, object, _, '!');
  7100. * bound('hi');
  7101. * // => 'hi fred!'
  7102. */
  7103. var bind = restParam(function(func, thisArg, partials) {
  7104. var bitmask = BIND_FLAG;
  7105. if (partials.length) {
  7106. var holders = replaceHolders(partials, bind.placeholder);
  7107. bitmask |= PARTIAL_FLAG;
  7108. }
  7109. return createWrapper(func, bitmask, thisArg, partials, holders);
  7110. });
  7111. /**
  7112. * Binds methods of an object to the object itself, overwriting the existing
  7113. * method. Method names may be specified as individual arguments or as arrays
  7114. * of method names. If no method names are provided all enumerable function
  7115. * properties, own and inherited, of `object` are bound.
  7116. *
  7117. * **Note:** This method does not set the "length" property of bound functions.
  7118. *
  7119. * @static
  7120. * @memberOf _
  7121. * @category Function
  7122. * @param {Object} object The object to bind and assign the bound methods to.
  7123. * @param {...(string|string[])} [methodNames] The object method names to bind,
  7124. * specified as individual method names or arrays of method names.
  7125. * @returns {Object} Returns `object`.
  7126. * @example
  7127. *
  7128. * var view = {
  7129. * 'label': 'docs',
  7130. * 'onClick': function() {
  7131. * console.log('clicked ' + this.label);
  7132. * }
  7133. * };
  7134. *
  7135. * _.bindAll(view);
  7136. * jQuery('#docs').on('click', view.onClick);
  7137. * // => logs 'clicked docs' when the element is clicked
  7138. */
  7139. var bindAll = restParam(function(object, methodNames) {
  7140. methodNames = methodNames.length ? baseFlatten(methodNames) : functions(object);
  7141. var index = -1,
  7142. length = methodNames.length;
  7143. while (++index < length) {
  7144. var key = methodNames[index];
  7145. object[key] = createWrapper(object[key], BIND_FLAG, object);
  7146. }
  7147. return object;
  7148. });
  7149. /**
  7150. * Creates a function that invokes the method at `object[key]` and prepends
  7151. * any additional `_.bindKey` arguments to those provided to the bound function.
  7152. *
  7153. * This method differs from `_.bind` by allowing bound functions to reference
  7154. * methods that may be redefined or don't yet exist.
  7155. * See [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern)
  7156. * for more details.
  7157. *
  7158. * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic
  7159. * builds, may be used as a placeholder for partially applied arguments.
  7160. *
  7161. * @static
  7162. * @memberOf _
  7163. * @category Function
  7164. * @param {Object} object The object the method belongs to.
  7165. * @param {string} key The key of the method.
  7166. * @param {...*} [partials] The arguments to be partially applied.
  7167. * @returns {Function} Returns the new bound function.
  7168. * @example
  7169. *
  7170. * var object = {
  7171. * 'user': 'fred',
  7172. * 'greet': function(greeting, punctuation) {
  7173. * return greeting + ' ' + this.user + punctuation;
  7174. * }
  7175. * };
  7176. *
  7177. * var bound = _.bindKey(object, 'greet', 'hi');
  7178. * bound('!');
  7179. * // => 'hi fred!'
  7180. *
  7181. * object.greet = function(greeting, punctuation) {
  7182. * return greeting + 'ya ' + this.user + punctuation;
  7183. * };
  7184. *
  7185. * bound('!');
  7186. * // => 'hiya fred!'
  7187. *
  7188. * // using placeholders
  7189. * var bound = _.bindKey(object, 'greet', _, '!');
  7190. * bound('hi');
  7191. * // => 'hiya fred!'
  7192. */
  7193. var bindKey = restParam(function(object, key, partials) {
  7194. var bitmask = BIND_FLAG | BIND_KEY_FLAG;
  7195. if (partials.length) {
  7196. var holders = replaceHolders(partials, bindKey.placeholder);
  7197. bitmask |= PARTIAL_FLAG;
  7198. }
  7199. return createWrapper(key, bitmask, object, partials, holders);
  7200. });
  7201. /**
  7202. * Creates a function that accepts one or more arguments of `func` that when
  7203. * called either invokes `func` returning its result, if all `func` arguments
  7204. * have been provided, or returns a function that accepts one or more of the
  7205. * remaining `func` arguments, and so on. The arity of `func` may be specified
  7206. * if `func.length` is not sufficient.
  7207. *
  7208. * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds,
  7209. * may be used as a placeholder for provided arguments.
  7210. *
  7211. * **Note:** This method does not set the "length" property of curried functions.
  7212. *
  7213. * @static
  7214. * @memberOf _
  7215. * @category Function
  7216. * @param {Function} func The function to curry.
  7217. * @param {number} [arity=func.length] The arity of `func`.
  7218. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  7219. * @returns {Function} Returns the new curried function.
  7220. * @example
  7221. *
  7222. * var abc = function(a, b, c) {
  7223. * return [a, b, c];
  7224. * };
  7225. *
  7226. * var curried = _.curry(abc);
  7227. *
  7228. * curried(1)(2)(3);
  7229. * // => [1, 2, 3]
  7230. *
  7231. * curried(1, 2)(3);
  7232. * // => [1, 2, 3]
  7233. *
  7234. * curried(1, 2, 3);
  7235. * // => [1, 2, 3]
  7236. *
  7237. * // using placeholders
  7238. * curried(1)(_, 3)(2);
  7239. * // => [1, 2, 3]
  7240. */
  7241. var curry = createCurry(CURRY_FLAG);
  7242. /**
  7243. * This method is like `_.curry` except that arguments are applied to `func`
  7244. * in the manner of `_.partialRight` instead of `_.partial`.
  7245. *
  7246. * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic
  7247. * builds, may be used as a placeholder for provided arguments.
  7248. *
  7249. * **Note:** This method does not set the "length" property of curried functions.
  7250. *
  7251. * @static
  7252. * @memberOf _
  7253. * @category Function
  7254. * @param {Function} func The function to curry.
  7255. * @param {number} [arity=func.length] The arity of `func`.
  7256. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  7257. * @returns {Function} Returns the new curried function.
  7258. * @example
  7259. *
  7260. * var abc = function(a, b, c) {
  7261. * return [a, b, c];
  7262. * };
  7263. *
  7264. * var curried = _.curryRight(abc);
  7265. *
  7266. * curried(3)(2)(1);
  7267. * // => [1, 2, 3]
  7268. *
  7269. * curried(2, 3)(1);
  7270. * // => [1, 2, 3]
  7271. *
  7272. * curried(1, 2, 3);
  7273. * // => [1, 2, 3]
  7274. *
  7275. * // using placeholders
  7276. * curried(3)(1, _)(2);
  7277. * // => [1, 2, 3]
  7278. */
  7279. var curryRight = createCurry(CURRY_RIGHT_FLAG);
  7280. /**
  7281. * Creates a debounced function that delays invoking `func` until after `wait`
  7282. * milliseconds have elapsed since the last time the debounced function was
  7283. * invoked. The debounced function comes with a `cancel` method to cancel
  7284. * delayed invocations. Provide an options object to indicate that `func`
  7285. * should be invoked on the leading and/or trailing edge of the `wait` timeout.
  7286. * Subsequent calls to the debounced function return the result of the last
  7287. * `func` invocation.
  7288. *
  7289. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  7290. * on the trailing edge of the timeout only if the the debounced function is
  7291. * invoked more than once during the `wait` timeout.
  7292. *
  7293. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  7294. * for details over the differences between `_.debounce` and `_.throttle`.
  7295. *
  7296. * @static
  7297. * @memberOf _
  7298. * @category Function
  7299. * @param {Function} func The function to debounce.
  7300. * @param {number} [wait=0] The number of milliseconds to delay.
  7301. * @param {Object} [options] The options object.
  7302. * @param {boolean} [options.leading=false] Specify invoking on the leading
  7303. * edge of the timeout.
  7304. * @param {number} [options.maxWait] The maximum time `func` is allowed to be
  7305. * delayed before it's invoked.
  7306. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  7307. * edge of the timeout.
  7308. * @returns {Function} Returns the new debounced function.
  7309. * @example
  7310. *
  7311. * // avoid costly calculations while the window size is in flux
  7312. * jQuery(window).on('resize', _.debounce(calculateLayout, 150));
  7313. *
  7314. * // invoke `sendMail` when the click event is fired, debouncing subsequent calls
  7315. * jQuery('#postbox').on('click', _.debounce(sendMail, 300, {
  7316. * 'leading': true,
  7317. * 'trailing': false
  7318. * }));
  7319. *
  7320. * // ensure `batchLog` is invoked once after 1 second of debounced calls
  7321. * var source = new EventSource('/stream');
  7322. * jQuery(source).on('message', _.debounce(batchLog, 250, {
  7323. * 'maxWait': 1000
  7324. * }));
  7325. *
  7326. * // cancel a debounced call
  7327. * var todoChanges = _.debounce(batchLog, 1000);
  7328. * Object.observe(models.todo, todoChanges);
  7329. *
  7330. * Object.observe(models, function(changes) {
  7331. * if (_.find(changes, { 'user': 'todo', 'type': 'delete'})) {
  7332. * todoChanges.cancel();
  7333. * }
  7334. * }, ['delete']);
  7335. *
  7336. * // ...at some point `models.todo` is changed
  7337. * models.todo.completed = true;
  7338. *
  7339. * // ...before 1 second has passed `models.todo` is deleted
  7340. * // which cancels the debounced `todoChanges` call
  7341. * delete models.todo;
  7342. */
  7343. function debounce(func, wait, options) {
  7344. var args,
  7345. maxTimeoutId,
  7346. result,
  7347. stamp,
  7348. thisArg,
  7349. timeoutId,
  7350. trailingCall,
  7351. lastCalled = 0,
  7352. maxWait = false,
  7353. trailing = true;
  7354. if (typeof func != 'function') {
  7355. throw new TypeError(FUNC_ERROR_TEXT);
  7356. }
  7357. wait = wait < 0 ? 0 : (+wait || 0);
  7358. if (options === true) {
  7359. var leading = true;
  7360. trailing = false;
  7361. } else if (isObject(options)) {
  7362. leading = !!options.leading;
  7363. maxWait = 'maxWait' in options && nativeMax(+options.maxWait || 0, wait);
  7364. trailing = 'trailing' in options ? !!options.trailing : trailing;
  7365. }
  7366. function cancel() {
  7367. if (timeoutId) {
  7368. clearTimeout(timeoutId);
  7369. }
  7370. if (maxTimeoutId) {
  7371. clearTimeout(maxTimeoutId);
  7372. }
  7373. lastCalled = 0;
  7374. maxTimeoutId = timeoutId = trailingCall = undefined;
  7375. }
  7376. function complete(isCalled, id) {
  7377. if (id) {
  7378. clearTimeout(id);
  7379. }
  7380. maxTimeoutId = timeoutId = trailingCall = undefined;
  7381. if (isCalled) {
  7382. lastCalled = now();
  7383. result = func.apply(thisArg, args);
  7384. if (!timeoutId && !maxTimeoutId) {
  7385. args = thisArg = undefined;
  7386. }
  7387. }
  7388. }
  7389. function delayed() {
  7390. var remaining = wait - (now() - stamp);
  7391. if (remaining <= 0 || remaining > wait) {
  7392. complete(trailingCall, maxTimeoutId);
  7393. } else {
  7394. timeoutId = setTimeout(delayed, remaining);
  7395. }
  7396. }
  7397. function maxDelayed() {
  7398. complete(trailing, timeoutId);
  7399. }
  7400. function debounced() {
  7401. args = arguments;
  7402. stamp = now();
  7403. thisArg = this;
  7404. trailingCall = trailing && (timeoutId || !leading);
  7405. if (maxWait === false) {
  7406. var leadingCall = leading && !timeoutId;
  7407. } else {
  7408. if (!maxTimeoutId && !leading) {
  7409. lastCalled = stamp;
  7410. }
  7411. var remaining = maxWait - (stamp - lastCalled),
  7412. isCalled = remaining <= 0 || remaining > maxWait;
  7413. if (isCalled) {
  7414. if (maxTimeoutId) {
  7415. maxTimeoutId = clearTimeout(maxTimeoutId);
  7416. }
  7417. lastCalled = stamp;
  7418. result = func.apply(thisArg, args);
  7419. }
  7420. else if (!maxTimeoutId) {
  7421. maxTimeoutId = setTimeout(maxDelayed, remaining);
  7422. }
  7423. }
  7424. if (isCalled && timeoutId) {
  7425. timeoutId = clearTimeout(timeoutId);
  7426. }
  7427. else if (!timeoutId && wait !== maxWait) {
  7428. timeoutId = setTimeout(delayed, wait);
  7429. }
  7430. if (leadingCall) {
  7431. isCalled = true;
  7432. result = func.apply(thisArg, args);
  7433. }
  7434. if (isCalled && !timeoutId && !maxTimeoutId) {
  7435. args = thisArg = undefined;
  7436. }
  7437. return result;
  7438. }
  7439. debounced.cancel = cancel;
  7440. return debounced;
  7441. }
  7442. /**
  7443. * Defers invoking the `func` until the current call stack has cleared. Any
  7444. * additional arguments are provided to `func` when it's invoked.
  7445. *
  7446. * @static
  7447. * @memberOf _
  7448. * @category Function
  7449. * @param {Function} func The function to defer.
  7450. * @param {...*} [args] The arguments to invoke the function with.
  7451. * @returns {number} Returns the timer id.
  7452. * @example
  7453. *
  7454. * _.defer(function(text) {
  7455. * console.log(text);
  7456. * }, 'deferred');
  7457. * // logs 'deferred' after one or more milliseconds
  7458. */
  7459. var defer = restParam(function(func, args) {
  7460. return baseDelay(func, 1, args);
  7461. });
  7462. /**
  7463. * Invokes `func` after `wait` milliseconds. Any additional arguments are
  7464. * provided to `func` when it's invoked.
  7465. *
  7466. * @static
  7467. * @memberOf _
  7468. * @category Function
  7469. * @param {Function} func The function to delay.
  7470. * @param {number} wait The number of milliseconds to delay invocation.
  7471. * @param {...*} [args] The arguments to invoke the function with.
  7472. * @returns {number} Returns the timer id.
  7473. * @example
  7474. *
  7475. * _.delay(function(text) {
  7476. * console.log(text);
  7477. * }, 1000, 'later');
  7478. * // => logs 'later' after one second
  7479. */
  7480. var delay = restParam(function(func, wait, args) {
  7481. return baseDelay(func, wait, args);
  7482. });
  7483. /**
  7484. * Creates a function that returns the result of invoking the provided
  7485. * functions with the `this` binding of the created function, where each
  7486. * successive invocation is supplied the return value of the previous.
  7487. *
  7488. * @static
  7489. * @memberOf _
  7490. * @category Function
  7491. * @param {...Function} [funcs] Functions to invoke.
  7492. * @returns {Function} Returns the new function.
  7493. * @example
  7494. *
  7495. * function square(n) {
  7496. * return n * n;
  7497. * }
  7498. *
  7499. * var addSquare = _.flow(_.add, square);
  7500. * addSquare(1, 2);
  7501. * // => 9
  7502. */
  7503. var flow = createFlow();
  7504. /**
  7505. * This method is like `_.flow` except that it creates a function that
  7506. * invokes the provided functions from right to left.
  7507. *
  7508. * @static
  7509. * @memberOf _
  7510. * @alias backflow, compose
  7511. * @category Function
  7512. * @param {...Function} [funcs] Functions to invoke.
  7513. * @returns {Function} Returns the new function.
  7514. * @example
  7515. *
  7516. * function square(n) {
  7517. * return n * n;
  7518. * }
  7519. *
  7520. * var addSquare = _.flowRight(square, _.add);
  7521. * addSquare(1, 2);
  7522. * // => 9
  7523. */
  7524. var flowRight = createFlow(true);
  7525. /**
  7526. * Creates a function that memoizes the result of `func`. If `resolver` is
  7527. * provided it determines the cache key for storing the result based on the
  7528. * arguments provided to the memoized function. By default, the first argument
  7529. * provided to the memoized function is coerced to a string and used as the
  7530. * cache key. The `func` is invoked with the `this` binding of the memoized
  7531. * function.
  7532. *
  7533. * **Note:** The cache is exposed as the `cache` property on the memoized
  7534. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  7535. * constructor with one whose instances implement the [`Map`](http://ecma-international.org/ecma-262/6.0/#sec-properties-of-the-map-prototype-object)
  7536. * method interface of `get`, `has`, and `set`.
  7537. *
  7538. * @static
  7539. * @memberOf _
  7540. * @category Function
  7541. * @param {Function} func The function to have its output memoized.
  7542. * @param {Function} [resolver] The function to resolve the cache key.
  7543. * @returns {Function} Returns the new memoizing function.
  7544. * @example
  7545. *
  7546. * var upperCase = _.memoize(function(string) {
  7547. * return string.toUpperCase();
  7548. * });
  7549. *
  7550. * upperCase('fred');
  7551. * // => 'FRED'
  7552. *
  7553. * // modifying the result cache
  7554. * upperCase.cache.set('fred', 'BARNEY');
  7555. * upperCase('fred');
  7556. * // => 'BARNEY'
  7557. *
  7558. * // replacing `_.memoize.Cache`
  7559. * var object = { 'user': 'fred' };
  7560. * var other = { 'user': 'barney' };
  7561. * var identity = _.memoize(_.identity);
  7562. *
  7563. * identity(object);
  7564. * // => { 'user': 'fred' }
  7565. * identity(other);
  7566. * // => { 'user': 'fred' }
  7567. *
  7568. * _.memoize.Cache = WeakMap;
  7569. * var identity = _.memoize(_.identity);
  7570. *
  7571. * identity(object);
  7572. * // => { 'user': 'fred' }
  7573. * identity(other);
  7574. * // => { 'user': 'barney' }
  7575. */
  7576. function memoize(func, resolver) {
  7577. if (typeof func != 'function' || (resolver && typeof resolver != 'function')) {
  7578. throw new TypeError(FUNC_ERROR_TEXT);
  7579. }
  7580. var memoized = function() {
  7581. var args = arguments,
  7582. key = resolver ? resolver.apply(this, args) : args[0],
  7583. cache = memoized.cache;
  7584. if (cache.has(key)) {
  7585. return cache.get(key);
  7586. }
  7587. var result = func.apply(this, args);
  7588. memoized.cache = cache.set(key, result);
  7589. return result;
  7590. };
  7591. memoized.cache = new memoize.Cache;
  7592. return memoized;
  7593. }
  7594. /**
  7595. * Creates a function that runs each argument through a corresponding
  7596. * transform function.
  7597. *
  7598. * @static
  7599. * @memberOf _
  7600. * @category Function
  7601. * @param {Function} func The function to wrap.
  7602. * @param {...(Function|Function[])} [transforms] The functions to transform
  7603. * arguments, specified as individual functions or arrays of functions.
  7604. * @returns {Function} Returns the new function.
  7605. * @example
  7606. *
  7607. * function doubled(n) {
  7608. * return n * 2;
  7609. * }
  7610. *
  7611. * function square(n) {
  7612. * return n * n;
  7613. * }
  7614. *
  7615. * var modded = _.modArgs(function(x, y) {
  7616. * return [x, y];
  7617. * }, square, doubled);
  7618. *
  7619. * modded(1, 2);
  7620. * // => [1, 4]
  7621. *
  7622. * modded(5, 10);
  7623. * // => [25, 20]
  7624. */
  7625. var modArgs = restParam(function(func, transforms) {
  7626. transforms = baseFlatten(transforms);
  7627. if (typeof func != 'function' || !arrayEvery(transforms, baseIsFunction)) {
  7628. throw new TypeError(FUNC_ERROR_TEXT);
  7629. }
  7630. var length = transforms.length;
  7631. return restParam(function(args) {
  7632. var index = nativeMin(args.length, length);
  7633. while (index--) {
  7634. args[index] = transforms[index](args[index]);
  7635. }
  7636. return func.apply(this, args);
  7637. });
  7638. });
  7639. /**
  7640. * Creates a function that negates the result of the predicate `func`. The
  7641. * `func` predicate is invoked with the `this` binding and arguments of the
  7642. * created function.
  7643. *
  7644. * @static
  7645. * @memberOf _
  7646. * @category Function
  7647. * @param {Function} predicate The predicate to negate.
  7648. * @returns {Function} Returns the new function.
  7649. * @example
  7650. *
  7651. * function isEven(n) {
  7652. * return n % 2 == 0;
  7653. * }
  7654. *
  7655. * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven));
  7656. * // => [1, 3, 5]
  7657. */
  7658. function negate(predicate) {
  7659. if (typeof predicate != 'function') {
  7660. throw new TypeError(FUNC_ERROR_TEXT);
  7661. }
  7662. return function() {
  7663. return !predicate.apply(this, arguments);
  7664. };
  7665. }
  7666. /**
  7667. * Creates a function that is restricted to invoking `func` once. Repeat calls
  7668. * to the function return the value of the first call. The `func` is invoked
  7669. * with the `this` binding and arguments of the created function.
  7670. *
  7671. * @static
  7672. * @memberOf _
  7673. * @category Function
  7674. * @param {Function} func The function to restrict.
  7675. * @returns {Function} Returns the new restricted function.
  7676. * @example
  7677. *
  7678. * var initialize = _.once(createApplication);
  7679. * initialize();
  7680. * initialize();
  7681. * // `initialize` invokes `createApplication` once
  7682. */
  7683. function once(func) {
  7684. return before(2, func);
  7685. }
  7686. /**
  7687. * Creates a function that invokes `func` with `partial` arguments prepended
  7688. * to those provided to the new function. This method is like `_.bind` except
  7689. * it does **not** alter the `this` binding.
  7690. *
  7691. * The `_.partial.placeholder` value, which defaults to `_` in monolithic
  7692. * builds, may be used as a placeholder for partially applied arguments.
  7693. *
  7694. * **Note:** This method does not set the "length" property of partially
  7695. * applied functions.
  7696. *
  7697. * @static
  7698. * @memberOf _
  7699. * @category Function
  7700. * @param {Function} func The function to partially apply arguments to.
  7701. * @param {...*} [partials] The arguments to be partially applied.
  7702. * @returns {Function} Returns the new partially applied function.
  7703. * @example
  7704. *
  7705. * var greet = function(greeting, name) {
  7706. * return greeting + ' ' + name;
  7707. * };
  7708. *
  7709. * var sayHelloTo = _.partial(greet, 'hello');
  7710. * sayHelloTo('fred');
  7711. * // => 'hello fred'
  7712. *
  7713. * // using placeholders
  7714. * var greetFred = _.partial(greet, _, 'fred');
  7715. * greetFred('hi');
  7716. * // => 'hi fred'
  7717. */
  7718. var partial = createPartial(PARTIAL_FLAG);
  7719. /**
  7720. * This method is like `_.partial` except that partially applied arguments
  7721. * are appended to those provided to the new function.
  7722. *
  7723. * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic
  7724. * builds, may be used as a placeholder for partially applied arguments.
  7725. *
  7726. * **Note:** This method does not set the "length" property of partially
  7727. * applied functions.
  7728. *
  7729. * @static
  7730. * @memberOf _
  7731. * @category Function
  7732. * @param {Function} func The function to partially apply arguments to.
  7733. * @param {...*} [partials] The arguments to be partially applied.
  7734. * @returns {Function} Returns the new partially applied function.
  7735. * @example
  7736. *
  7737. * var greet = function(greeting, name) {
  7738. * return greeting + ' ' + name;
  7739. * };
  7740. *
  7741. * var greetFred = _.partialRight(greet, 'fred');
  7742. * greetFred('hi');
  7743. * // => 'hi fred'
  7744. *
  7745. * // using placeholders
  7746. * var sayHelloTo = _.partialRight(greet, 'hello', _);
  7747. * sayHelloTo('fred');
  7748. * // => 'hello fred'
  7749. */
  7750. var partialRight = createPartial(PARTIAL_RIGHT_FLAG);
  7751. /**
  7752. * Creates a function that invokes `func` with arguments arranged according
  7753. * to the specified indexes where the argument value at the first index is
  7754. * provided as the first argument, the argument value at the second index is
  7755. * provided as the second argument, and so on.
  7756. *
  7757. * @static
  7758. * @memberOf _
  7759. * @category Function
  7760. * @param {Function} func The function to rearrange arguments for.
  7761. * @param {...(number|number[])} indexes The arranged argument indexes,
  7762. * specified as individual indexes or arrays of indexes.
  7763. * @returns {Function} Returns the new function.
  7764. * @example
  7765. *
  7766. * var rearged = _.rearg(function(a, b, c) {
  7767. * return [a, b, c];
  7768. * }, 2, 0, 1);
  7769. *
  7770. * rearged('b', 'c', 'a')
  7771. * // => ['a', 'b', 'c']
  7772. *
  7773. * var map = _.rearg(_.map, [1, 0]);
  7774. * map(function(n) {
  7775. * return n * 3;
  7776. * }, [1, 2, 3]);
  7777. * // => [3, 6, 9]
  7778. */
  7779. var rearg = restParam(function(func, indexes) {
  7780. return createWrapper(func, REARG_FLAG, undefined, undefined, undefined, baseFlatten(indexes));
  7781. });
  7782. /**
  7783. * Creates a function that invokes `func` with the `this` binding of the
  7784. * created function and arguments from `start` and beyond provided as an array.
  7785. *
  7786. * **Note:** This method is based on the [rest parameter](https://developer.mozilla.org/Web/JavaScript/Reference/Functions/rest_parameters).
  7787. *
  7788. * @static
  7789. * @memberOf _
  7790. * @category Function
  7791. * @param {Function} func The function to apply a rest parameter to.
  7792. * @param {number} [start=func.length-1] The start position of the rest parameter.
  7793. * @returns {Function} Returns the new function.
  7794. * @example
  7795. *
  7796. * var say = _.restParam(function(what, names) {
  7797. * return what + ' ' + _.initial(names).join(', ') +
  7798. * (_.size(names) > 1 ? ', & ' : '') + _.last(names);
  7799. * });
  7800. *
  7801. * say('hello', 'fred', 'barney', 'pebbles');
  7802. * // => 'hello fred, barney, & pebbles'
  7803. */
  7804. function restParam(func, start) {
  7805. if (typeof func != 'function') {
  7806. throw new TypeError(FUNC_ERROR_TEXT);
  7807. }
  7808. start = nativeMax(start === undefined ? (func.length - 1) : (+start || 0), 0);
  7809. return function() {
  7810. var args = arguments,
  7811. index = -1,
  7812. length = nativeMax(args.length - start, 0),
  7813. rest = Array(length);
  7814. while (++index < length) {
  7815. rest[index] = args[start + index];
  7816. }
  7817. switch (start) {
  7818. case 0: return func.call(this, rest);
  7819. case 1: return func.call(this, args[0], rest);
  7820. case 2: return func.call(this, args[0], args[1], rest);
  7821. }
  7822. var otherArgs = Array(start + 1);
  7823. index = -1;
  7824. while (++index < start) {
  7825. otherArgs[index] = args[index];
  7826. }
  7827. otherArgs[start] = rest;
  7828. return func.apply(this, otherArgs);
  7829. };
  7830. }
  7831. /**
  7832. * Creates a function that invokes `func` with the `this` binding of the created
  7833. * function and an array of arguments much like [`Function#apply`](https://es5.github.io/#x15.3.4.3).
  7834. *
  7835. * **Note:** This method is based on the [spread operator](https://developer.mozilla.org/Web/JavaScript/Reference/Operators/Spread_operator).
  7836. *
  7837. * @static
  7838. * @memberOf _
  7839. * @category Function
  7840. * @param {Function} func The function to spread arguments over.
  7841. * @returns {Function} Returns the new function.
  7842. * @example
  7843. *
  7844. * var say = _.spread(function(who, what) {
  7845. * return who + ' says ' + what;
  7846. * });
  7847. *
  7848. * say(['fred', 'hello']);
  7849. * // => 'fred says hello'
  7850. *
  7851. * // with a Promise
  7852. * var numbers = Promise.all([
  7853. * Promise.resolve(40),
  7854. * Promise.resolve(36)
  7855. * ]);
  7856. *
  7857. * numbers.then(_.spread(function(x, y) {
  7858. * return x + y;
  7859. * }));
  7860. * // => a Promise of 76
  7861. */
  7862. function spread(func) {
  7863. if (typeof func != 'function') {
  7864. throw new TypeError(FUNC_ERROR_TEXT);
  7865. }
  7866. return function(array) {
  7867. return func.apply(this, array);
  7868. };
  7869. }
  7870. /**
  7871. * Creates a throttled function that only invokes `func` at most once per
  7872. * every `wait` milliseconds. The throttled function comes with a `cancel`
  7873. * method to cancel delayed invocations. Provide an options object to indicate
  7874. * that `func` should be invoked on the leading and/or trailing edge of the
  7875. * `wait` timeout. Subsequent calls to the throttled function return the
  7876. * result of the last `func` call.
  7877. *
  7878. * **Note:** If `leading` and `trailing` options are `true`, `func` is invoked
  7879. * on the trailing edge of the timeout only if the the throttled function is
  7880. * invoked more than once during the `wait` timeout.
  7881. *
  7882. * See [David Corbacho's article](http://drupalmotion.com/article/debounce-and-throttle-visual-explanation)
  7883. * for details over the differences between `_.throttle` and `_.debounce`.
  7884. *
  7885. * @static
  7886. * @memberOf _
  7887. * @category Function
  7888. * @param {Function} func The function to throttle.
  7889. * @param {number} [wait=0] The number of milliseconds to throttle invocations to.
  7890. * @param {Object} [options] The options object.
  7891. * @param {boolean} [options.leading=true] Specify invoking on the leading
  7892. * edge of the timeout.
  7893. * @param {boolean} [options.trailing=true] Specify invoking on the trailing
  7894. * edge of the timeout.
  7895. * @returns {Function} Returns the new throttled function.
  7896. * @example
  7897. *
  7898. * // avoid excessively updating the position while scrolling
  7899. * jQuery(window).on('scroll', _.throttle(updatePosition, 100));
  7900. *
  7901. * // invoke `renewToken` when the click event is fired, but not more than once every 5 minutes
  7902. * jQuery('.interactive').on('click', _.throttle(renewToken, 300000, {
  7903. * 'trailing': false
  7904. * }));
  7905. *
  7906. * // cancel a trailing throttled call
  7907. * jQuery(window).on('popstate', throttled.cancel);
  7908. */
  7909. function throttle(func, wait, options) {
  7910. var leading = true,
  7911. trailing = true;
  7912. if (typeof func != 'function') {
  7913. throw new TypeError(FUNC_ERROR_TEXT);
  7914. }
  7915. if (options === false) {
  7916. leading = false;
  7917. } else if (isObject(options)) {
  7918. leading = 'leading' in options ? !!options.leading : leading;
  7919. trailing = 'trailing' in options ? !!options.trailing : trailing;
  7920. }
  7921. return debounce(func, wait, { 'leading': leading, 'maxWait': +wait, 'trailing': trailing });
  7922. }
  7923. /**
  7924. * Creates a function that provides `value` to the wrapper function as its
  7925. * first argument. Any additional arguments provided to the function are
  7926. * appended to those provided to the wrapper function. The wrapper is invoked
  7927. * with the `this` binding of the created function.
  7928. *
  7929. * @static
  7930. * @memberOf _
  7931. * @category Function
  7932. * @param {*} value The value to wrap.
  7933. * @param {Function} wrapper The wrapper function.
  7934. * @returns {Function} Returns the new function.
  7935. * @example
  7936. *
  7937. * var p = _.wrap(_.escape, function(func, text) {
  7938. * return '<p>' + func(text) + '</p>';
  7939. * });
  7940. *
  7941. * p('fred, barney, & pebbles');
  7942. * // => '<p>fred, barney, &amp; pebbles</p>'
  7943. */
  7944. function wrap(value, wrapper) {
  7945. wrapper = wrapper == null ? identity : wrapper;
  7946. return createWrapper(wrapper, PARTIAL_FLAG, undefined, [value], []);
  7947. }
  7948. /*------------------------------------------------------------------------*/
  7949. /**
  7950. * Creates a clone of `value`. If `isDeep` is `true` nested objects are cloned,
  7951. * otherwise they are assigned by reference. If `customizer` is provided it's
  7952. * invoked to produce the cloned values. If `customizer` returns `undefined`
  7953. * cloning is handled by the method instead. The `customizer` is bound to
  7954. * `thisArg` and invoked with up to three argument; (value [, index|key, object]).
  7955. *
  7956. * **Note:** This method is loosely based on the
  7957. * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
  7958. * The enumerable properties of `arguments` objects and objects created by
  7959. * constructors other than `Object` are cloned to plain `Object` objects. An
  7960. * empty object is returned for uncloneable values such as functions, DOM nodes,
  7961. * Maps, Sets, and WeakMaps.
  7962. *
  7963. * @static
  7964. * @memberOf _
  7965. * @category Lang
  7966. * @param {*} value The value to clone.
  7967. * @param {boolean} [isDeep] Specify a deep clone.
  7968. * @param {Function} [customizer] The function to customize cloning values.
  7969. * @param {*} [thisArg] The `this` binding of `customizer`.
  7970. * @returns {*} Returns the cloned value.
  7971. * @example
  7972. *
  7973. * var users = [
  7974. * { 'user': 'barney' },
  7975. * { 'user': 'fred' }
  7976. * ];
  7977. *
  7978. * var shallow = _.clone(users);
  7979. * shallow[0] === users[0];
  7980. * // => true
  7981. *
  7982. * var deep = _.clone(users, true);
  7983. * deep[0] === users[0];
  7984. * // => false
  7985. *
  7986. * // using a customizer callback
  7987. * var el = _.clone(document.body, function(value) {
  7988. * if (_.isElement(value)) {
  7989. * return value.cloneNode(false);
  7990. * }
  7991. * });
  7992. *
  7993. * el === document.body
  7994. * // => false
  7995. * el.nodeName
  7996. * // => BODY
  7997. * el.childNodes.length;
  7998. * // => 0
  7999. */
  8000. function clone(value, isDeep, customizer, thisArg) {
  8001. if (isDeep && typeof isDeep != 'boolean' && isIterateeCall(value, isDeep, customizer)) {
  8002. isDeep = false;
  8003. }
  8004. else if (typeof isDeep == 'function') {
  8005. thisArg = customizer;
  8006. customizer = isDeep;
  8007. isDeep = false;
  8008. }
  8009. return typeof customizer == 'function'
  8010. ? baseClone(value, isDeep, bindCallback(customizer, thisArg, 3))
  8011. : baseClone(value, isDeep);
  8012. }
  8013. /**
  8014. * Creates a deep clone of `value`. If `customizer` is provided it's invoked
  8015. * to produce the cloned values. If `customizer` returns `undefined` cloning
  8016. * is handled by the method instead. The `customizer` is bound to `thisArg`
  8017. * and invoked with up to three argument; (value [, index|key, object]).
  8018. *
  8019. * **Note:** This method is loosely based on the
  8020. * [structured clone algorithm](http://www.w3.org/TR/html5/infrastructure.html#internal-structured-cloning-algorithm).
  8021. * The enumerable properties of `arguments` objects and objects created by
  8022. * constructors other than `Object` are cloned to plain `Object` objects. An
  8023. * empty object is returned for uncloneable values such as functions, DOM nodes,
  8024. * Maps, Sets, and WeakMaps.
  8025. *
  8026. * @static
  8027. * @memberOf _
  8028. * @category Lang
  8029. * @param {*} value The value to deep clone.
  8030. * @param {Function} [customizer] The function to customize cloning values.
  8031. * @param {*} [thisArg] The `this` binding of `customizer`.
  8032. * @returns {*} Returns the deep cloned value.
  8033. * @example
  8034. *
  8035. * var users = [
  8036. * { 'user': 'barney' },
  8037. * { 'user': 'fred' }
  8038. * ];
  8039. *
  8040. * var deep = _.cloneDeep(users);
  8041. * deep[0] === users[0];
  8042. * // => false
  8043. *
  8044. * // using a customizer callback
  8045. * var el = _.cloneDeep(document.body, function(value) {
  8046. * if (_.isElement(value)) {
  8047. * return value.cloneNode(true);
  8048. * }
  8049. * });
  8050. *
  8051. * el === document.body
  8052. * // => false
  8053. * el.nodeName
  8054. * // => BODY
  8055. * el.childNodes.length;
  8056. * // => 20
  8057. */
  8058. function cloneDeep(value, customizer, thisArg) {
  8059. return typeof customizer == 'function'
  8060. ? baseClone(value, true, bindCallback(customizer, thisArg, 3))
  8061. : baseClone(value, true);
  8062. }
  8063. /**
  8064. * Checks if `value` is greater than `other`.
  8065. *
  8066. * @static
  8067. * @memberOf _
  8068. * @category Lang
  8069. * @param {*} value The value to compare.
  8070. * @param {*} other The other value to compare.
  8071. * @returns {boolean} Returns `true` if `value` is greater than `other`, else `false`.
  8072. * @example
  8073. *
  8074. * _.gt(3, 1);
  8075. * // => true
  8076. *
  8077. * _.gt(3, 3);
  8078. * // => false
  8079. *
  8080. * _.gt(1, 3);
  8081. * // => false
  8082. */
  8083. function gt(value, other) {
  8084. return value > other;
  8085. }
  8086. /**
  8087. * Checks if `value` is greater than or equal to `other`.
  8088. *
  8089. * @static
  8090. * @memberOf _
  8091. * @category Lang
  8092. * @param {*} value The value to compare.
  8093. * @param {*} other The other value to compare.
  8094. * @returns {boolean} Returns `true` if `value` is greater than or equal to `other`, else `false`.
  8095. * @example
  8096. *
  8097. * _.gte(3, 1);
  8098. * // => true
  8099. *
  8100. * _.gte(3, 3);
  8101. * // => true
  8102. *
  8103. * _.gte(1, 3);
  8104. * // => false
  8105. */
  8106. function gte(value, other) {
  8107. return value >= other;
  8108. }
  8109. /**
  8110. * Checks if `value` is classified as an `arguments` object.
  8111. *
  8112. * @static
  8113. * @memberOf _
  8114. * @category Lang
  8115. * @param {*} value The value to check.
  8116. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8117. * @example
  8118. *
  8119. * _.isArguments(function() { return arguments; }());
  8120. * // => true
  8121. *
  8122. * _.isArguments([1, 2, 3]);
  8123. * // => false
  8124. */
  8125. function isArguments(value) {
  8126. return isObjectLike(value) && isArrayLike(value) &&
  8127. hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
  8128. }
  8129. /**
  8130. * Checks if `value` is classified as an `Array` object.
  8131. *
  8132. * @static
  8133. * @memberOf _
  8134. * @category Lang
  8135. * @param {*} value The value to check.
  8136. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8137. * @example
  8138. *
  8139. * _.isArray([1, 2, 3]);
  8140. * // => true
  8141. *
  8142. * _.isArray(function() { return arguments; }());
  8143. * // => false
  8144. */
  8145. var isArray = nativeIsArray || function(value) {
  8146. return isObjectLike(value) && isLength(value.length) && objToString.call(value) == arrayTag;
  8147. };
  8148. /**
  8149. * Checks if `value` is classified as a boolean primitive or object.
  8150. *
  8151. * @static
  8152. * @memberOf _
  8153. * @category Lang
  8154. * @param {*} value The value to check.
  8155. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8156. * @example
  8157. *
  8158. * _.isBoolean(false);
  8159. * // => true
  8160. *
  8161. * _.isBoolean(null);
  8162. * // => false
  8163. */
  8164. function isBoolean(value) {
  8165. return value === true || value === false || (isObjectLike(value) && objToString.call(value) == boolTag);
  8166. }
  8167. /**
  8168. * Checks if `value` is classified as a `Date` object.
  8169. *
  8170. * @static
  8171. * @memberOf _
  8172. * @category Lang
  8173. * @param {*} value The value to check.
  8174. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8175. * @example
  8176. *
  8177. * _.isDate(new Date);
  8178. * // => true
  8179. *
  8180. * _.isDate('Mon April 23 2012');
  8181. * // => false
  8182. */
  8183. function isDate(value) {
  8184. return isObjectLike(value) && objToString.call(value) == dateTag;
  8185. }
  8186. /**
  8187. * Checks if `value` is a DOM element.
  8188. *
  8189. * @static
  8190. * @memberOf _
  8191. * @category Lang
  8192. * @param {*} value The value to check.
  8193. * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`.
  8194. * @example
  8195. *
  8196. * _.isElement(document.body);
  8197. * // => true
  8198. *
  8199. * _.isElement('<body>');
  8200. * // => false
  8201. */
  8202. function isElement(value) {
  8203. return !!value && value.nodeType === 1 && isObjectLike(value) && !isPlainObject(value);
  8204. }
  8205. /**
  8206. * Checks if `value` is empty. A value is considered empty unless it's an
  8207. * `arguments` object, array, string, or jQuery-like collection with a length
  8208. * greater than `0` or an object with own enumerable properties.
  8209. *
  8210. * @static
  8211. * @memberOf _
  8212. * @category Lang
  8213. * @param {Array|Object|string} value The value to inspect.
  8214. * @returns {boolean} Returns `true` if `value` is empty, else `false`.
  8215. * @example
  8216. *
  8217. * _.isEmpty(null);
  8218. * // => true
  8219. *
  8220. * _.isEmpty(true);
  8221. * // => true
  8222. *
  8223. * _.isEmpty(1);
  8224. * // => true
  8225. *
  8226. * _.isEmpty([1, 2, 3]);
  8227. * // => false
  8228. *
  8229. * _.isEmpty({ 'a': 1 });
  8230. * // => false
  8231. */
  8232. function isEmpty(value) {
  8233. if (value == null) {
  8234. return true;
  8235. }
  8236. if (isArrayLike(value) && (isArray(value) || isString(value) || isArguments(value) ||
  8237. (isObjectLike(value) && isFunction(value.splice)))) {
  8238. return !value.length;
  8239. }
  8240. return !keys(value).length;
  8241. }
  8242. /**
  8243. * Performs a deep comparison between two values to determine if they are
  8244. * equivalent. If `customizer` is provided it's invoked to compare values.
  8245. * If `customizer` returns `undefined` comparisons are handled by the method
  8246. * instead. The `customizer` is bound to `thisArg` and invoked with up to
  8247. * three arguments: (value, other [, index|key]).
  8248. *
  8249. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  8250. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  8251. * their own, not inherited, enumerable properties. Functions and DOM nodes
  8252. * are **not** supported. Provide a customizer function to extend support
  8253. * for comparing other values.
  8254. *
  8255. * @static
  8256. * @memberOf _
  8257. * @alias eq
  8258. * @category Lang
  8259. * @param {*} value The value to compare.
  8260. * @param {*} other The other value to compare.
  8261. * @param {Function} [customizer] The function to customize value comparisons.
  8262. * @param {*} [thisArg] The `this` binding of `customizer`.
  8263. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  8264. * @example
  8265. *
  8266. * var object = { 'user': 'fred' };
  8267. * var other = { 'user': 'fred' };
  8268. *
  8269. * object == other;
  8270. * // => false
  8271. *
  8272. * _.isEqual(object, other);
  8273. * // => true
  8274. *
  8275. * // using a customizer callback
  8276. * var array = ['hello', 'goodbye'];
  8277. * var other = ['hi', 'goodbye'];
  8278. *
  8279. * _.isEqual(array, other, function(value, other) {
  8280. * if (_.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/)) {
  8281. * return true;
  8282. * }
  8283. * });
  8284. * // => true
  8285. */
  8286. function isEqual(value, other, customizer, thisArg) {
  8287. customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
  8288. var result = customizer ? customizer(value, other) : undefined;
  8289. return result === undefined ? baseIsEqual(value, other, customizer) : !!result;
  8290. }
  8291. /**
  8292. * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`,
  8293. * `SyntaxError`, `TypeError`, or `URIError` object.
  8294. *
  8295. * @static
  8296. * @memberOf _
  8297. * @category Lang
  8298. * @param {*} value The value to check.
  8299. * @returns {boolean} Returns `true` if `value` is an error object, else `false`.
  8300. * @example
  8301. *
  8302. * _.isError(new Error);
  8303. * // => true
  8304. *
  8305. * _.isError(Error);
  8306. * // => false
  8307. */
  8308. function isError(value) {
  8309. return isObjectLike(value) && typeof value.message == 'string' && objToString.call(value) == errorTag;
  8310. }
  8311. /**
  8312. * Checks if `value` is a finite primitive number.
  8313. *
  8314. * **Note:** This method is based on [`Number.isFinite`](http://ecma-international.org/ecma-262/6.0/#sec-number.isfinite).
  8315. *
  8316. * @static
  8317. * @memberOf _
  8318. * @category Lang
  8319. * @param {*} value The value to check.
  8320. * @returns {boolean} Returns `true` if `value` is a finite number, else `false`.
  8321. * @example
  8322. *
  8323. * _.isFinite(10);
  8324. * // => true
  8325. *
  8326. * _.isFinite('10');
  8327. * // => false
  8328. *
  8329. * _.isFinite(true);
  8330. * // => false
  8331. *
  8332. * _.isFinite(Object(10));
  8333. * // => false
  8334. *
  8335. * _.isFinite(Infinity);
  8336. * // => false
  8337. */
  8338. function isFinite(value) {
  8339. return typeof value == 'number' && nativeIsFinite(value);
  8340. }
  8341. /**
  8342. * Checks if `value` is classified as a `Function` object.
  8343. *
  8344. * @static
  8345. * @memberOf _
  8346. * @category Lang
  8347. * @param {*} value The value to check.
  8348. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8349. * @example
  8350. *
  8351. * _.isFunction(_);
  8352. * // => true
  8353. *
  8354. * _.isFunction(/abc/);
  8355. * // => false
  8356. */
  8357. function isFunction(value) {
  8358. if (!isObject(value)) {
  8359. return false;
  8360. }//--•
  8361. // The use of `Object#toString` avoids issues with the `typeof` operator
  8362. // in older versions of Chrome and Safari which return 'function' for regexes
  8363. // and Safari 8 which returns 'object' for typed array constructors.
  8364. var tag = objToString.call(value);
  8365. // Return true if this looks like a function, an "async function", a "generator", or a "proxy".
  8366. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  8367. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8368. // ^^^^
  8369. // PATCHED FROM https://github.com/lodash/lodash/commit/95bc54a3ddc7a25f5e134f5b376a0d1d96118f49
  8370. // Note that, in Lodash 4, this looks like:
  8371. // ```
  8372. // return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  8373. // ```
  8374. // - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  8375. }
  8376. /**
  8377. * Checks if `value` is the [language type](https://es5.github.io/#x8) of `Object`.
  8378. * (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  8379. *
  8380. * @static
  8381. * @memberOf _
  8382. * @category Lang
  8383. * @param {*} value The value to check.
  8384. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  8385. * @example
  8386. *
  8387. * _.isObject({});
  8388. * // => true
  8389. *
  8390. * _.isObject([1, 2, 3]);
  8391. * // => true
  8392. *
  8393. * _.isObject(1);
  8394. * // => false
  8395. */
  8396. function isObject(value) {
  8397. // Avoid a V8 JIT bug in Chrome 19-20.
  8398. // See https://code.google.com/p/v8/issues/detail?id=2291 for more details.
  8399. var type = typeof value;
  8400. return !!value && (type == 'object' || type == 'function');
  8401. }
  8402. /**
  8403. * Performs a deep comparison between `object` and `source` to determine if
  8404. * `object` contains equivalent property values. If `customizer` is provided
  8405. * it's invoked to compare values. If `customizer` returns `undefined`
  8406. * comparisons are handled by the method instead. The `customizer` is bound
  8407. * to `thisArg` and invoked with three arguments: (value, other, index|key).
  8408. *
  8409. * **Note:** This method supports comparing properties of arrays, booleans,
  8410. * `Date` objects, numbers, `Object` objects, regexes, and strings. Functions
  8411. * and DOM nodes are **not** supported. Provide a customizer function to extend
  8412. * support for comparing other values.
  8413. *
  8414. * @static
  8415. * @memberOf _
  8416. * @category Lang
  8417. * @param {Object} object The object to inspect.
  8418. * @param {Object} source The object of property values to match.
  8419. * @param {Function} [customizer] The function to customize value comparisons.
  8420. * @param {*} [thisArg] The `this` binding of `customizer`.
  8421. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  8422. * @example
  8423. *
  8424. * var object = { 'user': 'fred', 'age': 40 };
  8425. *
  8426. * _.isMatch(object, { 'age': 40 });
  8427. * // => true
  8428. *
  8429. * _.isMatch(object, { 'age': 36 });
  8430. * // => false
  8431. *
  8432. * // using a customizer callback
  8433. * var object = { 'greeting': 'hello' };
  8434. * var source = { 'greeting': 'hi' };
  8435. *
  8436. * _.isMatch(object, source, function(value, other) {
  8437. * return _.every([value, other], RegExp.prototype.test, /^h(?:i|ello)$/) || undefined;
  8438. * });
  8439. * // => true
  8440. */
  8441. function isMatch(object, source, customizer, thisArg) {
  8442. customizer = typeof customizer == 'function' ? bindCallback(customizer, thisArg, 3) : undefined;
  8443. return baseIsMatch(object, getMatchData(source), customizer);
  8444. }
  8445. /**
  8446. * Checks if `value` is `NaN`.
  8447. *
  8448. * **Note:** This method is not the same as [`isNaN`](https://es5.github.io/#x15.1.2.4)
  8449. * which returns `true` for `undefined` and other non-numeric values.
  8450. *
  8451. * @static
  8452. * @memberOf _
  8453. * @category Lang
  8454. * @param {*} value The value to check.
  8455. * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`.
  8456. * @example
  8457. *
  8458. * _.isNaN(NaN);
  8459. * // => true
  8460. *
  8461. * _.isNaN(new Number(NaN));
  8462. * // => true
  8463. *
  8464. * isNaN(undefined);
  8465. * // => true
  8466. *
  8467. * _.isNaN(undefined);
  8468. * // => false
  8469. */
  8470. function isNaN(value) {
  8471. // An `NaN` primitive is the only value that is not equal to itself.
  8472. // Perform the `toStringTag` check first to avoid errors with some host objects in IE.
  8473. return isNumber(value) && value != +value;
  8474. }
  8475. /**
  8476. * Checks if `value` is a native function.
  8477. *
  8478. * @static
  8479. * @memberOf _
  8480. * @category Lang
  8481. * @param {*} value The value to check.
  8482. * @returns {boolean} Returns `true` if `value` is a native function, else `false`.
  8483. * @example
  8484. *
  8485. * _.isNative(Array.prototype.push);
  8486. * // => true
  8487. *
  8488. * _.isNative(_);
  8489. * // => false
  8490. */
  8491. function isNative(value) {
  8492. if (value == null) {
  8493. return false;
  8494. }
  8495. if (isFunction(value)) {
  8496. return reIsNative.test(fnToString.call(value));
  8497. }
  8498. return isObjectLike(value) && (isHostObject(value) ? reIsNative : reIsHostCtor).test(value);
  8499. }
  8500. /**
  8501. * Checks if `value` is `null`.
  8502. *
  8503. * @static
  8504. * @memberOf _
  8505. * @category Lang
  8506. * @param {*} value The value to check.
  8507. * @returns {boolean} Returns `true` if `value` is `null`, else `false`.
  8508. * @example
  8509. *
  8510. * _.isNull(null);
  8511. * // => true
  8512. *
  8513. * _.isNull(void 0);
  8514. * // => false
  8515. */
  8516. function isNull(value) {
  8517. return value === null;
  8518. }
  8519. /**
  8520. * Checks if `value` is classified as a `Number` primitive or object.
  8521. *
  8522. * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are classified
  8523. * as numbers, use the `_.isFinite` method.
  8524. *
  8525. * @static
  8526. * @memberOf _
  8527. * @category Lang
  8528. * @param {*} value The value to check.
  8529. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8530. * @example
  8531. *
  8532. * _.isNumber(8.4);
  8533. * // => true
  8534. *
  8535. * _.isNumber(NaN);
  8536. * // => true
  8537. *
  8538. * _.isNumber('8.4');
  8539. * // => false
  8540. */
  8541. function isNumber(value) {
  8542. return typeof value == 'number' || (isObjectLike(value) && objToString.call(value) == numberTag);
  8543. }
  8544. /**
  8545. * Checks if `value` is a plain object, that is, an object created by the
  8546. * `Object` constructor or one with a `[[Prototype]]` of `null`.
  8547. *
  8548. * **Note:** This method assumes objects created by the `Object` constructor
  8549. * have no inherited enumerable properties.
  8550. *
  8551. * @static
  8552. * @memberOf _
  8553. * @category Lang
  8554. * @param {*} value The value to check.
  8555. * @returns {boolean} Returns `true` if `value` is a plain object, else `false`.
  8556. * @example
  8557. *
  8558. * function Foo() {
  8559. * this.a = 1;
  8560. * }
  8561. *
  8562. * _.isPlainObject(new Foo);
  8563. * // => false
  8564. *
  8565. * _.isPlainObject([1, 2, 3]);
  8566. * // => false
  8567. *
  8568. * _.isPlainObject({ 'x': 0, 'y': 0 });
  8569. * // => true
  8570. *
  8571. * _.isPlainObject(Object.create(null));
  8572. * // => true
  8573. */
  8574. function isPlainObject(value) {
  8575. var Ctor;
  8576. // Exit early for non `Object` objects.
  8577. if (!(isObjectLike(value) && objToString.call(value) == objectTag && !isHostObject(value) && !isArguments(value)) ||
  8578. (!hasOwnProperty.call(value, 'constructor') && (Ctor = value.constructor, typeof Ctor == 'function' && !(Ctor instanceof Ctor)))) {
  8579. return false;
  8580. }
  8581. // IE < 9 iterates inherited properties before own properties. If the first
  8582. // iterated property is an object's own property then there are no inherited
  8583. // enumerable properties.
  8584. var result;
  8585. if (lodash.support.ownLast) {
  8586. baseForIn(value, function(subValue, key, object) {
  8587. result = hasOwnProperty.call(object, key);
  8588. return false;
  8589. });
  8590. return result !== false;
  8591. }
  8592. // In most environments an object's own properties are iterated before
  8593. // its inherited properties. If the last iterated property is an object's
  8594. // own property then there are no inherited enumerable properties.
  8595. baseForIn(value, function(subValue, key) {
  8596. result = key;
  8597. });
  8598. return result === undefined || hasOwnProperty.call(value, result);
  8599. }
  8600. /**
  8601. * Checks if `value` is classified as a `RegExp` object.
  8602. *
  8603. * @static
  8604. * @memberOf _
  8605. * @category Lang
  8606. * @param {*} value The value to check.
  8607. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8608. * @example
  8609. *
  8610. * _.isRegExp(/abc/);
  8611. * // => true
  8612. *
  8613. * _.isRegExp('/abc/');
  8614. * // => false
  8615. */
  8616. function isRegExp(value) {
  8617. return isObject(value) && objToString.call(value) == regexpTag;
  8618. }
  8619. /**
  8620. * Checks if `value` is classified as a `String` primitive or object.
  8621. *
  8622. * @static
  8623. * @memberOf _
  8624. * @category Lang
  8625. * @param {*} value The value to check.
  8626. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8627. * @example
  8628. *
  8629. * _.isString('abc');
  8630. * // => true
  8631. *
  8632. * _.isString(1);
  8633. * // => false
  8634. */
  8635. function isString(value) {
  8636. return typeof value == 'string' || (isObjectLike(value) && objToString.call(value) == stringTag);
  8637. }
  8638. /**
  8639. * Checks if `value` is classified as a typed array.
  8640. *
  8641. * @static
  8642. * @memberOf _
  8643. * @category Lang
  8644. * @param {*} value The value to check.
  8645. * @returns {boolean} Returns `true` if `value` is correctly classified, else `false`.
  8646. * @example
  8647. *
  8648. * _.isTypedArray(new Uint8Array);
  8649. * // => true
  8650. *
  8651. * _.isTypedArray([]);
  8652. * // => false
  8653. */
  8654. function isTypedArray(value) {
  8655. return isObjectLike(value) && isLength(value.length) && !!typedArrayTags[objToString.call(value)];
  8656. }
  8657. /**
  8658. * Checks if `value` is `undefined`.
  8659. *
  8660. * @static
  8661. * @memberOf _
  8662. * @category Lang
  8663. * @param {*} value The value to check.
  8664. * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`.
  8665. * @example
  8666. *
  8667. * _.isUndefined(void 0);
  8668. * // => true
  8669. *
  8670. * _.isUndefined(null);
  8671. * // => false
  8672. */
  8673. function isUndefined(value) {
  8674. return value === undefined;
  8675. }
  8676. /**
  8677. * Checks if `value` is less than `other`.
  8678. *
  8679. * @static
  8680. * @memberOf _
  8681. * @category Lang
  8682. * @param {*} value The value to compare.
  8683. * @param {*} other The other value to compare.
  8684. * @returns {boolean} Returns `true` if `value` is less than `other`, else `false`.
  8685. * @example
  8686. *
  8687. * _.lt(1, 3);
  8688. * // => true
  8689. *
  8690. * _.lt(3, 3);
  8691. * // => false
  8692. *
  8693. * _.lt(3, 1);
  8694. * // => false
  8695. */
  8696. function lt(value, other) {
  8697. return value < other;
  8698. }
  8699. /**
  8700. * Checks if `value` is less than or equal to `other`.
  8701. *
  8702. * @static
  8703. * @memberOf _
  8704. * @category Lang
  8705. * @param {*} value The value to compare.
  8706. * @param {*} other The other value to compare.
  8707. * @returns {boolean} Returns `true` if `value` is less than or equal to `other`, else `false`.
  8708. * @example
  8709. *
  8710. * _.lte(1, 3);
  8711. * // => true
  8712. *
  8713. * _.lte(3, 3);
  8714. * // => true
  8715. *
  8716. * _.lte(3, 1);
  8717. * // => false
  8718. */
  8719. function lte(value, other) {
  8720. return value <= other;
  8721. }
  8722. /**
  8723. * Converts `value` to an array.
  8724. *
  8725. * @static
  8726. * @memberOf _
  8727. * @category Lang
  8728. * @param {*} value The value to convert.
  8729. * @returns {Array} Returns the converted array.
  8730. * @example
  8731. *
  8732. * (function() {
  8733. * return _.toArray(arguments).slice(1);
  8734. * }(1, 2, 3));
  8735. * // => [2, 3]
  8736. */
  8737. function toArray(value) {
  8738. var length = value ? getLength(value) : 0;
  8739. if (!isLength(length)) {
  8740. return values(value);
  8741. }
  8742. if (!length) {
  8743. return [];
  8744. }
  8745. return (lodash.support.unindexedChars && isString(value))
  8746. ? value.split('')
  8747. : arrayCopy(value);
  8748. }
  8749. /**
  8750. * Converts `value` to a plain object flattening inherited enumerable
  8751. * properties of `value` to own properties of the plain object.
  8752. *
  8753. * @static
  8754. * @memberOf _
  8755. * @category Lang
  8756. * @param {*} value The value to convert.
  8757. * @returns {Object} Returns the converted plain object.
  8758. * @example
  8759. *
  8760. * function Foo() {
  8761. * this.b = 2;
  8762. * }
  8763. *
  8764. * Foo.prototype.c = 3;
  8765. *
  8766. * _.assign({ 'a': 1 }, new Foo);
  8767. * // => { 'a': 1, 'b': 2 }
  8768. *
  8769. * _.assign({ 'a': 1 }, _.toPlainObject(new Foo));
  8770. * // => { 'a': 1, 'b': 2, 'c': 3 }
  8771. */
  8772. function toPlainObject(value) {
  8773. return baseCopy(value, keysIn(value));
  8774. }
  8775. /*------------------------------------------------------------------------*/
  8776. /**
  8777. * Recursively merges own enumerable properties of the source object(s), that
  8778. * don't resolve to `undefined` into the destination object. Subsequent sources
  8779. * overwrite property assignments of previous sources. If `customizer` is
  8780. * provided it's invoked to produce the merged values of the destination and
  8781. * source properties. If `customizer` returns `undefined` merging is handled
  8782. * by the method instead. The `customizer` is bound to `thisArg` and invoked
  8783. * with five arguments: (objectValue, sourceValue, key, object, source).
  8784. *
  8785. * @static
  8786. * @memberOf _
  8787. * @category Object
  8788. * @param {Object} object The destination object.
  8789. * @param {...Object} [sources] The source objects.
  8790. * @param {Function} [customizer] The function to customize assigned values.
  8791. * @param {*} [thisArg] The `this` binding of `customizer`.
  8792. * @returns {Object} Returns `object`.
  8793. * @example
  8794. *
  8795. * var users = {
  8796. * 'data': [{ 'user': 'barney' }, { 'user': 'fred' }]
  8797. * };
  8798. *
  8799. * var ages = {
  8800. * 'data': [{ 'age': 36 }, { 'age': 40 }]
  8801. * };
  8802. *
  8803. * _.merge(users, ages);
  8804. * // => { 'data': [{ 'user': 'barney', 'age': 36 }, { 'user': 'fred', 'age': 40 }] }
  8805. *
  8806. * // using a customizer callback
  8807. * var object = {
  8808. * 'fruits': ['apple'],
  8809. * 'vegetables': ['beet']
  8810. * };
  8811. *
  8812. * var other = {
  8813. * 'fruits': ['banana'],
  8814. * 'vegetables': ['carrot']
  8815. * };
  8816. *
  8817. * _.merge(object, other, function(a, b) {
  8818. * if (_.isArray(a)) {
  8819. * return a.concat(b);
  8820. * }
  8821. * });
  8822. * // => { 'fruits': ['apple', 'banana'], 'vegetables': ['beet', 'carrot'] }
  8823. */
  8824. var merge = createAssigner(baseMerge);
  8825. /**
  8826. * Assigns own enumerable properties of source object(s) to the destination
  8827. * object. Subsequent sources overwrite property assignments of previous sources.
  8828. * If `customizer` is provided it's invoked to produce the assigned values.
  8829. * The `customizer` is bound to `thisArg` and invoked with five arguments:
  8830. * (objectValue, sourceValue, key, object, source).
  8831. *
  8832. * **Note:** This method mutates `object` and is based on
  8833. * [`Object.assign`](http://ecma-international.org/ecma-262/6.0/#sec-object.assign).
  8834. *
  8835. * @static
  8836. * @memberOf _
  8837. * @alias extend
  8838. * @category Object
  8839. * @param {Object} object The destination object.
  8840. * @param {...Object} [sources] The source objects.
  8841. * @param {Function} [customizer] The function to customize assigned values.
  8842. * @param {*} [thisArg] The `this` binding of `customizer`.
  8843. * @returns {Object} Returns `object`.
  8844. * @example
  8845. *
  8846. * _.assign({ 'user': 'barney' }, { 'age': 40 }, { 'user': 'fred' });
  8847. * // => { 'user': 'fred', 'age': 40 }
  8848. *
  8849. * // using a customizer callback
  8850. * var defaults = _.partialRight(_.assign, function(value, other) {
  8851. * return _.isUndefined(value) ? other : value;
  8852. * });
  8853. *
  8854. * defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  8855. * // => { 'user': 'barney', 'age': 36 }
  8856. */
  8857. var assign = createAssigner(function(object, source, customizer) {
  8858. return customizer
  8859. ? assignWith(object, source, customizer)
  8860. : baseAssign(object, source);
  8861. });
  8862. /**
  8863. * Creates an object that inherits from the given `prototype` object. If a
  8864. * `properties` object is provided its own enumerable properties are assigned
  8865. * to the created object.
  8866. *
  8867. * @static
  8868. * @memberOf _
  8869. * @category Object
  8870. * @param {Object} prototype The object to inherit from.
  8871. * @param {Object} [properties] The properties to assign to the object.
  8872. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  8873. * @returns {Object} Returns the new object.
  8874. * @example
  8875. *
  8876. * function Shape() {
  8877. * this.x = 0;
  8878. * this.y = 0;
  8879. * }
  8880. *
  8881. * function Circle() {
  8882. * Shape.call(this);
  8883. * }
  8884. *
  8885. * Circle.prototype = _.create(Shape.prototype, {
  8886. * 'constructor': Circle
  8887. * });
  8888. *
  8889. * var circle = new Circle;
  8890. * circle instanceof Circle;
  8891. * // => true
  8892. *
  8893. * circle instanceof Shape;
  8894. * // => true
  8895. */
  8896. function create(prototype, properties, guard) {
  8897. var result = baseCreate(prototype);
  8898. if (guard && isIterateeCall(prototype, properties, guard)) {
  8899. properties = undefined;
  8900. }
  8901. return properties ? baseAssign(result, properties) : result;
  8902. }
  8903. /**
  8904. * Assigns own enumerable properties of source object(s) to the destination
  8905. * object for all destination properties that resolve to `undefined`. Once a
  8906. * property is set, additional values of the same property are ignored.
  8907. *
  8908. * **Note:** This method mutates `object`.
  8909. *
  8910. * @static
  8911. * @memberOf _
  8912. * @category Object
  8913. * @param {Object} object The destination object.
  8914. * @param {...Object} [sources] The source objects.
  8915. * @returns {Object} Returns `object`.
  8916. * @example
  8917. *
  8918. * _.defaults({ 'user': 'barney' }, { 'age': 36 }, { 'user': 'fred' });
  8919. * // => { 'user': 'barney', 'age': 36 }
  8920. */
  8921. var defaults = createDefaults(assign, assignDefaults);
  8922. /**
  8923. * This method is like `_.defaults` except that it recursively assigns
  8924. * default properties.
  8925. *
  8926. * **Note:** This method mutates `object`.
  8927. *
  8928. * @static
  8929. * @memberOf _
  8930. * @category Object
  8931. * @param {Object} object The destination object.
  8932. * @param {...Object} [sources] The source objects.
  8933. * @returns {Object} Returns `object`.
  8934. * @example
  8935. *
  8936. * _.defaultsDeep({ 'user': { 'name': 'barney' } }, { 'user': { 'name': 'fred', 'age': 36 } });
  8937. * // => { 'user': { 'name': 'barney', 'age': 36 } }
  8938. *
  8939. */
  8940. var defaultsDeep = createDefaults(merge, mergeDefaults);
  8941. /**
  8942. * This method is like `_.find` except that it returns the key of the first
  8943. * element `predicate` returns truthy for instead of the element itself.
  8944. *
  8945. * If a property name is provided for `predicate` the created `_.property`
  8946. * style callback returns the property value of the given element.
  8947. *
  8948. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8949. * style callback returns `true` for elements that have a matching property
  8950. * value, else `false`.
  8951. *
  8952. * If an object is provided for `predicate` the created `_.matches` style
  8953. * callback returns `true` for elements that have the properties of the given
  8954. * object, else `false`.
  8955. *
  8956. * @static
  8957. * @memberOf _
  8958. * @category Object
  8959. * @param {Object} object The object to search.
  8960. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  8961. * per iteration.
  8962. * @param {*} [thisArg] The `this` binding of `predicate`.
  8963. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
  8964. * @example
  8965. *
  8966. * var users = {
  8967. * 'barney': { 'age': 36, 'active': true },
  8968. * 'fred': { 'age': 40, 'active': false },
  8969. * 'pebbles': { 'age': 1, 'active': true }
  8970. * };
  8971. *
  8972. * _.findKey(users, function(chr) {
  8973. * return chr.age < 40;
  8974. * });
  8975. * // => 'barney' (iteration order is not guaranteed)
  8976. *
  8977. * // using the `_.matches` callback shorthand
  8978. * _.findKey(users, { 'age': 1, 'active': true });
  8979. * // => 'pebbles'
  8980. *
  8981. * // using the `_.matchesProperty` callback shorthand
  8982. * _.findKey(users, 'active', false);
  8983. * // => 'fred'
  8984. *
  8985. * // using the `_.property` callback shorthand
  8986. * _.findKey(users, 'active');
  8987. * // => 'barney'
  8988. */
  8989. var findKey = createFindKey(baseForOwn);
  8990. /**
  8991. * This method is like `_.findKey` except that it iterates over elements of
  8992. * a collection in the opposite order.
  8993. *
  8994. * If a property name is provided for `predicate` the created `_.property`
  8995. * style callback returns the property value of the given element.
  8996. *
  8997. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  8998. * style callback returns `true` for elements that have a matching property
  8999. * value, else `false`.
  9000. *
  9001. * If an object is provided for `predicate` the created `_.matches` style
  9002. * callback returns `true` for elements that have the properties of the given
  9003. * object, else `false`.
  9004. *
  9005. * @static
  9006. * @memberOf _
  9007. * @category Object
  9008. * @param {Object} object The object to search.
  9009. * @param {Function|Object|string} [predicate=_.identity] The function invoked
  9010. * per iteration.
  9011. * @param {*} [thisArg] The `this` binding of `predicate`.
  9012. * @returns {string|undefined} Returns the key of the matched element, else `undefined`.
  9013. * @example
  9014. *
  9015. * var users = {
  9016. * 'barney': { 'age': 36, 'active': true },
  9017. * 'fred': { 'age': 40, 'active': false },
  9018. * 'pebbles': { 'age': 1, 'active': true }
  9019. * };
  9020. *
  9021. * _.findLastKey(users, function(chr) {
  9022. * return chr.age < 40;
  9023. * });
  9024. * // => returns `pebbles` assuming `_.findKey` returns `barney`
  9025. *
  9026. * // using the `_.matches` callback shorthand
  9027. * _.findLastKey(users, { 'age': 36, 'active': true });
  9028. * // => 'barney'
  9029. *
  9030. * // using the `_.matchesProperty` callback shorthand
  9031. * _.findLastKey(users, 'active', false);
  9032. * // => 'fred'
  9033. *
  9034. * // using the `_.property` callback shorthand
  9035. * _.findLastKey(users, 'active');
  9036. * // => 'pebbles'
  9037. */
  9038. var findLastKey = createFindKey(baseForOwnRight);
  9039. /**
  9040. * Iterates over own and inherited enumerable properties of an object invoking
  9041. * `iteratee` for each property. The `iteratee` is bound to `thisArg` and invoked
  9042. * with three arguments: (value, key, object). Iteratee functions may exit
  9043. * iteration early by explicitly returning `false`.
  9044. *
  9045. * @static
  9046. * @memberOf _
  9047. * @category Object
  9048. * @param {Object} object The object to iterate over.
  9049. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9050. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9051. * @returns {Object} Returns `object`.
  9052. * @example
  9053. *
  9054. * function Foo() {
  9055. * this.a = 1;
  9056. * this.b = 2;
  9057. * }
  9058. *
  9059. * Foo.prototype.c = 3;
  9060. *
  9061. * _.forIn(new Foo, function(value, key) {
  9062. * console.log(key);
  9063. * });
  9064. * // => logs 'a', 'b', and 'c' (iteration order is not guaranteed)
  9065. */
  9066. var forIn = createForIn(baseFor);
  9067. /**
  9068. * This method is like `_.forIn` except that it iterates over properties of
  9069. * `object` in the opposite order.
  9070. *
  9071. * @static
  9072. * @memberOf _
  9073. * @category Object
  9074. * @param {Object} object The object to iterate over.
  9075. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9076. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9077. * @returns {Object} Returns `object`.
  9078. * @example
  9079. *
  9080. * function Foo() {
  9081. * this.a = 1;
  9082. * this.b = 2;
  9083. * }
  9084. *
  9085. * Foo.prototype.c = 3;
  9086. *
  9087. * _.forInRight(new Foo, function(value, key) {
  9088. * console.log(key);
  9089. * });
  9090. * // => logs 'c', 'b', and 'a' assuming `_.forIn ` logs 'a', 'b', and 'c'
  9091. */
  9092. var forInRight = createForIn(baseForRight);
  9093. /**
  9094. * Iterates over own enumerable properties of an object invoking `iteratee`
  9095. * for each property. The `iteratee` is bound to `thisArg` and invoked with
  9096. * three arguments: (value, key, object). Iteratee functions may exit iteration
  9097. * early by explicitly returning `false`.
  9098. *
  9099. * @static
  9100. * @memberOf _
  9101. * @category Object
  9102. * @param {Object} object The object to iterate over.
  9103. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9104. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9105. * @returns {Object} Returns `object`.
  9106. * @example
  9107. *
  9108. * function Foo() {
  9109. * this.a = 1;
  9110. * this.b = 2;
  9111. * }
  9112. *
  9113. * Foo.prototype.c = 3;
  9114. *
  9115. * _.forOwn(new Foo, function(value, key) {
  9116. * console.log(key);
  9117. * });
  9118. * // => logs 'a' and 'b' (iteration order is not guaranteed)
  9119. */
  9120. var forOwn = createForOwn(baseForOwn);
  9121. /**
  9122. * This method is like `_.forOwn` except that it iterates over properties of
  9123. * `object` in the opposite order.
  9124. *
  9125. * @static
  9126. * @memberOf _
  9127. * @category Object
  9128. * @param {Object} object The object to iterate over.
  9129. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9130. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9131. * @returns {Object} Returns `object`.
  9132. * @example
  9133. *
  9134. * function Foo() {
  9135. * this.a = 1;
  9136. * this.b = 2;
  9137. * }
  9138. *
  9139. * Foo.prototype.c = 3;
  9140. *
  9141. * _.forOwnRight(new Foo, function(value, key) {
  9142. * console.log(key);
  9143. * });
  9144. * // => logs 'b' and 'a' assuming `_.forOwn` logs 'a' and 'b'
  9145. */
  9146. var forOwnRight = createForOwn(baseForOwnRight);
  9147. /**
  9148. * Creates an array of function property names from all enumerable properties,
  9149. * own and inherited, of `object`.
  9150. *
  9151. * @static
  9152. * @memberOf _
  9153. * @alias methods
  9154. * @category Object
  9155. * @param {Object} object The object to inspect.
  9156. * @returns {Array} Returns the new array of property names.
  9157. * @example
  9158. *
  9159. * _.functions(_);
  9160. * // => ['after', 'ary', 'assign', ...]
  9161. */
  9162. function functions(object) {
  9163. return baseFunctions(object, keysIn(object));
  9164. }
  9165. /**
  9166. * Gets the property value at `path` of `object`. If the resolved value is
  9167. * `undefined` the `defaultValue` is used in its place.
  9168. *
  9169. * @static
  9170. * @memberOf _
  9171. * @category Object
  9172. * @param {Object} object The object to query.
  9173. * @param {Array|string} path The path of the property to get.
  9174. * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
  9175. * @returns {*} Returns the resolved value.
  9176. * @example
  9177. *
  9178. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  9179. *
  9180. * _.get(object, 'a[0].b.c');
  9181. * // => 3
  9182. *
  9183. * _.get(object, ['a', '0', 'b', 'c']);
  9184. * // => 3
  9185. *
  9186. * _.get(object, 'a.b.c', 'default');
  9187. * // => 'default'
  9188. */
  9189. function get(object, path, defaultValue) {
  9190. var result = object == null ? undefined : baseGet(object, toPath(path), (path + ''));
  9191. return result === undefined ? defaultValue : result;
  9192. }
  9193. /**
  9194. * Checks if `path` is a direct property.
  9195. *
  9196. * @static
  9197. * @memberOf _
  9198. * @category Object
  9199. * @param {Object} object The object to query.
  9200. * @param {Array|string} path The path to check.
  9201. * @returns {boolean} Returns `true` if `path` is a direct property, else `false`.
  9202. * @example
  9203. *
  9204. * var object = { 'a': { 'b': { 'c': 3 } } };
  9205. *
  9206. * _.has(object, 'a');
  9207. * // => true
  9208. *
  9209. * _.has(object, 'a.b.c');
  9210. * // => true
  9211. *
  9212. * _.has(object, ['a', 'b', 'c']);
  9213. * // => true
  9214. */
  9215. function has(object, path) {
  9216. if (object == null) {
  9217. return false;
  9218. }
  9219. var result = hasOwnProperty.call(object, path);
  9220. if (!result && !isKey(path)) {
  9221. path = toPath(path);
  9222. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  9223. if (object == null) {
  9224. return false;
  9225. }
  9226. path = last(path);
  9227. result = hasOwnProperty.call(object, path);
  9228. }
  9229. return result || (isLength(object.length) && isIndex(path, object.length) &&
  9230. (isArray(object) || isArguments(object) || isString(object)));
  9231. }
  9232. /**
  9233. * Creates an object composed of the inverted keys and values of `object`.
  9234. * If `object` contains duplicate values, subsequent values overwrite property
  9235. * assignments of previous values unless `multiValue` is `true`.
  9236. *
  9237. * @static
  9238. * @memberOf _
  9239. * @category Object
  9240. * @param {Object} object The object to invert.
  9241. * @param {boolean} [multiValue] Allow multiple values per key.
  9242. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  9243. * @returns {Object} Returns the new inverted object.
  9244. * @example
  9245. *
  9246. * var object = { 'a': 1, 'b': 2, 'c': 1 };
  9247. *
  9248. * _.invert(object);
  9249. * // => { '1': 'c', '2': 'b' }
  9250. *
  9251. * // with `multiValue`
  9252. * _.invert(object, true);
  9253. * // => { '1': ['a', 'c'], '2': ['b'] }
  9254. */
  9255. function invert(object, multiValue, guard) {
  9256. if (guard && isIterateeCall(object, multiValue, guard)) {
  9257. multiValue = undefined;
  9258. }
  9259. var index = -1,
  9260. props = keys(object),
  9261. length = props.length,
  9262. result = {};
  9263. while (++index < length) {
  9264. var key = props[index],
  9265. value = object[key];
  9266. if (multiValue) {
  9267. if (hasOwnProperty.call(result, value)) {
  9268. result[value].push(key);
  9269. } else {
  9270. result[value] = [key];
  9271. }
  9272. }
  9273. else {
  9274. result[value] = key;
  9275. }
  9276. }
  9277. return result;
  9278. }
  9279. /**
  9280. * Creates an array of the own enumerable property names of `object`.
  9281. *
  9282. * **Note:** Non-object values are coerced to objects. See the
  9283. * [ES spec](http://ecma-international.org/ecma-262/6.0/#sec-object.keys)
  9284. * for more details.
  9285. *
  9286. * @static
  9287. * @memberOf _
  9288. * @category Object
  9289. * @param {Object} object The object to query.
  9290. * @returns {Array} Returns the array of property names.
  9291. * @example
  9292. *
  9293. * function Foo() {
  9294. * this.a = 1;
  9295. * this.b = 2;
  9296. * }
  9297. *
  9298. * Foo.prototype.c = 3;
  9299. *
  9300. * _.keys(new Foo);
  9301. * // => ['a', 'b'] (iteration order is not guaranteed)
  9302. *
  9303. * _.keys('hi');
  9304. * // => ['0', '1']
  9305. */
  9306. var keys = !nativeKeys ? shimKeys : function(object) {
  9307. var Ctor = object == null ? undefined : object.constructor;
  9308. if ((typeof Ctor == 'function' && Ctor.prototype === object) ||
  9309. (typeof object == 'function' ? lodash.support.enumPrototypes : isArrayLike(object))) {
  9310. return shimKeys(object);
  9311. }
  9312. return isObject(object) ? nativeKeys(object) : [];
  9313. };
  9314. /**
  9315. * Creates an array of the own and inherited enumerable property names of `object`.
  9316. *
  9317. * **Note:** Non-object values are coerced to objects.
  9318. *
  9319. * @static
  9320. * @memberOf _
  9321. * @category Object
  9322. * @param {Object} object The object to query.
  9323. * @returns {Array} Returns the array of property names.
  9324. * @example
  9325. *
  9326. * function Foo() {
  9327. * this.a = 1;
  9328. * this.b = 2;
  9329. * }
  9330. *
  9331. * Foo.prototype.c = 3;
  9332. *
  9333. * _.keysIn(new Foo);
  9334. * // => ['a', 'b', 'c'] (iteration order is not guaranteed)
  9335. */
  9336. function keysIn(object) {
  9337. if (object == null) {
  9338. return [];
  9339. }
  9340. if (!isObject(object)) {
  9341. object = Object(object);
  9342. }
  9343. var length = object.length,
  9344. support = lodash.support;
  9345. length = (length && isLength(length) &&
  9346. (isArray(object) || isArguments(object) || isString(object)) && length) || 0;
  9347. var Ctor = object.constructor,
  9348. index = -1,
  9349. proto = (isFunction(Ctor) && Ctor.prototype) || objectProto,
  9350. isProto = proto === object,
  9351. result = Array(length),
  9352. skipIndexes = length > 0,
  9353. skipErrorProps = support.enumErrorProps && (object === errorProto || object instanceof Error),
  9354. skipProto = support.enumPrototypes && isFunction(object);
  9355. while (++index < length) {
  9356. result[index] = (index + '');
  9357. }
  9358. // lodash skips the `constructor` property when it infers it's iterating
  9359. // over a `prototype` object because IE < 9 can't set the `[[Enumerable]]`
  9360. // attribute of an existing property and the `constructor` property of a
  9361. // prototype defaults to non-enumerable.
  9362. for (var key in object) {
  9363. if (!(skipProto && key == 'prototype') &&
  9364. !(skipErrorProps && (key == 'message' || key == 'name')) &&
  9365. !(skipIndexes && isIndex(key, length)) &&
  9366. !(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) {
  9367. result.push(key);
  9368. }
  9369. }
  9370. if (support.nonEnumShadows && object !== objectProto) {
  9371. var tag = object === stringProto ? stringTag : (object === errorProto ? errorTag : objToString.call(object)),
  9372. nonEnums = nonEnumProps[tag] || nonEnumProps[objectTag];
  9373. if (tag == objectTag) {
  9374. proto = objectProto;
  9375. }
  9376. length = shadowProps.length;
  9377. while (length--) {
  9378. key = shadowProps[length];
  9379. var nonEnum = nonEnums[key];
  9380. if (!(isProto && nonEnum) &&
  9381. (nonEnum ? hasOwnProperty.call(object, key) : object[key] !== proto[key])) {
  9382. result.push(key);
  9383. }
  9384. }
  9385. }
  9386. return result;
  9387. }
  9388. /**
  9389. * The opposite of `_.mapValues`; this method creates an object with the
  9390. * same values as `object` and keys generated by running each own enumerable
  9391. * property of `object` through `iteratee`.
  9392. *
  9393. * @static
  9394. * @memberOf _
  9395. * @category Object
  9396. * @param {Object} object The object to iterate over.
  9397. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  9398. * per iteration.
  9399. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9400. * @returns {Object} Returns the new mapped object.
  9401. * @example
  9402. *
  9403. * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) {
  9404. * return key + value;
  9405. * });
  9406. * // => { 'a1': 1, 'b2': 2 }
  9407. */
  9408. var mapKeys = createObjectMapper(true);
  9409. /**
  9410. * Creates an object with the same keys as `object` and values generated by
  9411. * running each own enumerable property of `object` through `iteratee`. The
  9412. * iteratee function is bound to `thisArg` and invoked with three arguments:
  9413. * (value, key, object).
  9414. *
  9415. * If a property name is provided for `iteratee` the created `_.property`
  9416. * style callback returns the property value of the given element.
  9417. *
  9418. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  9419. * style callback returns `true` for elements that have a matching property
  9420. * value, else `false`.
  9421. *
  9422. * If an object is provided for `iteratee` the created `_.matches` style
  9423. * callback returns `true` for elements that have the properties of the given
  9424. * object, else `false`.
  9425. *
  9426. * @static
  9427. * @memberOf _
  9428. * @category Object
  9429. * @param {Object} object The object to iterate over.
  9430. * @param {Function|Object|string} [iteratee=_.identity] The function invoked
  9431. * per iteration.
  9432. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9433. * @returns {Object} Returns the new mapped object.
  9434. * @example
  9435. *
  9436. * _.mapValues({ 'a': 1, 'b': 2 }, function(n) {
  9437. * return n * 3;
  9438. * });
  9439. * // => { 'a': 3, 'b': 6 }
  9440. *
  9441. * var users = {
  9442. * 'fred': { 'user': 'fred', 'age': 40 },
  9443. * 'pebbles': { 'user': 'pebbles', 'age': 1 }
  9444. * };
  9445. *
  9446. * // using the `_.property` callback shorthand
  9447. * _.mapValues(users, 'age');
  9448. * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed)
  9449. */
  9450. var mapValues = createObjectMapper();
  9451. /**
  9452. * The opposite of `_.pick`; this method creates an object composed of the
  9453. * own and inherited enumerable properties of `object` that are not omitted.
  9454. *
  9455. * @static
  9456. * @memberOf _
  9457. * @category Object
  9458. * @param {Object} object The source object.
  9459. * @param {Function|...(string|string[])} [predicate] The function invoked per
  9460. * iteration or property names to omit, specified as individual property
  9461. * names or arrays of property names.
  9462. * @param {*} [thisArg] The `this` binding of `predicate`.
  9463. * @returns {Object} Returns the new object.
  9464. * @example
  9465. *
  9466. * var object = { 'user': 'fred', 'age': 40 };
  9467. *
  9468. * _.omit(object, 'age');
  9469. * // => { 'user': 'fred' }
  9470. *
  9471. * _.omit(object, _.isNumber);
  9472. * // => { 'user': 'fred' }
  9473. */
  9474. var omit = restParam(function(object, props) {
  9475. if (object == null) {
  9476. return {};
  9477. }
  9478. if (typeof props[0] != 'function') {
  9479. var props = arrayMap(baseFlatten(props), String);
  9480. return pickByArray(object, baseDifference(keysIn(object), props));
  9481. }
  9482. var predicate = bindCallback(props[0], props[1], 3);
  9483. return pickByCallback(object, function(value, key, object) {
  9484. return !predicate(value, key, object);
  9485. });
  9486. });
  9487. /**
  9488. * Creates a two dimensional array of the key-value pairs for `object`,
  9489. * e.g. `[[key1, value1], [key2, value2]]`.
  9490. *
  9491. * @static
  9492. * @memberOf _
  9493. * @category Object
  9494. * @param {Object} object The object to query.
  9495. * @returns {Array} Returns the new array of key-value pairs.
  9496. * @example
  9497. *
  9498. * _.pairs({ 'barney': 36, 'fred': 40 });
  9499. * // => [['barney', 36], ['fred', 40]] (iteration order is not guaranteed)
  9500. */
  9501. function pairs(object) {
  9502. object = toObject(object);
  9503. var index = -1,
  9504. props = keys(object),
  9505. length = props.length,
  9506. result = Array(length);
  9507. while (++index < length) {
  9508. var key = props[index];
  9509. result[index] = [key, object[key]];
  9510. }
  9511. return result;
  9512. }
  9513. /**
  9514. * Creates an object composed of the picked `object` properties. Property
  9515. * names may be specified as individual arguments or as arrays of property
  9516. * names. If `predicate` is provided it's invoked for each property of `object`
  9517. * picking the properties `predicate` returns truthy for. The predicate is
  9518. * bound to `thisArg` and invoked with three arguments: (value, key, object).
  9519. *
  9520. * @static
  9521. * @memberOf _
  9522. * @category Object
  9523. * @param {Object} object The source object.
  9524. * @param {Function|...(string|string[])} [predicate] The function invoked per
  9525. * iteration or property names to pick, specified as individual property
  9526. * names or arrays of property names.
  9527. * @param {*} [thisArg] The `this` binding of `predicate`.
  9528. * @returns {Object} Returns the new object.
  9529. * @example
  9530. *
  9531. * var object = { 'user': 'fred', 'age': 40 };
  9532. *
  9533. * _.pick(object, 'user');
  9534. * // => { 'user': 'fred' }
  9535. *
  9536. * _.pick(object, _.isString);
  9537. * // => { 'user': 'fred' }
  9538. */
  9539. var pick = restParam(function(object, props) {
  9540. if (object == null) {
  9541. return {};
  9542. }
  9543. return typeof props[0] == 'function'
  9544. ? pickByCallback(object, bindCallback(props[0], props[1], 3))
  9545. : pickByArray(object, baseFlatten(props));
  9546. });
  9547. /**
  9548. * This method is like `_.get` except that if the resolved value is a function
  9549. * it's invoked with the `this` binding of its parent object and its result
  9550. * is returned.
  9551. *
  9552. * @static
  9553. * @memberOf _
  9554. * @category Object
  9555. * @param {Object} object The object to query.
  9556. * @param {Array|string} path The path of the property to resolve.
  9557. * @param {*} [defaultValue] The value returned if the resolved value is `undefined`.
  9558. * @returns {*} Returns the resolved value.
  9559. * @example
  9560. *
  9561. * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] };
  9562. *
  9563. * _.result(object, 'a[0].b.c1');
  9564. * // => 3
  9565. *
  9566. * _.result(object, 'a[0].b.c2');
  9567. * // => 4
  9568. *
  9569. * _.result(object, 'a.b.c', 'default');
  9570. * // => 'default'
  9571. *
  9572. * _.result(object, 'a.b.c', _.constant('default'));
  9573. * // => 'default'
  9574. */
  9575. function result(object, path, defaultValue) {
  9576. var result = object == null ? undefined : toObject(object)[path];
  9577. if (result === undefined) {
  9578. if (object != null && !isKey(path, object)) {
  9579. path = toPath(path);
  9580. object = path.length == 1 ? object : baseGet(object, baseSlice(path, 0, -1));
  9581. result = object == null ? undefined : toObject(object)[last(path)];
  9582. }
  9583. result = result === undefined ? defaultValue : result;
  9584. }
  9585. return isFunction(result) ? result.call(object) : result;
  9586. }
  9587. /**
  9588. * Sets the property value of `path` on `object`. If a portion of `path`
  9589. * does not exist it's created.
  9590. *
  9591. * @static
  9592. * @memberOf _
  9593. * @category Object
  9594. * @param {Object} object The object to augment.
  9595. * @param {Array|string} path The path of the property to set.
  9596. * @param {*} value The value to set.
  9597. * @returns {Object} Returns `object`.
  9598. * @example
  9599. *
  9600. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  9601. *
  9602. * _.set(object, 'a[0].b.c', 4);
  9603. * console.log(object.a[0].b.c);
  9604. * // => 4
  9605. *
  9606. * _.set(object, 'x[0].y.z', 5);
  9607. * console.log(object.x[0].y.z);
  9608. * // => 5
  9609. */
  9610. function set(object, path, value) {
  9611. if (object == null) {
  9612. return object;
  9613. }
  9614. var pathKey = (path + '');
  9615. path = (object[pathKey] != null || isKey(path, object)) ? [pathKey] : toPath(path);
  9616. var index = -1,
  9617. length = path.length,
  9618. lastIndex = length - 1,
  9619. nested = object;
  9620. while (nested != null && ++index < length) {
  9621. var key = path[index];
  9622. if (isObject(nested)) {
  9623. if (index == lastIndex) {
  9624. nested[key] = value;
  9625. } else if (nested[key] == null) {
  9626. nested[key] = isIndex(path[index + 1]) ? [] : {};
  9627. }
  9628. }
  9629. nested = nested[key];
  9630. }
  9631. return object;
  9632. }
  9633. /**
  9634. * An alternative to `_.reduce`; this method transforms `object` to a new
  9635. * `accumulator` object which is the result of running each of its own enumerable
  9636. * properties through `iteratee`, with each invocation potentially mutating
  9637. * the `accumulator` object. The `iteratee` is bound to `thisArg` and invoked
  9638. * with four arguments: (accumulator, value, key, object). Iteratee functions
  9639. * may exit iteration early by explicitly returning `false`.
  9640. *
  9641. * @static
  9642. * @memberOf _
  9643. * @category Object
  9644. * @param {Array|Object} object The object to iterate over.
  9645. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  9646. * @param {*} [accumulator] The custom accumulator value.
  9647. * @param {*} [thisArg] The `this` binding of `iteratee`.
  9648. * @returns {*} Returns the accumulated value.
  9649. * @example
  9650. *
  9651. * _.transform([2, 3, 4], function(result, n) {
  9652. * result.push(n *= n);
  9653. * return n % 2 == 0;
  9654. * });
  9655. * // => [4, 9]
  9656. *
  9657. * _.transform({ 'a': 1, 'b': 2 }, function(result, n, key) {
  9658. * result[key] = n * 3;
  9659. * });
  9660. * // => { 'a': 3, 'b': 6 }
  9661. */
  9662. function transform(object, iteratee, accumulator, thisArg) {
  9663. var isArr = isArray(object) || isTypedArray(object);
  9664. iteratee = getCallback(iteratee, thisArg, 4);
  9665. if (accumulator == null) {
  9666. if (isArr || isObject(object)) {
  9667. var Ctor = object.constructor;
  9668. if (isArr) {
  9669. accumulator = isArray(object) ? new Ctor : [];
  9670. } else {
  9671. accumulator = baseCreate(isFunction(Ctor) ? Ctor.prototype : undefined);
  9672. }
  9673. } else {
  9674. accumulator = {};
  9675. }
  9676. }
  9677. (isArr ? arrayEach : baseForOwn)(object, function(value, index, object) {
  9678. return iteratee(accumulator, value, index, object);
  9679. });
  9680. return accumulator;
  9681. }
  9682. /**
  9683. * Creates an array of the own enumerable property values of `object`.
  9684. *
  9685. * **Note:** Non-object values are coerced to objects.
  9686. *
  9687. * @static
  9688. * @memberOf _
  9689. * @category Object
  9690. * @param {Object} object The object to query.
  9691. * @returns {Array} Returns the array of property values.
  9692. * @example
  9693. *
  9694. * function Foo() {
  9695. * this.a = 1;
  9696. * this.b = 2;
  9697. * }
  9698. *
  9699. * Foo.prototype.c = 3;
  9700. *
  9701. * _.values(new Foo);
  9702. * // => [1, 2] (iteration order is not guaranteed)
  9703. *
  9704. * _.values('hi');
  9705. * // => ['h', 'i']
  9706. */
  9707. function values(object) {
  9708. return baseValues(object, keys(object));
  9709. }
  9710. /**
  9711. * Creates an array of the own and inherited enumerable property values
  9712. * of `object`.
  9713. *
  9714. * **Note:** Non-object values are coerced to objects.
  9715. *
  9716. * @static
  9717. * @memberOf _
  9718. * @category Object
  9719. * @param {Object} object The object to query.
  9720. * @returns {Array} Returns the array of property values.
  9721. * @example
  9722. *
  9723. * function Foo() {
  9724. * this.a = 1;
  9725. * this.b = 2;
  9726. * }
  9727. *
  9728. * Foo.prototype.c = 3;
  9729. *
  9730. * _.valuesIn(new Foo);
  9731. * // => [1, 2, 3] (iteration order is not guaranteed)
  9732. */
  9733. function valuesIn(object) {
  9734. return baseValues(object, keysIn(object));
  9735. }
  9736. /*------------------------------------------------------------------------*/
  9737. /**
  9738. * Checks if `n` is between `start` and up to but not including, `end`. If
  9739. * `end` is not specified it's set to `start` with `start` then set to `0`.
  9740. *
  9741. * @static
  9742. * @memberOf _
  9743. * @category Number
  9744. * @param {number} n The number to check.
  9745. * @param {number} [start=0] The start of the range.
  9746. * @param {number} end The end of the range.
  9747. * @returns {boolean} Returns `true` if `n` is in the range, else `false`.
  9748. * @example
  9749. *
  9750. * _.inRange(3, 2, 4);
  9751. * // => true
  9752. *
  9753. * _.inRange(4, 8);
  9754. * // => true
  9755. *
  9756. * _.inRange(4, 2);
  9757. * // => false
  9758. *
  9759. * _.inRange(2, 2);
  9760. * // => false
  9761. *
  9762. * _.inRange(1.2, 2);
  9763. * // => true
  9764. *
  9765. * _.inRange(5.2, 4);
  9766. * // => false
  9767. */
  9768. function inRange(value, start, end) {
  9769. start = +start || 0;
  9770. if (end === undefined) {
  9771. end = start;
  9772. start = 0;
  9773. } else {
  9774. end = +end || 0;
  9775. }
  9776. return value >= nativeMin(start, end) && value < nativeMax(start, end);
  9777. }
  9778. /**
  9779. * Produces a random number between `min` and `max` (inclusive). If only one
  9780. * argument is provided a number between `0` and the given number is returned.
  9781. * If `floating` is `true`, or either `min` or `max` are floats, a floating-point
  9782. * number is returned instead of an integer.
  9783. *
  9784. * @static
  9785. * @memberOf _
  9786. * @category Number
  9787. * @param {number} [min=0] The minimum possible value.
  9788. * @param {number} [max=1] The maximum possible value.
  9789. * @param {boolean} [floating] Specify returning a floating-point number.
  9790. * @returns {number} Returns the random number.
  9791. * @example
  9792. *
  9793. * _.random(0, 5);
  9794. * // => an integer between 0 and 5
  9795. *
  9796. * _.random(5);
  9797. * // => also an integer between 0 and 5
  9798. *
  9799. * _.random(5, true);
  9800. * // => a floating-point number between 0 and 5
  9801. *
  9802. * _.random(1.2, 5.2);
  9803. * // => a floating-point number between 1.2 and 5.2
  9804. */
  9805. function random(min, max, floating) {
  9806. if (floating && isIterateeCall(min, max, floating)) {
  9807. max = floating = undefined;
  9808. }
  9809. var noMin = min == null,
  9810. noMax = max == null;
  9811. if (floating == null) {
  9812. if (noMax && typeof min == 'boolean') {
  9813. floating = min;
  9814. min = 1;
  9815. }
  9816. else if (typeof max == 'boolean') {
  9817. floating = max;
  9818. noMax = true;
  9819. }
  9820. }
  9821. if (noMin && noMax) {
  9822. max = 1;
  9823. noMax = false;
  9824. }
  9825. min = +min || 0;
  9826. if (noMax) {
  9827. max = min;
  9828. min = 0;
  9829. } else {
  9830. max = +max || 0;
  9831. }
  9832. if (floating || min % 1 || max % 1) {
  9833. var rand = nativeRandom();
  9834. return nativeMin(min + (rand * (max - min + parseFloat('1e-' + ((rand + '').length - 1)))), max);
  9835. }
  9836. return baseRandom(min, max);
  9837. }
  9838. /*------------------------------------------------------------------------*/
  9839. /**
  9840. * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase).
  9841. *
  9842. * @static
  9843. * @memberOf _
  9844. * @category String
  9845. * @param {string} [string=''] The string to convert.
  9846. * @returns {string} Returns the camel cased string.
  9847. * @example
  9848. *
  9849. * _.camelCase('Foo Bar');
  9850. * // => 'fooBar'
  9851. *
  9852. * _.camelCase('--foo-bar');
  9853. * // => 'fooBar'
  9854. *
  9855. * _.camelCase('__foo_bar__');
  9856. * // => 'fooBar'
  9857. */
  9858. var camelCase = createCompounder(function(result, word, index) {
  9859. word = word.toLowerCase();
  9860. return result + (index ? (word.charAt(0).toUpperCase() + word.slice(1)) : word);
  9861. });
  9862. /**
  9863. * Capitalizes the first character of `string`.
  9864. *
  9865. * @static
  9866. * @memberOf _
  9867. * @category String
  9868. * @param {string} [string=''] The string to capitalize.
  9869. * @returns {string} Returns the capitalized string.
  9870. * @example
  9871. *
  9872. * _.capitalize('fred');
  9873. * // => 'Fred'
  9874. */
  9875. function capitalize(string) {
  9876. string = baseToString(string);
  9877. return string && (string.charAt(0).toUpperCase() + string.slice(1));
  9878. }
  9879. /**
  9880. * Deburrs `string` by converting [latin-1 supplementary letters](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table)
  9881. * to basic latin letters and removing [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks).
  9882. *
  9883. * @static
  9884. * @memberOf _
  9885. * @category String
  9886. * @param {string} [string=''] The string to deburr.
  9887. * @returns {string} Returns the deburred string.
  9888. * @example
  9889. *
  9890. * _.deburr('déjà vu');
  9891. * // => 'deja vu'
  9892. */
  9893. function deburr(string) {
  9894. string = baseToString(string);
  9895. return string && string.replace(reLatin1, deburrLetter).replace(reComboMark, '');
  9896. }
  9897. /**
  9898. * Checks if `string` ends with the given target string.
  9899. *
  9900. * @static
  9901. * @memberOf _
  9902. * @category String
  9903. * @param {string} [string=''] The string to search.
  9904. * @param {string} [target] The string to search for.
  9905. * @param {number} [position=string.length] The position to search from.
  9906. * @returns {boolean} Returns `true` if `string` ends with `target`, else `false`.
  9907. * @example
  9908. *
  9909. * _.endsWith('abc', 'c');
  9910. * // => true
  9911. *
  9912. * _.endsWith('abc', 'b');
  9913. * // => false
  9914. *
  9915. * _.endsWith('abc', 'b', 2);
  9916. * // => true
  9917. */
  9918. function endsWith(string, target, position) {
  9919. string = baseToString(string);
  9920. target = (target + '');
  9921. var length = string.length;
  9922. position = position === undefined
  9923. ? length
  9924. : nativeMin(position < 0 ? 0 : (+position || 0), length);
  9925. position -= target.length;
  9926. return position >= 0 && string.indexOf(target, position) == position;
  9927. }
  9928. /**
  9929. * Converts the characters "&", "<", ">", '"', "'", and "\`", in `string` to
  9930. * their corresponding HTML entities.
  9931. *
  9932. * **Note:** No other characters are escaped. To escape additional characters
  9933. * use a third-party library like [_he_](https://mths.be/he).
  9934. *
  9935. * Though the ">" character is escaped for symmetry, characters like
  9936. * ">" and "/" don't need escaping in HTML and have no special meaning
  9937. * unless they're part of a tag or unquoted attribute value.
  9938. * See [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands)
  9939. * (under "semi-related fun fact") for more details.
  9940. *
  9941. * Backticks are escaped because in Internet Explorer < 9, they can break out
  9942. * of attribute values or HTML comments. See [#59](https://html5sec.org/#59),
  9943. * [#102](https://html5sec.org/#102), [#108](https://html5sec.org/#108), and
  9944. * [#133](https://html5sec.org/#133) of the [HTML5 Security Cheatsheet](https://html5sec.org/)
  9945. * for more details.
  9946. *
  9947. * When working with HTML you should always [quote attribute values](http://wonko.com/post/html-escaping)
  9948. * to reduce XSS vectors.
  9949. *
  9950. * @static
  9951. * @memberOf _
  9952. * @category String
  9953. * @param {string} [string=''] The string to escape.
  9954. * @returns {string} Returns the escaped string.
  9955. * @example
  9956. *
  9957. * _.escape('fred, barney, & pebbles');
  9958. * // => 'fred, barney, &amp; pebbles'
  9959. */
  9960. function escape(string) {
  9961. // Reset `lastIndex` because in IE < 9 `String#replace` does not.
  9962. string = baseToString(string);
  9963. return (string && reHasUnescapedHtml.test(string))
  9964. ? string.replace(reUnescapedHtml, escapeHtmlChar)
  9965. : string;
  9966. }
  9967. /**
  9968. * Escapes the `RegExp` special characters "\", "/", "^", "$", ".", "|", "?",
  9969. * "*", "+", "(", ")", "[", "]", "{" and "}" in `string`.
  9970. *
  9971. * @static
  9972. * @memberOf _
  9973. * @category String
  9974. * @param {string} [string=''] The string to escape.
  9975. * @returns {string} Returns the escaped string.
  9976. * @example
  9977. *
  9978. * _.escapeRegExp('[lodash](https://lodash.com/)');
  9979. * // => '\[lodash\]\(https:\/\/lodash\.com\/\)'
  9980. */
  9981. function escapeRegExp(string) {
  9982. string = baseToString(string);
  9983. return (string && reHasRegExpChars.test(string))
  9984. ? string.replace(reRegExpChars, escapeRegExpChar)
  9985. : (string || '(?:)');
  9986. }
  9987. /**
  9988. * Converts `string` to [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles).
  9989. *
  9990. * @static
  9991. * @memberOf _
  9992. * @category String
  9993. * @param {string} [string=''] The string to convert.
  9994. * @returns {string} Returns the kebab cased string.
  9995. * @example
  9996. *
  9997. * _.kebabCase('Foo Bar');
  9998. * // => 'foo-bar'
  9999. *
  10000. * _.kebabCase('fooBar');
  10001. * // => 'foo-bar'
  10002. *
  10003. * _.kebabCase('__foo_bar__');
  10004. * // => 'foo-bar'
  10005. */
  10006. var kebabCase = createCompounder(function(result, word, index) {
  10007. return result + (index ? '-' : '') + word.toLowerCase();
  10008. });
  10009. /**
  10010. * Pads `string` on the left and right sides if it's shorter than `length`.
  10011. * Padding characters are truncated if they can't be evenly divided by `length`.
  10012. *
  10013. * @static
  10014. * @memberOf _
  10015. * @category String
  10016. * @param {string} [string=''] The string to pad.
  10017. * @param {number} [length=0] The padding length.
  10018. * @param {string} [chars=' '] The string used as padding.
  10019. * @returns {string} Returns the padded string.
  10020. * @example
  10021. *
  10022. * _.pad('abc', 8);
  10023. * // => ' abc '
  10024. *
  10025. * _.pad('abc', 8, '_-');
  10026. * // => '_-abc_-_'
  10027. *
  10028. * _.pad('abc', 3);
  10029. * // => 'abc'
  10030. */
  10031. function pad(string, length, chars) {
  10032. string = baseToString(string);
  10033. length = +length;
  10034. var strLength = string.length;
  10035. if (strLength >= length || !nativeIsFinite(length)) {
  10036. return string;
  10037. }
  10038. var mid = (length - strLength) / 2,
  10039. leftLength = nativeFloor(mid),
  10040. rightLength = nativeCeil(mid);
  10041. chars = createPadding('', rightLength, chars);
  10042. return chars.slice(0, leftLength) + string + chars;
  10043. }
  10044. /**
  10045. * Pads `string` on the left side if it's shorter than `length`. Padding
  10046. * characters are truncated if they exceed `length`.
  10047. *
  10048. * @static
  10049. * @memberOf _
  10050. * @category String
  10051. * @param {string} [string=''] The string to pad.
  10052. * @param {number} [length=0] The padding length.
  10053. * @param {string} [chars=' '] The string used as padding.
  10054. * @returns {string} Returns the padded string.
  10055. * @example
  10056. *
  10057. * _.padLeft('abc', 6);
  10058. * // => ' abc'
  10059. *
  10060. * _.padLeft('abc', 6, '_-');
  10061. * // => '_-_abc'
  10062. *
  10063. * _.padLeft('abc', 3);
  10064. * // => 'abc'
  10065. */
  10066. var padLeft = createPadDir();
  10067. /**
  10068. * Pads `string` on the right side if it's shorter than `length`. Padding
  10069. * characters are truncated if they exceed `length`.
  10070. *
  10071. * @static
  10072. * @memberOf _
  10073. * @category String
  10074. * @param {string} [string=''] The string to pad.
  10075. * @param {number} [length=0] The padding length.
  10076. * @param {string} [chars=' '] The string used as padding.
  10077. * @returns {string} Returns the padded string.
  10078. * @example
  10079. *
  10080. * _.padRight('abc', 6);
  10081. * // => 'abc '
  10082. *
  10083. * _.padRight('abc', 6, '_-');
  10084. * // => 'abc_-_'
  10085. *
  10086. * _.padRight('abc', 3);
  10087. * // => 'abc'
  10088. */
  10089. var padRight = createPadDir(true);
  10090. /**
  10091. * Converts `string` to an integer of the specified radix. If `radix` is
  10092. * `undefined` or `0`, a `radix` of `10` is used unless `value` is a hexadecimal,
  10093. * in which case a `radix` of `16` is used.
  10094. *
  10095. * **Note:** This method aligns with the [ES5 implementation](https://es5.github.io/#E)
  10096. * of `parseInt`.
  10097. *
  10098. * @static
  10099. * @memberOf _
  10100. * @category String
  10101. * @param {string} string The string to convert.
  10102. * @param {number} [radix] The radix to interpret `value` by.
  10103. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10104. * @returns {number} Returns the converted integer.
  10105. * @example
  10106. *
  10107. * _.parseInt('08');
  10108. * // => 8
  10109. *
  10110. * _.map(['6', '08', '10'], _.parseInt);
  10111. * // => [6, 8, 10]
  10112. */
  10113. function parseInt(string, radix, guard) {
  10114. // Firefox < 21 and Opera < 15 follow ES3 for `parseInt`.
  10115. // Chrome fails to trim leading <BOM> whitespace characters.
  10116. // See https://code.google.com/p/v8/issues/detail?id=3109 for more details.
  10117. if (guard ? isIterateeCall(string, radix, guard) : radix == null) {
  10118. radix = 0;
  10119. } else if (radix) {
  10120. radix = +radix;
  10121. }
  10122. string = trim(string);
  10123. return nativeParseInt(string, radix || (reHasHexPrefix.test(string) ? 16 : 10));
  10124. }
  10125. /**
  10126. * Repeats the given string `n` times.
  10127. *
  10128. * @static
  10129. * @memberOf _
  10130. * @category String
  10131. * @param {string} [string=''] The string to repeat.
  10132. * @param {number} [n=0] The number of times to repeat the string.
  10133. * @returns {string} Returns the repeated string.
  10134. * @example
  10135. *
  10136. * _.repeat('*', 3);
  10137. * // => '***'
  10138. *
  10139. * _.repeat('abc', 2);
  10140. * // => 'abcabc'
  10141. *
  10142. * _.repeat('abc', 0);
  10143. * // => ''
  10144. */
  10145. function repeat(string, n) {
  10146. var result = '';
  10147. string = baseToString(string);
  10148. n = +n;
  10149. if (n < 1 || !string || !nativeIsFinite(n)) {
  10150. return result;
  10151. }
  10152. // Leverage the exponentiation by squaring algorithm for a faster repeat.
  10153. // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details.
  10154. do {
  10155. if (n % 2) {
  10156. result += string;
  10157. }
  10158. n = nativeFloor(n / 2);
  10159. string += string;
  10160. } while (n);
  10161. return result;
  10162. }
  10163. /**
  10164. * Converts `string` to [snake case](https://en.wikipedia.org/wiki/Snake_case).
  10165. *
  10166. * @static
  10167. * @memberOf _
  10168. * @category String
  10169. * @param {string} [string=''] The string to convert.
  10170. * @returns {string} Returns the snake cased string.
  10171. * @example
  10172. *
  10173. * _.snakeCase('Foo Bar');
  10174. * // => 'foo_bar'
  10175. *
  10176. * _.snakeCase('fooBar');
  10177. * // => 'foo_bar'
  10178. *
  10179. * _.snakeCase('--foo-bar');
  10180. * // => 'foo_bar'
  10181. */
  10182. var snakeCase = createCompounder(function(result, word, index) {
  10183. return result + (index ? '_' : '') + word.toLowerCase();
  10184. });
  10185. /**
  10186. * Converts `string` to [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage).
  10187. *
  10188. * @static
  10189. * @memberOf _
  10190. * @category String
  10191. * @param {string} [string=''] The string to convert.
  10192. * @returns {string} Returns the start cased string.
  10193. * @example
  10194. *
  10195. * _.startCase('--foo-bar');
  10196. * // => 'Foo Bar'
  10197. *
  10198. * _.startCase('fooBar');
  10199. * // => 'Foo Bar'
  10200. *
  10201. * _.startCase('__foo_bar__');
  10202. * // => 'Foo Bar'
  10203. */
  10204. var startCase = createCompounder(function(result, word, index) {
  10205. return result + (index ? ' ' : '') + (word.charAt(0).toUpperCase() + word.slice(1));
  10206. });
  10207. /**
  10208. * Checks if `string` starts with the given target string.
  10209. *
  10210. * @static
  10211. * @memberOf _
  10212. * @category String
  10213. * @param {string} [string=''] The string to search.
  10214. * @param {string} [target] The string to search for.
  10215. * @param {number} [position=0] The position to search from.
  10216. * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
  10217. * @example
  10218. *
  10219. * _.startsWith('abc', 'a');
  10220. * // => true
  10221. *
  10222. * _.startsWith('abc', 'b');
  10223. * // => false
  10224. *
  10225. * _.startsWith('abc', 'b', 1);
  10226. * // => true
  10227. */
  10228. function startsWith(string, target, position) {
  10229. string = baseToString(string);
  10230. position = position == null
  10231. ? 0
  10232. : nativeMin(position < 0 ? 0 : (+position || 0), string.length);
  10233. return string.lastIndexOf(target, position) == position;
  10234. }
  10235. /**
  10236. * Creates a compiled template function that can interpolate data properties
  10237. * in "interpolate" delimiters, HTML-escape interpolated data properties in
  10238. * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data
  10239. * properties may be accessed as free variables in the template. If a setting
  10240. * object is provided it takes precedence over `_.templateSettings` values.
  10241. *
  10242. * **Note:** In the development build `_.template` utilizes
  10243. * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl)
  10244. * for easier debugging.
  10245. *
  10246. * For more information on precompiling templates see
  10247. * [lodash's custom builds documentation](https://lodash.com/custom-builds).
  10248. *
  10249. * For more information on Chrome extension sandboxes see
  10250. * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval).
  10251. *
  10252. * @static
  10253. * @memberOf _
  10254. * @category String
  10255. * @param {string} [string=''] The template string.
  10256. * @param {Object} [options] The options object.
  10257. * @param {RegExp} [options.escape] The HTML "escape" delimiter.
  10258. * @param {RegExp} [options.evaluate] The "evaluate" delimiter.
  10259. * @param {Object} [options.imports] An object to import into the template as free variables.
  10260. * @param {RegExp} [options.interpolate] The "interpolate" delimiter.
  10261. * @param {string} [options.sourceURL] The sourceURL of the template's compiled source.
  10262. * @param {string} [options.variable] The data object variable name.
  10263. * @param- {Object} [otherOptions] Enables the legacy `options` param signature.
  10264. * @returns {Function} Returns the compiled template function.
  10265. * @example
  10266. *
  10267. * // using the "interpolate" delimiter to create a compiled template
  10268. * var compiled = _.template('hello <%= user %>!');
  10269. * compiled({ 'user': 'fred' });
  10270. * // => 'hello fred!'
  10271. *
  10272. * // using the HTML "escape" delimiter to escape data property values
  10273. * var compiled = _.template('<b><%- value %></b>');
  10274. * compiled({ 'value': '<script>' });
  10275. * // => '<b>&lt;script&gt;</b>'
  10276. *
  10277. * // using the "evaluate" delimiter to execute JavaScript and generate HTML
  10278. * var compiled = _.template('<% _.forEach(users, function(user) { %><li><%- user %></li><% }); %>');
  10279. * compiled({ 'users': ['fred', 'barney'] });
  10280. * // => '<li>fred</li><li>barney</li>'
  10281. *
  10282. * // using the internal `print` function in "evaluate" delimiters
  10283. * var compiled = _.template('<% print("hello " + user); %>!');
  10284. * compiled({ 'user': 'barney' });
  10285. * // => 'hello barney!'
  10286. *
  10287. * // using the ES delimiter as an alternative to the default "interpolate" delimiter
  10288. * var compiled = _.template('hello ${ user }!');
  10289. * compiled({ 'user': 'pebbles' });
  10290. * // => 'hello pebbles!'
  10291. *
  10292. * // using custom template delimiters
  10293. * _.templateSettings.interpolate = /{{([\s\S]+?)}}/g;
  10294. * var compiled = _.template('hello {{ user }}!');
  10295. * compiled({ 'user': 'mustache' });
  10296. * // => 'hello mustache!'
  10297. *
  10298. * // using backslashes to treat delimiters as plain text
  10299. * var compiled = _.template('<%= "\\<%- value %\\>" %>');
  10300. * compiled({ 'value': 'ignored' });
  10301. * // => '<%- value %>'
  10302. *
  10303. * // using the `imports` option to import `jQuery` as `jq`
  10304. * var text = '<% jq.each(users, function(user) { %><li><%- user %></li><% }); %>';
  10305. * var compiled = _.template(text, { 'imports': { 'jq': jQuery } });
  10306. * compiled({ 'users': ['fred', 'barney'] });
  10307. * // => '<li>fred</li><li>barney</li>'
  10308. *
  10309. * // using the `sourceURL` option to specify a custom sourceURL for the template
  10310. * var compiled = _.template('hello <%= user %>!', { 'sourceURL': '/basic/greeting.jst' });
  10311. * compiled(data);
  10312. * // => find the source of "greeting.jst" under the Sources tab or Resources panel of the web inspector
  10313. *
  10314. * // using the `variable` option to ensure a with-statement isn't used in the compiled template
  10315. * var compiled = _.template('hi <%= data.user %>!', { 'variable': 'data' });
  10316. * compiled.source;
  10317. * // => function(data) {
  10318. * // var __t, __p = '';
  10319. * // __p += 'hi ' + ((__t = ( data.user )) == null ? '' : __t) + '!';
  10320. * // return __p;
  10321. * // }
  10322. *
  10323. * // using the `source` property to inline compiled templates for meaningful
  10324. * // line numbers in error messages and a stack trace
  10325. * fs.writeFileSync(path.join(cwd, 'jst.js'), '\
  10326. * var JST = {\
  10327. * "main": ' + _.template(mainText).source + '\
  10328. * };\
  10329. * ');
  10330. */
  10331. function template(string, options, otherOptions) {
  10332. // Based on John Resig's `tmpl` implementation (http://ejohn.org/blog/javascript-micro-templating/)
  10333. // and Laura Doktorova's doT.js (https://github.com/olado/doT).
  10334. var settings = lodash.templateSettings;
  10335. if (otherOptions && isIterateeCall(string, options, otherOptions)) {
  10336. options = otherOptions = undefined;
  10337. }
  10338. string = baseToString(string);
  10339. options = assignWith(baseAssign({}, otherOptions || options), settings, assignOwnDefaults);
  10340. var imports = assignWith(baseAssign({}, options.imports), settings.imports, assignOwnDefaults),
  10341. importsKeys = keys(imports),
  10342. importsValues = baseValues(imports, importsKeys);
  10343. var isEscaping,
  10344. isEvaluating,
  10345. index = 0,
  10346. interpolate = options.interpolate || reNoMatch,
  10347. source = "__p += '";
  10348. // Compile the regexp to match each delimiter.
  10349. var reDelimiters = RegExp(
  10350. (options.escape || reNoMatch).source + '|' +
  10351. interpolate.source + '|' +
  10352. (interpolate === reInterpolate ? reEsTemplate : reNoMatch).source + '|' +
  10353. (options.evaluate || reNoMatch).source + '|$'
  10354. , 'g');
  10355. // Use a sourceURL for easier debugging.
  10356. var sourceURL = '//# sourceURL=' +
  10357. ('sourceURL' in options
  10358. ? options.sourceURL
  10359. : ('lodash.templateSources[' + (++templateCounter) + ']')
  10360. ) + '\n';
  10361. string.replace(reDelimiters, function(match, escapeValue, interpolateValue, esTemplateValue, evaluateValue, offset) {
  10362. interpolateValue || (interpolateValue = esTemplateValue);
  10363. // Escape characters that can't be included in string literals.
  10364. source += string.slice(index, offset).replace(reUnescapedString, escapeStringChar);
  10365. // Replace delimiters with snippets.
  10366. if (escapeValue) {
  10367. isEscaping = true;
  10368. source += "' +\n__e(" + escapeValue + ") +\n'";
  10369. }
  10370. if (evaluateValue) {
  10371. isEvaluating = true;
  10372. source += "';\n" + evaluateValue + ";\n__p += '";
  10373. }
  10374. if (interpolateValue) {
  10375. source += "' +\n((__t = (" + interpolateValue + ")) == null ? '' : __t) +\n'";
  10376. }
  10377. index = offset + match.length;
  10378. // The JS engine embedded in Adobe products requires returning the `match`
  10379. // string in order to produce the correct `offset` value.
  10380. return match;
  10381. });
  10382. source += "';\n";
  10383. // If `variable` is not specified wrap a with-statement around the generated
  10384. // code to add the data object to the top of the scope chain.
  10385. var variable = options.variable;
  10386. if (!variable) {
  10387. source = 'with (obj) {\n' + source + '\n}\n';
  10388. }
  10389. // Cleanup code by stripping empty strings.
  10390. source = (isEvaluating ? source.replace(reEmptyStringLeading, '') : source)
  10391. .replace(reEmptyStringMiddle, '$1')
  10392. .replace(reEmptyStringTrailing, '$1;');
  10393. // Frame code as the function body.
  10394. source = 'function(' + (variable || 'obj') + ') {\n' +
  10395. (variable
  10396. ? ''
  10397. : 'obj || (obj = {});\n'
  10398. ) +
  10399. "var __t, __p = ''" +
  10400. (isEscaping
  10401. ? ', __e = _.escape'
  10402. : ''
  10403. ) +
  10404. (isEvaluating
  10405. ? ', __j = Array.prototype.join;\n' +
  10406. "function print() { __p += __j.call(arguments, '') }\n"
  10407. : ';\n'
  10408. ) +
  10409. source +
  10410. 'return __p\n}';
  10411. var result = attempt(function() {
  10412. return Function(importsKeys, sourceURL + 'return ' + source).apply(undefined, importsValues);
  10413. });
  10414. // Provide the compiled function's source by its `toString` method or
  10415. // the `source` property as a convenience for inlining compiled templates.
  10416. result.source = source;
  10417. if (isError(result)) {
  10418. throw result;
  10419. }
  10420. return result;
  10421. }
  10422. /**
  10423. * Removes leading and trailing whitespace or specified characters from `string`.
  10424. *
  10425. * @static
  10426. * @memberOf _
  10427. * @category String
  10428. * @param {string} [string=''] The string to trim.
  10429. * @param {string} [chars=whitespace] The characters to trim.
  10430. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10431. * @returns {string} Returns the trimmed string.
  10432. * @example
  10433. *
  10434. * _.trim(' abc ');
  10435. * // => 'abc'
  10436. *
  10437. * _.trim('-_-abc-_-', '_-');
  10438. * // => 'abc'
  10439. *
  10440. * _.map([' foo ', ' bar '], _.trim);
  10441. * // => ['foo', 'bar']
  10442. */
  10443. function trim(string, chars, guard) {
  10444. var value = string;
  10445. string = baseToString(string);
  10446. if (!string) {
  10447. return string;
  10448. }
  10449. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  10450. return string.slice(trimmedLeftIndex(string), trimmedRightIndex(string) + 1);
  10451. }
  10452. chars = (chars + '');
  10453. return string.slice(charsLeftIndex(string, chars), charsRightIndex(string, chars) + 1);
  10454. }
  10455. /**
  10456. * Removes leading whitespace or specified characters from `string`.
  10457. *
  10458. * @static
  10459. * @memberOf _
  10460. * @category String
  10461. * @param {string} [string=''] The string to trim.
  10462. * @param {string} [chars=whitespace] The characters to trim.
  10463. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10464. * @returns {string} Returns the trimmed string.
  10465. * @example
  10466. *
  10467. * _.trimLeft(' abc ');
  10468. * // => 'abc '
  10469. *
  10470. * _.trimLeft('-_-abc-_-', '_-');
  10471. * // => 'abc-_-'
  10472. */
  10473. function trimLeft(string, chars, guard) {
  10474. var value = string;
  10475. string = baseToString(string);
  10476. if (!string) {
  10477. return string;
  10478. }
  10479. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  10480. return string.slice(trimmedLeftIndex(string));
  10481. }
  10482. return string.slice(charsLeftIndex(string, (chars + '')));
  10483. }
  10484. /**
  10485. * Removes trailing whitespace or specified characters from `string`.
  10486. *
  10487. * @static
  10488. * @memberOf _
  10489. * @category String
  10490. * @param {string} [string=''] The string to trim.
  10491. * @param {string} [chars=whitespace] The characters to trim.
  10492. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10493. * @returns {string} Returns the trimmed string.
  10494. * @example
  10495. *
  10496. * _.trimRight(' abc ');
  10497. * // => ' abc'
  10498. *
  10499. * _.trimRight('-_-abc-_-', '_-');
  10500. * // => '-_-abc'
  10501. */
  10502. function trimRight(string, chars, guard) {
  10503. var value = string;
  10504. string = baseToString(string);
  10505. if (!string) {
  10506. return string;
  10507. }
  10508. if (guard ? isIterateeCall(value, chars, guard) : chars == null) {
  10509. return string.slice(0, trimmedRightIndex(string) + 1);
  10510. }
  10511. return string.slice(0, charsRightIndex(string, (chars + '')) + 1);
  10512. }
  10513. /**
  10514. * Truncates `string` if it's longer than the given maximum string length.
  10515. * The last characters of the truncated string are replaced with the omission
  10516. * string which defaults to "...".
  10517. *
  10518. * @static
  10519. * @memberOf _
  10520. * @category String
  10521. * @param {string} [string=''] The string to truncate.
  10522. * @param {Object|number} [options] The options object or maximum string length.
  10523. * @param {number} [options.length=30] The maximum string length.
  10524. * @param {string} [options.omission='...'] The string to indicate text is omitted.
  10525. * @param {RegExp|string} [options.separator] The separator pattern to truncate to.
  10526. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10527. * @returns {string} Returns the truncated string.
  10528. * @example
  10529. *
  10530. * _.trunc('hi-diddly-ho there, neighborino');
  10531. * // => 'hi-diddly-ho there, neighbo...'
  10532. *
  10533. * _.trunc('hi-diddly-ho there, neighborino', 24);
  10534. * // => 'hi-diddly-ho there, n...'
  10535. *
  10536. * _.trunc('hi-diddly-ho there, neighborino', {
  10537. * 'length': 24,
  10538. * 'separator': ' '
  10539. * });
  10540. * // => 'hi-diddly-ho there,...'
  10541. *
  10542. * _.trunc('hi-diddly-ho there, neighborino', {
  10543. * 'length': 24,
  10544. * 'separator': /,? +/
  10545. * });
  10546. * // => 'hi-diddly-ho there...'
  10547. *
  10548. * _.trunc('hi-diddly-ho there, neighborino', {
  10549. * 'omission': ' [...]'
  10550. * });
  10551. * // => 'hi-diddly-ho there, neig [...]'
  10552. */
  10553. function trunc(string, options, guard) {
  10554. if (guard && isIterateeCall(string, options, guard)) {
  10555. options = undefined;
  10556. }
  10557. var length = DEFAULT_TRUNC_LENGTH,
  10558. omission = DEFAULT_TRUNC_OMISSION;
  10559. if (options != null) {
  10560. if (isObject(options)) {
  10561. var separator = 'separator' in options ? options.separator : separator;
  10562. length = 'length' in options ? (+options.length || 0) : length;
  10563. omission = 'omission' in options ? baseToString(options.omission) : omission;
  10564. } else {
  10565. length = +options || 0;
  10566. }
  10567. }
  10568. string = baseToString(string);
  10569. if (length >= string.length) {
  10570. return string;
  10571. }
  10572. var end = length - omission.length;
  10573. if (end < 1) {
  10574. return omission;
  10575. }
  10576. var result = string.slice(0, end);
  10577. if (separator == null) {
  10578. return result + omission;
  10579. }
  10580. if (isRegExp(separator)) {
  10581. if (string.slice(end).search(separator)) {
  10582. var match,
  10583. newEnd,
  10584. substring = string.slice(0, end);
  10585. if (!separator.global) {
  10586. separator = RegExp(separator.source, (reFlags.exec(separator) || '') + 'g');
  10587. }
  10588. separator.lastIndex = 0;
  10589. while ((match = separator.exec(substring))) {
  10590. newEnd = match.index;
  10591. }
  10592. result = result.slice(0, newEnd == null ? end : newEnd);
  10593. }
  10594. } else if (string.indexOf(separator, end) != end) {
  10595. var index = result.lastIndexOf(separator);
  10596. if (index > -1) {
  10597. result = result.slice(0, index);
  10598. }
  10599. }
  10600. return result + omission;
  10601. }
  10602. /**
  10603. * The inverse of `_.escape`; this method converts the HTML entities
  10604. * `&amp;`, `&lt;`, `&gt;`, `&quot;`, `&#39;`, and `&#96;` in `string` to their
  10605. * corresponding characters.
  10606. *
  10607. * **Note:** No other HTML entities are unescaped. To unescape additional HTML
  10608. * entities use a third-party library like [_he_](https://mths.be/he).
  10609. *
  10610. * @static
  10611. * @memberOf _
  10612. * @category String
  10613. * @param {string} [string=''] The string to unescape.
  10614. * @returns {string} Returns the unescaped string.
  10615. * @example
  10616. *
  10617. * _.unescape('fred, barney, &amp; pebbles');
  10618. * // => 'fred, barney, & pebbles'
  10619. */
  10620. function unescape(string) {
  10621. string = baseToString(string);
  10622. return (string && reHasEscapedHtml.test(string))
  10623. ? string.replace(reEscapedHtml, unescapeHtmlChar)
  10624. : string;
  10625. }
  10626. /**
  10627. * Splits `string` into an array of its words.
  10628. *
  10629. * @static
  10630. * @memberOf _
  10631. * @category String
  10632. * @param {string} [string=''] The string to inspect.
  10633. * @param {RegExp|string} [pattern] The pattern to match words.
  10634. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10635. * @returns {Array} Returns the words of `string`.
  10636. * @example
  10637. *
  10638. * _.words('fred, barney, & pebbles');
  10639. * // => ['fred', 'barney', 'pebbles']
  10640. *
  10641. * _.words('fred, barney, & pebbles', /[^, ]+/g);
  10642. * // => ['fred', 'barney', '&', 'pebbles']
  10643. */
  10644. function words(string, pattern, guard) {
  10645. if (guard && isIterateeCall(string, pattern, guard)) {
  10646. pattern = undefined;
  10647. }
  10648. string = baseToString(string);
  10649. return string.match(pattern || reWords) || [];
  10650. }
  10651. /*------------------------------------------------------------------------*/
  10652. /**
  10653. * Attempts to invoke `func`, returning either the result or the caught error
  10654. * object. Any additional arguments are provided to `func` when it's invoked.
  10655. *
  10656. * @static
  10657. * @memberOf _
  10658. * @category Utility
  10659. * @param {Function} func The function to attempt.
  10660. * @returns {*} Returns the `func` result or error object.
  10661. * @example
  10662. *
  10663. * // avoid throwing errors for invalid selectors
  10664. * var elements = _.attempt(function(selector) {
  10665. * return document.querySelectorAll(selector);
  10666. * }, '>_>');
  10667. *
  10668. * if (_.isError(elements)) {
  10669. * elements = [];
  10670. * }
  10671. */
  10672. var attempt = restParam(function(func, args) {
  10673. try {
  10674. return func.apply(undefined, args);
  10675. } catch(e) {
  10676. return isError(e) ? e : new Error(e);
  10677. }
  10678. });
  10679. /**
  10680. * Creates a function that invokes `func` with the `this` binding of `thisArg`
  10681. * and arguments of the created function. If `func` is a property name the
  10682. * created callback returns the property value for a given element. If `func`
  10683. * is an object the created callback returns `true` for elements that contain
  10684. * the equivalent object properties, otherwise it returns `false`.
  10685. *
  10686. * @static
  10687. * @memberOf _
  10688. * @alias iteratee
  10689. * @category Utility
  10690. * @param {*} [func=_.identity] The value to convert to a callback.
  10691. * @param {*} [thisArg] The `this` binding of `func`.
  10692. * @param- {Object} [guard] Enables use as a callback for functions like `_.map`.
  10693. * @returns {Function} Returns the callback.
  10694. * @example
  10695. *
  10696. * var users = [
  10697. * { 'user': 'barney', 'age': 36 },
  10698. * { 'user': 'fred', 'age': 40 }
  10699. * ];
  10700. *
  10701. * // wrap to create custom callback shorthands
  10702. * _.callback = _.wrap(_.callback, function(callback, func, thisArg) {
  10703. * var match = /^(.+?)__([gl]t)(.+)$/.exec(func);
  10704. * if (!match) {
  10705. * return callback(func, thisArg);
  10706. * }
  10707. * return function(object) {
  10708. * return match[2] == 'gt'
  10709. * ? object[match[1]] > match[3]
  10710. * : object[match[1]] < match[3];
  10711. * };
  10712. * });
  10713. *
  10714. * _.filter(users, 'age__gt36');
  10715. * // => [{ 'user': 'fred', 'age': 40 }]
  10716. */
  10717. function callback(func, thisArg, guard) {
  10718. if (guard && isIterateeCall(func, thisArg, guard)) {
  10719. thisArg = undefined;
  10720. }
  10721. return isObjectLike(func)
  10722. ? matches(func)
  10723. : baseCallback(func, thisArg);
  10724. }
  10725. /**
  10726. * Creates a function that returns `value`.
  10727. *
  10728. * @static
  10729. * @memberOf _
  10730. * @category Utility
  10731. * @param {*} value The value to return from the new function.
  10732. * @returns {Function} Returns the new function.
  10733. * @example
  10734. *
  10735. * var object = { 'user': 'fred' };
  10736. * var getter = _.constant(object);
  10737. *
  10738. * getter() === object;
  10739. * // => true
  10740. */
  10741. function constant(value) {
  10742. return function() {
  10743. return value;
  10744. };
  10745. }
  10746. /**
  10747. * This method returns the first argument provided to it.
  10748. *
  10749. * @static
  10750. * @memberOf _
  10751. * @category Utility
  10752. * @param {*} value Any value.
  10753. * @returns {*} Returns `value`.
  10754. * @example
  10755. *
  10756. * var object = { 'user': 'fred' };
  10757. *
  10758. * _.identity(object) === object;
  10759. * // => true
  10760. */
  10761. function identity(value) {
  10762. return value;
  10763. }
  10764. /**
  10765. * Creates a function that performs a deep comparison between a given object
  10766. * and `source`, returning `true` if the given object has equivalent property
  10767. * values, else `false`.
  10768. *
  10769. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  10770. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  10771. * their own, not inherited, enumerable properties. For comparing a single
  10772. * own or inherited property value see `_.matchesProperty`.
  10773. *
  10774. * @static
  10775. * @memberOf _
  10776. * @category Utility
  10777. * @param {Object} source The object of property values to match.
  10778. * @returns {Function} Returns the new function.
  10779. * @example
  10780. *
  10781. * var users = [
  10782. * { 'user': 'barney', 'age': 36, 'active': true },
  10783. * { 'user': 'fred', 'age': 40, 'active': false }
  10784. * ];
  10785. *
  10786. * _.filter(users, _.matches({ 'age': 40, 'active': false }));
  10787. * // => [{ 'user': 'fred', 'age': 40, 'active': false }]
  10788. */
  10789. function matches(source) {
  10790. return baseMatches(baseClone(source, true));
  10791. }
  10792. /**
  10793. * Creates a function that compares the property value of `path` on a given
  10794. * object to `value`.
  10795. *
  10796. * **Note:** This method supports comparing arrays, booleans, `Date` objects,
  10797. * numbers, `Object` objects, regexes, and strings. Objects are compared by
  10798. * their own, not inherited, enumerable properties.
  10799. *
  10800. * @static
  10801. * @memberOf _
  10802. * @category Utility
  10803. * @param {Array|string} path The path of the property to get.
  10804. * @param {*} srcValue The value to match.
  10805. * @returns {Function} Returns the new function.
  10806. * @example
  10807. *
  10808. * var users = [
  10809. * { 'user': 'barney' },
  10810. * { 'user': 'fred' }
  10811. * ];
  10812. *
  10813. * _.find(users, _.matchesProperty('user', 'fred'));
  10814. * // => { 'user': 'fred' }
  10815. */
  10816. function matchesProperty(path, srcValue) {
  10817. return baseMatchesProperty(path, baseClone(srcValue, true));
  10818. }
  10819. /**
  10820. * Creates a function that invokes the method at `path` on a given object.
  10821. * Any additional arguments are provided to the invoked method.
  10822. *
  10823. * @static
  10824. * @memberOf _
  10825. * @category Utility
  10826. * @param {Array|string} path The path of the method to invoke.
  10827. * @param {...*} [args] The arguments to invoke the method with.
  10828. * @returns {Function} Returns the new function.
  10829. * @example
  10830. *
  10831. * var objects = [
  10832. * { 'a': { 'b': { 'c': _.constant(2) } } },
  10833. * { 'a': { 'b': { 'c': _.constant(1) } } }
  10834. * ];
  10835. *
  10836. * _.map(objects, _.method('a.b.c'));
  10837. * // => [2, 1]
  10838. *
  10839. * _.invoke(_.sortBy(objects, _.method(['a', 'b', 'c'])), 'a.b.c');
  10840. * // => [1, 2]
  10841. */
  10842. var method = restParam(function(path, args) {
  10843. return function(object) {
  10844. return invokePath(object, path, args);
  10845. };
  10846. });
  10847. /**
  10848. * The opposite of `_.method`; this method creates a function that invokes
  10849. * the method at a given path on `object`. Any additional arguments are
  10850. * provided to the invoked method.
  10851. *
  10852. * @static
  10853. * @memberOf _
  10854. * @category Utility
  10855. * @param {Object} object The object to query.
  10856. * @param {...*} [args] The arguments to invoke the method with.
  10857. * @returns {Function} Returns the new function.
  10858. * @example
  10859. *
  10860. * var array = _.times(3, _.constant),
  10861. * object = { 'a': array, 'b': array, 'c': array };
  10862. *
  10863. * _.map(['a[2]', 'c[0]'], _.methodOf(object));
  10864. * // => [2, 0]
  10865. *
  10866. * _.map([['a', '2'], ['c', '0']], _.methodOf(object));
  10867. * // => [2, 0]
  10868. */
  10869. var methodOf = restParam(function(object, args) {
  10870. return function(path) {
  10871. return invokePath(object, path, args);
  10872. };
  10873. });
  10874. /**
  10875. * Adds all own enumerable function properties of a source object to the
  10876. * destination object. If `object` is a function then methods are added to
  10877. * its prototype as well.
  10878. *
  10879. * **Note:** Use `_.runInContext` to create a pristine `lodash` function to
  10880. * avoid conflicts caused by modifying the original.
  10881. *
  10882. * @static
  10883. * @memberOf _
  10884. * @category Utility
  10885. * @param {Function|Object} [object=lodash] The destination object.
  10886. * @param {Object} source The object of functions to add.
  10887. * @param {Object} [options] The options object.
  10888. * @param {boolean} [options.chain=true] Specify whether the functions added
  10889. * are chainable.
  10890. * @returns {Function|Object} Returns `object`.
  10891. * @example
  10892. *
  10893. * function vowels(string) {
  10894. * return _.filter(string, function(v) {
  10895. * return /[aeiou]/i.test(v);
  10896. * });
  10897. * }
  10898. *
  10899. * _.mixin({ 'vowels': vowels });
  10900. * _.vowels('fred');
  10901. * // => ['e']
  10902. *
  10903. * _('fred').vowels().value();
  10904. * // => ['e']
  10905. *
  10906. * _.mixin({ 'vowels': vowels }, { 'chain': false });
  10907. * _('fred').vowels();
  10908. * // => ['e']
  10909. */
  10910. function mixin(object, source, options) {
  10911. if (options == null) {
  10912. var isObj = isObject(source),
  10913. props = isObj ? keys(source) : undefined,
  10914. methodNames = (props && props.length) ? baseFunctions(source, props) : undefined;
  10915. if (!(methodNames ? methodNames.length : isObj)) {
  10916. methodNames = false;
  10917. options = source;
  10918. source = object;
  10919. object = this;
  10920. }
  10921. }
  10922. if (!methodNames) {
  10923. methodNames = baseFunctions(source, keys(source));
  10924. }
  10925. var chain = true,
  10926. index = -1,
  10927. isFunc = isFunction(object),
  10928. length = methodNames.length;
  10929. if (options === false) {
  10930. chain = false;
  10931. } else if (isObject(options) && 'chain' in options) {
  10932. chain = options.chain;
  10933. }
  10934. while (++index < length) {
  10935. var methodName = methodNames[index],
  10936. func = source[methodName];
  10937. object[methodName] = func;
  10938. if (isFunc) {
  10939. object.prototype[methodName] = (function(func) {
  10940. return function() {
  10941. var chainAll = this.__chain__;
  10942. if (chain || chainAll) {
  10943. var result = object(this.__wrapped__),
  10944. actions = result.__actions__ = arrayCopy(this.__actions__);
  10945. actions.push({ 'func': func, 'args': arguments, 'thisArg': object });
  10946. result.__chain__ = chainAll;
  10947. return result;
  10948. }
  10949. return func.apply(object, arrayPush([this.value()], arguments));
  10950. };
  10951. }(func));
  10952. }
  10953. }
  10954. return object;
  10955. }
  10956. /**
  10957. * Reverts the `_` variable to its previous value and returns a reference to
  10958. * the `lodash` function.
  10959. *
  10960. * @static
  10961. * @memberOf _
  10962. * @category Utility
  10963. * @returns {Function} Returns the `lodash` function.
  10964. * @example
  10965. *
  10966. * var lodash = _.noConflict();
  10967. */
  10968. function noConflict() {
  10969. root._ = oldDash;
  10970. return this;
  10971. }
  10972. /**
  10973. * A no-operation function that returns `undefined` regardless of the
  10974. * arguments it receives.
  10975. *
  10976. * @static
  10977. * @memberOf _
  10978. * @category Utility
  10979. * @example
  10980. *
  10981. * var object = { 'user': 'fred' };
  10982. *
  10983. * _.noop(object) === undefined;
  10984. * // => true
  10985. */
  10986. function noop() {
  10987. // No operation performed.
  10988. }
  10989. /**
  10990. * Creates a function that returns the property value at `path` on a
  10991. * given object.
  10992. *
  10993. * @static
  10994. * @memberOf _
  10995. * @category Utility
  10996. * @param {Array|string} path The path of the property to get.
  10997. * @returns {Function} Returns the new function.
  10998. * @example
  10999. *
  11000. * var objects = [
  11001. * { 'a': { 'b': { 'c': 2 } } },
  11002. * { 'a': { 'b': { 'c': 1 } } }
  11003. * ];
  11004. *
  11005. * _.map(objects, _.property('a.b.c'));
  11006. * // => [2, 1]
  11007. *
  11008. * _.pluck(_.sortBy(objects, _.property(['a', 'b', 'c'])), 'a.b.c');
  11009. * // => [1, 2]
  11010. */
  11011. function property(path) {
  11012. return isKey(path) ? baseProperty(path) : basePropertyDeep(path);
  11013. }
  11014. /**
  11015. * The opposite of `_.property`; this method creates a function that returns
  11016. * the property value at a given path on `object`.
  11017. *
  11018. * @static
  11019. * @memberOf _
  11020. * @category Utility
  11021. * @param {Object} object The object to query.
  11022. * @returns {Function} Returns the new function.
  11023. * @example
  11024. *
  11025. * var array = [0, 1, 2],
  11026. * object = { 'a': array, 'b': array, 'c': array };
  11027. *
  11028. * _.map(['a[2]', 'c[0]'], _.propertyOf(object));
  11029. * // => [2, 0]
  11030. *
  11031. * _.map([['a', '2'], ['c', '0']], _.propertyOf(object));
  11032. * // => [2, 0]
  11033. */
  11034. function propertyOf(object) {
  11035. return function(path) {
  11036. return baseGet(object, toPath(path), (path + ''));
  11037. };
  11038. }
  11039. /**
  11040. * Creates an array of numbers (positive and/or negative) progressing from
  11041. * `start` up to, but not including, `end`. If `end` is not specified it's
  11042. * set to `start` with `start` then set to `0`. If `end` is less than `start`
  11043. * a zero-length range is created unless a negative `step` is specified.
  11044. *
  11045. * @static
  11046. * @memberOf _
  11047. * @category Utility
  11048. * @param {number} [start=0] The start of the range.
  11049. * @param {number} end The end of the range.
  11050. * @param {number} [step=1] The value to increment or decrement by.
  11051. * @returns {Array} Returns the new array of numbers.
  11052. * @example
  11053. *
  11054. * _.range(4);
  11055. * // => [0, 1, 2, 3]
  11056. *
  11057. * _.range(1, 5);
  11058. * // => [1, 2, 3, 4]
  11059. *
  11060. * _.range(0, 20, 5);
  11061. * // => [0, 5, 10, 15]
  11062. *
  11063. * _.range(0, -4, -1);
  11064. * // => [0, -1, -2, -3]
  11065. *
  11066. * _.range(1, 4, 0);
  11067. * // => [1, 1, 1]
  11068. *
  11069. * _.range(0);
  11070. * // => []
  11071. */
  11072. function range(start, end, step) {
  11073. if (step && isIterateeCall(start, end, step)) {
  11074. end = step = undefined;
  11075. }
  11076. start = +start || 0;
  11077. step = step == null ? 1 : (+step || 0);
  11078. if (end == null) {
  11079. end = start;
  11080. start = 0;
  11081. } else {
  11082. end = +end || 0;
  11083. }
  11084. // Use `Array(length)` so engines like Chakra and V8 avoid slower modes.
  11085. // See https://youtu.be/XAqIpGU8ZZk#t=17m25s for more details.
  11086. var index = -1,
  11087. length = nativeMax(nativeCeil((end - start) / (step || 1)), 0),
  11088. result = Array(length);
  11089. while (++index < length) {
  11090. result[index] = start;
  11091. start += step;
  11092. }
  11093. return result;
  11094. }
  11095. /**
  11096. * Invokes the iteratee function `n` times, returning an array of the results
  11097. * of each invocation. The `iteratee` is bound to `thisArg` and invoked with
  11098. * one argument; (index).
  11099. *
  11100. * @static
  11101. * @memberOf _
  11102. * @category Utility
  11103. * @param {number} n The number of times to invoke `iteratee`.
  11104. * @param {Function} [iteratee=_.identity] The function invoked per iteration.
  11105. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11106. * @returns {Array} Returns the array of results.
  11107. * @example
  11108. *
  11109. * var diceRolls = _.times(3, _.partial(_.random, 1, 6, false));
  11110. * // => [3, 6, 4]
  11111. *
  11112. * _.times(3, function(n) {
  11113. * mage.castSpell(n);
  11114. * });
  11115. * // => invokes `mage.castSpell(n)` three times with `n` of `0`, `1`, and `2`
  11116. *
  11117. * _.times(3, function(n) {
  11118. * this.cast(n);
  11119. * }, mage);
  11120. * // => also invokes `mage.castSpell(n)` three times
  11121. */
  11122. function times(n, iteratee, thisArg) {
  11123. n = nativeFloor(n);
  11124. // Exit early to avoid a JSC JIT bug in Safari 8
  11125. // where `Array(0)` is treated as `Array(1)`.
  11126. if (n < 1 || !nativeIsFinite(n)) {
  11127. return [];
  11128. }
  11129. var index = -1,
  11130. result = Array(nativeMin(n, MAX_ARRAY_LENGTH));
  11131. iteratee = bindCallback(iteratee, thisArg, 1);
  11132. while (++index < n) {
  11133. if (index < MAX_ARRAY_LENGTH) {
  11134. result[index] = iteratee(index);
  11135. } else {
  11136. iteratee(index);
  11137. }
  11138. }
  11139. return result;
  11140. }
  11141. /**
  11142. * Generates a unique ID. If `prefix` is provided the ID is appended to it.
  11143. *
  11144. * @static
  11145. * @memberOf _
  11146. * @category Utility
  11147. * @param {string} [prefix] The value to prefix the ID with.
  11148. * @returns {string} Returns the unique ID.
  11149. * @example
  11150. *
  11151. * _.uniqueId('contact_');
  11152. * // => 'contact_104'
  11153. *
  11154. * _.uniqueId();
  11155. * // => '105'
  11156. */
  11157. function uniqueId(prefix) {
  11158. var id = ++idCounter;
  11159. return baseToString(prefix) + id;
  11160. }
  11161. /*------------------------------------------------------------------------*/
  11162. /**
  11163. * Adds two numbers.
  11164. *
  11165. * @static
  11166. * @memberOf _
  11167. * @category Math
  11168. * @param {number} augend The first number to add.
  11169. * @param {number} addend The second number to add.
  11170. * @returns {number} Returns the sum.
  11171. * @example
  11172. *
  11173. * _.add(6, 4);
  11174. * // => 10
  11175. */
  11176. function add(augend, addend) {
  11177. return (+augend || 0) + (+addend || 0);
  11178. }
  11179. /**
  11180. * Calculates `n` rounded up to `precision`.
  11181. *
  11182. * @static
  11183. * @memberOf _
  11184. * @category Math
  11185. * @param {number} n The number to round up.
  11186. * @param {number} [precision=0] The precision to round up to.
  11187. * @returns {number} Returns the rounded up number.
  11188. * @example
  11189. *
  11190. * _.ceil(4.006);
  11191. * // => 5
  11192. *
  11193. * _.ceil(6.004, 2);
  11194. * // => 6.01
  11195. *
  11196. * _.ceil(6040, -2);
  11197. * // => 6100
  11198. */
  11199. var ceil = createRound('ceil');
  11200. /**
  11201. * Calculates `n` rounded down to `precision`.
  11202. *
  11203. * @static
  11204. * @memberOf _
  11205. * @category Math
  11206. * @param {number} n The number to round down.
  11207. * @param {number} [precision=0] The precision to round down to.
  11208. * @returns {number} Returns the rounded down number.
  11209. * @example
  11210. *
  11211. * _.floor(4.006);
  11212. * // => 4
  11213. *
  11214. * _.floor(0.046, 2);
  11215. * // => 0.04
  11216. *
  11217. * _.floor(4060, -2);
  11218. * // => 4000
  11219. */
  11220. var floor = createRound('floor');
  11221. /**
  11222. * Gets the maximum value of `collection`. If `collection` is empty or falsey
  11223. * `-Infinity` is returned. If an iteratee function is provided it's invoked
  11224. * for each value in `collection` to generate the criterion by which the value
  11225. * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
  11226. * arguments: (value, index, collection).
  11227. *
  11228. * If a property name is provided for `iteratee` the created `_.property`
  11229. * style callback returns the property value of the given element.
  11230. *
  11231. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  11232. * style callback returns `true` for elements that have a matching property
  11233. * value, else `false`.
  11234. *
  11235. * If an object is provided for `iteratee` the created `_.matches` style
  11236. * callback returns `true` for elements that have the properties of the given
  11237. * object, else `false`.
  11238. *
  11239. * @static
  11240. * @memberOf _
  11241. * @category Math
  11242. * @param {Array|Object|string} collection The collection to iterate over.
  11243. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  11244. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11245. * @returns {*} Returns the maximum value.
  11246. * @example
  11247. *
  11248. * _.max([4, 2, 8, 6]);
  11249. * // => 8
  11250. *
  11251. * _.max([]);
  11252. * // => -Infinity
  11253. *
  11254. * var users = [
  11255. * { 'user': 'barney', 'age': 36 },
  11256. * { 'user': 'fred', 'age': 40 }
  11257. * ];
  11258. *
  11259. * _.max(users, function(chr) {
  11260. * return chr.age;
  11261. * });
  11262. * // => { 'user': 'fred', 'age': 40 }
  11263. *
  11264. * // using the `_.property` callback shorthand
  11265. * _.max(users, 'age');
  11266. * // => { 'user': 'fred', 'age': 40 }
  11267. */
  11268. var max = createExtremum(gt, NEGATIVE_INFINITY);
  11269. /**
  11270. * Gets the minimum value of `collection`. If `collection` is empty or falsey
  11271. * `Infinity` is returned. If an iteratee function is provided it's invoked
  11272. * for each value in `collection` to generate the criterion by which the value
  11273. * is ranked. The `iteratee` is bound to `thisArg` and invoked with three
  11274. * arguments: (value, index, collection).
  11275. *
  11276. * If a property name is provided for `iteratee` the created `_.property`
  11277. * style callback returns the property value of the given element.
  11278. *
  11279. * If a value is also provided for `thisArg` the created `_.matchesProperty`
  11280. * style callback returns `true` for elements that have a matching property
  11281. * value, else `false`.
  11282. *
  11283. * If an object is provided for `iteratee` the created `_.matches` style
  11284. * callback returns `true` for elements that have the properties of the given
  11285. * object, else `false`.
  11286. *
  11287. * @static
  11288. * @memberOf _
  11289. * @category Math
  11290. * @param {Array|Object|string} collection The collection to iterate over.
  11291. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  11292. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11293. * @returns {*} Returns the minimum value.
  11294. * @example
  11295. *
  11296. * _.min([4, 2, 8, 6]);
  11297. * // => 2
  11298. *
  11299. * _.min([]);
  11300. * // => Infinity
  11301. *
  11302. * var users = [
  11303. * { 'user': 'barney', 'age': 36 },
  11304. * { 'user': 'fred', 'age': 40 }
  11305. * ];
  11306. *
  11307. * _.min(users, function(chr) {
  11308. * return chr.age;
  11309. * });
  11310. * // => { 'user': 'barney', 'age': 36 }
  11311. *
  11312. * // using the `_.property` callback shorthand
  11313. * _.min(users, 'age');
  11314. * // => { 'user': 'barney', 'age': 36 }
  11315. */
  11316. var min = createExtremum(lt, POSITIVE_INFINITY);
  11317. /**
  11318. * Calculates `n` rounded to `precision`.
  11319. *
  11320. * @static
  11321. * @memberOf _
  11322. * @category Math
  11323. * @param {number} n The number to round.
  11324. * @param {number} [precision=0] The precision to round to.
  11325. * @returns {number} Returns the rounded number.
  11326. * @example
  11327. *
  11328. * _.round(4.006);
  11329. * // => 4
  11330. *
  11331. * _.round(4.006, 2);
  11332. * // => 4.01
  11333. *
  11334. * _.round(4060, -2);
  11335. * // => 4100
  11336. */
  11337. var round = createRound('round');
  11338. /**
  11339. * Gets the sum of the values in `collection`.
  11340. *
  11341. * @static
  11342. * @memberOf _
  11343. * @category Math
  11344. * @param {Array|Object|string} collection The collection to iterate over.
  11345. * @param {Function|Object|string} [iteratee] The function invoked per iteration.
  11346. * @param {*} [thisArg] The `this` binding of `iteratee`.
  11347. * @returns {number} Returns the sum.
  11348. * @example
  11349. *
  11350. * _.sum([4, 6]);
  11351. * // => 10
  11352. *
  11353. * _.sum({ 'a': 4, 'b': 6 });
  11354. * // => 10
  11355. *
  11356. * var objects = [
  11357. * { 'n': 4 },
  11358. * { 'n': 6 }
  11359. * ];
  11360. *
  11361. * _.sum(objects, function(object) {
  11362. * return object.n;
  11363. * });
  11364. * // => 10
  11365. *
  11366. * // using the `_.property` callback shorthand
  11367. * _.sum(objects, 'n');
  11368. * // => 10
  11369. */
  11370. function sum(collection, iteratee, thisArg) {
  11371. if (thisArg && isIterateeCall(collection, iteratee, thisArg)) {
  11372. iteratee = undefined;
  11373. }
  11374. iteratee = getCallback(iteratee, thisArg, 3);
  11375. return iteratee.length == 1
  11376. ? arraySum(isArray(collection) ? collection : toIterable(collection), iteratee)
  11377. : baseSum(collection, iteratee);
  11378. }
  11379. /*------------------------------------------------------------------------*/
  11380. // Ensure wrappers are instances of `baseLodash`.
  11381. lodash.prototype = baseLodash.prototype;
  11382. LodashWrapper.prototype = baseCreate(baseLodash.prototype);
  11383. LodashWrapper.prototype.constructor = LodashWrapper;
  11384. LazyWrapper.prototype = baseCreate(baseLodash.prototype);
  11385. LazyWrapper.prototype.constructor = LazyWrapper;
  11386. // Add functions to the `Map` cache.
  11387. MapCache.prototype['delete'] = mapDelete;
  11388. MapCache.prototype.get = mapGet;
  11389. MapCache.prototype.has = mapHas;
  11390. MapCache.prototype.set = mapSet;
  11391. // Add functions to the `Set` cache.
  11392. SetCache.prototype.push = cachePush;
  11393. // Assign cache to `_.memoize`.
  11394. memoize.Cache = MapCache;
  11395. // Add functions that return wrapped values when chaining.
  11396. lodash.after = after;
  11397. lodash.ary = ary;
  11398. lodash.assign = assign;
  11399. lodash.at = at;
  11400. lodash.before = before;
  11401. lodash.bind = bind;
  11402. lodash.bindAll = bindAll;
  11403. lodash.bindKey = bindKey;
  11404. lodash.callback = callback;
  11405. lodash.chain = chain;
  11406. lodash.chunk = chunk;
  11407. lodash.compact = compact;
  11408. lodash.constant = constant;
  11409. lodash.countBy = countBy;
  11410. lodash.create = create;
  11411. lodash.curry = curry;
  11412. lodash.curryRight = curryRight;
  11413. lodash.debounce = debounce;
  11414. lodash.defaults = defaults;
  11415. lodash.defaultsDeep = defaultsDeep;
  11416. lodash.defer = defer;
  11417. lodash.delay = delay;
  11418. lodash.difference = difference;
  11419. lodash.drop = drop;
  11420. lodash.dropRight = dropRight;
  11421. lodash.dropRightWhile = dropRightWhile;
  11422. lodash.dropWhile = dropWhile;
  11423. lodash.fill = fill;
  11424. lodash.filter = filter;
  11425. lodash.flatten = flatten;
  11426. lodash.flattenDeep = flattenDeep;
  11427. lodash.flow = flow;
  11428. lodash.flowRight = flowRight;
  11429. lodash.forEach = forEach;
  11430. lodash.forEachRight = forEachRight;
  11431. lodash.forIn = forIn;
  11432. lodash.forInRight = forInRight;
  11433. lodash.forOwn = forOwn;
  11434. lodash.forOwnRight = forOwnRight;
  11435. lodash.functions = functions;
  11436. lodash.groupBy = groupBy;
  11437. lodash.indexBy = indexBy;
  11438. lodash.initial = initial;
  11439. lodash.intersection = intersection;
  11440. lodash.invert = invert;
  11441. lodash.invoke = invoke;
  11442. lodash.keys = keys;
  11443. lodash.keysIn = keysIn;
  11444. lodash.map = map;
  11445. lodash.mapKeys = mapKeys;
  11446. lodash.mapValues = mapValues;
  11447. lodash.matches = matches;
  11448. lodash.matchesProperty = matchesProperty;
  11449. lodash.memoize = memoize;
  11450. lodash.merge = merge;
  11451. lodash.method = method;
  11452. lodash.methodOf = methodOf;
  11453. lodash.mixin = mixin;
  11454. lodash.modArgs = modArgs;
  11455. lodash.negate = negate;
  11456. lodash.omit = omit;
  11457. lodash.once = once;
  11458. lodash.pairs = pairs;
  11459. lodash.partial = partial;
  11460. lodash.partialRight = partialRight;
  11461. lodash.partition = partition;
  11462. lodash.pick = pick;
  11463. lodash.pluck = pluck;
  11464. lodash.property = property;
  11465. lodash.propertyOf = propertyOf;
  11466. lodash.pull = pull;
  11467. lodash.pullAt = pullAt;
  11468. lodash.range = range;
  11469. lodash.rearg = rearg;
  11470. lodash.reject = reject;
  11471. lodash.remove = remove;
  11472. lodash.rest = rest;
  11473. lodash.restParam = restParam;
  11474. lodash.set = set;
  11475. lodash.shuffle = shuffle;
  11476. lodash.slice = slice;
  11477. lodash.sortBy = sortBy;
  11478. lodash.sortByAll = sortByAll;
  11479. lodash.sortByOrder = sortByOrder;
  11480. lodash.spread = spread;
  11481. lodash.take = take;
  11482. lodash.takeRight = takeRight;
  11483. lodash.takeRightWhile = takeRightWhile;
  11484. lodash.takeWhile = takeWhile;
  11485. lodash.tap = tap;
  11486. lodash.throttle = throttle;
  11487. lodash.thru = thru;
  11488. lodash.times = times;
  11489. lodash.toArray = toArray;
  11490. lodash.toPlainObject = toPlainObject;
  11491. lodash.transform = transform;
  11492. lodash.union = union;
  11493. lodash.uniq = uniq;
  11494. lodash.unzip = unzip;
  11495. lodash.unzipWith = unzipWith;
  11496. lodash.values = values;
  11497. lodash.valuesIn = valuesIn;
  11498. lodash.where = where;
  11499. lodash.without = without;
  11500. lodash.wrap = wrap;
  11501. lodash.xor = xor;
  11502. lodash.zip = zip;
  11503. lodash.zipObject = zipObject;
  11504. lodash.zipWith = zipWith;
  11505. // Add aliases.
  11506. lodash.backflow = flowRight;
  11507. lodash.collect = map;
  11508. lodash.compose = flowRight;
  11509. lodash.each = forEach;
  11510. lodash.eachRight = forEachRight;
  11511. lodash.extend = assign;
  11512. lodash.iteratee = callback;
  11513. lodash.methods = functions;
  11514. lodash.object = zipObject;
  11515. lodash.select = filter;
  11516. lodash.tail = rest;
  11517. lodash.unique = uniq;
  11518. // Add functions to `lodash.prototype`.
  11519. mixin(lodash, lodash);
  11520. /*------------------------------------------------------------------------*/
  11521. // Add functions that return unwrapped values when chaining.
  11522. lodash.add = add;
  11523. lodash.attempt = attempt;
  11524. lodash.camelCase = camelCase;
  11525. lodash.capitalize = capitalize;
  11526. lodash.ceil = ceil;
  11527. lodash.clone = clone;
  11528. lodash.cloneDeep = cloneDeep;
  11529. lodash.deburr = deburr;
  11530. lodash.endsWith = endsWith;
  11531. lodash.escape = escape;
  11532. lodash.escapeRegExp = escapeRegExp;
  11533. lodash.every = every;
  11534. lodash.find = find;
  11535. lodash.findIndex = findIndex;
  11536. lodash.findKey = findKey;
  11537. lodash.findLast = findLast;
  11538. lodash.findLastIndex = findLastIndex;
  11539. lodash.findLastKey = findLastKey;
  11540. lodash.findWhere = findWhere;
  11541. lodash.first = first;
  11542. lodash.floor = floor;
  11543. lodash.get = get;
  11544. lodash.gt = gt;
  11545. lodash.gte = gte;
  11546. lodash.has = has;
  11547. lodash.identity = identity;
  11548. lodash.includes = includes;
  11549. lodash.indexOf = indexOf;
  11550. lodash.inRange = inRange;
  11551. lodash.isArguments = isArguments;
  11552. lodash.isArray = isArray;
  11553. lodash.isBoolean = isBoolean;
  11554. lodash.isDate = isDate;
  11555. lodash.isElement = isElement;
  11556. lodash.isEmpty = isEmpty;
  11557. lodash.isEqual = isEqual;
  11558. lodash.isError = isError;
  11559. lodash.isFinite = isFinite;
  11560. lodash.isFunction = isFunction;
  11561. lodash.isMatch = isMatch;
  11562. lodash.isNaN = isNaN;
  11563. lodash.isNative = isNative;
  11564. lodash.isNull = isNull;
  11565. lodash.isNumber = isNumber;
  11566. lodash.isObject = isObject;
  11567. lodash.isPlainObject = isPlainObject;
  11568. lodash.isRegExp = isRegExp;
  11569. lodash.isString = isString;
  11570. lodash.isTypedArray = isTypedArray;
  11571. lodash.isUndefined = isUndefined;
  11572. lodash.kebabCase = kebabCase;
  11573. lodash.last = last;
  11574. lodash.lastIndexOf = lastIndexOf;
  11575. lodash.lt = lt;
  11576. lodash.lte = lte;
  11577. lodash.max = max;
  11578. lodash.min = min;
  11579. lodash.noConflict = noConflict;
  11580. lodash.noop = noop;
  11581. lodash.now = now;
  11582. lodash.pad = pad;
  11583. lodash.padLeft = padLeft;
  11584. lodash.padRight = padRight;
  11585. lodash.parseInt = parseInt;
  11586. lodash.random = random;
  11587. lodash.reduce = reduce;
  11588. lodash.reduceRight = reduceRight;
  11589. lodash.repeat = repeat;
  11590. lodash.result = result;
  11591. lodash.round = round;
  11592. lodash.runInContext = runInContext;
  11593. lodash.size = size;
  11594. lodash.snakeCase = snakeCase;
  11595. lodash.some = some;
  11596. lodash.sortedIndex = sortedIndex;
  11597. lodash.sortedLastIndex = sortedLastIndex;
  11598. lodash.startCase = startCase;
  11599. lodash.startsWith = startsWith;
  11600. lodash.sum = sum;
  11601. lodash.template = template;
  11602. lodash.trim = trim;
  11603. lodash.trimLeft = trimLeft;
  11604. lodash.trimRight = trimRight;
  11605. lodash.trunc = trunc;
  11606. lodash.unescape = unescape;
  11607. lodash.uniqueId = uniqueId;
  11608. lodash.words = words;
  11609. // Add aliases.
  11610. lodash.all = every;
  11611. lodash.any = some;
  11612. lodash.contains = includes;
  11613. lodash.eq = isEqual;
  11614. lodash.detect = find;
  11615. lodash.foldl = reduce;
  11616. lodash.foldr = reduceRight;
  11617. lodash.head = first;
  11618. lodash.include = includes;
  11619. lodash.inject = reduce;
  11620. mixin(lodash, (function() {
  11621. var source = {};
  11622. baseForOwn(lodash, function(func, methodName) {
  11623. if (!lodash.prototype[methodName]) {
  11624. source[methodName] = func;
  11625. }
  11626. });
  11627. return source;
  11628. }()), false);
  11629. /*------------------------------------------------------------------------*/
  11630. // Add functions capable of returning wrapped and unwrapped values when chaining.
  11631. lodash.sample = sample;
  11632. lodash.prototype.sample = function(n) {
  11633. if (!this.__chain__ && n == null) {
  11634. return sample(this.value());
  11635. }
  11636. return this.thru(function(value) {
  11637. return sample(value, n);
  11638. });
  11639. };
  11640. /*------------------------------------------------------------------------*/
  11641. /**
  11642. * The semantic version number.
  11643. *
  11644. * @static
  11645. * @memberOf _
  11646. * @type string
  11647. */
  11648. lodash.VERSION = VERSION;
  11649. // Assign default placeholders.
  11650. arrayEach(['bind', 'bindKey', 'curry', 'curryRight', 'partial', 'partialRight'], function(methodName) {
  11651. lodash[methodName].placeholder = lodash;
  11652. });
  11653. // Add `LazyWrapper` methods for `_.drop` and `_.take` variants.
  11654. arrayEach(['drop', 'take'], function(methodName, index) {
  11655. LazyWrapper.prototype[methodName] = function(n) {
  11656. var filtered = this.__filtered__;
  11657. if (filtered && !index) {
  11658. return new LazyWrapper(this);
  11659. }
  11660. n = n == null ? 1 : nativeMax(nativeFloor(n) || 0, 0);
  11661. var result = this.clone();
  11662. if (filtered) {
  11663. result.__takeCount__ = nativeMin(result.__takeCount__, n);
  11664. } else {
  11665. result.__views__.push({ 'size': n, 'type': methodName + (result.__dir__ < 0 ? 'Right' : '') });
  11666. }
  11667. return result;
  11668. };
  11669. LazyWrapper.prototype[methodName + 'Right'] = function(n) {
  11670. return this.reverse()[methodName](n).reverse();
  11671. };
  11672. });
  11673. // Add `LazyWrapper` methods that accept an `iteratee` value.
  11674. arrayEach(['filter', 'map', 'takeWhile'], function(methodName, index) {
  11675. var type = index + 1,
  11676. isFilter = type != LAZY_MAP_FLAG;
  11677. LazyWrapper.prototype[methodName] = function(iteratee, thisArg) {
  11678. var result = this.clone();
  11679. result.__iteratees__.push({ 'iteratee': getCallback(iteratee, thisArg, 1), 'type': type });
  11680. result.__filtered__ = result.__filtered__ || isFilter;
  11681. return result;
  11682. };
  11683. });
  11684. // Add `LazyWrapper` methods for `_.first` and `_.last`.
  11685. arrayEach(['first', 'last'], function(methodName, index) {
  11686. var takeName = 'take' + (index ? 'Right' : '');
  11687. LazyWrapper.prototype[methodName] = function() {
  11688. return this[takeName](1).value()[0];
  11689. };
  11690. });
  11691. // Add `LazyWrapper` methods for `_.initial` and `_.rest`.
  11692. arrayEach(['initial', 'rest'], function(methodName, index) {
  11693. var dropName = 'drop' + (index ? '' : 'Right');
  11694. LazyWrapper.prototype[methodName] = function() {
  11695. return this.__filtered__ ? new LazyWrapper(this) : this[dropName](1);
  11696. };
  11697. });
  11698. // Add `LazyWrapper` methods for `_.pluck` and `_.where`.
  11699. arrayEach(['pluck', 'where'], function(methodName, index) {
  11700. var operationName = index ? 'filter' : 'map',
  11701. createCallback = index ? baseMatches : property;
  11702. LazyWrapper.prototype[methodName] = function(value) {
  11703. return this[operationName](createCallback(value));
  11704. };
  11705. });
  11706. LazyWrapper.prototype.compact = function() {
  11707. return this.filter(identity);
  11708. };
  11709. LazyWrapper.prototype.reject = function(predicate, thisArg) {
  11710. predicate = getCallback(predicate, thisArg, 1);
  11711. return this.filter(function(value) {
  11712. return !predicate(value);
  11713. });
  11714. };
  11715. LazyWrapper.prototype.slice = function(start, end) {
  11716. start = start == null ? 0 : (+start || 0);
  11717. var result = this;
  11718. if (result.__filtered__ && (start > 0 || end < 0)) {
  11719. return new LazyWrapper(result);
  11720. }
  11721. if (start < 0) {
  11722. result = result.takeRight(-start);
  11723. } else if (start) {
  11724. result = result.drop(start);
  11725. }
  11726. if (end !== undefined) {
  11727. end = (+end || 0);
  11728. result = end < 0 ? result.dropRight(-end) : result.take(end - start);
  11729. }
  11730. return result;
  11731. };
  11732. LazyWrapper.prototype.takeRightWhile = function(predicate, thisArg) {
  11733. return this.reverse().takeWhile(predicate, thisArg).reverse();
  11734. };
  11735. LazyWrapper.prototype.toArray = function() {
  11736. return this.take(POSITIVE_INFINITY);
  11737. };
  11738. // Add `LazyWrapper` methods to `lodash.prototype`.
  11739. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  11740. var checkIteratee = /^(?:filter|map|reject)|While$/.test(methodName),
  11741. retUnwrapped = /^(?:first|last)$/.test(methodName),
  11742. lodashFunc = lodash[retUnwrapped ? ('take' + (methodName == 'last' ? 'Right' : '')) : methodName];
  11743. if (!lodashFunc) {
  11744. return;
  11745. }
  11746. lodash.prototype[methodName] = function() {
  11747. var args = retUnwrapped ? [1] : arguments,
  11748. chainAll = this.__chain__,
  11749. value = this.__wrapped__,
  11750. isHybrid = !!this.__actions__.length,
  11751. isLazy = value instanceof LazyWrapper,
  11752. iteratee = args[0],
  11753. useLazy = isLazy || isArray(value);
  11754. if (useLazy && checkIteratee && typeof iteratee == 'function' && iteratee.length != 1) {
  11755. // Avoid lazy use if the iteratee has a "length" value other than `1`.
  11756. isLazy = useLazy = false;
  11757. }
  11758. var interceptor = function(value) {
  11759. return (retUnwrapped && chainAll)
  11760. ? lodashFunc(value, 1)[0]
  11761. : lodashFunc.apply(undefined, arrayPush([value], args));
  11762. };
  11763. var action = { 'func': thru, 'args': [interceptor], 'thisArg': undefined },
  11764. onlyLazy = isLazy && !isHybrid;
  11765. if (retUnwrapped && !chainAll) {
  11766. if (onlyLazy) {
  11767. value = value.clone();
  11768. value.__actions__.push(action);
  11769. return func.call(value);
  11770. }
  11771. return lodashFunc.call(undefined, this.value())[0];
  11772. }
  11773. if (!retUnwrapped && useLazy) {
  11774. value = onlyLazy ? value : new LazyWrapper(this);
  11775. var result = func.apply(value, args);
  11776. result.__actions__.push(action);
  11777. return new LodashWrapper(result, chainAll);
  11778. }
  11779. return this.thru(interceptor);
  11780. };
  11781. });
  11782. // Add `Array` and `String` methods to `lodash.prototype`.
  11783. arrayEach(['join', 'pop', 'push', 'replace', 'shift', 'sort', 'splice', 'split', 'unshift'], function(methodName) {
  11784. var protoFunc = (/^(?:replace|split)$/.test(methodName) ? stringProto : arrayProto)[methodName],
  11785. chainName = /^(?:push|sort|unshift)$/.test(methodName) ? 'tap' : 'thru',
  11786. fixObjects = !support.spliceObjects && /^(?:pop|shift|splice)$/.test(methodName),
  11787. retUnwrapped = /^(?:join|pop|replace|shift)$/.test(methodName);
  11788. // Avoid array-like object bugs with `Array#shift` and `Array#splice` in
  11789. // IE < 9, Firefox < 10, and RingoJS.
  11790. var func = !fixObjects ? protoFunc : function() {
  11791. var result = protoFunc.apply(this, arguments);
  11792. if (this.length === 0) {
  11793. delete this[0];
  11794. }
  11795. return result;
  11796. };
  11797. lodash.prototype[methodName] = function() {
  11798. var args = arguments;
  11799. if (retUnwrapped && !this.__chain__) {
  11800. return func.apply(this.value(), args);
  11801. }
  11802. return this[chainName](function(value) {
  11803. return func.apply(value, args);
  11804. });
  11805. };
  11806. });
  11807. // Map minified function names to their real names.
  11808. baseForOwn(LazyWrapper.prototype, function(func, methodName) {
  11809. var lodashFunc = lodash[methodName];
  11810. if (lodashFunc) {
  11811. var key = (lodashFunc.name + ''),
  11812. names = realNames[key] || (realNames[key] = []);
  11813. names.push({ 'name': methodName, 'func': lodashFunc });
  11814. }
  11815. });
  11816. realNames[createHybridWrapper(undefined, BIND_KEY_FLAG).name] = [{ 'name': 'wrapper', 'func': undefined }];
  11817. // Add functions to the lazy wrapper.
  11818. LazyWrapper.prototype.clone = lazyClone;
  11819. LazyWrapper.prototype.reverse = lazyReverse;
  11820. LazyWrapper.prototype.value = lazyValue;
  11821. // Add chaining functions to the `lodash` wrapper.
  11822. lodash.prototype.chain = wrapperChain;
  11823. lodash.prototype.commit = wrapperCommit;
  11824. lodash.prototype.concat = wrapperConcat;
  11825. lodash.prototype.plant = wrapperPlant;
  11826. lodash.prototype.reverse = wrapperReverse;
  11827. lodash.prototype.toString = wrapperToString;
  11828. lodash.prototype.run = lodash.prototype.toJSON = lodash.prototype.valueOf = lodash.prototype.value = wrapperValue;
  11829. // Add function aliases to the `lodash` wrapper.
  11830. lodash.prototype.collect = lodash.prototype.map;
  11831. lodash.prototype.head = lodash.prototype.first;
  11832. lodash.prototype.select = lodash.prototype.filter;
  11833. lodash.prototype.tail = lodash.prototype.rest;
  11834. return lodash;
  11835. }
  11836. /*--------------------------------------------------------------------------*/
  11837. // Export lodash.
  11838. var _ = runInContext();
  11839. // Some AMD build optimizers like r.js check for condition patterns like the following:
  11840. if (typeof define == 'function' && typeof define.amd == 'object' && define.amd) {
  11841. // Expose lodash to the global object when an AMD loader is present to avoid
  11842. // errors in cases where lodash is loaded by a script tag and not intended
  11843. // as an AMD module. See http://requirejs.org/docs/errors.html#mismatch for
  11844. // more details.
  11845. root._ = _;
  11846. // Define as an anonymous module so, through path mapping, it can be
  11847. // referenced as the "underscore" module.
  11848. define(function() {
  11849. return _;
  11850. });
  11851. }
  11852. // Check for `exports` after `define` in case a build optimizer adds an `exports` object.
  11853. else if (freeExports && freeModule) {
  11854. // Export for Node.js or RingoJS.
  11855. if (moduleExports) {
  11856. (freeModule.exports = _)._ = _;
  11857. }
  11858. // Export for Rhino with CommonJS support.
  11859. else {
  11860. freeExports._ = _;
  11861. }
  11862. }
  11863. else {
  11864. // Export for a browser or Rhino.
  11865. root._ = _;
  11866. }
  11867. }.call(this));