third-party.js 130 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106
  1. 'use strict';
  2. function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
  3. var stream = _interopDefault(require('stream'));
  4. var os = _interopDefault(require('os'));
  5. var path = _interopDefault(require('path'));
  6. var util = _interopDefault(require('util'));
  7. var module$1 = _interopDefault(require('module'));
  8. var fs = _interopDefault(require('fs'));
  9. function commonjsRequire () {
  10. throw new Error('Dynamic requires are not currently supported by rollup-plugin-commonjs');
  11. }
  12. function createCommonjsModule(fn, module) {
  13. return module = { exports: {} }, fn(module, module.exports), module.exports;
  14. }
  15. var bufferStream = createCommonjsModule(function (module) {
  16. 'use strict';
  17. var PassThrough = stream.PassThrough;
  18. module.exports = function (opts) {
  19. opts = Object.assign({}, opts);
  20. var array = opts.array;
  21. var encoding = opts.encoding;
  22. var buffer = encoding === 'buffer';
  23. var objectMode = false;
  24. if (array) {
  25. objectMode = !(encoding || buffer);
  26. } else {
  27. encoding = encoding || 'utf8';
  28. }
  29. if (buffer) {
  30. encoding = null;
  31. }
  32. var len = 0;
  33. var ret = [];
  34. var stream$$1 = new PassThrough({
  35. objectMode
  36. });
  37. if (encoding) {
  38. stream$$1.setEncoding(encoding);
  39. }
  40. stream$$1.on('data', function (chunk) {
  41. ret.push(chunk);
  42. if (objectMode) {
  43. len = ret.length;
  44. } else {
  45. len += chunk.length;
  46. }
  47. });
  48. stream$$1.getBufferedValue = function () {
  49. if (array) {
  50. return ret;
  51. }
  52. return buffer ? Buffer.concat(ret, len) : ret.join('');
  53. };
  54. stream$$1.getBufferedLength = function () {
  55. return len;
  56. };
  57. return stream$$1;
  58. };
  59. });
  60. function getStream(inputStream, opts) {
  61. if (!inputStream) {
  62. return Promise.reject(new Error('Expected a stream'));
  63. }
  64. opts = Object.assign({
  65. maxBuffer: Infinity
  66. }, opts);
  67. var maxBuffer = opts.maxBuffer;
  68. var stream$$1;
  69. var clean;
  70. var p = new Promise(function (resolve, reject) {
  71. var error = function error(err) {
  72. if (err) {
  73. // null check
  74. err.bufferedData = stream$$1.getBufferedValue();
  75. }
  76. reject(err);
  77. };
  78. stream$$1 = bufferStream(opts);
  79. inputStream.once('error', error);
  80. inputStream.pipe(stream$$1);
  81. stream$$1.on('data', function () {
  82. if (stream$$1.getBufferedLength() > maxBuffer) {
  83. reject(new Error('maxBuffer exceeded'));
  84. }
  85. });
  86. stream$$1.once('error', error);
  87. stream$$1.on('end', resolve);
  88. clean = function clean() {
  89. // some streams doesn't implement the `stream.Readable` interface correctly
  90. if (inputStream.unpipe) {
  91. inputStream.unpipe(stream$$1);
  92. }
  93. };
  94. });
  95. p.then(clean, clean);
  96. return p.then(function () {
  97. return stream$$1.getBufferedValue();
  98. });
  99. }
  100. var getStream_1 = getStream;
  101. var buffer = function buffer(stream$$1, opts) {
  102. return getStream(stream$$1, Object.assign({}, opts, {
  103. encoding: 'buffer'
  104. }));
  105. };
  106. var array = function array(stream$$1, opts) {
  107. return getStream(stream$$1, Object.assign({}, opts, {
  108. array: true
  109. }));
  110. };
  111. getStream_1.buffer = buffer;
  112. getStream_1.array = array;
  113. function _classCallCheck(instance, Constructor) {
  114. if (!(instance instanceof Constructor)) {
  115. throw new TypeError("Cannot call a class as a function");
  116. }
  117. }
  118. function _defineProperties(target, props) {
  119. for (var i = 0; i < props.length; i++) {
  120. var descriptor = props[i];
  121. descriptor.enumerable = descriptor.enumerable || false;
  122. descriptor.configurable = true;
  123. if ("value" in descriptor) descriptor.writable = true;
  124. Object.defineProperty(target, descriptor.key, descriptor);
  125. }
  126. }
  127. function _createClass(Constructor, protoProps, staticProps) {
  128. if (protoProps) _defineProperties(Constructor.prototype, protoProps);
  129. if (staticProps) _defineProperties(Constructor, staticProps);
  130. return Constructor;
  131. }
  132. function _toArray(arr) {
  133. return _arrayWithHoles(arr) || _iterableToArray(arr) || _nonIterableRest();
  134. }
  135. function _arrayWithHoles(arr) {
  136. if (Array.isArray(arr)) return arr;
  137. }
  138. function _iterableToArray(iter) {
  139. if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter);
  140. }
  141. function _nonIterableRest() {
  142. throw new TypeError("Invalid attempt to destructure non-iterable instance");
  143. }
  144. function _toPrimitive(input, hint) {
  145. if (typeof input !== "object" || input === null) return input;
  146. var prim = input[Symbol.toPrimitive];
  147. if (prim !== undefined) {
  148. var res = prim.call(input, hint || "default");
  149. if (typeof res !== "object") return res;
  150. throw new TypeError("@@toPrimitive must return a primitive value.");
  151. }
  152. return (hint === "string" ? String : Number)(input);
  153. }
  154. function _toPropertyKey(arg) {
  155. var key = _toPrimitive(arg, "string");
  156. return typeof key === "symbol" ? key : String(key);
  157. }
  158. function _addElementPlacement(element, placements, silent) {
  159. var keys = placements[element.placement];
  160. if (!silent && keys.indexOf(element.key) !== -1) {
  161. throw new TypeError("Duplicated element (" + element.key + ")");
  162. }
  163. keys.push(element.key);
  164. }
  165. function _fromElementDescriptor(element) {
  166. var obj = {
  167. kind: element.kind,
  168. key: element.key,
  169. placement: element.placement,
  170. descriptor: element.descriptor
  171. };
  172. var desc = {
  173. value: "Descriptor",
  174. configurable: true
  175. };
  176. Object.defineProperty(obj, Symbol.toStringTag, desc);
  177. if (element.kind === "field") obj.initializer = element.initializer;
  178. return obj;
  179. }
  180. function _toElementDescriptors(elementObjects) {
  181. if (elementObjects === undefined) return;
  182. return _toArray(elementObjects).map(function (elementObject) {
  183. var element = _toElementDescriptor(elementObject);
  184. _disallowProperty(elementObject, "finisher", "An element descriptor");
  185. _disallowProperty(elementObject, "extras", "An element descriptor");
  186. return element;
  187. });
  188. }
  189. function _toElementDescriptor(elementObject) {
  190. var kind = String(elementObject.kind);
  191. if (kind !== "method" && kind !== "field") {
  192. throw new TypeError('An element descriptor\'s .kind property must be either "method" or' + ' "field", but a decorator created an element descriptor with' + ' .kind "' + kind + '"');
  193. }
  194. var key = _toPropertyKey(elementObject.key);
  195. var placement = String(elementObject.placement);
  196. if (placement !== "static" && placement !== "prototype" && placement !== "own") {
  197. throw new TypeError('An element descriptor\'s .placement property must be one of "static",' + ' "prototype" or "own", but a decorator created an element descriptor' + ' with .placement "' + placement + '"');
  198. }
  199. var descriptor = elementObject.descriptor;
  200. _disallowProperty(elementObject, "elements", "An element descriptor");
  201. var element = {
  202. kind: kind,
  203. key: key,
  204. placement: placement,
  205. descriptor: Object.assign({}, descriptor)
  206. };
  207. if (kind !== "field") {
  208. _disallowProperty(elementObject, "initializer", "A method descriptor");
  209. } else {
  210. _disallowProperty(descriptor, "get", "The property descriptor of a field descriptor");
  211. _disallowProperty(descriptor, "set", "The property descriptor of a field descriptor");
  212. _disallowProperty(descriptor, "value", "The property descriptor of a field descriptor");
  213. element.initializer = elementObject.initializer;
  214. }
  215. return element;
  216. }
  217. function _toElementFinisherExtras(elementObject) {
  218. var element = _toElementDescriptor(elementObject);
  219. var finisher = _optionalCallableProperty(elementObject, "finisher");
  220. var extras = _toElementDescriptors(elementObject.extras);
  221. return {
  222. element: element,
  223. finisher: finisher,
  224. extras: extras
  225. };
  226. }
  227. function _fromClassDescriptor(elements) {
  228. var obj = {
  229. kind: "class",
  230. elements: elements.map(_fromElementDescriptor)
  231. };
  232. var desc = {
  233. value: "Descriptor",
  234. configurable: true
  235. };
  236. Object.defineProperty(obj, Symbol.toStringTag, desc);
  237. return obj;
  238. }
  239. function _toClassDescriptor(obj) {
  240. var kind = String(obj.kind);
  241. if (kind !== "class") {
  242. throw new TypeError('A class descriptor\'s .kind property must be "class", but a decorator' + ' created a class descriptor with .kind "' + kind + '"');
  243. }
  244. _disallowProperty(obj, "key", "A class descriptor");
  245. _disallowProperty(obj, "placement", "A class descriptor");
  246. _disallowProperty(obj, "descriptor", "A class descriptor");
  247. _disallowProperty(obj, "initializer", "A class descriptor");
  248. _disallowProperty(obj, "extras", "A class descriptor");
  249. var finisher = _optionalCallableProperty(obj, "finisher");
  250. var elements = _toElementDescriptors(obj.elements);
  251. return {
  252. elements: elements,
  253. finisher: finisher
  254. };
  255. }
  256. function _disallowProperty(obj, name, objectType) {
  257. if (obj[name] !== undefined) {
  258. throw new TypeError(objectType + " can't have a ." + name + " property.");
  259. }
  260. }
  261. function _optionalCallableProperty(obj, name) {
  262. var value = obj[name];
  263. if (value !== undefined && typeof value !== "function") {
  264. throw new TypeError("Expected '" + name + "' to be a function");
  265. }
  266. return value;
  267. }
  268. var isArrayish = function isArrayish(obj) {
  269. if (!obj) {
  270. return false;
  271. }
  272. return obj instanceof Array || Array.isArray(obj) || obj.length >= 0 && obj.splice instanceof Function;
  273. };
  274. var errorEx = function errorEx(name, properties) {
  275. if (!name || name.constructor !== String) {
  276. properties = name || {};
  277. name = Error.name;
  278. }
  279. var errorExError = function ErrorEXError(message) {
  280. if (!this) {
  281. return new ErrorEXError(message);
  282. }
  283. message = message instanceof Error ? message.message : message || this.message;
  284. Error.call(this, message);
  285. Error.captureStackTrace(this, errorExError);
  286. this.name = name;
  287. Object.defineProperty(this, 'message', {
  288. configurable: true,
  289. enumerable: false,
  290. get: function get() {
  291. var newMessage = message.split(/\r?\n/g);
  292. for (var key in properties) {
  293. if (!properties.hasOwnProperty(key)) {
  294. continue;
  295. }
  296. var modifier = properties[key];
  297. if ('message' in modifier) {
  298. newMessage = modifier.message(this[key], newMessage) || newMessage;
  299. if (!isArrayish(newMessage)) {
  300. newMessage = [newMessage];
  301. }
  302. }
  303. }
  304. return newMessage.join('\n');
  305. },
  306. set: function set(v) {
  307. message = v;
  308. }
  309. });
  310. var overwrittenStack = null;
  311. var stackDescriptor = Object.getOwnPropertyDescriptor(this, 'stack');
  312. var stackGetter = stackDescriptor.get;
  313. var stackValue = stackDescriptor.value;
  314. delete stackDescriptor.value;
  315. delete stackDescriptor.writable;
  316. stackDescriptor.set = function (newstack) {
  317. overwrittenStack = newstack;
  318. };
  319. stackDescriptor.get = function () {
  320. var stack = (overwrittenStack || (stackGetter ? stackGetter.call(this) : stackValue)).split(/\r?\n+/g); // starting in Node 7, the stack builder caches the message.
  321. // just replace it.
  322. if (!overwrittenStack) {
  323. stack[0] = this.name + ': ' + this.message;
  324. }
  325. var lineCount = 1;
  326. for (var key in properties) {
  327. if (!properties.hasOwnProperty(key)) {
  328. continue;
  329. }
  330. var modifier = properties[key];
  331. if ('line' in modifier) {
  332. var line = modifier.line(this[key]);
  333. if (line) {
  334. stack.splice(lineCount++, 0, ' ' + line);
  335. }
  336. }
  337. if ('stack' in modifier) {
  338. modifier.stack(this[key], stack);
  339. }
  340. }
  341. return stack.join('\n');
  342. };
  343. Object.defineProperty(this, 'stack', stackDescriptor);
  344. };
  345. if (Object.setPrototypeOf) {
  346. Object.setPrototypeOf(errorExError.prototype, Error.prototype);
  347. Object.setPrototypeOf(errorExError, Error);
  348. } else {
  349. util.inherits(errorExError, Error);
  350. }
  351. return errorExError;
  352. };
  353. errorEx.append = function (str, def) {
  354. return {
  355. message: function message(v, _message) {
  356. v = v || def;
  357. if (v) {
  358. _message[0] += ' ' + str.replace('%s', v.toString());
  359. }
  360. return _message;
  361. }
  362. };
  363. };
  364. errorEx.line = function (str, def) {
  365. return {
  366. line: function line(v) {
  367. v = v || def;
  368. if (v) {
  369. return str.replace('%s', v.toString());
  370. }
  371. return null;
  372. }
  373. };
  374. };
  375. var errorEx_1 = errorEx;
  376. var jsonParseBetterErrors = parseJson$2;
  377. function parseJson$2(txt, reviver, context) {
  378. context = context || 20;
  379. try {
  380. return JSON.parse(txt, reviver);
  381. } catch (e) {
  382. if (typeof txt !== 'string') {
  383. var isEmptyArray = Array.isArray(txt) && txt.length === 0;
  384. var errorMessage = 'Cannot parse ' + (isEmptyArray ? 'an empty array' : String(txt));
  385. throw new TypeError(errorMessage);
  386. }
  387. var syntaxErr = e.message.match(/^Unexpected token.*position\s+(\d+)/i);
  388. var errIdx = syntaxErr ? +syntaxErr[1] : e.message.match(/^Unexpected end of JSON.*/i) ? txt.length - 1 : null;
  389. if (errIdx != null) {
  390. var start = errIdx <= context ? 0 : errIdx - context;
  391. var end = errIdx + context >= txt.length ? txt.length : errIdx + context;
  392. e.message += ` while parsing near '${start === 0 ? '' : '...'}${txt.slice(start, end)}${end === txt.length ? '' : '...'}'`;
  393. } else {
  394. e.message += ` while parsing '${txt.slice(0, context * 2)}'`;
  395. }
  396. throw e;
  397. }
  398. }
  399. var parseJson = createCommonjsModule(function (module) {
  400. 'use strict';
  401. var JSONError = errorEx_1('JSONError', {
  402. fileName: errorEx_1.append('in %s')
  403. });
  404. module.exports = function (input, reviver, filename) {
  405. if (typeof reviver === 'string') {
  406. filename = reviver;
  407. reviver = null;
  408. }
  409. try {
  410. try {
  411. return JSON.parse(input, reviver);
  412. } catch (err) {
  413. jsonParseBetterErrors(input, reviver);
  414. throw err;
  415. }
  416. } catch (err) {
  417. err.message = err.message.replace(/\n/g, '');
  418. var jsonErr = new JSONError(err);
  419. if (filename) {
  420. jsonErr.fileName = filename;
  421. }
  422. throw jsonErr;
  423. }
  424. };
  425. });
  426. function isNothing(subject) {
  427. return typeof subject === 'undefined' || subject === null;
  428. }
  429. function isObject(subject) {
  430. return typeof subject === 'object' && subject !== null;
  431. }
  432. function toArray(sequence) {
  433. if (Array.isArray(sequence)) return sequence;else if (isNothing(sequence)) return [];
  434. return [sequence];
  435. }
  436. function extend(target, source) {
  437. var index, length, key, sourceKeys;
  438. if (source) {
  439. sourceKeys = Object.keys(source);
  440. for (index = 0, length = sourceKeys.length; index < length; index += 1) {
  441. key = sourceKeys[index];
  442. target[key] = source[key];
  443. }
  444. }
  445. return target;
  446. }
  447. function repeat(string, count) {
  448. var result = '',
  449. cycle;
  450. for (cycle = 0; cycle < count; cycle += 1) {
  451. result += string;
  452. }
  453. return result;
  454. }
  455. function isNegativeZero(number) {
  456. return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
  457. }
  458. var isNothing_1 = isNothing;
  459. var isObject_1 = isObject;
  460. var toArray_1 = toArray;
  461. var repeat_1 = repeat;
  462. var isNegativeZero_1 = isNegativeZero;
  463. var extend_1 = extend;
  464. var common = {
  465. isNothing: isNothing_1,
  466. isObject: isObject_1,
  467. toArray: toArray_1,
  468. repeat: repeat_1,
  469. isNegativeZero: isNegativeZero_1,
  470. extend: extend_1
  471. };
  472. // YAML error class. http://stackoverflow.com/questions/8458984
  473. //
  474. function YAMLException$1(reason, mark) {
  475. // Super constructor
  476. Error.call(this);
  477. this.name = 'YAMLException';
  478. this.reason = reason;
  479. this.mark = mark;
  480. this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : ''); // Include stack trace in error object
  481. if (Error.captureStackTrace) {
  482. // Chrome and NodeJS
  483. Error.captureStackTrace(this, this.constructor);
  484. } else {
  485. // FF, IE 10+ and Safari 6+. Fallback for others
  486. this.stack = new Error().stack || '';
  487. }
  488. } // Inherit from Error
  489. YAMLException$1.prototype = Object.create(Error.prototype);
  490. YAMLException$1.prototype.constructor = YAMLException$1;
  491. YAMLException$1.prototype.toString = function toString(compact) {
  492. var result = this.name + ': ';
  493. result += this.reason || '(unknown reason)';
  494. if (!compact && this.mark) {
  495. result += ' ' + this.mark.toString();
  496. }
  497. return result;
  498. };
  499. var exception = YAMLException$1;
  500. function Mark(name, buffer, position, line, column) {
  501. this.name = name;
  502. this.buffer = buffer;
  503. this.position = position;
  504. this.line = line;
  505. this.column = column;
  506. }
  507. Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {
  508. var head, start, tail, end, snippet;
  509. if (!this.buffer) return null;
  510. indent = indent || 4;
  511. maxLength = maxLength || 75;
  512. head = '';
  513. start = this.position;
  514. while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
  515. start -= 1;
  516. if (this.position - start > maxLength / 2 - 1) {
  517. head = ' ... ';
  518. start += 5;
  519. break;
  520. }
  521. }
  522. tail = '';
  523. end = this.position;
  524. while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
  525. end += 1;
  526. if (end - this.position > maxLength / 2 - 1) {
  527. tail = ' ... ';
  528. end -= 5;
  529. break;
  530. }
  531. }
  532. snippet = this.buffer.slice(start, end);
  533. return common.repeat(' ', indent) + head + snippet + tail + '\n' + common.repeat(' ', indent + this.position - start + head.length) + '^';
  534. };
  535. Mark.prototype.toString = function toString(compact) {
  536. var snippet,
  537. where = '';
  538. if (this.name) {
  539. where += 'in "' + this.name + '" ';
  540. }
  541. where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
  542. if (!compact) {
  543. snippet = this.getSnippet();
  544. if (snippet) {
  545. where += ':\n' + snippet;
  546. }
  547. }
  548. return where;
  549. };
  550. var mark = Mark;
  551. var TYPE_CONSTRUCTOR_OPTIONS = ['kind', 'resolve', 'construct', 'instanceOf', 'predicate', 'represent', 'defaultStyle', 'styleAliases'];
  552. var YAML_NODE_KINDS = ['scalar', 'sequence', 'mapping'];
  553. function compileStyleAliases(map) {
  554. var result = {};
  555. if (map !== null) {
  556. Object.keys(map).forEach(function (style) {
  557. map[style].forEach(function (alias) {
  558. result[String(alias)] = style;
  559. });
  560. });
  561. }
  562. return result;
  563. }
  564. function Type$1(tag, options) {
  565. options = options || {};
  566. Object.keys(options).forEach(function (name) {
  567. if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
  568. throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
  569. }
  570. }); // TODO: Add tag format check.
  571. this.tag = tag;
  572. this.kind = options['kind'] || null;
  573. this.resolve = options['resolve'] || function () {
  574. return true;
  575. };
  576. this.construct = options['construct'] || function (data) {
  577. return data;
  578. };
  579. this.instanceOf = options['instanceOf'] || null;
  580. this.predicate = options['predicate'] || null;
  581. this.represent = options['represent'] || null;
  582. this.defaultStyle = options['defaultStyle'] || null;
  583. this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
  584. if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
  585. throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
  586. }
  587. }
  588. var type = Type$1;
  589. /*eslint-disable max-len*/
  590. function compileList(schema, name, result) {
  591. var exclude = [];
  592. schema.include.forEach(function (includedSchema) {
  593. result = compileList(includedSchema, name, result);
  594. });
  595. schema[name].forEach(function (currentType) {
  596. result.forEach(function (previousType, previousIndex) {
  597. if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) {
  598. exclude.push(previousIndex);
  599. }
  600. });
  601. result.push(currentType);
  602. });
  603. return result.filter(function (type$$1, index) {
  604. return exclude.indexOf(index) === -1;
  605. });
  606. }
  607. function compileMap()
  608. /* lists... */
  609. {
  610. var result = {
  611. scalar: {},
  612. sequence: {},
  613. mapping: {},
  614. fallback: {}
  615. },
  616. index,
  617. length;
  618. function collectType(type$$1) {
  619. result[type$$1.kind][type$$1.tag] = result['fallback'][type$$1.tag] = type$$1;
  620. }
  621. for (index = 0, length = arguments.length; index < length; index += 1) {
  622. arguments[index].forEach(collectType);
  623. }
  624. return result;
  625. }
  626. function Schema$1(definition) {
  627. this.include = definition.include || [];
  628. this.implicit = definition.implicit || [];
  629. this.explicit = definition.explicit || [];
  630. this.implicit.forEach(function (type$$1) {
  631. if (type$$1.loadKind && type$$1.loadKind !== 'scalar') {
  632. throw new exception('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
  633. }
  634. });
  635. this.compiledImplicit = compileList(this, 'implicit', []);
  636. this.compiledExplicit = compileList(this, 'explicit', []);
  637. this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
  638. }
  639. Schema$1.DEFAULT = null;
  640. Schema$1.create = function createSchema() {
  641. var schemas, types;
  642. switch (arguments.length) {
  643. case 1:
  644. schemas = Schema$1.DEFAULT;
  645. types = arguments[0];
  646. break;
  647. case 2:
  648. schemas = arguments[0];
  649. types = arguments[1];
  650. break;
  651. default:
  652. throw new exception('Wrong number of arguments for Schema.create function');
  653. }
  654. schemas = common.toArray(schemas);
  655. types = common.toArray(types);
  656. if (!schemas.every(function (schema) {
  657. return schema instanceof Schema$1;
  658. })) {
  659. throw new exception('Specified list of super schemas (or a single Schema object) contains a non-Schema object.');
  660. }
  661. if (!types.every(function (type$$1) {
  662. return type$$1 instanceof type;
  663. })) {
  664. throw new exception('Specified list of YAML types (or a single Type object) contains a non-Type object.');
  665. }
  666. return new Schema$1({
  667. include: schemas,
  668. explicit: types
  669. });
  670. };
  671. var schema = Schema$1;
  672. var str = new type('tag:yaml.org,2002:str', {
  673. kind: 'scalar',
  674. construct: function construct(data) {
  675. return data !== null ? data : '';
  676. }
  677. });
  678. var seq = new type('tag:yaml.org,2002:seq', {
  679. kind: 'sequence',
  680. construct: function construct(data) {
  681. return data !== null ? data : [];
  682. }
  683. });
  684. var map = new type('tag:yaml.org,2002:map', {
  685. kind: 'mapping',
  686. construct: function construct(data) {
  687. return data !== null ? data : {};
  688. }
  689. });
  690. var failsafe = new schema({
  691. explicit: [str, seq, map]
  692. });
  693. function resolveYamlNull(data) {
  694. if (data === null) return true;
  695. var max = data.length;
  696. return max === 1 && data === '~' || max === 4 && (data === 'null' || data === 'Null' || data === 'NULL');
  697. }
  698. function constructYamlNull() {
  699. return null;
  700. }
  701. function isNull(object) {
  702. return object === null;
  703. }
  704. var _null = new type('tag:yaml.org,2002:null', {
  705. kind: 'scalar',
  706. resolve: resolveYamlNull,
  707. construct: constructYamlNull,
  708. predicate: isNull,
  709. represent: {
  710. canonical: function canonical() {
  711. return '~';
  712. },
  713. lowercase: function lowercase() {
  714. return 'null';
  715. },
  716. uppercase: function uppercase() {
  717. return 'NULL';
  718. },
  719. camelcase: function camelcase() {
  720. return 'Null';
  721. }
  722. },
  723. defaultStyle: 'lowercase'
  724. });
  725. function resolveYamlBoolean(data) {
  726. if (data === null) return false;
  727. var max = data.length;
  728. return max === 4 && (data === 'true' || data === 'True' || data === 'TRUE') || max === 5 && (data === 'false' || data === 'False' || data === 'FALSE');
  729. }
  730. function constructYamlBoolean(data) {
  731. return data === 'true' || data === 'True' || data === 'TRUE';
  732. }
  733. function isBoolean(object) {
  734. return Object.prototype.toString.call(object) === '[object Boolean]';
  735. }
  736. var bool = new type('tag:yaml.org,2002:bool', {
  737. kind: 'scalar',
  738. resolve: resolveYamlBoolean,
  739. construct: constructYamlBoolean,
  740. predicate: isBoolean,
  741. represent: {
  742. lowercase: function lowercase(object) {
  743. return object ? 'true' : 'false';
  744. },
  745. uppercase: function uppercase(object) {
  746. return object ? 'TRUE' : 'FALSE';
  747. },
  748. camelcase: function camelcase(object) {
  749. return object ? 'True' : 'False';
  750. }
  751. },
  752. defaultStyle: 'lowercase'
  753. });
  754. function isHexCode(c) {
  755. return 0x30
  756. /* 0 */
  757. <= c && c <= 0x39
  758. /* 9 */
  759. || 0x41
  760. /* A */
  761. <= c && c <= 0x46
  762. /* F */
  763. || 0x61
  764. /* a */
  765. <= c && c <= 0x66
  766. /* f */
  767. ;
  768. }
  769. function isOctCode(c) {
  770. return 0x30
  771. /* 0 */
  772. <= c && c <= 0x37
  773. /* 7 */
  774. ;
  775. }
  776. function isDecCode(c) {
  777. return 0x30
  778. /* 0 */
  779. <= c && c <= 0x39
  780. /* 9 */
  781. ;
  782. }
  783. function resolveYamlInteger(data) {
  784. if (data === null) return false;
  785. var max = data.length,
  786. index = 0,
  787. hasDigits = false,
  788. ch;
  789. if (!max) return false;
  790. ch = data[index]; // sign
  791. if (ch === '-' || ch === '+') {
  792. ch = data[++index];
  793. }
  794. if (ch === '0') {
  795. // 0
  796. if (index + 1 === max) return true;
  797. ch = data[++index]; // base 2, base 8, base 16
  798. if (ch === 'b') {
  799. // base 2
  800. index++;
  801. for (; index < max; index++) {
  802. ch = data[index];
  803. if (ch === '_') continue;
  804. if (ch !== '0' && ch !== '1') return false;
  805. hasDigits = true;
  806. }
  807. return hasDigits && ch !== '_';
  808. }
  809. if (ch === 'x') {
  810. // base 16
  811. index++;
  812. for (; index < max; index++) {
  813. ch = data[index];
  814. if (ch === '_') continue;
  815. if (!isHexCode(data.charCodeAt(index))) return false;
  816. hasDigits = true;
  817. }
  818. return hasDigits && ch !== '_';
  819. } // base 8
  820. for (; index < max; index++) {
  821. ch = data[index];
  822. if (ch === '_') continue;
  823. if (!isOctCode(data.charCodeAt(index))) return false;
  824. hasDigits = true;
  825. }
  826. return hasDigits && ch !== '_';
  827. } // base 10 (except 0) or base 60
  828. // value should not start with `_`;
  829. if (ch === '_') return false;
  830. for (; index < max; index++) {
  831. ch = data[index];
  832. if (ch === '_') continue;
  833. if (ch === ':') break;
  834. if (!isDecCode(data.charCodeAt(index))) {
  835. return false;
  836. }
  837. hasDigits = true;
  838. } // Should have digits and should not end with `_`
  839. if (!hasDigits || ch === '_') return false; // if !base60 - done;
  840. if (ch !== ':') return true; // base60 almost not used, no needs to optimize
  841. return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
  842. }
  843. function constructYamlInteger(data) {
  844. var value = data,
  845. sign = 1,
  846. ch,
  847. base,
  848. digits = [];
  849. if (value.indexOf('_') !== -1) {
  850. value = value.replace(/_/g, '');
  851. }
  852. ch = value[0];
  853. if (ch === '-' || ch === '+') {
  854. if (ch === '-') sign = -1;
  855. value = value.slice(1);
  856. ch = value[0];
  857. }
  858. if (value === '0') return 0;
  859. if (ch === '0') {
  860. if (value[1] === 'b') return sign * parseInt(value.slice(2), 2);
  861. if (value[1] === 'x') return sign * parseInt(value, 16);
  862. return sign * parseInt(value, 8);
  863. }
  864. if (value.indexOf(':') !== -1) {
  865. value.split(':').forEach(function (v) {
  866. digits.unshift(parseInt(v, 10));
  867. });
  868. value = 0;
  869. base = 1;
  870. digits.forEach(function (d) {
  871. value += d * base;
  872. base *= 60;
  873. });
  874. return sign * value;
  875. }
  876. return sign * parseInt(value, 10);
  877. }
  878. function isInteger(object) {
  879. return Object.prototype.toString.call(object) === '[object Number]' && object % 1 === 0 && !common.isNegativeZero(object);
  880. }
  881. var int_1 = new type('tag:yaml.org,2002:int', {
  882. kind: 'scalar',
  883. resolve: resolveYamlInteger,
  884. construct: constructYamlInteger,
  885. predicate: isInteger,
  886. represent: {
  887. binary: function binary(obj) {
  888. return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1);
  889. },
  890. octal: function octal(obj) {
  891. return obj >= 0 ? '0' + obj.toString(8) : '-0' + obj.toString(8).slice(1);
  892. },
  893. decimal: function decimal(obj) {
  894. return obj.toString(10);
  895. },
  896. /* eslint-disable max-len */
  897. hexadecimal: function hexadecimal(obj) {
  898. return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1);
  899. }
  900. },
  901. defaultStyle: 'decimal',
  902. styleAliases: {
  903. binary: [2, 'bin'],
  904. octal: [8, 'oct'],
  905. decimal: [10, 'dec'],
  906. hexadecimal: [16, 'hex']
  907. }
  908. });
  909. var YAML_FLOAT_PATTERN = new RegExp( // 2.5e4, 2.5 and integers
  910. '^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' + // .2e4, .2
  911. // special case, seems not from spec
  912. '|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' + // 20:59
  913. '|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' + // .inf
  914. '|[-+]?\\.(?:inf|Inf|INF)' + // .nan
  915. '|\\.(?:nan|NaN|NAN))$');
  916. function resolveYamlFloat(data) {
  917. if (data === null) return false;
  918. if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
  919. // Probably should update regexp & check speed
  920. data[data.length - 1] === '_') {
  921. return false;
  922. }
  923. return true;
  924. }
  925. function constructYamlFloat(data) {
  926. var value, sign, base, digits;
  927. value = data.replace(/_/g, '').toLowerCase();
  928. sign = value[0] === '-' ? -1 : 1;
  929. digits = [];
  930. if ('+-'.indexOf(value[0]) >= 0) {
  931. value = value.slice(1);
  932. }
  933. if (value === '.inf') {
  934. return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
  935. } else if (value === '.nan') {
  936. return NaN;
  937. } else if (value.indexOf(':') >= 0) {
  938. value.split(':').forEach(function (v) {
  939. digits.unshift(parseFloat(v, 10));
  940. });
  941. value = 0.0;
  942. base = 1;
  943. digits.forEach(function (d) {
  944. value += d * base;
  945. base *= 60;
  946. });
  947. return sign * value;
  948. }
  949. return sign * parseFloat(value, 10);
  950. }
  951. var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
  952. function representYamlFloat(object, style) {
  953. var res;
  954. if (isNaN(object)) {
  955. switch (style) {
  956. case 'lowercase':
  957. return '.nan';
  958. case 'uppercase':
  959. return '.NAN';
  960. case 'camelcase':
  961. return '.NaN';
  962. }
  963. } else if (Number.POSITIVE_INFINITY === object) {
  964. switch (style) {
  965. case 'lowercase':
  966. return '.inf';
  967. case 'uppercase':
  968. return '.INF';
  969. case 'camelcase':
  970. return '.Inf';
  971. }
  972. } else if (Number.NEGATIVE_INFINITY === object) {
  973. switch (style) {
  974. case 'lowercase':
  975. return '-.inf';
  976. case 'uppercase':
  977. return '-.INF';
  978. case 'camelcase':
  979. return '-.Inf';
  980. }
  981. } else if (common.isNegativeZero(object)) {
  982. return '-0.0';
  983. }
  984. res = object.toString(10); // JS stringifier can build scientific format without dots: 5e-100,
  985. // while YAML requres dot: 5.e-100. Fix it with simple hack
  986. return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
  987. }
  988. function isFloat(object) {
  989. return Object.prototype.toString.call(object) === '[object Number]' && (object % 1 !== 0 || common.isNegativeZero(object));
  990. }
  991. var float_1 = new type('tag:yaml.org,2002:float', {
  992. kind: 'scalar',
  993. resolve: resolveYamlFloat,
  994. construct: constructYamlFloat,
  995. predicate: isFloat,
  996. represent: representYamlFloat,
  997. defaultStyle: 'lowercase'
  998. });
  999. var json = new schema({
  1000. include: [failsafe],
  1001. implicit: [_null, bool, int_1, float_1]
  1002. });
  1003. var core = new schema({
  1004. include: [json]
  1005. });
  1006. var YAML_DATE_REGEXP = new RegExp('^([0-9][0-9][0-9][0-9])' + // [1] year
  1007. '-([0-9][0-9])' + // [2] month
  1008. '-([0-9][0-9])$'); // [3] day
  1009. var YAML_TIMESTAMP_REGEXP = new RegExp('^([0-9][0-9][0-9][0-9])' + // [1] year
  1010. '-([0-9][0-9]?)' + // [2] month
  1011. '-([0-9][0-9]?)' + // [3] day
  1012. '(?:[Tt]|[ \\t]+)' + // ...
  1013. '([0-9][0-9]?)' + // [4] hour
  1014. ':([0-9][0-9])' + // [5] minute
  1015. ':([0-9][0-9])' + // [6] second
  1016. '(?:\\.([0-9]*))?' + // [7] fraction
  1017. '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
  1018. '(?::([0-9][0-9]))?))?$'); // [11] tz_minute
  1019. function resolveYamlTimestamp(data) {
  1020. if (data === null) return false;
  1021. if (YAML_DATE_REGEXP.exec(data) !== null) return true;
  1022. if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
  1023. return false;
  1024. }
  1025. function constructYamlTimestamp(data) {
  1026. var match,
  1027. year,
  1028. month,
  1029. day,
  1030. hour,
  1031. minute,
  1032. second,
  1033. fraction = 0,
  1034. delta = null,
  1035. tz_hour,
  1036. tz_minute,
  1037. date;
  1038. match = YAML_DATE_REGEXP.exec(data);
  1039. if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
  1040. if (match === null) throw new Error('Date resolve error'); // match: [1] year [2] month [3] day
  1041. year = +match[1];
  1042. month = +match[2] - 1; // JS month starts with 0
  1043. day = +match[3];
  1044. if (!match[4]) {
  1045. // no hour
  1046. return new Date(Date.UTC(year, month, day));
  1047. } // match: [4] hour [5] minute [6] second [7] fraction
  1048. hour = +match[4];
  1049. minute = +match[5];
  1050. second = +match[6];
  1051. if (match[7]) {
  1052. fraction = match[7].slice(0, 3);
  1053. while (fraction.length < 3) {
  1054. // milli-seconds
  1055. fraction += '0';
  1056. }
  1057. fraction = +fraction;
  1058. } // match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
  1059. if (match[9]) {
  1060. tz_hour = +match[10];
  1061. tz_minute = +(match[11] || 0);
  1062. delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
  1063. if (match[9] === '-') delta = -delta;
  1064. }
  1065. date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
  1066. if (delta) date.setTime(date.getTime() - delta);
  1067. return date;
  1068. }
  1069. function representYamlTimestamp(object
  1070. /*, style*/
  1071. ) {
  1072. return object.toISOString();
  1073. }
  1074. var timestamp = new type('tag:yaml.org,2002:timestamp', {
  1075. kind: 'scalar',
  1076. resolve: resolveYamlTimestamp,
  1077. construct: constructYamlTimestamp,
  1078. instanceOf: Date,
  1079. represent: representYamlTimestamp
  1080. });
  1081. function resolveYamlMerge(data) {
  1082. return data === '<<' || data === null;
  1083. }
  1084. var merge = new type('tag:yaml.org,2002:merge', {
  1085. kind: 'scalar',
  1086. resolve: resolveYamlMerge
  1087. });
  1088. /*eslint-disable no-bitwise*/
  1089. var NodeBuffer;
  1090. try {
  1091. // A trick for browserified version, to not include `Buffer` shim
  1092. var _require = commonjsRequire;
  1093. NodeBuffer = _require('buffer').Buffer;
  1094. } catch (__) {} // [ 64, 65, 66 ] -> [ padding, CR, LF ]
  1095. var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
  1096. function resolveYamlBinary(data) {
  1097. if (data === null) return false;
  1098. var code,
  1099. idx,
  1100. bitlen = 0,
  1101. max = data.length,
  1102. map = BASE64_MAP; // Convert one by one.
  1103. for (idx = 0; idx < max; idx++) {
  1104. code = map.indexOf(data.charAt(idx)); // Skip CR/LF
  1105. if (code > 64) continue; // Fail on illegal characters
  1106. if (code < 0) return false;
  1107. bitlen += 6;
  1108. } // If there are any bits left, source was corrupted
  1109. return bitlen % 8 === 0;
  1110. }
  1111. function constructYamlBinary(data) {
  1112. var idx,
  1113. tailbits,
  1114. input = data.replace(/[\r\n=]/g, ''),
  1115. // remove CR/LF & padding to simplify scan
  1116. max = input.length,
  1117. map = BASE64_MAP,
  1118. bits = 0,
  1119. result = []; // Collect by 6*4 bits (3 bytes)
  1120. for (idx = 0; idx < max; idx++) {
  1121. if (idx % 4 === 0 && idx) {
  1122. result.push(bits >> 16 & 0xFF);
  1123. result.push(bits >> 8 & 0xFF);
  1124. result.push(bits & 0xFF);
  1125. }
  1126. bits = bits << 6 | map.indexOf(input.charAt(idx));
  1127. } // Dump tail
  1128. tailbits = max % 4 * 6;
  1129. if (tailbits === 0) {
  1130. result.push(bits >> 16 & 0xFF);
  1131. result.push(bits >> 8 & 0xFF);
  1132. result.push(bits & 0xFF);
  1133. } else if (tailbits === 18) {
  1134. result.push(bits >> 10 & 0xFF);
  1135. result.push(bits >> 2 & 0xFF);
  1136. } else if (tailbits === 12) {
  1137. result.push(bits >> 4 & 0xFF);
  1138. } // Wrap into Buffer for NodeJS and leave Array for browser
  1139. if (NodeBuffer) {
  1140. // Support node 6.+ Buffer API when available
  1141. return NodeBuffer.from ? NodeBuffer.from(result) : new NodeBuffer(result);
  1142. }
  1143. return result;
  1144. }
  1145. function representYamlBinary(object
  1146. /*, style*/
  1147. ) {
  1148. var result = '',
  1149. bits = 0,
  1150. idx,
  1151. tail,
  1152. max = object.length,
  1153. map = BASE64_MAP; // Convert every three bytes to 4 ASCII characters.
  1154. for (idx = 0; idx < max; idx++) {
  1155. if (idx % 3 === 0 && idx) {
  1156. result += map[bits >> 18 & 0x3F];
  1157. result += map[bits >> 12 & 0x3F];
  1158. result += map[bits >> 6 & 0x3F];
  1159. result += map[bits & 0x3F];
  1160. }
  1161. bits = (bits << 8) + object[idx];
  1162. } // Dump tail
  1163. tail = max % 3;
  1164. if (tail === 0) {
  1165. result += map[bits >> 18 & 0x3F];
  1166. result += map[bits >> 12 & 0x3F];
  1167. result += map[bits >> 6 & 0x3F];
  1168. result += map[bits & 0x3F];
  1169. } else if (tail === 2) {
  1170. result += map[bits >> 10 & 0x3F];
  1171. result += map[bits >> 4 & 0x3F];
  1172. result += map[bits << 2 & 0x3F];
  1173. result += map[64];
  1174. } else if (tail === 1) {
  1175. result += map[bits >> 2 & 0x3F];
  1176. result += map[bits << 4 & 0x3F];
  1177. result += map[64];
  1178. result += map[64];
  1179. }
  1180. return result;
  1181. }
  1182. function isBinary(object) {
  1183. return NodeBuffer && NodeBuffer.isBuffer(object);
  1184. }
  1185. var binary = new type('tag:yaml.org,2002:binary', {
  1186. kind: 'scalar',
  1187. resolve: resolveYamlBinary,
  1188. construct: constructYamlBinary,
  1189. predicate: isBinary,
  1190. represent: representYamlBinary
  1191. });
  1192. var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
  1193. var _toString = Object.prototype.toString;
  1194. function resolveYamlOmap(data) {
  1195. if (data === null) return true;
  1196. var objectKeys = [],
  1197. index,
  1198. length,
  1199. pair,
  1200. pairKey,
  1201. pairHasKey,
  1202. object = data;
  1203. for (index = 0, length = object.length; index < length; index += 1) {
  1204. pair = object[index];
  1205. pairHasKey = false;
  1206. if (_toString.call(pair) !== '[object Object]') return false;
  1207. for (pairKey in pair) {
  1208. if (_hasOwnProperty$1.call(pair, pairKey)) {
  1209. if (!pairHasKey) pairHasKey = true;else return false;
  1210. }
  1211. }
  1212. if (!pairHasKey) return false;
  1213. if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);else return false;
  1214. }
  1215. return true;
  1216. }
  1217. function constructYamlOmap(data) {
  1218. return data !== null ? data : [];
  1219. }
  1220. var omap = new type('tag:yaml.org,2002:omap', {
  1221. kind: 'sequence',
  1222. resolve: resolveYamlOmap,
  1223. construct: constructYamlOmap
  1224. });
  1225. var _toString$1 = Object.prototype.toString;
  1226. function resolveYamlPairs(data) {
  1227. if (data === null) return true;
  1228. var index,
  1229. length,
  1230. pair,
  1231. keys,
  1232. result,
  1233. object = data;
  1234. result = new Array(object.length);
  1235. for (index = 0, length = object.length; index < length; index += 1) {
  1236. pair = object[index];
  1237. if (_toString$1.call(pair) !== '[object Object]') return false;
  1238. keys = Object.keys(pair);
  1239. if (keys.length !== 1) return false;
  1240. result[index] = [keys[0], pair[keys[0]]];
  1241. }
  1242. return true;
  1243. }
  1244. function constructYamlPairs(data) {
  1245. if (data === null) return [];
  1246. var index,
  1247. length,
  1248. pair,
  1249. keys,
  1250. result,
  1251. object = data;
  1252. result = new Array(object.length);
  1253. for (index = 0, length = object.length; index < length; index += 1) {
  1254. pair = object[index];
  1255. keys = Object.keys(pair);
  1256. result[index] = [keys[0], pair[keys[0]]];
  1257. }
  1258. return result;
  1259. }
  1260. var pairs = new type('tag:yaml.org,2002:pairs', {
  1261. kind: 'sequence',
  1262. resolve: resolveYamlPairs,
  1263. construct: constructYamlPairs
  1264. });
  1265. var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
  1266. function resolveYamlSet(data) {
  1267. if (data === null) return true;
  1268. var key,
  1269. object = data;
  1270. for (key in object) {
  1271. if (_hasOwnProperty$2.call(object, key)) {
  1272. if (object[key] !== null) return false;
  1273. }
  1274. }
  1275. return true;
  1276. }
  1277. function constructYamlSet(data) {
  1278. return data !== null ? data : {};
  1279. }
  1280. var set$1 = new type('tag:yaml.org,2002:set', {
  1281. kind: 'mapping',
  1282. resolve: resolveYamlSet,
  1283. construct: constructYamlSet
  1284. });
  1285. var default_safe = new schema({
  1286. include: [core],
  1287. implicit: [timestamp, merge],
  1288. explicit: [binary, omap, pairs, set$1]
  1289. });
  1290. function resolveJavascriptUndefined() {
  1291. return true;
  1292. }
  1293. function constructJavascriptUndefined() {
  1294. /*eslint-disable no-undefined*/
  1295. return undefined;
  1296. }
  1297. function representJavascriptUndefined() {
  1298. return '';
  1299. }
  1300. function isUndefined(object) {
  1301. return typeof object === 'undefined';
  1302. }
  1303. var _undefined = new type('tag:yaml.org,2002:js/undefined', {
  1304. kind: 'scalar',
  1305. resolve: resolveJavascriptUndefined,
  1306. construct: constructJavascriptUndefined,
  1307. predicate: isUndefined,
  1308. represent: representJavascriptUndefined
  1309. });
  1310. function resolveJavascriptRegExp(data) {
  1311. if (data === null) return false;
  1312. if (data.length === 0) return false;
  1313. var regexp = data,
  1314. tail = /\/([gim]*)$/.exec(data),
  1315. modifiers = ''; // if regexp starts with '/' it can have modifiers and must be properly closed
  1316. // `/foo/gim` - modifiers tail can be maximum 3 chars
  1317. if (regexp[0] === '/') {
  1318. if (tail) modifiers = tail[1];
  1319. if (modifiers.length > 3) return false; // if expression starts with /, is should be properly terminated
  1320. if (regexp[regexp.length - modifiers.length - 1] !== '/') return false;
  1321. }
  1322. return true;
  1323. }
  1324. function constructJavascriptRegExp(data) {
  1325. var regexp = data,
  1326. tail = /\/([gim]*)$/.exec(data),
  1327. modifiers = ''; // `/foo/gim` - tail can be maximum 4 chars
  1328. if (regexp[0] === '/') {
  1329. if (tail) modifiers = tail[1];
  1330. regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
  1331. }
  1332. return new RegExp(regexp, modifiers);
  1333. }
  1334. function representJavascriptRegExp(object
  1335. /*, style*/
  1336. ) {
  1337. var result = '/' + object.source + '/';
  1338. if (object.global) result += 'g';
  1339. if (object.multiline) result += 'm';
  1340. if (object.ignoreCase) result += 'i';
  1341. return result;
  1342. }
  1343. function isRegExp(object) {
  1344. return Object.prototype.toString.call(object) === '[object RegExp]';
  1345. }
  1346. var regexp = new type('tag:yaml.org,2002:js/regexp', {
  1347. kind: 'scalar',
  1348. resolve: resolveJavascriptRegExp,
  1349. construct: constructJavascriptRegExp,
  1350. predicate: isRegExp,
  1351. represent: representJavascriptRegExp
  1352. });
  1353. var esprima; // Browserified version does not have esprima
  1354. //
  1355. // 1. For node.js just require module as deps
  1356. // 2. For browser try to require mudule via external AMD system.
  1357. // If not found - try to fallback to window.esprima. If not
  1358. // found too - then fail to parse.
  1359. //
  1360. try {
  1361. // workaround to exclude package from browserify list.
  1362. var _require$1 = commonjsRequire;
  1363. esprima = _require$1('esprima');
  1364. } catch (_) {
  1365. /*global window */
  1366. if (typeof window !== 'undefined') esprima = window.esprima;
  1367. }
  1368. function resolveJavascriptFunction(data) {
  1369. if (data === null) return false;
  1370. try {
  1371. var source = '(' + data + ')',
  1372. ast = esprima.parse(source, {
  1373. range: true
  1374. });
  1375. if (ast.type !== 'Program' || ast.body.length !== 1 || ast.body[0].type !== 'ExpressionStatement' || ast.body[0].expression.type !== 'ArrowFunctionExpression' && ast.body[0].expression.type !== 'FunctionExpression') {
  1376. return false;
  1377. }
  1378. return true;
  1379. } catch (err) {
  1380. return false;
  1381. }
  1382. }
  1383. function constructJavascriptFunction(data) {
  1384. /*jslint evil:true*/
  1385. var source = '(' + data + ')',
  1386. ast = esprima.parse(source, {
  1387. range: true
  1388. }),
  1389. params = [],
  1390. body;
  1391. if (ast.type !== 'Program' || ast.body.length !== 1 || ast.body[0].type !== 'ExpressionStatement' || ast.body[0].expression.type !== 'ArrowFunctionExpression' && ast.body[0].expression.type !== 'FunctionExpression') {
  1392. throw new Error('Failed to resolve function');
  1393. }
  1394. ast.body[0].expression.params.forEach(function (param) {
  1395. params.push(param.name);
  1396. });
  1397. body = ast.body[0].expression.body.range; // Esprima's ranges include the first '{' and the last '}' characters on
  1398. // function expressions. So cut them out.
  1399. if (ast.body[0].expression.body.type === 'BlockStatement') {
  1400. /*eslint-disable no-new-func*/
  1401. return new Function(params, source.slice(body[0] + 1, body[1] - 1));
  1402. } // ES6 arrow functions can omit the BlockStatement. In that case, just return
  1403. // the body.
  1404. /*eslint-disable no-new-func*/
  1405. return new Function(params, 'return ' + source.slice(body[0], body[1]));
  1406. }
  1407. function representJavascriptFunction(object
  1408. /*, style*/
  1409. ) {
  1410. return object.toString();
  1411. }
  1412. function isFunction(object) {
  1413. return Object.prototype.toString.call(object) === '[object Function]';
  1414. }
  1415. var _function = new type('tag:yaml.org,2002:js/function', {
  1416. kind: 'scalar',
  1417. resolve: resolveJavascriptFunction,
  1418. construct: constructJavascriptFunction,
  1419. predicate: isFunction,
  1420. represent: representJavascriptFunction
  1421. });
  1422. var default_full = schema.DEFAULT = new schema({
  1423. include: [default_safe],
  1424. explicit: [_undefined, regexp, _function]
  1425. });
  1426. /*eslint-disable max-len,no-use-before-define*/
  1427. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  1428. var CONTEXT_FLOW_IN = 1;
  1429. var CONTEXT_FLOW_OUT = 2;
  1430. var CONTEXT_BLOCK_IN = 3;
  1431. var CONTEXT_BLOCK_OUT = 4;
  1432. var CHOMPING_CLIP = 1;
  1433. var CHOMPING_STRIP = 2;
  1434. var CHOMPING_KEEP = 3;
  1435. var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
  1436. var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
  1437. var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
  1438. var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
  1439. var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
  1440. function is_EOL(c) {
  1441. return c === 0x0A
  1442. /* LF */
  1443. || c === 0x0D
  1444. /* CR */
  1445. ;
  1446. }
  1447. function is_WHITE_SPACE(c) {
  1448. return c === 0x09
  1449. /* Tab */
  1450. || c === 0x20
  1451. /* Space */
  1452. ;
  1453. }
  1454. function is_WS_OR_EOL(c) {
  1455. return c === 0x09
  1456. /* Tab */
  1457. || c === 0x20
  1458. /* Space */
  1459. || c === 0x0A
  1460. /* LF */
  1461. || c === 0x0D
  1462. /* CR */
  1463. ;
  1464. }
  1465. function is_FLOW_INDICATOR(c) {
  1466. return c === 0x2C
  1467. /* , */
  1468. || c === 0x5B
  1469. /* [ */
  1470. || c === 0x5D
  1471. /* ] */
  1472. || c === 0x7B
  1473. /* { */
  1474. || c === 0x7D
  1475. /* } */
  1476. ;
  1477. }
  1478. function fromHexCode(c) {
  1479. var lc;
  1480. if (0x30
  1481. /* 0 */
  1482. <= c && c <= 0x39
  1483. /* 9 */
  1484. ) {
  1485. return c - 0x30;
  1486. }
  1487. /*eslint-disable no-bitwise*/
  1488. lc = c | 0x20;
  1489. if (0x61
  1490. /* a */
  1491. <= lc && lc <= 0x66
  1492. /* f */
  1493. ) {
  1494. return lc - 0x61 + 10;
  1495. }
  1496. return -1;
  1497. }
  1498. function escapedHexLen(c) {
  1499. if (c === 0x78
  1500. /* x */
  1501. ) {
  1502. return 2;
  1503. }
  1504. if (c === 0x75
  1505. /* u */
  1506. ) {
  1507. return 4;
  1508. }
  1509. if (c === 0x55
  1510. /* U */
  1511. ) {
  1512. return 8;
  1513. }
  1514. return 0;
  1515. }
  1516. function fromDecimalCode(c) {
  1517. if (0x30
  1518. /* 0 */
  1519. <= c && c <= 0x39
  1520. /* 9 */
  1521. ) {
  1522. return c - 0x30;
  1523. }
  1524. return -1;
  1525. }
  1526. function simpleEscapeSequence(c) {
  1527. /* eslint-disable indent */
  1528. return c === 0x30
  1529. /* 0 */
  1530. ? '\x00' : c === 0x61
  1531. /* a */
  1532. ? '\x07' : c === 0x62
  1533. /* b */
  1534. ? '\x08' : c === 0x74
  1535. /* t */
  1536. ? '\x09' : c === 0x09
  1537. /* Tab */
  1538. ? '\x09' : c === 0x6E
  1539. /* n */
  1540. ? '\x0A' : c === 0x76
  1541. /* v */
  1542. ? '\x0B' : c === 0x66
  1543. /* f */
  1544. ? '\x0C' : c === 0x72
  1545. /* r */
  1546. ? '\x0D' : c === 0x65
  1547. /* e */
  1548. ? '\x1B' : c === 0x20
  1549. /* Space */
  1550. ? ' ' : c === 0x22
  1551. /* " */
  1552. ? '\x22' : c === 0x2F
  1553. /* / */
  1554. ? '/' : c === 0x5C
  1555. /* \ */
  1556. ? '\x5C' : c === 0x4E
  1557. /* N */
  1558. ? '\x85' : c === 0x5F
  1559. /* _ */
  1560. ? '\xA0' : c === 0x4C
  1561. /* L */
  1562. ? '\u2028' : c === 0x50
  1563. /* P */
  1564. ? '\u2029' : '';
  1565. }
  1566. function charFromCodepoint(c) {
  1567. if (c <= 0xFFFF) {
  1568. return String.fromCharCode(c);
  1569. } // Encode UTF-16 surrogate pair
  1570. // https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
  1571. return String.fromCharCode((c - 0x010000 >> 10) + 0xD800, (c - 0x010000 & 0x03FF) + 0xDC00);
  1572. }
  1573. var simpleEscapeCheck = new Array(256); // integer, for fast access
  1574. var simpleEscapeMap = new Array(256);
  1575. for (var i = 0; i < 256; i++) {
  1576. simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
  1577. simpleEscapeMap[i] = simpleEscapeSequence(i);
  1578. }
  1579. function State(input, options) {
  1580. this.input = input;
  1581. this.filename = options['filename'] || null;
  1582. this.schema = options['schema'] || default_full;
  1583. this.onWarning = options['onWarning'] || null;
  1584. this.legacy = options['legacy'] || false;
  1585. this.json = options['json'] || false;
  1586. this.listener = options['listener'] || null;
  1587. this.implicitTypes = this.schema.compiledImplicit;
  1588. this.typeMap = this.schema.compiledTypeMap;
  1589. this.length = input.length;
  1590. this.position = 0;
  1591. this.line = 0;
  1592. this.lineStart = 0;
  1593. this.lineIndent = 0;
  1594. this.documents = [];
  1595. /*
  1596. this.version;
  1597. this.checkLineBreaks;
  1598. this.tagMap;
  1599. this.anchorMap;
  1600. this.tag;
  1601. this.anchor;
  1602. this.kind;
  1603. this.result;*/
  1604. }
  1605. function generateError(state, message) {
  1606. return new exception(message, new mark(state.filename, state.input, state.position, state.line, state.position - state.lineStart));
  1607. }
  1608. function throwError(state, message) {
  1609. throw generateError(state, message);
  1610. }
  1611. function throwWarning(state, message) {
  1612. if (state.onWarning) {
  1613. state.onWarning.call(null, generateError(state, message));
  1614. }
  1615. }
  1616. var directiveHandlers = {
  1617. YAML: function handleYamlDirective(state, name, args) {
  1618. var match, major, minor;
  1619. if (state.version !== null) {
  1620. throwError(state, 'duplication of %YAML directive');
  1621. }
  1622. if (args.length !== 1) {
  1623. throwError(state, 'YAML directive accepts exactly one argument');
  1624. }
  1625. match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
  1626. if (match === null) {
  1627. throwError(state, 'ill-formed argument of the YAML directive');
  1628. }
  1629. major = parseInt(match[1], 10);
  1630. minor = parseInt(match[2], 10);
  1631. if (major !== 1) {
  1632. throwError(state, 'unacceptable YAML version of the document');
  1633. }
  1634. state.version = args[0];
  1635. state.checkLineBreaks = minor < 2;
  1636. if (minor !== 1 && minor !== 2) {
  1637. throwWarning(state, 'unsupported YAML version of the document');
  1638. }
  1639. },
  1640. TAG: function handleTagDirective(state, name, args) {
  1641. var handle, prefix;
  1642. if (args.length !== 2) {
  1643. throwError(state, 'TAG directive accepts exactly two arguments');
  1644. }
  1645. handle = args[0];
  1646. prefix = args[1];
  1647. if (!PATTERN_TAG_HANDLE.test(handle)) {
  1648. throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
  1649. }
  1650. if (_hasOwnProperty.call(state.tagMap, handle)) {
  1651. throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
  1652. }
  1653. if (!PATTERN_TAG_URI.test(prefix)) {
  1654. throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
  1655. }
  1656. state.tagMap[handle] = prefix;
  1657. }
  1658. };
  1659. function captureSegment(state, start, end, checkJson) {
  1660. var _position, _length, _character, _result;
  1661. if (start < end) {
  1662. _result = state.input.slice(start, end);
  1663. if (checkJson) {
  1664. for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
  1665. _character = _result.charCodeAt(_position);
  1666. if (!(_character === 0x09 || 0x20 <= _character && _character <= 0x10FFFF)) {
  1667. throwError(state, 'expected valid JSON character');
  1668. }
  1669. }
  1670. } else if (PATTERN_NON_PRINTABLE.test(_result)) {
  1671. throwError(state, 'the stream contains non-printable characters');
  1672. }
  1673. state.result += _result;
  1674. }
  1675. }
  1676. function mergeMappings(state, destination, source, overridableKeys) {
  1677. var sourceKeys, key, index, quantity;
  1678. if (!common.isObject(source)) {
  1679. throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
  1680. }
  1681. sourceKeys = Object.keys(source);
  1682. for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
  1683. key = sourceKeys[index];
  1684. if (!_hasOwnProperty.call(destination, key)) {
  1685. destination[key] = source[key];
  1686. overridableKeys[key] = true;
  1687. }
  1688. }
  1689. }
  1690. function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
  1691. var index, quantity;
  1692. keyNode = String(keyNode);
  1693. if (_result === null) {
  1694. _result = {};
  1695. }
  1696. if (keyTag === 'tag:yaml.org,2002:merge') {
  1697. if (Array.isArray(valueNode)) {
  1698. for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
  1699. mergeMappings(state, _result, valueNode[index], overridableKeys);
  1700. }
  1701. } else {
  1702. mergeMappings(state, _result, valueNode, overridableKeys);
  1703. }
  1704. } else {
  1705. if (!state.json && !_hasOwnProperty.call(overridableKeys, keyNode) && _hasOwnProperty.call(_result, keyNode)) {
  1706. state.line = startLine || state.line;
  1707. state.position = startPos || state.position;
  1708. throwError(state, 'duplicated mapping key');
  1709. }
  1710. _result[keyNode] = valueNode;
  1711. delete overridableKeys[keyNode];
  1712. }
  1713. return _result;
  1714. }
  1715. function readLineBreak(state) {
  1716. var ch;
  1717. ch = state.input.charCodeAt(state.position);
  1718. if (ch === 0x0A
  1719. /* LF */
  1720. ) {
  1721. state.position++;
  1722. } else if (ch === 0x0D
  1723. /* CR */
  1724. ) {
  1725. state.position++;
  1726. if (state.input.charCodeAt(state.position) === 0x0A
  1727. /* LF */
  1728. ) {
  1729. state.position++;
  1730. }
  1731. } else {
  1732. throwError(state, 'a line break is expected');
  1733. }
  1734. state.line += 1;
  1735. state.lineStart = state.position;
  1736. }
  1737. function skipSeparationSpace(state, allowComments, checkIndent) {
  1738. var lineBreaks = 0,
  1739. ch = state.input.charCodeAt(state.position);
  1740. while (ch !== 0) {
  1741. while (is_WHITE_SPACE(ch)) {
  1742. ch = state.input.charCodeAt(++state.position);
  1743. }
  1744. if (allowComments && ch === 0x23
  1745. /* # */
  1746. ) {
  1747. do {
  1748. ch = state.input.charCodeAt(++state.position);
  1749. } while (ch !== 0x0A
  1750. /* LF */
  1751. && ch !== 0x0D
  1752. /* CR */
  1753. && ch !== 0);
  1754. }
  1755. if (is_EOL(ch)) {
  1756. readLineBreak(state);
  1757. ch = state.input.charCodeAt(state.position);
  1758. lineBreaks++;
  1759. state.lineIndent = 0;
  1760. while (ch === 0x20
  1761. /* Space */
  1762. ) {
  1763. state.lineIndent++;
  1764. ch = state.input.charCodeAt(++state.position);
  1765. }
  1766. } else {
  1767. break;
  1768. }
  1769. }
  1770. if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
  1771. throwWarning(state, 'deficient indentation');
  1772. }
  1773. return lineBreaks;
  1774. }
  1775. function testDocumentSeparator(state) {
  1776. var _position = state.position,
  1777. ch;
  1778. ch = state.input.charCodeAt(_position); // Condition state.position === state.lineStart is tested
  1779. // in parent on each call, for efficiency. No needs to test here again.
  1780. if ((ch === 0x2D
  1781. /* - */
  1782. || ch === 0x2E
  1783. /* . */
  1784. ) && ch === state.input.charCodeAt(_position + 1) && ch === state.input.charCodeAt(_position + 2)) {
  1785. _position += 3;
  1786. ch = state.input.charCodeAt(_position);
  1787. if (ch === 0 || is_WS_OR_EOL(ch)) {
  1788. return true;
  1789. }
  1790. }
  1791. return false;
  1792. }
  1793. function writeFoldedLines(state, count) {
  1794. if (count === 1) {
  1795. state.result += ' ';
  1796. } else if (count > 1) {
  1797. state.result += common.repeat('\n', count - 1);
  1798. }
  1799. }
  1800. function readPlainScalar(state, nodeIndent, withinFlowCollection) {
  1801. var preceding,
  1802. following,
  1803. captureStart,
  1804. captureEnd,
  1805. hasPendingContent,
  1806. _line,
  1807. _lineStart,
  1808. _lineIndent,
  1809. _kind = state.kind,
  1810. _result = state.result,
  1811. ch;
  1812. ch = state.input.charCodeAt(state.position);
  1813. if (is_WS_OR_EOL(ch) || is_FLOW_INDICATOR(ch) || ch === 0x23
  1814. /* # */
  1815. || ch === 0x26
  1816. /* & */
  1817. || ch === 0x2A
  1818. /* * */
  1819. || ch === 0x21
  1820. /* ! */
  1821. || ch === 0x7C
  1822. /* | */
  1823. || ch === 0x3E
  1824. /* > */
  1825. || ch === 0x27
  1826. /* ' */
  1827. || ch === 0x22
  1828. /* " */
  1829. || ch === 0x25
  1830. /* % */
  1831. || ch === 0x40
  1832. /* @ */
  1833. || ch === 0x60
  1834. /* ` */
  1835. ) {
  1836. return false;
  1837. }
  1838. if (ch === 0x3F
  1839. /* ? */
  1840. || ch === 0x2D
  1841. /* - */
  1842. ) {
  1843. following = state.input.charCodeAt(state.position + 1);
  1844. if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
  1845. return false;
  1846. }
  1847. }
  1848. state.kind = 'scalar';
  1849. state.result = '';
  1850. captureStart = captureEnd = state.position;
  1851. hasPendingContent = false;
  1852. while (ch !== 0) {
  1853. if (ch === 0x3A
  1854. /* : */
  1855. ) {
  1856. following = state.input.charCodeAt(state.position + 1);
  1857. if (is_WS_OR_EOL(following) || withinFlowCollection && is_FLOW_INDICATOR(following)) {
  1858. break;
  1859. }
  1860. } else if (ch === 0x23
  1861. /* # */
  1862. ) {
  1863. preceding = state.input.charCodeAt(state.position - 1);
  1864. if (is_WS_OR_EOL(preceding)) {
  1865. break;
  1866. }
  1867. } else if (state.position === state.lineStart && testDocumentSeparator(state) || withinFlowCollection && is_FLOW_INDICATOR(ch)) {
  1868. break;
  1869. } else if (is_EOL(ch)) {
  1870. _line = state.line;
  1871. _lineStart = state.lineStart;
  1872. _lineIndent = state.lineIndent;
  1873. skipSeparationSpace(state, false, -1);
  1874. if (state.lineIndent >= nodeIndent) {
  1875. hasPendingContent = true;
  1876. ch = state.input.charCodeAt(state.position);
  1877. continue;
  1878. } else {
  1879. state.position = captureEnd;
  1880. state.line = _line;
  1881. state.lineStart = _lineStart;
  1882. state.lineIndent = _lineIndent;
  1883. break;
  1884. }
  1885. }
  1886. if (hasPendingContent) {
  1887. captureSegment(state, captureStart, captureEnd, false);
  1888. writeFoldedLines(state, state.line - _line);
  1889. captureStart = captureEnd = state.position;
  1890. hasPendingContent = false;
  1891. }
  1892. if (!is_WHITE_SPACE(ch)) {
  1893. captureEnd = state.position + 1;
  1894. }
  1895. ch = state.input.charCodeAt(++state.position);
  1896. }
  1897. captureSegment(state, captureStart, captureEnd, false);
  1898. if (state.result) {
  1899. return true;
  1900. }
  1901. state.kind = _kind;
  1902. state.result = _result;
  1903. return false;
  1904. }
  1905. function readSingleQuotedScalar(state, nodeIndent) {
  1906. var ch, captureStart, captureEnd;
  1907. ch = state.input.charCodeAt(state.position);
  1908. if (ch !== 0x27
  1909. /* ' */
  1910. ) {
  1911. return false;
  1912. }
  1913. state.kind = 'scalar';
  1914. state.result = '';
  1915. state.position++;
  1916. captureStart = captureEnd = state.position;
  1917. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  1918. if (ch === 0x27
  1919. /* ' */
  1920. ) {
  1921. captureSegment(state, captureStart, state.position, true);
  1922. ch = state.input.charCodeAt(++state.position);
  1923. if (ch === 0x27
  1924. /* ' */
  1925. ) {
  1926. captureStart = state.position;
  1927. state.position++;
  1928. captureEnd = state.position;
  1929. } else {
  1930. return true;
  1931. }
  1932. } else if (is_EOL(ch)) {
  1933. captureSegment(state, captureStart, captureEnd, true);
  1934. writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
  1935. captureStart = captureEnd = state.position;
  1936. } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
  1937. throwError(state, 'unexpected end of the document within a single quoted scalar');
  1938. } else {
  1939. state.position++;
  1940. captureEnd = state.position;
  1941. }
  1942. }
  1943. throwError(state, 'unexpected end of the stream within a single quoted scalar');
  1944. }
  1945. function readDoubleQuotedScalar(state, nodeIndent) {
  1946. var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
  1947. ch = state.input.charCodeAt(state.position);
  1948. if (ch !== 0x22
  1949. /* " */
  1950. ) {
  1951. return false;
  1952. }
  1953. state.kind = 'scalar';
  1954. state.result = '';
  1955. state.position++;
  1956. captureStart = captureEnd = state.position;
  1957. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  1958. if (ch === 0x22
  1959. /* " */
  1960. ) {
  1961. captureSegment(state, captureStart, state.position, true);
  1962. state.position++;
  1963. return true;
  1964. } else if (ch === 0x5C
  1965. /* \ */
  1966. ) {
  1967. captureSegment(state, captureStart, state.position, true);
  1968. ch = state.input.charCodeAt(++state.position);
  1969. if (is_EOL(ch)) {
  1970. skipSeparationSpace(state, false, nodeIndent); // TODO: rework to inline fn with no type cast?
  1971. } else if (ch < 256 && simpleEscapeCheck[ch]) {
  1972. state.result += simpleEscapeMap[ch];
  1973. state.position++;
  1974. } else if ((tmp = escapedHexLen(ch)) > 0) {
  1975. hexLength = tmp;
  1976. hexResult = 0;
  1977. for (; hexLength > 0; hexLength--) {
  1978. ch = state.input.charCodeAt(++state.position);
  1979. if ((tmp = fromHexCode(ch)) >= 0) {
  1980. hexResult = (hexResult << 4) + tmp;
  1981. } else {
  1982. throwError(state, 'expected hexadecimal character');
  1983. }
  1984. }
  1985. state.result += charFromCodepoint(hexResult);
  1986. state.position++;
  1987. } else {
  1988. throwError(state, 'unknown escape sequence');
  1989. }
  1990. captureStart = captureEnd = state.position;
  1991. } else if (is_EOL(ch)) {
  1992. captureSegment(state, captureStart, captureEnd, true);
  1993. writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
  1994. captureStart = captureEnd = state.position;
  1995. } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
  1996. throwError(state, 'unexpected end of the document within a double quoted scalar');
  1997. } else {
  1998. state.position++;
  1999. captureEnd = state.position;
  2000. }
  2001. }
  2002. throwError(state, 'unexpected end of the stream within a double quoted scalar');
  2003. }
  2004. function readFlowCollection(state, nodeIndent) {
  2005. var readNext = true,
  2006. _line,
  2007. _tag = state.tag,
  2008. _result,
  2009. _anchor = state.anchor,
  2010. following,
  2011. terminator,
  2012. isPair,
  2013. isExplicitPair,
  2014. isMapping,
  2015. overridableKeys = {},
  2016. keyNode,
  2017. keyTag,
  2018. valueNode,
  2019. ch;
  2020. ch = state.input.charCodeAt(state.position);
  2021. if (ch === 0x5B
  2022. /* [ */
  2023. ) {
  2024. terminator = 0x5D;
  2025. /* ] */
  2026. isMapping = false;
  2027. _result = [];
  2028. } else if (ch === 0x7B
  2029. /* { */
  2030. ) {
  2031. terminator = 0x7D;
  2032. /* } */
  2033. isMapping = true;
  2034. _result = {};
  2035. } else {
  2036. return false;
  2037. }
  2038. if (state.anchor !== null) {
  2039. state.anchorMap[state.anchor] = _result;
  2040. }
  2041. ch = state.input.charCodeAt(++state.position);
  2042. while (ch !== 0) {
  2043. skipSeparationSpace(state, true, nodeIndent);
  2044. ch = state.input.charCodeAt(state.position);
  2045. if (ch === terminator) {
  2046. state.position++;
  2047. state.tag = _tag;
  2048. state.anchor = _anchor;
  2049. state.kind = isMapping ? 'mapping' : 'sequence';
  2050. state.result = _result;
  2051. return true;
  2052. } else if (!readNext) {
  2053. throwError(state, 'missed comma between flow collection entries');
  2054. }
  2055. keyTag = keyNode = valueNode = null;
  2056. isPair = isExplicitPair = false;
  2057. if (ch === 0x3F
  2058. /* ? */
  2059. ) {
  2060. following = state.input.charCodeAt(state.position + 1);
  2061. if (is_WS_OR_EOL(following)) {
  2062. isPair = isExplicitPair = true;
  2063. state.position++;
  2064. skipSeparationSpace(state, true, nodeIndent);
  2065. }
  2066. }
  2067. _line = state.line;
  2068. composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
  2069. keyTag = state.tag;
  2070. keyNode = state.result;
  2071. skipSeparationSpace(state, true, nodeIndent);
  2072. ch = state.input.charCodeAt(state.position);
  2073. if ((isExplicitPair || state.line === _line) && ch === 0x3A
  2074. /* : */
  2075. ) {
  2076. isPair = true;
  2077. ch = state.input.charCodeAt(++state.position);
  2078. skipSeparationSpace(state, true, nodeIndent);
  2079. composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
  2080. valueNode = state.result;
  2081. }
  2082. if (isMapping) {
  2083. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
  2084. } else if (isPair) {
  2085. _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
  2086. } else {
  2087. _result.push(keyNode);
  2088. }
  2089. skipSeparationSpace(state, true, nodeIndent);
  2090. ch = state.input.charCodeAt(state.position);
  2091. if (ch === 0x2C
  2092. /* , */
  2093. ) {
  2094. readNext = true;
  2095. ch = state.input.charCodeAt(++state.position);
  2096. } else {
  2097. readNext = false;
  2098. }
  2099. }
  2100. throwError(state, 'unexpected end of the stream within a flow collection');
  2101. }
  2102. function readBlockScalar(state, nodeIndent) {
  2103. var captureStart,
  2104. folding,
  2105. chomping = CHOMPING_CLIP,
  2106. didReadContent = false,
  2107. detectedIndent = false,
  2108. textIndent = nodeIndent,
  2109. emptyLines = 0,
  2110. atMoreIndented = false,
  2111. tmp,
  2112. ch;
  2113. ch = state.input.charCodeAt(state.position);
  2114. if (ch === 0x7C
  2115. /* | */
  2116. ) {
  2117. folding = false;
  2118. } else if (ch === 0x3E
  2119. /* > */
  2120. ) {
  2121. folding = true;
  2122. } else {
  2123. return false;
  2124. }
  2125. state.kind = 'scalar';
  2126. state.result = '';
  2127. while (ch !== 0) {
  2128. ch = state.input.charCodeAt(++state.position);
  2129. if (ch === 0x2B
  2130. /* + */
  2131. || ch === 0x2D
  2132. /* - */
  2133. ) {
  2134. if (CHOMPING_CLIP === chomping) {
  2135. chomping = ch === 0x2B
  2136. /* + */
  2137. ? CHOMPING_KEEP : CHOMPING_STRIP;
  2138. } else {
  2139. throwError(state, 'repeat of a chomping mode identifier');
  2140. }
  2141. } else if ((tmp = fromDecimalCode(ch)) >= 0) {
  2142. if (tmp === 0) {
  2143. throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
  2144. } else if (!detectedIndent) {
  2145. textIndent = nodeIndent + tmp - 1;
  2146. detectedIndent = true;
  2147. } else {
  2148. throwError(state, 'repeat of an indentation width identifier');
  2149. }
  2150. } else {
  2151. break;
  2152. }
  2153. }
  2154. if (is_WHITE_SPACE(ch)) {
  2155. do {
  2156. ch = state.input.charCodeAt(++state.position);
  2157. } while (is_WHITE_SPACE(ch));
  2158. if (ch === 0x23
  2159. /* # */
  2160. ) {
  2161. do {
  2162. ch = state.input.charCodeAt(++state.position);
  2163. } while (!is_EOL(ch) && ch !== 0);
  2164. }
  2165. }
  2166. while (ch !== 0) {
  2167. readLineBreak(state);
  2168. state.lineIndent = 0;
  2169. ch = state.input.charCodeAt(state.position);
  2170. while ((!detectedIndent || state.lineIndent < textIndent) && ch === 0x20
  2171. /* Space */
  2172. ) {
  2173. state.lineIndent++;
  2174. ch = state.input.charCodeAt(++state.position);
  2175. }
  2176. if (!detectedIndent && state.lineIndent > textIndent) {
  2177. textIndent = state.lineIndent;
  2178. }
  2179. if (is_EOL(ch)) {
  2180. emptyLines++;
  2181. continue;
  2182. } // End of the scalar.
  2183. if (state.lineIndent < textIndent) {
  2184. // Perform the chomping.
  2185. if (chomping === CHOMPING_KEEP) {
  2186. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
  2187. } else if (chomping === CHOMPING_CLIP) {
  2188. if (didReadContent) {
  2189. // i.e. only if the scalar is not empty.
  2190. state.result += '\n';
  2191. }
  2192. } // Break this `while` cycle and go to the funciton's epilogue.
  2193. break;
  2194. } // Folded style: use fancy rules to handle line breaks.
  2195. if (folding) {
  2196. // Lines starting with white space characters (more-indented lines) are not folded.
  2197. if (is_WHITE_SPACE(ch)) {
  2198. atMoreIndented = true; // except for the first content line (cf. Example 8.1)
  2199. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines); // End of more-indented block.
  2200. } else if (atMoreIndented) {
  2201. atMoreIndented = false;
  2202. state.result += common.repeat('\n', emptyLines + 1); // Just one line break - perceive as the same line.
  2203. } else if (emptyLines === 0) {
  2204. if (didReadContent) {
  2205. // i.e. only if we have already read some scalar content.
  2206. state.result += ' ';
  2207. } // Several line breaks - perceive as different lines.
  2208. } else {
  2209. state.result += common.repeat('\n', emptyLines);
  2210. } // Literal style: just add exact number of line breaks between content lines.
  2211. } else {
  2212. // Keep all line breaks except the header line break.
  2213. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
  2214. }
  2215. didReadContent = true;
  2216. detectedIndent = true;
  2217. emptyLines = 0;
  2218. captureStart = state.position;
  2219. while (!is_EOL(ch) && ch !== 0) {
  2220. ch = state.input.charCodeAt(++state.position);
  2221. }
  2222. captureSegment(state, captureStart, state.position, false);
  2223. }
  2224. return true;
  2225. }
  2226. function readBlockSequence(state, nodeIndent) {
  2227. var _line,
  2228. _tag = state.tag,
  2229. _anchor = state.anchor,
  2230. _result = [],
  2231. following,
  2232. detected = false,
  2233. ch;
  2234. if (state.anchor !== null) {
  2235. state.anchorMap[state.anchor] = _result;
  2236. }
  2237. ch = state.input.charCodeAt(state.position);
  2238. while (ch !== 0) {
  2239. if (ch !== 0x2D
  2240. /* - */
  2241. ) {
  2242. break;
  2243. }
  2244. following = state.input.charCodeAt(state.position + 1);
  2245. if (!is_WS_OR_EOL(following)) {
  2246. break;
  2247. }
  2248. detected = true;
  2249. state.position++;
  2250. if (skipSeparationSpace(state, true, -1)) {
  2251. if (state.lineIndent <= nodeIndent) {
  2252. _result.push(null);
  2253. ch = state.input.charCodeAt(state.position);
  2254. continue;
  2255. }
  2256. }
  2257. _line = state.line;
  2258. composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
  2259. _result.push(state.result);
  2260. skipSeparationSpace(state, true, -1);
  2261. ch = state.input.charCodeAt(state.position);
  2262. if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
  2263. throwError(state, 'bad indentation of a sequence entry');
  2264. } else if (state.lineIndent < nodeIndent) {
  2265. break;
  2266. }
  2267. }
  2268. if (detected) {
  2269. state.tag = _tag;
  2270. state.anchor = _anchor;
  2271. state.kind = 'sequence';
  2272. state.result = _result;
  2273. return true;
  2274. }
  2275. return false;
  2276. }
  2277. function readBlockMapping(state, nodeIndent, flowIndent) {
  2278. var following,
  2279. allowCompact,
  2280. _line,
  2281. _pos,
  2282. _tag = state.tag,
  2283. _anchor = state.anchor,
  2284. _result = {},
  2285. overridableKeys = {},
  2286. keyTag = null,
  2287. keyNode = null,
  2288. valueNode = null,
  2289. atExplicitKey = false,
  2290. detected = false,
  2291. ch;
  2292. if (state.anchor !== null) {
  2293. state.anchorMap[state.anchor] = _result;
  2294. }
  2295. ch = state.input.charCodeAt(state.position);
  2296. while (ch !== 0) {
  2297. following = state.input.charCodeAt(state.position + 1);
  2298. _line = state.line; // Save the current line.
  2299. _pos = state.position; //
  2300. // Explicit notation case. There are two separate blocks:
  2301. // first for the key (denoted by "?") and second for the value (denoted by ":")
  2302. //
  2303. if ((ch === 0x3F
  2304. /* ? */
  2305. || ch === 0x3A
  2306. /* : */
  2307. ) && is_WS_OR_EOL(following)) {
  2308. if (ch === 0x3F
  2309. /* ? */
  2310. ) {
  2311. if (atExplicitKey) {
  2312. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  2313. keyTag = keyNode = valueNode = null;
  2314. }
  2315. detected = true;
  2316. atExplicitKey = true;
  2317. allowCompact = true;
  2318. } else if (atExplicitKey) {
  2319. // i.e. 0x3A/* : */ === character after the explicit key.
  2320. atExplicitKey = false;
  2321. allowCompact = true;
  2322. } else {
  2323. throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line');
  2324. }
  2325. state.position += 1;
  2326. ch = following; //
  2327. // Implicit notation case. Flow-style node as the key first, then ":", and the value.
  2328. //
  2329. } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
  2330. if (state.line === _line) {
  2331. ch = state.input.charCodeAt(state.position);
  2332. while (is_WHITE_SPACE(ch)) {
  2333. ch = state.input.charCodeAt(++state.position);
  2334. }
  2335. if (ch === 0x3A
  2336. /* : */
  2337. ) {
  2338. ch = state.input.charCodeAt(++state.position);
  2339. if (!is_WS_OR_EOL(ch)) {
  2340. throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
  2341. }
  2342. if (atExplicitKey) {
  2343. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  2344. keyTag = keyNode = valueNode = null;
  2345. }
  2346. detected = true;
  2347. atExplicitKey = false;
  2348. allowCompact = false;
  2349. keyTag = state.tag;
  2350. keyNode = state.result;
  2351. } else if (detected) {
  2352. throwError(state, 'can not read an implicit mapping pair; a colon is missed');
  2353. } else {
  2354. state.tag = _tag;
  2355. state.anchor = _anchor;
  2356. return true; // Keep the result of `composeNode`.
  2357. }
  2358. } else if (detected) {
  2359. throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
  2360. } else {
  2361. state.tag = _tag;
  2362. state.anchor = _anchor;
  2363. return true; // Keep the result of `composeNode`.
  2364. }
  2365. } else {
  2366. break; // Reading is done. Go to the epilogue.
  2367. } //
  2368. // Common reading code for both explicit and implicit notations.
  2369. //
  2370. if (state.line === _line || state.lineIndent > nodeIndent) {
  2371. if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
  2372. if (atExplicitKey) {
  2373. keyNode = state.result;
  2374. } else {
  2375. valueNode = state.result;
  2376. }
  2377. }
  2378. if (!atExplicitKey) {
  2379. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos);
  2380. keyTag = keyNode = valueNode = null;
  2381. }
  2382. skipSeparationSpace(state, true, -1);
  2383. ch = state.input.charCodeAt(state.position);
  2384. }
  2385. if (state.lineIndent > nodeIndent && ch !== 0) {
  2386. throwError(state, 'bad indentation of a mapping entry');
  2387. } else if (state.lineIndent < nodeIndent) {
  2388. break;
  2389. }
  2390. } //
  2391. // Epilogue.
  2392. //
  2393. // Special case: last mapping's node contains only the key in explicit notation.
  2394. if (atExplicitKey) {
  2395. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  2396. } // Expose the resulting mapping.
  2397. if (detected) {
  2398. state.tag = _tag;
  2399. state.anchor = _anchor;
  2400. state.kind = 'mapping';
  2401. state.result = _result;
  2402. }
  2403. return detected;
  2404. }
  2405. function readTagProperty(state) {
  2406. var _position,
  2407. isVerbatim = false,
  2408. isNamed = false,
  2409. tagHandle,
  2410. tagName,
  2411. ch;
  2412. ch = state.input.charCodeAt(state.position);
  2413. if (ch !== 0x21
  2414. /* ! */
  2415. ) return false;
  2416. if (state.tag !== null) {
  2417. throwError(state, 'duplication of a tag property');
  2418. }
  2419. ch = state.input.charCodeAt(++state.position);
  2420. if (ch === 0x3C
  2421. /* < */
  2422. ) {
  2423. isVerbatim = true;
  2424. ch = state.input.charCodeAt(++state.position);
  2425. } else if (ch === 0x21
  2426. /* ! */
  2427. ) {
  2428. isNamed = true;
  2429. tagHandle = '!!';
  2430. ch = state.input.charCodeAt(++state.position);
  2431. } else {
  2432. tagHandle = '!';
  2433. }
  2434. _position = state.position;
  2435. if (isVerbatim) {
  2436. do {
  2437. ch = state.input.charCodeAt(++state.position);
  2438. } while (ch !== 0 && ch !== 0x3E
  2439. /* > */
  2440. );
  2441. if (state.position < state.length) {
  2442. tagName = state.input.slice(_position, state.position);
  2443. ch = state.input.charCodeAt(++state.position);
  2444. } else {
  2445. throwError(state, 'unexpected end of the stream within a verbatim tag');
  2446. }
  2447. } else {
  2448. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  2449. if (ch === 0x21
  2450. /* ! */
  2451. ) {
  2452. if (!isNamed) {
  2453. tagHandle = state.input.slice(_position - 1, state.position + 1);
  2454. if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
  2455. throwError(state, 'named tag handle cannot contain such characters');
  2456. }
  2457. isNamed = true;
  2458. _position = state.position + 1;
  2459. } else {
  2460. throwError(state, 'tag suffix cannot contain exclamation marks');
  2461. }
  2462. }
  2463. ch = state.input.charCodeAt(++state.position);
  2464. }
  2465. tagName = state.input.slice(_position, state.position);
  2466. if (PATTERN_FLOW_INDICATORS.test(tagName)) {
  2467. throwError(state, 'tag suffix cannot contain flow indicator characters');
  2468. }
  2469. }
  2470. if (tagName && !PATTERN_TAG_URI.test(tagName)) {
  2471. throwError(state, 'tag name cannot contain such characters: ' + tagName);
  2472. }
  2473. if (isVerbatim) {
  2474. state.tag = tagName;
  2475. } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
  2476. state.tag = state.tagMap[tagHandle] + tagName;
  2477. } else if (tagHandle === '!') {
  2478. state.tag = '!' + tagName;
  2479. } else if (tagHandle === '!!') {
  2480. state.tag = 'tag:yaml.org,2002:' + tagName;
  2481. } else {
  2482. throwError(state, 'undeclared tag handle "' + tagHandle + '"');
  2483. }
  2484. return true;
  2485. }
  2486. function readAnchorProperty(state) {
  2487. var _position, ch;
  2488. ch = state.input.charCodeAt(state.position);
  2489. if (ch !== 0x26
  2490. /* & */
  2491. ) return false;
  2492. if (state.anchor !== null) {
  2493. throwError(state, 'duplication of an anchor property');
  2494. }
  2495. ch = state.input.charCodeAt(++state.position);
  2496. _position = state.position;
  2497. while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
  2498. ch = state.input.charCodeAt(++state.position);
  2499. }
  2500. if (state.position === _position) {
  2501. throwError(state, 'name of an anchor node must contain at least one character');
  2502. }
  2503. state.anchor = state.input.slice(_position, state.position);
  2504. return true;
  2505. }
  2506. function readAlias(state) {
  2507. var _position, alias, ch;
  2508. ch = state.input.charCodeAt(state.position);
  2509. if (ch !== 0x2A
  2510. /* * */
  2511. ) return false;
  2512. ch = state.input.charCodeAt(++state.position);
  2513. _position = state.position;
  2514. while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
  2515. ch = state.input.charCodeAt(++state.position);
  2516. }
  2517. if (state.position === _position) {
  2518. throwError(state, 'name of an alias node must contain at least one character');
  2519. }
  2520. alias = state.input.slice(_position, state.position);
  2521. if (!state.anchorMap.hasOwnProperty(alias)) {
  2522. throwError(state, 'unidentified alias "' + alias + '"');
  2523. }
  2524. state.result = state.anchorMap[alias];
  2525. skipSeparationSpace(state, true, -1);
  2526. return true;
  2527. }
  2528. function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
  2529. var allowBlockStyles,
  2530. allowBlockScalars,
  2531. allowBlockCollections,
  2532. indentStatus = 1,
  2533. // 1: this>parent, 0: this=parent, -1: this<parent
  2534. atNewLine = false,
  2535. hasContent = false,
  2536. typeIndex,
  2537. typeQuantity,
  2538. type,
  2539. flowIndent,
  2540. blockIndent;
  2541. if (state.listener !== null) {
  2542. state.listener('open', state);
  2543. }
  2544. state.tag = null;
  2545. state.anchor = null;
  2546. state.kind = null;
  2547. state.result = null;
  2548. allowBlockStyles = allowBlockScalars = allowBlockCollections = CONTEXT_BLOCK_OUT === nodeContext || CONTEXT_BLOCK_IN === nodeContext;
  2549. if (allowToSeek) {
  2550. if (skipSeparationSpace(state, true, -1)) {
  2551. atNewLine = true;
  2552. if (state.lineIndent > parentIndent) {
  2553. indentStatus = 1;
  2554. } else if (state.lineIndent === parentIndent) {
  2555. indentStatus = 0;
  2556. } else if (state.lineIndent < parentIndent) {
  2557. indentStatus = -1;
  2558. }
  2559. }
  2560. }
  2561. if (indentStatus === 1) {
  2562. while (readTagProperty(state) || readAnchorProperty(state)) {
  2563. if (skipSeparationSpace(state, true, -1)) {
  2564. atNewLine = true;
  2565. allowBlockCollections = allowBlockStyles;
  2566. if (state.lineIndent > parentIndent) {
  2567. indentStatus = 1;
  2568. } else if (state.lineIndent === parentIndent) {
  2569. indentStatus = 0;
  2570. } else if (state.lineIndent < parentIndent) {
  2571. indentStatus = -1;
  2572. }
  2573. } else {
  2574. allowBlockCollections = false;
  2575. }
  2576. }
  2577. }
  2578. if (allowBlockCollections) {
  2579. allowBlockCollections = atNewLine || allowCompact;
  2580. }
  2581. if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
  2582. if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
  2583. flowIndent = parentIndent;
  2584. } else {
  2585. flowIndent = parentIndent + 1;
  2586. }
  2587. blockIndent = state.position - state.lineStart;
  2588. if (indentStatus === 1) {
  2589. if (allowBlockCollections && (readBlockSequence(state, blockIndent) || readBlockMapping(state, blockIndent, flowIndent)) || readFlowCollection(state, flowIndent)) {
  2590. hasContent = true;
  2591. } else {
  2592. if (allowBlockScalars && readBlockScalar(state, flowIndent) || readSingleQuotedScalar(state, flowIndent) || readDoubleQuotedScalar(state, flowIndent)) {
  2593. hasContent = true;
  2594. } else if (readAlias(state)) {
  2595. hasContent = true;
  2596. if (state.tag !== null || state.anchor !== null) {
  2597. throwError(state, 'alias node should not have any properties');
  2598. }
  2599. } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
  2600. hasContent = true;
  2601. if (state.tag === null) {
  2602. state.tag = '?';
  2603. }
  2604. }
  2605. if (state.anchor !== null) {
  2606. state.anchorMap[state.anchor] = state.result;
  2607. }
  2608. }
  2609. } else if (indentStatus === 0) {
  2610. // Special case: block sequences are allowed to have same indentation level as the parent.
  2611. // http://www.yaml.org/spec/1.2/spec.html#id2799784
  2612. hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
  2613. }
  2614. }
  2615. if (state.tag !== null && state.tag !== '!') {
  2616. if (state.tag === '?') {
  2617. for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
  2618. type = state.implicitTypes[typeIndex]; // Implicit resolving is not allowed for non-scalar types, and '?'
  2619. // non-specific tag is only assigned to plain scalars. So, it isn't
  2620. // needed to check for 'kind' conformity.
  2621. if (type.resolve(state.result)) {
  2622. // `state.result` updated in resolver if matched
  2623. state.result = type.construct(state.result);
  2624. state.tag = type.tag;
  2625. if (state.anchor !== null) {
  2626. state.anchorMap[state.anchor] = state.result;
  2627. }
  2628. break;
  2629. }
  2630. }
  2631. } else if (_hasOwnProperty.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
  2632. type = state.typeMap[state.kind || 'fallback'][state.tag];
  2633. if (state.result !== null && type.kind !== state.kind) {
  2634. throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
  2635. }
  2636. if (!type.resolve(state.result)) {
  2637. // `state.result` updated in resolver if matched
  2638. throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
  2639. } else {
  2640. state.result = type.construct(state.result);
  2641. if (state.anchor !== null) {
  2642. state.anchorMap[state.anchor] = state.result;
  2643. }
  2644. }
  2645. } else {
  2646. throwError(state, 'unknown tag !<' + state.tag + '>');
  2647. }
  2648. }
  2649. if (state.listener !== null) {
  2650. state.listener('close', state);
  2651. }
  2652. return state.tag !== null || state.anchor !== null || hasContent;
  2653. }
  2654. function readDocument(state) {
  2655. var documentStart = state.position,
  2656. _position,
  2657. directiveName,
  2658. directiveArgs,
  2659. hasDirectives = false,
  2660. ch;
  2661. state.version = null;
  2662. state.checkLineBreaks = state.legacy;
  2663. state.tagMap = {};
  2664. state.anchorMap = {};
  2665. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  2666. skipSeparationSpace(state, true, -1);
  2667. ch = state.input.charCodeAt(state.position);
  2668. if (state.lineIndent > 0 || ch !== 0x25
  2669. /* % */
  2670. ) {
  2671. break;
  2672. }
  2673. hasDirectives = true;
  2674. ch = state.input.charCodeAt(++state.position);
  2675. _position = state.position;
  2676. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  2677. ch = state.input.charCodeAt(++state.position);
  2678. }
  2679. directiveName = state.input.slice(_position, state.position);
  2680. directiveArgs = [];
  2681. if (directiveName.length < 1) {
  2682. throwError(state, 'directive name must not be less than one character in length');
  2683. }
  2684. while (ch !== 0) {
  2685. while (is_WHITE_SPACE(ch)) {
  2686. ch = state.input.charCodeAt(++state.position);
  2687. }
  2688. if (ch === 0x23
  2689. /* # */
  2690. ) {
  2691. do {
  2692. ch = state.input.charCodeAt(++state.position);
  2693. } while (ch !== 0 && !is_EOL(ch));
  2694. break;
  2695. }
  2696. if (is_EOL(ch)) break;
  2697. _position = state.position;
  2698. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  2699. ch = state.input.charCodeAt(++state.position);
  2700. }
  2701. directiveArgs.push(state.input.slice(_position, state.position));
  2702. }
  2703. if (ch !== 0) readLineBreak(state);
  2704. if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
  2705. directiveHandlers[directiveName](state, directiveName, directiveArgs);
  2706. } else {
  2707. throwWarning(state, 'unknown document directive "' + directiveName + '"');
  2708. }
  2709. }
  2710. skipSeparationSpace(state, true, -1);
  2711. if (state.lineIndent === 0 && state.input.charCodeAt(state.position) === 0x2D
  2712. /* - */
  2713. && state.input.charCodeAt(state.position + 1) === 0x2D
  2714. /* - */
  2715. && state.input.charCodeAt(state.position + 2) === 0x2D
  2716. /* - */
  2717. ) {
  2718. state.position += 3;
  2719. skipSeparationSpace(state, true, -1);
  2720. } else if (hasDirectives) {
  2721. throwError(state, 'directives end mark is expected');
  2722. }
  2723. composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
  2724. skipSeparationSpace(state, true, -1);
  2725. if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
  2726. throwWarning(state, 'non-ASCII line breaks are interpreted as content');
  2727. }
  2728. state.documents.push(state.result);
  2729. if (state.position === state.lineStart && testDocumentSeparator(state)) {
  2730. if (state.input.charCodeAt(state.position) === 0x2E
  2731. /* . */
  2732. ) {
  2733. state.position += 3;
  2734. skipSeparationSpace(state, true, -1);
  2735. }
  2736. return;
  2737. }
  2738. if (state.position < state.length - 1) {
  2739. throwError(state, 'end of the stream or a document separator is expected');
  2740. } else {
  2741. return;
  2742. }
  2743. }
  2744. function loadDocuments(input, options) {
  2745. input = String(input);
  2746. options = options || {};
  2747. if (input.length !== 0) {
  2748. // Add tailing `\n` if not exists
  2749. if (input.charCodeAt(input.length - 1) !== 0x0A
  2750. /* LF */
  2751. && input.charCodeAt(input.length - 1) !== 0x0D
  2752. /* CR */
  2753. ) {
  2754. input += '\n';
  2755. } // Strip BOM
  2756. if (input.charCodeAt(0) === 0xFEFF) {
  2757. input = input.slice(1);
  2758. }
  2759. }
  2760. var state = new State(input, options); // Use 0 as string terminator. That significantly simplifies bounds check.
  2761. state.input += '\0';
  2762. while (state.input.charCodeAt(state.position) === 0x20
  2763. /* Space */
  2764. ) {
  2765. state.lineIndent += 1;
  2766. state.position += 1;
  2767. }
  2768. while (state.position < state.length - 1) {
  2769. readDocument(state);
  2770. }
  2771. return state.documents;
  2772. }
  2773. function loadAll$1(input, iterator, options) {
  2774. var documents = loadDocuments(input, options),
  2775. index,
  2776. length;
  2777. if (typeof iterator !== 'function') {
  2778. return documents;
  2779. }
  2780. for (index = 0, length = documents.length; index < length; index += 1) {
  2781. iterator(documents[index]);
  2782. }
  2783. }
  2784. function load$1(input, options) {
  2785. var documents = loadDocuments(input, options);
  2786. if (documents.length === 0) {
  2787. /*eslint-disable no-undefined*/
  2788. return undefined;
  2789. } else if (documents.length === 1) {
  2790. return documents[0];
  2791. }
  2792. throw new exception('expected a single document in the stream, but found more');
  2793. }
  2794. function safeLoadAll$1(input, output, options) {
  2795. if (typeof output === 'function') {
  2796. loadAll$1(input, output, common.extend({
  2797. schema: default_safe
  2798. }, options));
  2799. } else {
  2800. return loadAll$1(input, common.extend({
  2801. schema: default_safe
  2802. }, options));
  2803. }
  2804. }
  2805. function safeLoad$1(input, options) {
  2806. return load$1(input, common.extend({
  2807. schema: default_safe
  2808. }, options));
  2809. }
  2810. var loadAll_1 = loadAll$1;
  2811. var load_1 = load$1;
  2812. var safeLoadAll_1 = safeLoadAll$1;
  2813. var safeLoad_1 = safeLoad$1;
  2814. var loader = {
  2815. loadAll: loadAll_1,
  2816. load: load_1,
  2817. safeLoadAll: safeLoadAll_1,
  2818. safeLoad: safeLoad_1
  2819. };
  2820. /*eslint-disable no-use-before-define*/
  2821. var _toString$2 = Object.prototype.toString;
  2822. var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
  2823. var CHAR_TAB = 0x09;
  2824. /* Tab */
  2825. var CHAR_LINE_FEED = 0x0A;
  2826. /* LF */
  2827. var CHAR_SPACE = 0x20;
  2828. /* Space */
  2829. var CHAR_EXCLAMATION = 0x21;
  2830. /* ! */
  2831. var CHAR_DOUBLE_QUOTE = 0x22;
  2832. /* " */
  2833. var CHAR_SHARP = 0x23;
  2834. /* # */
  2835. var CHAR_PERCENT = 0x25;
  2836. /* % */
  2837. var CHAR_AMPERSAND = 0x26;
  2838. /* & */
  2839. var CHAR_SINGLE_QUOTE = 0x27;
  2840. /* ' */
  2841. var CHAR_ASTERISK = 0x2A;
  2842. /* * */
  2843. var CHAR_COMMA = 0x2C;
  2844. /* , */
  2845. var CHAR_MINUS = 0x2D;
  2846. /* - */
  2847. var CHAR_COLON = 0x3A;
  2848. /* : */
  2849. var CHAR_GREATER_THAN = 0x3E;
  2850. /* > */
  2851. var CHAR_QUESTION = 0x3F;
  2852. /* ? */
  2853. var CHAR_COMMERCIAL_AT = 0x40;
  2854. /* @ */
  2855. var CHAR_LEFT_SQUARE_BRACKET = 0x5B;
  2856. /* [ */
  2857. var CHAR_RIGHT_SQUARE_BRACKET = 0x5D;
  2858. /* ] */
  2859. var CHAR_GRAVE_ACCENT = 0x60;
  2860. /* ` */
  2861. var CHAR_LEFT_CURLY_BRACKET = 0x7B;
  2862. /* { */
  2863. var CHAR_VERTICAL_LINE = 0x7C;
  2864. /* | */
  2865. var CHAR_RIGHT_CURLY_BRACKET = 0x7D;
  2866. /* } */
  2867. var ESCAPE_SEQUENCES = {};
  2868. ESCAPE_SEQUENCES[0x00] = '\\0';
  2869. ESCAPE_SEQUENCES[0x07] = '\\a';
  2870. ESCAPE_SEQUENCES[0x08] = '\\b';
  2871. ESCAPE_SEQUENCES[0x09] = '\\t';
  2872. ESCAPE_SEQUENCES[0x0A] = '\\n';
  2873. ESCAPE_SEQUENCES[0x0B] = '\\v';
  2874. ESCAPE_SEQUENCES[0x0C] = '\\f';
  2875. ESCAPE_SEQUENCES[0x0D] = '\\r';
  2876. ESCAPE_SEQUENCES[0x1B] = '\\e';
  2877. ESCAPE_SEQUENCES[0x22] = '\\"';
  2878. ESCAPE_SEQUENCES[0x5C] = '\\\\';
  2879. ESCAPE_SEQUENCES[0x85] = '\\N';
  2880. ESCAPE_SEQUENCES[0xA0] = '\\_';
  2881. ESCAPE_SEQUENCES[0x2028] = '\\L';
  2882. ESCAPE_SEQUENCES[0x2029] = '\\P';
  2883. var DEPRECATED_BOOLEANS_SYNTAX = ['y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON', 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'];
  2884. function compileStyleMap(schema, map) {
  2885. var result, keys, index, length, tag, style, type;
  2886. if (map === null) return {};
  2887. result = {};
  2888. keys = Object.keys(map);
  2889. for (index = 0, length = keys.length; index < length; index += 1) {
  2890. tag = keys[index];
  2891. style = String(map[tag]);
  2892. if (tag.slice(0, 2) === '!!') {
  2893. tag = 'tag:yaml.org,2002:' + tag.slice(2);
  2894. }
  2895. type = schema.compiledTypeMap['fallback'][tag];
  2896. if (type && _hasOwnProperty$3.call(type.styleAliases, style)) {
  2897. style = type.styleAliases[style];
  2898. }
  2899. result[tag] = style;
  2900. }
  2901. return result;
  2902. }
  2903. function encodeHex(character) {
  2904. var string, handle, length;
  2905. string = character.toString(16).toUpperCase();
  2906. if (character <= 0xFF) {
  2907. handle = 'x';
  2908. length = 2;
  2909. } else if (character <= 0xFFFF) {
  2910. handle = 'u';
  2911. length = 4;
  2912. } else if (character <= 0xFFFFFFFF) {
  2913. handle = 'U';
  2914. length = 8;
  2915. } else {
  2916. throw new exception('code point within a string may not be greater than 0xFFFFFFFF');
  2917. }
  2918. return '\\' + handle + common.repeat('0', length - string.length) + string;
  2919. }
  2920. function State$1(options) {
  2921. this.schema = options['schema'] || default_full;
  2922. this.indent = Math.max(1, options['indent'] || 2);
  2923. this.skipInvalid = options['skipInvalid'] || false;
  2924. this.flowLevel = common.isNothing(options['flowLevel']) ? -1 : options['flowLevel'];
  2925. this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
  2926. this.sortKeys = options['sortKeys'] || false;
  2927. this.lineWidth = options['lineWidth'] || 80;
  2928. this.noRefs = options['noRefs'] || false;
  2929. this.noCompatMode = options['noCompatMode'] || false;
  2930. this.condenseFlow = options['condenseFlow'] || false;
  2931. this.implicitTypes = this.schema.compiledImplicit;
  2932. this.explicitTypes = this.schema.compiledExplicit;
  2933. this.tag = null;
  2934. this.result = '';
  2935. this.duplicates = [];
  2936. this.usedDuplicates = null;
  2937. } // Indents every line in a string. Empty lines (\n only) are not indented.
  2938. function indentString(string, spaces) {
  2939. var ind = common.repeat(' ', spaces),
  2940. position = 0,
  2941. next = -1,
  2942. result = '',
  2943. line,
  2944. length = string.length;
  2945. while (position < length) {
  2946. next = string.indexOf('\n', position);
  2947. if (next === -1) {
  2948. line = string.slice(position);
  2949. position = length;
  2950. } else {
  2951. line = string.slice(position, next + 1);
  2952. position = next + 1;
  2953. }
  2954. if (line.length && line !== '\n') result += ind;
  2955. result += line;
  2956. }
  2957. return result;
  2958. }
  2959. function generateNextLine(state, level) {
  2960. return '\n' + common.repeat(' ', state.indent * level);
  2961. }
  2962. function testImplicitResolving(state, str) {
  2963. var index, length, type;
  2964. for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
  2965. type = state.implicitTypes[index];
  2966. if (type.resolve(str)) {
  2967. return true;
  2968. }
  2969. }
  2970. return false;
  2971. } // [33] s-white ::= s-space | s-tab
  2972. function isWhitespace(c) {
  2973. return c === CHAR_SPACE || c === CHAR_TAB;
  2974. } // Returns true if the character can be printed without escaping.
  2975. // From YAML 1.2: "any allowed characters known to be non-printable
  2976. // should also be escaped. [However,] This isn’t mandatory"
  2977. // Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029.
  2978. function isPrintable(c) {
  2979. return 0x00020 <= c && c <= 0x00007E || 0x000A1 <= c && c <= 0x00D7FF && c !== 0x2028 && c !== 0x2029 || 0x0E000 <= c && c <= 0x00FFFD && c !== 0xFEFF
  2980. /* BOM */
  2981. || 0x10000 <= c && c <= 0x10FFFF;
  2982. } // Simplified test for values allowed after the first character in plain style.
  2983. function isPlainSafe(c) {
  2984. // Uses a subset of nb-char - c-flow-indicator - ":" - "#"
  2985. // where nb-char ::= c-printable - b-char - c-byte-order-mark.
  2986. return isPrintable(c) && c !== 0xFEFF // - c-flow-indicator
  2987. && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET // - ":" - "#"
  2988. && c !== CHAR_COLON && c !== CHAR_SHARP;
  2989. } // Simplified test for values allowed as the first character in plain style.
  2990. function isPlainSafeFirst(c) {
  2991. // Uses a subset of ns-char - c-indicator
  2992. // where ns-char = nb-char - s-white.
  2993. return isPrintable(c) && c !== 0xFEFF && !isWhitespace(c) // - s-white
  2994. // - (c-indicator ::=
  2995. // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}”
  2996. && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET // | “#” | “&” | “*” | “!” | “|” | “>” | “'” | “"”
  2997. && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE // | “%” | “@” | “`”)
  2998. && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
  2999. } // Determines whether block indentation indicator is required.
  3000. function needIndentIndicator(string) {
  3001. var leadingSpaceRe = /^\n* /;
  3002. return leadingSpaceRe.test(string);
  3003. }
  3004. var STYLE_PLAIN = 1;
  3005. var STYLE_SINGLE = 2;
  3006. var STYLE_LITERAL = 3;
  3007. var STYLE_FOLDED = 4;
  3008. var STYLE_DOUBLE = 5; // Determines which scalar styles are possible and returns the preferred style.
  3009. // lineWidth = -1 => no limit.
  3010. // Pre-conditions: str.length > 0.
  3011. // Post-conditions:
  3012. // STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
  3013. // STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
  3014. // STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1).
  3015. function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
  3016. var i;
  3017. var char;
  3018. var hasLineBreak = false;
  3019. var hasFoldableLine = false; // only checked if shouldTrackWidth
  3020. var shouldTrackWidth = lineWidth !== -1;
  3021. var previousLineBreak = -1; // count the first line correctly
  3022. var plain = isPlainSafeFirst(string.charCodeAt(0)) && !isWhitespace(string.charCodeAt(string.length - 1));
  3023. if (singleLineOnly) {
  3024. // Case: no block styles.
  3025. // Check for disallowed characters to rule out plain and single.
  3026. for (i = 0; i < string.length; i++) {
  3027. char = string.charCodeAt(i);
  3028. if (!isPrintable(char)) {
  3029. return STYLE_DOUBLE;
  3030. }
  3031. plain = plain && isPlainSafe(char);
  3032. }
  3033. } else {
  3034. // Case: block styles permitted.
  3035. for (i = 0; i < string.length; i++) {
  3036. char = string.charCodeAt(i);
  3037. if (char === CHAR_LINE_FEED) {
  3038. hasLineBreak = true; // Check if any line can be folded.
  3039. if (shouldTrackWidth) {
  3040. hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
  3041. i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== ' ';
  3042. previousLineBreak = i;
  3043. }
  3044. } else if (!isPrintable(char)) {
  3045. return STYLE_DOUBLE;
  3046. }
  3047. plain = plain && isPlainSafe(char);
  3048. } // in case the end is missing a \n
  3049. hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== ' ';
  3050. } // Although every style can represent \n without escaping, prefer block styles
  3051. // for multiline, since they're more readable and they don't add empty lines.
  3052. // Also prefer folding a super-long line.
  3053. if (!hasLineBreak && !hasFoldableLine) {
  3054. // Strings interpretable as another type have to be quoted;
  3055. // e.g. the string 'true' vs. the boolean true.
  3056. return plain && !testAmbiguousType(string) ? STYLE_PLAIN : STYLE_SINGLE;
  3057. } // Edge case: block indentation indicator can only have one digit.
  3058. if (indentPerLevel > 9 && needIndentIndicator(string)) {
  3059. return STYLE_DOUBLE;
  3060. } // At this point we know block styles are valid.
  3061. // Prefer literal style unless we want to fold.
  3062. return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
  3063. } // Note: line breaking/folding is implemented for only the folded style.
  3064. // NB. We drop the last trailing newline (if any) of a returned block scalar
  3065. // since the dumper adds its own newline. This always works:
  3066. // • No ending newline => unaffected; already using strip "-" chomping.
  3067. // • Ending newline => removed then restored.
  3068. // Importantly, this keeps the "+" chomp indicator from gaining an extra line.
  3069. function writeScalar(state, string, level, iskey) {
  3070. state.dump = function () {
  3071. if (string.length === 0) {
  3072. return "''";
  3073. }
  3074. if (!state.noCompatMode && DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
  3075. return "'" + string + "'";
  3076. }
  3077. var indent = state.indent * Math.max(1, level); // no 0-indent scalars
  3078. // As indentation gets deeper, let the width decrease monotonically
  3079. // to the lower bound min(state.lineWidth, 40).
  3080. // Note that this implies
  3081. // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
  3082. // state.lineWidth > 40 + state.indent: width decreases until the lower bound.
  3083. // This behaves better than a constant minimum width which disallows narrower options,
  3084. // or an indent threshold which causes the width to suddenly increase.
  3085. var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent); // Without knowing if keys are implicit/explicit, assume implicit for safety.
  3086. var singleLineOnly = iskey // No block styles in flow mode.
  3087. || state.flowLevel > -1 && level >= state.flowLevel;
  3088. function testAmbiguity(string) {
  3089. return testImplicitResolving(state, string);
  3090. }
  3091. switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
  3092. case STYLE_PLAIN:
  3093. return string;
  3094. case STYLE_SINGLE:
  3095. return "'" + string.replace(/'/g, "''") + "'";
  3096. case STYLE_LITERAL:
  3097. return '|' + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
  3098. case STYLE_FOLDED:
  3099. return '>' + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
  3100. case STYLE_DOUBLE:
  3101. return '"' + escapeString(string, lineWidth) + '"';
  3102. default:
  3103. throw new exception('impossible error: invalid scalar style');
  3104. }
  3105. }();
  3106. } // Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
  3107. function blockHeader(string, indentPerLevel) {
  3108. var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : ''; // note the special case: the string '\n' counts as a "trailing" empty line.
  3109. var clip = string[string.length - 1] === '\n';
  3110. var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
  3111. var chomp = keep ? '+' : clip ? '' : '-';
  3112. return indentIndicator + chomp + '\n';
  3113. } // (See the note for writeScalar.)
  3114. function dropEndingNewline(string) {
  3115. return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
  3116. } // Note: a long line without a suitable break point will exceed the width limit.
  3117. // Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
  3118. function foldString(string, width) {
  3119. // In folded style, $k$ consecutive newlines output as $k+1$ newlines—
  3120. // unless they're before or after a more-indented line, or at the very
  3121. // beginning or end, in which case $k$ maps to $k$.
  3122. // Therefore, parse each chunk as newline(s) followed by a content line.
  3123. var lineRe = /(\n+)([^\n]*)/g; // first line (possibly an empty line)
  3124. var result = function () {
  3125. var nextLF = string.indexOf('\n');
  3126. nextLF = nextLF !== -1 ? nextLF : string.length;
  3127. lineRe.lastIndex = nextLF;
  3128. return foldLine(string.slice(0, nextLF), width);
  3129. }(); // If we haven't reached the first content line yet, don't add an extra \n.
  3130. var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
  3131. var moreIndented; // rest of the lines
  3132. var match;
  3133. while (match = lineRe.exec(string)) {
  3134. var prefix = match[1],
  3135. line = match[2];
  3136. moreIndented = line[0] === ' ';
  3137. result += prefix + (!prevMoreIndented && !moreIndented && line !== '' ? '\n' : '') + foldLine(line, width);
  3138. prevMoreIndented = moreIndented;
  3139. }
  3140. return result;
  3141. } // Greedy line breaking.
  3142. // Picks the longest line under the limit each time,
  3143. // otherwise settles for the shortest line over the limit.
  3144. // NB. More-indented lines *cannot* be folded, as that would add an extra \n.
  3145. function foldLine(line, width) {
  3146. if (line === '' || line[0] === ' ') return line; // Since a more-indented line adds a \n, breaks can't be followed by a space.
  3147. var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
  3148. var match; // start is an inclusive index. end, curr, and next are exclusive.
  3149. var start = 0,
  3150. end,
  3151. curr = 0,
  3152. next = 0;
  3153. var result = ''; // Invariants: 0 <= start <= length-1.
  3154. // 0 <= curr <= next <= max(0, length-2). curr - start <= width.
  3155. // Inside the loop:
  3156. // A match implies length >= 2, so curr and next are <= length-2.
  3157. while (match = breakRe.exec(line)) {
  3158. next = match.index; // maintain invariant: curr - start <= width
  3159. if (next - start > width) {
  3160. end = curr > start ? curr : next; // derive end <= length-2
  3161. result += '\n' + line.slice(start, end); // skip the space that was output as \n
  3162. start = end + 1; // derive start <= length-1
  3163. }
  3164. curr = next;
  3165. } // By the invariants, start <= length-1, so there is something left over.
  3166. // It is either the whole string or a part starting from non-whitespace.
  3167. result += '\n'; // Insert a break if the remainder is too long and there is a break available.
  3168. if (line.length - start > width && curr > start) {
  3169. result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
  3170. } else {
  3171. result += line.slice(start);
  3172. }
  3173. return result.slice(1); // drop extra \n joiner
  3174. } // Escapes a double-quoted string.
  3175. function escapeString(string) {
  3176. var result = '';
  3177. var char, nextChar;
  3178. var escapeSeq;
  3179. for (var i = 0; i < string.length; i++) {
  3180. char = string.charCodeAt(i); // Check for surrogate pairs (reference Unicode 3.0 section "3.7 Surrogates").
  3181. if (char >= 0xD800 && char <= 0xDBFF
  3182. /* high surrogate */
  3183. ) {
  3184. nextChar = string.charCodeAt(i + 1);
  3185. if (nextChar >= 0xDC00 && nextChar <= 0xDFFF
  3186. /* low surrogate */
  3187. ) {
  3188. // Combine the surrogate pair and store it escaped.
  3189. result += encodeHex((char - 0xD800) * 0x400 + nextChar - 0xDC00 + 0x10000); // Advance index one extra since we already used that char here.
  3190. i++;
  3191. continue;
  3192. }
  3193. }
  3194. escapeSeq = ESCAPE_SEQUENCES[char];
  3195. result += !escapeSeq && isPrintable(char) ? string[i] : escapeSeq || encodeHex(char);
  3196. }
  3197. return result;
  3198. }
  3199. function writeFlowSequence(state, level, object) {
  3200. var _result = '',
  3201. _tag = state.tag,
  3202. index,
  3203. length;
  3204. for (index = 0, length = object.length; index < length; index += 1) {
  3205. // Write only valid elements.
  3206. if (writeNode(state, level, object[index], false, false)) {
  3207. if (index !== 0) _result += ',' + (!state.condenseFlow ? ' ' : '');
  3208. _result += state.dump;
  3209. }
  3210. }
  3211. state.tag = _tag;
  3212. state.dump = '[' + _result + ']';
  3213. }
  3214. function writeBlockSequence(state, level, object, compact) {
  3215. var _result = '',
  3216. _tag = state.tag,
  3217. index,
  3218. length;
  3219. for (index = 0, length = object.length; index < length; index += 1) {
  3220. // Write only valid elements.
  3221. if (writeNode(state, level + 1, object[index], true, true)) {
  3222. if (!compact || index !== 0) {
  3223. _result += generateNextLine(state, level);
  3224. }
  3225. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  3226. _result += '-';
  3227. } else {
  3228. _result += '- ';
  3229. }
  3230. _result += state.dump;
  3231. }
  3232. }
  3233. state.tag = _tag;
  3234. state.dump = _result || '[]'; // Empty sequence if no valid values.
  3235. }
  3236. function writeFlowMapping(state, level, object) {
  3237. var _result = '',
  3238. _tag = state.tag,
  3239. objectKeyList = Object.keys(object),
  3240. index,
  3241. length,
  3242. objectKey,
  3243. objectValue,
  3244. pairBuffer;
  3245. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  3246. pairBuffer = state.condenseFlow ? '"' : '';
  3247. if (index !== 0) pairBuffer += ', ';
  3248. objectKey = objectKeyList[index];
  3249. objectValue = object[objectKey];
  3250. if (!writeNode(state, level, objectKey, false, false)) {
  3251. continue; // Skip this pair because of invalid key;
  3252. }
  3253. if (state.dump.length > 1024) pairBuffer += '? ';
  3254. pairBuffer += state.dump + (state.condenseFlow ? '"' : '') + ':' + (state.condenseFlow ? '' : ' ');
  3255. if (!writeNode(state, level, objectValue, false, false)) {
  3256. continue; // Skip this pair because of invalid value.
  3257. }
  3258. pairBuffer += state.dump; // Both key and value are valid.
  3259. _result += pairBuffer;
  3260. }
  3261. state.tag = _tag;
  3262. state.dump = '{' + _result + '}';
  3263. }
  3264. function writeBlockMapping(state, level, object, compact) {
  3265. var _result = '',
  3266. _tag = state.tag,
  3267. objectKeyList = Object.keys(object),
  3268. index,
  3269. length,
  3270. objectKey,
  3271. objectValue,
  3272. explicitPair,
  3273. pairBuffer; // Allow sorting keys so that the output file is deterministic
  3274. if (state.sortKeys === true) {
  3275. // Default sorting
  3276. objectKeyList.sort();
  3277. } else if (typeof state.sortKeys === 'function') {
  3278. // Custom sort function
  3279. objectKeyList.sort(state.sortKeys);
  3280. } else if (state.sortKeys) {
  3281. // Something is wrong
  3282. throw new exception('sortKeys must be a boolean or a function');
  3283. }
  3284. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  3285. pairBuffer = '';
  3286. if (!compact || index !== 0) {
  3287. pairBuffer += generateNextLine(state, level);
  3288. }
  3289. objectKey = objectKeyList[index];
  3290. objectValue = object[objectKey];
  3291. if (!writeNode(state, level + 1, objectKey, true, true, true)) {
  3292. continue; // Skip this pair because of invalid key.
  3293. }
  3294. explicitPair = state.tag !== null && state.tag !== '?' || state.dump && state.dump.length > 1024;
  3295. if (explicitPair) {
  3296. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  3297. pairBuffer += '?';
  3298. } else {
  3299. pairBuffer += '? ';
  3300. }
  3301. }
  3302. pairBuffer += state.dump;
  3303. if (explicitPair) {
  3304. pairBuffer += generateNextLine(state, level);
  3305. }
  3306. if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
  3307. continue; // Skip this pair because of invalid value.
  3308. }
  3309. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  3310. pairBuffer += ':';
  3311. } else {
  3312. pairBuffer += ': ';
  3313. }
  3314. pairBuffer += state.dump; // Both key and value are valid.
  3315. _result += pairBuffer;
  3316. }
  3317. state.tag = _tag;
  3318. state.dump = _result || '{}'; // Empty mapping if no valid pairs.
  3319. }
  3320. function detectType(state, object, explicit) {
  3321. var _result, typeList, index, length, type, style;
  3322. typeList = explicit ? state.explicitTypes : state.implicitTypes;
  3323. for (index = 0, length = typeList.length; index < length; index += 1) {
  3324. type = typeList[index];
  3325. if ((type.instanceOf || type.predicate) && (!type.instanceOf || typeof object === 'object' && object instanceof type.instanceOf) && (!type.predicate || type.predicate(object))) {
  3326. state.tag = explicit ? type.tag : '?';
  3327. if (type.represent) {
  3328. style = state.styleMap[type.tag] || type.defaultStyle;
  3329. if (_toString$2.call(type.represent) === '[object Function]') {
  3330. _result = type.represent(object, style);
  3331. } else if (_hasOwnProperty$3.call(type.represent, style)) {
  3332. _result = type.represent[style](object, style);
  3333. } else {
  3334. throw new exception('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
  3335. }
  3336. state.dump = _result;
  3337. }
  3338. return true;
  3339. }
  3340. }
  3341. return false;
  3342. } // Serializes `object` and writes it to global `result`.
  3343. // Returns true on success, or false on invalid object.
  3344. //
  3345. function writeNode(state, level, object, block, compact, iskey) {
  3346. state.tag = null;
  3347. state.dump = object;
  3348. if (!detectType(state, object, false)) {
  3349. detectType(state, object, true);
  3350. }
  3351. var type = _toString$2.call(state.dump);
  3352. if (block) {
  3353. block = state.flowLevel < 0 || state.flowLevel > level;
  3354. }
  3355. var objectOrArray = type === '[object Object]' || type === '[object Array]',
  3356. duplicateIndex,
  3357. duplicate;
  3358. if (objectOrArray) {
  3359. duplicateIndex = state.duplicates.indexOf(object);
  3360. duplicate = duplicateIndex !== -1;
  3361. }
  3362. if (state.tag !== null && state.tag !== '?' || duplicate || state.indent !== 2 && level > 0) {
  3363. compact = false;
  3364. }
  3365. if (duplicate && state.usedDuplicates[duplicateIndex]) {
  3366. state.dump = '*ref_' + duplicateIndex;
  3367. } else {
  3368. if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
  3369. state.usedDuplicates[duplicateIndex] = true;
  3370. }
  3371. if (type === '[object Object]') {
  3372. if (block && Object.keys(state.dump).length !== 0) {
  3373. writeBlockMapping(state, level, state.dump, compact);
  3374. if (duplicate) {
  3375. state.dump = '&ref_' + duplicateIndex + state.dump;
  3376. }
  3377. } else {
  3378. writeFlowMapping(state, level, state.dump);
  3379. if (duplicate) {
  3380. state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
  3381. }
  3382. }
  3383. } else if (type === '[object Array]') {
  3384. if (block && state.dump.length !== 0) {
  3385. writeBlockSequence(state, level, state.dump, compact);
  3386. if (duplicate) {
  3387. state.dump = '&ref_' + duplicateIndex + state.dump;
  3388. }
  3389. } else {
  3390. writeFlowSequence(state, level, state.dump);
  3391. if (duplicate) {
  3392. state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
  3393. }
  3394. }
  3395. } else if (type === '[object String]') {
  3396. if (state.tag !== '?') {
  3397. writeScalar(state, state.dump, level, iskey);
  3398. }
  3399. } else {
  3400. if (state.skipInvalid) return false;
  3401. throw new exception('unacceptable kind of an object to dump ' + type);
  3402. }
  3403. if (state.tag !== null && state.tag !== '?') {
  3404. state.dump = '!<' + state.tag + '> ' + state.dump;
  3405. }
  3406. }
  3407. return true;
  3408. }
  3409. function getDuplicateReferences(object, state) {
  3410. var objects = [],
  3411. duplicatesIndexes = [],
  3412. index,
  3413. length;
  3414. inspectNode(object, objects, duplicatesIndexes);
  3415. for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
  3416. state.duplicates.push(objects[duplicatesIndexes[index]]);
  3417. }
  3418. state.usedDuplicates = new Array(length);
  3419. }
  3420. function inspectNode(object, objects, duplicatesIndexes) {
  3421. var objectKeyList, index, length;
  3422. if (object !== null && typeof object === 'object') {
  3423. index = objects.indexOf(object);
  3424. if (index !== -1) {
  3425. if (duplicatesIndexes.indexOf(index) === -1) {
  3426. duplicatesIndexes.push(index);
  3427. }
  3428. } else {
  3429. objects.push(object);
  3430. if (Array.isArray(object)) {
  3431. for (index = 0, length = object.length; index < length; index += 1) {
  3432. inspectNode(object[index], objects, duplicatesIndexes);
  3433. }
  3434. } else {
  3435. objectKeyList = Object.keys(object);
  3436. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  3437. inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
  3438. }
  3439. }
  3440. }
  3441. }
  3442. }
  3443. function dump$1(input, options) {
  3444. options = options || {};
  3445. var state = new State$1(options);
  3446. if (!state.noRefs) getDuplicateReferences(input, state);
  3447. if (writeNode(state, 0, input, true, true)) return state.dump + '\n';
  3448. return '';
  3449. }
  3450. function safeDump$1(input, options) {
  3451. return dump$1(input, common.extend({
  3452. schema: default_safe
  3453. }, options));
  3454. }
  3455. var dump_1 = dump$1;
  3456. var safeDump_1 = safeDump$1;
  3457. var dumper = {
  3458. dump: dump_1,
  3459. safeDump: safeDump_1
  3460. };
  3461. function deprecated(name) {
  3462. return function () {
  3463. throw new Error('Function ' + name + ' is deprecated and cannot be used.');
  3464. };
  3465. }
  3466. var Type = type;
  3467. var Schema = schema;
  3468. var FAILSAFE_SCHEMA = failsafe;
  3469. var JSON_SCHEMA = json;
  3470. var CORE_SCHEMA = core;
  3471. var DEFAULT_SAFE_SCHEMA = default_safe;
  3472. var DEFAULT_FULL_SCHEMA = default_full;
  3473. var load = loader.load;
  3474. var loadAll = loader.loadAll;
  3475. var safeLoad = loader.safeLoad;
  3476. var safeLoadAll = loader.safeLoadAll;
  3477. var dump = dumper.dump;
  3478. var safeDump = dumper.safeDump;
  3479. var YAMLException = exception; // Deprecated schema names from JS-YAML 2.0.x
  3480. var MINIMAL_SCHEMA = failsafe;
  3481. var SAFE_SCHEMA = default_safe;
  3482. var DEFAULT_SCHEMA = default_full; // Deprecated functions from JS-YAML 1.x.x
  3483. var scan = deprecated('scan');
  3484. var parse = deprecated('parse');
  3485. var compose = deprecated('compose');
  3486. var addConstructor = deprecated('addConstructor');
  3487. var jsYaml$2 = {
  3488. Type: Type,
  3489. Schema: Schema,
  3490. FAILSAFE_SCHEMA: FAILSAFE_SCHEMA,
  3491. JSON_SCHEMA: JSON_SCHEMA,
  3492. CORE_SCHEMA: CORE_SCHEMA,
  3493. DEFAULT_SAFE_SCHEMA: DEFAULT_SAFE_SCHEMA,
  3494. DEFAULT_FULL_SCHEMA: DEFAULT_FULL_SCHEMA,
  3495. load: load,
  3496. loadAll: loadAll,
  3497. safeLoad: safeLoad,
  3498. safeLoadAll: safeLoadAll,
  3499. dump: dump,
  3500. safeDump: safeDump,
  3501. YAMLException: YAMLException,
  3502. MINIMAL_SCHEMA: MINIMAL_SCHEMA,
  3503. SAFE_SCHEMA: SAFE_SCHEMA,
  3504. DEFAULT_SCHEMA: DEFAULT_SCHEMA,
  3505. scan: scan,
  3506. parse: parse,
  3507. compose: compose,
  3508. addConstructor: addConstructor
  3509. };
  3510. var jsYaml = jsYaml$2;
  3511. var resolveFrom_1 = createCommonjsModule(function (module) {
  3512. 'use strict';
  3513. var resolveFrom = function resolveFrom(fromDir, moduleId, silent) {
  3514. if (typeof fromDir !== 'string') {
  3515. throw new TypeError(`Expected \`fromDir\` to be of type \`string\`, got \`${typeof fromDir}\``);
  3516. }
  3517. if (typeof moduleId !== 'string') {
  3518. throw new TypeError(`Expected \`moduleId\` to be of type \`string\`, got \`${typeof moduleId}\``);
  3519. }
  3520. fromDir = path.resolve(fromDir);
  3521. var fromFile = path.join(fromDir, 'noop.js');
  3522. var resolveFileName = function resolveFileName() {
  3523. return module$1._resolveFilename(moduleId, {
  3524. id: fromFile,
  3525. filename: fromFile,
  3526. paths: module$1._nodeModulePaths(fromDir)
  3527. });
  3528. };
  3529. if (silent) {
  3530. try {
  3531. return resolveFileName();
  3532. } catch (err) {
  3533. return null;
  3534. }
  3535. }
  3536. return resolveFileName();
  3537. };
  3538. module.exports = function (fromDir, moduleId) {
  3539. return resolveFrom(fromDir, moduleId);
  3540. };
  3541. module.exports.silent = function (fromDir, moduleId) {
  3542. return resolveFrom(fromDir, moduleId, true);
  3543. };
  3544. });
  3545. var callsites = createCommonjsModule(function (module) {
  3546. 'use strict';
  3547. module.exports = function () {
  3548. var _ = Error.prepareStackTrace;
  3549. Error.prepareStackTrace = function (_, stack) {
  3550. return stack;
  3551. };
  3552. var stack = new Error().stack.slice(1);
  3553. Error.prepareStackTrace = _;
  3554. return stack;
  3555. };
  3556. });
  3557. var callerCallsite = createCommonjsModule(function (module) {
  3558. 'use strict';
  3559. module.exports = function () {
  3560. var c = callsites();
  3561. var caller;
  3562. for (var i = 0; i < c.length; i++) {
  3563. var hasReceiver = c[i].getTypeName() !== null;
  3564. if (hasReceiver) {
  3565. caller = i;
  3566. break;
  3567. }
  3568. }
  3569. return c[caller];
  3570. };
  3571. });
  3572. var callerPath = function callerPath() {
  3573. return callerCallsite().getFileName();
  3574. };
  3575. var importFresh = createCommonjsModule(function (module) {
  3576. 'use strict';
  3577. module.exports = function (moduleId) {
  3578. if (typeof moduleId !== 'string') {
  3579. throw new TypeError('Expected a string');
  3580. }
  3581. var filePath = resolveFrom_1(path.dirname(callerPath()), moduleId); // Delete itself from module parent
  3582. if (require.cache[filePath] && require.cache[filePath].parent) {
  3583. var i = require.cache[filePath].parent.children.length;
  3584. while (i--) {
  3585. if (require.cache[filePath].parent.children[i].id === filePath) {
  3586. require.cache[filePath].parent.children.splice(i, 1);
  3587. }
  3588. }
  3589. } // Delete module from cache
  3590. delete require.cache[filePath]; // Return fresh module
  3591. return require(filePath);
  3592. };
  3593. });
  3594. function loadJs(filepath) {
  3595. var result = importFresh(filepath);
  3596. return result;
  3597. }
  3598. function loadJson(filepath, content) {
  3599. try {
  3600. return parseJson(content);
  3601. } catch (err) {
  3602. err.message = `JSON Error in ${filepath}:\n${err.message}`;
  3603. throw err;
  3604. }
  3605. }
  3606. function loadYaml(filepath, content) {
  3607. return jsYaml.safeLoad(content, {
  3608. filename: filepath
  3609. });
  3610. }
  3611. var loaders = {
  3612. loadJs,
  3613. loadJson,
  3614. loadYaml
  3615. };
  3616. function readFile(filepath, options) {
  3617. options = options || {};
  3618. var throwNotFound = options.throwNotFound || false;
  3619. return new Promise(function (resolve, reject) {
  3620. fs.readFile(filepath, 'utf8', function (err, content) {
  3621. if (err && err.code === 'ENOENT' && !throwNotFound) {
  3622. return resolve(null);
  3623. }
  3624. if (err) return reject(err);
  3625. resolve(content);
  3626. });
  3627. });
  3628. }
  3629. readFile.sync = function readFileSync(filepath, options) {
  3630. options = options || {};
  3631. var throwNotFound = options.throwNotFound || false;
  3632. try {
  3633. return fs.readFileSync(filepath, 'utf8');
  3634. } catch (err) {
  3635. if (err.code === 'ENOENT' && !throwNotFound) {
  3636. return null;
  3637. }
  3638. throw err;
  3639. }
  3640. };
  3641. var readFile_1 = readFile;
  3642. //
  3643. function cacheWrapper(cache, key, fn) {
  3644. if (!cache) {
  3645. return fn();
  3646. }
  3647. var cached = cache.get(key);
  3648. if (cached !== undefined) {
  3649. return cached;
  3650. }
  3651. var result = fn();
  3652. cache.set(key, result);
  3653. return result;
  3654. }
  3655. var cacheWrapper_1 = cacheWrapper;
  3656. /**
  3657. * async
  3658. */
  3659. function isDirectory(filepath, cb) {
  3660. if (typeof cb !== 'function') {
  3661. throw new Error('expected a callback function');
  3662. }
  3663. if (typeof filepath !== 'string') {
  3664. cb(new Error('expected filepath to be a string'));
  3665. return;
  3666. }
  3667. fs.stat(filepath, function (err, stats) {
  3668. if (err) {
  3669. if (err.code === 'ENOENT') {
  3670. cb(null, false);
  3671. return;
  3672. }
  3673. cb(err);
  3674. return;
  3675. }
  3676. cb(null, stats.isDirectory());
  3677. });
  3678. }
  3679. /**
  3680. * sync
  3681. */
  3682. isDirectory.sync = function isDirectorySync(filepath) {
  3683. if (typeof filepath !== 'string') {
  3684. throw new Error('expected filepath to be a string');
  3685. }
  3686. try {
  3687. var stat = fs.statSync(filepath);
  3688. return stat.isDirectory();
  3689. } catch (err) {
  3690. if (err.code === 'ENOENT') {
  3691. return false;
  3692. } else {
  3693. throw err;
  3694. }
  3695. }
  3696. return false;
  3697. };
  3698. /**
  3699. * Expose `isDirectory`
  3700. */
  3701. var isDirectory_1 = isDirectory;
  3702. function getDirectory(filepath) {
  3703. return new Promise(function (resolve, reject) {
  3704. return isDirectory_1(filepath, function (err, filepathIsDirectory) {
  3705. if (err) {
  3706. return reject(err);
  3707. }
  3708. return resolve(filepathIsDirectory ? filepath : path.dirname(filepath));
  3709. });
  3710. });
  3711. }
  3712. getDirectory.sync = function getDirectorySync(filepath) {
  3713. return isDirectory_1.sync(filepath) ? filepath : path.dirname(filepath);
  3714. };
  3715. var getDirectory_1 = getDirectory;
  3716. var MODE_SYNC = 'sync'; // An object value represents a config object.
  3717. // null represents that the loader did not find anything relevant.
  3718. // undefined represents that the loader found something relevant
  3719. // but it was empty.
  3720. var Explorer =
  3721. /*#__PURE__*/
  3722. function () {
  3723. function Explorer(options) {
  3724. _classCallCheck(this, Explorer);
  3725. this.loadCache = options.cache ? new Map() : null;
  3726. this.loadSyncCache = options.cache ? new Map() : null;
  3727. this.searchCache = options.cache ? new Map() : null;
  3728. this.searchSyncCache = options.cache ? new Map() : null;
  3729. this.config = options;
  3730. this.validateConfig();
  3731. }
  3732. _createClass(Explorer, [{
  3733. key: "clearLoadCache",
  3734. value: function clearLoadCache() {
  3735. if (this.loadCache) {
  3736. this.loadCache.clear();
  3737. }
  3738. if (this.loadSyncCache) {
  3739. this.loadSyncCache.clear();
  3740. }
  3741. }
  3742. }, {
  3743. key: "clearSearchCache",
  3744. value: function clearSearchCache() {
  3745. if (this.searchCache) {
  3746. this.searchCache.clear();
  3747. }
  3748. if (this.searchSyncCache) {
  3749. this.searchSyncCache.clear();
  3750. }
  3751. }
  3752. }, {
  3753. key: "clearCaches",
  3754. value: function clearCaches() {
  3755. this.clearLoadCache();
  3756. this.clearSearchCache();
  3757. }
  3758. }, {
  3759. key: "validateConfig",
  3760. value: function validateConfig() {
  3761. var config = this.config;
  3762. config.searchPlaces.forEach(function (place) {
  3763. var loaderKey = path.extname(place) || 'noExt';
  3764. var loader = config.loaders[loaderKey];
  3765. if (!loader) {
  3766. throw new Error(`No loader specified for ${getExtensionDescription(place)}, so searchPlaces item "${place}" is invalid`);
  3767. }
  3768. });
  3769. }
  3770. }, {
  3771. key: "search",
  3772. value: function search(searchFrom) {
  3773. var _this = this;
  3774. searchFrom = searchFrom || process.cwd();
  3775. return getDirectory_1(searchFrom).then(function (dir) {
  3776. return _this.searchFromDirectory(dir);
  3777. });
  3778. }
  3779. }, {
  3780. key: "searchFromDirectory",
  3781. value: function searchFromDirectory(dir) {
  3782. var _this2 = this;
  3783. var absoluteDir = path.resolve(process.cwd(), dir);
  3784. var run = function run() {
  3785. return _this2.searchDirectory(absoluteDir).then(function (result) {
  3786. var nextDir = _this2.nextDirectoryToSearch(absoluteDir, result);
  3787. if (nextDir) {
  3788. return _this2.searchFromDirectory(nextDir);
  3789. }
  3790. return _this2.config.transform(result);
  3791. });
  3792. };
  3793. if (this.searchCache) {
  3794. return cacheWrapper_1(this.searchCache, absoluteDir, run);
  3795. }
  3796. return run();
  3797. }
  3798. }, {
  3799. key: "searchSync",
  3800. value: function searchSync(searchFrom) {
  3801. searchFrom = searchFrom || process.cwd();
  3802. var dir = getDirectory_1.sync(searchFrom);
  3803. return this.searchFromDirectorySync(dir);
  3804. }
  3805. }, {
  3806. key: "searchFromDirectorySync",
  3807. value: function searchFromDirectorySync(dir) {
  3808. var _this3 = this;
  3809. var absoluteDir = path.resolve(process.cwd(), dir);
  3810. var run = function run() {
  3811. var result = _this3.searchDirectorySync(absoluteDir);
  3812. var nextDir = _this3.nextDirectoryToSearch(absoluteDir, result);
  3813. if (nextDir) {
  3814. return _this3.searchFromDirectorySync(nextDir);
  3815. }
  3816. return _this3.config.transform(result);
  3817. };
  3818. if (this.searchSyncCache) {
  3819. return cacheWrapper_1(this.searchSyncCache, absoluteDir, run);
  3820. }
  3821. return run();
  3822. }
  3823. }, {
  3824. key: "searchDirectory",
  3825. value: function searchDirectory(dir) {
  3826. var _this4 = this;
  3827. return this.config.searchPlaces.reduce(function (prevResultPromise, place) {
  3828. return prevResultPromise.then(function (prevResult) {
  3829. if (_this4.shouldSearchStopWithResult(prevResult)) {
  3830. return prevResult;
  3831. }
  3832. return _this4.loadSearchPlace(dir, place);
  3833. });
  3834. }, Promise.resolve(null));
  3835. }
  3836. }, {
  3837. key: "searchDirectorySync",
  3838. value: function searchDirectorySync(dir) {
  3839. var result = null;
  3840. var _iteratorNormalCompletion = true;
  3841. var _didIteratorError = false;
  3842. var _iteratorError = undefined;
  3843. try {
  3844. for (var _iterator = this.config.searchPlaces[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  3845. var place = _step.value;
  3846. result = this.loadSearchPlaceSync(dir, place);
  3847. if (this.shouldSearchStopWithResult(result)) break;
  3848. }
  3849. } catch (err) {
  3850. _didIteratorError = true;
  3851. _iteratorError = err;
  3852. } finally {
  3853. try {
  3854. if (!_iteratorNormalCompletion && _iterator.return != null) {
  3855. _iterator.return();
  3856. }
  3857. } finally {
  3858. if (_didIteratorError) {
  3859. throw _iteratorError;
  3860. }
  3861. }
  3862. }
  3863. return result;
  3864. }
  3865. }, {
  3866. key: "shouldSearchStopWithResult",
  3867. value: function shouldSearchStopWithResult(result) {
  3868. if (result === null) return false;
  3869. if (result.isEmpty && this.config.ignoreEmptySearchPlaces) return false;
  3870. return true;
  3871. }
  3872. }, {
  3873. key: "loadSearchPlace",
  3874. value: function loadSearchPlace(dir, place) {
  3875. var _this5 = this;
  3876. var filepath = path.join(dir, place);
  3877. return readFile_1(filepath).then(function (content) {
  3878. return _this5.createCosmiconfigResult(filepath, content);
  3879. });
  3880. }
  3881. }, {
  3882. key: "loadSearchPlaceSync",
  3883. value: function loadSearchPlaceSync(dir, place) {
  3884. var filepath = path.join(dir, place);
  3885. var content = readFile_1.sync(filepath);
  3886. return this.createCosmiconfigResultSync(filepath, content);
  3887. }
  3888. }, {
  3889. key: "nextDirectoryToSearch",
  3890. value: function nextDirectoryToSearch(currentDir, currentResult) {
  3891. if (this.shouldSearchStopWithResult(currentResult)) {
  3892. return null;
  3893. }
  3894. var nextDir = nextDirUp(currentDir);
  3895. if (nextDir === currentDir || currentDir === this.config.stopDir) {
  3896. return null;
  3897. }
  3898. return nextDir;
  3899. }
  3900. }, {
  3901. key: "loadPackageProp",
  3902. value: function loadPackageProp(filepath, content) {
  3903. var parsedContent = loaders.loadJson(filepath, content);
  3904. var packagePropValue = parsedContent[this.config.packageProp];
  3905. return packagePropValue || null;
  3906. }
  3907. }, {
  3908. key: "getLoaderEntryForFile",
  3909. value: function getLoaderEntryForFile(filepath) {
  3910. if (path.basename(filepath) === 'package.json') {
  3911. var loader = this.loadPackageProp.bind(this);
  3912. return {
  3913. sync: loader,
  3914. async: loader
  3915. };
  3916. }
  3917. var loaderKey = path.extname(filepath) || 'noExt';
  3918. return this.config.loaders[loaderKey] || {};
  3919. }
  3920. }, {
  3921. key: "getSyncLoaderForFile",
  3922. value: function getSyncLoaderForFile(filepath) {
  3923. var entry = this.getLoaderEntryForFile(filepath);
  3924. if (!entry.sync) {
  3925. throw new Error(`No sync loader specified for ${getExtensionDescription(filepath)}`);
  3926. }
  3927. return entry.sync;
  3928. }
  3929. }, {
  3930. key: "getAsyncLoaderForFile",
  3931. value: function getAsyncLoaderForFile(filepath) {
  3932. var entry = this.getLoaderEntryForFile(filepath);
  3933. var loader = entry.async || entry.sync;
  3934. if (!loader) {
  3935. throw new Error(`No async loader specified for ${getExtensionDescription(filepath)}`);
  3936. }
  3937. return loader;
  3938. }
  3939. }, {
  3940. key: "loadFileContent",
  3941. value: function loadFileContent(mode, filepath, content) {
  3942. if (content === null) {
  3943. return null;
  3944. }
  3945. if (content.trim() === '') {
  3946. return undefined;
  3947. }
  3948. var loader = mode === MODE_SYNC ? this.getSyncLoaderForFile(filepath) : this.getAsyncLoaderForFile(filepath);
  3949. return loader(filepath, content);
  3950. }
  3951. }, {
  3952. key: "loadedContentToCosmiconfigResult",
  3953. value: function loadedContentToCosmiconfigResult(filepath, loadedContent) {
  3954. if (loadedContent === null) {
  3955. return null;
  3956. }
  3957. if (loadedContent === undefined) {
  3958. return {
  3959. filepath,
  3960. config: undefined,
  3961. isEmpty: true
  3962. };
  3963. }
  3964. return {
  3965. config: loadedContent,
  3966. filepath
  3967. };
  3968. }
  3969. }, {
  3970. key: "createCosmiconfigResult",
  3971. value: function createCosmiconfigResult(filepath, content) {
  3972. var _this6 = this;
  3973. return Promise.resolve().then(function () {
  3974. return _this6.loadFileContent('async', filepath, content);
  3975. }).then(function (loaderResult) {
  3976. return _this6.loadedContentToCosmiconfigResult(filepath, loaderResult);
  3977. });
  3978. }
  3979. }, {
  3980. key: "createCosmiconfigResultSync",
  3981. value: function createCosmiconfigResultSync(filepath, content) {
  3982. var loaderResult = this.loadFileContent('sync', filepath, content);
  3983. return this.loadedContentToCosmiconfigResult(filepath, loaderResult);
  3984. }
  3985. }, {
  3986. key: "validateFilePath",
  3987. value: function validateFilePath(filepath) {
  3988. if (!filepath) {
  3989. throw new Error('load and loadSync must pass a non-empty string');
  3990. }
  3991. }
  3992. }, {
  3993. key: "load",
  3994. value: function load(filepath) {
  3995. var _this7 = this;
  3996. return Promise.resolve().then(function () {
  3997. _this7.validateFilePath(filepath);
  3998. var absoluteFilePath = path.resolve(process.cwd(), filepath);
  3999. return cacheWrapper_1(_this7.loadCache, absoluteFilePath, function () {
  4000. return readFile_1(absoluteFilePath, {
  4001. throwNotFound: true
  4002. }).then(function (content) {
  4003. return _this7.createCosmiconfigResult(absoluteFilePath, content);
  4004. }).then(_this7.config.transform);
  4005. });
  4006. });
  4007. }
  4008. }, {
  4009. key: "loadSync",
  4010. value: function loadSync(filepath) {
  4011. var _this8 = this;
  4012. this.validateFilePath(filepath);
  4013. var absoluteFilePath = path.resolve(process.cwd(), filepath);
  4014. return cacheWrapper_1(this.loadSyncCache, absoluteFilePath, function () {
  4015. var content = readFile_1.sync(absoluteFilePath, {
  4016. throwNotFound: true
  4017. });
  4018. var result = _this8.createCosmiconfigResultSync(absoluteFilePath, content);
  4019. return _this8.config.transform(result);
  4020. });
  4021. }
  4022. }]);
  4023. return Explorer;
  4024. }();
  4025. var createExplorer = function createExplorer(options) {
  4026. var explorer = new Explorer(options);
  4027. return {
  4028. search: explorer.search.bind(explorer),
  4029. searchSync: explorer.searchSync.bind(explorer),
  4030. load: explorer.load.bind(explorer),
  4031. loadSync: explorer.loadSync.bind(explorer),
  4032. clearLoadCache: explorer.clearLoadCache.bind(explorer),
  4033. clearSearchCache: explorer.clearSearchCache.bind(explorer),
  4034. clearCaches: explorer.clearCaches.bind(explorer)
  4035. };
  4036. };
  4037. function nextDirUp(dir) {
  4038. return path.dirname(dir);
  4039. }
  4040. function getExtensionDescription(filepath) {
  4041. var ext = path.extname(filepath);
  4042. return ext ? `extension "${ext}"` : 'files without extensions';
  4043. }
  4044. var dist = cosmiconfig;
  4045. function cosmiconfig(moduleName, options) {
  4046. options = options || {};
  4047. var defaults = {
  4048. packageProp: moduleName,
  4049. searchPlaces: ['package.json', `.${moduleName}rc`, `.${moduleName}rc.json`, `.${moduleName}rc.yaml`, `.${moduleName}rc.yml`, `.${moduleName}rc.js`, `${moduleName}.config.js`],
  4050. ignoreEmptySearchPlaces: true,
  4051. stopDir: os.homedir(),
  4052. cache: true,
  4053. transform: identity
  4054. };
  4055. var normalizedOptions = Object.assign({}, defaults, options, {
  4056. loaders: normalizeLoaders(options.loaders)
  4057. });
  4058. return createExplorer(normalizedOptions);
  4059. }
  4060. cosmiconfig.loadJs = loaders.loadJs;
  4061. cosmiconfig.loadJson = loaders.loadJson;
  4062. cosmiconfig.loadYaml = loaders.loadYaml;
  4063. function normalizeLoaders(rawLoaders) {
  4064. var defaults = {
  4065. '.js': {
  4066. sync: loaders.loadJs,
  4067. async: loaders.loadJs
  4068. },
  4069. '.json': {
  4070. sync: loaders.loadJson,
  4071. async: loaders.loadJson
  4072. },
  4073. '.yaml': {
  4074. sync: loaders.loadYaml,
  4075. async: loaders.loadYaml
  4076. },
  4077. '.yml': {
  4078. sync: loaders.loadYaml,
  4079. async: loaders.loadYaml
  4080. },
  4081. noExt: {
  4082. sync: loaders.loadYaml,
  4083. async: loaders.loadYaml
  4084. }
  4085. };
  4086. if (!rawLoaders) {
  4087. return defaults;
  4088. }
  4089. return Object.keys(rawLoaders).reduce(function (result, ext) {
  4090. var entry = rawLoaders && rawLoaders[ext];
  4091. if (typeof entry === 'function') {
  4092. result[ext] = {
  4093. sync: entry,
  4094. async: entry
  4095. };
  4096. } else {
  4097. result[ext] = entry;
  4098. }
  4099. return result;
  4100. }, defaults);
  4101. }
  4102. function identity(x) {
  4103. return x;
  4104. }
  4105. var findParentDir$1 = createCommonjsModule(function (module, exports) {
  4106. 'use strict';
  4107. var exists = fs.exists || path.exists,
  4108. existsSync = fs.existsSync || path.existsSync;
  4109. function splitPath(path$$2) {
  4110. var parts = path$$2.split(/(\/|\\)/);
  4111. if (!parts.length) return parts; // when path starts with a slash, the first part is empty string
  4112. return !parts[0].length ? parts.slice(1) : parts;
  4113. }
  4114. exports = module.exports = function (currentFullPath, clue, cb) {
  4115. function testDir(parts) {
  4116. if (parts.length === 0) return cb(null, null);
  4117. var p = parts.join('');
  4118. exists(path.join(p, clue), function (itdoes) {
  4119. if (itdoes) return cb(null, p);
  4120. testDir(parts.slice(0, -1));
  4121. });
  4122. }
  4123. testDir(splitPath(currentFullPath));
  4124. };
  4125. exports.sync = function (currentFullPath, clue) {
  4126. function testDir(parts) {
  4127. if (parts.length === 0) return null;
  4128. var p = parts.join('');
  4129. var itdoes = existsSync(path.join(p, clue));
  4130. return itdoes ? p : testDir(parts.slice(0, -1));
  4131. }
  4132. return testDir(splitPath(currentFullPath));
  4133. };
  4134. });
  4135. var findParentDir = findParentDir$1.sync;
  4136. var thirdParty = {
  4137. getStream: getStream_1,
  4138. cosmiconfig: dist,
  4139. findParentDir
  4140. };
  4141. module.exports = thirdParty;