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.

third-party.js 309KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228112291123011231112321123311234112351123611237112381123911240112411124211243112441124511246112471124811249112501125111252112531125411255112561125711258112591126011261112621126311264112651126611267112681126911270112711127211273112741127511276112771127811279112801128111282112831128411285112861128711288112891129011291112921129311294112951129611297112981129911300113011130211303113041130511306113071130811309113101131111312113131131411315113161131711318113191132011321113221132311324113251132611327113281132911330113311133211333113341133511336113371133811339113401134111342113431134411345113461134711348
  1. 'use strict';
  2. var os = require('os');
  3. var path = require('path');
  4. var Module = require('module');
  5. var fs = require('fs');
  6. var util = require('util');
  7. function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
  8. var os__default = /*#__PURE__*/_interopDefaultLegacy(os);
  9. var path__default = /*#__PURE__*/_interopDefaultLegacy(path);
  10. var Module__default = /*#__PURE__*/_interopDefaultLegacy(Module);
  11. var fs__default = /*#__PURE__*/_interopDefaultLegacy(fs);
  12. var util__default = /*#__PURE__*/_interopDefaultLegacy(util);
  13. function createCommonjsModule(fn) {
  14. var module = { exports: {} };
  15. return fn(module, module.exports), module.exports;
  16. }
  17. const resolveFrom = (fromDir, moduleId, silent) => {
  18. if (typeof fromDir !== 'string') {
  19. throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDir}\``);
  20. }
  21. if (typeof moduleId !== 'string') {
  22. throw new TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof moduleId}\``);
  23. }
  24. try {
  25. fromDir = fs__default['default'].realpathSync(fromDir);
  26. } catch (err) {
  27. if (err.code === 'ENOENT') {
  28. fromDir = path__default['default'].resolve(fromDir);
  29. } else if (silent) {
  30. return null;
  31. } else {
  32. throw err;
  33. }
  34. }
  35. const fromFile = path__default['default'].join(fromDir, 'noop.js');
  36. const resolveFileName = () => Module__default['default']._resolveFilename(moduleId, {
  37. id: fromFile,
  38. filename: fromFile,
  39. paths: Module__default['default']._nodeModulePaths(fromDir)
  40. });
  41. if (silent) {
  42. try {
  43. return resolveFileName();
  44. } catch (err) {
  45. return null;
  46. }
  47. }
  48. return resolveFileName();
  49. };
  50. var resolveFrom_1 = (fromDir, moduleId) => resolveFrom(fromDir, moduleId);
  51. var silent = (fromDir, moduleId) => resolveFrom(fromDir, moduleId, true);
  52. resolveFrom_1.silent = silent;
  53. var importFresh = moduleId => {
  54. if (typeof moduleId !== 'string') {
  55. throw new TypeError('Expected a string');
  56. }
  57. const parentPath = __filename;
  58. const cwd = parentPath ? path__default['default'].dirname(parentPath) : __dirname;
  59. const filePath = resolveFrom_1(cwd, moduleId);
  60. const oldModule = require.cache[filePath]; // Delete itself from module parent
  61. if (oldModule && oldModule.parent) {
  62. let i = oldModule.parent.children.length;
  63. while (i--) {
  64. if (oldModule.parent.children[i].id === filePath) {
  65. oldModule.parent.children.splice(i, 1);
  66. }
  67. }
  68. }
  69. delete require.cache[filePath]; // Delete module from cache
  70. const parent = require.cache[parentPath]; // If `filePath` and `parentPath` are the same, cache will already be deleted so we won't get a memory leak in next step
  71. return parent === undefined ? require(filePath) : parent.require(filePath); // In case cache doesn't have parent, fall back to normal require
  72. };
  73. var isArrayish = function isArrayish(obj) {
  74. if (!obj) {
  75. return false;
  76. }
  77. return obj instanceof Array || Array.isArray(obj) || obj.length >= 0 && obj.splice instanceof Function;
  78. };
  79. var errorEx = function errorEx(name, properties) {
  80. if (!name || name.constructor !== String) {
  81. properties = name || {};
  82. name = Error.name;
  83. }
  84. var errorExError = function ErrorEXError(message) {
  85. if (!this) {
  86. return new ErrorEXError(message);
  87. }
  88. message = message instanceof Error ? message.message : message || this.message;
  89. Error.call(this, message);
  90. Error.captureStackTrace(this, errorExError);
  91. this.name = name;
  92. Object.defineProperty(this, 'message', {
  93. configurable: true,
  94. enumerable: false,
  95. get: function () {
  96. var newMessage = message.split(/\r?\n/g);
  97. for (var key in properties) {
  98. if (!properties.hasOwnProperty(key)) {
  99. continue;
  100. }
  101. var modifier = properties[key];
  102. if ('message' in modifier) {
  103. newMessage = modifier.message(this[key], newMessage) || newMessage;
  104. if (!isArrayish(newMessage)) {
  105. newMessage = [newMessage];
  106. }
  107. }
  108. }
  109. return newMessage.join('\n');
  110. },
  111. set: function (v) {
  112. message = v;
  113. }
  114. });
  115. var overwrittenStack = null;
  116. var stackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack');
  117. var stackGetter = stackDescriptor.get;
  118. var stackValue = stackDescriptor.value;
  119. delete stackDescriptor.value;
  120. delete stackDescriptor.writable;
  121. stackDescriptor.set = function (newstack) {
  122. overwrittenStack = newstack;
  123. };
  124. stackDescriptor.get = function () {
  125. var stack = (overwrittenStack || (stackGetter ? stackGetter.call(this) : stackValue)).split(/\r?\n+/g); // starting in Node 7, the stack builder caches the message.
  126. // just replace it.
  127. if (!overwrittenStack) {
  128. stack[0] = this.name + ': ' + this.message;
  129. }
  130. var lineCount = 1;
  131. for (var key in properties) {
  132. if (!properties.hasOwnProperty(key)) {
  133. continue;
  134. }
  135. var modifier = properties[key];
  136. if ('line' in modifier) {
  137. var line = modifier.line(this[key]);
  138. if (line) {
  139. stack.splice(lineCount++, 0, ' ' + line);
  140. }
  141. }
  142. if ('stack' in modifier) {
  143. modifier.stack(this[key], stack);
  144. }
  145. }
  146. return stack.join('\n');
  147. };
  148. Object.defineProperty(this, 'stack', stackDescriptor);
  149. };
  150. if (Object.setPrototypeOf) {
  151. Object.setPrototypeOf(errorExError.prototype, Error.prototype);
  152. Object.setPrototypeOf(errorExError, Error);
  153. } else {
  154. util__default['default'].inherits(errorExError, Error);
  155. }
  156. return errorExError;
  157. };
  158. errorEx.append = function (str, def) {
  159. return {
  160. message: function (v, message) {
  161. v = v || def;
  162. if (v) {
  163. message[0] += ' ' + str.replace('%s', v.toString());
  164. }
  165. return message;
  166. }
  167. };
  168. };
  169. errorEx.line = function (str, def) {
  170. return {
  171. line: function (v) {
  172. v = v || def;
  173. if (v) {
  174. return str.replace('%s', v.toString());
  175. }
  176. return null;
  177. }
  178. };
  179. };
  180. var errorEx_1 = errorEx;
  181. const hexify = char => {
  182. const h = char.charCodeAt(0).toString(16).toUpperCase();
  183. return '0x' + (h.length % 2 ? '0' : '') + h;
  184. };
  185. const parseError = (e, txt, context) => {
  186. if (!txt) {
  187. return {
  188. message: e.message + ' while parsing empty string',
  189. position: 0
  190. };
  191. }
  192. const badToken = e.message.match(/^Unexpected token (.) .*position\s+(\d+)/i);
  193. const errIdx = badToken ? +badToken[2] : e.message.match(/^Unexpected end of JSON.*/i) ? txt.length - 1 : null;
  194. const msg = badToken ? e.message.replace(/^Unexpected token ./, `Unexpected token ${JSON.stringify(badToken[1])} (${hexify(badToken[1])})`) : e.message;
  195. if (errIdx !== null && errIdx !== undefined) {
  196. const start = errIdx <= context ? 0 : errIdx - context;
  197. const end = errIdx + context >= txt.length ? txt.length : errIdx + context;
  198. const slice = (start === 0 ? '' : '...') + txt.slice(start, end) + (end === txt.length ? '' : '...');
  199. const near = txt === slice ? '' : 'near ';
  200. return {
  201. message: msg + ` while parsing ${near}${JSON.stringify(slice)}`,
  202. position: errIdx
  203. };
  204. } else {
  205. return {
  206. message: msg + ` while parsing '${txt.slice(0, context * 2)}'`,
  207. position: 0
  208. };
  209. }
  210. };
  211. class JSONParseError extends SyntaxError {
  212. constructor(er, txt, context, caller) {
  213. context = context || 20;
  214. const metadata = parseError(er, txt, context);
  215. super(metadata.message);
  216. Object.assign(this, metadata);
  217. this.code = 'EJSONPARSE';
  218. this.systemError = er;
  219. Error.captureStackTrace(this, caller || this.constructor);
  220. }
  221. get name() {
  222. return this.constructor.name;
  223. }
  224. set name(n) {}
  225. get [Symbol.toStringTag]() {
  226. return this.constructor.name;
  227. }
  228. }
  229. const kIndent = Symbol.for('indent');
  230. const kNewline = Symbol.for('newline'); // only respect indentation if we got a line break, otherwise squash it
  231. // things other than objects and arrays aren't indented, so ignore those
  232. // Important: in both of these regexps, the $1 capture group is the newline
  233. // or undefined, and the $2 capture group is the indent, or undefined.
  234. const formatRE = /^\s*[{\[]((?:\r?\n)+)([\s\t]*)/;
  235. const emptyRE = /^(?:\{\}|\[\])((?:\r?\n)+)?$/;
  236. const parseJson$1 = (txt, reviver, context) => {
  237. const parseText = stripBOM(txt);
  238. context = context || 20;
  239. try {
  240. // get the indentation so that we can save it back nicely
  241. // if the file starts with {" then we have an indent of '', ie, none
  242. // otherwise, pick the indentation of the next line after the first \n
  243. // If the pattern doesn't match, then it means no indentation.
  244. // JSON.stringify ignores symbols, so this is reasonably safe.
  245. // if the string is '{}' or '[]', then use the default 2-space indent.
  246. const [, newline = '\n', indent = ' '] = parseText.match(emptyRE) || parseText.match(formatRE) || [, '', ''];
  247. const result = JSON.parse(parseText, reviver);
  248. if (result && typeof result === 'object') {
  249. result[kNewline] = newline;
  250. result[kIndent] = indent;
  251. }
  252. return result;
  253. } catch (e) {
  254. if (typeof txt !== 'string' && !Buffer.isBuffer(txt)) {
  255. const isEmptyArray = Array.isArray(txt) && txt.length === 0;
  256. throw Object.assign(new TypeError(`Cannot parse ${isEmptyArray ? 'an empty array' : String(txt)}`), {
  257. code: 'EJSONPARSE',
  258. systemError: e
  259. });
  260. }
  261. throw new JSONParseError(e, parseText, context, parseJson$1);
  262. }
  263. }; // Remove byte order marker. This catches EF BB BF (the UTF-8 BOM)
  264. // because the buffer-to-string conversion in `fs.readFileSync()`
  265. // translates it to FEFF, the UTF-16 BOM.
  266. const stripBOM = txt => String(txt).replace(/^\uFEFF/, '');
  267. var jsonParseEvenBetterErrors = parseJson$1;
  268. parseJson$1.JSONParseError = JSONParseError;
  269. parseJson$1.noExceptions = (txt, reviver) => {
  270. try {
  271. return JSON.parse(stripBOM(txt), reviver);
  272. } catch (e) {}
  273. };
  274. var dist$2 = createCommonjsModule(function (module, exports) {
  275. var LF = '\n';
  276. var CR = '\r';
  277. var LinesAndColumns = function () {
  278. function LinesAndColumns(string) {
  279. this.string = string;
  280. var offsets = [0];
  281. for (var offset = 0; offset < string.length;) {
  282. switch (string[offset]) {
  283. case LF:
  284. offset += LF.length;
  285. offsets.push(offset);
  286. break;
  287. case CR:
  288. offset += CR.length;
  289. if (string[offset] === LF) {
  290. offset += LF.length;
  291. }
  292. offsets.push(offset);
  293. break;
  294. default:
  295. offset++;
  296. break;
  297. }
  298. }
  299. this.offsets = offsets;
  300. }
  301. LinesAndColumns.prototype.locationForIndex = function (index) {
  302. if (index < 0 || index > this.string.length) {
  303. return null;
  304. }
  305. var line = 0;
  306. var offsets = this.offsets;
  307. while (offsets[line + 1] <= index) {
  308. line++;
  309. }
  310. var column = index - offsets[line];
  311. return {
  312. line: line,
  313. column: column
  314. };
  315. };
  316. LinesAndColumns.prototype.indexForLocation = function (location) {
  317. var line = location.line,
  318. column = location.column;
  319. if (line < 0 || line >= this.offsets.length) {
  320. return null;
  321. }
  322. if (column < 0 || column > this.lengthOfLine(line)) {
  323. return null;
  324. }
  325. return this.offsets[line] + column;
  326. };
  327. LinesAndColumns.prototype.lengthOfLine = function (line) {
  328. var offset = this.offsets[line];
  329. var nextOffset = line === this.offsets.length - 1 ? this.string.length : this.offsets[line + 1];
  330. return nextOffset - offset;
  331. };
  332. return LinesAndColumns;
  333. }();
  334. exports.__esModule = true;
  335. exports["default"] = LinesAndColumns;
  336. });
  337. // Copyright 2014, 2015, 2016, 2017, 2018 Simon Lydell
  338. // License: MIT. (See LICENSE.)
  339. // This regex comes from regex.coffee, and is inserted here by generate-index.js
  340. // (run `npm run build`).
  341. var _default$2 = /((['"])(?:(?!\2|\\).|\\(?:\r\n|[\s\S]))*(\2)?|`(?:[^`\\$]|\\[\s\S]|\$(?!\{)|\$\{(?:[^{}]|\{[^}]*\}?)*\}?)*(`)?)|(\/\/.*)|(\/\*(?:[^*]|\*(?!\/))*(\*\/)?)|(\/(?!\*)(?:\[(?:(?![\]\\]).|\\.)*\]|(?![\/\]\\]).|\\.)+\/(?:(?!\s*(?:\b|[\u0080-\uFFFF$\\'"~({]|[+\-!](?!=)|\.?\d))|[gmiyus]{1,6}\b(?![\u0080-\uFFFF$\\]|\s*(?:[+\-*%&|^<>!=?({]|\/(?![\/*])))))|(0[xX][\da-fA-F]+|0[oO][0-7]+|0[bB][01]+|(?:\d*\.\d+|\d+\.?)(?:[eE][+-]?\d+)?)|((?!\d)(?:(?!\s)[$\w\u0080-\uFFFF]|\\u[\da-fA-F]{4}|\\u\{[\da-fA-F]+\})+)|(--|\+\+|&&|\|\||=>|\.{3}|(?:[+\-\/%&|^]|\*{1,2}|<{1,2}|>{1,3}|!=?|={1,2})=?|[?~.,:;[\](){}])|(\s+)|(^$|[\s\S])/g;
  342. var matchToToken = function (match) {
  343. var token = {
  344. type: "invalid",
  345. value: match[0],
  346. closed: undefined
  347. };
  348. if (match[1]) token.type = "string", token.closed = !!(match[3] || match[4]);else if (match[5]) token.type = "comment";else if (match[6]) token.type = "comment", token.closed = !!match[7];else if (match[8]) token.type = "regex";else if (match[9]) token.type = "number";else if (match[10]) token.type = "name";else if (match[11]) token.type = "punctuator";else if (match[12]) token.type = "whitespace";
  349. return token;
  350. };
  351. var jsTokens = /*#__PURE__*/Object.defineProperty({
  352. default: _default$2,
  353. matchToToken: matchToToken
  354. }, '__esModule', {
  355. value: true
  356. });
  357. var isIdentifierStart_1 = isIdentifierStart;
  358. var isIdentifierChar_1 = isIdentifierChar;
  359. var isIdentifierName_1 = isIdentifierName;
  360. let nonASCIIidentifierStartChars = "\xaa\xb5\xba\xc0-\xd6\xd8-\xf6\xf8-\u02c1\u02c6-\u02d1\u02e0-\u02e4\u02ec\u02ee\u0370-\u0374\u0376\u0377\u037a-\u037d\u037f\u0386\u0388-\u038a\u038c\u038e-\u03a1\u03a3-\u03f5\u03f7-\u0481\u048a-\u052f\u0531-\u0556\u0559\u0560-\u0588\u05d0-\u05ea\u05ef-\u05f2\u0620-\u064a\u066e\u066f\u0671-\u06d3\u06d5\u06e5\u06e6\u06ee\u06ef\u06fa-\u06fc\u06ff\u0710\u0712-\u072f\u074d-\u07a5\u07b1\u07ca-\u07ea\u07f4\u07f5\u07fa\u0800-\u0815\u081a\u0824\u0828\u0840-\u0858\u0860-\u086a\u08a0-\u08b4\u08b6-\u08c7\u0904-\u0939\u093d\u0950\u0958-\u0961\u0971-\u0980\u0985-\u098c\u098f\u0990\u0993-\u09a8\u09aa-\u09b0\u09b2\u09b6-\u09b9\u09bd\u09ce\u09dc\u09dd\u09df-\u09e1\u09f0\u09f1\u09fc\u0a05-\u0a0a\u0a0f\u0a10\u0a13-\u0a28\u0a2a-\u0a30\u0a32\u0a33\u0a35\u0a36\u0a38\u0a39\u0a59-\u0a5c\u0a5e\u0a72-\u0a74\u0a85-\u0a8d\u0a8f-\u0a91\u0a93-\u0aa8\u0aaa-\u0ab0\u0ab2\u0ab3\u0ab5-\u0ab9\u0abd\u0ad0\u0ae0\u0ae1\u0af9\u0b05-\u0b0c\u0b0f\u0b10\u0b13-\u0b28\u0b2a-\u0b30\u0b32\u0b33\u0b35-\u0b39\u0b3d\u0b5c\u0b5d\u0b5f-\u0b61\u0b71\u0b83\u0b85-\u0b8a\u0b8e-\u0b90\u0b92-\u0b95\u0b99\u0b9a\u0b9c\u0b9e\u0b9f\u0ba3\u0ba4\u0ba8-\u0baa\u0bae-\u0bb9\u0bd0\u0c05-\u0c0c\u0c0e-\u0c10\u0c12-\u0c28\u0c2a-\u0c39\u0c3d\u0c58-\u0c5a\u0c60\u0c61\u0c80\u0c85-\u0c8c\u0c8e-\u0c90\u0c92-\u0ca8\u0caa-\u0cb3\u0cb5-\u0cb9\u0cbd\u0cde\u0ce0\u0ce1\u0cf1\u0cf2\u0d04-\u0d0c\u0d0e-\u0d10\u0d12-\u0d3a\u0d3d\u0d4e\u0d54-\u0d56\u0d5f-\u0d61\u0d7a-\u0d7f\u0d85-\u0d96\u0d9a-\u0db1\u0db3-\u0dbb\u0dbd\u0dc0-\u0dc6\u0e01-\u0e30\u0e32\u0e33\u0e40-\u0e46\u0e81\u0e82\u0e84\u0e86-\u0e8a\u0e8c-\u0ea3\u0ea5\u0ea7-\u0eb0\u0eb2\u0eb3\u0ebd\u0ec0-\u0ec4\u0ec6\u0edc-\u0edf\u0f00\u0f40-\u0f47\u0f49-\u0f6c\u0f88-\u0f8c\u1000-\u102a\u103f\u1050-\u1055\u105a-\u105d\u1061\u1065\u1066\u106e-\u1070\u1075-\u1081\u108e\u10a0-\u10c5\u10c7\u10cd\u10d0-\u10fa\u10fc-\u1248\u124a-\u124d\u1250-\u1256\u1258\u125a-\u125d\u1260-\u1288\u128a-\u128d\u1290-\u12b0\u12b2-\u12b5\u12b8-\u12be\u12c0\u12c2-\u12c5\u12c8-\u12d6\u12d8-\u1310\u1312-\u1315\u1318-\u135a\u1380-\u138f\u13a0-\u13f5\u13f8-\u13fd\u1401-\u166c\u166f-\u167f\u1681-\u169a\u16a0-\u16ea\u16ee-\u16f8\u1700-\u170c\u170e-\u1711\u1720-\u1731\u1740-\u1751\u1760-\u176c\u176e-\u1770\u1780-\u17b3\u17d7\u17dc\u1820-\u1878\u1880-\u18a8\u18aa\u18b0-\u18f5\u1900-\u191e\u1950-\u196d\u1970-\u1974\u1980-\u19ab\u19b0-\u19c9\u1a00-\u1a16\u1a20-\u1a54\u1aa7\u1b05-\u1b33\u1b45-\u1b4b\u1b83-\u1ba0\u1bae\u1baf\u1bba-\u1be5\u1c00-\u1c23\u1c4d-\u1c4f\u1c5a-\u1c7d\u1c80-\u1c88\u1c90-\u1cba\u1cbd-\u1cbf\u1ce9-\u1cec\u1cee-\u1cf3\u1cf5\u1cf6\u1cfa\u1d00-\u1dbf\u1e00-\u1f15\u1f18-\u1f1d\u1f20-\u1f45\u1f48-\u1f4d\u1f50-\u1f57\u1f59\u1f5b\u1f5d\u1f5f-\u1f7d\u1f80-\u1fb4\u1fb6-\u1fbc\u1fbe\u1fc2-\u1fc4\u1fc6-\u1fcc\u1fd0-\u1fd3\u1fd6-\u1fdb\u1fe0-\u1fec\u1ff2-\u1ff4\u1ff6-\u1ffc\u2071\u207f\u2090-\u209c\u2102\u2107\u210a-\u2113\u2115\u2118-\u211d\u2124\u2126\u2128\u212a-\u2139\u213c-\u213f\u2145-\u2149\u214e\u2160-\u2188\u2c00-\u2c2e\u2c30-\u2c5e\u2c60-\u2ce4\u2ceb-\u2cee\u2cf2\u2cf3\u2d00-\u2d25\u2d27\u2d2d\u2d30-\u2d67\u2d6f\u2d80-\u2d96\u2da0-\u2da6\u2da8-\u2dae\u2db0-\u2db6\u2db8-\u2dbe\u2dc0-\u2dc6\u2dc8-\u2dce\u2dd0-\u2dd6\u2dd8-\u2dde\u3005-\u3007\u3021-\u3029\u3031-\u3035\u3038-\u303c\u3041-\u3096\u309b-\u309f\u30a1-\u30fa\u30fc-\u30ff\u3105-\u312f\u3131-\u318e\u31a0-\u31bf\u31f0-\u31ff\u3400-\u4dbf\u4e00-\u9ffc\ua000-\ua48c\ua4d0-\ua4fd\ua500-\ua60c\ua610-\ua61f\ua62a\ua62b\ua640-\ua66e\ua67f-\ua69d\ua6a0-\ua6ef\ua717-\ua71f\ua722-\ua788\ua78b-\ua7bf\ua7c2-\ua7ca\ua7f5-\ua801\ua803-\ua805\ua807-\ua80a\ua80c-\ua822\ua840-\ua873\ua882-\ua8b3\ua8f2-\ua8f7\ua8fb\ua8fd\ua8fe\ua90a-\ua925\ua930-\ua946\ua960-\ua97c\ua984-\ua9b2\ua9cf\ua9e0-\ua9e4\ua9e6-\ua9ef\ua9fa-\ua9fe\uaa00-\uaa28\uaa40-\uaa42\uaa44-\uaa4b\uaa60-\uaa76\uaa7a\uaa7e-\uaaaf\uaab1\uaab5\uaab6\uaab9-\uaabd\uaac0\uaac2\uaadb-\uaadd\uaae0-\uaaea\uaaf2-\uaaf4\uab01-\uab06\uab09-\uab0e\uab11-\uab16\uab20-\uab26\uab28-\uab2e\uab30-\uab5a\uab5c-\uab69\uab70-\uabe2\uac00-\ud7a3\ud7b0-\ud7c6\ud7cb-\ud7fb\uf900-\ufa6d\ufa70-\ufad9\ufb00-\ufb06\ufb13-\ufb17\ufb1d\ufb1f-\ufb28\ufb2a-\ufb36\ufb38-\ufb3c\ufb3e\ufb40\ufb41\ufb43\ufb44\ufb46-\ufbb1\ufbd3-\ufd3d\ufd50-\ufd8f\ufd92-\ufdc7\ufdf0-\ufdfb\ufe70-\ufe74\ufe76-\ufefc\uff21-\uff3a\uff41-\uff5a\uff66-\uffbe\uffc2-\uffc7\uffca-\uffcf\uffd2-\uffd7\uffda-\uffdc";
  361. let nonASCIIidentifierChars = "\u200c\u200d\xb7\u0300-\u036f\u0387\u0483-\u0487\u0591-\u05bd\u05bf\u05c1\u05c2\u05c4\u05c5\u05c7\u0610-\u061a\u064b-\u0669\u0670\u06d6-\u06dc\u06df-\u06e4\u06e7\u06e8\u06ea-\u06ed\u06f0-\u06f9\u0711\u0730-\u074a\u07a6-\u07b0\u07c0-\u07c9\u07eb-\u07f3\u07fd\u0816-\u0819\u081b-\u0823\u0825-\u0827\u0829-\u082d\u0859-\u085b\u08d3-\u08e1\u08e3-\u0903\u093a-\u093c\u093e-\u094f\u0951-\u0957\u0962\u0963\u0966-\u096f\u0981-\u0983\u09bc\u09be-\u09c4\u09c7\u09c8\u09cb-\u09cd\u09d7\u09e2\u09e3\u09e6-\u09ef\u09fe\u0a01-\u0a03\u0a3c\u0a3e-\u0a42\u0a47\u0a48\u0a4b-\u0a4d\u0a51\u0a66-\u0a71\u0a75\u0a81-\u0a83\u0abc\u0abe-\u0ac5\u0ac7-\u0ac9\u0acb-\u0acd\u0ae2\u0ae3\u0ae6-\u0aef\u0afa-\u0aff\u0b01-\u0b03\u0b3c\u0b3e-\u0b44\u0b47\u0b48\u0b4b-\u0b4d\u0b55-\u0b57\u0b62\u0b63\u0b66-\u0b6f\u0b82\u0bbe-\u0bc2\u0bc6-\u0bc8\u0bca-\u0bcd\u0bd7\u0be6-\u0bef\u0c00-\u0c04\u0c3e-\u0c44\u0c46-\u0c48\u0c4a-\u0c4d\u0c55\u0c56\u0c62\u0c63\u0c66-\u0c6f\u0c81-\u0c83\u0cbc\u0cbe-\u0cc4\u0cc6-\u0cc8\u0cca-\u0ccd\u0cd5\u0cd6\u0ce2\u0ce3\u0ce6-\u0cef\u0d00-\u0d03\u0d3b\u0d3c\u0d3e-\u0d44\u0d46-\u0d48\u0d4a-\u0d4d\u0d57\u0d62\u0d63\u0d66-\u0d6f\u0d81-\u0d83\u0dca\u0dcf-\u0dd4\u0dd6\u0dd8-\u0ddf\u0de6-\u0def\u0df2\u0df3\u0e31\u0e34-\u0e3a\u0e47-\u0e4e\u0e50-\u0e59\u0eb1\u0eb4-\u0ebc\u0ec8-\u0ecd\u0ed0-\u0ed9\u0f18\u0f19\u0f20-\u0f29\u0f35\u0f37\u0f39\u0f3e\u0f3f\u0f71-\u0f84\u0f86\u0f87\u0f8d-\u0f97\u0f99-\u0fbc\u0fc6\u102b-\u103e\u1040-\u1049\u1056-\u1059\u105e-\u1060\u1062-\u1064\u1067-\u106d\u1071-\u1074\u1082-\u108d\u108f-\u109d\u135d-\u135f\u1369-\u1371\u1712-\u1714\u1732-\u1734\u1752\u1753\u1772\u1773\u17b4-\u17d3\u17dd\u17e0-\u17e9\u180b-\u180d\u1810-\u1819\u18a9\u1920-\u192b\u1930-\u193b\u1946-\u194f\u19d0-\u19da\u1a17-\u1a1b\u1a55-\u1a5e\u1a60-\u1a7c\u1a7f-\u1a89\u1a90-\u1a99\u1ab0-\u1abd\u1abf\u1ac0\u1b00-\u1b04\u1b34-\u1b44\u1b50-\u1b59\u1b6b-\u1b73\u1b80-\u1b82\u1ba1-\u1bad\u1bb0-\u1bb9\u1be6-\u1bf3\u1c24-\u1c37\u1c40-\u1c49\u1c50-\u1c59\u1cd0-\u1cd2\u1cd4-\u1ce8\u1ced\u1cf4\u1cf7-\u1cf9\u1dc0-\u1df9\u1dfb-\u1dff\u203f\u2040\u2054\u20d0-\u20dc\u20e1\u20e5-\u20f0\u2cef-\u2cf1\u2d7f\u2de0-\u2dff\u302a-\u302f\u3099\u309a\ua620-\ua629\ua66f\ua674-\ua67d\ua69e\ua69f\ua6f0\ua6f1\ua802\ua806\ua80b\ua823-\ua827\ua82c\ua880\ua881\ua8b4-\ua8c5\ua8d0-\ua8d9\ua8e0-\ua8f1\ua8ff-\ua909\ua926-\ua92d\ua947-\ua953\ua980-\ua983\ua9b3-\ua9c0\ua9d0-\ua9d9\ua9e5\ua9f0-\ua9f9\uaa29-\uaa36\uaa43\uaa4c\uaa4d\uaa50-\uaa59\uaa7b-\uaa7d\uaab0\uaab2-\uaab4\uaab7\uaab8\uaabe\uaabf\uaac1\uaaeb-\uaaef\uaaf5\uaaf6\uabe3-\uabea\uabec\uabed\uabf0-\uabf9\ufb1e\ufe00-\ufe0f\ufe20-\ufe2f\ufe33\ufe34\ufe4d-\ufe4f\uff10-\uff19\uff3f";
  362. const nonASCIIidentifierStart = new RegExp("[" + nonASCIIidentifierStartChars + "]");
  363. const nonASCIIidentifier = new RegExp("[" + nonASCIIidentifierStartChars + nonASCIIidentifierChars + "]");
  364. nonASCIIidentifierStartChars = nonASCIIidentifierChars = null;
  365. const astralIdentifierStartCodes = [0, 11, 2, 25, 2, 18, 2, 1, 2, 14, 3, 13, 35, 122, 70, 52, 268, 28, 4, 48, 48, 31, 14, 29, 6, 37, 11, 29, 3, 35, 5, 7, 2, 4, 43, 157, 19, 35, 5, 35, 5, 39, 9, 51, 157, 310, 10, 21, 11, 7, 153, 5, 3, 0, 2, 43, 2, 1, 4, 0, 3, 22, 11, 22, 10, 30, 66, 18, 2, 1, 11, 21, 11, 25, 71, 55, 7, 1, 65, 0, 16, 3, 2, 2, 2, 28, 43, 28, 4, 28, 36, 7, 2, 27, 28, 53, 11, 21, 11, 18, 14, 17, 111, 72, 56, 50, 14, 50, 14, 35, 349, 41, 7, 1, 79, 28, 11, 0, 9, 21, 107, 20, 28, 22, 13, 52, 76, 44, 33, 24, 27, 35, 30, 0, 3, 0, 9, 34, 4, 0, 13, 47, 15, 3, 22, 0, 2, 0, 36, 17, 2, 24, 85, 6, 2, 0, 2, 3, 2, 14, 2, 9, 8, 46, 39, 7, 3, 1, 3, 21, 2, 6, 2, 1, 2, 4, 4, 0, 19, 0, 13, 4, 159, 52, 19, 3, 21, 2, 31, 47, 21, 1, 2, 0, 185, 46, 42, 3, 37, 47, 21, 0, 60, 42, 14, 0, 72, 26, 230, 43, 117, 63, 32, 7, 3, 0, 3, 7, 2, 1, 2, 23, 16, 0, 2, 0, 95, 7, 3, 38, 17, 0, 2, 0, 29, 0, 11, 39, 8, 0, 22, 0, 12, 45, 20, 0, 35, 56, 264, 8, 2, 36, 18, 0, 50, 29, 113, 6, 2, 1, 2, 37, 22, 0, 26, 5, 2, 1, 2, 31, 15, 0, 328, 18, 190, 0, 80, 921, 103, 110, 18, 195, 2749, 1070, 4050, 582, 8634, 568, 8, 30, 114, 29, 19, 47, 17, 3, 32, 20, 6, 18, 689, 63, 129, 74, 6, 0, 67, 12, 65, 1, 2, 0, 29, 6135, 9, 1237, 43, 8, 8952, 286, 50, 2, 18, 3, 9, 395, 2309, 106, 6, 12, 4, 8, 8, 9, 5991, 84, 2, 70, 2, 1, 3, 0, 3, 1, 3, 3, 2, 11, 2, 0, 2, 6, 2, 64, 2, 3, 3, 7, 2, 6, 2, 27, 2, 3, 2, 4, 2, 0, 4, 6, 2, 339, 3, 24, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 30, 2, 24, 2, 7, 2357, 44, 11, 6, 17, 0, 370, 43, 1301, 196, 60, 67, 8, 0, 1205, 3, 2, 26, 2, 1, 2, 0, 3, 0, 2, 9, 2, 3, 2, 0, 2, 0, 7, 0, 5, 0, 2, 0, 2, 0, 2, 2, 2, 1, 2, 0, 3, 0, 2, 0, 2, 0, 2, 0, 2, 0, 2, 1, 2, 0, 3, 3, 2, 6, 2, 3, 2, 3, 2, 0, 2, 9, 2, 16, 6, 2, 2, 4, 2, 16, 4421, 42717, 35, 4148, 12, 221, 3, 5761, 15, 7472, 3104, 541, 1507, 4938];
  366. const astralIdentifierCodes = [509, 0, 227, 0, 150, 4, 294, 9, 1368, 2, 2, 1, 6, 3, 41, 2, 5, 0, 166, 1, 574, 3, 9, 9, 370, 1, 154, 10, 176, 2, 54, 14, 32, 9, 16, 3, 46, 10, 54, 9, 7, 2, 37, 13, 2, 9, 6, 1, 45, 0, 13, 2, 49, 13, 9, 3, 2, 11, 83, 11, 7, 0, 161, 11, 6, 9, 7, 3, 56, 1, 2, 6, 3, 1, 3, 2, 10, 0, 11, 1, 3, 6, 4, 4, 193, 17, 10, 9, 5, 0, 82, 19, 13, 9, 214, 6, 3, 8, 28, 1, 83, 16, 16, 9, 82, 12, 9, 9, 84, 14, 5, 9, 243, 14, 166, 9, 71, 5, 2, 1, 3, 3, 2, 0, 2, 1, 13, 9, 120, 6, 3, 6, 4, 0, 29, 9, 41, 6, 2, 3, 9, 0, 10, 10, 47, 15, 406, 7, 2, 7, 17, 9, 57, 21, 2, 13, 123, 5, 4, 0, 2, 1, 2, 6, 2, 0, 9, 9, 49, 4, 2, 1, 2, 4, 9, 9, 330, 3, 19306, 9, 135, 4, 60, 6, 26, 9, 1014, 0, 2, 54, 8, 3, 82, 0, 12, 1, 19628, 1, 5319, 4, 4, 5, 9, 7, 3, 6, 31, 3, 149, 2, 1418, 49, 513, 54, 5, 49, 9, 0, 15, 0, 23, 4, 2, 14, 1361, 6, 2, 16, 3, 6, 2, 1, 2, 4, 262, 6, 10, 9, 419, 13, 1495, 6, 110, 6, 6, 9, 4759, 9, 787719, 239];
  367. function isInAstralSet(code, set) {
  368. let pos = 0x10000;
  369. for (let i = 0, length = set.length; i < length; i += 2) {
  370. pos += set[i];
  371. if (pos > code) return false;
  372. pos += set[i + 1];
  373. if (pos >= code) return true;
  374. }
  375. return false;
  376. }
  377. function isIdentifierStart(code) {
  378. if (code < 65) return code === 36;
  379. if (code <= 90) return true;
  380. if (code < 97) return code === 95;
  381. if (code <= 122) return true;
  382. if (code <= 0xffff) {
  383. return code >= 0xaa && nonASCIIidentifierStart.test(String.fromCharCode(code));
  384. }
  385. return isInAstralSet(code, astralIdentifierStartCodes);
  386. }
  387. function isIdentifierChar(code) {
  388. if (code < 48) return code === 36;
  389. if (code < 58) return true;
  390. if (code < 65) return false;
  391. if (code <= 90) return true;
  392. if (code < 97) return code === 95;
  393. if (code <= 122) return true;
  394. if (code <= 0xffff) {
  395. return code >= 0xaa && nonASCIIidentifier.test(String.fromCharCode(code));
  396. }
  397. return isInAstralSet(code, astralIdentifierStartCodes) || isInAstralSet(code, astralIdentifierCodes);
  398. }
  399. function isIdentifierName(name) {
  400. let isFirst = true;
  401. for (let i = 0; i < name.length; i++) {
  402. let cp = name.charCodeAt(i);
  403. if ((cp & 0xfc00) === 0xd800 && i + 1 < name.length) {
  404. const trail = name.charCodeAt(++i);
  405. if ((trail & 0xfc00) === 0xdc00) {
  406. cp = 0x10000 + ((cp & 0x3ff) << 10) + (trail & 0x3ff);
  407. }
  408. }
  409. if (isFirst) {
  410. isFirst = false;
  411. if (!isIdentifierStart(cp)) {
  412. return false;
  413. }
  414. } else if (!isIdentifierChar(cp)) {
  415. return false;
  416. }
  417. }
  418. return !isFirst;
  419. }
  420. var identifier = /*#__PURE__*/Object.defineProperty({
  421. isIdentifierStart: isIdentifierStart_1,
  422. isIdentifierChar: isIdentifierChar_1,
  423. isIdentifierName: isIdentifierName_1
  424. }, '__esModule', {
  425. value: true
  426. });
  427. var isReservedWord_1 = isReservedWord;
  428. var isStrictReservedWord_1 = isStrictReservedWord;
  429. var isStrictBindOnlyReservedWord_1 = isStrictBindOnlyReservedWord;
  430. var isStrictBindReservedWord_1 = isStrictBindReservedWord;
  431. var isKeyword_1 = isKeyword;
  432. const reservedWords = {
  433. keyword: ["break", "case", "catch", "continue", "debugger", "default", "do", "else", "finally", "for", "function", "if", "return", "switch", "throw", "try", "var", "const", "while", "with", "new", "this", "super", "class", "extends", "export", "import", "null", "true", "false", "in", "instanceof", "typeof", "void", "delete"],
  434. strict: ["implements", "interface", "let", "package", "private", "protected", "public", "static", "yield"],
  435. strictBind: ["eval", "arguments"]
  436. };
  437. const keywords = new Set(reservedWords.keyword);
  438. const reservedWordsStrictSet = new Set(reservedWords.strict);
  439. const reservedWordsStrictBindSet = new Set(reservedWords.strictBind);
  440. function isReservedWord(word, inModule) {
  441. return inModule && word === "await" || word === "enum";
  442. }
  443. function isStrictReservedWord(word, inModule) {
  444. return isReservedWord(word, inModule) || reservedWordsStrictSet.has(word);
  445. }
  446. function isStrictBindOnlyReservedWord(word) {
  447. return reservedWordsStrictBindSet.has(word);
  448. }
  449. function isStrictBindReservedWord(word, inModule) {
  450. return isStrictReservedWord(word, inModule) || isStrictBindOnlyReservedWord(word);
  451. }
  452. function isKeyword(word) {
  453. return keywords.has(word);
  454. }
  455. var keyword = /*#__PURE__*/Object.defineProperty({
  456. isReservedWord: isReservedWord_1,
  457. isStrictReservedWord: isStrictReservedWord_1,
  458. isStrictBindOnlyReservedWord: isStrictBindOnlyReservedWord_1,
  459. isStrictBindReservedWord: isStrictBindReservedWord_1,
  460. isKeyword: isKeyword_1
  461. }, '__esModule', {
  462. value: true
  463. });
  464. var lib$2 = createCommonjsModule(function (module, exports) {
  465. Object.defineProperty(exports, "__esModule", {
  466. value: true
  467. });
  468. Object.defineProperty(exports, "isIdentifierName", {
  469. enumerable: true,
  470. get: function () {
  471. return identifier.isIdentifierName;
  472. }
  473. });
  474. Object.defineProperty(exports, "isIdentifierChar", {
  475. enumerable: true,
  476. get: function () {
  477. return identifier.isIdentifierChar;
  478. }
  479. });
  480. Object.defineProperty(exports, "isIdentifierStart", {
  481. enumerable: true,
  482. get: function () {
  483. return identifier.isIdentifierStart;
  484. }
  485. });
  486. Object.defineProperty(exports, "isReservedWord", {
  487. enumerable: true,
  488. get: function () {
  489. return keyword.isReservedWord;
  490. }
  491. });
  492. Object.defineProperty(exports, "isStrictBindOnlyReservedWord", {
  493. enumerable: true,
  494. get: function () {
  495. return keyword.isStrictBindOnlyReservedWord;
  496. }
  497. });
  498. Object.defineProperty(exports, "isStrictBindReservedWord", {
  499. enumerable: true,
  500. get: function () {
  501. return keyword.isStrictBindReservedWord;
  502. }
  503. });
  504. Object.defineProperty(exports, "isStrictReservedWord", {
  505. enumerable: true,
  506. get: function () {
  507. return keyword.isStrictReservedWord;
  508. }
  509. });
  510. Object.defineProperty(exports, "isKeyword", {
  511. enumerable: true,
  512. get: function () {
  513. return keyword.isKeyword;
  514. }
  515. });
  516. });
  517. var matchOperatorsRe = /[|\\{}()[\]^$+*?.]/g;
  518. var escapeStringRegexp = function (str) {
  519. if (typeof str !== 'string') {
  520. throw new TypeError('Expected a string');
  521. }
  522. return str.replace(matchOperatorsRe, '\\$&');
  523. };
  524. var colorName = {
  525. "aliceblue": [240, 248, 255],
  526. "antiquewhite": [250, 235, 215],
  527. "aqua": [0, 255, 255],
  528. "aquamarine": [127, 255, 212],
  529. "azure": [240, 255, 255],
  530. "beige": [245, 245, 220],
  531. "bisque": [255, 228, 196],
  532. "black": [0, 0, 0],
  533. "blanchedalmond": [255, 235, 205],
  534. "blue": [0, 0, 255],
  535. "blueviolet": [138, 43, 226],
  536. "brown": [165, 42, 42],
  537. "burlywood": [222, 184, 135],
  538. "cadetblue": [95, 158, 160],
  539. "chartreuse": [127, 255, 0],
  540. "chocolate": [210, 105, 30],
  541. "coral": [255, 127, 80],
  542. "cornflowerblue": [100, 149, 237],
  543. "cornsilk": [255, 248, 220],
  544. "crimson": [220, 20, 60],
  545. "cyan": [0, 255, 255],
  546. "darkblue": [0, 0, 139],
  547. "darkcyan": [0, 139, 139],
  548. "darkgoldenrod": [184, 134, 11],
  549. "darkgray": [169, 169, 169],
  550. "darkgreen": [0, 100, 0],
  551. "darkgrey": [169, 169, 169],
  552. "darkkhaki": [189, 183, 107],
  553. "darkmagenta": [139, 0, 139],
  554. "darkolivegreen": [85, 107, 47],
  555. "darkorange": [255, 140, 0],
  556. "darkorchid": [153, 50, 204],
  557. "darkred": [139, 0, 0],
  558. "darksalmon": [233, 150, 122],
  559. "darkseagreen": [143, 188, 143],
  560. "darkslateblue": [72, 61, 139],
  561. "darkslategray": [47, 79, 79],
  562. "darkslategrey": [47, 79, 79],
  563. "darkturquoise": [0, 206, 209],
  564. "darkviolet": [148, 0, 211],
  565. "deeppink": [255, 20, 147],
  566. "deepskyblue": [0, 191, 255],
  567. "dimgray": [105, 105, 105],
  568. "dimgrey": [105, 105, 105],
  569. "dodgerblue": [30, 144, 255],
  570. "firebrick": [178, 34, 34],
  571. "floralwhite": [255, 250, 240],
  572. "forestgreen": [34, 139, 34],
  573. "fuchsia": [255, 0, 255],
  574. "gainsboro": [220, 220, 220],
  575. "ghostwhite": [248, 248, 255],
  576. "gold": [255, 215, 0],
  577. "goldenrod": [218, 165, 32],
  578. "gray": [128, 128, 128],
  579. "green": [0, 128, 0],
  580. "greenyellow": [173, 255, 47],
  581. "grey": [128, 128, 128],
  582. "honeydew": [240, 255, 240],
  583. "hotpink": [255, 105, 180],
  584. "indianred": [205, 92, 92],
  585. "indigo": [75, 0, 130],
  586. "ivory": [255, 255, 240],
  587. "khaki": [240, 230, 140],
  588. "lavender": [230, 230, 250],
  589. "lavenderblush": [255, 240, 245],
  590. "lawngreen": [124, 252, 0],
  591. "lemonchiffon": [255, 250, 205],
  592. "lightblue": [173, 216, 230],
  593. "lightcoral": [240, 128, 128],
  594. "lightcyan": [224, 255, 255],
  595. "lightgoldenrodyellow": [250, 250, 210],
  596. "lightgray": [211, 211, 211],
  597. "lightgreen": [144, 238, 144],
  598. "lightgrey": [211, 211, 211],
  599. "lightpink": [255, 182, 193],
  600. "lightsalmon": [255, 160, 122],
  601. "lightseagreen": [32, 178, 170],
  602. "lightskyblue": [135, 206, 250],
  603. "lightslategray": [119, 136, 153],
  604. "lightslategrey": [119, 136, 153],
  605. "lightsteelblue": [176, 196, 222],
  606. "lightyellow": [255, 255, 224],
  607. "lime": [0, 255, 0],
  608. "limegreen": [50, 205, 50],
  609. "linen": [250, 240, 230],
  610. "magenta": [255, 0, 255],
  611. "maroon": [128, 0, 0],
  612. "mediumaquamarine": [102, 205, 170],
  613. "mediumblue": [0, 0, 205],
  614. "mediumorchid": [186, 85, 211],
  615. "mediumpurple": [147, 112, 219],
  616. "mediumseagreen": [60, 179, 113],
  617. "mediumslateblue": [123, 104, 238],
  618. "mediumspringgreen": [0, 250, 154],
  619. "mediumturquoise": [72, 209, 204],
  620. "mediumvioletred": [199, 21, 133],
  621. "midnightblue": [25, 25, 112],
  622. "mintcream": [245, 255, 250],
  623. "mistyrose": [255, 228, 225],
  624. "moccasin": [255, 228, 181],
  625. "navajowhite": [255, 222, 173],
  626. "navy": [0, 0, 128],
  627. "oldlace": [253, 245, 230],
  628. "olive": [128, 128, 0],
  629. "olivedrab": [107, 142, 35],
  630. "orange": [255, 165, 0],
  631. "orangered": [255, 69, 0],
  632. "orchid": [218, 112, 214],
  633. "palegoldenrod": [238, 232, 170],
  634. "palegreen": [152, 251, 152],
  635. "paleturquoise": [175, 238, 238],
  636. "palevioletred": [219, 112, 147],
  637. "papayawhip": [255, 239, 213],
  638. "peachpuff": [255, 218, 185],
  639. "peru": [205, 133, 63],
  640. "pink": [255, 192, 203],
  641. "plum": [221, 160, 221],
  642. "powderblue": [176, 224, 230],
  643. "purple": [128, 0, 128],
  644. "rebeccapurple": [102, 51, 153],
  645. "red": [255, 0, 0],
  646. "rosybrown": [188, 143, 143],
  647. "royalblue": [65, 105, 225],
  648. "saddlebrown": [139, 69, 19],
  649. "salmon": [250, 128, 114],
  650. "sandybrown": [244, 164, 96],
  651. "seagreen": [46, 139, 87],
  652. "seashell": [255, 245, 238],
  653. "sienna": [160, 82, 45],
  654. "silver": [192, 192, 192],
  655. "skyblue": [135, 206, 235],
  656. "slateblue": [106, 90, 205],
  657. "slategray": [112, 128, 144],
  658. "slategrey": [112, 128, 144],
  659. "snow": [255, 250, 250],
  660. "springgreen": [0, 255, 127],
  661. "steelblue": [70, 130, 180],
  662. "tan": [210, 180, 140],
  663. "teal": [0, 128, 128],
  664. "thistle": [216, 191, 216],
  665. "tomato": [255, 99, 71],
  666. "turquoise": [64, 224, 208],
  667. "violet": [238, 130, 238],
  668. "wheat": [245, 222, 179],
  669. "white": [255, 255, 255],
  670. "whitesmoke": [245, 245, 245],
  671. "yellow": [255, 255, 0],
  672. "yellowgreen": [154, 205, 50]
  673. };
  674. /* MIT license */
  675. var conversions = createCommonjsModule(function (module) {
  676. // NOTE: conversions should only return primitive values (i.e. arrays, or
  677. // values that give correct `typeof` results).
  678. // do not use box values types (i.e. Number(), String(), etc.)
  679. var reverseKeywords = {};
  680. for (var key in colorName) {
  681. if (colorName.hasOwnProperty(key)) {
  682. reverseKeywords[colorName[key]] = key;
  683. }
  684. }
  685. var convert = module.exports = {
  686. rgb: {
  687. channels: 3,
  688. labels: 'rgb'
  689. },
  690. hsl: {
  691. channels: 3,
  692. labels: 'hsl'
  693. },
  694. hsv: {
  695. channels: 3,
  696. labels: 'hsv'
  697. },
  698. hwb: {
  699. channels: 3,
  700. labels: 'hwb'
  701. },
  702. cmyk: {
  703. channels: 4,
  704. labels: 'cmyk'
  705. },
  706. xyz: {
  707. channels: 3,
  708. labels: 'xyz'
  709. },
  710. lab: {
  711. channels: 3,
  712. labels: 'lab'
  713. },
  714. lch: {
  715. channels: 3,
  716. labels: 'lch'
  717. },
  718. hex: {
  719. channels: 1,
  720. labels: ['hex']
  721. },
  722. keyword: {
  723. channels: 1,
  724. labels: ['keyword']
  725. },
  726. ansi16: {
  727. channels: 1,
  728. labels: ['ansi16']
  729. },
  730. ansi256: {
  731. channels: 1,
  732. labels: ['ansi256']
  733. },
  734. hcg: {
  735. channels: 3,
  736. labels: ['h', 'c', 'g']
  737. },
  738. apple: {
  739. channels: 3,
  740. labels: ['r16', 'g16', 'b16']
  741. },
  742. gray: {
  743. channels: 1,
  744. labels: ['gray']
  745. }
  746. }; // hide .channels and .labels properties
  747. for (var model in convert) {
  748. if (convert.hasOwnProperty(model)) {
  749. if (!('channels' in convert[model])) {
  750. throw new Error('missing channels property: ' + model);
  751. }
  752. if (!('labels' in convert[model])) {
  753. throw new Error('missing channel labels property: ' + model);
  754. }
  755. if (convert[model].labels.length !== convert[model].channels) {
  756. throw new Error('channel and label counts mismatch: ' + model);
  757. }
  758. var channels = convert[model].channels;
  759. var labels = convert[model].labels;
  760. delete convert[model].channels;
  761. delete convert[model].labels;
  762. Object.defineProperty(convert[model], 'channels', {
  763. value: channels
  764. });
  765. Object.defineProperty(convert[model], 'labels', {
  766. value: labels
  767. });
  768. }
  769. }
  770. convert.rgb.hsl = function (rgb) {
  771. var r = rgb[0] / 255;
  772. var g = rgb[1] / 255;
  773. var b = rgb[2] / 255;
  774. var min = Math.min(r, g, b);
  775. var max = Math.max(r, g, b);
  776. var delta = max - min;
  777. var h;
  778. var s;
  779. var l;
  780. if (max === min) {
  781. h = 0;
  782. } else if (r === max) {
  783. h = (g - b) / delta;
  784. } else if (g === max) {
  785. h = 2 + (b - r) / delta;
  786. } else if (b === max) {
  787. h = 4 + (r - g) / delta;
  788. }
  789. h = Math.min(h * 60, 360);
  790. if (h < 0) {
  791. h += 360;
  792. }
  793. l = (min + max) / 2;
  794. if (max === min) {
  795. s = 0;
  796. } else if (l <= 0.5) {
  797. s = delta / (max + min);
  798. } else {
  799. s = delta / (2 - max - min);
  800. }
  801. return [h, s * 100, l * 100];
  802. };
  803. convert.rgb.hsv = function (rgb) {
  804. var rdif;
  805. var gdif;
  806. var bdif;
  807. var h;
  808. var s;
  809. var r = rgb[0] / 255;
  810. var g = rgb[1] / 255;
  811. var b = rgb[2] / 255;
  812. var v = Math.max(r, g, b);
  813. var diff = v - Math.min(r, g, b);
  814. var diffc = function (c) {
  815. return (v - c) / 6 / diff + 1 / 2;
  816. };
  817. if (diff === 0) {
  818. h = s = 0;
  819. } else {
  820. s = diff / v;
  821. rdif = diffc(r);
  822. gdif = diffc(g);
  823. bdif = diffc(b);
  824. if (r === v) {
  825. h = bdif - gdif;
  826. } else if (g === v) {
  827. h = 1 / 3 + rdif - bdif;
  828. } else if (b === v) {
  829. h = 2 / 3 + gdif - rdif;
  830. }
  831. if (h < 0) {
  832. h += 1;
  833. } else if (h > 1) {
  834. h -= 1;
  835. }
  836. }
  837. return [h * 360, s * 100, v * 100];
  838. };
  839. convert.rgb.hwb = function (rgb) {
  840. var r = rgb[0];
  841. var g = rgb[1];
  842. var b = rgb[2];
  843. var h = convert.rgb.hsl(rgb)[0];
  844. var w = 1 / 255 * Math.min(r, Math.min(g, b));
  845. b = 1 - 1 / 255 * Math.max(r, Math.max(g, b));
  846. return [h, w * 100, b * 100];
  847. };
  848. convert.rgb.cmyk = function (rgb) {
  849. var r = rgb[0] / 255;
  850. var g = rgb[1] / 255;
  851. var b = rgb[2] / 255;
  852. var c;
  853. var m;
  854. var y;
  855. var k;
  856. k = Math.min(1 - r, 1 - g, 1 - b);
  857. c = (1 - r - k) / (1 - k) || 0;
  858. m = (1 - g - k) / (1 - k) || 0;
  859. y = (1 - b - k) / (1 - k) || 0;
  860. return [c * 100, m * 100, y * 100, k * 100];
  861. };
  862. /**
  863. * See https://en.m.wikipedia.org/wiki/Euclidean_distance#Squared_Euclidean_distance
  864. * */
  865. function comparativeDistance(x, y) {
  866. return Math.pow(x[0] - y[0], 2) + Math.pow(x[1] - y[1], 2) + Math.pow(x[2] - y[2], 2);
  867. }
  868. convert.rgb.keyword = function (rgb) {
  869. var reversed = reverseKeywords[rgb];
  870. if (reversed) {
  871. return reversed;
  872. }
  873. var currentClosestDistance = Infinity;
  874. var currentClosestKeyword;
  875. for (var keyword in colorName) {
  876. if (colorName.hasOwnProperty(keyword)) {
  877. var value = colorName[keyword]; // Compute comparative distance
  878. var distance = comparativeDistance(rgb, value); // Check if its less, if so set as closest
  879. if (distance < currentClosestDistance) {
  880. currentClosestDistance = distance;
  881. currentClosestKeyword = keyword;
  882. }
  883. }
  884. }
  885. return currentClosestKeyword;
  886. };
  887. convert.keyword.rgb = function (keyword) {
  888. return colorName[keyword];
  889. };
  890. convert.rgb.xyz = function (rgb) {
  891. var r = rgb[0] / 255;
  892. var g = rgb[1] / 255;
  893. var b = rgb[2] / 255; // assume sRGB
  894. r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
  895. g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
  896. b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
  897. var x = r * 0.4124 + g * 0.3576 + b * 0.1805;
  898. var y = r * 0.2126 + g * 0.7152 + b * 0.0722;
  899. var z = r * 0.0193 + g * 0.1192 + b * 0.9505;
  900. return [x * 100, y * 100, z * 100];
  901. };
  902. convert.rgb.lab = function (rgb) {
  903. var xyz = convert.rgb.xyz(rgb);
  904. var x = xyz[0];
  905. var y = xyz[1];
  906. var z = xyz[2];
  907. var l;
  908. var a;
  909. var b;
  910. x /= 95.047;
  911. y /= 100;
  912. z /= 108.883;
  913. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  914. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  915. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  916. l = 116 * y - 16;
  917. a = 500 * (x - y);
  918. b = 200 * (y - z);
  919. return [l, a, b];
  920. };
  921. convert.hsl.rgb = function (hsl) {
  922. var h = hsl[0] / 360;
  923. var s = hsl[1] / 100;
  924. var l = hsl[2] / 100;
  925. var t1;
  926. var t2;
  927. var t3;
  928. var rgb;
  929. var val;
  930. if (s === 0) {
  931. val = l * 255;
  932. return [val, val, val];
  933. }
  934. if (l < 0.5) {
  935. t2 = l * (1 + s);
  936. } else {
  937. t2 = l + s - l * s;
  938. }
  939. t1 = 2 * l - t2;
  940. rgb = [0, 0, 0];
  941. for (var i = 0; i < 3; i++) {
  942. t3 = h + 1 / 3 * -(i - 1);
  943. if (t3 < 0) {
  944. t3++;
  945. }
  946. if (t3 > 1) {
  947. t3--;
  948. }
  949. if (6 * t3 < 1) {
  950. val = t1 + (t2 - t1) * 6 * t3;
  951. } else if (2 * t3 < 1) {
  952. val = t2;
  953. } else if (3 * t3 < 2) {
  954. val = t1 + (t2 - t1) * (2 / 3 - t3) * 6;
  955. } else {
  956. val = t1;
  957. }
  958. rgb[i] = val * 255;
  959. }
  960. return rgb;
  961. };
  962. convert.hsl.hsv = function (hsl) {
  963. var h = hsl[0];
  964. var s = hsl[1] / 100;
  965. var l = hsl[2] / 100;
  966. var smin = s;
  967. var lmin = Math.max(l, 0.01);
  968. var sv;
  969. var v;
  970. l *= 2;
  971. s *= l <= 1 ? l : 2 - l;
  972. smin *= lmin <= 1 ? lmin : 2 - lmin;
  973. v = (l + s) / 2;
  974. sv = l === 0 ? 2 * smin / (lmin + smin) : 2 * s / (l + s);
  975. return [h, sv * 100, v * 100];
  976. };
  977. convert.hsv.rgb = function (hsv) {
  978. var h = hsv[0] / 60;
  979. var s = hsv[1] / 100;
  980. var v = hsv[2] / 100;
  981. var hi = Math.floor(h) % 6;
  982. var f = h - Math.floor(h);
  983. var p = 255 * v * (1 - s);
  984. var q = 255 * v * (1 - s * f);
  985. var t = 255 * v * (1 - s * (1 - f));
  986. v *= 255;
  987. switch (hi) {
  988. case 0:
  989. return [v, t, p];
  990. case 1:
  991. return [q, v, p];
  992. case 2:
  993. return [p, v, t];
  994. case 3:
  995. return [p, q, v];
  996. case 4:
  997. return [t, p, v];
  998. case 5:
  999. return [v, p, q];
  1000. }
  1001. };
  1002. convert.hsv.hsl = function (hsv) {
  1003. var h = hsv[0];
  1004. var s = hsv[1] / 100;
  1005. var v = hsv[2] / 100;
  1006. var vmin = Math.max(v, 0.01);
  1007. var lmin;
  1008. var sl;
  1009. var l;
  1010. l = (2 - s) * v;
  1011. lmin = (2 - s) * vmin;
  1012. sl = s * vmin;
  1013. sl /= lmin <= 1 ? lmin : 2 - lmin;
  1014. sl = sl || 0;
  1015. l /= 2;
  1016. return [h, sl * 100, l * 100];
  1017. }; // http://dev.w3.org/csswg/css-color/#hwb-to-rgb
  1018. convert.hwb.rgb = function (hwb) {
  1019. var h = hwb[0] / 360;
  1020. var wh = hwb[1] / 100;
  1021. var bl = hwb[2] / 100;
  1022. var ratio = wh + bl;
  1023. var i;
  1024. var v;
  1025. var f;
  1026. var n; // wh + bl cant be > 1
  1027. if (ratio > 1) {
  1028. wh /= ratio;
  1029. bl /= ratio;
  1030. }
  1031. i = Math.floor(6 * h);
  1032. v = 1 - bl;
  1033. f = 6 * h - i;
  1034. if ((i & 0x01) !== 0) {
  1035. f = 1 - f;
  1036. }
  1037. n = wh + f * (v - wh); // linear interpolation
  1038. var r;
  1039. var g;
  1040. var b;
  1041. switch (i) {
  1042. default:
  1043. case 6:
  1044. case 0:
  1045. r = v;
  1046. g = n;
  1047. b = wh;
  1048. break;
  1049. case 1:
  1050. r = n;
  1051. g = v;
  1052. b = wh;
  1053. break;
  1054. case 2:
  1055. r = wh;
  1056. g = v;
  1057. b = n;
  1058. break;
  1059. case 3:
  1060. r = wh;
  1061. g = n;
  1062. b = v;
  1063. break;
  1064. case 4:
  1065. r = n;
  1066. g = wh;
  1067. b = v;
  1068. break;
  1069. case 5:
  1070. r = v;
  1071. g = wh;
  1072. b = n;
  1073. break;
  1074. }
  1075. return [r * 255, g * 255, b * 255];
  1076. };
  1077. convert.cmyk.rgb = function (cmyk) {
  1078. var c = cmyk[0] / 100;
  1079. var m = cmyk[1] / 100;
  1080. var y = cmyk[2] / 100;
  1081. var k = cmyk[3] / 100;
  1082. var r;
  1083. var g;
  1084. var b;
  1085. r = 1 - Math.min(1, c * (1 - k) + k);
  1086. g = 1 - Math.min(1, m * (1 - k) + k);
  1087. b = 1 - Math.min(1, y * (1 - k) + k);
  1088. return [r * 255, g * 255, b * 255];
  1089. };
  1090. convert.xyz.rgb = function (xyz) {
  1091. var x = xyz[0] / 100;
  1092. var y = xyz[1] / 100;
  1093. var z = xyz[2] / 100;
  1094. var r;
  1095. var g;
  1096. var b;
  1097. r = x * 3.2406 + y * -1.5372 + z * -0.4986;
  1098. g = x * -0.9689 + y * 1.8758 + z * 0.0415;
  1099. b = x * 0.0557 + y * -0.2040 + z * 1.0570; // assume sRGB
  1100. r = r > 0.0031308 ? 1.055 * Math.pow(r, 1.0 / 2.4) - 0.055 : r * 12.92;
  1101. g = g > 0.0031308 ? 1.055 * Math.pow(g, 1.0 / 2.4) - 0.055 : g * 12.92;
  1102. b = b > 0.0031308 ? 1.055 * Math.pow(b, 1.0 / 2.4) - 0.055 : b * 12.92;
  1103. r = Math.min(Math.max(0, r), 1);
  1104. g = Math.min(Math.max(0, g), 1);
  1105. b = Math.min(Math.max(0, b), 1);
  1106. return [r * 255, g * 255, b * 255];
  1107. };
  1108. convert.xyz.lab = function (xyz) {
  1109. var x = xyz[0];
  1110. var y = xyz[1];
  1111. var z = xyz[2];
  1112. var l;
  1113. var a;
  1114. var b;
  1115. x /= 95.047;
  1116. y /= 100;
  1117. z /= 108.883;
  1118. x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
  1119. y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
  1120. z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
  1121. l = 116 * y - 16;
  1122. a = 500 * (x - y);
  1123. b = 200 * (y - z);
  1124. return [l, a, b];
  1125. };
  1126. convert.lab.xyz = function (lab) {
  1127. var l = lab[0];
  1128. var a = lab[1];
  1129. var b = lab[2];
  1130. var x;
  1131. var y;
  1132. var z;
  1133. y = (l + 16) / 116;
  1134. x = a / 500 + y;
  1135. z = y - b / 200;
  1136. var y2 = Math.pow(y, 3);
  1137. var x2 = Math.pow(x, 3);
  1138. var z2 = Math.pow(z, 3);
  1139. y = y2 > 0.008856 ? y2 : (y - 16 / 116) / 7.787;
  1140. x = x2 > 0.008856 ? x2 : (x - 16 / 116) / 7.787;
  1141. z = z2 > 0.008856 ? z2 : (z - 16 / 116) / 7.787;
  1142. x *= 95.047;
  1143. y *= 100;
  1144. z *= 108.883;
  1145. return [x, y, z];
  1146. };
  1147. convert.lab.lch = function (lab) {
  1148. var l = lab[0];
  1149. var a = lab[1];
  1150. var b = lab[2];
  1151. var hr;
  1152. var h;
  1153. var c;
  1154. hr = Math.atan2(b, a);
  1155. h = hr * 360 / 2 / Math.PI;
  1156. if (h < 0) {
  1157. h += 360;
  1158. }
  1159. c = Math.sqrt(a * a + b * b);
  1160. return [l, c, h];
  1161. };
  1162. convert.lch.lab = function (lch) {
  1163. var l = lch[0];
  1164. var c = lch[1];
  1165. var h = lch[2];
  1166. var a;
  1167. var b;
  1168. var hr;
  1169. hr = h / 360 * 2 * Math.PI;
  1170. a = c * Math.cos(hr);
  1171. b = c * Math.sin(hr);
  1172. return [l, a, b];
  1173. };
  1174. convert.rgb.ansi16 = function (args) {
  1175. var r = args[0];
  1176. var g = args[1];
  1177. var b = args[2];
  1178. var value = 1 in arguments ? arguments[1] : convert.rgb.hsv(args)[2]; // hsv -> ansi16 optimization
  1179. value = Math.round(value / 50);
  1180. if (value === 0) {
  1181. return 30;
  1182. }
  1183. var ansi = 30 + (Math.round(b / 255) << 2 | Math.round(g / 255) << 1 | Math.round(r / 255));
  1184. if (value === 2) {
  1185. ansi += 60;
  1186. }
  1187. return ansi;
  1188. };
  1189. convert.hsv.ansi16 = function (args) {
  1190. // optimization here; we already know the value and don't need to get
  1191. // it converted for us.
  1192. return convert.rgb.ansi16(convert.hsv.rgb(args), args[2]);
  1193. };
  1194. convert.rgb.ansi256 = function (args) {
  1195. var r = args[0];
  1196. var g = args[1];
  1197. var b = args[2]; // we use the extended greyscale palette here, with the exception of
  1198. // black and white. normal palette only has 4 greyscale shades.
  1199. if (r === g && g === b) {
  1200. if (r < 8) {
  1201. return 16;
  1202. }
  1203. if (r > 248) {
  1204. return 231;
  1205. }
  1206. return Math.round((r - 8) / 247 * 24) + 232;
  1207. }
  1208. var ansi = 16 + 36 * Math.round(r / 255 * 5) + 6 * Math.round(g / 255 * 5) + Math.round(b / 255 * 5);
  1209. return ansi;
  1210. };
  1211. convert.ansi16.rgb = function (args) {
  1212. var color = args % 10; // handle greyscale
  1213. if (color === 0 || color === 7) {
  1214. if (args > 50) {
  1215. color += 3.5;
  1216. }
  1217. color = color / 10.5 * 255;
  1218. return [color, color, color];
  1219. }
  1220. var mult = (~~(args > 50) + 1) * 0.5;
  1221. var r = (color & 1) * mult * 255;
  1222. var g = (color >> 1 & 1) * mult * 255;
  1223. var b = (color >> 2 & 1) * mult * 255;
  1224. return [r, g, b];
  1225. };
  1226. convert.ansi256.rgb = function (args) {
  1227. // handle greyscale
  1228. if (args >= 232) {
  1229. var c = (args - 232) * 10 + 8;
  1230. return [c, c, c];
  1231. }
  1232. args -= 16;
  1233. var rem;
  1234. var r = Math.floor(args / 36) / 5 * 255;
  1235. var g = Math.floor((rem = args % 36) / 6) / 5 * 255;
  1236. var b = rem % 6 / 5 * 255;
  1237. return [r, g, b];
  1238. };
  1239. convert.rgb.hex = function (args) {
  1240. var integer = ((Math.round(args[0]) & 0xFF) << 16) + ((Math.round(args[1]) & 0xFF) << 8) + (Math.round(args[2]) & 0xFF);
  1241. var string = integer.toString(16).toUpperCase();
  1242. return '000000'.substring(string.length) + string;
  1243. };
  1244. convert.hex.rgb = function (args) {
  1245. var match = args.toString(16).match(/[a-f0-9]{6}|[a-f0-9]{3}/i);
  1246. if (!match) {
  1247. return [0, 0, 0];
  1248. }
  1249. var colorString = match[0];
  1250. if (match[0].length === 3) {
  1251. colorString = colorString.split('').map(function (char) {
  1252. return char + char;
  1253. }).join('');
  1254. }
  1255. var integer = parseInt(colorString, 16);
  1256. var r = integer >> 16 & 0xFF;
  1257. var g = integer >> 8 & 0xFF;
  1258. var b = integer & 0xFF;
  1259. return [r, g, b];
  1260. };
  1261. convert.rgb.hcg = function (rgb) {
  1262. var r = rgb[0] / 255;
  1263. var g = rgb[1] / 255;
  1264. var b = rgb[2] / 255;
  1265. var max = Math.max(Math.max(r, g), b);
  1266. var min = Math.min(Math.min(r, g), b);
  1267. var chroma = max - min;
  1268. var grayscale;
  1269. var hue;
  1270. if (chroma < 1) {
  1271. grayscale = min / (1 - chroma);
  1272. } else {
  1273. grayscale = 0;
  1274. }
  1275. if (chroma <= 0) {
  1276. hue = 0;
  1277. } else if (max === r) {
  1278. hue = (g - b) / chroma % 6;
  1279. } else if (max === g) {
  1280. hue = 2 + (b - r) / chroma;
  1281. } else {
  1282. hue = 4 + (r - g) / chroma + 4;
  1283. }
  1284. hue /= 6;
  1285. hue %= 1;
  1286. return [hue * 360, chroma * 100, grayscale * 100];
  1287. };
  1288. convert.hsl.hcg = function (hsl) {
  1289. var s = hsl[1] / 100;
  1290. var l = hsl[2] / 100;
  1291. var c = 1;
  1292. var f = 0;
  1293. if (l < 0.5) {
  1294. c = 2.0 * s * l;
  1295. } else {
  1296. c = 2.0 * s * (1.0 - l);
  1297. }
  1298. if (c < 1.0) {
  1299. f = (l - 0.5 * c) / (1.0 - c);
  1300. }
  1301. return [hsl[0], c * 100, f * 100];
  1302. };
  1303. convert.hsv.hcg = function (hsv) {
  1304. var s = hsv[1] / 100;
  1305. var v = hsv[2] / 100;
  1306. var c = s * v;
  1307. var f = 0;
  1308. if (c < 1.0) {
  1309. f = (v - c) / (1 - c);
  1310. }
  1311. return [hsv[0], c * 100, f * 100];
  1312. };
  1313. convert.hcg.rgb = function (hcg) {
  1314. var h = hcg[0] / 360;
  1315. var c = hcg[1] / 100;
  1316. var g = hcg[2] / 100;
  1317. if (c === 0.0) {
  1318. return [g * 255, g * 255, g * 255];
  1319. }
  1320. var pure = [0, 0, 0];
  1321. var hi = h % 1 * 6;
  1322. var v = hi % 1;
  1323. var w = 1 - v;
  1324. var mg = 0;
  1325. switch (Math.floor(hi)) {
  1326. case 0:
  1327. pure[0] = 1;
  1328. pure[1] = v;
  1329. pure[2] = 0;
  1330. break;
  1331. case 1:
  1332. pure[0] = w;
  1333. pure[1] = 1;
  1334. pure[2] = 0;
  1335. break;
  1336. case 2:
  1337. pure[0] = 0;
  1338. pure[1] = 1;
  1339. pure[2] = v;
  1340. break;
  1341. case 3:
  1342. pure[0] = 0;
  1343. pure[1] = w;
  1344. pure[2] = 1;
  1345. break;
  1346. case 4:
  1347. pure[0] = v;
  1348. pure[1] = 0;
  1349. pure[2] = 1;
  1350. break;
  1351. default:
  1352. pure[0] = 1;
  1353. pure[1] = 0;
  1354. pure[2] = w;
  1355. }
  1356. mg = (1.0 - c) * g;
  1357. return [(c * pure[0] + mg) * 255, (c * pure[1] + mg) * 255, (c * pure[2] + mg) * 255];
  1358. };
  1359. convert.hcg.hsv = function (hcg) {
  1360. var c = hcg[1] / 100;
  1361. var g = hcg[2] / 100;
  1362. var v = c + g * (1.0 - c);
  1363. var f = 0;
  1364. if (v > 0.0) {
  1365. f = c / v;
  1366. }
  1367. return [hcg[0], f * 100, v * 100];
  1368. };
  1369. convert.hcg.hsl = function (hcg) {
  1370. var c = hcg[1] / 100;
  1371. var g = hcg[2] / 100;
  1372. var l = g * (1.0 - c) + 0.5 * c;
  1373. var s = 0;
  1374. if (l > 0.0 && l < 0.5) {
  1375. s = c / (2 * l);
  1376. } else if (l >= 0.5 && l < 1.0) {
  1377. s = c / (2 * (1 - l));
  1378. }
  1379. return [hcg[0], s * 100, l * 100];
  1380. };
  1381. convert.hcg.hwb = function (hcg) {
  1382. var c = hcg[1] / 100;
  1383. var g = hcg[2] / 100;
  1384. var v = c + g * (1.0 - c);
  1385. return [hcg[0], (v - c) * 100, (1 - v) * 100];
  1386. };
  1387. convert.hwb.hcg = function (hwb) {
  1388. var w = hwb[1] / 100;
  1389. var b = hwb[2] / 100;
  1390. var v = 1 - b;
  1391. var c = v - w;
  1392. var g = 0;
  1393. if (c < 1) {
  1394. g = (v - c) / (1 - c);
  1395. }
  1396. return [hwb[0], c * 100, g * 100];
  1397. };
  1398. convert.apple.rgb = function (apple) {
  1399. return [apple[0] / 65535 * 255, apple[1] / 65535 * 255, apple[2] / 65535 * 255];
  1400. };
  1401. convert.rgb.apple = function (rgb) {
  1402. return [rgb[0] / 255 * 65535, rgb[1] / 255 * 65535, rgb[2] / 255 * 65535];
  1403. };
  1404. convert.gray.rgb = function (args) {
  1405. return [args[0] / 100 * 255, args[0] / 100 * 255, args[0] / 100 * 255];
  1406. };
  1407. convert.gray.hsl = convert.gray.hsv = function (args) {
  1408. return [0, 0, args[0]];
  1409. };
  1410. convert.gray.hwb = function (gray) {
  1411. return [0, 100, gray[0]];
  1412. };
  1413. convert.gray.cmyk = function (gray) {
  1414. return [0, 0, 0, gray[0]];
  1415. };
  1416. convert.gray.lab = function (gray) {
  1417. return [gray[0], 0, 0];
  1418. };
  1419. convert.gray.hex = function (gray) {
  1420. var val = Math.round(gray[0] / 100 * 255) & 0xFF;
  1421. var integer = (val << 16) + (val << 8) + val;
  1422. var string = integer.toString(16).toUpperCase();
  1423. return '000000'.substring(string.length) + string;
  1424. };
  1425. convert.rgb.gray = function (rgb) {
  1426. var val = (rgb[0] + rgb[1] + rgb[2]) / 3;
  1427. return [val / 255 * 100];
  1428. };
  1429. });
  1430. /*
  1431. this function routes a model to all other models.
  1432. all functions that are routed have a property `.conversion` attached
  1433. to the returned synthetic function. This property is an array
  1434. of strings, each with the steps in between the 'from' and 'to'
  1435. color models (inclusive).
  1436. conversions that are not possible simply are not included.
  1437. */
  1438. function buildGraph() {
  1439. var graph = {}; // https://jsperf.com/object-keys-vs-for-in-with-closure/3
  1440. var models = Object.keys(conversions);
  1441. for (var len = models.length, i = 0; i < len; i++) {
  1442. graph[models[i]] = {
  1443. // http://jsperf.com/1-vs-infinity
  1444. // micro-opt, but this is simple.
  1445. distance: -1,
  1446. parent: null
  1447. };
  1448. }
  1449. return graph;
  1450. } // https://en.wikipedia.org/wiki/Breadth-first_search
  1451. function deriveBFS(fromModel) {
  1452. var graph = buildGraph();
  1453. var queue = [fromModel]; // unshift -> queue -> pop
  1454. graph[fromModel].distance = 0;
  1455. while (queue.length) {
  1456. var current = queue.pop();
  1457. var adjacents = Object.keys(conversions[current]);
  1458. for (var len = adjacents.length, i = 0; i < len; i++) {
  1459. var adjacent = adjacents[i];
  1460. var node = graph[adjacent];
  1461. if (node.distance === -1) {
  1462. node.distance = graph[current].distance + 1;
  1463. node.parent = current;
  1464. queue.unshift(adjacent);
  1465. }
  1466. }
  1467. }
  1468. return graph;
  1469. }
  1470. function link(from, to) {
  1471. return function (args) {
  1472. return to(from(args));
  1473. };
  1474. }
  1475. function wrapConversion(toModel, graph) {
  1476. var path = [graph[toModel].parent, toModel];
  1477. var fn = conversions[graph[toModel].parent][toModel];
  1478. var cur = graph[toModel].parent;
  1479. while (graph[cur].parent) {
  1480. path.unshift(graph[cur].parent);
  1481. fn = link(conversions[graph[cur].parent][cur], fn);
  1482. cur = graph[cur].parent;
  1483. }
  1484. fn.conversion = path;
  1485. return fn;
  1486. }
  1487. var route = function (fromModel) {
  1488. var graph = deriveBFS(fromModel);
  1489. var conversion = {};
  1490. var models = Object.keys(graph);
  1491. for (var len = models.length, i = 0; i < len; i++) {
  1492. var toModel = models[i];
  1493. var node = graph[toModel];
  1494. if (node.parent === null) {
  1495. // no possible conversion, or this node is the source model.
  1496. continue;
  1497. }
  1498. conversion[toModel] = wrapConversion(toModel, graph);
  1499. }
  1500. return conversion;
  1501. };
  1502. var convert = {};
  1503. var models = Object.keys(conversions);
  1504. function wrapRaw(fn) {
  1505. var wrappedFn = function (args) {
  1506. if (args === undefined || args === null) {
  1507. return args;
  1508. }
  1509. if (arguments.length > 1) {
  1510. args = Array.prototype.slice.call(arguments);
  1511. }
  1512. return fn(args);
  1513. }; // preserve .conversion property if there is one
  1514. if ('conversion' in fn) {
  1515. wrappedFn.conversion = fn.conversion;
  1516. }
  1517. return wrappedFn;
  1518. }
  1519. function wrapRounded(fn) {
  1520. var wrappedFn = function (args) {
  1521. if (args === undefined || args === null) {
  1522. return args;
  1523. }
  1524. if (arguments.length > 1) {
  1525. args = Array.prototype.slice.call(arguments);
  1526. }
  1527. var result = fn(args); // we're assuming the result is an array here.
  1528. // see notice in conversions.js; don't use box types
  1529. // in conversion functions.
  1530. if (typeof result === 'object') {
  1531. for (var len = result.length, i = 0; i < len; i++) {
  1532. result[i] = Math.round(result[i]);
  1533. }
  1534. }
  1535. return result;
  1536. }; // preserve .conversion property if there is one
  1537. if ('conversion' in fn) {
  1538. wrappedFn.conversion = fn.conversion;
  1539. }
  1540. return wrappedFn;
  1541. }
  1542. models.forEach(function (fromModel) {
  1543. convert[fromModel] = {};
  1544. Object.defineProperty(convert[fromModel], 'channels', {
  1545. value: conversions[fromModel].channels
  1546. });
  1547. Object.defineProperty(convert[fromModel], 'labels', {
  1548. value: conversions[fromModel].labels
  1549. });
  1550. var routes = route(fromModel);
  1551. var routeModels = Object.keys(routes);
  1552. routeModels.forEach(function (toModel) {
  1553. var fn = routes[toModel];
  1554. convert[fromModel][toModel] = wrapRounded(fn);
  1555. convert[fromModel][toModel].raw = wrapRaw(fn);
  1556. });
  1557. });
  1558. var colorConvert = convert;
  1559. var ansiStyles = createCommonjsModule(function (module) {
  1560. const wrapAnsi16 = (fn, offset) => function () {
  1561. const code = fn.apply(colorConvert, arguments);
  1562. return `\u001B[${code + offset}m`;
  1563. };
  1564. const wrapAnsi256 = (fn, offset) => function () {
  1565. const code = fn.apply(colorConvert, arguments);
  1566. return `\u001B[${38 + offset};5;${code}m`;
  1567. };
  1568. const wrapAnsi16m = (fn, offset) => function () {
  1569. const rgb = fn.apply(colorConvert, arguments);
  1570. return `\u001B[${38 + offset};2;${rgb[0]};${rgb[1]};${rgb[2]}m`;
  1571. };
  1572. function assembleStyles() {
  1573. const codes = new Map();
  1574. const styles = {
  1575. modifier: {
  1576. reset: [0, 0],
  1577. // 21 isn't widely supported and 22 does the same thing
  1578. bold: [1, 22],
  1579. dim: [2, 22],
  1580. italic: [3, 23],
  1581. underline: [4, 24],
  1582. inverse: [7, 27],
  1583. hidden: [8, 28],
  1584. strikethrough: [9, 29]
  1585. },
  1586. color: {
  1587. black: [30, 39],
  1588. red: [31, 39],
  1589. green: [32, 39],
  1590. yellow: [33, 39],
  1591. blue: [34, 39],
  1592. magenta: [35, 39],
  1593. cyan: [36, 39],
  1594. white: [37, 39],
  1595. gray: [90, 39],
  1596. // Bright color
  1597. redBright: [91, 39],
  1598. greenBright: [92, 39],
  1599. yellowBright: [93, 39],
  1600. blueBright: [94, 39],
  1601. magentaBright: [95, 39],
  1602. cyanBright: [96, 39],
  1603. whiteBright: [97, 39]
  1604. },
  1605. bgColor: {
  1606. bgBlack: [40, 49],
  1607. bgRed: [41, 49],
  1608. bgGreen: [42, 49],
  1609. bgYellow: [43, 49],
  1610. bgBlue: [44, 49],
  1611. bgMagenta: [45, 49],
  1612. bgCyan: [46, 49],
  1613. bgWhite: [47, 49],
  1614. // Bright color
  1615. bgBlackBright: [100, 49],
  1616. bgRedBright: [101, 49],
  1617. bgGreenBright: [102, 49],
  1618. bgYellowBright: [103, 49],
  1619. bgBlueBright: [104, 49],
  1620. bgMagentaBright: [105, 49],
  1621. bgCyanBright: [106, 49],
  1622. bgWhiteBright: [107, 49]
  1623. }
  1624. }; // Fix humans
  1625. styles.color.grey = styles.color.gray;
  1626. for (const groupName of Object.keys(styles)) {
  1627. const group = styles[groupName];
  1628. for (const styleName of Object.keys(group)) {
  1629. const style = group[styleName];
  1630. styles[styleName] = {
  1631. open: `\u001B[${style[0]}m`,
  1632. close: `\u001B[${style[1]}m`
  1633. };
  1634. group[styleName] = styles[styleName];
  1635. codes.set(style[0], style[1]);
  1636. }
  1637. Object.defineProperty(styles, groupName, {
  1638. value: group,
  1639. enumerable: false
  1640. });
  1641. Object.defineProperty(styles, 'codes', {
  1642. value: codes,
  1643. enumerable: false
  1644. });
  1645. }
  1646. const ansi2ansi = n => n;
  1647. const rgb2rgb = (r, g, b) => [r, g, b];
  1648. styles.color.close = '\u001B[39m';
  1649. styles.bgColor.close = '\u001B[49m';
  1650. styles.color.ansi = {
  1651. ansi: wrapAnsi16(ansi2ansi, 0)
  1652. };
  1653. styles.color.ansi256 = {
  1654. ansi256: wrapAnsi256(ansi2ansi, 0)
  1655. };
  1656. styles.color.ansi16m = {
  1657. rgb: wrapAnsi16m(rgb2rgb, 0)
  1658. };
  1659. styles.bgColor.ansi = {
  1660. ansi: wrapAnsi16(ansi2ansi, 10)
  1661. };
  1662. styles.bgColor.ansi256 = {
  1663. ansi256: wrapAnsi256(ansi2ansi, 10)
  1664. };
  1665. styles.bgColor.ansi16m = {
  1666. rgb: wrapAnsi16m(rgb2rgb, 10)
  1667. };
  1668. for (let key of Object.keys(colorConvert)) {
  1669. if (typeof colorConvert[key] !== 'object') {
  1670. continue;
  1671. }
  1672. const suite = colorConvert[key];
  1673. if (key === 'ansi16') {
  1674. key = 'ansi';
  1675. }
  1676. if ('ansi16' in suite) {
  1677. styles.color.ansi[key] = wrapAnsi16(suite.ansi16, 0);
  1678. styles.bgColor.ansi[key] = wrapAnsi16(suite.ansi16, 10);
  1679. }
  1680. if ('ansi256' in suite) {
  1681. styles.color.ansi256[key] = wrapAnsi256(suite.ansi256, 0);
  1682. styles.bgColor.ansi256[key] = wrapAnsi256(suite.ansi256, 10);
  1683. }
  1684. if ('rgb' in suite) {
  1685. styles.color.ansi16m[key] = wrapAnsi16m(suite.rgb, 0);
  1686. styles.bgColor.ansi16m[key] = wrapAnsi16m(suite.rgb, 10);
  1687. }
  1688. }
  1689. return styles;
  1690. } // Make the export immutable
  1691. Object.defineProperty(module, 'exports', {
  1692. enumerable: true,
  1693. get: assembleStyles
  1694. });
  1695. });
  1696. var hasFlag = (flag, argv) => {
  1697. argv = argv || process.argv;
  1698. const prefix = flag.startsWith('-') ? '' : flag.length === 1 ? '-' : '--';
  1699. const pos = argv.indexOf(prefix + flag);
  1700. const terminatorPos = argv.indexOf('--');
  1701. return pos !== -1 && (terminatorPos === -1 ? true : pos < terminatorPos);
  1702. };
  1703. const env = process.env;
  1704. let forceColor;
  1705. if (hasFlag('no-color') || hasFlag('no-colors') || hasFlag('color=false')) {
  1706. forceColor = false;
  1707. } else if (hasFlag('color') || hasFlag('colors') || hasFlag('color=true') || hasFlag('color=always')) {
  1708. forceColor = true;
  1709. }
  1710. if ('FORCE_COLOR' in env) {
  1711. forceColor = env.FORCE_COLOR.length === 0 || parseInt(env.FORCE_COLOR, 10) !== 0;
  1712. }
  1713. function translateLevel(level) {
  1714. if (level === 0) {
  1715. return false;
  1716. }
  1717. return {
  1718. level,
  1719. hasBasic: true,
  1720. has256: level >= 2,
  1721. has16m: level >= 3
  1722. };
  1723. }
  1724. function supportsColor(stream) {
  1725. if (forceColor === false) {
  1726. return 0;
  1727. }
  1728. if (hasFlag('color=16m') || hasFlag('color=full') || hasFlag('color=truecolor')) {
  1729. return 3;
  1730. }
  1731. if (hasFlag('color=256')) {
  1732. return 2;
  1733. }
  1734. if (stream && !stream.isTTY && forceColor !== true) {
  1735. return 0;
  1736. }
  1737. const min = forceColor ? 1 : 0;
  1738. if (process.platform === 'win32') {
  1739. // Node.js 7.5.0 is the first version of Node.js to include a patch to
  1740. // libuv that enables 256 color output on Windows. Anything earlier and it
  1741. // won't work. However, here we target Node.js 8 at minimum as it is an LTS
  1742. // release, and Node.js 7 is not. Windows 10 build 10586 is the first Windows
  1743. // release that supports 256 colors. Windows 10 build 14931 is the first release
  1744. // that supports 16m/TrueColor.
  1745. const osRelease = os__default['default'].release().split('.');
  1746. if (Number(process.versions.node.split('.')[0]) >= 8 && Number(osRelease[0]) >= 10 && Number(osRelease[2]) >= 10586) {
  1747. return Number(osRelease[2]) >= 14931 ? 3 : 2;
  1748. }
  1749. return 1;
  1750. }
  1751. if ('CI' in env) {
  1752. if (['TRAVIS', 'CIRCLECI', 'APPVEYOR', 'GITLAB_CI'].some(sign => sign in env) || env.CI_NAME === 'codeship') {
  1753. return 1;
  1754. }
  1755. return min;
  1756. }
  1757. if ('TEAMCITY_VERSION' in env) {
  1758. return /^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(env.TEAMCITY_VERSION) ? 1 : 0;
  1759. }
  1760. if (env.COLORTERM === 'truecolor') {
  1761. return 3;
  1762. }
  1763. if ('TERM_PROGRAM' in env) {
  1764. const version = parseInt((env.TERM_PROGRAM_VERSION || '').split('.')[0], 10);
  1765. switch (env.TERM_PROGRAM) {
  1766. case 'iTerm.app':
  1767. return version >= 3 ? 3 : 2;
  1768. case 'Apple_Terminal':
  1769. return 2;
  1770. // No default
  1771. }
  1772. }
  1773. if (/-256(color)?$/i.test(env.TERM)) {
  1774. return 2;
  1775. }
  1776. if (/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(env.TERM)) {
  1777. return 1;
  1778. }
  1779. if ('COLORTERM' in env) {
  1780. return 1;
  1781. }
  1782. if (env.TERM === 'dumb') {
  1783. return min;
  1784. }
  1785. return min;
  1786. }
  1787. function getSupportLevel(stream) {
  1788. const level = supportsColor(stream);
  1789. return translateLevel(level);
  1790. }
  1791. var supportsColor_1 = {
  1792. supportsColor: getSupportLevel,
  1793. stdout: getSupportLevel(process.stdout),
  1794. stderr: getSupportLevel(process.stderr)
  1795. };
  1796. const TEMPLATE_REGEX = /(?:\\(u[a-f\d]{4}|x[a-f\d]{2}|.))|(?:\{(~)?(\w+(?:\([^)]*\))?(?:\.\w+(?:\([^)]*\))?)*)(?:[ \t]|(?=\r?\n)))|(\})|((?:.|[\r\n\f])+?)/gi;
  1797. const STYLE_REGEX = /(?:^|\.)(\w+)(?:\(([^)]*)\))?/g;
  1798. const STRING_REGEX = /^(['"])((?:\\.|(?!\1)[^\\])*)\1$/;
  1799. const ESCAPE_REGEX = /\\(u[a-f\d]{4}|x[a-f\d]{2}|.)|([^\\])/gi;
  1800. const ESCAPES = new Map([['n', '\n'], ['r', '\r'], ['t', '\t'], ['b', '\b'], ['f', '\f'], ['v', '\v'], ['0', '\0'], ['\\', '\\'], ['e', '\u001B'], ['a', '\u0007']]);
  1801. function unescape(c) {
  1802. if (c[0] === 'u' && c.length === 5 || c[0] === 'x' && c.length === 3) {
  1803. return String.fromCharCode(parseInt(c.slice(1), 16));
  1804. }
  1805. return ESCAPES.get(c) || c;
  1806. }
  1807. function parseArguments(name, args) {
  1808. const results = [];
  1809. const chunks = args.trim().split(/\s*,\s*/g);
  1810. let matches;
  1811. for (const chunk of chunks) {
  1812. if (!isNaN(chunk)) {
  1813. results.push(Number(chunk));
  1814. } else if (matches = chunk.match(STRING_REGEX)) {
  1815. results.push(matches[2].replace(ESCAPE_REGEX, (m, escape, chr) => escape ? unescape(escape) : chr));
  1816. } else {
  1817. throw new Error(`Invalid Chalk template style argument: ${chunk} (in style '${name}')`);
  1818. }
  1819. }
  1820. return results;
  1821. }
  1822. function parseStyle(style) {
  1823. STYLE_REGEX.lastIndex = 0;
  1824. const results = [];
  1825. let matches;
  1826. while ((matches = STYLE_REGEX.exec(style)) !== null) {
  1827. const name = matches[1];
  1828. if (matches[2]) {
  1829. const args = parseArguments(name, matches[2]);
  1830. results.push([name].concat(args));
  1831. } else {
  1832. results.push([name]);
  1833. }
  1834. }
  1835. return results;
  1836. }
  1837. function buildStyle(chalk, styles) {
  1838. const enabled = {};
  1839. for (const layer of styles) {
  1840. for (const style of layer.styles) {
  1841. enabled[style[0]] = layer.inverse ? null : style.slice(1);
  1842. }
  1843. }
  1844. let current = chalk;
  1845. for (const styleName of Object.keys(enabled)) {
  1846. if (Array.isArray(enabled[styleName])) {
  1847. if (!(styleName in current)) {
  1848. throw new Error(`Unknown Chalk style: ${styleName}`);
  1849. }
  1850. if (enabled[styleName].length > 0) {
  1851. current = current[styleName].apply(current, enabled[styleName]);
  1852. } else {
  1853. current = current[styleName];
  1854. }
  1855. }
  1856. }
  1857. return current;
  1858. }
  1859. var templates = (chalk, tmp) => {
  1860. const styles = [];
  1861. const chunks = [];
  1862. let chunk = []; // eslint-disable-next-line max-params
  1863. tmp.replace(TEMPLATE_REGEX, (m, escapeChar, inverse, style, close, chr) => {
  1864. if (escapeChar) {
  1865. chunk.push(unescape(escapeChar));
  1866. } else if (style) {
  1867. const str = chunk.join('');
  1868. chunk = [];
  1869. chunks.push(styles.length === 0 ? str : buildStyle(chalk, styles)(str));
  1870. styles.push({
  1871. inverse,
  1872. styles: parseStyle(style)
  1873. });
  1874. } else if (close) {
  1875. if (styles.length === 0) {
  1876. throw new Error('Found extraneous } in Chalk template literal');
  1877. }
  1878. chunks.push(buildStyle(chalk, styles)(chunk.join('')));
  1879. chunk = [];
  1880. styles.pop();
  1881. } else {
  1882. chunk.push(chr);
  1883. }
  1884. });
  1885. chunks.push(chunk.join(''));
  1886. if (styles.length > 0) {
  1887. const errMsg = `Chalk template literal is missing ${styles.length} closing bracket${styles.length === 1 ? '' : 's'} (\`}\`)`;
  1888. throw new Error(errMsg);
  1889. }
  1890. return chunks.join('');
  1891. };
  1892. var chalk = createCommonjsModule(function (module) {
  1893. const stdoutColor = supportsColor_1.stdout;
  1894. const isSimpleWindowsTerm = process.platform === 'win32' && !(process.env.TERM || '').toLowerCase().startsWith('xterm'); // `supportsColor.level` → `ansiStyles.color[name]` mapping
  1895. const levelMapping = ['ansi', 'ansi', 'ansi256', 'ansi16m']; // `color-convert` models to exclude from the Chalk API due to conflicts and such
  1896. const skipModels = new Set(['gray']);
  1897. const styles = Object.create(null);
  1898. function applyOptions(obj, options) {
  1899. options = options || {}; // Detect level if not set manually
  1900. const scLevel = stdoutColor ? stdoutColor.level : 0;
  1901. obj.level = options.level === undefined ? scLevel : options.level;
  1902. obj.enabled = 'enabled' in options ? options.enabled : obj.level > 0;
  1903. }
  1904. function Chalk(options) {
  1905. // We check for this.template here since calling `chalk.constructor()`
  1906. // by itself will have a `this` of a previously constructed chalk object
  1907. if (!this || !(this instanceof Chalk) || this.template) {
  1908. const chalk = {};
  1909. applyOptions(chalk, options);
  1910. chalk.template = function () {
  1911. const args = [].slice.call(arguments);
  1912. return chalkTag.apply(null, [chalk.template].concat(args));
  1913. };
  1914. Object.setPrototypeOf(chalk, Chalk.prototype);
  1915. Object.setPrototypeOf(chalk.template, chalk);
  1916. chalk.template.constructor = Chalk;
  1917. return chalk.template;
  1918. }
  1919. applyOptions(this, options);
  1920. } // Use bright blue on Windows as the normal blue color is illegible
  1921. if (isSimpleWindowsTerm) {
  1922. ansiStyles.blue.open = '\u001B[94m';
  1923. }
  1924. for (const key of Object.keys(ansiStyles)) {
  1925. ansiStyles[key].closeRe = new RegExp(escapeStringRegexp(ansiStyles[key].close), 'g');
  1926. styles[key] = {
  1927. get() {
  1928. const codes = ansiStyles[key];
  1929. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, key);
  1930. }
  1931. };
  1932. }
  1933. styles.visible = {
  1934. get() {
  1935. return build.call(this, this._styles || [], true, 'visible');
  1936. }
  1937. };
  1938. ansiStyles.color.closeRe = new RegExp(escapeStringRegexp(ansiStyles.color.close), 'g');
  1939. for (const model of Object.keys(ansiStyles.color.ansi)) {
  1940. if (skipModels.has(model)) {
  1941. continue;
  1942. }
  1943. styles[model] = {
  1944. get() {
  1945. const level = this.level;
  1946. return function () {
  1947. const open = ansiStyles.color[levelMapping[level]][model].apply(null, arguments);
  1948. const codes = {
  1949. open,
  1950. close: ansiStyles.color.close,
  1951. closeRe: ansiStyles.color.closeRe
  1952. };
  1953. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  1954. };
  1955. }
  1956. };
  1957. }
  1958. ansiStyles.bgColor.closeRe = new RegExp(escapeStringRegexp(ansiStyles.bgColor.close), 'g');
  1959. for (const model of Object.keys(ansiStyles.bgColor.ansi)) {
  1960. if (skipModels.has(model)) {
  1961. continue;
  1962. }
  1963. const bgModel = 'bg' + model[0].toUpperCase() + model.slice(1);
  1964. styles[bgModel] = {
  1965. get() {
  1966. const level = this.level;
  1967. return function () {
  1968. const open = ansiStyles.bgColor[levelMapping[level]][model].apply(null, arguments);
  1969. const codes = {
  1970. open,
  1971. close: ansiStyles.bgColor.close,
  1972. closeRe: ansiStyles.bgColor.closeRe
  1973. };
  1974. return build.call(this, this._styles ? this._styles.concat(codes) : [codes], this._empty, model);
  1975. };
  1976. }
  1977. };
  1978. }
  1979. const proto = Object.defineProperties(() => {}, styles);
  1980. function build(_styles, _empty, key) {
  1981. const builder = function () {
  1982. return applyStyle.apply(builder, arguments);
  1983. };
  1984. builder._styles = _styles;
  1985. builder._empty = _empty;
  1986. const self = this;
  1987. Object.defineProperty(builder, 'level', {
  1988. enumerable: true,
  1989. get() {
  1990. return self.level;
  1991. },
  1992. set(level) {
  1993. self.level = level;
  1994. }
  1995. });
  1996. Object.defineProperty(builder, 'enabled', {
  1997. enumerable: true,
  1998. get() {
  1999. return self.enabled;
  2000. },
  2001. set(enabled) {
  2002. self.enabled = enabled;
  2003. }
  2004. }); // See below for fix regarding invisible grey/dim combination on Windows
  2005. builder.hasGrey = this.hasGrey || key === 'gray' || key === 'grey'; // `__proto__` is used because we must return a function, but there is
  2006. // no way to create a function with a different prototype
  2007. builder.__proto__ = proto; // eslint-disable-line no-proto
  2008. return builder;
  2009. }
  2010. function applyStyle() {
  2011. // Support varags, but simply cast to string in case there's only one arg
  2012. const args = arguments;
  2013. const argsLen = args.length;
  2014. let str = String(arguments[0]);
  2015. if (argsLen === 0) {
  2016. return '';
  2017. }
  2018. if (argsLen > 1) {
  2019. // Don't slice `arguments`, it prevents V8 optimizations
  2020. for (let a = 1; a < argsLen; a++) {
  2021. str += ' ' + args[a];
  2022. }
  2023. }
  2024. if (!this.enabled || this.level <= 0 || !str) {
  2025. return this._empty ? '' : str;
  2026. } // Turns out that on Windows dimmed gray text becomes invisible in cmd.exe,
  2027. // see https://github.com/chalk/chalk/issues/58
  2028. // If we're on Windows and we're dealing with a gray color, temporarily make 'dim' a noop.
  2029. const originalDim = ansiStyles.dim.open;
  2030. if (isSimpleWindowsTerm && this.hasGrey) {
  2031. ansiStyles.dim.open = '';
  2032. }
  2033. for (const code of this._styles.slice().reverse()) {
  2034. // Replace any instances already present with a re-opening code
  2035. // otherwise only the part of the string until said closing code
  2036. // will be colored, and the rest will simply be 'plain'.
  2037. str = code.open + str.replace(code.closeRe, code.open) + code.close; // Close the styling before a linebreak and reopen
  2038. // after next line to fix a bleed issue on macOS
  2039. // https://github.com/chalk/chalk/pull/92
  2040. str = str.replace(/\r?\n/g, `${code.close}$&${code.open}`);
  2041. } // Reset the original `dim` if we changed it to work around the Windows dimmed gray issue
  2042. ansiStyles.dim.open = originalDim;
  2043. return str;
  2044. }
  2045. function chalkTag(chalk, strings) {
  2046. if (!Array.isArray(strings)) {
  2047. // If chalk() was called by itself or with a string,
  2048. // return the string itself as a string.
  2049. return [].slice.call(arguments, 1).join(' ');
  2050. }
  2051. const args = [].slice.call(arguments, 2);
  2052. const parts = [strings.raw[0]];
  2053. for (let i = 1; i < strings.length; i++) {
  2054. parts.push(String(args[i - 1]).replace(/[{}\\]/g, '\\$&'));
  2055. parts.push(String(strings.raw[i]));
  2056. }
  2057. return templates(chalk, parts.join(''));
  2058. }
  2059. Object.defineProperties(Chalk.prototype, styles);
  2060. module.exports = Chalk(); // eslint-disable-line new-cap
  2061. module.exports.supportsColor = stdoutColor;
  2062. module.exports.default = module.exports; // For TypeScript
  2063. });
  2064. var shouldHighlight_1 = shouldHighlight;
  2065. var getChalk_1 = getChalk;
  2066. var _default$1 = highlight;
  2067. const sometimesKeywords = new Set(["as", "async", "from", "get", "of", "set"]);
  2068. function getDefs$1(chalk) {
  2069. return {
  2070. keyword: chalk.cyan,
  2071. capitalized: chalk.yellow,
  2072. jsxIdentifier: chalk.yellow,
  2073. punctuator: chalk.yellow,
  2074. number: chalk.magenta,
  2075. string: chalk.green,
  2076. regex: chalk.magenta,
  2077. comment: chalk.grey,
  2078. invalid: chalk.white.bgRed.bold
  2079. };
  2080. }
  2081. const NEWLINE$1 = /\r\n|[\n\r\u2028\u2029]/;
  2082. const BRACKET = /^[()[\]{}]$/;
  2083. let tokenize;
  2084. {
  2085. const JSX_TAG = /^[a-z][\w-]*$/i;
  2086. const getTokenType = function (token, offset, text) {
  2087. if (token.type === "name") {
  2088. if ((0, lib$2.isKeyword)(token.value) || (0, lib$2.isStrictReservedWord)(token.value, true) || sometimesKeywords.has(token.value)) {
  2089. return "keyword";
  2090. }
  2091. if (JSX_TAG.test(token.value) && (text[offset - 1] === "<" || text.substr(offset - 2, 2) == "</")) {
  2092. return "jsxIdentifier";
  2093. }
  2094. if (token.value[0] !== token.value[0].toLowerCase()) {
  2095. return "capitalized";
  2096. }
  2097. }
  2098. if (token.type === "punctuator" && BRACKET.test(token.value)) {
  2099. return "bracket";
  2100. }
  2101. if (token.type === "invalid" && (token.value === "@" || token.value === "#")) {
  2102. return "punctuator";
  2103. }
  2104. return token.type;
  2105. };
  2106. tokenize = function* (text) {
  2107. let match;
  2108. while (match = jsTokens.default.exec(text)) {
  2109. const token = jsTokens.matchToToken(match);
  2110. yield {
  2111. type: getTokenType(token, match.index, text),
  2112. value: token.value
  2113. };
  2114. }
  2115. };
  2116. }
  2117. function highlightTokens(defs, text) {
  2118. let highlighted = "";
  2119. for (const {
  2120. type,
  2121. value
  2122. } of tokenize(text)) {
  2123. const colorize = defs[type];
  2124. if (colorize) {
  2125. highlighted += value.split(NEWLINE$1).map(str => colorize(str)).join("\n");
  2126. } else {
  2127. highlighted += value;
  2128. }
  2129. }
  2130. return highlighted;
  2131. }
  2132. function shouldHighlight(options) {
  2133. return !!chalk.supportsColor || options.forceColor;
  2134. }
  2135. function getChalk(options) {
  2136. return options.forceColor ? new chalk.constructor({
  2137. enabled: true,
  2138. level: 1
  2139. }) : chalk;
  2140. }
  2141. function highlight(code, options = {}) {
  2142. if (shouldHighlight(options)) {
  2143. const chalk = getChalk(options);
  2144. const defs = getDefs$1(chalk);
  2145. return highlightTokens(defs, code);
  2146. } else {
  2147. return code;
  2148. }
  2149. }
  2150. var lib$1 = /*#__PURE__*/Object.defineProperty({
  2151. shouldHighlight: shouldHighlight_1,
  2152. getChalk: getChalk_1,
  2153. default: _default$1
  2154. }, '__esModule', {
  2155. value: true
  2156. });
  2157. var codeFrameColumns_1 = codeFrameColumns$1;
  2158. var default_1 = _default;
  2159. let deprecationWarningShown = false;
  2160. function getDefs(chalk) {
  2161. return {
  2162. gutter: chalk.grey,
  2163. marker: chalk.red.bold,
  2164. message: chalk.red.bold
  2165. };
  2166. }
  2167. const NEWLINE = /\r\n|[\n\r\u2028\u2029]/;
  2168. function getMarkerLines(loc, source, opts) {
  2169. const startLoc = Object.assign({
  2170. column: 0,
  2171. line: -1
  2172. }, loc.start);
  2173. const endLoc = Object.assign({}, startLoc, loc.end);
  2174. const {
  2175. linesAbove = 2,
  2176. linesBelow = 3
  2177. } = opts || {};
  2178. const startLine = startLoc.line;
  2179. const startColumn = startLoc.column;
  2180. const endLine = endLoc.line;
  2181. const endColumn = endLoc.column;
  2182. let start = Math.max(startLine - (linesAbove + 1), 0);
  2183. let end = Math.min(source.length, endLine + linesBelow);
  2184. if (startLine === -1) {
  2185. start = 0;
  2186. }
  2187. if (endLine === -1) {
  2188. end = source.length;
  2189. }
  2190. const lineDiff = endLine - startLine;
  2191. const markerLines = {};
  2192. if (lineDiff) {
  2193. for (let i = 0; i <= lineDiff; i++) {
  2194. const lineNumber = i + startLine;
  2195. if (!startColumn) {
  2196. markerLines[lineNumber] = true;
  2197. } else if (i === 0) {
  2198. const sourceLength = source[lineNumber - 1].length;
  2199. markerLines[lineNumber] = [startColumn, sourceLength - startColumn + 1];
  2200. } else if (i === lineDiff) {
  2201. markerLines[lineNumber] = [0, endColumn];
  2202. } else {
  2203. const sourceLength = source[lineNumber - i].length;
  2204. markerLines[lineNumber] = [0, sourceLength];
  2205. }
  2206. }
  2207. } else {
  2208. if (startColumn === endColumn) {
  2209. if (startColumn) {
  2210. markerLines[startLine] = [startColumn, 0];
  2211. } else {
  2212. markerLines[startLine] = true;
  2213. }
  2214. } else {
  2215. markerLines[startLine] = [startColumn, endColumn - startColumn];
  2216. }
  2217. }
  2218. return {
  2219. start,
  2220. end,
  2221. markerLines
  2222. };
  2223. }
  2224. function codeFrameColumns$1(rawLines, loc, opts = {}) {
  2225. const highlighted = (opts.highlightCode || opts.forceColor) && (0, lib$1.shouldHighlight)(opts);
  2226. const chalk = (0, lib$1.getChalk)(opts);
  2227. const defs = getDefs(chalk);
  2228. const maybeHighlight = (chalkFn, string) => {
  2229. return highlighted ? chalkFn(string) : string;
  2230. };
  2231. const lines = rawLines.split(NEWLINE);
  2232. const {
  2233. start,
  2234. end,
  2235. markerLines
  2236. } = getMarkerLines(loc, lines, opts);
  2237. const hasColumns = loc.start && typeof loc.start.column === "number";
  2238. const numberMaxWidth = String(end).length;
  2239. const highlightedLines = highlighted ? (0, lib$1.default)(rawLines, opts) : rawLines;
  2240. let frame = highlightedLines.split(NEWLINE).slice(start, end).map((line, index) => {
  2241. const number = start + 1 + index;
  2242. const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
  2243. const gutter = ` ${paddedNumber} |`;
  2244. const hasMarker = markerLines[number];
  2245. const lastMarkerLine = !markerLines[number + 1];
  2246. if (hasMarker) {
  2247. let markerLine = "";
  2248. if (Array.isArray(hasMarker)) {
  2249. const markerSpacing = line.slice(0, Math.max(hasMarker[0] - 1, 0)).replace(/[^\t]/g, " ");
  2250. const numberOfMarkers = hasMarker[1] || 1;
  2251. markerLine = ["\n ", maybeHighlight(defs.gutter, gutter.replace(/\d/g, " ")), " ", markerSpacing, maybeHighlight(defs.marker, "^").repeat(numberOfMarkers)].join("");
  2252. if (lastMarkerLine && opts.message) {
  2253. markerLine += " " + maybeHighlight(defs.message, opts.message);
  2254. }
  2255. }
  2256. return [maybeHighlight(defs.marker, ">"), maybeHighlight(defs.gutter, gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
  2257. } else {
  2258. return ` ${maybeHighlight(defs.gutter, gutter)}${line.length > 0 ? ` ${line}` : ""}`;
  2259. }
  2260. }).join("\n");
  2261. if (opts.message && !hasColumns) {
  2262. frame = `${" ".repeat(numberMaxWidth + 1)}${opts.message}\n${frame}`;
  2263. }
  2264. if (highlighted) {
  2265. return chalk.reset(frame);
  2266. } else {
  2267. return frame;
  2268. }
  2269. }
  2270. function _default(rawLines, lineNumber, colNumber, opts = {}) {
  2271. if (!deprecationWarningShown) {
  2272. deprecationWarningShown = true;
  2273. const message = "Passing lineNumber and colNumber is deprecated to @babel/code-frame. Please use `codeFrameColumns`.";
  2274. if (process.emitWarning) {
  2275. process.emitWarning(message, "DeprecationWarning");
  2276. } else {
  2277. const deprecationError = new Error(message);
  2278. deprecationError.name = "DeprecationWarning";
  2279. console.warn(new Error(message));
  2280. }
  2281. }
  2282. colNumber = Math.max(colNumber, 0);
  2283. const location = {
  2284. start: {
  2285. column: colNumber,
  2286. line: lineNumber
  2287. }
  2288. };
  2289. return codeFrameColumns$1(rawLines, location, opts);
  2290. }
  2291. var lib = /*#__PURE__*/Object.defineProperty({
  2292. codeFrameColumns: codeFrameColumns_1,
  2293. default: default_1
  2294. }, '__esModule', {
  2295. value: true
  2296. });
  2297. const {
  2298. default: LinesAndColumns
  2299. } = dist$2;
  2300. const {
  2301. codeFrameColumns
  2302. } = lib;
  2303. const JSONError = errorEx_1('JSONError', {
  2304. fileName: errorEx_1.append('in %s'),
  2305. codeFrame: errorEx_1.append('\n\n%s\n')
  2306. });
  2307. const parseJson = (string, reviver, filename) => {
  2308. if (typeof reviver === 'string') {
  2309. filename = reviver;
  2310. reviver = null;
  2311. }
  2312. try {
  2313. try {
  2314. return JSON.parse(string, reviver);
  2315. } catch (error) {
  2316. jsonParseEvenBetterErrors(string, reviver);
  2317. throw error;
  2318. }
  2319. } catch (error) {
  2320. error.message = error.message.replace(/\n/g, '');
  2321. const indexMatch = error.message.match(/in JSON at position (\d+) while parsing/);
  2322. const jsonError = new JSONError(error);
  2323. if (filename) {
  2324. jsonError.fileName = filename;
  2325. }
  2326. if (indexMatch && indexMatch.length > 0) {
  2327. const lines = new LinesAndColumns(string);
  2328. const index = Number(indexMatch[1]);
  2329. const location = lines.locationForIndex(index);
  2330. const codeFrame = codeFrameColumns(string, {
  2331. start: {
  2332. line: location.line + 1,
  2333. column: location.column + 1
  2334. }
  2335. }, {
  2336. highlightCode: true
  2337. });
  2338. jsonError.codeFrame = codeFrame;
  2339. }
  2340. throw jsonError;
  2341. }
  2342. };
  2343. parseJson.JSONError = JSONError;
  2344. var parseJson_1 = parseJson;
  2345. const Char = {
  2346. ANCHOR: '&',
  2347. COMMENT: '#',
  2348. TAG: '!',
  2349. DIRECTIVES_END: '-',
  2350. DOCUMENT_END: '.'
  2351. };
  2352. const Type = {
  2353. ALIAS: 'ALIAS',
  2354. BLANK_LINE: 'BLANK_LINE',
  2355. BLOCK_FOLDED: 'BLOCK_FOLDED',
  2356. BLOCK_LITERAL: 'BLOCK_LITERAL',
  2357. COMMENT: 'COMMENT',
  2358. DIRECTIVE: 'DIRECTIVE',
  2359. DOCUMENT: 'DOCUMENT',
  2360. FLOW_MAP: 'FLOW_MAP',
  2361. FLOW_SEQ: 'FLOW_SEQ',
  2362. MAP: 'MAP',
  2363. MAP_KEY: 'MAP_KEY',
  2364. MAP_VALUE: 'MAP_VALUE',
  2365. PLAIN: 'PLAIN',
  2366. QUOTE_DOUBLE: 'QUOTE_DOUBLE',
  2367. QUOTE_SINGLE: 'QUOTE_SINGLE',
  2368. SEQ: 'SEQ',
  2369. SEQ_ITEM: 'SEQ_ITEM'
  2370. };
  2371. const defaultTagPrefix = 'tag:yaml.org,2002:';
  2372. const defaultTags = {
  2373. MAP: 'tag:yaml.org,2002:map',
  2374. SEQ: 'tag:yaml.org,2002:seq',
  2375. STR: 'tag:yaml.org,2002:str'
  2376. };
  2377. function findLineStarts(src) {
  2378. const ls = [0];
  2379. let offset = src.indexOf('\n');
  2380. while (offset !== -1) {
  2381. offset += 1;
  2382. ls.push(offset);
  2383. offset = src.indexOf('\n', offset);
  2384. }
  2385. return ls;
  2386. }
  2387. function getSrcInfo(cst) {
  2388. let lineStarts, src;
  2389. if (typeof cst === 'string') {
  2390. lineStarts = findLineStarts(cst);
  2391. src = cst;
  2392. } else {
  2393. if (Array.isArray(cst)) cst = cst[0];
  2394. if (cst && cst.context) {
  2395. if (!cst.lineStarts) cst.lineStarts = findLineStarts(cst.context.src);
  2396. lineStarts = cst.lineStarts;
  2397. src = cst.context.src;
  2398. }
  2399. }
  2400. return {
  2401. lineStarts,
  2402. src
  2403. };
  2404. }
  2405. /**
  2406. * @typedef {Object} LinePos - One-indexed position in the source
  2407. * @property {number} line
  2408. * @property {number} col
  2409. */
  2410. /**
  2411. * Determine the line/col position matching a character offset.
  2412. *
  2413. * Accepts a source string or a CST document as the second parameter. With
  2414. * the latter, starting indices for lines are cached in the document as
  2415. * `lineStarts: number[]`.
  2416. *
  2417. * Returns a one-indexed `{ line, col }` location if found, or
  2418. * `undefined` otherwise.
  2419. *
  2420. * @param {number} offset
  2421. * @param {string|Document|Document[]} cst
  2422. * @returns {?LinePos}
  2423. */
  2424. function getLinePos(offset, cst) {
  2425. if (typeof offset !== 'number' || offset < 0) return null;
  2426. const {
  2427. lineStarts,
  2428. src
  2429. } = getSrcInfo(cst);
  2430. if (!lineStarts || !src || offset > src.length) return null;
  2431. for (let i = 0; i < lineStarts.length; ++i) {
  2432. const start = lineStarts[i];
  2433. if (offset < start) {
  2434. return {
  2435. line: i,
  2436. col: offset - lineStarts[i - 1] + 1
  2437. };
  2438. }
  2439. if (offset === start) return {
  2440. line: i + 1,
  2441. col: 1
  2442. };
  2443. }
  2444. const line = lineStarts.length;
  2445. return {
  2446. line,
  2447. col: offset - lineStarts[line - 1] + 1
  2448. };
  2449. }
  2450. /**
  2451. * Get a specified line from the source.
  2452. *
  2453. * Accepts a source string or a CST document as the second parameter. With
  2454. * the latter, starting indices for lines are cached in the document as
  2455. * `lineStarts: number[]`.
  2456. *
  2457. * Returns the line as a string if found, or `null` otherwise.
  2458. *
  2459. * @param {number} line One-indexed line number
  2460. * @param {string|Document|Document[]} cst
  2461. * @returns {?string}
  2462. */
  2463. function getLine(line, cst) {
  2464. const {
  2465. lineStarts,
  2466. src
  2467. } = getSrcInfo(cst);
  2468. if (!lineStarts || !(line >= 1) || line > lineStarts.length) return null;
  2469. const start = lineStarts[line - 1];
  2470. let end = lineStarts[line]; // undefined for last line; that's ok for slice()
  2471. while (end && end > start && src[end - 1] === '\n') --end;
  2472. return src.slice(start, end);
  2473. }
  2474. /**
  2475. * Pretty-print the starting line from the source indicated by the range `pos`
  2476. *
  2477. * Trims output to `maxWidth` chars while keeping the starting column visible,
  2478. * using `…` at either end to indicate dropped characters.
  2479. *
  2480. * Returns a two-line string (or `null`) with `\n` as separator; the second line
  2481. * will hold appropriately indented `^` marks indicating the column range.
  2482. *
  2483. * @param {Object} pos
  2484. * @param {LinePos} pos.start
  2485. * @param {LinePos} [pos.end]
  2486. * @param {string|Document|Document[]*} cst
  2487. * @param {number} [maxWidth=80]
  2488. * @returns {?string}
  2489. */
  2490. function getPrettyContext({
  2491. start,
  2492. end
  2493. }, cst, maxWidth = 80) {
  2494. let src = getLine(start.line, cst);
  2495. if (!src) return null;
  2496. let {
  2497. col
  2498. } = start;
  2499. if (src.length > maxWidth) {
  2500. if (col <= maxWidth - 10) {
  2501. src = src.substr(0, maxWidth - 1) + '…';
  2502. } else {
  2503. const halfWidth = Math.round(maxWidth / 2);
  2504. if (src.length > col + halfWidth) src = src.substr(0, col + halfWidth - 1) + '…';
  2505. col -= src.length - maxWidth;
  2506. src = '…' + src.substr(1 - maxWidth);
  2507. }
  2508. }
  2509. let errLen = 1;
  2510. let errEnd = '';
  2511. if (end) {
  2512. if (end.line === start.line && col + (end.col - start.col) <= maxWidth + 1) {
  2513. errLen = end.col - start.col;
  2514. } else {
  2515. errLen = Math.min(src.length + 1, maxWidth) - col;
  2516. errEnd = '…';
  2517. }
  2518. }
  2519. const offset = col > 1 ? ' '.repeat(col - 1) : '';
  2520. const err = '^'.repeat(errLen);
  2521. return `${src}\n${offset}${err}${errEnd}`;
  2522. }
  2523. class Range {
  2524. static copy(orig) {
  2525. return new Range(orig.start, orig.end);
  2526. }
  2527. constructor(start, end) {
  2528. this.start = start;
  2529. this.end = end || start;
  2530. }
  2531. isEmpty() {
  2532. return typeof this.start !== 'number' || !this.end || this.end <= this.start;
  2533. }
  2534. /**
  2535. * Set `origStart` and `origEnd` to point to the original source range for
  2536. * this node, which may differ due to dropped CR characters.
  2537. *
  2538. * @param {number[]} cr - Positions of dropped CR characters
  2539. * @param {number} offset - Starting index of `cr` from the last call
  2540. * @returns {number} - The next offset, matching the one found for `origStart`
  2541. */
  2542. setOrigRange(cr, offset) {
  2543. const {
  2544. start,
  2545. end
  2546. } = this;
  2547. if (cr.length === 0 || end <= cr[0]) {
  2548. this.origStart = start;
  2549. this.origEnd = end;
  2550. return offset;
  2551. }
  2552. let i = offset;
  2553. while (i < cr.length) {
  2554. if (cr[i] > start) break;else ++i;
  2555. }
  2556. this.origStart = start + i;
  2557. const nextOffset = i;
  2558. while (i < cr.length) {
  2559. // if end was at \n, it should now be at \r
  2560. if (cr[i] >= end) break;else ++i;
  2561. }
  2562. this.origEnd = end + i;
  2563. return nextOffset;
  2564. }
  2565. }
  2566. /** Root class of all nodes */
  2567. class Node$1 {
  2568. static addStringTerminator(src, offset, str) {
  2569. if (str[str.length - 1] === '\n') return str;
  2570. const next = Node$1.endOfWhiteSpace(src, offset);
  2571. return next >= src.length || src[next] === '\n' ? str + '\n' : str;
  2572. } // ^(---|...)
  2573. static atDocumentBoundary(src, offset, sep) {
  2574. const ch0 = src[offset];
  2575. if (!ch0) return true;
  2576. const prev = src[offset - 1];
  2577. if (prev && prev !== '\n') return false;
  2578. if (sep) {
  2579. if (ch0 !== sep) return false;
  2580. } else {
  2581. if (ch0 !== Char.DIRECTIVES_END && ch0 !== Char.DOCUMENT_END) return false;
  2582. }
  2583. const ch1 = src[offset + 1];
  2584. const ch2 = src[offset + 2];
  2585. if (ch1 !== ch0 || ch2 !== ch0) return false;
  2586. const ch3 = src[offset + 3];
  2587. return !ch3 || ch3 === '\n' || ch3 === '\t' || ch3 === ' ';
  2588. }
  2589. static endOfIdentifier(src, offset) {
  2590. let ch = src[offset];
  2591. const isVerbatim = ch === '<';
  2592. const notOk = isVerbatim ? ['\n', '\t', ' ', '>'] : ['\n', '\t', ' ', '[', ']', '{', '}', ','];
  2593. while (ch && notOk.indexOf(ch) === -1) ch = src[offset += 1];
  2594. if (isVerbatim && ch === '>') offset += 1;
  2595. return offset;
  2596. }
  2597. static endOfIndent(src, offset) {
  2598. let ch = src[offset];
  2599. while (ch === ' ') ch = src[offset += 1];
  2600. return offset;
  2601. }
  2602. static endOfLine(src, offset) {
  2603. let ch = src[offset];
  2604. while (ch && ch !== '\n') ch = src[offset += 1];
  2605. return offset;
  2606. }
  2607. static endOfWhiteSpace(src, offset) {
  2608. let ch = src[offset];
  2609. while (ch === '\t' || ch === ' ') ch = src[offset += 1];
  2610. return offset;
  2611. }
  2612. static startOfLine(src, offset) {
  2613. let ch = src[offset - 1];
  2614. if (ch === '\n') return offset;
  2615. while (ch && ch !== '\n') ch = src[offset -= 1];
  2616. return offset + 1;
  2617. }
  2618. /**
  2619. * End of indentation, or null if the line's indent level is not more
  2620. * than `indent`
  2621. *
  2622. * @param {string} src
  2623. * @param {number} indent
  2624. * @param {number} lineStart
  2625. * @returns {?number}
  2626. */
  2627. static endOfBlockIndent(src, indent, lineStart) {
  2628. const inEnd = Node$1.endOfIndent(src, lineStart);
  2629. if (inEnd > lineStart + indent) {
  2630. return inEnd;
  2631. } else {
  2632. const wsEnd = Node$1.endOfWhiteSpace(src, inEnd);
  2633. const ch = src[wsEnd];
  2634. if (!ch || ch === '\n') return wsEnd;
  2635. }
  2636. return null;
  2637. }
  2638. static atBlank(src, offset, endAsBlank) {
  2639. const ch = src[offset];
  2640. return ch === '\n' || ch === '\t' || ch === ' ' || endAsBlank && !ch;
  2641. }
  2642. static nextNodeIsIndented(ch, indentDiff, indicatorAsIndent) {
  2643. if (!ch || indentDiff < 0) return false;
  2644. if (indentDiff > 0) return true;
  2645. return indicatorAsIndent && ch === '-';
  2646. } // should be at line or string end, or at next non-whitespace char
  2647. static normalizeOffset(src, offset) {
  2648. const ch = src[offset];
  2649. return !ch ? offset : ch !== '\n' && src[offset - 1] === '\n' ? offset - 1 : Node$1.endOfWhiteSpace(src, offset);
  2650. } // fold single newline into space, multiple newlines to N - 1 newlines
  2651. // presumes src[offset] === '\n'
  2652. static foldNewline(src, offset, indent) {
  2653. let inCount = 0;
  2654. let error = false;
  2655. let fold = '';
  2656. let ch = src[offset + 1];
  2657. while (ch === ' ' || ch === '\t' || ch === '\n') {
  2658. switch (ch) {
  2659. case '\n':
  2660. inCount = 0;
  2661. offset += 1;
  2662. fold += '\n';
  2663. break;
  2664. case '\t':
  2665. if (inCount <= indent) error = true;
  2666. offset = Node$1.endOfWhiteSpace(src, offset + 2) - 1;
  2667. break;
  2668. case ' ':
  2669. inCount += 1;
  2670. offset += 1;
  2671. break;
  2672. }
  2673. ch = src[offset + 1];
  2674. }
  2675. if (!fold) fold = ' ';
  2676. if (ch && inCount <= indent) error = true;
  2677. return {
  2678. fold,
  2679. offset,
  2680. error
  2681. };
  2682. }
  2683. constructor(type, props, context) {
  2684. Object.defineProperty(this, 'context', {
  2685. value: context || null,
  2686. writable: true
  2687. });
  2688. this.error = null;
  2689. this.range = null;
  2690. this.valueRange = null;
  2691. this.props = props || [];
  2692. this.type = type;
  2693. this.value = null;
  2694. }
  2695. getPropValue(idx, key, skipKey) {
  2696. if (!this.context) return null;
  2697. const {
  2698. src
  2699. } = this.context;
  2700. const prop = this.props[idx];
  2701. return prop && src[prop.start] === key ? src.slice(prop.start + (skipKey ? 1 : 0), prop.end) : null;
  2702. }
  2703. get anchor() {
  2704. for (let i = 0; i < this.props.length; ++i) {
  2705. const anchor = this.getPropValue(i, Char.ANCHOR, true);
  2706. if (anchor != null) return anchor;
  2707. }
  2708. return null;
  2709. }
  2710. get comment() {
  2711. const comments = [];
  2712. for (let i = 0; i < this.props.length; ++i) {
  2713. const comment = this.getPropValue(i, Char.COMMENT, true);
  2714. if (comment != null) comments.push(comment);
  2715. }
  2716. return comments.length > 0 ? comments.join('\n') : null;
  2717. }
  2718. commentHasRequiredWhitespace(start) {
  2719. const {
  2720. src
  2721. } = this.context;
  2722. if (this.header && start === this.header.end) return false;
  2723. if (!this.valueRange) return false;
  2724. const {
  2725. end
  2726. } = this.valueRange;
  2727. return start !== end || Node$1.atBlank(src, end - 1);
  2728. }
  2729. get hasComment() {
  2730. if (this.context) {
  2731. const {
  2732. src
  2733. } = this.context;
  2734. for (let i = 0; i < this.props.length; ++i) {
  2735. if (src[this.props[i].start] === Char.COMMENT) return true;
  2736. }
  2737. }
  2738. return false;
  2739. }
  2740. get hasProps() {
  2741. if (this.context) {
  2742. const {
  2743. src
  2744. } = this.context;
  2745. for (let i = 0; i < this.props.length; ++i) {
  2746. if (src[this.props[i].start] !== Char.COMMENT) return true;
  2747. }
  2748. }
  2749. return false;
  2750. }
  2751. get includesTrailingLines() {
  2752. return false;
  2753. }
  2754. get jsonLike() {
  2755. const jsonLikeTypes = [Type.FLOW_MAP, Type.FLOW_SEQ, Type.QUOTE_DOUBLE, Type.QUOTE_SINGLE];
  2756. return jsonLikeTypes.indexOf(this.type) !== -1;
  2757. }
  2758. get rangeAsLinePos() {
  2759. if (!this.range || !this.context) return undefined;
  2760. const start = getLinePos(this.range.start, this.context.root);
  2761. if (!start) return undefined;
  2762. const end = getLinePos(this.range.end, this.context.root);
  2763. return {
  2764. start,
  2765. end
  2766. };
  2767. }
  2768. get rawValue() {
  2769. if (!this.valueRange || !this.context) return null;
  2770. const {
  2771. start,
  2772. end
  2773. } = this.valueRange;
  2774. return this.context.src.slice(start, end);
  2775. }
  2776. get tag() {
  2777. for (let i = 0; i < this.props.length; ++i) {
  2778. const tag = this.getPropValue(i, Char.TAG, false);
  2779. if (tag != null) {
  2780. if (tag[1] === '<') {
  2781. return {
  2782. verbatim: tag.slice(2, -1)
  2783. };
  2784. } else {
  2785. // eslint-disable-next-line no-unused-vars
  2786. const [_, handle, suffix] = tag.match(/^(.*!)([^!]*)$/);
  2787. return {
  2788. handle,
  2789. suffix
  2790. };
  2791. }
  2792. }
  2793. }
  2794. return null;
  2795. }
  2796. get valueRangeContainsNewline() {
  2797. if (!this.valueRange || !this.context) return false;
  2798. const {
  2799. start,
  2800. end
  2801. } = this.valueRange;
  2802. const {
  2803. src
  2804. } = this.context;
  2805. for (let i = start; i < end; ++i) {
  2806. if (src[i] === '\n') return true;
  2807. }
  2808. return false;
  2809. }
  2810. parseComment(start) {
  2811. const {
  2812. src
  2813. } = this.context;
  2814. if (src[start] === Char.COMMENT) {
  2815. const end = Node$1.endOfLine(src, start + 1);
  2816. const commentRange = new Range(start, end);
  2817. this.props.push(commentRange);
  2818. return end;
  2819. }
  2820. return start;
  2821. }
  2822. /**
  2823. * Populates the `origStart` and `origEnd` values of all ranges for this
  2824. * node. Extended by child classes to handle descendant nodes.
  2825. *
  2826. * @param {number[]} cr - Positions of dropped CR characters
  2827. * @param {number} offset - Starting index of `cr` from the last call
  2828. * @returns {number} - The next offset, matching the one found for `origStart`
  2829. */
  2830. setOrigRanges(cr, offset) {
  2831. if (this.range) offset = this.range.setOrigRange(cr, offset);
  2832. if (this.valueRange) this.valueRange.setOrigRange(cr, offset);
  2833. this.props.forEach(prop => prop.setOrigRange(cr, offset));
  2834. return offset;
  2835. }
  2836. toString() {
  2837. const {
  2838. context: {
  2839. src
  2840. },
  2841. range,
  2842. value
  2843. } = this;
  2844. if (value != null) return value;
  2845. const str = src.slice(range.start, range.end);
  2846. return Node$1.addStringTerminator(src, range.end, str);
  2847. }
  2848. }
  2849. class YAMLError extends Error {
  2850. constructor(name, source, message) {
  2851. if (!message || !(source instanceof Node$1)) throw new Error(`Invalid arguments for new ${name}`);
  2852. super();
  2853. this.name = name;
  2854. this.message = message;
  2855. this.source = source;
  2856. }
  2857. makePretty() {
  2858. if (!this.source) return;
  2859. this.nodeType = this.source.type;
  2860. const cst = this.source.context && this.source.context.root;
  2861. if (typeof this.offset === 'number') {
  2862. this.range = new Range(this.offset, this.offset + 1);
  2863. const start = cst && getLinePos(this.offset, cst);
  2864. if (start) {
  2865. const end = {
  2866. line: start.line,
  2867. col: start.col + 1
  2868. };
  2869. this.linePos = {
  2870. start,
  2871. end
  2872. };
  2873. }
  2874. delete this.offset;
  2875. } else {
  2876. this.range = this.source.range;
  2877. this.linePos = this.source.rangeAsLinePos;
  2878. }
  2879. if (this.linePos) {
  2880. const {
  2881. line,
  2882. col
  2883. } = this.linePos.start;
  2884. this.message += ` at line ${line}, column ${col}`;
  2885. const ctx = cst && getPrettyContext(this.linePos, cst);
  2886. if (ctx) this.message += `:\n\n${ctx}\n`;
  2887. }
  2888. delete this.source;
  2889. }
  2890. }
  2891. class YAMLReferenceError extends YAMLError {
  2892. constructor(source, message) {
  2893. super('YAMLReferenceError', source, message);
  2894. }
  2895. }
  2896. class YAMLSemanticError extends YAMLError {
  2897. constructor(source, message) {
  2898. super('YAMLSemanticError', source, message);
  2899. }
  2900. }
  2901. class YAMLSyntaxError extends YAMLError {
  2902. constructor(source, message) {
  2903. super('YAMLSyntaxError', source, message);
  2904. }
  2905. }
  2906. class YAMLWarning extends YAMLError {
  2907. constructor(source, message) {
  2908. super('YAMLWarning', source, message);
  2909. }
  2910. }
  2911. function _defineProperty(obj, key, value) {
  2912. if (key in obj) {
  2913. Object.defineProperty(obj, key, {
  2914. value: value,
  2915. enumerable: true,
  2916. configurable: true,
  2917. writable: true
  2918. });
  2919. } else {
  2920. obj[key] = value;
  2921. }
  2922. return obj;
  2923. }
  2924. class PlainValue extends Node$1 {
  2925. static endOfLine(src, start, inFlow) {
  2926. let ch = src[start];
  2927. let offset = start;
  2928. while (ch && ch !== '\n') {
  2929. if (inFlow && (ch === '[' || ch === ']' || ch === '{' || ch === '}' || ch === ',')) break;
  2930. const next = src[offset + 1];
  2931. if (ch === ':' && (!next || next === '\n' || next === '\t' || next === ' ' || inFlow && next === ',')) break;
  2932. if ((ch === ' ' || ch === '\t') && next === '#') break;
  2933. offset += 1;
  2934. ch = next;
  2935. }
  2936. return offset;
  2937. }
  2938. get strValue() {
  2939. if (!this.valueRange || !this.context) return null;
  2940. let {
  2941. start,
  2942. end
  2943. } = this.valueRange;
  2944. const {
  2945. src
  2946. } = this.context;
  2947. let ch = src[end - 1];
  2948. while (start < end && (ch === '\n' || ch === '\t' || ch === ' ')) ch = src[--end - 1];
  2949. let str = '';
  2950. for (let i = start; i < end; ++i) {
  2951. const ch = src[i];
  2952. if (ch === '\n') {
  2953. const {
  2954. fold,
  2955. offset
  2956. } = Node$1.foldNewline(src, i, -1);
  2957. str += fold;
  2958. i = offset;
  2959. } else if (ch === ' ' || ch === '\t') {
  2960. // trim trailing whitespace
  2961. const wsStart = i;
  2962. let next = src[i + 1];
  2963. while (i < end && (next === ' ' || next === '\t')) {
  2964. i += 1;
  2965. next = src[i + 1];
  2966. }
  2967. if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
  2968. } else {
  2969. str += ch;
  2970. }
  2971. }
  2972. const ch0 = src[start];
  2973. switch (ch0) {
  2974. case '\t':
  2975. {
  2976. const msg = 'Plain value cannot start with a tab character';
  2977. const errors = [new YAMLSemanticError(this, msg)];
  2978. return {
  2979. errors,
  2980. str
  2981. };
  2982. }
  2983. case '@':
  2984. case '`':
  2985. {
  2986. const msg = `Plain value cannot start with reserved character ${ch0}`;
  2987. const errors = [new YAMLSemanticError(this, msg)];
  2988. return {
  2989. errors,
  2990. str
  2991. };
  2992. }
  2993. default:
  2994. return str;
  2995. }
  2996. }
  2997. parseBlockValue(start) {
  2998. const {
  2999. indent,
  3000. inFlow,
  3001. src
  3002. } = this.context;
  3003. let offset = start;
  3004. let valueEnd = start;
  3005. for (let ch = src[offset]; ch === '\n'; ch = src[offset]) {
  3006. if (Node$1.atDocumentBoundary(src, offset + 1)) break;
  3007. const end = Node$1.endOfBlockIndent(src, indent, offset + 1);
  3008. if (end === null || src[end] === '#') break;
  3009. if (src[end] === '\n') {
  3010. offset = end;
  3011. } else {
  3012. valueEnd = PlainValue.endOfLine(src, end, inFlow);
  3013. offset = valueEnd;
  3014. }
  3015. }
  3016. if (this.valueRange.isEmpty()) this.valueRange.start = start;
  3017. this.valueRange.end = valueEnd;
  3018. return valueEnd;
  3019. }
  3020. /**
  3021. * Parses a plain value from the source
  3022. *
  3023. * Accepted forms are:
  3024. * ```
  3025. * #comment
  3026. *
  3027. * first line
  3028. *
  3029. * first line #comment
  3030. *
  3031. * first line
  3032. * block
  3033. * lines
  3034. *
  3035. * #comment
  3036. * block
  3037. * lines
  3038. * ```
  3039. * where block lines are empty or have an indent level greater than `indent`.
  3040. *
  3041. * @param {ParseContext} context
  3042. * @param {number} start - Index of first character
  3043. * @returns {number} - Index of the character after this scalar, may be `\n`
  3044. */
  3045. parse(context, start) {
  3046. this.context = context;
  3047. const {
  3048. inFlow,
  3049. src
  3050. } = context;
  3051. let offset = start;
  3052. const ch = src[offset];
  3053. if (ch && ch !== '#' && ch !== '\n') {
  3054. offset = PlainValue.endOfLine(src, start, inFlow);
  3055. }
  3056. this.valueRange = new Range(start, offset);
  3057. offset = Node$1.endOfWhiteSpace(src, offset);
  3058. offset = this.parseComment(offset);
  3059. if (!this.hasComment || this.valueRange.isEmpty()) {
  3060. offset = this.parseBlockValue(offset);
  3061. }
  3062. return offset;
  3063. }
  3064. }
  3065. var Char_1 = Char;
  3066. var Node_1$1 = Node$1;
  3067. var PlainValue_1 = PlainValue;
  3068. var Range_1 = Range;
  3069. var Type_1 = Type;
  3070. var YAMLError_1 = YAMLError;
  3071. var YAMLReferenceError_1 = YAMLReferenceError;
  3072. var YAMLSemanticError_1 = YAMLSemanticError;
  3073. var YAMLSyntaxError_1 = YAMLSyntaxError;
  3074. var YAMLWarning_1 = YAMLWarning;
  3075. var _defineProperty_1 = _defineProperty;
  3076. var defaultTagPrefix_1 = defaultTagPrefix;
  3077. var defaultTags_1 = defaultTags;
  3078. var PlainValueEc8e588e = {
  3079. Char: Char_1,
  3080. Node: Node_1$1,
  3081. PlainValue: PlainValue_1,
  3082. Range: Range_1,
  3083. Type: Type_1,
  3084. YAMLError: YAMLError_1,
  3085. YAMLReferenceError: YAMLReferenceError_1,
  3086. YAMLSemanticError: YAMLSemanticError_1,
  3087. YAMLSyntaxError: YAMLSyntaxError_1,
  3088. YAMLWarning: YAMLWarning_1,
  3089. _defineProperty: _defineProperty_1,
  3090. defaultTagPrefix: defaultTagPrefix_1,
  3091. defaultTags: defaultTags_1
  3092. };
  3093. class BlankLine extends PlainValueEc8e588e.Node {
  3094. constructor() {
  3095. super(PlainValueEc8e588e.Type.BLANK_LINE);
  3096. }
  3097. /* istanbul ignore next */
  3098. get includesTrailingLines() {
  3099. // This is never called from anywhere, but if it were,
  3100. // this is the value it should return.
  3101. return true;
  3102. }
  3103. /**
  3104. * Parses a blank line from the source
  3105. *
  3106. * @param {ParseContext} context
  3107. * @param {number} start - Index of first \n character
  3108. * @returns {number} - Index of the character after this
  3109. */
  3110. parse(context, start) {
  3111. this.context = context;
  3112. this.range = new PlainValueEc8e588e.Range(start, start + 1);
  3113. return start + 1;
  3114. }
  3115. }
  3116. class CollectionItem extends PlainValueEc8e588e.Node {
  3117. constructor(type, props) {
  3118. super(type, props);
  3119. this.node = null;
  3120. }
  3121. get includesTrailingLines() {
  3122. return !!this.node && this.node.includesTrailingLines;
  3123. }
  3124. /**
  3125. * @param {ParseContext} context
  3126. * @param {number} start - Index of first character
  3127. * @returns {number} - Index of the character after this
  3128. */
  3129. parse(context, start) {
  3130. this.context = context;
  3131. const {
  3132. parseNode,
  3133. src
  3134. } = context;
  3135. let {
  3136. atLineStart,
  3137. lineStart
  3138. } = context;
  3139. if (!atLineStart && this.type === PlainValueEc8e588e.Type.SEQ_ITEM) this.error = new PlainValueEc8e588e.YAMLSemanticError(this, 'Sequence items must not have preceding content on the same line');
  3140. const indent = atLineStart ? start - lineStart : context.indent;
  3141. let offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, start + 1);
  3142. let ch = src[offset];
  3143. const inlineComment = ch === '#';
  3144. const comments = [];
  3145. let blankLine = null;
  3146. while (ch === '\n' || ch === '#') {
  3147. if (ch === '#') {
  3148. const end = PlainValueEc8e588e.Node.endOfLine(src, offset + 1);
  3149. comments.push(new PlainValueEc8e588e.Range(offset, end));
  3150. offset = end;
  3151. } else {
  3152. atLineStart = true;
  3153. lineStart = offset + 1;
  3154. const wsEnd = PlainValueEc8e588e.Node.endOfWhiteSpace(src, lineStart);
  3155. if (src[wsEnd] === '\n' && comments.length === 0) {
  3156. blankLine = new BlankLine();
  3157. lineStart = blankLine.parse({
  3158. src
  3159. }, lineStart);
  3160. }
  3161. offset = PlainValueEc8e588e.Node.endOfIndent(src, lineStart);
  3162. }
  3163. ch = src[offset];
  3164. }
  3165. if (PlainValueEc8e588e.Node.nextNodeIsIndented(ch, offset - (lineStart + indent), this.type !== PlainValueEc8e588e.Type.SEQ_ITEM)) {
  3166. this.node = parseNode({
  3167. atLineStart,
  3168. inCollection: false,
  3169. indent,
  3170. lineStart,
  3171. parent: this
  3172. }, offset);
  3173. } else if (ch && lineStart > start + 1) {
  3174. offset = lineStart - 1;
  3175. }
  3176. if (this.node) {
  3177. if (blankLine) {
  3178. // Only blank lines preceding non-empty nodes are captured. Note that
  3179. // this means that collection item range start indices do not always
  3180. // increase monotonically. -- eemeli/yaml#126
  3181. const items = context.parent.items || context.parent.contents;
  3182. if (items) items.push(blankLine);
  3183. }
  3184. if (comments.length) Array.prototype.push.apply(this.props, comments);
  3185. offset = this.node.range.end;
  3186. } else {
  3187. if (inlineComment) {
  3188. const c = comments[0];
  3189. this.props.push(c);
  3190. offset = c.end;
  3191. } else {
  3192. offset = PlainValueEc8e588e.Node.endOfLine(src, start + 1);
  3193. }
  3194. }
  3195. const end = this.node ? this.node.valueRange.end : offset;
  3196. this.valueRange = new PlainValueEc8e588e.Range(start, end);
  3197. return offset;
  3198. }
  3199. setOrigRanges(cr, offset) {
  3200. offset = super.setOrigRanges(cr, offset);
  3201. return this.node ? this.node.setOrigRanges(cr, offset) : offset;
  3202. }
  3203. toString() {
  3204. const {
  3205. context: {
  3206. src
  3207. },
  3208. node,
  3209. range,
  3210. value
  3211. } = this;
  3212. if (value != null) return value;
  3213. const str = node ? src.slice(range.start, node.range.start) + String(node) : src.slice(range.start, range.end);
  3214. return PlainValueEc8e588e.Node.addStringTerminator(src, range.end, str);
  3215. }
  3216. }
  3217. class Comment extends PlainValueEc8e588e.Node {
  3218. constructor() {
  3219. super(PlainValueEc8e588e.Type.COMMENT);
  3220. }
  3221. /**
  3222. * Parses a comment line from the source
  3223. *
  3224. * @param {ParseContext} context
  3225. * @param {number} start - Index of first character
  3226. * @returns {number} - Index of the character after this scalar
  3227. */
  3228. parse(context, start) {
  3229. this.context = context;
  3230. const offset = this.parseComment(start);
  3231. this.range = new PlainValueEc8e588e.Range(start, offset);
  3232. return offset;
  3233. }
  3234. }
  3235. function grabCollectionEndComments(node) {
  3236. let cnode = node;
  3237. while (cnode instanceof CollectionItem) cnode = cnode.node;
  3238. if (!(cnode instanceof Collection$1)) return null;
  3239. const len = cnode.items.length;
  3240. let ci = -1;
  3241. for (let i = len - 1; i >= 0; --i) {
  3242. const n = cnode.items[i];
  3243. if (n.type === PlainValueEc8e588e.Type.COMMENT) {
  3244. // Keep sufficiently indented comments with preceding node
  3245. const {
  3246. indent,
  3247. lineStart
  3248. } = n.context;
  3249. if (indent > 0 && n.range.start >= lineStart + indent) break;
  3250. ci = i;
  3251. } else if (n.type === PlainValueEc8e588e.Type.BLANK_LINE) ci = i;else break;
  3252. }
  3253. if (ci === -1) return null;
  3254. const ca = cnode.items.splice(ci, len - ci);
  3255. const prevEnd = ca[0].range.start;
  3256. while (true) {
  3257. cnode.range.end = prevEnd;
  3258. if (cnode.valueRange && cnode.valueRange.end > prevEnd) cnode.valueRange.end = prevEnd;
  3259. if (cnode === node) break;
  3260. cnode = cnode.context.parent;
  3261. }
  3262. return ca;
  3263. }
  3264. class Collection$1 extends PlainValueEc8e588e.Node {
  3265. static nextContentHasIndent(src, offset, indent) {
  3266. const lineStart = PlainValueEc8e588e.Node.endOfLine(src, offset) + 1;
  3267. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, lineStart);
  3268. const ch = src[offset];
  3269. if (!ch) return false;
  3270. if (offset >= lineStart + indent) return true;
  3271. if (ch !== '#' && ch !== '\n') return false;
  3272. return Collection$1.nextContentHasIndent(src, offset, indent);
  3273. }
  3274. constructor(firstItem) {
  3275. super(firstItem.type === PlainValueEc8e588e.Type.SEQ_ITEM ? PlainValueEc8e588e.Type.SEQ : PlainValueEc8e588e.Type.MAP);
  3276. for (let i = firstItem.props.length - 1; i >= 0; --i) {
  3277. if (firstItem.props[i].start < firstItem.context.lineStart) {
  3278. // props on previous line are assumed by the collection
  3279. this.props = firstItem.props.slice(0, i + 1);
  3280. firstItem.props = firstItem.props.slice(i + 1);
  3281. const itemRange = firstItem.props[0] || firstItem.valueRange;
  3282. firstItem.range.start = itemRange.start;
  3283. break;
  3284. }
  3285. }
  3286. this.items = [firstItem];
  3287. const ec = grabCollectionEndComments(firstItem);
  3288. if (ec) Array.prototype.push.apply(this.items, ec);
  3289. }
  3290. get includesTrailingLines() {
  3291. return this.items.length > 0;
  3292. }
  3293. /**
  3294. * @param {ParseContext} context
  3295. * @param {number} start - Index of first character
  3296. * @returns {number} - Index of the character after this
  3297. */
  3298. parse(context, start) {
  3299. this.context = context;
  3300. const {
  3301. parseNode,
  3302. src
  3303. } = context; // It's easier to recalculate lineStart here rather than tracking down the
  3304. // last context from which to read it -- eemeli/yaml#2
  3305. let lineStart = PlainValueEc8e588e.Node.startOfLine(src, start);
  3306. const firstItem = this.items[0]; // First-item context needs to be correct for later comment handling
  3307. // -- eemeli/yaml#17
  3308. firstItem.context.parent = this;
  3309. this.valueRange = PlainValueEc8e588e.Range.copy(firstItem.valueRange);
  3310. const indent = firstItem.range.start - firstItem.context.lineStart;
  3311. let offset = start;
  3312. offset = PlainValueEc8e588e.Node.normalizeOffset(src, offset);
  3313. let ch = src[offset];
  3314. let atLineStart = PlainValueEc8e588e.Node.endOfWhiteSpace(src, lineStart) === offset;
  3315. let prevIncludesTrailingLines = false;
  3316. while (ch) {
  3317. while (ch === '\n' || ch === '#') {
  3318. if (atLineStart && ch === '\n' && !prevIncludesTrailingLines) {
  3319. const blankLine = new BlankLine();
  3320. offset = blankLine.parse({
  3321. src
  3322. }, offset);
  3323. this.valueRange.end = offset;
  3324. if (offset >= src.length) {
  3325. ch = null;
  3326. break;
  3327. }
  3328. this.items.push(blankLine);
  3329. offset -= 1; // blankLine.parse() consumes terminal newline
  3330. } else if (ch === '#') {
  3331. if (offset < lineStart + indent && !Collection$1.nextContentHasIndent(src, offset, indent)) {
  3332. return offset;
  3333. }
  3334. const comment = new Comment();
  3335. offset = comment.parse({
  3336. indent,
  3337. lineStart,
  3338. src
  3339. }, offset);
  3340. this.items.push(comment);
  3341. this.valueRange.end = offset;
  3342. if (offset >= src.length) {
  3343. ch = null;
  3344. break;
  3345. }
  3346. }
  3347. lineStart = offset + 1;
  3348. offset = PlainValueEc8e588e.Node.endOfIndent(src, lineStart);
  3349. if (PlainValueEc8e588e.Node.atBlank(src, offset)) {
  3350. const wsEnd = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  3351. const next = src[wsEnd];
  3352. if (!next || next === '\n' || next === '#') {
  3353. offset = wsEnd;
  3354. }
  3355. }
  3356. ch = src[offset];
  3357. atLineStart = true;
  3358. }
  3359. if (!ch) {
  3360. break;
  3361. }
  3362. if (offset !== lineStart + indent && (atLineStart || ch !== ':')) {
  3363. if (offset < lineStart + indent) {
  3364. if (lineStart > start) offset = lineStart;
  3365. break;
  3366. } else if (!this.error) {
  3367. const msg = 'All collection items must start at the same column';
  3368. this.error = new PlainValueEc8e588e.YAMLSyntaxError(this, msg);
  3369. }
  3370. }
  3371. if (firstItem.type === PlainValueEc8e588e.Type.SEQ_ITEM) {
  3372. if (ch !== '-') {
  3373. if (lineStart > start) offset = lineStart;
  3374. break;
  3375. }
  3376. } else if (ch === '-' && !this.error) {
  3377. // map key may start with -, as long as it's followed by a non-whitespace char
  3378. const next = src[offset + 1];
  3379. if (!next || next === '\n' || next === '\t' || next === ' ') {
  3380. const msg = 'A collection cannot be both a mapping and a sequence';
  3381. this.error = new PlainValueEc8e588e.YAMLSyntaxError(this, msg);
  3382. }
  3383. }
  3384. const node = parseNode({
  3385. atLineStart,
  3386. inCollection: true,
  3387. indent,
  3388. lineStart,
  3389. parent: this
  3390. }, offset);
  3391. if (!node) return offset; // at next document start
  3392. this.items.push(node);
  3393. this.valueRange.end = node.valueRange.end;
  3394. offset = PlainValueEc8e588e.Node.normalizeOffset(src, node.range.end);
  3395. ch = src[offset];
  3396. atLineStart = false;
  3397. prevIncludesTrailingLines = node.includesTrailingLines; // Need to reset lineStart and atLineStart here if preceding node's range
  3398. // has advanced to check the current line's indentation level
  3399. // -- eemeli/yaml#10 & eemeli/yaml#38
  3400. if (ch) {
  3401. let ls = offset - 1;
  3402. let prev = src[ls];
  3403. while (prev === ' ' || prev === '\t') prev = src[--ls];
  3404. if (prev === '\n') {
  3405. lineStart = ls + 1;
  3406. atLineStart = true;
  3407. }
  3408. }
  3409. const ec = grabCollectionEndComments(node);
  3410. if (ec) Array.prototype.push.apply(this.items, ec);
  3411. }
  3412. return offset;
  3413. }
  3414. setOrigRanges(cr, offset) {
  3415. offset = super.setOrigRanges(cr, offset);
  3416. this.items.forEach(node => {
  3417. offset = node.setOrigRanges(cr, offset);
  3418. });
  3419. return offset;
  3420. }
  3421. toString() {
  3422. const {
  3423. context: {
  3424. src
  3425. },
  3426. items,
  3427. range,
  3428. value
  3429. } = this;
  3430. if (value != null) return value;
  3431. let str = src.slice(range.start, items[0].range.start) + String(items[0]);
  3432. for (let i = 1; i < items.length; ++i) {
  3433. const item = items[i];
  3434. const {
  3435. atLineStart,
  3436. indent
  3437. } = item.context;
  3438. if (atLineStart) for (let i = 0; i < indent; ++i) str += ' ';
  3439. str += String(item);
  3440. }
  3441. return PlainValueEc8e588e.Node.addStringTerminator(src, range.end, str);
  3442. }
  3443. }
  3444. class Directive extends PlainValueEc8e588e.Node {
  3445. constructor() {
  3446. super(PlainValueEc8e588e.Type.DIRECTIVE);
  3447. this.name = null;
  3448. }
  3449. get parameters() {
  3450. const raw = this.rawValue;
  3451. return raw ? raw.trim().split(/[ \t]+/) : [];
  3452. }
  3453. parseName(start) {
  3454. const {
  3455. src
  3456. } = this.context;
  3457. let offset = start;
  3458. let ch = src[offset];
  3459. while (ch && ch !== '\n' && ch !== '\t' && ch !== ' ') ch = src[offset += 1];
  3460. this.name = src.slice(start, offset);
  3461. return offset;
  3462. }
  3463. parseParameters(start) {
  3464. const {
  3465. src
  3466. } = this.context;
  3467. let offset = start;
  3468. let ch = src[offset];
  3469. while (ch && ch !== '\n' && ch !== '#') ch = src[offset += 1];
  3470. this.valueRange = new PlainValueEc8e588e.Range(start, offset);
  3471. return offset;
  3472. }
  3473. parse(context, start) {
  3474. this.context = context;
  3475. let offset = this.parseName(start + 1);
  3476. offset = this.parseParameters(offset);
  3477. offset = this.parseComment(offset);
  3478. this.range = new PlainValueEc8e588e.Range(start, offset);
  3479. return offset;
  3480. }
  3481. }
  3482. class Document$2 extends PlainValueEc8e588e.Node {
  3483. static startCommentOrEndBlankLine(src, start) {
  3484. const offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, start);
  3485. const ch = src[offset];
  3486. return ch === '#' || ch === '\n' ? offset : start;
  3487. }
  3488. constructor() {
  3489. super(PlainValueEc8e588e.Type.DOCUMENT);
  3490. this.directives = null;
  3491. this.contents = null;
  3492. this.directivesEndMarker = null;
  3493. this.documentEndMarker = null;
  3494. }
  3495. parseDirectives(start) {
  3496. const {
  3497. src
  3498. } = this.context;
  3499. this.directives = [];
  3500. let atLineStart = true;
  3501. let hasDirectives = false;
  3502. let offset = start;
  3503. while (!PlainValueEc8e588e.Node.atDocumentBoundary(src, offset, PlainValueEc8e588e.Char.DIRECTIVES_END)) {
  3504. offset = Document$2.startCommentOrEndBlankLine(src, offset);
  3505. switch (src[offset]) {
  3506. case '\n':
  3507. if (atLineStart) {
  3508. const blankLine = new BlankLine();
  3509. offset = blankLine.parse({
  3510. src
  3511. }, offset);
  3512. if (offset < src.length) {
  3513. this.directives.push(blankLine);
  3514. }
  3515. } else {
  3516. offset += 1;
  3517. atLineStart = true;
  3518. }
  3519. break;
  3520. case '#':
  3521. {
  3522. const comment = new Comment();
  3523. offset = comment.parse({
  3524. src
  3525. }, offset);
  3526. this.directives.push(comment);
  3527. atLineStart = false;
  3528. }
  3529. break;
  3530. case '%':
  3531. {
  3532. const directive = new Directive();
  3533. offset = directive.parse({
  3534. parent: this,
  3535. src
  3536. }, offset);
  3537. this.directives.push(directive);
  3538. hasDirectives = true;
  3539. atLineStart = false;
  3540. }
  3541. break;
  3542. default:
  3543. if (hasDirectives) {
  3544. this.error = new PlainValueEc8e588e.YAMLSemanticError(this, 'Missing directives-end indicator line');
  3545. } else if (this.directives.length > 0) {
  3546. this.contents = this.directives;
  3547. this.directives = [];
  3548. }
  3549. return offset;
  3550. }
  3551. }
  3552. if (src[offset]) {
  3553. this.directivesEndMarker = new PlainValueEc8e588e.Range(offset, offset + 3);
  3554. return offset + 3;
  3555. }
  3556. if (hasDirectives) {
  3557. this.error = new PlainValueEc8e588e.YAMLSemanticError(this, 'Missing directives-end indicator line');
  3558. } else if (this.directives.length > 0) {
  3559. this.contents = this.directives;
  3560. this.directives = [];
  3561. }
  3562. return offset;
  3563. }
  3564. parseContents(start) {
  3565. const {
  3566. parseNode,
  3567. src
  3568. } = this.context;
  3569. if (!this.contents) this.contents = [];
  3570. let lineStart = start;
  3571. while (src[lineStart - 1] === '-') lineStart -= 1;
  3572. let offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, start);
  3573. let atLineStart = lineStart === start;
  3574. this.valueRange = new PlainValueEc8e588e.Range(offset);
  3575. while (!PlainValueEc8e588e.Node.atDocumentBoundary(src, offset, PlainValueEc8e588e.Char.DOCUMENT_END)) {
  3576. switch (src[offset]) {
  3577. case '\n':
  3578. if (atLineStart) {
  3579. const blankLine = new BlankLine();
  3580. offset = blankLine.parse({
  3581. src
  3582. }, offset);
  3583. if (offset < src.length) {
  3584. this.contents.push(blankLine);
  3585. }
  3586. } else {
  3587. offset += 1;
  3588. atLineStart = true;
  3589. }
  3590. lineStart = offset;
  3591. break;
  3592. case '#':
  3593. {
  3594. const comment = new Comment();
  3595. offset = comment.parse({
  3596. src
  3597. }, offset);
  3598. this.contents.push(comment);
  3599. atLineStart = false;
  3600. }
  3601. break;
  3602. default:
  3603. {
  3604. const iEnd = PlainValueEc8e588e.Node.endOfIndent(src, offset);
  3605. const context = {
  3606. atLineStart,
  3607. indent: -1,
  3608. inFlow: false,
  3609. inCollection: false,
  3610. lineStart,
  3611. parent: this
  3612. };
  3613. const node = parseNode(context, iEnd);
  3614. if (!node) return this.valueRange.end = iEnd; // at next document start
  3615. this.contents.push(node);
  3616. offset = node.range.end;
  3617. atLineStart = false;
  3618. const ec = grabCollectionEndComments(node);
  3619. if (ec) Array.prototype.push.apply(this.contents, ec);
  3620. }
  3621. }
  3622. offset = Document$2.startCommentOrEndBlankLine(src, offset);
  3623. }
  3624. this.valueRange.end = offset;
  3625. if (src[offset]) {
  3626. this.documentEndMarker = new PlainValueEc8e588e.Range(offset, offset + 3);
  3627. offset += 3;
  3628. if (src[offset]) {
  3629. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  3630. if (src[offset] === '#') {
  3631. const comment = new Comment();
  3632. offset = comment.parse({
  3633. src
  3634. }, offset);
  3635. this.contents.push(comment);
  3636. }
  3637. switch (src[offset]) {
  3638. case '\n':
  3639. offset += 1;
  3640. break;
  3641. case undefined:
  3642. break;
  3643. default:
  3644. this.error = new PlainValueEc8e588e.YAMLSyntaxError(this, 'Document end marker line cannot have a non-comment suffix');
  3645. }
  3646. }
  3647. }
  3648. return offset;
  3649. }
  3650. /**
  3651. * @param {ParseContext} context
  3652. * @param {number} start - Index of first character
  3653. * @returns {number} - Index of the character after this
  3654. */
  3655. parse(context, start) {
  3656. context.root = this;
  3657. this.context = context;
  3658. const {
  3659. src
  3660. } = context;
  3661. let offset = src.charCodeAt(start) === 0xfeff ? start + 1 : start; // skip BOM
  3662. offset = this.parseDirectives(offset);
  3663. offset = this.parseContents(offset);
  3664. return offset;
  3665. }
  3666. setOrigRanges(cr, offset) {
  3667. offset = super.setOrigRanges(cr, offset);
  3668. this.directives.forEach(node => {
  3669. offset = node.setOrigRanges(cr, offset);
  3670. });
  3671. if (this.directivesEndMarker) offset = this.directivesEndMarker.setOrigRange(cr, offset);
  3672. this.contents.forEach(node => {
  3673. offset = node.setOrigRanges(cr, offset);
  3674. });
  3675. if (this.documentEndMarker) offset = this.documentEndMarker.setOrigRange(cr, offset);
  3676. return offset;
  3677. }
  3678. toString() {
  3679. const {
  3680. contents,
  3681. directives,
  3682. value
  3683. } = this;
  3684. if (value != null) return value;
  3685. let str = directives.join('');
  3686. if (contents.length > 0) {
  3687. if (directives.length > 0 || contents[0].type === PlainValueEc8e588e.Type.COMMENT) str += '---\n';
  3688. str += contents.join('');
  3689. }
  3690. if (str[str.length - 1] !== '\n') str += '\n';
  3691. return str;
  3692. }
  3693. }
  3694. class Alias$1 extends PlainValueEc8e588e.Node {
  3695. /**
  3696. * Parses an *alias from the source
  3697. *
  3698. * @param {ParseContext} context
  3699. * @param {number} start - Index of first character
  3700. * @returns {number} - Index of the character after this scalar
  3701. */
  3702. parse(context, start) {
  3703. this.context = context;
  3704. const {
  3705. src
  3706. } = context;
  3707. let offset = PlainValueEc8e588e.Node.endOfIdentifier(src, start + 1);
  3708. this.valueRange = new PlainValueEc8e588e.Range(start + 1, offset);
  3709. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  3710. offset = this.parseComment(offset);
  3711. return offset;
  3712. }
  3713. }
  3714. const Chomp = {
  3715. CLIP: 'CLIP',
  3716. KEEP: 'KEEP',
  3717. STRIP: 'STRIP'
  3718. };
  3719. class BlockValue extends PlainValueEc8e588e.Node {
  3720. constructor(type, props) {
  3721. super(type, props);
  3722. this.blockIndent = null;
  3723. this.chomping = Chomp.CLIP;
  3724. this.header = null;
  3725. }
  3726. get includesTrailingLines() {
  3727. return this.chomping === Chomp.KEEP;
  3728. }
  3729. get strValue() {
  3730. if (!this.valueRange || !this.context) return null;
  3731. let {
  3732. start,
  3733. end
  3734. } = this.valueRange;
  3735. const {
  3736. indent,
  3737. src
  3738. } = this.context;
  3739. if (this.valueRange.isEmpty()) return '';
  3740. let lastNewLine = null;
  3741. let ch = src[end - 1];
  3742. while (ch === '\n' || ch === '\t' || ch === ' ') {
  3743. end -= 1;
  3744. if (end <= start) {
  3745. if (this.chomping === Chomp.KEEP) break;else return ''; // probably never happens
  3746. }
  3747. if (ch === '\n') lastNewLine = end;
  3748. ch = src[end - 1];
  3749. }
  3750. let keepStart = end + 1;
  3751. if (lastNewLine) {
  3752. if (this.chomping === Chomp.KEEP) {
  3753. keepStart = lastNewLine;
  3754. end = this.valueRange.end;
  3755. } else {
  3756. end = lastNewLine;
  3757. }
  3758. }
  3759. const bi = indent + this.blockIndent;
  3760. const folded = this.type === PlainValueEc8e588e.Type.BLOCK_FOLDED;
  3761. let atStart = true;
  3762. let str = '';
  3763. let sep = '';
  3764. let prevMoreIndented = false;
  3765. for (let i = start; i < end; ++i) {
  3766. for (let j = 0; j < bi; ++j) {
  3767. if (src[i] !== ' ') break;
  3768. i += 1;
  3769. }
  3770. const ch = src[i];
  3771. if (ch === '\n') {
  3772. if (sep === '\n') str += '\n';else sep = '\n';
  3773. } else {
  3774. const lineEnd = PlainValueEc8e588e.Node.endOfLine(src, i);
  3775. const line = src.slice(i, lineEnd);
  3776. i = lineEnd;
  3777. if (folded && (ch === ' ' || ch === '\t') && i < keepStart) {
  3778. if (sep === ' ') sep = '\n';else if (!prevMoreIndented && !atStart && sep === '\n') sep = '\n\n';
  3779. str += sep + line; //+ ((lineEnd < end && src[lineEnd]) || '')
  3780. sep = lineEnd < end && src[lineEnd] || '';
  3781. prevMoreIndented = true;
  3782. } else {
  3783. str += sep + line;
  3784. sep = folded && i < keepStart ? ' ' : '\n';
  3785. prevMoreIndented = false;
  3786. }
  3787. if (atStart && line !== '') atStart = false;
  3788. }
  3789. }
  3790. return this.chomping === Chomp.STRIP ? str : str + '\n';
  3791. }
  3792. parseBlockHeader(start) {
  3793. const {
  3794. src
  3795. } = this.context;
  3796. let offset = start + 1;
  3797. let bi = '';
  3798. while (true) {
  3799. const ch = src[offset];
  3800. switch (ch) {
  3801. case '-':
  3802. this.chomping = Chomp.STRIP;
  3803. break;
  3804. case '+':
  3805. this.chomping = Chomp.KEEP;
  3806. break;
  3807. case '0':
  3808. case '1':
  3809. case '2':
  3810. case '3':
  3811. case '4':
  3812. case '5':
  3813. case '6':
  3814. case '7':
  3815. case '8':
  3816. case '9':
  3817. bi += ch;
  3818. break;
  3819. default:
  3820. this.blockIndent = Number(bi) || null;
  3821. this.header = new PlainValueEc8e588e.Range(start, offset);
  3822. return offset;
  3823. }
  3824. offset += 1;
  3825. }
  3826. }
  3827. parseBlockValue(start) {
  3828. const {
  3829. indent,
  3830. src
  3831. } = this.context;
  3832. const explicit = !!this.blockIndent;
  3833. let offset = start;
  3834. let valueEnd = start;
  3835. let minBlockIndent = 1;
  3836. for (let ch = src[offset]; ch === '\n'; ch = src[offset]) {
  3837. offset += 1;
  3838. if (PlainValueEc8e588e.Node.atDocumentBoundary(src, offset)) break;
  3839. const end = PlainValueEc8e588e.Node.endOfBlockIndent(src, indent, offset); // should not include tab?
  3840. if (end === null) break;
  3841. const ch = src[end];
  3842. const lineIndent = end - (offset + indent);
  3843. if (!this.blockIndent) {
  3844. // no explicit block indent, none yet detected
  3845. if (src[end] !== '\n') {
  3846. // first line with non-whitespace content
  3847. if (lineIndent < minBlockIndent) {
  3848. const msg = 'Block scalars with more-indented leading empty lines must use an explicit indentation indicator';
  3849. this.error = new PlainValueEc8e588e.YAMLSemanticError(this, msg);
  3850. }
  3851. this.blockIndent = lineIndent;
  3852. } else if (lineIndent > minBlockIndent) {
  3853. // empty line with more whitespace
  3854. minBlockIndent = lineIndent;
  3855. }
  3856. } else if (ch && ch !== '\n' && lineIndent < this.blockIndent) {
  3857. if (src[end] === '#') break;
  3858. if (!this.error) {
  3859. const src = explicit ? 'explicit indentation indicator' : 'first line';
  3860. const msg = `Block scalars must not be less indented than their ${src}`;
  3861. this.error = new PlainValueEc8e588e.YAMLSemanticError(this, msg);
  3862. }
  3863. }
  3864. if (src[end] === '\n') {
  3865. offset = end;
  3866. } else {
  3867. offset = valueEnd = PlainValueEc8e588e.Node.endOfLine(src, end);
  3868. }
  3869. }
  3870. if (this.chomping !== Chomp.KEEP) {
  3871. offset = src[valueEnd] ? valueEnd + 1 : valueEnd;
  3872. }
  3873. this.valueRange = new PlainValueEc8e588e.Range(start + 1, offset);
  3874. return offset;
  3875. }
  3876. /**
  3877. * Parses a block value from the source
  3878. *
  3879. * Accepted forms are:
  3880. * ```
  3881. * BS
  3882. * block
  3883. * lines
  3884. *
  3885. * BS #comment
  3886. * block
  3887. * lines
  3888. * ```
  3889. * where the block style BS matches the regexp `[|>][-+1-9]*` and block lines
  3890. * are empty or have an indent level greater than `indent`.
  3891. *
  3892. * @param {ParseContext} context
  3893. * @param {number} start - Index of first character
  3894. * @returns {number} - Index of the character after this block
  3895. */
  3896. parse(context, start) {
  3897. this.context = context;
  3898. const {
  3899. src
  3900. } = context;
  3901. let offset = this.parseBlockHeader(start);
  3902. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  3903. offset = this.parseComment(offset);
  3904. offset = this.parseBlockValue(offset);
  3905. return offset;
  3906. }
  3907. setOrigRanges(cr, offset) {
  3908. offset = super.setOrigRanges(cr, offset);
  3909. return this.header ? this.header.setOrigRange(cr, offset) : offset;
  3910. }
  3911. }
  3912. class FlowCollection extends PlainValueEc8e588e.Node {
  3913. constructor(type, props) {
  3914. super(type, props);
  3915. this.items = null;
  3916. }
  3917. prevNodeIsJsonLike(idx = this.items.length) {
  3918. const node = this.items[idx - 1];
  3919. return !!node && (node.jsonLike || node.type === PlainValueEc8e588e.Type.COMMENT && this.prevNodeIsJsonLike(idx - 1));
  3920. }
  3921. /**
  3922. * @param {ParseContext} context
  3923. * @param {number} start - Index of first character
  3924. * @returns {number} - Index of the character after this
  3925. */
  3926. parse(context, start) {
  3927. this.context = context;
  3928. const {
  3929. parseNode,
  3930. src
  3931. } = context;
  3932. let {
  3933. indent,
  3934. lineStart
  3935. } = context;
  3936. let char = src[start]; // { or [
  3937. this.items = [{
  3938. char,
  3939. offset: start
  3940. }];
  3941. let offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, start + 1);
  3942. char = src[offset];
  3943. while (char && char !== ']' && char !== '}') {
  3944. switch (char) {
  3945. case '\n':
  3946. {
  3947. lineStart = offset + 1;
  3948. const wsEnd = PlainValueEc8e588e.Node.endOfWhiteSpace(src, lineStart);
  3949. if (src[wsEnd] === '\n') {
  3950. const blankLine = new BlankLine();
  3951. lineStart = blankLine.parse({
  3952. src
  3953. }, lineStart);
  3954. this.items.push(blankLine);
  3955. }
  3956. offset = PlainValueEc8e588e.Node.endOfIndent(src, lineStart);
  3957. if (offset <= lineStart + indent) {
  3958. char = src[offset];
  3959. if (offset < lineStart + indent || char !== ']' && char !== '}') {
  3960. const msg = 'Insufficient indentation in flow collection';
  3961. this.error = new PlainValueEc8e588e.YAMLSemanticError(this, msg);
  3962. }
  3963. }
  3964. }
  3965. break;
  3966. case ',':
  3967. {
  3968. this.items.push({
  3969. char,
  3970. offset
  3971. });
  3972. offset += 1;
  3973. }
  3974. break;
  3975. case '#':
  3976. {
  3977. const comment = new Comment();
  3978. offset = comment.parse({
  3979. src
  3980. }, offset);
  3981. this.items.push(comment);
  3982. }
  3983. break;
  3984. case '?':
  3985. case ':':
  3986. {
  3987. const next = src[offset + 1];
  3988. if (next === '\n' || next === '\t' || next === ' ' || next === ',' || // in-flow : after JSON-like key does not need to be followed by whitespace
  3989. char === ':' && this.prevNodeIsJsonLike()) {
  3990. this.items.push({
  3991. char,
  3992. offset
  3993. });
  3994. offset += 1;
  3995. break;
  3996. }
  3997. }
  3998. // fallthrough
  3999. default:
  4000. {
  4001. const node = parseNode({
  4002. atLineStart: false,
  4003. inCollection: false,
  4004. inFlow: true,
  4005. indent: -1,
  4006. lineStart,
  4007. parent: this
  4008. }, offset);
  4009. if (!node) {
  4010. // at next document start
  4011. this.valueRange = new PlainValueEc8e588e.Range(start, offset);
  4012. return offset;
  4013. }
  4014. this.items.push(node);
  4015. offset = PlainValueEc8e588e.Node.normalizeOffset(src, node.range.end);
  4016. }
  4017. }
  4018. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  4019. char = src[offset];
  4020. }
  4021. this.valueRange = new PlainValueEc8e588e.Range(start, offset + 1);
  4022. if (char) {
  4023. this.items.push({
  4024. char,
  4025. offset
  4026. });
  4027. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset + 1);
  4028. offset = this.parseComment(offset);
  4029. }
  4030. return offset;
  4031. }
  4032. setOrigRanges(cr, offset) {
  4033. offset = super.setOrigRanges(cr, offset);
  4034. this.items.forEach(node => {
  4035. if (node instanceof PlainValueEc8e588e.Node) {
  4036. offset = node.setOrigRanges(cr, offset);
  4037. } else if (cr.length === 0) {
  4038. node.origOffset = node.offset;
  4039. } else {
  4040. let i = offset;
  4041. while (i < cr.length) {
  4042. if (cr[i] > node.offset) break;else ++i;
  4043. }
  4044. node.origOffset = node.offset + i;
  4045. offset = i;
  4046. }
  4047. });
  4048. return offset;
  4049. }
  4050. toString() {
  4051. const {
  4052. context: {
  4053. src
  4054. },
  4055. items,
  4056. range,
  4057. value
  4058. } = this;
  4059. if (value != null) return value;
  4060. const nodes = items.filter(item => item instanceof PlainValueEc8e588e.Node);
  4061. let str = '';
  4062. let prevEnd = range.start;
  4063. nodes.forEach(node => {
  4064. const prefix = src.slice(prevEnd, node.range.start);
  4065. prevEnd = node.range.end;
  4066. str += prefix + String(node);
  4067. if (str[str.length - 1] === '\n' && src[prevEnd - 1] !== '\n' && src[prevEnd] === '\n') {
  4068. // Comment range does not include the terminal newline, but its
  4069. // stringified value does. Without this fix, newlines at comment ends
  4070. // get duplicated.
  4071. prevEnd += 1;
  4072. }
  4073. });
  4074. str += src.slice(prevEnd, range.end);
  4075. return PlainValueEc8e588e.Node.addStringTerminator(src, range.end, str);
  4076. }
  4077. }
  4078. class QuoteDouble extends PlainValueEc8e588e.Node {
  4079. static endOfQuote(src, offset) {
  4080. let ch = src[offset];
  4081. while (ch && ch !== '"') {
  4082. offset += ch === '\\' ? 2 : 1;
  4083. ch = src[offset];
  4084. }
  4085. return offset + 1;
  4086. }
  4087. /**
  4088. * @returns {string | { str: string, errors: YAMLSyntaxError[] }}
  4089. */
  4090. get strValue() {
  4091. if (!this.valueRange || !this.context) return null;
  4092. const errors = [];
  4093. const {
  4094. start,
  4095. end
  4096. } = this.valueRange;
  4097. const {
  4098. indent,
  4099. src
  4100. } = this.context;
  4101. if (src[end - 1] !== '"') errors.push(new PlainValueEc8e588e.YAMLSyntaxError(this, 'Missing closing "quote')); // Using String#replace is too painful with escaped newlines preceded by
  4102. // escaped backslashes; also, this should be faster.
  4103. let str = '';
  4104. for (let i = start + 1; i < end - 1; ++i) {
  4105. const ch = src[i];
  4106. if (ch === '\n') {
  4107. if (PlainValueEc8e588e.Node.atDocumentBoundary(src, i + 1)) errors.push(new PlainValueEc8e588e.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
  4108. const {
  4109. fold,
  4110. offset,
  4111. error
  4112. } = PlainValueEc8e588e.Node.foldNewline(src, i, indent);
  4113. str += fold;
  4114. i = offset;
  4115. if (error) errors.push(new PlainValueEc8e588e.YAMLSemanticError(this, 'Multi-line double-quoted string needs to be sufficiently indented'));
  4116. } else if (ch === '\\') {
  4117. i += 1;
  4118. switch (src[i]) {
  4119. case '0':
  4120. str += '\0';
  4121. break;
  4122. // null character
  4123. case 'a':
  4124. str += '\x07';
  4125. break;
  4126. // bell character
  4127. case 'b':
  4128. str += '\b';
  4129. break;
  4130. // backspace
  4131. case 'e':
  4132. str += '\x1b';
  4133. break;
  4134. // escape character
  4135. case 'f':
  4136. str += '\f';
  4137. break;
  4138. // form feed
  4139. case 'n':
  4140. str += '\n';
  4141. break;
  4142. // line feed
  4143. case 'r':
  4144. str += '\r';
  4145. break;
  4146. // carriage return
  4147. case 't':
  4148. str += '\t';
  4149. break;
  4150. // horizontal tab
  4151. case 'v':
  4152. str += '\v';
  4153. break;
  4154. // vertical tab
  4155. case 'N':
  4156. str += '\u0085';
  4157. break;
  4158. // Unicode next line
  4159. case '_':
  4160. str += '\u00a0';
  4161. break;
  4162. // Unicode non-breaking space
  4163. case 'L':
  4164. str += '\u2028';
  4165. break;
  4166. // Unicode line separator
  4167. case 'P':
  4168. str += '\u2029';
  4169. break;
  4170. // Unicode paragraph separator
  4171. case ' ':
  4172. str += ' ';
  4173. break;
  4174. case '"':
  4175. str += '"';
  4176. break;
  4177. case '/':
  4178. str += '/';
  4179. break;
  4180. case '\\':
  4181. str += '\\';
  4182. break;
  4183. case '\t':
  4184. str += '\t';
  4185. break;
  4186. case 'x':
  4187. str += this.parseCharCode(i + 1, 2, errors);
  4188. i += 2;
  4189. break;
  4190. case 'u':
  4191. str += this.parseCharCode(i + 1, 4, errors);
  4192. i += 4;
  4193. break;
  4194. case 'U':
  4195. str += this.parseCharCode(i + 1, 8, errors);
  4196. i += 8;
  4197. break;
  4198. case '\n':
  4199. // skip escaped newlines, but still trim the following line
  4200. while (src[i + 1] === ' ' || src[i + 1] === '\t') i += 1;
  4201. break;
  4202. default:
  4203. errors.push(new PlainValueEc8e588e.YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(i - 1, 2)}`));
  4204. str += '\\' + src[i];
  4205. }
  4206. } else if (ch === ' ' || ch === '\t') {
  4207. // trim trailing whitespace
  4208. const wsStart = i;
  4209. let next = src[i + 1];
  4210. while (next === ' ' || next === '\t') {
  4211. i += 1;
  4212. next = src[i + 1];
  4213. }
  4214. if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
  4215. } else {
  4216. str += ch;
  4217. }
  4218. }
  4219. return errors.length > 0 ? {
  4220. errors,
  4221. str
  4222. } : str;
  4223. }
  4224. parseCharCode(offset, length, errors) {
  4225. const {
  4226. src
  4227. } = this.context;
  4228. const cc = src.substr(offset, length);
  4229. const ok = cc.length === length && /^[0-9a-fA-F]+$/.test(cc);
  4230. const code = ok ? parseInt(cc, 16) : NaN;
  4231. if (isNaN(code)) {
  4232. errors.push(new PlainValueEc8e588e.YAMLSyntaxError(this, `Invalid escape sequence ${src.substr(offset - 2, length + 2)}`));
  4233. return src.substr(offset - 2, length + 2);
  4234. }
  4235. return String.fromCodePoint(code);
  4236. }
  4237. /**
  4238. * Parses a "double quoted" value from the source
  4239. *
  4240. * @param {ParseContext} context
  4241. * @param {number} start - Index of first character
  4242. * @returns {number} - Index of the character after this scalar
  4243. */
  4244. parse(context, start) {
  4245. this.context = context;
  4246. const {
  4247. src
  4248. } = context;
  4249. let offset = QuoteDouble.endOfQuote(src, start + 1);
  4250. this.valueRange = new PlainValueEc8e588e.Range(start, offset);
  4251. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  4252. offset = this.parseComment(offset);
  4253. return offset;
  4254. }
  4255. }
  4256. class QuoteSingle extends PlainValueEc8e588e.Node {
  4257. static endOfQuote(src, offset) {
  4258. let ch = src[offset];
  4259. while (ch) {
  4260. if (ch === "'") {
  4261. if (src[offset + 1] !== "'") break;
  4262. ch = src[offset += 2];
  4263. } else {
  4264. ch = src[offset += 1];
  4265. }
  4266. }
  4267. return offset + 1;
  4268. }
  4269. /**
  4270. * @returns {string | { str: string, errors: YAMLSyntaxError[] }}
  4271. */
  4272. get strValue() {
  4273. if (!this.valueRange || !this.context) return null;
  4274. const errors = [];
  4275. const {
  4276. start,
  4277. end
  4278. } = this.valueRange;
  4279. const {
  4280. indent,
  4281. src
  4282. } = this.context;
  4283. if (src[end - 1] !== "'") errors.push(new PlainValueEc8e588e.YAMLSyntaxError(this, "Missing closing 'quote"));
  4284. let str = '';
  4285. for (let i = start + 1; i < end - 1; ++i) {
  4286. const ch = src[i];
  4287. if (ch === '\n') {
  4288. if (PlainValueEc8e588e.Node.atDocumentBoundary(src, i + 1)) errors.push(new PlainValueEc8e588e.YAMLSemanticError(this, 'Document boundary indicators are not allowed within string values'));
  4289. const {
  4290. fold,
  4291. offset,
  4292. error
  4293. } = PlainValueEc8e588e.Node.foldNewline(src, i, indent);
  4294. str += fold;
  4295. i = offset;
  4296. if (error) errors.push(new PlainValueEc8e588e.YAMLSemanticError(this, 'Multi-line single-quoted string needs to be sufficiently indented'));
  4297. } else if (ch === "'") {
  4298. str += ch;
  4299. i += 1;
  4300. if (src[i] !== "'") errors.push(new PlainValueEc8e588e.YAMLSyntaxError(this, 'Unescaped single quote? This should not happen.'));
  4301. } else if (ch === ' ' || ch === '\t') {
  4302. // trim trailing whitespace
  4303. const wsStart = i;
  4304. let next = src[i + 1];
  4305. while (next === ' ' || next === '\t') {
  4306. i += 1;
  4307. next = src[i + 1];
  4308. }
  4309. if (next !== '\n') str += i > wsStart ? src.slice(wsStart, i + 1) : ch;
  4310. } else {
  4311. str += ch;
  4312. }
  4313. }
  4314. return errors.length > 0 ? {
  4315. errors,
  4316. str
  4317. } : str;
  4318. }
  4319. /**
  4320. * Parses a 'single quoted' value from the source
  4321. *
  4322. * @param {ParseContext} context
  4323. * @param {number} start - Index of first character
  4324. * @returns {number} - Index of the character after this scalar
  4325. */
  4326. parse(context, start) {
  4327. this.context = context;
  4328. const {
  4329. src
  4330. } = context;
  4331. let offset = QuoteSingle.endOfQuote(src, start + 1);
  4332. this.valueRange = new PlainValueEc8e588e.Range(start, offset);
  4333. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  4334. offset = this.parseComment(offset);
  4335. return offset;
  4336. }
  4337. }
  4338. function createNewNode(type, props) {
  4339. switch (type) {
  4340. case PlainValueEc8e588e.Type.ALIAS:
  4341. return new Alias$1(type, props);
  4342. case PlainValueEc8e588e.Type.BLOCK_FOLDED:
  4343. case PlainValueEc8e588e.Type.BLOCK_LITERAL:
  4344. return new BlockValue(type, props);
  4345. case PlainValueEc8e588e.Type.FLOW_MAP:
  4346. case PlainValueEc8e588e.Type.FLOW_SEQ:
  4347. return new FlowCollection(type, props);
  4348. case PlainValueEc8e588e.Type.MAP_KEY:
  4349. case PlainValueEc8e588e.Type.MAP_VALUE:
  4350. case PlainValueEc8e588e.Type.SEQ_ITEM:
  4351. return new CollectionItem(type, props);
  4352. case PlainValueEc8e588e.Type.COMMENT:
  4353. case PlainValueEc8e588e.Type.PLAIN:
  4354. return new PlainValueEc8e588e.PlainValue(type, props);
  4355. case PlainValueEc8e588e.Type.QUOTE_DOUBLE:
  4356. return new QuoteDouble(type, props);
  4357. case PlainValueEc8e588e.Type.QUOTE_SINGLE:
  4358. return new QuoteSingle(type, props);
  4359. /* istanbul ignore next */
  4360. default:
  4361. return null;
  4362. // should never happen
  4363. }
  4364. }
  4365. /**
  4366. * @param {boolean} atLineStart - Node starts at beginning of line
  4367. * @param {boolean} inFlow - true if currently in a flow context
  4368. * @param {boolean} inCollection - true if currently in a collection context
  4369. * @param {number} indent - Current level of indentation
  4370. * @param {number} lineStart - Start of the current line
  4371. * @param {Node} parent - The parent of the node
  4372. * @param {string} src - Source of the YAML document
  4373. */
  4374. class ParseContext {
  4375. static parseType(src, offset, inFlow) {
  4376. switch (src[offset]) {
  4377. case '*':
  4378. return PlainValueEc8e588e.Type.ALIAS;
  4379. case '>':
  4380. return PlainValueEc8e588e.Type.BLOCK_FOLDED;
  4381. case '|':
  4382. return PlainValueEc8e588e.Type.BLOCK_LITERAL;
  4383. case '{':
  4384. return PlainValueEc8e588e.Type.FLOW_MAP;
  4385. case '[':
  4386. return PlainValueEc8e588e.Type.FLOW_SEQ;
  4387. case '?':
  4388. return !inFlow && PlainValueEc8e588e.Node.atBlank(src, offset + 1, true) ? PlainValueEc8e588e.Type.MAP_KEY : PlainValueEc8e588e.Type.PLAIN;
  4389. case ':':
  4390. return !inFlow && PlainValueEc8e588e.Node.atBlank(src, offset + 1, true) ? PlainValueEc8e588e.Type.MAP_VALUE : PlainValueEc8e588e.Type.PLAIN;
  4391. case '-':
  4392. return !inFlow && PlainValueEc8e588e.Node.atBlank(src, offset + 1, true) ? PlainValueEc8e588e.Type.SEQ_ITEM : PlainValueEc8e588e.Type.PLAIN;
  4393. case '"':
  4394. return PlainValueEc8e588e.Type.QUOTE_DOUBLE;
  4395. case "'":
  4396. return PlainValueEc8e588e.Type.QUOTE_SINGLE;
  4397. default:
  4398. return PlainValueEc8e588e.Type.PLAIN;
  4399. }
  4400. }
  4401. constructor(orig = {}, {
  4402. atLineStart,
  4403. inCollection,
  4404. inFlow,
  4405. indent,
  4406. lineStart,
  4407. parent
  4408. } = {}) {
  4409. PlainValueEc8e588e._defineProperty(this, "parseNode", (overlay, start) => {
  4410. if (PlainValueEc8e588e.Node.atDocumentBoundary(this.src, start)) return null;
  4411. const context = new ParseContext(this, overlay);
  4412. const {
  4413. props,
  4414. type,
  4415. valueStart
  4416. } = context.parseProps(start);
  4417. const node = createNewNode(type, props);
  4418. let offset = node.parse(context, valueStart);
  4419. node.range = new PlainValueEc8e588e.Range(start, offset);
  4420. /* istanbul ignore if */
  4421. if (offset <= start) {
  4422. // This should never happen, but if it does, let's make sure to at least
  4423. // step one character forward to avoid a busy loop.
  4424. node.error = new Error(`Node#parse consumed no characters`);
  4425. node.error.parseEnd = offset;
  4426. node.error.source = node;
  4427. node.range.end = start + 1;
  4428. }
  4429. if (context.nodeStartsCollection(node)) {
  4430. if (!node.error && !context.atLineStart && context.parent.type === PlainValueEc8e588e.Type.DOCUMENT) {
  4431. node.error = new PlainValueEc8e588e.YAMLSyntaxError(node, 'Block collection must not have preceding content here (e.g. directives-end indicator)');
  4432. }
  4433. const collection = new Collection$1(node);
  4434. offset = collection.parse(new ParseContext(context), offset);
  4435. collection.range = new PlainValueEc8e588e.Range(start, offset);
  4436. return collection;
  4437. }
  4438. return node;
  4439. });
  4440. this.atLineStart = atLineStart != null ? atLineStart : orig.atLineStart || false;
  4441. this.inCollection = inCollection != null ? inCollection : orig.inCollection || false;
  4442. this.inFlow = inFlow != null ? inFlow : orig.inFlow || false;
  4443. this.indent = indent != null ? indent : orig.indent;
  4444. this.lineStart = lineStart != null ? lineStart : orig.lineStart;
  4445. this.parent = parent != null ? parent : orig.parent || {};
  4446. this.root = orig.root;
  4447. this.src = orig.src;
  4448. }
  4449. nodeStartsCollection(node) {
  4450. const {
  4451. inCollection,
  4452. inFlow,
  4453. src
  4454. } = this;
  4455. if (inCollection || inFlow) return false;
  4456. if (node instanceof CollectionItem) return true; // check for implicit key
  4457. let offset = node.range.end;
  4458. if (src[offset] === '\n' || src[offset - 1] === '\n') return false;
  4459. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  4460. return src[offset] === ':';
  4461. } // Anchor and tag are before type, which determines the node implementation
  4462. // class; hence this intermediate step.
  4463. parseProps(offset) {
  4464. const {
  4465. inFlow,
  4466. parent,
  4467. src
  4468. } = this;
  4469. const props = [];
  4470. let lineHasProps = false;
  4471. offset = this.atLineStart ? PlainValueEc8e588e.Node.endOfIndent(src, offset) : PlainValueEc8e588e.Node.endOfWhiteSpace(src, offset);
  4472. let ch = src[offset];
  4473. while (ch === PlainValueEc8e588e.Char.ANCHOR || ch === PlainValueEc8e588e.Char.COMMENT || ch === PlainValueEc8e588e.Char.TAG || ch === '\n') {
  4474. if (ch === '\n') {
  4475. let inEnd = offset;
  4476. let lineStart;
  4477. do {
  4478. lineStart = inEnd + 1;
  4479. inEnd = PlainValueEc8e588e.Node.endOfIndent(src, lineStart);
  4480. } while (src[inEnd] === '\n');
  4481. const indentDiff = inEnd - (lineStart + this.indent);
  4482. const noIndicatorAsIndent = parent.type === PlainValueEc8e588e.Type.SEQ_ITEM && parent.context.atLineStart;
  4483. if (src[inEnd] !== '#' && !PlainValueEc8e588e.Node.nextNodeIsIndented(src[inEnd], indentDiff, !noIndicatorAsIndent)) break;
  4484. this.atLineStart = true;
  4485. this.lineStart = lineStart;
  4486. lineHasProps = false;
  4487. offset = inEnd;
  4488. } else if (ch === PlainValueEc8e588e.Char.COMMENT) {
  4489. const end = PlainValueEc8e588e.Node.endOfLine(src, offset + 1);
  4490. props.push(new PlainValueEc8e588e.Range(offset, end));
  4491. offset = end;
  4492. } else {
  4493. let end = PlainValueEc8e588e.Node.endOfIdentifier(src, offset + 1);
  4494. if (ch === PlainValueEc8e588e.Char.TAG && src[end] === ',' && /^[a-zA-Z0-9-]+\.[a-zA-Z0-9-]+,\d\d\d\d(-\d\d){0,2}\/\S/.test(src.slice(offset + 1, end + 13))) {
  4495. // Let's presume we're dealing with a YAML 1.0 domain tag here, rather
  4496. // than an empty but 'foo.bar' private-tagged node in a flow collection
  4497. // followed without whitespace by a plain string starting with a year
  4498. // or date divided by something.
  4499. end = PlainValueEc8e588e.Node.endOfIdentifier(src, end + 5);
  4500. }
  4501. props.push(new PlainValueEc8e588e.Range(offset, end));
  4502. lineHasProps = true;
  4503. offset = PlainValueEc8e588e.Node.endOfWhiteSpace(src, end);
  4504. }
  4505. ch = src[offset];
  4506. } // '- &a : b' has an anchor on an empty node
  4507. if (lineHasProps && ch === ':' && PlainValueEc8e588e.Node.atBlank(src, offset + 1, true)) offset -= 1;
  4508. const type = ParseContext.parseType(src, offset, inFlow);
  4509. return {
  4510. props,
  4511. type,
  4512. valueStart: offset
  4513. };
  4514. }
  4515. /**
  4516. * Parses a node from the source
  4517. * @param {ParseContext} overlay
  4518. * @param {number} start - Index of first non-whitespace character for the node
  4519. * @returns {?Node} - null if at a document boundary
  4520. */
  4521. } // Published as 'yaml/parse-cst'
  4522. function parse$1(src) {
  4523. const cr = [];
  4524. if (src.indexOf('\r') !== -1) {
  4525. src = src.replace(/\r\n?/g, (match, offset) => {
  4526. if (match.length > 1) cr.push(offset);
  4527. return '\n';
  4528. });
  4529. }
  4530. const documents = [];
  4531. let offset = 0;
  4532. do {
  4533. const doc = new Document$2();
  4534. const context = new ParseContext({
  4535. src
  4536. });
  4537. offset = doc.parse(context, offset);
  4538. documents.push(doc);
  4539. } while (offset < src.length);
  4540. documents.setOrigRanges = () => {
  4541. if (cr.length === 0) return false;
  4542. for (let i = 1; i < cr.length; ++i) cr[i] -= i;
  4543. let crOffset = 0;
  4544. for (let i = 0; i < documents.length; ++i) {
  4545. crOffset = documents[i].setOrigRanges(cr, crOffset);
  4546. }
  4547. cr.splice(0, cr.length);
  4548. return true;
  4549. };
  4550. documents.toString = () => documents.join('...\n');
  4551. return documents;
  4552. }
  4553. var parse_1 = parse$1;
  4554. var parseCst = {
  4555. parse: parse_1
  4556. };
  4557. function addCommentBefore(str, indent, comment) {
  4558. if (!comment) return str;
  4559. const cc = comment.replace(/[\s\S]^/gm, `$&${indent}#`);
  4560. return `#${cc}\n${indent}${str}`;
  4561. }
  4562. function addComment(str, indent, comment) {
  4563. return !comment ? str : comment.indexOf('\n') === -1 ? `${str} #${comment}` : `${str}\n` + comment.replace(/^/gm, `${indent || ''}#`);
  4564. }
  4565. class Node {}
  4566. function toJSON(value, arg, ctx) {
  4567. if (Array.isArray(value)) return value.map((v, i) => toJSON(v, String(i), ctx));
  4568. if (value && typeof value.toJSON === 'function') {
  4569. const anchor = ctx && ctx.anchors && ctx.anchors.get(value);
  4570. if (anchor) ctx.onCreate = res => {
  4571. anchor.res = res;
  4572. delete ctx.onCreate;
  4573. };
  4574. const res = value.toJSON(arg, ctx);
  4575. if (anchor && ctx.onCreate) ctx.onCreate(res);
  4576. return res;
  4577. }
  4578. if ((!ctx || !ctx.keep) && typeof value === 'bigint') return Number(value);
  4579. return value;
  4580. }
  4581. class Scalar extends Node {
  4582. constructor(value) {
  4583. super();
  4584. this.value = value;
  4585. }
  4586. toJSON(arg, ctx) {
  4587. return ctx && ctx.keep ? this.value : toJSON(this.value, arg, ctx);
  4588. }
  4589. toString() {
  4590. return String(this.value);
  4591. }
  4592. }
  4593. function collectionFromPath(schema, path, value) {
  4594. let v = value;
  4595. for (let i = path.length - 1; i >= 0; --i) {
  4596. const k = path[i];
  4597. if (Number.isInteger(k) && k >= 0) {
  4598. const a = [];
  4599. a[k] = v;
  4600. v = a;
  4601. } else {
  4602. const o = {};
  4603. Object.defineProperty(o, k, {
  4604. value: v,
  4605. writable: true,
  4606. enumerable: true,
  4607. configurable: true
  4608. });
  4609. v = o;
  4610. }
  4611. }
  4612. return schema.createNode(v, false);
  4613. } // null, undefined, or an empty non-string iterable (e.g. [])
  4614. const isEmptyPath = path => path == null || typeof path === 'object' && path[Symbol.iterator]().next().done;
  4615. class Collection extends Node {
  4616. constructor(schema) {
  4617. super();
  4618. PlainValueEc8e588e._defineProperty(this, "items", []);
  4619. this.schema = schema;
  4620. }
  4621. addIn(path, value) {
  4622. if (isEmptyPath(path)) this.add(value);else {
  4623. const [key, ...rest] = path;
  4624. const node = this.get(key, true);
  4625. if (node instanceof Collection) node.addIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
  4626. }
  4627. }
  4628. deleteIn([key, ...rest]) {
  4629. if (rest.length === 0) return this.delete(key);
  4630. const node = this.get(key, true);
  4631. if (node instanceof Collection) return node.deleteIn(rest);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
  4632. }
  4633. getIn([key, ...rest], keepScalar) {
  4634. const node = this.get(key, true);
  4635. if (rest.length === 0) return !keepScalar && node instanceof Scalar ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined;
  4636. }
  4637. hasAllNullValues() {
  4638. return this.items.every(node => {
  4639. if (!node || node.type !== 'PAIR') return false;
  4640. const n = node.value;
  4641. return n == null || n instanceof Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag;
  4642. });
  4643. }
  4644. hasIn([key, ...rest]) {
  4645. if (rest.length === 0) return this.has(key);
  4646. const node = this.get(key, true);
  4647. return node instanceof Collection ? node.hasIn(rest) : false;
  4648. }
  4649. setIn([key, ...rest], value) {
  4650. if (rest.length === 0) {
  4651. this.set(key, value);
  4652. } else {
  4653. const node = this.get(key, true);
  4654. if (node instanceof Collection) node.setIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
  4655. }
  4656. } // overridden in implementations
  4657. /* istanbul ignore next */
  4658. toJSON() {
  4659. return null;
  4660. }
  4661. toString(ctx, {
  4662. blockItem,
  4663. flowChars,
  4664. isMap,
  4665. itemIndent
  4666. }, onComment, onChompKeep) {
  4667. const {
  4668. indent,
  4669. indentStep,
  4670. stringify
  4671. } = ctx;
  4672. const inFlow = this.type === PlainValueEc8e588e.Type.FLOW_MAP || this.type === PlainValueEc8e588e.Type.FLOW_SEQ || ctx.inFlow;
  4673. if (inFlow) itemIndent += indentStep;
  4674. const allNullValues = isMap && this.hasAllNullValues();
  4675. ctx = Object.assign({}, ctx, {
  4676. allNullValues,
  4677. indent: itemIndent,
  4678. inFlow,
  4679. type: null
  4680. });
  4681. let chompKeep = false;
  4682. let hasItemWithNewLine = false;
  4683. const nodes = this.items.reduce((nodes, item, i) => {
  4684. let comment;
  4685. if (item) {
  4686. if (!chompKeep && item.spaceBefore) nodes.push({
  4687. type: 'comment',
  4688. str: ''
  4689. });
  4690. if (item.commentBefore) item.commentBefore.match(/^.*$/gm).forEach(line => {
  4691. nodes.push({
  4692. type: 'comment',
  4693. str: `#${line}`
  4694. });
  4695. });
  4696. if (item.comment) comment = item.comment;
  4697. if (inFlow && (!chompKeep && item.spaceBefore || item.commentBefore || item.comment || item.key && (item.key.commentBefore || item.key.comment) || item.value && (item.value.commentBefore || item.value.comment))) hasItemWithNewLine = true;
  4698. }
  4699. chompKeep = false;
  4700. let str = stringify(item, ctx, () => comment = null, () => chompKeep = true);
  4701. if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true;
  4702. if (inFlow && i < this.items.length - 1) str += ',';
  4703. str = addComment(str, itemIndent, comment);
  4704. if (chompKeep && (comment || inFlow)) chompKeep = false;
  4705. nodes.push({
  4706. type: 'item',
  4707. str
  4708. });
  4709. return nodes;
  4710. }, []);
  4711. let str;
  4712. if (nodes.length === 0) {
  4713. str = flowChars.start + flowChars.end;
  4714. } else if (inFlow) {
  4715. const {
  4716. start,
  4717. end
  4718. } = flowChars;
  4719. const strings = nodes.map(n => n.str);
  4720. if (hasItemWithNewLine || strings.reduce((sum, str) => sum + str.length + 2, 2) > Collection.maxFlowStringSingleLineLength) {
  4721. str = start;
  4722. for (const s of strings) {
  4723. str += s ? `\n${indentStep}${indent}${s}` : '\n';
  4724. }
  4725. str += `\n${indent}${end}`;
  4726. } else {
  4727. str = `${start} ${strings.join(' ')} ${end}`;
  4728. }
  4729. } else {
  4730. const strings = nodes.map(blockItem);
  4731. str = strings.shift();
  4732. for (const s of strings) str += s ? `\n${indent}${s}` : '\n';
  4733. }
  4734. if (this.comment) {
  4735. str += '\n' + this.comment.replace(/^/gm, `${indent}#`);
  4736. if (onComment) onComment();
  4737. } else if (chompKeep && onChompKeep) onChompKeep();
  4738. return str;
  4739. }
  4740. }
  4741. PlainValueEc8e588e._defineProperty(Collection, "maxFlowStringSingleLineLength", 60);
  4742. function asItemIndex(key) {
  4743. let idx = key instanceof Scalar ? key.value : key;
  4744. if (idx && typeof idx === 'string') idx = Number(idx);
  4745. return Number.isInteger(idx) && idx >= 0 ? idx : null;
  4746. }
  4747. class YAMLSeq extends Collection {
  4748. add(value) {
  4749. this.items.push(value);
  4750. }
  4751. delete(key) {
  4752. const idx = asItemIndex(key);
  4753. if (typeof idx !== 'number') return false;
  4754. const del = this.items.splice(idx, 1);
  4755. return del.length > 0;
  4756. }
  4757. get(key, keepScalar) {
  4758. const idx = asItemIndex(key);
  4759. if (typeof idx !== 'number') return undefined;
  4760. const it = this.items[idx];
  4761. return !keepScalar && it instanceof Scalar ? it.value : it;
  4762. }
  4763. has(key) {
  4764. const idx = asItemIndex(key);
  4765. return typeof idx === 'number' && idx < this.items.length;
  4766. }
  4767. set(key, value) {
  4768. const idx = asItemIndex(key);
  4769. if (typeof idx !== 'number') throw new Error(`Expected a valid index, not ${key}.`);
  4770. this.items[idx] = value;
  4771. }
  4772. toJSON(_, ctx) {
  4773. const seq = [];
  4774. if (ctx && ctx.onCreate) ctx.onCreate(seq);
  4775. let i = 0;
  4776. for (const item of this.items) seq.push(toJSON(item, String(i++), ctx));
  4777. return seq;
  4778. }
  4779. toString(ctx, onComment, onChompKeep) {
  4780. if (!ctx) return JSON.stringify(this);
  4781. return super.toString(ctx, {
  4782. blockItem: n => n.type === 'comment' ? n.str : `- ${n.str}`,
  4783. flowChars: {
  4784. start: '[',
  4785. end: ']'
  4786. },
  4787. isMap: false,
  4788. itemIndent: (ctx.indent || '') + ' '
  4789. }, onComment, onChompKeep);
  4790. }
  4791. }
  4792. const stringifyKey = (key, jsKey, ctx) => {
  4793. if (jsKey === null) return '';
  4794. if (typeof jsKey !== 'object') return String(jsKey);
  4795. if (key instanceof Node && ctx && ctx.doc) return key.toString({
  4796. anchors: Object.create(null),
  4797. doc: ctx.doc,
  4798. indent: '',
  4799. indentStep: ctx.indentStep,
  4800. inFlow: true,
  4801. inStringifyKey: true,
  4802. stringify: ctx.stringify
  4803. });
  4804. return JSON.stringify(jsKey);
  4805. };
  4806. class Pair extends Node {
  4807. constructor(key, value = null) {
  4808. super();
  4809. this.key = key;
  4810. this.value = value;
  4811. this.type = Pair.Type.PAIR;
  4812. }
  4813. get commentBefore() {
  4814. return this.key instanceof Node ? this.key.commentBefore : undefined;
  4815. }
  4816. set commentBefore(cb) {
  4817. if (this.key == null) this.key = new Scalar(null);
  4818. if (this.key instanceof Node) this.key.commentBefore = cb;else {
  4819. const msg = 'Pair.commentBefore is an alias for Pair.key.commentBefore. To set it, the key must be a Node.';
  4820. throw new Error(msg);
  4821. }
  4822. }
  4823. addToJSMap(ctx, map) {
  4824. const key = toJSON(this.key, '', ctx);
  4825. if (map instanceof Map) {
  4826. const value = toJSON(this.value, key, ctx);
  4827. map.set(key, value);
  4828. } else if (map instanceof Set) {
  4829. map.add(key);
  4830. } else {
  4831. const stringKey = stringifyKey(this.key, key, ctx);
  4832. const value = toJSON(this.value, stringKey, ctx);
  4833. if (stringKey in map) Object.defineProperty(map, stringKey, {
  4834. value,
  4835. writable: true,
  4836. enumerable: true,
  4837. configurable: true
  4838. });else map[stringKey] = value;
  4839. }
  4840. return map;
  4841. }
  4842. toJSON(_, ctx) {
  4843. const pair = ctx && ctx.mapAsMap ? new Map() : {};
  4844. return this.addToJSMap(ctx, pair);
  4845. }
  4846. toString(ctx, onComment, onChompKeep) {
  4847. if (!ctx || !ctx.doc) return JSON.stringify(this);
  4848. const {
  4849. indent: indentSize,
  4850. indentSeq,
  4851. simpleKeys
  4852. } = ctx.doc.options;
  4853. let {
  4854. key,
  4855. value
  4856. } = this;
  4857. let keyComment = key instanceof Node && key.comment;
  4858. if (simpleKeys) {
  4859. if (keyComment) {
  4860. throw new Error('With simple keys, key nodes cannot have comments');
  4861. }
  4862. if (key instanceof Collection) {
  4863. const msg = 'With simple keys, collection cannot be used as a key value';
  4864. throw new Error(msg);
  4865. }
  4866. }
  4867. let explicitKey = !simpleKeys && (!key || keyComment || (key instanceof Node ? key instanceof Collection || key.type === PlainValueEc8e588e.Type.BLOCK_FOLDED || key.type === PlainValueEc8e588e.Type.BLOCK_LITERAL : typeof key === 'object'));
  4868. const {
  4869. doc,
  4870. indent,
  4871. indentStep,
  4872. stringify
  4873. } = ctx;
  4874. ctx = Object.assign({}, ctx, {
  4875. implicitKey: !explicitKey,
  4876. indent: indent + indentStep
  4877. });
  4878. let chompKeep = false;
  4879. let str = stringify(key, ctx, () => keyComment = null, () => chompKeep = true);
  4880. str = addComment(str, ctx.indent, keyComment);
  4881. if (!explicitKey && str.length > 1024) {
  4882. if (simpleKeys) throw new Error('With simple keys, single line scalar must not span more than 1024 characters');
  4883. explicitKey = true;
  4884. }
  4885. if (ctx.allNullValues && !simpleKeys) {
  4886. if (this.comment) {
  4887. str = addComment(str, ctx.indent, this.comment);
  4888. if (onComment) onComment();
  4889. } else if (chompKeep && !keyComment && onChompKeep) onChompKeep();
  4890. return ctx.inFlow && !explicitKey ? str : `? ${str}`;
  4891. }
  4892. str = explicitKey ? `? ${str}\n${indent}:` : `${str}:`;
  4893. if (this.comment) {
  4894. // expected (but not strictly required) to be a single-line comment
  4895. str = addComment(str, ctx.indent, this.comment);
  4896. if (onComment) onComment();
  4897. }
  4898. let vcb = '';
  4899. let valueComment = null;
  4900. if (value instanceof Node) {
  4901. if (value.spaceBefore) vcb = '\n';
  4902. if (value.commentBefore) {
  4903. const cs = value.commentBefore.replace(/^/gm, `${ctx.indent}#`);
  4904. vcb += `\n${cs}`;
  4905. }
  4906. valueComment = value.comment;
  4907. } else if (value && typeof value === 'object') {
  4908. value = doc.schema.createNode(value, true);
  4909. }
  4910. ctx.implicitKey = false;
  4911. if (!explicitKey && !this.comment && value instanceof Scalar) ctx.indentAtStart = str.length + 1;
  4912. chompKeep = false;
  4913. if (!indentSeq && indentSize >= 2 && !ctx.inFlow && !explicitKey && value instanceof YAMLSeq && value.type !== PlainValueEc8e588e.Type.FLOW_SEQ && !value.tag && !doc.anchors.getName(value)) {
  4914. // If indentSeq === false, consider '- ' as part of indentation where possible
  4915. ctx.indent = ctx.indent.substr(2);
  4916. }
  4917. const valueStr = stringify(value, ctx, () => valueComment = null, () => chompKeep = true);
  4918. let ws = ' ';
  4919. if (vcb || this.comment) {
  4920. ws = `${vcb}\n${ctx.indent}`;
  4921. } else if (!explicitKey && value instanceof Collection) {
  4922. const flow = valueStr[0] === '[' || valueStr[0] === '{';
  4923. if (!flow || valueStr.includes('\n')) ws = `\n${ctx.indent}`;
  4924. } else if (valueStr[0] === '\n') ws = '';
  4925. if (chompKeep && !valueComment && onChompKeep) onChompKeep();
  4926. return addComment(str + ws + valueStr, ctx.indent, valueComment);
  4927. }
  4928. }
  4929. PlainValueEc8e588e._defineProperty(Pair, "Type", {
  4930. PAIR: 'PAIR',
  4931. MERGE_PAIR: 'MERGE_PAIR'
  4932. });
  4933. const getAliasCount = (node, anchors) => {
  4934. if (node instanceof Alias) {
  4935. const anchor = anchors.get(node.source);
  4936. return anchor.count * anchor.aliasCount;
  4937. } else if (node instanceof Collection) {
  4938. let count = 0;
  4939. for (const item of node.items) {
  4940. const c = getAliasCount(item, anchors);
  4941. if (c > count) count = c;
  4942. }
  4943. return count;
  4944. } else if (node instanceof Pair) {
  4945. const kc = getAliasCount(node.key, anchors);
  4946. const vc = getAliasCount(node.value, anchors);
  4947. return Math.max(kc, vc);
  4948. }
  4949. return 1;
  4950. };
  4951. class Alias extends Node {
  4952. static stringify({
  4953. range,
  4954. source
  4955. }, {
  4956. anchors,
  4957. doc,
  4958. implicitKey,
  4959. inStringifyKey
  4960. }) {
  4961. let anchor = Object.keys(anchors).find(a => anchors[a] === source);
  4962. if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName();
  4963. if (anchor) return `*${anchor}${implicitKey ? ' ' : ''}`;
  4964. const msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
  4965. throw new Error(`${msg} [${range}]`);
  4966. }
  4967. constructor(source) {
  4968. super();
  4969. this.source = source;
  4970. this.type = PlainValueEc8e588e.Type.ALIAS;
  4971. }
  4972. set tag(t) {
  4973. throw new Error('Alias nodes cannot have tags');
  4974. }
  4975. toJSON(arg, ctx) {
  4976. if (!ctx) return toJSON(this.source, arg, ctx);
  4977. const {
  4978. anchors,
  4979. maxAliasCount
  4980. } = ctx;
  4981. const anchor = anchors.get(this.source);
  4982. /* istanbul ignore if */
  4983. if (!anchor || anchor.res === undefined) {
  4984. const msg = 'This should not happen: Alias anchor was not resolved?';
  4985. if (this.cstNode) throw new PlainValueEc8e588e.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
  4986. }
  4987. if (maxAliasCount >= 0) {
  4988. anchor.count += 1;
  4989. if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
  4990. if (anchor.count * anchor.aliasCount > maxAliasCount) {
  4991. const msg = 'Excessive alias count indicates a resource exhaustion attack';
  4992. if (this.cstNode) throw new PlainValueEc8e588e.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
  4993. }
  4994. }
  4995. return anchor.res;
  4996. } // Only called when stringifying an alias mapping key while constructing
  4997. // Object output.
  4998. toString(ctx) {
  4999. return Alias.stringify(this, ctx);
  5000. }
  5001. }
  5002. PlainValueEc8e588e._defineProperty(Alias, "default", true);
  5003. function findPair(items, key) {
  5004. const k = key instanceof Scalar ? key.value : key;
  5005. for (const it of items) {
  5006. if (it instanceof Pair) {
  5007. if (it.key === key || it.key === k) return it;
  5008. if (it.key && it.key.value === k) return it;
  5009. }
  5010. }
  5011. return undefined;
  5012. }
  5013. class YAMLMap extends Collection {
  5014. add(pair, overwrite) {
  5015. if (!pair) pair = new Pair(pair);else if (!(pair instanceof Pair)) pair = new Pair(pair.key || pair, pair.value);
  5016. const prev = findPair(this.items, pair.key);
  5017. const sortEntries = this.schema && this.schema.sortMapEntries;
  5018. if (prev) {
  5019. if (overwrite) prev.value = pair.value;else throw new Error(`Key ${pair.key} already set`);
  5020. } else if (sortEntries) {
  5021. const i = this.items.findIndex(item => sortEntries(pair, item) < 0);
  5022. if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair);
  5023. } else {
  5024. this.items.push(pair);
  5025. }
  5026. }
  5027. delete(key) {
  5028. const it = findPair(this.items, key);
  5029. if (!it) return false;
  5030. const del = this.items.splice(this.items.indexOf(it), 1);
  5031. return del.length > 0;
  5032. }
  5033. get(key, keepScalar) {
  5034. const it = findPair(this.items, key);
  5035. const node = it && it.value;
  5036. return !keepScalar && node instanceof Scalar ? node.value : node;
  5037. }
  5038. has(key) {
  5039. return !!findPair(this.items, key);
  5040. }
  5041. set(key, value) {
  5042. this.add(new Pair(key, value), true);
  5043. }
  5044. /**
  5045. * @param {*} arg ignored
  5046. * @param {*} ctx Conversion context, originally set in Document#toJSON()
  5047. * @param {Class} Type If set, forces the returned collection type
  5048. * @returns {*} Instance of Type, Map, or Object
  5049. */
  5050. toJSON(_, ctx, Type) {
  5051. const map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
  5052. if (ctx && ctx.onCreate) ctx.onCreate(map);
  5053. for (const item of this.items) item.addToJSMap(ctx, map);
  5054. return map;
  5055. }
  5056. toString(ctx, onComment, onChompKeep) {
  5057. if (!ctx) return JSON.stringify(this);
  5058. for (const item of this.items) {
  5059. if (!(item instanceof Pair)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
  5060. }
  5061. return super.toString(ctx, {
  5062. blockItem: n => n.str,
  5063. flowChars: {
  5064. start: '{',
  5065. end: '}'
  5066. },
  5067. isMap: true,
  5068. itemIndent: ctx.indent || ''
  5069. }, onComment, onChompKeep);
  5070. }
  5071. }
  5072. const MERGE_KEY = '<<';
  5073. class Merge extends Pair {
  5074. constructor(pair) {
  5075. if (pair instanceof Pair) {
  5076. let seq = pair.value;
  5077. if (!(seq instanceof YAMLSeq)) {
  5078. seq = new YAMLSeq();
  5079. seq.items.push(pair.value);
  5080. seq.range = pair.value.range;
  5081. }
  5082. super(pair.key, seq);
  5083. this.range = pair.range;
  5084. } else {
  5085. super(new Scalar(MERGE_KEY), new YAMLSeq());
  5086. }
  5087. this.type = Pair.Type.MERGE_PAIR;
  5088. } // If the value associated with a merge key is a single mapping node, each of
  5089. // its key/value pairs is inserted into the current mapping, unless the key
  5090. // already exists in it. If the value associated with the merge key is a
  5091. // sequence, then this sequence is expected to contain mapping nodes and each
  5092. // of these nodes is merged in turn according to its order in the sequence.
  5093. // Keys in mapping nodes earlier in the sequence override keys specified in
  5094. // later mapping nodes. -- http://yaml.org/type/merge.html
  5095. addToJSMap(ctx, map) {
  5096. for (const {
  5097. source
  5098. } of this.value.items) {
  5099. if (!(source instanceof YAMLMap)) throw new Error('Merge sources must be maps');
  5100. const srcMap = source.toJSON(null, ctx, Map);
  5101. for (const [key, value] of srcMap) {
  5102. if (map instanceof Map) {
  5103. if (!map.has(key)) map.set(key, value);
  5104. } else if (map instanceof Set) {
  5105. map.add(key);
  5106. } else if (!Object.prototype.hasOwnProperty.call(map, key)) {
  5107. Object.defineProperty(map, key, {
  5108. value,
  5109. writable: true,
  5110. enumerable: true,
  5111. configurable: true
  5112. });
  5113. }
  5114. }
  5115. }
  5116. return map;
  5117. }
  5118. toString(ctx, onComment) {
  5119. const seq = this.value;
  5120. if (seq.items.length > 1) return super.toString(ctx, onComment);
  5121. this.value = seq.items[0];
  5122. const str = super.toString(ctx, onComment);
  5123. this.value = seq;
  5124. return str;
  5125. }
  5126. }
  5127. const binaryOptions = {
  5128. defaultType: PlainValueEc8e588e.Type.BLOCK_LITERAL,
  5129. lineWidth: 76
  5130. };
  5131. const boolOptions = {
  5132. trueStr: 'true',
  5133. falseStr: 'false'
  5134. };
  5135. const intOptions = {
  5136. asBigInt: false
  5137. };
  5138. const nullOptions = {
  5139. nullStr: 'null'
  5140. };
  5141. const strOptions = {
  5142. defaultType: PlainValueEc8e588e.Type.PLAIN,
  5143. doubleQuoted: {
  5144. jsonEncoding: false,
  5145. minMultiLineLength: 40
  5146. },
  5147. fold: {
  5148. lineWidth: 80,
  5149. minContentWidth: 20
  5150. }
  5151. };
  5152. function resolveScalar(str, tags, scalarFallback) {
  5153. for (const {
  5154. format,
  5155. test,
  5156. resolve
  5157. } of tags) {
  5158. if (test) {
  5159. const match = str.match(test);
  5160. if (match) {
  5161. let res = resolve.apply(null, match);
  5162. if (!(res instanceof Scalar)) res = new Scalar(res);
  5163. if (format) res.format = format;
  5164. return res;
  5165. }
  5166. }
  5167. }
  5168. if (scalarFallback) str = scalarFallback(str);
  5169. return new Scalar(str);
  5170. }
  5171. const FOLD_FLOW = 'flow';
  5172. const FOLD_BLOCK = 'block';
  5173. const FOLD_QUOTED = 'quoted'; // presumes i+1 is at the start of a line
  5174. // returns index of last newline in more-indented block
  5175. const consumeMoreIndentedLines = (text, i) => {
  5176. let ch = text[i + 1];
  5177. while (ch === ' ' || ch === '\t') {
  5178. do {
  5179. ch = text[i += 1];
  5180. } while (ch && ch !== '\n');
  5181. ch = text[i + 1];
  5182. }
  5183. return i;
  5184. };
  5185. /**
  5186. * Tries to keep input at up to `lineWidth` characters, splitting only on spaces
  5187. * not followed by newlines or spaces unless `mode` is `'quoted'`. Lines are
  5188. * terminated with `\n` and started with `indent`.
  5189. *
  5190. * @param {string} text
  5191. * @param {string} indent
  5192. * @param {string} [mode='flow'] `'block'` prevents more-indented lines
  5193. * from being folded; `'quoted'` allows for `\` escapes, including escaped
  5194. * newlines
  5195. * @param {Object} options
  5196. * @param {number} [options.indentAtStart] Accounts for leading contents on
  5197. * the first line, defaulting to `indent.length`
  5198. * @param {number} [options.lineWidth=80]
  5199. * @param {number} [options.minContentWidth=20] Allow highly indented lines to
  5200. * stretch the line width or indent content from the start
  5201. * @param {function} options.onFold Called once if the text is folded
  5202. * @param {function} options.onFold Called once if any line of text exceeds
  5203. * lineWidth characters
  5204. */
  5205. function foldFlowLines(text, indent, mode, {
  5206. indentAtStart,
  5207. lineWidth = 80,
  5208. minContentWidth = 20,
  5209. onFold,
  5210. onOverflow
  5211. }) {
  5212. if (!lineWidth || lineWidth < 0) return text;
  5213. const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);
  5214. if (text.length <= endStep) return text;
  5215. const folds = [];
  5216. const escapedFolds = {};
  5217. let end = lineWidth - indent.length;
  5218. if (typeof indentAtStart === 'number') {
  5219. if (indentAtStart > lineWidth - Math.max(2, minContentWidth)) folds.push(0);else end = lineWidth - indentAtStart;
  5220. }
  5221. let split = undefined;
  5222. let prev = undefined;
  5223. let overflow = false;
  5224. let i = -1;
  5225. let escStart = -1;
  5226. let escEnd = -1;
  5227. if (mode === FOLD_BLOCK) {
  5228. i = consumeMoreIndentedLines(text, i);
  5229. if (i !== -1) end = i + endStep;
  5230. }
  5231. for (let ch; ch = text[i += 1];) {
  5232. if (mode === FOLD_QUOTED && ch === '\\') {
  5233. escStart = i;
  5234. switch (text[i + 1]) {
  5235. case 'x':
  5236. i += 3;
  5237. break;
  5238. case 'u':
  5239. i += 5;
  5240. break;
  5241. case 'U':
  5242. i += 9;
  5243. break;
  5244. default:
  5245. i += 1;
  5246. }
  5247. escEnd = i;
  5248. }
  5249. if (ch === '\n') {
  5250. if (mode === FOLD_BLOCK) i = consumeMoreIndentedLines(text, i);
  5251. end = i + endStep;
  5252. split = undefined;
  5253. } else {
  5254. if (ch === ' ' && prev && prev !== ' ' && prev !== '\n' && prev !== '\t') {
  5255. // space surrounded by non-space can be replaced with newline + indent
  5256. const next = text[i + 1];
  5257. if (next && next !== ' ' && next !== '\n' && next !== '\t') split = i;
  5258. }
  5259. if (i >= end) {
  5260. if (split) {
  5261. folds.push(split);
  5262. end = split + endStep;
  5263. split = undefined;
  5264. } else if (mode === FOLD_QUOTED) {
  5265. // white-space collected at end may stretch past lineWidth
  5266. while (prev === ' ' || prev === '\t') {
  5267. prev = ch;
  5268. ch = text[i += 1];
  5269. overflow = true;
  5270. } // Account for newline escape, but don't break preceding escape
  5271. const j = i > escEnd + 1 ? i - 2 : escStart - 1; // Bail out if lineWidth & minContentWidth are shorter than an escape string
  5272. if (escapedFolds[j]) return text;
  5273. folds.push(j);
  5274. escapedFolds[j] = true;
  5275. end = j + endStep;
  5276. split = undefined;
  5277. } else {
  5278. overflow = true;
  5279. }
  5280. }
  5281. }
  5282. prev = ch;
  5283. }
  5284. if (overflow && onOverflow) onOverflow();
  5285. if (folds.length === 0) return text;
  5286. if (onFold) onFold();
  5287. let res = text.slice(0, folds[0]);
  5288. for (let i = 0; i < folds.length; ++i) {
  5289. const fold = folds[i];
  5290. const end = folds[i + 1] || text.length;
  5291. if (fold === 0) res = `\n${indent}${text.slice(0, end)}`;else {
  5292. if (mode === FOLD_QUOTED && escapedFolds[fold]) res += `${text[fold]}\\`;
  5293. res += `\n${indent}${text.slice(fold + 1, end)}`;
  5294. }
  5295. }
  5296. return res;
  5297. }
  5298. const getFoldOptions = ({
  5299. indentAtStart
  5300. }) => indentAtStart ? Object.assign({
  5301. indentAtStart
  5302. }, strOptions.fold) : strOptions.fold; // Also checks for lines starting with %, as parsing the output as YAML 1.1 will
  5303. // presume that's starting a new document.
  5304. const containsDocumentMarker = str => /^(%|---|\.\.\.)/m.test(str);
  5305. function lineLengthOverLimit(str, lineWidth, indentLength) {
  5306. if (!lineWidth || lineWidth < 0) return false;
  5307. const limit = lineWidth - indentLength;
  5308. const strLen = str.length;
  5309. if (strLen <= limit) return false;
  5310. for (let i = 0, start = 0; i < strLen; ++i) {
  5311. if (str[i] === '\n') {
  5312. if (i - start > limit) return true;
  5313. start = i + 1;
  5314. if (strLen - start <= limit) return false;
  5315. }
  5316. }
  5317. return true;
  5318. }
  5319. function doubleQuotedString(value, ctx) {
  5320. const {
  5321. implicitKey
  5322. } = ctx;
  5323. const {
  5324. jsonEncoding,
  5325. minMultiLineLength
  5326. } = strOptions.doubleQuoted;
  5327. const json = JSON.stringify(value);
  5328. if (jsonEncoding) return json;
  5329. const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
  5330. let str = '';
  5331. let start = 0;
  5332. for (let i = 0, ch = json[i]; ch; ch = json[++i]) {
  5333. if (ch === ' ' && json[i + 1] === '\\' && json[i + 2] === 'n') {
  5334. // space before newline needs to be escaped to not be folded
  5335. str += json.slice(start, i) + '\\ ';
  5336. i += 1;
  5337. start = i;
  5338. ch = '\\';
  5339. }
  5340. if (ch === '\\') switch (json[i + 1]) {
  5341. case 'u':
  5342. {
  5343. str += json.slice(start, i);
  5344. const code = json.substr(i + 2, 4);
  5345. switch (code) {
  5346. case '0000':
  5347. str += '\\0';
  5348. break;
  5349. case '0007':
  5350. str += '\\a';
  5351. break;
  5352. case '000b':
  5353. str += '\\v';
  5354. break;
  5355. case '001b':
  5356. str += '\\e';
  5357. break;
  5358. case '0085':
  5359. str += '\\N';
  5360. break;
  5361. case '00a0':
  5362. str += '\\_';
  5363. break;
  5364. case '2028':
  5365. str += '\\L';
  5366. break;
  5367. case '2029':
  5368. str += '\\P';
  5369. break;
  5370. default:
  5371. if (code.substr(0, 2) === '00') str += '\\x' + code.substr(2);else str += json.substr(i, 6);
  5372. }
  5373. i += 5;
  5374. start = i + 1;
  5375. }
  5376. break;
  5377. case 'n':
  5378. if (implicitKey || json[i + 2] === '"' || json.length < minMultiLineLength) {
  5379. i += 1;
  5380. } else {
  5381. // folding will eat first newline
  5382. str += json.slice(start, i) + '\n\n';
  5383. while (json[i + 2] === '\\' && json[i + 3] === 'n' && json[i + 4] !== '"') {
  5384. str += '\n';
  5385. i += 2;
  5386. }
  5387. str += indent; // space after newline needs to be escaped to not be folded
  5388. if (json[i + 2] === ' ') str += '\\';
  5389. i += 1;
  5390. start = i + 1;
  5391. }
  5392. break;
  5393. default:
  5394. i += 1;
  5395. }
  5396. }
  5397. str = start ? str + json.slice(start) : json;
  5398. return implicitKey ? str : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
  5399. }
  5400. function singleQuotedString(value, ctx) {
  5401. if (ctx.implicitKey) {
  5402. if (/\n/.test(value)) return doubleQuotedString(value, ctx);
  5403. } else {
  5404. // single quoted string can't have leading or trailing whitespace around newline
  5405. if (/[ \t]\n|\n[ \t]/.test(value)) return doubleQuotedString(value, ctx);
  5406. }
  5407. const indent = ctx.indent || (containsDocumentMarker(value) ? ' ' : '');
  5408. const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
  5409. return ctx.implicitKey ? res : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
  5410. }
  5411. function blockString({
  5412. comment,
  5413. type,
  5414. value
  5415. }, ctx, onComment, onChompKeep) {
  5416. // 1. Block can't end in whitespace unless the last line is non-empty.
  5417. // 2. Strings consisting of only whitespace are best rendered explicitly.
  5418. if (/\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
  5419. return doubleQuotedString(value, ctx);
  5420. }
  5421. const indent = ctx.indent || (ctx.forceBlockIndent || containsDocumentMarker(value) ? ' ' : '');
  5422. const indentSize = indent ? '2' : '1'; // root is at -1
  5423. const literal = type === PlainValueEc8e588e.Type.BLOCK_FOLDED ? false : type === PlainValueEc8e588e.Type.BLOCK_LITERAL ? true : !lineLengthOverLimit(value, strOptions.fold.lineWidth, indent.length);
  5424. let header = literal ? '|' : '>';
  5425. if (!value) return header + '\n';
  5426. let wsStart = '';
  5427. let wsEnd = '';
  5428. value = value.replace(/[\n\t ]*$/, ws => {
  5429. const n = ws.indexOf('\n');
  5430. if (n === -1) {
  5431. header += '-'; // strip
  5432. } else if (value === ws || n !== ws.length - 1) {
  5433. header += '+'; // keep
  5434. if (onChompKeep) onChompKeep();
  5435. }
  5436. wsEnd = ws.replace(/\n$/, '');
  5437. return '';
  5438. }).replace(/^[\n ]*/, ws => {
  5439. if (ws.indexOf(' ') !== -1) header += indentSize;
  5440. const m = ws.match(/ +$/);
  5441. if (m) {
  5442. wsStart = ws.slice(0, -m[0].length);
  5443. return m[0];
  5444. } else {
  5445. wsStart = ws;
  5446. return '';
  5447. }
  5448. });
  5449. if (wsEnd) wsEnd = wsEnd.replace(/\n+(?!\n|$)/g, `$&${indent}`);
  5450. if (wsStart) wsStart = wsStart.replace(/\n+/g, `$&${indent}`);
  5451. if (comment) {
  5452. header += ' #' + comment.replace(/ ?[\r\n]+/g, ' ');
  5453. if (onComment) onComment();
  5454. }
  5455. if (!value) return `${header}${indentSize}\n${indent}${wsEnd}`;
  5456. if (literal) {
  5457. value = value.replace(/\n+/g, `$&${indent}`);
  5458. return `${header}\n${indent}${wsStart}${value}${wsEnd}`;
  5459. }
  5460. value = value.replace(/\n+/g, '\n$&').replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
  5461. // ^ ind.line ^ empty ^ capture next empty lines only at end of indent
  5462. .replace(/\n+/g, `$&${indent}`);
  5463. const body = foldFlowLines(`${wsStart}${value}${wsEnd}`, indent, FOLD_BLOCK, strOptions.fold);
  5464. return `${header}\n${indent}${body}`;
  5465. }
  5466. function plainString(item, ctx, onComment, onChompKeep) {
  5467. const {
  5468. comment,
  5469. type,
  5470. value
  5471. } = item;
  5472. const {
  5473. actualString,
  5474. implicitKey,
  5475. indent,
  5476. inFlow
  5477. } = ctx;
  5478. if (implicitKey && /[\n[\]{},]/.test(value) || inFlow && /[[\]{},]/.test(value)) {
  5479. return doubleQuotedString(value, ctx);
  5480. }
  5481. if (!value || /^[\n\t ,[\]{}#&*!|>'"%@`]|^[?-]$|^[?-][ \t]|[\n:][ \t]|[ \t]\n|[\n\t ]#|[\n\t :]$/.test(value)) {
  5482. // not allowed:
  5483. // - empty string, '-' or '?'
  5484. // - start with an indicator character (except [?:-]) or /[?-] /
  5485. // - '\n ', ': ' or ' \n' anywhere
  5486. // - '#' not preceded by a non-space char
  5487. // - end with ' ' or ':'
  5488. return implicitKey || inFlow || value.indexOf('\n') === -1 ? value.indexOf('"') !== -1 && value.indexOf("'") === -1 ? singleQuotedString(value, ctx) : doubleQuotedString(value, ctx) : blockString(item, ctx, onComment, onChompKeep);
  5489. }
  5490. if (!implicitKey && !inFlow && type !== PlainValueEc8e588e.Type.PLAIN && value.indexOf('\n') !== -1) {
  5491. // Where allowed & type not set explicitly, prefer block style for multiline strings
  5492. return blockString(item, ctx, onComment, onChompKeep);
  5493. }
  5494. if (indent === '' && containsDocumentMarker(value)) {
  5495. ctx.forceBlockIndent = true;
  5496. return blockString(item, ctx, onComment, onChompKeep);
  5497. }
  5498. const str = value.replace(/\n+/g, `$&\n${indent}`); // Verify that output will be parsed as a string, as e.g. plain numbers and
  5499. // booleans get parsed with those types in v1.2 (e.g. '42', 'true' & '0.9e-3'),
  5500. // and others in v1.1.
  5501. if (actualString) {
  5502. const {
  5503. tags
  5504. } = ctx.doc.schema;
  5505. const resolved = resolveScalar(str, tags, tags.scalarFallback).value;
  5506. if (typeof resolved !== 'string') return doubleQuotedString(value, ctx);
  5507. }
  5508. const body = implicitKey ? str : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
  5509. if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
  5510. if (onComment) onComment();
  5511. return addCommentBefore(body, indent, comment);
  5512. }
  5513. return body;
  5514. }
  5515. function stringifyString(item, ctx, onComment, onChompKeep) {
  5516. const {
  5517. defaultType
  5518. } = strOptions;
  5519. const {
  5520. implicitKey,
  5521. inFlow
  5522. } = ctx;
  5523. let {
  5524. type,
  5525. value
  5526. } = item;
  5527. if (typeof value !== 'string') {
  5528. value = String(value);
  5529. item = Object.assign({}, item, {
  5530. value
  5531. });
  5532. }
  5533. const _stringify = _type => {
  5534. switch (_type) {
  5535. case PlainValueEc8e588e.Type.BLOCK_FOLDED:
  5536. case PlainValueEc8e588e.Type.BLOCK_LITERAL:
  5537. return blockString(item, ctx, onComment, onChompKeep);
  5538. case PlainValueEc8e588e.Type.QUOTE_DOUBLE:
  5539. return doubleQuotedString(value, ctx);
  5540. case PlainValueEc8e588e.Type.QUOTE_SINGLE:
  5541. return singleQuotedString(value, ctx);
  5542. case PlainValueEc8e588e.Type.PLAIN:
  5543. return plainString(item, ctx, onComment, onChompKeep);
  5544. default:
  5545. return null;
  5546. }
  5547. };
  5548. if (type !== PlainValueEc8e588e.Type.QUOTE_DOUBLE && /[\x00-\x08\x0b-\x1f\x7f-\x9f]/.test(value)) {
  5549. // force double quotes on control characters
  5550. type = PlainValueEc8e588e.Type.QUOTE_DOUBLE;
  5551. } else if ((implicitKey || inFlow) && (type === PlainValueEc8e588e.Type.BLOCK_FOLDED || type === PlainValueEc8e588e.Type.BLOCK_LITERAL)) {
  5552. // should not happen; blocks are not valid inside flow containers
  5553. type = PlainValueEc8e588e.Type.QUOTE_DOUBLE;
  5554. }
  5555. let res = _stringify(type);
  5556. if (res === null) {
  5557. res = _stringify(defaultType);
  5558. if (res === null) throw new Error(`Unsupported default string type ${defaultType}`);
  5559. }
  5560. return res;
  5561. }
  5562. function stringifyNumber({
  5563. format,
  5564. minFractionDigits,
  5565. tag,
  5566. value
  5567. }) {
  5568. if (typeof value === 'bigint') return String(value);
  5569. if (!isFinite(value)) return isNaN(value) ? '.nan' : value < 0 ? '-.inf' : '.inf';
  5570. let n = JSON.stringify(value);
  5571. if (!format && minFractionDigits && (!tag || tag === 'tag:yaml.org,2002:float') && /^\d/.test(n)) {
  5572. let i = n.indexOf('.');
  5573. if (i < 0) {
  5574. i = n.length;
  5575. n += '.';
  5576. }
  5577. let d = minFractionDigits - (n.length - i - 1);
  5578. while (d-- > 0) n += '0';
  5579. }
  5580. return n;
  5581. }
  5582. function checkFlowCollectionEnd(errors, cst) {
  5583. let char, name;
  5584. switch (cst.type) {
  5585. case PlainValueEc8e588e.Type.FLOW_MAP:
  5586. char = '}';
  5587. name = 'flow map';
  5588. break;
  5589. case PlainValueEc8e588e.Type.FLOW_SEQ:
  5590. char = ']';
  5591. name = 'flow sequence';
  5592. break;
  5593. default:
  5594. errors.push(new PlainValueEc8e588e.YAMLSemanticError(cst, 'Not a flow collection!?'));
  5595. return;
  5596. }
  5597. let lastItem;
  5598. for (let i = cst.items.length - 1; i >= 0; --i) {
  5599. const item = cst.items[i];
  5600. if (!item || item.type !== PlainValueEc8e588e.Type.COMMENT) {
  5601. lastItem = item;
  5602. break;
  5603. }
  5604. }
  5605. if (lastItem && lastItem.char !== char) {
  5606. const msg = `Expected ${name} to end with ${char}`;
  5607. let err;
  5608. if (typeof lastItem.offset === 'number') {
  5609. err = new PlainValueEc8e588e.YAMLSemanticError(cst, msg);
  5610. err.offset = lastItem.offset + 1;
  5611. } else {
  5612. err = new PlainValueEc8e588e.YAMLSemanticError(lastItem, msg);
  5613. if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
  5614. }
  5615. errors.push(err);
  5616. }
  5617. }
  5618. function checkFlowCommentSpace(errors, comment) {
  5619. const prev = comment.context.src[comment.range.start - 1];
  5620. if (prev !== '\n' && prev !== '\t' && prev !== ' ') {
  5621. const msg = 'Comments must be separated from other tokens by white space characters';
  5622. errors.push(new PlainValueEc8e588e.YAMLSemanticError(comment, msg));
  5623. }
  5624. }
  5625. function getLongKeyError(source, key) {
  5626. const sk = String(key);
  5627. const k = sk.substr(0, 8) + '...' + sk.substr(-8);
  5628. return new PlainValueEc8e588e.YAMLSemanticError(source, `The "${k}" key is too long`);
  5629. }
  5630. function resolveComments(collection, comments) {
  5631. for (const {
  5632. afterKey,
  5633. before,
  5634. comment
  5635. } of comments) {
  5636. let item = collection.items[before];
  5637. if (!item) {
  5638. if (comment !== undefined) {
  5639. if (collection.comment) collection.comment += '\n' + comment;else collection.comment = comment;
  5640. }
  5641. } else {
  5642. if (afterKey && item.value) item = item.value;
  5643. if (comment === undefined) {
  5644. if (afterKey || !item.commentBefore) item.spaceBefore = true;
  5645. } else {
  5646. if (item.commentBefore) item.commentBefore += '\n' + comment;else item.commentBefore = comment;
  5647. }
  5648. }
  5649. }
  5650. } // on error, will return { str: string, errors: Error[] }
  5651. function resolveString(doc, node) {
  5652. const res = node.strValue;
  5653. if (!res) return '';
  5654. if (typeof res === 'string') return res;
  5655. res.errors.forEach(error => {
  5656. if (!error.source) error.source = node;
  5657. doc.errors.push(error);
  5658. });
  5659. return res.str;
  5660. }
  5661. function resolveTagHandle(doc, node) {
  5662. const {
  5663. handle,
  5664. suffix
  5665. } = node.tag;
  5666. let prefix = doc.tagPrefixes.find(p => p.handle === handle);
  5667. if (!prefix) {
  5668. const dtp = doc.getDefaults().tagPrefixes;
  5669. if (dtp) prefix = dtp.find(p => p.handle === handle);
  5670. if (!prefix) throw new PlainValueEc8e588e.YAMLSemanticError(node, `The ${handle} tag handle is non-default and was not declared.`);
  5671. }
  5672. if (!suffix) throw new PlainValueEc8e588e.YAMLSemanticError(node, `The ${handle} tag has no suffix.`);
  5673. if (handle === '!' && (doc.version || doc.options.version) === '1.0') {
  5674. if (suffix[0] === '^') {
  5675. doc.warnings.push(new PlainValueEc8e588e.YAMLWarning(node, 'YAML 1.0 ^ tag expansion is not supported'));
  5676. return suffix;
  5677. }
  5678. if (/[:/]/.test(suffix)) {
  5679. // word/foo -> tag:word.yaml.org,2002:foo
  5680. const vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i);
  5681. return vocab ? `tag:${vocab[1]}.yaml.org,2002:${vocab[2]}` : `tag:${suffix}`;
  5682. }
  5683. }
  5684. return prefix.prefix + decodeURIComponent(suffix);
  5685. }
  5686. function resolveTagName(doc, node) {
  5687. const {
  5688. tag,
  5689. type
  5690. } = node;
  5691. let nonSpecific = false;
  5692. if (tag) {
  5693. const {
  5694. handle,
  5695. suffix,
  5696. verbatim
  5697. } = tag;
  5698. if (verbatim) {
  5699. if (verbatim !== '!' && verbatim !== '!!') return verbatim;
  5700. const msg = `Verbatim tags aren't resolved, so ${verbatim} is invalid.`;
  5701. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(node, msg));
  5702. } else if (handle === '!' && !suffix) {
  5703. nonSpecific = true;
  5704. } else {
  5705. try {
  5706. return resolveTagHandle(doc, node);
  5707. } catch (error) {
  5708. doc.errors.push(error);
  5709. }
  5710. }
  5711. }
  5712. switch (type) {
  5713. case PlainValueEc8e588e.Type.BLOCK_FOLDED:
  5714. case PlainValueEc8e588e.Type.BLOCK_LITERAL:
  5715. case PlainValueEc8e588e.Type.QUOTE_DOUBLE:
  5716. case PlainValueEc8e588e.Type.QUOTE_SINGLE:
  5717. return PlainValueEc8e588e.defaultTags.STR;
  5718. case PlainValueEc8e588e.Type.FLOW_MAP:
  5719. case PlainValueEc8e588e.Type.MAP:
  5720. return PlainValueEc8e588e.defaultTags.MAP;
  5721. case PlainValueEc8e588e.Type.FLOW_SEQ:
  5722. case PlainValueEc8e588e.Type.SEQ:
  5723. return PlainValueEc8e588e.defaultTags.SEQ;
  5724. case PlainValueEc8e588e.Type.PLAIN:
  5725. return nonSpecific ? PlainValueEc8e588e.defaultTags.STR : null;
  5726. default:
  5727. return null;
  5728. }
  5729. }
  5730. function resolveByTagName(doc, node, tagName) {
  5731. const {
  5732. tags
  5733. } = doc.schema;
  5734. const matchWithTest = [];
  5735. for (const tag of tags) {
  5736. if (tag.tag === tagName) {
  5737. if (tag.test) matchWithTest.push(tag);else {
  5738. const res = tag.resolve(doc, node);
  5739. return res instanceof Collection ? res : new Scalar(res);
  5740. }
  5741. }
  5742. }
  5743. const str = resolveString(doc, node);
  5744. if (typeof str === 'string' && matchWithTest.length > 0) return resolveScalar(str, matchWithTest, tags.scalarFallback);
  5745. return null;
  5746. }
  5747. function getFallbackTagName({
  5748. type
  5749. }) {
  5750. switch (type) {
  5751. case PlainValueEc8e588e.Type.FLOW_MAP:
  5752. case PlainValueEc8e588e.Type.MAP:
  5753. return PlainValueEc8e588e.defaultTags.MAP;
  5754. case PlainValueEc8e588e.Type.FLOW_SEQ:
  5755. case PlainValueEc8e588e.Type.SEQ:
  5756. return PlainValueEc8e588e.defaultTags.SEQ;
  5757. default:
  5758. return PlainValueEc8e588e.defaultTags.STR;
  5759. }
  5760. }
  5761. function resolveTag(doc, node, tagName) {
  5762. try {
  5763. const res = resolveByTagName(doc, node, tagName);
  5764. if (res) {
  5765. if (tagName && node.tag) res.tag = tagName;
  5766. return res;
  5767. }
  5768. } catch (error) {
  5769. /* istanbul ignore if */
  5770. if (!error.source) error.source = node;
  5771. doc.errors.push(error);
  5772. return null;
  5773. }
  5774. try {
  5775. const fallback = getFallbackTagName(node);
  5776. if (!fallback) throw new Error(`The tag ${tagName} is unavailable`);
  5777. const msg = `The tag ${tagName} is unavailable, falling back to ${fallback}`;
  5778. doc.warnings.push(new PlainValueEc8e588e.YAMLWarning(node, msg));
  5779. const res = resolveByTagName(doc, node, fallback);
  5780. res.tag = tagName;
  5781. return res;
  5782. } catch (error) {
  5783. const refError = new PlainValueEc8e588e.YAMLReferenceError(node, error.message);
  5784. refError.stack = error.stack;
  5785. doc.errors.push(refError);
  5786. return null;
  5787. }
  5788. }
  5789. const isCollectionItem = node => {
  5790. if (!node) return false;
  5791. const {
  5792. type
  5793. } = node;
  5794. return type === PlainValueEc8e588e.Type.MAP_KEY || type === PlainValueEc8e588e.Type.MAP_VALUE || type === PlainValueEc8e588e.Type.SEQ_ITEM;
  5795. };
  5796. function resolveNodeProps(errors, node) {
  5797. const comments = {
  5798. before: [],
  5799. after: []
  5800. };
  5801. let hasAnchor = false;
  5802. let hasTag = false;
  5803. const props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
  5804. for (const {
  5805. start,
  5806. end
  5807. } of props) {
  5808. switch (node.context.src[start]) {
  5809. case PlainValueEc8e588e.Char.COMMENT:
  5810. {
  5811. if (!node.commentHasRequiredWhitespace(start)) {
  5812. const msg = 'Comments must be separated from other tokens by white space characters';
  5813. errors.push(new PlainValueEc8e588e.YAMLSemanticError(node, msg));
  5814. }
  5815. const {
  5816. header,
  5817. valueRange
  5818. } = node;
  5819. const cc = valueRange && (start > valueRange.start || header && start > header.start) ? comments.after : comments.before;
  5820. cc.push(node.context.src.slice(start + 1, end));
  5821. break;
  5822. }
  5823. // Actual anchor & tag resolution is handled by schema, here we just complain
  5824. case PlainValueEc8e588e.Char.ANCHOR:
  5825. if (hasAnchor) {
  5826. const msg = 'A node can have at most one anchor';
  5827. errors.push(new PlainValueEc8e588e.YAMLSemanticError(node, msg));
  5828. }
  5829. hasAnchor = true;
  5830. break;
  5831. case PlainValueEc8e588e.Char.TAG:
  5832. if (hasTag) {
  5833. const msg = 'A node can have at most one tag';
  5834. errors.push(new PlainValueEc8e588e.YAMLSemanticError(node, msg));
  5835. }
  5836. hasTag = true;
  5837. break;
  5838. }
  5839. }
  5840. return {
  5841. comments,
  5842. hasAnchor,
  5843. hasTag
  5844. };
  5845. }
  5846. function resolveNodeValue(doc, node) {
  5847. const {
  5848. anchors,
  5849. errors,
  5850. schema
  5851. } = doc;
  5852. if (node.type === PlainValueEc8e588e.Type.ALIAS) {
  5853. const name = node.rawValue;
  5854. const src = anchors.getNode(name);
  5855. if (!src) {
  5856. const msg = `Aliased anchor not found: ${name}`;
  5857. errors.push(new PlainValueEc8e588e.YAMLReferenceError(node, msg));
  5858. return null;
  5859. } // Lazy resolution for circular references
  5860. const res = new Alias(src);
  5861. anchors._cstAliases.push(res);
  5862. return res;
  5863. }
  5864. const tagName = resolveTagName(doc, node);
  5865. if (tagName) return resolveTag(doc, node, tagName);
  5866. if (node.type !== PlainValueEc8e588e.Type.PLAIN) {
  5867. const msg = `Failed to resolve ${node.type} node here`;
  5868. errors.push(new PlainValueEc8e588e.YAMLSyntaxError(node, msg));
  5869. return null;
  5870. }
  5871. try {
  5872. const str = resolveString(doc, node);
  5873. return resolveScalar(str, schema.tags, schema.tags.scalarFallback);
  5874. } catch (error) {
  5875. if (!error.source) error.source = node;
  5876. errors.push(error);
  5877. return null;
  5878. }
  5879. } // sets node.resolved on success
  5880. function resolveNode(doc, node) {
  5881. if (!node) return null;
  5882. if (node.error) doc.errors.push(node.error);
  5883. const {
  5884. comments,
  5885. hasAnchor,
  5886. hasTag
  5887. } = resolveNodeProps(doc.errors, node);
  5888. if (hasAnchor) {
  5889. const {
  5890. anchors
  5891. } = doc;
  5892. const name = node.anchor;
  5893. const prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor
  5894. // name have already been resolved, so it may safely be renamed.
  5895. if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as
  5896. // anchors need to be available during resolution to allow for
  5897. // circular references.
  5898. anchors.map[name] = node;
  5899. }
  5900. if (node.type === PlainValueEc8e588e.Type.ALIAS && (hasAnchor || hasTag)) {
  5901. const msg = 'An alias node must not specify any properties';
  5902. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(node, msg));
  5903. }
  5904. const res = resolveNodeValue(doc, node);
  5905. if (res) {
  5906. res.range = [node.range.start, node.range.end];
  5907. if (doc.options.keepCstNodes) res.cstNode = node;
  5908. if (doc.options.keepNodeTypes) res.type = node.type;
  5909. const cb = comments.before.join('\n');
  5910. if (cb) {
  5911. res.commentBefore = res.commentBefore ? `${res.commentBefore}\n${cb}` : cb;
  5912. }
  5913. const ca = comments.after.join('\n');
  5914. if (ca) res.comment = res.comment ? `${res.comment}\n${ca}` : ca;
  5915. }
  5916. return node.resolved = res;
  5917. }
  5918. function resolveMap(doc, cst) {
  5919. if (cst.type !== PlainValueEc8e588e.Type.MAP && cst.type !== PlainValueEc8e588e.Type.FLOW_MAP) {
  5920. const msg = `A ${cst.type} node cannot be resolved as a mapping`;
  5921. doc.errors.push(new PlainValueEc8e588e.YAMLSyntaxError(cst, msg));
  5922. return null;
  5923. }
  5924. const {
  5925. comments,
  5926. items
  5927. } = cst.type === PlainValueEc8e588e.Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst);
  5928. const map = new YAMLMap();
  5929. map.items = items;
  5930. resolveComments(map, comments);
  5931. let hasCollectionKey = false;
  5932. for (let i = 0; i < items.length; ++i) {
  5933. const {
  5934. key: iKey
  5935. } = items[i];
  5936. if (iKey instanceof Collection) hasCollectionKey = true;
  5937. if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) {
  5938. items[i] = new Merge(items[i]);
  5939. const sources = items[i].value.items;
  5940. let error = null;
  5941. sources.some(node => {
  5942. if (node instanceof Alias) {
  5943. // During parsing, alias sources are CST nodes; to account for
  5944. // circular references their resolved values can't be used here.
  5945. const {
  5946. type
  5947. } = node.source;
  5948. if (type === PlainValueEc8e588e.Type.MAP || type === PlainValueEc8e588e.Type.FLOW_MAP) return false;
  5949. return error = 'Merge nodes aliases can only point to maps';
  5950. }
  5951. return error = 'Merge nodes can only have Alias nodes as values';
  5952. });
  5953. if (error) doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(cst, error));
  5954. } else {
  5955. for (let j = i + 1; j < items.length; ++j) {
  5956. const {
  5957. key: jKey
  5958. } = items[j];
  5959. if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) {
  5960. const msg = `Map keys must be unique; "${iKey}" is repeated`;
  5961. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(cst, msg));
  5962. break;
  5963. }
  5964. }
  5965. }
  5966. }
  5967. if (hasCollectionKey && !doc.options.mapAsMap) {
  5968. const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
  5969. doc.warnings.push(new PlainValueEc8e588e.YAMLWarning(cst, warn));
  5970. }
  5971. cst.resolved = map;
  5972. return map;
  5973. }
  5974. const valueHasPairComment = ({
  5975. context: {
  5976. lineStart,
  5977. node,
  5978. src
  5979. },
  5980. props
  5981. }) => {
  5982. if (props.length === 0) return false;
  5983. const {
  5984. start
  5985. } = props[0];
  5986. if (node && start > node.valueRange.start) return false;
  5987. if (src[start] !== PlainValueEc8e588e.Char.COMMENT) return false;
  5988. for (let i = lineStart; i < start; ++i) if (src[i] === '\n') return false;
  5989. return true;
  5990. };
  5991. function resolvePairComment(item, pair) {
  5992. if (!valueHasPairComment(item)) return;
  5993. const comment = item.getPropValue(0, PlainValueEc8e588e.Char.COMMENT, true);
  5994. let found = false;
  5995. const cb = pair.value.commentBefore;
  5996. if (cb && cb.startsWith(comment)) {
  5997. pair.value.commentBefore = cb.substr(comment.length + 1);
  5998. found = true;
  5999. } else {
  6000. const cc = pair.value.comment;
  6001. if (!item.node && cc && cc.startsWith(comment)) {
  6002. pair.value.comment = cc.substr(comment.length + 1);
  6003. found = true;
  6004. }
  6005. }
  6006. if (found) pair.comment = comment;
  6007. }
  6008. function resolveBlockMapItems(doc, cst) {
  6009. const comments = [];
  6010. const items = [];
  6011. let key = undefined;
  6012. let keyStart = null;
  6013. for (let i = 0; i < cst.items.length; ++i) {
  6014. const item = cst.items[i];
  6015. switch (item.type) {
  6016. case PlainValueEc8e588e.Type.BLANK_LINE:
  6017. comments.push({
  6018. afterKey: !!key,
  6019. before: items.length
  6020. });
  6021. break;
  6022. case PlainValueEc8e588e.Type.COMMENT:
  6023. comments.push({
  6024. afterKey: !!key,
  6025. before: items.length,
  6026. comment: item.comment
  6027. });
  6028. break;
  6029. case PlainValueEc8e588e.Type.MAP_KEY:
  6030. if (key !== undefined) items.push(new Pair(key));
  6031. if (item.error) doc.errors.push(item.error);
  6032. key = resolveNode(doc, item.node);
  6033. keyStart = null;
  6034. break;
  6035. case PlainValueEc8e588e.Type.MAP_VALUE:
  6036. {
  6037. if (key === undefined) key = null;
  6038. if (item.error) doc.errors.push(item.error);
  6039. if (!item.context.atLineStart && item.node && item.node.type === PlainValueEc8e588e.Type.MAP && !item.node.context.atLineStart) {
  6040. const msg = 'Nested mappings are not allowed in compact mappings';
  6041. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item.node, msg));
  6042. }
  6043. let valueNode = item.node;
  6044. if (!valueNode && item.props.length > 0) {
  6045. // Comments on an empty mapping value need to be preserved, so we
  6046. // need to construct a minimal empty node here to use instead of the
  6047. // missing `item.node`. -- eemeli/yaml#19
  6048. valueNode = new PlainValueEc8e588e.PlainValue(PlainValueEc8e588e.Type.PLAIN, []);
  6049. valueNode.context = {
  6050. parent: item,
  6051. src: item.context.src
  6052. };
  6053. const pos = item.range.start + 1;
  6054. valueNode.range = {
  6055. start: pos,
  6056. end: pos
  6057. };
  6058. valueNode.valueRange = {
  6059. start: pos,
  6060. end: pos
  6061. };
  6062. if (typeof item.range.origStart === 'number') {
  6063. const origPos = item.range.origStart + 1;
  6064. valueNode.range.origStart = valueNode.range.origEnd = origPos;
  6065. valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos;
  6066. }
  6067. }
  6068. const pair = new Pair(key, resolveNode(doc, valueNode));
  6069. resolvePairComment(item, pair);
  6070. items.push(pair);
  6071. if (key && typeof keyStart === 'number') {
  6072. if (item.range.start > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
  6073. }
  6074. key = undefined;
  6075. keyStart = null;
  6076. }
  6077. break;
  6078. default:
  6079. if (key !== undefined) items.push(new Pair(key));
  6080. key = resolveNode(doc, item);
  6081. keyStart = item.range.start;
  6082. if (item.error) doc.errors.push(item.error);
  6083. next: for (let j = i + 1;; ++j) {
  6084. const nextItem = cst.items[j];
  6085. switch (nextItem && nextItem.type) {
  6086. case PlainValueEc8e588e.Type.BLANK_LINE:
  6087. case PlainValueEc8e588e.Type.COMMENT:
  6088. continue next;
  6089. case PlainValueEc8e588e.Type.MAP_VALUE:
  6090. break next;
  6091. default:
  6092. {
  6093. const msg = 'Implicit map keys need to be followed by map values';
  6094. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item, msg));
  6095. break next;
  6096. }
  6097. }
  6098. }
  6099. if (item.valueRangeContainsNewline) {
  6100. const msg = 'Implicit map keys need to be on a single line';
  6101. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item, msg));
  6102. }
  6103. }
  6104. }
  6105. if (key !== undefined) items.push(new Pair(key));
  6106. return {
  6107. comments,
  6108. items
  6109. };
  6110. }
  6111. function resolveFlowMapItems(doc, cst) {
  6112. const comments = [];
  6113. const items = [];
  6114. let key = undefined;
  6115. let explicitKey = false;
  6116. let next = '{';
  6117. for (let i = 0; i < cst.items.length; ++i) {
  6118. const item = cst.items[i];
  6119. if (typeof item.char === 'string') {
  6120. const {
  6121. char,
  6122. offset
  6123. } = item;
  6124. if (char === '?' && key === undefined && !explicitKey) {
  6125. explicitKey = true;
  6126. next = ':';
  6127. continue;
  6128. }
  6129. if (char === ':') {
  6130. if (key === undefined) key = null;
  6131. if (next === ':') {
  6132. next = ',';
  6133. continue;
  6134. }
  6135. } else {
  6136. if (explicitKey) {
  6137. if (key === undefined && char !== ',') key = null;
  6138. explicitKey = false;
  6139. }
  6140. if (key !== undefined) {
  6141. items.push(new Pair(key));
  6142. key = undefined;
  6143. if (char === ',') {
  6144. next = ':';
  6145. continue;
  6146. }
  6147. }
  6148. }
  6149. if (char === '}') {
  6150. if (i === cst.items.length - 1) continue;
  6151. } else if (char === next) {
  6152. next = ':';
  6153. continue;
  6154. }
  6155. const msg = `Flow map contains an unexpected ${char}`;
  6156. const err = new PlainValueEc8e588e.YAMLSyntaxError(cst, msg);
  6157. err.offset = offset;
  6158. doc.errors.push(err);
  6159. } else if (item.type === PlainValueEc8e588e.Type.BLANK_LINE) {
  6160. comments.push({
  6161. afterKey: !!key,
  6162. before: items.length
  6163. });
  6164. } else if (item.type === PlainValueEc8e588e.Type.COMMENT) {
  6165. checkFlowCommentSpace(doc.errors, item);
  6166. comments.push({
  6167. afterKey: !!key,
  6168. before: items.length,
  6169. comment: item.comment
  6170. });
  6171. } else if (key === undefined) {
  6172. if (next === ',') doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item, 'Separator , missing in flow map'));
  6173. key = resolveNode(doc, item);
  6174. } else {
  6175. if (next !== ',') doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
  6176. items.push(new Pair(key, resolveNode(doc, item)));
  6177. key = undefined;
  6178. explicitKey = false;
  6179. }
  6180. }
  6181. checkFlowCollectionEnd(doc.errors, cst);
  6182. if (key !== undefined) items.push(new Pair(key));
  6183. return {
  6184. comments,
  6185. items
  6186. };
  6187. }
  6188. function resolveSeq(doc, cst) {
  6189. if (cst.type !== PlainValueEc8e588e.Type.SEQ && cst.type !== PlainValueEc8e588e.Type.FLOW_SEQ) {
  6190. const msg = `A ${cst.type} node cannot be resolved as a sequence`;
  6191. doc.errors.push(new PlainValueEc8e588e.YAMLSyntaxError(cst, msg));
  6192. return null;
  6193. }
  6194. const {
  6195. comments,
  6196. items
  6197. } = cst.type === PlainValueEc8e588e.Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst);
  6198. const seq = new YAMLSeq();
  6199. seq.items = items;
  6200. resolveComments(seq, comments);
  6201. if (!doc.options.mapAsMap && items.some(it => it instanceof Pair && it.key instanceof Collection)) {
  6202. const warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
  6203. doc.warnings.push(new PlainValueEc8e588e.YAMLWarning(cst, warn));
  6204. }
  6205. cst.resolved = seq;
  6206. return seq;
  6207. }
  6208. function resolveBlockSeqItems(doc, cst) {
  6209. const comments = [];
  6210. const items = [];
  6211. for (let i = 0; i < cst.items.length; ++i) {
  6212. const item = cst.items[i];
  6213. switch (item.type) {
  6214. case PlainValueEc8e588e.Type.BLANK_LINE:
  6215. comments.push({
  6216. before: items.length
  6217. });
  6218. break;
  6219. case PlainValueEc8e588e.Type.COMMENT:
  6220. comments.push({
  6221. comment: item.comment,
  6222. before: items.length
  6223. });
  6224. break;
  6225. case PlainValueEc8e588e.Type.SEQ_ITEM:
  6226. if (item.error) doc.errors.push(item.error);
  6227. items.push(resolveNode(doc, item.node));
  6228. if (item.hasProps) {
  6229. const msg = 'Sequence items cannot have tags or anchors before the - indicator';
  6230. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item, msg));
  6231. }
  6232. break;
  6233. default:
  6234. if (item.error) doc.errors.push(item.error);
  6235. doc.errors.push(new PlainValueEc8e588e.YAMLSyntaxError(item, `Unexpected ${item.type} node in sequence`));
  6236. }
  6237. }
  6238. return {
  6239. comments,
  6240. items
  6241. };
  6242. }
  6243. function resolveFlowSeqItems(doc, cst) {
  6244. const comments = [];
  6245. const items = [];
  6246. let explicitKey = false;
  6247. let key = undefined;
  6248. let keyStart = null;
  6249. let next = '[';
  6250. let prevItem = null;
  6251. for (let i = 0; i < cst.items.length; ++i) {
  6252. const item = cst.items[i];
  6253. if (typeof item.char === 'string') {
  6254. const {
  6255. char,
  6256. offset
  6257. } = item;
  6258. if (char !== ':' && (explicitKey || key !== undefined)) {
  6259. if (explicitKey && key === undefined) key = next ? items.pop() : null;
  6260. items.push(new Pair(key));
  6261. explicitKey = false;
  6262. key = undefined;
  6263. keyStart = null;
  6264. }
  6265. if (char === next) {
  6266. next = null;
  6267. } else if (!next && char === '?') {
  6268. explicitKey = true;
  6269. } else if (next !== '[' && char === ':' && key === undefined) {
  6270. if (next === ',') {
  6271. key = items.pop();
  6272. if (key instanceof Pair) {
  6273. const msg = 'Chaining flow sequence pairs is invalid';
  6274. const err = new PlainValueEc8e588e.YAMLSemanticError(cst, msg);
  6275. err.offset = offset;
  6276. doc.errors.push(err);
  6277. }
  6278. if (!explicitKey && typeof keyStart === 'number') {
  6279. const keyEnd = item.range ? item.range.start : item.offset;
  6280. if (keyEnd > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
  6281. const {
  6282. src
  6283. } = prevItem.context;
  6284. for (let i = keyStart; i < keyEnd; ++i) if (src[i] === '\n') {
  6285. const msg = 'Implicit keys of flow sequence pairs need to be on a single line';
  6286. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(prevItem, msg));
  6287. break;
  6288. }
  6289. }
  6290. } else {
  6291. key = null;
  6292. }
  6293. keyStart = null;
  6294. explicitKey = false;
  6295. next = null;
  6296. } else if (next === '[' || char !== ']' || i < cst.items.length - 1) {
  6297. const msg = `Flow sequence contains an unexpected ${char}`;
  6298. const err = new PlainValueEc8e588e.YAMLSyntaxError(cst, msg);
  6299. err.offset = offset;
  6300. doc.errors.push(err);
  6301. }
  6302. } else if (item.type === PlainValueEc8e588e.Type.BLANK_LINE) {
  6303. comments.push({
  6304. before: items.length
  6305. });
  6306. } else if (item.type === PlainValueEc8e588e.Type.COMMENT) {
  6307. checkFlowCommentSpace(doc.errors, item);
  6308. comments.push({
  6309. comment: item.comment,
  6310. before: items.length
  6311. });
  6312. } else {
  6313. if (next) {
  6314. const msg = `Expected a ${next} in flow sequence`;
  6315. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(item, msg));
  6316. }
  6317. const value = resolveNode(doc, item);
  6318. if (key === undefined) {
  6319. items.push(value);
  6320. prevItem = item;
  6321. } else {
  6322. items.push(new Pair(key, value));
  6323. key = undefined;
  6324. }
  6325. keyStart = item.range.start;
  6326. next = ',';
  6327. }
  6328. }
  6329. checkFlowCollectionEnd(doc.errors, cst);
  6330. if (key !== undefined) items.push(new Pair(key));
  6331. return {
  6332. comments,
  6333. items
  6334. };
  6335. }
  6336. var Alias_1 = Alias;
  6337. var Collection_1 = Collection;
  6338. var Merge_1 = Merge;
  6339. var Node_1 = Node;
  6340. var Pair_1 = Pair;
  6341. var Scalar_1 = Scalar;
  6342. var YAMLMap_1 = YAMLMap;
  6343. var YAMLSeq_1 = YAMLSeq;
  6344. var addComment_1 = addComment;
  6345. var binaryOptions_1 = binaryOptions;
  6346. var boolOptions_1 = boolOptions;
  6347. var findPair_1 = findPair;
  6348. var intOptions_1 = intOptions;
  6349. var isEmptyPath_1 = isEmptyPath;
  6350. var nullOptions_1 = nullOptions;
  6351. var resolveMap_1 = resolveMap;
  6352. var resolveNode_1 = resolveNode;
  6353. var resolveSeq_1 = resolveSeq;
  6354. var resolveString_1 = resolveString;
  6355. var strOptions_1 = strOptions;
  6356. var stringifyNumber_1 = stringifyNumber;
  6357. var stringifyString_1 = stringifyString;
  6358. var toJSON_1 = toJSON;
  6359. var resolveSeqD03cb037 = {
  6360. Alias: Alias_1,
  6361. Collection: Collection_1,
  6362. Merge: Merge_1,
  6363. Node: Node_1,
  6364. Pair: Pair_1,
  6365. Scalar: Scalar_1,
  6366. YAMLMap: YAMLMap_1,
  6367. YAMLSeq: YAMLSeq_1,
  6368. addComment: addComment_1,
  6369. binaryOptions: binaryOptions_1,
  6370. boolOptions: boolOptions_1,
  6371. findPair: findPair_1,
  6372. intOptions: intOptions_1,
  6373. isEmptyPath: isEmptyPath_1,
  6374. nullOptions: nullOptions_1,
  6375. resolveMap: resolveMap_1,
  6376. resolveNode: resolveNode_1,
  6377. resolveSeq: resolveSeq_1,
  6378. resolveString: resolveString_1,
  6379. strOptions: strOptions_1,
  6380. stringifyNumber: stringifyNumber_1,
  6381. stringifyString: stringifyString_1,
  6382. toJSON: toJSON_1
  6383. };
  6384. var check = function (it) {
  6385. return it && it.Math == Math && it;
  6386. };
  6387. // https://github.com/zloirock/core-js/issues/86#issuecomment-115759028
  6388. var global =
  6389. // eslint-disable-next-line es/no-global-this -- safe
  6390. check(typeof globalThis == 'object' && globalThis) ||
  6391. check(typeof window == 'object' && window) ||
  6392. // eslint-disable-next-line no-restricted-globals -- safe
  6393. check(typeof self == 'object' && self) ||
  6394. check(typeof global == 'object' && global) ||
  6395. // eslint-disable-next-line no-new-func -- fallback
  6396. (function () { return this; })() || Function('return this')();
  6397. var fails = function (exec) {
  6398. try {
  6399. return !!exec();
  6400. } catch (error) {
  6401. return true;
  6402. }
  6403. };
  6404. // Detect IE8's incomplete defineProperty implementation
  6405. var descriptors = !fails(function () {
  6406. // eslint-disable-next-line es/no-object-defineproperty -- required for testing
  6407. return Object.defineProperty({}, 1, { get: function () { return 7; } })[1] != 7;
  6408. });
  6409. var $propertyIsEnumerable = {}.propertyIsEnumerable;
  6410. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  6411. var getOwnPropertyDescriptor$1 = Object.getOwnPropertyDescriptor;
  6412. // Nashorn ~ JDK8 bug
  6413. var NASHORN_BUG = getOwnPropertyDescriptor$1 && !$propertyIsEnumerable.call({ 1: 2 }, 1);
  6414. // `Object.prototype.propertyIsEnumerable` method implementation
  6415. // https://tc39.es/ecma262/#sec-object.prototype.propertyisenumerable
  6416. var f$4 = NASHORN_BUG ? function propertyIsEnumerable(V) {
  6417. var descriptor = getOwnPropertyDescriptor$1(this, V);
  6418. return !!descriptor && descriptor.enumerable;
  6419. } : $propertyIsEnumerable;
  6420. var objectPropertyIsEnumerable = {
  6421. f: f$4
  6422. };
  6423. var createPropertyDescriptor = function (bitmap, value) {
  6424. return {
  6425. enumerable: !(bitmap & 1),
  6426. configurable: !(bitmap & 2),
  6427. writable: !(bitmap & 4),
  6428. value: value
  6429. };
  6430. };
  6431. var toString$1 = {}.toString;
  6432. var classofRaw = function (it) {
  6433. return toString$1.call(it).slice(8, -1);
  6434. };
  6435. var split = ''.split;
  6436. // fallback for non-array-like ES3 and non-enumerable old V8 strings
  6437. var indexedObject = fails(function () {
  6438. // throws an error in rhino, see https://github.com/mozilla/rhino/issues/346
  6439. // eslint-disable-next-line no-prototype-builtins -- safe
  6440. return !Object('z').propertyIsEnumerable(0);
  6441. }) ? function (it) {
  6442. return classofRaw(it) == 'String' ? split.call(it, '') : Object(it);
  6443. } : Object;
  6444. // `RequireObjectCoercible` abstract operation
  6445. // https://tc39.es/ecma262/#sec-requireobjectcoercible
  6446. var requireObjectCoercible = function (it) {
  6447. if (it == undefined) throw TypeError("Can't call method on " + it);
  6448. return it;
  6449. };
  6450. // toObject with fallback for non-array-like ES3 strings
  6451. var toIndexedObject = function (it) {
  6452. return indexedObject(requireObjectCoercible(it));
  6453. };
  6454. var isObject = function (it) {
  6455. return typeof it === 'object' ? it !== null : typeof it === 'function';
  6456. };
  6457. var aFunction$1 = function (variable) {
  6458. return typeof variable == 'function' ? variable : undefined;
  6459. };
  6460. var getBuiltIn = function (namespace, method) {
  6461. return arguments.length < 2 ? aFunction$1(global[namespace]) : global[namespace] && global[namespace][method];
  6462. };
  6463. var engineUserAgent = getBuiltIn('navigator', 'userAgent') || '';
  6464. var process$1 = global.process;
  6465. var Deno = global.Deno;
  6466. var versions = process$1 && process$1.versions || Deno && Deno.version;
  6467. var v8 = versions && versions.v8;
  6468. var match, version;
  6469. if (v8) {
  6470. match = v8.split('.');
  6471. version = match[0] < 4 ? 1 : match[0] + match[1];
  6472. } else if (engineUserAgent) {
  6473. match = engineUserAgent.match(/Edge\/(\d+)/);
  6474. if (!match || match[1] >= 74) {
  6475. match = engineUserAgent.match(/Chrome\/(\d+)/);
  6476. if (match) version = match[1];
  6477. }
  6478. }
  6479. var engineV8Version = version && +version;
  6480. /* eslint-disable es/no-symbol -- required for testing */
  6481. // eslint-disable-next-line es/no-object-getownpropertysymbols -- required for testing
  6482. var nativeSymbol = !!Object.getOwnPropertySymbols && !fails(function () {
  6483. var symbol = Symbol();
  6484. // Chrome 38 Symbol has incorrect toString conversion
  6485. // `get-own-property-symbols` polyfill symbols converted to object are not Symbol instances
  6486. return !String(symbol) || !(Object(symbol) instanceof Symbol) ||
  6487. // Chrome 38-40 symbols are not inherited from DOM collections prototypes to instances
  6488. !Symbol.sham && engineV8Version && engineV8Version < 41;
  6489. });
  6490. /* eslint-disable es/no-symbol -- required for testing */
  6491. var useSymbolAsUid = nativeSymbol
  6492. && !Symbol.sham
  6493. && typeof Symbol.iterator == 'symbol';
  6494. var isSymbol = useSymbolAsUid ? function (it) {
  6495. return typeof it == 'symbol';
  6496. } : function (it) {
  6497. var $Symbol = getBuiltIn('Symbol');
  6498. return typeof $Symbol == 'function' && Object(it) instanceof $Symbol;
  6499. };
  6500. // `OrdinaryToPrimitive` abstract operation
  6501. // https://tc39.es/ecma262/#sec-ordinarytoprimitive
  6502. var ordinaryToPrimitive = function (input, pref) {
  6503. var fn, val;
  6504. if (pref === 'string' && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
  6505. if (typeof (fn = input.valueOf) == 'function' && !isObject(val = fn.call(input))) return val;
  6506. if (pref !== 'string' && typeof (fn = input.toString) == 'function' && !isObject(val = fn.call(input))) return val;
  6507. throw TypeError("Can't convert object to primitive value");
  6508. };
  6509. var setGlobal = function (key, value) {
  6510. try {
  6511. // eslint-disable-next-line es/no-object-defineproperty -- safe
  6512. Object.defineProperty(global, key, { value: value, configurable: true, writable: true });
  6513. } catch (error) {
  6514. global[key] = value;
  6515. } return value;
  6516. };
  6517. var SHARED = '__core-js_shared__';
  6518. var store$1 = global[SHARED] || setGlobal(SHARED, {});
  6519. var sharedStore = store$1;
  6520. var shared = createCommonjsModule(function (module) {
  6521. (module.exports = function (key, value) {
  6522. return sharedStore[key] || (sharedStore[key] = value !== undefined ? value : {});
  6523. })('versions', []).push({
  6524. version: '3.17.3',
  6525. mode: 'global',
  6526. copyright: '© 2021 Denis Pushkarev (zloirock.ru)'
  6527. });
  6528. });
  6529. // `ToObject` abstract operation
  6530. // https://tc39.es/ecma262/#sec-toobject
  6531. var toObject = function (argument) {
  6532. return Object(requireObjectCoercible(argument));
  6533. };
  6534. var hasOwnProperty = {}.hasOwnProperty;
  6535. var has$1 = Object.hasOwn || function hasOwn(it, key) {
  6536. return hasOwnProperty.call(toObject(it), key);
  6537. };
  6538. var id = 0;
  6539. var postfix = Math.random();
  6540. var uid = function (key) {
  6541. return 'Symbol(' + String(key === undefined ? '' : key) + ')_' + (++id + postfix).toString(36);
  6542. };
  6543. var WellKnownSymbolsStore = shared('wks');
  6544. var Symbol$1 = global.Symbol;
  6545. var createWellKnownSymbol = useSymbolAsUid ? Symbol$1 : Symbol$1 && Symbol$1.withoutSetter || uid;
  6546. var wellKnownSymbol = function (name) {
  6547. if (!has$1(WellKnownSymbolsStore, name) || !(nativeSymbol || typeof WellKnownSymbolsStore[name] == 'string')) {
  6548. if (nativeSymbol && has$1(Symbol$1, name)) {
  6549. WellKnownSymbolsStore[name] = Symbol$1[name];
  6550. } else {
  6551. WellKnownSymbolsStore[name] = createWellKnownSymbol('Symbol.' + name);
  6552. }
  6553. } return WellKnownSymbolsStore[name];
  6554. };
  6555. var TO_PRIMITIVE = wellKnownSymbol('toPrimitive');
  6556. // `ToPrimitive` abstract operation
  6557. // https://tc39.es/ecma262/#sec-toprimitive
  6558. var toPrimitive = function (input, pref) {
  6559. if (!isObject(input) || isSymbol(input)) return input;
  6560. var exoticToPrim = input[TO_PRIMITIVE];
  6561. var result;
  6562. if (exoticToPrim !== undefined) {
  6563. if (pref === undefined) pref = 'default';
  6564. result = exoticToPrim.call(input, pref);
  6565. if (!isObject(result) || isSymbol(result)) return result;
  6566. throw TypeError("Can't convert object to primitive value");
  6567. }
  6568. if (pref === undefined) pref = 'number';
  6569. return ordinaryToPrimitive(input, pref);
  6570. };
  6571. // `ToPropertyKey` abstract operation
  6572. // https://tc39.es/ecma262/#sec-topropertykey
  6573. var toPropertyKey = function (argument) {
  6574. var key = toPrimitive(argument, 'string');
  6575. return isSymbol(key) ? key : String(key);
  6576. };
  6577. var document = global.document;
  6578. // typeof document.createElement is 'object' in old IE
  6579. var EXISTS = isObject(document) && isObject(document.createElement);
  6580. var documentCreateElement = function (it) {
  6581. return EXISTS ? document.createElement(it) : {};
  6582. };
  6583. // Thank's IE8 for his funny defineProperty
  6584. var ie8DomDefine = !descriptors && !fails(function () {
  6585. // eslint-disable-next-line es/no-object-defineproperty -- requied for testing
  6586. return Object.defineProperty(documentCreateElement('div'), 'a', {
  6587. get: function () { return 7; }
  6588. }).a != 7;
  6589. });
  6590. // eslint-disable-next-line es/no-object-getownpropertydescriptor -- safe
  6591. var $getOwnPropertyDescriptor = Object.getOwnPropertyDescriptor;
  6592. // `Object.getOwnPropertyDescriptor` method
  6593. // https://tc39.es/ecma262/#sec-object.getownpropertydescriptor
  6594. var f$3 = descriptors ? $getOwnPropertyDescriptor : function getOwnPropertyDescriptor(O, P) {
  6595. O = toIndexedObject(O);
  6596. P = toPropertyKey(P);
  6597. if (ie8DomDefine) try {
  6598. return $getOwnPropertyDescriptor(O, P);
  6599. } catch (error) { /* empty */ }
  6600. if (has$1(O, P)) return createPropertyDescriptor(!objectPropertyIsEnumerable.f.call(O, P), O[P]);
  6601. };
  6602. var objectGetOwnPropertyDescriptor = {
  6603. f: f$3
  6604. };
  6605. var anObject = function (it) {
  6606. if (!isObject(it)) {
  6607. throw TypeError(String(it) + ' is not an object');
  6608. } return it;
  6609. };
  6610. // eslint-disable-next-line es/no-object-defineproperty -- safe
  6611. var $defineProperty = Object.defineProperty;
  6612. // `Object.defineProperty` method
  6613. // https://tc39.es/ecma262/#sec-object.defineproperty
  6614. var f$2 = descriptors ? $defineProperty : function defineProperty(O, P, Attributes) {
  6615. anObject(O);
  6616. P = toPropertyKey(P);
  6617. anObject(Attributes);
  6618. if (ie8DomDefine) try {
  6619. return $defineProperty(O, P, Attributes);
  6620. } catch (error) { /* empty */ }
  6621. if ('get' in Attributes || 'set' in Attributes) throw TypeError('Accessors not supported');
  6622. if ('value' in Attributes) O[P] = Attributes.value;
  6623. return O;
  6624. };
  6625. var objectDefineProperty = {
  6626. f: f$2
  6627. };
  6628. var createNonEnumerableProperty = descriptors ? function (object, key, value) {
  6629. return objectDefineProperty.f(object, key, createPropertyDescriptor(1, value));
  6630. } : function (object, key, value) {
  6631. object[key] = value;
  6632. return object;
  6633. };
  6634. var functionToString = Function.toString;
  6635. // this helper broken in `core-js@3.4.1-3.4.4`, so we can't use `shared` helper
  6636. if (typeof sharedStore.inspectSource != 'function') {
  6637. sharedStore.inspectSource = function (it) {
  6638. return functionToString.call(it);
  6639. };
  6640. }
  6641. var inspectSource = sharedStore.inspectSource;
  6642. var WeakMap$1 = global.WeakMap;
  6643. var nativeWeakMap = typeof WeakMap$1 === 'function' && /native code/.test(inspectSource(WeakMap$1));
  6644. var keys = shared('keys');
  6645. var sharedKey = function (key) {
  6646. return keys[key] || (keys[key] = uid(key));
  6647. };
  6648. var hiddenKeys$1 = {};
  6649. var OBJECT_ALREADY_INITIALIZED = 'Object already initialized';
  6650. var WeakMap = global.WeakMap;
  6651. var set$1, get, has;
  6652. var enforce = function (it) {
  6653. return has(it) ? get(it) : set$1(it, {});
  6654. };
  6655. var getterFor = function (TYPE) {
  6656. return function (it) {
  6657. var state;
  6658. if (!isObject(it) || (state = get(it)).type !== TYPE) {
  6659. throw TypeError('Incompatible receiver, ' + TYPE + ' required');
  6660. } return state;
  6661. };
  6662. };
  6663. if (nativeWeakMap || sharedStore.state) {
  6664. var store = sharedStore.state || (sharedStore.state = new WeakMap());
  6665. var wmget = store.get;
  6666. var wmhas = store.has;
  6667. var wmset = store.set;
  6668. set$1 = function (it, metadata) {
  6669. if (wmhas.call(store, it)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
  6670. metadata.facade = it;
  6671. wmset.call(store, it, metadata);
  6672. return metadata;
  6673. };
  6674. get = function (it) {
  6675. return wmget.call(store, it) || {};
  6676. };
  6677. has = function (it) {
  6678. return wmhas.call(store, it);
  6679. };
  6680. } else {
  6681. var STATE = sharedKey('state');
  6682. hiddenKeys$1[STATE] = true;
  6683. set$1 = function (it, metadata) {
  6684. if (has$1(it, STATE)) throw new TypeError(OBJECT_ALREADY_INITIALIZED);
  6685. metadata.facade = it;
  6686. createNonEnumerableProperty(it, STATE, metadata);
  6687. return metadata;
  6688. };
  6689. get = function (it) {
  6690. return has$1(it, STATE) ? it[STATE] : {};
  6691. };
  6692. has = function (it) {
  6693. return has$1(it, STATE);
  6694. };
  6695. }
  6696. var internalState = {
  6697. set: set$1,
  6698. get: get,
  6699. has: has,
  6700. enforce: enforce,
  6701. getterFor: getterFor
  6702. };
  6703. var redefine = createCommonjsModule(function (module) {
  6704. var getInternalState = internalState.get;
  6705. var enforceInternalState = internalState.enforce;
  6706. var TEMPLATE = String(String).split('String');
  6707. (module.exports = function (O, key, value, options) {
  6708. var unsafe = options ? !!options.unsafe : false;
  6709. var simple = options ? !!options.enumerable : false;
  6710. var noTargetGet = options ? !!options.noTargetGet : false;
  6711. var state;
  6712. if (typeof value == 'function') {
  6713. if (typeof key == 'string' && !has$1(value, 'name')) {
  6714. createNonEnumerableProperty(value, 'name', key);
  6715. }
  6716. state = enforceInternalState(value);
  6717. if (!state.source) {
  6718. state.source = TEMPLATE.join(typeof key == 'string' ? key : '');
  6719. }
  6720. }
  6721. if (O === global) {
  6722. if (simple) O[key] = value;
  6723. else setGlobal(key, value);
  6724. return;
  6725. } else if (!unsafe) {
  6726. delete O[key];
  6727. } else if (!noTargetGet && O[key]) {
  6728. simple = true;
  6729. }
  6730. if (simple) O[key] = value;
  6731. else createNonEnumerableProperty(O, key, value);
  6732. // add fake Function#toString for correct work wrapped methods / constructors with methods like LoDash isNative
  6733. })(Function.prototype, 'toString', function toString() {
  6734. return typeof this == 'function' && getInternalState(this).source || inspectSource(this);
  6735. });
  6736. });
  6737. var ceil = Math.ceil;
  6738. var floor$1 = Math.floor;
  6739. // `ToInteger` abstract operation
  6740. // https://tc39.es/ecma262/#sec-tointeger
  6741. var toInteger = function (argument) {
  6742. return isNaN(argument = +argument) ? 0 : (argument > 0 ? floor$1 : ceil)(argument);
  6743. };
  6744. var min$1 = Math.min;
  6745. // `ToLength` abstract operation
  6746. // https://tc39.es/ecma262/#sec-tolength
  6747. var toLength = function (argument) {
  6748. return argument > 0 ? min$1(toInteger(argument), 0x1FFFFFFFFFFFFF) : 0; // 2 ** 53 - 1 == 9007199254740991
  6749. };
  6750. var max = Math.max;
  6751. var min = Math.min;
  6752. // Helper for a popular repeating case of the spec:
  6753. // Let integer be ? ToInteger(index).
  6754. // If integer < 0, let result be max((length + integer), 0); else let result be min(integer, length).
  6755. var toAbsoluteIndex = function (index, length) {
  6756. var integer = toInteger(index);
  6757. return integer < 0 ? max(integer + length, 0) : min(integer, length);
  6758. };
  6759. // `Array.prototype.{ indexOf, includes }` methods implementation
  6760. var createMethod = function (IS_INCLUDES) {
  6761. return function ($this, el, fromIndex) {
  6762. var O = toIndexedObject($this);
  6763. var length = toLength(O.length);
  6764. var index = toAbsoluteIndex(fromIndex, length);
  6765. var value;
  6766. // Array#includes uses SameValueZero equality algorithm
  6767. // eslint-disable-next-line no-self-compare -- NaN check
  6768. if (IS_INCLUDES && el != el) while (length > index) {
  6769. value = O[index++];
  6770. // eslint-disable-next-line no-self-compare -- NaN check
  6771. if (value != value) return true;
  6772. // Array#indexOf ignores holes, Array#includes - not
  6773. } else for (;length > index; index++) {
  6774. if ((IS_INCLUDES || index in O) && O[index] === el) return IS_INCLUDES || index || 0;
  6775. } return !IS_INCLUDES && -1;
  6776. };
  6777. };
  6778. var arrayIncludes = {
  6779. // `Array.prototype.includes` method
  6780. // https://tc39.es/ecma262/#sec-array.prototype.includes
  6781. includes: createMethod(true),
  6782. // `Array.prototype.indexOf` method
  6783. // https://tc39.es/ecma262/#sec-array.prototype.indexof
  6784. indexOf: createMethod(false)
  6785. };
  6786. var indexOf = arrayIncludes.indexOf;
  6787. var objectKeysInternal = function (object, names) {
  6788. var O = toIndexedObject(object);
  6789. var i = 0;
  6790. var result = [];
  6791. var key;
  6792. for (key in O) !has$1(hiddenKeys$1, key) && has$1(O, key) && result.push(key);
  6793. // Don't enum bug & hidden keys
  6794. while (names.length > i) if (has$1(O, key = names[i++])) {
  6795. ~indexOf(result, key) || result.push(key);
  6796. }
  6797. return result;
  6798. };
  6799. // IE8- don't enum bug keys
  6800. var enumBugKeys = [
  6801. 'constructor',
  6802. 'hasOwnProperty',
  6803. 'isPrototypeOf',
  6804. 'propertyIsEnumerable',
  6805. 'toLocaleString',
  6806. 'toString',
  6807. 'valueOf'
  6808. ];
  6809. var hiddenKeys = enumBugKeys.concat('length', 'prototype');
  6810. // `Object.getOwnPropertyNames` method
  6811. // https://tc39.es/ecma262/#sec-object.getownpropertynames
  6812. // eslint-disable-next-line es/no-object-getownpropertynames -- safe
  6813. var f$1 = Object.getOwnPropertyNames || function getOwnPropertyNames(O) {
  6814. return objectKeysInternal(O, hiddenKeys);
  6815. };
  6816. var objectGetOwnPropertyNames = {
  6817. f: f$1
  6818. };
  6819. // eslint-disable-next-line es/no-object-getownpropertysymbols -- safe
  6820. var f = Object.getOwnPropertySymbols;
  6821. var objectGetOwnPropertySymbols = {
  6822. f: f
  6823. };
  6824. // all object keys, includes non-enumerable and symbols
  6825. var ownKeys = getBuiltIn('Reflect', 'ownKeys') || function ownKeys(it) {
  6826. var keys = objectGetOwnPropertyNames.f(anObject(it));
  6827. var getOwnPropertySymbols = objectGetOwnPropertySymbols.f;
  6828. return getOwnPropertySymbols ? keys.concat(getOwnPropertySymbols(it)) : keys;
  6829. };
  6830. var copyConstructorProperties = function (target, source) {
  6831. var keys = ownKeys(source);
  6832. var defineProperty = objectDefineProperty.f;
  6833. var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
  6834. for (var i = 0; i < keys.length; i++) {
  6835. var key = keys[i];
  6836. if (!has$1(target, key)) defineProperty(target, key, getOwnPropertyDescriptor(source, key));
  6837. }
  6838. };
  6839. var replacement = /#|\.prototype\./;
  6840. var isForced = function (feature, detection) {
  6841. var value = data[normalize(feature)];
  6842. return value == POLYFILL ? true
  6843. : value == NATIVE ? false
  6844. : typeof detection == 'function' ? fails(detection)
  6845. : !!detection;
  6846. };
  6847. var normalize = isForced.normalize = function (string) {
  6848. return String(string).replace(replacement, '.').toLowerCase();
  6849. };
  6850. var data = isForced.data = {};
  6851. var NATIVE = isForced.NATIVE = 'N';
  6852. var POLYFILL = isForced.POLYFILL = 'P';
  6853. var isForced_1 = isForced;
  6854. var getOwnPropertyDescriptor = objectGetOwnPropertyDescriptor.f;
  6855. /*
  6856. options.target - name of the target object
  6857. options.global - target is the global object
  6858. options.stat - export as static methods of target
  6859. options.proto - export as prototype methods of target
  6860. options.real - real prototype method for the `pure` version
  6861. options.forced - export even if the native feature is available
  6862. options.bind - bind methods to the target, required for the `pure` version
  6863. options.wrap - wrap constructors to preventing global pollution, required for the `pure` version
  6864. options.unsafe - use the simple assignment of property instead of delete + defineProperty
  6865. options.sham - add a flag to not completely full polyfills
  6866. options.enumerable - export as enumerable property
  6867. options.noTargetGet - prevent calling a getter on target
  6868. */
  6869. var _export = function (options, source) {
  6870. var TARGET = options.target;
  6871. var GLOBAL = options.global;
  6872. var STATIC = options.stat;
  6873. var FORCED, target, key, targetProperty, sourceProperty, descriptor;
  6874. if (GLOBAL) {
  6875. target = global;
  6876. } else if (STATIC) {
  6877. target = global[TARGET] || setGlobal(TARGET, {});
  6878. } else {
  6879. target = (global[TARGET] || {}).prototype;
  6880. }
  6881. if (target) for (key in source) {
  6882. sourceProperty = source[key];
  6883. if (options.noTargetGet) {
  6884. descriptor = getOwnPropertyDescriptor(target, key);
  6885. targetProperty = descriptor && descriptor.value;
  6886. } else targetProperty = target[key];
  6887. FORCED = isForced_1(GLOBAL ? key : TARGET + (STATIC ? '.' : '#') + key, options.forced);
  6888. // contained in target
  6889. if (!FORCED && targetProperty !== undefined) {
  6890. if (typeof sourceProperty === typeof targetProperty) continue;
  6891. copyConstructorProperties(sourceProperty, targetProperty);
  6892. }
  6893. // add a flag to not completely full polyfills
  6894. if (options.sham || (targetProperty && targetProperty.sham)) {
  6895. createNonEnumerableProperty(sourceProperty, 'sham', true);
  6896. }
  6897. // extend global
  6898. redefine(target, key, sourceProperty, options);
  6899. }
  6900. };
  6901. var aFunction = function (it) {
  6902. if (typeof it != 'function') {
  6903. throw TypeError(String(it) + ' is not a function');
  6904. } return it;
  6905. };
  6906. var toString = function (argument) {
  6907. if (isSymbol(argument)) throw TypeError('Cannot convert a Symbol value to a string');
  6908. return String(argument);
  6909. };
  6910. // TODO: use something more complex like timsort?
  6911. var floor = Math.floor;
  6912. var mergeSort = function (array, comparefn) {
  6913. var length = array.length;
  6914. var middle = floor(length / 2);
  6915. return length < 8 ? insertionSort(array, comparefn) : merge(
  6916. mergeSort(array.slice(0, middle), comparefn),
  6917. mergeSort(array.slice(middle), comparefn),
  6918. comparefn
  6919. );
  6920. };
  6921. var insertionSort = function (array, comparefn) {
  6922. var length = array.length;
  6923. var i = 1;
  6924. var element, j;
  6925. while (i < length) {
  6926. j = i;
  6927. element = array[i];
  6928. while (j && comparefn(array[j - 1], element) > 0) {
  6929. array[j] = array[--j];
  6930. }
  6931. if (j !== i++) array[j] = element;
  6932. } return array;
  6933. };
  6934. var merge = function (left, right, comparefn) {
  6935. var llength = left.length;
  6936. var rlength = right.length;
  6937. var lindex = 0;
  6938. var rindex = 0;
  6939. var result = [];
  6940. while (lindex < llength || rindex < rlength) {
  6941. if (lindex < llength && rindex < rlength) {
  6942. result.push(comparefn(left[lindex], right[rindex]) <= 0 ? left[lindex++] : right[rindex++]);
  6943. } else {
  6944. result.push(lindex < llength ? left[lindex++] : right[rindex++]);
  6945. }
  6946. } return result;
  6947. };
  6948. var arraySort = mergeSort;
  6949. var arrayMethodIsStrict = function (METHOD_NAME, argument) {
  6950. var method = [][METHOD_NAME];
  6951. return !!method && fails(function () {
  6952. // eslint-disable-next-line no-useless-call,no-throw-literal -- required for testing
  6953. method.call(null, argument || function () { throw 1; }, 1);
  6954. });
  6955. };
  6956. var firefox = engineUserAgent.match(/firefox\/(\d+)/i);
  6957. var engineFfVersion = !!firefox && +firefox[1];
  6958. var engineIsIeOrEdge = /MSIE|Trident/.test(engineUserAgent);
  6959. var webkit = engineUserAgent.match(/AppleWebKit\/(\d+)\./);
  6960. var engineWebkitVersion = !!webkit && +webkit[1];
  6961. var test = [];
  6962. var nativeSort = test.sort;
  6963. // IE8-
  6964. var FAILS_ON_UNDEFINED = fails(function () {
  6965. test.sort(undefined);
  6966. });
  6967. // V8 bug
  6968. var FAILS_ON_NULL = fails(function () {
  6969. test.sort(null);
  6970. });
  6971. // Old WebKit
  6972. var STRICT_METHOD = arrayMethodIsStrict('sort');
  6973. var STABLE_SORT = !fails(function () {
  6974. // feature detection can be too slow, so check engines versions
  6975. if (engineV8Version) return engineV8Version < 70;
  6976. if (engineFfVersion && engineFfVersion > 3) return;
  6977. if (engineIsIeOrEdge) return true;
  6978. if (engineWebkitVersion) return engineWebkitVersion < 603;
  6979. var result = '';
  6980. var code, chr, value, index;
  6981. // generate an array with more 512 elements (Chakra and old V8 fails only in this case)
  6982. for (code = 65; code < 76; code++) {
  6983. chr = String.fromCharCode(code);
  6984. switch (code) {
  6985. case 66: case 69: case 70: case 72: value = 3; break;
  6986. case 68: case 71: value = 4; break;
  6987. default: value = 2;
  6988. }
  6989. for (index = 0; index < 47; index++) {
  6990. test.push({ k: chr + index, v: value });
  6991. }
  6992. }
  6993. test.sort(function (a, b) { return b.v - a.v; });
  6994. for (index = 0; index < test.length; index++) {
  6995. chr = test[index].k.charAt(0);
  6996. if (result.charAt(result.length - 1) !== chr) result += chr;
  6997. }
  6998. return result !== 'DGBEFHACIJK';
  6999. });
  7000. var FORCED = FAILS_ON_UNDEFINED || !FAILS_ON_NULL || !STRICT_METHOD || !STABLE_SORT;
  7001. var getSortCompare = function (comparefn) {
  7002. return function (x, y) {
  7003. if (y === undefined) return -1;
  7004. if (x === undefined) return 1;
  7005. if (comparefn !== undefined) return +comparefn(x, y) || 0;
  7006. return toString(x) > toString(y) ? 1 : -1;
  7007. };
  7008. };
  7009. // `Array.prototype.sort` method
  7010. // https://tc39.es/ecma262/#sec-array.prototype.sort
  7011. _export({ target: 'Array', proto: true, forced: FORCED }, {
  7012. sort: function sort(comparefn) {
  7013. if (comparefn !== undefined) aFunction(comparefn);
  7014. var array = toObject(this);
  7015. if (STABLE_SORT) return comparefn === undefined ? nativeSort.call(array) : nativeSort.call(array, comparefn);
  7016. var items = [];
  7017. var arrayLength = toLength(array.length);
  7018. var itemsLength, index;
  7019. for (index = 0; index < arrayLength; index++) {
  7020. if (index in array) items.push(array[index]);
  7021. }
  7022. items = arraySort(items, getSortCompare(comparefn));
  7023. itemsLength = items.length;
  7024. index = 0;
  7025. while (index < itemsLength) array[index] = items[index++];
  7026. while (index < arrayLength) delete array[index++];
  7027. return array;
  7028. }
  7029. });
  7030. /* global atob, btoa, Buffer */
  7031. const binary = {
  7032. identify: value => value instanceof Uint8Array,
  7033. // Buffer inherits from Uint8Array
  7034. default: false,
  7035. tag: 'tag:yaml.org,2002:binary',
  7036. /**
  7037. * Returns a Buffer in node and an Uint8Array in browsers
  7038. *
  7039. * To use the resulting buffer as an image, you'll want to do something like:
  7040. *
  7041. * const blob = new Blob([buffer], { type: 'image/jpeg' })
  7042. * document.querySelector('#photo').src = URL.createObjectURL(blob)
  7043. */
  7044. resolve: (doc, node) => {
  7045. const src = resolveSeqD03cb037.resolveString(doc, node);
  7046. if (typeof Buffer === 'function') {
  7047. return Buffer.from(src, 'base64');
  7048. } else if (typeof atob === 'function') {
  7049. // On IE 11, atob() can't handle newlines
  7050. const str = atob(src.replace(/[\n\r]/g, ''));
  7051. const buffer = new Uint8Array(str.length);
  7052. for (let i = 0; i < str.length; ++i) buffer[i] = str.charCodeAt(i);
  7053. return buffer;
  7054. } else {
  7055. const msg = 'This environment does not support reading binary tags; either Buffer or atob is required';
  7056. doc.errors.push(new PlainValueEc8e588e.YAMLReferenceError(node, msg));
  7057. return null;
  7058. }
  7059. },
  7060. options: resolveSeqD03cb037.binaryOptions,
  7061. stringify: ({
  7062. comment,
  7063. type,
  7064. value
  7065. }, ctx, onComment, onChompKeep) => {
  7066. let src;
  7067. if (typeof Buffer === 'function') {
  7068. src = value instanceof Buffer ? value.toString('base64') : Buffer.from(value.buffer).toString('base64');
  7069. } else if (typeof btoa === 'function') {
  7070. let s = '';
  7071. for (let i = 0; i < value.length; ++i) s += String.fromCharCode(value[i]);
  7072. src = btoa(s);
  7073. } else {
  7074. throw new Error('This environment does not support writing binary tags; either Buffer or btoa is required');
  7075. }
  7076. if (!type) type = resolveSeqD03cb037.binaryOptions.defaultType;
  7077. if (type === PlainValueEc8e588e.Type.QUOTE_DOUBLE) {
  7078. value = src;
  7079. } else {
  7080. const {
  7081. lineWidth
  7082. } = resolveSeqD03cb037.binaryOptions;
  7083. const n = Math.ceil(src.length / lineWidth);
  7084. const lines = new Array(n);
  7085. for (let i = 0, o = 0; i < n; ++i, o += lineWidth) {
  7086. lines[i] = src.substr(o, lineWidth);
  7087. }
  7088. value = lines.join(type === PlainValueEc8e588e.Type.BLOCK_LITERAL ? '\n' : ' ');
  7089. }
  7090. return resolveSeqD03cb037.stringifyString({
  7091. comment,
  7092. type,
  7093. value
  7094. }, ctx, onComment, onChompKeep);
  7095. }
  7096. };
  7097. function parsePairs(doc, cst) {
  7098. const seq = resolveSeqD03cb037.resolveSeq(doc, cst);
  7099. for (let i = 0; i < seq.items.length; ++i) {
  7100. let item = seq.items[i];
  7101. if (item instanceof resolveSeqD03cb037.Pair) continue;else if (item instanceof resolveSeqD03cb037.YAMLMap) {
  7102. if (item.items.length > 1) {
  7103. const msg = 'Each pair must have its own sequence indicator';
  7104. throw new PlainValueEc8e588e.YAMLSemanticError(cst, msg);
  7105. }
  7106. const pair = item.items[0] || new resolveSeqD03cb037.Pair();
  7107. if (item.commentBefore) pair.commentBefore = pair.commentBefore ? `${item.commentBefore}\n${pair.commentBefore}` : item.commentBefore;
  7108. if (item.comment) pair.comment = pair.comment ? `${item.comment}\n${pair.comment}` : item.comment;
  7109. item = pair;
  7110. }
  7111. seq.items[i] = item instanceof resolveSeqD03cb037.Pair ? item : new resolveSeqD03cb037.Pair(item);
  7112. }
  7113. return seq;
  7114. }
  7115. function createPairs(schema, iterable, ctx) {
  7116. const pairs = new resolveSeqD03cb037.YAMLSeq(schema);
  7117. pairs.tag = 'tag:yaml.org,2002:pairs';
  7118. for (const it of iterable) {
  7119. let key, value;
  7120. if (Array.isArray(it)) {
  7121. if (it.length === 2) {
  7122. key = it[0];
  7123. value = it[1];
  7124. } else throw new TypeError(`Expected [key, value] tuple: ${it}`);
  7125. } else if (it && it instanceof Object) {
  7126. const keys = Object.keys(it);
  7127. if (keys.length === 1) {
  7128. key = keys[0];
  7129. value = it[key];
  7130. } else throw new TypeError(`Expected { key: value } tuple: ${it}`);
  7131. } else {
  7132. key = it;
  7133. }
  7134. const pair = schema.createPair(key, value, ctx);
  7135. pairs.items.push(pair);
  7136. }
  7137. return pairs;
  7138. }
  7139. const pairs = {
  7140. default: false,
  7141. tag: 'tag:yaml.org,2002:pairs',
  7142. resolve: parsePairs,
  7143. createNode: createPairs
  7144. };
  7145. class YAMLOMap extends resolveSeqD03cb037.YAMLSeq {
  7146. constructor() {
  7147. super();
  7148. PlainValueEc8e588e._defineProperty(this, "add", resolveSeqD03cb037.YAMLMap.prototype.add.bind(this));
  7149. PlainValueEc8e588e._defineProperty(this, "delete", resolveSeqD03cb037.YAMLMap.prototype.delete.bind(this));
  7150. PlainValueEc8e588e._defineProperty(this, "get", resolveSeqD03cb037.YAMLMap.prototype.get.bind(this));
  7151. PlainValueEc8e588e._defineProperty(this, "has", resolveSeqD03cb037.YAMLMap.prototype.has.bind(this));
  7152. PlainValueEc8e588e._defineProperty(this, "set", resolveSeqD03cb037.YAMLMap.prototype.set.bind(this));
  7153. this.tag = YAMLOMap.tag;
  7154. }
  7155. toJSON(_, ctx) {
  7156. const map = new Map();
  7157. if (ctx && ctx.onCreate) ctx.onCreate(map);
  7158. for (const pair of this.items) {
  7159. let key, value;
  7160. if (pair instanceof resolveSeqD03cb037.Pair) {
  7161. key = resolveSeqD03cb037.toJSON(pair.key, '', ctx);
  7162. value = resolveSeqD03cb037.toJSON(pair.value, key, ctx);
  7163. } else {
  7164. key = resolveSeqD03cb037.toJSON(pair, '', ctx);
  7165. }
  7166. if (map.has(key)) throw new Error('Ordered maps must not include duplicate keys');
  7167. map.set(key, value);
  7168. }
  7169. return map;
  7170. }
  7171. }
  7172. PlainValueEc8e588e._defineProperty(YAMLOMap, "tag", 'tag:yaml.org,2002:omap');
  7173. function parseOMap(doc, cst) {
  7174. const pairs = parsePairs(doc, cst);
  7175. const seenKeys = [];
  7176. for (const {
  7177. key
  7178. } of pairs.items) {
  7179. if (key instanceof resolveSeqD03cb037.Scalar) {
  7180. if (seenKeys.includes(key.value)) {
  7181. const msg = 'Ordered maps must not include duplicate keys';
  7182. throw new PlainValueEc8e588e.YAMLSemanticError(cst, msg);
  7183. } else {
  7184. seenKeys.push(key.value);
  7185. }
  7186. }
  7187. }
  7188. return Object.assign(new YAMLOMap(), pairs);
  7189. }
  7190. function createOMap(schema, iterable, ctx) {
  7191. const pairs = createPairs(schema, iterable, ctx);
  7192. const omap = new YAMLOMap();
  7193. omap.items = pairs.items;
  7194. return omap;
  7195. }
  7196. const omap = {
  7197. identify: value => value instanceof Map,
  7198. nodeClass: YAMLOMap,
  7199. default: false,
  7200. tag: 'tag:yaml.org,2002:omap',
  7201. resolve: parseOMap,
  7202. createNode: createOMap
  7203. };
  7204. class YAMLSet extends resolveSeqD03cb037.YAMLMap {
  7205. constructor() {
  7206. super();
  7207. this.tag = YAMLSet.tag;
  7208. }
  7209. add(key) {
  7210. const pair = key instanceof resolveSeqD03cb037.Pair ? key : new resolveSeqD03cb037.Pair(key);
  7211. const prev = resolveSeqD03cb037.findPair(this.items, pair.key);
  7212. if (!prev) this.items.push(pair);
  7213. }
  7214. get(key, keepPair) {
  7215. const pair = resolveSeqD03cb037.findPair(this.items, key);
  7216. return !keepPair && pair instanceof resolveSeqD03cb037.Pair ? pair.key instanceof resolveSeqD03cb037.Scalar ? pair.key.value : pair.key : pair;
  7217. }
  7218. set(key, value) {
  7219. if (typeof value !== 'boolean') throw new Error(`Expected boolean value for set(key, value) in a YAML set, not ${typeof value}`);
  7220. const prev = resolveSeqD03cb037.findPair(this.items, key);
  7221. if (prev && !value) {
  7222. this.items.splice(this.items.indexOf(prev), 1);
  7223. } else if (!prev && value) {
  7224. this.items.push(new resolveSeqD03cb037.Pair(key));
  7225. }
  7226. }
  7227. toJSON(_, ctx) {
  7228. return super.toJSON(_, ctx, Set);
  7229. }
  7230. toString(ctx, onComment, onChompKeep) {
  7231. if (!ctx) return JSON.stringify(this);
  7232. if (this.hasAllNullValues()) return super.toString(ctx, onComment, onChompKeep);else throw new Error('Set items must all have null values');
  7233. }
  7234. }
  7235. PlainValueEc8e588e._defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
  7236. function parseSet(doc, cst) {
  7237. const map = resolveSeqD03cb037.resolveMap(doc, cst);
  7238. if (!map.hasAllNullValues()) throw new PlainValueEc8e588e.YAMLSemanticError(cst, 'Set items must all have null values');
  7239. return Object.assign(new YAMLSet(), map);
  7240. }
  7241. function createSet(schema, iterable, ctx) {
  7242. const set = new YAMLSet();
  7243. for (const value of iterable) set.items.push(schema.createPair(value, null, ctx));
  7244. return set;
  7245. }
  7246. const set = {
  7247. identify: value => value instanceof Set,
  7248. nodeClass: YAMLSet,
  7249. default: false,
  7250. tag: 'tag:yaml.org,2002:set',
  7251. resolve: parseSet,
  7252. createNode: createSet
  7253. };
  7254. const parseSexagesimal = (sign, parts) => {
  7255. const n = parts.split(':').reduce((n, p) => n * 60 + Number(p), 0);
  7256. return sign === '-' ? -n : n;
  7257. }; // hhhh:mm:ss.sss
  7258. const stringifySexagesimal = ({
  7259. value
  7260. }) => {
  7261. if (isNaN(value) || !isFinite(value)) return resolveSeqD03cb037.stringifyNumber(value);
  7262. let sign = '';
  7263. if (value < 0) {
  7264. sign = '-';
  7265. value = Math.abs(value);
  7266. }
  7267. const parts = [value % 60]; // seconds, including ms
  7268. if (value < 60) {
  7269. parts.unshift(0); // at least one : is required
  7270. } else {
  7271. value = Math.round((value - parts[0]) / 60);
  7272. parts.unshift(value % 60); // minutes
  7273. if (value >= 60) {
  7274. value = Math.round((value - parts[0]) / 60);
  7275. parts.unshift(value); // hours
  7276. }
  7277. }
  7278. return sign + parts.map(n => n < 10 ? '0' + String(n) : String(n)).join(':').replace(/000000\d*$/, '') // % 60 may introduce error
  7279. ;
  7280. };
  7281. const intTime = {
  7282. identify: value => typeof value === 'number',
  7283. default: true,
  7284. tag: 'tag:yaml.org,2002:int',
  7285. format: 'TIME',
  7286. test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+)$/,
  7287. resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')),
  7288. stringify: stringifySexagesimal
  7289. };
  7290. const floatTime = {
  7291. identify: value => typeof value === 'number',
  7292. default: true,
  7293. tag: 'tag:yaml.org,2002:float',
  7294. format: 'TIME',
  7295. test: /^([-+]?)([0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*)$/,
  7296. resolve: (str, sign, parts) => parseSexagesimal(sign, parts.replace(/_/g, '')),
  7297. stringify: stringifySexagesimal
  7298. };
  7299. const timestamp = {
  7300. identify: value => value instanceof Date,
  7301. default: true,
  7302. tag: 'tag:yaml.org,2002:timestamp',
  7303. // If the time zone is omitted, the timestamp is assumed to be specified in UTC. The time part
  7304. // may be omitted altogether, resulting in a date format. In such a case, the time part is
  7305. // assumed to be 00:00:00Z (start of day, UTC).
  7306. test: RegExp('^(?:' + '([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})' + // YYYY-Mm-Dd
  7307. '(?:(?:t|T|[ \\t]+)' + // t | T | whitespace
  7308. '([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)' + // Hh:Mm:Ss(.ss)?
  7309. '(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?' + // Z | +5 | -03:30
  7310. ')?' + ')$'),
  7311. resolve: (str, year, month, day, hour, minute, second, millisec, tz) => {
  7312. if (millisec) millisec = (millisec + '00').substr(1, 3);
  7313. let date = Date.UTC(year, month - 1, day, hour || 0, minute || 0, second || 0, millisec || 0);
  7314. if (tz && tz !== 'Z') {
  7315. let d = parseSexagesimal(tz[0], tz.slice(1));
  7316. if (Math.abs(d) < 30) d *= 60;
  7317. date -= 60000 * d;
  7318. }
  7319. return new Date(date);
  7320. },
  7321. stringify: ({
  7322. value
  7323. }) => value.toISOString().replace(/((T00:00)?:00)?\.000Z$/, '')
  7324. };
  7325. /* global console, process, YAML_SILENCE_DEPRECATION_WARNINGS, YAML_SILENCE_WARNINGS */
  7326. function shouldWarn(deprecation) {
  7327. const env = typeof process !== 'undefined' && process.env || {};
  7328. if (deprecation) {
  7329. if (typeof YAML_SILENCE_DEPRECATION_WARNINGS !== 'undefined') return !YAML_SILENCE_DEPRECATION_WARNINGS;
  7330. return !env.YAML_SILENCE_DEPRECATION_WARNINGS;
  7331. }
  7332. if (typeof YAML_SILENCE_WARNINGS !== 'undefined') return !YAML_SILENCE_WARNINGS;
  7333. return !env.YAML_SILENCE_WARNINGS;
  7334. }
  7335. function warn(warning, type) {
  7336. if (shouldWarn(false)) {
  7337. const emit = typeof process !== 'undefined' && process.emitWarning; // This will throw in Jest if `warning` is an Error instance due to
  7338. // https://github.com/facebook/jest/issues/2549
  7339. if (emit) emit(warning, type);else {
  7340. // eslint-disable-next-line no-console
  7341. console.warn(type ? `${type}: ${warning}` : warning);
  7342. }
  7343. }
  7344. }
  7345. function warnFileDeprecation(filename) {
  7346. if (shouldWarn(true)) {
  7347. const path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/');
  7348. warn(`The endpoint 'yaml/${path}' will be removed in a future release.`, 'DeprecationWarning');
  7349. }
  7350. }
  7351. const warned = {};
  7352. function warnOptionDeprecation(name, alternative) {
  7353. if (!warned[name] && shouldWarn(true)) {
  7354. warned[name] = true;
  7355. let msg = `The option '${name}' will be removed in a future release`;
  7356. msg += alternative ? `, use '${alternative}' instead.` : '.';
  7357. warn(msg, 'DeprecationWarning');
  7358. }
  7359. }
  7360. var binary_1 = binary;
  7361. var floatTime_1 = floatTime;
  7362. var intTime_1 = intTime;
  7363. var omap_1 = omap;
  7364. var pairs_1 = pairs;
  7365. var set_1 = set;
  7366. var timestamp_1 = timestamp;
  7367. var warn_1 = warn;
  7368. var warnFileDeprecation_1 = warnFileDeprecation;
  7369. var warnOptionDeprecation_1 = warnOptionDeprecation;
  7370. var warnings1000a372 = {
  7371. binary: binary_1,
  7372. floatTime: floatTime_1,
  7373. intTime: intTime_1,
  7374. omap: omap_1,
  7375. pairs: pairs_1,
  7376. set: set_1,
  7377. timestamp: timestamp_1,
  7378. warn: warn_1,
  7379. warnFileDeprecation: warnFileDeprecation_1,
  7380. warnOptionDeprecation: warnOptionDeprecation_1
  7381. };
  7382. function createMap(schema, obj, ctx) {
  7383. const map = new resolveSeqD03cb037.YAMLMap(schema);
  7384. if (obj instanceof Map) {
  7385. for (const [key, value] of obj) map.items.push(schema.createPair(key, value, ctx));
  7386. } else if (obj && typeof obj === 'object') {
  7387. for (const key of Object.keys(obj)) map.items.push(schema.createPair(key, obj[key], ctx));
  7388. }
  7389. if (typeof schema.sortMapEntries === 'function') {
  7390. map.items.sort(schema.sortMapEntries);
  7391. }
  7392. return map;
  7393. }
  7394. const map = {
  7395. createNode: createMap,
  7396. default: true,
  7397. nodeClass: resolveSeqD03cb037.YAMLMap,
  7398. tag: 'tag:yaml.org,2002:map',
  7399. resolve: resolveSeqD03cb037.resolveMap
  7400. };
  7401. function createSeq(schema, obj, ctx) {
  7402. const seq = new resolveSeqD03cb037.YAMLSeq(schema);
  7403. if (obj && obj[Symbol.iterator]) {
  7404. for (const it of obj) {
  7405. const v = schema.createNode(it, ctx.wrapScalars, null, ctx);
  7406. seq.items.push(v);
  7407. }
  7408. }
  7409. return seq;
  7410. }
  7411. const seq = {
  7412. createNode: createSeq,
  7413. default: true,
  7414. nodeClass: resolveSeqD03cb037.YAMLSeq,
  7415. tag: 'tag:yaml.org,2002:seq',
  7416. resolve: resolveSeqD03cb037.resolveSeq
  7417. };
  7418. const string = {
  7419. identify: value => typeof value === 'string',
  7420. default: true,
  7421. tag: 'tag:yaml.org,2002:str',
  7422. resolve: resolveSeqD03cb037.resolveString,
  7423. stringify(item, ctx, onComment, onChompKeep) {
  7424. ctx = Object.assign({
  7425. actualString: true
  7426. }, ctx);
  7427. return resolveSeqD03cb037.stringifyString(item, ctx, onComment, onChompKeep);
  7428. },
  7429. options: resolveSeqD03cb037.strOptions
  7430. };
  7431. const failsafe = [map, seq, string];
  7432. /* global BigInt */
  7433. const intIdentify$2 = value => typeof value === 'bigint' || Number.isInteger(value);
  7434. const intResolve$1 = (src, part, radix) => resolveSeqD03cb037.intOptions.asBigInt ? BigInt(src) : parseInt(part, radix);
  7435. function intStringify$1(node, radix, prefix) {
  7436. const {
  7437. value
  7438. } = node;
  7439. if (intIdentify$2(value) && value >= 0) return prefix + value.toString(radix);
  7440. return resolveSeqD03cb037.stringifyNumber(node);
  7441. }
  7442. const nullObj = {
  7443. identify: value => value == null,
  7444. createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeqD03cb037.Scalar(null) : null,
  7445. default: true,
  7446. tag: 'tag:yaml.org,2002:null',
  7447. test: /^(?:~|[Nn]ull|NULL)?$/,
  7448. resolve: () => null,
  7449. options: resolveSeqD03cb037.nullOptions,
  7450. stringify: () => resolveSeqD03cb037.nullOptions.nullStr
  7451. };
  7452. const boolObj = {
  7453. identify: value => typeof value === 'boolean',
  7454. default: true,
  7455. tag: 'tag:yaml.org,2002:bool',
  7456. test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
  7457. resolve: str => str[0] === 't' || str[0] === 'T',
  7458. options: resolveSeqD03cb037.boolOptions,
  7459. stringify: ({
  7460. value
  7461. }) => value ? resolveSeqD03cb037.boolOptions.trueStr : resolveSeqD03cb037.boolOptions.falseStr
  7462. };
  7463. const octObj = {
  7464. identify: value => intIdentify$2(value) && value >= 0,
  7465. default: true,
  7466. tag: 'tag:yaml.org,2002:int',
  7467. format: 'OCT',
  7468. test: /^0o([0-7]+)$/,
  7469. resolve: (str, oct) => intResolve$1(str, oct, 8),
  7470. options: resolveSeqD03cb037.intOptions,
  7471. stringify: node => intStringify$1(node, 8, '0o')
  7472. };
  7473. const intObj = {
  7474. identify: intIdentify$2,
  7475. default: true,
  7476. tag: 'tag:yaml.org,2002:int',
  7477. test: /^[-+]?[0-9]+$/,
  7478. resolve: str => intResolve$1(str, str, 10),
  7479. options: resolveSeqD03cb037.intOptions,
  7480. stringify: resolveSeqD03cb037.stringifyNumber
  7481. };
  7482. const hexObj = {
  7483. identify: value => intIdentify$2(value) && value >= 0,
  7484. default: true,
  7485. tag: 'tag:yaml.org,2002:int',
  7486. format: 'HEX',
  7487. test: /^0x([0-9a-fA-F]+)$/,
  7488. resolve: (str, hex) => intResolve$1(str, hex, 16),
  7489. options: resolveSeqD03cb037.intOptions,
  7490. stringify: node => intStringify$1(node, 16, '0x')
  7491. };
  7492. const nanObj = {
  7493. identify: value => typeof value === 'number',
  7494. default: true,
  7495. tag: 'tag:yaml.org,2002:float',
  7496. test: /^(?:[-+]?\.inf|(\.nan))$/i,
  7497. resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
  7498. stringify: resolveSeqD03cb037.stringifyNumber
  7499. };
  7500. const expObj = {
  7501. identify: value => typeof value === 'number',
  7502. default: true,
  7503. tag: 'tag:yaml.org,2002:float',
  7504. format: 'EXP',
  7505. test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
  7506. resolve: str => parseFloat(str),
  7507. stringify: ({
  7508. value
  7509. }) => Number(value).toExponential()
  7510. };
  7511. const floatObj = {
  7512. identify: value => typeof value === 'number',
  7513. default: true,
  7514. tag: 'tag:yaml.org,2002:float',
  7515. test: /^[-+]?(?:\.([0-9]+)|[0-9]+\.([0-9]*))$/,
  7516. resolve(str, frac1, frac2) {
  7517. const frac = frac1 || frac2;
  7518. const node = new resolveSeqD03cb037.Scalar(parseFloat(str));
  7519. if (frac && frac[frac.length - 1] === '0') node.minFractionDigits = frac.length;
  7520. return node;
  7521. },
  7522. stringify: resolveSeqD03cb037.stringifyNumber
  7523. };
  7524. const core = failsafe.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
  7525. /* global BigInt */
  7526. const intIdentify$1 = value => typeof value === 'bigint' || Number.isInteger(value);
  7527. const stringifyJSON = ({
  7528. value
  7529. }) => JSON.stringify(value);
  7530. const json = [map, seq, {
  7531. identify: value => typeof value === 'string',
  7532. default: true,
  7533. tag: 'tag:yaml.org,2002:str',
  7534. resolve: resolveSeqD03cb037.resolveString,
  7535. stringify: stringifyJSON
  7536. }, {
  7537. identify: value => value == null,
  7538. createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeqD03cb037.Scalar(null) : null,
  7539. default: true,
  7540. tag: 'tag:yaml.org,2002:null',
  7541. test: /^null$/,
  7542. resolve: () => null,
  7543. stringify: stringifyJSON
  7544. }, {
  7545. identify: value => typeof value === 'boolean',
  7546. default: true,
  7547. tag: 'tag:yaml.org,2002:bool',
  7548. test: /^true|false$/,
  7549. resolve: str => str === 'true',
  7550. stringify: stringifyJSON
  7551. }, {
  7552. identify: intIdentify$1,
  7553. default: true,
  7554. tag: 'tag:yaml.org,2002:int',
  7555. test: /^-?(?:0|[1-9][0-9]*)$/,
  7556. resolve: str => resolveSeqD03cb037.intOptions.asBigInt ? BigInt(str) : parseInt(str, 10),
  7557. stringify: ({
  7558. value
  7559. }) => intIdentify$1(value) ? value.toString() : JSON.stringify(value)
  7560. }, {
  7561. identify: value => typeof value === 'number',
  7562. default: true,
  7563. tag: 'tag:yaml.org,2002:float',
  7564. test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
  7565. resolve: str => parseFloat(str),
  7566. stringify: stringifyJSON
  7567. }];
  7568. json.scalarFallback = str => {
  7569. throw new SyntaxError(`Unresolved plain scalar ${JSON.stringify(str)}`);
  7570. };
  7571. /* global BigInt */
  7572. const boolStringify = ({
  7573. value
  7574. }) => value ? resolveSeqD03cb037.boolOptions.trueStr : resolveSeqD03cb037.boolOptions.falseStr;
  7575. const intIdentify = value => typeof value === 'bigint' || Number.isInteger(value);
  7576. function intResolve(sign, src, radix) {
  7577. let str = src.replace(/_/g, '');
  7578. if (resolveSeqD03cb037.intOptions.asBigInt) {
  7579. switch (radix) {
  7580. case 2:
  7581. str = `0b${str}`;
  7582. break;
  7583. case 8:
  7584. str = `0o${str}`;
  7585. break;
  7586. case 16:
  7587. str = `0x${str}`;
  7588. break;
  7589. }
  7590. const n = BigInt(str);
  7591. return sign === '-' ? BigInt(-1) * n : n;
  7592. }
  7593. const n = parseInt(str, radix);
  7594. return sign === '-' ? -1 * n : n;
  7595. }
  7596. function intStringify(node, radix, prefix) {
  7597. const {
  7598. value
  7599. } = node;
  7600. if (intIdentify(value)) {
  7601. const str = value.toString(radix);
  7602. return value < 0 ? '-' + prefix + str.substr(1) : prefix + str;
  7603. }
  7604. return resolveSeqD03cb037.stringifyNumber(node);
  7605. }
  7606. const yaml11 = failsafe.concat([{
  7607. identify: value => value == null,
  7608. createNode: (schema, value, ctx) => ctx.wrapScalars ? new resolveSeqD03cb037.Scalar(null) : null,
  7609. default: true,
  7610. tag: 'tag:yaml.org,2002:null',
  7611. test: /^(?:~|[Nn]ull|NULL)?$/,
  7612. resolve: () => null,
  7613. options: resolveSeqD03cb037.nullOptions,
  7614. stringify: () => resolveSeqD03cb037.nullOptions.nullStr
  7615. }, {
  7616. identify: value => typeof value === 'boolean',
  7617. default: true,
  7618. tag: 'tag:yaml.org,2002:bool',
  7619. test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
  7620. resolve: () => true,
  7621. options: resolveSeqD03cb037.boolOptions,
  7622. stringify: boolStringify
  7623. }, {
  7624. identify: value => typeof value === 'boolean',
  7625. default: true,
  7626. tag: 'tag:yaml.org,2002:bool',
  7627. test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
  7628. resolve: () => false,
  7629. options: resolveSeqD03cb037.boolOptions,
  7630. stringify: boolStringify
  7631. }, {
  7632. identify: intIdentify,
  7633. default: true,
  7634. tag: 'tag:yaml.org,2002:int',
  7635. format: 'BIN',
  7636. test: /^([-+]?)0b([0-1_]+)$/,
  7637. resolve: (str, sign, bin) => intResolve(sign, bin, 2),
  7638. stringify: node => intStringify(node, 2, '0b')
  7639. }, {
  7640. identify: intIdentify,
  7641. default: true,
  7642. tag: 'tag:yaml.org,2002:int',
  7643. format: 'OCT',
  7644. test: /^([-+]?)0([0-7_]+)$/,
  7645. resolve: (str, sign, oct) => intResolve(sign, oct, 8),
  7646. stringify: node => intStringify(node, 8, '0')
  7647. }, {
  7648. identify: intIdentify,
  7649. default: true,
  7650. tag: 'tag:yaml.org,2002:int',
  7651. test: /^([-+]?)([0-9][0-9_]*)$/,
  7652. resolve: (str, sign, abs) => intResolve(sign, abs, 10),
  7653. stringify: resolveSeqD03cb037.stringifyNumber
  7654. }, {
  7655. identify: intIdentify,
  7656. default: true,
  7657. tag: 'tag:yaml.org,2002:int',
  7658. format: 'HEX',
  7659. test: /^([-+]?)0x([0-9a-fA-F_]+)$/,
  7660. resolve: (str, sign, hex) => intResolve(sign, hex, 16),
  7661. stringify: node => intStringify(node, 16, '0x')
  7662. }, {
  7663. identify: value => typeof value === 'number',
  7664. default: true,
  7665. tag: 'tag:yaml.org,2002:float',
  7666. test: /^(?:[-+]?\.inf|(\.nan))$/i,
  7667. resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
  7668. stringify: resolveSeqD03cb037.stringifyNumber
  7669. }, {
  7670. identify: value => typeof value === 'number',
  7671. default: true,
  7672. tag: 'tag:yaml.org,2002:float',
  7673. format: 'EXP',
  7674. test: /^[-+]?([0-9][0-9_]*)?(\.[0-9_]*)?[eE][-+]?[0-9]+$/,
  7675. resolve: str => parseFloat(str.replace(/_/g, '')),
  7676. stringify: ({
  7677. value
  7678. }) => Number(value).toExponential()
  7679. }, {
  7680. identify: value => typeof value === 'number',
  7681. default: true,
  7682. tag: 'tag:yaml.org,2002:float',
  7683. test: /^[-+]?(?:[0-9][0-9_]*)?\.([0-9_]*)$/,
  7684. resolve(str, frac) {
  7685. const node = new resolveSeqD03cb037.Scalar(parseFloat(str.replace(/_/g, '')));
  7686. if (frac) {
  7687. const f = frac.replace(/_/g, '');
  7688. if (f[f.length - 1] === '0') node.minFractionDigits = f.length;
  7689. }
  7690. return node;
  7691. },
  7692. stringify: resolveSeqD03cb037.stringifyNumber
  7693. }], warnings1000a372.binary, warnings1000a372.omap, warnings1000a372.pairs, warnings1000a372.set, warnings1000a372.intTime, warnings1000a372.floatTime, warnings1000a372.timestamp);
  7694. const schemas = {
  7695. core,
  7696. failsafe,
  7697. json,
  7698. yaml11
  7699. };
  7700. const tags = {
  7701. binary: warnings1000a372.binary,
  7702. bool: boolObj,
  7703. float: floatObj,
  7704. floatExp: expObj,
  7705. floatNaN: nanObj,
  7706. floatTime: warnings1000a372.floatTime,
  7707. int: intObj,
  7708. intHex: hexObj,
  7709. intOct: octObj,
  7710. intTime: warnings1000a372.intTime,
  7711. map,
  7712. null: nullObj,
  7713. omap: warnings1000a372.omap,
  7714. pairs: warnings1000a372.pairs,
  7715. seq,
  7716. set: warnings1000a372.set,
  7717. timestamp: warnings1000a372.timestamp
  7718. };
  7719. function findTagObject(value, tagName, tags) {
  7720. if (tagName) {
  7721. const match = tags.filter(t => t.tag === tagName);
  7722. const tagObj = match.find(t => !t.format) || match[0];
  7723. if (!tagObj) throw new Error(`Tag ${tagName} not found`);
  7724. return tagObj;
  7725. } // TODO: deprecate/remove class check
  7726. return tags.find(t => (t.identify && t.identify(value) || t.class && value instanceof t.class) && !t.format);
  7727. }
  7728. function createNode$1(value, tagName, ctx) {
  7729. if (value instanceof resolveSeqD03cb037.Node) return value;
  7730. const {
  7731. defaultPrefix,
  7732. onTagObj,
  7733. prevObjects,
  7734. schema,
  7735. wrapScalars
  7736. } = ctx;
  7737. if (tagName && tagName.startsWith('!!')) tagName = defaultPrefix + tagName.slice(2);
  7738. let tagObj = findTagObject(value, tagName, schema.tags);
  7739. if (!tagObj) {
  7740. if (typeof value.toJSON === 'function') value = value.toJSON();
  7741. if (!value || typeof value !== 'object') return wrapScalars ? new resolveSeqD03cb037.Scalar(value) : value;
  7742. tagObj = value instanceof Map ? map : value[Symbol.iterator] ? seq : map;
  7743. }
  7744. if (onTagObj) {
  7745. onTagObj(tagObj);
  7746. delete ctx.onTagObj;
  7747. } // Detect duplicate references to the same object & use Alias nodes for all
  7748. // after first. The `obj` wrapper allows for circular references to resolve.
  7749. const obj = {
  7750. value: undefined,
  7751. node: undefined
  7752. };
  7753. if (value && typeof value === 'object' && prevObjects) {
  7754. const prev = prevObjects.get(value);
  7755. if (prev) {
  7756. const alias = new resolveSeqD03cb037.Alias(prev); // leaves source dirty; must be cleaned by caller
  7757. ctx.aliasNodes.push(alias); // defined along with prevObjects
  7758. return alias;
  7759. }
  7760. obj.value = value;
  7761. prevObjects.set(value, obj);
  7762. }
  7763. obj.node = tagObj.createNode ? tagObj.createNode(ctx.schema, value, ctx) : wrapScalars ? new resolveSeqD03cb037.Scalar(value) : value;
  7764. if (tagName && obj.node instanceof resolveSeqD03cb037.Node) obj.node.tag = tagName;
  7765. return obj.node;
  7766. }
  7767. function getSchemaTags(schemas, knownTags, customTags, schemaId) {
  7768. let tags = schemas[schemaId.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
  7769. if (!tags) {
  7770. const keys = Object.keys(schemas).map(key => JSON.stringify(key)).join(', ');
  7771. throw new Error(`Unknown schema "${schemaId}"; use one of ${keys}`);
  7772. }
  7773. if (Array.isArray(customTags)) {
  7774. for (const tag of customTags) tags = tags.concat(tag);
  7775. } else if (typeof customTags === 'function') {
  7776. tags = customTags(tags.slice());
  7777. }
  7778. for (let i = 0; i < tags.length; ++i) {
  7779. const tag = tags[i];
  7780. if (typeof tag === 'string') {
  7781. const tagObj = knownTags[tag];
  7782. if (!tagObj) {
  7783. const keys = Object.keys(knownTags).map(key => JSON.stringify(key)).join(', ');
  7784. throw new Error(`Unknown custom tag "${tag}"; use one of ${keys}`);
  7785. }
  7786. tags[i] = tagObj;
  7787. }
  7788. }
  7789. return tags;
  7790. }
  7791. const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
  7792. class Schema {
  7793. // TODO: remove in v2
  7794. // TODO: remove in v2
  7795. constructor({
  7796. customTags,
  7797. merge,
  7798. schema,
  7799. sortMapEntries,
  7800. tags: deprecatedCustomTags
  7801. }) {
  7802. this.merge = !!merge;
  7803. this.name = schema;
  7804. this.sortMapEntries = sortMapEntries === true ? sortMapEntriesByKey : sortMapEntries || null;
  7805. if (!customTags && deprecatedCustomTags) warnings1000a372.warnOptionDeprecation('tags', 'customTags');
  7806. this.tags = getSchemaTags(schemas, tags, customTags || deprecatedCustomTags, schema);
  7807. }
  7808. createNode(value, wrapScalars, tagName, ctx) {
  7809. const baseCtx = {
  7810. defaultPrefix: Schema.defaultPrefix,
  7811. schema: this,
  7812. wrapScalars
  7813. };
  7814. const createCtx = ctx ? Object.assign(ctx, baseCtx) : baseCtx;
  7815. return createNode$1(value, tagName, createCtx);
  7816. }
  7817. createPair(key, value, ctx) {
  7818. if (!ctx) ctx = {
  7819. wrapScalars: true
  7820. };
  7821. const k = this.createNode(key, ctx.wrapScalars, null, ctx);
  7822. const v = this.createNode(value, ctx.wrapScalars, null, ctx);
  7823. return new resolveSeqD03cb037.Pair(k, v);
  7824. }
  7825. }
  7826. PlainValueEc8e588e._defineProperty(Schema, "defaultPrefix", PlainValueEc8e588e.defaultTagPrefix);
  7827. PlainValueEc8e588e._defineProperty(Schema, "defaultTags", PlainValueEc8e588e.defaultTags);
  7828. var Schema_1 = Schema;
  7829. var Schema88e323a7 = {
  7830. Schema: Schema_1
  7831. };
  7832. const defaultOptions = {
  7833. anchorPrefix: 'a',
  7834. customTags: null,
  7835. indent: 2,
  7836. indentSeq: true,
  7837. keepCstNodes: false,
  7838. keepNodeTypes: true,
  7839. keepBlobsInJSON: true,
  7840. mapAsMap: false,
  7841. maxAliasCount: 100,
  7842. prettyErrors: false,
  7843. // TODO Set true in v2
  7844. simpleKeys: false,
  7845. version: '1.2'
  7846. };
  7847. const scalarOptions = {
  7848. get binary() {
  7849. return resolveSeqD03cb037.binaryOptions;
  7850. },
  7851. set binary(opt) {
  7852. Object.assign(resolveSeqD03cb037.binaryOptions, opt);
  7853. },
  7854. get bool() {
  7855. return resolveSeqD03cb037.boolOptions;
  7856. },
  7857. set bool(opt) {
  7858. Object.assign(resolveSeqD03cb037.boolOptions, opt);
  7859. },
  7860. get int() {
  7861. return resolveSeqD03cb037.intOptions;
  7862. },
  7863. set int(opt) {
  7864. Object.assign(resolveSeqD03cb037.intOptions, opt);
  7865. },
  7866. get null() {
  7867. return resolveSeqD03cb037.nullOptions;
  7868. },
  7869. set null(opt) {
  7870. Object.assign(resolveSeqD03cb037.nullOptions, opt);
  7871. },
  7872. get str() {
  7873. return resolveSeqD03cb037.strOptions;
  7874. },
  7875. set str(opt) {
  7876. Object.assign(resolveSeqD03cb037.strOptions, opt);
  7877. }
  7878. };
  7879. const documentOptions = {
  7880. '1.0': {
  7881. schema: 'yaml-1.1',
  7882. merge: true,
  7883. tagPrefixes: [{
  7884. handle: '!',
  7885. prefix: PlainValueEc8e588e.defaultTagPrefix
  7886. }, {
  7887. handle: '!!',
  7888. prefix: 'tag:private.yaml.org,2002:'
  7889. }]
  7890. },
  7891. 1.1: {
  7892. schema: 'yaml-1.1',
  7893. merge: true,
  7894. tagPrefixes: [{
  7895. handle: '!',
  7896. prefix: '!'
  7897. }, {
  7898. handle: '!!',
  7899. prefix: PlainValueEc8e588e.defaultTagPrefix
  7900. }]
  7901. },
  7902. 1.2: {
  7903. schema: 'core',
  7904. merge: false,
  7905. tagPrefixes: [{
  7906. handle: '!',
  7907. prefix: '!'
  7908. }, {
  7909. handle: '!!',
  7910. prefix: PlainValueEc8e588e.defaultTagPrefix
  7911. }]
  7912. }
  7913. };
  7914. function stringifyTag(doc, tag) {
  7915. if ((doc.version || doc.options.version) === '1.0') {
  7916. const priv = tag.match(/^tag:private\.yaml\.org,2002:([^:/]+)$/);
  7917. if (priv) return '!' + priv[1];
  7918. const vocab = tag.match(/^tag:([a-zA-Z0-9-]+)\.yaml\.org,2002:(.*)/);
  7919. return vocab ? `!${vocab[1]}/${vocab[2]}` : `!${tag.replace(/^tag:/, '')}`;
  7920. }
  7921. let p = doc.tagPrefixes.find(p => tag.indexOf(p.prefix) === 0);
  7922. if (!p) {
  7923. const dtp = doc.getDefaults().tagPrefixes;
  7924. p = dtp && dtp.find(p => tag.indexOf(p.prefix) === 0);
  7925. }
  7926. if (!p) return tag[0] === '!' ? tag : `!<${tag}>`;
  7927. const suffix = tag.substr(p.prefix.length).replace(/[!,[\]{}]/g, ch => ({
  7928. '!': '%21',
  7929. ',': '%2C',
  7930. '[': '%5B',
  7931. ']': '%5D',
  7932. '{': '%7B',
  7933. '}': '%7D'
  7934. })[ch]);
  7935. return p.handle + suffix;
  7936. }
  7937. function getTagObject(tags, item) {
  7938. if (item instanceof resolveSeqD03cb037.Alias) return resolveSeqD03cb037.Alias;
  7939. if (item.tag) {
  7940. const match = tags.filter(t => t.tag === item.tag);
  7941. if (match.length > 0) return match.find(t => t.format === item.format) || match[0];
  7942. }
  7943. let tagObj, obj;
  7944. if (item instanceof resolveSeqD03cb037.Scalar) {
  7945. obj = item.value; // TODO: deprecate/remove class check
  7946. const match = tags.filter(t => t.identify && t.identify(obj) || t.class && obj instanceof t.class);
  7947. tagObj = match.find(t => t.format === item.format) || match.find(t => !t.format);
  7948. } else {
  7949. obj = item;
  7950. tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
  7951. }
  7952. if (!tagObj) {
  7953. const name = obj && obj.constructor ? obj.constructor.name : typeof obj;
  7954. throw new Error(`Tag not resolved for ${name} value`);
  7955. }
  7956. return tagObj;
  7957. } // needs to be called before value stringifier to allow for circular anchor refs
  7958. function stringifyProps(node, tagObj, {
  7959. anchors,
  7960. doc
  7961. }) {
  7962. const props = [];
  7963. const anchor = doc.anchors.getName(node);
  7964. if (anchor) {
  7965. anchors[anchor] = node;
  7966. props.push(`&${anchor}`);
  7967. }
  7968. if (node.tag) {
  7969. props.push(stringifyTag(doc, node.tag));
  7970. } else if (!tagObj.default) {
  7971. props.push(stringifyTag(doc, tagObj.tag));
  7972. }
  7973. return props.join(' ');
  7974. }
  7975. function stringify$1(item, ctx, onComment, onChompKeep) {
  7976. const {
  7977. anchors,
  7978. schema
  7979. } = ctx.doc;
  7980. let tagObj;
  7981. if (!(item instanceof resolveSeqD03cb037.Node)) {
  7982. const createCtx = {
  7983. aliasNodes: [],
  7984. onTagObj: o => tagObj = o,
  7985. prevObjects: new Map()
  7986. };
  7987. item = schema.createNode(item, true, null, createCtx);
  7988. for (const alias of createCtx.aliasNodes) {
  7989. alias.source = alias.source.node;
  7990. let name = anchors.getName(alias.source);
  7991. if (!name) {
  7992. name = anchors.newName();
  7993. anchors.map[name] = alias.source;
  7994. }
  7995. }
  7996. }
  7997. if (item instanceof resolveSeqD03cb037.Pair) return item.toString(ctx, onComment, onChompKeep);
  7998. if (!tagObj) tagObj = getTagObject(schema.tags, item);
  7999. const props = stringifyProps(item, tagObj, ctx);
  8000. if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1;
  8001. const str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof resolveSeqD03cb037.Scalar ? resolveSeqD03cb037.stringifyString(item, ctx, onComment, onChompKeep) : item.toString(ctx, onComment, onChompKeep);
  8002. if (!props) return str;
  8003. return item instanceof resolveSeqD03cb037.Scalar || str[0] === '{' || str[0] === '[' ? `${props} ${str}` : `${props}\n${ctx.indent}${str}`;
  8004. }
  8005. class Anchors {
  8006. static validAnchorNode(node) {
  8007. return node instanceof resolveSeqD03cb037.Scalar || node instanceof resolveSeqD03cb037.YAMLSeq || node instanceof resolveSeqD03cb037.YAMLMap;
  8008. }
  8009. constructor(prefix) {
  8010. PlainValueEc8e588e._defineProperty(this, "map", Object.create(null));
  8011. this.prefix = prefix;
  8012. }
  8013. createAlias(node, name) {
  8014. this.setAnchor(node, name);
  8015. return new resolveSeqD03cb037.Alias(node);
  8016. }
  8017. createMergePair(...sources) {
  8018. const merge = new resolveSeqD03cb037.Merge();
  8019. merge.value.items = sources.map(s => {
  8020. if (s instanceof resolveSeqD03cb037.Alias) {
  8021. if (s.source instanceof resolveSeqD03cb037.YAMLMap) return s;
  8022. } else if (s instanceof resolveSeqD03cb037.YAMLMap) {
  8023. return this.createAlias(s);
  8024. }
  8025. throw new Error('Merge sources must be Map nodes or their Aliases');
  8026. });
  8027. return merge;
  8028. }
  8029. getName(node) {
  8030. const {
  8031. map
  8032. } = this;
  8033. return Object.keys(map).find(a => map[a] === node);
  8034. }
  8035. getNames() {
  8036. return Object.keys(this.map);
  8037. }
  8038. getNode(name) {
  8039. return this.map[name];
  8040. }
  8041. newName(prefix) {
  8042. if (!prefix) prefix = this.prefix;
  8043. const names = Object.keys(this.map);
  8044. for (let i = 1; true; ++i) {
  8045. const name = `${prefix}${i}`;
  8046. if (!names.includes(name)) return name;
  8047. }
  8048. } // During parsing, map & aliases contain CST nodes
  8049. resolveNodes() {
  8050. const {
  8051. map,
  8052. _cstAliases
  8053. } = this;
  8054. Object.keys(map).forEach(a => {
  8055. map[a] = map[a].resolved;
  8056. });
  8057. _cstAliases.forEach(a => {
  8058. a.source = a.source.resolved;
  8059. });
  8060. delete this._cstAliases;
  8061. }
  8062. setAnchor(node, name) {
  8063. if (node != null && !Anchors.validAnchorNode(node)) {
  8064. throw new Error('Anchors may only be set for Scalar, Seq and Map nodes');
  8065. }
  8066. if (name && /[\x00-\x19\s,[\]{}]/.test(name)) {
  8067. throw new Error('Anchor names must not contain whitespace or control characters');
  8068. }
  8069. const {
  8070. map
  8071. } = this;
  8072. const prev = node && Object.keys(map).find(a => map[a] === node);
  8073. if (prev) {
  8074. if (!name) {
  8075. return prev;
  8076. } else if (prev !== name) {
  8077. delete map[prev];
  8078. map[name] = node;
  8079. }
  8080. } else {
  8081. if (!name) {
  8082. if (!node) return null;
  8083. name = this.newName();
  8084. }
  8085. map[name] = node;
  8086. }
  8087. return name;
  8088. }
  8089. }
  8090. const visit = (node, tags) => {
  8091. if (node && typeof node === 'object') {
  8092. const {
  8093. tag
  8094. } = node;
  8095. if (node instanceof resolveSeqD03cb037.Collection) {
  8096. if (tag) tags[tag] = true;
  8097. node.items.forEach(n => visit(n, tags));
  8098. } else if (node instanceof resolveSeqD03cb037.Pair) {
  8099. visit(node.key, tags);
  8100. visit(node.value, tags);
  8101. } else if (node instanceof resolveSeqD03cb037.Scalar) {
  8102. if (tag) tags[tag] = true;
  8103. }
  8104. }
  8105. return tags;
  8106. };
  8107. const listTagNames = node => Object.keys(visit(node, {}));
  8108. function parseContents(doc, contents) {
  8109. const comments = {
  8110. before: [],
  8111. after: []
  8112. };
  8113. let body = undefined;
  8114. let spaceBefore = false;
  8115. for (const node of contents) {
  8116. if (node.valueRange) {
  8117. if (body !== undefined) {
  8118. const msg = 'Document contains trailing content not separated by a ... or --- line';
  8119. doc.errors.push(new PlainValueEc8e588e.YAMLSyntaxError(node, msg));
  8120. break;
  8121. }
  8122. const res = resolveSeqD03cb037.resolveNode(doc, node);
  8123. if (spaceBefore) {
  8124. res.spaceBefore = true;
  8125. spaceBefore = false;
  8126. }
  8127. body = res;
  8128. } else if (node.comment !== null) {
  8129. const cc = body === undefined ? comments.before : comments.after;
  8130. cc.push(node.comment);
  8131. } else if (node.type === PlainValueEc8e588e.Type.BLANK_LINE) {
  8132. spaceBefore = true;
  8133. if (body === undefined && comments.before.length > 0 && !doc.commentBefore) {
  8134. // space-separated comments at start are parsed as document comments
  8135. doc.commentBefore = comments.before.join('\n');
  8136. comments.before = [];
  8137. }
  8138. }
  8139. }
  8140. doc.contents = body || null;
  8141. if (!body) {
  8142. doc.comment = comments.before.concat(comments.after).join('\n') || null;
  8143. } else {
  8144. const cb = comments.before.join('\n');
  8145. if (cb) {
  8146. const cbNode = body instanceof resolveSeqD03cb037.Collection && body.items[0] ? body.items[0] : body;
  8147. cbNode.commentBefore = cbNode.commentBefore ? `${cb}\n${cbNode.commentBefore}` : cb;
  8148. }
  8149. doc.comment = comments.after.join('\n') || null;
  8150. }
  8151. }
  8152. function resolveTagDirective({
  8153. tagPrefixes
  8154. }, directive) {
  8155. const [handle, prefix] = directive.parameters;
  8156. if (!handle || !prefix) {
  8157. const msg = 'Insufficient parameters given for %TAG directive';
  8158. throw new PlainValueEc8e588e.YAMLSemanticError(directive, msg);
  8159. }
  8160. if (tagPrefixes.some(p => p.handle === handle)) {
  8161. const msg = 'The %TAG directive must only be given at most once per handle in the same document.';
  8162. throw new PlainValueEc8e588e.YAMLSemanticError(directive, msg);
  8163. }
  8164. return {
  8165. handle,
  8166. prefix
  8167. };
  8168. }
  8169. function resolveYamlDirective(doc, directive) {
  8170. let [version] = directive.parameters;
  8171. if (directive.name === 'YAML:1.0') version = '1.0';
  8172. if (!version) {
  8173. const msg = 'Insufficient parameters given for %YAML directive';
  8174. throw new PlainValueEc8e588e.YAMLSemanticError(directive, msg);
  8175. }
  8176. if (!documentOptions[version]) {
  8177. const v0 = doc.version || doc.options.version;
  8178. const msg = `Document will be parsed as YAML ${v0} rather than YAML ${version}`;
  8179. doc.warnings.push(new PlainValueEc8e588e.YAMLWarning(directive, msg));
  8180. }
  8181. return version;
  8182. }
  8183. function parseDirectives(doc, directives, prevDoc) {
  8184. const directiveComments = [];
  8185. let hasDirectives = false;
  8186. for (const directive of directives) {
  8187. const {
  8188. comment,
  8189. name
  8190. } = directive;
  8191. switch (name) {
  8192. case 'TAG':
  8193. try {
  8194. doc.tagPrefixes.push(resolveTagDirective(doc, directive));
  8195. } catch (error) {
  8196. doc.errors.push(error);
  8197. }
  8198. hasDirectives = true;
  8199. break;
  8200. case 'YAML':
  8201. case 'YAML:1.0':
  8202. if (doc.version) {
  8203. const msg = 'The %YAML directive must only be given at most once per document.';
  8204. doc.errors.push(new PlainValueEc8e588e.YAMLSemanticError(directive, msg));
  8205. }
  8206. try {
  8207. doc.version = resolveYamlDirective(doc, directive);
  8208. } catch (error) {
  8209. doc.errors.push(error);
  8210. }
  8211. hasDirectives = true;
  8212. break;
  8213. default:
  8214. if (name) {
  8215. const msg = `YAML only supports %TAG and %YAML directives, and not %${name}`;
  8216. doc.warnings.push(new PlainValueEc8e588e.YAMLWarning(directive, msg));
  8217. }
  8218. }
  8219. if (comment) directiveComments.push(comment);
  8220. }
  8221. if (prevDoc && !hasDirectives && '1.1' === (doc.version || prevDoc.version || doc.options.version)) {
  8222. const copyTagPrefix = ({
  8223. handle,
  8224. prefix
  8225. }) => ({
  8226. handle,
  8227. prefix
  8228. });
  8229. doc.tagPrefixes = prevDoc.tagPrefixes.map(copyTagPrefix);
  8230. doc.version = prevDoc.version;
  8231. }
  8232. doc.commentBefore = directiveComments.join('\n') || null;
  8233. }
  8234. function assertCollection(contents) {
  8235. if (contents instanceof resolveSeqD03cb037.Collection) return true;
  8236. throw new Error('Expected a YAML collection as document contents');
  8237. }
  8238. class Document$1 {
  8239. constructor(options) {
  8240. this.anchors = new Anchors(options.anchorPrefix);
  8241. this.commentBefore = null;
  8242. this.comment = null;
  8243. this.contents = null;
  8244. this.directivesEndMarker = null;
  8245. this.errors = [];
  8246. this.options = options;
  8247. this.schema = null;
  8248. this.tagPrefixes = [];
  8249. this.version = null;
  8250. this.warnings = [];
  8251. }
  8252. add(value) {
  8253. assertCollection(this.contents);
  8254. return this.contents.add(value);
  8255. }
  8256. addIn(path, value) {
  8257. assertCollection(this.contents);
  8258. this.contents.addIn(path, value);
  8259. }
  8260. delete(key) {
  8261. assertCollection(this.contents);
  8262. return this.contents.delete(key);
  8263. }
  8264. deleteIn(path) {
  8265. if (resolveSeqD03cb037.isEmptyPath(path)) {
  8266. if (this.contents == null) return false;
  8267. this.contents = null;
  8268. return true;
  8269. }
  8270. assertCollection(this.contents);
  8271. return this.contents.deleteIn(path);
  8272. }
  8273. getDefaults() {
  8274. return Document$1.defaults[this.version] || Document$1.defaults[this.options.version] || {};
  8275. }
  8276. get(key, keepScalar) {
  8277. return this.contents instanceof resolveSeqD03cb037.Collection ? this.contents.get(key, keepScalar) : undefined;
  8278. }
  8279. getIn(path, keepScalar) {
  8280. if (resolveSeqD03cb037.isEmptyPath(path)) return !keepScalar && this.contents instanceof resolveSeqD03cb037.Scalar ? this.contents.value : this.contents;
  8281. return this.contents instanceof resolveSeqD03cb037.Collection ? this.contents.getIn(path, keepScalar) : undefined;
  8282. }
  8283. has(key) {
  8284. return this.contents instanceof resolveSeqD03cb037.Collection ? this.contents.has(key) : false;
  8285. }
  8286. hasIn(path) {
  8287. if (resolveSeqD03cb037.isEmptyPath(path)) return this.contents !== undefined;
  8288. return this.contents instanceof resolveSeqD03cb037.Collection ? this.contents.hasIn(path) : false;
  8289. }
  8290. set(key, value) {
  8291. assertCollection(this.contents);
  8292. this.contents.set(key, value);
  8293. }
  8294. setIn(path, value) {
  8295. if (resolveSeqD03cb037.isEmptyPath(path)) this.contents = value;else {
  8296. assertCollection(this.contents);
  8297. this.contents.setIn(path, value);
  8298. }
  8299. }
  8300. setSchema(id, customTags) {
  8301. if (!id && !customTags && this.schema) return;
  8302. if (typeof id === 'number') id = id.toFixed(1);
  8303. if (id === '1.0' || id === '1.1' || id === '1.2') {
  8304. if (this.version) this.version = id;else this.options.version = id;
  8305. delete this.options.schema;
  8306. } else if (id && typeof id === 'string') {
  8307. this.options.schema = id;
  8308. }
  8309. if (Array.isArray(customTags)) this.options.customTags = customTags;
  8310. const opt = Object.assign({}, this.getDefaults(), this.options);
  8311. this.schema = new Schema88e323a7.Schema(opt);
  8312. }
  8313. parse(node, prevDoc) {
  8314. if (this.options.keepCstNodes) this.cstNode = node;
  8315. if (this.options.keepNodeTypes) this.type = 'DOCUMENT';
  8316. const {
  8317. directives = [],
  8318. contents = [],
  8319. directivesEndMarker,
  8320. error,
  8321. valueRange
  8322. } = node;
  8323. if (error) {
  8324. if (!error.source) error.source = this;
  8325. this.errors.push(error);
  8326. }
  8327. parseDirectives(this, directives, prevDoc);
  8328. if (directivesEndMarker) this.directivesEndMarker = true;
  8329. this.range = valueRange ? [valueRange.start, valueRange.end] : null;
  8330. this.setSchema();
  8331. this.anchors._cstAliases = [];
  8332. parseContents(this, contents);
  8333. this.anchors.resolveNodes();
  8334. if (this.options.prettyErrors) {
  8335. for (const error of this.errors) if (error instanceof PlainValueEc8e588e.YAMLError) error.makePretty();
  8336. for (const warn of this.warnings) if (warn instanceof PlainValueEc8e588e.YAMLError) warn.makePretty();
  8337. }
  8338. return this;
  8339. }
  8340. listNonDefaultTags() {
  8341. return listTagNames(this.contents).filter(t => t.indexOf(Schema88e323a7.Schema.defaultPrefix) !== 0);
  8342. }
  8343. setTagPrefix(handle, prefix) {
  8344. if (handle[0] !== '!' || handle[handle.length - 1] !== '!') throw new Error('Handle must start and end with !');
  8345. if (prefix) {
  8346. const prev = this.tagPrefixes.find(p => p.handle === handle);
  8347. if (prev) prev.prefix = prefix;else this.tagPrefixes.push({
  8348. handle,
  8349. prefix
  8350. });
  8351. } else {
  8352. this.tagPrefixes = this.tagPrefixes.filter(p => p.handle !== handle);
  8353. }
  8354. }
  8355. toJSON(arg, onAnchor) {
  8356. const {
  8357. keepBlobsInJSON,
  8358. mapAsMap,
  8359. maxAliasCount
  8360. } = this.options;
  8361. const keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof resolveSeqD03cb037.Scalar));
  8362. const ctx = {
  8363. doc: this,
  8364. indentStep: ' ',
  8365. keep,
  8366. mapAsMap: keep && !!mapAsMap,
  8367. maxAliasCount,
  8368. stringify: stringify$1 // Requiring directly in Pair would create circular dependencies
  8369. };
  8370. const anchorNames = Object.keys(this.anchors.map);
  8371. if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(name => [this.anchors.map[name], {
  8372. alias: [],
  8373. aliasCount: 0,
  8374. count: 1
  8375. }]));
  8376. const res = resolveSeqD03cb037.toJSON(this.contents, arg, ctx);
  8377. if (typeof onAnchor === 'function' && ctx.anchors) for (const {
  8378. count,
  8379. res
  8380. } of ctx.anchors.values()) onAnchor(res, count);
  8381. return res;
  8382. }
  8383. toString() {
  8384. if (this.errors.length > 0) throw new Error('Document with errors cannot be stringified');
  8385. const indentSize = this.options.indent;
  8386. if (!Number.isInteger(indentSize) || indentSize <= 0) {
  8387. const s = JSON.stringify(indentSize);
  8388. throw new Error(`"indent" option must be a positive integer, not ${s}`);
  8389. }
  8390. this.setSchema();
  8391. const lines = [];
  8392. let hasDirectives = false;
  8393. if (this.version) {
  8394. let vd = '%YAML 1.2';
  8395. if (this.schema.name === 'yaml-1.1') {
  8396. if (this.version === '1.0') vd = '%YAML:1.0';else if (this.version === '1.1') vd = '%YAML 1.1';
  8397. }
  8398. lines.push(vd);
  8399. hasDirectives = true;
  8400. }
  8401. const tagNames = this.listNonDefaultTags();
  8402. this.tagPrefixes.forEach(({
  8403. handle,
  8404. prefix
  8405. }) => {
  8406. if (tagNames.some(t => t.indexOf(prefix) === 0)) {
  8407. lines.push(`%TAG ${handle} ${prefix}`);
  8408. hasDirectives = true;
  8409. }
  8410. });
  8411. if (hasDirectives || this.directivesEndMarker) lines.push('---');
  8412. if (this.commentBefore) {
  8413. if (hasDirectives || !this.directivesEndMarker) lines.unshift('');
  8414. lines.unshift(this.commentBefore.replace(/^/gm, '#'));
  8415. }
  8416. const ctx = {
  8417. anchors: Object.create(null),
  8418. doc: this,
  8419. indent: '',
  8420. indentStep: ' '.repeat(indentSize),
  8421. stringify: stringify$1 // Requiring directly in nodes would create circular dependencies
  8422. };
  8423. let chompKeep = false;
  8424. let contentComment = null;
  8425. if (this.contents) {
  8426. if (this.contents instanceof resolveSeqD03cb037.Node) {
  8427. if (this.contents.spaceBefore && (hasDirectives || this.directivesEndMarker)) lines.push('');
  8428. if (this.contents.commentBefore) lines.push(this.contents.commentBefore.replace(/^/gm, '#')); // top-level block scalars need to be indented if followed by a comment
  8429. ctx.forceBlockIndent = !!this.comment;
  8430. contentComment = this.contents.comment;
  8431. }
  8432. const onChompKeep = contentComment ? null : () => chompKeep = true;
  8433. const body = stringify$1(this.contents, ctx, () => contentComment = null, onChompKeep);
  8434. lines.push(resolveSeqD03cb037.addComment(body, '', contentComment));
  8435. } else if (this.contents !== undefined) {
  8436. lines.push(stringify$1(this.contents, ctx));
  8437. }
  8438. if (this.comment) {
  8439. if ((!chompKeep || contentComment) && lines[lines.length - 1] !== '') lines.push('');
  8440. lines.push(this.comment.replace(/^/gm, '#'));
  8441. }
  8442. return lines.join('\n') + '\n';
  8443. }
  8444. }
  8445. PlainValueEc8e588e._defineProperty(Document$1, "defaults", documentOptions);
  8446. var Document_1 = Document$1;
  8447. var defaultOptions_1 = defaultOptions;
  8448. var scalarOptions_1 = scalarOptions;
  8449. var Document9b4560a1 = {
  8450. Document: Document_1,
  8451. defaultOptions: defaultOptions_1,
  8452. scalarOptions: scalarOptions_1
  8453. };
  8454. function createNode(value, wrapScalars = true, tag) {
  8455. if (tag === undefined && typeof wrapScalars === 'string') {
  8456. tag = wrapScalars;
  8457. wrapScalars = true;
  8458. }
  8459. const options = Object.assign({}, Document9b4560a1.Document.defaults[Document9b4560a1.defaultOptions.version], Document9b4560a1.defaultOptions);
  8460. const schema = new Schema88e323a7.Schema(options);
  8461. return schema.createNode(value, wrapScalars, tag);
  8462. }
  8463. class Document extends Document9b4560a1.Document {
  8464. constructor(options) {
  8465. super(Object.assign({}, Document9b4560a1.defaultOptions, options));
  8466. }
  8467. }
  8468. function parseAllDocuments(src, options) {
  8469. const stream = [];
  8470. let prev;
  8471. for (const cstDoc of parseCst.parse(src)) {
  8472. const doc = new Document(options);
  8473. doc.parse(cstDoc, prev);
  8474. stream.push(doc);
  8475. prev = doc;
  8476. }
  8477. return stream;
  8478. }
  8479. function parseDocument(src, options) {
  8480. const cst = parseCst.parse(src);
  8481. const doc = new Document(options).parse(cst[0]);
  8482. if (cst.length > 1) {
  8483. const errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()';
  8484. doc.errors.unshift(new PlainValueEc8e588e.YAMLSemanticError(cst[1], errMsg));
  8485. }
  8486. return doc;
  8487. }
  8488. function parse(src, options) {
  8489. const doc = parseDocument(src, options);
  8490. doc.warnings.forEach(warning => warnings1000a372.warn(warning));
  8491. if (doc.errors.length > 0) throw doc.errors[0];
  8492. return doc.toJSON();
  8493. }
  8494. function stringify(value, options) {
  8495. const doc = new Document(options);
  8496. doc.contents = value;
  8497. return String(doc);
  8498. }
  8499. const YAML = {
  8500. createNode,
  8501. defaultOptions: Document9b4560a1.defaultOptions,
  8502. Document,
  8503. parse,
  8504. parseAllDocuments,
  8505. parseCST: parseCst.parse,
  8506. parseDocument,
  8507. scalarOptions: Document9b4560a1.scalarOptions,
  8508. stringify
  8509. };
  8510. var YAML_1 = YAML;
  8511. var dist$1 = {
  8512. YAML: YAML_1
  8513. };
  8514. var yaml = dist$1.YAML;
  8515. var loaders_1 = createCommonjsModule(function (module, exports) {
  8516. Object.defineProperty(exports, "__esModule", {
  8517. value: true
  8518. });
  8519. exports.loaders = void 0;
  8520. /* eslint-disable @typescript-eslint/no-require-imports */
  8521. let importFresh$1;
  8522. const loadJs = function loadJs(filepath) {
  8523. if (importFresh$1 === undefined) {
  8524. importFresh$1 = importFresh;
  8525. }
  8526. const result = importFresh$1(filepath);
  8527. return result;
  8528. };
  8529. let parseJson;
  8530. const loadJson = function loadJson(filepath, content) {
  8531. if (parseJson === undefined) {
  8532. parseJson = parseJson_1;
  8533. }
  8534. try {
  8535. const result = parseJson(content);
  8536. return result;
  8537. } catch (error) {
  8538. error.message = `JSON Error in ${filepath}:\n${error.message}`;
  8539. throw error;
  8540. }
  8541. };
  8542. let yaml$1;
  8543. const loadYaml = function loadYaml(filepath, content) {
  8544. if (yaml$1 === undefined) {
  8545. yaml$1 = yaml;
  8546. }
  8547. try {
  8548. const result = yaml$1.parse(content, {
  8549. prettyErrors: true
  8550. });
  8551. return result;
  8552. } catch (error) {
  8553. error.message = `YAML Error in ${filepath}:\n${error.message}`;
  8554. throw error;
  8555. }
  8556. };
  8557. const loaders = {
  8558. loadJs,
  8559. loadJson,
  8560. loadYaml
  8561. };
  8562. exports.loaders = loaders;
  8563. });
  8564. var getPropertyByPath_2 = getPropertyByPath; // Resolves property names or property paths defined with period-delimited
  8565. // strings or arrays of strings. Property names that are found on the source
  8566. // object are used directly (even if they include a period).
  8567. // Nested property names that include periods, within a path, are only
  8568. // understood in array paths.
  8569. function getPropertyByPath(source, path) {
  8570. if (typeof path === 'string' && Object.prototype.hasOwnProperty.call(source, path)) {
  8571. return source[path];
  8572. }
  8573. const parsedPath = typeof path === 'string' ? path.split('.') : path; // eslint-disable-next-line @typescript-eslint/no-explicit-any
  8574. return parsedPath.reduce((previous, key) => {
  8575. if (previous === undefined) {
  8576. return previous;
  8577. }
  8578. return previous[key];
  8579. }, source);
  8580. }
  8581. var getPropertyByPath_1 = /*#__PURE__*/Object.defineProperty({
  8582. getPropertyByPath: getPropertyByPath_2
  8583. }, '__esModule', {
  8584. value: true
  8585. });
  8586. var ExplorerBase_1 = createCommonjsModule(function (module, exports) {
  8587. Object.defineProperty(exports, "__esModule", {
  8588. value: true
  8589. });
  8590. exports.getExtensionDescription = getExtensionDescription;
  8591. exports.ExplorerBase = void 0;
  8592. var _path = _interopRequireDefault(path__default['default']);
  8593. function _interopRequireDefault(obj) {
  8594. return obj && obj.__esModule ? obj : {
  8595. default: obj
  8596. };
  8597. }
  8598. class ExplorerBase {
  8599. constructor(options) {
  8600. if (options.cache === true) {
  8601. this.loadCache = new Map();
  8602. this.searchCache = new Map();
  8603. }
  8604. this.config = options;
  8605. this.validateConfig();
  8606. }
  8607. clearLoadCache() {
  8608. if (this.loadCache) {
  8609. this.loadCache.clear();
  8610. }
  8611. }
  8612. clearSearchCache() {
  8613. if (this.searchCache) {
  8614. this.searchCache.clear();
  8615. }
  8616. }
  8617. clearCaches() {
  8618. this.clearLoadCache();
  8619. this.clearSearchCache();
  8620. }
  8621. validateConfig() {
  8622. const config = this.config;
  8623. config.searchPlaces.forEach(place => {
  8624. const loaderKey = _path.default.extname(place) || 'noExt';
  8625. const loader = config.loaders[loaderKey];
  8626. if (!loader) {
  8627. throw new Error(`No loader specified for ${getExtensionDescription(place)}, so searchPlaces item "${place}" is invalid`);
  8628. }
  8629. if (typeof loader !== 'function') {
  8630. throw new Error(`loader for ${getExtensionDescription(place)} is not a function (type provided: "${typeof loader}"), so searchPlaces item "${place}" is invalid`);
  8631. }
  8632. });
  8633. }
  8634. shouldSearchStopWithResult(result) {
  8635. if (result === null) return false;
  8636. if (result.isEmpty && this.config.ignoreEmptySearchPlaces) return false;
  8637. return true;
  8638. }
  8639. nextDirectoryToSearch(currentDir, currentResult) {
  8640. if (this.shouldSearchStopWithResult(currentResult)) {
  8641. return null;
  8642. }
  8643. const nextDir = nextDirUp(currentDir);
  8644. if (nextDir === currentDir || currentDir === this.config.stopDir) {
  8645. return null;
  8646. }
  8647. return nextDir;
  8648. }
  8649. loadPackageProp(filepath, content) {
  8650. const parsedContent = loaders_1.loaders.loadJson(filepath, content);
  8651. const packagePropValue = (0, getPropertyByPath_1.getPropertyByPath)(parsedContent, this.config.packageProp);
  8652. return packagePropValue || null;
  8653. }
  8654. getLoaderEntryForFile(filepath) {
  8655. if (_path.default.basename(filepath) === 'package.json') {
  8656. const loader = this.loadPackageProp.bind(this);
  8657. return loader;
  8658. }
  8659. const loaderKey = _path.default.extname(filepath) || 'noExt';
  8660. const loader = this.config.loaders[loaderKey];
  8661. if (!loader) {
  8662. throw new Error(`No loader specified for ${getExtensionDescription(filepath)}`);
  8663. }
  8664. return loader;
  8665. }
  8666. loadedContentToCosmiconfigResult(filepath, loadedContent) {
  8667. if (loadedContent === null) {
  8668. return null;
  8669. }
  8670. if (loadedContent === undefined) {
  8671. return {
  8672. filepath,
  8673. config: undefined,
  8674. isEmpty: true
  8675. };
  8676. }
  8677. return {
  8678. config: loadedContent,
  8679. filepath
  8680. };
  8681. }
  8682. validateFilePath(filepath) {
  8683. if (!filepath) {
  8684. throw new Error('load must pass a non-empty string');
  8685. }
  8686. }
  8687. }
  8688. exports.ExplorerBase = ExplorerBase;
  8689. function nextDirUp(dir) {
  8690. return _path.default.dirname(dir);
  8691. }
  8692. function getExtensionDescription(filepath) {
  8693. const ext = _path.default.extname(filepath);
  8694. return ext ? `extension "${ext}"` : 'files without extensions';
  8695. }
  8696. });
  8697. var readFile_2 = readFile;
  8698. var readFileSync_1 = readFileSync;
  8699. var _fs = _interopRequireDefault$1(fs__default['default']);
  8700. function _interopRequireDefault$1(obj) {
  8701. return obj && obj.__esModule ? obj : {
  8702. default: obj
  8703. };
  8704. }
  8705. async function fsReadFileAsync(pathname, encoding) {
  8706. return new Promise((resolve, reject) => {
  8707. _fs.default.readFile(pathname, encoding, (error, contents) => {
  8708. if (error) {
  8709. reject(error);
  8710. return;
  8711. }
  8712. resolve(contents);
  8713. });
  8714. });
  8715. }
  8716. async function readFile(filepath, options = {}) {
  8717. const throwNotFound = options.throwNotFound === true;
  8718. try {
  8719. const content = await fsReadFileAsync(filepath, 'utf8');
  8720. return content;
  8721. } catch (error) {
  8722. if (throwNotFound === false && (error.code === 'ENOENT' || error.code === 'EISDIR')) {
  8723. return null;
  8724. }
  8725. throw error;
  8726. }
  8727. }
  8728. function readFileSync(filepath, options = {}) {
  8729. const throwNotFound = options.throwNotFound === true;
  8730. try {
  8731. const content = _fs.default.readFileSync(filepath, 'utf8');
  8732. return content;
  8733. } catch (error) {
  8734. if (throwNotFound === false && (error.code === 'ENOENT' || error.code === 'EISDIR')) {
  8735. return null;
  8736. }
  8737. throw error;
  8738. }
  8739. }
  8740. var readFile_1 = /*#__PURE__*/Object.defineProperty({
  8741. readFile: readFile_2,
  8742. readFileSync: readFileSync_1
  8743. }, '__esModule', {
  8744. value: true
  8745. });
  8746. var cacheWrapper_2 = cacheWrapper;
  8747. var cacheWrapperSync_1 = cacheWrapperSync;
  8748. async function cacheWrapper(cache, key, fn) {
  8749. const cached = cache.get(key);
  8750. if (cached !== undefined) {
  8751. return cached;
  8752. }
  8753. const result = await fn();
  8754. cache.set(key, result);
  8755. return result;
  8756. }
  8757. function cacheWrapperSync(cache, key, fn) {
  8758. const cached = cache.get(key);
  8759. if (cached !== undefined) {
  8760. return cached;
  8761. }
  8762. const result = fn();
  8763. cache.set(key, result);
  8764. return result;
  8765. }
  8766. var cacheWrapper_1 = /*#__PURE__*/Object.defineProperty({
  8767. cacheWrapper: cacheWrapper_2,
  8768. cacheWrapperSync: cacheWrapperSync_1
  8769. }, '__esModule', {
  8770. value: true
  8771. });
  8772. const {
  8773. promisify
  8774. } = util__default['default'];
  8775. async function isType(fsStatType, statsMethodName, filePath) {
  8776. if (typeof filePath !== 'string') {
  8777. throw new TypeError(`Expected a string, got ${typeof filePath}`);
  8778. }
  8779. try {
  8780. const stats = await promisify(fs__default['default'][fsStatType])(filePath);
  8781. return stats[statsMethodName]();
  8782. } catch (error) {
  8783. if (error.code === 'ENOENT') {
  8784. return false;
  8785. }
  8786. throw error;
  8787. }
  8788. }
  8789. function isTypeSync(fsStatType, statsMethodName, filePath) {
  8790. if (typeof filePath !== 'string') {
  8791. throw new TypeError(`Expected a string, got ${typeof filePath}`);
  8792. }
  8793. try {
  8794. return fs__default['default'][fsStatType](filePath)[statsMethodName]();
  8795. } catch (error) {
  8796. if (error.code === 'ENOENT') {
  8797. return false;
  8798. }
  8799. throw error;
  8800. }
  8801. }
  8802. var isFile = isType.bind(null, 'stat', 'isFile');
  8803. var isDirectory = isType.bind(null, 'stat', 'isDirectory');
  8804. var isSymlink = isType.bind(null, 'lstat', 'isSymbolicLink');
  8805. var isFileSync = isTypeSync.bind(null, 'statSync', 'isFile');
  8806. var isDirectorySync = isTypeSync.bind(null, 'statSync', 'isDirectory');
  8807. var isSymlinkSync = isTypeSync.bind(null, 'lstatSync', 'isSymbolicLink');
  8808. var pathType = {
  8809. isFile: isFile,
  8810. isDirectory: isDirectory,
  8811. isSymlink: isSymlink,
  8812. isFileSync: isFileSync,
  8813. isDirectorySync: isDirectorySync,
  8814. isSymlinkSync: isSymlinkSync
  8815. };
  8816. var getDirectory_2 = getDirectory;
  8817. var getDirectorySync_1 = getDirectorySync;
  8818. var _path = _interopRequireDefault(path__default['default']);
  8819. function _interopRequireDefault(obj) {
  8820. return obj && obj.__esModule ? obj : {
  8821. default: obj
  8822. };
  8823. }
  8824. async function getDirectory(filepath) {
  8825. const filePathIsDirectory = await (0, pathType.isDirectory)(filepath);
  8826. if (filePathIsDirectory === true) {
  8827. return filepath;
  8828. }
  8829. const directory = _path.default.dirname(filepath);
  8830. return directory;
  8831. }
  8832. function getDirectorySync(filepath) {
  8833. const filePathIsDirectory = (0, pathType.isDirectorySync)(filepath);
  8834. if (filePathIsDirectory === true) {
  8835. return filepath;
  8836. }
  8837. const directory = _path.default.dirname(filepath);
  8838. return directory;
  8839. }
  8840. var getDirectory_1 = /*#__PURE__*/Object.defineProperty({
  8841. getDirectory: getDirectory_2,
  8842. getDirectorySync: getDirectorySync_1
  8843. }, '__esModule', {
  8844. value: true
  8845. });
  8846. var Explorer_1 = createCommonjsModule(function (module, exports) {
  8847. Object.defineProperty(exports, "__esModule", {
  8848. value: true
  8849. });
  8850. exports.Explorer = void 0;
  8851. var _path = _interopRequireDefault(path__default['default']);
  8852. function _interopRequireDefault(obj) {
  8853. return obj && obj.__esModule ? obj : {
  8854. default: obj
  8855. };
  8856. }
  8857. class Explorer extends ExplorerBase_1.ExplorerBase {
  8858. constructor(options) {
  8859. super(options);
  8860. }
  8861. async search(searchFrom = process.cwd()) {
  8862. const startDirectory = await (0, getDirectory_1.getDirectory)(searchFrom);
  8863. const result = await this.searchFromDirectory(startDirectory);
  8864. return result;
  8865. }
  8866. async searchFromDirectory(dir) {
  8867. const absoluteDir = _path.default.resolve(process.cwd(), dir);
  8868. const run = async () => {
  8869. const result = await this.searchDirectory(absoluteDir);
  8870. const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
  8871. if (nextDir) {
  8872. return this.searchFromDirectory(nextDir);
  8873. }
  8874. const transformResult = await this.config.transform(result);
  8875. return transformResult;
  8876. };
  8877. if (this.searchCache) {
  8878. return (0, cacheWrapper_1.cacheWrapper)(this.searchCache, absoluteDir, run);
  8879. }
  8880. return run();
  8881. }
  8882. async searchDirectory(dir) {
  8883. for await (const place of this.config.searchPlaces) {
  8884. const placeResult = await this.loadSearchPlace(dir, place);
  8885. if (this.shouldSearchStopWithResult(placeResult) === true) {
  8886. return placeResult;
  8887. }
  8888. } // config not found
  8889. return null;
  8890. }
  8891. async loadSearchPlace(dir, place) {
  8892. const filepath = _path.default.join(dir, place);
  8893. const fileContents = await (0, readFile_1.readFile)(filepath);
  8894. const result = await this.createCosmiconfigResult(filepath, fileContents);
  8895. return result;
  8896. }
  8897. async loadFileContent(filepath, content) {
  8898. if (content === null) {
  8899. return null;
  8900. }
  8901. if (content.trim() === '') {
  8902. return undefined;
  8903. }
  8904. const loader = this.getLoaderEntryForFile(filepath);
  8905. const loaderResult = await loader(filepath, content);
  8906. return loaderResult;
  8907. }
  8908. async createCosmiconfigResult(filepath, content) {
  8909. const fileContent = await this.loadFileContent(filepath, content);
  8910. const result = this.loadedContentToCosmiconfigResult(filepath, fileContent);
  8911. return result;
  8912. }
  8913. async load(filepath) {
  8914. this.validateFilePath(filepath);
  8915. const absoluteFilePath = _path.default.resolve(process.cwd(), filepath);
  8916. const runLoad = async () => {
  8917. const fileContents = await (0, readFile_1.readFile)(absoluteFilePath, {
  8918. throwNotFound: true
  8919. });
  8920. const result = await this.createCosmiconfigResult(absoluteFilePath, fileContents);
  8921. const transformResult = await this.config.transform(result);
  8922. return transformResult;
  8923. };
  8924. if (this.loadCache) {
  8925. return (0, cacheWrapper_1.cacheWrapper)(this.loadCache, absoluteFilePath, runLoad);
  8926. }
  8927. return runLoad();
  8928. }
  8929. }
  8930. exports.Explorer = Explorer;
  8931. });
  8932. var ExplorerSync_1 = createCommonjsModule(function (module, exports) {
  8933. Object.defineProperty(exports, "__esModule", {
  8934. value: true
  8935. });
  8936. exports.ExplorerSync = void 0;
  8937. var _path = _interopRequireDefault(path__default['default']);
  8938. function _interopRequireDefault(obj) {
  8939. return obj && obj.__esModule ? obj : {
  8940. default: obj
  8941. };
  8942. }
  8943. class ExplorerSync extends ExplorerBase_1.ExplorerBase {
  8944. constructor(options) {
  8945. super(options);
  8946. }
  8947. searchSync(searchFrom = process.cwd()) {
  8948. const startDirectory = (0, getDirectory_1.getDirectorySync)(searchFrom);
  8949. const result = this.searchFromDirectorySync(startDirectory);
  8950. return result;
  8951. }
  8952. searchFromDirectorySync(dir) {
  8953. const absoluteDir = _path.default.resolve(process.cwd(), dir);
  8954. const run = () => {
  8955. const result = this.searchDirectorySync(absoluteDir);
  8956. const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
  8957. if (nextDir) {
  8958. return this.searchFromDirectorySync(nextDir);
  8959. }
  8960. const transformResult = this.config.transform(result);
  8961. return transformResult;
  8962. };
  8963. if (this.searchCache) {
  8964. return (0, cacheWrapper_1.cacheWrapperSync)(this.searchCache, absoluteDir, run);
  8965. }
  8966. return run();
  8967. }
  8968. searchDirectorySync(dir) {
  8969. for (const place of this.config.searchPlaces) {
  8970. const placeResult = this.loadSearchPlaceSync(dir, place);
  8971. if (this.shouldSearchStopWithResult(placeResult) === true) {
  8972. return placeResult;
  8973. }
  8974. } // config not found
  8975. return null;
  8976. }
  8977. loadSearchPlaceSync(dir, place) {
  8978. const filepath = _path.default.join(dir, place);
  8979. const content = (0, readFile_1.readFileSync)(filepath);
  8980. const result = this.createCosmiconfigResultSync(filepath, content);
  8981. return result;
  8982. }
  8983. loadFileContentSync(filepath, content) {
  8984. if (content === null) {
  8985. return null;
  8986. }
  8987. if (content.trim() === '') {
  8988. return undefined;
  8989. }
  8990. const loader = this.getLoaderEntryForFile(filepath);
  8991. const loaderResult = loader(filepath, content);
  8992. return loaderResult;
  8993. }
  8994. createCosmiconfigResultSync(filepath, content) {
  8995. const fileContent = this.loadFileContentSync(filepath, content);
  8996. const result = this.loadedContentToCosmiconfigResult(filepath, fileContent);
  8997. return result;
  8998. }
  8999. loadSync(filepath) {
  9000. this.validateFilePath(filepath);
  9001. const absoluteFilePath = _path.default.resolve(process.cwd(), filepath);
  9002. const runLoadSync = () => {
  9003. const content = (0, readFile_1.readFileSync)(absoluteFilePath, {
  9004. throwNotFound: true
  9005. });
  9006. const cosmiconfigResult = this.createCosmiconfigResultSync(absoluteFilePath, content);
  9007. const transformResult = this.config.transform(cosmiconfigResult);
  9008. return transformResult;
  9009. };
  9010. if (this.loadCache) {
  9011. return (0, cacheWrapper_1.cacheWrapperSync)(this.loadCache, absoluteFilePath, runLoadSync);
  9012. }
  9013. return runLoadSync();
  9014. }
  9015. }
  9016. exports.ExplorerSync = ExplorerSync;
  9017. });
  9018. var dist = createCommonjsModule(function (module, exports) {
  9019. Object.defineProperty(exports, "__esModule", {
  9020. value: true
  9021. });
  9022. exports.cosmiconfig = cosmiconfig;
  9023. exports.cosmiconfigSync = cosmiconfigSync;
  9024. exports.defaultLoaders = void 0;
  9025. var _os = _interopRequireDefault(os__default['default']);
  9026. function _interopRequireDefault(obj) {
  9027. return obj && obj.__esModule ? obj : {
  9028. default: obj
  9029. };
  9030. }
  9031. /* eslint-disable @typescript-eslint/explicit-module-boundary-types */
  9032. // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
  9033. function cosmiconfig(moduleName, options = {}) {
  9034. const normalizedOptions = normalizeOptions(moduleName, options);
  9035. const explorer = new Explorer_1.Explorer(normalizedOptions);
  9036. return {
  9037. search: explorer.search.bind(explorer),
  9038. load: explorer.load.bind(explorer),
  9039. clearLoadCache: explorer.clearLoadCache.bind(explorer),
  9040. clearSearchCache: explorer.clearSearchCache.bind(explorer),
  9041. clearCaches: explorer.clearCaches.bind(explorer)
  9042. };
  9043. } // eslint-disable-next-line @typescript-eslint/explicit-function-return-type
  9044. function cosmiconfigSync(moduleName, options = {}) {
  9045. const normalizedOptions = normalizeOptions(moduleName, options);
  9046. const explorerSync = new ExplorerSync_1.ExplorerSync(normalizedOptions);
  9047. return {
  9048. search: explorerSync.searchSync.bind(explorerSync),
  9049. load: explorerSync.loadSync.bind(explorerSync),
  9050. clearLoadCache: explorerSync.clearLoadCache.bind(explorerSync),
  9051. clearSearchCache: explorerSync.clearSearchCache.bind(explorerSync),
  9052. clearCaches: explorerSync.clearCaches.bind(explorerSync)
  9053. };
  9054. } // do not allow mutation of default loaders. Make sure it is set inside options
  9055. const defaultLoaders = Object.freeze({
  9056. '.cjs': loaders_1.loaders.loadJs,
  9057. '.js': loaders_1.loaders.loadJs,
  9058. '.json': loaders_1.loaders.loadJson,
  9059. '.yaml': loaders_1.loaders.loadYaml,
  9060. '.yml': loaders_1.loaders.loadYaml,
  9061. noExt: loaders_1.loaders.loadYaml
  9062. });
  9063. exports.defaultLoaders = defaultLoaders;
  9064. const identity = function identity(x) {
  9065. return x;
  9066. };
  9067. function normalizeOptions(moduleName, options) {
  9068. const defaults = {
  9069. packageProp: moduleName,
  9070. searchPlaces: ['package.json', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.js`, `.${moduleName}rc.cjs`, `${moduleName}.config.js`, `${moduleName}.config.cjs`],
  9071. ignoreEmptySearchPlaces: true,
  9072. stopDir: _os.default.homedir(),
  9073. cache: true,
  9074. transform: identity,
  9075. loaders: defaultLoaders
  9076. };
  9077. const normalizedOptions = Object.assign(Object.assign(Object.assign({}, defaults), options), {}, {
  9078. loaders: Object.assign(Object.assign({}, defaults.loaders), options.loaders)
  9079. });
  9080. return normalizedOptions;
  9081. }
  9082. });
  9083. var findParentDir = createCommonjsModule(function (module, exports) {
  9084. var exists = fs__default['default'].exists || path__default['default'].exists,
  9085. existsSync = fs__default['default'].existsSync || path__default['default'].existsSync;
  9086. function splitPath(path) {
  9087. var parts = path.split(/(\/|\\)/);
  9088. if (!parts.length) return parts; // when path starts with a slash, the first part is empty string
  9089. return !parts[0].length ? parts.slice(1) : parts;
  9090. }
  9091. exports = module.exports = function (currentFullPath, clue, cb) {
  9092. function testDir(parts) {
  9093. if (parts.length === 0) return cb(null, null);
  9094. var p = parts.join('');
  9095. exists(path__default['default'].join(p, clue), function (itdoes) {
  9096. if (itdoes) return cb(null, p);
  9097. testDir(parts.slice(0, -1));
  9098. });
  9099. }
  9100. testDir(splitPath(currentFullPath));
  9101. };
  9102. exports.sync = function (currentFullPath, clue) {
  9103. function testDir(parts) {
  9104. if (parts.length === 0) return null;
  9105. var p = parts.join('');
  9106. var itdoes = existsSync(path__default['default'].join(p, clue));
  9107. return itdoes ? p : testDir(parts.slice(0, -1));
  9108. }
  9109. return testDir(splitPath(currentFullPath));
  9110. };
  9111. });
  9112. const {
  9113. stdin
  9114. } = process;
  9115. var getStdin = async () => {
  9116. let result = '';
  9117. if (stdin.isTTY) {
  9118. return result;
  9119. }
  9120. stdin.setEncoding('utf8');
  9121. for await (const chunk of stdin) {
  9122. result += chunk;
  9123. }
  9124. return result;
  9125. };
  9126. var buffer = async () => {
  9127. const result = [];
  9128. let length = 0;
  9129. if (stdin.isTTY) {
  9130. return Buffer.concat([]);
  9131. }
  9132. for await (const chunk of stdin) {
  9133. result.push(chunk);
  9134. length += chunk.length;
  9135. }
  9136. return Buffer.concat(result, length);
  9137. };
  9138. getStdin.buffer = buffer;
  9139. var vendors = [
  9140. {
  9141. name: "AppVeyor",
  9142. constant: "APPVEYOR",
  9143. env: "APPVEYOR",
  9144. pr: "APPVEYOR_PULL_REQUEST_NUMBER"
  9145. },
  9146. {
  9147. name: "Azure Pipelines",
  9148. constant: "AZURE_PIPELINES",
  9149. env: "SYSTEM_TEAMFOUNDATIONCOLLECTIONURI",
  9150. pr: "SYSTEM_PULLREQUEST_PULLREQUESTID"
  9151. },
  9152. {
  9153. name: "Appcircle",
  9154. constant: "APPCIRCLE",
  9155. env: "AC_APPCIRCLE"
  9156. },
  9157. {
  9158. name: "Bamboo",
  9159. constant: "BAMBOO",
  9160. env: "bamboo_planKey"
  9161. },
  9162. {
  9163. name: "Bitbucket Pipelines",
  9164. constant: "BITBUCKET",
  9165. env: "BITBUCKET_COMMIT",
  9166. pr: "BITBUCKET_PR_ID"
  9167. },
  9168. {
  9169. name: "Bitrise",
  9170. constant: "BITRISE",
  9171. env: "BITRISE_IO",
  9172. pr: "BITRISE_PULL_REQUEST"
  9173. },
  9174. {
  9175. name: "Buddy",
  9176. constant: "BUDDY",
  9177. env: "BUDDY_WORKSPACE_ID",
  9178. pr: "BUDDY_EXECUTION_PULL_REQUEST_ID"
  9179. },
  9180. {
  9181. name: "Buildkite",
  9182. constant: "BUILDKITE",
  9183. env: "BUILDKITE",
  9184. pr: {
  9185. env: "BUILDKITE_PULL_REQUEST",
  9186. ne: "false"
  9187. }
  9188. },
  9189. {
  9190. name: "CircleCI",
  9191. constant: "CIRCLE",
  9192. env: "CIRCLECI",
  9193. pr: "CIRCLE_PULL_REQUEST"
  9194. },
  9195. {
  9196. name: "Cirrus CI",
  9197. constant: "CIRRUS",
  9198. env: "CIRRUS_CI",
  9199. pr: "CIRRUS_PR"
  9200. },
  9201. {
  9202. name: "AWS CodeBuild",
  9203. constant: "CODEBUILD",
  9204. env: "CODEBUILD_BUILD_ARN"
  9205. },
  9206. {
  9207. name: "Codefresh",
  9208. constant: "CODEFRESH",
  9209. env: "CF_BUILD_ID",
  9210. pr: {
  9211. any: [
  9212. "CF_PULL_REQUEST_NUMBER",
  9213. "CF_PULL_REQUEST_ID"
  9214. ]
  9215. }
  9216. },
  9217. {
  9218. name: "Codeship",
  9219. constant: "CODESHIP",
  9220. env: {
  9221. CI_NAME: "codeship"
  9222. }
  9223. },
  9224. {
  9225. name: "Drone",
  9226. constant: "DRONE",
  9227. env: "DRONE",
  9228. pr: {
  9229. DRONE_BUILD_EVENT: "pull_request"
  9230. }
  9231. },
  9232. {
  9233. name: "dsari",
  9234. constant: "DSARI",
  9235. env: "DSARI"
  9236. },
  9237. {
  9238. name: "GitHub Actions",
  9239. constant: "GITHUB_ACTIONS",
  9240. env: "GITHUB_ACTIONS",
  9241. pr: {
  9242. GITHUB_EVENT_NAME: "pull_request"
  9243. }
  9244. },
  9245. {
  9246. name: "GitLab CI",
  9247. constant: "GITLAB",
  9248. env: "GITLAB_CI",
  9249. pr: "CI_MERGE_REQUEST_ID"
  9250. },
  9251. {
  9252. name: "GoCD",
  9253. constant: "GOCD",
  9254. env: "GO_PIPELINE_LABEL"
  9255. },
  9256. {
  9257. name: "LayerCI",
  9258. constant: "LAYERCI",
  9259. env: "LAYERCI",
  9260. pr: "LAYERCI_PULL_REQUEST"
  9261. },
  9262. {
  9263. name: "Hudson",
  9264. constant: "HUDSON",
  9265. env: "HUDSON_URL"
  9266. },
  9267. {
  9268. name: "Jenkins",
  9269. constant: "JENKINS",
  9270. env: [
  9271. "JENKINS_URL",
  9272. "BUILD_ID"
  9273. ],
  9274. pr: {
  9275. any: [
  9276. "ghprbPullId",
  9277. "CHANGE_ID"
  9278. ]
  9279. }
  9280. },
  9281. {
  9282. name: "Magnum CI",
  9283. constant: "MAGNUM",
  9284. env: "MAGNUM"
  9285. },
  9286. {
  9287. name: "Netlify CI",
  9288. constant: "NETLIFY",
  9289. env: "NETLIFY",
  9290. pr: {
  9291. env: "PULL_REQUEST",
  9292. ne: "false"
  9293. }
  9294. },
  9295. {
  9296. name: "Nevercode",
  9297. constant: "NEVERCODE",
  9298. env: "NEVERCODE",
  9299. pr: {
  9300. env: "NEVERCODE_PULL_REQUEST",
  9301. ne: "false"
  9302. }
  9303. },
  9304. {
  9305. name: "Render",
  9306. constant: "RENDER",
  9307. env: "RENDER",
  9308. pr: {
  9309. IS_PULL_REQUEST: "true"
  9310. }
  9311. },
  9312. {
  9313. name: "Sail CI",
  9314. constant: "SAIL",
  9315. env: "SAILCI",
  9316. pr: "SAIL_PULL_REQUEST_NUMBER"
  9317. },
  9318. {
  9319. name: "Semaphore",
  9320. constant: "SEMAPHORE",
  9321. env: "SEMAPHORE",
  9322. pr: "PULL_REQUEST_NUMBER"
  9323. },
  9324. {
  9325. name: "Screwdriver",
  9326. constant: "SCREWDRIVER",
  9327. env: "SCREWDRIVER",
  9328. pr: {
  9329. env: "SD_PULL_REQUEST",
  9330. ne: "false"
  9331. }
  9332. },
  9333. {
  9334. name: "Shippable",
  9335. constant: "SHIPPABLE",
  9336. env: "SHIPPABLE",
  9337. pr: {
  9338. IS_PULL_REQUEST: "true"
  9339. }
  9340. },
  9341. {
  9342. name: "Solano CI",
  9343. constant: "SOLANO",
  9344. env: "TDDIUM",
  9345. pr: "TDDIUM_PR_ID"
  9346. },
  9347. {
  9348. name: "Strider CD",
  9349. constant: "STRIDER",
  9350. env: "STRIDER"
  9351. },
  9352. {
  9353. name: "TaskCluster",
  9354. constant: "TASKCLUSTER",
  9355. env: [
  9356. "TASK_ID",
  9357. "RUN_ID"
  9358. ]
  9359. },
  9360. {
  9361. name: "TeamCity",
  9362. constant: "TEAMCITY",
  9363. env: "TEAMCITY_VERSION"
  9364. },
  9365. {
  9366. name: "Travis CI",
  9367. constant: "TRAVIS",
  9368. env: "TRAVIS",
  9369. pr: {
  9370. env: "TRAVIS_PULL_REQUEST",
  9371. ne: "false"
  9372. }
  9373. },
  9374. {
  9375. name: "Vercel",
  9376. constant: "VERCEL",
  9377. env: "NOW_BUILDER"
  9378. },
  9379. {
  9380. name: "Visual Studio App Center",
  9381. constant: "APPCENTER",
  9382. env: "APPCENTER_BUILD_ID"
  9383. }
  9384. ];
  9385. var ciInfo = createCommonjsModule(function (module, exports) {
  9386. const env = process.env; // Used for testing only
  9387. Object.defineProperty(exports, '_vendors', {
  9388. value: vendors.map(function (v) {
  9389. return v.constant;
  9390. })
  9391. });
  9392. exports.name = null;
  9393. exports.isPR = null;
  9394. vendors.forEach(function (vendor) {
  9395. const envs = Array.isArray(vendor.env) ? vendor.env : [vendor.env];
  9396. const isCI = envs.every(function (obj) {
  9397. return checkEnv(obj);
  9398. });
  9399. exports[vendor.constant] = isCI;
  9400. if (isCI) {
  9401. exports.name = vendor.name;
  9402. switch (typeof vendor.pr) {
  9403. case 'string':
  9404. // "pr": "CIRRUS_PR"
  9405. exports.isPR = !!env[vendor.pr];
  9406. break;
  9407. case 'object':
  9408. if ('env' in vendor.pr) {
  9409. // "pr": { "env": "BUILDKITE_PULL_REQUEST", "ne": "false" }
  9410. exports.isPR = vendor.pr.env in env && env[vendor.pr.env] !== vendor.pr.ne;
  9411. } else if ('any' in vendor.pr) {
  9412. // "pr": { "any": ["ghprbPullId", "CHANGE_ID"] }
  9413. exports.isPR = vendor.pr.any.some(function (key) {
  9414. return !!env[key];
  9415. });
  9416. } else {
  9417. // "pr": { "DRONE_BUILD_EVENT": "pull_request" }
  9418. exports.isPR = checkEnv(vendor.pr);
  9419. }
  9420. break;
  9421. default:
  9422. // PR detection not supported for this vendor
  9423. exports.isPR = null;
  9424. }
  9425. }
  9426. });
  9427. exports.isCI = !!(env.CI || // Travis CI, CircleCI, Cirrus CI, Gitlab CI, Appveyor, CodeShip, dsari
  9428. env.CONTINUOUS_INTEGRATION || // Travis CI, Cirrus CI
  9429. env.BUILD_NUMBER || // Jenkins, TeamCity
  9430. env.RUN_ID || // TaskCluster, dsari
  9431. exports.name || false);
  9432. function checkEnv(obj) {
  9433. if (typeof obj === 'string') return !!env[obj];
  9434. return Object.keys(obj).every(function (k) {
  9435. return env[k] === obj[k];
  9436. });
  9437. }
  9438. });
  9439. var thirdParty = {
  9440. cosmiconfig: dist.cosmiconfig,
  9441. cosmiconfigSync: dist.cosmiconfigSync,
  9442. findParentDir: findParentDir.sync,
  9443. getStdin: getStdin,
  9444. isCI: () => ciInfo.isCI
  9445. };
  9446. module.exports = thirdParty;