Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bin-prettier.js 479KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348113491135011351113521135311354113551135611357113581135911360113611136211363113641136511366113671136811369113701137111372113731137411375113761137711378113791138011381113821138311384113851138611387113881138911390113911139211393113941139511396113971139811399114001140111402114031140411405114061140711408114091141011411114121141311414114151141611417114181141911420114211142211423114241142511426114271142811429114301143111432114331143411435114361143711438114391144011441114421144311444114451144611447114481144911450114511145211453114541145511456114571145811459114601146111462114631146411465114661146711468114691147011471114721147311474114751147611477114781147911480114811148211483114841148511486114871148811489114901149111492114931149411495114961149711498114991150011501115021150311504115051150611507115081150911510115111151211513115141151511516115171151811519115201152111522115231152411525115261152711528115291153011531115321153311534115351153611537115381153911540115411154211543115441154511546115471154811549115501155111552115531155411555115561155711558115591156011561115621156311564115651156611567115681156911570115711157211573115741157511576115771157811579115801158111582115831158411585115861158711588115891159011591115921159311594115951159611597115981159911600116011160211603116041160511606116071160811609116101161111612116131161411615116161161711618116191162011621116221162311624116251162611627116281162911630116311163211633116341163511636116371163811639116401164111642116431164411645116461164711648116491165011651116521165311654116551165611657116581165911660116611166211663116641166511666116671166811669116701167111672116731167411675116761167711678116791168011681116821168311684116851168611687116881168911690116911169211693116941169511696116971169811699117001170111702117031170411705117061170711708117091171011711117121171311714117151171611717117181171911720117211172211723117241172511726117271172811729117301173111732117331173411735117361173711738117391174011741117421174311744117451174611747117481174911750117511175211753117541175511756117571175811759117601176111762117631176411765117661176711768117691177011771117721177311774117751177611777117781177911780117811178211783117841178511786117871178811789117901179111792117931179411795117961179711798117991180011801118021180311804118051180611807118081180911810118111181211813118141181511816118171181811819118201182111822118231182411825118261182711828118291183011831118321183311834118351183611837118381183911840118411184211843118441184511846118471184811849118501185111852118531185411855118561185711858118591186011861118621186311864118651186611867118681186911870118711187211873118741187511876118771187811879118801188111882118831188411885118861188711888118891189011891118921189311894118951189611897118981189911900119011190211903119041190511906119071190811909119101191111912119131191411915119161191711918119191192011921119221192311924119251192611927119281192911930119311193211933119341193511936119371193811939119401194111942119431194411945119461194711948119491195011951119521195311954119551195611957119581195911960119611196211963119641196511966119671196811969119701197111972119731197411975119761197711978119791198011981119821198311984119851198611987119881198911990119911199211993119941199511996119971199811999120001200112002120031200412005120061200712008120091201012011120121201312014120151201612017120181201912020120211202212023120241202512026120271202812029120301203112032120331203412035120361203712038120391204012041120421204312044120451204612047120481204912050120511205212053120541205512056120571205812059120601206112062120631206412065120661206712068120691207012071120721207312074120751207612077120781207912080120811208212083120841208512086120871208812089120901209112092120931209412095120961209712098120991210012101121021210312104121051210612107121081210912110121111211212113121141211512116121171211812119121201212112122121231212412125121261212712128121291213012131121321213312134121351213612137121381213912140121411214212143121441214512146121471214812149121501215112152121531215412155121561215712158121591216012161121621216312164121651216612167121681216912170121711217212173121741217512176121771217812179121801218112182121831218412185121861218712188121891219012191121921219312194121951219612197121981219912200122011220212203122041220512206122071220812209122101221112212122131221412215122161221712218122191222012221122221222312224122251222612227122281222912230122311223212233122341223512236122371223812239122401224112242122431224412245122461224712248122491225012251122521225312254122551225612257122581225912260122611226212263122641226512266122671226812269122701227112272122731227412275122761227712278122791228012281122821228312284122851228612287122881228912290122911229212293122941229512296122971229812299123001230112302123031230412305123061230712308123091231012311123121231312314123151231612317123181231912320123211232212323123241232512326123271232812329123301233112332123331233412335123361233712338123391234012341123421234312344123451234612347123481234912350123511235212353123541235512356123571235812359123601236112362123631236412365123661236712368123691237012371123721237312374123751237612377123781237912380123811238212383123841238512386123871238812389123901239112392123931239412395123961239712398123991240012401124021240312404124051240612407124081240912410124111241212413124141241512416124171241812419124201242112422124231242412425124261242712428124291243012431124321243312434124351243612437124381243912440124411244212443124441244512446124471244812449124501245112452124531245412455124561245712458124591246012461124621246312464124651246612467124681246912470124711247212473124741247512476124771247812479124801248112482124831248412485124861248712488124891249012491124921249312494124951249612497124981249912500125011250212503125041250512506125071250812509125101251112512125131251412515125161251712518125191252012521125221252312524125251252612527125281252912530125311253212533125341253512536125371253812539125401254112542125431254412545125461254712548125491255012551125521255312554125551255612557125581255912560125611256212563125641256512566125671256812569125701257112572125731257412575125761257712578125791258012581125821258312584125851258612587125881258912590125911259212593125941259512596125971259812599126001260112602126031260412605126061260712608126091261012611126121261312614126151261612617126181261912620126211262212623126241262512626126271262812629126301263112632126331263412635126361263712638126391264012641126421264312644126451264612647126481264912650126511265212653126541265512656126571265812659126601266112662126631266412665126661266712668126691267012671126721267312674126751267612677126781267912680126811268212683126841268512686126871268812689126901269112692126931269412695126961269712698126991270012701127021270312704127051270612707127081270912710127111271212713127141271512716127171271812719127201272112722127231272412725127261272712728127291273012731127321273312734127351273612737127381273912740127411274212743127441274512746127471274812749127501275112752127531275412755127561275712758127591276012761127621276312764127651276612767127681276912770127711277212773127741277512776127771277812779127801278112782127831278412785127861278712788127891279012791127921279312794127951279612797127981279912800128011280212803128041280512806128071280812809128101281112812128131281412815128161281712818128191282012821128221282312824128251282612827128281282912830128311283212833128341283512836128371283812839128401284112842128431284412845128461284712848128491285012851128521285312854128551285612857128581285912860128611286212863128641286512866128671286812869128701287112872128731287412875128761287712878128791288012881128821288312884128851288612887128881288912890128911289212893128941289512896128971289812899129001290112902129031290412905129061290712908129091291012911129121291312914129151291612917129181291912920129211292212923129241292512926129271292812929129301293112932129331293412935129361293712938129391294012941129421294312944129451294612947129481294912950129511295212953129541295512956129571295812959129601296112962129631296412965129661296712968129691297012971129721297312974129751297612977129781297912980129811298212983129841298512986129871298812989129901299112992129931299412995129961299712998129991300013001130021300313004130051300613007130081300913010130111301213013130141301513016130171301813019130201302113022130231302413025130261302713028130291303013031130321303313034130351303613037130381303913040130411304213043130441304513046130471304813049130501305113052130531305413055130561305713058130591306013061130621306313064130651306613067130681306913070130711307213073130741307513076130771307813079130801308113082130831308413085130861308713088130891309013091130921309313094130951309613097130981309913100131011310213103131041310513106131071310813109131101311113112131131311413115131161311713118131191312013121131221312313124131251312613127131281312913130131311313213133131341313513136131371313813139131401314113142131431314413145131461314713148131491315013151131521315313154131551315613157131581315913160131611316213163131641316513166131671316813169131701317113172131731317413175131761317713178131791318013181131821318313184131851318613187131881318913190131911319213193131941319513196131971319813199132001320113202132031320413205132061320713208132091321013211132121321313214132151321613217132181321913220132211322213223132241322513226132271322813229132301323113232132331323413235132361323713238132391324013241132421324313244132451324613247132481324913250132511325213253132541325513256132571325813259132601326113262132631326413265132661326713268132691327013271132721327313274132751327613277132781327913280132811328213283132841328513286132871328813289132901329113292132931329413295132961329713298132991330013301133021330313304133051330613307133081330913310133111331213313133141331513316133171331813319133201332113322133231332413325133261332713328133291333013331133321333313334133351333613337133381333913340133411334213343133441334513346133471334813349133501335113352133531335413355133561335713358133591336013361133621336313364133651336613367133681336913370133711337213373133741337513376133771337813379133801338113382133831338413385133861338713388133891339013391133921339313394133951339613397133981339913400134011340213403134041340513406134071340813409134101341113412134131341413415134161341713418134191342013421134221342313424134251342613427134281342913430134311343213433134341343513436134371343813439134401344113442134431344413445134461344713448134491345013451134521345313454134551345613457134581345913460134611346213463134641346513466134671346813469134701347113472134731347413475134761347713478134791348013481134821348313484134851348613487134881348913490134911349213493134941349513496134971349813499135001350113502135031350413505135061350713508135091351013511135121351313514135151351613517135181351913520135211352213523135241352513526135271352813529135301353113532135331353413535135361353713538135391354013541135421354313544135451354613547135481354913550135511355213553135541355513556135571355813559135601356113562135631356413565135661356713568135691357013571135721357313574135751357613577135781357913580135811358213583135841358513586135871358813589135901359113592135931359413595135961359713598135991360013601136021360313604136051360613607136081360913610136111361213613136141361513616136171361813619136201362113622136231362413625136261362713628136291363013631136321363313634136351363613637136381363913640136411364213643136441364513646136471364813649136501365113652136531365413655136561365713658136591366013661136621366313664136651366613667136681366913670136711367213673136741367513676136771367813679136801368113682136831368413685136861368713688136891369013691136921369313694136951369613697136981369913700137011370213703137041370513706137071370813709137101371113712137131371413715137161371713718137191372013721137221372313724137251372613727137281372913730137311373213733137341373513736137371373813739137401374113742137431374413745137461374713748137491375013751137521375313754137551375613757137581375913760137611376213763137641376513766137671376813769137701377113772137731377413775137761377713778137791378013781137821378313784137851378613787137881378913790137911379213793137941379513796137971379813799138001380113802138031380413805138061380713808138091381013811138121381313814138151381613817138181381913820138211382213823138241382513826138271382813829138301383113832138331383413835138361383713838138391384013841138421384313844138451384613847138481384913850138511385213853138541385513856138571385813859138601386113862138631386413865138661386713868138691387013871138721387313874138751387613877138781387913880138811388213883138841388513886138871388813889138901389113892138931389413895138961389713898138991390013901139021390313904139051390613907139081390913910139111391213913139141391513916139171391813919139201392113922139231392413925139261392713928139291393013931139321393313934139351393613937139381393913940139411394213943139441394513946139471394813949139501395113952139531395413955139561395713958139591396013961139621396313964139651396613967139681396913970139711397213973139741397513976139771397813979139801398113982139831398413985139861398713988139891399013991139921399313994139951399613997139981399914000140011400214003140041400514006140071400814009140101401114012140131401414015140161401714018140191402014021140221402314024140251402614027140281402914030140311403214033140341403514036140371403814039140401404114042140431404414045140461404714048140491405014051140521405314054140551405614057140581405914060140611406214063140641406514066140671406814069140701407114072140731407414075140761407714078140791408014081140821408314084140851408614087140881408914090140911409214093140941409514096140971409814099141001410114102141031410414105141061410714108141091411014111141121411314114141151411614117141181411914120141211412214123141241412514126141271412814129141301413114132141331413414135141361413714138141391414014141141421414314144141451414614147141481414914150141511415214153141541415514156141571415814159141601416114162141631416414165141661416714168141691417014171141721417314174141751417614177141781417914180141811418214183141841418514186141871418814189141901419114192141931419414195141961419714198141991420014201142021420314204142051420614207142081420914210142111421214213142141421514216142171421814219142201422114222142231422414225142261422714228142291423014231142321423314234142351423614237142381423914240142411424214243142441424514246142471424814249142501425114252142531425414255142561425714258142591426014261142621426314264142651426614267142681426914270142711427214273142741427514276142771427814279142801428114282142831428414285142861428714288142891429014291142921429314294142951429614297142981429914300143011430214303143041430514306143071430814309143101431114312143131431414315143161431714318143191432014321143221432314324143251432614327143281432914330143311433214333143341433514336143371433814339143401434114342143431434414345143461434714348143491435014351143521435314354143551435614357143581435914360143611436214363143641436514366143671436814369143701437114372143731437414375143761437714378143791438014381143821438314384143851438614387143881438914390143911439214393143941439514396143971439814399144001440114402144031440414405144061440714408144091441014411144121441314414144151441614417144181441914420144211442214423144241442514426144271442814429144301443114432144331443414435144361443714438144391444014441144421444314444144451444614447144481444914450144511445214453144541445514456144571445814459144601446114462144631446414465144661446714468144691447014471144721447314474144751447614477144781447914480144811448214483144841448514486144871448814489144901449114492144931449414495144961449714498144991450014501145021450314504145051450614507145081450914510145111451214513145141451514516145171451814519145201452114522145231452414525145261452714528145291453014531145321453314534145351453614537145381453914540145411454214543145441454514546145471454814549145501455114552145531455414555145561455714558145591456014561145621456314564145651456614567145681456914570145711457214573145741457514576145771457814579145801458114582145831458414585145861458714588145891459014591145921459314594145951459614597145981459914600146011460214603146041460514606146071460814609146101461114612146131461414615146161461714618146191462014621146221462314624146251462614627146281462914630146311463214633146341463514636146371463814639146401464114642146431464414645146461464714648146491465014651146521465314654146551465614657146581465914660146611466214663146641466514666146671466814669146701467114672146731467414675146761467714678146791468014681146821468314684146851468614687146881468914690146911469214693146941469514696146971469814699147001470114702147031470414705147061470714708147091471014711147121471314714147151471614717147181471914720147211472214723147241472514726147271472814729147301473114732147331473414735147361473714738147391474014741147421474314744147451474614747147481474914750147511475214753147541475514756147571475814759147601476114762147631476414765147661476714768147691477014771147721477314774147751477614777147781477914780147811478214783147841478514786147871478814789147901479114792147931479414795147961479714798147991480014801148021480314804148051480614807148081480914810148111481214813148141481514816148171481814819148201482114822148231482414825148261482714828148291483014831148321483314834148351483614837148381483914840148411484214843148441484514846148471484814849148501485114852148531485414855148561485714858148591486014861148621486314864148651486614867148681486914870148711487214873148741487514876148771487814879148801488114882148831488414885148861488714888148891489014891148921489314894148951489614897148981489914900149011490214903149041490514906149071490814909149101491114912149131491414915149161491714918149191492014921149221492314924149251492614927149281492914930149311493214933149341493514936149371493814939149401494114942149431494414945149461494714948149491495014951149521495314954149551495614957149581495914960149611496214963149641496514966149671496814969149701497114972149731497414975149761497714978149791498014981149821498314984149851498614987149881498914990149911499214993149941499514996149971499814999150001500115002150031500415005150061500715008150091501015011150121501315014150151501615017150181501915020150211502215023150241502515026150271502815029150301503115032150331503415035150361503715038150391504015041150421504315044150451504615047150481504915050150511505215053150541505515056150571505815059150601506115062150631506415065150661506715068150691507015071150721507315074150751507615077150781507915080150811508215083150841508515086150871508815089150901509115092150931509415095150961509715098150991510015101151021510315104151051510615107151081510915110151111511215113151141511515116151171511815119151201512115122151231512415125151261512715128151291513015131151321513315134151351513615137151381513915140151411514215143151441514515146151471514815149151501515115152151531515415155151561515715158151591516015161151621516315164151651516615167151681516915170151711517215173151741517515176151771517815179151801518115182151831518415185151861518715188151891519015191151921519315194151951519615197151981519915200152011520215203152041520515206152071520815209152101521115212152131521415215152161521715218152191522015221152221522315224152251522615227152281522915230152311523215233152341523515236152371523815239152401524115242152431524415245152461524715248152491525015251152521525315254152551525615257152581525915260152611526215263152641526515266152671526815269152701527115272152731527415275152761527715278152791528015281152821528315284152851528615287152881528915290152911529215293152941529515296152971529815299153001530115302153031530415305153061530715308153091531015311153121531315314153151531615317153181531915320153211532215323153241532515326153271532815329153301533115332153331533415335153361533715338153391534015341153421534315344153451534615347153481534915350153511535215353153541535515356153571535815359153601536115362153631536415365153661536715368153691537015371153721537315374153751537615377153781537915380153811538215383153841538515386153871538815389153901539115392153931539415395153961539715398153991540015401154021540315404154051540615407154081540915410154111541215413154141541515416154171541815419154201542115422154231542415425154261542715428154291543015431154321543315434154351543615437154381543915440154411544215443154441544515446154471544815449154501545115452154531545415455154561545715458154591546015461154621546315464154651546615467154681546915470154711547215473154741547515476154771547815479154801548115482154831548415485154861548715488154891549015491154921549315494154951549615497154981549915500155011550215503155041550515506155071550815509155101551115512155131551415515155161551715518155191552015521155221552315524155251552615527155281552915530155311553215533155341553515536155371553815539155401554115542155431554415545155461554715548155491555015551155521555315554155551555615557155581555915560155611556215563155641556515566155671556815569155701557115572155731557415575155761557715578155791558015581155821558315584155851558615587155881558915590155911559215593155941559515596155971559815599156001560115602156031560415605156061560715608156091561015611156121561315614156151561615617156181561915620156211562215623156241562515626156271562815629156301563115632156331563415635156361563715638156391564015641156421564315644156451564615647156481564915650156511565215653156541565515656156571565815659156601566115662156631566415665156661566715668156691567015671156721567315674156751567615677156781567915680156811568215683156841568515686156871568815689156901569115692156931569415695156961569715698156991570015701157021570315704157051570615707157081570915710157111571215713157141571515716157171571815719157201572115722157231572415725157261572715728157291573015731157321573315734157351573615737157381573915740157411574215743157441574515746157471574815749157501575115752157531575415755157561575715758157591576015761157621576315764157651576615767157681576915770157711577215773157741577515776157771577815779157801578115782157831578415785157861578715788157891579015791157921579315794157951579615797157981579915800158011580215803158041580515806158071580815809158101581115812158131581415815158161581715818158191582015821158221582315824158251582615827158281582915830158311583215833158341583515836158371583815839158401584115842158431584415845158461584715848158491585015851158521585315854158551585615857158581585915860158611586215863158641586515866158671586815869158701587115872158731587415875158761587715878158791588015881158821588315884158851588615887158881588915890158911589215893158941589515896158971589815899159001590115902159031590415905159061590715908159091591015911159121591315914159151591615917159181591915920159211592215923159241592515926159271592815929159301593115932159331593415935159361593715938159391594015941159421594315944159451594615947159481594915950159511595215953159541595515956159571595815959159601596115962159631596415965159661596715968159691597015971159721597315974159751597615977159781597915980159811598215983159841598515986159871598815989159901599115992159931599415995159961599715998159991600016001160021600316004160051600616007160081600916010160111601216013160141601516016160171601816019160201602116022160231602416025160261602716028160291603016031160321603316034160351603616037160381603916040160411604216043160441604516046160471604816049160501605116052160531605416055160561605716058160591606016061160621606316064160651606616067160681606916070160711607216073160741607516076160771607816079160801608116082160831608416085160861608716088160891609016091160921609316094160951609616097160981609916100161011610216103161041610516106161071610816109161101611116112161131611416115161161611716118161191612016121161221612316124161251612616127161281612916130161311613216133161341613516136161371613816139161401614116142161431614416145161461614716148161491615016151161521615316154161551615616157161581615916160161611616216163161641616516166161671616816169161701617116172161731617416175161761617716178161791618016181161821618316184161851618616187161881618916190161911619216193161941619516196161971619816199162001620116202162031620416205162061620716208162091621016211162121621316214162151621616217162181621916220162211622216223162241622516226162271622816229162301623116232162331623416235162361623716238162391624016241162421624316244162451624616247162481624916250162511625216253162541625516256162571625816259162601626116262162631626416265162661626716268162691627016271162721627316274162751627616277162781627916280162811628216283162841628516286162871628816289162901629116292162931629416295162961629716298162991630016301163021630316304163051630616307163081630916310163111631216313163141631516316163171631816319163201632116322163231632416325163261632716328163291633016331163321633316334163351633616337163381633916340163411634216343163441634516346163471634816349163501635116352163531635416355163561635716358163591636016361163621636316364163651636616367163681636916370163711637216373163741637516376163771637816379163801638116382163831638416385163861638716388163891639016391163921639316394163951639616397163981639916400164011640216403164041640516406164071640816409164101641116412164131641416415164161641716418164191642016421164221642316424164251642616427164281642916430164311643216433164341643516436164371643816439164401644116442164431644416445164461644716448164491645016451164521645316454164551645616457164581645916460164611646216463164641646516466164671646816469164701647116472164731647416475164761647716478164791648016481164821648316484164851648616487164881648916490164911649216493164941649516496164971649816499165001650116502165031650416505165061650716508165091651016511165121651316514165151651616517165181651916520165211652216523165241652516526165271652816529165301653116532165331653416535165361653716538165391654016541165421654316544165451654616547165481654916550165511655216553165541655516556165571655816559165601656116562165631656416565165661656716568165691657016571165721657316574165751657616577165781657916580165811658216583165841658516586165871658816589165901659116592165931659416595165961659716598165991660016601166021660316604166051660616607166081660916610166111661216613166141661516616166171661816619166201662116622166231662416625166261662716628166291663016631166321663316634166351663616637166381663916640166411664216643166441664516646166471664816649166501665116652166531665416655166561665716658166591666016661166621666316664166651666616667166681666916670166711667216673166741667516676166771667816679166801668116682166831668416685166861668716688166891669016691166921669316694166951669616697166981669916700167011670216703167041670516706167071670816709167101671116712167131671416715167161671716718167191672016721167221672316724167251672616727167281672916730167311673216733167341673516736167371673816739167401674116742167431674416745167461674716748167491675016751167521675316754167551675616757167581675916760167611676216763167641676516766167671676816769167701677116772167731677416775167761677716778167791678016781167821678316784167851678616787167881678916790167911679216793167941679516796167971679816799168001680116802168031680416805168061680716808168091681016811168121681316814168151681616817168181681916820168211682216823168241682516826168271682816829168301683116832168331683416835168361683716838168391684016841168421684316844168451684616847168481684916850168511685216853168541685516856168571685816859168601686116862168631686416865168661686716868168691687016871168721687316874168751687616877168781687916880168811688216883168841688516886168871688816889168901689116892168931689416895168961689716898168991690016901169021690316904169051690616907169081690916910169111691216913169141691516916169171691816919169201692116922169231692416925169261692716928169291693016931169321693316934169351693616937169381693916940169411694216943169441694516946169471694816949169501695116952169531695416955169561695716958169591696016961169621696316964169651696616967169681696916970169711697216973169741697516976169771697816979169801698116982169831698416985169861698716988169891699016991169921699316994169951699616997169981699917000170011700217003170041700517006170071700817009170101701117012170131701417015170161701717018170191702017021170221702317024170251702617027170281702917030170311703217033170341703517036170371703817039170401704117042170431704417045170461704717048170491705017051170521705317054170551705617057170581705917060170611706217063170641706517066170671706817069170701707117072170731707417075170761707717078170791708017081170821708317084170851708617087170881708917090170911709217093170941709517096170971709817099171001710117102171031710417105171061710717108171091711017111171121711317114171151711617117171181711917120171211712217123171241712517126171271712817129171301713117132171331713417135171361713717138171391714017141171421714317144171451714617147171481714917150171511715217153171541715517156171571715817159171601716117162171631716417165171661716717168171691717017171171721717317174171751717617177171781717917180171811718217183171841718517186171871718817189171901719117192171931719417195171961719717198171991720017201172021720317204172051720617207172081720917210172111721217213172141721517216172171721817219172201722117222172231722417225172261722717228172291723017231172321723317234172351723617237172381723917240172411724217243172441724517246172471724817249172501725117252172531725417255172561725717258172591726017261172621726317264172651726617267172681726917270172711727217273172741727517276172771727817279172801728117282172831728417285172861728717288172891729017291172921729317294172951729617297172981729917300173011730217303173041730517306173071730817309173101731117312173131731417315173161731717318173191732017321173221732317324173251732617327173281732917330173311733217333173341733517336173371733817339173401734117342173431734417345173461734717348173491735017351173521735317354173551735617357173581735917360173611736217363173641736517366173671736817369173701737117372173731737417375173761737717378173791738017381173821738317384173851738617387173881738917390173911739217393173941739517396173971739817399174001740117402174031740417405174061740717408174091741017411174121741317414174151741617417174181741917420174211742217423174241742517426174271742817429174301743117432174331743417435174361743717438174391744017441174421744317444174451744617447174481744917450174511745217453174541745517456174571745817459174601746117462174631746417465174661746717468174691747017471174721747317474174751747617477174781747917480174811748217483174841748517486174871748817489174901749117492174931749417495174961749717498174991750017501175021750317504175051750617507175081750917510175111751217513175141751517516175171751817519175201752117522175231752417525175261752717528175291753017531175321753317534175351753617537175381753917540175411754217543175441754517546175471754817549175501755117552175531755417555175561755717558175591756017561175621756317564175651756617567175681756917570175711757217573175741757517576175771757817579175801758117582175831758417585175861758717588175891759017591175921759317594175951759617597175981759917600176011760217603176041760517606176071760817609176101761117612176131761417615176161761717618176191762017621176221762317624176251762617627176281762917630176311763217633176341763517636176371763817639176401764117642176431764417645176461764717648176491765017651176521765317654176551765617657176581765917660176611766217663176641766517666176671766817669176701767117672176731767417675176761767717678176791768017681176821768317684176851768617687176881768917690176911769217693176941769517696176971769817699177001770117702177031770417705177061770717708177091771017711177121771317714177151771617717177181771917720177211772217723177241772517726177271772817729177301773117732177331773417735177361773717738177391774017741177421774317744177451774617747177481774917750177511775217753177541775517756177571775817759177601776117762177631776417765177661776717768177691777017771177721777317774177751777617777177781777917780177811778217783177841778517786177871778817789177901779117792177931779417795177961779717798177991780017801178021780317804178051780617807178081780917810178111781217813178141781517816178171781817819178201782117822178231782417825178261782717828178291783017831178321783317834178351783617837178381783917840178411784217843178441784517846178471784817849178501785117852178531785417855178561785717858178591786017861178621786317864178651786617867178681786917870178711787217873178741787517876178771787817879178801788117882178831788417885178861788717888178891789017891178921789317894178951789617897178981789917900179011790217903179041790517906179071790817909179101791117912179131791417915179161791717918179191792017921179221792317924179251792617927179281792917930179311793217933179341793517936179371793817939179401794117942179431794417945179461794717948179491795017951179521795317954179551795617957179581795917960179611796217963179641796517966179671796817969179701797117972179731797417975179761797717978179791798017981179821798317984179851798617987179881798917990179911799217993179941799517996179971799817999180001800118002180031800418005180061800718008180091801018011180121801318014180151801618017180181801918020180211802218023180241802518026180271802818029180301803118032180331803418035180361803718038180391804018041180421804318044180451804618047180481804918050180511805218053180541805518056180571805818059180601806118062180631806418065180661806718068180691807018071180721807318074180751807618077180781807918080180811808218083180841808518086180871808818089180901809118092180931809418095180961809718098180991810018101181021810318104181051810618107181081810918110181111811218113181141811518116181171811818119181201812118122181231812418125181261812718128181291813018131181321813318134181351813618137181381813918140181411814218143181441814518146181471814818149181501815118152181531815418155181561815718158181591816018161181621816318164181651816618167181681816918170181711817218173181741817518176181771817818179181801818118182181831818418185181861818718188181891819018191181921819318194181951819618197181981819918200182011820218203182041820518206182071820818209182101821118212182131821418215182161821718218182191822018221182221822318224182251822618227182281822918230182311823218233182341823518236182371823818239182401824118242182431824418245182461824718248182491825018251182521825318254182551825618257182581825918260182611826218263182641826518266182671826818269182701827118272182731827418275182761827718278182791828018281182821828318284182851828618287182881828918290182911829218293182941829518296182971829818299183001830118302183031830418305183061830718308183091831018311183121831318314183151831618317183181831918320183211832218323183241832518326183271832818329183301833118332183331833418335183361833718338183391834018341183421834318344183451834618347183481834918350183511835218353183541835518356183571835818359183601836118362183631836418365183661836718368183691837018371183721837318374183751837618377183781837918380183811838218383183841838518386183871838818389183901839118392183931839418395183961839718398183991840018401184021840318404184051840618407184081840918410184111841218413184141841518416184171841818419184201842118422184231842418425184261842718428184291843018431184321843318434184351843618437184381843918440184411844218443184441844518446184471844818449184501845118452184531845418455184561845718458184591846018461184621846318464184651846618467184681846918470184711847218473184741847518476184771847818479184801848118482184831848418485184861848718488184891849018491184921849318494184951849618497184981849918500185011850218503185041850518506185071850818509185101851118512185131851418515185161851718518185191852018521185221852318524185251852618527185281852918530185311853218533185341853518536185371853818539185401854118542185431854418545185461854718548185491855018551185521855318554185551855618557185581855918560185611856218563185641856518566185671856818569185701857118572185731857418575185761857718578185791858018581185821858318584185851858618587185881858918590185911859218593185941859518596185971859818599186001860118602186031860418605186061860718608186091861018611186121861318614186151861618617186181861918620186211862218623186241862518626186271862818629186301863118632186331863418635186361863718638186391864018641186421864318644186451864618647186481864918650186511865218653186541865518656186571865818659186601866118662186631866418665186661866718668186691867018671186721867318674186751867618677186781867918680186811868218683186841868518686186871868818689186901869118692186931869418695186961869718698186991870018701187021870318704187051870618707187081870918710187111871218713187141871518716187171871818719187201872118722187231872418725187261872718728187291873018731187321873318734187351873618737187381873918740187411874218743187441874518746187471874818749187501875118752187531875418755187561875718758187591876018761187621876318764187651876618767187681876918770187711877218773187741877518776187771877818779187801878118782187831878418785187861878718788187891879018791187921879318794187951879618797187981879918800188011880218803188041880518806188071880818809188101881118812188131881418815188161881718818188191882018821188221882318824188251882618827188281882918830188311883218833188341883518836188371883818839188401884118842188431884418845188461884718848188491885018851188521885318854188551885618857188581885918860188611886218863188641886518866188671886818869188701887118872188731887418875188761887718878188791888018881188821888318884188851888618887188881888918890188911889218893188941889518896188971889818899189001890118902189031890418905189061890718908189091891018911189121891318914189151891618917189181891918920189211892218923189241892518926189271892818929189301893118932189331893418935189361893718938
  1. #!/usr/bin/env node
  2. 'use strict';
  3. var path = require('path');
  4. var fs$4 = require('fs');
  5. var os = require('os');
  6. var tty = require('tty');
  7. var util$1 = require('util');
  8. var stream_1 = require('stream');
  9. var events_1 = require('events');
  10. var readline = require('readline');
  11. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  12. var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
  13. var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs$4);
  14. var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
  15. var tty__default = /*#__PURE__*/_interopDefaultLegacy(tty);
  16. var util__default = /*#__PURE__*/_interopDefaultLegacy(util$1);
  17. var stream_1__default = /*#__PURE__*/_interopDefaultLegacy(stream_1);
  18. var events_1__default = /*#__PURE__*/_interopDefaultLegacy(events_1);
  19. var readline__default = /*#__PURE__*/_interopDefaultLegacy(readline);
  20. var packageJson = require("./package.json");
  21. var semverCompare = function cmp(a, b) {
  22. var pa = a.split('.');
  23. var pb = b.split('.');
  24. for (var i = 0; i < 3; i++) {
  25. var na = Number(pa[i]);
  26. var nb = Number(pb[i]);
  27. if (na > nb) return 1;
  28. if (nb > na) return -1;
  29. if (!isNaN(na) && isNaN(nb)) return 1;
  30. if (isNaN(na) && !isNaN(nb)) return -1;
  31. }
  32. return 0;
  33. };
  34. var pleaseUpgradeNode = function pleaseUpgradeNode(pkg, opts) {
  35. var opts = opts || {};
  36. var requiredVersion = pkg.engines.node.replace('>=', '');
  37. var currentVersion = process.version.replace('v', '');
  38. if (semverCompare(currentVersion, requiredVersion) === -1) {
  39. if (opts.message) {
  40. console.error(opts.message(requiredVersion));
  41. } else {
  42. console.error(pkg.name + ' requires at least version ' + requiredVersion + ' of Node, please upgrade');
  43. }
  44. if (opts.hasOwnProperty('exitCode')) {
  45. process.exit(opts.exitCode);
  46. } else {
  47. process.exit(1);
  48. }
  49. }
  50. };
  51. var check = function (it) {
  52. return it && it.Math == Math && it;
  53. };
  54. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  55. var global$1 =
  56. // eslint-disable-next-line es/no-global-this -- safe
  57. check(typeof globalThis == 'object' && globalThis) ||
  58. check(typeof window == 'object' && window) ||
  59. // eslint-disable-next-line no-restricted-globals -- safe
  60. check(typeof self == 'object' && self) ||
  61. check(typeof global$1 == 'object' && global$1) ||
  62. // eslint-disable-next-line no-new-func -- fallback
  63. (function () { return this; })() || Function('return this')();
  64. var fails = function (exec) {
  65. try {
  66. return !!exec();
  67. } catch (error) {
  68. return true;
  69. }
  70. };
  71. // Detect IE8's incomplete defineProperty implementation
  72. var descriptors = !fails(function () {
  73. // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  74. return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
  75. });
  76. var $propertyIsEnumerable = {}.propertyIsEnumerable;
  77. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  78. var getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
  79. // Nashorn ~ JDK8 bug
  80. var NASHORN_BUG = getOwnPropertyDescriptor$1 && !$propertyIsEnumerable.call({ 1: 2 }, 1);
  81. // `Object.prototype.propertyIsEnumerable` method implementation
  82. // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
  83. var f$4 = NASHORN_BUG ? function propertyIsEnumerable(V) {
  84. var descriptor = getOwnPropertyDescriptor$1(this, V);
  85. return !!descriptor && descriptor.enumerable;
  86. } : $propertyIsEnumerable;
  87. var objectPropertyIsEnumerable = {
  88. f: f$4
  89. };
  90. var createPropertyDescriptor = function (bitmap, value) {
  91. return {
  92. enumerable: !(bitmap & 1),
  93. configurable: !(bitmap & 2),
  94. writable: !(bitmap & 4),
  95. value: value
  96. };
  97. };
  98. var toString$2 = {}.toString;
  99. var classofRaw = function (it) {
  100. return toString$2.call(it).slice(8, -1);
  101. };
  102. var split = ''.split;
  103. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  104. var indexedObject = fails(function () {
  105. // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
  106. // eslint-disable-next-line no-prototype-builtins -- safe
  107. return !Object('z').propertyIsEnumerable(0);
  108. }) ? function (it) {
  109. return classofRaw(it) == 'String' ? split.call(it, '') : Object(it);
  110. } : Object;
  111. // `RequireObjectCoercible` abstract operation
  112. // https://tc39.es/ecma262/#sec-requireobjectcoercible
  113. var requireObjectCoercible = function (it) {
  114. if (it == undefined) throw TypeError("Can't call method on " + it);
  115. return it;
  116. };
  117. // toObject with fallback for non-array-like ES3 strings
  118. var toIndexedObject = function (it) {
  119. return indexedObject(requireObjectCoercible(it));
  120. };
  121. var isObject$3 = function (it) {
  122. return typeof it === 'object' ? it !== null : typeof it === 'function';
  123. };
  124. var aFunction$1 = function (variable) {
  125. return typeof variable == 'function' ? variable : undefined;
  126. };
  127. var getBuiltIn = function (namespace, method) {
  128. return arguments.length < 2 ? aFunction$1(global$1[namespace]) : global$1[namespace] && global$1[namespace][method];
  129. };
  130. var engineUserAgent = getBuiltIn('navigator', 'userAgent') || '';
  131. var process$1 = global$1.process;
  132. var Deno = global$1.Deno;
  133. var versions = process$1 && process$1.versions || Deno && Deno.version;
  134. var v8 = versions && versions.v8;
  135. var match, version;
  136. if (v8) {
  137. match = v8.split('.');
  138. version = match[0] < 4 ? 1 : match[0] + match[1];
  139. } else if (engineUserAgent) {
  140. match = engineUserAgent.match(/Edge\/(\d+)/);
  141. if (!match || match[1] >= 74) {
  142. match = engineUserAgent.match(/Chrome\/(\d+)/);
  143. if (match) version = match[1];
  144. }
  145. }
  146. var engineV8Version = version && +version;
  147. /* eslint-disable es/no-symbol -- required for testing */
  148. // eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
  149. var nativeSymbol = !!Object.getOwnPropertySymbols && !fails(function () {
  150. var symbol = Symbol();
  151. // Chrome 38 Symbol has incorrect toString conversion
  152. // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
  153. return !String(symbol) || !(Object(symbol) instanceof Symbol) ||
  154. // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
  155. !Symbol.sham && engineV8Version && engineV8Version < 41;
  156. });
  157. /* eslint-disable es/no-symbol -- required for testing */
  158. var useSymbolAsUid = nativeSymbol
  159. && !Symbol.sham
  160. && typeof Symbol.iterator == 'symbol';
  161. var isSymbol$1 = useSymbolAsUid ? function (it) {
  162. return typeof it == 'symbol';
  163. } : function (it) {
  164. var $Symbol = getBuiltIn('Symbol');
  165. return typeof $Symbol == 'function' && Object(it) instanceof $Symbol;
  166. };
  167. // `OrdinaryToPrimitive` abstract operation
  168. // https://tc39.es/ecma262/#sec-ordinarytoprimitive
  169. var ordinaryToPrimitive = function (input, pref) {
  170. var fn, val;
  171. if (pref === 'string' && typeof (fn = input.toString) == 'function' && !isObject$3(val = fn.call(input))) return val;
  172. if (typeof (fn = input.valueOf) == 'function' && !isObject$3(val = fn.call(input))) return val;
  173. if (pref !== 'string' && typeof (fn = input.toString) == 'function' && !isObject$3(val = fn.call(input))) return val;
  174. throw TypeError("Can't convert object to primitive value");
  175. };
  176. function createCommonjsModule(fn) {
  177. var module = { exports: {} };
  178. return fn(module, module.exports), module.exports;
  179. }
  180. var setGlobal = function (key, value) {
  181. try {
  182. // eslint-disable-next-line es/no-object-defineproperty -- safe
  183. Object.defineProperty(global$1, key, { value: value, configurable: true, writable: true });
  184. } catch (error) {
  185. global$1[key] = value;
  186. } return value;
  187. };
  188. var SHARED = '__core-js_shared__';
  189. var store$1 = global$1[SHARED] || setGlobal(SHARED, {});
  190. var sharedStore = store$1;
  191. var shared = createCommonjsModule(function (module) {
  192. (module.exports = function (key, value) {
  193. return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {});
  194. })('versions', []).push({
  195. version: '3.17.3',
  196. mode: 'global',
  197. copyright: '© 2021 Denis Pushkarev (zloirock.ru)'
  198. });
  199. });
  200. // `ToObject` abstract operation
  201. // https://tc39.es/ecma262/#sec-toobject
  202. var toObject = function (argument) {
  203. return Object(requireObjectCoercible(argument));
  204. };
  205. var hasOwnProperty$b = {}.hasOwnProperty;
  206. var has$1 = Object.hasOwn || function hasOwn(it, key) {
  207. return hasOwnProperty$b.call(toObject(it), key);
  208. };
  209. var id = 0;
  210. var postfix = Math.random();
  211. var uid = function (key) {
  212. return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36);
  213. };
  214. var WellKnownSymbolsStore = shared('wks');
  215. var Symbol$2 = global$1.Symbol;
  216. var createWellKnownSymbol = useSymbolAsUid ? Symbol$2 : Symbol$2 && Symbol$2.withoutSetter || uid;
  217. var wellKnownSymbol = function (name) {
  218. if (!has$1(WellKnownSymbolsStore, name) || !(nativeSymbol || typeof WellKnownSymbolsStore[name] == 'string')) {
  219. if (nativeSymbol && has$1(Symbol$2, name)) {
  220. WellKnownSymbolsStore[name] = Symbol$2[name];
  221. } else {
  222. WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
  223. }
  224. } return WellKnownSymbolsStore[name];
  225. };
  226. var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
  227. // `ToPrimitive` abstract operation
  228. // https://tc39.es/ecma262/#sec-toprimitive
  229. var toPrimitive = function (input, pref) {
  230. if (!isObject$3(input) || isSymbol$1(input)) return input;
  231. var exoticToPrim = input[TO_PRIMITIVE];
  232. var result;
  233. if (exoticToPrim !== undefined) {
  234. if (pref === undefined) pref = 'default';
  235. result = exoticToPrim.call(input, pref);
  236. if (!isObject$3(result) || isSymbol$1(result)) return result;
  237. throw TypeError("Can't convert object to primitive value");
  238. }
  239. if (pref === undefined) pref = 'number';
  240. return ordinaryToPrimitive(input, pref);
  241. };
  242. // `ToPropertyKey` abstract operation
  243. // https://tc39.es/ecma262/#sec-topropertykey
  244. var toPropertyKey = function (argument) {
  245. var key = toPrimitive(argument, 'string');
  246. return isSymbol$1(key) ? key : String(key);
  247. };
  248. var document = global$1.document;
  249. // typeof document.createElement is 'object' in old IE
  250. var EXISTS = isObject$3(document) && isObject$3(document.createElement);
  251. var documentCreateElement = function (it) {
  252. return EXISTS ? document.createElement(it) : {};
  253. };
  254. // Thank's IE8 for his funny defineProperty
  255. var ie8DomDefine = !descriptors && !fails(function () {
  256. // eslint-disable-next-line es/no-object-defineproperty -- requied for testing
  257. return Object.defineProperty(documentCreateElement('div'), 'a', {
  258. get: function () { return 7; }
  259. }).a != 7;
  260. });
  261. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  262. var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  263. // `Object.getOwnPropertyDescriptor` method
  264. // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
  265. var f$3 = descriptors ? $getOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
  266. O = toIndexedObject(O);
  267. P = toPropertyKey(P);
  268. if (ie8DomDefine) try {
  269. return $getOwnPropertyDescriptor(O, P);
  270. } catch (error) { /* empty */ }
  271. if (has$1(O, P)) return createPropertyDescriptor(!objectPropertyIsEnumerable.f.call(O, P), O[P]);
  272. };
  273. var objectGetOwnPropertyDescriptor = {
  274. f: f$3
  275. };
  276. var anObject = function (it) {
  277. if (!isObject$3(it)) {
  278. throw TypeError(String(it) + ' is not an object');
  279. } return it;
  280. };
  281. // eslint-disable-next-line es/no-object-defineproperty -- safe
  282. var $defineProperty = Object.defineProperty;
  283. // `Object.defineProperty` method
  284. // https://tc39.es/ecma262/#sec-object.defineproperty
  285. var f$2 = descriptors ? $defineProperty : function defineProperty(O, P, Attributes) {
  286. anObject(O);
  287. P = toPropertyKey(P);
  288. anObject(Attributes);
  289. if (ie8DomDefine) try {
  290. return $defineProperty(O, P, Attributes);
  291. } catch (error) { /* empty */ }
  292. if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
  293. if ('value' in Attributes) O[P] = Attributes.value;
  294. return O;
  295. };
  296. var objectDefineProperty = {
  297. f: f$2
  298. };
  299. var createNonEnumerableProperty = descriptors ? function (object, key, value) {
  300. return objectDefineProperty.f(object, key, createPropertyDescriptor(1, value));
  301. } : function (object, key, value) {
  302. object[key] = value;
  303. return object;
  304. };
  305. var functionToString = Function.toString;
  306. // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
  307. if (typeof sharedStore.inspectSource != 'function') {
  308. sharedStore.inspectSource = function (it) {
  309. return functionToString.call(it);
  310. };
  311. }
  312. var inspectSource = sharedStore.inspectSource;
  313. var WeakMap$3 = global$1.WeakMap;
  314. var nativeWeakMap = typeof WeakMap$3 === 'function' && /native code/.test(inspectSource(WeakMap$3));
  315. var keys$1 = shared('keys');
  316. var sharedKey = function (key) {
  317. return keys$1[key] || (keys$1[key] = uid(key));
  318. };
  319. var hiddenKeys$1 = {};
  320. var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
  321. var WeakMap$2 = global$1.WeakMap;
  322. var set, get$1, has;
  323. var enforce = function (it) {
  324. return has(it) ? get$1(it) : set(it, {});
  325. };
  326. var getterFor = function (TYPE) {
  327. return function (it) {
  328. var state;
  329. if (!isObject$3(it) || (state = get$1(it)).type !== TYPE) {
  330. throw TypeError('Incompatible receiver, ' + TYPE + ' required');
  331. } return state;
  332. };
  333. };
  334. if (nativeWeakMap || sharedStore.state) {
  335. var store = sharedStore.state || (sharedStore.state = new WeakMap$2());
  336. var wmget = store.get;
  337. var wmhas = store.has;
  338. var wmset = store.set;
  339. set = function (it, metadata) {
  340. if (wmhas.call(store, it)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
  341. metadata.facade = it;
  342. wmset.call(store, it, metadata);
  343. return metadata;
  344. };
  345. get$1 = function (it) {
  346. return wmget.call(store, it) || {};
  347. };
  348. has = function (it) {
  349. return wmhas.call(store, it);
  350. };
  351. } else {
  352. var STATE = sharedKey('state');
  353. hiddenKeys$1[STATE] = true;
  354. set = function (it, metadata) {
  355. if (has$1(it, STATE)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
  356. metadata.facade = it;
  357. createNonEnumerableProperty(it, STATE, metadata);
  358. return metadata;
  359. };
  360. get$1 = function (it) {
  361. return has$1(it, STATE) ? it[STATE] : {};
  362. };
  363. has = function (it) {
  364. return has$1(it, STATE);
  365. };
  366. }
  367. var internalState = {
  368. set: set,
  369. get: get$1,
  370. has: has,
  371. enforce: enforce,
  372. getterFor: getterFor
  373. };
  374. var redefine = createCommonjsModule(function (module) {
  375. var getInternalState = internalState.get;
  376. var enforceInternalState = internalState.enforce;
  377. var TEMPLATE = String(String).split('String');
  378. (module.exports = function (O, key, value, options) {
  379. var unsafe = options ? !!options.unsafe : false;
  380. var simple = options ? !!options.enumerable : false;
  381. var noTargetGet = options ? !!options.noTargetGet : false;
  382. var state;
  383. if (typeof value == 'function') {
  384. if (typeof key == 'string' && !has$1(value, 'name')) {
  385. createNonEnumerableProperty(value, 'name', key);
  386. }
  387. state = enforceInternalState(value);
  388. if (!state.source) {
  389. state.source = TEMPLATE.join(typeof key == 'string' ? key : '');
  390. }
  391. }
  392. if (O === global$1) {
  393. if (simple) O[key] = value;
  394. else setGlobal(key, value);
  395. return;
  396. } else if (!unsafe) {
  397. delete O[key];
  398. } else if (!noTargetGet && O[key]) {
  399. simple = true;
  400. }
  401. if (simple) O[key] = value;
  402. else createNonEnumerableProperty(O, key, value);
  403. // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
  404. })(Function.prototype, 'toString', function toString() {
  405. return typeof this == 'function' && getInternalState(this).source || inspectSource(this);
  406. });
  407. });
  408. var ceil = Math.ceil;
  409. var floor$1 = Math.floor;
  410. // `ToInteger` abstract operation
  411. // https://tc39.es/ecma262/#sec-tointeger
  412. var toInteger = function (argument) {
  413. return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor$1 : ceil)(argument);
  414. };
  415. var min$1 = Math.min;
  416. // `ToLength` abstract operation
  417. // https://tc39.es/ecma262/#sec-tolength
  418. var toLength = function (argument) {
  419. return argument > 0 ? min$1(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
  420. };
  421. var max = Math.max;
  422. var min = Math.min;
  423. // Helper for a popular repeating case of the spec:
  424. // Let integer be ? ToInteger(index).
  425. // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
  426. var toAbsoluteIndex = function (index, length) {
  427. var integer = toInteger(index);
  428. return integer < 0 ? max(integer + length, 0) : min(integer, length);
  429. };
  430. // `Array.prototype.{ indexOf, includes }` methods implementation
  431. var createMethod = function (IS_INCLUDES) {
  432. return function ($this, el, fromIndex) {
  433. var O = toIndexedObject($this);
  434. var length = toLength(O.length);
  435. var index = toAbsoluteIndex(fromIndex, length);
  436. var value;
  437. // Array#includes uses SameValueZero equality algorithm
  438. // eslint-disable-next-line no-self-compare -- NaN check
  439. if (IS_INCLUDES && el != el) while (length > index) {
  440. value = O[index++];
  441. // eslint-disable-next-line no-self-compare -- NaN check
  442. if (value != value) return true;
  443. // Array#indexOf ignores holes, Array#includes - not
  444. } else for (;length > index; index++) {
  445. if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
  446. } return !IS_INCLUDES && -1;
  447. };
  448. };
  449. var arrayIncludes = {
  450. // `Array.prototype.includes` method
  451. // https://tc39.es/ecma262/#sec-array.prototype.includes
  452. includes: createMethod(true),
  453. // `Array.prototype.indexOf` method
  454. // https://tc39.es/ecma262/#sec-array.prototype.indexof
  455. indexOf: createMethod(false)
  456. };
  457. var indexOf = arrayIncludes.indexOf;
  458. var objectKeysInternal = function (object, names) {
  459. var O = toIndexedObject(object);
  460. var i = 0;
  461. var result = [];
  462. var key;
  463. for (key in O) !has$1(hiddenKeys$1, key) && has$1(O, key) && result.push(key);
  464. // Don't enum bug & hidden keys
  465. while (names.length > i) if (has$1(O, key = names[i++])) {
  466. ~indexOf(result, key) || result.push(key);
  467. }
  468. return result;
  469. };
  470. // IE8- don't enum bug keys
  471. var enumBugKeys = [
  472. 'constructor',
  473. 'hasOwnProperty',
  474. 'isPrototypeOf',
  475. 'propertyIsEnumerable',
  476. 'toLocaleString',
  477. 'toString',
  478. 'valueOf'
  479. ];
  480. var hiddenKeys = enumBugKeys.concat('length', 'prototype');
  481. // `Object.getOwnPropertyNames` method
  482. // https://tc39.es/ecma262/#sec-object.getownpropertynames
  483. // eslint-disable-next-line es/no-object-getownpropertynames -- safe
  484. var f$1 = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
  485. return objectKeysInternal(O, hiddenKeys);
  486. };
  487. var objectGetOwnPropertyNames = {
  488. f: f$1
  489. };
  490. // eslint-disable-next-line es/no-object-getownpropertysymbols -- safe
  491. var f = Object.getOwnPropertySymbols;
  492. var objectGetOwnPropertySymbols = {
  493. f: f
  494. };
  495. // all object keys, includes non-enumerable and symbols
  496. var ownKeys = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
  497. var keys = objectGetOwnPropertyNames.f(anObject(it));
  498. var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
  499. return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
  500. };
  501. var copyConstructorProperties = function (target, source) {
  502. var keys = ownKeys(source);
  503. var defineProperty = objectDefineProperty.f;
  504. var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
  505. for (var i = 0; i < keys.length; i++) {
  506. var key = keys[i];
  507. if (!has$1(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key));
  508. }
  509. };
  510. var replacement = /#|\.prototype\./;
  511. var isForced = function (feature, detection) {
  512. var value = data[normalize(feature)];
  513. return value == POLYFILL ? true
  514. : value == NATIVE ? false
  515. : typeof detection == 'function' ? fails(detection)
  516. : !!detection;
  517. };
  518. var normalize = isForced.normalize = function (string) {
  519. return String(string).replace(replacement, '.').toLowerCase();
  520. };
  521. var data = isForced.data = {};
  522. var NATIVE = isForced.NATIVE = 'N';
  523. var POLYFILL = isForced.POLYFILL = 'P';
  524. var isForced_1 = isForced;
  525. var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
  526. /*
  527. options.target - name of the target object
  528. options.global - target is the global object
  529. options.stat - export as static methods of target
  530. options.proto - export as prototype methods of target
  531. options.real - real prototype method for the `pure` version
  532. options.forced - export even if the native feature is available
  533. options.bind - bind methods to the target, required for the `pure` version
  534. options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
  535. options.unsafe - use the simple assignment of property instead of delete + defineProperty
  536. options.sham - add a flag to not completely full polyfills
  537. options.enumerable - export as enumerable property
  538. options.noTargetGet - prevent calling a getter on target
  539. */
  540. var _export = function (options, source) {
  541. var TARGET = options.target;
  542. var GLOBAL = options.global;
  543. var STATIC = options.stat;
  544. var FORCED, target, key, targetProperty, sourceProperty, descriptor;
  545. if (GLOBAL) {
  546. target = global$1;
  547. } else if (STATIC) {
  548. target = global$1[TARGET] || setGlobal(TARGET, {});
  549. } else {
  550. target = (global$1[TARGET] || {}).prototype;
  551. }
  552. if (target) for (key in source) {
  553. sourceProperty = source[key];
  554. if (options.noTargetGet) {
  555. descriptor = getOwnPropertyDescriptor(target, key);
  556. targetProperty = descriptor && descriptor.value;
  557. } else targetProperty = target[key];
  558. FORCED = isForced_1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
  559. // contained in target
  560. if (!FORCED && targetProperty !== undefined) {
  561. if (typeof sourceProperty === typeof targetProperty) continue;
  562. copyConstructorProperties(sourceProperty, targetProperty);
  563. }
  564. // add a flag to not completely full polyfills
  565. if (options.sham || (targetProperty && targetProperty.sham)) {
  566. createNonEnumerableProperty(sourceProperty, 'sham', true);
  567. }
  568. // extend global
  569. redefine(target, key, sourceProperty, options);
  570. }
  571. };
  572. var aFunction = function (it) {
  573. if (typeof it != 'function') {
  574. throw TypeError(String(it) + ' is not a function');
  575. } return it;
  576. };
  577. var toString$1 = function (argument) {
  578. if (isSymbol$1(argument)) throw TypeError('Cannot convert a Symbol value to a string');
  579. return String(argument);
  580. };
  581. // TODO: use something more complex like timsort?
  582. var floor = Math.floor;
  583. var mergeSort = function (array, comparefn) {
  584. var length = array.length;
  585. var middle = floor(length / 2);
  586. return length < 8 ? insertionSort(array, comparefn) : merge$1(
  587. mergeSort(array.slice(0, middle), comparefn),
  588. mergeSort(array.slice(middle), comparefn),
  589. comparefn
  590. );
  591. };
  592. var insertionSort = function (array, comparefn) {
  593. var length = array.length;
  594. var i = 1;
  595. var element, j;
  596. while (i < length) {
  597. j = i;
  598. element = array[i];
  599. while (j && comparefn(array[j - 1], element) > 0) {
  600. array[j] = array[--j];
  601. }
  602. if (j !== i++) array[j] = element;
  603. } return array;
  604. };
  605. var merge$1 = function (left, right, comparefn) {
  606. var llength = left.length;
  607. var rlength = right.length;
  608. var lindex = 0;
  609. var rindex = 0;
  610. var result = [];
  611. while (lindex < llength || rindex < rlength) {
  612. if (lindex < llength && rindex < rlength) {
  613. result.push(comparefn(left[lindex], right[rindex]) <= 0 ? left[lindex++] : right[rindex++]);
  614. } else {
  615. result.push(lindex < llength ? left[lindex++] : right[rindex++]);
  616. }
  617. } return result;
  618. };
  619. var arraySort = mergeSort;
  620. var arrayMethodIsStrict = function (METHOD_NAME, argument) {
  621. var method = [][METHOD_NAME];
  622. return !!method && fails(function () {
  623. // eslint-disable-next-line no-useless-call,no-throw-literal -- required for testing
  624. method.call(null, argument || function () { throw 1; }, 1);
  625. });
  626. };
  627. var firefox = engineUserAgent.match(/firefox\/(\d+)/i);
  628. var engineFfVersion = !!firefox && +firefox[1];
  629. var engineIsIeOrEdge = /MSIE|Trident/.test(engineUserAgent);
  630. var webkit = engineUserAgent.match(/AppleWebKit\/(\d+)\./);
  631. var engineWebkitVersion = !!webkit && +webkit[1];
  632. var test$1 = [];
  633. var nativeSort = test$1.sort;
  634. // IE8-
  635. var FAILS_ON_UNDEFINED = fails(function () {
  636. test$1.sort(undefined);
  637. });
  638. // V8 bug
  639. var FAILS_ON_NULL = fails(function () {
  640. test$1.sort(null);
  641. });
  642. // Old WebKit
  643. var STRICT_METHOD = arrayMethodIsStrict('sort');
  644. var STABLE_SORT = !fails(function () {
  645. // feature detection can be too slow, so check engines versions
  646. if (engineV8Version) return engineV8Version < 70;
  647. if (engineFfVersion && engineFfVersion > 3) return;
  648. if (engineIsIeOrEdge) return true;
  649. if (engineWebkitVersion) return engineWebkitVersion < 603;
  650. var result = '';
  651. var code, chr, value, index;
  652. // generate an array with more 512 elements (Chakra and old V8 fails only in this case)
  653. for (code = 65; code < 76; code++) {
  654. chr = String.fromCharCode(code);
  655. switch (code) {
  656. case 66: case 69: case 70: case 72: value = 3; break;
  657. case 68: case 71: value = 4; break;
  658. default: value = 2;
  659. }
  660. for (index = 0; index < 47; index++) {
  661. test$1.push({ k: chr + index, v: value });
  662. }
  663. }
  664. test$1.sort(function (a, b) { return b.v - a.v; });
  665. for (index = 0; index < test$1.length; index++) {
  666. chr = test$1[index].k.charAt(0);
  667. if (result.charAt(result.length - 1) !== chr) result += chr;
  668. }
  669. return result !== 'DGBEFHACIJK';
  670. });
  671. var FORCED = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || !STRICT_METHOD || !STABLE_SORT;
  672. var getSortCompare = function (comparefn) {
  673. return function (x, y) {
  674. if (y === undefined) return -1;
  675. if (x === undefined) return 1;
  676. if (comparefn !== undefined) return +comparefn(x, y) || 0;
  677. return toString$1(x) > toString$1(y) ? 1 : -1;
  678. };
  679. };
  680. // `Array.prototype.sort` method
  681. // https://tc39.es/ecma262/#sec-array.prototype.sort
  682. _export({ target: 'Array', proto: true, forced: FORCED }, {
  683. sort: function sort(comparefn) {
  684. if (comparefn !== undefined) aFunction(comparefn);
  685. var array = toObject(this);
  686. if (STABLE_SORT) return comparefn === undefined ? nativeSort.call(array) : nativeSort.call(array, comparefn);
  687. var items = [];
  688. var arrayLength = toLength(array.length);
  689. var itemsLength, index;
  690. for (index = 0; index < arrayLength; index++) {
  691. if (index in array) items.push(array[index]);
  692. }
  693. items = arraySort(items, getSortCompare(comparefn));
  694. itemsLength = items.length;
  695. index = 0;
  696. while (index < itemsLength) array[index] = items[index++];
  697. while (index < arrayLength) delete array[index++];
  698. return array;
  699. }
  700. });
  701. var fastJsonStableStringify = function (data, opts) {
  702. if (!opts) opts = {};
  703. if (typeof opts === 'function') opts = {
  704. cmp: opts
  705. };
  706. var cycles = typeof opts.cycles === 'boolean' ? opts.cycles : false;
  707. var cmp = opts.cmp && function (f) {
  708. return function (node) {
  709. return function (a, b) {
  710. var aobj = {
  711. key: a,
  712. value: node[a]
  713. };
  714. var bobj = {
  715. key: b,
  716. value: node[b]
  717. };
  718. return f(aobj, bobj);
  719. };
  720. };
  721. }(opts.cmp);
  722. var seen = [];
  723. return function stringify(node) {
  724. if (node && node.toJSON && typeof node.toJSON === 'function') {
  725. node = node.toJSON();
  726. }
  727. if (node === undefined) return;
  728. if (typeof node == 'number') return isFinite(node) ? '' + node : 'null';
  729. if (typeof node !== 'object') return JSON.stringify(node);
  730. var i, out;
  731. if (Array.isArray(node)) {
  732. out = '[';
  733. for (i = 0; i < node.length; i++) {
  734. if (i) out += ',';
  735. out += stringify(node[i]) || 'null';
  736. }
  737. return out + ']';
  738. }
  739. if (node === null) return 'null';
  740. if (seen.indexOf(node) !== -1) {
  741. if (cycles) return JSON.stringify('__cycle__');
  742. throw new TypeError('Converting circular structure to JSON');
  743. }
  744. var seenIndex = seen.push(node) - 1;
  745. var keys = Object.keys(node).sort(cmp && cmp(node));
  746. out = '';
  747. for (i = 0; i < keys.length; i++) {
  748. var key = keys[i];
  749. var value = stringify(node[key]);
  750. if (!value) continue;
  751. if (out) out += ',';
  752. out += JSON.stringify(key) + ':' + value;
  753. }
  754. seen.splice(seenIndex, 1);
  755. return '{' + out + '}';
  756. }(data);
  757. };
  758. var prettier$1 = require("./index.js");
  759. var colorName = {
  760. "aliceblue": [240, 248, 255],
  761. "antiquewhite": [250, 235, 215],
  762. "aqua": [0, 255, 255],
  763. "aquamarine": [127, 255, 212],
  764. "azure": [240, 255, 255],
  765. "beige": [245, 245, 220],
  766. "bisque": [255, 228, 196],
  767. "black": [0, 0, 0],
  768. "blanchedalmond": [255, 235, 205],
  769. "blue": [0, 0, 255],
  770. "blueviolet": [138, 43, 226],
  771. "brown": [165, 42, 42],
  772. "burlywood": [222, 184, 135],
  773. "cadetblue": [95, 158, 160],
  774. "chartreuse": [127, 255, 0],
  775. "chocolate": [210, 105, 30],
  776. "coral": [255, 127, 80],
  777. "cornflowerblue": [100, 149, 237],
  778. "cornsilk": [255, 248, 220],
  779. "crimson": [220, 20, 60],
  780. "cyan": [0, 255, 255],
  781. "darkblue": [0, 0, 139],
  782. "darkcyan": [0, 139, 139],
  783. "darkgoldenrod": [184, 134, 11],
  784. "darkgray": [169, 169, 169],
  785. "darkgreen": [0, 100, 0],
  786. "darkgrey": [169, 169, 169],
  787. "darkkhaki": [189, 183, 107],
  788. "darkmagenta": [139, 0, 139],
  789. "darkolivegreen": [85, 107, 47],
  790. "darkorange": [255, 140, 0],
  791. "darkorchid": [153, 50, 204],
  792. "darkred": [139, 0, 0],
  793. "darksalmon": [233, 150, 122],
  794. "darkseagreen": [143, 188, 143],
  795. "darkslateblue": [72, 61, 139],
  796. "darkslategray": [47, 79, 79],
  797. "darkslategrey": [47, 79, 79],
  798. "darkturquoise": [0, 206, 209],
  799. "darkviolet": [148, 0, 211],
  800. "deeppink": [255, 20, 147],
  801. "deepskyblue": [0, 191, 255],
  802. "dimgray": [105, 105, 105],
  803. "dimgrey": [105, 105, 105],
  804. "dodgerblue": [30, 144, 255],
  805. "firebrick": [178, 34, 34],
  806. "floralwhite": [255, 250, 240],
  807. "forestgreen": [34, 139, 34],
  808. "fuchsia": [255, 0, 255],
  809. "gainsboro": [220, 220, 220],
  810. "ghostwhite": [248, 248, 255],
  811. "gold": [255, 215, 0],
  812. "goldenrod": [218, 165, 32],
  813. "gray": [128, 128, 128],
  814. "green": [0, 128, 0],
  815. "greenyellow": [173, 255, 47],
  816. "grey": [128, 128, 128],
  817. "honeydew": [240, 255, 240],
  818. "hotpink": [255, 105, 180],
  819. "indianred": [205, 92, 92],
  820. "indigo": [75, 0, 130],
  821. "ivory": [255, 255, 240],
  822. "khaki": [240, 230, 140],
  823. "lavender": [230, 230, 250],
  824. "lavenderblush": [255, 240, 245],
  825. "lawngreen": [124, 252, 0],
  826. "lemonchiffon": [255, 250, 205],
  827. "lightblue": [173, 216, 230],
  828. "lightcoral": [240, 128, 128],
  829. "lightcyan": [224, 255, 255],
  830. "lightgoldenrodyellow": [250, 250, 210],
  831. "lightgray": [211, 211, 211],
  832. "lightgreen": [144, 238, 144],
  833. "lightgrey": [211, 211, 211],
  834. "lightpink": [255, 182, 193],
  835. "lightsalmon": [255, 160, 122],
  836. "lightseagreen": [32, 178, 170],
  837. "lightskyblue": [135, 206, 250],
  838. "lightslategray": [119, 136, 153],
  839. "lightslategrey": [119, 136, 153],
  840. "lightsteelblue": [176, 196, 222],
  841. "lightyellow": [255, 255, 224],
  842. "lime": [0, 255, 0],
  843. "limegreen": [50, 205, 50],
  844. "linen": [250, 240, 230],
  845. "magenta": [255, 0, 255],
  846. "maroon": [128, 0, 0],
  847. "mediumaquamarine": [102, 205, 170],
  848. "mediumblue": [0, 0, 205],
  849. "mediumorchid": [186, 85, 211],
  850. "mediumpurple": [147, 112, 219],
  851. "mediumseagreen": [60, 179, 113],
  852. "mediumslateblue": [123, 104, 238],
  853. "mediumspringgreen": [0, 250, 154],
  854. "mediumturquoise": [72, 209, 204],
  855. "mediumvioletred": [199, 21, 133],
  856. "midnightblue": [25, 25, 112],
  857. "mintcream": [245, 255, 250],
  858. "mistyrose": [255, 228, 225],
  859. "moccasin": [255, 228, 181],
  860. "navajowhite": [255, 222, 173],
  861. "navy": [0, 0, 128],
  862. "oldlace": [253, 245, 230],
  863. "olive": [128, 128, 0],
  864. "olivedrab": [107, 142, 35],
  865. "orange": [255, 165, 0],
  866. "orangered": [255, 69, 0],
  867. "orchid": [218, 112, 214],
  868. "palegoldenrod": [238, 232, 170],
  869. "palegreen": [152, 251, 152],
  870. "paleturquoise": [175, 238, 238],
  871. "palevioletred": [219, 112, 147],
  872. "papayawhip": [255, 239, 213],
  873. "peachpuff": [255, 218, 185],
  874. "peru": [205, 133, 63],
  875. "pink": [255, 192, 203],
  876. "plum": [221, 160, 221],
  877. "powderblue": [176, 224, 230],
  878. "purple": [128, 0, 128],
  879. "rebeccapurple": [102, 51, 153],
  880. "red": [255, 0, 0],
  881. "rosybrown": [188, 143, 143],
  882. "royalblue": [65, 105, 225],
  883. "saddlebrown": [139, 69, 19],
  884. "salmon": [250, 128, 114],
  885. "sandybrown": [244, 164, 96],
  886. "seagreen": [46, 139, 87],
  887. "seashell": [255, 245, 238],
  888. "sienna": [160, 82, 45],
  889. "silver": [192, 192, 192],
  890. "skyblue": [135, 206, 235],
  891. "slateblue": [106, 90, 205],
  892. "slategray": [112, 128, 144],
  893. "slategrey": [112, 128, 144],
  894. "snow": [255, 250, 250],
  895. "springgreen": [0, 255, 127],
  896. "steelblue": [70, 130, 180],
  897. "tan": [210, 180, 140],
  898. "teal": [0, 128, 128],
  899. "thistle": [216, 191, 216],
  900. "tomato": [255, 99, 71],
  901. "turquoise": [64, 224, 208],
  902. "violet": [238, 130, 238],
  903. "wheat": [245, 222, 179],
  904. "white": [255, 255, 255],
  905. "whitesmoke": [245, 245, 245],
  906. "yellow": [255, 255, 0],
  907. "yellowgreen": [154, 205, 50]
  908. };
  909. /* MIT license */
  910. /* eslint-disable no-mixed-operators */
  911. // NOTE: conversions should only return primitive values (i.e. arrays, or
  912. // values that give correct `typeof` results).
  913. // do not use box values types (i.e. Number(), String(), etc.)
  914. const reverseKeywords = {};
  915. for (const key of Object.keys(colorName)) {
  916. reverseKeywords[colorName[key]] = key;
  917. }
  918. const convert$1 = {
  919. rgb: {
  920. channels: 3,
  921. labels: 'rgb'
  922. },
  923. hsl: {
  924. channels: 3,
  925. labels: 'hsl'
  926. },
  927. hsv: {
  928. channels: 3,
  929. labels: 'hsv'
  930. },
  931. hwb: {
  932. channels: 3,
  933. labels: 'hwb'
  934. },
  935. cmyk: {
  936. channels: 4,
  937. labels: 'cmyk'
  938. },
  939. xyz: {
  940. channels: 3,
  941. labels: 'xyz'
  942. },
  943. lab: {
  944. channels: 3,
  945. labels: 'lab'
  946. },
  947. lch: {
  948. channels: 3,
  949. labels: 'lch'
  950. },
  951. hex: {
  952. channels: 1,
  953. labels: ['hex']
  954. },
  955. keyword: {
  956. channels: 1,
  957. labels: ['keyword']
  958. },
  959. ansi16: {
  960. channels: 1,
  961. labels: ['ansi16']
  962. },
  963. ansi256: {
  964. channels: 1,
  965. labels: ['ansi256']
  966. },
  967. hcg: {
  968. channels: 3,
  969. labels: ['h', 'c', 'g']
  970. },
  971. apple: {
  972. channels: 3,
  973. labels: ['r16', 'g16', 'b16']
  974. },
  975. gray: {
  976. channels: 1,
  977. labels: ['gray']
  978. }
  979. };
  980. var conversions = convert$1; // Hide .channels and .labels properties
  981. for (const model of Object.keys(convert$1)) {
  982. if (!('channels' in convert$1[model])) {
  983. throw new Error('missing channels property: ' + model);
  984. }
  985. if (!('labels' in convert$1[model])) {
  986. throw new Error('missing channel labels property: ' + model);
  987. }
  988. if (convert$1[model].labels.length !== convert$1[model].channels) {
  989. throw new Error('channel and label counts mismatch: ' + model);
  990. }
  991. const {
  992. channels,
  993. labels
  994. } = convert$1[model];
  995. delete convert$1[model].channels;
  996. delete convert$1[model].labels;
  997. Object.defineProperty(convert$1[model], 'channels', {
  998. value: channels
  999. });
  1000. Object.defineProperty(convert$1[model], 'labels', {
  1001. value: labels
  1002. });
  1003. }
  1004. convert$1.rgb.hsl = function (rgb) {
  1005. const r = rgb[0] / 255;
  1006. const g = rgb[1] / 255;
  1007. const b = rgb[2] / 255;
  1008. const min = Math.min(r, g, b);
  1009. const max = Math.max(r, g, b);
  1010. const delta = max - min;
  1011. let h;
  1012. let s;
  1013. if (max === min) {
  1014. h = 0;
  1015. } else if (r === max) {
  1016. h = (g - b) / delta;
  1017. } else if (g === max) {
  1018. h = 2 + (b - r) / delta;
  1019. } else if (b === max) {
  1020. h = 4 + (r - g) / delta;
  1021. }
  1022. h = Math.min(h * 60, 360);
  1023. if (h < 0) {
  1024. h += 360;
  1025. }
  1026. const l = (min + max) / 2;
  1027. if (max === min) {
  1028. s = 0;
  1029. } else if (l <= 0.5) {
  1030. s = delta / (max + min);
  1031. } else {
  1032. s = delta / (2 - max - min);
  1033. }
  1034. return [h, s * 100, l * 100];
  1035. };
  1036. convert$1.rgb.hsv = function (rgb) {
  1037. let rdif;
  1038. let gdif;
  1039. let bdif;
  1040. let h;
  1041. let s;
  1042. const r = rgb[0] / 255;
  1043. const g = rgb[1] / 255;
  1044. const b = rgb[2] / 255;
  1045. const v = Math.max(r, g, b);
  1046. const diff = v - Math.min(r, g, b);
  1047. const diffc = function (c) {
  1048. return (v - c) / 6 / diff + 1 / 2;
  1049. };
  1050. if (diff === 0) {
  1051. h = 0;
  1052. s = 0;
  1053. } else {
  1054. s = diff / v;
  1055. rdif = diffc(r);
  1056. gdif = diffc(g);
  1057. bdif = diffc(b);
  1058. if (r === v) {
  1059. h = bdif - gdif;
  1060. } else if (g === v) {
  1061. h = 1 / 3 + rdif - bdif;
  1062. } else if (b === v) {
  1063. h = 2 / 3 + gdif - rdif;
  1064. }
  1065. if (h < 0) {
  1066. h += 1;
  1067. } else if (h > 1) {
  1068. h -= 1;
  1069. }
  1070. }
  1071. return [h * 360, s * 100, v * 100];
  1072. };
  1073. convert$1.rgb.hwb = function (rgb) {
  1074. const r = rgb[0];
  1075. const g = rgb[1];
  1076. let b = rgb[2];
  1077. const h = convert$1.rgb.hsl(rgb)[0];
  1078. const w = 1 / 255 * Math.min(r, Math.min(g, b));
  1079. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  1080. return [h, w * 100, b * 100];
  1081. };
  1082. convert$1.rgb.cmyk = function (rgb) {
  1083. const r = rgb[0] / 255;
  1084. const g = rgb[1] / 255;
  1085. const b = rgb[2] / 255;
  1086. const k = Math.min(1 - r, 1 - g, 1 - b);
  1087. const c = (1 - r - k) / (1 - k) || 0;
  1088. const m = (1 - g - k) / (1 - k) || 0;
  1089. const y = (1 - b - k) / (1 - k) || 0;
  1090. return [c * 100, m * 100, y * 100, k * 100];
  1091. };
  1092. function comparativeDistance(x, y) {
  1093. /*
  1094. See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  1095. */
  1096. return (x[0] - y[0]) ** 2 + (x[1] - y[1]) ** 2 + (x[2] - y[2]) ** 2;
  1097. }
  1098. convert$1.rgb.keyword = function (rgb) {
  1099. const reversed = reverseKeywords[rgb];
  1100. if (reversed) {
  1101. return reversed;
  1102. }
  1103. let currentClosestDistance = Infinity;
  1104. let currentClosestKeyword;
  1105. for (const keyword of Object.keys(colorName)) {
  1106. const value = colorName[keyword]; // Compute comparative distance
  1107. const distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  1108. if (distance < currentClosestDistance) {
  1109. currentClosestDistance = distance;
  1110. currentClosestKeyword = keyword;
  1111. }
  1112. }
  1113. return currentClosestKeyword;
  1114. };
  1115. convert$1.keyword.rgb = function (keyword) {
  1116. return colorName[keyword];
  1117. };
  1118. convert$1.rgb.xyz = function (rgb) {
  1119. let r = rgb[0] / 255;
  1120. let g = rgb[1] / 255;
  1121. let b = rgb[2] / 255; // Assume sRGB
  1122. r = r > 0.04045 ? ((r + 0.055) / 1.055) ** 2.4 : r / 12.92;
  1123. g = g > 0.04045 ? ((g + 0.055) / 1.055) ** 2.4 : g / 12.92;
  1124. b = b > 0.04045 ? ((b + 0.055) / 1.055) ** 2.4 : b / 12.92;
  1125. const x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  1126. const y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  1127. const z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  1128. return [x * 100, y * 100, z * 100];
  1129. };
  1130. convert$1.rgb.lab = function (rgb) {
  1131. const xyz = convert$1.rgb.xyz(rgb);
  1132. let x = xyz[0];
  1133. let y = xyz[1];
  1134. let z = xyz[2];
  1135. x /= 95.047;
  1136. y /= 100;
  1137. z /= 108.883;
  1138. x = x > 0.008856 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
  1139. y = y > 0.008856 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
  1140. z = z > 0.008856 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
  1141. const l = 116 * y - 16;
  1142. const a = 500 * (x - y);
  1143. const b = 200 * (y - z);
  1144. return [l, a, b];
  1145. };
  1146. convert$1.hsl.rgb = function (hsl) {
  1147. const h = hsl[0] / 360;
  1148. const s = hsl[1] / 100;
  1149. const l = hsl[2] / 100;
  1150. let t2;
  1151. let t3;
  1152. let val;
  1153. if (s === 0) {
  1154. val = l * 255;
  1155. return [val, val, val];
  1156. }
  1157. if (l < 0.5) {
  1158. t2 = l * (1 + s);
  1159. } else {
  1160. t2 = l + s - l * s;
  1161. }
  1162. const t1 = 2 * l - t2;
  1163. const rgb = [0, 0, 0];
  1164. for (let i = 0; i < 3; i++) {
  1165. t3 = h + 1 / 3 * -(i - 1);
  1166. if (t3 < 0) {
  1167. t3++;
  1168. }
  1169. if (t3 > 1) {
  1170. t3--;
  1171. }
  1172. if (6 * t3 < 1) {
  1173. val = t1 + (t2 - t1) * 6 * t3;
  1174. } else if (2 * t3 < 1) {
  1175. val = t2;
  1176. } else if (3 * t3 < 2) {
  1177. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  1178. } else {
  1179. val = t1;
  1180. }
  1181. rgb[i] = val * 255;
  1182. }
  1183. return rgb;
  1184. };
  1185. convert$1.hsl.hsv = function (hsl) {
  1186. const h = hsl[0];
  1187. let s = hsl[1] / 100;
  1188. let l = hsl[2] / 100;
  1189. let smin = s;
  1190. const lmin = Math.max(l, 0.01);
  1191. l *= 2;
  1192. s *= l <= 1 ? l : 2 - l;
  1193. smin *= lmin <= 1 ? lmin : 2 - lmin;
  1194. const v = (l + s) / 2;
  1195. const sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  1196. return [h, sv * 100, v * 100];
  1197. };
  1198. convert$1.hsv.rgb = function (hsv) {
  1199. const h = hsv[0] / 60;
  1200. const s = hsv[1] / 100;
  1201. let v = hsv[2] / 100;
  1202. const hi = Math.floor(h) % 6;
  1203. const f = h - Math.floor(h);
  1204. const p = 255 * v * (1 - s);
  1205. const q = 255 * v * (1 - s * f);
  1206. const t = 255 * v * (1 - s * (1 - f));
  1207. v *= 255;
  1208. switch (hi) {
  1209. case 0:
  1210. return [v, t, p];
  1211. case 1:
  1212. return [q, v, p];
  1213. case 2:
  1214. return [p, v, t];
  1215. case 3:
  1216. return [p, q, v];
  1217. case 4:
  1218. return [t, p, v];
  1219. case 5:
  1220. return [v, p, q];
  1221. }
  1222. };
  1223. convert$1.hsv.hsl = function (hsv) {
  1224. const h = hsv[0];
  1225. const s = hsv[1] / 100;
  1226. const v = hsv[2] / 100;
  1227. const vmin = Math.max(v, 0.01);
  1228. let sl;
  1229. let l;
  1230. l = (2 - s) * v;
  1231. const lmin = (2 - s) * vmin;
  1232. sl = s * vmin;
  1233. sl /= lmin <= 1 ? lmin : 2 - lmin;
  1234. sl = sl || 0;
  1235. l /= 2;
  1236. return [h, sl * 100, l * 100];
  1237. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  1238. convert$1.hwb.rgb = function (hwb) {
  1239. const h = hwb[0] / 360;
  1240. let wh = hwb[1] / 100;
  1241. let bl = hwb[2] / 100;
  1242. const ratio = wh + bl;
  1243. let f; // Wh + bl cant be > 1
  1244. if (ratio > 1) {
  1245. wh /= ratio;
  1246. bl /= ratio;
  1247. }
  1248. const i = Math.floor(6 * h);
  1249. const v = 1 - bl;
  1250. f = 6 * h - i;
  1251. if ((i & 0x01) !== 0) {
  1252. f = 1 - f;
  1253. }
  1254. const n = wh + f * (v - wh); // Linear interpolation
  1255. let r;
  1256. let g;
  1257. let b;
  1258. /* eslint-disable max-statements-per-line,no-multi-spaces */
  1259. switch (i) {
  1260. default:
  1261. case 6:
  1262. case 0:
  1263. r = v;
  1264. g = n;
  1265. b = wh;
  1266. break;
  1267. case 1:
  1268. r = n;
  1269. g = v;
  1270. b = wh;
  1271. break;
  1272. case 2:
  1273. r = wh;
  1274. g = v;
  1275. b = n;
  1276. break;
  1277. case 3:
  1278. r = wh;
  1279. g = n;
  1280. b = v;
  1281. break;
  1282. case 4:
  1283. r = n;
  1284. g = wh;
  1285. b = v;
  1286. break;
  1287. case 5:
  1288. r = v;
  1289. g = wh;
  1290. b = n;
  1291. break;
  1292. }
  1293. /* eslint-enable max-statements-per-line,no-multi-spaces */
  1294. return [r * 255, g * 255, b * 255];
  1295. };
  1296. convert$1.cmyk.rgb = function (cmyk) {
  1297. const c = cmyk[0] / 100;
  1298. const m = cmyk[1] / 100;
  1299. const y = cmyk[2] / 100;
  1300. const k = cmyk[3] / 100;
  1301. const r = 1 - Math.min(1, c * (1 - k) + k);
  1302. const g = 1 - Math.min(1, m * (1 - k) + k);
  1303. const b = 1 - Math.min(1, y * (1 - k) + k);
  1304. return [r * 255, g * 255, b * 255];
  1305. };
  1306. convert$1.xyz.rgb = function (xyz) {
  1307. const x = xyz[0] / 100;
  1308. const y = xyz[1] / 100;
  1309. const z = xyz[2] / 100;
  1310. let r;
  1311. let g;
  1312. let b;
  1313. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  1314. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  1315. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // Assume sRGB
  1316. r = r > 0.0031308 ? 1.055 * r ** (1.0 / 2.4) - 0.055 : r * 12.92;
  1317. g = g > 0.0031308 ? 1.055 * g ** (1.0 / 2.4) - 0.055 : g * 12.92;
  1318. b = b > 0.0031308 ? 1.055 * b ** (1.0 / 2.4) - 0.055 : b * 12.92;
  1319. r = Math.min(Math.max(0, r), 1);
  1320. g = Math.min(Math.max(0, g), 1);
  1321. b = Math.min(Math.max(0, b), 1);
  1322. return [r * 255, g * 255, b * 255];
  1323. };
  1324. convert$1.xyz.lab = function (xyz) {
  1325. let x = xyz[0];
  1326. let y = xyz[1];
  1327. let z = xyz[2];
  1328. x /= 95.047;
  1329. y /= 100;
  1330. z /= 108.883;
  1331. x = x > 0.008856 ? x ** (1 / 3) : 7.787 * x + 16 / 116;
  1332. y = y > 0.008856 ? y ** (1 / 3) : 7.787 * y + 16 / 116;
  1333. z = z > 0.008856 ? z ** (1 / 3) : 7.787 * z + 16 / 116;
  1334. const l = 116 * y - 16;
  1335. const a = 500 * (x - y);
  1336. const b = 200 * (y - z);
  1337. return [l, a, b];
  1338. };
  1339. convert$1.lab.xyz = function (lab) {
  1340. const l = lab[0];
  1341. const a = lab[1];
  1342. const b = lab[2];
  1343. let x;
  1344. let y;
  1345. let z;
  1346. y = (l + 16) / 116;
  1347. x = a / 500 + y;
  1348. z = y - b / 200;
  1349. const y2 = y ** 3;
  1350. const x2 = x ** 3;
  1351. const z2 = z ** 3;
  1352. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  1353. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  1354. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  1355. x *= 95.047;
  1356. y *= 100;
  1357. z *= 108.883;
  1358. return [x, y, z];
  1359. };
  1360. convert$1.lab.lch = function (lab) {
  1361. const l = lab[0];
  1362. const a = lab[1];
  1363. const b = lab[2];
  1364. let h;
  1365. const hr = Math.atan2(b, a);
  1366. h = hr * 360 / 2 / Math.PI;
  1367. if (h < 0) {
  1368. h += 360;
  1369. }
  1370. const c = Math.sqrt(a * a + b * b);
  1371. return [l, c, h];
  1372. };
  1373. convert$1.lch.lab = function (lch) {
  1374. const l = lch[0];
  1375. const c = lch[1];
  1376. const h = lch[2];
  1377. const hr = h / 360 * 2 * Math.PI;
  1378. const a = c * Math.cos(hr);
  1379. const b = c * Math.sin(hr);
  1380. return [l, a, b];
  1381. };
  1382. convert$1.rgb.ansi16 = function (args, saturation = null) {
  1383. const [r, g, b] = args;
  1384. let value = saturation === null ? convert$1.rgb.hsv(args)[2] : saturation; // Hsv -> ansi16 optimization
  1385. value = Math.round(value / 50);
  1386. if (value === 0) {
  1387. return 30;
  1388. }
  1389. let ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  1390. if (value === 2) {
  1391. ansi += 60;
  1392. }
  1393. return ansi;
  1394. };
  1395. convert$1.hsv.ansi16 = function (args) {
  1396. // Optimization here; we already know the value and don't need to get
  1397. // it converted for us.
  1398. return convert$1.rgb.ansi16(convert$1.hsv.rgb(args), args[2]);
  1399. };
  1400. convert$1.rgb.ansi256 = function (args) {
  1401. const r = args[0];
  1402. const g = args[1];
  1403. const b = args[2]; // We use the extended greyscale palette here, with the exception of
  1404. // black and white. normal palette only has 4 greyscale shades.
  1405. if (r === g && g === b) {
  1406. if (r < 8) {
  1407. return 16;
  1408. }
  1409. if (r > 248) {
  1410. return 231;
  1411. }
  1412. return Math.round((r - 8) / 247 * 24) + 232;
  1413. }
  1414. const ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  1415. return ansi;
  1416. };
  1417. convert$1.ansi16.rgb = function (args) {
  1418. let color = args % 10; // Handle greyscale
  1419. if (color === 0 || color === 7) {
  1420. if (args > 50) {
  1421. color += 3.5;
  1422. }
  1423. color = color / 10.5 * 255;
  1424. return [color, color, color];
  1425. }
  1426. const mult = (~~(args > 50) + 1) * 0.5;
  1427. const r = (color & 1) * mult * 255;
  1428. const g = (color >> 1 & 1) * mult * 255;
  1429. const b = (color >> 2 & 1) * mult * 255;
  1430. return [r, g, b];
  1431. };
  1432. convert$1.ansi256.rgb = function (args) {
  1433. // Handle greyscale
  1434. if (args >= 232) {
  1435. const c = (args - 232) * 10 + 8;
  1436. return [c, c, c];
  1437. }
  1438. args -= 16;
  1439. let rem;
  1440. const r = Math.floor(args / 36) / 5 * 255;
  1441. const g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  1442. const b = rem % 6 / 5 * 255;
  1443. return [r, g, b];
  1444. };
  1445. convert$1.rgb.hex = function (args) {
  1446. const integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  1447. const string = integer.toString(16).toUpperCase();
  1448. return '000000'.substring(string.length) + string;
  1449. };
  1450. convert$1.hex.rgb = function (args) {
  1451. const match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  1452. if (!match) {
  1453. return [0, 0, 0];
  1454. }
  1455. let colorString = match[0];
  1456. if (match[0].length === 3) {
  1457. colorString = colorString.split('').map(char => {
  1458. return char + char;
  1459. }).join('');
  1460. }
  1461. const integer = parseInt(colorString, 16);
  1462. const r = integer >> 16 & 0xFF;
  1463. const g = integer >> 8 & 0xFF;
  1464. const b = integer & 0xFF;
  1465. return [r, g, b];
  1466. };
  1467. convert$1.rgb.hcg = function (rgb) {
  1468. const r = rgb[0] / 255;
  1469. const g = rgb[1] / 255;
  1470. const b = rgb[2] / 255;
  1471. const max = Math.max(Math.max(r, g), b);
  1472. const min = Math.min(Math.min(r, g), b);
  1473. const chroma = max - min;
  1474. let grayscale;
  1475. let hue;
  1476. if (chroma < 1) {
  1477. grayscale = min / (1 - chroma);
  1478. } else {
  1479. grayscale = 0;
  1480. }
  1481. if (chroma <= 0) {
  1482. hue = 0;
  1483. } else if (max === r) {
  1484. hue = (g - b) / chroma % 6;
  1485. } else if (max === g) {
  1486. hue = 2 + (b - r) / chroma;
  1487. } else {
  1488. hue = 4 + (r - g) / chroma;
  1489. }
  1490. hue /= 6;
  1491. hue %= 1;
  1492. return [hue * 360, chroma * 100, grayscale * 100];
  1493. };
  1494. convert$1.hsl.hcg = function (hsl) {
  1495. const s = hsl[1] / 100;
  1496. const l = hsl[2] / 100;
  1497. const c = l < 0.5 ? 2.0 * s * l : 2.0 * s * (1.0 - l);
  1498. let f = 0;
  1499. if (c < 1.0) {
  1500. f = (l - 0.5 * c) / (1.0 - c);
  1501. }
  1502. return [hsl[0], c * 100, f * 100];
  1503. };
  1504. convert$1.hsv.hcg = function (hsv) {
  1505. const s = hsv[1] / 100;
  1506. const v = hsv[2] / 100;
  1507. const c = s * v;
  1508. let f = 0;
  1509. if (c < 1.0) {
  1510. f = (v - c) / (1 - c);
  1511. }
  1512. return [hsv[0], c * 100, f * 100];
  1513. };
  1514. convert$1.hcg.rgb = function (hcg) {
  1515. const h = hcg[0] / 360;
  1516. const c = hcg[1] / 100;
  1517. const g = hcg[2] / 100;
  1518. if (c === 0.0) {
  1519. return [g * 255, g * 255, g * 255];
  1520. }
  1521. const pure = [0, 0, 0];
  1522. const hi = h % 1 * 6;
  1523. const v = hi % 1;
  1524. const w = 1 - v;
  1525. let mg = 0;
  1526. /* eslint-disable max-statements-per-line */
  1527. switch (Math.floor(hi)) {
  1528. case 0:
  1529. pure[0] = 1;
  1530. pure[1] = v;
  1531. pure[2] = 0;
  1532. break;
  1533. case 1:
  1534. pure[0] = w;
  1535. pure[1] = 1;
  1536. pure[2] = 0;
  1537. break;
  1538. case 2:
  1539. pure[0] = 0;
  1540. pure[1] = 1;
  1541. pure[2] = v;
  1542. break;
  1543. case 3:
  1544. pure[0] = 0;
  1545. pure[1] = w;
  1546. pure[2] = 1;
  1547. break;
  1548. case 4:
  1549. pure[0] = v;
  1550. pure[1] = 0;
  1551. pure[2] = 1;
  1552. break;
  1553. default:
  1554. pure[0] = 1;
  1555. pure[1] = 0;
  1556. pure[2] = w;
  1557. }
  1558. /* eslint-enable max-statements-per-line */
  1559. mg = (1.0 - c) * g;
  1560. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  1561. };
  1562. convert$1.hcg.hsv = function (hcg) {
  1563. const c = hcg[1] / 100;
  1564. const g = hcg[2] / 100;
  1565. const v = c + g * (1.0 - c);
  1566. let f = 0;
  1567. if (v > 0.0) {
  1568. f = c / v;
  1569. }
  1570. return [hcg[0], f * 100, v * 100];
  1571. };
  1572. convert$1.hcg.hsl = function (hcg) {
  1573. const c = hcg[1] / 100;
  1574. const g = hcg[2] / 100;
  1575. const l = g * (1.0 - c) + 0.5 * c;
  1576. let s = 0;
  1577. if (l > 0.0 && l < 0.5) {
  1578. s = c / (2 * l);
  1579. } else if (l >= 0.5 && l < 1.0) {
  1580. s = c / (2 * (1 - l));
  1581. }
  1582. return [hcg[0], s * 100, l * 100];
  1583. };
  1584. convert$1.hcg.hwb = function (hcg) {
  1585. const c = hcg[1] / 100;
  1586. const g = hcg[2] / 100;
  1587. const v = c + g * (1.0 - c);
  1588. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  1589. };
  1590. convert$1.hwb.hcg = function (hwb) {
  1591. const w = hwb[1] / 100;
  1592. const b = hwb[2] / 100;
  1593. const v = 1 - b;
  1594. const c = v - w;
  1595. let g = 0;
  1596. if (c < 1) {
  1597. g = (v - c) / (1 - c);
  1598. }
  1599. return [hwb[0], c * 100, g * 100];
  1600. };
  1601. convert$1.apple.rgb = function (apple) {
  1602. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  1603. };
  1604. convert$1.rgb.apple = function (rgb) {
  1605. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  1606. };
  1607. convert$1.gray.rgb = function (args) {
  1608. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  1609. };
  1610. convert$1.gray.hsl = function (args) {
  1611. return [0, 0, args[0]];
  1612. };
  1613. convert$1.gray.hsv = convert$1.gray.hsl;
  1614. convert$1.gray.hwb = function (gray) {
  1615. return [0, 100, gray[0]];
  1616. };
  1617. convert$1.gray.cmyk = function (gray) {
  1618. return [0, 0, 0, gray[0]];
  1619. };
  1620. convert$1.gray.lab = function (gray) {
  1621. return [gray[0], 0, 0];
  1622. };
  1623. convert$1.gray.hex = function (gray) {
  1624. const val = Math.round(gray[0] / 100 * 255) & 0xFF;
  1625. const integer = (val << 16) + (val << 8) + val;
  1626. const string = integer.toString(16).toUpperCase();
  1627. return '000000'.substring(string.length) + string;
  1628. };
  1629. convert$1.rgb.gray = function (rgb) {
  1630. const val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  1631. return [val / 255 * 100];
  1632. };
  1633. /*
  1634. This function routes a model to all other models.
  1635. all functions that are routed have a property `.conversion` attached
  1636. to the returned synthetic function. This property is an array
  1637. of strings, each with the steps in between the 'from' and 'to'
  1638. color models (inclusive).
  1639. conversions that are not possible simply are not included.
  1640. */
  1641. function buildGraph() {
  1642. const graph = {}; // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  1643. const models = Object.keys(conversions);
  1644. for (let len = models.length, i = 0; i < len; i++) {
  1645. graph[models[i]] = {
  1646. // http://jsperf.com/1-vs-infinity
  1647. // micro-opt, but this is simple.
  1648. distance: -1,
  1649. parent: null
  1650. };
  1651. }
  1652. return graph;
  1653. } // https://en.wikipedia.org/wiki/Breadth-first_search
  1654. function deriveBFS(fromModel) {
  1655. const graph = buildGraph();
  1656. const queue = [fromModel]; // Unshift -> queue -> pop
  1657. graph[fromModel].distance = 0;
  1658. while (queue.length) {
  1659. const current = queue.pop();
  1660. const adjacents = Object.keys(conversions[current]);
  1661. for (let len = adjacents.length, i = 0; i < len; i++) {
  1662. const adjacent = adjacents[i];
  1663. const node = graph[adjacent];
  1664. if (node.distance === -1) {
  1665. node.distance = graph[current].distance + 1;
  1666. node.parent = current;
  1667. queue.unshift(adjacent);
  1668. }
  1669. }
  1670. }
  1671. return graph;
  1672. }
  1673. function link(from, to) {
  1674. return function (args) {
  1675. return to(from(args));
  1676. };
  1677. }
  1678. function wrapConversion(toModel, graph) {
  1679. const path = [graph[toModel].parent, toModel];
  1680. let fn = conversions[graph[toModel].parent][toModel];
  1681. let cur = graph[toModel].parent;
  1682. while (graph[cur].parent) {
  1683. path.unshift(graph[cur].parent);
  1684. fn = link(conversions[graph[cur].parent][cur], fn);
  1685. cur = graph[cur].parent;
  1686. }
  1687. fn.conversion = path;
  1688. return fn;
  1689. }
  1690. var route = function (fromModel) {
  1691. const graph = deriveBFS(fromModel);
  1692. const conversion = {};
  1693. const models = Object.keys(graph);
  1694. for (let len = models.length, i = 0; i < len; i++) {
  1695. const toModel = models[i];
  1696. const node = graph[toModel];
  1697. if (node.parent === null) {
  1698. // No possible conversion, or this node is the source model.
  1699. continue;
  1700. }
  1701. conversion[toModel] = wrapConversion(toModel, graph);
  1702. }
  1703. return conversion;
  1704. };
  1705. const convert = {};
  1706. const models = Object.keys(conversions);
  1707. function wrapRaw(fn) {
  1708. const wrappedFn = function (...args) {
  1709. const arg0 = args[0];
  1710. if (arg0 === undefined || arg0 === null) {
  1711. return arg0;
  1712. }
  1713. if (arg0.length > 1) {
  1714. args = arg0;
  1715. }
  1716. return fn(args);
  1717. }; // Preserve .conversion property if there is one
  1718. if ('conversion' in fn) {
  1719. wrappedFn.conversion = fn.conversion;
  1720. }
  1721. return wrappedFn;
  1722. }
  1723. function wrapRounded(fn) {
  1724. const wrappedFn = function (...args) {
  1725. const arg0 = args[0];
  1726. if (arg0 === undefined || arg0 === null) {
  1727. return arg0;
  1728. }
  1729. if (arg0.length > 1) {
  1730. args = arg0;
  1731. }
  1732. const result = fn(args); // We're assuming the result is an array here.
  1733. // see notice in conversions.js; don't use box types
  1734. // in conversion functions.
  1735. if (typeof result === 'object') {
  1736. for (let len = result.length, i = 0; i < len; i++) {
  1737. result[i] = Math.round(result[i]);
  1738. }
  1739. }
  1740. return result;
  1741. }; // Preserve .conversion property if there is one
  1742. if ('conversion' in fn) {
  1743. wrappedFn.conversion = fn.conversion;
  1744. }
  1745. return wrappedFn;
  1746. }
  1747. models.forEach(fromModel => {
  1748. convert[fromModel] = {};
  1749. Object.defineProperty(convert[fromModel], 'channels', {
  1750. value: conversions[fromModel].channels
  1751. });
  1752. Object.defineProperty(convert[fromModel], 'labels', {
  1753. value: conversions[fromModel].labels
  1754. });
  1755. const routes = route(fromModel);
  1756. const routeModels = Object.keys(routes);
  1757. routeModels.forEach(toModel => {
  1758. const fn = routes[toModel];
  1759. convert[fromModel][toModel] = wrapRounded(fn);
  1760. convert[fromModel][toModel].raw = wrapRaw(fn);
  1761. });
  1762. });
  1763. var colorConvert = convert;
  1764. var ansiStyles = createCommonjsModule(function (module) {
  1765. const wrapAnsi16 = (fn, offset) => (...args) => {
  1766. const code = fn(...args);
  1767. return `\u001B[${code + offset}m`;
  1768. };
  1769. const wrapAnsi256 = (fn, offset) => (...args) => {
  1770. const code = fn(...args);
  1771. return `\u001B[${38 + offset};5;${code}m`;
  1772. };
  1773. const wrapAnsi16m = (fn, offset) => (...args) => {
  1774. const rgb = fn(...args);
  1775. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  1776. };
  1777. const ansi2ansi = n => n;
  1778. const rgb2rgb = (r, g, b) => [r, g, b];
  1779. const setLazyProperty = (object, property, get) => {
  1780. Object.defineProperty(object, property, {
  1781. get: () => {
  1782. const value = get();
  1783. Object.defineProperty(object, property, {
  1784. value,
  1785. enumerable: true,
  1786. configurable: true
  1787. });
  1788. return value;
  1789. },
  1790. enumerable: true,
  1791. configurable: true
  1792. });
  1793. };
  1794. /** @type {typeof import('color-convert')} */
  1795. let colorConvert$1;
  1796. const makeDynamicStyles = (wrap, targetSpace, identity, isBackground) => {
  1797. if (colorConvert$1 === undefined) {
  1798. colorConvert$1 = colorConvert;
  1799. }
  1800. const offset = isBackground ? 10 : 0;
  1801. const styles = {};
  1802. for (const [sourceSpace, suite] of Object.entries(colorConvert$1)) {
  1803. const name = sourceSpace === 'ansi16' ? 'ansi' : sourceSpace;
  1804. if (sourceSpace === targetSpace) {
  1805. styles[name] = wrap(identity, offset);
  1806. } else if (typeof suite === 'object') {
  1807. styles[name] = wrap(suite[targetSpace], offset);
  1808. }
  1809. }
  1810. return styles;
  1811. };
  1812. function assembleStyles() {
  1813. const codes = new Map();
  1814. const styles = {
  1815. modifier: {
  1816. reset: [0, 0],
  1817. // 21 isn't widely supported and 22 does the same thing
  1818. bold: [1, 22],
  1819. dim: [2, 22],
  1820. italic: [3, 23],
  1821. underline: [4, 24],
  1822. inverse: [7, 27],
  1823. hidden: [8, 28],
  1824. strikethrough: [9, 29]
  1825. },
  1826. color: {
  1827. black: [30, 39],
  1828. red: [31, 39],
  1829. green: [32, 39],
  1830. yellow: [33, 39],
  1831. blue: [34, 39],
  1832. magenta: [35, 39],
  1833. cyan: [36, 39],
  1834. white: [37, 39],
  1835. // Bright color
  1836. blackBright: [90, 39],
  1837. redBright: [91, 39],
  1838. greenBright: [92, 39],
  1839. yellowBright: [93, 39],
  1840. blueBright: [94, 39],
  1841. magentaBright: [95, 39],
  1842. cyanBright: [96, 39],
  1843. whiteBright: [97, 39]
  1844. },
  1845. bgColor: {
  1846. bgBlack: [40, 49],
  1847. bgRed: [41, 49],
  1848. bgGreen: [42, 49],
  1849. bgYellow: [43, 49],
  1850. bgBlue: [44, 49],
  1851. bgMagenta: [45, 49],
  1852. bgCyan: [46, 49],
  1853. bgWhite: [47, 49],
  1854. // Bright color
  1855. bgBlackBright: [100, 49],
  1856. bgRedBright: [101, 49],
  1857. bgGreenBright: [102, 49],
  1858. bgYellowBright: [103, 49],
  1859. bgBlueBright: [104, 49],
  1860. bgMagentaBright: [105, 49],
  1861. bgCyanBright: [106, 49],
  1862. bgWhiteBright: [107, 49]
  1863. }
  1864. }; // Alias bright black as gray (and grey)
  1865. styles.color.gray = styles.color.blackBright;
  1866. styles.bgColor.bgGray = styles.bgColor.bgBlackBright;
  1867. styles.color.grey = styles.color.blackBright;
  1868. styles.bgColor.bgGrey = styles.bgColor.bgBlackBright;
  1869. for (const [groupName, group] of Object.entries(styles)) {
  1870. for (const [styleName, style] of Object.entries(group)) {
  1871. styles[styleName] = {
  1872. open: `\u001B[${style[0]}m`,
  1873. close: `\u001B[${style[1]}m`
  1874. };
  1875. group[styleName] = styles[styleName];
  1876. codes.set(style[0], style[1]);
  1877. }
  1878. Object.defineProperty(styles, groupName, {
  1879. value: group,
  1880. enumerable: false
  1881. });
  1882. }
  1883. Object.defineProperty(styles, 'codes', {
  1884. value: codes,
  1885. enumerable: false
  1886. });
  1887. styles.color.close = '\u001B[39m';
  1888. styles.bgColor.close = '\u001B[49m';
  1889. setLazyProperty(styles.color, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, false));
  1890. setLazyProperty(styles.color, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, false));
  1891. setLazyProperty(styles.color, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, false));
  1892. setLazyProperty(styles.bgColor, 'ansi', () => makeDynamicStyles(wrapAnsi16, 'ansi16', ansi2ansi, true));
  1893. setLazyProperty(styles.bgColor, 'ansi256', () => makeDynamicStyles(wrapAnsi256, 'ansi256', ansi2ansi, true));
  1894. setLazyProperty(styles.bgColor, 'ansi16m', () => makeDynamicStyles(wrapAnsi16m, 'rgb', rgb2rgb, true));
  1895. return styles;
  1896. } // Make the export immutable
  1897. Object.defineProperty(module, 'exports', {
  1898. enumerable: true,
  1899. get: assembleStyles
  1900. });
  1901. });
  1902. var hasFlag = (flag, argv = process.argv) => {
  1903. const prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
  1904. const position = argv.indexOf(prefix + flag);
  1905. const terminatorPosition = argv.indexOf('--');
  1906. return position !== -1 && (terminatorPosition === -1 || position < terminatorPosition);
  1907. };
  1908. const {
  1909. env
  1910. } = process;
  1911. let forceColor;
  1912. if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false') || hasFlag('color=never')) {
  1913. forceColor = 0;
  1914. } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
  1915. forceColor = 1;
  1916. }
  1917. if ('FORCE_COLOR' in env) {
  1918. if (env.FORCE_COLOR === 'true') {
  1919. forceColor = 1;
  1920. } else if (env.FORCE_COLOR === 'false') {
  1921. forceColor = 0;
  1922. } else {
  1923. forceColor = env.FORCE_COLOR.length === 0 ? 1 : Math.min(parseInt(env.FORCE_COLOR, 10), 3);
  1924. }
  1925. }
  1926. function translateLevel(level) {
  1927. if (level === 0) {
  1928. return false;
  1929. }
  1930. return {
  1931. level,
  1932. hasBasic: true,
  1933. has256: level >= 2,
  1934. has16m: level >= 3
  1935. };
  1936. }
  1937. function supportsColor(haveStream, streamIsTTY) {
  1938. if (forceColor === 0) {
  1939. return 0;
  1940. }
  1941. if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
  1942. return 3;
  1943. }
  1944. if (hasFlag('color=256')) {
  1945. return 2;
  1946. }
  1947. if (haveStream && !streamIsTTY && forceColor === undefined) {
  1948. return 0;
  1949. }
  1950. const min = forceColor || 0;
  1951. if (env.TERM === 'dumb') {
  1952. return min;
  1953. }
  1954. if (process.platform === 'win32') {
  1955. // Windows 10 build 10586 is the first Windows release that supports 256 colors.
  1956. // Windows 10 build 14931 is the first release that supports 16m/TrueColor.
  1957. const osRelease = os__default['default'].release().split('.');
  1958. if (Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  1959. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  1960. }
  1961. return 1;
  1962. }
  1963. if ('CI' in env) {
  1964. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI', 'GITHUB_ACTIONS', 'BUILDKITE'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
  1965. return 1;
  1966. }
  1967. return min;
  1968. }
  1969. if ('TEAMCITY_VERSION' in env) {
  1970. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  1971. }
  1972. if (env.COLORTERM === 'truecolor') {
  1973. return 3;
  1974. }
  1975. if ('TERM_PROGRAM' in env) {
  1976. const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  1977. switch (env.TERM_PROGRAM) {
  1978. case 'iTerm.app':
  1979. return version >= 3 ? 3 : 2;
  1980. case 'Apple_Terminal':
  1981. return 2;
  1982. // No default
  1983. }
  1984. }
  1985. if (/-256(color)?$/i.test(env.TERM)) {
  1986. return 2;
  1987. }
  1988. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  1989. return 1;
  1990. }
  1991. if ('COLORTERM' in env) {
  1992. return 1;
  1993. }
  1994. return min;
  1995. }
  1996. function getSupportLevel(stream) {
  1997. const level = supportsColor(stream, stream && stream.isTTY);
  1998. return translateLevel(level);
  1999. }
  2000. var supportsColor_1 = {
  2001. supportsColor: getSupportLevel,
  2002. stdout: translateLevel(supportsColor(true, tty__default['default'].isatty(1))),
  2003. stderr: translateLevel(supportsColor(true, tty__default['default'].isatty(2)))
  2004. };
  2005. const stringReplaceAll$1 = (string, substring, replacer) => {
  2006. let index = string.indexOf(substring);
  2007. if (index === -1) {
  2008. return string;
  2009. }
  2010. const substringLength = substring.length;
  2011. let endIndex = 0;
  2012. let returnValue = '';
  2013. do {
  2014. returnValue += string.substr(endIndex, index - endIndex) + substring + replacer;
  2015. endIndex = index + substringLength;
  2016. index = string.indexOf(substring, endIndex);
  2017. } while (index !== -1);
  2018. returnValue += string.substr(endIndex);
  2019. return returnValue;
  2020. };
  2021. const stringEncaseCRLFWithFirstIndex$1 = (string, prefix, postfix, index) => {
  2022. let endIndex = 0;
  2023. let returnValue = '';
  2024. do {
  2025. const gotCR = string[index - 1] === '\r';
  2026. returnValue += string.substr(endIndex, (gotCR ? index - 1 : index) - endIndex) + prefix + (gotCR ? '\r\n' : '\n') + postfix;
  2027. endIndex = index + 1;
  2028. index = string.indexOf('\n', endIndex);
  2029. } while (index !== -1);
  2030. returnValue += string.substr(endIndex);
  2031. return returnValue;
  2032. };
  2033. var util = {
  2034. stringReplaceAll: stringReplaceAll$1,
  2035. stringEncaseCRLFWithFirstIndex: stringEncaseCRLFWithFirstIndex$1
  2036. };
  2037. const TEMPLATE_REGEX = /(?:\\(u(?:[a-f\d]{4}|\{[a-f\d]{1,6}\})|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  2038. const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  2039. const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  2040. const ESCAPE_REGEX = /\\(u(?:[a-f\d]{4}|{[a-f\d]{1,6}})|x[a-f\d]{2}|.)|([^\\])/gi;
  2041. const ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  2042. function unescape(c) {
  2043. const u = c[0] === 'u';
  2044. const bracket = c[1] === '{';
  2045. if (u && !bracket && c.length === 5 || c[0] === 'x' && c.length === 3) {
  2046. return String.fromCharCode(parseInt(c.slice(1), 16));
  2047. }
  2048. if (u && bracket) {
  2049. return String.fromCodePoint(parseInt(c.slice(2, -1), 16));
  2050. }
  2051. return ESCAPES.get(c) || c;
  2052. }
  2053. function parseArguments(name, arguments_) {
  2054. const results = [];
  2055. const chunks = arguments_.trim().split(/\s*,\s*/g);
  2056. let matches;
  2057. for (const chunk of chunks) {
  2058. const number = Number(chunk);
  2059. if (!Number.isNaN(number)) {
  2060. results.push(number);
  2061. } else if (matches = chunk.match(STRING_REGEX)) {
  2062. results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, character) => escape ? unescape(escape) : character));
  2063. } else {
  2064. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  2065. }
  2066. }
  2067. return results;
  2068. }
  2069. function parseStyle(style) {
  2070. STYLE_REGEX.lastIndex = 0;
  2071. const results = [];
  2072. let matches;
  2073. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  2074. const name = matches[1];
  2075. if (matches[2]) {
  2076. const args = parseArguments(name, matches[2]);
  2077. results.push([name].concat(args));
  2078. } else {
  2079. results.push([name]);
  2080. }
  2081. }
  2082. return results;
  2083. }
  2084. function buildStyle(chalk, styles) {
  2085. const enabled = {};
  2086. for (const layer of styles) {
  2087. for (const style of layer.styles) {
  2088. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  2089. }
  2090. }
  2091. let current = chalk;
  2092. for (const [styleName, styles] of Object.entries(enabled)) {
  2093. if (!Array.isArray(styles)) {
  2094. continue;
  2095. }
  2096. if (!(styleName in current)) {
  2097. throw new Error(`Unknown Chalk style: ${styleName}`);
  2098. }
  2099. current = styles.length > 0 ? current[styleName](...styles) : current[styleName];
  2100. }
  2101. return current;
  2102. }
  2103. var templates = (chalk, temporary) => {
  2104. const styles = [];
  2105. const chunks = [];
  2106. let chunk = []; // eslint-disable-next-line max-params
  2107. temporary.replace(TEMPLATE_REGEX, (m, escapeCharacter, inverse, style, close, character) => {
  2108. if (escapeCharacter) {
  2109. chunk.push(unescape(escapeCharacter));
  2110. } else if (style) {
  2111. const string = chunk.join('');
  2112. chunk = [];
  2113. chunks.push(styles.length === 0 ? string : buildStyle(chalk, styles)(string));
  2114. styles.push({
  2115. inverse,
  2116. styles: parseStyle(style)
  2117. });
  2118. } else if (close) {
  2119. if (styles.length === 0) {
  2120. throw new Error('Found extraneous } in Chalk template literal');
  2121. }
  2122. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  2123. chunk = [];
  2124. styles.pop();
  2125. } else {
  2126. chunk.push(character);
  2127. }
  2128. });
  2129. chunks.push(chunk.join(''));
  2130. if (styles.length > 0) {
  2131. const errMessage = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  2132. throw new Error(errMessage);
  2133. }
  2134. return chunks.join('');
  2135. };
  2136. const {
  2137. stdout: stdoutColor,
  2138. stderr: stderrColor
  2139. } = supportsColor_1;
  2140. const {
  2141. stringReplaceAll,
  2142. stringEncaseCRLFWithFirstIndex
  2143. } = util;
  2144. const {
  2145. isArray: isArray$2
  2146. } = Array; // `supportsColor.level` → `ansiStyles.color[name]` mapping
  2147. const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m'];
  2148. const styles = Object.create(null);
  2149. const applyOptions = (object, options = {}) => {
  2150. if (options.level && !(Number.isInteger(options.level) && options.level >= 0 && options.level <= 3)) {
  2151. throw new Error('The `level` option should be an integer from 0 to 3');
  2152. } // Detect level if not set manually
  2153. const colorLevel = stdoutColor ? stdoutColor.level : 0;
  2154. object.level = options.level === undefined ? colorLevel : options.level;
  2155. };
  2156. class ChalkClass {
  2157. constructor(options) {
  2158. // eslint-disable-next-line no-constructor-return
  2159. return chalkFactory(options);
  2160. }
  2161. }
  2162. const chalkFactory = options => {
  2163. const chalk = {};
  2164. applyOptions(chalk, options);
  2165. chalk.template = (...arguments_) => chalkTag(chalk.template, ...arguments_);
  2166. Object.setPrototypeOf(chalk, Chalk.prototype);
  2167. Object.setPrototypeOf(chalk.template, chalk);
  2168. chalk.template.constructor = () => {
  2169. throw new Error('`chalk.constructor()` is deprecated. Use `new chalk.Instance()` instead.');
  2170. };
  2171. chalk.template.Instance = ChalkClass;
  2172. return chalk.template;
  2173. };
  2174. function Chalk(options) {
  2175. return chalkFactory(options);
  2176. }
  2177. for (const [styleName, style] of Object.entries(ansiStyles)) {
  2178. styles[styleName] = {
  2179. get() {
  2180. const builder = createBuilder(this, createStyler(style.open, style.close, this._styler), this._isEmpty);
  2181. Object.defineProperty(this, styleName, {
  2182. value: builder
  2183. });
  2184. return builder;
  2185. }
  2186. };
  2187. }
  2188. styles.visible = {
  2189. get() {
  2190. const builder = createBuilder(this, this._styler, true);
  2191. Object.defineProperty(this, 'visible', {
  2192. value: builder
  2193. });
  2194. return builder;
  2195. }
  2196. };
  2197. const usedModels = ['rgb', 'hex', 'keyword', 'hsl', 'hsv', 'hwb', 'ansi', 'ansi256'];
  2198. for (const model of usedModels) {
  2199. styles[model] = {
  2200. get() {
  2201. const {
  2202. level
  2203. } = this;
  2204. return function (...arguments_) {
  2205. const styler = createStyler(ansiStyles.color[levelMapping[level]][model](...arguments_), ansiStyles.color.close, this._styler);
  2206. return createBuilder(this, styler, this._isEmpty);
  2207. };
  2208. }
  2209. };
  2210. }
  2211. for (const model of usedModels) {
  2212. const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  2213. styles[bgModel] = {
  2214. get() {
  2215. const {
  2216. level
  2217. } = this;
  2218. return function (...arguments_) {
  2219. const styler = createStyler(ansiStyles.bgColor[levelMapping[level]][model](...arguments_), ansiStyles.bgColor.close, this._styler);
  2220. return createBuilder(this, styler, this._isEmpty);
  2221. };
  2222. }
  2223. };
  2224. }
  2225. const proto = Object.defineProperties(() => {}, Object.assign(Object.assign({}, styles), {}, {
  2226. level: {
  2227. enumerable: true,
  2228. get() {
  2229. return this._generator.level;
  2230. },
  2231. set(level) {
  2232. this._generator.level = level;
  2233. }
  2234. }
  2235. }));
  2236. const createStyler = (open, close, parent) => {
  2237. let openAll;
  2238. let closeAll;
  2239. if (parent === undefined) {
  2240. openAll = open;
  2241. closeAll = close;
  2242. } else {
  2243. openAll = parent.openAll + open;
  2244. closeAll = close + parent.closeAll;
  2245. }
  2246. return {
  2247. open,
  2248. close,
  2249. openAll,
  2250. closeAll,
  2251. parent
  2252. };
  2253. };
  2254. const createBuilder = (self, _styler, _isEmpty) => {
  2255. const builder = (...arguments_) => {
  2256. if (isArray$2(arguments_[0]) && isArray$2(arguments_[0].raw)) {
  2257. // Called as a template literal, for example: chalk.red`2 + 3 = {bold ${2+3}}`
  2258. return applyStyle(builder, chalkTag(builder, ...arguments_));
  2259. } // Single argument is hot path, implicit coercion is faster than anything
  2260. // eslint-disable-next-line no-implicit-coercion
  2261. return applyStyle(builder, arguments_.length === 1 ? '' + arguments_[0] : arguments_.join(' '));
  2262. }; // We alter the prototype because we must return a function, but there is
  2263. // no way to create a function with a different prototype
  2264. Object.setPrototypeOf(builder, proto);
  2265. builder._generator = self;
  2266. builder._styler = _styler;
  2267. builder._isEmpty = _isEmpty;
  2268. return builder;
  2269. };
  2270. const applyStyle = (self, string) => {
  2271. if (self.level <= 0 || !string) {
  2272. return self._isEmpty ? '' : string;
  2273. }
  2274. let styler = self._styler;
  2275. if (styler === undefined) {
  2276. return string;
  2277. }
  2278. const {
  2279. openAll,
  2280. closeAll
  2281. } = styler;
  2282. if (string.indexOf('\u001B') !== -1) {
  2283. while (styler !== undefined) {
  2284. // Replace any instances already present with a re-opening code
  2285. // otherwise only the part of the string until said closing code
  2286. // will be colored, and the rest will simply be 'plain'.
  2287. string = stringReplaceAll(string, styler.close, styler.open);
  2288. styler = styler.parent;
  2289. }
  2290. } // We can move both next actions out of loop, because remaining actions in loop won't have
  2291. // any/visible effect on parts we add here. Close the styling before a linebreak and reopen
  2292. // after next line to fix a bleed issue on macOS: https://github.com/chalk/chalk/pull/92
  2293. const lfIndex = string.indexOf('\n');
  2294. if (lfIndex !== -1) {
  2295. string = stringEncaseCRLFWithFirstIndex(string, closeAll, openAll, lfIndex);
  2296. }
  2297. return openAll + string + closeAll;
  2298. };
  2299. let template;
  2300. const chalkTag = (chalk, ...strings) => {
  2301. const [firstString] = strings;
  2302. if (!isArray$2(firstString) || !isArray$2(firstString.raw)) {
  2303. // If chalk() was called by itself or with a string,
  2304. // return the string itself as a string.
  2305. return strings.join(' ');
  2306. }
  2307. const arguments_ = strings.slice(1);
  2308. const parts = [firstString.raw[0]];
  2309. for (let i = 1; i < firstString.length; i++) {
  2310. parts.push(String(arguments_[i - 1]).replace(/[{}\\]/g, '\\$&'), String(firstString.raw[i]));
  2311. }
  2312. if (template === undefined) {
  2313. template = templates;
  2314. }
  2315. return template(chalk, parts.join(''));
  2316. };
  2317. Object.defineProperties(Chalk.prototype, styles);
  2318. const chalk = Chalk(); // eslint-disable-line new-cap
  2319. chalk.supportsColor = stdoutColor;
  2320. chalk.stderr = Chalk({
  2321. level: stderrColor ? stderrColor.level : 0
  2322. }); // eslint-disable-line new-cap
  2323. chalk.stderr.supportsColor = stderrColor;
  2324. var source = chalk;
  2325. var require$$1 = require("./third-party.js");
  2326. var prettierInternal = prettier$1.__internal;
  2327. // `IsArray` abstract operation
  2328. // https://tc39.es/ecma262/#sec-isarray
  2329. // eslint-disable-next-line es/no-array-isarray -- safe
  2330. var isArray$1 = Array.isArray || function isArray(arg) {
  2331. return classofRaw(arg) == 'Array';
  2332. };
  2333. // optional / simple context binding
  2334. var functionBindContext = function (fn, that, length) {
  2335. aFunction(fn);
  2336. if (that === undefined) return fn;
  2337. switch (length) {
  2338. case 0: return function () {
  2339. return fn.call(that);
  2340. };
  2341. case 1: return function (a) {
  2342. return fn.call(that, a);
  2343. };
  2344. case 2: return function (a, b) {
  2345. return fn.call(that, a, b);
  2346. };
  2347. case 3: return function (a, b, c) {
  2348. return fn.call(that, a, b, c);
  2349. };
  2350. }
  2351. return function (/* ...args */) {
  2352. return fn.apply(that, arguments);
  2353. };
  2354. };
  2355. // `FlattenIntoArray` abstract operation
  2356. // https://tc39.github.io/proposal-flatMap/#sec-FlattenIntoArray
  2357. var flattenIntoArray = function (target, original, source, sourceLen, start, depth, mapper, thisArg) {
  2358. var targetIndex = start;
  2359. var sourceIndex = 0;
  2360. var mapFn = mapper ? functionBindContext(mapper, thisArg, 3) : false;
  2361. var element;
  2362. while (sourceIndex < sourceLen) {
  2363. if (sourceIndex in source) {
  2364. element = mapFn ? mapFn(source[sourceIndex], sourceIndex, original) : source[sourceIndex];
  2365. if (depth > 0 && isArray$1(element)) {
  2366. targetIndex = flattenIntoArray(target, original, element, toLength(element.length), targetIndex, depth - 1) - 1;
  2367. } else {
  2368. if (targetIndex >= 0x1FFFFFFFFFFFFF) throw TypeError('Exceed the acceptable array length');
  2369. target[targetIndex] = element;
  2370. }
  2371. targetIndex++;
  2372. }
  2373. sourceIndex++;
  2374. }
  2375. return targetIndex;
  2376. };
  2377. var flattenIntoArray_1 = flattenIntoArray;
  2378. var SPECIES = wellKnownSymbol('species');
  2379. // a part of `ArraySpeciesCreate` abstract operation
  2380. // https://tc39.es/ecma262/#sec-arrayspeciescreate
  2381. var arraySpeciesConstructor = function (originalArray) {
  2382. var C;
  2383. if (isArray$1(originalArray)) {
  2384. C = originalArray.constructor;
  2385. // cross-realm fallback
  2386. if (typeof C == 'function' && (C === Array || isArray$1(C.prototype))) C = undefined;
  2387. else if (isObject$3(C)) {
  2388. C = C[SPECIES];
  2389. if (C === null) C = undefined;
  2390. }
  2391. } return C === undefined ? Array : C;
  2392. };
  2393. // `ArraySpeciesCreate` abstract operation
  2394. // https://tc39.es/ecma262/#sec-arrayspeciescreate
  2395. var arraySpeciesCreate = function (originalArray, length) {
  2396. return new (arraySpeciesConstructor(originalArray))(length === 0 ? 0 : length);
  2397. };
  2398. // `Array.prototype.flatMap` method
  2399. // https://tc39.es/ecma262/#sec-array.prototype.flatmap
  2400. _export({ target: 'Array', proto: true }, {
  2401. flatMap: function flatMap(callbackfn /* , thisArg */) {
  2402. var O = toObject(this);
  2403. var sourceLen = toLength(O.length);
  2404. var A;
  2405. aFunction(callbackfn);
  2406. A = arraySpeciesCreate(O, 0);
  2407. A.length = flattenIntoArray_1(A, O, O, sourceLen, 0, 1, callbackfn, arguments.length > 1 ? arguments[1] : undefined);
  2408. return A;
  2409. }
  2410. });
  2411. var array$2 = createCommonjsModule(function (module, exports) {
  2412. Object.defineProperty(exports, "__esModule", {
  2413. value: true
  2414. });
  2415. exports.splitWhen = exports.flatten = void 0;
  2416. function flatten(items) {
  2417. return items.reduce((collection, item) => [].concat(collection, item), []);
  2418. }
  2419. exports.flatten = flatten;
  2420. function splitWhen(items, predicate) {
  2421. const result = [[]];
  2422. let groupIndex = 0;
  2423. for (const item of items) {
  2424. if (predicate(item)) {
  2425. groupIndex++;
  2426. result[groupIndex] = [];
  2427. } else {
  2428. result[groupIndex].push(item);
  2429. }
  2430. }
  2431. return result;
  2432. }
  2433. exports.splitWhen = splitWhen;
  2434. });
  2435. var errno = createCommonjsModule(function (module, exports) {
  2436. Object.defineProperty(exports, "__esModule", {
  2437. value: true
  2438. });
  2439. exports.isEnoentCodeError = void 0;
  2440. function isEnoentCodeError(error) {
  2441. return error.code === 'ENOENT';
  2442. }
  2443. exports.isEnoentCodeError = isEnoentCodeError;
  2444. });
  2445. var fs$3 = createCommonjsModule(function (module, exports) {
  2446. Object.defineProperty(exports, "__esModule", {
  2447. value: true
  2448. });
  2449. exports.createDirentFromStats = void 0;
  2450. class DirentFromStats {
  2451. constructor(name, stats) {
  2452. this.name = name;
  2453. this.isBlockDevice = stats.isBlockDevice.bind(stats);
  2454. this.isCharacterDevice = stats.isCharacterDevice.bind(stats);
  2455. this.isDirectory = stats.isDirectory.bind(stats);
  2456. this.isFIFO = stats.isFIFO.bind(stats);
  2457. this.isFile = stats.isFile.bind(stats);
  2458. this.isSocket = stats.isSocket.bind(stats);
  2459. this.isSymbolicLink = stats.isSymbolicLink.bind(stats);
  2460. }
  2461. }
  2462. function createDirentFromStats(name, stats) {
  2463. return new DirentFromStats(name, stats);
  2464. }
  2465. exports.createDirentFromStats = createDirentFromStats;
  2466. });
  2467. var path_1 = createCommonjsModule(function (module, exports) {
  2468. Object.defineProperty(exports, "__esModule", {
  2469. value: true
  2470. });
  2471. exports.removeLeadingDotSegment = exports.escape = exports.makeAbsolute = exports.unixify = void 0;
  2472. const LEADING_DOT_SEGMENT_CHARACTERS_COUNT = 2; // ./ or .\\
  2473. const UNESCAPED_GLOB_SYMBOLS_RE = /(\\?)([()*?[\]{|}]|^!|[!+@](?=\())/g;
  2474. /**
  2475. * Designed to work only with simple paths: `dir\\file`.
  2476. */
  2477. function unixify(filepath) {
  2478. return filepath.replace(/\\/g, '/');
  2479. }
  2480. exports.unixify = unixify;
  2481. function makeAbsolute(cwd, filepath) {
  2482. return path__default['default'].resolve(cwd, filepath);
  2483. }
  2484. exports.makeAbsolute = makeAbsolute;
  2485. function escape(pattern) {
  2486. return pattern.replace(UNESCAPED_GLOB_SYMBOLS_RE, '\\$2');
  2487. }
  2488. exports.escape = escape;
  2489. function removeLeadingDotSegment(entry) {
  2490. // We do not use `startsWith` because this is 10x slower than current implementation for some cases.
  2491. // eslint-disable-next-line @typescript-eslint/prefer-string-starts-ends-with
  2492. if (entry.charAt(0) === '.') {
  2493. const secondCharactery = entry.charAt(1);
  2494. if (secondCharactery === '/' || secondCharactery === '\\') {
  2495. return entry.slice(LEADING_DOT_SEGMENT_CHARACTERS_COUNT);
  2496. }
  2497. }
  2498. return entry;
  2499. }
  2500. exports.removeLeadingDotSegment = removeLeadingDotSegment;
  2501. });
  2502. /*!
  2503. * is-extglob <https://github.com/jonschlinkert/is-extglob>
  2504. *
  2505. * Copyright (c) 2014-2016, Jon Schlinkert.
  2506. * Licensed under the MIT License.
  2507. */
  2508. var isExtglob = function isExtglob(str) {
  2509. if (typeof str !== 'string' || str === '') {
  2510. return false;
  2511. }
  2512. var match;
  2513. while (match = /(\\).|([@?!+*]\(.*\))/g.exec(str)) {
  2514. if (match[2]) return true;
  2515. str = str.slice(match.index + match[0].length);
  2516. }
  2517. return false;
  2518. };
  2519. /*!
  2520. * is-glob <https://github.com/jonschlinkert/is-glob>
  2521. *
  2522. * Copyright (c) 2014-2017, Jon Schlinkert.
  2523. * Released under the MIT License.
  2524. */
  2525. var chars = {
  2526. '{': '}',
  2527. '(': ')',
  2528. '[': ']'
  2529. };
  2530. var strictRegex = /\\(.)|(^!|\*|[\].+)]\?|\[[^\\\]]+\]|\{[^\\}]+\}|\(\?[:!=][^\\)]+\)|\([^|]+\|[^\\)]+\))/;
  2531. var relaxedRegex = /\\(.)|(^!|[*?{}()[\]]|\(\?)/;
  2532. var isGlob = function isGlob(str, options) {
  2533. if (typeof str !== 'string' || str === '') {
  2534. return false;
  2535. }
  2536. if (isExtglob(str)) {
  2537. return true;
  2538. }
  2539. var regex = strictRegex;
  2540. var match; // optionally relax regex
  2541. if (options && options.strict === false) {
  2542. regex = relaxedRegex;
  2543. }
  2544. while (match = regex.exec(str)) {
  2545. if (match[2]) return true;
  2546. var idx = match.index + match[0].length; // if an open bracket/brace/paren is escaped,
  2547. // set the index to the next closing character
  2548. var open = match[1];
  2549. var close = open ? chars[open] : null;
  2550. if (open && close) {
  2551. var n = str.indexOf(close, idx);
  2552. if (n !== -1) {
  2553. idx = n + 1;
  2554. }
  2555. }
  2556. str = str.slice(idx);
  2557. }
  2558. return false;
  2559. };
  2560. var pathPosixDirname = path__default['default'].posix.dirname;
  2561. var isWin32 = os__default['default'].platform() === 'win32';
  2562. var slash = '/';
  2563. var backslash = /\\/g;
  2564. var enclosure = /[\{\[].*[\}\]]$/;
  2565. var globby = /(^|[^\\])([\{\[]|\([^\)]+$)/;
  2566. var escaped = /\\([\!\*\?\|\[\]\(\)\{\}])/g;
  2567. /**
  2568. * @param {string} str
  2569. * @param {Object} opts
  2570. * @param {boolean} [opts.flipBackslashes=true]
  2571. * @returns {string}
  2572. */
  2573. var globParent = function globParent(str, opts) {
  2574. var options = Object.assign({
  2575. flipBackslashes: true
  2576. }, opts); // flip windows path separators
  2577. if (options.flipBackslashes && isWin32 && str.indexOf(slash) < 0) {
  2578. str = str.replace(backslash, slash);
  2579. } // special case for strings ending in enclosure containing path separator
  2580. if (enclosure.test(str)) {
  2581. str += slash;
  2582. } // preserves full path in case of trailing path separator
  2583. str += 'a'; // remove path parts that are globby
  2584. do {
  2585. str = pathPosixDirname(str);
  2586. } while (isGlob(str) || globby.test(str)); // remove escape chars and return result
  2587. return str.replace(escaped, '$1');
  2588. };
  2589. var utils$3 = createCommonjsModule(function (module, exports) {
  2590. exports.isInteger = num => {
  2591. if (typeof num === 'number') {
  2592. return Number.isInteger(num);
  2593. }
  2594. if (typeof num === 'string' && num.trim() !== '') {
  2595. return Number.isInteger(Number(num));
  2596. }
  2597. return false;
  2598. };
  2599. /**
  2600. * Find a node of the given type
  2601. */
  2602. exports.find = (node, type) => node.nodes.find(node => node.type === type);
  2603. /**
  2604. * Find a node of the given type
  2605. */
  2606. exports.exceedsLimit = (min, max, step = 1, limit) => {
  2607. if (limit === false) return false;
  2608. if (!exports.isInteger(min) || !exports.isInteger(max)) return false;
  2609. return (Number(max) - Number(min)) / Number(step) >= limit;
  2610. };
  2611. /**
  2612. * Escape the given node with '\\' before node.value
  2613. */
  2614. exports.escapeNode = (block, n = 0, type) => {
  2615. let node = block.nodes[n];
  2616. if (!node) return;
  2617. if (type && node.type === type || node.type === 'open' || node.type === 'close') {
  2618. if (node.escaped !== true) {
  2619. node.value = '\\' + node.value;
  2620. node.escaped = true;
  2621. }
  2622. }
  2623. };
  2624. /**
  2625. * Returns true if the given brace node should be enclosed in literal braces
  2626. */
  2627. exports.encloseBrace = node => {
  2628. if (node.type !== 'brace') return false;
  2629. if (node.commas >> 0 + node.ranges >> 0 === 0) {
  2630. node.invalid = true;
  2631. return true;
  2632. }
  2633. return false;
  2634. };
  2635. /**
  2636. * Returns true if a brace node is invalid.
  2637. */
  2638. exports.isInvalidBrace = block => {
  2639. if (block.type !== 'brace') return false;
  2640. if (block.invalid === true || block.dollar) return true;
  2641. if (block.commas >> 0 + block.ranges >> 0 === 0) {
  2642. block.invalid = true;
  2643. return true;
  2644. }
  2645. if (block.open !== true || block.close !== true) {
  2646. block.invalid = true;
  2647. return true;
  2648. }
  2649. return false;
  2650. };
  2651. /**
  2652. * Returns true if a node is an open or close node
  2653. */
  2654. exports.isOpenOrClose = node => {
  2655. if (node.type === 'open' || node.type === 'close') {
  2656. return true;
  2657. }
  2658. return node.open === true || node.close === true;
  2659. };
  2660. /**
  2661. * Reduce an array of text nodes.
  2662. */
  2663. exports.reduce = nodes => nodes.reduce((acc, node) => {
  2664. if (node.type === 'text') acc.push(node.value);
  2665. if (node.type === 'range') node.type = 'text';
  2666. return acc;
  2667. }, []);
  2668. /**
  2669. * Flatten an array
  2670. */
  2671. exports.flatten = (...args) => {
  2672. const result = [];
  2673. const flat = arr => {
  2674. for (let i = 0; i < arr.length; i++) {
  2675. let ele = arr[i];
  2676. Array.isArray(ele) ? flat(ele) : ele !== void 0 && result.push(ele);
  2677. }
  2678. return result;
  2679. };
  2680. flat(args);
  2681. return result;
  2682. };
  2683. });
  2684. var stringify$1 = (ast, options = {}) => {
  2685. let stringify = (node, parent = {}) => {
  2686. let invalidBlock = options.escapeInvalid && utils$3.isInvalidBrace(parent);
  2687. let invalidNode = node.invalid === true && options.escapeInvalid === true;
  2688. let output = '';
  2689. if (node.value) {
  2690. if ((invalidBlock || invalidNode) && utils$3.isOpenOrClose(node)) {
  2691. return '\\' + node.value;
  2692. }
  2693. return node.value;
  2694. }
  2695. if (node.value) {
  2696. return node.value;
  2697. }
  2698. if (node.nodes) {
  2699. for (let child of node.nodes) {
  2700. output += stringify(child);
  2701. }
  2702. }
  2703. return output;
  2704. };
  2705. return stringify(ast);
  2706. };
  2707. /*!
  2708. * is-number <https://github.com/jonschlinkert/is-number>
  2709. *
  2710. * Copyright (c) 2014-present, Jon Schlinkert.
  2711. * Released under the MIT License.
  2712. */
  2713. var isNumber$2 = function (num) {
  2714. if (typeof num === 'number') {
  2715. return num - num === 0;
  2716. }
  2717. if (typeof num === 'string' && num.trim() !== '') {
  2718. return Number.isFinite ? Number.isFinite(+num) : isFinite(+num);
  2719. }
  2720. return false;
  2721. };
  2722. const toRegexRange = (min, max, options) => {
  2723. if (isNumber$2(min) === false) {
  2724. throw new TypeError('toRegexRange: expected the first argument to be a number');
  2725. }
  2726. if (max === void 0 || min === max) {
  2727. return String(min);
  2728. }
  2729. if (isNumber$2(max) === false) {
  2730. throw new TypeError('toRegexRange: expected the second argument to be a number.');
  2731. }
  2732. let opts = Object.assign({
  2733. relaxZeros: true
  2734. }, options);
  2735. if (typeof opts.strictZeros === 'boolean') {
  2736. opts.relaxZeros = opts.strictZeros === false;
  2737. }
  2738. let relax = String(opts.relaxZeros);
  2739. let shorthand = String(opts.shorthand);
  2740. let capture = String(opts.capture);
  2741. let wrap = String(opts.wrap);
  2742. let cacheKey = min + ':' + max + '=' + relax + shorthand + capture + wrap;
  2743. if (toRegexRange.cache.hasOwnProperty(cacheKey)) {
  2744. return toRegexRange.cache[cacheKey].result;
  2745. }
  2746. let a = Math.min(min, max);
  2747. let b = Math.max(min, max);
  2748. if (Math.abs(a - b) === 1) {
  2749. let result = min + '|' + max;
  2750. if (opts.capture) {
  2751. return `(${result})`;
  2752. }
  2753. if (opts.wrap === false) {
  2754. return result;
  2755. }
  2756. return `(?:${result})`;
  2757. }
  2758. let isPadded = hasPadding(min) || hasPadding(max);
  2759. let state = {
  2760. min,
  2761. max,
  2762. a,
  2763. b
  2764. };
  2765. let positives = [];
  2766. let negatives = [];
  2767. if (isPadded) {
  2768. state.isPadded = isPadded;
  2769. state.maxLen = String(state.max).length;
  2770. }
  2771. if (a < 0) {
  2772. let newMin = b < 0 ? Math.abs(b) : 1;
  2773. negatives = splitToPatterns(newMin, Math.abs(a), state, opts);
  2774. a = state.a = 0;
  2775. }
  2776. if (b >= 0) {
  2777. positives = splitToPatterns(a, b, state, opts);
  2778. }
  2779. state.negatives = negatives;
  2780. state.positives = positives;
  2781. state.result = collatePatterns(negatives, positives);
  2782. if (opts.capture === true) {
  2783. state.result = `(${state.result})`;
  2784. } else if (opts.wrap !== false && positives.length + negatives.length > 1) {
  2785. state.result = `(?:${state.result})`;
  2786. }
  2787. toRegexRange.cache[cacheKey] = state;
  2788. return state.result;
  2789. };
  2790. function collatePatterns(neg, pos, options) {
  2791. let onlyNegative = filterPatterns(neg, pos, '-', false) || [];
  2792. let onlyPositive = filterPatterns(pos, neg, '', false) || [];
  2793. let intersected = filterPatterns(neg, pos, '-?', true) || [];
  2794. let subpatterns = onlyNegative.concat(intersected).concat(onlyPositive);
  2795. return subpatterns.join('|');
  2796. }
  2797. function splitToRanges(min, max) {
  2798. let nines = 1;
  2799. let zeros = 1;
  2800. let stop = countNines(min, nines);
  2801. let stops = new Set([max]);
  2802. while (min <= stop && stop <= max) {
  2803. stops.add(stop);
  2804. nines += 1;
  2805. stop = countNines(min, nines);
  2806. }
  2807. stop = countZeros(max + 1, zeros) - 1;
  2808. while (min < stop && stop <= max) {
  2809. stops.add(stop);
  2810. zeros += 1;
  2811. stop = countZeros(max + 1, zeros) - 1;
  2812. }
  2813. stops = [...stops];
  2814. stops.sort(compare);
  2815. return stops;
  2816. }
  2817. /**
  2818. * Convert a range to a regex pattern
  2819. * @param {Number} `start`
  2820. * @param {Number} `stop`
  2821. * @return {String}
  2822. */
  2823. function rangeToPattern(start, stop, options) {
  2824. if (start === stop) {
  2825. return {
  2826. pattern: start,
  2827. count: [],
  2828. digits: 0
  2829. };
  2830. }
  2831. let zipped = zip(start, stop);
  2832. let digits = zipped.length;
  2833. let pattern = '';
  2834. let count = 0;
  2835. for (let i = 0; i < digits; i++) {
  2836. let [startDigit, stopDigit] = zipped[i];
  2837. if (startDigit === stopDigit) {
  2838. pattern += startDigit;
  2839. } else if (startDigit !== '0' || stopDigit !== '9') {
  2840. pattern += toCharacterClass(startDigit, stopDigit);
  2841. } else {
  2842. count++;
  2843. }
  2844. }
  2845. if (count) {
  2846. pattern += options.shorthand === true ? '\\d' : '[0-9]';
  2847. }
  2848. return {
  2849. pattern,
  2850. count: [count],
  2851. digits
  2852. };
  2853. }
  2854. function splitToPatterns(min, max, tok, options) {
  2855. let ranges = splitToRanges(min, max);
  2856. let tokens = [];
  2857. let start = min;
  2858. let prev;
  2859. for (let i = 0; i < ranges.length; i++) {
  2860. let max = ranges[i];
  2861. let obj = rangeToPattern(String(start), String(max), options);
  2862. let zeros = '';
  2863. if (!tok.isPadded && prev && prev.pattern === obj.pattern) {
  2864. if (prev.count.length > 1) {
  2865. prev.count.pop();
  2866. }
  2867. prev.count.push(obj.count[0]);
  2868. prev.string = prev.pattern + toQuantifier(prev.count);
  2869. start = max + 1;
  2870. continue;
  2871. }
  2872. if (tok.isPadded) {
  2873. zeros = padZeros(max, tok, options);
  2874. }
  2875. obj.string = zeros + obj.pattern + toQuantifier(obj.count);
  2876. tokens.push(obj);
  2877. start = max + 1;
  2878. prev = obj;
  2879. }
  2880. return tokens;
  2881. }
  2882. function filterPatterns(arr, comparison, prefix, intersection, options) {
  2883. let result = [];
  2884. for (let ele of arr) {
  2885. let {
  2886. string
  2887. } = ele; // only push if _both_ are negative...
  2888. if (!intersection && !contains(comparison, 'string', string)) {
  2889. result.push(prefix + string);
  2890. } // or _both_ are positive
  2891. if (intersection && contains(comparison, 'string', string)) {
  2892. result.push(prefix + string);
  2893. }
  2894. }
  2895. return result;
  2896. }
  2897. /**
  2898. * Zip strings
  2899. */
  2900. function zip(a, b) {
  2901. let arr = [];
  2902. for (let i = 0; i < a.length; i++) arr.push([a[i], b[i]]);
  2903. return arr;
  2904. }
  2905. function compare(a, b) {
  2906. return a > b ? 1 : b > a ? -1 : 0;
  2907. }
  2908. function contains(arr, key, val) {
  2909. return arr.some(ele => ele[key] === val);
  2910. }
  2911. function countNines(min, len) {
  2912. return Number(String(min).slice(0, -len) + '9'.repeat(len));
  2913. }
  2914. function countZeros(integer, zeros) {
  2915. return integer - integer % Math.pow(10, zeros);
  2916. }
  2917. function toQuantifier(digits) {
  2918. let [start = 0, stop = ''] = digits;
  2919. if (stop || start > 1) {
  2920. return `{${start + (stop ? ',' + stop : '')}}`;
  2921. }
  2922. return '';
  2923. }
  2924. function toCharacterClass(a, b, options) {
  2925. return `[${a}${b - a === 1 ? '' : '-'}${b}]`;
  2926. }
  2927. function hasPadding(str) {
  2928. return /^-?(0+)\d/.test(str);
  2929. }
  2930. function padZeros(value, tok, options) {
  2931. if (!tok.isPadded) {
  2932. return value;
  2933. }
  2934. let diff = Math.abs(tok.maxLen - String(value).length);
  2935. let relax = options.relaxZeros !== false;
  2936. switch (diff) {
  2937. case 0:
  2938. return '';
  2939. case 1:
  2940. return relax ? '0?' : '0';
  2941. case 2:
  2942. return relax ? '0{0,2}' : '00';
  2943. default:
  2944. {
  2945. return relax ? `0{0,${diff}}` : `0{${diff}}`;
  2946. }
  2947. }
  2948. }
  2949. /**
  2950. * Cache
  2951. */
  2952. toRegexRange.cache = {};
  2953. toRegexRange.clearCache = () => toRegexRange.cache = {};
  2954. /**
  2955. * Expose `toRegexRange`
  2956. */
  2957. var toRegexRange_1 = toRegexRange;
  2958. const isObject$2 = val => val !== null && typeof val === 'object' && !Array.isArray(val);
  2959. const transform = toNumber => {
  2960. return value => toNumber === true ? Number(value) : String(value);
  2961. };
  2962. const isValidValue = value => {
  2963. return typeof value === 'number' || typeof value === 'string' && value !== '';
  2964. };
  2965. const isNumber$1 = num => Number.isInteger(+num);
  2966. const zeros = input => {
  2967. let value = `${input}`;
  2968. let index = -1;
  2969. if (value[0] === '-') value = value.slice(1);
  2970. if (value === '0') return false;
  2971. while (value[++index] === '0');
  2972. return index > 0;
  2973. };
  2974. const stringify = (start, end, options) => {
  2975. if (typeof start === 'string' || typeof end === 'string') {
  2976. return true;
  2977. }
  2978. return options.stringify === true;
  2979. };
  2980. const pad = (input, maxLength, toNumber) => {
  2981. if (maxLength > 0) {
  2982. let dash = input[0] === '-' ? '-' : '';
  2983. if (dash) input = input.slice(1);
  2984. input = dash + input.padStart(dash ? maxLength - 1 : maxLength, '0');
  2985. }
  2986. if (toNumber === false) {
  2987. return String(input);
  2988. }
  2989. return input;
  2990. };
  2991. const toMaxLen = (input, maxLength) => {
  2992. let negative = input[0] === '-' ? '-' : '';
  2993. if (negative) {
  2994. input = input.slice(1);
  2995. maxLength--;
  2996. }
  2997. while (input.length < maxLength) input = '0' + input;
  2998. return negative ? '-' + input : input;
  2999. };
  3000. const toSequence = (parts, options) => {
  3001. parts.negatives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
  3002. parts.positives.sort((a, b) => a < b ? -1 : a > b ? 1 : 0);
  3003. let prefix = options.capture ? '' : '?:';
  3004. let positives = '';
  3005. let negatives = '';
  3006. let result;
  3007. if (parts.positives.length) {
  3008. positives = parts.positives.join('|');
  3009. }
  3010. if (parts.negatives.length) {
  3011. negatives = `-(${prefix}${parts.negatives.join('|')})`;
  3012. }
  3013. if (positives && negatives) {
  3014. result = `${positives}|${negatives}`;
  3015. } else {
  3016. result = positives || negatives;
  3017. }
  3018. if (options.wrap) {
  3019. return `(${prefix}${result})`;
  3020. }
  3021. return result;
  3022. };
  3023. const toRange = (a, b, isNumbers, options) => {
  3024. if (isNumbers) {
  3025. return toRegexRange_1(a, b, Object.assign({
  3026. wrap: false
  3027. }, options));
  3028. }
  3029. let start = String.fromCharCode(a);
  3030. if (a === b) return start;
  3031. let stop = String.fromCharCode(b);
  3032. return `[${start}-${stop}]`;
  3033. };
  3034. const toRegex = (start, end, options) => {
  3035. if (Array.isArray(start)) {
  3036. let wrap = options.wrap === true;
  3037. let prefix = options.capture ? '' : '?:';
  3038. return wrap ? `(${prefix}${start.join('|')})` : start.join('|');
  3039. }
  3040. return toRegexRange_1(start, end, options);
  3041. };
  3042. const rangeError = (...args) => {
  3043. return new RangeError('Invalid range arguments: ' + util__default['default'].inspect(...args));
  3044. };
  3045. const invalidRange = (start, end, options) => {
  3046. if (options.strictRanges === true) throw rangeError([start, end]);
  3047. return [];
  3048. };
  3049. const invalidStep = (step, options) => {
  3050. if (options.strictRanges === true) {
  3051. throw new TypeError(`Expected step "${step}" to be a number`);
  3052. }
  3053. return [];
  3054. };
  3055. const fillNumbers = (start, end, step = 1, options = {}) => {
  3056. let a = Number(start);
  3057. let b = Number(end);
  3058. if (!Number.isInteger(a) || !Number.isInteger(b)) {
  3059. if (options.strictRanges === true) throw rangeError([start, end]);
  3060. return [];
  3061. } // fix negative zero
  3062. if (a === 0) a = 0;
  3063. if (b === 0) b = 0;
  3064. let descending = a > b;
  3065. let startString = String(start);
  3066. let endString = String(end);
  3067. let stepString = String(step);
  3068. step = Math.max(Math.abs(step), 1);
  3069. let padded = zeros(startString) || zeros(endString) || zeros(stepString);
  3070. let maxLen = padded ? Math.max(startString.length, endString.length, stepString.length) : 0;
  3071. let toNumber = padded === false && stringify(start, end, options) === false;
  3072. let format = options.transform || transform(toNumber);
  3073. if (options.toRegex && step === 1) {
  3074. return toRange(toMaxLen(start, maxLen), toMaxLen(end, maxLen), true, options);
  3075. }
  3076. let parts = {
  3077. negatives: [],
  3078. positives: []
  3079. };
  3080. let push = num => parts[num < 0 ? 'negatives' : 'positives'].push(Math.abs(num));
  3081. let range = [];
  3082. let index = 0;
  3083. while (descending ? a >= b : a <= b) {
  3084. if (options.toRegex === true && step > 1) {
  3085. push(a);
  3086. } else {
  3087. range.push(pad(format(a, index), maxLen, toNumber));
  3088. }
  3089. a = descending ? a - step : a + step;
  3090. index++;
  3091. }
  3092. if (options.toRegex === true) {
  3093. return step > 1 ? toSequence(parts, options) : toRegex(range, null, Object.assign({
  3094. wrap: false
  3095. }, options));
  3096. }
  3097. return range;
  3098. };
  3099. const fillLetters = (start, end, step = 1, options = {}) => {
  3100. if (!isNumber$1(start) && start.length > 1 || !isNumber$1(end) && end.length > 1) {
  3101. return invalidRange(start, end, options);
  3102. }
  3103. let format = options.transform || (val => String.fromCharCode(val));
  3104. let a = `${start}`.charCodeAt(0);
  3105. let b = `${end}`.charCodeAt(0);
  3106. let descending = a > b;
  3107. let min = Math.min(a, b);
  3108. let max = Math.max(a, b);
  3109. if (options.toRegex && step === 1) {
  3110. return toRange(min, max, false, options);
  3111. }
  3112. let range = [];
  3113. let index = 0;
  3114. while (descending ? a >= b : a <= b) {
  3115. range.push(format(a, index));
  3116. a = descending ? a - step : a + step;
  3117. index++;
  3118. }
  3119. if (options.toRegex === true) {
  3120. return toRegex(range, null, {
  3121. wrap: false,
  3122. options
  3123. });
  3124. }
  3125. return range;
  3126. };
  3127. const fill = (start, end, step, options = {}) => {
  3128. if (end == null && isValidValue(start)) {
  3129. return [start];
  3130. }
  3131. if (!isValidValue(start) || !isValidValue(end)) {
  3132. return invalidRange(start, end, options);
  3133. }
  3134. if (typeof step === 'function') {
  3135. return fill(start, end, 1, {
  3136. transform: step
  3137. });
  3138. }
  3139. if (isObject$2(step)) {
  3140. return fill(start, end, 0, step);
  3141. }
  3142. let opts = Object.assign({}, options);
  3143. if (opts.capture === true) opts.wrap = true;
  3144. step = step || opts.step || 1;
  3145. if (!isNumber$1(step)) {
  3146. if (step != null && !isObject$2(step)) return invalidStep(step, opts);
  3147. return fill(start, end, 1, step);
  3148. }
  3149. if (isNumber$1(start) && isNumber$1(end)) {
  3150. return fillNumbers(start, end, step, opts);
  3151. }
  3152. return fillLetters(start, end, Math.max(Math.abs(step), 1), opts);
  3153. };
  3154. var fillRange = fill;
  3155. const compile = (ast, options = {}) => {
  3156. let walk = (node, parent = {}) => {
  3157. let invalidBlock = utils$3.isInvalidBrace(parent);
  3158. let invalidNode = node.invalid === true && options.escapeInvalid === true;
  3159. let invalid = invalidBlock === true || invalidNode === true;
  3160. let prefix = options.escapeInvalid === true ? '\\' : '';
  3161. let output = '';
  3162. if (node.isOpen === true) {
  3163. return prefix + node.value;
  3164. }
  3165. if (node.isClose === true) {
  3166. return prefix + node.value;
  3167. }
  3168. if (node.type === 'open') {
  3169. return invalid ? prefix + node.value : '(';
  3170. }
  3171. if (node.type === 'close') {
  3172. return invalid ? prefix + node.value : ')';
  3173. }
  3174. if (node.type === 'comma') {
  3175. return node.prev.type === 'comma' ? '' : invalid ? node.value : '|';
  3176. }
  3177. if (node.value) {
  3178. return node.value;
  3179. }
  3180. if (node.nodes && node.ranges > 0) {
  3181. let args = utils$3.reduce(node.nodes);
  3182. let range = fillRange(...args, Object.assign(Object.assign({}, options), {}, {
  3183. wrap: false,
  3184. toRegex: true
  3185. }));
  3186. if (range.length !== 0) {
  3187. return args.length > 1 && range.length > 1 ? `(${range})` : range;
  3188. }
  3189. }
  3190. if (node.nodes) {
  3191. for (let child of node.nodes) {
  3192. output += walk(child, node);
  3193. }
  3194. }
  3195. return output;
  3196. };
  3197. return walk(ast);
  3198. };
  3199. var compile_1 = compile;
  3200. const append = (queue = '', stash = '', enclose = false) => {
  3201. let result = [];
  3202. queue = [].concat(queue);
  3203. stash = [].concat(stash);
  3204. if (!stash.length) return queue;
  3205. if (!queue.length) {
  3206. return enclose ? utils$3.flatten(stash).map(ele => `{${ele}}`) : stash;
  3207. }
  3208. for (let item of queue) {
  3209. if (Array.isArray(item)) {
  3210. for (let value of item) {
  3211. result.push(append(value, stash, enclose));
  3212. }
  3213. } else {
  3214. for (let ele of stash) {
  3215. if (enclose === true && typeof ele === 'string') ele = `{${ele}}`;
  3216. result.push(Array.isArray(ele) ? append(item, ele, enclose) : item + ele);
  3217. }
  3218. }
  3219. }
  3220. return utils$3.flatten(result);
  3221. };
  3222. const expand = (ast, options = {}) => {
  3223. let rangeLimit = options.rangeLimit === void 0 ? 1000 : options.rangeLimit;
  3224. let walk = (node, parent = {}) => {
  3225. node.queue = [];
  3226. let p = parent;
  3227. let q = parent.queue;
  3228. while (p.type !== 'brace' && p.type !== 'root' && p.parent) {
  3229. p = p.parent;
  3230. q = p.queue;
  3231. }
  3232. if (node.invalid || node.dollar) {
  3233. q.push(append(q.pop(), stringify$1(node, options)));
  3234. return;
  3235. }
  3236. if (node.type === 'brace' && node.invalid !== true && node.nodes.length === 2) {
  3237. q.push(append(q.pop(), ['{}']));
  3238. return;
  3239. }
  3240. if (node.nodes && node.ranges > 0) {
  3241. let args = utils$3.reduce(node.nodes);
  3242. if (utils$3.exceedsLimit(...args, options.step, rangeLimit)) {
  3243. throw new RangeError('expanded array length exceeds range limit. Use options.rangeLimit to increase or disable the limit.');
  3244. }
  3245. let range = fillRange(...args, options);
  3246. if (range.length === 0) {
  3247. range = stringify$1(node, options);
  3248. }
  3249. q.push(append(q.pop(), range));
  3250. node.nodes = [];
  3251. return;
  3252. }
  3253. let enclose = utils$3.encloseBrace(node);
  3254. let queue = node.queue;
  3255. let block = node;
  3256. while (block.type !== 'brace' && block.type !== 'root' && block.parent) {
  3257. block = block.parent;
  3258. queue = block.queue;
  3259. }
  3260. for (let i = 0; i < node.nodes.length; i++) {
  3261. let child = node.nodes[i];
  3262. if (child.type === 'comma' && node.type === 'brace') {
  3263. if (i === 1) queue.push('');
  3264. queue.push('');
  3265. continue;
  3266. }
  3267. if (child.type === 'close') {
  3268. q.push(append(q.pop(), queue, enclose));
  3269. continue;
  3270. }
  3271. if (child.value && child.type !== 'open') {
  3272. queue.push(append(queue.pop(), child.value));
  3273. continue;
  3274. }
  3275. if (child.nodes) {
  3276. walk(child, node);
  3277. }
  3278. }
  3279. return queue;
  3280. };
  3281. return utils$3.flatten(walk(ast));
  3282. };
  3283. var expand_1 = expand;
  3284. var constants$2 = {
  3285. MAX_LENGTH: 1024 * 64,
  3286. // Digits
  3287. CHAR_0: '0',
  3288. /* 0 */
  3289. CHAR_9: '9',
  3290. /* 9 */
  3291. // Alphabet chars.
  3292. CHAR_UPPERCASE_A: 'A',
  3293. /* A */
  3294. CHAR_LOWERCASE_A: 'a',
  3295. /* a */
  3296. CHAR_UPPERCASE_Z: 'Z',
  3297. /* Z */
  3298. CHAR_LOWERCASE_Z: 'z',
  3299. /* z */
  3300. CHAR_LEFT_PARENTHESES: '(',
  3301. /* ( */
  3302. CHAR_RIGHT_PARENTHESES: ')',
  3303. /* ) */
  3304. CHAR_ASTERISK: '*',
  3305. /* * */
  3306. // Non-alphabetic chars.
  3307. CHAR_AMPERSAND: '&',
  3308. /* & */
  3309. CHAR_AT: '@',
  3310. /* @ */
  3311. CHAR_BACKSLASH: '\\',
  3312. /* \ */
  3313. CHAR_BACKTICK: '`',
  3314. /* ` */
  3315. CHAR_CARRIAGE_RETURN: '\r',
  3316. /* \r */
  3317. CHAR_CIRCUMFLEX_ACCENT: '^',
  3318. /* ^ */
  3319. CHAR_COLON: ':',
  3320. /* : */
  3321. CHAR_COMMA: ',',
  3322. /* , */
  3323. CHAR_DOLLAR: '$',
  3324. /* . */
  3325. CHAR_DOT: '.',
  3326. /* . */
  3327. CHAR_DOUBLE_QUOTE: '"',
  3328. /* " */
  3329. CHAR_EQUAL: '=',
  3330. /* = */
  3331. CHAR_EXCLAMATION_MARK: '!',
  3332. /* ! */
  3333. CHAR_FORM_FEED: '\f',
  3334. /* \f */
  3335. CHAR_FORWARD_SLASH: '/',
  3336. /* / */
  3337. CHAR_HASH: '#',
  3338. /* # */
  3339. CHAR_HYPHEN_MINUS: '-',
  3340. /* - */
  3341. CHAR_LEFT_ANGLE_BRACKET: '<',
  3342. /* < */
  3343. CHAR_LEFT_CURLY_BRACE: '{',
  3344. /* { */
  3345. CHAR_LEFT_SQUARE_BRACKET: '[',
  3346. /* [ */
  3347. CHAR_LINE_FEED: '\n',
  3348. /* \n */
  3349. CHAR_NO_BREAK_SPACE: '\u00A0',
  3350. /* \u00A0 */
  3351. CHAR_PERCENT: '%',
  3352. /* % */
  3353. CHAR_PLUS: '+',
  3354. /* + */
  3355. CHAR_QUESTION_MARK: '?',
  3356. /* ? */
  3357. CHAR_RIGHT_ANGLE_BRACKET: '>',
  3358. /* > */
  3359. CHAR_RIGHT_CURLY_BRACE: '}',
  3360. /* } */
  3361. CHAR_RIGHT_SQUARE_BRACKET: ']',
  3362. /* ] */
  3363. CHAR_SEMICOLON: ';',
  3364. /* ; */
  3365. CHAR_SINGLE_QUOTE: '\'',
  3366. /* ' */
  3367. CHAR_SPACE: ' ',
  3368. /* */
  3369. CHAR_TAB: '\t',
  3370. /* \t */
  3371. CHAR_UNDERSCORE: '_',
  3372. /* _ */
  3373. CHAR_VERTICAL_LINE: '|',
  3374. /* | */
  3375. CHAR_ZERO_WIDTH_NOBREAK_SPACE: '\uFEFF'
  3376. /* \uFEFF */
  3377. };
  3378. /**
  3379. * Constants
  3380. */
  3381. const {
  3382. MAX_LENGTH: MAX_LENGTH$1,
  3383. CHAR_BACKSLASH,
  3384. /* \ */
  3385. CHAR_BACKTICK,
  3386. /* ` */
  3387. CHAR_COMMA: CHAR_COMMA$1,
  3388. /* , */
  3389. CHAR_DOT: CHAR_DOT$1,
  3390. /* . */
  3391. CHAR_LEFT_PARENTHESES: CHAR_LEFT_PARENTHESES$1,
  3392. /* ( */
  3393. CHAR_RIGHT_PARENTHESES: CHAR_RIGHT_PARENTHESES$1,
  3394. /* ) */
  3395. CHAR_LEFT_CURLY_BRACE: CHAR_LEFT_CURLY_BRACE$1,
  3396. /* { */
  3397. CHAR_RIGHT_CURLY_BRACE: CHAR_RIGHT_CURLY_BRACE$1,
  3398. /* } */
  3399. CHAR_LEFT_SQUARE_BRACKET: CHAR_LEFT_SQUARE_BRACKET$1,
  3400. /* [ */
  3401. CHAR_RIGHT_SQUARE_BRACKET: CHAR_RIGHT_SQUARE_BRACKET$1,
  3402. /* ] */
  3403. CHAR_DOUBLE_QUOTE,
  3404. /* " */
  3405. CHAR_SINGLE_QUOTE,
  3406. /* ' */
  3407. CHAR_NO_BREAK_SPACE,
  3408. CHAR_ZERO_WIDTH_NOBREAK_SPACE
  3409. } = constants$2;
  3410. /**
  3411. * parse
  3412. */
  3413. const parse$2 = (input, options = {}) => {
  3414. if (typeof input !== 'string') {
  3415. throw new TypeError('Expected a string');
  3416. }
  3417. let opts = options || {};
  3418. let max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH$1, opts.maxLength) : MAX_LENGTH$1;
  3419. if (input.length > max) {
  3420. throw new SyntaxError(`Input length (${input.length}), exceeds max characters (${max})`);
  3421. }
  3422. let ast = {
  3423. type: 'root',
  3424. input,
  3425. nodes: []
  3426. };
  3427. let stack = [ast];
  3428. let block = ast;
  3429. let prev = ast;
  3430. let brackets = 0;
  3431. let length = input.length;
  3432. let index = 0;
  3433. let depth = 0;
  3434. let value;
  3435. /**
  3436. * Helpers
  3437. */
  3438. const advance = () => input[index++];
  3439. const push = node => {
  3440. if (node.type === 'text' && prev.type === 'dot') {
  3441. prev.type = 'text';
  3442. }
  3443. if (prev && prev.type === 'text' && node.type === 'text') {
  3444. prev.value += node.value;
  3445. return;
  3446. }
  3447. block.nodes.push(node);
  3448. node.parent = block;
  3449. node.prev = prev;
  3450. prev = node;
  3451. return node;
  3452. };
  3453. push({
  3454. type: 'bos'
  3455. });
  3456. while (index < length) {
  3457. block = stack[stack.length - 1];
  3458. value = advance();
  3459. /**
  3460. * Invalid chars
  3461. */
  3462. if (value === CHAR_ZERO_WIDTH_NOBREAK_SPACE || value === CHAR_NO_BREAK_SPACE) {
  3463. continue;
  3464. }
  3465. /**
  3466. * Escaped chars
  3467. */
  3468. if (value === CHAR_BACKSLASH) {
  3469. push({
  3470. type: 'text',
  3471. value: (options.keepEscaping ? value : '') + advance()
  3472. });
  3473. continue;
  3474. }
  3475. /**
  3476. * Right square bracket (literal): ']'
  3477. */
  3478. if (value === CHAR_RIGHT_SQUARE_BRACKET$1) {
  3479. push({
  3480. type: 'text',
  3481. value: '\\' + value
  3482. });
  3483. continue;
  3484. }
  3485. /**
  3486. * Left square bracket: '['
  3487. */
  3488. if (value === CHAR_LEFT_SQUARE_BRACKET$1) {
  3489. brackets++;
  3490. let next;
  3491. while (index < length && (next = advance())) {
  3492. value += next;
  3493. if (next === CHAR_LEFT_SQUARE_BRACKET$1) {
  3494. brackets++;
  3495. continue;
  3496. }
  3497. if (next === CHAR_BACKSLASH) {
  3498. value += advance();
  3499. continue;
  3500. }
  3501. if (next === CHAR_RIGHT_SQUARE_BRACKET$1) {
  3502. brackets--;
  3503. if (brackets === 0) {
  3504. break;
  3505. }
  3506. }
  3507. }
  3508. push({
  3509. type: 'text',
  3510. value
  3511. });
  3512. continue;
  3513. }
  3514. /**
  3515. * Parentheses
  3516. */
  3517. if (value === CHAR_LEFT_PARENTHESES$1) {
  3518. block = push({
  3519. type: 'paren',
  3520. nodes: []
  3521. });
  3522. stack.push(block);
  3523. push({
  3524. type: 'text',
  3525. value
  3526. });
  3527. continue;
  3528. }
  3529. if (value === CHAR_RIGHT_PARENTHESES$1) {
  3530. if (block.type !== 'paren') {
  3531. push({
  3532. type: 'text',
  3533. value
  3534. });
  3535. continue;
  3536. }
  3537. block = stack.pop();
  3538. push({
  3539. type: 'text',
  3540. value
  3541. });
  3542. block = stack[stack.length - 1];
  3543. continue;
  3544. }
  3545. /**
  3546. * Quotes: '|"|`
  3547. */
  3548. if (value === CHAR_DOUBLE_QUOTE || value === CHAR_SINGLE_QUOTE || value === CHAR_BACKTICK) {
  3549. let open = value;
  3550. let next;
  3551. if (options.keepQuotes !== true) {
  3552. value = '';
  3553. }
  3554. while (index < length && (next = advance())) {
  3555. if (next === CHAR_BACKSLASH) {
  3556. value += next + advance();
  3557. continue;
  3558. }
  3559. if (next === open) {
  3560. if (options.keepQuotes === true) value += next;
  3561. break;
  3562. }
  3563. value += next;
  3564. }
  3565. push({
  3566. type: 'text',
  3567. value
  3568. });
  3569. continue;
  3570. }
  3571. /**
  3572. * Left curly brace: '{'
  3573. */
  3574. if (value === CHAR_LEFT_CURLY_BRACE$1) {
  3575. depth++;
  3576. let dollar = prev.value && prev.value.slice(-1) === '$' || block.dollar === true;
  3577. let brace = {
  3578. type: 'brace',
  3579. open: true,
  3580. close: false,
  3581. dollar,
  3582. depth,
  3583. commas: 0,
  3584. ranges: 0,
  3585. nodes: []
  3586. };
  3587. block = push(brace);
  3588. stack.push(block);
  3589. push({
  3590. type: 'open',
  3591. value
  3592. });
  3593. continue;
  3594. }
  3595. /**
  3596. * Right curly brace: '}'
  3597. */
  3598. if (value === CHAR_RIGHT_CURLY_BRACE$1) {
  3599. if (block.type !== 'brace') {
  3600. push({
  3601. type: 'text',
  3602. value
  3603. });
  3604. continue;
  3605. }
  3606. let type = 'close';
  3607. block = stack.pop();
  3608. block.close = true;
  3609. push({
  3610. type,
  3611. value
  3612. });
  3613. depth--;
  3614. block = stack[stack.length - 1];
  3615. continue;
  3616. }
  3617. /**
  3618. * Comma: ','
  3619. */
  3620. if (value === CHAR_COMMA$1 && depth > 0) {
  3621. if (block.ranges > 0) {
  3622. block.ranges = 0;
  3623. let open = block.nodes.shift();
  3624. block.nodes = [open, {
  3625. type: 'text',
  3626. value: stringify$1(block)
  3627. }];
  3628. }
  3629. push({
  3630. type: 'comma',
  3631. value
  3632. });
  3633. block.commas++;
  3634. continue;
  3635. }
  3636. /**
  3637. * Dot: '.'
  3638. */
  3639. if (value === CHAR_DOT$1 && depth > 0 && block.commas === 0) {
  3640. let siblings = block.nodes;
  3641. if (depth === 0 || siblings.length === 0) {
  3642. push({
  3643. type: 'text',
  3644. value
  3645. });
  3646. continue;
  3647. }
  3648. if (prev.type === 'dot') {
  3649. block.range = [];
  3650. prev.value += value;
  3651. prev.type = 'range';
  3652. if (block.nodes.length !== 3 && block.nodes.length !== 5) {
  3653. block.invalid = true;
  3654. block.ranges = 0;
  3655. prev.type = 'text';
  3656. continue;
  3657. }
  3658. block.ranges++;
  3659. block.args = [];
  3660. continue;
  3661. }
  3662. if (prev.type === 'range') {
  3663. siblings.pop();
  3664. let before = siblings[siblings.length - 1];
  3665. before.value += prev.value + value;
  3666. prev = before;
  3667. block.ranges--;
  3668. continue;
  3669. }
  3670. push({
  3671. type: 'dot',
  3672. value
  3673. });
  3674. continue;
  3675. }
  3676. /**
  3677. * Text
  3678. */
  3679. push({
  3680. type: 'text',
  3681. value
  3682. });
  3683. } // Mark imbalanced braces and brackets as invalid
  3684. do {
  3685. block = stack.pop();
  3686. if (block.type !== 'root') {
  3687. block.nodes.forEach(node => {
  3688. if (!node.nodes) {
  3689. if (node.type === 'open') node.isOpen = true;
  3690. if (node.type === 'close') node.isClose = true;
  3691. if (!node.nodes) node.type = 'text';
  3692. node.invalid = true;
  3693. }
  3694. }); // get the location of the block on parent.nodes (block's siblings)
  3695. let parent = stack[stack.length - 1];
  3696. let index = parent.nodes.indexOf(block); // replace the (invalid) block with it's nodes
  3697. parent.nodes.splice(index, 1, ...block.nodes);
  3698. }
  3699. } while (stack.length > 0);
  3700. push({
  3701. type: 'eos'
  3702. });
  3703. return ast;
  3704. };
  3705. var parse_1$1 = parse$2;
  3706. /**
  3707. * Expand the given pattern or create a regex-compatible string.
  3708. *
  3709. * ```js
  3710. * const braces = require('braces');
  3711. * console.log(braces('{a,b,c}', { compile: true })); //=> ['(a|b|c)']
  3712. * console.log(braces('{a,b,c}')); //=> ['a', 'b', 'c']
  3713. * ```
  3714. * @param {String} `str`
  3715. * @param {Object} `options`
  3716. * @return {String}
  3717. * @api public
  3718. */
  3719. const braces = (input, options = {}) => {
  3720. let output = [];
  3721. if (Array.isArray(input)) {
  3722. for (let pattern of input) {
  3723. let result = braces.create(pattern, options);
  3724. if (Array.isArray(result)) {
  3725. output.push(...result);
  3726. } else {
  3727. output.push(result);
  3728. }
  3729. }
  3730. } else {
  3731. output = [].concat(braces.create(input, options));
  3732. }
  3733. if (options && options.expand === true && options.nodupes === true) {
  3734. output = [...new Set(output)];
  3735. }
  3736. return output;
  3737. };
  3738. /**
  3739. * Parse the given `str` with the given `options`.
  3740. *
  3741. * ```js
  3742. * // braces.parse(pattern, [, options]);
  3743. * const ast = braces.parse('a/{b,c}/d');
  3744. * console.log(ast);
  3745. * ```
  3746. * @param {String} pattern Brace pattern to parse
  3747. * @param {Object} options
  3748. * @return {Object} Returns an AST
  3749. * @api public
  3750. */
  3751. braces.parse = (input, options = {}) => parse_1$1(input, options);
  3752. /**
  3753. * Creates a braces string from an AST, or an AST node.
  3754. *
  3755. * ```js
  3756. * const braces = require('braces');
  3757. * let ast = braces.parse('foo/{a,b}/bar');
  3758. * console.log(stringify(ast.nodes[2])); //=> '{a,b}'
  3759. * ```
  3760. * @param {String} `input` Brace pattern or AST.
  3761. * @param {Object} `options`
  3762. * @return {Array} Returns an array of expanded values.
  3763. * @api public
  3764. */
  3765. braces.stringify = (input, options = {}) => {
  3766. if (typeof input === 'string') {
  3767. return stringify$1(braces.parse(input, options), options);
  3768. }
  3769. return stringify$1(input, options);
  3770. };
  3771. /**
  3772. * Compiles a brace pattern into a regex-compatible, optimized string.
  3773. * This method is called by the main [braces](#braces) function by default.
  3774. *
  3775. * ```js
  3776. * const braces = require('braces');
  3777. * console.log(braces.compile('a/{b,c}/d'));
  3778. * //=> ['a/(b|c)/d']
  3779. * ```
  3780. * @param {String} `input` Brace pattern or AST.
  3781. * @param {Object} `options`
  3782. * @return {Array} Returns an array of expanded values.
  3783. * @api public
  3784. */
  3785. braces.compile = (input, options = {}) => {
  3786. if (typeof input === 'string') {
  3787. input = braces.parse(input, options);
  3788. }
  3789. return compile_1(input, options);
  3790. };
  3791. /**
  3792. * Expands a brace pattern into an array. This method is called by the
  3793. * main [braces](#braces) function when `options.expand` is true. Before
  3794. * using this method it's recommended that you read the [performance notes](#performance))
  3795. * and advantages of using [.compile](#compile) instead.
  3796. *
  3797. * ```js
  3798. * const braces = require('braces');
  3799. * console.log(braces.expand('a/{b,c}/d'));
  3800. * //=> ['a/b/d', 'a/c/d'];
  3801. * ```
  3802. * @param {String} `pattern` Brace pattern
  3803. * @param {Object} `options`
  3804. * @return {Array} Returns an array of expanded values.
  3805. * @api public
  3806. */
  3807. braces.expand = (input, options = {}) => {
  3808. if (typeof input === 'string') {
  3809. input = braces.parse(input, options);
  3810. }
  3811. let result = expand_1(input, options); // filter out empty strings if specified
  3812. if (options.noempty === true) {
  3813. result = result.filter(Boolean);
  3814. } // filter out duplicates if specified
  3815. if (options.nodupes === true) {
  3816. result = [...new Set(result)];
  3817. }
  3818. return result;
  3819. };
  3820. /**
  3821. * Processes a brace pattern and returns either an expanded array
  3822. * (if `options.expand` is true), a highly optimized regex-compatible string.
  3823. * This method is called by the main [braces](#braces) function.
  3824. *
  3825. * ```js
  3826. * const braces = require('braces');
  3827. * console.log(braces.create('user-{200..300}/project-{a,b,c}-{1..10}'))
  3828. * //=> 'user-(20[0-9]|2[1-9][0-9]|300)/project-(a|b|c)-([1-9]|10)'
  3829. * ```
  3830. * @param {String} `pattern` Brace pattern
  3831. * @param {Object} `options`
  3832. * @return {Array} Returns an array of expanded values.
  3833. * @api public
  3834. */
  3835. braces.create = (input, options = {}) => {
  3836. if (input === '' || input.length < 3) {
  3837. return [input];
  3838. }
  3839. return options.expand !== true ? braces.compile(input, options) : braces.expand(input, options);
  3840. };
  3841. /**
  3842. * Expose "braces"
  3843. */
  3844. var braces_1 = braces;
  3845. const WIN_SLASH = '\\\\/';
  3846. const WIN_NO_SLASH = `[^${WIN_SLASH}]`;
  3847. /**
  3848. * Posix glob regex
  3849. */
  3850. const DOT_LITERAL = '\\.';
  3851. const PLUS_LITERAL = '\\+';
  3852. const QMARK_LITERAL = '\\?';
  3853. const SLASH_LITERAL = '\\/';
  3854. const ONE_CHAR = '(?=.)';
  3855. const QMARK = '[^/]';
  3856. const END_ANCHOR = `(?:${SLASH_LITERAL}|$)`;
  3857. const START_ANCHOR = `(?:^|${SLASH_LITERAL})`;
  3858. const DOTS_SLASH = `${DOT_LITERAL}{1,2}${END_ANCHOR}`;
  3859. const NO_DOT = `(?!${DOT_LITERAL})`;
  3860. const NO_DOTS = `(?!${START_ANCHOR}${DOTS_SLASH})`;
  3861. const NO_DOT_SLASH = `(?!${DOT_LITERAL}{0,1}${END_ANCHOR})`;
  3862. const NO_DOTS_SLASH = `(?!${DOTS_SLASH})`;
  3863. const QMARK_NO_DOT = `[^.${SLASH_LITERAL}]`;
  3864. const STAR = `${QMARK}*?`;
  3865. const POSIX_CHARS = {
  3866. DOT_LITERAL,
  3867. PLUS_LITERAL,
  3868. QMARK_LITERAL,
  3869. SLASH_LITERAL,
  3870. ONE_CHAR,
  3871. QMARK,
  3872. END_ANCHOR,
  3873. DOTS_SLASH,
  3874. NO_DOT,
  3875. NO_DOTS,
  3876. NO_DOT_SLASH,
  3877. NO_DOTS_SLASH,
  3878. QMARK_NO_DOT,
  3879. STAR,
  3880. START_ANCHOR
  3881. };
  3882. /**
  3883. * Windows glob regex
  3884. */
  3885. const WINDOWS_CHARS = Object.assign(Object.assign({}, POSIX_CHARS), {}, {
  3886. SLASH_LITERAL: `[${WIN_SLASH}]`,
  3887. QMARK: WIN_NO_SLASH,
  3888. STAR: `${WIN_NO_SLASH}*?`,
  3889. DOTS_SLASH: `${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$)`,
  3890. NO_DOT: `(?!${DOT_LITERAL})`,
  3891. NO_DOTS: `(?!(?:^|[${WIN_SLASH}])${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
  3892. NO_DOT_SLASH: `(?!${DOT_LITERAL}{0,1}(?:[${WIN_SLASH}]|$))`,
  3893. NO_DOTS_SLASH: `(?!${DOT_LITERAL}{1,2}(?:[${WIN_SLASH}]|$))`,
  3894. QMARK_NO_DOT: `[^.${WIN_SLASH}]`,
  3895. START_ANCHOR: `(?:^|[${WIN_SLASH}])`,
  3896. END_ANCHOR: `(?:[${WIN_SLASH}]|$)`
  3897. });
  3898. /**
  3899. * POSIX Bracket Regex
  3900. */
  3901. const POSIX_REGEX_SOURCE$1 = {
  3902. alnum: 'a-zA-Z0-9',
  3903. alpha: 'a-zA-Z',
  3904. ascii: '\\x00-\\x7F',
  3905. blank: ' \\t',
  3906. cntrl: '\\x00-\\x1F\\x7F',
  3907. digit: '0-9',
  3908. graph: '\\x21-\\x7E',
  3909. lower: 'a-z',
  3910. print: '\\x20-\\x7E ',
  3911. punct: '\\-!"#$%&\'()\\*+,./:;<=>?@[\\]^_`{|}~',
  3912. space: ' \\t\\r\\n\\v\\f',
  3913. upper: 'A-Z',
  3914. word: 'A-Za-z0-9_',
  3915. xdigit: 'A-Fa-f0-9'
  3916. };
  3917. var constants$1 = {
  3918. MAX_LENGTH: 1024 * 64,
  3919. POSIX_REGEX_SOURCE: POSIX_REGEX_SOURCE$1,
  3920. // regular expressions
  3921. REGEX_BACKSLASH: /\\(?![*+?^${}(|)[\]])/g,
  3922. REGEX_NON_SPECIAL_CHARS: /^[^@![\].,$*+?^{}()|\\/]+/,
  3923. REGEX_SPECIAL_CHARS: /[-*+?.^${}(|)[\]]/,
  3924. REGEX_SPECIAL_CHARS_BACKREF: /(\\?)((\W)(\3*))/g,
  3925. REGEX_SPECIAL_CHARS_GLOBAL: /([-*+?.^${}(|)[\]])/g,
  3926. REGEX_REMOVE_BACKSLASH: /(?:\[.*?[^\\]\]|\\(?=.))/g,
  3927. // Replace globs with equivalent patterns to reduce parsing time.
  3928. REPLACEMENTS: {
  3929. '***': '*',
  3930. '**/**': '**',
  3931. '**/**/**': '**'
  3932. },
  3933. // Digits
  3934. CHAR_0: 48,
  3935. /* 0 */
  3936. CHAR_9: 57,
  3937. /* 9 */
  3938. // Alphabet chars.
  3939. CHAR_UPPERCASE_A: 65,
  3940. /* A */
  3941. CHAR_LOWERCASE_A: 97,
  3942. /* a */
  3943. CHAR_UPPERCASE_Z: 90,
  3944. /* Z */
  3945. CHAR_LOWERCASE_Z: 122,
  3946. /* z */
  3947. CHAR_LEFT_PARENTHESES: 40,
  3948. /* ( */
  3949. CHAR_RIGHT_PARENTHESES: 41,
  3950. /* ) */
  3951. CHAR_ASTERISK: 42,
  3952. /* * */
  3953. // Non-alphabetic chars.
  3954. CHAR_AMPERSAND: 38,
  3955. /* & */
  3956. CHAR_AT: 64,
  3957. /* @ */
  3958. CHAR_BACKWARD_SLASH: 92,
  3959. /* \ */
  3960. CHAR_CARRIAGE_RETURN: 13,
  3961. /* \r */
  3962. CHAR_CIRCUMFLEX_ACCENT: 94,
  3963. /* ^ */
  3964. CHAR_COLON: 58,
  3965. /* : */
  3966. CHAR_COMMA: 44,
  3967. /* , */
  3968. CHAR_DOT: 46,
  3969. /* . */
  3970. CHAR_DOUBLE_QUOTE: 34,
  3971. /* " */
  3972. CHAR_EQUAL: 61,
  3973. /* = */
  3974. CHAR_EXCLAMATION_MARK: 33,
  3975. /* ! */
  3976. CHAR_FORM_FEED: 12,
  3977. /* \f */
  3978. CHAR_FORWARD_SLASH: 47,
  3979. /* / */
  3980. CHAR_GRAVE_ACCENT: 96,
  3981. /* ` */
  3982. CHAR_HASH: 35,
  3983. /* # */
  3984. CHAR_HYPHEN_MINUS: 45,
  3985. /* - */
  3986. CHAR_LEFT_ANGLE_BRACKET: 60,
  3987. /* < */
  3988. CHAR_LEFT_CURLY_BRACE: 123,
  3989. /* { */
  3990. CHAR_LEFT_SQUARE_BRACKET: 91,
  3991. /* [ */
  3992. CHAR_LINE_FEED: 10,
  3993. /* \n */
  3994. CHAR_NO_BREAK_SPACE: 160,
  3995. /* \u00A0 */
  3996. CHAR_PERCENT: 37,
  3997. /* % */
  3998. CHAR_PLUS: 43,
  3999. /* + */
  4000. CHAR_QUESTION_MARK: 63,
  4001. /* ? */
  4002. CHAR_RIGHT_ANGLE_BRACKET: 62,
  4003. /* > */
  4004. CHAR_RIGHT_CURLY_BRACE: 125,
  4005. /* } */
  4006. CHAR_RIGHT_SQUARE_BRACKET: 93,
  4007. /* ] */
  4008. CHAR_SEMICOLON: 59,
  4009. /* ; */
  4010. CHAR_SINGLE_QUOTE: 39,
  4011. /* ' */
  4012. CHAR_SPACE: 32,
  4013. /* */
  4014. CHAR_TAB: 9,
  4015. /* \t */
  4016. CHAR_UNDERSCORE: 95,
  4017. /* _ */
  4018. CHAR_VERTICAL_LINE: 124,
  4019. /* | */
  4020. CHAR_ZERO_WIDTH_NOBREAK_SPACE: 65279,
  4021. /* \uFEFF */
  4022. SEP: path__default['default'].sep,
  4023. /**
  4024. * Create EXTGLOB_CHARS
  4025. */
  4026. extglobChars(chars) {
  4027. return {
  4028. '!': {
  4029. type: 'negate',
  4030. open: '(?:(?!(?:',
  4031. close: `))${chars.STAR})`
  4032. },
  4033. '?': {
  4034. type: 'qmark',
  4035. open: '(?:',
  4036. close: ')?'
  4037. },
  4038. '+': {
  4039. type: 'plus',
  4040. open: '(?:',
  4041. close: ')+'
  4042. },
  4043. '*': {
  4044. type: 'star',
  4045. open: '(?:',
  4046. close: ')*'
  4047. },
  4048. '@': {
  4049. type: 'at',
  4050. open: '(?:',
  4051. close: ')'
  4052. }
  4053. };
  4054. },
  4055. /**
  4056. * Create GLOB_CHARS
  4057. */
  4058. globChars(win32) {
  4059. return win32 === true ? WINDOWS_CHARS : POSIX_CHARS;
  4060. }
  4061. };
  4062. var utils$2 = createCommonjsModule(function (module, exports) {
  4063. const win32 = process.platform === 'win32';
  4064. const {
  4065. REGEX_BACKSLASH,
  4066. REGEX_REMOVE_BACKSLASH,
  4067. REGEX_SPECIAL_CHARS,
  4068. REGEX_SPECIAL_CHARS_GLOBAL
  4069. } = constants$1;
  4070. exports.isObject = val => val !== null && typeof val === 'object' && !Array.isArray(val);
  4071. exports.hasRegexChars = str => REGEX_SPECIAL_CHARS.test(str);
  4072. exports.isRegexChar = str => str.length === 1 && exports.hasRegexChars(str);
  4073. exports.escapeRegex = str => str.replace(REGEX_SPECIAL_CHARS_GLOBAL, '\\$1');
  4074. exports.toPosixSlashes = str => str.replace(REGEX_BACKSLASH, '/');
  4075. exports.removeBackslashes = str => {
  4076. return str.replace(REGEX_REMOVE_BACKSLASH, match => {
  4077. return match === '\\' ? '' : match;
  4078. });
  4079. };
  4080. exports.supportsLookbehinds = () => {
  4081. const segs = process.version.slice(1).split('.').map(Number);
  4082. if (segs.length === 3 && segs[0] >= 9 || segs[0] === 8 && segs[1] >= 10) {
  4083. return true;
  4084. }
  4085. return false;
  4086. };
  4087. exports.isWindows = options => {
  4088. if (options && typeof options.windows === 'boolean') {
  4089. return options.windows;
  4090. }
  4091. return win32 === true || path__default['default'].sep === '\\';
  4092. };
  4093. exports.escapeLast = (input, char, lastIdx) => {
  4094. const idx = input.lastIndexOf(char, lastIdx);
  4095. if (idx === -1) return input;
  4096. if (input[idx - 1] === '\\') return exports.escapeLast(input, char, idx - 1);
  4097. return `${input.slice(0, idx)}\\${input.slice(idx)}`;
  4098. };
  4099. exports.removePrefix = (input, state = {}) => {
  4100. let output = input;
  4101. if (output.startsWith('./')) {
  4102. output = output.slice(2);
  4103. state.prefix = './';
  4104. }
  4105. return output;
  4106. };
  4107. exports.wrapOutput = (input, state = {}, options = {}) => {
  4108. const prepend = options.contains ? '' : '^';
  4109. const append = options.contains ? '' : '$';
  4110. let output = `${prepend}(?:${input})${append}`;
  4111. if (state.negated === true) {
  4112. output = `(?:^(?!${output}).*$)`;
  4113. }
  4114. return output;
  4115. };
  4116. });
  4117. const {
  4118. CHAR_ASTERISK,
  4119. /* * */
  4120. CHAR_AT,
  4121. /* @ */
  4122. CHAR_BACKWARD_SLASH,
  4123. /* \ */
  4124. CHAR_COMMA,
  4125. /* , */
  4126. CHAR_DOT,
  4127. /* . */
  4128. CHAR_EXCLAMATION_MARK,
  4129. /* ! */
  4130. CHAR_FORWARD_SLASH,
  4131. /* / */
  4132. CHAR_LEFT_CURLY_BRACE,
  4133. /* { */
  4134. CHAR_LEFT_PARENTHESES,
  4135. /* ( */
  4136. CHAR_LEFT_SQUARE_BRACKET,
  4137. /* [ */
  4138. CHAR_PLUS,
  4139. /* + */
  4140. CHAR_QUESTION_MARK,
  4141. /* ? */
  4142. CHAR_RIGHT_CURLY_BRACE,
  4143. /* } */
  4144. CHAR_RIGHT_PARENTHESES,
  4145. /* ) */
  4146. CHAR_RIGHT_SQUARE_BRACKET
  4147. /* ] */
  4148. } = constants$1;
  4149. const isPathSeparator = code => {
  4150. return code === CHAR_FORWARD_SLASH || code === CHAR_BACKWARD_SLASH;
  4151. };
  4152. const depth = token => {
  4153. if (token.isPrefix !== true) {
  4154. token.depth = token.isGlobstar ? Infinity : 1;
  4155. }
  4156. };
  4157. /**
  4158. * Quickly scans a glob pattern and returns an object with a handful of
  4159. * useful properties, like `isGlob`, `path` (the leading non-glob, if it exists),
  4160. * `glob` (the actual pattern), `negated` (true if the path starts with `!` but not
  4161. * with `!(`) and `negatedExtglob` (true if the path starts with `!(`).
  4162. *
  4163. * ```js
  4164. * const pm = require('picomatch');
  4165. * console.log(pm.scan('foo/bar/*.js'));
  4166. * { isGlob: true, input: 'foo/bar/*.js', base: 'foo/bar', glob: '*.js' }
  4167. * ```
  4168. * @param {String} `str`
  4169. * @param {Object} `options`
  4170. * @return {Object} Returns an object with tokens and regex source string.
  4171. * @api public
  4172. */
  4173. const scan = (input, options) => {
  4174. const opts = options || {};
  4175. const length = input.length - 1;
  4176. const scanToEnd = opts.parts === true || opts.scanToEnd === true;
  4177. const slashes = [];
  4178. const tokens = [];
  4179. const parts = [];
  4180. let str = input;
  4181. let index = -1;
  4182. let start = 0;
  4183. let lastIndex = 0;
  4184. let isBrace = false;
  4185. let isBracket = false;
  4186. let isGlob = false;
  4187. let isExtglob = false;
  4188. let isGlobstar = false;
  4189. let braceEscaped = false;
  4190. let backslashes = false;
  4191. let negated = false;
  4192. let negatedExtglob = false;
  4193. let finished = false;
  4194. let braces = 0;
  4195. let prev;
  4196. let code;
  4197. let token = {
  4198. value: '',
  4199. depth: 0,
  4200. isGlob: false
  4201. };
  4202. const eos = () => index >= length;
  4203. const peek = () => str.charCodeAt(index + 1);
  4204. const advance = () => {
  4205. prev = code;
  4206. return str.charCodeAt(++index);
  4207. };
  4208. while (index < length) {
  4209. code = advance();
  4210. let next;
  4211. if (code === CHAR_BACKWARD_SLASH) {
  4212. backslashes = token.backslashes = true;
  4213. code = advance();
  4214. if (code === CHAR_LEFT_CURLY_BRACE) {
  4215. braceEscaped = true;
  4216. }
  4217. continue;
  4218. }
  4219. if (braceEscaped === true || code === CHAR_LEFT_CURLY_BRACE) {
  4220. braces++;
  4221. while (eos() !== true && (code = advance())) {
  4222. if (code === CHAR_BACKWARD_SLASH) {
  4223. backslashes = token.backslashes = true;
  4224. advance();
  4225. continue;
  4226. }
  4227. if (code === CHAR_LEFT_CURLY_BRACE) {
  4228. braces++;
  4229. continue;
  4230. }
  4231. if (braceEscaped !== true && code === CHAR_DOT && (code = advance()) === CHAR_DOT) {
  4232. isBrace = token.isBrace = true;
  4233. isGlob = token.isGlob = true;
  4234. finished = true;
  4235. if (scanToEnd === true) {
  4236. continue;
  4237. }
  4238. break;
  4239. }
  4240. if (braceEscaped !== true && code === CHAR_COMMA) {
  4241. isBrace = token.isBrace = true;
  4242. isGlob = token.isGlob = true;
  4243. finished = true;
  4244. if (scanToEnd === true) {
  4245. continue;
  4246. }
  4247. break;
  4248. }
  4249. if (code === CHAR_RIGHT_CURLY_BRACE) {
  4250. braces--;
  4251. if (braces === 0) {
  4252. braceEscaped = false;
  4253. isBrace = token.isBrace = true;
  4254. finished = true;
  4255. break;
  4256. }
  4257. }
  4258. }
  4259. if (scanToEnd === true) {
  4260. continue;
  4261. }
  4262. break;
  4263. }
  4264. if (code === CHAR_FORWARD_SLASH) {
  4265. slashes.push(index);
  4266. tokens.push(token);
  4267. token = {
  4268. value: '',
  4269. depth: 0,
  4270. isGlob: false
  4271. };
  4272. if (finished === true) continue;
  4273. if (prev === CHAR_DOT && index === start + 1) {
  4274. start += 2;
  4275. continue;
  4276. }
  4277. lastIndex = index + 1;
  4278. continue;
  4279. }
  4280. if (opts.noext !== true) {
  4281. const isExtglobChar = code === CHAR_PLUS || code === CHAR_AT || code === CHAR_ASTERISK || code === CHAR_QUESTION_MARK || code === CHAR_EXCLAMATION_MARK;
  4282. if (isExtglobChar === true && peek() === CHAR_LEFT_PARENTHESES) {
  4283. isGlob = token.isGlob = true;
  4284. isExtglob = token.isExtglob = true;
  4285. finished = true;
  4286. if (code === CHAR_EXCLAMATION_MARK && index === start) {
  4287. negatedExtglob = true;
  4288. }
  4289. if (scanToEnd === true) {
  4290. while (eos() !== true && (code = advance())) {
  4291. if (code === CHAR_BACKWARD_SLASH) {
  4292. backslashes = token.backslashes = true;
  4293. code = advance();
  4294. continue;
  4295. }
  4296. if (code === CHAR_RIGHT_PARENTHESES) {
  4297. isGlob = token.isGlob = true;
  4298. finished = true;
  4299. break;
  4300. }
  4301. }
  4302. continue;
  4303. }
  4304. break;
  4305. }
  4306. }
  4307. if (code === CHAR_ASTERISK) {
  4308. if (prev === CHAR_ASTERISK) isGlobstar = token.isGlobstar = true;
  4309. isGlob = token.isGlob = true;
  4310. finished = true;
  4311. if (scanToEnd === true) {
  4312. continue;
  4313. }
  4314. break;
  4315. }
  4316. if (code === CHAR_QUESTION_MARK) {
  4317. isGlob = token.isGlob = true;
  4318. finished = true;
  4319. if (scanToEnd === true) {
  4320. continue;
  4321. }
  4322. break;
  4323. }
  4324. if (code === CHAR_LEFT_SQUARE_BRACKET) {
  4325. while (eos() !== true && (next = advance())) {
  4326. if (next === CHAR_BACKWARD_SLASH) {
  4327. backslashes = token.backslashes = true;
  4328. advance();
  4329. continue;
  4330. }
  4331. if (next === CHAR_RIGHT_SQUARE_BRACKET) {
  4332. isBracket = token.isBracket = true;
  4333. isGlob = token.isGlob = true;
  4334. finished = true;
  4335. break;
  4336. }
  4337. }
  4338. if (scanToEnd === true) {
  4339. continue;
  4340. }
  4341. break;
  4342. }
  4343. if (opts.nonegate !== true && code === CHAR_EXCLAMATION_MARK && index === start) {
  4344. negated = token.negated = true;
  4345. start++;
  4346. continue;
  4347. }
  4348. if (opts.noparen !== true && code === CHAR_LEFT_PARENTHESES) {
  4349. isGlob = token.isGlob = true;
  4350. if (scanToEnd === true) {
  4351. while (eos() !== true && (code = advance())) {
  4352. if (code === CHAR_LEFT_PARENTHESES) {
  4353. backslashes = token.backslashes = true;
  4354. code = advance();
  4355. continue;
  4356. }
  4357. if (code === CHAR_RIGHT_PARENTHESES) {
  4358. finished = true;
  4359. break;
  4360. }
  4361. }
  4362. continue;
  4363. }
  4364. break;
  4365. }
  4366. if (isGlob === true) {
  4367. finished = true;
  4368. if (scanToEnd === true) {
  4369. continue;
  4370. }
  4371. break;
  4372. }
  4373. }
  4374. if (opts.noext === true) {
  4375. isExtglob = false;
  4376. isGlob = false;
  4377. }
  4378. let base = str;
  4379. let prefix = '';
  4380. let glob = '';
  4381. if (start > 0) {
  4382. prefix = str.slice(0, start);
  4383. str = str.slice(start);
  4384. lastIndex -= start;
  4385. }
  4386. if (base && isGlob === true && lastIndex > 0) {
  4387. base = str.slice(0, lastIndex);
  4388. glob = str.slice(lastIndex);
  4389. } else if (isGlob === true) {
  4390. base = '';
  4391. glob = str;
  4392. } else {
  4393. base = str;
  4394. }
  4395. if (base && base !== '' && base !== '/' && base !== str) {
  4396. if (isPathSeparator(base.charCodeAt(base.length - 1))) {
  4397. base = base.slice(0, -1);
  4398. }
  4399. }
  4400. if (opts.unescape === true) {
  4401. if (glob) glob = utils$2.removeBackslashes(glob);
  4402. if (base && backslashes === true) {
  4403. base = utils$2.removeBackslashes(base);
  4404. }
  4405. }
  4406. const state = {
  4407. prefix,
  4408. input,
  4409. start,
  4410. base,
  4411. glob,
  4412. isBrace,
  4413. isBracket,
  4414. isGlob,
  4415. isExtglob,
  4416. isGlobstar,
  4417. negated,
  4418. negatedExtglob
  4419. };
  4420. if (opts.tokens === true) {
  4421. state.maxDepth = 0;
  4422. if (!isPathSeparator(code)) {
  4423. tokens.push(token);
  4424. }
  4425. state.tokens = tokens;
  4426. }
  4427. if (opts.parts === true || opts.tokens === true) {
  4428. let prevIndex;
  4429. for (let idx = 0; idx < slashes.length; idx++) {
  4430. const n = prevIndex ? prevIndex + 1 : start;
  4431. const i = slashes[idx];
  4432. const value = input.slice(n, i);
  4433. if (opts.tokens) {
  4434. if (idx === 0 && start !== 0) {
  4435. tokens[idx].isPrefix = true;
  4436. tokens[idx].value = prefix;
  4437. } else {
  4438. tokens[idx].value = value;
  4439. }
  4440. depth(tokens[idx]);
  4441. state.maxDepth += tokens[idx].depth;
  4442. }
  4443. if (idx !== 0 || value !== '') {
  4444. parts.push(value);
  4445. }
  4446. prevIndex = i;
  4447. }
  4448. if (prevIndex && prevIndex + 1 < input.length) {
  4449. const value = input.slice(prevIndex + 1);
  4450. parts.push(value);
  4451. if (opts.tokens) {
  4452. tokens[tokens.length - 1].value = value;
  4453. depth(tokens[tokens.length - 1]);
  4454. state.maxDepth += tokens[tokens.length - 1].depth;
  4455. }
  4456. }
  4457. state.slashes = slashes;
  4458. state.parts = parts;
  4459. }
  4460. return state;
  4461. };
  4462. var scan_1 = scan;
  4463. /**
  4464. * Constants
  4465. */
  4466. const {
  4467. MAX_LENGTH,
  4468. POSIX_REGEX_SOURCE,
  4469. REGEX_NON_SPECIAL_CHARS,
  4470. REGEX_SPECIAL_CHARS_BACKREF,
  4471. REPLACEMENTS
  4472. } = constants$1;
  4473. /**
  4474. * Helpers
  4475. */
  4476. const expandRange = (args, options) => {
  4477. if (typeof options.expandRange === 'function') {
  4478. return options.expandRange(...args, options);
  4479. }
  4480. args.sort();
  4481. const value = `[${args.join('-')}]`;
  4482. try {
  4483. /* eslint-disable-next-line no-new */
  4484. new RegExp(value);
  4485. } catch (ex) {
  4486. return args.map(v => utils$2.escapeRegex(v)).join('..');
  4487. }
  4488. return value;
  4489. };
  4490. /**
  4491. * Create the message for a syntax error
  4492. */
  4493. const syntaxError = (type, char) => {
  4494. return `Missing ${type}: "${char}" - use "\\\\${char}" to match literal characters`;
  4495. };
  4496. /**
  4497. * Parse the given input string.
  4498. * @param {String} input
  4499. * @param {Object} options
  4500. * @return {Object}
  4501. */
  4502. const parse$1 = (input, options) => {
  4503. if (typeof input !== 'string') {
  4504. throw new TypeError('Expected a string');
  4505. }
  4506. input = REPLACEMENTS[input] || input;
  4507. const opts = Object.assign({}, options);
  4508. const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
  4509. let len = input.length;
  4510. if (len > max) {
  4511. throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
  4512. }
  4513. const bos = {
  4514. type: 'bos',
  4515. value: '',
  4516. output: opts.prepend || ''
  4517. };
  4518. const tokens = [bos];
  4519. const capture = opts.capture ? '' : '?:';
  4520. const win32 = utils$2.isWindows(options); // create constants based on platform, for windows or posix
  4521. const PLATFORM_CHARS = constants$1.globChars(win32);
  4522. const EXTGLOB_CHARS = constants$1.extglobChars(PLATFORM_CHARS);
  4523. const {
  4524. DOT_LITERAL,
  4525. PLUS_LITERAL,
  4526. SLASH_LITERAL,
  4527. ONE_CHAR,
  4528. DOTS_SLASH,
  4529. NO_DOT,
  4530. NO_DOT_SLASH,
  4531. NO_DOTS_SLASH,
  4532. QMARK,
  4533. QMARK_NO_DOT,
  4534. STAR,
  4535. START_ANCHOR
  4536. } = PLATFORM_CHARS;
  4537. const globstar = opts => {
  4538. return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
  4539. };
  4540. const nodot = opts.dot ? '' : NO_DOT;
  4541. const qmarkNoDot = opts.dot ? QMARK : QMARK_NO_DOT;
  4542. let star = opts.bash === true ? globstar(opts) : STAR;
  4543. if (opts.capture) {
  4544. star = `(${star})`;
  4545. } // minimatch options support
  4546. if (typeof opts.noext === 'boolean') {
  4547. opts.noextglob = opts.noext;
  4548. }
  4549. const state = {
  4550. input,
  4551. index: -1,
  4552. start: 0,
  4553. dot: opts.dot === true,
  4554. consumed: '',
  4555. output: '',
  4556. prefix: '',
  4557. backtrack: false,
  4558. negated: false,
  4559. brackets: 0,
  4560. braces: 0,
  4561. parens: 0,
  4562. quotes: 0,
  4563. globstar: false,
  4564. tokens
  4565. };
  4566. input = utils$2.removePrefix(input, state);
  4567. len = input.length;
  4568. const extglobs = [];
  4569. const braces = [];
  4570. const stack = [];
  4571. let prev = bos;
  4572. let value;
  4573. /**
  4574. * Tokenizing helpers
  4575. */
  4576. const eos = () => state.index === len - 1;
  4577. const peek = state.peek = (n = 1) => input[state.index + n];
  4578. const advance = state.advance = () => input[++state.index] || '';
  4579. const remaining = () => input.slice(state.index + 1);
  4580. const consume = (value = '', num = 0) => {
  4581. state.consumed += value;
  4582. state.index += num;
  4583. };
  4584. const append = token => {
  4585. state.output += token.output != null ? token.output : token.value;
  4586. consume(token.value);
  4587. };
  4588. const negate = () => {
  4589. let count = 1;
  4590. while (peek() === '!' && (peek(2) !== '(' || peek(3) === '?')) {
  4591. advance();
  4592. state.start++;
  4593. count++;
  4594. }
  4595. if (count % 2 === 0) {
  4596. return false;
  4597. }
  4598. state.negated = true;
  4599. state.start++;
  4600. return true;
  4601. };
  4602. const increment = type => {
  4603. state[type]++;
  4604. stack.push(type);
  4605. };
  4606. const decrement = type => {
  4607. state[type]--;
  4608. stack.pop();
  4609. };
  4610. /**
  4611. * Push tokens onto the tokens array. This helper speeds up
  4612. * tokenizing by 1) helping us avoid backtracking as much as possible,
  4613. * and 2) helping us avoid creating extra tokens when consecutive
  4614. * characters are plain text. This improves performance and simplifies
  4615. * lookbehinds.
  4616. */
  4617. const push = tok => {
  4618. if (prev.type === 'globstar') {
  4619. const isBrace = state.braces > 0 && (tok.type === 'comma' || tok.type === 'brace');
  4620. const isExtglob = tok.extglob === true || extglobs.length && (tok.type === 'pipe' || tok.type === 'paren');
  4621. if (tok.type !== 'slash' && tok.type !== 'paren' && !isBrace && !isExtglob) {
  4622. state.output = state.output.slice(0, -prev.output.length);
  4623. prev.type = 'star';
  4624. prev.value = '*';
  4625. prev.output = star;
  4626. state.output += prev.output;
  4627. }
  4628. }
  4629. if (extglobs.length && tok.type !== 'paren') {
  4630. extglobs[extglobs.length - 1].inner += tok.value;
  4631. }
  4632. if (tok.value || tok.output) append(tok);
  4633. if (prev && prev.type === 'text' && tok.type === 'text') {
  4634. prev.value += tok.value;
  4635. prev.output = (prev.output || '') + tok.value;
  4636. return;
  4637. }
  4638. tok.prev = prev;
  4639. tokens.push(tok);
  4640. prev = tok;
  4641. };
  4642. const extglobOpen = (type, value) => {
  4643. const token = Object.assign(Object.assign({}, EXTGLOB_CHARS[value]), {}, {
  4644. conditions: 1,
  4645. inner: ''
  4646. });
  4647. token.prev = prev;
  4648. token.parens = state.parens;
  4649. token.output = state.output;
  4650. const output = (opts.capture ? '(' : '') + token.open;
  4651. increment('parens');
  4652. push({
  4653. type,
  4654. value,
  4655. output: state.output ? '' : ONE_CHAR
  4656. });
  4657. push({
  4658. type: 'paren',
  4659. extglob: true,
  4660. value: advance(),
  4661. output
  4662. });
  4663. extglobs.push(token);
  4664. };
  4665. const extglobClose = token => {
  4666. let output = token.close + (opts.capture ? ')' : '');
  4667. let rest;
  4668. if (token.type === 'negate') {
  4669. let extglobStar = star;
  4670. if (token.inner && token.inner.length > 1 && token.inner.includes('/')) {
  4671. extglobStar = globstar(opts);
  4672. }
  4673. if (extglobStar !== star || eos() || /^\)+$/.test(remaining())) {
  4674. output = token.close = `)$))${extglobStar}`;
  4675. }
  4676. if (token.inner.includes('*') && (rest = remaining()) && /^\.[^\\/.]+$/.test(rest)) {
  4677. output = token.close = `)${rest})${extglobStar})`;
  4678. }
  4679. if (token.prev.type === 'bos') {
  4680. state.negatedExtglob = true;
  4681. }
  4682. }
  4683. push({
  4684. type: 'paren',
  4685. extglob: true,
  4686. value,
  4687. output
  4688. });
  4689. decrement('parens');
  4690. };
  4691. /**
  4692. * Fast paths
  4693. */
  4694. if (opts.fastpaths !== false && !/(^[*!]|[/()[\]{}"])/.test(input)) {
  4695. let backslashes = false;
  4696. let output = input.replace(REGEX_SPECIAL_CHARS_BACKREF, (m, esc, chars, first, rest, index) => {
  4697. if (first === '\\') {
  4698. backslashes = true;
  4699. return m;
  4700. }
  4701. if (first === '?') {
  4702. if (esc) {
  4703. return esc + first + (rest ? QMARK.repeat(rest.length) : '');
  4704. }
  4705. if (index === 0) {
  4706. return qmarkNoDot + (rest ? QMARK.repeat(rest.length) : '');
  4707. }
  4708. return QMARK.repeat(chars.length);
  4709. }
  4710. if (first === '.') {
  4711. return DOT_LITERAL.repeat(chars.length);
  4712. }
  4713. if (first === '*') {
  4714. if (esc) {
  4715. return esc + first + (rest ? star : '');
  4716. }
  4717. return star;
  4718. }
  4719. return esc ? m : `\\${m}`;
  4720. });
  4721. if (backslashes === true) {
  4722. if (opts.unescape === true) {
  4723. output = output.replace(/\\/g, '');
  4724. } else {
  4725. output = output.replace(/\\+/g, m => {
  4726. return m.length % 2 === 0 ? '\\\\' : m ? '\\' : '';
  4727. });
  4728. }
  4729. }
  4730. if (output === input && opts.contains === true) {
  4731. state.output = input;
  4732. return state;
  4733. }
  4734. state.output = utils$2.wrapOutput(output, state, options);
  4735. return state;
  4736. }
  4737. /**
  4738. * Tokenize input until we reach end-of-string
  4739. */
  4740. while (!eos()) {
  4741. value = advance();
  4742. if (value === '\u0000') {
  4743. continue;
  4744. }
  4745. /**
  4746. * Escaped characters
  4747. */
  4748. if (value === '\\') {
  4749. const next = peek();
  4750. if (next === '/' && opts.bash !== true) {
  4751. continue;
  4752. }
  4753. if (next === '.' || next === ';') {
  4754. continue;
  4755. }
  4756. if (!next) {
  4757. value += '\\';
  4758. push({
  4759. type: 'text',
  4760. value
  4761. });
  4762. continue;
  4763. } // collapse slashes to reduce potential for exploits
  4764. const match = /^\\+/.exec(remaining());
  4765. let slashes = 0;
  4766. if (match && match[0].length > 2) {
  4767. slashes = match[0].length;
  4768. state.index += slashes;
  4769. if (slashes % 2 !== 0) {
  4770. value += '\\';
  4771. }
  4772. }
  4773. if (opts.unescape === true) {
  4774. value = advance();
  4775. } else {
  4776. value += advance();
  4777. }
  4778. if (state.brackets === 0) {
  4779. push({
  4780. type: 'text',
  4781. value
  4782. });
  4783. continue;
  4784. }
  4785. }
  4786. /**
  4787. * If we're inside a regex character class, continue
  4788. * until we reach the closing bracket.
  4789. */
  4790. if (state.brackets > 0 && (value !== ']' || prev.value === '[' || prev.value === '[^')) {
  4791. if (opts.posix !== false && value === ':') {
  4792. const inner = prev.value.slice(1);
  4793. if (inner.includes('[')) {
  4794. prev.posix = true;
  4795. if (inner.includes(':')) {
  4796. const idx = prev.value.lastIndexOf('[');
  4797. const pre = prev.value.slice(0, idx);
  4798. const rest = prev.value.slice(idx + 2);
  4799. const posix = POSIX_REGEX_SOURCE[rest];
  4800. if (posix) {
  4801. prev.value = pre + posix;
  4802. state.backtrack = true;
  4803. advance();
  4804. if (!bos.output && tokens.indexOf(prev) === 1) {
  4805. bos.output = ONE_CHAR;
  4806. }
  4807. continue;
  4808. }
  4809. }
  4810. }
  4811. }
  4812. if (value === '[' && peek() !== ':' || value === '-' && peek() === ']') {
  4813. value = `\\${value}`;
  4814. }
  4815. if (value === ']' && (prev.value === '[' || prev.value === '[^')) {
  4816. value = `\\${value}`;
  4817. }
  4818. if (opts.posix === true && value === '!' && prev.value === '[') {
  4819. value = '^';
  4820. }
  4821. prev.value += value;
  4822. append({
  4823. value
  4824. });
  4825. continue;
  4826. }
  4827. /**
  4828. * If we're inside a quoted string, continue
  4829. * until we reach the closing double quote.
  4830. */
  4831. if (state.quotes === 1 && value !== '"') {
  4832. value = utils$2.escapeRegex(value);
  4833. prev.value += value;
  4834. append({
  4835. value
  4836. });
  4837. continue;
  4838. }
  4839. /**
  4840. * Double quotes
  4841. */
  4842. if (value === '"') {
  4843. state.quotes = state.quotes === 1 ? 0 : 1;
  4844. if (opts.keepQuotes === true) {
  4845. push({
  4846. type: 'text',
  4847. value
  4848. });
  4849. }
  4850. continue;
  4851. }
  4852. /**
  4853. * Parentheses
  4854. */
  4855. if (value === '(') {
  4856. increment('parens');
  4857. push({
  4858. type: 'paren',
  4859. value
  4860. });
  4861. continue;
  4862. }
  4863. if (value === ')') {
  4864. if (state.parens === 0 && opts.strictBrackets === true) {
  4865. throw new SyntaxError(syntaxError('opening', '('));
  4866. }
  4867. const extglob = extglobs[extglobs.length - 1];
  4868. if (extglob && state.parens === extglob.parens + 1) {
  4869. extglobClose(extglobs.pop());
  4870. continue;
  4871. }
  4872. push({
  4873. type: 'paren',
  4874. value,
  4875. output: state.parens ? ')' : '\\)'
  4876. });
  4877. decrement('parens');
  4878. continue;
  4879. }
  4880. /**
  4881. * Square brackets
  4882. */
  4883. if (value === '[') {
  4884. if (opts.nobracket === true || !remaining().includes(']')) {
  4885. if (opts.nobracket !== true && opts.strictBrackets === true) {
  4886. throw new SyntaxError(syntaxError('closing', ']'));
  4887. }
  4888. value = `\\${value}`;
  4889. } else {
  4890. increment('brackets');
  4891. }
  4892. push({
  4893. type: 'bracket',
  4894. value
  4895. });
  4896. continue;
  4897. }
  4898. if (value === ']') {
  4899. if (opts.nobracket === true || prev && prev.type === 'bracket' && prev.value.length === 1) {
  4900. push({
  4901. type: 'text',
  4902. value,
  4903. output: `\\${value}`
  4904. });
  4905. continue;
  4906. }
  4907. if (state.brackets === 0) {
  4908. if (opts.strictBrackets === true) {
  4909. throw new SyntaxError(syntaxError('opening', '['));
  4910. }
  4911. push({
  4912. type: 'text',
  4913. value,
  4914. output: `\\${value}`
  4915. });
  4916. continue;
  4917. }
  4918. decrement('brackets');
  4919. const prevValue = prev.value.slice(1);
  4920. if (prev.posix !== true && prevValue[0] === '^' && !prevValue.includes('/')) {
  4921. value = `/${value}`;
  4922. }
  4923. prev.value += value;
  4924. append({
  4925. value
  4926. }); // when literal brackets are explicitly disabled
  4927. // assume we should match with a regex character class
  4928. if (opts.literalBrackets === false || utils$2.hasRegexChars(prevValue)) {
  4929. continue;
  4930. }
  4931. const escaped = utils$2.escapeRegex(prev.value);
  4932. state.output = state.output.slice(0, -prev.value.length); // when literal brackets are explicitly enabled
  4933. // assume we should escape the brackets to match literal characters
  4934. if (opts.literalBrackets === true) {
  4935. state.output += escaped;
  4936. prev.value = escaped;
  4937. continue;
  4938. } // when the user specifies nothing, try to match both
  4939. prev.value = `(${capture}${escaped}|${prev.value})`;
  4940. state.output += prev.value;
  4941. continue;
  4942. }
  4943. /**
  4944. * Braces
  4945. */
  4946. if (value === '{' && opts.nobrace !== true) {
  4947. increment('braces');
  4948. const open = {
  4949. type: 'brace',
  4950. value,
  4951. output: '(',
  4952. outputIndex: state.output.length,
  4953. tokensIndex: state.tokens.length
  4954. };
  4955. braces.push(open);
  4956. push(open);
  4957. continue;
  4958. }
  4959. if (value === '}') {
  4960. const brace = braces[braces.length - 1];
  4961. if (opts.nobrace === true || !brace) {
  4962. push({
  4963. type: 'text',
  4964. value,
  4965. output: value
  4966. });
  4967. continue;
  4968. }
  4969. let output = ')';
  4970. if (brace.dots === true) {
  4971. const arr = tokens.slice();
  4972. const range = [];
  4973. for (let i = arr.length - 1; i >= 0; i--) {
  4974. tokens.pop();
  4975. if (arr[i].type === 'brace') {
  4976. break;
  4977. }
  4978. if (arr[i].type !== 'dots') {
  4979. range.unshift(arr[i].value);
  4980. }
  4981. }
  4982. output = expandRange(range, opts);
  4983. state.backtrack = true;
  4984. }
  4985. if (brace.comma !== true && brace.dots !== true) {
  4986. const out = state.output.slice(0, brace.outputIndex);
  4987. const toks = state.tokens.slice(brace.tokensIndex);
  4988. brace.value = brace.output = '\\{';
  4989. value = output = '\\}';
  4990. state.output = out;
  4991. for (const t of toks) {
  4992. state.output += t.output || t.value;
  4993. }
  4994. }
  4995. push({
  4996. type: 'brace',
  4997. value,
  4998. output
  4999. });
  5000. decrement('braces');
  5001. braces.pop();
  5002. continue;
  5003. }
  5004. /**
  5005. * Pipes
  5006. */
  5007. if (value === '|') {
  5008. if (extglobs.length > 0) {
  5009. extglobs[extglobs.length - 1].conditions++;
  5010. }
  5011. push({
  5012. type: 'text',
  5013. value
  5014. });
  5015. continue;
  5016. }
  5017. /**
  5018. * Commas
  5019. */
  5020. if (value === ',') {
  5021. let output = value;
  5022. const brace = braces[braces.length - 1];
  5023. if (brace && stack[stack.length - 1] === 'braces') {
  5024. brace.comma = true;
  5025. output = '|';
  5026. }
  5027. push({
  5028. type: 'comma',
  5029. value,
  5030. output
  5031. });
  5032. continue;
  5033. }
  5034. /**
  5035. * Slashes
  5036. */
  5037. if (value === '/') {
  5038. // if the beginning of the glob is "./", advance the start
  5039. // to the current index, and don't add the "./" characters
  5040. // to the state. This greatly simplifies lookbehinds when
  5041. // checking for BOS characters like "!" and "." (not "./")
  5042. if (prev.type === 'dot' && state.index === state.start + 1) {
  5043. state.start = state.index + 1;
  5044. state.consumed = '';
  5045. state.output = '';
  5046. tokens.pop();
  5047. prev = bos; // reset "prev" to the first token
  5048. continue;
  5049. }
  5050. push({
  5051. type: 'slash',
  5052. value,
  5053. output: SLASH_LITERAL
  5054. });
  5055. continue;
  5056. }
  5057. /**
  5058. * Dots
  5059. */
  5060. if (value === '.') {
  5061. if (state.braces > 0 && prev.type === 'dot') {
  5062. if (prev.value === '.') prev.output = DOT_LITERAL;
  5063. const brace = braces[braces.length - 1];
  5064. prev.type = 'dots';
  5065. prev.output += value;
  5066. prev.value += value;
  5067. brace.dots = true;
  5068. continue;
  5069. }
  5070. if (state.braces + state.parens === 0 && prev.type !== 'bos' && prev.type !== 'slash') {
  5071. push({
  5072. type: 'text',
  5073. value,
  5074. output: DOT_LITERAL
  5075. });
  5076. continue;
  5077. }
  5078. push({
  5079. type: 'dot',
  5080. value,
  5081. output: DOT_LITERAL
  5082. });
  5083. continue;
  5084. }
  5085. /**
  5086. * Question marks
  5087. */
  5088. if (value === '?') {
  5089. const isGroup = prev && prev.value === '(';
  5090. if (!isGroup && opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  5091. extglobOpen('qmark', value);
  5092. continue;
  5093. }
  5094. if (prev && prev.type === 'paren') {
  5095. const next = peek();
  5096. let output = value;
  5097. if (next === '<' && !utils$2.supportsLookbehinds()) {
  5098. throw new Error('Node.js v10 or higher is required for regex lookbehinds');
  5099. }
  5100. if (prev.value === '(' && !/[!=<:]/.test(next) || next === '<' && !/<([!=]|\w+>)/.test(remaining())) {
  5101. output = `\\${value}`;
  5102. }
  5103. push({
  5104. type: 'text',
  5105. value,
  5106. output
  5107. });
  5108. continue;
  5109. }
  5110. if (opts.dot !== true && (prev.type === 'slash' || prev.type === 'bos')) {
  5111. push({
  5112. type: 'qmark',
  5113. value,
  5114. output: QMARK_NO_DOT
  5115. });
  5116. continue;
  5117. }
  5118. push({
  5119. type: 'qmark',
  5120. value,
  5121. output: QMARK
  5122. });
  5123. continue;
  5124. }
  5125. /**
  5126. * Exclamation
  5127. */
  5128. if (value === '!') {
  5129. if (opts.noextglob !== true && peek() === '(') {
  5130. if (peek(2) !== '?' || !/[!=<:]/.test(peek(3))) {
  5131. extglobOpen('negate', value);
  5132. continue;
  5133. }
  5134. }
  5135. if (opts.nonegate !== true && state.index === 0) {
  5136. negate();
  5137. continue;
  5138. }
  5139. }
  5140. /**
  5141. * Plus
  5142. */
  5143. if (value === '+') {
  5144. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  5145. extglobOpen('plus', value);
  5146. continue;
  5147. }
  5148. if (prev && prev.value === '(' || opts.regex === false) {
  5149. push({
  5150. type: 'plus',
  5151. value,
  5152. output: PLUS_LITERAL
  5153. });
  5154. continue;
  5155. }
  5156. if (prev && (prev.type === 'bracket' || prev.type === 'paren' || prev.type === 'brace') || state.parens > 0) {
  5157. push({
  5158. type: 'plus',
  5159. value
  5160. });
  5161. continue;
  5162. }
  5163. push({
  5164. type: 'plus',
  5165. value: PLUS_LITERAL
  5166. });
  5167. continue;
  5168. }
  5169. /**
  5170. * Plain text
  5171. */
  5172. if (value === '@') {
  5173. if (opts.noextglob !== true && peek() === '(' && peek(2) !== '?') {
  5174. push({
  5175. type: 'at',
  5176. extglob: true,
  5177. value,
  5178. output: ''
  5179. });
  5180. continue;
  5181. }
  5182. push({
  5183. type: 'text',
  5184. value
  5185. });
  5186. continue;
  5187. }
  5188. /**
  5189. * Plain text
  5190. */
  5191. if (value !== '*') {
  5192. if (value === '$' || value === '^') {
  5193. value = `\\${value}`;
  5194. }
  5195. const match = REGEX_NON_SPECIAL_CHARS.exec(remaining());
  5196. if (match) {
  5197. value += match[0];
  5198. state.index += match[0].length;
  5199. }
  5200. push({
  5201. type: 'text',
  5202. value
  5203. });
  5204. continue;
  5205. }
  5206. /**
  5207. * Stars
  5208. */
  5209. if (prev && (prev.type === 'globstar' || prev.star === true)) {
  5210. prev.type = 'star';
  5211. prev.star = true;
  5212. prev.value += value;
  5213. prev.output = star;
  5214. state.backtrack = true;
  5215. state.globstar = true;
  5216. consume(value);
  5217. continue;
  5218. }
  5219. let rest = remaining();
  5220. if (opts.noextglob !== true && /^\([^?]/.test(rest)) {
  5221. extglobOpen('star', value);
  5222. continue;
  5223. }
  5224. if (prev.type === 'star') {
  5225. if (opts.noglobstar === true) {
  5226. consume(value);
  5227. continue;
  5228. }
  5229. const prior = prev.prev;
  5230. const before = prior.prev;
  5231. const isStart = prior.type === 'slash' || prior.type === 'bos';
  5232. const afterStar = before && (before.type === 'star' || before.type === 'globstar');
  5233. if (opts.bash === true && (!isStart || rest[0] && rest[0] !== '/')) {
  5234. push({
  5235. type: 'star',
  5236. value,
  5237. output: ''
  5238. });
  5239. continue;
  5240. }
  5241. const isBrace = state.braces > 0 && (prior.type === 'comma' || prior.type === 'brace');
  5242. const isExtglob = extglobs.length && (prior.type === 'pipe' || prior.type === 'paren');
  5243. if (!isStart && prior.type !== 'paren' && !isBrace && !isExtglob) {
  5244. push({
  5245. type: 'star',
  5246. value,
  5247. output: ''
  5248. });
  5249. continue;
  5250. } // strip consecutive `/**/`
  5251. while (rest.slice(0, 3) === '/**') {
  5252. const after = input[state.index + 4];
  5253. if (after && after !== '/') {
  5254. break;
  5255. }
  5256. rest = rest.slice(3);
  5257. consume('/**', 3);
  5258. }
  5259. if (prior.type === 'bos' && eos()) {
  5260. prev.type = 'globstar';
  5261. prev.value += value;
  5262. prev.output = globstar(opts);
  5263. state.output = prev.output;
  5264. state.globstar = true;
  5265. consume(value);
  5266. continue;
  5267. }
  5268. if (prior.type === 'slash' && prior.prev.type !== 'bos' && !afterStar && eos()) {
  5269. state.output = state.output.slice(0, -(prior.output + prev.output).length);
  5270. prior.output = `(?:${prior.output}`;
  5271. prev.type = 'globstar';
  5272. prev.output = globstar(opts) + (opts.strictSlashes ? ')' : '|$)');
  5273. prev.value += value;
  5274. state.globstar = true;
  5275. state.output += prior.output + prev.output;
  5276. consume(value);
  5277. continue;
  5278. }
  5279. if (prior.type === 'slash' && prior.prev.type !== 'bos' && rest[0] === '/') {
  5280. const end = rest[1] !== void 0 ? '|$' : '';
  5281. state.output = state.output.slice(0, -(prior.output + prev.output).length);
  5282. prior.output = `(?:${prior.output}`;
  5283. prev.type = 'globstar';
  5284. prev.output = `${globstar(opts)}${SLASH_LITERAL}|${SLASH_LITERAL}${end})`;
  5285. prev.value += value;
  5286. state.output += prior.output + prev.output;
  5287. state.globstar = true;
  5288. consume(value + advance());
  5289. push({
  5290. type: 'slash',
  5291. value: '/',
  5292. output: ''
  5293. });
  5294. continue;
  5295. }
  5296. if (prior.type === 'bos' && rest[0] === '/') {
  5297. prev.type = 'globstar';
  5298. prev.value += value;
  5299. prev.output = `(?:^|${SLASH_LITERAL}|${globstar(opts)}${SLASH_LITERAL})`;
  5300. state.output = prev.output;
  5301. state.globstar = true;
  5302. consume(value + advance());
  5303. push({
  5304. type: 'slash',
  5305. value: '/',
  5306. output: ''
  5307. });
  5308. continue;
  5309. } // remove single star from output
  5310. state.output = state.output.slice(0, -prev.output.length); // reset previous token to globstar
  5311. prev.type = 'globstar';
  5312. prev.output = globstar(opts);
  5313. prev.value += value; // reset output with globstar
  5314. state.output += prev.output;
  5315. state.globstar = true;
  5316. consume(value);
  5317. continue;
  5318. }
  5319. const token = {
  5320. type: 'star',
  5321. value,
  5322. output: star
  5323. };
  5324. if (opts.bash === true) {
  5325. token.output = '.*?';
  5326. if (prev.type === 'bos' || prev.type === 'slash') {
  5327. token.output = nodot + token.output;
  5328. }
  5329. push(token);
  5330. continue;
  5331. }
  5332. if (prev && (prev.type === 'bracket' || prev.type === 'paren') && opts.regex === true) {
  5333. token.output = value;
  5334. push(token);
  5335. continue;
  5336. }
  5337. if (state.index === state.start || prev.type === 'slash' || prev.type === 'dot') {
  5338. if (prev.type === 'dot') {
  5339. state.output += NO_DOT_SLASH;
  5340. prev.output += NO_DOT_SLASH;
  5341. } else if (opts.dot === true) {
  5342. state.output += NO_DOTS_SLASH;
  5343. prev.output += NO_DOTS_SLASH;
  5344. } else {
  5345. state.output += nodot;
  5346. prev.output += nodot;
  5347. }
  5348. if (peek() !== '*') {
  5349. state.output += ONE_CHAR;
  5350. prev.output += ONE_CHAR;
  5351. }
  5352. }
  5353. push(token);
  5354. }
  5355. while (state.brackets > 0) {
  5356. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ']'));
  5357. state.output = utils$2.escapeLast(state.output, '[');
  5358. decrement('brackets');
  5359. }
  5360. while (state.parens > 0) {
  5361. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', ')'));
  5362. state.output = utils$2.escapeLast(state.output, '(');
  5363. decrement('parens');
  5364. }
  5365. while (state.braces > 0) {
  5366. if (opts.strictBrackets === true) throw new SyntaxError(syntaxError('closing', '}'));
  5367. state.output = utils$2.escapeLast(state.output, '{');
  5368. decrement('braces');
  5369. }
  5370. if (opts.strictSlashes !== true && (prev.type === 'star' || prev.type === 'bracket')) {
  5371. push({
  5372. type: 'maybe_slash',
  5373. value: '',
  5374. output: `${SLASH_LITERAL}?`
  5375. });
  5376. } // rebuild the output if we had to backtrack at any point
  5377. if (state.backtrack === true) {
  5378. state.output = '';
  5379. for (const token of state.tokens) {
  5380. state.output += token.output != null ? token.output : token.value;
  5381. if (token.suffix) {
  5382. state.output += token.suffix;
  5383. }
  5384. }
  5385. }
  5386. return state;
  5387. };
  5388. /**
  5389. * Fast paths for creating regular expressions for common glob patterns.
  5390. * This can significantly speed up processing and has very little downside
  5391. * impact when none of the fast paths match.
  5392. */
  5393. parse$1.fastpaths = (input, options) => {
  5394. const opts = Object.assign({}, options);
  5395. const max = typeof opts.maxLength === 'number' ? Math.min(MAX_LENGTH, opts.maxLength) : MAX_LENGTH;
  5396. const len = input.length;
  5397. if (len > max) {
  5398. throw new SyntaxError(`Input length: ${len}, exceeds maximum allowed length: ${max}`);
  5399. }
  5400. input = REPLACEMENTS[input] || input;
  5401. const win32 = utils$2.isWindows(options); // create constants based on platform, for windows or posix
  5402. const {
  5403. DOT_LITERAL,
  5404. SLASH_LITERAL,
  5405. ONE_CHAR,
  5406. DOTS_SLASH,
  5407. NO_DOT,
  5408. NO_DOTS,
  5409. NO_DOTS_SLASH,
  5410. STAR,
  5411. START_ANCHOR
  5412. } = constants$1.globChars(win32);
  5413. const nodot = opts.dot ? NO_DOTS : NO_DOT;
  5414. const slashDot = opts.dot ? NO_DOTS_SLASH : NO_DOT;
  5415. const capture = opts.capture ? '' : '?:';
  5416. const state = {
  5417. negated: false,
  5418. prefix: ''
  5419. };
  5420. let star = opts.bash === true ? '.*?' : STAR;
  5421. if (opts.capture) {
  5422. star = `(${star})`;
  5423. }
  5424. const globstar = opts => {
  5425. if (opts.noglobstar === true) return star;
  5426. return `(${capture}(?:(?!${START_ANCHOR}${opts.dot ? DOTS_SLASH : DOT_LITERAL}).)*?)`;
  5427. };
  5428. const create = str => {
  5429. switch (str) {
  5430. case '*':
  5431. return `${nodot}${ONE_CHAR}${star}`;
  5432. case '.*':
  5433. return `${DOT_LITERAL}${ONE_CHAR}${star}`;
  5434. case '*.*':
  5435. return `${nodot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
  5436. case '*/*':
  5437. return `${nodot}${star}${SLASH_LITERAL}${ONE_CHAR}${slashDot}${star}`;
  5438. case '**':
  5439. return nodot + globstar(opts);
  5440. case '**/*':
  5441. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${ONE_CHAR}${star}`;
  5442. case '**/*.*':
  5443. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${slashDot}${star}${DOT_LITERAL}${ONE_CHAR}${star}`;
  5444. case '**/.*':
  5445. return `(?:${nodot}${globstar(opts)}${SLASH_LITERAL})?${DOT_LITERAL}${ONE_CHAR}${star}`;
  5446. default:
  5447. {
  5448. const match = /^(.*?)\.(\w+)$/.exec(str);
  5449. if (!match) return;
  5450. const source = create(match[1]);
  5451. if (!source) return;
  5452. return source + DOT_LITERAL + match[2];
  5453. }
  5454. }
  5455. };
  5456. const output = utils$2.removePrefix(input, state);
  5457. let source = create(output);
  5458. if (source && opts.strictSlashes !== true) {
  5459. source += `${SLASH_LITERAL}?`;
  5460. }
  5461. return source;
  5462. };
  5463. var parse_1 = parse$1;
  5464. const isObject$1 = val => val && typeof val === 'object' && !Array.isArray(val);
  5465. /**
  5466. * Creates a matcher function from one or more glob patterns. The
  5467. * returned function takes a string to match as its first argument,
  5468. * and returns true if the string is a match. The returned matcher
  5469. * function also takes a boolean as the second argument that, when true,
  5470. * returns an object with additional information.
  5471. *
  5472. * ```js
  5473. * const picomatch = require('picomatch');
  5474. * // picomatch(glob[, options]);
  5475. *
  5476. * const isMatch = picomatch('*.!(*a)');
  5477. * console.log(isMatch('a.a')); //=> false
  5478. * console.log(isMatch('a.b')); //=> true
  5479. * ```
  5480. * @name picomatch
  5481. * @param {String|Array} `globs` One or more glob patterns.
  5482. * @param {Object=} `options`
  5483. * @return {Function=} Returns a matcher function.
  5484. * @api public
  5485. */
  5486. const picomatch$1 = (glob, options, returnState = false) => {
  5487. if (Array.isArray(glob)) {
  5488. const fns = glob.map(input => picomatch$1(input, options, returnState));
  5489. const arrayMatcher = str => {
  5490. for (const isMatch of fns) {
  5491. const state = isMatch(str);
  5492. if (state) return state;
  5493. }
  5494. return false;
  5495. };
  5496. return arrayMatcher;
  5497. }
  5498. const isState = isObject$1(glob) && glob.tokens && glob.input;
  5499. if (glob === '' || typeof glob !== 'string' && !isState) {
  5500. throw new TypeError('Expected pattern to be a non-empty string');
  5501. }
  5502. const opts = options || {};
  5503. const posix = utils$2.isWindows(options);
  5504. const regex = isState ? picomatch$1.compileRe(glob, options) : picomatch$1.makeRe(glob, options, false, true);
  5505. const state = regex.state;
  5506. delete regex.state;
  5507. let isIgnored = () => false;
  5508. if (opts.ignore) {
  5509. const ignoreOpts = Object.assign(Object.assign({}, options), {}, {
  5510. ignore: null,
  5511. onMatch: null,
  5512. onResult: null
  5513. });
  5514. isIgnored = picomatch$1(opts.ignore, ignoreOpts, returnState);
  5515. }
  5516. const matcher = (input, returnObject = false) => {
  5517. const {
  5518. isMatch,
  5519. match,
  5520. output
  5521. } = picomatch$1.test(input, regex, options, {
  5522. glob,
  5523. posix
  5524. });
  5525. const result = {
  5526. glob,
  5527. state,
  5528. regex,
  5529. posix,
  5530. input,
  5531. output,
  5532. match,
  5533. isMatch
  5534. };
  5535. if (typeof opts.onResult === 'function') {
  5536. opts.onResult(result);
  5537. }
  5538. if (isMatch === false) {
  5539. result.isMatch = false;
  5540. return returnObject ? result : false;
  5541. }
  5542. if (isIgnored(input)) {
  5543. if (typeof opts.onIgnore === 'function') {
  5544. opts.onIgnore(result);
  5545. }
  5546. result.isMatch = false;
  5547. return returnObject ? result : false;
  5548. }
  5549. if (typeof opts.onMatch === 'function') {
  5550. opts.onMatch(result);
  5551. }
  5552. return returnObject ? result : true;
  5553. };
  5554. if (returnState) {
  5555. matcher.state = state;
  5556. }
  5557. return matcher;
  5558. };
  5559. /**
  5560. * Test `input` with the given `regex`. This is used by the main
  5561. * `picomatch()` function to test the input string.
  5562. *
  5563. * ```js
  5564. * const picomatch = require('picomatch');
  5565. * // picomatch.test(input, regex[, options]);
  5566. *
  5567. * console.log(picomatch.test('foo/bar', /^(?:([^/]*?)\/([^/]*?))$/));
  5568. * // { isMatch: true, match: [ 'foo/', 'foo', 'bar' ], output: 'foo/bar' }
  5569. * ```
  5570. * @param {String} `input` String to test.
  5571. * @param {RegExp} `regex`
  5572. * @return {Object} Returns an object with matching info.
  5573. * @api public
  5574. */
  5575. picomatch$1.test = (input, regex, options, {
  5576. glob,
  5577. posix
  5578. } = {}) => {
  5579. if (typeof input !== 'string') {
  5580. throw new TypeError('Expected input to be a string');
  5581. }
  5582. if (input === '') {
  5583. return {
  5584. isMatch: false,
  5585. output: ''
  5586. };
  5587. }
  5588. const opts = options || {};
  5589. const format = opts.format || (posix ? utils$2.toPosixSlashes : null);
  5590. let match = input === glob;
  5591. let output = match && format ? format(input) : input;
  5592. if (match === false) {
  5593. output = format ? format(input) : input;
  5594. match = output === glob;
  5595. }
  5596. if (match === false || opts.capture === true) {
  5597. if (opts.matchBase === true || opts.basename === true) {
  5598. match = picomatch$1.matchBase(input, regex, options, posix);
  5599. } else {
  5600. match = regex.exec(output);
  5601. }
  5602. }
  5603. return {
  5604. isMatch: Boolean(match),
  5605. match,
  5606. output
  5607. };
  5608. };
  5609. /**
  5610. * Match the basename of a filepath.
  5611. *
  5612. * ```js
  5613. * const picomatch = require('picomatch');
  5614. * // picomatch.matchBase(input, glob[, options]);
  5615. * console.log(picomatch.matchBase('foo/bar.js', '*.js'); // true
  5616. * ```
  5617. * @param {String} `input` String to test.
  5618. * @param {RegExp|String} `glob` Glob pattern or regex created by [.makeRe](#makeRe).
  5619. * @return {Boolean}
  5620. * @api public
  5621. */
  5622. picomatch$1.matchBase = (input, glob, options, posix = utils$2.isWindows(options)) => {
  5623. const regex = glob instanceof RegExp ? glob : picomatch$1.makeRe(glob, options);
  5624. return regex.test(path__default['default'].basename(input));
  5625. };
  5626. /**
  5627. * Returns true if **any** of the given glob `patterns` match the specified `string`.
  5628. *
  5629. * ```js
  5630. * const picomatch = require('picomatch');
  5631. * // picomatch.isMatch(string, patterns[, options]);
  5632. *
  5633. * console.log(picomatch.isMatch('a.a', ['b.*', '*.a'])); //=> true
  5634. * console.log(picomatch.isMatch('a.a', 'b.*')); //=> false
  5635. * ```
  5636. * @param {String|Array} str The string to test.
  5637. * @param {String|Array} patterns One or more glob patterns to use for matching.
  5638. * @param {Object} [options] See available [options](#options).
  5639. * @return {Boolean} Returns true if any patterns match `str`
  5640. * @api public
  5641. */
  5642. picomatch$1.isMatch = (str, patterns, options) => picomatch$1(patterns, options)(str);
  5643. /**
  5644. * Parse a glob pattern to create the source string for a regular
  5645. * expression.
  5646. *
  5647. * ```js
  5648. * const picomatch = require('picomatch');
  5649. * const result = picomatch.parse(pattern[, options]);
  5650. * ```
  5651. * @param {String} `pattern`
  5652. * @param {Object} `options`
  5653. * @return {Object} Returns an object with useful properties and output to be used as a regex source string.
  5654. * @api public
  5655. */
  5656. picomatch$1.parse = (pattern, options) => {
  5657. if (Array.isArray(pattern)) return pattern.map(p => picomatch$1.parse(p, options));
  5658. return parse_1(pattern, Object.assign(Object.assign({}, options), {}, {
  5659. fastpaths: false
  5660. }));
  5661. };
  5662. /**
  5663. * Scan a glob pattern to separate the pattern into segments.
  5664. *
  5665. * ```js
  5666. * const picomatch = require('picomatch');
  5667. * // picomatch.scan(input[, options]);
  5668. *
  5669. * const result = picomatch.scan('!./foo/*.js');
  5670. * console.log(result);
  5671. * { prefix: '!./',
  5672. * input: '!./foo/*.js',
  5673. * start: 3,
  5674. * base: 'foo',
  5675. * glob: '*.js',
  5676. * isBrace: false,
  5677. * isBracket: false,
  5678. * isGlob: true,
  5679. * isExtglob: false,
  5680. * isGlobstar: false,
  5681. * negated: true }
  5682. * ```
  5683. * @param {String} `input` Glob pattern to scan.
  5684. * @param {Object} `options`
  5685. * @return {Object} Returns an object with
  5686. * @api public
  5687. */
  5688. picomatch$1.scan = (input, options) => scan_1(input, options);
  5689. /**
  5690. * Compile a regular expression from the `state` object returned by the
  5691. * [parse()](#parse) method.
  5692. *
  5693. * @param {Object} `state`
  5694. * @param {Object} `options`
  5695. * @param {Boolean} `returnOutput` Intended for implementors, this argument allows you to return the raw output from the parser.
  5696. * @param {Boolean} `returnState` Adds the state to a `state` property on the returned regex. Useful for implementors and debugging.
  5697. * @return {RegExp}
  5698. * @api public
  5699. */
  5700. picomatch$1.compileRe = (state, options, returnOutput = false, returnState = false) => {
  5701. if (returnOutput === true) {
  5702. return state.output;
  5703. }
  5704. const opts = options || {};
  5705. const prepend = opts.contains ? '' : '^';
  5706. const append = opts.contains ? '' : '$';
  5707. let source = `${prepend}(?:${state.output})${append}`;
  5708. if (state && state.negated === true) {
  5709. source = `^(?!${source}).*$`;
  5710. }
  5711. const regex = picomatch$1.toRegex(source, options);
  5712. if (returnState === true) {
  5713. regex.state = state;
  5714. }
  5715. return regex;
  5716. };
  5717. /**
  5718. * Create a regular expression from a parsed glob pattern.
  5719. *
  5720. * ```js
  5721. * const picomatch = require('picomatch');
  5722. * const state = picomatch.parse('*.js');
  5723. * // picomatch.compileRe(state[, options]);
  5724. *
  5725. * console.log(picomatch.compileRe(state));
  5726. * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
  5727. * ```
  5728. * @param {String} `state` The object returned from the `.parse` method.
  5729. * @param {Object} `options`
  5730. * @param {Boolean} `returnOutput` Implementors may use this argument to return the compiled output, instead of a regular expression. This is not exposed on the options to prevent end-users from mutating the result.
  5731. * @param {Boolean} `returnState` Implementors may use this argument to return the state from the parsed glob with the returned regular expression.
  5732. * @return {RegExp} Returns a regex created from the given pattern.
  5733. * @api public
  5734. */
  5735. picomatch$1.makeRe = (input, options = {}, returnOutput = false, returnState = false) => {
  5736. if (!input || typeof input !== 'string') {
  5737. throw new TypeError('Expected a non-empty string');
  5738. }
  5739. let parsed = {
  5740. negated: false,
  5741. fastpaths: true
  5742. };
  5743. if (options.fastpaths !== false && (input[0] === '.' || input[0] === '*')) {
  5744. parsed.output = parse_1.fastpaths(input, options);
  5745. }
  5746. if (!parsed.output) {
  5747. parsed = parse_1(input, options);
  5748. }
  5749. return picomatch$1.compileRe(parsed, options, returnOutput, returnState);
  5750. };
  5751. /**
  5752. * Create a regular expression from the given regex source string.
  5753. *
  5754. * ```js
  5755. * const picomatch = require('picomatch');
  5756. * // picomatch.toRegex(source[, options]);
  5757. *
  5758. * const { output } = picomatch.parse('*.js');
  5759. * console.log(picomatch.toRegex(output));
  5760. * //=> /^(?:(?!\.)(?=.)[^/]*?\.js)$/
  5761. * ```
  5762. * @param {String} `source` Regular expression source string.
  5763. * @param {Object} `options`
  5764. * @return {RegExp}
  5765. * @api public
  5766. */
  5767. picomatch$1.toRegex = (source, options) => {
  5768. try {
  5769. const opts = options || {};
  5770. return new RegExp(source, opts.flags || (opts.nocase ? 'i' : ''));
  5771. } catch (err) {
  5772. if (options && options.debug === true) throw err;
  5773. return /$^/;
  5774. }
  5775. };
  5776. /**
  5777. * Picomatch constants.
  5778. * @return {Object}
  5779. */
  5780. picomatch$1.constants = constants$1;
  5781. /**
  5782. * Expose "picomatch"
  5783. */
  5784. var picomatch_1 = picomatch$1;
  5785. var picomatch = picomatch_1;
  5786. const isEmptyString = val => val === '' || val === './';
  5787. /**
  5788. * Returns an array of strings that match one or more glob patterns.
  5789. *
  5790. * ```js
  5791. * const mm = require('micromatch');
  5792. * // mm(list, patterns[, options]);
  5793. *
  5794. * console.log(mm(['a.js', 'a.txt'], ['*.js']));
  5795. * //=> [ 'a.js' ]
  5796. * ```
  5797. * @param {String|Array<string>} `list` List of strings to match.
  5798. * @param {String|Array<string>} `patterns` One or more glob patterns to use for matching.
  5799. * @param {Object} `options` See available [options](#options)
  5800. * @return {Array} Returns an array of matches
  5801. * @summary false
  5802. * @api public
  5803. */
  5804. const micromatch = (list, patterns, options) => {
  5805. patterns = [].concat(patterns);
  5806. list = [].concat(list);
  5807. let omit = new Set();
  5808. let keep = new Set();
  5809. let items = new Set();
  5810. let negatives = 0;
  5811. let onResult = state => {
  5812. items.add(state.output);
  5813. if (options && options.onResult) {
  5814. options.onResult(state);
  5815. }
  5816. };
  5817. for (let i = 0; i < patterns.length; i++) {
  5818. let isMatch = picomatch(String(patterns[i]), Object.assign(Object.assign({}, options), {}, {
  5819. onResult
  5820. }), true);
  5821. let negated = isMatch.state.negated || isMatch.state.negatedExtglob;
  5822. if (negated) negatives++;
  5823. for (let item of list) {
  5824. let matched = isMatch(item, true);
  5825. let match = negated ? !matched.isMatch : matched.isMatch;
  5826. if (!match) continue;
  5827. if (negated) {
  5828. omit.add(matched.output);
  5829. } else {
  5830. omit.delete(matched.output);
  5831. keep.add(matched.output);
  5832. }
  5833. }
  5834. }
  5835. let result = negatives === patterns.length ? [...items] : [...keep];
  5836. let matches = result.filter(item => !omit.has(item));
  5837. if (options && matches.length === 0) {
  5838. if (options.failglob === true) {
  5839. throw new Error(`No matches found for "${patterns.join(', ')}"`);
  5840. }
  5841. if (options.nonull === true || options.nullglob === true) {
  5842. return options.unescape ? patterns.map(p => p.replace(/\\/g, '')) : patterns;
  5843. }
  5844. }
  5845. return matches;
  5846. };
  5847. /**
  5848. * Backwards compatibility
  5849. */
  5850. micromatch.match = micromatch;
  5851. /**
  5852. * Returns a matcher function from the given glob `pattern` and `options`.
  5853. * The returned function takes a string to match as its only argument and returns
  5854. * true if the string is a match.
  5855. *
  5856. * ```js
  5857. * const mm = require('micromatch');
  5858. * // mm.matcher(pattern[, options]);
  5859. *
  5860. * const isMatch = mm.matcher('*.!(*a)');
  5861. * console.log(isMatch('a.a')); //=> false
  5862. * console.log(isMatch('a.b')); //=> true
  5863. * ```
  5864. * @param {String} `pattern` Glob pattern
  5865. * @param {Object} `options`
  5866. * @return {Function} Returns a matcher function.
  5867. * @api public
  5868. */
  5869. micromatch.matcher = (pattern, options) => picomatch(pattern, options);
  5870. /**
  5871. * Returns true if **any** of the given glob `patterns` match the specified `string`.
  5872. *
  5873. * ```js
  5874. * const mm = require('micromatch');
  5875. * // mm.isMatch(string, patterns[, options]);
  5876. *
  5877. * console.log(mm.isMatch('a.a', ['b.*', '*.a'])); //=> true
  5878. * console.log(mm.isMatch('a.a', 'b.*')); //=> false
  5879. * ```
  5880. * @param {String} `str` The string to test.
  5881. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  5882. * @param {Object} `[options]` See available [options](#options).
  5883. * @return {Boolean} Returns true if any patterns match `str`
  5884. * @api public
  5885. */
  5886. micromatch.isMatch = (str, patterns, options) => picomatch(patterns, options)(str);
  5887. /**
  5888. * Backwards compatibility
  5889. */
  5890. micromatch.any = micromatch.isMatch;
  5891. /**
  5892. * Returns a list of strings that _**do not match any**_ of the given `patterns`.
  5893. *
  5894. * ```js
  5895. * const mm = require('micromatch');
  5896. * // mm.not(list, patterns[, options]);
  5897. *
  5898. * console.log(mm.not(['a.a', 'b.b', 'c.c'], '*.a'));
  5899. * //=> ['b.b', 'c.c']
  5900. * ```
  5901. * @param {Array} `list` Array of strings to match.
  5902. * @param {String|Array} `patterns` One or more glob pattern to use for matching.
  5903. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  5904. * @return {Array} Returns an array of strings that **do not match** the given patterns.
  5905. * @api public
  5906. */
  5907. micromatch.not = (list, patterns, options = {}) => {
  5908. patterns = [].concat(patterns).map(String);
  5909. let result = new Set();
  5910. let items = [];
  5911. let onResult = state => {
  5912. if (options.onResult) options.onResult(state);
  5913. items.push(state.output);
  5914. };
  5915. let matches = micromatch(list, patterns, Object.assign(Object.assign({}, options), {}, {
  5916. onResult
  5917. }));
  5918. for (let item of items) {
  5919. if (!matches.includes(item)) {
  5920. result.add(item);
  5921. }
  5922. }
  5923. return [...result];
  5924. };
  5925. /**
  5926. * Returns true if the given `string` contains the given pattern. Similar
  5927. * to [.isMatch](#isMatch) but the pattern can match any part of the string.
  5928. *
  5929. * ```js
  5930. * var mm = require('micromatch');
  5931. * // mm.contains(string, pattern[, options]);
  5932. *
  5933. * console.log(mm.contains('aa/bb/cc', '*b'));
  5934. * //=> true
  5935. * console.log(mm.contains('aa/bb/cc', '*d'));
  5936. * //=> false
  5937. * ```
  5938. * @param {String} `str` The string to match.
  5939. * @param {String|Array} `patterns` Glob pattern to use for matching.
  5940. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  5941. * @return {Boolean} Returns true if any of the patterns matches any part of `str`.
  5942. * @api public
  5943. */
  5944. micromatch.contains = (str, pattern, options) => {
  5945. if (typeof str !== 'string') {
  5946. throw new TypeError(`Expected a string: "${util__default['default'].inspect(str)}"`);
  5947. }
  5948. if (Array.isArray(pattern)) {
  5949. return pattern.some(p => micromatch.contains(str, p, options));
  5950. }
  5951. if (typeof pattern === 'string') {
  5952. if (isEmptyString(str) || isEmptyString(pattern)) {
  5953. return false;
  5954. }
  5955. if (str.includes(pattern) || str.startsWith('./') && str.slice(2).includes(pattern)) {
  5956. return true;
  5957. }
  5958. }
  5959. return micromatch.isMatch(str, pattern, Object.assign(Object.assign({}, options), {}, {
  5960. contains: true
  5961. }));
  5962. };
  5963. /**
  5964. * Filter the keys of the given object with the given `glob` pattern
  5965. * and `options`. Does not attempt to match nested keys. If you need this feature,
  5966. * use [glob-object][] instead.
  5967. *
  5968. * ```js
  5969. * const mm = require('micromatch');
  5970. * // mm.matchKeys(object, patterns[, options]);
  5971. *
  5972. * const obj = { aa: 'a', ab: 'b', ac: 'c' };
  5973. * console.log(mm.matchKeys(obj, '*b'));
  5974. * //=> { ab: 'b' }
  5975. * ```
  5976. * @param {Object} `object` The object with keys to filter.
  5977. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  5978. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  5979. * @return {Object} Returns an object with only keys that match the given patterns.
  5980. * @api public
  5981. */
  5982. micromatch.matchKeys = (obj, patterns, options) => {
  5983. if (!utils$2.isObject(obj)) {
  5984. throw new TypeError('Expected the first argument to be an object');
  5985. }
  5986. let keys = micromatch(Object.keys(obj), patterns, options);
  5987. let res = {};
  5988. for (let key of keys) res[key] = obj[key];
  5989. return res;
  5990. };
  5991. /**
  5992. * Returns true if some of the strings in the given `list` match any of the given glob `patterns`.
  5993. *
  5994. * ```js
  5995. * const mm = require('micromatch');
  5996. * // mm.some(list, patterns[, options]);
  5997. *
  5998. * console.log(mm.some(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
  5999. * // true
  6000. * console.log(mm.some(['foo.js'], ['*.js', '!foo.js']));
  6001. * // false
  6002. * ```
  6003. * @param {String|Array} `list` The string or array of strings to test. Returns as soon as the first match is found.
  6004. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  6005. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  6006. * @return {Boolean} Returns true if any `patterns` matches any of the strings in `list`
  6007. * @api public
  6008. */
  6009. micromatch.some = (list, patterns, options) => {
  6010. let items = [].concat(list);
  6011. for (let pattern of [].concat(patterns)) {
  6012. let isMatch = picomatch(String(pattern), options);
  6013. if (items.some(item => isMatch(item))) {
  6014. return true;
  6015. }
  6016. }
  6017. return false;
  6018. };
  6019. /**
  6020. * Returns true if every string in the given `list` matches
  6021. * any of the given glob `patterns`.
  6022. *
  6023. * ```js
  6024. * const mm = require('micromatch');
  6025. * // mm.every(list, patterns[, options]);
  6026. *
  6027. * console.log(mm.every('foo.js', ['foo.js']));
  6028. * // true
  6029. * console.log(mm.every(['foo.js', 'bar.js'], ['*.js']));
  6030. * // true
  6031. * console.log(mm.every(['foo.js', 'bar.js'], ['*.js', '!foo.js']));
  6032. * // false
  6033. * console.log(mm.every(['foo.js'], ['*.js', '!foo.js']));
  6034. * // false
  6035. * ```
  6036. * @param {String|Array} `list` The string or array of strings to test.
  6037. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  6038. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  6039. * @return {Boolean} Returns true if all `patterns` matches all of the strings in `list`
  6040. * @api public
  6041. */
  6042. micromatch.every = (list, patterns, options) => {
  6043. let items = [].concat(list);
  6044. for (let pattern of [].concat(patterns)) {
  6045. let isMatch = picomatch(String(pattern), options);
  6046. if (!items.every(item => isMatch(item))) {
  6047. return false;
  6048. }
  6049. }
  6050. return true;
  6051. };
  6052. /**
  6053. * Returns true if **all** of the given `patterns` match
  6054. * the specified string.
  6055. *
  6056. * ```js
  6057. * const mm = require('micromatch');
  6058. * // mm.all(string, patterns[, options]);
  6059. *
  6060. * console.log(mm.all('foo.js', ['foo.js']));
  6061. * // true
  6062. *
  6063. * console.log(mm.all('foo.js', ['*.js', '!foo.js']));
  6064. * // false
  6065. *
  6066. * console.log(mm.all('foo.js', ['*.js', 'foo.js']));
  6067. * // true
  6068. *
  6069. * console.log(mm.all('foo.js', ['*.js', 'f*', '*o*', '*o.js']));
  6070. * // true
  6071. * ```
  6072. * @param {String|Array} `str` The string to test.
  6073. * @param {String|Array} `patterns` One or more glob patterns to use for matching.
  6074. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  6075. * @return {Boolean} Returns true if any patterns match `str`
  6076. * @api public
  6077. */
  6078. micromatch.all = (str, patterns, options) => {
  6079. if (typeof str !== 'string') {
  6080. throw new TypeError(`Expected a string: "${util__default['default'].inspect(str)}"`);
  6081. }
  6082. return [].concat(patterns).every(p => picomatch(p, options)(str));
  6083. };
  6084. /**
  6085. * Returns an array of matches captured by `pattern` in `string, or `null` if the pattern did not match.
  6086. *
  6087. * ```js
  6088. * const mm = require('micromatch');
  6089. * // mm.capture(pattern, string[, options]);
  6090. *
  6091. * console.log(mm.capture('test/*.js', 'test/foo.js'));
  6092. * //=> ['foo']
  6093. * console.log(mm.capture('test/*.js', 'foo/bar.css'));
  6094. * //=> null
  6095. * ```
  6096. * @param {String} `glob` Glob pattern to use for matching.
  6097. * @param {String} `input` String to match
  6098. * @param {Object} `options` See available [options](#options) for changing how matches are performed
  6099. * @return {Array|null} Returns an array of captures if the input matches the glob pattern, otherwise `null`.
  6100. * @api public
  6101. */
  6102. micromatch.capture = (glob, input, options) => {
  6103. let posix = utils$2.isWindows(options);
  6104. let regex = picomatch.makeRe(String(glob), Object.assign(Object.assign({}, options), {}, {
  6105. capture: true
  6106. }));
  6107. let match = regex.exec(posix ? utils$2.toPosixSlashes(input) : input);
  6108. if (match) {
  6109. return match.slice(1).map(v => v === void 0 ? '' : v);
  6110. }
  6111. };
  6112. /**
  6113. * Create a regular expression from the given glob `pattern`.
  6114. *
  6115. * ```js
  6116. * const mm = require('micromatch');
  6117. * // mm.makeRe(pattern[, options]);
  6118. *
  6119. * console.log(mm.makeRe('*.js'));
  6120. * //=> /^(?:(\.[\\\/])?(?!\.)(?=.)[^\/]*?\.js)$/
  6121. * ```
  6122. * @param {String} `pattern` A glob pattern to convert to regex.
  6123. * @param {Object} `options`
  6124. * @return {RegExp} Returns a regex created from the given pattern.
  6125. * @api public
  6126. */
  6127. micromatch.makeRe = (...args) => picomatch.makeRe(...args);
  6128. /**
  6129. * Scan a glob pattern to separate the pattern into segments. Used
  6130. * by the [split](#split) method.
  6131. *
  6132. * ```js
  6133. * const mm = require('micromatch');
  6134. * const state = mm.scan(pattern[, options]);
  6135. * ```
  6136. * @param {String} `pattern`
  6137. * @param {Object} `options`
  6138. * @return {Object} Returns an object with
  6139. * @api public
  6140. */
  6141. micromatch.scan = (...args) => picomatch.scan(...args);
  6142. /**
  6143. * Parse a glob pattern to create the source string for a regular
  6144. * expression.
  6145. *
  6146. * ```js
  6147. * const mm = require('micromatch');
  6148. * const state = mm(pattern[, options]);
  6149. * ```
  6150. * @param {String} `glob`
  6151. * @param {Object} `options`
  6152. * @return {Object} Returns an object with useful properties and output to be used as regex source string.
  6153. * @api public
  6154. */
  6155. micromatch.parse = (patterns, options) => {
  6156. let res = [];
  6157. for (let pattern of [].concat(patterns || [])) {
  6158. for (let str of braces_1(String(pattern), options)) {
  6159. res.push(picomatch.parse(str, options));
  6160. }
  6161. }
  6162. return res;
  6163. };
  6164. /**
  6165. * Process the given brace `pattern`.
  6166. *
  6167. * ```js
  6168. * const { braces } = require('micromatch');
  6169. * console.log(braces('foo/{a,b,c}/bar'));
  6170. * //=> [ 'foo/(a|b|c)/bar' ]
  6171. *
  6172. * console.log(braces('foo/{a,b,c}/bar', { expand: true }));
  6173. * //=> [ 'foo/a/bar', 'foo/b/bar', 'foo/c/bar' ]
  6174. * ```
  6175. * @param {String} `pattern` String with brace pattern to process.
  6176. * @param {Object} `options` Any [options](#options) to change how expansion is performed. See the [braces][] library for all available options.
  6177. * @return {Array}
  6178. * @api public
  6179. */
  6180. micromatch.braces = (pattern, options) => {
  6181. if (typeof pattern !== 'string') throw new TypeError('Expected a string');
  6182. if (options && options.nobrace === true || !/\{.*\}/.test(pattern)) {
  6183. return [pattern];
  6184. }
  6185. return braces_1(pattern, options);
  6186. };
  6187. /**
  6188. * Expand braces
  6189. */
  6190. micromatch.braceExpand = (pattern, options) => {
  6191. if (typeof pattern !== 'string') throw new TypeError('Expected a string');
  6192. return micromatch.braces(pattern, Object.assign(Object.assign({}, options), {}, {
  6193. expand: true
  6194. }));
  6195. };
  6196. /**
  6197. * Expose micromatch
  6198. */
  6199. var micromatch_1 = micromatch;
  6200. var pattern = createCommonjsModule(function (module, exports) {
  6201. Object.defineProperty(exports, "__esModule", {
  6202. value: true
  6203. });
  6204. exports.matchAny = exports.convertPatternsToRe = exports.makeRe = exports.getPatternParts = exports.expandBraceExpansion = exports.expandPatternsWithBraceExpansion = exports.isAffectDepthOfReadingPattern = exports.endsWithSlashGlobStar = exports.hasGlobStar = exports.getBaseDirectory = exports.isPatternRelatedToParentDirectory = exports.getPatternsOutsideCurrentDirectory = exports.getPatternsInsideCurrentDirectory = exports.getPositivePatterns = exports.getNegativePatterns = exports.isPositivePattern = exports.isNegativePattern = exports.convertToNegativePattern = exports.convertToPositivePattern = exports.isDynamicPattern = exports.isStaticPattern = void 0;
  6205. const GLOBSTAR = '**';
  6206. const ESCAPE_SYMBOL = '\\';
  6207. const COMMON_GLOB_SYMBOLS_RE = /[*?]|^!/;
  6208. const REGEX_CHARACTER_CLASS_SYMBOLS_RE = /\[.*]/;
  6209. const REGEX_GROUP_SYMBOLS_RE = /(?:^|[^!*+?@])\(.*\|.*\)/;
  6210. const GLOB_EXTENSION_SYMBOLS_RE = /[!*+?@]\(.*\)/;
  6211. const BRACE_EXPANSIONS_SYMBOLS_RE = /{.*(?:,|\.\.).*}/;
  6212. function isStaticPattern(pattern, options = {}) {
  6213. return !isDynamicPattern(pattern, options);
  6214. }
  6215. exports.isStaticPattern = isStaticPattern;
  6216. function isDynamicPattern(pattern, options = {}) {
  6217. /**
  6218. * A special case with an empty string is necessary for matching patterns that start with a forward slash.
  6219. * An empty string cannot be a dynamic pattern.
  6220. * For example, the pattern `/lib/*` will be spread into parts: '', 'lib', '*'.
  6221. */
  6222. if (pattern === '') {
  6223. return false;
  6224. }
  6225. /**
  6226. * When the `caseSensitiveMatch` option is disabled, all patterns must be marked as dynamic, because we cannot check
  6227. * filepath directly (without read directory).
  6228. */
  6229. if (options.caseSensitiveMatch === false || pattern.includes(ESCAPE_SYMBOL)) {
  6230. return true;
  6231. }
  6232. if (COMMON_GLOB_SYMBOLS_RE.test(pattern) || REGEX_CHARACTER_CLASS_SYMBOLS_RE.test(pattern) || REGEX_GROUP_SYMBOLS_RE.test(pattern)) {
  6233. return true;
  6234. }
  6235. if (options.extglob !== false && GLOB_EXTENSION_SYMBOLS_RE.test(pattern)) {
  6236. return true;
  6237. }
  6238. if (options.braceExpansion !== false && BRACE_EXPANSIONS_SYMBOLS_RE.test(pattern)) {
  6239. return true;
  6240. }
  6241. return false;
  6242. }
  6243. exports.isDynamicPattern = isDynamicPattern;
  6244. function convertToPositivePattern(pattern) {
  6245. return isNegativePattern(pattern) ? pattern.slice(1) : pattern;
  6246. }
  6247. exports.convertToPositivePattern = convertToPositivePattern;
  6248. function convertToNegativePattern(pattern) {
  6249. return '!' + pattern;
  6250. }
  6251. exports.convertToNegativePattern = convertToNegativePattern;
  6252. function isNegativePattern(pattern) {
  6253. return pattern.startsWith('!') && pattern[1] !== '(';
  6254. }
  6255. exports.isNegativePattern = isNegativePattern;
  6256. function isPositivePattern(pattern) {
  6257. return !isNegativePattern(pattern);
  6258. }
  6259. exports.isPositivePattern = isPositivePattern;
  6260. function getNegativePatterns(patterns) {
  6261. return patterns.filter(isNegativePattern);
  6262. }
  6263. exports.getNegativePatterns = getNegativePatterns;
  6264. function getPositivePatterns(patterns) {
  6265. return patterns.filter(isPositivePattern);
  6266. }
  6267. exports.getPositivePatterns = getPositivePatterns;
  6268. /**
  6269. * Returns patterns that can be applied inside the current directory.
  6270. *
  6271. * @example
  6272. * // ['./*', '*', 'a/*']
  6273. * getPatternsInsideCurrentDirectory(['./*', '*', 'a/*', '../*', './../*'])
  6274. */
  6275. function getPatternsInsideCurrentDirectory(patterns) {
  6276. return patterns.filter(pattern => !isPatternRelatedToParentDirectory(pattern));
  6277. }
  6278. exports.getPatternsInsideCurrentDirectory = getPatternsInsideCurrentDirectory;
  6279. /**
  6280. * Returns patterns to be expanded relative to (outside) the current directory.
  6281. *
  6282. * @example
  6283. * // ['../*', './../*']
  6284. * getPatternsInsideCurrentDirectory(['./*', '*', 'a/*', '../*', './../*'])
  6285. */
  6286. function getPatternsOutsideCurrentDirectory(patterns) {
  6287. return patterns.filter(isPatternRelatedToParentDirectory);
  6288. }
  6289. exports.getPatternsOutsideCurrentDirectory = getPatternsOutsideCurrentDirectory;
  6290. function isPatternRelatedToParentDirectory(pattern) {
  6291. return pattern.startsWith('..') || pattern.startsWith('./..');
  6292. }
  6293. exports.isPatternRelatedToParentDirectory = isPatternRelatedToParentDirectory;
  6294. function getBaseDirectory(pattern) {
  6295. return globParent(pattern, {
  6296. flipBackslashes: false
  6297. });
  6298. }
  6299. exports.getBaseDirectory = getBaseDirectory;
  6300. function hasGlobStar(pattern) {
  6301. return pattern.includes(GLOBSTAR);
  6302. }
  6303. exports.hasGlobStar = hasGlobStar;
  6304. function endsWithSlashGlobStar(pattern) {
  6305. return pattern.endsWith('/' + GLOBSTAR);
  6306. }
  6307. exports.endsWithSlashGlobStar = endsWithSlashGlobStar;
  6308. function isAffectDepthOfReadingPattern(pattern) {
  6309. const basename = path__default['default'].basename(pattern);
  6310. return endsWithSlashGlobStar(pattern) || isStaticPattern(basename);
  6311. }
  6312. exports.isAffectDepthOfReadingPattern = isAffectDepthOfReadingPattern;
  6313. function expandPatternsWithBraceExpansion(patterns) {
  6314. return patterns.reduce((collection, pattern) => {
  6315. return collection.concat(expandBraceExpansion(pattern));
  6316. }, []);
  6317. }
  6318. exports.expandPatternsWithBraceExpansion = expandPatternsWithBraceExpansion;
  6319. function expandBraceExpansion(pattern) {
  6320. return micromatch_1.braces(pattern, {
  6321. expand: true,
  6322. nodupes: true
  6323. });
  6324. }
  6325. exports.expandBraceExpansion = expandBraceExpansion;
  6326. function getPatternParts(pattern, options) {
  6327. let {
  6328. parts
  6329. } = micromatch_1.scan(pattern, Object.assign(Object.assign({}, options), {
  6330. parts: true
  6331. }));
  6332. /**
  6333. * The scan method returns an empty array in some cases.
  6334. * See micromatch/picomatch#58 for more details.
  6335. */
  6336. if (parts.length === 0) {
  6337. parts = [pattern];
  6338. }
  6339. /**
  6340. * The scan method does not return an empty part for the pattern with a forward slash.
  6341. * This is another part of micromatch/picomatch#58.
  6342. */
  6343. if (parts[0].startsWith('/')) {
  6344. parts[0] = parts[0].slice(1);
  6345. parts.unshift('');
  6346. }
  6347. return parts;
  6348. }
  6349. exports.getPatternParts = getPatternParts;
  6350. function makeRe(pattern, options) {
  6351. return micromatch_1.makeRe(pattern, options);
  6352. }
  6353. exports.makeRe = makeRe;
  6354. function convertPatternsToRe(patterns, options) {
  6355. return patterns.map(pattern => makeRe(pattern, options));
  6356. }
  6357. exports.convertPatternsToRe = convertPatternsToRe;
  6358. function matchAny(entry, patternsRe) {
  6359. return patternsRe.some(patternRe => patternRe.test(entry));
  6360. }
  6361. exports.matchAny = matchAny;
  6362. });
  6363. /*
  6364. * merge2
  6365. * https://github.com/teambition/merge2
  6366. *
  6367. * Copyright (c) 2014-2020 Teambition
  6368. * Licensed under the MIT license.
  6369. */
  6370. const PassThrough = stream_1__default['default'].PassThrough;
  6371. const slice = Array.prototype.slice;
  6372. var merge2_1 = merge2;
  6373. function merge2() {
  6374. const streamsQueue = [];
  6375. const args = slice.call(arguments);
  6376. let merging = false;
  6377. let options = args[args.length - 1];
  6378. if (options && !Array.isArray(options) && options.pipe == null) {
  6379. args.pop();
  6380. } else {
  6381. options = {};
  6382. }
  6383. const doEnd = options.end !== false;
  6384. const doPipeError = options.pipeError === true;
  6385. if (options.objectMode == null) {
  6386. options.objectMode = true;
  6387. }
  6388. if (options.highWaterMark == null) {
  6389. options.highWaterMark = 64 * 1024;
  6390. }
  6391. const mergedStream = PassThrough(options);
  6392. function addStream() {
  6393. for (let i = 0, len = arguments.length; i < len; i++) {
  6394. streamsQueue.push(pauseStreams(arguments[i], options));
  6395. }
  6396. mergeStream();
  6397. return this;
  6398. }
  6399. function mergeStream() {
  6400. if (merging) {
  6401. return;
  6402. }
  6403. merging = true;
  6404. let streams = streamsQueue.shift();
  6405. if (!streams) {
  6406. process.nextTick(endStream);
  6407. return;
  6408. }
  6409. if (!Array.isArray(streams)) {
  6410. streams = [streams];
  6411. }
  6412. let pipesCount = streams.length + 1;
  6413. function next() {
  6414. if (--pipesCount > 0) {
  6415. return;
  6416. }
  6417. merging = false;
  6418. mergeStream();
  6419. }
  6420. function pipe(stream) {
  6421. function onend() {
  6422. stream.removeListener('merge2UnpipeEnd', onend);
  6423. stream.removeListener('end', onend);
  6424. if (doPipeError) {
  6425. stream.removeListener('error', onerror);
  6426. }
  6427. next();
  6428. }
  6429. function onerror(err) {
  6430. mergedStream.emit('error', err);
  6431. } // skip ended stream
  6432. if (stream._readableState.endEmitted) {
  6433. return next();
  6434. }
  6435. stream.on('merge2UnpipeEnd', onend);
  6436. stream.on('end', onend);
  6437. if (doPipeError) {
  6438. stream.on('error', onerror);
  6439. }
  6440. stream.pipe(mergedStream, {
  6441. end: false
  6442. }); // compatible for old stream
  6443. stream.resume();
  6444. }
  6445. for (let i = 0; i < streams.length; i++) {
  6446. pipe(streams[i]);
  6447. }
  6448. next();
  6449. }
  6450. function endStream() {
  6451. merging = false; // emit 'queueDrain' when all streams merged.
  6452. mergedStream.emit('queueDrain');
  6453. if (doEnd) {
  6454. mergedStream.end();
  6455. }
  6456. }
  6457. mergedStream.setMaxListeners(0);
  6458. mergedStream.add = addStream;
  6459. mergedStream.on('unpipe', function (stream) {
  6460. stream.emit('merge2UnpipeEnd');
  6461. });
  6462. if (args.length) {
  6463. addStream.apply(null, args);
  6464. }
  6465. return mergedStream;
  6466. } // check and pause streams for pipe.
  6467. function pauseStreams(streams, options) {
  6468. if (!Array.isArray(streams)) {
  6469. // Backwards-compat with old-style streams
  6470. if (!streams._readableState && streams.pipe) {
  6471. streams = streams.pipe(PassThrough(options));
  6472. }
  6473. if (!streams._readableState || !streams.pause || !streams.pipe) {
  6474. throw new Error('Only readable stream can be merged.');
  6475. }
  6476. streams.pause();
  6477. } else {
  6478. for (let i = 0, len = streams.length; i < len; i++) {
  6479. streams[i] = pauseStreams(streams[i], options);
  6480. }
  6481. }
  6482. return streams;
  6483. }
  6484. var stream$3 = createCommonjsModule(function (module, exports) {
  6485. Object.defineProperty(exports, "__esModule", {
  6486. value: true
  6487. });
  6488. exports.merge = void 0;
  6489. function merge(streams) {
  6490. const mergedStream = merge2_1(streams);
  6491. streams.forEach(stream => {
  6492. stream.once('error', error => mergedStream.emit('error', error));
  6493. });
  6494. mergedStream.once('close', () => propagateCloseEventToSources(streams));
  6495. mergedStream.once('end', () => propagateCloseEventToSources(streams));
  6496. return mergedStream;
  6497. }
  6498. exports.merge = merge;
  6499. function propagateCloseEventToSources(streams) {
  6500. streams.forEach(stream => stream.emit('close'));
  6501. }
  6502. });
  6503. var string = createCommonjsModule(function (module, exports) {
  6504. Object.defineProperty(exports, "__esModule", {
  6505. value: true
  6506. });
  6507. exports.isEmpty = exports.isString = void 0;
  6508. function isString(input) {
  6509. return typeof input === 'string';
  6510. }
  6511. exports.isString = isString;
  6512. function isEmpty(input) {
  6513. return input === '';
  6514. }
  6515. exports.isEmpty = isEmpty;
  6516. });
  6517. var utils$1 = createCommonjsModule(function (module, exports) {
  6518. Object.defineProperty(exports, "__esModule", {
  6519. value: true
  6520. });
  6521. exports.string = exports.stream = exports.pattern = exports.path = exports.fs = exports.errno = exports.array = void 0;
  6522. exports.array = array$2;
  6523. exports.errno = errno;
  6524. exports.fs = fs$3;
  6525. exports.path = path_1;
  6526. exports.pattern = pattern;
  6527. exports.stream = stream$3;
  6528. exports.string = string;
  6529. });
  6530. var tasks = createCommonjsModule(function (module, exports) {
  6531. Object.defineProperty(exports, "__esModule", {
  6532. value: true
  6533. });
  6534. exports.convertPatternGroupToTask = exports.convertPatternGroupsToTasks = exports.groupPatternsByBaseDirectory = exports.getNegativePatternsAsPositive = exports.getPositivePatterns = exports.convertPatternsToTasks = exports.generate = void 0;
  6535. function generate(patterns, settings) {
  6536. const positivePatterns = getPositivePatterns(patterns);
  6537. const negativePatterns = getNegativePatternsAsPositive(patterns, settings.ignore);
  6538. const staticPatterns = positivePatterns.filter(pattern => utils$1.pattern.isStaticPattern(pattern, settings));
  6539. const dynamicPatterns = positivePatterns.filter(pattern => utils$1.pattern.isDynamicPattern(pattern, settings));
  6540. const staticTasks = convertPatternsToTasks(staticPatterns, negativePatterns,
  6541. /* dynamic */
  6542. false);
  6543. const dynamicTasks = convertPatternsToTasks(dynamicPatterns, negativePatterns,
  6544. /* dynamic */
  6545. true);
  6546. return staticTasks.concat(dynamicTasks);
  6547. }
  6548. exports.generate = generate;
  6549. /**
  6550. * Returns tasks grouped by basic pattern directories.
  6551. *
  6552. * Patterns that can be found inside (`./`) and outside (`../`) the current directory are handled separately.
  6553. * This is necessary because directory traversal starts at the base directory and goes deeper.
  6554. */
  6555. function convertPatternsToTasks(positive, negative, dynamic) {
  6556. const tasks = [];
  6557. const patternsOutsideCurrentDirectory = utils$1.pattern.getPatternsOutsideCurrentDirectory(positive);
  6558. const patternsInsideCurrentDirectory = utils$1.pattern.getPatternsInsideCurrentDirectory(positive);
  6559. const outsideCurrentDirectoryGroup = groupPatternsByBaseDirectory(patternsOutsideCurrentDirectory);
  6560. const insideCurrentDirectoryGroup = groupPatternsByBaseDirectory(patternsInsideCurrentDirectory);
  6561. tasks.push(...convertPatternGroupsToTasks(outsideCurrentDirectoryGroup, negative, dynamic));
  6562. /*
  6563. * For the sake of reducing future accesses to the file system, we merge all tasks within the current directory
  6564. * into a global task, if at least one pattern refers to the root (`.`). In this case, the global task covers the rest.
  6565. */
  6566. if ('.' in insideCurrentDirectoryGroup) {
  6567. tasks.push(convertPatternGroupToTask('.', patternsInsideCurrentDirectory, negative, dynamic));
  6568. } else {
  6569. tasks.push(...convertPatternGroupsToTasks(insideCurrentDirectoryGroup, negative, dynamic));
  6570. }
  6571. return tasks;
  6572. }
  6573. exports.convertPatternsToTasks = convertPatternsToTasks;
  6574. function getPositivePatterns(patterns) {
  6575. return utils$1.pattern.getPositivePatterns(patterns);
  6576. }
  6577. exports.getPositivePatterns = getPositivePatterns;
  6578. function getNegativePatternsAsPositive(patterns, ignore) {
  6579. const negative = utils$1.pattern.getNegativePatterns(patterns).concat(ignore);
  6580. const positive = negative.map(utils$1.pattern.convertToPositivePattern);
  6581. return positive;
  6582. }
  6583. exports.getNegativePatternsAsPositive = getNegativePatternsAsPositive;
  6584. function groupPatternsByBaseDirectory(patterns) {
  6585. const group = {};
  6586. return patterns.reduce((collection, pattern) => {
  6587. const base = utils$1.pattern.getBaseDirectory(pattern);
  6588. if (base in collection) {
  6589. collection[base].push(pattern);
  6590. } else {
  6591. collection[base] = [pattern];
  6592. }
  6593. return collection;
  6594. }, group);
  6595. }
  6596. exports.groupPatternsByBaseDirectory = groupPatternsByBaseDirectory;
  6597. function convertPatternGroupsToTasks(positive, negative, dynamic) {
  6598. return Object.keys(positive).map(base => {
  6599. return convertPatternGroupToTask(base, positive[base], negative, dynamic);
  6600. });
  6601. }
  6602. exports.convertPatternGroupsToTasks = convertPatternGroupsToTasks;
  6603. function convertPatternGroupToTask(base, positive, negative, dynamic) {
  6604. return {
  6605. dynamic,
  6606. positive,
  6607. negative,
  6608. base,
  6609. patterns: [].concat(positive, negative.map(utils$1.pattern.convertToNegativePattern))
  6610. };
  6611. }
  6612. exports.convertPatternGroupToTask = convertPatternGroupToTask;
  6613. });
  6614. var async$4 = createCommonjsModule(function (module, exports) {
  6615. Object.defineProperty(exports, "__esModule", {
  6616. value: true
  6617. });
  6618. exports.read = void 0;
  6619. function read(path, settings, callback) {
  6620. settings.fs.lstat(path, (lstatError, lstat) => {
  6621. if (lstatError !== null) {
  6622. callFailureCallback(callback, lstatError);
  6623. return;
  6624. }
  6625. if (!lstat.isSymbolicLink() || !settings.followSymbolicLink) {
  6626. callSuccessCallback(callback, lstat);
  6627. return;
  6628. }
  6629. settings.fs.stat(path, (statError, stat) => {
  6630. if (statError !== null) {
  6631. if (settings.throwErrorOnBrokenSymbolicLink) {
  6632. callFailureCallback(callback, statError);
  6633. return;
  6634. }
  6635. callSuccessCallback(callback, lstat);
  6636. return;
  6637. }
  6638. if (settings.markSymbolicLink) {
  6639. stat.isSymbolicLink = () => true;
  6640. }
  6641. callSuccessCallback(callback, stat);
  6642. });
  6643. });
  6644. }
  6645. exports.read = read;
  6646. function callFailureCallback(callback, error) {
  6647. callback(error);
  6648. }
  6649. function callSuccessCallback(callback, result) {
  6650. callback(null, result);
  6651. }
  6652. });
  6653. var sync$5 = createCommonjsModule(function (module, exports) {
  6654. Object.defineProperty(exports, "__esModule", {
  6655. value: true
  6656. });
  6657. exports.read = void 0;
  6658. function read(path, settings) {
  6659. const lstat = settings.fs.lstatSync(path);
  6660. if (!lstat.isSymbolicLink() || !settings.followSymbolicLink) {
  6661. return lstat;
  6662. }
  6663. try {
  6664. const stat = settings.fs.statSync(path);
  6665. if (settings.markSymbolicLink) {
  6666. stat.isSymbolicLink = () => true;
  6667. }
  6668. return stat;
  6669. } catch (error) {
  6670. if (!settings.throwErrorOnBrokenSymbolicLink) {
  6671. return lstat;
  6672. }
  6673. throw error;
  6674. }
  6675. }
  6676. exports.read = read;
  6677. });
  6678. var fs_1$1 = createCommonjsModule(function (module, exports) {
  6679. Object.defineProperty(exports, "__esModule", {
  6680. value: true
  6681. });
  6682. exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
  6683. exports.FILE_SYSTEM_ADAPTER = {
  6684. lstat: fs__default['default'].lstat,
  6685. stat: fs__default['default'].stat,
  6686. lstatSync: fs__default['default'].lstatSync,
  6687. statSync: fs__default['default'].statSync
  6688. };
  6689. function createFileSystemAdapter(fsMethods) {
  6690. if (fsMethods === undefined) {
  6691. return exports.FILE_SYSTEM_ADAPTER;
  6692. }
  6693. return Object.assign(Object.assign({}, exports.FILE_SYSTEM_ADAPTER), fsMethods);
  6694. }
  6695. exports.createFileSystemAdapter = createFileSystemAdapter;
  6696. });
  6697. class Settings$2 {
  6698. constructor(_options = {}) {
  6699. this._options = _options;
  6700. this.followSymbolicLink = this._getValue(this._options.followSymbolicLink, true);
  6701. this.fs = fs_1$1.createFileSystemAdapter(this._options.fs);
  6702. this.markSymbolicLink = this._getValue(this._options.markSymbolicLink, false);
  6703. this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
  6704. }
  6705. _getValue(option, value) {
  6706. return option !== null && option !== void 0 ? option : value;
  6707. }
  6708. }
  6709. var _default$m = Settings$2;
  6710. var settings$3 = /*#__PURE__*/Object.defineProperty({
  6711. default: _default$m
  6712. }, '__esModule', {
  6713. value: true
  6714. });
  6715. var out$3 = createCommonjsModule(function (module, exports) {
  6716. Object.defineProperty(exports, "__esModule", {
  6717. value: true
  6718. });
  6719. exports.statSync = exports.stat = exports.Settings = void 0;
  6720. exports.Settings = settings$3.default;
  6721. function stat(path, optionsOrSettingsOrCallback, callback) {
  6722. if (typeof optionsOrSettingsOrCallback === 'function') {
  6723. async$4.read(path, getSettings(), optionsOrSettingsOrCallback);
  6724. return;
  6725. }
  6726. async$4.read(path, getSettings(optionsOrSettingsOrCallback), callback);
  6727. }
  6728. exports.stat = stat;
  6729. function statSync(path, optionsOrSettings) {
  6730. const settings = getSettings(optionsOrSettings);
  6731. return sync$5.read(path, settings);
  6732. }
  6733. exports.statSync = statSync;
  6734. function getSettings(settingsOrOptions = {}) {
  6735. if (settingsOrOptions instanceof settings$3.default) {
  6736. return settingsOrOptions;
  6737. }
  6738. return new settings$3.default(settingsOrOptions);
  6739. }
  6740. });
  6741. /*! queue-microtask. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
  6742. let promise$1;
  6743. var queueMicrotask_1 = typeof queueMicrotask === 'function' ? queueMicrotask.bind(typeof window !== 'undefined' ? window : global) // reuse resolved promise, and allocate it lazily
  6744. : cb => (promise$1 || (promise$1 = Promise.resolve())).then(cb).catch(err => setTimeout(() => {
  6745. throw err;
  6746. }, 0));
  6747. /*! run-parallel. MIT License. Feross Aboukhadijeh <https://feross.org/opensource> */
  6748. var runParallel_1 = runParallel;
  6749. function runParallel(tasks, cb) {
  6750. let results, pending, keys;
  6751. let isSync = true;
  6752. if (Array.isArray(tasks)) {
  6753. results = [];
  6754. pending = tasks.length;
  6755. } else {
  6756. keys = Object.keys(tasks);
  6757. results = {};
  6758. pending = keys.length;
  6759. }
  6760. function done(err) {
  6761. function end() {
  6762. if (cb) cb(err, results);
  6763. cb = null;
  6764. }
  6765. if (isSync) queueMicrotask_1(end);else end();
  6766. }
  6767. function each(i, err, result) {
  6768. results[i] = result;
  6769. if (--pending === 0 || err) {
  6770. done(err);
  6771. }
  6772. }
  6773. if (!pending) {
  6774. // empty
  6775. done(null);
  6776. } else if (keys) {
  6777. // object
  6778. keys.forEach(function (key) {
  6779. tasks[key](function (err, result) {
  6780. each(key, err, result);
  6781. });
  6782. });
  6783. } else {
  6784. // array
  6785. tasks.forEach(function (task, i) {
  6786. task(function (err, result) {
  6787. each(i, err, result);
  6788. });
  6789. });
  6790. }
  6791. isSync = false;
  6792. }
  6793. var constants = createCommonjsModule(function (module, exports) {
  6794. Object.defineProperty(exports, "__esModule", {
  6795. value: true
  6796. });
  6797. exports.IS_SUPPORT_READDIR_WITH_FILE_TYPES = void 0;
  6798. const NODE_PROCESS_VERSION_PARTS = process.versions.node.split('.');
  6799. if (NODE_PROCESS_VERSION_PARTS[0] === undefined || NODE_PROCESS_VERSION_PARTS[1] === undefined) {
  6800. throw new Error(`Unexpected behavior. The 'process.versions.node' variable has invalid value: ${process.versions.node}`);
  6801. }
  6802. const MAJOR_VERSION = Number.parseInt(NODE_PROCESS_VERSION_PARTS[0], 10);
  6803. const MINOR_VERSION = Number.parseInt(NODE_PROCESS_VERSION_PARTS[1], 10);
  6804. const SUPPORTED_MAJOR_VERSION = 10;
  6805. const SUPPORTED_MINOR_VERSION = 10;
  6806. const IS_MATCHED_BY_MAJOR = MAJOR_VERSION > SUPPORTED_MAJOR_VERSION;
  6807. const IS_MATCHED_BY_MAJOR_AND_MINOR = MAJOR_VERSION === SUPPORTED_MAJOR_VERSION && MINOR_VERSION >= SUPPORTED_MINOR_VERSION;
  6808. /**
  6809. * IS `true` for Node.js 10.10 and greater.
  6810. */
  6811. exports.IS_SUPPORT_READDIR_WITH_FILE_TYPES = IS_MATCHED_BY_MAJOR || IS_MATCHED_BY_MAJOR_AND_MINOR;
  6812. });
  6813. var fs$2 = createCommonjsModule(function (module, exports) {
  6814. Object.defineProperty(exports, "__esModule", {
  6815. value: true
  6816. });
  6817. exports.createDirentFromStats = void 0;
  6818. class DirentFromStats {
  6819. constructor(name, stats) {
  6820. this.name = name;
  6821. this.isBlockDevice = stats.isBlockDevice.bind(stats);
  6822. this.isCharacterDevice = stats.isCharacterDevice.bind(stats);
  6823. this.isDirectory = stats.isDirectory.bind(stats);
  6824. this.isFIFO = stats.isFIFO.bind(stats);
  6825. this.isFile = stats.isFile.bind(stats);
  6826. this.isSocket = stats.isSocket.bind(stats);
  6827. this.isSymbolicLink = stats.isSymbolicLink.bind(stats);
  6828. }
  6829. }
  6830. function createDirentFromStats(name, stats) {
  6831. return new DirentFromStats(name, stats);
  6832. }
  6833. exports.createDirentFromStats = createDirentFromStats;
  6834. });
  6835. var utils = createCommonjsModule(function (module, exports) {
  6836. Object.defineProperty(exports, "__esModule", {
  6837. value: true
  6838. });
  6839. exports.fs = void 0;
  6840. exports.fs = fs$2;
  6841. });
  6842. var common$1 = createCommonjsModule(function (module, exports) {
  6843. Object.defineProperty(exports, "__esModule", {
  6844. value: true
  6845. });
  6846. exports.joinPathSegments = void 0;
  6847. function joinPathSegments(a, b, separator) {
  6848. /**
  6849. * The correct handling of cases when the first segment is a root (`/`, `C:/`) or UNC path (`//?/C:/`).
  6850. */
  6851. if (a.endsWith(separator)) {
  6852. return a + b;
  6853. }
  6854. return a + separator + b;
  6855. }
  6856. exports.joinPathSegments = joinPathSegments;
  6857. });
  6858. var async$3 = createCommonjsModule(function (module, exports) {
  6859. Object.defineProperty(exports, "__esModule", {
  6860. value: true
  6861. });
  6862. exports.readdir = exports.readdirWithFileTypes = exports.read = void 0;
  6863. function read(directory, settings, callback) {
  6864. if (!settings.stats && constants.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
  6865. readdirWithFileTypes(directory, settings, callback);
  6866. return;
  6867. }
  6868. readdir(directory, settings, callback);
  6869. }
  6870. exports.read = read;
  6871. function readdirWithFileTypes(directory, settings, callback) {
  6872. settings.fs.readdir(directory, {
  6873. withFileTypes: true
  6874. }, (readdirError, dirents) => {
  6875. if (readdirError !== null) {
  6876. callFailureCallback(callback, readdirError);
  6877. return;
  6878. }
  6879. const entries = dirents.map(dirent => ({
  6880. dirent,
  6881. name: dirent.name,
  6882. path: common$1.joinPathSegments(directory, dirent.name, settings.pathSegmentSeparator)
  6883. }));
  6884. if (!settings.followSymbolicLinks) {
  6885. callSuccessCallback(callback, entries);
  6886. return;
  6887. }
  6888. const tasks = entries.map(entry => makeRplTaskEntry(entry, settings));
  6889. runParallel_1(tasks, (rplError, rplEntries) => {
  6890. if (rplError !== null) {
  6891. callFailureCallback(callback, rplError);
  6892. return;
  6893. }
  6894. callSuccessCallback(callback, rplEntries);
  6895. });
  6896. });
  6897. }
  6898. exports.readdirWithFileTypes = readdirWithFileTypes;
  6899. function makeRplTaskEntry(entry, settings) {
  6900. return done => {
  6901. if (!entry.dirent.isSymbolicLink()) {
  6902. done(null, entry);
  6903. return;
  6904. }
  6905. settings.fs.stat(entry.path, (statError, stats) => {
  6906. if (statError !== null) {
  6907. if (settings.throwErrorOnBrokenSymbolicLink) {
  6908. done(statError);
  6909. return;
  6910. }
  6911. done(null, entry);
  6912. return;
  6913. }
  6914. entry.dirent = utils.fs.createDirentFromStats(entry.name, stats);
  6915. done(null, entry);
  6916. });
  6917. };
  6918. }
  6919. function readdir(directory, settings, callback) {
  6920. settings.fs.readdir(directory, (readdirError, names) => {
  6921. if (readdirError !== null) {
  6922. callFailureCallback(callback, readdirError);
  6923. return;
  6924. }
  6925. const tasks = names.map(name => {
  6926. const path = common$1.joinPathSegments(directory, name, settings.pathSegmentSeparator);
  6927. return done => {
  6928. out$3.stat(path, settings.fsStatSettings, (error, stats) => {
  6929. if (error !== null) {
  6930. done(error);
  6931. return;
  6932. }
  6933. const entry = {
  6934. name,
  6935. path,
  6936. dirent: utils.fs.createDirentFromStats(name, stats)
  6937. };
  6938. if (settings.stats) {
  6939. entry.stats = stats;
  6940. }
  6941. done(null, entry);
  6942. });
  6943. };
  6944. });
  6945. runParallel_1(tasks, (rplError, entries) => {
  6946. if (rplError !== null) {
  6947. callFailureCallback(callback, rplError);
  6948. return;
  6949. }
  6950. callSuccessCallback(callback, entries);
  6951. });
  6952. });
  6953. }
  6954. exports.readdir = readdir;
  6955. function callFailureCallback(callback, error) {
  6956. callback(error);
  6957. }
  6958. function callSuccessCallback(callback, result) {
  6959. callback(null, result);
  6960. }
  6961. });
  6962. var sync$4 = createCommonjsModule(function (module, exports) {
  6963. Object.defineProperty(exports, "__esModule", {
  6964. value: true
  6965. });
  6966. exports.readdir = exports.readdirWithFileTypes = exports.read = void 0;
  6967. function read(directory, settings) {
  6968. if (!settings.stats && constants.IS_SUPPORT_READDIR_WITH_FILE_TYPES) {
  6969. return readdirWithFileTypes(directory, settings);
  6970. }
  6971. return readdir(directory, settings);
  6972. }
  6973. exports.read = read;
  6974. function readdirWithFileTypes(directory, settings) {
  6975. const dirents = settings.fs.readdirSync(directory, {
  6976. withFileTypes: true
  6977. });
  6978. return dirents.map(dirent => {
  6979. const entry = {
  6980. dirent,
  6981. name: dirent.name,
  6982. path: common$1.joinPathSegments(directory, dirent.name, settings.pathSegmentSeparator)
  6983. };
  6984. if (entry.dirent.isSymbolicLink() && settings.followSymbolicLinks) {
  6985. try {
  6986. const stats = settings.fs.statSync(entry.path);
  6987. entry.dirent = utils.fs.createDirentFromStats(entry.name, stats);
  6988. } catch (error) {
  6989. if (settings.throwErrorOnBrokenSymbolicLink) {
  6990. throw error;
  6991. }
  6992. }
  6993. }
  6994. return entry;
  6995. });
  6996. }
  6997. exports.readdirWithFileTypes = readdirWithFileTypes;
  6998. function readdir(directory, settings) {
  6999. const names = settings.fs.readdirSync(directory);
  7000. return names.map(name => {
  7001. const entryPath = common$1.joinPathSegments(directory, name, settings.pathSegmentSeparator);
  7002. const stats = out$3.statSync(entryPath, settings.fsStatSettings);
  7003. const entry = {
  7004. name,
  7005. path: entryPath,
  7006. dirent: utils.fs.createDirentFromStats(name, stats)
  7007. };
  7008. if (settings.stats) {
  7009. entry.stats = stats;
  7010. }
  7011. return entry;
  7012. });
  7013. }
  7014. exports.readdir = readdir;
  7015. });
  7016. var fs_1 = createCommonjsModule(function (module, exports) {
  7017. Object.defineProperty(exports, "__esModule", {
  7018. value: true
  7019. });
  7020. exports.createFileSystemAdapter = exports.FILE_SYSTEM_ADAPTER = void 0;
  7021. exports.FILE_SYSTEM_ADAPTER = {
  7022. lstat: fs__default['default'].lstat,
  7023. stat: fs__default['default'].stat,
  7024. lstatSync: fs__default['default'].lstatSync,
  7025. statSync: fs__default['default'].statSync,
  7026. readdir: fs__default['default'].readdir,
  7027. readdirSync: fs__default['default'].readdirSync
  7028. };
  7029. function createFileSystemAdapter(fsMethods) {
  7030. if (fsMethods === undefined) {
  7031. return exports.FILE_SYSTEM_ADAPTER;
  7032. }
  7033. return Object.assign(Object.assign({}, exports.FILE_SYSTEM_ADAPTER), fsMethods);
  7034. }
  7035. exports.createFileSystemAdapter = createFileSystemAdapter;
  7036. });
  7037. class Settings$1 {
  7038. constructor(_options = {}) {
  7039. this._options = _options;
  7040. this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, false);
  7041. this.fs = fs_1.createFileSystemAdapter(this._options.fs);
  7042. this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path__default['default'].sep);
  7043. this.stats = this._getValue(this._options.stats, false);
  7044. this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, true);
  7045. this.fsStatSettings = new out$3.Settings({
  7046. followSymbolicLink: this.followSymbolicLinks,
  7047. fs: this.fs,
  7048. throwErrorOnBrokenSymbolicLink: this.throwErrorOnBrokenSymbolicLink
  7049. });
  7050. }
  7051. _getValue(option, value) {
  7052. return option !== null && option !== void 0 ? option : value;
  7053. }
  7054. }
  7055. var _default$l = Settings$1;
  7056. var settings$2 = /*#__PURE__*/Object.defineProperty({
  7057. default: _default$l
  7058. }, '__esModule', {
  7059. value: true
  7060. });
  7061. var out$2 = createCommonjsModule(function (module, exports) {
  7062. Object.defineProperty(exports, "__esModule", {
  7063. value: true
  7064. });
  7065. exports.Settings = exports.scandirSync = exports.scandir = void 0;
  7066. exports.Settings = settings$2.default;
  7067. function scandir(path, optionsOrSettingsOrCallback, callback) {
  7068. if (typeof optionsOrSettingsOrCallback === 'function') {
  7069. async$3.read(path, getSettings(), optionsOrSettingsOrCallback);
  7070. return;
  7071. }
  7072. async$3.read(path, getSettings(optionsOrSettingsOrCallback), callback);
  7073. }
  7074. exports.scandir = scandir;
  7075. function scandirSync(path, optionsOrSettings) {
  7076. const settings = getSettings(optionsOrSettings);
  7077. return sync$4.read(path, settings);
  7078. }
  7079. exports.scandirSync = scandirSync;
  7080. function getSettings(settingsOrOptions = {}) {
  7081. if (settingsOrOptions instanceof settings$2.default) {
  7082. return settingsOrOptions;
  7083. }
  7084. return new settings$2.default(settingsOrOptions);
  7085. }
  7086. });
  7087. function reusify(Constructor) {
  7088. var head = new Constructor();
  7089. var tail = head;
  7090. function get() {
  7091. var current = head;
  7092. if (current.next) {
  7093. head = current.next;
  7094. } else {
  7095. head = new Constructor();
  7096. tail = head;
  7097. }
  7098. current.next = null;
  7099. return current;
  7100. }
  7101. function release(obj) {
  7102. tail.next = obj;
  7103. tail = obj;
  7104. }
  7105. return {
  7106. get: get,
  7107. release: release
  7108. };
  7109. }
  7110. var reusify_1 = reusify;
  7111. /* eslint-disable no-var */
  7112. function fastqueue(context, worker, concurrency) {
  7113. if (typeof context === 'function') {
  7114. concurrency = worker;
  7115. worker = context;
  7116. context = null;
  7117. }
  7118. if (concurrency < 1) {
  7119. throw new Error('fastqueue concurrency must be greater than 1');
  7120. }
  7121. var cache = reusify_1(Task);
  7122. var queueHead = null;
  7123. var queueTail = null;
  7124. var _running = 0;
  7125. var errorHandler = null;
  7126. var self = {
  7127. push: push,
  7128. drain: noop,
  7129. saturated: noop,
  7130. pause: pause,
  7131. paused: false,
  7132. concurrency: concurrency,
  7133. running: running,
  7134. resume: resume,
  7135. idle: idle,
  7136. length: length,
  7137. getQueue: getQueue,
  7138. unshift: unshift,
  7139. empty: noop,
  7140. kill: kill,
  7141. killAndDrain: killAndDrain,
  7142. error: error
  7143. };
  7144. return self;
  7145. function running() {
  7146. return _running;
  7147. }
  7148. function pause() {
  7149. self.paused = true;
  7150. }
  7151. function length() {
  7152. var current = queueHead;
  7153. var counter = 0;
  7154. while (current) {
  7155. current = current.next;
  7156. counter++;
  7157. }
  7158. return counter;
  7159. }
  7160. function getQueue() {
  7161. var current = queueHead;
  7162. var tasks = [];
  7163. while (current) {
  7164. tasks.push(current.value);
  7165. current = current.next;
  7166. }
  7167. return tasks;
  7168. }
  7169. function resume() {
  7170. if (!self.paused) return;
  7171. self.paused = false;
  7172. for (var i = 0; i < self.concurrency; i++) {
  7173. _running++;
  7174. release();
  7175. }
  7176. }
  7177. function idle() {
  7178. return _running === 0 && self.length() === 0;
  7179. }
  7180. function push(value, done) {
  7181. var current = cache.get();
  7182. current.context = context;
  7183. current.release = release;
  7184. current.value = value;
  7185. current.callback = done || noop;
  7186. current.errorHandler = errorHandler;
  7187. if (_running === self.concurrency || self.paused) {
  7188. if (queueTail) {
  7189. queueTail.next = current;
  7190. queueTail = current;
  7191. } else {
  7192. queueHead = current;
  7193. queueTail = current;
  7194. self.saturated();
  7195. }
  7196. } else {
  7197. _running++;
  7198. worker.call(context, current.value, current.worked);
  7199. }
  7200. }
  7201. function unshift(value, done) {
  7202. var current = cache.get();
  7203. current.context = context;
  7204. current.release = release;
  7205. current.value = value;
  7206. current.callback = done || noop;
  7207. if (_running === self.concurrency || self.paused) {
  7208. if (queueHead) {
  7209. current.next = queueHead;
  7210. queueHead = current;
  7211. } else {
  7212. queueHead = current;
  7213. queueTail = current;
  7214. self.saturated();
  7215. }
  7216. } else {
  7217. _running++;
  7218. worker.call(context, current.value, current.worked);
  7219. }
  7220. }
  7221. function release(holder) {
  7222. if (holder) {
  7223. cache.release(holder);
  7224. }
  7225. var next = queueHead;
  7226. if (next) {
  7227. if (!self.paused) {
  7228. if (queueTail === queueHead) {
  7229. queueTail = null;
  7230. }
  7231. queueHead = next.next;
  7232. next.next = null;
  7233. worker.call(context, next.value, next.worked);
  7234. if (queueTail === null) {
  7235. self.empty();
  7236. }
  7237. } else {
  7238. _running--;
  7239. }
  7240. } else if (--_running === 0) {
  7241. self.drain();
  7242. }
  7243. }
  7244. function kill() {
  7245. queueHead = null;
  7246. queueTail = null;
  7247. self.drain = noop;
  7248. }
  7249. function killAndDrain() {
  7250. queueHead = null;
  7251. queueTail = null;
  7252. self.drain();
  7253. self.drain = noop;
  7254. }
  7255. function error(handler) {
  7256. errorHandler = handler;
  7257. }
  7258. }
  7259. function noop() {}
  7260. function Task() {
  7261. this.value = null;
  7262. this.callback = noop;
  7263. this.next = null;
  7264. this.release = noop;
  7265. this.context = null;
  7266. this.errorHandler = null;
  7267. var self = this;
  7268. this.worked = function worked(err, result) {
  7269. var callback = self.callback;
  7270. var errorHandler = self.errorHandler;
  7271. var val = self.value;
  7272. self.value = null;
  7273. self.callback = noop;
  7274. if (self.errorHandler) {
  7275. errorHandler(err, val);
  7276. }
  7277. callback.call(self.context, err, result);
  7278. self.release(self);
  7279. };
  7280. }
  7281. function queueAsPromised(context, worker, concurrency) {
  7282. if (typeof context === 'function') {
  7283. concurrency = worker;
  7284. worker = context;
  7285. context = null;
  7286. }
  7287. function asyncWrapper(arg, cb) {
  7288. worker.call(this, arg).then(function (res) {
  7289. cb(null, res);
  7290. }, cb);
  7291. }
  7292. var queue = fastqueue(context, asyncWrapper, concurrency);
  7293. var pushCb = queue.push;
  7294. var unshiftCb = queue.unshift;
  7295. queue.push = push;
  7296. queue.unshift = unshift;
  7297. return queue;
  7298. function push(value) {
  7299. var p = new Promise(function (resolve, reject) {
  7300. pushCb(value, function (err, result) {
  7301. if (err) {
  7302. reject(err);
  7303. return;
  7304. }
  7305. resolve(result);
  7306. });
  7307. }); // Let's fork the promise chain to
  7308. // make the error bubble up to the user but
  7309. // not lead to a unhandledRejection
  7310. p.catch(noop);
  7311. return p;
  7312. }
  7313. function unshift(value) {
  7314. var p = new Promise(function (resolve, reject) {
  7315. unshiftCb(value, function (err, result) {
  7316. if (err) {
  7317. reject(err);
  7318. return;
  7319. }
  7320. resolve(result);
  7321. });
  7322. }); // Let's fork the promise chain to
  7323. // make the error bubble up to the user but
  7324. // not lead to a unhandledRejection
  7325. p.catch(noop);
  7326. return p;
  7327. }
  7328. }
  7329. var queue = fastqueue;
  7330. var promise = queueAsPromised;
  7331. queue.promise = promise;
  7332. var common = createCommonjsModule(function (module, exports) {
  7333. Object.defineProperty(exports, "__esModule", {
  7334. value: true
  7335. });
  7336. exports.joinPathSegments = exports.replacePathSegmentSeparator = exports.isAppliedFilter = exports.isFatalError = void 0;
  7337. function isFatalError(settings, error) {
  7338. if (settings.errorFilter === null) {
  7339. return true;
  7340. }
  7341. return !settings.errorFilter(error);
  7342. }
  7343. exports.isFatalError = isFatalError;
  7344. function isAppliedFilter(filter, value) {
  7345. return filter === null || filter(value);
  7346. }
  7347. exports.isAppliedFilter = isAppliedFilter;
  7348. function replacePathSegmentSeparator(filepath, separator) {
  7349. return filepath.split(/[/\\]/).join(separator);
  7350. }
  7351. exports.replacePathSegmentSeparator = replacePathSegmentSeparator;
  7352. function joinPathSegments(a, b, separator) {
  7353. if (a === '') {
  7354. return b;
  7355. }
  7356. /**
  7357. * The correct handling of cases when the first segment is a root (`/`, `C:/`) or UNC path (`//?/C:/`).
  7358. */
  7359. if (a.endsWith(separator)) {
  7360. return a + b;
  7361. }
  7362. return a + separator + b;
  7363. }
  7364. exports.joinPathSegments = joinPathSegments;
  7365. });
  7366. class Reader$1 {
  7367. constructor(_root, _settings) {
  7368. this._root = _root;
  7369. this._settings = _settings;
  7370. this._root = common.replacePathSegmentSeparator(_root, _settings.pathSegmentSeparator);
  7371. }
  7372. }
  7373. var _default$k = Reader$1;
  7374. var reader$1 = /*#__PURE__*/Object.defineProperty({
  7375. default: _default$k
  7376. }, '__esModule', {
  7377. value: true
  7378. });
  7379. class AsyncReader extends reader$1.default {
  7380. constructor(_root, _settings) {
  7381. super(_root, _settings);
  7382. this._settings = _settings;
  7383. this._scandir = out$2.scandir;
  7384. this._emitter = new events_1__default['default'].EventEmitter();
  7385. this._queue = queue(this._worker.bind(this), this._settings.concurrency);
  7386. this._isFatalError = false;
  7387. this._isDestroyed = false;
  7388. this._queue.drain = () => {
  7389. if (!this._isFatalError) {
  7390. this._emitter.emit('end');
  7391. }
  7392. };
  7393. }
  7394. read() {
  7395. this._isFatalError = false;
  7396. this._isDestroyed = false;
  7397. setImmediate(() => {
  7398. this._pushToQueue(this._root, this._settings.basePath);
  7399. });
  7400. return this._emitter;
  7401. }
  7402. get isDestroyed() {
  7403. return this._isDestroyed;
  7404. }
  7405. destroy() {
  7406. if (this._isDestroyed) {
  7407. throw new Error('The reader is already destroyed');
  7408. }
  7409. this._isDestroyed = true;
  7410. this._queue.killAndDrain();
  7411. }
  7412. onEntry(callback) {
  7413. this._emitter.on('entry', callback);
  7414. }
  7415. onError(callback) {
  7416. this._emitter.once('error', callback);
  7417. }
  7418. onEnd(callback) {
  7419. this._emitter.once('end', callback);
  7420. }
  7421. _pushToQueue(directory, base) {
  7422. const queueItem = {
  7423. directory,
  7424. base
  7425. };
  7426. this._queue.push(queueItem, error => {
  7427. if (error !== null) {
  7428. this._handleError(error);
  7429. }
  7430. });
  7431. }
  7432. _worker(item, done) {
  7433. this._scandir(item.directory, this._settings.fsScandirSettings, (error, entries) => {
  7434. if (error !== null) {
  7435. done(error, undefined);
  7436. return;
  7437. }
  7438. for (const entry of entries) {
  7439. this._handleEntry(entry, item.base);
  7440. }
  7441. done(null, undefined);
  7442. });
  7443. }
  7444. _handleError(error) {
  7445. if (this._isDestroyed || !common.isFatalError(this._settings, error)) {
  7446. return;
  7447. }
  7448. this._isFatalError = true;
  7449. this._isDestroyed = true;
  7450. this._emitter.emit('error', error);
  7451. }
  7452. _handleEntry(entry, base) {
  7453. if (this._isDestroyed || this._isFatalError) {
  7454. return;
  7455. }
  7456. const fullpath = entry.path;
  7457. if (base !== undefined) {
  7458. entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
  7459. }
  7460. if (common.isAppliedFilter(this._settings.entryFilter, entry)) {
  7461. this._emitEntry(entry);
  7462. }
  7463. if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) {
  7464. this._pushToQueue(fullpath, base === undefined ? undefined : entry.path);
  7465. }
  7466. }
  7467. _emitEntry(entry) {
  7468. this._emitter.emit('entry', entry);
  7469. }
  7470. }
  7471. var _default$j = AsyncReader;
  7472. var async$2 = /*#__PURE__*/Object.defineProperty({
  7473. default: _default$j
  7474. }, '__esModule', {
  7475. value: true
  7476. });
  7477. class AsyncProvider {
  7478. constructor(_root, _settings) {
  7479. this._root = _root;
  7480. this._settings = _settings;
  7481. this._reader = new async$2.default(this._root, this._settings);
  7482. this._storage = [];
  7483. }
  7484. read(callback) {
  7485. this._reader.onError(error => {
  7486. callFailureCallback(callback, error);
  7487. });
  7488. this._reader.onEntry(entry => {
  7489. this._storage.push(entry);
  7490. });
  7491. this._reader.onEnd(() => {
  7492. callSuccessCallback(callback, this._storage);
  7493. });
  7494. this._reader.read();
  7495. }
  7496. }
  7497. var _default$i = AsyncProvider;
  7498. function callFailureCallback(callback, error) {
  7499. callback(error);
  7500. }
  7501. function callSuccessCallback(callback, entries) {
  7502. callback(null, entries);
  7503. }
  7504. var async$1 = /*#__PURE__*/Object.defineProperty({
  7505. default: _default$i
  7506. }, '__esModule', {
  7507. value: true
  7508. });
  7509. class StreamProvider {
  7510. constructor(_root, _settings) {
  7511. this._root = _root;
  7512. this._settings = _settings;
  7513. this._reader = new async$2.default(this._root, this._settings);
  7514. this._stream = new stream_1__default['default'].Readable({
  7515. objectMode: true,
  7516. read: () => {},
  7517. destroy: () => {
  7518. if (!this._reader.isDestroyed) {
  7519. this._reader.destroy();
  7520. }
  7521. }
  7522. });
  7523. }
  7524. read() {
  7525. this._reader.onError(error => {
  7526. this._stream.emit('error', error);
  7527. });
  7528. this._reader.onEntry(entry => {
  7529. this._stream.push(entry);
  7530. });
  7531. this._reader.onEnd(() => {
  7532. this._stream.push(null);
  7533. });
  7534. this._reader.read();
  7535. return this._stream;
  7536. }
  7537. }
  7538. var _default$h = StreamProvider;
  7539. var stream$2 = /*#__PURE__*/Object.defineProperty({
  7540. default: _default$h
  7541. }, '__esModule', {
  7542. value: true
  7543. });
  7544. class SyncReader extends reader$1.default {
  7545. constructor() {
  7546. super(...arguments);
  7547. this._scandir = out$2.scandirSync;
  7548. this._storage = [];
  7549. this._queue = new Set();
  7550. }
  7551. read() {
  7552. this._pushToQueue(this._root, this._settings.basePath);
  7553. this._handleQueue();
  7554. return this._storage;
  7555. }
  7556. _pushToQueue(directory, base) {
  7557. this._queue.add({
  7558. directory,
  7559. base
  7560. });
  7561. }
  7562. _handleQueue() {
  7563. for (const item of this._queue.values()) {
  7564. this._handleDirectory(item.directory, item.base);
  7565. }
  7566. }
  7567. _handleDirectory(directory, base) {
  7568. try {
  7569. const entries = this._scandir(directory, this._settings.fsScandirSettings);
  7570. for (const entry of entries) {
  7571. this._handleEntry(entry, base);
  7572. }
  7573. } catch (error) {
  7574. this._handleError(error);
  7575. }
  7576. }
  7577. _handleError(error) {
  7578. if (!common.isFatalError(this._settings, error)) {
  7579. return;
  7580. }
  7581. throw error;
  7582. }
  7583. _handleEntry(entry, base) {
  7584. const fullpath = entry.path;
  7585. if (base !== undefined) {
  7586. entry.path = common.joinPathSegments(base, entry.name, this._settings.pathSegmentSeparator);
  7587. }
  7588. if (common.isAppliedFilter(this._settings.entryFilter, entry)) {
  7589. this._pushToStorage(entry);
  7590. }
  7591. if (entry.dirent.isDirectory() && common.isAppliedFilter(this._settings.deepFilter, entry)) {
  7592. this._pushToQueue(fullpath, base === undefined ? undefined : entry.path);
  7593. }
  7594. }
  7595. _pushToStorage(entry) {
  7596. this._storage.push(entry);
  7597. }
  7598. }
  7599. var _default$g = SyncReader;
  7600. var sync$3 = /*#__PURE__*/Object.defineProperty({
  7601. default: _default$g
  7602. }, '__esModule', {
  7603. value: true
  7604. });
  7605. class SyncProvider {
  7606. constructor(_root, _settings) {
  7607. this._root = _root;
  7608. this._settings = _settings;
  7609. this._reader = new sync$3.default(this._root, this._settings);
  7610. }
  7611. read() {
  7612. return this._reader.read();
  7613. }
  7614. }
  7615. var _default$f = SyncProvider;
  7616. var sync$2 = /*#__PURE__*/Object.defineProperty({
  7617. default: _default$f
  7618. }, '__esModule', {
  7619. value: true
  7620. });
  7621. class Settings {
  7622. constructor(_options = {}) {
  7623. this._options = _options;
  7624. this.basePath = this._getValue(this._options.basePath, undefined);
  7625. this.concurrency = this._getValue(this._options.concurrency, Number.POSITIVE_INFINITY);
  7626. this.deepFilter = this._getValue(this._options.deepFilter, null);
  7627. this.entryFilter = this._getValue(this._options.entryFilter, null);
  7628. this.errorFilter = this._getValue(this._options.errorFilter, null);
  7629. this.pathSegmentSeparator = this._getValue(this._options.pathSegmentSeparator, path__default['default'].sep);
  7630. this.fsScandirSettings = new out$2.Settings({
  7631. followSymbolicLinks: this._options.followSymbolicLinks,
  7632. fs: this._options.fs,
  7633. pathSegmentSeparator: this._options.pathSegmentSeparator,
  7634. stats: this._options.stats,
  7635. throwErrorOnBrokenSymbolicLink: this._options.throwErrorOnBrokenSymbolicLink
  7636. });
  7637. }
  7638. _getValue(option, value) {
  7639. return option !== null && option !== void 0 ? option : value;
  7640. }
  7641. }
  7642. var _default$e = Settings;
  7643. var settings$1 = /*#__PURE__*/Object.defineProperty({
  7644. default: _default$e
  7645. }, '__esModule', {
  7646. value: true
  7647. });
  7648. var out$1 = createCommonjsModule(function (module, exports) {
  7649. Object.defineProperty(exports, "__esModule", {
  7650. value: true
  7651. });
  7652. exports.Settings = exports.walkStream = exports.walkSync = exports.walk = void 0;
  7653. exports.Settings = settings$1.default;
  7654. function walk(directory, optionsOrSettingsOrCallback, callback) {
  7655. if (typeof optionsOrSettingsOrCallback === 'function') {
  7656. new async$1.default(directory, getSettings()).read(optionsOrSettingsOrCallback);
  7657. return;
  7658. }
  7659. new async$1.default(directory, getSettings(optionsOrSettingsOrCallback)).read(callback);
  7660. }
  7661. exports.walk = walk;
  7662. function walkSync(directory, optionsOrSettings) {
  7663. const settings = getSettings(optionsOrSettings);
  7664. const provider = new sync$2.default(directory, settings);
  7665. return provider.read();
  7666. }
  7667. exports.walkSync = walkSync;
  7668. function walkStream(directory, optionsOrSettings) {
  7669. const settings = getSettings(optionsOrSettings);
  7670. const provider = new stream$2.default(directory, settings);
  7671. return provider.read();
  7672. }
  7673. exports.walkStream = walkStream;
  7674. function getSettings(settingsOrOptions = {}) {
  7675. if (settingsOrOptions instanceof settings$1.default) {
  7676. return settingsOrOptions;
  7677. }
  7678. return new settings$1.default(settingsOrOptions);
  7679. }
  7680. });
  7681. class Reader {
  7682. constructor(_settings) {
  7683. this._settings = _settings;
  7684. this._fsStatSettings = new out$3.Settings({
  7685. followSymbolicLink: this._settings.followSymbolicLinks,
  7686. fs: this._settings.fs,
  7687. throwErrorOnBrokenSymbolicLink: this._settings.followSymbolicLinks
  7688. });
  7689. }
  7690. _getFullEntryPath(filepath) {
  7691. return path__default['default'].resolve(this._settings.cwd, filepath);
  7692. }
  7693. _makeEntry(stats, pattern) {
  7694. const entry = {
  7695. name: pattern,
  7696. path: pattern,
  7697. dirent: utils$1.fs.createDirentFromStats(pattern, stats)
  7698. };
  7699. if (this._settings.stats) {
  7700. entry.stats = stats;
  7701. }
  7702. return entry;
  7703. }
  7704. _isFatalError(error) {
  7705. return !utils$1.errno.isEnoentCodeError(error) && !this._settings.suppressErrors;
  7706. }
  7707. }
  7708. var _default$d = Reader;
  7709. var reader = /*#__PURE__*/Object.defineProperty({
  7710. default: _default$d
  7711. }, '__esModule', {
  7712. value: true
  7713. });
  7714. class ReaderStream extends reader.default {
  7715. constructor() {
  7716. super(...arguments);
  7717. this._walkStream = out$1.walkStream;
  7718. this._stat = out$3.stat;
  7719. }
  7720. dynamic(root, options) {
  7721. return this._walkStream(root, options);
  7722. }
  7723. static(patterns, options) {
  7724. const filepaths = patterns.map(this._getFullEntryPath, this);
  7725. const stream = new stream_1__default['default'].PassThrough({
  7726. objectMode: true
  7727. });
  7728. stream._write = (index, _enc, done) => {
  7729. return this._getEntry(filepaths[index], patterns[index], options).then(entry => {
  7730. if (entry !== null && options.entryFilter(entry)) {
  7731. stream.push(entry);
  7732. }
  7733. if (index === filepaths.length - 1) {
  7734. stream.end();
  7735. }
  7736. done();
  7737. }).catch(done);
  7738. };
  7739. for (let i = 0; i < filepaths.length; i++) {
  7740. stream.write(i);
  7741. }
  7742. return stream;
  7743. }
  7744. _getEntry(filepath, pattern, options) {
  7745. return this._getStat(filepath).then(stats => this._makeEntry(stats, pattern)).catch(error => {
  7746. if (options.errorFilter(error)) {
  7747. return null;
  7748. }
  7749. throw error;
  7750. });
  7751. }
  7752. _getStat(filepath) {
  7753. return new Promise((resolve, reject) => {
  7754. this._stat(filepath, this._fsStatSettings, (error, stats) => {
  7755. return error === null ? resolve(stats) : reject(error);
  7756. });
  7757. });
  7758. }
  7759. }
  7760. var _default$c = ReaderStream;
  7761. var stream$1 = /*#__PURE__*/Object.defineProperty({
  7762. default: _default$c
  7763. }, '__esModule', {
  7764. value: true
  7765. });
  7766. class Matcher {
  7767. constructor(_patterns, _settings, _micromatchOptions) {
  7768. this._patterns = _patterns;
  7769. this._settings = _settings;
  7770. this._micromatchOptions = _micromatchOptions;
  7771. this._storage = [];
  7772. this._fillStorage();
  7773. }
  7774. _fillStorage() {
  7775. /**
  7776. * The original pattern may include `{,*,**,a/*}`, which will lead to problems with matching (unresolved level).
  7777. * So, before expand patterns with brace expansion into separated patterns.
  7778. */
  7779. const patterns = utils$1.pattern.expandPatternsWithBraceExpansion(this._patterns);
  7780. for (const pattern of patterns) {
  7781. const segments = this._getPatternSegments(pattern);
  7782. const sections = this._splitSegmentsIntoSections(segments);
  7783. this._storage.push({
  7784. complete: sections.length <= 1,
  7785. pattern,
  7786. segments,
  7787. sections
  7788. });
  7789. }
  7790. }
  7791. _getPatternSegments(pattern) {
  7792. const parts = utils$1.pattern.getPatternParts(pattern, this._micromatchOptions);
  7793. return parts.map(part => {
  7794. const dynamic = utils$1.pattern.isDynamicPattern(part, this._settings);
  7795. if (!dynamic) {
  7796. return {
  7797. dynamic: false,
  7798. pattern: part
  7799. };
  7800. }
  7801. return {
  7802. dynamic: true,
  7803. pattern: part,
  7804. patternRe: utils$1.pattern.makeRe(part, this._micromatchOptions)
  7805. };
  7806. });
  7807. }
  7808. _splitSegmentsIntoSections(segments) {
  7809. return utils$1.array.splitWhen(segments, segment => segment.dynamic && utils$1.pattern.hasGlobStar(segment.pattern));
  7810. }
  7811. }
  7812. var _default$b = Matcher;
  7813. var matcher = /*#__PURE__*/Object.defineProperty({
  7814. default: _default$b
  7815. }, '__esModule', {
  7816. value: true
  7817. });
  7818. class PartialMatcher extends matcher.default {
  7819. match(filepath) {
  7820. const parts = filepath.split('/');
  7821. const levels = parts.length;
  7822. const patterns = this._storage.filter(info => !info.complete || info.segments.length > levels);
  7823. for (const pattern of patterns) {
  7824. const section = pattern.sections[0];
  7825. /**
  7826. * In this case, the pattern has a globstar and we must read all directories unconditionally,
  7827. * but only if the level has reached the end of the first group.
  7828. *
  7829. * fixtures/{a,b}/**
  7830. * ^ true/false ^ always true
  7831. */
  7832. if (!pattern.complete && levels > section.length) {
  7833. return true;
  7834. }
  7835. const match = parts.every((part, index) => {
  7836. const segment = pattern.segments[index];
  7837. if (segment.dynamic && segment.patternRe.test(part)) {
  7838. return true;
  7839. }
  7840. if (!segment.dynamic && segment.pattern === part) {
  7841. return true;
  7842. }
  7843. return false;
  7844. });
  7845. if (match) {
  7846. return true;
  7847. }
  7848. }
  7849. return false;
  7850. }
  7851. }
  7852. var _default$a = PartialMatcher;
  7853. var partial = /*#__PURE__*/Object.defineProperty({
  7854. default: _default$a
  7855. }, '__esModule', {
  7856. value: true
  7857. });
  7858. class DeepFilter {
  7859. constructor(_settings, _micromatchOptions) {
  7860. this._settings = _settings;
  7861. this._micromatchOptions = _micromatchOptions;
  7862. }
  7863. getFilter(basePath, positive, negative) {
  7864. const matcher = this._getMatcher(positive);
  7865. const negativeRe = this._getNegativePatternsRe(negative);
  7866. return entry => this._filter(basePath, entry, matcher, negativeRe);
  7867. }
  7868. _getMatcher(patterns) {
  7869. return new partial.default(patterns, this._settings, this._micromatchOptions);
  7870. }
  7871. _getNegativePatternsRe(patterns) {
  7872. const affectDepthOfReadingPatterns = patterns.filter(utils$1.pattern.isAffectDepthOfReadingPattern);
  7873. return utils$1.pattern.convertPatternsToRe(affectDepthOfReadingPatterns, this._micromatchOptions);
  7874. }
  7875. _filter(basePath, entry, matcher, negativeRe) {
  7876. if (this._isSkippedByDeep(basePath, entry.path)) {
  7877. return false;
  7878. }
  7879. if (this._isSkippedSymbolicLink(entry)) {
  7880. return false;
  7881. }
  7882. const filepath = utils$1.path.removeLeadingDotSegment(entry.path);
  7883. if (this._isSkippedByPositivePatterns(filepath, matcher)) {
  7884. return false;
  7885. }
  7886. return this._isSkippedByNegativePatterns(filepath, negativeRe);
  7887. }
  7888. _isSkippedByDeep(basePath, entryPath) {
  7889. /**
  7890. * Avoid unnecessary depth calculations when it doesn't matter.
  7891. */
  7892. if (this._settings.deep === Infinity) {
  7893. return false;
  7894. }
  7895. return this._getEntryLevel(basePath, entryPath) >= this._settings.deep;
  7896. }
  7897. _getEntryLevel(basePath, entryPath) {
  7898. const entryPathDepth = entryPath.split('/').length;
  7899. if (basePath === '') {
  7900. return entryPathDepth;
  7901. }
  7902. const basePathDepth = basePath.split('/').length;
  7903. return entryPathDepth - basePathDepth;
  7904. }
  7905. _isSkippedSymbolicLink(entry) {
  7906. return !this._settings.followSymbolicLinks && entry.dirent.isSymbolicLink();
  7907. }
  7908. _isSkippedByPositivePatterns(entryPath, matcher) {
  7909. return !this._settings.baseNameMatch && !matcher.match(entryPath);
  7910. }
  7911. _isSkippedByNegativePatterns(entryPath, patternsRe) {
  7912. return !utils$1.pattern.matchAny(entryPath, patternsRe);
  7913. }
  7914. }
  7915. var _default$9 = DeepFilter;
  7916. var deep = /*#__PURE__*/Object.defineProperty({
  7917. default: _default$9
  7918. }, '__esModule', {
  7919. value: true
  7920. });
  7921. class EntryFilter {
  7922. constructor(_settings, _micromatchOptions) {
  7923. this._settings = _settings;
  7924. this._micromatchOptions = _micromatchOptions;
  7925. this.index = new Map();
  7926. }
  7927. getFilter(positive, negative) {
  7928. const positiveRe = utils$1.pattern.convertPatternsToRe(positive, this._micromatchOptions);
  7929. const negativeRe = utils$1.pattern.convertPatternsToRe(negative, this._micromatchOptions);
  7930. return entry => this._filter(entry, positiveRe, negativeRe);
  7931. }
  7932. _filter(entry, positiveRe, negativeRe) {
  7933. if (this._settings.unique && this._isDuplicateEntry(entry)) {
  7934. return false;
  7935. }
  7936. if (this._onlyFileFilter(entry) || this._onlyDirectoryFilter(entry)) {
  7937. return false;
  7938. }
  7939. if (this._isSkippedByAbsoluteNegativePatterns(entry.path, negativeRe)) {
  7940. return false;
  7941. }
  7942. const filepath = this._settings.baseNameMatch ? entry.name : entry.path;
  7943. const isMatched = this._isMatchToPatterns(filepath, positiveRe) && !this._isMatchToPatterns(entry.path, negativeRe);
  7944. if (this._settings.unique && isMatched) {
  7945. this._createIndexRecord(entry);
  7946. }
  7947. return isMatched;
  7948. }
  7949. _isDuplicateEntry(entry) {
  7950. return this.index.has(entry.path);
  7951. }
  7952. _createIndexRecord(entry) {
  7953. this.index.set(entry.path, undefined);
  7954. }
  7955. _onlyFileFilter(entry) {
  7956. return this._settings.onlyFiles && !entry.dirent.isFile();
  7957. }
  7958. _onlyDirectoryFilter(entry) {
  7959. return this._settings.onlyDirectories && !entry.dirent.isDirectory();
  7960. }
  7961. _isSkippedByAbsoluteNegativePatterns(entryPath, patternsRe) {
  7962. if (!this._settings.absolute) {
  7963. return false;
  7964. }
  7965. const fullpath = utils$1.path.makeAbsolute(this._settings.cwd, entryPath);
  7966. return utils$1.pattern.matchAny(fullpath, patternsRe);
  7967. }
  7968. _isMatchToPatterns(entryPath, patternsRe) {
  7969. const filepath = utils$1.path.removeLeadingDotSegment(entryPath);
  7970. return utils$1.pattern.matchAny(filepath, patternsRe);
  7971. }
  7972. }
  7973. var _default$8 = EntryFilter;
  7974. var entry$1 = /*#__PURE__*/Object.defineProperty({
  7975. default: _default$8
  7976. }, '__esModule', {
  7977. value: true
  7978. });
  7979. class ErrorFilter {
  7980. constructor(_settings) {
  7981. this._settings = _settings;
  7982. }
  7983. getFilter() {
  7984. return error => this._isNonFatalError(error);
  7985. }
  7986. _isNonFatalError(error) {
  7987. return utils$1.errno.isEnoentCodeError(error) || this._settings.suppressErrors;
  7988. }
  7989. }
  7990. var _default$7 = ErrorFilter;
  7991. var error = /*#__PURE__*/Object.defineProperty({
  7992. default: _default$7
  7993. }, '__esModule', {
  7994. value: true
  7995. });
  7996. class EntryTransformer {
  7997. constructor(_settings) {
  7998. this._settings = _settings;
  7999. }
  8000. getTransformer() {
  8001. return entry => this._transform(entry);
  8002. }
  8003. _transform(entry) {
  8004. let filepath = entry.path;
  8005. if (this._settings.absolute) {
  8006. filepath = utils$1.path.makeAbsolute(this._settings.cwd, filepath);
  8007. filepath = utils$1.path.unixify(filepath);
  8008. }
  8009. if (this._settings.markDirectories && entry.dirent.isDirectory()) {
  8010. filepath += '/';
  8011. }
  8012. if (!this._settings.objectMode) {
  8013. return filepath;
  8014. }
  8015. return Object.assign(Object.assign({}, entry), {
  8016. path: filepath
  8017. });
  8018. }
  8019. }
  8020. var _default$6 = EntryTransformer;
  8021. var entry = /*#__PURE__*/Object.defineProperty({
  8022. default: _default$6
  8023. }, '__esModule', {
  8024. value: true
  8025. });
  8026. class Provider {
  8027. constructor(_settings) {
  8028. this._settings = _settings;
  8029. this.errorFilter = new error.default(this._settings);
  8030. this.entryFilter = new entry$1.default(this._settings, this._getMicromatchOptions());
  8031. this.deepFilter = new deep.default(this._settings, this._getMicromatchOptions());
  8032. this.entryTransformer = new entry.default(this._settings);
  8033. }
  8034. _getRootDirectory(task) {
  8035. return path__default['default'].resolve(this._settings.cwd, task.base);
  8036. }
  8037. _getReaderOptions(task) {
  8038. const basePath = task.base === '.' ? '' : task.base;
  8039. return {
  8040. basePath,
  8041. pathSegmentSeparator: '/',
  8042. concurrency: this._settings.concurrency,
  8043. deepFilter: this.deepFilter.getFilter(basePath, task.positive, task.negative),
  8044. entryFilter: this.entryFilter.getFilter(task.positive, task.negative),
  8045. errorFilter: this.errorFilter.getFilter(),
  8046. followSymbolicLinks: this._settings.followSymbolicLinks,
  8047. fs: this._settings.fs,
  8048. stats: this._settings.stats,
  8049. throwErrorOnBrokenSymbolicLink: this._settings.throwErrorOnBrokenSymbolicLink,
  8050. transform: this.entryTransformer.getTransformer()
  8051. };
  8052. }
  8053. _getMicromatchOptions() {
  8054. return {
  8055. dot: this._settings.dot,
  8056. matchBase: this._settings.baseNameMatch,
  8057. nobrace: !this._settings.braceExpansion,
  8058. nocase: !this._settings.caseSensitiveMatch,
  8059. noext: !this._settings.extglob,
  8060. noglobstar: !this._settings.globstar,
  8061. posix: true,
  8062. strictSlashes: false
  8063. };
  8064. }
  8065. }
  8066. var _default$5 = Provider;
  8067. var provider = /*#__PURE__*/Object.defineProperty({
  8068. default: _default$5
  8069. }, '__esModule', {
  8070. value: true
  8071. });
  8072. class ProviderAsync extends provider.default {
  8073. constructor() {
  8074. super(...arguments);
  8075. this._reader = new stream$1.default(this._settings);
  8076. }
  8077. read(task) {
  8078. const root = this._getRootDirectory(task);
  8079. const options = this._getReaderOptions(task);
  8080. const entries = [];
  8081. return new Promise((resolve, reject) => {
  8082. const stream = this.api(root, task, options);
  8083. stream.once('error', reject);
  8084. stream.on('data', entry => entries.push(options.transform(entry)));
  8085. stream.once('end', () => resolve(entries));
  8086. });
  8087. }
  8088. api(root, task, options) {
  8089. if (task.dynamic) {
  8090. return this._reader.dynamic(root, options);
  8091. }
  8092. return this._reader.static(task.patterns, options);
  8093. }
  8094. }
  8095. var _default$4 = ProviderAsync;
  8096. var async = /*#__PURE__*/Object.defineProperty({
  8097. default: _default$4
  8098. }, '__esModule', {
  8099. value: true
  8100. });
  8101. class ProviderStream extends provider.default {
  8102. constructor() {
  8103. super(...arguments);
  8104. this._reader = new stream$1.default(this._settings);
  8105. }
  8106. read(task) {
  8107. const root = this._getRootDirectory(task);
  8108. const options = this._getReaderOptions(task);
  8109. const source = this.api(root, task, options);
  8110. const destination = new stream_1__default['default'].Readable({
  8111. objectMode: true,
  8112. read: () => {}
  8113. });
  8114. source.once('error', error => destination.emit('error', error)).on('data', entry => destination.emit('data', options.transform(entry))).once('end', () => destination.emit('end'));
  8115. destination.once('close', () => source.destroy());
  8116. return destination;
  8117. }
  8118. api(root, task, options) {
  8119. if (task.dynamic) {
  8120. return this._reader.dynamic(root, options);
  8121. }
  8122. return this._reader.static(task.patterns, options);
  8123. }
  8124. }
  8125. var _default$3 = ProviderStream;
  8126. var stream = /*#__PURE__*/Object.defineProperty({
  8127. default: _default$3
  8128. }, '__esModule', {
  8129. value: true
  8130. });
  8131. class ReaderSync extends reader.default {
  8132. constructor() {
  8133. super(...arguments);
  8134. this._walkSync = out$1.walkSync;
  8135. this._statSync = out$3.statSync;
  8136. }
  8137. dynamic(root, options) {
  8138. return this._walkSync(root, options);
  8139. }
  8140. static(patterns, options) {
  8141. const entries = [];
  8142. for (const pattern of patterns) {
  8143. const filepath = this._getFullEntryPath(pattern);
  8144. const entry = this._getEntry(filepath, pattern, options);
  8145. if (entry === null || !options.entryFilter(entry)) {
  8146. continue;
  8147. }
  8148. entries.push(entry);
  8149. }
  8150. return entries;
  8151. }
  8152. _getEntry(filepath, pattern, options) {
  8153. try {
  8154. const stats = this._getStat(filepath);
  8155. return this._makeEntry(stats, pattern);
  8156. } catch (error) {
  8157. if (options.errorFilter(error)) {
  8158. return null;
  8159. }
  8160. throw error;
  8161. }
  8162. }
  8163. _getStat(filepath) {
  8164. return this._statSync(filepath, this._fsStatSettings);
  8165. }
  8166. }
  8167. var _default$2 = ReaderSync;
  8168. var sync$1 = /*#__PURE__*/Object.defineProperty({
  8169. default: _default$2
  8170. }, '__esModule', {
  8171. value: true
  8172. });
  8173. class ProviderSync extends provider.default {
  8174. constructor() {
  8175. super(...arguments);
  8176. this._reader = new sync$1.default(this._settings);
  8177. }
  8178. read(task) {
  8179. const root = this._getRootDirectory(task);
  8180. const options = this._getReaderOptions(task);
  8181. const entries = this.api(root, task, options);
  8182. return entries.map(options.transform);
  8183. }
  8184. api(root, task, options) {
  8185. if (task.dynamic) {
  8186. return this._reader.dynamic(root, options);
  8187. }
  8188. return this._reader.static(task.patterns, options);
  8189. }
  8190. }
  8191. var _default$1 = ProviderSync;
  8192. var sync = /*#__PURE__*/Object.defineProperty({
  8193. default: _default$1
  8194. }, '__esModule', {
  8195. value: true
  8196. });
  8197. var settings = createCommonjsModule(function (module, exports) {
  8198. Object.defineProperty(exports, "__esModule", {
  8199. value: true
  8200. });
  8201. exports.DEFAULT_FILE_SYSTEM_ADAPTER = void 0;
  8202. /**
  8203. * The `os.cpus` method can return zero. We expect the number of cores to be greater than zero.
  8204. * https://github.com/nodejs/node/blob/7faeddf23a98c53896f8b574a6e66589e8fb1eb8/lib/os.js#L106-L107
  8205. */
  8206. const CPU_COUNT = Math.max(os__default['default'].cpus().length, 1);
  8207. exports.DEFAULT_FILE_SYSTEM_ADAPTER = {
  8208. lstat: fs__default['default'].lstat,
  8209. lstatSync: fs__default['default'].lstatSync,
  8210. stat: fs__default['default'].stat,
  8211. statSync: fs__default['default'].statSync,
  8212. readdir: fs__default['default'].readdir,
  8213. readdirSync: fs__default['default'].readdirSync
  8214. };
  8215. class Settings {
  8216. constructor(_options = {}) {
  8217. this._options = _options;
  8218. this.absolute = this._getValue(this._options.absolute, false);
  8219. this.baseNameMatch = this._getValue(this._options.baseNameMatch, false);
  8220. this.braceExpansion = this._getValue(this._options.braceExpansion, true);
  8221. this.caseSensitiveMatch = this._getValue(this._options.caseSensitiveMatch, true);
  8222. this.concurrency = this._getValue(this._options.concurrency, CPU_COUNT);
  8223. this.cwd = this._getValue(this._options.cwd, process.cwd());
  8224. this.deep = this._getValue(this._options.deep, Infinity);
  8225. this.dot = this._getValue(this._options.dot, false);
  8226. this.extglob = this._getValue(this._options.extglob, true);
  8227. this.followSymbolicLinks = this._getValue(this._options.followSymbolicLinks, true);
  8228. this.fs = this._getFileSystemMethods(this._options.fs);
  8229. this.globstar = this._getValue(this._options.globstar, true);
  8230. this.ignore = this._getValue(this._options.ignore, []);
  8231. this.markDirectories = this._getValue(this._options.markDirectories, false);
  8232. this.objectMode = this._getValue(this._options.objectMode, false);
  8233. this.onlyDirectories = this._getValue(this._options.onlyDirectories, false);
  8234. this.onlyFiles = this._getValue(this._options.onlyFiles, true);
  8235. this.stats = this._getValue(this._options.stats, false);
  8236. this.suppressErrors = this._getValue(this._options.suppressErrors, false);
  8237. this.throwErrorOnBrokenSymbolicLink = this._getValue(this._options.throwErrorOnBrokenSymbolicLink, false);
  8238. this.unique = this._getValue(this._options.unique, true);
  8239. if (this.onlyDirectories) {
  8240. this.onlyFiles = false;
  8241. }
  8242. if (this.stats) {
  8243. this.objectMode = true;
  8244. }
  8245. }
  8246. _getValue(option, value) {
  8247. return option === undefined ? value : option;
  8248. }
  8249. _getFileSystemMethods(methods = {}) {
  8250. return Object.assign(Object.assign({}, exports.DEFAULT_FILE_SYSTEM_ADAPTER), methods);
  8251. }
  8252. }
  8253. exports.default = Settings;
  8254. });
  8255. async function FastGlob(source, options) {
  8256. assertPatternsInput(source);
  8257. const works = getWorks(source, async.default, options);
  8258. const result = await Promise.all(works);
  8259. return utils$1.array.flatten(result);
  8260. } // https://github.com/typescript-eslint/typescript-eslint/issues/60
  8261. // eslint-disable-next-line no-redeclare
  8262. (function (FastGlob) {
  8263. function sync$1(source, options) {
  8264. assertPatternsInput(source);
  8265. const works = getWorks(source, sync.default, options);
  8266. return utils$1.array.flatten(works);
  8267. }
  8268. FastGlob.sync = sync$1;
  8269. function stream$1(source, options) {
  8270. assertPatternsInput(source);
  8271. const works = getWorks(source, stream.default, options);
  8272. /**
  8273. * The stream returned by the provider cannot work with an asynchronous iterator.
  8274. * To support asynchronous iterators, regardless of the number of tasks, we always multiplex streams.
  8275. * This affects performance (+25%). I don't see best solution right now.
  8276. */
  8277. return utils$1.stream.merge(works);
  8278. }
  8279. FastGlob.stream = stream$1;
  8280. function generateTasks(source, options) {
  8281. assertPatternsInput(source);
  8282. const patterns = [].concat(source);
  8283. const settings$1 = new settings.default(options);
  8284. return tasks.generate(patterns, settings$1);
  8285. }
  8286. FastGlob.generateTasks = generateTasks;
  8287. function isDynamicPattern(source, options) {
  8288. assertPatternsInput(source);
  8289. const settings$1 = new settings.default(options);
  8290. return utils$1.pattern.isDynamicPattern(source, settings$1);
  8291. }
  8292. FastGlob.isDynamicPattern = isDynamicPattern;
  8293. function escapePath(source) {
  8294. assertPatternsInput(source);
  8295. return utils$1.path.escape(source);
  8296. }
  8297. FastGlob.escapePath = escapePath;
  8298. })(FastGlob || (FastGlob = {}));
  8299. function getWorks(source, _Provider, options) {
  8300. const patterns = [].concat(source);
  8301. const settings$1 = new settings.default(options);
  8302. const tasks$1 = tasks.generate(patterns, settings$1);
  8303. const provider = new _Provider(settings$1);
  8304. return tasks$1.map(provider.read, provider);
  8305. }
  8306. function assertPatternsInput(input) {
  8307. const source = [].concat(input);
  8308. const isValidSource = source.every(item => utils$1.string.isString(item) && !utils$1.string.isEmpty(item));
  8309. if (!isValidSource) {
  8310. throw new TypeError('Patterns must be a string (non empty) or an array of strings');
  8311. }
  8312. }
  8313. var out = FastGlob;
  8314. const {
  8315. promises: fs$1
  8316. } = fs__default['default'];
  8317. /** @typedef {import('./context').Context} Context */
  8318. /**
  8319. * @param {Context} context
  8320. */
  8321. async function* expandPatterns$1(context) {
  8322. const cwd = process.cwd();
  8323. const seen = new Set();
  8324. let noResults = true;
  8325. for await (const pathOrError of expandPatternsInternal(context)) {
  8326. noResults = false;
  8327. if (typeof pathOrError !== "string") {
  8328. yield pathOrError;
  8329. continue;
  8330. }
  8331. const relativePath = path__default['default'].relative(cwd, pathOrError); // filter out duplicates
  8332. if (seen.has(relativePath)) {
  8333. continue;
  8334. }
  8335. seen.add(relativePath);
  8336. yield relativePath;
  8337. }
  8338. if (noResults && context.argv["error-on-unmatched-pattern"] !== false) {
  8339. // If there was no files and no other errors, let's yield a general error.
  8340. yield {
  8341. error: `No matching files. Patterns: ${context.filePatterns.join(" ")}`
  8342. };
  8343. }
  8344. }
  8345. /**
  8346. * @param {Context} context
  8347. */
  8348. async function* expandPatternsInternal(context) {
  8349. // Ignores files in version control systems directories and `node_modules`
  8350. const silentlyIgnoredDirs = [".git", ".svn", ".hg"];
  8351. if (context.argv["with-node-modules"] !== true) {
  8352. silentlyIgnoredDirs.push("node_modules");
  8353. }
  8354. const globOptions = {
  8355. dot: true,
  8356. ignore: silentlyIgnoredDirs.map(dir => "**/" + dir)
  8357. };
  8358. let supportedFilesGlob;
  8359. const cwd = process.cwd();
  8360. /** @type {Array<{ type: 'file' | 'dir' | 'glob'; glob: string; input: string; }>} */
  8361. const entries = [];
  8362. for (const pattern of context.filePatterns) {
  8363. const absolutePath = path__default['default'].resolve(cwd, pattern);
  8364. if (containsIgnoredPathSegment(absolutePath, cwd, silentlyIgnoredDirs)) {
  8365. continue;
  8366. }
  8367. const stat = await statSafe(absolutePath);
  8368. if (stat) {
  8369. if (stat.isFile()) {
  8370. entries.push({
  8371. type: "file",
  8372. glob: escapePathForGlob(fixWindowsSlashes$1(pattern)),
  8373. input: pattern
  8374. });
  8375. } else if (stat.isDirectory()) {
  8376. /*
  8377. 1. Remove trailing `/`, `fast-glob` can't find files for `src//*.js` pattern
  8378. 2. Cleanup dirname, when glob `src/../*.js` pattern with `fast-glob`,
  8379. it returns files like 'src/../index.js'
  8380. */
  8381. const relativePath = path__default['default'].relative(cwd, absolutePath) || ".";
  8382. entries.push({
  8383. type: "dir",
  8384. glob: escapePathForGlob(fixWindowsSlashes$1(relativePath)) + "/" + getSupportedFilesGlob(),
  8385. input: pattern
  8386. });
  8387. }
  8388. } else if (pattern[0] === "!") {
  8389. // convert negative patterns to `ignore` entries
  8390. globOptions.ignore.push(fixWindowsSlashes$1(pattern.slice(1)));
  8391. } else {
  8392. entries.push({
  8393. type: "glob",
  8394. glob: fixWindowsSlashes$1(pattern),
  8395. input: pattern
  8396. });
  8397. }
  8398. }
  8399. for (const {
  8400. type,
  8401. glob,
  8402. input
  8403. } of entries) {
  8404. let result;
  8405. try {
  8406. result = await out(glob, globOptions);
  8407. } catch ({
  8408. message
  8409. }) {
  8410. /* istanbul ignore next */
  8411. yield {
  8412. error: `${errorMessages.globError[type]}: ${input}\n${message}`
  8413. };
  8414. /* istanbul ignore next */
  8415. continue;
  8416. }
  8417. if (result.length === 0) {
  8418. if (context.argv["error-on-unmatched-pattern"] !== false) {
  8419. yield {
  8420. error: `${errorMessages.emptyResults[type]}: "${input}".`
  8421. };
  8422. }
  8423. } else {
  8424. yield* sortPaths(result);
  8425. }
  8426. }
  8427. function getSupportedFilesGlob() {
  8428. if (!supportedFilesGlob) {
  8429. const extensions = context.languages.flatMap(lang => lang.extensions || []);
  8430. const filenames = context.languages.flatMap(lang => lang.filenames || []);
  8431. supportedFilesGlob = `**/{${[...extensions.map(ext => "*" + (ext[0] === "." ? ext : "." + ext)), ...filenames]}}`;
  8432. }
  8433. return supportedFilesGlob;
  8434. }
  8435. }
  8436. const errorMessages = {
  8437. globError: {
  8438. file: "Unable to resolve file",
  8439. dir: "Unable to expand directory",
  8440. glob: "Unable to expand glob pattern"
  8441. },
  8442. emptyResults: {
  8443. file: "Explicitly specified file was ignored due to negative glob patterns",
  8444. dir: "No supported files were found in the directory",
  8445. glob: "No files matching the pattern were found"
  8446. }
  8447. };
  8448. /**
  8449. * @param {string} absolutePath
  8450. * @param {string} cwd
  8451. * @param {string[]} ignoredDirectories
  8452. */
  8453. function containsIgnoredPathSegment(absolutePath, cwd, ignoredDirectories) {
  8454. return path__default['default'].relative(cwd, absolutePath).split(path__default['default'].sep).some(dir => ignoredDirectories.includes(dir));
  8455. }
  8456. /**
  8457. * @param {string[]} paths
  8458. */
  8459. function sortPaths(paths) {
  8460. return paths.sort((a, b) => a.localeCompare(b));
  8461. }
  8462. /**
  8463. * Get stats of a given path.
  8464. * @param {string} filePath The path to target file.
  8465. * @returns {Promise<import('fs').Stats | undefined>} The stats.
  8466. */
  8467. async function statSafe(filePath) {
  8468. try {
  8469. return await fs$1.stat(filePath);
  8470. } catch (error) {
  8471. /* istanbul ignore next */
  8472. if (error.code !== "ENOENT") {
  8473. throw error;
  8474. }
  8475. }
  8476. }
  8477. /**
  8478. * This function should be replaced with `fastGlob.escapePath` when these issues are fixed:
  8479. * - https://github.com/mrmlnc/fast-glob/issues/261
  8480. * - https://github.com/mrmlnc/fast-glob/issues/262
  8481. * @param {string} path
  8482. */
  8483. function escapePathForGlob(path) {
  8484. return out.escapePath(path.replace(/\\/g, "\0") // Workaround for fast-glob#262 (part 1)
  8485. ).replace(/\\!/g, "@(!)") // Workaround for fast-glob#261
  8486. .replace(/\0/g, "@(\\\\)"); // Workaround for fast-glob#262 (part 2)
  8487. }
  8488. const isWindows = path__default['default'].sep === "\\";
  8489. /**
  8490. * Using backslashes in globs is probably not okay, but not accepting
  8491. * backslashes as path separators on Windows is even more not okay.
  8492. * https://github.com/prettier/prettier/pull/6776#discussion_r380723717
  8493. * https://github.com/mrmlnc/fast-glob#how-to-write-patterns-on-windows
  8494. * @param {string} pattern
  8495. */
  8496. function fixWindowsSlashes$1(pattern) {
  8497. return isWindows ? pattern.replace(/\\/g, "/") : pattern;
  8498. }
  8499. var expandPatterns_1 = {
  8500. expandPatterns: expandPatterns$1,
  8501. fixWindowsSlashes: fixWindowsSlashes$1
  8502. };
  8503. var iterators = {};
  8504. var ITERATOR$1 = wellKnownSymbol('iterator');
  8505. var ArrayPrototype = Array.prototype;
  8506. // check on default Array iterator
  8507. var isArrayIteratorMethod = function (it) {
  8508. return it !== undefined && (iterators.Array === it || ArrayPrototype[ITERATOR$1] === it);
  8509. };
  8510. var TO_STRING_TAG$1 = wellKnownSymbol('toStringTag');
  8511. var test = {};
  8512. test[TO_STRING_TAG$1] = 'z';
  8513. var toStringTagSupport = String(test) === '[object z]';
  8514. var TO_STRING_TAG = wellKnownSymbol('toStringTag');
  8515. // ES3 wrong here
  8516. var CORRECT_ARGUMENTS = classofRaw(function () { return arguments; }()) == 'Arguments';
  8517. // fallback for IE11 Script Access Denied error
  8518. var tryGet = function (it, key) {
  8519. try {
  8520. return it[key];
  8521. } catch (error) { /* empty */ }
  8522. };
  8523. // getting tag from ES6+ `Object.prototype.toString`
  8524. var classof = toStringTagSupport ? classofRaw : function (it) {
  8525. var O, tag, result;
  8526. return it === undefined ? 'Undefined' : it === null ? 'Null'
  8527. // @@toStringTag case
  8528. : typeof (tag = tryGet(O = Object(it), TO_STRING_TAG)) == 'string' ? tag
  8529. // builtinTag case
  8530. : CORRECT_ARGUMENTS ? classofRaw(O)
  8531. // ES3 arguments fallback
  8532. : (result = classofRaw(O)) == 'Object' && typeof O.callee == 'function' ? 'Arguments' : result;
  8533. };
  8534. var ITERATOR = wellKnownSymbol('iterator');
  8535. var getIteratorMethod = function (it) {
  8536. if (it != undefined) return it[ITERATOR]
  8537. || it['@@iterator']
  8538. || iterators[classof(it)];
  8539. };
  8540. var getIterator = function (it, usingIterator) {
  8541. var iteratorMethod = arguments.length < 2 ? getIteratorMethod(it) : usingIterator;
  8542. if (typeof iteratorMethod != 'function') {
  8543. throw TypeError(String(it) + ' is not iterable');
  8544. } return anObject(iteratorMethod.call(it));
  8545. };
  8546. var iteratorClose = function (iterator, kind, value) {
  8547. var innerResult, innerError;
  8548. anObject(iterator);
  8549. try {
  8550. innerResult = iterator['return'];
  8551. if (innerResult === undefined) {
  8552. if (kind === 'throw') throw value;
  8553. return value;
  8554. }
  8555. innerResult = innerResult.call(iterator);
  8556. } catch (error) {
  8557. innerError = true;
  8558. innerResult = error;
  8559. }
  8560. if (kind === 'throw') throw value;
  8561. if (innerError) throw innerResult;
  8562. anObject(innerResult);
  8563. return value;
  8564. };
  8565. var Result = function (stopped, result) {
  8566. this.stopped = stopped;
  8567. this.result = result;
  8568. };
  8569. var iterate = function (iterable, unboundFunction, options) {
  8570. var that = options && options.that;
  8571. var AS_ENTRIES = !!(options && options.AS_ENTRIES);
  8572. var IS_ITERATOR = !!(options && options.IS_ITERATOR);
  8573. var INTERRUPTED = !!(options && options.INTERRUPTED);
  8574. var fn = functionBindContext(unboundFunction, that, 1 + AS_ENTRIES + INTERRUPTED);
  8575. var iterator, iterFn, index, length, result, next, step;
  8576. var stop = function (condition) {
  8577. if (iterator) iteratorClose(iterator, 'normal', condition);
  8578. return new Result(true, condition);
  8579. };
  8580. var callFn = function (value) {
  8581. if (AS_ENTRIES) {
  8582. anObject(value);
  8583. return INTERRUPTED ? fn(value[0], value[1], stop) : fn(value[0], value[1]);
  8584. } return INTERRUPTED ? fn(value, stop) : fn(value);
  8585. };
  8586. if (IS_ITERATOR) {
  8587. iterator = iterable;
  8588. } else {
  8589. iterFn = getIteratorMethod(iterable);
  8590. if (typeof iterFn != 'function') throw TypeError('Target is not iterable');
  8591. // optimisation for array iterators
  8592. if (isArrayIteratorMethod(iterFn)) {
  8593. for (index = 0, length = toLength(iterable.length); length > index; index++) {
  8594. result = callFn(iterable[index]);
  8595. if (result && result instanceof Result) return result;
  8596. } return new Result(false);
  8597. }
  8598. iterator = getIterator(iterable, iterFn);
  8599. }
  8600. next = iterator.next;
  8601. while (!(step = next.call(iterator)).done) {
  8602. try {
  8603. result = callFn(step.value);
  8604. } catch (error) {
  8605. iteratorClose(iterator, 'throw', error);
  8606. }
  8607. if (typeof result == 'object' && result && result instanceof Result) return result;
  8608. } return new Result(false);
  8609. };
  8610. var createProperty = function (object, key, value) {
  8611. var propertyKey = toPropertyKey(key);
  8612. if (propertyKey in object) objectDefineProperty.f(object, propertyKey, createPropertyDescriptor(0, value));
  8613. else object[propertyKey] = value;
  8614. };
  8615. // `Object.fromEntries` method
  8616. // https://github.com/tc39/proposal-object-from-entries
  8617. _export({ target: 'Object', stat: true }, {
  8618. fromEntries: function fromEntries(iterable) {
  8619. var obj = {};
  8620. iterate(iterable, function (k, v) {
  8621. createProperty(obj, k, v);
  8622. }, { AS_ENTRIES: true });
  8623. return obj;
  8624. }
  8625. });
  8626. /*!
  8627. * dashify <https://github.com/jonschlinkert/dashify>
  8628. *
  8629. * Copyright (c) 2015-2017, Jon Schlinkert.
  8630. * Released under the MIT License.
  8631. */
  8632. var dashify = (str, options) => {
  8633. if (typeof str !== 'string') throw new TypeError('expected a string');
  8634. return str.trim().replace(/([a-z])([A-Z])/g, '$1-$2').replace(/\W/g, m => /[À-ž]/.test(m) ? m : '-').replace(/^-+|-+$/g, '').replace(/-{2,}/g, m => options && options.condense ? '-' : m).toLowerCase();
  8635. };
  8636. var minimist = function (args, opts) {
  8637. if (!opts) opts = {};
  8638. var flags = {
  8639. bools: {},
  8640. strings: {},
  8641. unknownFn: null
  8642. };
  8643. if (typeof opts['unknown'] === 'function') {
  8644. flags.unknownFn = opts['unknown'];
  8645. }
  8646. if (typeof opts['boolean'] === 'boolean' && opts['boolean']) {
  8647. flags.allBools = true;
  8648. } else {
  8649. [].concat(opts['boolean']).filter(Boolean).forEach(function (key) {
  8650. flags.bools[key] = true;
  8651. });
  8652. }
  8653. var aliases = {};
  8654. Object.keys(opts.alias || {}).forEach(function (key) {
  8655. aliases[key] = [].concat(opts.alias[key]);
  8656. aliases[key].forEach(function (x) {
  8657. aliases[x] = [key].concat(aliases[key].filter(function (y) {
  8658. return x !== y;
  8659. }));
  8660. });
  8661. });
  8662. [].concat(opts.string).filter(Boolean).forEach(function (key) {
  8663. flags.strings[key] = true;
  8664. if (aliases[key]) {
  8665. flags.strings[aliases[key]] = true;
  8666. }
  8667. });
  8668. var defaults = opts['default'] || {};
  8669. var argv = {
  8670. _: []
  8671. };
  8672. Object.keys(flags.bools).forEach(function (key) {
  8673. setArg(key, defaults[key] === undefined ? false : defaults[key]);
  8674. });
  8675. var notFlags = [];
  8676. if (args.indexOf('--') !== -1) {
  8677. notFlags = args.slice(args.indexOf('--') + 1);
  8678. args = args.slice(0, args.indexOf('--'));
  8679. }
  8680. function argDefined(key, arg) {
  8681. return flags.allBools && /^--[^=]+$/.test(arg) || flags.strings[key] || flags.bools[key] || aliases[key];
  8682. }
  8683. function setArg(key, val, arg) {
  8684. if (arg && flags.unknownFn && !argDefined(key, arg)) {
  8685. if (flags.unknownFn(arg) === false) return;
  8686. }
  8687. var value = !flags.strings[key] && isNumber(val) ? Number(val) : val;
  8688. setKey(argv, key.split('.'), value);
  8689. (aliases[key] || []).forEach(function (x) {
  8690. setKey(argv, x.split('.'), value);
  8691. });
  8692. }
  8693. function setKey(obj, keys, value) {
  8694. var o = obj;
  8695. for (var i = 0; i < keys.length - 1; i++) {
  8696. var key = keys[i];
  8697. if (key === '__proto__') return;
  8698. if (o[key] === undefined) o[key] = {};
  8699. if (o[key] === Object.prototype || o[key] === Number.prototype || o[key] === String.prototype) o[key] = {};
  8700. if (o[key] === Array.prototype) o[key] = [];
  8701. o = o[key];
  8702. }
  8703. var key = keys[keys.length - 1];
  8704. if (key === '__proto__') return;
  8705. if (o === Object.prototype || o === Number.prototype || o === String.prototype) o = {};
  8706. if (o === Array.prototype) o = [];
  8707. if (o[key] === undefined || flags.bools[key] || typeof o[key] === 'boolean') {
  8708. o[key] = value;
  8709. } else if (Array.isArray(o[key])) {
  8710. o[key].push(value);
  8711. } else {
  8712. o[key] = [o[key], value];
  8713. }
  8714. }
  8715. function aliasIsBoolean(key) {
  8716. return aliases[key].some(function (x) {
  8717. return flags.bools[x];
  8718. });
  8719. }
  8720. for (var i = 0; i < args.length; i++) {
  8721. var arg = args[i];
  8722. if (/^--.+=/.test(arg)) {
  8723. // Using [\s\S] instead of . because js doesn't support the
  8724. // 'dotall' regex modifier. See:
  8725. // http://stackoverflow.com/a/1068308/13216
  8726. var m = arg.match(/^--([^=]+)=([\s\S]*)$/);
  8727. var key = m[1];
  8728. var value = m[2];
  8729. if (flags.bools[key]) {
  8730. value = value !== 'false';
  8731. }
  8732. setArg(key, value, arg);
  8733. } else if (/^--no-.+/.test(arg)) {
  8734. var key = arg.match(/^--no-(.+)/)[1];
  8735. setArg(key, false, arg);
  8736. } else if (/^--.+/.test(arg)) {
  8737. var key = arg.match(/^--(.+)/)[1];
  8738. var next = args[i + 1];
  8739. if (next !== undefined && !/^-/.test(next) && !flags.bools[key] && !flags.allBools && (aliases[key] ? !aliasIsBoolean(key) : true)) {
  8740. setArg(key, next, arg);
  8741. i++;
  8742. } else if (/^(true|false)$/.test(next)) {
  8743. setArg(key, next === 'true', arg);
  8744. i++;
  8745. } else {
  8746. setArg(key, flags.strings[key] ? '' : true, arg);
  8747. }
  8748. } else if (/^-[^-]+/.test(arg)) {
  8749. var letters = arg.slice(1, -1).split('');
  8750. var broken = false;
  8751. for (var j = 0; j < letters.length; j++) {
  8752. var next = arg.slice(j + 2);
  8753. if (next === '-') {
  8754. setArg(letters[j], next, arg);
  8755. continue;
  8756. }
  8757. if (/[A-Za-z]/.test(letters[j]) && /=/.test(next)) {
  8758. setArg(letters[j], next.split('=')[1], arg);
  8759. broken = true;
  8760. break;
  8761. }
  8762. if (/[A-Za-z]/.test(letters[j]) && /-?\d+(\.\d*)?(e-?\d+)?$/.test(next)) {
  8763. setArg(letters[j], next, arg);
  8764. broken = true;
  8765. break;
  8766. }
  8767. if (letters[j + 1] && letters[j + 1].match(/\W/)) {
  8768. setArg(letters[j], arg.slice(j + 2), arg);
  8769. broken = true;
  8770. break;
  8771. } else {
  8772. setArg(letters[j], flags.strings[letters[j]] ? '' : true, arg);
  8773. }
  8774. }
  8775. var key = arg.slice(-1)[0];
  8776. if (!broken && key !== '-') {
  8777. if (args[i + 1] && !/^(-|--)[^-]/.test(args[i + 1]) && !flags.bools[key] && (aliases[key] ? !aliasIsBoolean(key) : true)) {
  8778. setArg(key, args[i + 1], arg);
  8779. i++;
  8780. } else if (args[i + 1] && /^(true|false)$/.test(args[i + 1])) {
  8781. setArg(key, args[i + 1] === 'true', arg);
  8782. i++;
  8783. } else {
  8784. setArg(key, flags.strings[key] ? '' : true, arg);
  8785. }
  8786. }
  8787. } else {
  8788. if (!flags.unknownFn || flags.unknownFn(arg) !== false) {
  8789. argv._.push(flags.strings['_'] || !isNumber(arg) ? arg : Number(arg));
  8790. }
  8791. if (opts.stopEarly) {
  8792. argv._.push.apply(argv._, args.slice(i + 1));
  8793. break;
  8794. }
  8795. }
  8796. }
  8797. Object.keys(defaults).forEach(function (key) {
  8798. if (!hasKey(argv, key.split('.'))) {
  8799. setKey(argv, key.split('.'), defaults[key]);
  8800. (aliases[key] || []).forEach(function (x) {
  8801. setKey(argv, x.split('.'), defaults[key]);
  8802. });
  8803. }
  8804. });
  8805. if (opts['--']) {
  8806. argv['--'] = new Array();
  8807. notFlags.forEach(function (key) {
  8808. argv['--'].push(key);
  8809. });
  8810. } else {
  8811. notFlags.forEach(function (key) {
  8812. argv._.push(key);
  8813. });
  8814. }
  8815. return argv;
  8816. };
  8817. function hasKey(obj, keys) {
  8818. var o = obj;
  8819. keys.slice(0, -1).forEach(function (key) {
  8820. o = o[key] || {};
  8821. });
  8822. var key = keys[keys.length - 1];
  8823. return key in o;
  8824. }
  8825. function isNumber(x) {
  8826. if (typeof x === 'number') return true;
  8827. if (/^0x[0-9a-f]+$/i.test(x)) return true;
  8828. return /^[-+]?(?:\d+(?:\.\d*)?|\.\d+)(e[-+]?\d+)?$/.test(x);
  8829. }
  8830. const PLACEHOLDER = null;
  8831. /**
  8832. * unspecified boolean flag without default value is parsed as `undefined` instead of `false`
  8833. */
  8834. var minimist_1 = function (args, options) {
  8835. const boolean = options.boolean || [];
  8836. const defaults = options.default || {};
  8837. const booleanWithoutDefault = boolean.filter(key => !(key in defaults));
  8838. const newDefaults = Object.assign(Object.assign({}, defaults), Object.fromEntries(booleanWithoutDefault.map(key => [key, PLACEHOLDER])));
  8839. const parsed = minimist(args, Object.assign(Object.assign({}, options), {}, {
  8840. default: newDefaults
  8841. }));
  8842. return Object.fromEntries(Object.entries(parsed).filter(([, value]) => value !== PLACEHOLDER));
  8843. };
  8844. /**
  8845. * A specialized version of `baseAggregator` for arrays.
  8846. *
  8847. * @private
  8848. * @param {Array} [array] The array to iterate over.
  8849. * @param {Function} setter The function to set `accumulator` values.
  8850. * @param {Function} iteratee The iteratee to transform keys.
  8851. * @param {Object} accumulator The initial aggregated object.
  8852. * @returns {Function} Returns `accumulator`.
  8853. */
  8854. function arrayAggregator(array, setter, iteratee, accumulator) {
  8855. var index = -1,
  8856. length = array == null ? 0 : array.length;
  8857. while (++index < length) {
  8858. var value = array[index];
  8859. setter(accumulator, value, iteratee(value), array);
  8860. }
  8861. return accumulator;
  8862. }
  8863. var _arrayAggregator = arrayAggregator;
  8864. /**
  8865. * Creates a base function for methods like `_.forIn` and `_.forOwn`.
  8866. *
  8867. * @private
  8868. * @param {boolean} [fromRight] Specify iterating from right to left.
  8869. * @returns {Function} Returns the new base function.
  8870. */
  8871. function createBaseFor(fromRight) {
  8872. return function (object, iteratee, keysFunc) {
  8873. var index = -1,
  8874. iterable = Object(object),
  8875. props = keysFunc(object),
  8876. length = props.length;
  8877. while (length--) {
  8878. var key = props[fromRight ? length : ++index];
  8879. if (iteratee(iterable[key], key, iterable) === false) {
  8880. break;
  8881. }
  8882. }
  8883. return object;
  8884. };
  8885. }
  8886. var _createBaseFor = createBaseFor;
  8887. /**
  8888. * The base implementation of `baseForOwn` which iterates over `object`
  8889. * properties returned by `keysFunc` and invokes `iteratee` for each property.
  8890. * Iteratee functions may exit iteration early by explicitly returning `false`.
  8891. *
  8892. * @private
  8893. * @param {Object} object The object to iterate over.
  8894. * @param {Function} iteratee The function invoked per iteration.
  8895. * @param {Function} keysFunc The function to get the keys of `object`.
  8896. * @returns {Object} Returns `object`.
  8897. */
  8898. var baseFor = _createBaseFor();
  8899. var _baseFor = baseFor;
  8900. /**
  8901. * The base implementation of `_.times` without support for iteratee shorthands
  8902. * or max array length checks.
  8903. *
  8904. * @private
  8905. * @param {number} n The number of times to invoke `iteratee`.
  8906. * @param {Function} iteratee The function invoked per iteration.
  8907. * @returns {Array} Returns the array of results.
  8908. */
  8909. function baseTimes(n, iteratee) {
  8910. var index = -1,
  8911. result = Array(n);
  8912. while (++index < n) {
  8913. result[index] = iteratee(index);
  8914. }
  8915. return result;
  8916. }
  8917. var _baseTimes = baseTimes;
  8918. /** Detect free variable `global` from Node.js. */
  8919. var freeGlobal = typeof global == 'object' && global && global.Object === Object && global;
  8920. var _freeGlobal = freeGlobal;
  8921. /** Detect free variable `self`. */
  8922. var freeSelf = typeof self == 'object' && self && self.Object === Object && self;
  8923. /** Used as a reference to the global object. */
  8924. var root = _freeGlobal || freeSelf || Function('return this')();
  8925. var _root = root;
  8926. /** Built-in value references. */
  8927. var Symbol$1 = _root.Symbol;
  8928. var _Symbol = Symbol$1;
  8929. /** Used for built-in method references. */
  8930. var objectProto$d = Object.prototype;
  8931. /** Used to check objects for own properties. */
  8932. var hasOwnProperty$a = objectProto$d.hasOwnProperty;
  8933. /**
  8934. * Used to resolve the
  8935. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  8936. * of values.
  8937. */
  8938. var nativeObjectToString$1 = objectProto$d.toString;
  8939. /** Built-in value references. */
  8940. var symToStringTag$1 = _Symbol ? _Symbol.toStringTag : undefined;
  8941. /**
  8942. * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values.
  8943. *
  8944. * @private
  8945. * @param {*} value The value to query.
  8946. * @returns {string} Returns the raw `toStringTag`.
  8947. */
  8948. function getRawTag(value) {
  8949. var isOwn = hasOwnProperty$a.call(value, symToStringTag$1),
  8950. tag = value[symToStringTag$1];
  8951. try {
  8952. value[symToStringTag$1] = undefined;
  8953. var unmasked = true;
  8954. } catch (e) {}
  8955. var result = nativeObjectToString$1.call(value);
  8956. if (unmasked) {
  8957. if (isOwn) {
  8958. value[symToStringTag$1] = tag;
  8959. } else {
  8960. delete value[symToStringTag$1];
  8961. }
  8962. }
  8963. return result;
  8964. }
  8965. var _getRawTag = getRawTag;
  8966. /** Used for built-in method references. */
  8967. var objectProto$c = Object.prototype;
  8968. /**
  8969. * Used to resolve the
  8970. * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring)
  8971. * of values.
  8972. */
  8973. var nativeObjectToString = objectProto$c.toString;
  8974. /**
  8975. * Converts `value` to a string using `Object.prototype.toString`.
  8976. *
  8977. * @private
  8978. * @param {*} value The value to convert.
  8979. * @returns {string} Returns the converted string.
  8980. */
  8981. function objectToString(value) {
  8982. return nativeObjectToString.call(value);
  8983. }
  8984. var _objectToString = objectToString;
  8985. /** `Object#toString` result references. */
  8986. var nullTag = '[object Null]',
  8987. undefinedTag = '[object Undefined]';
  8988. /** Built-in value references. */
  8989. var symToStringTag = _Symbol ? _Symbol.toStringTag : undefined;
  8990. /**
  8991. * The base implementation of `getTag` without fallbacks for buggy environments.
  8992. *
  8993. * @private
  8994. * @param {*} value The value to query.
  8995. * @returns {string} Returns the `toStringTag`.
  8996. */
  8997. function baseGetTag(value) {
  8998. if (value == null) {
  8999. return value === undefined ? undefinedTag : nullTag;
  9000. }
  9001. return symToStringTag && symToStringTag in Object(value) ? _getRawTag(value) : _objectToString(value);
  9002. }
  9003. var _baseGetTag = baseGetTag;
  9004. /**
  9005. * Checks if `value` is object-like. A value is object-like if it's not `null`
  9006. * and has a `typeof` result of "object".
  9007. *
  9008. * @static
  9009. * @memberOf _
  9010. * @since 4.0.0
  9011. * @category Lang
  9012. * @param {*} value The value to check.
  9013. * @returns {boolean} Returns `true` if `value` is object-like, else `false`.
  9014. * @example
  9015. *
  9016. * _.isObjectLike({});
  9017. * // => true
  9018. *
  9019. * _.isObjectLike([1, 2, 3]);
  9020. * // => true
  9021. *
  9022. * _.isObjectLike(_.noop);
  9023. * // => false
  9024. *
  9025. * _.isObjectLike(null);
  9026. * // => false
  9027. */
  9028. function isObjectLike(value) {
  9029. return value != null && typeof value == 'object';
  9030. }
  9031. var isObjectLike_1 = isObjectLike;
  9032. /** `Object#toString` result references. */
  9033. var argsTag$2 = '[object Arguments]';
  9034. /**
  9035. * The base implementation of `_.isArguments`.
  9036. *
  9037. * @private
  9038. * @param {*} value The value to check.
  9039. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  9040. */
  9041. function baseIsArguments(value) {
  9042. return isObjectLike_1(value) && _baseGetTag(value) == argsTag$2;
  9043. }
  9044. var _baseIsArguments = baseIsArguments;
  9045. /** Used for built-in method references. */
  9046. var objectProto$b = Object.prototype;
  9047. /** Used to check objects for own properties. */
  9048. var hasOwnProperty$9 = objectProto$b.hasOwnProperty;
  9049. /** Built-in value references. */
  9050. var propertyIsEnumerable$1 = objectProto$b.propertyIsEnumerable;
  9051. /**
  9052. * Checks if `value` is likely an `arguments` object.
  9053. *
  9054. * @static
  9055. * @memberOf _
  9056. * @since 0.1.0
  9057. * @category Lang
  9058. * @param {*} value The value to check.
  9059. * @returns {boolean} Returns `true` if `value` is an `arguments` object,
  9060. * else `false`.
  9061. * @example
  9062. *
  9063. * _.isArguments(function() { return arguments; }());
  9064. * // => true
  9065. *
  9066. * _.isArguments([1, 2, 3]);
  9067. * // => false
  9068. */
  9069. var isArguments = _baseIsArguments(function () {
  9070. return arguments;
  9071. }()) ? _baseIsArguments : function (value) {
  9072. return isObjectLike_1(value) && hasOwnProperty$9.call(value, 'callee') && !propertyIsEnumerable$1.call(value, 'callee');
  9073. };
  9074. var isArguments_1 = isArguments;
  9075. /**
  9076. * Checks if `value` is classified as an `Array` object.
  9077. *
  9078. * @static
  9079. * @memberOf _
  9080. * @since 0.1.0
  9081. * @category Lang
  9082. * @param {*} value The value to check.
  9083. * @returns {boolean} Returns `true` if `value` is an array, else `false`.
  9084. * @example
  9085. *
  9086. * _.isArray([1, 2, 3]);
  9087. * // => true
  9088. *
  9089. * _.isArray(document.body.children);
  9090. * // => false
  9091. *
  9092. * _.isArray('abc');
  9093. * // => false
  9094. *
  9095. * _.isArray(_.noop);
  9096. * // => false
  9097. */
  9098. var isArray = Array.isArray;
  9099. var isArray_1 = isArray;
  9100. /**
  9101. * This method returns `false`.
  9102. *
  9103. * @static
  9104. * @memberOf _
  9105. * @since 4.13.0
  9106. * @category Util
  9107. * @returns {boolean} Returns `false`.
  9108. * @example
  9109. *
  9110. * _.times(2, _.stubFalse);
  9111. * // => [false, false]
  9112. */
  9113. function stubFalse() {
  9114. return false;
  9115. }
  9116. var stubFalse_1 = stubFalse;
  9117. var isBuffer_1 = createCommonjsModule(function (module, exports) {
  9118. /** Detect free variable `exports`. */
  9119. var freeExports = exports && !exports.nodeType && exports;
  9120. /** Detect free variable `module`. */
  9121. var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
  9122. /** Detect the popular CommonJS extension `module.exports`. */
  9123. var moduleExports = freeModule && freeModule.exports === freeExports;
  9124. /** Built-in value references. */
  9125. var Buffer = moduleExports ? _root.Buffer : undefined;
  9126. /* Built-in method references for those with the same name as other `lodash` methods. */
  9127. var nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined;
  9128. /**
  9129. * Checks if `value` is a buffer.
  9130. *
  9131. * @static
  9132. * @memberOf _
  9133. * @since 4.3.0
  9134. * @category Lang
  9135. * @param {*} value The value to check.
  9136. * @returns {boolean} Returns `true` if `value` is a buffer, else `false`.
  9137. * @example
  9138. *
  9139. * _.isBuffer(new Buffer(2));
  9140. * // => true
  9141. *
  9142. * _.isBuffer(new Uint8Array(2));
  9143. * // => false
  9144. */
  9145. var isBuffer = nativeIsBuffer || stubFalse_1;
  9146. module.exports = isBuffer;
  9147. });
  9148. /** Used as references for various `Number` constants. */
  9149. var MAX_SAFE_INTEGER$1 = 9007199254740991;
  9150. /** Used to detect unsigned integer values. */
  9151. var reIsUint = /^(?:0|[1-9]\d*)$/;
  9152. /**
  9153. * Checks if `value` is a valid array-like index.
  9154. *
  9155. * @private
  9156. * @param {*} value The value to check.
  9157. * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
  9158. * @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
  9159. */
  9160. function isIndex(value, length) {
  9161. var type = typeof value;
  9162. length = length == null ? MAX_SAFE_INTEGER$1 : length;
  9163. return !!length && (type == 'number' || type != 'symbol' && reIsUint.test(value)) && value > -1 && value % 1 == 0 && value < length;
  9164. }
  9165. var _isIndex = isIndex;
  9166. /** Used as references for various `Number` constants. */
  9167. var MAX_SAFE_INTEGER = 9007199254740991;
  9168. /**
  9169. * Checks if `value` is a valid array-like length.
  9170. *
  9171. * **Note:** This method is loosely based on
  9172. * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength).
  9173. *
  9174. * @static
  9175. * @memberOf _
  9176. * @since 4.0.0
  9177. * @category Lang
  9178. * @param {*} value The value to check.
  9179. * @returns {boolean} Returns `true` if `value` is a valid length, else `false`.
  9180. * @example
  9181. *
  9182. * _.isLength(3);
  9183. * // => true
  9184. *
  9185. * _.isLength(Number.MIN_VALUE);
  9186. * // => false
  9187. *
  9188. * _.isLength(Infinity);
  9189. * // => false
  9190. *
  9191. * _.isLength('3');
  9192. * // => false
  9193. */
  9194. function isLength(value) {
  9195. return typeof value == 'number' && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
  9196. }
  9197. var isLength_1 = isLength;
  9198. /** `Object#toString` result references. */
  9199. var argsTag$1 = '[object Arguments]',
  9200. arrayTag$1 = '[object Array]',
  9201. boolTag$1 = '[object Boolean]',
  9202. dateTag$1 = '[object Date]',
  9203. errorTag$1 = '[object Error]',
  9204. funcTag$1 = '[object Function]',
  9205. mapTag$2 = '[object Map]',
  9206. numberTag$1 = '[object Number]',
  9207. objectTag$2 = '[object Object]',
  9208. regexpTag$1 = '[object RegExp]',
  9209. setTag$2 = '[object Set]',
  9210. stringTag$1 = '[object String]',
  9211. weakMapTag$1 = '[object WeakMap]';
  9212. var arrayBufferTag$1 = '[object ArrayBuffer]',
  9213. dataViewTag$2 = '[object DataView]',
  9214. float32Tag = '[object Float32Array]',
  9215. float64Tag = '[object Float64Array]',
  9216. int8Tag = '[object Int8Array]',
  9217. int16Tag = '[object Int16Array]',
  9218. int32Tag = '[object Int32Array]',
  9219. uint8Tag = '[object Uint8Array]',
  9220. uint8ClampedTag = '[object Uint8ClampedArray]',
  9221. uint16Tag = '[object Uint16Array]',
  9222. uint32Tag = '[object Uint32Array]';
  9223. /** Used to identify `toStringTag` values of typed arrays. */
  9224. var typedArrayTags = {};
  9225. typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = typedArrayTags[uint32Tag] = true;
  9226. typedArrayTags[argsTag$1] = typedArrayTags[arrayTag$1] = typedArrayTags[arrayBufferTag$1] = typedArrayTags[boolTag$1] = typedArrayTags[dataViewTag$2] = typedArrayTags[dateTag$1] = typedArrayTags[errorTag$1] = typedArrayTags[funcTag$1] = typedArrayTags[mapTag$2] = typedArrayTags[numberTag$1] = typedArrayTags[objectTag$2] = typedArrayTags[regexpTag$1] = typedArrayTags[setTag$2] = typedArrayTags[stringTag$1] = typedArrayTags[weakMapTag$1] = false;
  9227. /**
  9228. * The base implementation of `_.isTypedArray` without Node.js optimizations.
  9229. *
  9230. * @private
  9231. * @param {*} value The value to check.
  9232. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  9233. */
  9234. function baseIsTypedArray(value) {
  9235. return isObjectLike_1(value) && isLength_1(value.length) && !!typedArrayTags[_baseGetTag(value)];
  9236. }
  9237. var _baseIsTypedArray = baseIsTypedArray;
  9238. /**
  9239. * The base implementation of `_.unary` without support for storing metadata.
  9240. *
  9241. * @private
  9242. * @param {Function} func The function to cap arguments for.
  9243. * @returns {Function} Returns the new capped function.
  9244. */
  9245. function baseUnary(func) {
  9246. return function (value) {
  9247. return func(value);
  9248. };
  9249. }
  9250. var _baseUnary = baseUnary;
  9251. var _nodeUtil = createCommonjsModule(function (module, exports) {
  9252. /** Detect free variable `exports`. */
  9253. var freeExports = exports && !exports.nodeType && exports;
  9254. /** Detect free variable `module`. */
  9255. var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module;
  9256. /** Detect the popular CommonJS extension `module.exports`. */
  9257. var moduleExports = freeModule && freeModule.exports === freeExports;
  9258. /** Detect free variable `process` from Node.js. */
  9259. var freeProcess = moduleExports && _freeGlobal.process;
  9260. /** Used to access faster Node.js helpers. */
  9261. var nodeUtil = function () {
  9262. try {
  9263. // Use `util.types` for Node.js 10+.
  9264. var types = freeModule && freeModule.require && freeModule.require('util').types;
  9265. if (types) {
  9266. return types;
  9267. } // Legacy `process.binding('util')` for Node.js < 10.
  9268. return freeProcess && freeProcess.binding && freeProcess.binding('util');
  9269. } catch (e) {}
  9270. }();
  9271. module.exports = nodeUtil;
  9272. });
  9273. /* Node.js helper references. */
  9274. var nodeIsTypedArray = _nodeUtil && _nodeUtil.isTypedArray;
  9275. /**
  9276. * Checks if `value` is classified as a typed array.
  9277. *
  9278. * @static
  9279. * @memberOf _
  9280. * @since 3.0.0
  9281. * @category Lang
  9282. * @param {*} value The value to check.
  9283. * @returns {boolean} Returns `true` if `value` is a typed array, else `false`.
  9284. * @example
  9285. *
  9286. * _.isTypedArray(new Uint8Array);
  9287. * // => true
  9288. *
  9289. * _.isTypedArray([]);
  9290. * // => false
  9291. */
  9292. var isTypedArray = nodeIsTypedArray ? _baseUnary(nodeIsTypedArray) : _baseIsTypedArray;
  9293. var isTypedArray_1 = isTypedArray;
  9294. /** Used for built-in method references. */
  9295. var objectProto$a = Object.prototype;
  9296. /** Used to check objects for own properties. */
  9297. var hasOwnProperty$8 = objectProto$a.hasOwnProperty;
  9298. /**
  9299. * Creates an array of the enumerable property names of the array-like `value`.
  9300. *
  9301. * @private
  9302. * @param {*} value The value to query.
  9303. * @param {boolean} inherited Specify returning inherited property names.
  9304. * @returns {Array} Returns the array of property names.
  9305. */
  9306. function arrayLikeKeys(value, inherited) {
  9307. var isArr = isArray_1(value),
  9308. isArg = !isArr && isArguments_1(value),
  9309. isBuff = !isArr && !isArg && isBuffer_1(value),
  9310. isType = !isArr && !isArg && !isBuff && isTypedArray_1(value),
  9311. skipIndexes = isArr || isArg || isBuff || isType,
  9312. result = skipIndexes ? _baseTimes(value.length, String) : [],
  9313. length = result.length;
  9314. for (var key in value) {
  9315. if ((inherited || hasOwnProperty$8.call(value, key)) && !(skipIndexes && ( // Safari 9 has enumerable `arguments.length` in strict mode.
  9316. key == 'length' || isBuff && (key == 'offset' || key == 'parent') || isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset') || // Skip index properties.
  9317. _isIndex(key, length)))) {
  9318. result.push(key);
  9319. }
  9320. }
  9321. return result;
  9322. }
  9323. var _arrayLikeKeys = arrayLikeKeys;
  9324. /** Used for built-in method references. */
  9325. var objectProto$9 = Object.prototype;
  9326. /**
  9327. * Checks if `value` is likely a prototype object.
  9328. *
  9329. * @private
  9330. * @param {*} value The value to check.
  9331. * @returns {boolean} Returns `true` if `value` is a prototype, else `false`.
  9332. */
  9333. function isPrototype(value) {
  9334. var Ctor = value && value.constructor,
  9335. proto = typeof Ctor == 'function' && Ctor.prototype || objectProto$9;
  9336. return value === proto;
  9337. }
  9338. var _isPrototype = isPrototype;
  9339. /**
  9340. * Creates a unary function that invokes `func` with its argument transformed.
  9341. *
  9342. * @private
  9343. * @param {Function} func The function to wrap.
  9344. * @param {Function} transform The argument transform.
  9345. * @returns {Function} Returns the new function.
  9346. */
  9347. function overArg(func, transform) {
  9348. return function (arg) {
  9349. return func(transform(arg));
  9350. };
  9351. }
  9352. var _overArg = overArg;
  9353. /* Built-in method references for those with the same name as other `lodash` methods. */
  9354. var nativeKeys = _overArg(Object.keys, Object);
  9355. var _nativeKeys = nativeKeys;
  9356. /** Used for built-in method references. */
  9357. var objectProto$8 = Object.prototype;
  9358. /** Used to check objects for own properties. */
  9359. var hasOwnProperty$7 = objectProto$8.hasOwnProperty;
  9360. /**
  9361. * The base implementation of `_.keys` which doesn't treat sparse arrays as dense.
  9362. *
  9363. * @private
  9364. * @param {Object} object The object to query.
  9365. * @returns {Array} Returns the array of property names.
  9366. */
  9367. function baseKeys(object) {
  9368. if (!_isPrototype(object)) {
  9369. return _nativeKeys(object);
  9370. }
  9371. var result = [];
  9372. for (var key in Object(object)) {
  9373. if (hasOwnProperty$7.call(object, key) && key != 'constructor') {
  9374. result.push(key);
  9375. }
  9376. }
  9377. return result;
  9378. }
  9379. var _baseKeys = baseKeys;
  9380. /**
  9381. * Checks if `value` is the
  9382. * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
  9383. * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
  9384. *
  9385. * @static
  9386. * @memberOf _
  9387. * @since 0.1.0
  9388. * @category Lang
  9389. * @param {*} value The value to check.
  9390. * @returns {boolean} Returns `true` if `value` is an object, else `false`.
  9391. * @example
  9392. *
  9393. * _.isObject({});
  9394. * // => true
  9395. *
  9396. * _.isObject([1, 2, 3]);
  9397. * // => true
  9398. *
  9399. * _.isObject(_.noop);
  9400. * // => true
  9401. *
  9402. * _.isObject(null);
  9403. * // => false
  9404. */
  9405. function isObject(value) {
  9406. var type = typeof value;
  9407. return value != null && (type == 'object' || type == 'function');
  9408. }
  9409. var isObject_1 = isObject;
  9410. /** `Object#toString` result references. */
  9411. var asyncTag = '[object AsyncFunction]',
  9412. funcTag = '[object Function]',
  9413. genTag = '[object GeneratorFunction]',
  9414. proxyTag = '[object Proxy]';
  9415. /**
  9416. * Checks if `value` is classified as a `Function` object.
  9417. *
  9418. * @static
  9419. * @memberOf _
  9420. * @since 0.1.0
  9421. * @category Lang
  9422. * @param {*} value The value to check.
  9423. * @returns {boolean} Returns `true` if `value` is a function, else `false`.
  9424. * @example
  9425. *
  9426. * _.isFunction(_);
  9427. * // => true
  9428. *
  9429. * _.isFunction(/abc/);
  9430. * // => false
  9431. */
  9432. function isFunction(value) {
  9433. if (!isObject_1(value)) {
  9434. return false;
  9435. } // The use of `Object#toString` avoids issues with the `typeof` operator
  9436. // in Safari 9 which returns 'object' for typed arrays and other constructors.
  9437. var tag = _baseGetTag(value);
  9438. return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag;
  9439. }
  9440. var isFunction_1 = isFunction;
  9441. /**
  9442. * Checks if `value` is array-like. A value is considered array-like if it's
  9443. * not a function and has a `value.length` that's an integer greater than or
  9444. * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`.
  9445. *
  9446. * @static
  9447. * @memberOf _
  9448. * @since 4.0.0
  9449. * @category Lang
  9450. * @param {*} value The value to check.
  9451. * @returns {boolean} Returns `true` if `value` is array-like, else `false`.
  9452. * @example
  9453. *
  9454. * _.isArrayLike([1, 2, 3]);
  9455. * // => true
  9456. *
  9457. * _.isArrayLike(document.body.children);
  9458. * // => true
  9459. *
  9460. * _.isArrayLike('abc');
  9461. * // => true
  9462. *
  9463. * _.isArrayLike(_.noop);
  9464. * // => false
  9465. */
  9466. function isArrayLike(value) {
  9467. return value != null && isLength_1(value.length) && !isFunction_1(value);
  9468. }
  9469. var isArrayLike_1 = isArrayLike;
  9470. /**
  9471. * Creates an array of the own enumerable property names of `object`.
  9472. *
  9473. * **Note:** Non-object values are coerced to objects. See the
  9474. * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys)
  9475. * for more details.
  9476. *
  9477. * @static
  9478. * @since 0.1.0
  9479. * @memberOf _
  9480. * @category Object
  9481. * @param {Object} object The object to query.
  9482. * @returns {Array} Returns the array of property names.
  9483. * @example
  9484. *
  9485. * function Foo() {
  9486. * this.a = 1;
  9487. * this.b = 2;
  9488. * }
  9489. *
  9490. * Foo.prototype.c = 3;
  9491. *
  9492. * _.keys(new Foo);
  9493. * // => ['a', 'b'] (iteration order is not guaranteed)
  9494. *
  9495. * _.keys('hi');
  9496. * // => ['0', '1']
  9497. */
  9498. function keys(object) {
  9499. return isArrayLike_1(object) ? _arrayLikeKeys(object) : _baseKeys(object);
  9500. }
  9501. var keys_1 = keys;
  9502. /**
  9503. * The base implementation of `_.forOwn` without support for iteratee shorthands.
  9504. *
  9505. * @private
  9506. * @param {Object} object The object to iterate over.
  9507. * @param {Function} iteratee The function invoked per iteration.
  9508. * @returns {Object} Returns `object`.
  9509. */
  9510. function baseForOwn(object, iteratee) {
  9511. return object && _baseFor(object, iteratee, keys_1);
  9512. }
  9513. var _baseForOwn = baseForOwn;
  9514. /**
  9515. * Creates a `baseEach` or `baseEachRight` function.
  9516. *
  9517. * @private
  9518. * @param {Function} eachFunc The function to iterate over a collection.
  9519. * @param {boolean} [fromRight] Specify iterating from right to left.
  9520. * @returns {Function} Returns the new base function.
  9521. */
  9522. function createBaseEach(eachFunc, fromRight) {
  9523. return function (collection, iteratee) {
  9524. if (collection == null) {
  9525. return collection;
  9526. }
  9527. if (!isArrayLike_1(collection)) {
  9528. return eachFunc(collection, iteratee);
  9529. }
  9530. var length = collection.length,
  9531. index = fromRight ? length : -1,
  9532. iterable = Object(collection);
  9533. while (fromRight ? index-- : ++index < length) {
  9534. if (iteratee(iterable[index], index, iterable) === false) {
  9535. break;
  9536. }
  9537. }
  9538. return collection;
  9539. };
  9540. }
  9541. var _createBaseEach = createBaseEach;
  9542. /**
  9543. * The base implementation of `_.forEach` without support for iteratee shorthands.
  9544. *
  9545. * @private
  9546. * @param {Array|Object} collection The collection to iterate over.
  9547. * @param {Function} iteratee The function invoked per iteration.
  9548. * @returns {Array|Object} Returns `collection`.
  9549. */
  9550. var baseEach = _createBaseEach(_baseForOwn);
  9551. var _baseEach = baseEach;
  9552. /**
  9553. * Aggregates elements of `collection` on `accumulator` with keys transformed
  9554. * by `iteratee` and values set by `setter`.
  9555. *
  9556. * @private
  9557. * @param {Array|Object} collection The collection to iterate over.
  9558. * @param {Function} setter The function to set `accumulator` values.
  9559. * @param {Function} iteratee The iteratee to transform keys.
  9560. * @param {Object} accumulator The initial aggregated object.
  9561. * @returns {Function} Returns `accumulator`.
  9562. */
  9563. function baseAggregator(collection, setter, iteratee, accumulator) {
  9564. _baseEach(collection, function (value, key, collection) {
  9565. setter(accumulator, value, iteratee(value), collection);
  9566. });
  9567. return accumulator;
  9568. }
  9569. var _baseAggregator = baseAggregator;
  9570. /**
  9571. * Removes all key-value entries from the list cache.
  9572. *
  9573. * @private
  9574. * @name clear
  9575. * @memberOf ListCache
  9576. */
  9577. function listCacheClear() {
  9578. this.__data__ = [];
  9579. this.size = 0;
  9580. }
  9581. var _listCacheClear = listCacheClear;
  9582. /**
  9583. * Performs a
  9584. * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  9585. * comparison between two values to determine if they are equivalent.
  9586. *
  9587. * @static
  9588. * @memberOf _
  9589. * @since 4.0.0
  9590. * @category Lang
  9591. * @param {*} value The value to compare.
  9592. * @param {*} other The other value to compare.
  9593. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  9594. * @example
  9595. *
  9596. * var object = { 'a': 1 };
  9597. * var other = { 'a': 1 };
  9598. *
  9599. * _.eq(object, object);
  9600. * // => true
  9601. *
  9602. * _.eq(object, other);
  9603. * // => false
  9604. *
  9605. * _.eq('a', 'a');
  9606. * // => true
  9607. *
  9608. * _.eq('a', Object('a'));
  9609. * // => false
  9610. *
  9611. * _.eq(NaN, NaN);
  9612. * // => true
  9613. */
  9614. function eq(value, other) {
  9615. return value === other || value !== value && other !== other;
  9616. }
  9617. var eq_1 = eq;
  9618. /**
  9619. * Gets the index at which the `key` is found in `array` of key-value pairs.
  9620. *
  9621. * @private
  9622. * @param {Array} array The array to inspect.
  9623. * @param {*} key The key to search for.
  9624. * @returns {number} Returns the index of the matched value, else `-1`.
  9625. */
  9626. function assocIndexOf(array, key) {
  9627. var length = array.length;
  9628. while (length--) {
  9629. if (eq_1(array[length][0], key)) {
  9630. return length;
  9631. }
  9632. }
  9633. return -1;
  9634. }
  9635. var _assocIndexOf = assocIndexOf;
  9636. /** Used for built-in method references. */
  9637. var arrayProto = Array.prototype;
  9638. /** Built-in value references. */
  9639. var splice = arrayProto.splice;
  9640. /**
  9641. * Removes `key` and its value from the list cache.
  9642. *
  9643. * @private
  9644. * @name delete
  9645. * @memberOf ListCache
  9646. * @param {string} key The key of the value to remove.
  9647. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  9648. */
  9649. function listCacheDelete(key) {
  9650. var data = this.__data__,
  9651. index = _assocIndexOf(data, key);
  9652. if (index < 0) {
  9653. return false;
  9654. }
  9655. var lastIndex = data.length - 1;
  9656. if (index == lastIndex) {
  9657. data.pop();
  9658. } else {
  9659. splice.call(data, index, 1);
  9660. }
  9661. --this.size;
  9662. return true;
  9663. }
  9664. var _listCacheDelete = listCacheDelete;
  9665. /**
  9666. * Gets the list cache value for `key`.
  9667. *
  9668. * @private
  9669. * @name get
  9670. * @memberOf ListCache
  9671. * @param {string} key The key of the value to get.
  9672. * @returns {*} Returns the entry value.
  9673. */
  9674. function listCacheGet(key) {
  9675. var data = this.__data__,
  9676. index = _assocIndexOf(data, key);
  9677. return index < 0 ? undefined : data[index][1];
  9678. }
  9679. var _listCacheGet = listCacheGet;
  9680. /**
  9681. * Checks if a list cache value for `key` exists.
  9682. *
  9683. * @private
  9684. * @name has
  9685. * @memberOf ListCache
  9686. * @param {string} key The key of the entry to check.
  9687. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9688. */
  9689. function listCacheHas(key) {
  9690. return _assocIndexOf(this.__data__, key) > -1;
  9691. }
  9692. var _listCacheHas = listCacheHas;
  9693. /**
  9694. * Sets the list cache `key` to `value`.
  9695. *
  9696. * @private
  9697. * @name set
  9698. * @memberOf ListCache
  9699. * @param {string} key The key of the value to set.
  9700. * @param {*} value The value to set.
  9701. * @returns {Object} Returns the list cache instance.
  9702. */
  9703. function listCacheSet(key, value) {
  9704. var data = this.__data__,
  9705. index = _assocIndexOf(data, key);
  9706. if (index < 0) {
  9707. ++this.size;
  9708. data.push([key, value]);
  9709. } else {
  9710. data[index][1] = value;
  9711. }
  9712. return this;
  9713. }
  9714. var _listCacheSet = listCacheSet;
  9715. /**
  9716. * Creates an list cache object.
  9717. *
  9718. * @private
  9719. * @constructor
  9720. * @param {Array} [entries] The key-value pairs to cache.
  9721. */
  9722. function ListCache(entries) {
  9723. var index = -1,
  9724. length = entries == null ? 0 : entries.length;
  9725. this.clear();
  9726. while (++index < length) {
  9727. var entry = entries[index];
  9728. this.set(entry[0], entry[1]);
  9729. }
  9730. } // Add methods to `ListCache`.
  9731. ListCache.prototype.clear = _listCacheClear;
  9732. ListCache.prototype['delete'] = _listCacheDelete;
  9733. ListCache.prototype.get = _listCacheGet;
  9734. ListCache.prototype.has = _listCacheHas;
  9735. ListCache.prototype.set = _listCacheSet;
  9736. var _ListCache = ListCache;
  9737. /**
  9738. * Removes all key-value entries from the stack.
  9739. *
  9740. * @private
  9741. * @name clear
  9742. * @memberOf Stack
  9743. */
  9744. function stackClear() {
  9745. this.__data__ = new _ListCache();
  9746. this.size = 0;
  9747. }
  9748. var _stackClear = stackClear;
  9749. /**
  9750. * Removes `key` and its value from the stack.
  9751. *
  9752. * @private
  9753. * @name delete
  9754. * @memberOf Stack
  9755. * @param {string} key The key of the value to remove.
  9756. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  9757. */
  9758. function stackDelete(key) {
  9759. var data = this.__data__,
  9760. result = data['delete'](key);
  9761. this.size = data.size;
  9762. return result;
  9763. }
  9764. var _stackDelete = stackDelete;
  9765. /**
  9766. * Gets the stack value for `key`.
  9767. *
  9768. * @private
  9769. * @name get
  9770. * @memberOf Stack
  9771. * @param {string} key The key of the value to get.
  9772. * @returns {*} Returns the entry value.
  9773. */
  9774. function stackGet(key) {
  9775. return this.__data__.get(key);
  9776. }
  9777. var _stackGet = stackGet;
  9778. /**
  9779. * Checks if a stack value for `key` exists.
  9780. *
  9781. * @private
  9782. * @name has
  9783. * @memberOf Stack
  9784. * @param {string} key The key of the entry to check.
  9785. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9786. */
  9787. function stackHas(key) {
  9788. return this.__data__.has(key);
  9789. }
  9790. var _stackHas = stackHas;
  9791. /** Used to detect overreaching core-js shims. */
  9792. var coreJsData = _root['__core-js_shared__'];
  9793. var _coreJsData = coreJsData;
  9794. /** Used to detect methods masquerading as native. */
  9795. var maskSrcKey = function () {
  9796. var uid = /[^.]+$/.exec(_coreJsData && _coreJsData.keys && _coreJsData.keys.IE_PROTO || '');
  9797. return uid ? 'Symbol(src)_1.' + uid : '';
  9798. }();
  9799. /**
  9800. * Checks if `func` has its source masked.
  9801. *
  9802. * @private
  9803. * @param {Function} func The function to check.
  9804. * @returns {boolean} Returns `true` if `func` is masked, else `false`.
  9805. */
  9806. function isMasked(func) {
  9807. return !!maskSrcKey && maskSrcKey in func;
  9808. }
  9809. var _isMasked = isMasked;
  9810. /** Used for built-in method references. */
  9811. var funcProto$1 = Function.prototype;
  9812. /** Used to resolve the decompiled source of functions. */
  9813. var funcToString$1 = funcProto$1.toString;
  9814. /**
  9815. * Converts `func` to its source code.
  9816. *
  9817. * @private
  9818. * @param {Function} func The function to convert.
  9819. * @returns {string} Returns the source code.
  9820. */
  9821. function toSource(func) {
  9822. if (func != null) {
  9823. try {
  9824. return funcToString$1.call(func);
  9825. } catch (e) {}
  9826. try {
  9827. return func + '';
  9828. } catch (e) {}
  9829. }
  9830. return '';
  9831. }
  9832. var _toSource = toSource;
  9833. /**
  9834. * Used to match `RegExp`
  9835. * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns).
  9836. */
  9837. var reRegExpChar = /[\\^$.*+?()[\]{}|]/g;
  9838. /** Used to detect host constructors (Safari). */
  9839. var reIsHostCtor = /^\[object .+?Constructor\]$/;
  9840. /** Used for built-in method references. */
  9841. var funcProto = Function.prototype,
  9842. objectProto$7 = Object.prototype;
  9843. /** Used to resolve the decompiled source of functions. */
  9844. var funcToString = funcProto.toString;
  9845. /** Used to check objects for own properties. */
  9846. var hasOwnProperty$6 = objectProto$7.hasOwnProperty;
  9847. /** Used to detect if a method is native. */
  9848. var reIsNative = RegExp('^' + funcToString.call(hasOwnProperty$6).replace(reRegExpChar, '\\$&').replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$');
  9849. /**
  9850. * The base implementation of `_.isNative` without bad shim checks.
  9851. *
  9852. * @private
  9853. * @param {*} value The value to check.
  9854. * @returns {boolean} Returns `true` if `value` is a native function,
  9855. * else `false`.
  9856. */
  9857. function baseIsNative(value) {
  9858. if (!isObject_1(value) || _isMasked(value)) {
  9859. return false;
  9860. }
  9861. var pattern = isFunction_1(value) ? reIsNative : reIsHostCtor;
  9862. return pattern.test(_toSource(value));
  9863. }
  9864. var _baseIsNative = baseIsNative;
  9865. /**
  9866. * Gets the value at `key` of `object`.
  9867. *
  9868. * @private
  9869. * @param {Object} [object] The object to query.
  9870. * @param {string} key The key of the property to get.
  9871. * @returns {*} Returns the property value.
  9872. */
  9873. function getValue(object, key) {
  9874. return object == null ? undefined : object[key];
  9875. }
  9876. var _getValue = getValue;
  9877. /**
  9878. * Gets the native function at `key` of `object`.
  9879. *
  9880. * @private
  9881. * @param {Object} object The object to query.
  9882. * @param {string} key The key of the method to get.
  9883. * @returns {*} Returns the function if it's native, else `undefined`.
  9884. */
  9885. function getNative(object, key) {
  9886. var value = _getValue(object, key);
  9887. return _baseIsNative(value) ? value : undefined;
  9888. }
  9889. var _getNative = getNative;
  9890. /* Built-in method references that are verified to be native. */
  9891. var Map$1 = _getNative(_root, 'Map');
  9892. var _Map = Map$1;
  9893. /* Built-in method references that are verified to be native. */
  9894. var nativeCreate = _getNative(Object, 'create');
  9895. var _nativeCreate = nativeCreate;
  9896. /**
  9897. * Removes all key-value entries from the hash.
  9898. *
  9899. * @private
  9900. * @name clear
  9901. * @memberOf Hash
  9902. */
  9903. function hashClear() {
  9904. this.__data__ = _nativeCreate ? _nativeCreate(null) : {};
  9905. this.size = 0;
  9906. }
  9907. var _hashClear = hashClear;
  9908. /**
  9909. * Removes `key` and its value from the hash.
  9910. *
  9911. * @private
  9912. * @name delete
  9913. * @memberOf Hash
  9914. * @param {Object} hash The hash to modify.
  9915. * @param {string} key The key of the value to remove.
  9916. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  9917. */
  9918. function hashDelete(key) {
  9919. var result = this.has(key) && delete this.__data__[key];
  9920. this.size -= result ? 1 : 0;
  9921. return result;
  9922. }
  9923. var _hashDelete = hashDelete;
  9924. /** Used to stand-in for `undefined` hash values. */
  9925. var HASH_UNDEFINED$2 = '__lodash_hash_undefined__';
  9926. /** Used for built-in method references. */
  9927. var objectProto$6 = Object.prototype;
  9928. /** Used to check objects for own properties. */
  9929. var hasOwnProperty$5 = objectProto$6.hasOwnProperty;
  9930. /**
  9931. * Gets the hash value for `key`.
  9932. *
  9933. * @private
  9934. * @name get
  9935. * @memberOf Hash
  9936. * @param {string} key The key of the value to get.
  9937. * @returns {*} Returns the entry value.
  9938. */
  9939. function hashGet(key) {
  9940. var data = this.__data__;
  9941. if (_nativeCreate) {
  9942. var result = data[key];
  9943. return result === HASH_UNDEFINED$2 ? undefined : result;
  9944. }
  9945. return hasOwnProperty$5.call(data, key) ? data[key] : undefined;
  9946. }
  9947. var _hashGet = hashGet;
  9948. /** Used for built-in method references. */
  9949. var objectProto$5 = Object.prototype;
  9950. /** Used to check objects for own properties. */
  9951. var hasOwnProperty$4 = objectProto$5.hasOwnProperty;
  9952. /**
  9953. * Checks if a hash value for `key` exists.
  9954. *
  9955. * @private
  9956. * @name has
  9957. * @memberOf Hash
  9958. * @param {string} key The key of the entry to check.
  9959. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  9960. */
  9961. function hashHas(key) {
  9962. var data = this.__data__;
  9963. return _nativeCreate ? data[key] !== undefined : hasOwnProperty$4.call(data, key);
  9964. }
  9965. var _hashHas = hashHas;
  9966. /** Used to stand-in for `undefined` hash values. */
  9967. var HASH_UNDEFINED$1 = '__lodash_hash_undefined__';
  9968. /**
  9969. * Sets the hash `key` to `value`.
  9970. *
  9971. * @private
  9972. * @name set
  9973. * @memberOf Hash
  9974. * @param {string} key The key of the value to set.
  9975. * @param {*} value The value to set.
  9976. * @returns {Object} Returns the hash instance.
  9977. */
  9978. function hashSet(key, value) {
  9979. var data = this.__data__;
  9980. this.size += this.has(key) ? 0 : 1;
  9981. data[key] = _nativeCreate && value === undefined ? HASH_UNDEFINED$1 : value;
  9982. return this;
  9983. }
  9984. var _hashSet = hashSet;
  9985. /**
  9986. * Creates a hash object.
  9987. *
  9988. * @private
  9989. * @constructor
  9990. * @param {Array} [entries] The key-value pairs to cache.
  9991. */
  9992. function Hash(entries) {
  9993. var index = -1,
  9994. length = entries == null ? 0 : entries.length;
  9995. this.clear();
  9996. while (++index < length) {
  9997. var entry = entries[index];
  9998. this.set(entry[0], entry[1]);
  9999. }
  10000. } // Add methods to `Hash`.
  10001. Hash.prototype.clear = _hashClear;
  10002. Hash.prototype['delete'] = _hashDelete;
  10003. Hash.prototype.get = _hashGet;
  10004. Hash.prototype.has = _hashHas;
  10005. Hash.prototype.set = _hashSet;
  10006. var _Hash = Hash;
  10007. /**
  10008. * Removes all key-value entries from the map.
  10009. *
  10010. * @private
  10011. * @name clear
  10012. * @memberOf MapCache
  10013. */
  10014. function mapCacheClear() {
  10015. this.size = 0;
  10016. this.__data__ = {
  10017. 'hash': new _Hash(),
  10018. 'map': new (_Map || _ListCache)(),
  10019. 'string': new _Hash()
  10020. };
  10021. }
  10022. var _mapCacheClear = mapCacheClear;
  10023. /**
  10024. * Checks if `value` is suitable for use as unique object key.
  10025. *
  10026. * @private
  10027. * @param {*} value The value to check.
  10028. * @returns {boolean} Returns `true` if `value` is suitable, else `false`.
  10029. */
  10030. function isKeyable(value) {
  10031. var type = typeof value;
  10032. return type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean' ? value !== '__proto__' : value === null;
  10033. }
  10034. var _isKeyable = isKeyable;
  10035. /**
  10036. * Gets the data for `map`.
  10037. *
  10038. * @private
  10039. * @param {Object} map The map to query.
  10040. * @param {string} key The reference key.
  10041. * @returns {*} Returns the map data.
  10042. */
  10043. function getMapData(map, key) {
  10044. var data = map.__data__;
  10045. return _isKeyable(key) ? data[typeof key == 'string' ? 'string' : 'hash'] : data.map;
  10046. }
  10047. var _getMapData = getMapData;
  10048. /**
  10049. * Removes `key` and its value from the map.
  10050. *
  10051. * @private
  10052. * @name delete
  10053. * @memberOf MapCache
  10054. * @param {string} key The key of the value to remove.
  10055. * @returns {boolean} Returns `true` if the entry was removed, else `false`.
  10056. */
  10057. function mapCacheDelete(key) {
  10058. var result = _getMapData(this, key)['delete'](key);
  10059. this.size -= result ? 1 : 0;
  10060. return result;
  10061. }
  10062. var _mapCacheDelete = mapCacheDelete;
  10063. /**
  10064. * Gets the map value for `key`.
  10065. *
  10066. * @private
  10067. * @name get
  10068. * @memberOf MapCache
  10069. * @param {string} key The key of the value to get.
  10070. * @returns {*} Returns the entry value.
  10071. */
  10072. function mapCacheGet(key) {
  10073. return _getMapData(this, key).get(key);
  10074. }
  10075. var _mapCacheGet = mapCacheGet;
  10076. /**
  10077. * Checks if a map value for `key` exists.
  10078. *
  10079. * @private
  10080. * @name has
  10081. * @memberOf MapCache
  10082. * @param {string} key The key of the entry to check.
  10083. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  10084. */
  10085. function mapCacheHas(key) {
  10086. return _getMapData(this, key).has(key);
  10087. }
  10088. var _mapCacheHas = mapCacheHas;
  10089. /**
  10090. * Sets the map `key` to `value`.
  10091. *
  10092. * @private
  10093. * @name set
  10094. * @memberOf MapCache
  10095. * @param {string} key The key of the value to set.
  10096. * @param {*} value The value to set.
  10097. * @returns {Object} Returns the map cache instance.
  10098. */
  10099. function mapCacheSet(key, value) {
  10100. var data = _getMapData(this, key),
  10101. size = data.size;
  10102. data.set(key, value);
  10103. this.size += data.size == size ? 0 : 1;
  10104. return this;
  10105. }
  10106. var _mapCacheSet = mapCacheSet;
  10107. /**
  10108. * Creates a map cache object to store key-value pairs.
  10109. *
  10110. * @private
  10111. * @constructor
  10112. * @param {Array} [entries] The key-value pairs to cache.
  10113. */
  10114. function MapCache(entries) {
  10115. var index = -1,
  10116. length = entries == null ? 0 : entries.length;
  10117. this.clear();
  10118. while (++index < length) {
  10119. var entry = entries[index];
  10120. this.set(entry[0], entry[1]);
  10121. }
  10122. } // Add methods to `MapCache`.
  10123. MapCache.prototype.clear = _mapCacheClear;
  10124. MapCache.prototype['delete'] = _mapCacheDelete;
  10125. MapCache.prototype.get = _mapCacheGet;
  10126. MapCache.prototype.has = _mapCacheHas;
  10127. MapCache.prototype.set = _mapCacheSet;
  10128. var _MapCache = MapCache;
  10129. /** Used as the size to enable large array optimizations. */
  10130. var LARGE_ARRAY_SIZE = 200;
  10131. /**
  10132. * Sets the stack `key` to `value`.
  10133. *
  10134. * @private
  10135. * @name set
  10136. * @memberOf Stack
  10137. * @param {string} key The key of the value to set.
  10138. * @param {*} value The value to set.
  10139. * @returns {Object} Returns the stack cache instance.
  10140. */
  10141. function stackSet(key, value) {
  10142. var data = this.__data__;
  10143. if (data instanceof _ListCache) {
  10144. var pairs = data.__data__;
  10145. if (!_Map || pairs.length < LARGE_ARRAY_SIZE - 1) {
  10146. pairs.push([key, value]);
  10147. this.size = ++data.size;
  10148. return this;
  10149. }
  10150. data = this.__data__ = new _MapCache(pairs);
  10151. }
  10152. data.set(key, value);
  10153. this.size = data.size;
  10154. return this;
  10155. }
  10156. var _stackSet = stackSet;
  10157. /**
  10158. * Creates a stack cache object to store key-value pairs.
  10159. *
  10160. * @private
  10161. * @constructor
  10162. * @param {Array} [entries] The key-value pairs to cache.
  10163. */
  10164. function Stack(entries) {
  10165. var data = this.__data__ = new _ListCache(entries);
  10166. this.size = data.size;
  10167. } // Add methods to `Stack`.
  10168. Stack.prototype.clear = _stackClear;
  10169. Stack.prototype['delete'] = _stackDelete;
  10170. Stack.prototype.get = _stackGet;
  10171. Stack.prototype.has = _stackHas;
  10172. Stack.prototype.set = _stackSet;
  10173. var _Stack = Stack;
  10174. /** Used to stand-in for `undefined` hash values. */
  10175. var HASH_UNDEFINED = '__lodash_hash_undefined__';
  10176. /**
  10177. * Adds `value` to the array cache.
  10178. *
  10179. * @private
  10180. * @name add
  10181. * @memberOf SetCache
  10182. * @alias push
  10183. * @param {*} value The value to cache.
  10184. * @returns {Object} Returns the cache instance.
  10185. */
  10186. function setCacheAdd(value) {
  10187. this.__data__.set(value, HASH_UNDEFINED);
  10188. return this;
  10189. }
  10190. var _setCacheAdd = setCacheAdd;
  10191. /**
  10192. * Checks if `value` is in the array cache.
  10193. *
  10194. * @private
  10195. * @name has
  10196. * @memberOf SetCache
  10197. * @param {*} value The value to search for.
  10198. * @returns {number} Returns `true` if `value` is found, else `false`.
  10199. */
  10200. function setCacheHas(value) {
  10201. return this.__data__.has(value);
  10202. }
  10203. var _setCacheHas = setCacheHas;
  10204. /**
  10205. *
  10206. * Creates an array cache object to store unique values.
  10207. *
  10208. * @private
  10209. * @constructor
  10210. * @param {Array} [values] The values to cache.
  10211. */
  10212. function SetCache(values) {
  10213. var index = -1,
  10214. length = values == null ? 0 : values.length;
  10215. this.__data__ = new _MapCache();
  10216. while (++index < length) {
  10217. this.add(values[index]);
  10218. }
  10219. } // Add methods to `SetCache`.
  10220. SetCache.prototype.add = SetCache.prototype.push = _setCacheAdd;
  10221. SetCache.prototype.has = _setCacheHas;
  10222. var _SetCache = SetCache;
  10223. /**
  10224. * A specialized version of `_.some` for arrays without support for iteratee
  10225. * shorthands.
  10226. *
  10227. * @private
  10228. * @param {Array} [array] The array to iterate over.
  10229. * @param {Function} predicate The function invoked per iteration.
  10230. * @returns {boolean} Returns `true` if any element passes the predicate check,
  10231. * else `false`.
  10232. */
  10233. function arraySome(array, predicate) {
  10234. var index = -1,
  10235. length = array == null ? 0 : array.length;
  10236. while (++index < length) {
  10237. if (predicate(array[index], index, array)) {
  10238. return true;
  10239. }
  10240. }
  10241. return false;
  10242. }
  10243. var _arraySome = arraySome;
  10244. /**
  10245. * Checks if a `cache` value for `key` exists.
  10246. *
  10247. * @private
  10248. * @param {Object} cache The cache to query.
  10249. * @param {string} key The key of the entry to check.
  10250. * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`.
  10251. */
  10252. function cacheHas(cache, key) {
  10253. return cache.has(key);
  10254. }
  10255. var _cacheHas = cacheHas;
  10256. /** Used to compose bitmasks for value comparisons. */
  10257. var COMPARE_PARTIAL_FLAG$5 = 1,
  10258. COMPARE_UNORDERED_FLAG$3 = 2;
  10259. /**
  10260. * A specialized version of `baseIsEqualDeep` for arrays with support for
  10261. * partial deep comparisons.
  10262. *
  10263. * @private
  10264. * @param {Array} array The array to compare.
  10265. * @param {Array} other The other array to compare.
  10266. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  10267. * @param {Function} customizer The function to customize comparisons.
  10268. * @param {Function} equalFunc The function to determine equivalents of values.
  10269. * @param {Object} stack Tracks traversed `array` and `other` objects.
  10270. * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`.
  10271. */
  10272. function equalArrays(array, other, bitmask, customizer, equalFunc, stack) {
  10273. var isPartial = bitmask & COMPARE_PARTIAL_FLAG$5,
  10274. arrLength = array.length,
  10275. othLength = other.length;
  10276. if (arrLength != othLength && !(isPartial && othLength > arrLength)) {
  10277. return false;
  10278. } // Check that cyclic values are equal.
  10279. var arrStacked = stack.get(array);
  10280. var othStacked = stack.get(other);
  10281. if (arrStacked && othStacked) {
  10282. return arrStacked == other && othStacked == array;
  10283. }
  10284. var index = -1,
  10285. result = true,
  10286. seen = bitmask & COMPARE_UNORDERED_FLAG$3 ? new _SetCache() : undefined;
  10287. stack.set(array, other);
  10288. stack.set(other, array); // Ignore non-index properties.
  10289. while (++index < arrLength) {
  10290. var arrValue = array[index],
  10291. othValue = other[index];
  10292. if (customizer) {
  10293. var compared = isPartial ? customizer(othValue, arrValue, index, other, array, stack) : customizer(arrValue, othValue, index, array, other, stack);
  10294. }
  10295. if (compared !== undefined) {
  10296. if (compared) {
  10297. continue;
  10298. }
  10299. result = false;
  10300. break;
  10301. } // Recursively compare arrays (susceptible to call stack limits).
  10302. if (seen) {
  10303. if (!_arraySome(other, function (othValue, othIndex) {
  10304. if (!_cacheHas(seen, othIndex) && (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  10305. return seen.push(othIndex);
  10306. }
  10307. })) {
  10308. result = false;
  10309. break;
  10310. }
  10311. } else if (!(arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) {
  10312. result = false;
  10313. break;
  10314. }
  10315. }
  10316. stack['delete'](array);
  10317. stack['delete'](other);
  10318. return result;
  10319. }
  10320. var _equalArrays = equalArrays;
  10321. /** Built-in value references. */
  10322. var Uint8Array = _root.Uint8Array;
  10323. var _Uint8Array = Uint8Array;
  10324. /**
  10325. * Converts `map` to its key-value pairs.
  10326. *
  10327. * @private
  10328. * @param {Object} map The map to convert.
  10329. * @returns {Array} Returns the key-value pairs.
  10330. */
  10331. function mapToArray(map) {
  10332. var index = -1,
  10333. result = Array(map.size);
  10334. map.forEach(function (value, key) {
  10335. result[++index] = [key, value];
  10336. });
  10337. return result;
  10338. }
  10339. var _mapToArray = mapToArray;
  10340. /**
  10341. * Converts `set` to an array of its values.
  10342. *
  10343. * @private
  10344. * @param {Object} set The set to convert.
  10345. * @returns {Array} Returns the values.
  10346. */
  10347. function setToArray(set) {
  10348. var index = -1,
  10349. result = Array(set.size);
  10350. set.forEach(function (value) {
  10351. result[++index] = value;
  10352. });
  10353. return result;
  10354. }
  10355. var _setToArray = setToArray;
  10356. /** Used to compose bitmasks for value comparisons. */
  10357. var COMPARE_PARTIAL_FLAG$4 = 1,
  10358. COMPARE_UNORDERED_FLAG$2 = 2;
  10359. /** `Object#toString` result references. */
  10360. var boolTag = '[object Boolean]',
  10361. dateTag = '[object Date]',
  10362. errorTag = '[object Error]',
  10363. mapTag$1 = '[object Map]',
  10364. numberTag = '[object Number]',
  10365. regexpTag = '[object RegExp]',
  10366. setTag$1 = '[object Set]',
  10367. stringTag = '[object String]',
  10368. symbolTag$1 = '[object Symbol]';
  10369. var arrayBufferTag = '[object ArrayBuffer]',
  10370. dataViewTag$1 = '[object DataView]';
  10371. /** Used to convert symbols to primitives and strings. */
  10372. var symbolProto$1 = _Symbol ? _Symbol.prototype : undefined,
  10373. symbolValueOf = symbolProto$1 ? symbolProto$1.valueOf : undefined;
  10374. /**
  10375. * A specialized version of `baseIsEqualDeep` for comparing objects of
  10376. * the same `toStringTag`.
  10377. *
  10378. * **Note:** This function only supports comparing values with tags of
  10379. * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`.
  10380. *
  10381. * @private
  10382. * @param {Object} object The object to compare.
  10383. * @param {Object} other The other object to compare.
  10384. * @param {string} tag The `toStringTag` of the objects to compare.
  10385. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  10386. * @param {Function} customizer The function to customize comparisons.
  10387. * @param {Function} equalFunc The function to determine equivalents of values.
  10388. * @param {Object} stack Tracks traversed `object` and `other` objects.
  10389. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  10390. */
  10391. function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) {
  10392. switch (tag) {
  10393. case dataViewTag$1:
  10394. if (object.byteLength != other.byteLength || object.byteOffset != other.byteOffset) {
  10395. return false;
  10396. }
  10397. object = object.buffer;
  10398. other = other.buffer;
  10399. case arrayBufferTag:
  10400. if (object.byteLength != other.byteLength || !equalFunc(new _Uint8Array(object), new _Uint8Array(other))) {
  10401. return false;
  10402. }
  10403. return true;
  10404. case boolTag:
  10405. case dateTag:
  10406. case numberTag:
  10407. // Coerce booleans to `1` or `0` and dates to milliseconds.
  10408. // Invalid dates are coerced to `NaN`.
  10409. return eq_1(+object, +other);
  10410. case errorTag:
  10411. return object.name == other.name && object.message == other.message;
  10412. case regexpTag:
  10413. case stringTag:
  10414. // Coerce regexes to strings and treat strings, primitives and objects,
  10415. // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring
  10416. // for more details.
  10417. return object == other + '';
  10418. case mapTag$1:
  10419. var convert = _mapToArray;
  10420. case setTag$1:
  10421. var isPartial = bitmask & COMPARE_PARTIAL_FLAG$4;
  10422. convert || (convert = _setToArray);
  10423. if (object.size != other.size && !isPartial) {
  10424. return false;
  10425. } // Assume cyclic values are equal.
  10426. var stacked = stack.get(object);
  10427. if (stacked) {
  10428. return stacked == other;
  10429. }
  10430. bitmask |= COMPARE_UNORDERED_FLAG$2; // Recursively compare objects (susceptible to call stack limits).
  10431. stack.set(object, other);
  10432. var result = _equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack);
  10433. stack['delete'](object);
  10434. return result;
  10435. case symbolTag$1:
  10436. if (symbolValueOf) {
  10437. return symbolValueOf.call(object) == symbolValueOf.call(other);
  10438. }
  10439. }
  10440. return false;
  10441. }
  10442. var _equalByTag = equalByTag;
  10443. /**
  10444. * Appends the elements of `values` to `array`.
  10445. *
  10446. * @private
  10447. * @param {Array} array The array to modify.
  10448. * @param {Array} values The values to append.
  10449. * @returns {Array} Returns `array`.
  10450. */
  10451. function arrayPush(array, values) {
  10452. var index = -1,
  10453. length = values.length,
  10454. offset = array.length;
  10455. while (++index < length) {
  10456. array[offset + index] = values[index];
  10457. }
  10458. return array;
  10459. }
  10460. var _arrayPush = arrayPush;
  10461. /**
  10462. * The base implementation of `getAllKeys` and `getAllKeysIn` which uses
  10463. * `keysFunc` and `symbolsFunc` to get the enumerable property names and
  10464. * symbols of `object`.
  10465. *
  10466. * @private
  10467. * @param {Object} object The object to query.
  10468. * @param {Function} keysFunc The function to get the keys of `object`.
  10469. * @param {Function} symbolsFunc The function to get the symbols of `object`.
  10470. * @returns {Array} Returns the array of property names and symbols.
  10471. */
  10472. function baseGetAllKeys(object, keysFunc, symbolsFunc) {
  10473. var result = keysFunc(object);
  10474. return isArray_1(object) ? result : _arrayPush(result, symbolsFunc(object));
  10475. }
  10476. var _baseGetAllKeys = baseGetAllKeys;
  10477. /**
  10478. * A specialized version of `_.filter` for arrays without support for
  10479. * iteratee shorthands.
  10480. *
  10481. * @private
  10482. * @param {Array} [array] The array to iterate over.
  10483. * @param {Function} predicate The function invoked per iteration.
  10484. * @returns {Array} Returns the new filtered array.
  10485. */
  10486. function arrayFilter(array, predicate) {
  10487. var index = -1,
  10488. length = array == null ? 0 : array.length,
  10489. resIndex = 0,
  10490. result = [];
  10491. while (++index < length) {
  10492. var value = array[index];
  10493. if (predicate(value, index, array)) {
  10494. result[resIndex++] = value;
  10495. }
  10496. }
  10497. return result;
  10498. }
  10499. var _arrayFilter = arrayFilter;
  10500. /**
  10501. * This method returns a new empty array.
  10502. *
  10503. * @static
  10504. * @memberOf _
  10505. * @since 4.13.0
  10506. * @category Util
  10507. * @returns {Array} Returns the new empty array.
  10508. * @example
  10509. *
  10510. * var arrays = _.times(2, _.stubArray);
  10511. *
  10512. * console.log(arrays);
  10513. * // => [[], []]
  10514. *
  10515. * console.log(arrays[0] === arrays[1]);
  10516. * // => false
  10517. */
  10518. function stubArray() {
  10519. return [];
  10520. }
  10521. var stubArray_1 = stubArray;
  10522. /** Used for built-in method references. */
  10523. var objectProto$4 = Object.prototype;
  10524. /** Built-in value references. */
  10525. var propertyIsEnumerable = objectProto$4.propertyIsEnumerable;
  10526. /* Built-in method references for those with the same name as other `lodash` methods. */
  10527. var nativeGetSymbols = Object.getOwnPropertySymbols;
  10528. /**
  10529. * Creates an array of the own enumerable symbols of `object`.
  10530. *
  10531. * @private
  10532. * @param {Object} object The object to query.
  10533. * @returns {Array} Returns the array of symbols.
  10534. */
  10535. var getSymbols = !nativeGetSymbols ? stubArray_1 : function (object) {
  10536. if (object == null) {
  10537. return [];
  10538. }
  10539. object = Object(object);
  10540. return _arrayFilter(nativeGetSymbols(object), function (symbol) {
  10541. return propertyIsEnumerable.call(object, symbol);
  10542. });
  10543. };
  10544. var _getSymbols = getSymbols;
  10545. /**
  10546. * Creates an array of own enumerable property names and symbols of `object`.
  10547. *
  10548. * @private
  10549. * @param {Object} object The object to query.
  10550. * @returns {Array} Returns the array of property names and symbols.
  10551. */
  10552. function getAllKeys(object) {
  10553. return _baseGetAllKeys(object, keys_1, _getSymbols);
  10554. }
  10555. var _getAllKeys = getAllKeys;
  10556. /** Used to compose bitmasks for value comparisons. */
  10557. var COMPARE_PARTIAL_FLAG$3 = 1;
  10558. /** Used for built-in method references. */
  10559. var objectProto$3 = Object.prototype;
  10560. /** Used to check objects for own properties. */
  10561. var hasOwnProperty$3 = objectProto$3.hasOwnProperty;
  10562. /**
  10563. * A specialized version of `baseIsEqualDeep` for objects with support for
  10564. * partial deep comparisons.
  10565. *
  10566. * @private
  10567. * @param {Object} object The object to compare.
  10568. * @param {Object} other The other object to compare.
  10569. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  10570. * @param {Function} customizer The function to customize comparisons.
  10571. * @param {Function} equalFunc The function to determine equivalents of values.
  10572. * @param {Object} stack Tracks traversed `object` and `other` objects.
  10573. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  10574. */
  10575. function equalObjects(object, other, bitmask, customizer, equalFunc, stack) {
  10576. var isPartial = bitmask & COMPARE_PARTIAL_FLAG$3,
  10577. objProps = _getAllKeys(object),
  10578. objLength = objProps.length,
  10579. othProps = _getAllKeys(other),
  10580. othLength = othProps.length;
  10581. if (objLength != othLength && !isPartial) {
  10582. return false;
  10583. }
  10584. var index = objLength;
  10585. while (index--) {
  10586. var key = objProps[index];
  10587. if (!(isPartial ? key in other : hasOwnProperty$3.call(other, key))) {
  10588. return false;
  10589. }
  10590. } // Check that cyclic values are equal.
  10591. var objStacked = stack.get(object);
  10592. var othStacked = stack.get(other);
  10593. if (objStacked && othStacked) {
  10594. return objStacked == other && othStacked == object;
  10595. }
  10596. var result = true;
  10597. stack.set(object, other);
  10598. stack.set(other, object);
  10599. var skipCtor = isPartial;
  10600. while (++index < objLength) {
  10601. key = objProps[index];
  10602. var objValue = object[key],
  10603. othValue = other[key];
  10604. if (customizer) {
  10605. var compared = isPartial ? customizer(othValue, objValue, key, other, object, stack) : customizer(objValue, othValue, key, object, other, stack);
  10606. } // Recursively compare objects (susceptible to call stack limits).
  10607. if (!(compared === undefined ? objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack) : compared)) {
  10608. result = false;
  10609. break;
  10610. }
  10611. skipCtor || (skipCtor = key == 'constructor');
  10612. }
  10613. if (result && !skipCtor) {
  10614. var objCtor = object.constructor,
  10615. othCtor = other.constructor; // Non `Object` object instances with different constructors are not equal.
  10616. if (objCtor != othCtor && 'constructor' in object && 'constructor' in other && !(typeof objCtor == 'function' && objCtor instanceof objCtor && typeof othCtor == 'function' && othCtor instanceof othCtor)) {
  10617. result = false;
  10618. }
  10619. }
  10620. stack['delete'](object);
  10621. stack['delete'](other);
  10622. return result;
  10623. }
  10624. var _equalObjects = equalObjects;
  10625. /* Built-in method references that are verified to be native. */
  10626. var DataView = _getNative(_root, 'DataView');
  10627. var _DataView = DataView;
  10628. /* Built-in method references that are verified to be native. */
  10629. var Promise$1 = _getNative(_root, 'Promise');
  10630. var _Promise = Promise$1;
  10631. /* Built-in method references that are verified to be native. */
  10632. var Set$1 = _getNative(_root, 'Set');
  10633. var _Set = Set$1;
  10634. /* Built-in method references that are verified to be native. */
  10635. var WeakMap$1 = _getNative(_root, 'WeakMap');
  10636. var _WeakMap = WeakMap$1;
  10637. /** `Object#toString` result references. */
  10638. var mapTag = '[object Map]',
  10639. objectTag$1 = '[object Object]',
  10640. promiseTag = '[object Promise]',
  10641. setTag = '[object Set]',
  10642. weakMapTag = '[object WeakMap]';
  10643. var dataViewTag = '[object DataView]';
  10644. /** Used to detect maps, sets, and weakmaps. */
  10645. var dataViewCtorString = _toSource(_DataView),
  10646. mapCtorString = _toSource(_Map),
  10647. promiseCtorString = _toSource(_Promise),
  10648. setCtorString = _toSource(_Set),
  10649. weakMapCtorString = _toSource(_WeakMap);
  10650. /**
  10651. * Gets the `toStringTag` of `value`.
  10652. *
  10653. * @private
  10654. * @param {*} value The value to query.
  10655. * @returns {string} Returns the `toStringTag`.
  10656. */
  10657. var getTag = _baseGetTag; // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6.
  10658. if (_DataView && getTag(new _DataView(new ArrayBuffer(1))) != dataViewTag || _Map && getTag(new _Map()) != mapTag || _Promise && getTag(_Promise.resolve()) != promiseTag || _Set && getTag(new _Set()) != setTag || _WeakMap && getTag(new _WeakMap()) != weakMapTag) {
  10659. getTag = function (value) {
  10660. var result = _baseGetTag(value),
  10661. Ctor = result == objectTag$1 ? value.constructor : undefined,
  10662. ctorString = Ctor ? _toSource(Ctor) : '';
  10663. if (ctorString) {
  10664. switch (ctorString) {
  10665. case dataViewCtorString:
  10666. return dataViewTag;
  10667. case mapCtorString:
  10668. return mapTag;
  10669. case promiseCtorString:
  10670. return promiseTag;
  10671. case setCtorString:
  10672. return setTag;
  10673. case weakMapCtorString:
  10674. return weakMapTag;
  10675. }
  10676. }
  10677. return result;
  10678. };
  10679. }
  10680. var _getTag = getTag;
  10681. /** Used to compose bitmasks for value comparisons. */
  10682. var COMPARE_PARTIAL_FLAG$2 = 1;
  10683. /** `Object#toString` result references. */
  10684. var argsTag = '[object Arguments]',
  10685. arrayTag = '[object Array]',
  10686. objectTag = '[object Object]';
  10687. /** Used for built-in method references. */
  10688. var objectProto$2 = Object.prototype;
  10689. /** Used to check objects for own properties. */
  10690. var hasOwnProperty$2 = objectProto$2.hasOwnProperty;
  10691. /**
  10692. * A specialized version of `baseIsEqual` for arrays and objects which performs
  10693. * deep comparisons and tracks traversed objects enabling objects with circular
  10694. * references to be compared.
  10695. *
  10696. * @private
  10697. * @param {Object} object The object to compare.
  10698. * @param {Object} other The other object to compare.
  10699. * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details.
  10700. * @param {Function} customizer The function to customize comparisons.
  10701. * @param {Function} equalFunc The function to determine equivalents of values.
  10702. * @param {Object} [stack] Tracks traversed `object` and `other` objects.
  10703. * @returns {boolean} Returns `true` if the objects are equivalent, else `false`.
  10704. */
  10705. function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) {
  10706. var objIsArr = isArray_1(object),
  10707. othIsArr = isArray_1(other),
  10708. objTag = objIsArr ? arrayTag : _getTag(object),
  10709. othTag = othIsArr ? arrayTag : _getTag(other);
  10710. objTag = objTag == argsTag ? objectTag : objTag;
  10711. othTag = othTag == argsTag ? objectTag : othTag;
  10712. var objIsObj = objTag == objectTag,
  10713. othIsObj = othTag == objectTag,
  10714. isSameTag = objTag == othTag;
  10715. if (isSameTag && isBuffer_1(object)) {
  10716. if (!isBuffer_1(other)) {
  10717. return false;
  10718. }
  10719. objIsArr = true;
  10720. objIsObj = false;
  10721. }
  10722. if (isSameTag && !objIsObj) {
  10723. stack || (stack = new _Stack());
  10724. return objIsArr || isTypedArray_1(object) ? _equalArrays(object, other, bitmask, customizer, equalFunc, stack) : _equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack);
  10725. }
  10726. if (!(bitmask & COMPARE_PARTIAL_FLAG$2)) {
  10727. var objIsWrapped = objIsObj && hasOwnProperty$2.call(object, '__wrapped__'),
  10728. othIsWrapped = othIsObj && hasOwnProperty$2.call(other, '__wrapped__');
  10729. if (objIsWrapped || othIsWrapped) {
  10730. var objUnwrapped = objIsWrapped ? object.value() : object,
  10731. othUnwrapped = othIsWrapped ? other.value() : other;
  10732. stack || (stack = new _Stack());
  10733. return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack);
  10734. }
  10735. }
  10736. if (!isSameTag) {
  10737. return false;
  10738. }
  10739. stack || (stack = new _Stack());
  10740. return _equalObjects(object, other, bitmask, customizer, equalFunc, stack);
  10741. }
  10742. var _baseIsEqualDeep = baseIsEqualDeep;
  10743. /**
  10744. * The base implementation of `_.isEqual` which supports partial comparisons
  10745. * and tracks traversed objects.
  10746. *
  10747. * @private
  10748. * @param {*} value The value to compare.
  10749. * @param {*} other The other value to compare.
  10750. * @param {boolean} bitmask The bitmask flags.
  10751. * 1 - Unordered comparison
  10752. * 2 - Partial comparison
  10753. * @param {Function} [customizer] The function to customize comparisons.
  10754. * @param {Object} [stack] Tracks traversed `value` and `other` objects.
  10755. * @returns {boolean} Returns `true` if the values are equivalent, else `false`.
  10756. */
  10757. function baseIsEqual(value, other, bitmask, customizer, stack) {
  10758. if (value === other) {
  10759. return true;
  10760. }
  10761. if (value == null || other == null || !isObjectLike_1(value) && !isObjectLike_1(other)) {
  10762. return value !== value && other !== other;
  10763. }
  10764. return _baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack);
  10765. }
  10766. var _baseIsEqual = baseIsEqual;
  10767. /** Used to compose bitmasks for value comparisons. */
  10768. var COMPARE_PARTIAL_FLAG$1 = 1,
  10769. COMPARE_UNORDERED_FLAG$1 = 2;
  10770. /**
  10771. * The base implementation of `_.isMatch` without support for iteratee shorthands.
  10772. *
  10773. * @private
  10774. * @param {Object} object The object to inspect.
  10775. * @param {Object} source The object of property values to match.
  10776. * @param {Array} matchData The property names, values, and compare flags to match.
  10777. * @param {Function} [customizer] The function to customize comparisons.
  10778. * @returns {boolean} Returns `true` if `object` is a match, else `false`.
  10779. */
  10780. function baseIsMatch(object, source, matchData, customizer) {
  10781. var index = matchData.length,
  10782. length = index,
  10783. noCustomizer = !customizer;
  10784. if (object == null) {
  10785. return !length;
  10786. }
  10787. object = Object(object);
  10788. while (index--) {
  10789. var data = matchData[index];
  10790. if (noCustomizer && data[2] ? data[1] !== object[data[0]] : !(data[0] in object)) {
  10791. return false;
  10792. }
  10793. }
  10794. while (++index < length) {
  10795. data = matchData[index];
  10796. var key = data[0],
  10797. objValue = object[key],
  10798. srcValue = data[1];
  10799. if (noCustomizer && data[2]) {
  10800. if (objValue === undefined && !(key in object)) {
  10801. return false;
  10802. }
  10803. } else {
  10804. var stack = new _Stack();
  10805. if (customizer) {
  10806. var result = customizer(objValue, srcValue, key, object, source, stack);
  10807. }
  10808. if (!(result === undefined ? _baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG$1 | COMPARE_UNORDERED_FLAG$1, customizer, stack) : result)) {
  10809. return false;
  10810. }
  10811. }
  10812. }
  10813. return true;
  10814. }
  10815. var _baseIsMatch = baseIsMatch;
  10816. /**
  10817. * Checks if `value` is suitable for strict equality comparisons, i.e. `===`.
  10818. *
  10819. * @private
  10820. * @param {*} value The value to check.
  10821. * @returns {boolean} Returns `true` if `value` if suitable for strict
  10822. * equality comparisons, else `false`.
  10823. */
  10824. function isStrictComparable(value) {
  10825. return value === value && !isObject_1(value);
  10826. }
  10827. var _isStrictComparable = isStrictComparable;
  10828. /**
  10829. * Gets the property names, values, and compare flags of `object`.
  10830. *
  10831. * @private
  10832. * @param {Object} object The object to query.
  10833. * @returns {Array} Returns the match data of `object`.
  10834. */
  10835. function getMatchData(object) {
  10836. var result = keys_1(object),
  10837. length = result.length;
  10838. while (length--) {
  10839. var key = result[length],
  10840. value = object[key];
  10841. result[length] = [key, value, _isStrictComparable(value)];
  10842. }
  10843. return result;
  10844. }
  10845. var _getMatchData = getMatchData;
  10846. /**
  10847. * A specialized version of `matchesProperty` for source values suitable
  10848. * for strict equality comparisons, i.e. `===`.
  10849. *
  10850. * @private
  10851. * @param {string} key The key of the property to get.
  10852. * @param {*} srcValue The value to match.
  10853. * @returns {Function} Returns the new spec function.
  10854. */
  10855. function matchesStrictComparable(key, srcValue) {
  10856. return function (object) {
  10857. if (object == null) {
  10858. return false;
  10859. }
  10860. return object[key] === srcValue && (srcValue !== undefined || key in Object(object));
  10861. };
  10862. }
  10863. var _matchesStrictComparable = matchesStrictComparable;
  10864. /**
  10865. * The base implementation of `_.matches` which doesn't clone `source`.
  10866. *
  10867. * @private
  10868. * @param {Object} source The object of property values to match.
  10869. * @returns {Function} Returns the new spec function.
  10870. */
  10871. function baseMatches(source) {
  10872. var matchData = _getMatchData(source);
  10873. if (matchData.length == 1 && matchData[0][2]) {
  10874. return _matchesStrictComparable(matchData[0][0], matchData[0][1]);
  10875. }
  10876. return function (object) {
  10877. return object === source || _baseIsMatch(object, source, matchData);
  10878. };
  10879. }
  10880. var _baseMatches = baseMatches;
  10881. /** `Object#toString` result references. */
  10882. var symbolTag = '[object Symbol]';
  10883. /**
  10884. * Checks if `value` is classified as a `Symbol` primitive or object.
  10885. *
  10886. * @static
  10887. * @memberOf _
  10888. * @since 4.0.0
  10889. * @category Lang
  10890. * @param {*} value The value to check.
  10891. * @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
  10892. * @example
  10893. *
  10894. * _.isSymbol(Symbol.iterator);
  10895. * // => true
  10896. *
  10897. * _.isSymbol('abc');
  10898. * // => false
  10899. */
  10900. function isSymbol(value) {
  10901. return typeof value == 'symbol' || isObjectLike_1(value) && _baseGetTag(value) == symbolTag;
  10902. }
  10903. var isSymbol_1 = isSymbol;
  10904. /** Used to match property names within property paths. */
  10905. var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,
  10906. reIsPlainProp = /^\w*$/;
  10907. /**
  10908. * Checks if `value` is a property name and not a property path.
  10909. *
  10910. * @private
  10911. * @param {*} value The value to check.
  10912. * @param {Object} [object] The object to query keys on.
  10913. * @returns {boolean} Returns `true` if `value` is a property name, else `false`.
  10914. */
  10915. function isKey(value, object) {
  10916. if (isArray_1(value)) {
  10917. return false;
  10918. }
  10919. var type = typeof value;
  10920. if (type == 'number' || type == 'symbol' || type == 'boolean' || value == null || isSymbol_1(value)) {
  10921. return true;
  10922. }
  10923. return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || object != null && value in Object(object);
  10924. }
  10925. var _isKey = isKey;
  10926. /** Error message constants. */
  10927. var FUNC_ERROR_TEXT = 'Expected a function';
  10928. /**
  10929. * Creates a function that memoizes the result of `func`. If `resolver` is
  10930. * provided, it determines the cache key for storing the result based on the
  10931. * arguments provided to the memoized function. By default, the first argument
  10932. * provided to the memoized function is used as the map cache key. The `func`
  10933. * is invoked with the `this` binding of the memoized function.
  10934. *
  10935. * **Note:** The cache is exposed as the `cache` property on the memoized
  10936. * function. Its creation may be customized by replacing the `_.memoize.Cache`
  10937. * constructor with one whose instances implement the
  10938. * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object)
  10939. * method interface of `clear`, `delete`, `get`, `has`, and `set`.
  10940. *
  10941. * @static
  10942. * @memberOf _
  10943. * @since 0.1.0
  10944. * @category Function
  10945. * @param {Function} func The function to have its output memoized.
  10946. * @param {Function} [resolver] The function to resolve the cache key.
  10947. * @returns {Function} Returns the new memoized function.
  10948. * @example
  10949. *
  10950. * var object = { 'a': 1, 'b': 2 };
  10951. * var other = { 'c': 3, 'd': 4 };
  10952. *
  10953. * var values = _.memoize(_.values);
  10954. * values(object);
  10955. * // => [1, 2]
  10956. *
  10957. * values(other);
  10958. * // => [3, 4]
  10959. *
  10960. * object.a = 2;
  10961. * values(object);
  10962. * // => [1, 2]
  10963. *
  10964. * // Modify the result cache.
  10965. * values.cache.set(object, ['a', 'b']);
  10966. * values(object);
  10967. * // => ['a', 'b']
  10968. *
  10969. * // Replace `_.memoize.Cache`.
  10970. * _.memoize.Cache = WeakMap;
  10971. */
  10972. function memoize(func, resolver) {
  10973. if (typeof func != 'function' || resolver != null && typeof resolver != 'function') {
  10974. throw new TypeError(FUNC_ERROR_TEXT);
  10975. }
  10976. var memoized = function () {
  10977. var args = arguments,
  10978. key = resolver ? resolver.apply(this, args) : args[0],
  10979. cache = memoized.cache;
  10980. if (cache.has(key)) {
  10981. return cache.get(key);
  10982. }
  10983. var result = func.apply(this, args);
  10984. memoized.cache = cache.set(key, result) || cache;
  10985. return result;
  10986. };
  10987. memoized.cache = new (memoize.Cache || _MapCache)();
  10988. return memoized;
  10989. } // Expose `MapCache`.
  10990. memoize.Cache = _MapCache;
  10991. var memoize_1 = memoize;
  10992. /** Used as the maximum memoize cache size. */
  10993. var MAX_MEMOIZE_SIZE = 500;
  10994. /**
  10995. * A specialized version of `_.memoize` which clears the memoized function's
  10996. * cache when it exceeds `MAX_MEMOIZE_SIZE`.
  10997. *
  10998. * @private
  10999. * @param {Function} func The function to have its output memoized.
  11000. * @returns {Function} Returns the new memoized function.
  11001. */
  11002. function memoizeCapped(func) {
  11003. var result = memoize_1(func, function (key) {
  11004. if (cache.size === MAX_MEMOIZE_SIZE) {
  11005. cache.clear();
  11006. }
  11007. return key;
  11008. });
  11009. var cache = result.cache;
  11010. return result;
  11011. }
  11012. var _memoizeCapped = memoizeCapped;
  11013. /** Used to match property names within property paths. */
  11014. var rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g;
  11015. /** Used to match backslashes in property paths. */
  11016. var reEscapeChar = /\\(\\)?/g;
  11017. /**
  11018. * Converts `string` to a property path array.
  11019. *
  11020. * @private
  11021. * @param {string} string The string to convert.
  11022. * @returns {Array} Returns the property path array.
  11023. */
  11024. var stringToPath = _memoizeCapped(function (string) {
  11025. var result = [];
  11026. if (string.charCodeAt(0) === 46
  11027. /* . */
  11028. ) {
  11029. result.push('');
  11030. }
  11031. string.replace(rePropName, function (match, number, quote, subString) {
  11032. result.push(quote ? subString.replace(reEscapeChar, '$1') : number || match);
  11033. });
  11034. return result;
  11035. });
  11036. var _stringToPath = stringToPath;
  11037. /**
  11038. * A specialized version of `_.map` for arrays without support for iteratee
  11039. * shorthands.
  11040. *
  11041. * @private
  11042. * @param {Array} [array] The array to iterate over.
  11043. * @param {Function} iteratee The function invoked per iteration.
  11044. * @returns {Array} Returns the new mapped array.
  11045. */
  11046. function arrayMap(array, iteratee) {
  11047. var index = -1,
  11048. length = array == null ? 0 : array.length,
  11049. result = Array(length);
  11050. while (++index < length) {
  11051. result[index] = iteratee(array[index], index, array);
  11052. }
  11053. return result;
  11054. }
  11055. var _arrayMap = arrayMap;
  11056. /** Used as references for various `Number` constants. */
  11057. var INFINITY$1 = 1 / 0;
  11058. /** Used to convert symbols to primitives and strings. */
  11059. var symbolProto = _Symbol ? _Symbol.prototype : undefined,
  11060. symbolToString = symbolProto ? symbolProto.toString : undefined;
  11061. /**
  11062. * The base implementation of `_.toString` which doesn't convert nullish
  11063. * values to empty strings.
  11064. *
  11065. * @private
  11066. * @param {*} value The value to process.
  11067. * @returns {string} Returns the string.
  11068. */
  11069. function baseToString(value) {
  11070. // Exit early for strings to avoid a performance hit in some environments.
  11071. if (typeof value == 'string') {
  11072. return value;
  11073. }
  11074. if (isArray_1(value)) {
  11075. // Recursively convert values (susceptible to call stack limits).
  11076. return _arrayMap(value, baseToString) + '';
  11077. }
  11078. if (isSymbol_1(value)) {
  11079. return symbolToString ? symbolToString.call(value) : '';
  11080. }
  11081. var result = value + '';
  11082. return result == '0' && 1 / value == -INFINITY$1 ? '-0' : result;
  11083. }
  11084. var _baseToString = baseToString;
  11085. /**
  11086. * Converts `value` to a string. An empty string is returned for `null`
  11087. * and `undefined` values. The sign of `-0` is preserved.
  11088. *
  11089. * @static
  11090. * @memberOf _
  11091. * @since 4.0.0
  11092. * @category Lang
  11093. * @param {*} value The value to convert.
  11094. * @returns {string} Returns the converted string.
  11095. * @example
  11096. *
  11097. * _.toString(null);
  11098. * // => ''
  11099. *
  11100. * _.toString(-0);
  11101. * // => '-0'
  11102. *
  11103. * _.toString([1, 2, 3]);
  11104. * // => '1,2,3'
  11105. */
  11106. function toString(value) {
  11107. return value == null ? '' : _baseToString(value);
  11108. }
  11109. var toString_1 = toString;
  11110. /**
  11111. * Casts `value` to a path array if it's not one.
  11112. *
  11113. * @private
  11114. * @param {*} value The value to inspect.
  11115. * @param {Object} [object] The object to query keys on.
  11116. * @returns {Array} Returns the cast property path array.
  11117. */
  11118. function castPath(value, object) {
  11119. if (isArray_1(value)) {
  11120. return value;
  11121. }
  11122. return _isKey(value, object) ? [value] : _stringToPath(toString_1(value));
  11123. }
  11124. var _castPath = castPath;
  11125. /** Used as references for various `Number` constants. */
  11126. var INFINITY = 1 / 0;
  11127. /**
  11128. * Converts `value` to a string key if it's not a string or symbol.
  11129. *
  11130. * @private
  11131. * @param {*} value The value to inspect.
  11132. * @returns {string|symbol} Returns the key.
  11133. */
  11134. function toKey(value) {
  11135. if (typeof value == 'string' || isSymbol_1(value)) {
  11136. return value;
  11137. }
  11138. var result = value + '';
  11139. return result == '0' && 1 / value == -INFINITY ? '-0' : result;
  11140. }
  11141. var _toKey = toKey;
  11142. /**
  11143. * The base implementation of `_.get` without support for default values.
  11144. *
  11145. * @private
  11146. * @param {Object} object The object to query.
  11147. * @param {Array|string} path The path of the property to get.
  11148. * @returns {*} Returns the resolved value.
  11149. */
  11150. function baseGet(object, path) {
  11151. path = _castPath(path, object);
  11152. var index = 0,
  11153. length = path.length;
  11154. while (object != null && index < length) {
  11155. object = object[_toKey(path[index++])];
  11156. }
  11157. return index && index == length ? object : undefined;
  11158. }
  11159. var _baseGet = baseGet;
  11160. /**
  11161. * Gets the value at `path` of `object`. If the resolved value is
  11162. * `undefined`, the `defaultValue` is returned in its place.
  11163. *
  11164. * @static
  11165. * @memberOf _
  11166. * @since 3.7.0
  11167. * @category Object
  11168. * @param {Object} object The object to query.
  11169. * @param {Array|string} path The path of the property to get.
  11170. * @param {*} [defaultValue] The value returned for `undefined` resolved values.
  11171. * @returns {*} Returns the resolved value.
  11172. * @example
  11173. *
  11174. * var object = { 'a': [{ 'b': { 'c': 3 } }] };
  11175. *
  11176. * _.get(object, 'a[0].b.c');
  11177. * // => 3
  11178. *
  11179. * _.get(object, ['a', '0', 'b', 'c']);
  11180. * // => 3
  11181. *
  11182. * _.get(object, 'a.b.c', 'default');
  11183. * // => 'default'
  11184. */
  11185. function get(object, path, defaultValue) {
  11186. var result = object == null ? undefined : _baseGet(object, path);
  11187. return result === undefined ? defaultValue : result;
  11188. }
  11189. var get_1 = get;
  11190. /**
  11191. * The base implementation of `_.hasIn` without support for deep paths.
  11192. *
  11193. * @private
  11194. * @param {Object} [object] The object to query.
  11195. * @param {Array|string} key The key to check.
  11196. * @returns {boolean} Returns `true` if `key` exists, else `false`.
  11197. */
  11198. function baseHasIn(object, key) {
  11199. return object != null && key in Object(object);
  11200. }
  11201. var _baseHasIn = baseHasIn;
  11202. /**
  11203. * Checks if `path` exists on `object`.
  11204. *
  11205. * @private
  11206. * @param {Object} object The object to query.
  11207. * @param {Array|string} path The path to check.
  11208. * @param {Function} hasFunc The function to check properties.
  11209. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  11210. */
  11211. function hasPath(object, path, hasFunc) {
  11212. path = _castPath(path, object);
  11213. var index = -1,
  11214. length = path.length,
  11215. result = false;
  11216. while (++index < length) {
  11217. var key = _toKey(path[index]);
  11218. if (!(result = object != null && hasFunc(object, key))) {
  11219. break;
  11220. }
  11221. object = object[key];
  11222. }
  11223. if (result || ++index != length) {
  11224. return result;
  11225. }
  11226. length = object == null ? 0 : object.length;
  11227. return !!length && isLength_1(length) && _isIndex(key, length) && (isArray_1(object) || isArguments_1(object));
  11228. }
  11229. var _hasPath = hasPath;
  11230. /**
  11231. * Checks if `path` is a direct or inherited property of `object`.
  11232. *
  11233. * @static
  11234. * @memberOf _
  11235. * @since 4.0.0
  11236. * @category Object
  11237. * @param {Object} object The object to query.
  11238. * @param {Array|string} path The path to check.
  11239. * @returns {boolean} Returns `true` if `path` exists, else `false`.
  11240. * @example
  11241. *
  11242. * var object = _.create({ 'a': _.create({ 'b': 2 }) });
  11243. *
  11244. * _.hasIn(object, 'a');
  11245. * // => true
  11246. *
  11247. * _.hasIn(object, 'a.b');
  11248. * // => true
  11249. *
  11250. * _.hasIn(object, ['a', 'b']);
  11251. * // => true
  11252. *
  11253. * _.hasIn(object, 'b');
  11254. * // => false
  11255. */
  11256. function hasIn(object, path) {
  11257. return object != null && _hasPath(object, path, _baseHasIn);
  11258. }
  11259. var hasIn_1 = hasIn;
  11260. /** Used to compose bitmasks for value comparisons. */
  11261. var COMPARE_PARTIAL_FLAG = 1,
  11262. COMPARE_UNORDERED_FLAG = 2;
  11263. /**
  11264. * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`.
  11265. *
  11266. * @private
  11267. * @param {string} path The path of the property to get.
  11268. * @param {*} srcValue The value to match.
  11269. * @returns {Function} Returns the new spec function.
  11270. */
  11271. function baseMatchesProperty(path, srcValue) {
  11272. if (_isKey(path) && _isStrictComparable(srcValue)) {
  11273. return _matchesStrictComparable(_toKey(path), srcValue);
  11274. }
  11275. return function (object) {
  11276. var objValue = get_1(object, path);
  11277. return objValue === undefined && objValue === srcValue ? hasIn_1(object, path) : _baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG);
  11278. };
  11279. }
  11280. var _baseMatchesProperty = baseMatchesProperty;
  11281. /**
  11282. * This method returns the first argument it receives.
  11283. *
  11284. * @static
  11285. * @since 0.1.0
  11286. * @memberOf _
  11287. * @category Util
  11288. * @param {*} value Any value.
  11289. * @returns {*} Returns `value`.
  11290. * @example
  11291. *
  11292. * var object = { 'a': 1 };
  11293. *
  11294. * console.log(_.identity(object) === object);
  11295. * // => true
  11296. */
  11297. function identity(value) {
  11298. return value;
  11299. }
  11300. var identity_1 = identity;
  11301. /**
  11302. * The base implementation of `_.property` without support for deep paths.
  11303. *
  11304. * @private
  11305. * @param {string} key The key of the property to get.
  11306. * @returns {Function} Returns the new accessor function.
  11307. */
  11308. function baseProperty(key) {
  11309. return function (object) {
  11310. return object == null ? undefined : object[key];
  11311. };
  11312. }
  11313. var _baseProperty = baseProperty;
  11314. /**
  11315. * A specialized version of `baseProperty` which supports deep paths.
  11316. *
  11317. * @private
  11318. * @param {Array|string} path The path of the property to get.
  11319. * @returns {Function} Returns the new accessor function.
  11320. */
  11321. function basePropertyDeep(path) {
  11322. return function (object) {
  11323. return _baseGet(object, path);
  11324. };
  11325. }
  11326. var _basePropertyDeep = basePropertyDeep;
  11327. /**
  11328. * Creates a function that returns the value at `path` of a given object.
  11329. *
  11330. * @static
  11331. * @memberOf _
  11332. * @since 2.4.0
  11333. * @category Util
  11334. * @param {Array|string} path The path of the property to get.
  11335. * @returns {Function} Returns the new accessor function.
  11336. * @example
  11337. *
  11338. * var objects = [
  11339. * { 'a': { 'b': 2 } },
  11340. * { 'a': { 'b': 1 } }
  11341. * ];
  11342. *
  11343. * _.map(objects, _.property('a.b'));
  11344. * // => [2, 1]
  11345. *
  11346. * _.map(_.sortBy(objects, _.property(['a', 'b'])), 'a.b');
  11347. * // => [1, 2]
  11348. */
  11349. function property(path) {
  11350. return _isKey(path) ? _baseProperty(_toKey(path)) : _basePropertyDeep(path);
  11351. }
  11352. var property_1 = property;
  11353. /**
  11354. * The base implementation of `_.iteratee`.
  11355. *
  11356. * @private
  11357. * @param {*} [value=_.identity] The value to convert to an iteratee.
  11358. * @returns {Function} Returns the iteratee.
  11359. */
  11360. function baseIteratee(value) {
  11361. // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9.
  11362. // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details.
  11363. if (typeof value == 'function') {
  11364. return value;
  11365. }
  11366. if (value == null) {
  11367. return identity_1;
  11368. }
  11369. if (typeof value == 'object') {
  11370. return isArray_1(value) ? _baseMatchesProperty(value[0], value[1]) : _baseMatches(value);
  11371. }
  11372. return property_1(value);
  11373. }
  11374. var _baseIteratee = baseIteratee;
  11375. /**
  11376. * Creates a function like `_.groupBy`.
  11377. *
  11378. * @private
  11379. * @param {Function} setter The function to set accumulator values.
  11380. * @param {Function} [initializer] The accumulator object initializer.
  11381. * @returns {Function} Returns the new aggregator function.
  11382. */
  11383. function createAggregator(setter, initializer) {
  11384. return function (collection, iteratee) {
  11385. var func = isArray_1(collection) ? _arrayAggregator : _baseAggregator,
  11386. accumulator = initializer ? initializer() : {};
  11387. return func(collection, setter, _baseIteratee(iteratee), accumulator);
  11388. };
  11389. }
  11390. var _createAggregator = createAggregator;
  11391. /**
  11392. * Creates an array of elements split into two groups, the first of which
  11393. * contains elements `predicate` returns truthy for, the second of which
  11394. * contains elements `predicate` returns falsey for. The predicate is
  11395. * invoked with one argument: (value).
  11396. *
  11397. * @static
  11398. * @memberOf _
  11399. * @since 3.0.0
  11400. * @category Collection
  11401. * @param {Array|Object} collection The collection to iterate over.
  11402. * @param {Function} [predicate=_.identity] The function invoked per iteration.
  11403. * @returns {Array} Returns the array of grouped elements.
  11404. * @example
  11405. *
  11406. * var users = [
  11407. * { 'user': 'barney', 'age': 36, 'active': false },
  11408. * { 'user': 'fred', 'age': 40, 'active': true },
  11409. * { 'user': 'pebbles', 'age': 1, 'active': false }
  11410. * ];
  11411. *
  11412. * _.partition(users, function(o) { return o.active; });
  11413. * // => objects for [['fred'], ['barney', 'pebbles']]
  11414. *
  11415. * // The `_.matches` iteratee shorthand.
  11416. * _.partition(users, { 'age': 1, 'active': false });
  11417. * // => objects for [['pebbles'], ['barney', 'fred']]
  11418. *
  11419. * // The `_.matchesProperty` iteratee shorthand.
  11420. * _.partition(users, ['active', false]);
  11421. * // => objects for [['barney', 'pebbles'], ['fred']]
  11422. *
  11423. * // The `_.property` iteratee shorthand.
  11424. * _.partition(users, 'active');
  11425. * // => objects for [['fred'], ['barney', 'pebbles']]
  11426. */
  11427. var partition = _createAggregator(function (result, value, key) {
  11428. result[key ? 0 : 1].push(value);
  11429. }, function () {
  11430. return [[], []];
  11431. });
  11432. var partition_1 = partition;
  11433. var createMinimistOptions = function createMinimistOptions(detailedOptions) {
  11434. const [boolean, string] = partition_1(detailedOptions, ({
  11435. type
  11436. }) => type === "boolean").map(detailedOptions => detailedOptions.flatMap(({
  11437. name,
  11438. alias
  11439. }) => alias ? [name, alias] : [name]));
  11440. const defaults = Object.fromEntries(detailedOptions.filter(option => !option.deprecated && (!option.forwardToApi || option.name === "plugin" || option.name === "plugin-search-dir") && option.default !== undefined).map(option => [option.name, option.default]));
  11441. return {
  11442. // we use vnopts' AliasSchema to handle aliases for better error messages
  11443. alias: {},
  11444. boolean,
  11445. string,
  11446. default: defaults
  11447. };
  11448. };
  11449. const {
  11450. optionsNormalizer
  11451. } = prettierInternal;
  11452. function getOptions(argv, detailedOptions) {
  11453. return Object.fromEntries(detailedOptions.filter(({
  11454. forwardToApi
  11455. }) => forwardToApi).map(({
  11456. forwardToApi,
  11457. name
  11458. }) => [forwardToApi, argv[name]]));
  11459. }
  11460. function cliifyOptions(object, apiDetailedOptionMap) {
  11461. return Object.fromEntries(Object.entries(object || {}).map(([key, value]) => {
  11462. const apiOption = apiDetailedOptionMap[key];
  11463. const cliKey = apiOption ? apiOption.name : key;
  11464. return [dashify(cliKey), value];
  11465. }));
  11466. }
  11467. function createApiDetailedOptionMap(detailedOptions) {
  11468. return Object.fromEntries(detailedOptions.filter(option => option.forwardToApi && option.forwardToApi !== option.name).map(option => [option.forwardToApi, option]));
  11469. }
  11470. function parseArgsToOptions(context, overrideDefaults) {
  11471. const minimistOptions = createMinimistOptions(context.detailedOptions);
  11472. const apiDetailedOptionMap = createApiDetailedOptionMap(context.detailedOptions);
  11473. return getOptions(optionsNormalizer.normalizeCliOptions(minimist_1(context.rawArguments, {
  11474. string: minimistOptions.string,
  11475. boolean: minimistOptions.boolean,
  11476. default: cliifyOptions(overrideDefaults, apiDetailedOptionMap)
  11477. }), context.detailedOptions, {
  11478. logger: false
  11479. }), context.detailedOptions);
  11480. }
  11481. async function getOptionsOrDie(context, filePath) {
  11482. try {
  11483. if (context.argv.config === false) {
  11484. context.logger.debug("'--no-config' option found, skip loading config file.");
  11485. return null;
  11486. }
  11487. context.logger.debug(context.argv.config ? `load config file from '${context.argv.config}'` : `resolve config from '${filePath}'`);
  11488. const options = await prettier$1.resolveConfig(filePath, {
  11489. editorconfig: context.argv.editorconfig,
  11490. config: context.argv.config
  11491. });
  11492. context.logger.debug("loaded options `" + JSON.stringify(options) + "`");
  11493. return options;
  11494. } catch (error) {
  11495. context.logger.error(`Invalid configuration file \`${filePath}\`: ` + error.message);
  11496. process.exit(2);
  11497. }
  11498. }
  11499. function applyConfigPrecedence(context, options) {
  11500. try {
  11501. switch (context.argv["config-precedence"]) {
  11502. case "cli-override":
  11503. return parseArgsToOptions(context, options);
  11504. case "file-override":
  11505. return Object.assign(Object.assign({}, parseArgsToOptions(context)), options);
  11506. case "prefer-file":
  11507. return options || parseArgsToOptions(context);
  11508. }
  11509. } catch (error) {
  11510. /* istanbul ignore next */
  11511. context.logger.error(error.toString());
  11512. /* istanbul ignore next */
  11513. process.exit(2);
  11514. }
  11515. }
  11516. async function getOptionsForFile$1(context, filepath) {
  11517. const options = await getOptionsOrDie(context, filepath);
  11518. const hasPlugins = options && options.plugins;
  11519. if (hasPlugins) {
  11520. context.pushContextPlugins(options.plugins);
  11521. }
  11522. const appliedOptions = Object.assign({
  11523. filepath
  11524. }, applyConfigPrecedence(context, options && optionsNormalizer.normalizeApiOptions(options, context.supportOptions, {
  11525. logger: context.logger
  11526. })));
  11527. context.logger.debug(`applied config-precedence (${context.argv["config-precedence"]}): ` + `${JSON.stringify(appliedOptions)}`);
  11528. if (hasPlugins) {
  11529. context.popContextPlugins();
  11530. }
  11531. return appliedOptions;
  11532. }
  11533. var option = {
  11534. getOptionsForFile: getOptionsForFile$1,
  11535. createMinimistOptions
  11536. };
  11537. const {
  11538. isCI
  11539. } = require$$1; // Some CI pipelines incorrectly report process.stdout.isTTY status,
  11540. // which causes unwanted lines in the output. An additional check for isCI() helps.
  11541. // See https://github.com/prettier/prettier/issues/5801
  11542. var isTty = function isTTY() {
  11543. return process.stdout.isTTY && !isCI();
  11544. };
  11545. /*istanbul ignore start*/
  11546. var base = createCommonjsModule(function (module, exports) {
  11547. Object.defineProperty(exports, "__esModule", {
  11548. value: true
  11549. });
  11550. exports["default"] = Diff;
  11551. /*istanbul ignore end*/
  11552. function Diff() {}
  11553. Diff.prototype = {
  11554. /*istanbul ignore start*/
  11555. /*istanbul ignore end*/
  11556. diff: function diff(oldString, newString) {
  11557. /*istanbul ignore start*/
  11558. var
  11559. /*istanbul ignore end*/
  11560. options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  11561. var callback = options.callback;
  11562. if (typeof options === 'function') {
  11563. callback = options;
  11564. options = {};
  11565. }
  11566. this.options = options;
  11567. var self = this;
  11568. function done(value) {
  11569. if (callback) {
  11570. setTimeout(function () {
  11571. callback(undefined, value);
  11572. }, 0);
  11573. return true;
  11574. } else {
  11575. return value;
  11576. }
  11577. } // Allow subclasses to massage the input prior to running
  11578. oldString = this.castInput(oldString);
  11579. newString = this.castInput(newString);
  11580. oldString = this.removeEmpty(this.tokenize(oldString));
  11581. newString = this.removeEmpty(this.tokenize(newString));
  11582. var newLen = newString.length,
  11583. oldLen = oldString.length;
  11584. var editLength = 1;
  11585. var maxEditLength = newLen + oldLen;
  11586. var bestPath = [{
  11587. newPos: -1,
  11588. components: []
  11589. }]; // Seed editLength = 0, i.e. the content starts with the same values
  11590. var oldPos = this.extractCommon(bestPath[0], newString, oldString, 0);
  11591. if (bestPath[0].newPos + 1 >= newLen && oldPos + 1 >= oldLen) {
  11592. // Identity per the equality and tokenizer
  11593. return done([{
  11594. value: this.join(newString),
  11595. count: newString.length
  11596. }]);
  11597. } // Main worker method. checks all permutations of a given edit length for acceptance.
  11598. function execEditLength() {
  11599. for (var diagonalPath = -1 * editLength; diagonalPath <= editLength; diagonalPath += 2) {
  11600. var basePath =
  11601. /*istanbul ignore start*/
  11602. void 0
  11603. /*istanbul ignore end*/
  11604. ;
  11605. var addPath = bestPath[diagonalPath - 1],
  11606. removePath = bestPath[diagonalPath + 1],
  11607. _oldPos = (removePath ? removePath.newPos : 0) - diagonalPath;
  11608. if (addPath) {
  11609. // No one else is going to attempt to use this value, clear it
  11610. bestPath[diagonalPath - 1] = undefined;
  11611. }
  11612. var canAdd = addPath && addPath.newPos + 1 < newLen,
  11613. canRemove = removePath && 0 <= _oldPos && _oldPos < oldLen;
  11614. if (!canAdd && !canRemove) {
  11615. // If this path is a terminal then prune
  11616. bestPath[diagonalPath] = undefined;
  11617. continue;
  11618. } // Select the diagonal that we want to branch from. We select the prior
  11619. // path whose position in the new string is the farthest from the origin
  11620. // and does not pass the bounds of the diff graph
  11621. if (!canAdd || canRemove && addPath.newPos < removePath.newPos) {
  11622. basePath = clonePath(removePath);
  11623. self.pushComponent(basePath.components, undefined, true);
  11624. } else {
  11625. basePath = addPath; // No need to clone, we've pulled it from the list
  11626. basePath.newPos++;
  11627. self.pushComponent(basePath.components, true, undefined);
  11628. }
  11629. _oldPos = self.extractCommon(basePath, newString, oldString, diagonalPath); // If we have hit the end of both strings, then we are done
  11630. if (basePath.newPos + 1 >= newLen && _oldPos + 1 >= oldLen) {
  11631. return done(buildValues(self, basePath.components, newString, oldString, self.useLongestToken));
  11632. } else {
  11633. // Otherwise track this path as a potential candidate and continue.
  11634. bestPath[diagonalPath] = basePath;
  11635. }
  11636. }
  11637. editLength++;
  11638. } // Performs the length of edit iteration. Is a bit fugly as this has to support the
  11639. // sync and async mode which is never fun. Loops over execEditLength until a value
  11640. // is produced.
  11641. if (callback) {
  11642. (function exec() {
  11643. setTimeout(function () {
  11644. // This should not happen, but we want to be safe.
  11645. /* istanbul ignore next */
  11646. if (editLength > maxEditLength) {
  11647. return callback();
  11648. }
  11649. if (!execEditLength()) {
  11650. exec();
  11651. }
  11652. }, 0);
  11653. })();
  11654. } else {
  11655. while (editLength <= maxEditLength) {
  11656. var ret = execEditLength();
  11657. if (ret) {
  11658. return ret;
  11659. }
  11660. }
  11661. }
  11662. },
  11663. /*istanbul ignore start*/
  11664. /*istanbul ignore end*/
  11665. pushComponent: function pushComponent(components, added, removed) {
  11666. var last = components[components.length - 1];
  11667. if (last && last.added === added && last.removed === removed) {
  11668. // We need to clone here as the component clone operation is just
  11669. // as shallow array clone
  11670. components[components.length - 1] = {
  11671. count: last.count + 1,
  11672. added: added,
  11673. removed: removed
  11674. };
  11675. } else {
  11676. components.push({
  11677. count: 1,
  11678. added: added,
  11679. removed: removed
  11680. });
  11681. }
  11682. },
  11683. /*istanbul ignore start*/
  11684. /*istanbul ignore end*/
  11685. extractCommon: function extractCommon(basePath, newString, oldString, diagonalPath) {
  11686. var newLen = newString.length,
  11687. oldLen = oldString.length,
  11688. newPos = basePath.newPos,
  11689. oldPos = newPos - diagonalPath,
  11690. commonCount = 0;
  11691. while (newPos + 1 < newLen && oldPos + 1 < oldLen && this.equals(newString[newPos + 1], oldString[oldPos + 1])) {
  11692. newPos++;
  11693. oldPos++;
  11694. commonCount++;
  11695. }
  11696. if (commonCount) {
  11697. basePath.components.push({
  11698. count: commonCount
  11699. });
  11700. }
  11701. basePath.newPos = newPos;
  11702. return oldPos;
  11703. },
  11704. /*istanbul ignore start*/
  11705. /*istanbul ignore end*/
  11706. equals: function equals(left, right) {
  11707. if (this.options.comparator) {
  11708. return this.options.comparator(left, right);
  11709. } else {
  11710. return left === right || this.options.ignoreCase && left.toLowerCase() === right.toLowerCase();
  11711. }
  11712. },
  11713. /*istanbul ignore start*/
  11714. /*istanbul ignore end*/
  11715. removeEmpty: function removeEmpty(array) {
  11716. var ret = [];
  11717. for (var i = 0; i < array.length; i++) {
  11718. if (array[i]) {
  11719. ret.push(array[i]);
  11720. }
  11721. }
  11722. return ret;
  11723. },
  11724. /*istanbul ignore start*/
  11725. /*istanbul ignore end*/
  11726. castInput: function castInput(value) {
  11727. return value;
  11728. },
  11729. /*istanbul ignore start*/
  11730. /*istanbul ignore end*/
  11731. tokenize: function tokenize(value) {
  11732. return value.split('');
  11733. },
  11734. /*istanbul ignore start*/
  11735. /*istanbul ignore end*/
  11736. join: function join(chars) {
  11737. return chars.join('');
  11738. }
  11739. };
  11740. function buildValues(diff, components, newString, oldString, useLongestToken) {
  11741. var componentPos = 0,
  11742. componentLen = components.length,
  11743. newPos = 0,
  11744. oldPos = 0;
  11745. for (; componentPos < componentLen; componentPos++) {
  11746. var component = components[componentPos];
  11747. if (!component.removed) {
  11748. if (!component.added && useLongestToken) {
  11749. var value = newString.slice(newPos, newPos + component.count);
  11750. value = value.map(function (value, i) {
  11751. var oldValue = oldString[oldPos + i];
  11752. return oldValue.length > value.length ? oldValue : value;
  11753. });
  11754. component.value = diff.join(value);
  11755. } else {
  11756. component.value = diff.join(newString.slice(newPos, newPos + component.count));
  11757. }
  11758. newPos += component.count; // Common case
  11759. if (!component.added) {
  11760. oldPos += component.count;
  11761. }
  11762. } else {
  11763. component.value = diff.join(oldString.slice(oldPos, oldPos + component.count));
  11764. oldPos += component.count; // Reverse add and remove so removes are output first to match common convention
  11765. // The diffing algorithm is tied to add then remove output and this is the simplest
  11766. // route to get the desired output with minimal overhead.
  11767. if (componentPos && components[componentPos - 1].added) {
  11768. var tmp = components[componentPos - 1];
  11769. components[componentPos - 1] = components[componentPos];
  11770. components[componentPos] = tmp;
  11771. }
  11772. }
  11773. } // Special case handle for when one terminal is ignored (i.e. whitespace).
  11774. // For this case we merge the terminal into the prior string and drop the change.
  11775. // This is only available for string mode.
  11776. var lastComponent = components[componentLen - 1];
  11777. if (componentLen > 1 && typeof lastComponent.value === 'string' && (lastComponent.added || lastComponent.removed) && diff.equals('', lastComponent.value)) {
  11778. components[componentLen - 2].value += lastComponent.value;
  11779. components.pop();
  11780. }
  11781. return components;
  11782. }
  11783. function clonePath(path) {
  11784. return {
  11785. newPos: path.newPos,
  11786. components: path.components.slice(0)
  11787. };
  11788. }
  11789. });
  11790. /*istanbul ignore start*/
  11791. var character = createCommonjsModule(function (module, exports) {
  11792. Object.defineProperty(exports, "__esModule", {
  11793. value: true
  11794. });
  11795. exports.diffChars = diffChars;
  11796. exports.characterDiff = void 0;
  11797. /*istanbul ignore end*/
  11798. var
  11799. /*istanbul ignore start*/
  11800. _base = _interopRequireDefault(base)
  11801. /*istanbul ignore end*/
  11802. ;
  11803. /*istanbul ignore start*/
  11804. function _interopRequireDefault(obj) {
  11805. return obj && obj.__esModule ? obj : {
  11806. "default": obj
  11807. };
  11808. }
  11809. /*istanbul ignore end*/
  11810. var characterDiff = new
  11811. /*istanbul ignore start*/
  11812. _base
  11813. /*istanbul ignore end*/
  11814. [
  11815. /*istanbul ignore start*/
  11816. "default"
  11817. /*istanbul ignore end*/
  11818. ]();
  11819. /*istanbul ignore start*/
  11820. exports.characterDiff = characterDiff;
  11821. /*istanbul ignore end*/
  11822. function diffChars(oldStr, newStr, options) {
  11823. return characterDiff.diff(oldStr, newStr, options);
  11824. }
  11825. });
  11826. /*istanbul ignore start*/
  11827. var generateOptions_1 = generateOptions;
  11828. /*istanbul ignore end*/
  11829. function generateOptions(options, defaults) {
  11830. if (typeof options === 'function') {
  11831. defaults.callback = options;
  11832. } else if (options) {
  11833. for (var name in options) {
  11834. /* istanbul ignore else */
  11835. if (options.hasOwnProperty(name)) {
  11836. defaults[name] = options[name];
  11837. }
  11838. }
  11839. }
  11840. return defaults;
  11841. }
  11842. var params = /*#__PURE__*/Object.defineProperty({
  11843. generateOptions: generateOptions_1
  11844. }, '__esModule', {
  11845. value: true
  11846. });
  11847. /*istanbul ignore start*/
  11848. var word = createCommonjsModule(function (module, exports) {
  11849. Object.defineProperty(exports, "__esModule", {
  11850. value: true
  11851. });
  11852. exports.diffWords = diffWords;
  11853. exports.diffWordsWithSpace = diffWordsWithSpace;
  11854. exports.wordDiff = void 0;
  11855. /*istanbul ignore end*/
  11856. var
  11857. /*istanbul ignore start*/
  11858. _base = _interopRequireDefault(base)
  11859. /*istanbul ignore end*/
  11860. ;
  11861. /*istanbul ignore start*/
  11862. function _interopRequireDefault(obj) {
  11863. return obj && obj.__esModule ? obj : {
  11864. "default": obj
  11865. };
  11866. }
  11867. /*istanbul ignore end*/
  11868. // Based on https://en.wikipedia.org/wiki/Latin_script_in_Unicode
  11869. //
  11870. // Ranges and exceptions:
  11871. // Latin-1 Supplement, 0080–00FF
  11872. // - U+00D7 × Multiplication sign
  11873. // - U+00F7 ÷ Division sign
  11874. // Latin Extended-A, 0100–017F
  11875. // Latin Extended-B, 0180–024F
  11876. // IPA Extensions, 0250–02AF
  11877. // Spacing Modifier Letters, 02B0–02FF
  11878. // - U+02C7 ˇ &#711; Caron
  11879. // - U+02D8 ˘ &#728; Breve
  11880. // - U+02D9 ˙ &#729; Dot Above
  11881. // - U+02DA ˚ &#730; Ring Above
  11882. // - U+02DB ˛ &#731; Ogonek
  11883. // - U+02DC ˜ &#732; Small Tilde
  11884. // - U+02DD ˝ &#733; Double Acute Accent
  11885. // Latin Extended Additional, 1E00–1EFF
  11886. var extendedWordChars = /^[A-Za-z\xC0-\u02C6\u02C8-\u02D7\u02DE-\u02FF\u1E00-\u1EFF]+$/;
  11887. var reWhitespace = /\S/;
  11888. var wordDiff = new
  11889. /*istanbul ignore start*/
  11890. _base
  11891. /*istanbul ignore end*/
  11892. [
  11893. /*istanbul ignore start*/
  11894. "default"
  11895. /*istanbul ignore end*/
  11896. ]();
  11897. /*istanbul ignore start*/
  11898. exports.wordDiff = wordDiff;
  11899. /*istanbul ignore end*/
  11900. wordDiff.equals = function (left, right) {
  11901. if (this.options.ignoreCase) {
  11902. left = left.toLowerCase();
  11903. right = right.toLowerCase();
  11904. }
  11905. return left === right || this.options.ignoreWhitespace && !reWhitespace.test(left) && !reWhitespace.test(right);
  11906. };
  11907. wordDiff.tokenize = function (value) {
  11908. // All whitespace symbols except newline group into one token, each newline - in separate token
  11909. var tokens = value.split(/([^\S\r\n]+|[()[\]{}'"\r\n]|\b)/); // Join the boundary splits that we do not consider to be boundaries. This is primarily the extended Latin character set.
  11910. for (var i = 0; i < tokens.length - 1; i++) {
  11911. // If we have an empty string in the next field and we have only word chars before and after, merge
  11912. if (!tokens[i + 1] && tokens[i + 2] && extendedWordChars.test(tokens[i]) && extendedWordChars.test(tokens[i + 2])) {
  11913. tokens[i] += tokens[i + 2];
  11914. tokens.splice(i + 1, 2);
  11915. i--;
  11916. }
  11917. }
  11918. return tokens;
  11919. };
  11920. function diffWords(oldStr, newStr, options) {
  11921. options =
  11922. /*istanbul ignore start*/
  11923. (/*istanbul ignore end*/
  11924. /*istanbul ignore start*/
  11925. 0, params
  11926. /*istanbul ignore end*/
  11927. .
  11928. /*istanbul ignore start*/
  11929. generateOptions
  11930. /*istanbul ignore end*/
  11931. )(options, {
  11932. ignoreWhitespace: true
  11933. });
  11934. return wordDiff.diff(oldStr, newStr, options);
  11935. }
  11936. function diffWordsWithSpace(oldStr, newStr, options) {
  11937. return wordDiff.diff(oldStr, newStr, options);
  11938. }
  11939. });
  11940. /*istanbul ignore start*/
  11941. var line = createCommonjsModule(function (module, exports) {
  11942. Object.defineProperty(exports, "__esModule", {
  11943. value: true
  11944. });
  11945. exports.diffLines = diffLines;
  11946. exports.diffTrimmedLines = diffTrimmedLines;
  11947. exports.lineDiff = void 0;
  11948. /*istanbul ignore end*/
  11949. var
  11950. /*istanbul ignore start*/
  11951. _base = _interopRequireDefault(base)
  11952. /*istanbul ignore end*/
  11953. ;
  11954. /*istanbul ignore start*/
  11955. function _interopRequireDefault(obj) {
  11956. return obj && obj.__esModule ? obj : {
  11957. "default": obj
  11958. };
  11959. }
  11960. /*istanbul ignore end*/
  11961. var lineDiff = new
  11962. /*istanbul ignore start*/
  11963. _base
  11964. /*istanbul ignore end*/
  11965. [
  11966. /*istanbul ignore start*/
  11967. "default"
  11968. /*istanbul ignore end*/
  11969. ]();
  11970. /*istanbul ignore start*/
  11971. exports.lineDiff = lineDiff;
  11972. /*istanbul ignore end*/
  11973. lineDiff.tokenize = function (value) {
  11974. var retLines = [],
  11975. linesAndNewlines = value.split(/(\n|\r\n)/); // Ignore the final empty token that occurs if the string ends with a new line
  11976. if (!linesAndNewlines[linesAndNewlines.length - 1]) {
  11977. linesAndNewlines.pop();
  11978. } // Merge the content and line separators into single tokens
  11979. for (var i = 0; i < linesAndNewlines.length; i++) {
  11980. var line = linesAndNewlines[i];
  11981. if (i % 2 && !this.options.newlineIsToken) {
  11982. retLines[retLines.length - 1] += line;
  11983. } else {
  11984. if (this.options.ignoreWhitespace) {
  11985. line = line.trim();
  11986. }
  11987. retLines.push(line);
  11988. }
  11989. }
  11990. return retLines;
  11991. };
  11992. function diffLines(oldStr, newStr, callback) {
  11993. return lineDiff.diff(oldStr, newStr, callback);
  11994. }
  11995. function diffTrimmedLines(oldStr, newStr, callback) {
  11996. var options =
  11997. /*istanbul ignore start*/
  11998. (/*istanbul ignore end*/
  11999. /*istanbul ignore start*/
  12000. 0, params
  12001. /*istanbul ignore end*/
  12002. .
  12003. /*istanbul ignore start*/
  12004. generateOptions
  12005. /*istanbul ignore end*/
  12006. )(callback, {
  12007. ignoreWhitespace: true
  12008. });
  12009. return lineDiff.diff(oldStr, newStr, options);
  12010. }
  12011. });
  12012. /*istanbul ignore start*/
  12013. var sentence = createCommonjsModule(function (module, exports) {
  12014. Object.defineProperty(exports, "__esModule", {
  12015. value: true
  12016. });
  12017. exports.diffSentences = diffSentences;
  12018. exports.sentenceDiff = void 0;
  12019. /*istanbul ignore end*/
  12020. var
  12021. /*istanbul ignore start*/
  12022. _base = _interopRequireDefault(base)
  12023. /*istanbul ignore end*/
  12024. ;
  12025. /*istanbul ignore start*/
  12026. function _interopRequireDefault(obj) {
  12027. return obj && obj.__esModule ? obj : {
  12028. "default": obj
  12029. };
  12030. }
  12031. /*istanbul ignore end*/
  12032. var sentenceDiff = new
  12033. /*istanbul ignore start*/
  12034. _base
  12035. /*istanbul ignore end*/
  12036. [
  12037. /*istanbul ignore start*/
  12038. "default"
  12039. /*istanbul ignore end*/
  12040. ]();
  12041. /*istanbul ignore start*/
  12042. exports.sentenceDiff = sentenceDiff;
  12043. /*istanbul ignore end*/
  12044. sentenceDiff.tokenize = function (value) {
  12045. return value.split(/(\S.+?[.!?])(?=\s+|$)/);
  12046. };
  12047. function diffSentences(oldStr, newStr, callback) {
  12048. return sentenceDiff.diff(oldStr, newStr, callback);
  12049. }
  12050. });
  12051. /*istanbul ignore start*/
  12052. var css = createCommonjsModule(function (module, exports) {
  12053. Object.defineProperty(exports, "__esModule", {
  12054. value: true
  12055. });
  12056. exports.diffCss = diffCss;
  12057. exports.cssDiff = void 0;
  12058. /*istanbul ignore end*/
  12059. var
  12060. /*istanbul ignore start*/
  12061. _base = _interopRequireDefault(base)
  12062. /*istanbul ignore end*/
  12063. ;
  12064. /*istanbul ignore start*/
  12065. function _interopRequireDefault(obj) {
  12066. return obj && obj.__esModule ? obj : {
  12067. "default": obj
  12068. };
  12069. }
  12070. /*istanbul ignore end*/
  12071. var cssDiff = new
  12072. /*istanbul ignore start*/
  12073. _base
  12074. /*istanbul ignore end*/
  12075. [
  12076. /*istanbul ignore start*/
  12077. "default"
  12078. /*istanbul ignore end*/
  12079. ]();
  12080. /*istanbul ignore start*/
  12081. exports.cssDiff = cssDiff;
  12082. /*istanbul ignore end*/
  12083. cssDiff.tokenize = function (value) {
  12084. return value.split(/([{}:;,]|\s+)/);
  12085. };
  12086. function diffCss(oldStr, newStr, callback) {
  12087. return cssDiff.diff(oldStr, newStr, callback);
  12088. }
  12089. });
  12090. var json = createCommonjsModule(function (module, exports) {
  12091. Object.defineProperty(exports, "__esModule", {
  12092. value: true
  12093. });
  12094. exports.diffJson = diffJson;
  12095. exports.canonicalize = canonicalize;
  12096. exports.jsonDiff = void 0;
  12097. /*istanbul ignore end*/
  12098. var
  12099. /*istanbul ignore start*/
  12100. _base = _interopRequireDefault(base)
  12101. /*istanbul ignore end*/
  12102. ;
  12103. /*istanbul ignore start*/
  12104. function _interopRequireDefault(obj) {
  12105. return obj && obj.__esModule ? obj : {
  12106. "default": obj
  12107. };
  12108. }
  12109. function _typeof(obj) {
  12110. "@babel/helpers - typeof";
  12111. if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") {
  12112. _typeof = function _typeof(obj) {
  12113. return typeof obj;
  12114. };
  12115. } else {
  12116. _typeof = function _typeof(obj) {
  12117. return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj;
  12118. };
  12119. }
  12120. return _typeof(obj);
  12121. }
  12122. /*istanbul ignore end*/
  12123. var objectPrototypeToString = Object.prototype.toString;
  12124. var jsonDiff = new
  12125. /*istanbul ignore start*/
  12126. _base
  12127. /*istanbul ignore end*/
  12128. [
  12129. /*istanbul ignore start*/
  12130. "default"
  12131. /*istanbul ignore end*/
  12132. ](); // Discriminate between two lines of pretty-printed, serialized JSON where one of them has a
  12133. // dangling comma and the other doesn't. Turns out including the dangling comma yields the nicest output:
  12134. /*istanbul ignore start*/
  12135. exports.jsonDiff = jsonDiff;
  12136. /*istanbul ignore end*/
  12137. jsonDiff.useLongestToken = true;
  12138. jsonDiff.tokenize =
  12139. /*istanbul ignore start*/
  12140. line
  12141. /*istanbul ignore end*/
  12142. .
  12143. /*istanbul ignore start*/
  12144. lineDiff
  12145. /*istanbul ignore end*/
  12146. .tokenize;
  12147. jsonDiff.castInput = function (value) {
  12148. /*istanbul ignore start*/
  12149. var _this$options =
  12150. /*istanbul ignore end*/
  12151. this.options,
  12152. undefinedReplacement = _this$options.undefinedReplacement,
  12153. _this$options$stringi = _this$options.stringifyReplacer,
  12154. stringifyReplacer = _this$options$stringi === void 0 ? function (k, v)
  12155. /*istanbul ignore start*/
  12156. {
  12157. return (
  12158. /*istanbul ignore end*/
  12159. typeof v === 'undefined' ? undefinedReplacement : v
  12160. );
  12161. } : _this$options$stringi;
  12162. return typeof value === 'string' ? value : JSON.stringify(canonicalize(value, null, null, stringifyReplacer), stringifyReplacer, ' ');
  12163. };
  12164. jsonDiff.equals = function (left, right) {
  12165. return (
  12166. /*istanbul ignore start*/
  12167. _base
  12168. /*istanbul ignore end*/
  12169. [
  12170. /*istanbul ignore start*/
  12171. "default"
  12172. /*istanbul ignore end*/
  12173. ].prototype.equals.call(jsonDiff, left.replace(/,([\r\n])/g, '$1'), right.replace(/,([\r\n])/g, '$1'))
  12174. );
  12175. };
  12176. function diffJson(oldObj, newObj, options) {
  12177. return jsonDiff.diff(oldObj, newObj, options);
  12178. } // This function handles the presence of circular references by bailing out when encountering an
  12179. // object that is already on the "stack" of items being processed. Accepts an optional replacer
  12180. function canonicalize(obj, stack, replacementStack, replacer, key) {
  12181. stack = stack || [];
  12182. replacementStack = replacementStack || [];
  12183. if (replacer) {
  12184. obj = replacer(key, obj);
  12185. }
  12186. var i;
  12187. for (i = 0; i < stack.length; i += 1) {
  12188. if (stack[i] === obj) {
  12189. return replacementStack[i];
  12190. }
  12191. }
  12192. var canonicalizedObj;
  12193. if ('[object Array]' === objectPrototypeToString.call(obj)) {
  12194. stack.push(obj);
  12195. canonicalizedObj = new Array(obj.length);
  12196. replacementStack.push(canonicalizedObj);
  12197. for (i = 0; i < obj.length; i += 1) {
  12198. canonicalizedObj[i] = canonicalize(obj[i], stack, replacementStack, replacer, key);
  12199. }
  12200. stack.pop();
  12201. replacementStack.pop();
  12202. return canonicalizedObj;
  12203. }
  12204. if (obj && obj.toJSON) {
  12205. obj = obj.toJSON();
  12206. }
  12207. if (
  12208. /*istanbul ignore start*/
  12209. _typeof(
  12210. /*istanbul ignore end*/
  12211. obj) === 'object' && obj !== null) {
  12212. stack.push(obj);
  12213. canonicalizedObj = {};
  12214. replacementStack.push(canonicalizedObj);
  12215. var sortedKeys = [],
  12216. _key;
  12217. for (_key in obj) {
  12218. /* istanbul ignore else */
  12219. if (obj.hasOwnProperty(_key)) {
  12220. sortedKeys.push(_key);
  12221. }
  12222. }
  12223. sortedKeys.sort();
  12224. for (i = 0; i < sortedKeys.length; i += 1) {
  12225. _key = sortedKeys[i];
  12226. canonicalizedObj[_key] = canonicalize(obj[_key], stack, replacementStack, replacer, _key);
  12227. }
  12228. stack.pop();
  12229. replacementStack.pop();
  12230. } else {
  12231. canonicalizedObj = obj;
  12232. }
  12233. return canonicalizedObj;
  12234. }
  12235. });
  12236. /*istanbul ignore start*/
  12237. var array$1 = createCommonjsModule(function (module, exports) {
  12238. Object.defineProperty(exports, "__esModule", {
  12239. value: true
  12240. });
  12241. exports.diffArrays = diffArrays;
  12242. exports.arrayDiff = void 0;
  12243. /*istanbul ignore end*/
  12244. var
  12245. /*istanbul ignore start*/
  12246. _base = _interopRequireDefault(base)
  12247. /*istanbul ignore end*/
  12248. ;
  12249. /*istanbul ignore start*/
  12250. function _interopRequireDefault(obj) {
  12251. return obj && obj.__esModule ? obj : {
  12252. "default": obj
  12253. };
  12254. }
  12255. /*istanbul ignore end*/
  12256. var arrayDiff = new
  12257. /*istanbul ignore start*/
  12258. _base
  12259. /*istanbul ignore end*/
  12260. [
  12261. /*istanbul ignore start*/
  12262. "default"
  12263. /*istanbul ignore end*/
  12264. ]();
  12265. /*istanbul ignore start*/
  12266. exports.arrayDiff = arrayDiff;
  12267. /*istanbul ignore end*/
  12268. arrayDiff.tokenize = function (value) {
  12269. return value.slice();
  12270. };
  12271. arrayDiff.join = arrayDiff.removeEmpty = function (value) {
  12272. return value;
  12273. };
  12274. function diffArrays(oldArr, newArr, callback) {
  12275. return arrayDiff.diff(oldArr, newArr, callback);
  12276. }
  12277. });
  12278. /*istanbul ignore start*/
  12279. var parsePatch_1 = parsePatch;
  12280. /*istanbul ignore end*/
  12281. function parsePatch(uniDiff) {
  12282. /*istanbul ignore start*/
  12283. var
  12284. /*istanbul ignore end*/
  12285. options = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {};
  12286. var diffstr = uniDiff.split(/\r\n|[\n\v\f\r\x85]/),
  12287. delimiters = uniDiff.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  12288. list = [],
  12289. i = 0;
  12290. function parseIndex() {
  12291. var index = {};
  12292. list.push(index); // Parse diff metadata
  12293. while (i < diffstr.length) {
  12294. var line = diffstr[i]; // File header found, end parsing diff metadata
  12295. if (/^(\-\-\-|\+\+\+|@@)\s/.test(line)) {
  12296. break;
  12297. } // Diff index
  12298. var header = /^(?:Index:|diff(?: -r \w+)+)\s+(.+?)\s*$/.exec(line);
  12299. if (header) {
  12300. index.index = header[1];
  12301. }
  12302. i++;
  12303. } // Parse file headers if they are defined. Unified diff requires them, but
  12304. // there's no technical issues to have an isolated hunk without file header
  12305. parseFileHeader(index);
  12306. parseFileHeader(index); // Parse hunks
  12307. index.hunks = [];
  12308. while (i < diffstr.length) {
  12309. var _line = diffstr[i];
  12310. if (/^(Index:|diff|\-\-\-|\+\+\+)\s/.test(_line)) {
  12311. break;
  12312. } else if (/^@@/.test(_line)) {
  12313. index.hunks.push(parseHunk());
  12314. } else if (_line && options.strict) {
  12315. // Ignore unexpected content unless in strict mode
  12316. throw new Error('Unknown line ' + (i + 1) + ' ' + JSON.stringify(_line));
  12317. } else {
  12318. i++;
  12319. }
  12320. }
  12321. } // Parses the --- and +++ headers, if none are found, no lines
  12322. // are consumed.
  12323. function parseFileHeader(index) {
  12324. var fileHeader = /^(---|\+\+\+)\s+(.*)$/.exec(diffstr[i]);
  12325. if (fileHeader) {
  12326. var keyPrefix = fileHeader[1] === '---' ? 'old' : 'new';
  12327. var data = fileHeader[2].split('\t', 2);
  12328. var fileName = data[0].replace(/\\\\/g, '\\');
  12329. if (/^".*"$/.test(fileName)) {
  12330. fileName = fileName.substr(1, fileName.length - 2);
  12331. }
  12332. index[keyPrefix + 'FileName'] = fileName;
  12333. index[keyPrefix + 'Header'] = (data[1] || '').trim();
  12334. i++;
  12335. }
  12336. } // Parses a hunk
  12337. // This assumes that we are at the start of a hunk.
  12338. function parseHunk() {
  12339. var chunkHeaderIndex = i,
  12340. chunkHeaderLine = diffstr[i++],
  12341. chunkHeader = chunkHeaderLine.split(/@@ -(\d+)(?:,(\d+))? \+(\d+)(?:,(\d+))? @@/);
  12342. var hunk = {
  12343. oldStart: +chunkHeader[1],
  12344. oldLines: typeof chunkHeader[2] === 'undefined' ? 1 : +chunkHeader[2],
  12345. newStart: +chunkHeader[3],
  12346. newLines: typeof chunkHeader[4] === 'undefined' ? 1 : +chunkHeader[4],
  12347. lines: [],
  12348. linedelimiters: []
  12349. }; // Unified Diff Format quirk: If the chunk size is 0,
  12350. // the first number is one lower than one would expect.
  12351. // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
  12352. if (hunk.oldLines === 0) {
  12353. hunk.oldStart += 1;
  12354. }
  12355. if (hunk.newLines === 0) {
  12356. hunk.newStart += 1;
  12357. }
  12358. var addCount = 0,
  12359. removeCount = 0;
  12360. for (; i < diffstr.length; i++) {
  12361. // Lines starting with '---' could be mistaken for the "remove line" operation
  12362. // But they could be the header for the next file. Therefore prune such cases out.
  12363. if (diffstr[i].indexOf('--- ') === 0 && i + 2 < diffstr.length && diffstr[i + 1].indexOf('+++ ') === 0 && diffstr[i + 2].indexOf('@@') === 0) {
  12364. break;
  12365. }
  12366. var operation = diffstr[i].length == 0 && i != diffstr.length - 1 ? ' ' : diffstr[i][0];
  12367. if (operation === '+' || operation === '-' || operation === ' ' || operation === '\\') {
  12368. hunk.lines.push(diffstr[i]);
  12369. hunk.linedelimiters.push(delimiters[i] || '\n');
  12370. if (operation === '+') {
  12371. addCount++;
  12372. } else if (operation === '-') {
  12373. removeCount++;
  12374. } else if (operation === ' ') {
  12375. addCount++;
  12376. removeCount++;
  12377. }
  12378. } else {
  12379. break;
  12380. }
  12381. } // Handle the empty block count case
  12382. if (!addCount && hunk.newLines === 1) {
  12383. hunk.newLines = 0;
  12384. }
  12385. if (!removeCount && hunk.oldLines === 1) {
  12386. hunk.oldLines = 0;
  12387. } // Perform optional sanity checking
  12388. if (options.strict) {
  12389. if (addCount !== hunk.newLines) {
  12390. throw new Error('Added line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  12391. }
  12392. if (removeCount !== hunk.oldLines) {
  12393. throw new Error('Removed line count did not match for hunk at line ' + (chunkHeaderIndex + 1));
  12394. }
  12395. }
  12396. return hunk;
  12397. }
  12398. while (i < diffstr.length) {
  12399. parseIndex();
  12400. }
  12401. return list;
  12402. }
  12403. var parse = /*#__PURE__*/Object.defineProperty({
  12404. parsePatch: parsePatch_1
  12405. }, '__esModule', {
  12406. value: true
  12407. });
  12408. /*istanbul ignore start*/
  12409. var distanceIterator = createCommonjsModule(function (module, exports) {
  12410. Object.defineProperty(exports, "__esModule", {
  12411. value: true
  12412. });
  12413. exports["default"] = _default;
  12414. /*istanbul ignore end*/
  12415. // Iterator that traverses in the range of [min, max], stepping
  12416. // by distance from a given start position. I.e. for [0, 4], with
  12417. // start of 2, this will iterate 2, 3, 1, 4, 0.
  12418. function
  12419. /*istanbul ignore start*/
  12420. _default
  12421. /*istanbul ignore end*/
  12422. (start, minLine, maxLine) {
  12423. var wantForward = true,
  12424. backwardExhausted = false,
  12425. forwardExhausted = false,
  12426. localOffset = 1;
  12427. return function iterator() {
  12428. if (wantForward && !forwardExhausted) {
  12429. if (backwardExhausted) {
  12430. localOffset++;
  12431. } else {
  12432. wantForward = false;
  12433. } // Check if trying to fit beyond text length, and if not, check it fits
  12434. // after offset location (or desired location on first iteration)
  12435. if (start + localOffset <= maxLine) {
  12436. return localOffset;
  12437. }
  12438. forwardExhausted = true;
  12439. }
  12440. if (!backwardExhausted) {
  12441. if (!forwardExhausted) {
  12442. wantForward = true;
  12443. } // Check if trying to fit before text beginning, and if not, check it fits
  12444. // before offset location
  12445. if (minLine <= start - localOffset) {
  12446. return -localOffset++;
  12447. }
  12448. backwardExhausted = true;
  12449. return iterator();
  12450. } // We tried to fit hunk before text beginning and beyond text length, then
  12451. // hunk can't fit on the text. Return undefined
  12452. };
  12453. }
  12454. });
  12455. /*istanbul ignore start*/
  12456. var applyPatch_1 = applyPatch;
  12457. var applyPatches_1 = applyPatches;
  12458. /*istanbul ignore end*/
  12459. var
  12460. /*istanbul ignore start*/
  12461. _distanceIterator = _interopRequireDefault(distanceIterator)
  12462. /*istanbul ignore end*/
  12463. ;
  12464. /*istanbul ignore start*/
  12465. function _interopRequireDefault(obj) {
  12466. return obj && obj.__esModule ? obj : {
  12467. "default": obj
  12468. };
  12469. }
  12470. /*istanbul ignore end*/
  12471. function applyPatch(source, uniDiff) {
  12472. /*istanbul ignore start*/
  12473. var
  12474. /*istanbul ignore end*/
  12475. options = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
  12476. if (typeof uniDiff === 'string') {
  12477. uniDiff =
  12478. /*istanbul ignore start*/
  12479. (/*istanbul ignore end*/
  12480. /*istanbul ignore start*/
  12481. 0, parse
  12482. /*istanbul ignore end*/
  12483. .
  12484. /*istanbul ignore start*/
  12485. parsePatch
  12486. /*istanbul ignore end*/
  12487. )(uniDiff);
  12488. }
  12489. if (Array.isArray(uniDiff)) {
  12490. if (uniDiff.length > 1) {
  12491. throw new Error('applyPatch only works with a single input.');
  12492. }
  12493. uniDiff = uniDiff[0];
  12494. } // Apply the diff to the input
  12495. var lines = source.split(/\r\n|[\n\v\f\r\x85]/),
  12496. delimiters = source.match(/\r\n|[\n\v\f\r\x85]/g) || [],
  12497. hunks = uniDiff.hunks,
  12498. compareLine = options.compareLine || function (lineNumber, line, operation, patchContent)
  12499. /*istanbul ignore start*/
  12500. {
  12501. return (
  12502. /*istanbul ignore end*/
  12503. line === patchContent
  12504. );
  12505. },
  12506. errorCount = 0,
  12507. fuzzFactor = options.fuzzFactor || 0,
  12508. minLine = 0,
  12509. offset = 0,
  12510. removeEOFNL,
  12511. addEOFNL;
  12512. /**
  12513. * Checks if the hunk exactly fits on the provided location
  12514. */
  12515. function hunkFits(hunk, toPos) {
  12516. for (var j = 0; j < hunk.lines.length; j++) {
  12517. var line = hunk.lines[j],
  12518. operation = line.length > 0 ? line[0] : ' ',
  12519. content = line.length > 0 ? line.substr(1) : line;
  12520. if (operation === ' ' || operation === '-') {
  12521. // Context sanity check
  12522. if (!compareLine(toPos + 1, lines[toPos], operation, content)) {
  12523. errorCount++;
  12524. if (errorCount > fuzzFactor) {
  12525. return false;
  12526. }
  12527. }
  12528. toPos++;
  12529. }
  12530. }
  12531. return true;
  12532. } // Search best fit offsets for each hunk based on the previous ones
  12533. for (var i = 0; i < hunks.length; i++) {
  12534. var hunk = hunks[i],
  12535. maxLine = lines.length - hunk.oldLines,
  12536. localOffset = 0,
  12537. toPos = offset + hunk.oldStart - 1;
  12538. var iterator =
  12539. /*istanbul ignore start*/
  12540. (/*istanbul ignore end*/
  12541. /*istanbul ignore start*/
  12542. 0, _distanceIterator
  12543. /*istanbul ignore end*/
  12544. [
  12545. /*istanbul ignore start*/
  12546. "default"
  12547. /*istanbul ignore end*/
  12548. ])(toPos, minLine, maxLine);
  12549. for (; localOffset !== undefined; localOffset = iterator()) {
  12550. if (hunkFits(hunk, toPos + localOffset)) {
  12551. hunk.offset = offset += localOffset;
  12552. break;
  12553. }
  12554. }
  12555. if (localOffset === undefined) {
  12556. return false;
  12557. } // Set lower text limit to end of the current hunk, so next ones don't try
  12558. // to fit over already patched text
  12559. minLine = hunk.offset + hunk.oldStart + hunk.oldLines;
  12560. } // Apply patch hunks
  12561. var diffOffset = 0;
  12562. for (var _i = 0; _i < hunks.length; _i++) {
  12563. var _hunk = hunks[_i],
  12564. _toPos = _hunk.oldStart + _hunk.offset + diffOffset - 1;
  12565. diffOffset += _hunk.newLines - _hunk.oldLines;
  12566. for (var j = 0; j < _hunk.lines.length; j++) {
  12567. var line = _hunk.lines[j],
  12568. operation = line.length > 0 ? line[0] : ' ',
  12569. content = line.length > 0 ? line.substr(1) : line,
  12570. delimiter = _hunk.linedelimiters[j];
  12571. if (operation === ' ') {
  12572. _toPos++;
  12573. } else if (operation === '-') {
  12574. lines.splice(_toPos, 1);
  12575. delimiters.splice(_toPos, 1);
  12576. /* istanbul ignore else */
  12577. } else if (operation === '+') {
  12578. lines.splice(_toPos, 0, content);
  12579. delimiters.splice(_toPos, 0, delimiter);
  12580. _toPos++;
  12581. } else if (operation === '\\') {
  12582. var previousOperation = _hunk.lines[j - 1] ? _hunk.lines[j - 1][0] : null;
  12583. if (previousOperation === '+') {
  12584. removeEOFNL = true;
  12585. } else if (previousOperation === '-') {
  12586. addEOFNL = true;
  12587. }
  12588. }
  12589. }
  12590. } // Handle EOFNL insertion/removal
  12591. if (removeEOFNL) {
  12592. while (!lines[lines.length - 1]) {
  12593. lines.pop();
  12594. delimiters.pop();
  12595. }
  12596. } else if (addEOFNL) {
  12597. lines.push('');
  12598. delimiters.push('\n');
  12599. }
  12600. for (var _k = 0; _k < lines.length - 1; _k++) {
  12601. lines[_k] = lines[_k] + delimiters[_k];
  12602. }
  12603. return lines.join('');
  12604. } // Wrapper that supports multiple file patches via callbacks.
  12605. function applyPatches(uniDiff, options) {
  12606. if (typeof uniDiff === 'string') {
  12607. uniDiff =
  12608. /*istanbul ignore start*/
  12609. (/*istanbul ignore end*/
  12610. /*istanbul ignore start*/
  12611. 0, parse
  12612. /*istanbul ignore end*/
  12613. .
  12614. /*istanbul ignore start*/
  12615. parsePatch
  12616. /*istanbul ignore end*/
  12617. )(uniDiff);
  12618. }
  12619. var currentIndex = 0;
  12620. function processIndex() {
  12621. var index = uniDiff[currentIndex++];
  12622. if (!index) {
  12623. return options.complete();
  12624. }
  12625. options.loadFile(index, function (err, data) {
  12626. if (err) {
  12627. return options.complete(err);
  12628. }
  12629. var updatedContent = applyPatch(data, index, options);
  12630. options.patched(index, updatedContent, function (err) {
  12631. if (err) {
  12632. return options.complete(err);
  12633. }
  12634. processIndex();
  12635. });
  12636. });
  12637. }
  12638. processIndex();
  12639. }
  12640. var apply$1 = /*#__PURE__*/Object.defineProperty({
  12641. applyPatch: applyPatch_1,
  12642. applyPatches: applyPatches_1
  12643. }, '__esModule', {
  12644. value: true
  12645. });
  12646. /*istanbul ignore start*/
  12647. var structuredPatch_1 = structuredPatch;
  12648. var formatPatch_1 = formatPatch;
  12649. var createTwoFilesPatch_1 = createTwoFilesPatch;
  12650. var createPatch_1 = createPatch;
  12651. /*istanbul ignore end*/
  12652. /*istanbul ignore start*/
  12653. function _toConsumableArray$1(arr) {
  12654. return _arrayWithoutHoles$1(arr) || _iterableToArray$1(arr) || _unsupportedIterableToArray$1(arr) || _nonIterableSpread$1();
  12655. }
  12656. function _nonIterableSpread$1() {
  12657. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  12658. }
  12659. function _unsupportedIterableToArray$1(o, minLen) {
  12660. if (!o) return;
  12661. if (typeof o === "string") return _arrayLikeToArray$1(o, minLen);
  12662. var n = Object.prototype.toString.call(o).slice(8, -1);
  12663. if (n === "Object" && o.constructor) n = o.constructor.name;
  12664. if (n === "Map" || n === "Set") return Array.from(o);
  12665. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray$1(o, minLen);
  12666. }
  12667. function _iterableToArray$1(iter) {
  12668. if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
  12669. }
  12670. function _arrayWithoutHoles$1(arr) {
  12671. if (Array.isArray(arr)) return _arrayLikeToArray$1(arr);
  12672. }
  12673. function _arrayLikeToArray$1(arr, len) {
  12674. if (len == null || len > arr.length) len = arr.length;
  12675. for (var i = 0, arr2 = new Array(len); i < len; i++) {
  12676. arr2[i] = arr[i];
  12677. }
  12678. return arr2;
  12679. }
  12680. /*istanbul ignore end*/
  12681. function structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  12682. if (!options) {
  12683. options = {};
  12684. }
  12685. if (typeof options.context === 'undefined') {
  12686. options.context = 4;
  12687. }
  12688. var diff =
  12689. /*istanbul ignore start*/
  12690. (/*istanbul ignore end*/
  12691. /*istanbul ignore start*/
  12692. 0, line
  12693. /*istanbul ignore end*/
  12694. .
  12695. /*istanbul ignore start*/
  12696. diffLines
  12697. /*istanbul ignore end*/
  12698. )(oldStr, newStr, options);
  12699. diff.push({
  12700. value: '',
  12701. lines: []
  12702. }); // Append an empty value to make cleanup easier
  12703. function contextLines(lines) {
  12704. return lines.map(function (entry) {
  12705. return ' ' + entry;
  12706. });
  12707. }
  12708. var hunks = [];
  12709. var oldRangeStart = 0,
  12710. newRangeStart = 0,
  12711. curRange = [],
  12712. oldLine = 1,
  12713. newLine = 1;
  12714. /*istanbul ignore start*/
  12715. var _loop = function _loop(
  12716. /*istanbul ignore end*/
  12717. i) {
  12718. var current = diff[i],
  12719. lines = current.lines || current.value.replace(/\n$/, '').split('\n');
  12720. current.lines = lines;
  12721. if (current.added || current.removed) {
  12722. /*istanbul ignore start*/
  12723. var _curRange;
  12724. /*istanbul ignore end*/
  12725. // If we have previous context, start with that
  12726. if (!oldRangeStart) {
  12727. var prev = diff[i - 1];
  12728. oldRangeStart = oldLine;
  12729. newRangeStart = newLine;
  12730. if (prev) {
  12731. curRange = options.context > 0 ? contextLines(prev.lines.slice(-options.context)) : [];
  12732. oldRangeStart -= curRange.length;
  12733. newRangeStart -= curRange.length;
  12734. }
  12735. } // Output our changes
  12736. /*istanbul ignore start*/
  12737. /*istanbul ignore end*/
  12738. /*istanbul ignore start*/
  12739. (_curRange =
  12740. /*istanbul ignore end*/
  12741. curRange).push.apply(
  12742. /*istanbul ignore start*/
  12743. _curRange
  12744. /*istanbul ignore end*/
  12745. ,
  12746. /*istanbul ignore start*/
  12747. _toConsumableArray$1(
  12748. /*istanbul ignore end*/
  12749. lines.map(function (entry) {
  12750. return (current.added ? '+' : '-') + entry;
  12751. }))); // Track the updated file position
  12752. if (current.added) {
  12753. newLine += lines.length;
  12754. } else {
  12755. oldLine += lines.length;
  12756. }
  12757. } else {
  12758. // Identical context lines. Track line changes
  12759. if (oldRangeStart) {
  12760. // Close out any changes that have been output (or join overlapping)
  12761. if (lines.length <= options.context * 2 && i < diff.length - 2) {
  12762. /*istanbul ignore start*/
  12763. var _curRange2;
  12764. /*istanbul ignore end*/
  12765. // Overlapping
  12766. /*istanbul ignore start*/
  12767. /*istanbul ignore end*/
  12768. /*istanbul ignore start*/
  12769. (_curRange2 =
  12770. /*istanbul ignore end*/
  12771. curRange).push.apply(
  12772. /*istanbul ignore start*/
  12773. _curRange2
  12774. /*istanbul ignore end*/
  12775. ,
  12776. /*istanbul ignore start*/
  12777. _toConsumableArray$1(
  12778. /*istanbul ignore end*/
  12779. contextLines(lines)));
  12780. } else {
  12781. /*istanbul ignore start*/
  12782. var _curRange3;
  12783. /*istanbul ignore end*/
  12784. // end the range and output
  12785. var contextSize = Math.min(lines.length, options.context);
  12786. /*istanbul ignore start*/
  12787. /*istanbul ignore end*/
  12788. /*istanbul ignore start*/
  12789. (_curRange3 =
  12790. /*istanbul ignore end*/
  12791. curRange).push.apply(
  12792. /*istanbul ignore start*/
  12793. _curRange3
  12794. /*istanbul ignore end*/
  12795. ,
  12796. /*istanbul ignore start*/
  12797. _toConsumableArray$1(
  12798. /*istanbul ignore end*/
  12799. contextLines(lines.slice(0, contextSize))));
  12800. var hunk = {
  12801. oldStart: oldRangeStart,
  12802. oldLines: oldLine - oldRangeStart + contextSize,
  12803. newStart: newRangeStart,
  12804. newLines: newLine - newRangeStart + contextSize,
  12805. lines: curRange
  12806. };
  12807. if (i >= diff.length - 2 && lines.length <= options.context) {
  12808. // EOF is inside this hunk
  12809. var oldEOFNewline = /\n$/.test(oldStr);
  12810. var newEOFNewline = /\n$/.test(newStr);
  12811. var noNlBeforeAdds = lines.length == 0 && curRange.length > hunk.oldLines;
  12812. if (!oldEOFNewline && noNlBeforeAdds && oldStr.length > 0) {
  12813. // special case: old has no eol and no trailing context; no-nl can end up before adds
  12814. // however, if the old file is empty, do not output the no-nl line
  12815. curRange.splice(hunk.oldLines, 0, '\\ No newline at end of file');
  12816. }
  12817. if (!oldEOFNewline && !noNlBeforeAdds || !newEOFNewline) {
  12818. curRange.push('\\ No newline at end of file');
  12819. }
  12820. }
  12821. hunks.push(hunk);
  12822. oldRangeStart = 0;
  12823. newRangeStart = 0;
  12824. curRange = [];
  12825. }
  12826. }
  12827. oldLine += lines.length;
  12828. newLine += lines.length;
  12829. }
  12830. };
  12831. for (var i = 0; i < diff.length; i++) {
  12832. /*istanbul ignore start*/
  12833. _loop(
  12834. /*istanbul ignore end*/
  12835. i);
  12836. }
  12837. return {
  12838. oldFileName: oldFileName,
  12839. newFileName: newFileName,
  12840. oldHeader: oldHeader,
  12841. newHeader: newHeader,
  12842. hunks: hunks
  12843. };
  12844. }
  12845. function formatPatch(diff) {
  12846. var ret = [];
  12847. if (diff.oldFileName == diff.newFileName) {
  12848. ret.push('Index: ' + diff.oldFileName);
  12849. }
  12850. ret.push('===================================================================');
  12851. ret.push('--- ' + diff.oldFileName + (typeof diff.oldHeader === 'undefined' ? '' : '\t' + diff.oldHeader));
  12852. ret.push('+++ ' + diff.newFileName + (typeof diff.newHeader === 'undefined' ? '' : '\t' + diff.newHeader));
  12853. for (var i = 0; i < diff.hunks.length; i++) {
  12854. var hunk = diff.hunks[i]; // Unified Diff Format quirk: If the chunk size is 0,
  12855. // the first number is one lower than one would expect.
  12856. // https://www.artima.com/weblogs/viewpost.jsp?thread=164293
  12857. if (hunk.oldLines === 0) {
  12858. hunk.oldStart -= 1;
  12859. }
  12860. if (hunk.newLines === 0) {
  12861. hunk.newStart -= 1;
  12862. }
  12863. ret.push('@@ -' + hunk.oldStart + ',' + hunk.oldLines + ' +' + hunk.newStart + ',' + hunk.newLines + ' @@');
  12864. ret.push.apply(ret, hunk.lines);
  12865. }
  12866. return ret.join('\n') + '\n';
  12867. }
  12868. function createTwoFilesPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options) {
  12869. return formatPatch(structuredPatch(oldFileName, newFileName, oldStr, newStr, oldHeader, newHeader, options));
  12870. }
  12871. function createPatch(fileName, oldStr, newStr, oldHeader, newHeader, options) {
  12872. return createTwoFilesPatch(fileName, fileName, oldStr, newStr, oldHeader, newHeader, options);
  12873. }
  12874. var create = /*#__PURE__*/Object.defineProperty({
  12875. structuredPatch: structuredPatch_1,
  12876. formatPatch: formatPatch_1,
  12877. createTwoFilesPatch: createTwoFilesPatch_1,
  12878. createPatch: createPatch_1
  12879. }, '__esModule', {
  12880. value: true
  12881. });
  12882. /*istanbul ignore start*/
  12883. var arrayEqual_1 = arrayEqual;
  12884. var arrayStartsWith_1 = arrayStartsWith;
  12885. /*istanbul ignore end*/
  12886. function arrayEqual(a, b) {
  12887. if (a.length !== b.length) {
  12888. return false;
  12889. }
  12890. return arrayStartsWith(a, b);
  12891. }
  12892. function arrayStartsWith(array, start) {
  12893. if (start.length > array.length) {
  12894. return false;
  12895. }
  12896. for (var i = 0; i < start.length; i++) {
  12897. if (start[i] !== array[i]) {
  12898. return false;
  12899. }
  12900. }
  12901. return true;
  12902. }
  12903. var array = /*#__PURE__*/Object.defineProperty({
  12904. arrayEqual: arrayEqual_1,
  12905. arrayStartsWith: arrayStartsWith_1
  12906. }, '__esModule', {
  12907. value: true
  12908. });
  12909. /*istanbul ignore start*/
  12910. var calcLineCount_1 = calcLineCount;
  12911. var merge_2 = merge;
  12912. /*istanbul ignore end*/
  12913. /*istanbul ignore start*/
  12914. function _toConsumableArray(arr) {
  12915. return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread();
  12916. }
  12917. function _nonIterableSpread() {
  12918. throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
  12919. }
  12920. function _unsupportedIterableToArray(o, minLen) {
  12921. if (!o) return;
  12922. if (typeof o === "string") return _arrayLikeToArray(o, minLen);
  12923. var n = Object.prototype.toString.call(o).slice(8, -1);
  12924. if (n === "Object" && o.constructor) n = o.constructor.name;
  12925. if (n === "Map" || n === "Set") return Array.from(o);
  12926. if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
  12927. }
  12928. function _iterableToArray(iter) {
  12929. if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter);
  12930. }
  12931. function _arrayWithoutHoles(arr) {
  12932. if (Array.isArray(arr)) return _arrayLikeToArray(arr);
  12933. }
  12934. function _arrayLikeToArray(arr, len) {
  12935. if (len == null || len > arr.length) len = arr.length;
  12936. for (var i = 0, arr2 = new Array(len); i < len; i++) {
  12937. arr2[i] = arr[i];
  12938. }
  12939. return arr2;
  12940. }
  12941. /*istanbul ignore end*/
  12942. function calcLineCount(hunk) {
  12943. /*istanbul ignore start*/
  12944. var _calcOldNewLineCount =
  12945. /*istanbul ignore end*/
  12946. calcOldNewLineCount(hunk.lines),
  12947. oldLines = _calcOldNewLineCount.oldLines,
  12948. newLines = _calcOldNewLineCount.newLines;
  12949. if (oldLines !== undefined) {
  12950. hunk.oldLines = oldLines;
  12951. } else {
  12952. delete hunk.oldLines;
  12953. }
  12954. if (newLines !== undefined) {
  12955. hunk.newLines = newLines;
  12956. } else {
  12957. delete hunk.newLines;
  12958. }
  12959. }
  12960. function merge(mine, theirs, base) {
  12961. mine = loadPatch(mine, base);
  12962. theirs = loadPatch(theirs, base);
  12963. var ret = {}; // For index we just let it pass through as it doesn't have any necessary meaning.
  12964. // Leaving sanity checks on this to the API consumer that may know more about the
  12965. // meaning in their own context.
  12966. if (mine.index || theirs.index) {
  12967. ret.index = mine.index || theirs.index;
  12968. }
  12969. if (mine.newFileName || theirs.newFileName) {
  12970. if (!fileNameChanged(mine)) {
  12971. // No header or no change in ours, use theirs (and ours if theirs does not exist)
  12972. ret.oldFileName = theirs.oldFileName || mine.oldFileName;
  12973. ret.newFileName = theirs.newFileName || mine.newFileName;
  12974. ret.oldHeader = theirs.oldHeader || mine.oldHeader;
  12975. ret.newHeader = theirs.newHeader || mine.newHeader;
  12976. } else if (!fileNameChanged(theirs)) {
  12977. // No header or no change in theirs, use ours
  12978. ret.oldFileName = mine.oldFileName;
  12979. ret.newFileName = mine.newFileName;
  12980. ret.oldHeader = mine.oldHeader;
  12981. ret.newHeader = mine.newHeader;
  12982. } else {
  12983. // Both changed... figure it out
  12984. ret.oldFileName = selectField(ret, mine.oldFileName, theirs.oldFileName);
  12985. ret.newFileName = selectField(ret, mine.newFileName, theirs.newFileName);
  12986. ret.oldHeader = selectField(ret, mine.oldHeader, theirs.oldHeader);
  12987. ret.newHeader = selectField(ret, mine.newHeader, theirs.newHeader);
  12988. }
  12989. }
  12990. ret.hunks = [];
  12991. var mineIndex = 0,
  12992. theirsIndex = 0,
  12993. mineOffset = 0,
  12994. theirsOffset = 0;
  12995. while (mineIndex < mine.hunks.length || theirsIndex < theirs.hunks.length) {
  12996. var mineCurrent = mine.hunks[mineIndex] || {
  12997. oldStart: Infinity
  12998. },
  12999. theirsCurrent = theirs.hunks[theirsIndex] || {
  13000. oldStart: Infinity
  13001. };
  13002. if (hunkBefore(mineCurrent, theirsCurrent)) {
  13003. // This patch does not overlap with any of the others, yay.
  13004. ret.hunks.push(cloneHunk(mineCurrent, mineOffset));
  13005. mineIndex++;
  13006. theirsOffset += mineCurrent.newLines - mineCurrent.oldLines;
  13007. } else if (hunkBefore(theirsCurrent, mineCurrent)) {
  13008. // This patch does not overlap with any of the others, yay.
  13009. ret.hunks.push(cloneHunk(theirsCurrent, theirsOffset));
  13010. theirsIndex++;
  13011. mineOffset += theirsCurrent.newLines - theirsCurrent.oldLines;
  13012. } else {
  13013. // Overlap, merge as best we can
  13014. var mergedHunk = {
  13015. oldStart: Math.min(mineCurrent.oldStart, theirsCurrent.oldStart),
  13016. oldLines: 0,
  13017. newStart: Math.min(mineCurrent.newStart + mineOffset, theirsCurrent.oldStart + theirsOffset),
  13018. newLines: 0,
  13019. lines: []
  13020. };
  13021. mergeLines(mergedHunk, mineCurrent.oldStart, mineCurrent.lines, theirsCurrent.oldStart, theirsCurrent.lines);
  13022. theirsIndex++;
  13023. mineIndex++;
  13024. ret.hunks.push(mergedHunk);
  13025. }
  13026. }
  13027. return ret;
  13028. }
  13029. function loadPatch(param, base) {
  13030. if (typeof param === 'string') {
  13031. if (/^@@/m.test(param) || /^Index:/m.test(param)) {
  13032. return (
  13033. /*istanbul ignore start*/
  13034. (/*istanbul ignore end*/
  13035. /*istanbul ignore start*/
  13036. 0, parse
  13037. /*istanbul ignore end*/
  13038. .
  13039. /*istanbul ignore start*/
  13040. parsePatch
  13041. /*istanbul ignore end*/
  13042. )(param)[0]
  13043. );
  13044. }
  13045. if (!base) {
  13046. throw new Error('Must provide a base reference or pass in a patch');
  13047. }
  13048. return (
  13049. /*istanbul ignore start*/
  13050. (/*istanbul ignore end*/
  13051. /*istanbul ignore start*/
  13052. 0, create
  13053. /*istanbul ignore end*/
  13054. .
  13055. /*istanbul ignore start*/
  13056. structuredPatch
  13057. /*istanbul ignore end*/
  13058. )(undefined, undefined, base, param)
  13059. );
  13060. }
  13061. return param;
  13062. }
  13063. function fileNameChanged(patch) {
  13064. return patch.newFileName && patch.newFileName !== patch.oldFileName;
  13065. }
  13066. function selectField(index, mine, theirs) {
  13067. if (mine === theirs) {
  13068. return mine;
  13069. } else {
  13070. index.conflict = true;
  13071. return {
  13072. mine: mine,
  13073. theirs: theirs
  13074. };
  13075. }
  13076. }
  13077. function hunkBefore(test, check) {
  13078. return test.oldStart < check.oldStart && test.oldStart + test.oldLines < check.oldStart;
  13079. }
  13080. function cloneHunk(hunk, offset) {
  13081. return {
  13082. oldStart: hunk.oldStart,
  13083. oldLines: hunk.oldLines,
  13084. newStart: hunk.newStart + offset,
  13085. newLines: hunk.newLines,
  13086. lines: hunk.lines
  13087. };
  13088. }
  13089. function mergeLines(hunk, mineOffset, mineLines, theirOffset, theirLines) {
  13090. // This will generally result in a conflicted hunk, but there are cases where the context
  13091. // is the only overlap where we can successfully merge the content here.
  13092. var mine = {
  13093. offset: mineOffset,
  13094. lines: mineLines,
  13095. index: 0
  13096. },
  13097. their = {
  13098. offset: theirOffset,
  13099. lines: theirLines,
  13100. index: 0
  13101. }; // Handle any leading content
  13102. insertLeading(hunk, mine, their);
  13103. insertLeading(hunk, their, mine); // Now in the overlap content. Scan through and select the best changes from each.
  13104. while (mine.index < mine.lines.length && their.index < their.lines.length) {
  13105. var mineCurrent = mine.lines[mine.index],
  13106. theirCurrent = their.lines[their.index];
  13107. if ((mineCurrent[0] === '-' || mineCurrent[0] === '+') && (theirCurrent[0] === '-' || theirCurrent[0] === '+')) {
  13108. // Both modified ...
  13109. mutualChange(hunk, mine, their);
  13110. } else if (mineCurrent[0] === '+' && theirCurrent[0] === ' ') {
  13111. /*istanbul ignore start*/
  13112. var _hunk$lines;
  13113. /*istanbul ignore end*/
  13114. // Mine inserted
  13115. /*istanbul ignore start*/
  13116. /*istanbul ignore end*/
  13117. /*istanbul ignore start*/
  13118. (_hunk$lines =
  13119. /*istanbul ignore end*/
  13120. hunk.lines).push.apply(
  13121. /*istanbul ignore start*/
  13122. _hunk$lines
  13123. /*istanbul ignore end*/
  13124. ,
  13125. /*istanbul ignore start*/
  13126. _toConsumableArray(
  13127. /*istanbul ignore end*/
  13128. collectChange(mine)));
  13129. } else if (theirCurrent[0] === '+' && mineCurrent[0] === ' ') {
  13130. /*istanbul ignore start*/
  13131. var _hunk$lines2;
  13132. /*istanbul ignore end*/
  13133. // Theirs inserted
  13134. /*istanbul ignore start*/
  13135. /*istanbul ignore end*/
  13136. /*istanbul ignore start*/
  13137. (_hunk$lines2 =
  13138. /*istanbul ignore end*/
  13139. hunk.lines).push.apply(
  13140. /*istanbul ignore start*/
  13141. _hunk$lines2
  13142. /*istanbul ignore end*/
  13143. ,
  13144. /*istanbul ignore start*/
  13145. _toConsumableArray(
  13146. /*istanbul ignore end*/
  13147. collectChange(their)));
  13148. } else if (mineCurrent[0] === '-' && theirCurrent[0] === ' ') {
  13149. // Mine removed or edited
  13150. removal(hunk, mine, their);
  13151. } else if (theirCurrent[0] === '-' && mineCurrent[0] === ' ') {
  13152. // Their removed or edited
  13153. removal(hunk, their, mine, true);
  13154. } else if (mineCurrent === theirCurrent) {
  13155. // Context identity
  13156. hunk.lines.push(mineCurrent);
  13157. mine.index++;
  13158. their.index++;
  13159. } else {
  13160. // Context mismatch
  13161. conflict(hunk, collectChange(mine), collectChange(their));
  13162. }
  13163. } // Now push anything that may be remaining
  13164. insertTrailing(hunk, mine);
  13165. insertTrailing(hunk, their);
  13166. calcLineCount(hunk);
  13167. }
  13168. function mutualChange(hunk, mine, their) {
  13169. var myChanges = collectChange(mine),
  13170. theirChanges = collectChange(their);
  13171. if (allRemoves(myChanges) && allRemoves(theirChanges)) {
  13172. // Special case for remove changes that are supersets of one another
  13173. if (
  13174. /*istanbul ignore start*/
  13175. (/*istanbul ignore end*/
  13176. /*istanbul ignore start*/
  13177. 0, array
  13178. /*istanbul ignore end*/
  13179. .
  13180. /*istanbul ignore start*/
  13181. arrayStartsWith
  13182. /*istanbul ignore end*/
  13183. )(myChanges, theirChanges) && skipRemoveSuperset(their, myChanges, myChanges.length - theirChanges.length)) {
  13184. /*istanbul ignore start*/
  13185. var _hunk$lines3;
  13186. /*istanbul ignore end*/
  13187. /*istanbul ignore start*/
  13188. /*istanbul ignore end*/
  13189. /*istanbul ignore start*/
  13190. (_hunk$lines3 =
  13191. /*istanbul ignore end*/
  13192. hunk.lines).push.apply(
  13193. /*istanbul ignore start*/
  13194. _hunk$lines3
  13195. /*istanbul ignore end*/
  13196. ,
  13197. /*istanbul ignore start*/
  13198. _toConsumableArray(
  13199. /*istanbul ignore end*/
  13200. myChanges));
  13201. return;
  13202. } else if (
  13203. /*istanbul ignore start*/
  13204. (/*istanbul ignore end*/
  13205. /*istanbul ignore start*/
  13206. 0, array
  13207. /*istanbul ignore end*/
  13208. .
  13209. /*istanbul ignore start*/
  13210. arrayStartsWith
  13211. /*istanbul ignore end*/
  13212. )(theirChanges, myChanges) && skipRemoveSuperset(mine, theirChanges, theirChanges.length - myChanges.length)) {
  13213. /*istanbul ignore start*/
  13214. var _hunk$lines4;
  13215. /*istanbul ignore end*/
  13216. /*istanbul ignore start*/
  13217. /*istanbul ignore end*/
  13218. /*istanbul ignore start*/
  13219. (_hunk$lines4 =
  13220. /*istanbul ignore end*/
  13221. hunk.lines).push.apply(
  13222. /*istanbul ignore start*/
  13223. _hunk$lines4
  13224. /*istanbul ignore end*/
  13225. ,
  13226. /*istanbul ignore start*/
  13227. _toConsumableArray(
  13228. /*istanbul ignore end*/
  13229. theirChanges));
  13230. return;
  13231. }
  13232. } else if (
  13233. /*istanbul ignore start*/
  13234. (/*istanbul ignore end*/
  13235. /*istanbul ignore start*/
  13236. 0, array
  13237. /*istanbul ignore end*/
  13238. .
  13239. /*istanbul ignore start*/
  13240. arrayEqual
  13241. /*istanbul ignore end*/
  13242. )(myChanges, theirChanges)) {
  13243. /*istanbul ignore start*/
  13244. var _hunk$lines5;
  13245. /*istanbul ignore end*/
  13246. /*istanbul ignore start*/
  13247. /*istanbul ignore end*/
  13248. /*istanbul ignore start*/
  13249. (_hunk$lines5 =
  13250. /*istanbul ignore end*/
  13251. hunk.lines).push.apply(
  13252. /*istanbul ignore start*/
  13253. _hunk$lines5
  13254. /*istanbul ignore end*/
  13255. ,
  13256. /*istanbul ignore start*/
  13257. _toConsumableArray(
  13258. /*istanbul ignore end*/
  13259. myChanges));
  13260. return;
  13261. }
  13262. conflict(hunk, myChanges, theirChanges);
  13263. }
  13264. function removal(hunk, mine, their, swap) {
  13265. var myChanges = collectChange(mine),
  13266. theirChanges = collectContext(their, myChanges);
  13267. if (theirChanges.merged) {
  13268. /*istanbul ignore start*/
  13269. var _hunk$lines6;
  13270. /*istanbul ignore end*/
  13271. /*istanbul ignore start*/
  13272. /*istanbul ignore end*/
  13273. /*istanbul ignore start*/
  13274. (_hunk$lines6 =
  13275. /*istanbul ignore end*/
  13276. hunk.lines).push.apply(
  13277. /*istanbul ignore start*/
  13278. _hunk$lines6
  13279. /*istanbul ignore end*/
  13280. ,
  13281. /*istanbul ignore start*/
  13282. _toConsumableArray(
  13283. /*istanbul ignore end*/
  13284. theirChanges.merged));
  13285. } else {
  13286. conflict(hunk, swap ? theirChanges : myChanges, swap ? myChanges : theirChanges);
  13287. }
  13288. }
  13289. function conflict(hunk, mine, their) {
  13290. hunk.conflict = true;
  13291. hunk.lines.push({
  13292. conflict: true,
  13293. mine: mine,
  13294. theirs: their
  13295. });
  13296. }
  13297. function insertLeading(hunk, insert, their) {
  13298. while (insert.offset < their.offset && insert.index < insert.lines.length) {
  13299. var line = insert.lines[insert.index++];
  13300. hunk.lines.push(line);
  13301. insert.offset++;
  13302. }
  13303. }
  13304. function insertTrailing(hunk, insert) {
  13305. while (insert.index < insert.lines.length) {
  13306. var line = insert.lines[insert.index++];
  13307. hunk.lines.push(line);
  13308. }
  13309. }
  13310. function collectChange(state) {
  13311. var ret = [],
  13312. operation = state.lines[state.index][0];
  13313. while (state.index < state.lines.length) {
  13314. var line = state.lines[state.index]; // Group additions that are immediately after subtractions and treat them as one "atomic" modify change.
  13315. if (operation === '-' && line[0] === '+') {
  13316. operation = '+';
  13317. }
  13318. if (operation === line[0]) {
  13319. ret.push(line);
  13320. state.index++;
  13321. } else {
  13322. break;
  13323. }
  13324. }
  13325. return ret;
  13326. }
  13327. function collectContext(state, matchChanges) {
  13328. var changes = [],
  13329. merged = [],
  13330. matchIndex = 0,
  13331. contextChanges = false,
  13332. conflicted = false;
  13333. while (matchIndex < matchChanges.length && state.index < state.lines.length) {
  13334. var change = state.lines[state.index],
  13335. match = matchChanges[matchIndex]; // Once we've hit our add, then we are done
  13336. if (match[0] === '+') {
  13337. break;
  13338. }
  13339. contextChanges = contextChanges || change[0] !== ' ';
  13340. merged.push(match);
  13341. matchIndex++; // Consume any additions in the other block as a conflict to attempt
  13342. // to pull in the remaining context after this
  13343. if (change[0] === '+') {
  13344. conflicted = true;
  13345. while (change[0] === '+') {
  13346. changes.push(change);
  13347. change = state.lines[++state.index];
  13348. }
  13349. }
  13350. if (match.substr(1) === change.substr(1)) {
  13351. changes.push(change);
  13352. state.index++;
  13353. } else {
  13354. conflicted = true;
  13355. }
  13356. }
  13357. if ((matchChanges[matchIndex] || '')[0] === '+' && contextChanges) {
  13358. conflicted = true;
  13359. }
  13360. if (conflicted) {
  13361. return changes;
  13362. }
  13363. while (matchIndex < matchChanges.length) {
  13364. merged.push(matchChanges[matchIndex++]);
  13365. }
  13366. return {
  13367. merged: merged,
  13368. changes: changes
  13369. };
  13370. }
  13371. function allRemoves(changes) {
  13372. return changes.reduce(function (prev, change) {
  13373. return prev && change[0] === '-';
  13374. }, true);
  13375. }
  13376. function skipRemoveSuperset(state, removeChanges, delta) {
  13377. for (var i = 0; i < delta; i++) {
  13378. var changeContent = removeChanges[removeChanges.length - delta + i].substr(1);
  13379. if (state.lines[state.index + i] !== ' ' + changeContent) {
  13380. return false;
  13381. }
  13382. }
  13383. state.index += delta;
  13384. return true;
  13385. }
  13386. function calcOldNewLineCount(lines) {
  13387. var oldLines = 0;
  13388. var newLines = 0;
  13389. lines.forEach(function (line) {
  13390. if (typeof line !== 'string') {
  13391. var myCount = calcOldNewLineCount(line.mine);
  13392. var theirCount = calcOldNewLineCount(line.theirs);
  13393. if (oldLines !== undefined) {
  13394. if (myCount.oldLines === theirCount.oldLines) {
  13395. oldLines += myCount.oldLines;
  13396. } else {
  13397. oldLines = undefined;
  13398. }
  13399. }
  13400. if (newLines !== undefined) {
  13401. if (myCount.newLines === theirCount.newLines) {
  13402. newLines += myCount.newLines;
  13403. } else {
  13404. newLines = undefined;
  13405. }
  13406. }
  13407. } else {
  13408. if (newLines !== undefined && (line[0] === '+' || line[0] === ' ')) {
  13409. newLines++;
  13410. }
  13411. if (oldLines !== undefined && (line[0] === '-' || line[0] === ' ')) {
  13412. oldLines++;
  13413. }
  13414. }
  13415. });
  13416. return {
  13417. oldLines: oldLines,
  13418. newLines: newLines
  13419. };
  13420. }
  13421. var merge_1 = /*#__PURE__*/Object.defineProperty({
  13422. calcLineCount: calcLineCount_1,
  13423. merge: merge_2
  13424. }, '__esModule', {
  13425. value: true
  13426. });
  13427. /*istanbul ignore start*/
  13428. var convertChangesToDMP_1 = convertChangesToDMP;
  13429. /*istanbul ignore end*/
  13430. // See: http://code.google.com/p/google-diff-match-patch/wiki/API
  13431. function convertChangesToDMP(changes) {
  13432. var ret = [],
  13433. change,
  13434. operation;
  13435. for (var i = 0; i < changes.length; i++) {
  13436. change = changes[i];
  13437. if (change.added) {
  13438. operation = 1;
  13439. } else if (change.removed) {
  13440. operation = -1;
  13441. } else {
  13442. operation = 0;
  13443. }
  13444. ret.push([operation, change.value]);
  13445. }
  13446. return ret;
  13447. }
  13448. var dmp = /*#__PURE__*/Object.defineProperty({
  13449. convertChangesToDMP: convertChangesToDMP_1
  13450. }, '__esModule', {
  13451. value: true
  13452. });
  13453. /*istanbul ignore start*/
  13454. var convertChangesToXML_1 = convertChangesToXML;
  13455. /*istanbul ignore end*/
  13456. function convertChangesToXML(changes) {
  13457. var ret = [];
  13458. for (var i = 0; i < changes.length; i++) {
  13459. var change = changes[i];
  13460. if (change.added) {
  13461. ret.push('<ins>');
  13462. } else if (change.removed) {
  13463. ret.push('<del>');
  13464. }
  13465. ret.push(escapeHTML(change.value));
  13466. if (change.added) {
  13467. ret.push('</ins>');
  13468. } else if (change.removed) {
  13469. ret.push('</del>');
  13470. }
  13471. }
  13472. return ret.join('');
  13473. }
  13474. function escapeHTML(s) {
  13475. var n = s;
  13476. n = n.replace(/&/g, '&amp;');
  13477. n = n.replace(/</g, '&lt;');
  13478. n = n.replace(/>/g, '&gt;');
  13479. n = n.replace(/"/g, '&quot;');
  13480. return n;
  13481. }
  13482. var xml = /*#__PURE__*/Object.defineProperty({
  13483. convertChangesToXML: convertChangesToXML_1
  13484. }, '__esModule', {
  13485. value: true
  13486. });
  13487. /*istanbul ignore start*/
  13488. var lib$1 = createCommonjsModule(function (module, exports) {
  13489. Object.defineProperty(exports, "__esModule", {
  13490. value: true
  13491. });
  13492. Object.defineProperty(exports, "Diff", {
  13493. enumerable: true,
  13494. get: function get() {
  13495. return _base["default"];
  13496. }
  13497. });
  13498. Object.defineProperty(exports, "diffChars", {
  13499. enumerable: true,
  13500. get: function get() {
  13501. return character.diffChars;
  13502. }
  13503. });
  13504. Object.defineProperty(exports, "diffWords", {
  13505. enumerable: true,
  13506. get: function get() {
  13507. return word.diffWords;
  13508. }
  13509. });
  13510. Object.defineProperty(exports, "diffWordsWithSpace", {
  13511. enumerable: true,
  13512. get: function get() {
  13513. return word.diffWordsWithSpace;
  13514. }
  13515. });
  13516. Object.defineProperty(exports, "diffLines", {
  13517. enumerable: true,
  13518. get: function get() {
  13519. return line.diffLines;
  13520. }
  13521. });
  13522. Object.defineProperty(exports, "diffTrimmedLines", {
  13523. enumerable: true,
  13524. get: function get() {
  13525. return line.diffTrimmedLines;
  13526. }
  13527. });
  13528. Object.defineProperty(exports, "diffSentences", {
  13529. enumerable: true,
  13530. get: function get() {
  13531. return sentence.diffSentences;
  13532. }
  13533. });
  13534. Object.defineProperty(exports, "diffCss", {
  13535. enumerable: true,
  13536. get: function get() {
  13537. return css.diffCss;
  13538. }
  13539. });
  13540. Object.defineProperty(exports, "diffJson", {
  13541. enumerable: true,
  13542. get: function get() {
  13543. return json.diffJson;
  13544. }
  13545. });
  13546. Object.defineProperty(exports, "canonicalize", {
  13547. enumerable: true,
  13548. get: function get() {
  13549. return json.canonicalize;
  13550. }
  13551. });
  13552. Object.defineProperty(exports, "diffArrays", {
  13553. enumerable: true,
  13554. get: function get() {
  13555. return array$1.diffArrays;
  13556. }
  13557. });
  13558. Object.defineProperty(exports, "applyPatch", {
  13559. enumerable: true,
  13560. get: function get() {
  13561. return apply$1.applyPatch;
  13562. }
  13563. });
  13564. Object.defineProperty(exports, "applyPatches", {
  13565. enumerable: true,
  13566. get: function get() {
  13567. return apply$1.applyPatches;
  13568. }
  13569. });
  13570. Object.defineProperty(exports, "parsePatch", {
  13571. enumerable: true,
  13572. get: function get() {
  13573. return parse.parsePatch;
  13574. }
  13575. });
  13576. Object.defineProperty(exports, "merge", {
  13577. enumerable: true,
  13578. get: function get() {
  13579. return merge_1.merge;
  13580. }
  13581. });
  13582. Object.defineProperty(exports, "structuredPatch", {
  13583. enumerable: true,
  13584. get: function get() {
  13585. return create.structuredPatch;
  13586. }
  13587. });
  13588. Object.defineProperty(exports, "createTwoFilesPatch", {
  13589. enumerable: true,
  13590. get: function get() {
  13591. return create.createTwoFilesPatch;
  13592. }
  13593. });
  13594. Object.defineProperty(exports, "createPatch", {
  13595. enumerable: true,
  13596. get: function get() {
  13597. return create.createPatch;
  13598. }
  13599. });
  13600. Object.defineProperty(exports, "convertChangesToDMP", {
  13601. enumerable: true,
  13602. get: function get() {
  13603. return dmp.convertChangesToDMP;
  13604. }
  13605. });
  13606. Object.defineProperty(exports, "convertChangesToXML", {
  13607. enumerable: true,
  13608. get: function get() {
  13609. return xml.convertChangesToXML;
  13610. }
  13611. });
  13612. /*istanbul ignore end*/
  13613. var
  13614. /*istanbul ignore start*/
  13615. _base = _interopRequireDefault(base)
  13616. /*istanbul ignore end*/
  13617. ;
  13618. /*istanbul ignore start*/
  13619. function _interopRequireDefault(obj) {
  13620. return obj && obj.__esModule ? obj : {
  13621. "default": obj
  13622. };
  13623. }
  13624. /*istanbul ignore end*/
  13625. });
  13626. const {
  13627. promises: fs
  13628. } = fs__default['default']; // eslint-disable-next-line no-restricted-modules
  13629. // eslint-disable-next-line no-restricted-modules
  13630. const {
  13631. getStdin
  13632. } = require$$1;
  13633. const {
  13634. createIgnorer,
  13635. errors
  13636. } = prettierInternal;
  13637. const {
  13638. expandPatterns,
  13639. fixWindowsSlashes
  13640. } = expandPatterns_1;
  13641. const {
  13642. getOptionsForFile
  13643. } = option;
  13644. function diff(a, b) {
  13645. return lib$1.createTwoFilesPatch("", "", a, b, "", "", {
  13646. context: 2
  13647. });
  13648. }
  13649. function handleError(context, filename, error, printedFilename) {
  13650. if (error instanceof errors.UndefinedParserError) {
  13651. // Can't test on CI, `isTTY()` is always false, see ./is-tty.js
  13652. /* istanbul ignore next */
  13653. if ((context.argv.write || context.argv["ignore-unknown"]) && printedFilename) {
  13654. printedFilename.clear();
  13655. }
  13656. if (context.argv["ignore-unknown"]) {
  13657. return;
  13658. }
  13659. if (!context.argv.check && !context.argv["list-different"]) {
  13660. process.exitCode = 2;
  13661. }
  13662. context.logger.error(error.message);
  13663. return;
  13664. }
  13665. if (context.argv.write) {
  13666. // Add newline to split errors from filename line.
  13667. process.stdout.write("\n");
  13668. }
  13669. const isParseError = Boolean(error && error.loc);
  13670. const isValidationError = /^Invalid \S+ value\./.test(error && error.message);
  13671. if (isParseError) {
  13672. // `invalid.js: SyntaxError: Unexpected token (1:1)`.
  13673. context.logger.error(`${filename}: ${String(error)}`);
  13674. } else if (isValidationError || error instanceof errors.ConfigError) {
  13675. // `Invalid printWidth value. Expected an integer, but received 0.5.`
  13676. context.logger.error(error.message); // If validation fails for one file, it will fail for all of them.
  13677. process.exit(1);
  13678. } else if (error instanceof errors.DebugError) {
  13679. // `invalid.js: Some debug error message`
  13680. context.logger.error(`${filename}: ${error.message}`);
  13681. } else {
  13682. // `invalid.js: Error: Some unexpected error\n[stack trace]`
  13683. /* istanbul ignore next */
  13684. context.logger.error(filename + ": " + (error.stack || error));
  13685. } // Don't exit the process if one file failed
  13686. process.exitCode = 2;
  13687. }
  13688. function writeOutput(context, result, options) {
  13689. // Don't use `console.log` here since it adds an extra newline at the end.
  13690. process.stdout.write(context.argv["debug-check"] ? result.filepath : result.formatted);
  13691. if (options && options.cursorOffset >= 0) {
  13692. process.stderr.write(result.cursorOffset + "\n");
  13693. }
  13694. }
  13695. function listDifferent(context, input, options, filename) {
  13696. if (!context.argv.check && !context.argv["list-different"]) {
  13697. return;
  13698. }
  13699. try {
  13700. if (!options.filepath && !options.parser) {
  13701. throw new errors.UndefinedParserError("No parser and no file path given, couldn't infer a parser.");
  13702. }
  13703. if (!prettier$1.check(input, options)) {
  13704. if (!context.argv.write) {
  13705. context.logger.log(filename);
  13706. process.exitCode = 1;
  13707. }
  13708. }
  13709. } catch (error) {
  13710. context.logger.error(error.message);
  13711. }
  13712. return true;
  13713. }
  13714. function format$1(context, input, opt) {
  13715. if (!opt.parser && !opt.filepath) {
  13716. throw new errors.UndefinedParserError("No parser and no file path given, couldn't infer a parser.");
  13717. }
  13718. if (context.argv["debug-print-doc"]) {
  13719. const doc = prettier$1.__debug.printToDoc(input, opt);
  13720. return {
  13721. formatted: prettier$1.__debug.formatDoc(doc) + "\n"
  13722. };
  13723. }
  13724. if (context.argv["debug-print-comments"]) {
  13725. return {
  13726. formatted: prettier$1.format(JSON.stringify(prettier$1.formatWithCursor(input, opt).comments || []), {
  13727. parser: "json"
  13728. })
  13729. };
  13730. }
  13731. if (context.argv["debug-print-ast"]) {
  13732. const {
  13733. ast
  13734. } = prettier$1.__debug.parse(input, opt);
  13735. return {
  13736. formatted: JSON.stringify(ast)
  13737. };
  13738. }
  13739. if (context.argv["debug-check"]) {
  13740. const pp = prettier$1.format(input, opt);
  13741. const pppp = prettier$1.format(pp, opt);
  13742. if (pp !== pppp) {
  13743. throw new errors.DebugError("prettier(input) !== prettier(prettier(input))\n" + diff(pp, pppp));
  13744. } else {
  13745. const stringify = obj => JSON.stringify(obj, null, 2);
  13746. const ast = stringify(prettier$1.__debug.parse(input, opt,
  13747. /* massage */
  13748. true).ast);
  13749. const past = stringify(prettier$1.__debug.parse(pp, opt,
  13750. /* massage */
  13751. true).ast);
  13752. /* istanbul ignore next */
  13753. if (ast !== past) {
  13754. const MAX_AST_SIZE = 2097152; // 2MB
  13755. const astDiff = ast.length > MAX_AST_SIZE || past.length > MAX_AST_SIZE ? "AST diff too large to render" : diff(ast, past);
  13756. throw new errors.DebugError("ast(input) !== ast(prettier(input))\n" + astDiff + "\n" + diff(input, pp));
  13757. }
  13758. }
  13759. return {
  13760. formatted: pp,
  13761. filepath: opt.filepath || "(stdin)\n"
  13762. };
  13763. }
  13764. /* istanbul ignore next */
  13765. if (context.argv["debug-benchmark"]) {
  13766. let benchmark;
  13767. try {
  13768. // eslint-disable-next-line import/no-extraneous-dependencies
  13769. benchmark = require("benchmark");
  13770. } catch {
  13771. context.logger.debug("'--debug-benchmark' requires the 'benchmark' package to be installed.");
  13772. process.exit(2);
  13773. }
  13774. context.logger.debug("'--debug-benchmark' option found, measuring formatWithCursor with 'benchmark' module.");
  13775. const suite = new benchmark.Suite();
  13776. suite.add("format", () => {
  13777. prettier$1.formatWithCursor(input, opt);
  13778. }).on("cycle", event => {
  13779. const results = {
  13780. benchmark: String(event.target),
  13781. hz: event.target.hz,
  13782. ms: event.target.times.cycle * 1000
  13783. };
  13784. context.logger.debug("'--debug-benchmark' measurements for formatWithCursor: " + JSON.stringify(results, null, 2));
  13785. }).run({
  13786. async: false
  13787. });
  13788. } else if (context.argv["debug-repeat"] > 0) {
  13789. const repeat = context.argv["debug-repeat"];
  13790. context.logger.debug("'--debug-repeat' option found, running formatWithCursor " + repeat + " times.");
  13791. let totalMs = 0;
  13792. for (let i = 0; i < repeat; ++i) {
  13793. // should be using `performance.now()`, but only `Date` is cross-platform enough
  13794. const startMs = Date.now();
  13795. prettier$1.formatWithCursor(input, opt);
  13796. totalMs += Date.now() - startMs;
  13797. }
  13798. const averageMs = totalMs / repeat;
  13799. const results = {
  13800. repeat,
  13801. hz: 1000 / averageMs,
  13802. ms: averageMs
  13803. };
  13804. context.logger.debug("'--debug-repeat' measurements for formatWithCursor: " + JSON.stringify(results, null, 2));
  13805. }
  13806. return prettier$1.formatWithCursor(input, opt);
  13807. }
  13808. async function createIgnorerFromContextOrDie(context) {
  13809. try {
  13810. return await createIgnorer(context.argv["ignore-path"], context.argv["with-node-modules"]);
  13811. } catch (e) {
  13812. context.logger.error(e.message);
  13813. process.exit(2);
  13814. }
  13815. }
  13816. async function formatStdin$1(context) {
  13817. const filepath = context.argv["stdin-filepath"] ? path__default['default'].resolve(process.cwd(), context.argv["stdin-filepath"]) : process.cwd();
  13818. const ignorer = await createIgnorerFromContextOrDie(context); // If there's an ignore-path set, the filename must be relative to the
  13819. // ignore path, not the current working directory.
  13820. const relativeFilepath = context.argv["ignore-path"] ? path__default['default'].relative(path__default['default'].dirname(context.argv["ignore-path"]), filepath) : path__default['default'].relative(process.cwd(), filepath);
  13821. try {
  13822. const input = await getStdin();
  13823. if (relativeFilepath && ignorer.ignores(fixWindowsSlashes(relativeFilepath))) {
  13824. writeOutput(context, {
  13825. formatted: input
  13826. });
  13827. return;
  13828. }
  13829. const options = await getOptionsForFile(context, filepath);
  13830. if (listDifferent(context, input, options, "(stdin)")) {
  13831. return;
  13832. }
  13833. writeOutput(context, format$1(context, input, options), options);
  13834. } catch (error) {
  13835. handleError(context, relativeFilepath || "stdin", error);
  13836. }
  13837. }
  13838. async function formatFiles$1(context) {
  13839. // The ignorer will be used to filter file paths after the glob is checked,
  13840. // before any files are actually written
  13841. const ignorer = await createIgnorerFromContextOrDie(context);
  13842. let numberOfUnformattedFilesFound = 0;
  13843. if (context.argv.check) {
  13844. context.logger.log("Checking formatting...");
  13845. }
  13846. for await (const pathOrError of expandPatterns(context)) {
  13847. if (typeof pathOrError === "object") {
  13848. context.logger.error(pathOrError.error); // Don't exit, but set the exit code to 2
  13849. process.exitCode = 2;
  13850. continue;
  13851. }
  13852. const filename = pathOrError; // If there's an ignore-path set, the filename must be relative to the
  13853. // ignore path, not the current working directory.
  13854. const ignoreFilename = context.argv["ignore-path"] ? path__default['default'].relative(path__default['default'].dirname(context.argv["ignore-path"]), filename) : filename;
  13855. const fileIgnored = ignorer.ignores(fixWindowsSlashes(ignoreFilename));
  13856. if (fileIgnored && (context.argv["debug-check"] || context.argv.write || context.argv.check || context.argv["list-different"])) {
  13857. continue;
  13858. }
  13859. const options = Object.assign(Object.assign({}, await getOptionsForFile(context, filename)), {}, {
  13860. filepath: filename
  13861. });
  13862. let printedFilename;
  13863. if (isTty()) {
  13864. printedFilename = context.logger.log(filename, {
  13865. newline: false,
  13866. clearable: true
  13867. });
  13868. }
  13869. let input;
  13870. try {
  13871. input = await fs.readFile(filename, "utf8");
  13872. } catch (error) {
  13873. // Add newline to split errors from filename line.
  13874. /* istanbul ignore next */
  13875. context.logger.log("");
  13876. /* istanbul ignore next */
  13877. context.logger.error(`Unable to read file: ${filename}\n${error.message}`); // Don't exit the process if one file failed
  13878. /* istanbul ignore next */
  13879. process.exitCode = 2;
  13880. /* istanbul ignore next */
  13881. continue;
  13882. }
  13883. if (fileIgnored) {
  13884. writeOutput(context, {
  13885. formatted: input
  13886. }, options);
  13887. continue;
  13888. }
  13889. const start = Date.now();
  13890. let result;
  13891. let output;
  13892. try {
  13893. result = format$1(context, input, options);
  13894. output = result.formatted;
  13895. } catch (error) {
  13896. handleError(context, filename, error, printedFilename);
  13897. continue;
  13898. }
  13899. const isDifferent = output !== input;
  13900. if (printedFilename) {
  13901. // Remove previously printed filename to log it with duration.
  13902. printedFilename.clear();
  13903. }
  13904. if (context.argv.write) {
  13905. // Don't write the file if it won't change in order not to invalidate
  13906. // mtime based caches.
  13907. if (isDifferent) {
  13908. if (!context.argv.check && !context.argv["list-different"]) {
  13909. context.logger.log(`${filename} ${Date.now() - start}ms`);
  13910. }
  13911. try {
  13912. await fs.writeFile(filename, output, "utf8");
  13913. } catch (error) {
  13914. /* istanbul ignore next */
  13915. context.logger.error(`Unable to write file: ${filename}\n${error.message}`); // Don't exit the process if one file failed
  13916. /* istanbul ignore next */
  13917. process.exitCode = 2;
  13918. }
  13919. } else if (!context.argv.check && !context.argv["list-different"]) {
  13920. context.logger.log(`${source.grey(filename)} ${Date.now() - start}ms`);
  13921. }
  13922. } else if (context.argv["debug-check"]) {
  13923. /* istanbul ignore else */
  13924. if (result.filepath) {
  13925. context.logger.log(result.filepath);
  13926. } else {
  13927. process.exitCode = 2;
  13928. }
  13929. } else if (!context.argv.check && !context.argv["list-different"]) {
  13930. writeOutput(context, result, options);
  13931. }
  13932. if (isDifferent) {
  13933. if (context.argv.check) {
  13934. context.logger.warn(filename);
  13935. } else if (context.argv["list-different"]) {
  13936. context.logger.log(filename);
  13937. }
  13938. numberOfUnformattedFilesFound += 1;
  13939. }
  13940. } // Print check summary based on expected exit code
  13941. if (context.argv.check) {
  13942. if (numberOfUnformattedFilesFound === 0) {
  13943. context.logger.log("All matched files use Prettier code style!");
  13944. } else {
  13945. context.logger.warn(context.argv.write ? "Code style issues fixed in the above file(s)." : "Code style issues found in the above file(s). Forgot to run Prettier?");
  13946. }
  13947. } // Ensure non-zero exitCode when using --check/list-different is not combined with --write
  13948. if ((context.argv.check || context.argv["list-different"]) && numberOfUnformattedFilesFound > 0 && !process.exitCode && !context.argv.write) {
  13949. process.exitCode = 1;
  13950. }
  13951. }
  13952. var format_1 = {
  13953. format: format$1,
  13954. formatStdin: formatStdin$1,
  13955. formatFiles: formatFiles$1
  13956. };
  13957. var defineProperty = function () {
  13958. try {
  13959. var func = _getNative(Object, 'defineProperty');
  13960. func({}, '', {});
  13961. return func;
  13962. } catch (e) {}
  13963. }();
  13964. var _defineProperty = defineProperty;
  13965. /**
  13966. * The base implementation of `assignValue` and `assignMergeValue` without
  13967. * value checks.
  13968. *
  13969. * @private
  13970. * @param {Object} object The object to modify.
  13971. * @param {string} key The key of the property to assign.
  13972. * @param {*} value The value to assign.
  13973. */
  13974. function baseAssignValue(object, key, value) {
  13975. if (key == '__proto__' && _defineProperty) {
  13976. _defineProperty(object, key, {
  13977. 'configurable': true,
  13978. 'enumerable': true,
  13979. 'value': value,
  13980. 'writable': true
  13981. });
  13982. } else {
  13983. object[key] = value;
  13984. }
  13985. }
  13986. var _baseAssignValue = baseAssignValue;
  13987. /** Used for built-in method references. */
  13988. var objectProto$1 = Object.prototype;
  13989. /** Used to check objects for own properties. */
  13990. var hasOwnProperty$1 = objectProto$1.hasOwnProperty;
  13991. /**
  13992. * Assigns `value` to `key` of `object` if the existing value is not equivalent
  13993. * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
  13994. * for equality comparisons.
  13995. *
  13996. * @private
  13997. * @param {Object} object The object to modify.
  13998. * @param {string} key The key of the property to assign.
  13999. * @param {*} value The value to assign.
  14000. */
  14001. function assignValue(object, key, value) {
  14002. var objValue = object[key];
  14003. if (!(hasOwnProperty$1.call(object, key) && eq_1(objValue, value)) || value === undefined && !(key in object)) {
  14004. _baseAssignValue(object, key, value);
  14005. }
  14006. }
  14007. var _assignValue = assignValue;
  14008. /**
  14009. * The base implementation of `_.set`.
  14010. *
  14011. * @private
  14012. * @param {Object} object The object to modify.
  14013. * @param {Array|string} path The path of the property to set.
  14014. * @param {*} value The value to set.
  14015. * @param {Function} [customizer] The function to customize path creation.
  14016. * @returns {Object} Returns `object`.
  14017. */
  14018. function baseSet(object, path, value, customizer) {
  14019. if (!isObject_1(object)) {
  14020. return object;
  14021. }
  14022. path = _castPath(path, object);
  14023. var index = -1,
  14024. length = path.length,
  14025. lastIndex = length - 1,
  14026. nested = object;
  14027. while (nested != null && ++index < length) {
  14028. var key = _toKey(path[index]),
  14029. newValue = value;
  14030. if (key === '__proto__' || key === 'constructor' || key === 'prototype') {
  14031. return object;
  14032. }
  14033. if (index != lastIndex) {
  14034. var objValue = nested[key];
  14035. newValue = customizer ? customizer(objValue, key, nested) : undefined;
  14036. if (newValue === undefined) {
  14037. newValue = isObject_1(objValue) ? objValue : _isIndex(path[index + 1]) ? [] : {};
  14038. }
  14039. }
  14040. _assignValue(nested, key, newValue);
  14041. nested = nested[key];
  14042. }
  14043. return object;
  14044. }
  14045. var _baseSet = baseSet;
  14046. /**
  14047. * The base implementation of `_.pickBy` without support for iteratee shorthands.
  14048. *
  14049. * @private
  14050. * @param {Object} object The source object.
  14051. * @param {string[]} paths The property paths to pick.
  14052. * @param {Function} predicate The function invoked per property.
  14053. * @returns {Object} Returns the new object.
  14054. */
  14055. function basePickBy(object, paths, predicate) {
  14056. var index = -1,
  14057. length = paths.length,
  14058. result = {};
  14059. while (++index < length) {
  14060. var path = paths[index],
  14061. value = _baseGet(object, path);
  14062. if (predicate(value, path)) {
  14063. _baseSet(result, _castPath(path, object), value);
  14064. }
  14065. }
  14066. return result;
  14067. }
  14068. var _basePickBy = basePickBy;
  14069. /**
  14070. * The base implementation of `_.pick` without support for individual
  14071. * property identifiers.
  14072. *
  14073. * @private
  14074. * @param {Object} object The source object.
  14075. * @param {string[]} paths The property paths to pick.
  14076. * @returns {Object} Returns the new object.
  14077. */
  14078. function basePick(object, paths) {
  14079. return _basePickBy(object, paths, function (value, path) {
  14080. return hasIn_1(object, path);
  14081. });
  14082. }
  14083. var _basePick = basePick;
  14084. /** Built-in value references. */
  14085. var spreadableSymbol = _Symbol ? _Symbol.isConcatSpreadable : undefined;
  14086. /**
  14087. * Checks if `value` is a flattenable `arguments` object or array.
  14088. *
  14089. * @private
  14090. * @param {*} value The value to check.
  14091. * @returns {boolean} Returns `true` if `value` is flattenable, else `false`.
  14092. */
  14093. function isFlattenable(value) {
  14094. return isArray_1(value) || isArguments_1(value) || !!(spreadableSymbol && value && value[spreadableSymbol]);
  14095. }
  14096. var _isFlattenable = isFlattenable;
  14097. /**
  14098. * The base implementation of `_.flatten` with support for restricting flattening.
  14099. *
  14100. * @private
  14101. * @param {Array} array The array to flatten.
  14102. * @param {number} depth The maximum recursion depth.
  14103. * @param {boolean} [predicate=isFlattenable] The function invoked per iteration.
  14104. * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks.
  14105. * @param {Array} [result=[]] The initial result value.
  14106. * @returns {Array} Returns the new flattened array.
  14107. */
  14108. function baseFlatten(array, depth, predicate, isStrict, result) {
  14109. var index = -1,
  14110. length = array.length;
  14111. predicate || (predicate = _isFlattenable);
  14112. result || (result = []);
  14113. while (++index < length) {
  14114. var value = array[index];
  14115. if (depth > 0 && predicate(value)) {
  14116. if (depth > 1) {
  14117. // Recursively flatten arrays (susceptible to call stack limits).
  14118. baseFlatten(value, depth - 1, predicate, isStrict, result);
  14119. } else {
  14120. _arrayPush(result, value);
  14121. }
  14122. } else if (!isStrict) {
  14123. result[result.length] = value;
  14124. }
  14125. }
  14126. return result;
  14127. }
  14128. var _baseFlatten = baseFlatten;
  14129. /**
  14130. * Flattens `array` a single level deep.
  14131. *
  14132. * @static
  14133. * @memberOf _
  14134. * @since 0.1.0
  14135. * @category Array
  14136. * @param {Array} array The array to flatten.
  14137. * @returns {Array} Returns the new flattened array.
  14138. * @example
  14139. *
  14140. * _.flatten([1, [2, [3, [4]], 5]]);
  14141. * // => [1, 2, [3, [4]], 5]
  14142. */
  14143. function flatten(array) {
  14144. var length = array == null ? 0 : array.length;
  14145. return length ? _baseFlatten(array, 1) : [];
  14146. }
  14147. var flatten_1 = flatten;
  14148. /**
  14149. * A faster alternative to `Function#apply`, this function invokes `func`
  14150. * with the `this` binding of `thisArg` and the arguments of `args`.
  14151. *
  14152. * @private
  14153. * @param {Function} func The function to invoke.
  14154. * @param {*} thisArg The `this` binding of `func`.
  14155. * @param {Array} args The arguments to invoke `func` with.
  14156. * @returns {*} Returns the result of `func`.
  14157. */
  14158. function apply(func, thisArg, args) {
  14159. switch (args.length) {
  14160. case 0:
  14161. return func.call(thisArg);
  14162. case 1:
  14163. return func.call(thisArg, args[0]);
  14164. case 2:
  14165. return func.call(thisArg, args[0], args[1]);
  14166. case 3:
  14167. return func.call(thisArg, args[0], args[1], args[2]);
  14168. }
  14169. return func.apply(thisArg, args);
  14170. }
  14171. var _apply = apply;
  14172. /* Built-in method references for those with the same name as other `lodash` methods. */
  14173. var nativeMax = Math.max;
  14174. /**
  14175. * A specialized version of `baseRest` which transforms the rest array.
  14176. *
  14177. * @private
  14178. * @param {Function} func The function to apply a rest parameter to.
  14179. * @param {number} [start=func.length-1] The start position of the rest parameter.
  14180. * @param {Function} transform The rest array transform.
  14181. * @returns {Function} Returns the new function.
  14182. */
  14183. function overRest(func, start, transform) {
  14184. start = nativeMax(start === undefined ? func.length - 1 : start, 0);
  14185. return function () {
  14186. var args = arguments,
  14187. index = -1,
  14188. length = nativeMax(args.length - start, 0),
  14189. array = Array(length);
  14190. while (++index < length) {
  14191. array[index] = args[start + index];
  14192. }
  14193. index = -1;
  14194. var otherArgs = Array(start + 1);
  14195. while (++index < start) {
  14196. otherArgs[index] = args[index];
  14197. }
  14198. otherArgs[start] = transform(array);
  14199. return _apply(func, this, otherArgs);
  14200. };
  14201. }
  14202. var _overRest = overRest;
  14203. /**
  14204. * Creates a function that returns `value`.
  14205. *
  14206. * @static
  14207. * @memberOf _
  14208. * @since 2.4.0
  14209. * @category Util
  14210. * @param {*} value The value to return from the new function.
  14211. * @returns {Function} Returns the new constant function.
  14212. * @example
  14213. *
  14214. * var objects = _.times(2, _.constant({ 'a': 1 }));
  14215. *
  14216. * console.log(objects);
  14217. * // => [{ 'a': 1 }, { 'a': 1 }]
  14218. *
  14219. * console.log(objects[0] === objects[1]);
  14220. * // => true
  14221. */
  14222. function constant$1(value) {
  14223. return function () {
  14224. return value;
  14225. };
  14226. }
  14227. var constant_1 = constant$1;
  14228. /**
  14229. * The base implementation of `setToString` without support for hot loop shorting.
  14230. *
  14231. * @private
  14232. * @param {Function} func The function to modify.
  14233. * @param {Function} string The `toString` result.
  14234. * @returns {Function} Returns `func`.
  14235. */
  14236. var baseSetToString = !_defineProperty ? identity_1 : function (func, string) {
  14237. return _defineProperty(func, 'toString', {
  14238. 'configurable': true,
  14239. 'enumerable': false,
  14240. 'value': constant_1(string),
  14241. 'writable': true
  14242. });
  14243. };
  14244. var _baseSetToString = baseSetToString;
  14245. /** Used to detect hot functions by number of calls within a span of milliseconds. */
  14246. var HOT_COUNT = 800,
  14247. HOT_SPAN = 16;
  14248. /* Built-in method references for those with the same name as other `lodash` methods. */
  14249. var nativeNow = Date.now;
  14250. /**
  14251. * Creates a function that'll short out and invoke `identity` instead
  14252. * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN`
  14253. * milliseconds.
  14254. *
  14255. * @private
  14256. * @param {Function} func The function to restrict.
  14257. * @returns {Function} Returns the new shortable function.
  14258. */
  14259. function shortOut(func) {
  14260. var count = 0,
  14261. lastCalled = 0;
  14262. return function () {
  14263. var stamp = nativeNow(),
  14264. remaining = HOT_SPAN - (stamp - lastCalled);
  14265. lastCalled = stamp;
  14266. if (remaining > 0) {
  14267. if (++count >= HOT_COUNT) {
  14268. return arguments[0];
  14269. }
  14270. } else {
  14271. count = 0;
  14272. }
  14273. return func.apply(undefined, arguments);
  14274. };
  14275. }
  14276. var _shortOut = shortOut;
  14277. /**
  14278. * Sets the `toString` method of `func` to return `string`.
  14279. *
  14280. * @private
  14281. * @param {Function} func The function to modify.
  14282. * @param {Function} string The `toString` result.
  14283. * @returns {Function} Returns `func`.
  14284. */
  14285. var setToString = _shortOut(_baseSetToString);
  14286. var _setToString = setToString;
  14287. /**
  14288. * A specialized version of `baseRest` which flattens the rest array.
  14289. *
  14290. * @private
  14291. * @param {Function} func The function to apply a rest parameter to.
  14292. * @returns {Function} Returns the new function.
  14293. */
  14294. function flatRest(func) {
  14295. return _setToString(_overRest(func, undefined, flatten_1), func + '');
  14296. }
  14297. var _flatRest = flatRest;
  14298. /**
  14299. * Creates an object composed of the picked `object` properties.
  14300. *
  14301. * @static
  14302. * @since 0.1.0
  14303. * @memberOf _
  14304. * @category Object
  14305. * @param {Object} object The source object.
  14306. * @param {...(string|string[])} [paths] The property paths to pick.
  14307. * @returns {Object} Returns the new object.
  14308. * @example
  14309. *
  14310. * var object = { 'a': 1, 'b': '2', 'c': 3 };
  14311. *
  14312. * _.pick(object, ['a', 'c']);
  14313. * // => { 'a': 1, 'c': 3 }
  14314. */
  14315. var pick = _flatRest(function (object, paths) {
  14316. return object == null ? {} : _basePick(object, paths);
  14317. });
  14318. var pick_1 = pick;
  14319. var lib = createCommonjsModule(function (module, exports) {
  14320. Object.defineProperty(exports, "__esModule", {
  14321. value: true
  14322. });
  14323. exports.outdent = void 0; // In the absence of a WeakSet or WeakMap implementation, don't break, but don't cache either.
  14324. function noop() {
  14325. var args = [];
  14326. for (var _i = 0; _i < arguments.length; _i++) {
  14327. args[_i] = arguments[_i];
  14328. }
  14329. }
  14330. function createWeakMap() {
  14331. if (typeof WeakMap !== "undefined") {
  14332. return new WeakMap();
  14333. } else {
  14334. return fakeSetOrMap();
  14335. }
  14336. }
  14337. /**
  14338. * Creates and returns a no-op implementation of a WeakMap / WeakSet that never stores anything.
  14339. */
  14340. function fakeSetOrMap() {
  14341. return {
  14342. add: noop,
  14343. delete: noop,
  14344. get: noop,
  14345. set: noop,
  14346. has: function (k) {
  14347. return false;
  14348. }
  14349. };
  14350. } // Safe hasOwnProperty
  14351. var hop = Object.prototype.hasOwnProperty;
  14352. var has = function (obj, prop) {
  14353. return hop.call(obj, prop);
  14354. }; // Copy all own enumerable properties from source to target
  14355. function extend(target, source) {
  14356. for (var prop in source) {
  14357. if (has(source, prop)) {
  14358. target[prop] = source[prop];
  14359. }
  14360. }
  14361. return target;
  14362. }
  14363. var reLeadingNewline = /^[ \t]*(?:\r\n|\r|\n)/;
  14364. var reTrailingNewline = /(?:\r\n|\r|\n)[ \t]*$/;
  14365. var reStartsWithNewlineOrIsEmpty = /^(?:[\r\n]|$)/;
  14366. var reDetectIndentation = /(?:\r\n|\r|\n)([ \t]*)(?:[^ \t\r\n]|$)/;
  14367. var reOnlyWhitespaceWithAtLeastOneNewline = /^[ \t]*[\r\n][ \t\r\n]*$/;
  14368. function _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options) {
  14369. // If first interpolated value is a reference to outdent,
  14370. // determine indentation level from the indentation of the interpolated value.
  14371. var indentationLevel = 0;
  14372. var match = strings[0].match(reDetectIndentation);
  14373. if (match) {
  14374. indentationLevel = match[1].length;
  14375. }
  14376. var reSource = "(\\r\\n|\\r|\\n).{0," + indentationLevel + "}";
  14377. var reMatchIndent = new RegExp(reSource, "g");
  14378. if (firstInterpolatedValueSetsIndentationLevel) {
  14379. strings = strings.slice(1);
  14380. }
  14381. var newline = options.newline,
  14382. trimLeadingNewline = options.trimLeadingNewline,
  14383. trimTrailingNewline = options.trimTrailingNewline;
  14384. var normalizeNewlines = typeof newline === "string";
  14385. var l = strings.length;
  14386. var outdentedStrings = strings.map(function (v, i) {
  14387. // Remove leading indentation from all lines
  14388. v = v.replace(reMatchIndent, "$1"); // Trim a leading newline from the first string
  14389. if (i === 0 && trimLeadingNewline) {
  14390. v = v.replace(reLeadingNewline, "");
  14391. } // Trim a trailing newline from the last string
  14392. if (i === l - 1 && trimTrailingNewline) {
  14393. v = v.replace(reTrailingNewline, "");
  14394. } // Normalize newlines
  14395. if (normalizeNewlines) {
  14396. v = v.replace(/\r\n|\n|\r/g, function (_) {
  14397. return newline;
  14398. });
  14399. }
  14400. return v;
  14401. });
  14402. return outdentedStrings;
  14403. }
  14404. function concatStringsAndValues(strings, values) {
  14405. var ret = "";
  14406. for (var i = 0, l = strings.length; i < l; i++) {
  14407. ret += strings[i];
  14408. if (i < l - 1) {
  14409. ret += values[i];
  14410. }
  14411. }
  14412. return ret;
  14413. }
  14414. function isTemplateStringsArray(v) {
  14415. return has(v, "raw") && has(v, "length");
  14416. }
  14417. /**
  14418. * It is assumed that opts will not change. If this is a problem, clone your options object and pass the clone to
  14419. * makeInstance
  14420. * @param options
  14421. * @return {outdent}
  14422. */
  14423. function createInstance(options) {
  14424. /** Cache of pre-processed template literal arrays */
  14425. var arrayAutoIndentCache = createWeakMap();
  14426. /**
  14427. * Cache of pre-processed template literal arrays, where first interpolated value is a reference to outdent,
  14428. * before interpolated values are injected.
  14429. */
  14430. var arrayFirstInterpSetsIndentCache = createWeakMap();
  14431. function outdent(stringsOrOptions) {
  14432. var values = [];
  14433. for (var _i = 1; _i < arguments.length; _i++) {
  14434. values[_i - 1] = arguments[_i];
  14435. }
  14436. /* tslint:enable:no-shadowed-variable */
  14437. if (isTemplateStringsArray(stringsOrOptions)) {
  14438. var strings = stringsOrOptions; // Is first interpolated value a reference to outdent, alone on its own line, without any preceding non-whitespace?
  14439. var firstInterpolatedValueSetsIndentationLevel = (values[0] === outdent || values[0] === defaultOutdent) && reOnlyWhitespaceWithAtLeastOneNewline.test(strings[0]) && reStartsWithNewlineOrIsEmpty.test(strings[1]); // Perform outdentation
  14440. var cache = firstInterpolatedValueSetsIndentationLevel ? arrayFirstInterpSetsIndentCache : arrayAutoIndentCache;
  14441. var renderedArray = cache.get(strings);
  14442. if (!renderedArray) {
  14443. renderedArray = _outdentArray(strings, firstInterpolatedValueSetsIndentationLevel, options);
  14444. cache.set(strings, renderedArray);
  14445. }
  14446. /** If no interpolated values, skip concatenation step */
  14447. if (values.length === 0) {
  14448. return renderedArray[0];
  14449. }
  14450. /** Concatenate string literals with interpolated values */
  14451. var rendered = concatStringsAndValues(renderedArray, firstInterpolatedValueSetsIndentationLevel ? values.slice(1) : values);
  14452. return rendered;
  14453. } else {
  14454. // Create and return a new instance of outdent with the given options
  14455. return createInstance(extend(extend({}, options), stringsOrOptions || {}));
  14456. }
  14457. }
  14458. var fullOutdent = extend(outdent, {
  14459. string: function (str) {
  14460. return _outdentArray([str], false, options)[0];
  14461. }
  14462. });
  14463. return fullOutdent;
  14464. }
  14465. var defaultOutdent = createInstance({
  14466. trimLeadingNewline: true,
  14467. trimTrailingNewline: true
  14468. });
  14469. exports.outdent = defaultOutdent; // Named exports. Simple and preferred.
  14470. // import outdent from 'outdent';
  14471. exports.default = defaultOutdent;
  14472. {
  14473. // In webpack harmony-modules environments, module.exports is read-only,
  14474. // so we fail gracefully.
  14475. try {
  14476. module.exports = defaultOutdent;
  14477. Object.defineProperty(defaultOutdent, "__esModule", {
  14478. value: true
  14479. });
  14480. defaultOutdent.default = defaultOutdent;
  14481. defaultOutdent.outdent = defaultOutdent;
  14482. } catch (e) {}
  14483. }
  14484. });
  14485. const {
  14486. outdent
  14487. } = lib;
  14488. const {
  14489. coreOptions: coreOptions$1
  14490. } = prettierInternal;
  14491. const categoryOrder = [coreOptions$1.CATEGORY_OUTPUT, coreOptions$1.CATEGORY_FORMAT, coreOptions$1.CATEGORY_CONFIG, coreOptions$1.CATEGORY_EDITOR, coreOptions$1.CATEGORY_OTHER];
  14492. /**
  14493. * {
  14494. * [optionName]: {
  14495. * // The type of the option. For 'choice', see also `choices` below.
  14496. * // When passing a type other than the ones listed below, the option is
  14497. * // treated as taking any string as argument, and `--option <${type}>` will
  14498. * // be displayed in --help.
  14499. * type: "boolean" | "choice" | "int" | string;
  14500. *
  14501. * // Default value to be passed to the minimist option `default`.
  14502. * default?: any;
  14503. *
  14504. * // Alias name to be passed to the minimist option `alias`.
  14505. * alias?: string;
  14506. *
  14507. * // For grouping options by category in --help.
  14508. * category?: string;
  14509. *
  14510. * // Description to be displayed in --help. If omitted, the option won't be
  14511. * // shown at all in --help (but see also `oppositeDescription` below).
  14512. * description?: string;
  14513. *
  14514. * // Description for `--no-${name}` to be displayed in --help. If omitted,
  14515. * // `--no-${name}` won't be shown.
  14516. * oppositeDescription?: string;
  14517. *
  14518. * // Indicate if this option is simply passed to the API.
  14519. * // true: use camelified name as the API option name.
  14520. * // string: use this value as the API option name.
  14521. * forwardToApi?: boolean | string;
  14522. *
  14523. * // Indicate that a CLI flag should be an array when forwarded to the API.
  14524. * array?: boolean;
  14525. *
  14526. * // Specify available choices for validation. They will also be displayed
  14527. * // in --help as <a|b|c>.
  14528. * // Use an object instead of a string if a choice is deprecated and should
  14529. * // be treated as `redirect` instead, or if you'd like to add description for
  14530. * // the choice.
  14531. * choices?: Array<
  14532. * | string
  14533. * | { value: string, description?: string, deprecated?: boolean, redirect?: string }
  14534. * >;
  14535. *
  14536. * // If the option has a value that is an exception to the regular value
  14537. * // constraints, indicate that value here (or use a function for more
  14538. * // flexibility).
  14539. * exception?: ((value: any) => boolean);
  14540. *
  14541. * // Indicate that the option is deprecated. Use a string to add an extra
  14542. * // message to --help for the option, for example to suggest a replacement
  14543. * // option.
  14544. * deprecated?: true | string;
  14545. * }
  14546. * }
  14547. *
  14548. * Note: The options below are sorted alphabetically.
  14549. */
  14550. const options = {
  14551. check: {
  14552. type: "boolean",
  14553. category: coreOptions$1.CATEGORY_OUTPUT,
  14554. alias: "c",
  14555. description: outdent`
  14556. Check if the given files are formatted, print a human-friendly summary
  14557. message and paths to unformatted files (see also --list-different).
  14558. `
  14559. },
  14560. color: {
  14561. // The supports-color package (a sub sub dependency) looks directly at
  14562. // `process.argv` for `--no-color` and such-like options. The reason it is
  14563. // listed here is to avoid "Ignored unknown option: --no-color" warnings.
  14564. // See https://github.com/chalk/supports-color/#info for more information.
  14565. type: "boolean",
  14566. default: true,
  14567. description: "Colorize error messages.",
  14568. oppositeDescription: "Do not colorize error messages."
  14569. },
  14570. config: {
  14571. type: "path",
  14572. category: coreOptions$1.CATEGORY_CONFIG,
  14573. description: "Path to a Prettier configuration file (.prettierrc, package.json, prettier.config.js).",
  14574. oppositeDescription: "Do not look for a configuration file.",
  14575. exception: value => value === false
  14576. },
  14577. "config-precedence": {
  14578. type: "choice",
  14579. category: coreOptions$1.CATEGORY_CONFIG,
  14580. default: "cli-override",
  14581. choices: [{
  14582. value: "cli-override",
  14583. description: "CLI options take precedence over config file"
  14584. }, {
  14585. value: "file-override",
  14586. description: "Config file take precedence over CLI options"
  14587. }, {
  14588. value: "prefer-file",
  14589. description: outdent`
  14590. If a config file is found will evaluate it and ignore other CLI options.
  14591. If no config file is found CLI options will evaluate as normal.
  14592. `
  14593. }],
  14594. description: "Define in which order config files and CLI options should be evaluated."
  14595. },
  14596. "debug-benchmark": {
  14597. // Run the formatting benchmarks. Requires 'benchmark' module to be installed.
  14598. type: "boolean"
  14599. },
  14600. "debug-check": {
  14601. // Run the formatting once again on the formatted output, throw if different.
  14602. type: "boolean"
  14603. },
  14604. "debug-print-doc": {
  14605. type: "boolean"
  14606. },
  14607. "debug-print-comments": {
  14608. type: "boolean"
  14609. },
  14610. "debug-print-ast": {
  14611. type: "boolean"
  14612. },
  14613. "debug-repeat": {
  14614. // Repeat the formatting a few times and measure the average duration.
  14615. type: "int",
  14616. default: 0
  14617. },
  14618. editorconfig: {
  14619. type: "boolean",
  14620. category: coreOptions$1.CATEGORY_CONFIG,
  14621. description: "Take .editorconfig into account when parsing configuration.",
  14622. oppositeDescription: "Don't take .editorconfig into account when parsing configuration.",
  14623. default: true
  14624. },
  14625. "error-on-unmatched-pattern": {
  14626. type: "boolean",
  14627. oppositeDescription: "Prevent errors when pattern is unmatched."
  14628. },
  14629. "find-config-path": {
  14630. type: "path",
  14631. category: coreOptions$1.CATEGORY_CONFIG,
  14632. description: "Find and print the path to a configuration file for the given input file."
  14633. },
  14634. "file-info": {
  14635. type: "path",
  14636. description: outdent`
  14637. Extract the following info (as JSON) for a given file path. Reported fields:
  14638. * ignored (boolean) - true if file path is filtered by --ignore-path
  14639. * inferredParser (string | null) - name of parser inferred from file path
  14640. `
  14641. },
  14642. help: {
  14643. type: "flag",
  14644. alias: "h",
  14645. description: outdent`
  14646. Show CLI usage, or details about the given flag.
  14647. Example: --help write
  14648. `,
  14649. exception: value => value === ""
  14650. },
  14651. "ignore-path": {
  14652. type: "path",
  14653. category: coreOptions$1.CATEGORY_CONFIG,
  14654. default: ".prettierignore",
  14655. description: "Path to a file with patterns describing files to ignore."
  14656. },
  14657. "ignore-unknown": {
  14658. type: "boolean",
  14659. alias: "u",
  14660. description: "Ignore unknown files."
  14661. },
  14662. "list-different": {
  14663. type: "boolean",
  14664. category: coreOptions$1.CATEGORY_OUTPUT,
  14665. alias: "l",
  14666. description: "Print the names of files that are different from Prettier's formatting (see also --check)."
  14667. },
  14668. loglevel: {
  14669. type: "choice",
  14670. description: "What level of logs to report.",
  14671. default: "log",
  14672. choices: ["silent", "error", "warn", "log", "debug"]
  14673. },
  14674. "support-info": {
  14675. type: "boolean",
  14676. description: "Print support information as JSON."
  14677. },
  14678. version: {
  14679. type: "boolean",
  14680. alias: "v",
  14681. description: "Print Prettier version."
  14682. },
  14683. "with-node-modules": {
  14684. type: "boolean",
  14685. category: coreOptions$1.CATEGORY_CONFIG,
  14686. description: "Process files inside 'node_modules' directory."
  14687. },
  14688. write: {
  14689. type: "boolean",
  14690. alias: "w",
  14691. category: coreOptions$1.CATEGORY_OUTPUT,
  14692. description: "Edit files in-place. (Beware!)"
  14693. }
  14694. };
  14695. const usageSummary = outdent`
  14696. Usage: prettier [options] [file/dir/glob ...]
  14697. By default, output is written to stdout.
  14698. Stdin is read if it is piped to Prettier and no files are given.
  14699. `;
  14700. var constant = {
  14701. categoryOrder,
  14702. options,
  14703. usageSummary
  14704. };
  14705. const {
  14706. coreOptions
  14707. } = prettierInternal;
  14708. function normalizeDetailedOption(name, option) {
  14709. return Object.assign(Object.assign({
  14710. category: coreOptions.CATEGORY_OTHER
  14711. }, option), {}, {
  14712. choices: option.choices && option.choices.map(choice => {
  14713. const newChoice = Object.assign({
  14714. description: "",
  14715. deprecated: false
  14716. }, typeof choice === "object" ? choice : {
  14717. value: choice
  14718. });
  14719. /* istanbul ignore next */
  14720. if (newChoice.value === true) {
  14721. newChoice.value = ""; // backward compatibility for original boolean option
  14722. }
  14723. return newChoice;
  14724. })
  14725. });
  14726. }
  14727. function normalizeDetailedOptionMap$2(detailedOptionMap) {
  14728. return Object.fromEntries(Object.entries(detailedOptionMap).sort(([leftName], [rightName]) => leftName.localeCompare(rightName)).map(([name, option]) => [name, normalizeDetailedOption(name, option)]));
  14729. }
  14730. function createDetailedOptionMap$2(supportOptions) {
  14731. return Object.fromEntries(supportOptions.map(option => {
  14732. const newOption = Object.assign(Object.assign({}, option), {}, {
  14733. name: option.cliName || dashify(option.name),
  14734. description: option.cliDescription || option.description,
  14735. category: option.cliCategory || coreOptions.CATEGORY_FORMAT,
  14736. forwardToApi: option.name
  14737. });
  14738. /* istanbul ignore next */
  14739. if (option.deprecated) {
  14740. delete newOption.forwardToApi;
  14741. delete newOption.description;
  14742. delete newOption.oppositeDescription;
  14743. newOption.deprecated = true;
  14744. }
  14745. return [newOption.name, newOption];
  14746. }));
  14747. }
  14748. var optionMap = {
  14749. normalizeDetailedOptionMap: normalizeDetailedOptionMap$2,
  14750. createDetailedOptionMap: createDetailedOptionMap$2
  14751. };
  14752. const {
  14753. optionsModule,
  14754. optionsNormalizer: {
  14755. normalizeCliOptions
  14756. },
  14757. utils: {
  14758. arrayify
  14759. }
  14760. } = prettierInternal;
  14761. const {
  14762. createDetailedOptionMap: createDetailedOptionMap$1,
  14763. normalizeDetailedOptionMap: normalizeDetailedOptionMap$1
  14764. } = optionMap;
  14765. /**
  14766. * @typedef {Object} Context
  14767. * @property logger
  14768. * @property {string[]} rawArguments
  14769. * @property argv
  14770. * @property {string[]} filePatterns
  14771. * @property {any[]} supportOptions
  14772. * @property detailedOptions
  14773. * @property detailedOptionMap
  14774. * @property apiDefaultOptions
  14775. * @property languages
  14776. * @property {Partial<Context>[]} stack
  14777. * @property pushContextPlugins
  14778. * @property popContextPlugins
  14779. */
  14780. class Context$1 {
  14781. constructor({
  14782. rawArguments,
  14783. logger
  14784. }) {
  14785. this.rawArguments = rawArguments;
  14786. this.logger = logger;
  14787. this.stack = [];
  14788. const {
  14789. plugin: plugins,
  14790. "plugin-search-dir": pluginSearchDirs
  14791. } = parseArgvWithoutPlugins$1(rawArguments, logger, ["plugin", "plugin-search-dir"]);
  14792. this.pushContextPlugins(plugins, pluginSearchDirs);
  14793. const argv = parseArgv(rawArguments, this.detailedOptions, logger);
  14794. this.argv = argv;
  14795. this.filePatterns = argv._.map(file => String(file));
  14796. }
  14797. /**
  14798. * @param {string[]} plugins
  14799. * @param {string[]=} pluginSearchDirs
  14800. */
  14801. pushContextPlugins(plugins, pluginSearchDirs) {
  14802. this.stack.push(pick_1(this, ["supportOptions", "detailedOptions", "detailedOptionMap", "apiDefaultOptions", "languages"]));
  14803. Object.assign(this, getContextOptions(plugins, pluginSearchDirs));
  14804. }
  14805. popContextPlugins() {
  14806. Object.assign(this, this.stack.pop());
  14807. }
  14808. }
  14809. function getContextOptions(plugins, pluginSearchDirs) {
  14810. const {
  14811. options: supportOptions,
  14812. languages
  14813. } = prettier$1.getSupportInfo({
  14814. showDeprecated: true,
  14815. showUnreleased: true,
  14816. showInternal: true,
  14817. plugins,
  14818. pluginSearchDirs
  14819. });
  14820. const detailedOptionMap = normalizeDetailedOptionMap$1(Object.assign(Object.assign({}, createDetailedOptionMap$1(supportOptions)), constant.options));
  14821. const detailedOptions = arrayify(detailedOptionMap, "name");
  14822. const apiDefaultOptions = Object.assign(Object.assign({}, optionsModule.hiddenDefaults), Object.fromEntries(supportOptions.filter(({
  14823. deprecated
  14824. }) => !deprecated).map(option => [option.name, option.default])));
  14825. return {
  14826. supportOptions,
  14827. detailedOptions,
  14828. detailedOptionMap,
  14829. apiDefaultOptions,
  14830. languages
  14831. };
  14832. }
  14833. function parseArgv(rawArguments, detailedOptions, logger, keys) {
  14834. const minimistOptions = createMinimistOptions(detailedOptions);
  14835. let argv = minimist_1(rawArguments, minimistOptions);
  14836. if (keys) {
  14837. detailedOptions = detailedOptions.filter(option => keys.includes(option.name));
  14838. argv = pick_1(argv, keys);
  14839. }
  14840. return normalizeCliOptions(argv, detailedOptions, {
  14841. logger
  14842. });
  14843. }
  14844. const detailedOptionsWithoutPlugins = getContextOptions().detailedOptions;
  14845. function parseArgvWithoutPlugins$1(rawArguments, logger, keys) {
  14846. return parseArgv(rawArguments, detailedOptionsWithoutPlugins, logger, typeof keys === "string" ? [keys] : keys);
  14847. }
  14848. var context = {
  14849. Context: Context$1,
  14850. parseArgvWithoutPlugins: parseArgvWithoutPlugins$1
  14851. };
  14852. // `Array.prototype.flat` method
  14853. // https://tc39.es/ecma262/#sec-array.prototype.flat
  14854. _export({ target: 'Array', proto: true }, {
  14855. flat: function flat(/* depthArg = 1 */) {
  14856. var depthArg = arguments.length ? arguments[0] : undefined;
  14857. var O = toObject(this);
  14858. var sourceLen = toLength(O.length);
  14859. var A = arraySpeciesCreate(O, 0);
  14860. A.length = flattenIntoArray_1(A, O, O, sourceLen, 0, depthArg === undefined ? 1 : toInteger(depthArg));
  14861. return A;
  14862. }
  14863. });
  14864. /** Used for built-in method references. */
  14865. var objectProto = Object.prototype;
  14866. /** Used to check objects for own properties. */
  14867. var hasOwnProperty = objectProto.hasOwnProperty;
  14868. /**
  14869. * Creates an object composed of keys generated from the results of running
  14870. * each element of `collection` thru `iteratee`. The order of grouped values
  14871. * is determined by the order they occur in `collection`. The corresponding
  14872. * value of each key is an array of elements responsible for generating the
  14873. * key. The iteratee is invoked with one argument: (value).
  14874. *
  14875. * @static
  14876. * @memberOf _
  14877. * @since 0.1.0
  14878. * @category Collection
  14879. * @param {Array|Object} collection The collection to iterate over.
  14880. * @param {Function} [iteratee=_.identity] The iteratee to transform keys.
  14881. * @returns {Object} Returns the composed aggregate object.
  14882. * @example
  14883. *
  14884. * _.groupBy([6.1, 4.2, 6.3], Math.floor);
  14885. * // => { '4': [4.2], '6': [6.1, 6.3] }
  14886. *
  14887. * // The `_.property` iteratee shorthand.
  14888. * _.groupBy(['one', 'two', 'three'], 'length');
  14889. * // => { '3': ['one', 'two'], '5': ['three'] }
  14890. */
  14891. var groupBy = _createAggregator(function (result, value, key) {
  14892. if (hasOwnProperty.call(result, key)) {
  14893. result[key].push(value);
  14894. } else {
  14895. _baseAssignValue(result, key, [value]);
  14896. }
  14897. });
  14898. var groupBy_1 = groupBy;
  14899. const preserveCamelCase = (string, locale) => {
  14900. let isLastCharLower = false;
  14901. let isLastCharUpper = false;
  14902. let isLastLastCharUpper = false;
  14903. for (let i = 0; i < string.length; i++) {
  14904. const character = string[i];
  14905. if (isLastCharLower && /[\p{Lu}]/u.test(character)) {
  14906. string = string.slice(0, i) + '-' + string.slice(i);
  14907. isLastCharLower = false;
  14908. isLastLastCharUpper = isLastCharUpper;
  14909. isLastCharUpper = true;
  14910. i++;
  14911. } else if (isLastCharUpper && isLastLastCharUpper && /[\p{Ll}]/u.test(character)) {
  14912. string = string.slice(0, i - 1) + '-' + string.slice(i - 1);
  14913. isLastLastCharUpper = isLastCharUpper;
  14914. isLastCharUpper = false;
  14915. isLastCharLower = true;
  14916. } else {
  14917. isLastCharLower = character.toLocaleLowerCase(locale) === character && character.toLocaleUpperCase(locale) !== character;
  14918. isLastLastCharUpper = isLastCharUpper;
  14919. isLastCharUpper = character.toLocaleUpperCase(locale) === character && character.toLocaleLowerCase(locale) !== character;
  14920. }
  14921. }
  14922. return string;
  14923. };
  14924. const preserveConsecutiveUppercase = input => {
  14925. return input.replace(/^[\p{Lu}](?![\p{Lu}])/gu, m1 => m1.toLowerCase());
  14926. };
  14927. const postProcess = (input, options) => {
  14928. return input.replace(/[_.\- ]+([\p{Alpha}\p{N}_]|$)/gu, (_, p1) => p1.toLocaleUpperCase(options.locale)).replace(/\d+([\p{Alpha}\p{N}_]|$)/gu, m => m.toLocaleUpperCase(options.locale));
  14929. };
  14930. const camelCase = (input, options) => {
  14931. if (!(typeof input === 'string' || Array.isArray(input))) {
  14932. throw new TypeError('Expected the input to be `string | string[]`');
  14933. }
  14934. options = Object.assign({
  14935. pascalCase: false,
  14936. preserveConsecutiveUppercase: false
  14937. }, options);
  14938. if (Array.isArray(input)) {
  14939. input = input.map(x => x.trim()).filter(x => x.length).join('-');
  14940. } else {
  14941. input = input.trim();
  14942. }
  14943. if (input.length === 0) {
  14944. return '';
  14945. }
  14946. if (input.length === 1) {
  14947. return options.pascalCase ? input.toLocaleUpperCase(options.locale) : input.toLocaleLowerCase(options.locale);
  14948. }
  14949. const hasUpperCase = input !== input.toLocaleLowerCase(options.locale);
  14950. if (hasUpperCase) {
  14951. input = preserveCamelCase(input, options.locale);
  14952. }
  14953. input = input.replace(/^[_.\- ]+/, '');
  14954. if (options.preserveConsecutiveUppercase) {
  14955. input = preserveConsecutiveUppercase(input);
  14956. } else {
  14957. input = input.toLocaleLowerCase();
  14958. }
  14959. if (options.pascalCase) {
  14960. input = input.charAt(0).toLocaleUpperCase(options.locale) + input.slice(1);
  14961. }
  14962. return postProcess(input, options);
  14963. };
  14964. var camelcase = camelCase; // TODO: Remove this for the next major release
  14965. var _default = camelCase;
  14966. camelcase.default = _default;
  14967. const OPTION_USAGE_THRESHOLD = 25;
  14968. const CHOICE_USAGE_MARGIN = 3;
  14969. const CHOICE_USAGE_INDENTATION = 2;
  14970. function indent(str, spaces) {
  14971. return str.replace(/^/gm, " ".repeat(spaces));
  14972. }
  14973. function createDefaultValueDisplay(value) {
  14974. return Array.isArray(value) ? `[${value.map(createDefaultValueDisplay).join(", ")}]` : value;
  14975. }
  14976. function getOptionDefaultValue(context, optionName) {
  14977. // --no-option
  14978. if (!(optionName in context.detailedOptionMap)) {
  14979. return;
  14980. }
  14981. const option = context.detailedOptionMap[optionName];
  14982. if (option.default !== undefined) {
  14983. return option.default;
  14984. }
  14985. const optionCamelName = camelcase(optionName);
  14986. if (optionCamelName in context.apiDefaultOptions) {
  14987. return context.apiDefaultOptions[optionCamelName];
  14988. }
  14989. }
  14990. function createOptionUsageHeader(option) {
  14991. const name = `--${option.name}`;
  14992. const alias = option.alias ? `-${option.alias},` : null;
  14993. const type = createOptionUsageType(option);
  14994. return [alias, name, type].filter(Boolean).join(" ");
  14995. }
  14996. function createOptionUsageRow(header, content, threshold) {
  14997. const separator = header.length >= threshold ? `\n${" ".repeat(threshold)}` : " ".repeat(threshold - header.length);
  14998. const description = content.replace(/\n/g, `\n${" ".repeat(threshold)}`);
  14999. return `${header}${separator}${description}`;
  15000. }
  15001. function createOptionUsageType(option) {
  15002. switch (option.type) {
  15003. case "boolean":
  15004. return null;
  15005. case "choice":
  15006. return `<${option.choices.filter(choice => !choice.deprecated && choice.since !== null).map(choice => choice.value).join("|")}>`;
  15007. default:
  15008. return `<${option.type}>`;
  15009. }
  15010. }
  15011. function createChoiceUsages(choices, margin, indentation) {
  15012. const activeChoices = choices.filter(choice => !choice.deprecated && choice.since !== null);
  15013. const threshold = Math.max(0, ...activeChoices.map(choice => choice.value.length)) + margin;
  15014. return activeChoices.map(choice => indent(createOptionUsageRow(choice.value, choice.description, threshold), indentation));
  15015. }
  15016. function createOptionUsage(context, option, threshold) {
  15017. const header = createOptionUsageHeader(option);
  15018. const optionDefaultValue = getOptionDefaultValue(context, option.name);
  15019. return createOptionUsageRow(header, `${option.description}${optionDefaultValue === undefined ? "" : `\nDefaults to ${createDefaultValueDisplay(optionDefaultValue)}.`}`, threshold);
  15020. }
  15021. function getOptionsWithOpposites(options) {
  15022. // Add --no-foo after --foo.
  15023. const optionsWithOpposites = options.map(option => [option.description ? option : null, option.oppositeDescription ? Object.assign(Object.assign({}, option), {}, {
  15024. name: `no-${option.name}`,
  15025. type: "boolean",
  15026. description: option.oppositeDescription
  15027. }) : null]);
  15028. return optionsWithOpposites.flat().filter(Boolean);
  15029. }
  15030. function createUsage$1(context) {
  15031. const options = getOptionsWithOpposites(context.detailedOptions).filter( // remove unnecessary option (e.g. `semi`, `color`, etc.), which is only used for --help <flag>
  15032. option => !(option.type === "boolean" && option.oppositeDescription && !option.name.startsWith("no-")));
  15033. const groupedOptions = groupBy_1(options, option => option.category);
  15034. const firstCategories = constant.categoryOrder.slice(0, -1);
  15035. const lastCategories = constant.categoryOrder.slice(-1);
  15036. const restCategories = Object.keys(groupedOptions).filter(category => !constant.categoryOrder.includes(category));
  15037. const allCategories = [...firstCategories, ...restCategories, ...lastCategories];
  15038. const optionsUsage = allCategories.map(category => {
  15039. const categoryOptions = groupedOptions[category].map(option => createOptionUsage(context, option, OPTION_USAGE_THRESHOLD)).join("\n");
  15040. return `${category} options:\n\n${indent(categoryOptions, 2)}`;
  15041. });
  15042. return [constant.usageSummary, ...optionsUsage, ""].join("\n\n");
  15043. }
  15044. function createDetailedUsage$1(context, flag) {
  15045. const option = getOptionsWithOpposites(context.detailedOptions).find(option => option.name === flag || option.alias === flag);
  15046. const header = createOptionUsageHeader(option);
  15047. const description = `\n\n${indent(option.description, 2)}`;
  15048. const choices = option.type !== "choice" ? "" : `\n\nValid options:\n\n${createChoiceUsages(option.choices, CHOICE_USAGE_MARGIN, CHOICE_USAGE_INDENTATION).join("\n")}`;
  15049. const optionDefaultValue = getOptionDefaultValue(context, option.name);
  15050. const defaults = optionDefaultValue !== undefined ? `\n\nDefault: ${createDefaultValueDisplay(optionDefaultValue)}` : "";
  15051. const pluginDefaults = option.pluginDefaults && Object.keys(option.pluginDefaults).length > 0 ? `\nPlugin defaults:${Object.entries(option.pluginDefaults).map(([key, value]) => `\n* ${key}: ${createDefaultValueDisplay(value)}`)}` : "";
  15052. return `${header}${description}${choices}${defaults}${pluginDefaults}`;
  15053. }
  15054. var usage = {
  15055. createUsage: createUsage$1,
  15056. createDetailedUsage: createDetailedUsage$1
  15057. };
  15058. var ansiRegex = ({
  15059. onlyFirst = false
  15060. } = {}) => {
  15061. const pattern = ['[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[-a-zA-Z\\d\\/#&.:=?%@~_]*)*)?\\u0007)', '(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PR-TZcf-ntqry=><~]))'].join('|');
  15062. return new RegExp(pattern, onlyFirst ? undefined : 'g');
  15063. };
  15064. var stripAnsi = string => typeof string === 'string' ? string.replace(ansiRegex(), '') : string;
  15065. var clone_1 = createCommonjsModule(function (module) {
  15066. var clone = function () {
  15067. /**
  15068. * Clones (copies) an Object using deep copying.
  15069. *
  15070. * This function supports circular references by default, but if you are certain
  15071. * there are no circular references in your object, you can save some CPU time
  15072. * by calling clone(obj, false).
  15073. *
  15074. * Caution: if `circular` is false and `parent` contains circular references,
  15075. * your program may enter an infinite loop and crash.
  15076. *
  15077. * @param `parent` - the object to be cloned
  15078. * @param `circular` - set to true if the object to be cloned may contain
  15079. * circular references. (optional - true by default)
  15080. * @param `depth` - set to a number if the object is only to be cloned to
  15081. * a particular depth. (optional - defaults to Infinity)
  15082. * @param `prototype` - sets the prototype to be used when cloning an object.
  15083. * (optional - defaults to parent prototype).
  15084. */
  15085. function clone(parent, circular, depth, prototype) {
  15086. if (typeof circular === 'object') {
  15087. depth = circular.depth;
  15088. prototype = circular.prototype;
  15089. circular = circular.circular;
  15090. } // maintain two arrays for circular references, where corresponding parents
  15091. // and children have the same index
  15092. var allParents = [];
  15093. var allChildren = [];
  15094. var useBuffer = typeof Buffer != 'undefined';
  15095. if (typeof circular == 'undefined') circular = true;
  15096. if (typeof depth == 'undefined') depth = Infinity; // recurse this function so we don't reset allParents and allChildren
  15097. function _clone(parent, depth) {
  15098. // cloning null always returns null
  15099. if (parent === null) return null;
  15100. if (depth == 0) return parent;
  15101. var child;
  15102. var proto;
  15103. if (typeof parent != 'object') {
  15104. return parent;
  15105. }
  15106. if (clone.__isArray(parent)) {
  15107. child = [];
  15108. } else if (clone.__isRegExp(parent)) {
  15109. child = new RegExp(parent.source, __getRegExpFlags(parent));
  15110. if (parent.lastIndex) child.lastIndex = parent.lastIndex;
  15111. } else if (clone.__isDate(parent)) {
  15112. child = new Date(parent.getTime());
  15113. } else if (useBuffer && Buffer.isBuffer(parent)) {
  15114. if (Buffer.allocUnsafe) {
  15115. // Node.js >= 4.5.0
  15116. child = Buffer.allocUnsafe(parent.length);
  15117. } else {
  15118. // Older Node.js versions
  15119. child = new Buffer(parent.length);
  15120. }
  15121. parent.copy(child);
  15122. return child;
  15123. } else {
  15124. if (typeof prototype == 'undefined') {
  15125. proto = Object.getPrototypeOf(parent);
  15126. child = Object.create(proto);
  15127. } else {
  15128. child = Object.create(prototype);
  15129. proto = prototype;
  15130. }
  15131. }
  15132. if (circular) {
  15133. var index = allParents.indexOf(parent);
  15134. if (index != -1) {
  15135. return allChildren[index];
  15136. }
  15137. allParents.push(parent);
  15138. allChildren.push(child);
  15139. }
  15140. for (var i in parent) {
  15141. var attrs;
  15142. if (proto) {
  15143. attrs = Object.getOwnPropertyDescriptor(proto, i);
  15144. }
  15145. if (attrs && attrs.set == null) {
  15146. continue;
  15147. }
  15148. child[i] = _clone(parent[i], depth - 1);
  15149. }
  15150. return child;
  15151. }
  15152. return _clone(parent, depth);
  15153. }
  15154. /**
  15155. * Simple flat clone using prototype, accepts only objects, usefull for property
  15156. * override on FLAT configuration object (no nested props).
  15157. *
  15158. * USE WITH CAUTION! This may not behave as you wish if you do not know how this
  15159. * works.
  15160. */
  15161. clone.clonePrototype = function clonePrototype(parent) {
  15162. if (parent === null) return null;
  15163. var c = function () {};
  15164. c.prototype = parent;
  15165. return new c();
  15166. }; // private utility functions
  15167. function __objToStr(o) {
  15168. return Object.prototype.toString.call(o);
  15169. }
  15170. clone.__objToStr = __objToStr;
  15171. function __isDate(o) {
  15172. return typeof o === 'object' && __objToStr(o) === '[object Date]';
  15173. }
  15174. clone.__isDate = __isDate;
  15175. function __isArray(o) {
  15176. return typeof o === 'object' && __objToStr(o) === '[object Array]';
  15177. }
  15178. clone.__isArray = __isArray;
  15179. function __isRegExp(o) {
  15180. return typeof o === 'object' && __objToStr(o) === '[object RegExp]';
  15181. }
  15182. clone.__isRegExp = __isRegExp;
  15183. function __getRegExpFlags(re) {
  15184. var flags = '';
  15185. if (re.global) flags += 'g';
  15186. if (re.ignoreCase) flags += 'i';
  15187. if (re.multiline) flags += 'm';
  15188. return flags;
  15189. }
  15190. clone.__getRegExpFlags = __getRegExpFlags;
  15191. return clone;
  15192. }();
  15193. if (module.exports) {
  15194. module.exports = clone;
  15195. }
  15196. });
  15197. var defaults = function (options, defaults) {
  15198. options = options || {};
  15199. Object.keys(defaults).forEach(function (key) {
  15200. if (typeof options[key] === 'undefined') {
  15201. options[key] = clone_1(defaults[key]);
  15202. }
  15203. });
  15204. return options;
  15205. };
  15206. var combining = [[0x0300, 0x036F], [0x0483, 0x0486], [0x0488, 0x0489], [0x0591, 0x05BD], [0x05BF, 0x05BF], [0x05C1, 0x05C2], [0x05C4, 0x05C5], [0x05C7, 0x05C7], [0x0600, 0x0603], [0x0610, 0x0615], [0x064B, 0x065E], [0x0670, 0x0670], [0x06D6, 0x06E4], [0x06E7, 0x06E8], [0x06EA, 0x06ED], [0x070F, 0x070F], [0x0711, 0x0711], [0x0730, 0x074A], [0x07A6, 0x07B0], [0x07EB, 0x07F3], [0x0901, 0x0902], [0x093C, 0x093C], [0x0941, 0x0948], [0x094D, 0x094D], [0x0951, 0x0954], [0x0962, 0x0963], [0x0981, 0x0981], [0x09BC, 0x09BC], [0x09C1, 0x09C4], [0x09CD, 0x09CD], [0x09E2, 0x09E3], [0x0A01, 0x0A02], [0x0A3C, 0x0A3C], [0x0A41, 0x0A42], [0x0A47, 0x0A48], [0x0A4B, 0x0A4D], [0x0A70, 0x0A71], [0x0A81, 0x0A82], [0x0ABC, 0x0ABC], [0x0AC1, 0x0AC5], [0x0AC7, 0x0AC8], [0x0ACD, 0x0ACD], [0x0AE2, 0x0AE3], [0x0B01, 0x0B01], [0x0B3C, 0x0B3C], [0x0B3F, 0x0B3F], [0x0B41, 0x0B43], [0x0B4D, 0x0B4D], [0x0B56, 0x0B56], [0x0B82, 0x0B82], [0x0BC0, 0x0BC0], [0x0BCD, 0x0BCD], [0x0C3E, 0x0C40], [0x0C46, 0x0C48], [0x0C4A, 0x0C4D], [0x0C55, 0x0C56], [0x0CBC, 0x0CBC], [0x0CBF, 0x0CBF], [0x0CC6, 0x0CC6], [0x0CCC, 0x0CCD], [0x0CE2, 0x0CE3], [0x0D41, 0x0D43], [0x0D4D, 0x0D4D], [0x0DCA, 0x0DCA], [0x0DD2, 0x0DD4], [0x0DD6, 0x0DD6], [0x0E31, 0x0E31], [0x0E34, 0x0E3A], [0x0E47, 0x0E4E], [0x0EB1, 0x0EB1], [0x0EB4, 0x0EB9], [0x0EBB, 0x0EBC], [0x0EC8, 0x0ECD], [0x0F18, 0x0F19], [0x0F35, 0x0F35], [0x0F37, 0x0F37], [0x0F39, 0x0F39], [0x0F71, 0x0F7E], [0x0F80, 0x0F84], [0x0F86, 0x0F87], [0x0F90, 0x0F97], [0x0F99, 0x0FBC], [0x0FC6, 0x0FC6], [0x102D, 0x1030], [0x1032, 0x1032], [0x1036, 0x1037], [0x1039, 0x1039], [0x1058, 0x1059], [0x1160, 0x11FF], [0x135F, 0x135F], [0x1712, 0x1714], [0x1732, 0x1734], [0x1752, 0x1753], [0x1772, 0x1773], [0x17B4, 0x17B5], [0x17B7, 0x17BD], [0x17C6, 0x17C6], [0x17C9, 0x17D3], [0x17DD, 0x17DD], [0x180B, 0x180D], [0x18A9, 0x18A9], [0x1920, 0x1922], [0x1927, 0x1928], [0x1932, 0x1932], [0x1939, 0x193B], [0x1A17, 0x1A18], [0x1B00, 0x1B03], [0x1B34, 0x1B34], [0x1B36, 0x1B3A], [0x1B3C, 0x1B3C], [0x1B42, 0x1B42], [0x1B6B, 0x1B73], [0x1DC0, 0x1DCA], [0x1DFE, 0x1DFF], [0x200B, 0x200F], [0x202A, 0x202E], [0x2060, 0x2063], [0x206A, 0x206F], [0x20D0, 0x20EF], [0x302A, 0x302F], [0x3099, 0x309A], [0xA806, 0xA806], [0xA80B, 0xA80B], [0xA825, 0xA826], [0xFB1E, 0xFB1E], [0xFE00, 0xFE0F], [0xFE20, 0xFE23], [0xFEFF, 0xFEFF], [0xFFF9, 0xFFFB], [0x10A01, 0x10A03], [0x10A05, 0x10A06], [0x10A0C, 0x10A0F], [0x10A38, 0x10A3A], [0x10A3F, 0x10A3F], [0x1D167, 0x1D169], [0x1D173, 0x1D182], [0x1D185, 0x1D18B], [0x1D1AA, 0x1D1AD], [0x1D242, 0x1D244], [0xE0001, 0xE0001], [0xE0020, 0xE007F], [0xE0100, 0xE01EF]];
  15207. var DEFAULTS = {
  15208. nul: 0,
  15209. control: 0
  15210. };
  15211. var wcwidth_1 = function wcwidth(str) {
  15212. return wcswidth(str, DEFAULTS);
  15213. };
  15214. var config = function (opts) {
  15215. opts = defaults(opts || {}, DEFAULTS);
  15216. return function wcwidth(str) {
  15217. return wcswidth(str, opts);
  15218. };
  15219. };
  15220. /*
  15221. * The following functions define the column width of an ISO 10646
  15222. * character as follows:
  15223. * - The null character (U+0000) has a column width of 0.
  15224. * - Other C0/C1 control characters and DEL will lead to a return value
  15225. * of -1.
  15226. * - Non-spacing and enclosing combining characters (general category
  15227. * code Mn or Me in the
  15228. * Unicode database) have a column width of 0.
  15229. * - SOFT HYPHEN (U+00AD) has a column width of 1.
  15230. * - Other format characters (general category code Cf in the Unicode
  15231. * database) and ZERO WIDTH
  15232. * SPACE (U+200B) have a column width of 0.
  15233. * - Hangul Jamo medial vowels and final consonants (U+1160-U+11FF)
  15234. * have a column width of 0.
  15235. * - Spacing characters in the East Asian Wide (W) or East Asian
  15236. * Full-width (F) category as
  15237. * defined in Unicode Technical Report #11 have a column width of 2.
  15238. * - All remaining characters (including all printable ISO 8859-1 and
  15239. * WGL4 characters, Unicode control characters, etc.) have a column
  15240. * width of 1.
  15241. * This implementation assumes that characters are encoded in ISO 10646.
  15242. */
  15243. function wcswidth(str, opts) {
  15244. if (typeof str !== 'string') return wcwidth(str, opts);
  15245. var s = 0;
  15246. for (var i = 0; i < str.length; i++) {
  15247. var n = wcwidth(str.charCodeAt(i), opts);
  15248. if (n < 0) return -1;
  15249. s += n;
  15250. }
  15251. return s;
  15252. }
  15253. function wcwidth(ucs, opts) {
  15254. // test for 8-bit control characters
  15255. if (ucs === 0) return opts.nul;
  15256. if (ucs < 32 || ucs >= 0x7f && ucs < 0xa0) return opts.control; // binary search in table of non-spacing characters
  15257. if (bisearch(ucs)) return 0; // if we arrive here, ucs is not a combining or C0/C1 control character
  15258. return 1 + (ucs >= 0x1100 && (ucs <= 0x115f || // Hangul Jamo init. consonants
  15259. ucs == 0x2329 || ucs == 0x232a || ucs >= 0x2e80 && ucs <= 0xa4cf && ucs != 0x303f || ucs >= 0xac00 && ucs <= 0xd7a3 || ucs >= 0xf900 && ucs <= 0xfaff || ucs >= 0xfe10 && ucs <= 0xfe19 || ucs >= 0xfe30 && ucs <= 0xfe6f || ucs >= 0xff00 && ucs <= 0xff60 || ucs >= 0xffe0 && ucs <= 0xffe6 || ucs >= 0x20000 && ucs <= 0x2fffd || ucs >= 0x30000 && ucs <= 0x3fffd));
  15260. }
  15261. function bisearch(ucs) {
  15262. var min = 0;
  15263. var max = combining.length - 1;
  15264. var mid;
  15265. if (ucs < combining[0][0] || ucs > combining[max][1]) return false;
  15266. while (max >= min) {
  15267. mid = Math.floor((min + max) / 2);
  15268. if (ucs > combining[mid][1]) min = mid + 1;else if (ucs < combining[mid][0]) max = mid - 1;else return true;
  15269. }
  15270. return false;
  15271. }
  15272. wcwidth_1.config = config;
  15273. const countLines = (stream, text) => {
  15274. const columns = stream.columns || 80;
  15275. let lineCount = 0;
  15276. for (const line of stripAnsi(text).split("\n")) {
  15277. lineCount += Math.max(1, Math.ceil(wcwidth_1(line) / columns));
  15278. }
  15279. return lineCount;
  15280. };
  15281. const clear = (stream, text) => () => {
  15282. const lineCount = countLines(stream, text);
  15283. for (let line = 0; line < lineCount; line++) {
  15284. if (line > 0) {
  15285. readline__default['default'].moveCursor(stream, 0, -1);
  15286. }
  15287. readline__default['default'].clearLine(stream, 0);
  15288. readline__default['default'].cursorTo(stream, 0);
  15289. }
  15290. };
  15291. const emptyLogResult = {
  15292. clear() {}
  15293. };
  15294. function createLogger$1(logLevel = "log") {
  15295. return {
  15296. logLevel,
  15297. warn: createLogFunc("warn", "yellow"),
  15298. error: createLogFunc("error", "red"),
  15299. debug: createLogFunc("debug", "blue"),
  15300. log: createLogFunc("log")
  15301. };
  15302. function createLogFunc(loggerName, color) {
  15303. if (!shouldLog(loggerName)) {
  15304. return () => emptyLogResult;
  15305. }
  15306. const prefix = color ? `[${source[color](loggerName)}] ` : "";
  15307. const stream = process[loggerName === "log" ? "stdout" : "stderr"];
  15308. return (message, options) => {
  15309. options = Object.assign({
  15310. newline: true,
  15311. clearable: false
  15312. }, options);
  15313. message = message.replace(/^/gm, prefix) + (options.newline ? "\n" : "");
  15314. stream.write(message);
  15315. if (options.clearable) {
  15316. return {
  15317. clear: clear(stream, message)
  15318. };
  15319. }
  15320. };
  15321. }
  15322. function shouldLog(loggerName) {
  15323. switch (logLevel) {
  15324. case "silent":
  15325. return false;
  15326. case "debug":
  15327. if (loggerName === "debug") {
  15328. return true;
  15329. }
  15330. // fall through
  15331. case "log":
  15332. if (loggerName === "log") {
  15333. return true;
  15334. }
  15335. // fall through
  15336. case "warn":
  15337. if (loggerName === "warn") {
  15338. return true;
  15339. }
  15340. // fall through
  15341. case "error":
  15342. return loggerName === "error";
  15343. }
  15344. }
  15345. }
  15346. var logger = {
  15347. createLogger: createLogger$1
  15348. };
  15349. const {
  15350. format,
  15351. formatStdin,
  15352. formatFiles
  15353. } = format_1;
  15354. const {
  15355. Context,
  15356. parseArgvWithoutPlugins
  15357. } = context;
  15358. const {
  15359. normalizeDetailedOptionMap,
  15360. createDetailedOptionMap
  15361. } = optionMap;
  15362. const {
  15363. createDetailedUsage,
  15364. createUsage
  15365. } = usage;
  15366. const {
  15367. createLogger
  15368. } = logger;
  15369. async function logResolvedConfigPathOrDie(context) {
  15370. const file = context.argv["find-config-path"];
  15371. const configFile = await prettier$1.resolveConfigFile(file);
  15372. if (configFile) {
  15373. context.logger.log(path__default['default'].relative(process.cwd(), configFile));
  15374. } else {
  15375. throw new Error(`Can not find configure file for "${file}"`);
  15376. }
  15377. }
  15378. async function logFileInfoOrDie(context) {
  15379. const options = {
  15380. ignorePath: context.argv["ignore-path"],
  15381. withNodeModules: context.argv["with-node-modules"],
  15382. plugins: context.argv.plugin,
  15383. pluginSearchDirs: context.argv["plugin-search-dir"],
  15384. resolveConfig: context.argv.config !== false
  15385. };
  15386. context.logger.log(prettier$1.format(fastJsonStableStringify(await prettier$1.getFileInfo(context.argv["file-info"], options)), {
  15387. parser: "json"
  15388. }));
  15389. }
  15390. var core = {
  15391. Context,
  15392. createDetailedOptionMap,
  15393. createDetailedUsage,
  15394. createUsage,
  15395. format,
  15396. formatFiles,
  15397. formatStdin,
  15398. logResolvedConfigPathOrDie,
  15399. logFileInfoOrDie,
  15400. normalizeDetailedOptionMap,
  15401. parseArgvWithoutPlugins,
  15402. createLogger
  15403. };
  15404. pleaseUpgradeNode(packageJson); // eslint-disable-next-line import/order
  15405. // eslint-disable-next-line no-restricted-modules
  15406. async function run(rawArguments) {
  15407. // Create a default level logger, so we can log errors during `logLevel` parsing
  15408. let logger = core.createLogger();
  15409. try {
  15410. const logLevel = core.parseArgvWithoutPlugins(rawArguments, logger, "loglevel").loglevel;
  15411. if (logLevel !== logger.logLevel) {
  15412. logger = core.createLogger(logLevel);
  15413. }
  15414. await main(rawArguments, logger);
  15415. } catch (error) {
  15416. logger.error(error.message);
  15417. process.exitCode = 1;
  15418. }
  15419. }
  15420. async function main(rawArguments, logger) {
  15421. const context = new core.Context({
  15422. rawArguments,
  15423. logger
  15424. });
  15425. logger.debug(`normalized argv: ${JSON.stringify(context.argv)}`);
  15426. if (context.argv.check && context.argv["list-different"]) {
  15427. throw new Error("Cannot use --check and --list-different together.");
  15428. }
  15429. if (context.argv.write && context.argv["debug-check"]) {
  15430. throw new Error("Cannot use --write and --debug-check together.");
  15431. }
  15432. if (context.argv["find-config-path"] && context.filePatterns.length > 0) {
  15433. throw new Error("Cannot use --find-config-path with multiple files");
  15434. }
  15435. if (context.argv["file-info"] && context.filePatterns.length > 0) {
  15436. throw new Error("Cannot use --file-info with multiple files");
  15437. }
  15438. if (context.argv.version) {
  15439. logger.log(prettier$1.version);
  15440. return;
  15441. }
  15442. if (context.argv.help !== undefined) {
  15443. logger.log(typeof context.argv.help === "string" && context.argv.help !== "" ? core.createDetailedUsage(context, context.argv.help) : core.createUsage(context));
  15444. return;
  15445. }
  15446. if (context.argv["support-info"]) {
  15447. logger.log(prettier$1.format(fastJsonStableStringify(prettier$1.getSupportInfo()), {
  15448. parser: "json"
  15449. }));
  15450. return;
  15451. }
  15452. const hasFilePatterns = context.filePatterns.length > 0;
  15453. const useStdin = !hasFilePatterns && (!process.stdin.isTTY || context.argv["stdin-filepath"]);
  15454. if (context.argv["find-config-path"]) {
  15455. await core.logResolvedConfigPathOrDie(context);
  15456. } else if (context.argv["file-info"]) {
  15457. await core.logFileInfoOrDie(context);
  15458. } else if (useStdin) {
  15459. await core.formatStdin(context);
  15460. } else if (hasFilePatterns) {
  15461. await core.formatFiles(context);
  15462. } else {
  15463. logger.log(core.createUsage(context));
  15464. process.exitCode = 1;
  15465. }
  15466. }
  15467. var cli = {
  15468. run
  15469. };
  15470. var prettier = cli.run(process.argv.slice(2));
  15471. module.exports = prettier;