js-yaml.js 103 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855
  1. /* js-yaml 3.7.0 https://github.com/nodeca/js-yaml */(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.jsyaml = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
  2. 'use strict';
  3. var loader = require('./js-yaml/loader');
  4. var dumper = require('./js-yaml/dumper');
  5. function deprecated(name) {
  6. return function () {
  7. throw new Error('Function ' + name + ' is deprecated and cannot be used.');
  8. };
  9. }
  10. module.exports.Type = require('./js-yaml/type');
  11. module.exports.Schema = require('./js-yaml/schema');
  12. module.exports.FAILSAFE_SCHEMA = require('./js-yaml/schema/failsafe');
  13. module.exports.JSON_SCHEMA = require('./js-yaml/schema/json');
  14. module.exports.CORE_SCHEMA = require('./js-yaml/schema/core');
  15. module.exports.DEFAULT_SAFE_SCHEMA = require('./js-yaml/schema/default_safe');
  16. module.exports.DEFAULT_FULL_SCHEMA = require('./js-yaml/schema/default_full');
  17. module.exports.load = loader.load;
  18. module.exports.loadAll = loader.loadAll;
  19. module.exports.safeLoad = loader.safeLoad;
  20. module.exports.safeLoadAll = loader.safeLoadAll;
  21. module.exports.dump = dumper.dump;
  22. module.exports.safeDump = dumper.safeDump;
  23. module.exports.YAMLException = require('./js-yaml/exception');
  24. // Deprecated schema names from JS-YAML 2.0.x
  25. module.exports.MINIMAL_SCHEMA = require('./js-yaml/schema/failsafe');
  26. module.exports.SAFE_SCHEMA = require('./js-yaml/schema/default_safe');
  27. module.exports.DEFAULT_SCHEMA = require('./js-yaml/schema/default_full');
  28. // Deprecated functions from JS-YAML 1.x.x
  29. module.exports.scan = deprecated('scan');
  30. module.exports.parse = deprecated('parse');
  31. module.exports.compose = deprecated('compose');
  32. module.exports.addConstructor = deprecated('addConstructor');
  33. },{"./js-yaml/dumper":3,"./js-yaml/exception":4,"./js-yaml/loader":5,"./js-yaml/schema":7,"./js-yaml/schema/core":8,"./js-yaml/schema/default_full":9,"./js-yaml/schema/default_safe":10,"./js-yaml/schema/failsafe":11,"./js-yaml/schema/json":12,"./js-yaml/type":13}],2:[function(require,module,exports){
  34. 'use strict';
  35. function isNothing(subject) {
  36. return (typeof subject === 'undefined') || (subject === null);
  37. }
  38. function isObject(subject) {
  39. return (typeof subject === 'object') && (subject !== null);
  40. }
  41. function toArray(sequence) {
  42. if (Array.isArray(sequence)) return sequence;
  43. else if (isNothing(sequence)) return [];
  44. return [ sequence ];
  45. }
  46. function extend(target, source) {
  47. var index, length, key, sourceKeys;
  48. if (source) {
  49. sourceKeys = Object.keys(source);
  50. for (index = 0, length = sourceKeys.length; index < length; index += 1) {
  51. key = sourceKeys[index];
  52. target[key] = source[key];
  53. }
  54. }
  55. return target;
  56. }
  57. function repeat(string, count) {
  58. var result = '', cycle;
  59. for (cycle = 0; cycle < count; cycle += 1) {
  60. result += string;
  61. }
  62. return result;
  63. }
  64. function isNegativeZero(number) {
  65. return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
  66. }
  67. module.exports.isNothing = isNothing;
  68. module.exports.isObject = isObject;
  69. module.exports.toArray = toArray;
  70. module.exports.repeat = repeat;
  71. module.exports.isNegativeZero = isNegativeZero;
  72. module.exports.extend = extend;
  73. },{}],3:[function(require,module,exports){
  74. 'use strict';
  75. /*eslint-disable no-use-before-define*/
  76. var common = require('./common');
  77. var YAMLException = require('./exception');
  78. var DEFAULT_FULL_SCHEMA = require('./schema/default_full');
  79. var DEFAULT_SAFE_SCHEMA = require('./schema/default_safe');
  80. var _toString = Object.prototype.toString;
  81. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  82. var CHAR_TAB = 0x09; /* Tab */
  83. var CHAR_LINE_FEED = 0x0A; /* LF */
  84. var CHAR_SPACE = 0x20; /* Space */
  85. var CHAR_EXCLAMATION = 0x21; /* ! */
  86. var CHAR_DOUBLE_QUOTE = 0x22; /* " */
  87. var CHAR_SHARP = 0x23; /* # */
  88. var CHAR_PERCENT = 0x25; /* % */
  89. var CHAR_AMPERSAND = 0x26; /* & */
  90. var CHAR_SINGLE_QUOTE = 0x27; /* ' */
  91. var CHAR_ASTERISK = 0x2A; /* * */
  92. var CHAR_COMMA = 0x2C; /* , */
  93. var CHAR_MINUS = 0x2D; /* - */
  94. var CHAR_COLON = 0x3A; /* : */
  95. var CHAR_GREATER_THAN = 0x3E; /* > */
  96. var CHAR_QUESTION = 0x3F; /* ? */
  97. var CHAR_COMMERCIAL_AT = 0x40; /* @ */
  98. var CHAR_LEFT_SQUARE_BRACKET = 0x5B; /* [ */
  99. var CHAR_RIGHT_SQUARE_BRACKET = 0x5D; /* ] */
  100. var CHAR_GRAVE_ACCENT = 0x60; /* ` */
  101. var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */
  102. var CHAR_VERTICAL_LINE = 0x7C; /* | */
  103. var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */
  104. var ESCAPE_SEQUENCES = {};
  105. ESCAPE_SEQUENCES[0x00] = '\\0';
  106. ESCAPE_SEQUENCES[0x07] = '\\a';
  107. ESCAPE_SEQUENCES[0x08] = '\\b';
  108. ESCAPE_SEQUENCES[0x09] = '\\t';
  109. ESCAPE_SEQUENCES[0x0A] = '\\n';
  110. ESCAPE_SEQUENCES[0x0B] = '\\v';
  111. ESCAPE_SEQUENCES[0x0C] = '\\f';
  112. ESCAPE_SEQUENCES[0x0D] = '\\r';
  113. ESCAPE_SEQUENCES[0x1B] = '\\e';
  114. ESCAPE_SEQUENCES[0x22] = '\\"';
  115. ESCAPE_SEQUENCES[0x5C] = '\\\\';
  116. ESCAPE_SEQUENCES[0x85] = '\\N';
  117. ESCAPE_SEQUENCES[0xA0] = '\\_';
  118. ESCAPE_SEQUENCES[0x2028] = '\\L';
  119. ESCAPE_SEQUENCES[0x2029] = '\\P';
  120. var DEPRECATED_BOOLEANS_SYNTAX = [
  121. 'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON',
  122. 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'
  123. ];
  124. function compileStyleMap(schema, map) {
  125. var result, keys, index, length, tag, style, type;
  126. if (map === null) return {};
  127. result = {};
  128. keys = Object.keys(map);
  129. for (index = 0, length = keys.length; index < length; index += 1) {
  130. tag = keys[index];
  131. style = String(map[tag]);
  132. if (tag.slice(0, 2) === '!!') {
  133. tag = 'tag:yaml.org,2002:' + tag.slice(2);
  134. }
  135. type = schema.compiledTypeMap['fallback'][tag];
  136. if (type && _hasOwnProperty.call(type.styleAliases, style)) {
  137. style = type.styleAliases[style];
  138. }
  139. result[tag] = style;
  140. }
  141. return result;
  142. }
  143. function encodeHex(character) {
  144. var string, handle, length;
  145. string = character.toString(16).toUpperCase();
  146. if (character <= 0xFF) {
  147. handle = 'x';
  148. length = 2;
  149. } else if (character <= 0xFFFF) {
  150. handle = 'u';
  151. length = 4;
  152. } else if (character <= 0xFFFFFFFF) {
  153. handle = 'U';
  154. length = 8;
  155. } else {
  156. throw new YAMLException('code point within a string may not be greater than 0xFFFFFFFF');
  157. }
  158. return '\\' + handle + common.repeat('0', length - string.length) + string;
  159. }
  160. function State(options) {
  161. this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
  162. this.indent = Math.max(1, (options['indent'] || 2));
  163. this.skipInvalid = options['skipInvalid'] || false;
  164. this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
  165. this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
  166. this.sortKeys = options['sortKeys'] || false;
  167. this.lineWidth = options['lineWidth'] || 80;
  168. this.noRefs = options['noRefs'] || false;
  169. this.noCompatMode = options['noCompatMode'] || false;
  170. this.implicitTypes = this.schema.compiledImplicit;
  171. this.explicitTypes = this.schema.compiledExplicit;
  172. this.tag = null;
  173. this.result = '';
  174. this.duplicates = [];
  175. this.usedDuplicates = null;
  176. }
  177. // Indents every line in a string. Empty lines (\n only) are not indented.
  178. function indentString(string, spaces) {
  179. var ind = common.repeat(' ', spaces),
  180. position = 0,
  181. next = -1,
  182. result = '',
  183. line,
  184. length = string.length;
  185. while (position < length) {
  186. next = string.indexOf('\n', position);
  187. if (next === -1) {
  188. line = string.slice(position);
  189. position = length;
  190. } else {
  191. line = string.slice(position, next + 1);
  192. position = next + 1;
  193. }
  194. if (line.length && line !== '\n') result += ind;
  195. result += line;
  196. }
  197. return result;
  198. }
  199. function generateNextLine(state, level) {
  200. return '\n' + common.repeat(' ', state.indent * level);
  201. }
  202. function testImplicitResolving(state, str) {
  203. var index, length, type;
  204. for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
  205. type = state.implicitTypes[index];
  206. if (type.resolve(str)) {
  207. return true;
  208. }
  209. }
  210. return false;
  211. }
  212. // [33] s-white ::= s-space | s-tab
  213. function isWhitespace(c) {
  214. return c === CHAR_SPACE || c === CHAR_TAB;
  215. }
  216. // Returns true if the character can be printed without escaping.
  217. // From YAML 1.2: "any allowed characters known to be non-printable
  218. // should also be escaped. [However,] This isn’t mandatory"
  219. // Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029.
  220. function isPrintable(c) {
  221. return (0x00020 <= c && c <= 0x00007E)
  222. || ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029)
  223. || ((0x0E000 <= c && c <= 0x00FFFD) && c !== 0xFEFF /* BOM */)
  224. || (0x10000 <= c && c <= 0x10FFFF);
  225. }
  226. // Simplified test for values allowed after the first character in plain style.
  227. function isPlainSafe(c) {
  228. // Uses a subset of nb-char - c-flow-indicator - ":" - "#"
  229. // where nb-char ::= c-printable - b-char - c-byte-order-mark.
  230. return isPrintable(c) && c !== 0xFEFF
  231. // - c-flow-indicator
  232. && c !== CHAR_COMMA
  233. && c !== CHAR_LEFT_SQUARE_BRACKET
  234. && c !== CHAR_RIGHT_SQUARE_BRACKET
  235. && c !== CHAR_LEFT_CURLY_BRACKET
  236. && c !== CHAR_RIGHT_CURLY_BRACKET
  237. // - ":" - "#"
  238. && c !== CHAR_COLON
  239. && c !== CHAR_SHARP;
  240. }
  241. // Simplified test for values allowed as the first character in plain style.
  242. function isPlainSafeFirst(c) {
  243. // Uses a subset of ns-char - c-indicator
  244. // where ns-char = nb-char - s-white.
  245. return isPrintable(c) && c !== 0xFEFF
  246. && !isWhitespace(c) // - s-white
  247. // - (c-indicator ::=
  248. // “-” | “?” | “:” | “,” | “[” | “]” | “{” | “}”
  249. && c !== CHAR_MINUS
  250. && c !== CHAR_QUESTION
  251. && c !== CHAR_COLON
  252. && c !== CHAR_COMMA
  253. && c !== CHAR_LEFT_SQUARE_BRACKET
  254. && c !== CHAR_RIGHT_SQUARE_BRACKET
  255. && c !== CHAR_LEFT_CURLY_BRACKET
  256. && c !== CHAR_RIGHT_CURLY_BRACKET
  257. // | “#” | “&” | “*” | “!” | “|” | “>” | “'” | “"”
  258. && c !== CHAR_SHARP
  259. && c !== CHAR_AMPERSAND
  260. && c !== CHAR_ASTERISK
  261. && c !== CHAR_EXCLAMATION
  262. && c !== CHAR_VERTICAL_LINE
  263. && c !== CHAR_GREATER_THAN
  264. && c !== CHAR_SINGLE_QUOTE
  265. && c !== CHAR_DOUBLE_QUOTE
  266. // | “%” | “@” | “`”)
  267. && c !== CHAR_PERCENT
  268. && c !== CHAR_COMMERCIAL_AT
  269. && c !== CHAR_GRAVE_ACCENT;
  270. }
  271. var STYLE_PLAIN = 1,
  272. STYLE_SINGLE = 2,
  273. STYLE_LITERAL = 3,
  274. STYLE_FOLDED = 4,
  275. STYLE_DOUBLE = 5;
  276. // Determines which scalar styles are possible and returns the preferred style.
  277. // lineWidth = -1 => no limit.
  278. // Pre-conditions: str.length > 0.
  279. // Post-conditions:
  280. // STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
  281. // STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
  282. // STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1).
  283. function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
  284. var i;
  285. var char;
  286. var hasLineBreak = false;
  287. var hasFoldableLine = false; // only checked if shouldTrackWidth
  288. var shouldTrackWidth = lineWidth !== -1;
  289. var previousLineBreak = -1; // count the first line correctly
  290. var plain = isPlainSafeFirst(string.charCodeAt(0))
  291. && !isWhitespace(string.charCodeAt(string.length - 1));
  292. if (singleLineOnly) {
  293. // Case: no block styles.
  294. // Check for disallowed characters to rule out plain and single.
  295. for (i = 0; i < string.length; i++) {
  296. char = string.charCodeAt(i);
  297. if (!isPrintable(char)) {
  298. return STYLE_DOUBLE;
  299. }
  300. plain = plain && isPlainSafe(char);
  301. }
  302. } else {
  303. // Case: block styles permitted.
  304. for (i = 0; i < string.length; i++) {
  305. char = string.charCodeAt(i);
  306. if (char === CHAR_LINE_FEED) {
  307. hasLineBreak = true;
  308. // Check if any line can be folded.
  309. if (shouldTrackWidth) {
  310. hasFoldableLine = hasFoldableLine ||
  311. // Foldable line = too long, and not more-indented.
  312. (i - previousLineBreak - 1 > lineWidth &&
  313. string[previousLineBreak + 1] !== ' ');
  314. previousLineBreak = i;
  315. }
  316. } else if (!isPrintable(char)) {
  317. return STYLE_DOUBLE;
  318. }
  319. plain = plain && isPlainSafe(char);
  320. }
  321. // in case the end is missing a \n
  322. hasFoldableLine = hasFoldableLine || (shouldTrackWidth &&
  323. (i - previousLineBreak - 1 > lineWidth &&
  324. string[previousLineBreak + 1] !== ' '));
  325. }
  326. // Although every style can represent \n without escaping, prefer block styles
  327. // for multiline, since they're more readable and they don't add empty lines.
  328. // Also prefer folding a super-long line.
  329. if (!hasLineBreak && !hasFoldableLine) {
  330. // Strings interpretable as another type have to be quoted;
  331. // e.g. the string 'true' vs. the boolean true.
  332. return plain && !testAmbiguousType(string)
  333. ? STYLE_PLAIN : STYLE_SINGLE;
  334. }
  335. // Edge case: block indentation indicator can only have one digit.
  336. if (string[0] === ' ' && indentPerLevel > 9) {
  337. return STYLE_DOUBLE;
  338. }
  339. // At this point we know block styles are valid.
  340. // Prefer literal style unless we want to fold.
  341. return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
  342. }
  343. // Note: line breaking/folding is implemented for only the folded style.
  344. // NB. We drop the last trailing newline (if any) of a returned block scalar
  345. // since the dumper adds its own newline. This always works:
  346. // • No ending newline => unaffected; already using strip "-" chomping.
  347. // • Ending newline => removed then restored.
  348. // Importantly, this keeps the "+" chomp indicator from gaining an extra line.
  349. function writeScalar(state, string, level, iskey) {
  350. state.dump = (function () {
  351. if (string.length === 0) {
  352. return "''";
  353. }
  354. if (!state.noCompatMode &&
  355. DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
  356. return "'" + string + "'";
  357. }
  358. var indent = state.indent * Math.max(1, level); // no 0-indent scalars
  359. // As indentation gets deeper, let the width decrease monotonically
  360. // to the lower bound min(state.lineWidth, 40).
  361. // Note that this implies
  362. // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
  363. // state.lineWidth > 40 + state.indent: width decreases until the lower bound.
  364. // This behaves better than a constant minimum width which disallows narrower options,
  365. // or an indent threshold which causes the width to suddenly increase.
  366. var lineWidth = state.lineWidth === -1
  367. ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
  368. // Without knowing if keys are implicit/explicit, assume implicit for safety.
  369. var singleLineOnly = iskey
  370. // No block styles in flow mode.
  371. || (state.flowLevel > -1 && level >= state.flowLevel);
  372. function testAmbiguity(string) {
  373. return testImplicitResolving(state, string);
  374. }
  375. switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
  376. case STYLE_PLAIN:
  377. return string;
  378. case STYLE_SINGLE:
  379. return "'" + string.replace(/'/g, "''") + "'";
  380. case STYLE_LITERAL:
  381. return '|' + blockHeader(string, state.indent)
  382. + dropEndingNewline(indentString(string, indent));
  383. case STYLE_FOLDED:
  384. return '>' + blockHeader(string, state.indent)
  385. + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
  386. case STYLE_DOUBLE:
  387. return '"' + escapeString(string, lineWidth) + '"';
  388. default:
  389. throw new YAMLException('impossible error: invalid scalar style');
  390. }
  391. }());
  392. }
  393. // Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
  394. function blockHeader(string, indentPerLevel) {
  395. var indentIndicator = (string[0] === ' ') ? String(indentPerLevel) : '';
  396. // note the special case: the string '\n' counts as a "trailing" empty line.
  397. var clip = string[string.length - 1] === '\n';
  398. var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
  399. var chomp = keep ? '+' : (clip ? '' : '-');
  400. return indentIndicator + chomp + '\n';
  401. }
  402. // (See the note for writeScalar.)
  403. function dropEndingNewline(string) {
  404. return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
  405. }
  406. // Note: a long line without a suitable break point will exceed the width limit.
  407. // Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
  408. function foldString(string, width) {
  409. // In folded style, $k$ consecutive newlines output as $k+1$ newlines—
  410. // unless they're before or after a more-indented line, or at the very
  411. // beginning or end, in which case $k$ maps to $k$.
  412. // Therefore, parse each chunk as newline(s) followed by a content line.
  413. var lineRe = /(\n+)([^\n]*)/g;
  414. // first line (possibly an empty line)
  415. var result = (function () {
  416. var nextLF = string.indexOf('\n');
  417. nextLF = nextLF !== -1 ? nextLF : string.length;
  418. lineRe.lastIndex = nextLF;
  419. return foldLine(string.slice(0, nextLF), width);
  420. }());
  421. // If we haven't reached the first content line yet, don't add an extra \n.
  422. var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
  423. var moreIndented;
  424. // rest of the lines
  425. var match;
  426. while ((match = lineRe.exec(string))) {
  427. var prefix = match[1], line = match[2];
  428. moreIndented = (line[0] === ' ');
  429. result += prefix
  430. + (!prevMoreIndented && !moreIndented && line !== ''
  431. ? '\n' : '')
  432. + foldLine(line, width);
  433. prevMoreIndented = moreIndented;
  434. }
  435. return result;
  436. }
  437. // Greedy line breaking.
  438. // Picks the longest line under the limit each time,
  439. // otherwise settles for the shortest line over the limit.
  440. // NB. More-indented lines *cannot* be folded, as that would add an extra \n.
  441. function foldLine(line, width) {
  442. if (line === '' || line[0] === ' ') return line;
  443. // Since a more-indented line adds a \n, breaks can't be followed by a space.
  444. var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
  445. var match;
  446. // start is an inclusive index. end, curr, and next are exclusive.
  447. var start = 0, end, curr = 0, next = 0;
  448. var result = '';
  449. // Invariants: 0 <= start <= length-1.
  450. // 0 <= curr <= next <= max(0, length-2). curr - start <= width.
  451. // Inside the loop:
  452. // A match implies length >= 2, so curr and next are <= length-2.
  453. while ((match = breakRe.exec(line))) {
  454. next = match.index;
  455. // maintain invariant: curr - start <= width
  456. if (next - start > width) {
  457. end = (curr > start) ? curr : next; // derive end <= length-2
  458. result += '\n' + line.slice(start, end);
  459. // skip the space that was output as \n
  460. start = end + 1; // derive start <= length-1
  461. }
  462. curr = next;
  463. }
  464. // By the invariants, start <= length-1, so there is something left over.
  465. // It is either the whole string or a part starting from non-whitespace.
  466. result += '\n';
  467. // Insert a break if the remainder is too long and there is a break available.
  468. if (line.length - start > width && curr > start) {
  469. result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
  470. } else {
  471. result += line.slice(start);
  472. }
  473. return result.slice(1); // drop extra \n joiner
  474. }
  475. // Escapes a double-quoted string.
  476. function escapeString(string) {
  477. var result = '';
  478. var char;
  479. var escapeSeq;
  480. for (var i = 0; i < string.length; i++) {
  481. char = string.charCodeAt(i);
  482. escapeSeq = ESCAPE_SEQUENCES[char];
  483. result += !escapeSeq && isPrintable(char)
  484. ? string[i]
  485. : escapeSeq || encodeHex(char);
  486. }
  487. return result;
  488. }
  489. function writeFlowSequence(state, level, object) {
  490. var _result = '',
  491. _tag = state.tag,
  492. index,
  493. length;
  494. for (index = 0, length = object.length; index < length; index += 1) {
  495. // Write only valid elements.
  496. if (writeNode(state, level, object[index], false, false)) {
  497. if (index !== 0) _result += ', ';
  498. _result += state.dump;
  499. }
  500. }
  501. state.tag = _tag;
  502. state.dump = '[' + _result + ']';
  503. }
  504. function writeBlockSequence(state, level, object, compact) {
  505. var _result = '',
  506. _tag = state.tag,
  507. index,
  508. length;
  509. for (index = 0, length = object.length; index < length; index += 1) {
  510. // Write only valid elements.
  511. if (writeNode(state, level + 1, object[index], true, true)) {
  512. if (!compact || index !== 0) {
  513. _result += generateNextLine(state, level);
  514. }
  515. _result += '- ' + state.dump;
  516. }
  517. }
  518. state.tag = _tag;
  519. state.dump = _result || '[]'; // Empty sequence if no valid values.
  520. }
  521. function writeFlowMapping(state, level, object) {
  522. var _result = '',
  523. _tag = state.tag,
  524. objectKeyList = Object.keys(object),
  525. index,
  526. length,
  527. objectKey,
  528. objectValue,
  529. pairBuffer;
  530. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  531. pairBuffer = '';
  532. if (index !== 0) pairBuffer += ', ';
  533. objectKey = objectKeyList[index];
  534. objectValue = object[objectKey];
  535. if (!writeNode(state, level, objectKey, false, false)) {
  536. continue; // Skip this pair because of invalid key;
  537. }
  538. if (state.dump.length > 1024) pairBuffer += '? ';
  539. pairBuffer += state.dump + ': ';
  540. if (!writeNode(state, level, objectValue, false, false)) {
  541. continue; // Skip this pair because of invalid value.
  542. }
  543. pairBuffer += state.dump;
  544. // Both key and value are valid.
  545. _result += pairBuffer;
  546. }
  547. state.tag = _tag;
  548. state.dump = '{' + _result + '}';
  549. }
  550. function writeBlockMapping(state, level, object, compact) {
  551. var _result = '',
  552. _tag = state.tag,
  553. objectKeyList = Object.keys(object),
  554. index,
  555. length,
  556. objectKey,
  557. objectValue,
  558. explicitPair,
  559. pairBuffer;
  560. // Allow sorting keys so that the output file is deterministic
  561. if (state.sortKeys === true) {
  562. // Default sorting
  563. objectKeyList.sort();
  564. } else if (typeof state.sortKeys === 'function') {
  565. // Custom sort function
  566. objectKeyList.sort(state.sortKeys);
  567. } else if (state.sortKeys) {
  568. // Something is wrong
  569. throw new YAMLException('sortKeys must be a boolean or a function');
  570. }
  571. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  572. pairBuffer = '';
  573. if (!compact || index !== 0) {
  574. pairBuffer += generateNextLine(state, level);
  575. }
  576. objectKey = objectKeyList[index];
  577. objectValue = object[objectKey];
  578. if (!writeNode(state, level + 1, objectKey, true, true, true)) {
  579. continue; // Skip this pair because of invalid key.
  580. }
  581. explicitPair = (state.tag !== null && state.tag !== '?') ||
  582. (state.dump && state.dump.length > 1024);
  583. if (explicitPair) {
  584. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  585. pairBuffer += '?';
  586. } else {
  587. pairBuffer += '? ';
  588. }
  589. }
  590. pairBuffer += state.dump;
  591. if (explicitPair) {
  592. pairBuffer += generateNextLine(state, level);
  593. }
  594. if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
  595. continue; // Skip this pair because of invalid value.
  596. }
  597. if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
  598. pairBuffer += ':';
  599. } else {
  600. pairBuffer += ': ';
  601. }
  602. pairBuffer += state.dump;
  603. // Both key and value are valid.
  604. _result += pairBuffer;
  605. }
  606. state.tag = _tag;
  607. state.dump = _result || '{}'; // Empty mapping if no valid pairs.
  608. }
  609. function detectType(state, object, explicit) {
  610. var _result, typeList, index, length, type, style;
  611. typeList = explicit ? state.explicitTypes : state.implicitTypes;
  612. for (index = 0, length = typeList.length; index < length; index += 1) {
  613. type = typeList[index];
  614. if ((type.instanceOf || type.predicate) &&
  615. (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) &&
  616. (!type.predicate || type.predicate(object))) {
  617. state.tag = explicit ? type.tag : '?';
  618. if (type.represent) {
  619. style = state.styleMap[type.tag] || type.defaultStyle;
  620. if (_toString.call(type.represent) === '[object Function]') {
  621. _result = type.represent(object, style);
  622. } else if (_hasOwnProperty.call(type.represent, style)) {
  623. _result = type.represent[style](object, style);
  624. } else {
  625. throw new YAMLException('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
  626. }
  627. state.dump = _result;
  628. }
  629. return true;
  630. }
  631. }
  632. return false;
  633. }
  634. // Serializes `object` and writes it to global `result`.
  635. // Returns true on success, or false on invalid object.
  636. //
  637. function writeNode(state, level, object, block, compact, iskey) {
  638. state.tag = null;
  639. state.dump = object;
  640. if (!detectType(state, object, false)) {
  641. detectType(state, object, true);
  642. }
  643. var type = _toString.call(state.dump);
  644. if (block) {
  645. block = (state.flowLevel < 0 || state.flowLevel > level);
  646. }
  647. var objectOrArray = type === '[object Object]' || type === '[object Array]',
  648. duplicateIndex,
  649. duplicate;
  650. if (objectOrArray) {
  651. duplicateIndex = state.duplicates.indexOf(object);
  652. duplicate = duplicateIndex !== -1;
  653. }
  654. if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
  655. compact = false;
  656. }
  657. if (duplicate && state.usedDuplicates[duplicateIndex]) {
  658. state.dump = '*ref_' + duplicateIndex;
  659. } else {
  660. if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
  661. state.usedDuplicates[duplicateIndex] = true;
  662. }
  663. if (type === '[object Object]') {
  664. if (block && (Object.keys(state.dump).length !== 0)) {
  665. writeBlockMapping(state, level, state.dump, compact);
  666. if (duplicate) {
  667. state.dump = '&ref_' + duplicateIndex + state.dump;
  668. }
  669. } else {
  670. writeFlowMapping(state, level, state.dump);
  671. if (duplicate) {
  672. state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
  673. }
  674. }
  675. } else if (type === '[object Array]') {
  676. if (block && (state.dump.length !== 0)) {
  677. writeBlockSequence(state, level, state.dump, compact);
  678. if (duplicate) {
  679. state.dump = '&ref_' + duplicateIndex + state.dump;
  680. }
  681. } else {
  682. writeFlowSequence(state, level, state.dump);
  683. if (duplicate) {
  684. state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
  685. }
  686. }
  687. } else if (type === '[object String]') {
  688. if (state.tag !== '?') {
  689. writeScalar(state, state.dump, level, iskey);
  690. }
  691. } else {
  692. if (state.skipInvalid) return false;
  693. throw new YAMLException('unacceptable kind of an object to dump ' + type);
  694. }
  695. if (state.tag !== null && state.tag !== '?') {
  696. state.dump = '!<' + state.tag + '> ' + state.dump;
  697. }
  698. }
  699. return true;
  700. }
  701. function getDuplicateReferences(object, state) {
  702. var objects = [],
  703. duplicatesIndexes = [],
  704. index,
  705. length;
  706. inspectNode(object, objects, duplicatesIndexes);
  707. for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
  708. state.duplicates.push(objects[duplicatesIndexes[index]]);
  709. }
  710. state.usedDuplicates = new Array(length);
  711. }
  712. function inspectNode(object, objects, duplicatesIndexes) {
  713. var objectKeyList,
  714. index,
  715. length;
  716. if (object !== null && typeof object === 'object') {
  717. index = objects.indexOf(object);
  718. if (index !== -1) {
  719. if (duplicatesIndexes.indexOf(index) === -1) {
  720. duplicatesIndexes.push(index);
  721. }
  722. } else {
  723. objects.push(object);
  724. if (Array.isArray(object)) {
  725. for (index = 0, length = object.length; index < length; index += 1) {
  726. inspectNode(object[index], objects, duplicatesIndexes);
  727. }
  728. } else {
  729. objectKeyList = Object.keys(object);
  730. for (index = 0, length = objectKeyList.length; index < length; index += 1) {
  731. inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
  732. }
  733. }
  734. }
  735. }
  736. }
  737. function dump(input, options) {
  738. options = options || {};
  739. var state = new State(options);
  740. if (!state.noRefs) getDuplicateReferences(input, state);
  741. if (writeNode(state, 0, input, true, true)) return state.dump + '\n';
  742. return '';
  743. }
  744. function safeDump(input, options) {
  745. return dump(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
  746. }
  747. module.exports.dump = dump;
  748. module.exports.safeDump = safeDump;
  749. },{"./common":2,"./exception":4,"./schema/default_full":9,"./schema/default_safe":10}],4:[function(require,module,exports){
  750. // YAML error class. http://stackoverflow.com/questions/8458984
  751. //
  752. 'use strict';
  753. function YAMLException(reason, mark) {
  754. // Super constructor
  755. Error.call(this);
  756. // Include stack trace in error object
  757. if (Error.captureStackTrace) {
  758. // Chrome and NodeJS
  759. Error.captureStackTrace(this, this.constructor);
  760. } else {
  761. // FF, IE 10+ and Safari 6+. Fallback for others
  762. this.stack = (new Error()).stack || '';
  763. }
  764. this.name = 'YAMLException';
  765. this.reason = reason;
  766. this.mark = mark;
  767. this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : '');
  768. }
  769. // Inherit from Error
  770. YAMLException.prototype = Object.create(Error.prototype);
  771. YAMLException.prototype.constructor = YAMLException;
  772. YAMLException.prototype.toString = function toString(compact) {
  773. var result = this.name + ': ';
  774. result += this.reason || '(unknown reason)';
  775. if (!compact && this.mark) {
  776. result += ' ' + this.mark.toString();
  777. }
  778. return result;
  779. };
  780. module.exports = YAMLException;
  781. },{}],5:[function(require,module,exports){
  782. 'use strict';
  783. /*eslint-disable max-len,no-use-before-define*/
  784. var common = require('./common');
  785. var YAMLException = require('./exception');
  786. var Mark = require('./mark');
  787. var DEFAULT_SAFE_SCHEMA = require('./schema/default_safe');
  788. var DEFAULT_FULL_SCHEMA = require('./schema/default_full');
  789. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  790. var CONTEXT_FLOW_IN = 1;
  791. var CONTEXT_FLOW_OUT = 2;
  792. var CONTEXT_BLOCK_IN = 3;
  793. var CONTEXT_BLOCK_OUT = 4;
  794. var CHOMPING_CLIP = 1;
  795. var CHOMPING_STRIP = 2;
  796. var CHOMPING_KEEP = 3;
  797. var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
  798. var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
  799. var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
  800. var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
  801. var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
  802. function is_EOL(c) {
  803. return (c === 0x0A/* LF */) || (c === 0x0D/* CR */);
  804. }
  805. function is_WHITE_SPACE(c) {
  806. return (c === 0x09/* Tab */) || (c === 0x20/* Space */);
  807. }
  808. function is_WS_OR_EOL(c) {
  809. return (c === 0x09/* Tab */) ||
  810. (c === 0x20/* Space */) ||
  811. (c === 0x0A/* LF */) ||
  812. (c === 0x0D/* CR */);
  813. }
  814. function is_FLOW_INDICATOR(c) {
  815. return c === 0x2C/* , */ ||
  816. c === 0x5B/* [ */ ||
  817. c === 0x5D/* ] */ ||
  818. c === 0x7B/* { */ ||
  819. c === 0x7D/* } */;
  820. }
  821. function fromHexCode(c) {
  822. var lc;
  823. if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
  824. return c - 0x30;
  825. }
  826. /*eslint-disable no-bitwise*/
  827. lc = c | 0x20;
  828. if ((0x61/* a */ <= lc) && (lc <= 0x66/* f */)) {
  829. return lc - 0x61 + 10;
  830. }
  831. return -1;
  832. }
  833. function escapedHexLen(c) {
  834. if (c === 0x78/* x */) { return 2; }
  835. if (c === 0x75/* u */) { return 4; }
  836. if (c === 0x55/* U */) { return 8; }
  837. return 0;
  838. }
  839. function fromDecimalCode(c) {
  840. if ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) {
  841. return c - 0x30;
  842. }
  843. return -1;
  844. }
  845. function simpleEscapeSequence(c) {
  846. return (c === 0x30/* 0 */) ? '\x00' :
  847. (c === 0x61/* a */) ? '\x07' :
  848. (c === 0x62/* b */) ? '\x08' :
  849. (c === 0x74/* t */) ? '\x09' :
  850. (c === 0x09/* Tab */) ? '\x09' :
  851. (c === 0x6E/* n */) ? '\x0A' :
  852. (c === 0x76/* v */) ? '\x0B' :
  853. (c === 0x66/* f */) ? '\x0C' :
  854. (c === 0x72/* r */) ? '\x0D' :
  855. (c === 0x65/* e */) ? '\x1B' :
  856. (c === 0x20/* Space */) ? ' ' :
  857. (c === 0x22/* " */) ? '\x22' :
  858. (c === 0x2F/* / */) ? '/' :
  859. (c === 0x5C/* \ */) ? '\x5C' :
  860. (c === 0x4E/* N */) ? '\x85' :
  861. (c === 0x5F/* _ */) ? '\xA0' :
  862. (c === 0x4C/* L */) ? '\u2028' :
  863. (c === 0x50/* P */) ? '\u2029' : '';
  864. }
  865. function charFromCodepoint(c) {
  866. if (c <= 0xFFFF) {
  867. return String.fromCharCode(c);
  868. }
  869. // Encode UTF-16 surrogate pair
  870. // https://en.wikipedia.org/wiki/UTF-16#Code_points_U.2B010000_to_U.2B10FFFF
  871. return String.fromCharCode(((c - 0x010000) >> 10) + 0xD800,
  872. ((c - 0x010000) & 0x03FF) + 0xDC00);
  873. }
  874. var simpleEscapeCheck = new Array(256); // integer, for fast access
  875. var simpleEscapeMap = new Array(256);
  876. for (var i = 0; i < 256; i++) {
  877. simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
  878. simpleEscapeMap[i] = simpleEscapeSequence(i);
  879. }
  880. function State(input, options) {
  881. this.input = input;
  882. this.filename = options['filename'] || null;
  883. this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
  884. this.onWarning = options['onWarning'] || null;
  885. this.legacy = options['legacy'] || false;
  886. this.json = options['json'] || false;
  887. this.listener = options['listener'] || null;
  888. this.implicitTypes = this.schema.compiledImplicit;
  889. this.typeMap = this.schema.compiledTypeMap;
  890. this.length = input.length;
  891. this.position = 0;
  892. this.line = 0;
  893. this.lineStart = 0;
  894. this.lineIndent = 0;
  895. this.documents = [];
  896. /*
  897. this.version;
  898. this.checkLineBreaks;
  899. this.tagMap;
  900. this.anchorMap;
  901. this.tag;
  902. this.anchor;
  903. this.kind;
  904. this.result;*/
  905. }
  906. function generateError(state, message) {
  907. return new YAMLException(
  908. message,
  909. new Mark(state.filename, state.input, state.position, state.line, (state.position - state.lineStart)));
  910. }
  911. function throwError(state, message) {
  912. throw generateError(state, message);
  913. }
  914. function throwWarning(state, message) {
  915. if (state.onWarning) {
  916. state.onWarning.call(null, generateError(state, message));
  917. }
  918. }
  919. var directiveHandlers = {
  920. YAML: function handleYamlDirective(state, name, args) {
  921. var match, major, minor;
  922. if (state.version !== null) {
  923. throwError(state, 'duplication of %YAML directive');
  924. }
  925. if (args.length !== 1) {
  926. throwError(state, 'YAML directive accepts exactly one argument');
  927. }
  928. match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
  929. if (match === null) {
  930. throwError(state, 'ill-formed argument of the YAML directive');
  931. }
  932. major = parseInt(match[1], 10);
  933. minor = parseInt(match[2], 10);
  934. if (major !== 1) {
  935. throwError(state, 'unacceptable YAML version of the document');
  936. }
  937. state.version = args[0];
  938. state.checkLineBreaks = (minor < 2);
  939. if (minor !== 1 && minor !== 2) {
  940. throwWarning(state, 'unsupported YAML version of the document');
  941. }
  942. },
  943. TAG: function handleTagDirective(state, name, args) {
  944. var handle, prefix;
  945. if (args.length !== 2) {
  946. throwError(state, 'TAG directive accepts exactly two arguments');
  947. }
  948. handle = args[0];
  949. prefix = args[1];
  950. if (!PATTERN_TAG_HANDLE.test(handle)) {
  951. throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
  952. }
  953. if (_hasOwnProperty.call(state.tagMap, handle)) {
  954. throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
  955. }
  956. if (!PATTERN_TAG_URI.test(prefix)) {
  957. throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
  958. }
  959. state.tagMap[handle] = prefix;
  960. }
  961. };
  962. function captureSegment(state, start, end, checkJson) {
  963. var _position, _length, _character, _result;
  964. if (start < end) {
  965. _result = state.input.slice(start, end);
  966. if (checkJson) {
  967. for (_position = 0, _length = _result.length;
  968. _position < _length;
  969. _position += 1) {
  970. _character = _result.charCodeAt(_position);
  971. if (!(_character === 0x09 ||
  972. (0x20 <= _character && _character <= 0x10FFFF))) {
  973. throwError(state, 'expected valid JSON character');
  974. }
  975. }
  976. } else if (PATTERN_NON_PRINTABLE.test(_result)) {
  977. throwError(state, 'the stream contains non-printable characters');
  978. }
  979. state.result += _result;
  980. }
  981. }
  982. function mergeMappings(state, destination, source, overridableKeys) {
  983. var sourceKeys, key, index, quantity;
  984. if (!common.isObject(source)) {
  985. throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
  986. }
  987. sourceKeys = Object.keys(source);
  988. for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
  989. key = sourceKeys[index];
  990. if (!_hasOwnProperty.call(destination, key)) {
  991. destination[key] = source[key];
  992. overridableKeys[key] = true;
  993. }
  994. }
  995. }
  996. function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode) {
  997. var index, quantity;
  998. keyNode = String(keyNode);
  999. if (_result === null) {
  1000. _result = {};
  1001. }
  1002. if (keyTag === 'tag:yaml.org,2002:merge') {
  1003. if (Array.isArray(valueNode)) {
  1004. for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
  1005. mergeMappings(state, _result, valueNode[index], overridableKeys);
  1006. }
  1007. } else {
  1008. mergeMappings(state, _result, valueNode, overridableKeys);
  1009. }
  1010. } else {
  1011. if (!state.json &&
  1012. !_hasOwnProperty.call(overridableKeys, keyNode) &&
  1013. _hasOwnProperty.call(_result, keyNode)) {
  1014. throwError(state, 'duplicated mapping key');
  1015. }
  1016. _result[keyNode] = valueNode;
  1017. delete overridableKeys[keyNode];
  1018. }
  1019. return _result;
  1020. }
  1021. function readLineBreak(state) {
  1022. var ch;
  1023. ch = state.input.charCodeAt(state.position);
  1024. if (ch === 0x0A/* LF */) {
  1025. state.position++;
  1026. } else if (ch === 0x0D/* CR */) {
  1027. state.position++;
  1028. if (state.input.charCodeAt(state.position) === 0x0A/* LF */) {
  1029. state.position++;
  1030. }
  1031. } else {
  1032. throwError(state, 'a line break is expected');
  1033. }
  1034. state.line += 1;
  1035. state.lineStart = state.position;
  1036. }
  1037. function skipSeparationSpace(state, allowComments, checkIndent) {
  1038. var lineBreaks = 0,
  1039. ch = state.input.charCodeAt(state.position);
  1040. while (ch !== 0) {
  1041. while (is_WHITE_SPACE(ch)) {
  1042. ch = state.input.charCodeAt(++state.position);
  1043. }
  1044. if (allowComments && ch === 0x23/* # */) {
  1045. do {
  1046. ch = state.input.charCodeAt(++state.position);
  1047. } while (ch !== 0x0A/* LF */ && ch !== 0x0D/* CR */ && ch !== 0);
  1048. }
  1049. if (is_EOL(ch)) {
  1050. readLineBreak(state);
  1051. ch = state.input.charCodeAt(state.position);
  1052. lineBreaks++;
  1053. state.lineIndent = 0;
  1054. while (ch === 0x20/* Space */) {
  1055. state.lineIndent++;
  1056. ch = state.input.charCodeAt(++state.position);
  1057. }
  1058. } else {
  1059. break;
  1060. }
  1061. }
  1062. if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
  1063. throwWarning(state, 'deficient indentation');
  1064. }
  1065. return lineBreaks;
  1066. }
  1067. function testDocumentSeparator(state) {
  1068. var _position = state.position,
  1069. ch;
  1070. ch = state.input.charCodeAt(_position);
  1071. // Condition state.position === state.lineStart is tested
  1072. // in parent on each call, for efficiency. No needs to test here again.
  1073. if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) &&
  1074. ch === state.input.charCodeAt(_position + 1) &&
  1075. ch === state.input.charCodeAt(_position + 2)) {
  1076. _position += 3;
  1077. ch = state.input.charCodeAt(_position);
  1078. if (ch === 0 || is_WS_OR_EOL(ch)) {
  1079. return true;
  1080. }
  1081. }
  1082. return false;
  1083. }
  1084. function writeFoldedLines(state, count) {
  1085. if (count === 1) {
  1086. state.result += ' ';
  1087. } else if (count > 1) {
  1088. state.result += common.repeat('\n', count - 1);
  1089. }
  1090. }
  1091. function readPlainScalar(state, nodeIndent, withinFlowCollection) {
  1092. var preceding,
  1093. following,
  1094. captureStart,
  1095. captureEnd,
  1096. hasPendingContent,
  1097. _line,
  1098. _lineStart,
  1099. _lineIndent,
  1100. _kind = state.kind,
  1101. _result = state.result,
  1102. ch;
  1103. ch = state.input.charCodeAt(state.position);
  1104. if (is_WS_OR_EOL(ch) ||
  1105. is_FLOW_INDICATOR(ch) ||
  1106. ch === 0x23/* # */ ||
  1107. ch === 0x26/* & */ ||
  1108. ch === 0x2A/* * */ ||
  1109. ch === 0x21/* ! */ ||
  1110. ch === 0x7C/* | */ ||
  1111. ch === 0x3E/* > */ ||
  1112. ch === 0x27/* ' */ ||
  1113. ch === 0x22/* " */ ||
  1114. ch === 0x25/* % */ ||
  1115. ch === 0x40/* @ */ ||
  1116. ch === 0x60/* ` */) {
  1117. return false;
  1118. }
  1119. if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) {
  1120. following = state.input.charCodeAt(state.position + 1);
  1121. if (is_WS_OR_EOL(following) ||
  1122. withinFlowCollection && is_FLOW_INDICATOR(following)) {
  1123. return false;
  1124. }
  1125. }
  1126. state.kind = 'scalar';
  1127. state.result = '';
  1128. captureStart = captureEnd = state.position;
  1129. hasPendingContent = false;
  1130. while (ch !== 0) {
  1131. if (ch === 0x3A/* : */) {
  1132. following = state.input.charCodeAt(state.position + 1);
  1133. if (is_WS_OR_EOL(following) ||
  1134. withinFlowCollection && is_FLOW_INDICATOR(following)) {
  1135. break;
  1136. }
  1137. } else if (ch === 0x23/* # */) {
  1138. preceding = state.input.charCodeAt(state.position - 1);
  1139. if (is_WS_OR_EOL(preceding)) {
  1140. break;
  1141. }
  1142. } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
  1143. withinFlowCollection && is_FLOW_INDICATOR(ch)) {
  1144. break;
  1145. } else if (is_EOL(ch)) {
  1146. _line = state.line;
  1147. _lineStart = state.lineStart;
  1148. _lineIndent = state.lineIndent;
  1149. skipSeparationSpace(state, false, -1);
  1150. if (state.lineIndent >= nodeIndent) {
  1151. hasPendingContent = true;
  1152. ch = state.input.charCodeAt(state.position);
  1153. continue;
  1154. } else {
  1155. state.position = captureEnd;
  1156. state.line = _line;
  1157. state.lineStart = _lineStart;
  1158. state.lineIndent = _lineIndent;
  1159. break;
  1160. }
  1161. }
  1162. if (hasPendingContent) {
  1163. captureSegment(state, captureStart, captureEnd, false);
  1164. writeFoldedLines(state, state.line - _line);
  1165. captureStart = captureEnd = state.position;
  1166. hasPendingContent = false;
  1167. }
  1168. if (!is_WHITE_SPACE(ch)) {
  1169. captureEnd = state.position + 1;
  1170. }
  1171. ch = state.input.charCodeAt(++state.position);
  1172. }
  1173. captureSegment(state, captureStart, captureEnd, false);
  1174. if (state.result) {
  1175. return true;
  1176. }
  1177. state.kind = _kind;
  1178. state.result = _result;
  1179. return false;
  1180. }
  1181. function readSingleQuotedScalar(state, nodeIndent) {
  1182. var ch,
  1183. captureStart, captureEnd;
  1184. ch = state.input.charCodeAt(state.position);
  1185. if (ch !== 0x27/* ' */) {
  1186. return false;
  1187. }
  1188. state.kind = 'scalar';
  1189. state.result = '';
  1190. state.position++;
  1191. captureStart = captureEnd = state.position;
  1192. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  1193. if (ch === 0x27/* ' */) {
  1194. captureSegment(state, captureStart, state.position, true);
  1195. ch = state.input.charCodeAt(++state.position);
  1196. if (ch === 0x27/* ' */) {
  1197. captureStart = state.position;
  1198. state.position++;
  1199. captureEnd = state.position;
  1200. } else {
  1201. return true;
  1202. }
  1203. } else if (is_EOL(ch)) {
  1204. captureSegment(state, captureStart, captureEnd, true);
  1205. writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
  1206. captureStart = captureEnd = state.position;
  1207. } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
  1208. throwError(state, 'unexpected end of the document within a single quoted scalar');
  1209. } else {
  1210. state.position++;
  1211. captureEnd = state.position;
  1212. }
  1213. }
  1214. throwError(state, 'unexpected end of the stream within a single quoted scalar');
  1215. }
  1216. function readDoubleQuotedScalar(state, nodeIndent) {
  1217. var captureStart,
  1218. captureEnd,
  1219. hexLength,
  1220. hexResult,
  1221. tmp,
  1222. ch;
  1223. ch = state.input.charCodeAt(state.position);
  1224. if (ch !== 0x22/* " */) {
  1225. return false;
  1226. }
  1227. state.kind = 'scalar';
  1228. state.result = '';
  1229. state.position++;
  1230. captureStart = captureEnd = state.position;
  1231. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  1232. if (ch === 0x22/* " */) {
  1233. captureSegment(state, captureStart, state.position, true);
  1234. state.position++;
  1235. return true;
  1236. } else if (ch === 0x5C/* \ */) {
  1237. captureSegment(state, captureStart, state.position, true);
  1238. ch = state.input.charCodeAt(++state.position);
  1239. if (is_EOL(ch)) {
  1240. skipSeparationSpace(state, false, nodeIndent);
  1241. // TODO: rework to inline fn with no type cast?
  1242. } else if (ch < 256 && simpleEscapeCheck[ch]) {
  1243. state.result += simpleEscapeMap[ch];
  1244. state.position++;
  1245. } else if ((tmp = escapedHexLen(ch)) > 0) {
  1246. hexLength = tmp;
  1247. hexResult = 0;
  1248. for (; hexLength > 0; hexLength--) {
  1249. ch = state.input.charCodeAt(++state.position);
  1250. if ((tmp = fromHexCode(ch)) >= 0) {
  1251. hexResult = (hexResult << 4) + tmp;
  1252. } else {
  1253. throwError(state, 'expected hexadecimal character');
  1254. }
  1255. }
  1256. state.result += charFromCodepoint(hexResult);
  1257. state.position++;
  1258. } else {
  1259. throwError(state, 'unknown escape sequence');
  1260. }
  1261. captureStart = captureEnd = state.position;
  1262. } else if (is_EOL(ch)) {
  1263. captureSegment(state, captureStart, captureEnd, true);
  1264. writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
  1265. captureStart = captureEnd = state.position;
  1266. } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
  1267. throwError(state, 'unexpected end of the document within a double quoted scalar');
  1268. } else {
  1269. state.position++;
  1270. captureEnd = state.position;
  1271. }
  1272. }
  1273. throwError(state, 'unexpected end of the stream within a double quoted scalar');
  1274. }
  1275. function readFlowCollection(state, nodeIndent) {
  1276. var readNext = true,
  1277. _line,
  1278. _tag = state.tag,
  1279. _result,
  1280. _anchor = state.anchor,
  1281. following,
  1282. terminator,
  1283. isPair,
  1284. isExplicitPair,
  1285. isMapping,
  1286. overridableKeys = {},
  1287. keyNode,
  1288. keyTag,
  1289. valueNode,
  1290. ch;
  1291. ch = state.input.charCodeAt(state.position);
  1292. if (ch === 0x5B/* [ */) {
  1293. terminator = 0x5D;/* ] */
  1294. isMapping = false;
  1295. _result = [];
  1296. } else if (ch === 0x7B/* { */) {
  1297. terminator = 0x7D;/* } */
  1298. isMapping = true;
  1299. _result = {};
  1300. } else {
  1301. return false;
  1302. }
  1303. if (state.anchor !== null) {
  1304. state.anchorMap[state.anchor] = _result;
  1305. }
  1306. ch = state.input.charCodeAt(++state.position);
  1307. while (ch !== 0) {
  1308. skipSeparationSpace(state, true, nodeIndent);
  1309. ch = state.input.charCodeAt(state.position);
  1310. if (ch === terminator) {
  1311. state.position++;
  1312. state.tag = _tag;
  1313. state.anchor = _anchor;
  1314. state.kind = isMapping ? 'mapping' : 'sequence';
  1315. state.result = _result;
  1316. return true;
  1317. } else if (!readNext) {
  1318. throwError(state, 'missed comma between flow collection entries');
  1319. }
  1320. keyTag = keyNode = valueNode = null;
  1321. isPair = isExplicitPair = false;
  1322. if (ch === 0x3F/* ? */) {
  1323. following = state.input.charCodeAt(state.position + 1);
  1324. if (is_WS_OR_EOL(following)) {
  1325. isPair = isExplicitPair = true;
  1326. state.position++;
  1327. skipSeparationSpace(state, true, nodeIndent);
  1328. }
  1329. }
  1330. _line = state.line;
  1331. composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
  1332. keyTag = state.tag;
  1333. keyNode = state.result;
  1334. skipSeparationSpace(state, true, nodeIndent);
  1335. ch = state.input.charCodeAt(state.position);
  1336. if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {
  1337. isPair = true;
  1338. ch = state.input.charCodeAt(++state.position);
  1339. skipSeparationSpace(state, true, nodeIndent);
  1340. composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
  1341. valueNode = state.result;
  1342. }
  1343. if (isMapping) {
  1344. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
  1345. } else if (isPair) {
  1346. _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
  1347. } else {
  1348. _result.push(keyNode);
  1349. }
  1350. skipSeparationSpace(state, true, nodeIndent);
  1351. ch = state.input.charCodeAt(state.position);
  1352. if (ch === 0x2C/* , */) {
  1353. readNext = true;
  1354. ch = state.input.charCodeAt(++state.position);
  1355. } else {
  1356. readNext = false;
  1357. }
  1358. }
  1359. throwError(state, 'unexpected end of the stream within a flow collection');
  1360. }
  1361. function readBlockScalar(state, nodeIndent) {
  1362. var captureStart,
  1363. folding,
  1364. chomping = CHOMPING_CLIP,
  1365. didReadContent = false,
  1366. detectedIndent = false,
  1367. textIndent = nodeIndent,
  1368. emptyLines = 0,
  1369. atMoreIndented = false,
  1370. tmp,
  1371. ch;
  1372. ch = state.input.charCodeAt(state.position);
  1373. if (ch === 0x7C/* | */) {
  1374. folding = false;
  1375. } else if (ch === 0x3E/* > */) {
  1376. folding = true;
  1377. } else {
  1378. return false;
  1379. }
  1380. state.kind = 'scalar';
  1381. state.result = '';
  1382. while (ch !== 0) {
  1383. ch = state.input.charCodeAt(++state.position);
  1384. if (ch === 0x2B/* + */ || ch === 0x2D/* - */) {
  1385. if (CHOMPING_CLIP === chomping) {
  1386. chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP;
  1387. } else {
  1388. throwError(state, 'repeat of a chomping mode identifier');
  1389. }
  1390. } else if ((tmp = fromDecimalCode(ch)) >= 0) {
  1391. if (tmp === 0) {
  1392. throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
  1393. } else if (!detectedIndent) {
  1394. textIndent = nodeIndent + tmp - 1;
  1395. detectedIndent = true;
  1396. } else {
  1397. throwError(state, 'repeat of an indentation width identifier');
  1398. }
  1399. } else {
  1400. break;
  1401. }
  1402. }
  1403. if (is_WHITE_SPACE(ch)) {
  1404. do { ch = state.input.charCodeAt(++state.position); }
  1405. while (is_WHITE_SPACE(ch));
  1406. if (ch === 0x23/* # */) {
  1407. do { ch = state.input.charCodeAt(++state.position); }
  1408. while (!is_EOL(ch) && (ch !== 0));
  1409. }
  1410. }
  1411. while (ch !== 0) {
  1412. readLineBreak(state);
  1413. state.lineIndent = 0;
  1414. ch = state.input.charCodeAt(state.position);
  1415. while ((!detectedIndent || state.lineIndent < textIndent) &&
  1416. (ch === 0x20/* Space */)) {
  1417. state.lineIndent++;
  1418. ch = state.input.charCodeAt(++state.position);
  1419. }
  1420. if (!detectedIndent && state.lineIndent > textIndent) {
  1421. textIndent = state.lineIndent;
  1422. }
  1423. if (is_EOL(ch)) {
  1424. emptyLines++;
  1425. continue;
  1426. }
  1427. // End of the scalar.
  1428. if (state.lineIndent < textIndent) {
  1429. // Perform the chomping.
  1430. if (chomping === CHOMPING_KEEP) {
  1431. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
  1432. } else if (chomping === CHOMPING_CLIP) {
  1433. if (didReadContent) { // i.e. only if the scalar is not empty.
  1434. state.result += '\n';
  1435. }
  1436. }
  1437. // Break this `while` cycle and go to the funciton's epilogue.
  1438. break;
  1439. }
  1440. // Folded style: use fancy rules to handle line breaks.
  1441. if (folding) {
  1442. // Lines starting with white space characters (more-indented lines) are not folded.
  1443. if (is_WHITE_SPACE(ch)) {
  1444. atMoreIndented = true;
  1445. // except for the first content line (cf. Example 8.1)
  1446. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
  1447. // End of more-indented block.
  1448. } else if (atMoreIndented) {
  1449. atMoreIndented = false;
  1450. state.result += common.repeat('\n', emptyLines + 1);
  1451. // Just one line break - perceive as the same line.
  1452. } else if (emptyLines === 0) {
  1453. if (didReadContent) { // i.e. only if we have already read some scalar content.
  1454. state.result += ' ';
  1455. }
  1456. // Several line breaks - perceive as different lines.
  1457. } else {
  1458. state.result += common.repeat('\n', emptyLines);
  1459. }
  1460. // Literal style: just add exact number of line breaks between content lines.
  1461. } else {
  1462. // Keep all line breaks except the header line break.
  1463. state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
  1464. }
  1465. didReadContent = true;
  1466. detectedIndent = true;
  1467. emptyLines = 0;
  1468. captureStart = state.position;
  1469. while (!is_EOL(ch) && (ch !== 0)) {
  1470. ch = state.input.charCodeAt(++state.position);
  1471. }
  1472. captureSegment(state, captureStart, state.position, false);
  1473. }
  1474. return true;
  1475. }
  1476. function readBlockSequence(state, nodeIndent) {
  1477. var _line,
  1478. _tag = state.tag,
  1479. _anchor = state.anchor,
  1480. _result = [],
  1481. following,
  1482. detected = false,
  1483. ch;
  1484. if (state.anchor !== null) {
  1485. state.anchorMap[state.anchor] = _result;
  1486. }
  1487. ch = state.input.charCodeAt(state.position);
  1488. while (ch !== 0) {
  1489. if (ch !== 0x2D/* - */) {
  1490. break;
  1491. }
  1492. following = state.input.charCodeAt(state.position + 1);
  1493. if (!is_WS_OR_EOL(following)) {
  1494. break;
  1495. }
  1496. detected = true;
  1497. state.position++;
  1498. if (skipSeparationSpace(state, true, -1)) {
  1499. if (state.lineIndent <= nodeIndent) {
  1500. _result.push(null);
  1501. ch = state.input.charCodeAt(state.position);
  1502. continue;
  1503. }
  1504. }
  1505. _line = state.line;
  1506. composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
  1507. _result.push(state.result);
  1508. skipSeparationSpace(state, true, -1);
  1509. ch = state.input.charCodeAt(state.position);
  1510. if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
  1511. throwError(state, 'bad indentation of a sequence entry');
  1512. } else if (state.lineIndent < nodeIndent) {
  1513. break;
  1514. }
  1515. }
  1516. if (detected) {
  1517. state.tag = _tag;
  1518. state.anchor = _anchor;
  1519. state.kind = 'sequence';
  1520. state.result = _result;
  1521. return true;
  1522. }
  1523. return false;
  1524. }
  1525. function readBlockMapping(state, nodeIndent, flowIndent) {
  1526. var following,
  1527. allowCompact,
  1528. _line,
  1529. _tag = state.tag,
  1530. _anchor = state.anchor,
  1531. _result = {},
  1532. overridableKeys = {},
  1533. keyTag = null,
  1534. keyNode = null,
  1535. valueNode = null,
  1536. atExplicitKey = false,
  1537. detected = false,
  1538. ch;
  1539. if (state.anchor !== null) {
  1540. state.anchorMap[state.anchor] = _result;
  1541. }
  1542. ch = state.input.charCodeAt(state.position);
  1543. while (ch !== 0) {
  1544. following = state.input.charCodeAt(state.position + 1);
  1545. _line = state.line; // Save the current line.
  1546. //
  1547. // Explicit notation case. There are two separate blocks:
  1548. // first for the key (denoted by "?") and second for the value (denoted by ":")
  1549. //
  1550. if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && is_WS_OR_EOL(following)) {
  1551. if (ch === 0x3F/* ? */) {
  1552. if (atExplicitKey) {
  1553. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  1554. keyTag = keyNode = valueNode = null;
  1555. }
  1556. detected = true;
  1557. atExplicitKey = true;
  1558. allowCompact = true;
  1559. } else if (atExplicitKey) {
  1560. // i.e. 0x3A/* : */ === character after the explicit key.
  1561. atExplicitKey = false;
  1562. allowCompact = true;
  1563. } else {
  1564. throwError(state, 'incomplete explicit mapping pair; a key node is missed');
  1565. }
  1566. state.position += 1;
  1567. ch = following;
  1568. //
  1569. // Implicit notation case. Flow-style node as the key first, then ":", and the value.
  1570. //
  1571. } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
  1572. if (state.line === _line) {
  1573. ch = state.input.charCodeAt(state.position);
  1574. while (is_WHITE_SPACE(ch)) {
  1575. ch = state.input.charCodeAt(++state.position);
  1576. }
  1577. if (ch === 0x3A/* : */) {
  1578. ch = state.input.charCodeAt(++state.position);
  1579. if (!is_WS_OR_EOL(ch)) {
  1580. throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
  1581. }
  1582. if (atExplicitKey) {
  1583. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  1584. keyTag = keyNode = valueNode = null;
  1585. }
  1586. detected = true;
  1587. atExplicitKey = false;
  1588. allowCompact = false;
  1589. keyTag = state.tag;
  1590. keyNode = state.result;
  1591. } else if (detected) {
  1592. throwError(state, 'can not read an implicit mapping pair; a colon is missed');
  1593. } else {
  1594. state.tag = _tag;
  1595. state.anchor = _anchor;
  1596. return true; // Keep the result of `composeNode`.
  1597. }
  1598. } else if (detected) {
  1599. throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
  1600. } else {
  1601. state.tag = _tag;
  1602. state.anchor = _anchor;
  1603. return true; // Keep the result of `composeNode`.
  1604. }
  1605. } else {
  1606. break; // Reading is done. Go to the epilogue.
  1607. }
  1608. //
  1609. // Common reading code for both explicit and implicit notations.
  1610. //
  1611. if (state.line === _line || state.lineIndent > nodeIndent) {
  1612. if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
  1613. if (atExplicitKey) {
  1614. keyNode = state.result;
  1615. } else {
  1616. valueNode = state.result;
  1617. }
  1618. }
  1619. if (!atExplicitKey) {
  1620. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
  1621. keyTag = keyNode = valueNode = null;
  1622. }
  1623. skipSeparationSpace(state, true, -1);
  1624. ch = state.input.charCodeAt(state.position);
  1625. }
  1626. if (state.lineIndent > nodeIndent && (ch !== 0)) {
  1627. throwError(state, 'bad indentation of a mapping entry');
  1628. } else if (state.lineIndent < nodeIndent) {
  1629. break;
  1630. }
  1631. }
  1632. //
  1633. // Epilogue.
  1634. //
  1635. // Special case: last mapping's node contains only the key in explicit notation.
  1636. if (atExplicitKey) {
  1637. storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
  1638. }
  1639. // Expose the resulting mapping.
  1640. if (detected) {
  1641. state.tag = _tag;
  1642. state.anchor = _anchor;
  1643. state.kind = 'mapping';
  1644. state.result = _result;
  1645. }
  1646. return detected;
  1647. }
  1648. function readTagProperty(state) {
  1649. var _position,
  1650. isVerbatim = false,
  1651. isNamed = false,
  1652. tagHandle,
  1653. tagName,
  1654. ch;
  1655. ch = state.input.charCodeAt(state.position);
  1656. if (ch !== 0x21/* ! */) return false;
  1657. if (state.tag !== null) {
  1658. throwError(state, 'duplication of a tag property');
  1659. }
  1660. ch = state.input.charCodeAt(++state.position);
  1661. if (ch === 0x3C/* < */) {
  1662. isVerbatim = true;
  1663. ch = state.input.charCodeAt(++state.position);
  1664. } else if (ch === 0x21/* ! */) {
  1665. isNamed = true;
  1666. tagHandle = '!!';
  1667. ch = state.input.charCodeAt(++state.position);
  1668. } else {
  1669. tagHandle = '!';
  1670. }
  1671. _position = state.position;
  1672. if (isVerbatim) {
  1673. do { ch = state.input.charCodeAt(++state.position); }
  1674. while (ch !== 0 && ch !== 0x3E/* > */);
  1675. if (state.position < state.length) {
  1676. tagName = state.input.slice(_position, state.position);
  1677. ch = state.input.charCodeAt(++state.position);
  1678. } else {
  1679. throwError(state, 'unexpected end of the stream within a verbatim tag');
  1680. }
  1681. } else {
  1682. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  1683. if (ch === 0x21/* ! */) {
  1684. if (!isNamed) {
  1685. tagHandle = state.input.slice(_position - 1, state.position + 1);
  1686. if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
  1687. throwError(state, 'named tag handle cannot contain such characters');
  1688. }
  1689. isNamed = true;
  1690. _position = state.position + 1;
  1691. } else {
  1692. throwError(state, 'tag suffix cannot contain exclamation marks');
  1693. }
  1694. }
  1695. ch = state.input.charCodeAt(++state.position);
  1696. }
  1697. tagName = state.input.slice(_position, state.position);
  1698. if (PATTERN_FLOW_INDICATORS.test(tagName)) {
  1699. throwError(state, 'tag suffix cannot contain flow indicator characters');
  1700. }
  1701. }
  1702. if (tagName && !PATTERN_TAG_URI.test(tagName)) {
  1703. throwError(state, 'tag name cannot contain such characters: ' + tagName);
  1704. }
  1705. if (isVerbatim) {
  1706. state.tag = tagName;
  1707. } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
  1708. state.tag = state.tagMap[tagHandle] + tagName;
  1709. } else if (tagHandle === '!') {
  1710. state.tag = '!' + tagName;
  1711. } else if (tagHandle === '!!') {
  1712. state.tag = 'tag:yaml.org,2002:' + tagName;
  1713. } else {
  1714. throwError(state, 'undeclared tag handle "' + tagHandle + '"');
  1715. }
  1716. return true;
  1717. }
  1718. function readAnchorProperty(state) {
  1719. var _position,
  1720. ch;
  1721. ch = state.input.charCodeAt(state.position);
  1722. if (ch !== 0x26/* & */) return false;
  1723. if (state.anchor !== null) {
  1724. throwError(state, 'duplication of an anchor property');
  1725. }
  1726. ch = state.input.charCodeAt(++state.position);
  1727. _position = state.position;
  1728. while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
  1729. ch = state.input.charCodeAt(++state.position);
  1730. }
  1731. if (state.position === _position) {
  1732. throwError(state, 'name of an anchor node must contain at least one character');
  1733. }
  1734. state.anchor = state.input.slice(_position, state.position);
  1735. return true;
  1736. }
  1737. function readAlias(state) {
  1738. var _position, alias,
  1739. ch;
  1740. ch = state.input.charCodeAt(state.position);
  1741. if (ch !== 0x2A/* * */) return false;
  1742. ch = state.input.charCodeAt(++state.position);
  1743. _position = state.position;
  1744. while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
  1745. ch = state.input.charCodeAt(++state.position);
  1746. }
  1747. if (state.position === _position) {
  1748. throwError(state, 'name of an alias node must contain at least one character');
  1749. }
  1750. alias = state.input.slice(_position, state.position);
  1751. if (!state.anchorMap.hasOwnProperty(alias)) {
  1752. throwError(state, 'unidentified alias "' + alias + '"');
  1753. }
  1754. state.result = state.anchorMap[alias];
  1755. skipSeparationSpace(state, true, -1);
  1756. return true;
  1757. }
  1758. function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
  1759. var allowBlockStyles,
  1760. allowBlockScalars,
  1761. allowBlockCollections,
  1762. indentStatus = 1, // 1: this>parent, 0: this=parent, -1: this<parent
  1763. atNewLine = false,
  1764. hasContent = false,
  1765. typeIndex,
  1766. typeQuantity,
  1767. type,
  1768. flowIndent,
  1769. blockIndent;
  1770. if (state.listener !== null) {
  1771. state.listener('open', state);
  1772. }
  1773. state.tag = null;
  1774. state.anchor = null;
  1775. state.kind = null;
  1776. state.result = null;
  1777. allowBlockStyles = allowBlockScalars = allowBlockCollections =
  1778. CONTEXT_BLOCK_OUT === nodeContext ||
  1779. CONTEXT_BLOCK_IN === nodeContext;
  1780. if (allowToSeek) {
  1781. if (skipSeparationSpace(state, true, -1)) {
  1782. atNewLine = true;
  1783. if (state.lineIndent > parentIndent) {
  1784. indentStatus = 1;
  1785. } else if (state.lineIndent === parentIndent) {
  1786. indentStatus = 0;
  1787. } else if (state.lineIndent < parentIndent) {
  1788. indentStatus = -1;
  1789. }
  1790. }
  1791. }
  1792. if (indentStatus === 1) {
  1793. while (readTagProperty(state) || readAnchorProperty(state)) {
  1794. if (skipSeparationSpace(state, true, -1)) {
  1795. atNewLine = true;
  1796. allowBlockCollections = allowBlockStyles;
  1797. if (state.lineIndent > parentIndent) {
  1798. indentStatus = 1;
  1799. } else if (state.lineIndent === parentIndent) {
  1800. indentStatus = 0;
  1801. } else if (state.lineIndent < parentIndent) {
  1802. indentStatus = -1;
  1803. }
  1804. } else {
  1805. allowBlockCollections = false;
  1806. }
  1807. }
  1808. }
  1809. if (allowBlockCollections) {
  1810. allowBlockCollections = atNewLine || allowCompact;
  1811. }
  1812. if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
  1813. if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
  1814. flowIndent = parentIndent;
  1815. } else {
  1816. flowIndent = parentIndent + 1;
  1817. }
  1818. blockIndent = state.position - state.lineStart;
  1819. if (indentStatus === 1) {
  1820. if (allowBlockCollections &&
  1821. (readBlockSequence(state, blockIndent) ||
  1822. readBlockMapping(state, blockIndent, flowIndent)) ||
  1823. readFlowCollection(state, flowIndent)) {
  1824. hasContent = true;
  1825. } else {
  1826. if ((allowBlockScalars && readBlockScalar(state, flowIndent)) ||
  1827. readSingleQuotedScalar(state, flowIndent) ||
  1828. readDoubleQuotedScalar(state, flowIndent)) {
  1829. hasContent = true;
  1830. } else if (readAlias(state)) {
  1831. hasContent = true;
  1832. if (state.tag !== null || state.anchor !== null) {
  1833. throwError(state, 'alias node should not have any properties');
  1834. }
  1835. } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
  1836. hasContent = true;
  1837. if (state.tag === null) {
  1838. state.tag = '?';
  1839. }
  1840. }
  1841. if (state.anchor !== null) {
  1842. state.anchorMap[state.anchor] = state.result;
  1843. }
  1844. }
  1845. } else if (indentStatus === 0) {
  1846. // Special case: block sequences are allowed to have same indentation level as the parent.
  1847. // http://www.yaml.org/spec/1.2/spec.html#id2799784
  1848. hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
  1849. }
  1850. }
  1851. if (state.tag !== null && state.tag !== '!') {
  1852. if (state.tag === '?') {
  1853. for (typeIndex = 0, typeQuantity = state.implicitTypes.length;
  1854. typeIndex < typeQuantity;
  1855. typeIndex += 1) {
  1856. type = state.implicitTypes[typeIndex];
  1857. // Implicit resolving is not allowed for non-scalar types, and '?'
  1858. // non-specific tag is only assigned to plain scalars. So, it isn't
  1859. // needed to check for 'kind' conformity.
  1860. if (type.resolve(state.result)) { // `state.result` updated in resolver if matched
  1861. state.result = type.construct(state.result);
  1862. state.tag = type.tag;
  1863. if (state.anchor !== null) {
  1864. state.anchorMap[state.anchor] = state.result;
  1865. }
  1866. break;
  1867. }
  1868. }
  1869. } else if (_hasOwnProperty.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
  1870. type = state.typeMap[state.kind || 'fallback'][state.tag];
  1871. if (state.result !== null && type.kind !== state.kind) {
  1872. throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
  1873. }
  1874. if (!type.resolve(state.result)) { // `state.result` updated in resolver if matched
  1875. throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
  1876. } else {
  1877. state.result = type.construct(state.result);
  1878. if (state.anchor !== null) {
  1879. state.anchorMap[state.anchor] = state.result;
  1880. }
  1881. }
  1882. } else {
  1883. throwError(state, 'unknown tag !<' + state.tag + '>');
  1884. }
  1885. }
  1886. if (state.listener !== null) {
  1887. state.listener('close', state);
  1888. }
  1889. return state.tag !== null || state.anchor !== null || hasContent;
  1890. }
  1891. function readDocument(state) {
  1892. var documentStart = state.position,
  1893. _position,
  1894. directiveName,
  1895. directiveArgs,
  1896. hasDirectives = false,
  1897. ch;
  1898. state.version = null;
  1899. state.checkLineBreaks = state.legacy;
  1900. state.tagMap = {};
  1901. state.anchorMap = {};
  1902. while ((ch = state.input.charCodeAt(state.position)) !== 0) {
  1903. skipSeparationSpace(state, true, -1);
  1904. ch = state.input.charCodeAt(state.position);
  1905. if (state.lineIndent > 0 || ch !== 0x25/* % */) {
  1906. break;
  1907. }
  1908. hasDirectives = true;
  1909. ch = state.input.charCodeAt(++state.position);
  1910. _position = state.position;
  1911. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  1912. ch = state.input.charCodeAt(++state.position);
  1913. }
  1914. directiveName = state.input.slice(_position, state.position);
  1915. directiveArgs = [];
  1916. if (directiveName.length < 1) {
  1917. throwError(state, 'directive name must not be less than one character in length');
  1918. }
  1919. while (ch !== 0) {
  1920. while (is_WHITE_SPACE(ch)) {
  1921. ch = state.input.charCodeAt(++state.position);
  1922. }
  1923. if (ch === 0x23/* # */) {
  1924. do { ch = state.input.charCodeAt(++state.position); }
  1925. while (ch !== 0 && !is_EOL(ch));
  1926. break;
  1927. }
  1928. if (is_EOL(ch)) break;
  1929. _position = state.position;
  1930. while (ch !== 0 && !is_WS_OR_EOL(ch)) {
  1931. ch = state.input.charCodeAt(++state.position);
  1932. }
  1933. directiveArgs.push(state.input.slice(_position, state.position));
  1934. }
  1935. if (ch !== 0) readLineBreak(state);
  1936. if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
  1937. directiveHandlers[directiveName](state, directiveName, directiveArgs);
  1938. } else {
  1939. throwWarning(state, 'unknown document directive "' + directiveName + '"');
  1940. }
  1941. }
  1942. skipSeparationSpace(state, true, -1);
  1943. if (state.lineIndent === 0 &&
  1944. state.input.charCodeAt(state.position) === 0x2D/* - */ &&
  1945. state.input.charCodeAt(state.position + 1) === 0x2D/* - */ &&
  1946. state.input.charCodeAt(state.position + 2) === 0x2D/* - */) {
  1947. state.position += 3;
  1948. skipSeparationSpace(state, true, -1);
  1949. } else if (hasDirectives) {
  1950. throwError(state, 'directives end mark is expected');
  1951. }
  1952. composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
  1953. skipSeparationSpace(state, true, -1);
  1954. if (state.checkLineBreaks &&
  1955. PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
  1956. throwWarning(state, 'non-ASCII line breaks are interpreted as content');
  1957. }
  1958. state.documents.push(state.result);
  1959. if (state.position === state.lineStart && testDocumentSeparator(state)) {
  1960. if (state.input.charCodeAt(state.position) === 0x2E/* . */) {
  1961. state.position += 3;
  1962. skipSeparationSpace(state, true, -1);
  1963. }
  1964. return;
  1965. }
  1966. if (state.position < (state.length - 1)) {
  1967. throwError(state, 'end of the stream or a document separator is expected');
  1968. } else {
  1969. return;
  1970. }
  1971. }
  1972. function loadDocuments(input, options) {
  1973. input = String(input);
  1974. options = options || {};
  1975. if (input.length !== 0) {
  1976. // Add tailing `\n` if not exists
  1977. if (input.charCodeAt(input.length - 1) !== 0x0A/* LF */ &&
  1978. input.charCodeAt(input.length - 1) !== 0x0D/* CR */) {
  1979. input += '\n';
  1980. }
  1981. // Strip BOM
  1982. if (input.charCodeAt(0) === 0xFEFF) {
  1983. input = input.slice(1);
  1984. }
  1985. }
  1986. var state = new State(input, options);
  1987. // Use 0 as string terminator. That significantly simplifies bounds check.
  1988. state.input += '\0';
  1989. while (state.input.charCodeAt(state.position) === 0x20/* Space */) {
  1990. state.lineIndent += 1;
  1991. state.position += 1;
  1992. }
  1993. while (state.position < (state.length - 1)) {
  1994. readDocument(state);
  1995. }
  1996. return state.documents;
  1997. }
  1998. function loadAll(input, iterator, options) {
  1999. var documents = loadDocuments(input, options), index, length;
  2000. for (index = 0, length = documents.length; index < length; index += 1) {
  2001. iterator(documents[index]);
  2002. }
  2003. }
  2004. function load(input, options) {
  2005. var documents = loadDocuments(input, options);
  2006. if (documents.length === 0) {
  2007. /*eslint-disable no-undefined*/
  2008. return undefined;
  2009. } else if (documents.length === 1) {
  2010. return documents[0];
  2011. }
  2012. throw new YAMLException('expected a single document in the stream, but found more');
  2013. }
  2014. function safeLoadAll(input, output, options) {
  2015. loadAll(input, output, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
  2016. }
  2017. function safeLoad(input, options) {
  2018. return load(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
  2019. }
  2020. module.exports.loadAll = loadAll;
  2021. module.exports.load = load;
  2022. module.exports.safeLoadAll = safeLoadAll;
  2023. module.exports.safeLoad = safeLoad;
  2024. },{"./common":2,"./exception":4,"./mark":6,"./schema/default_full":9,"./schema/default_safe":10}],6:[function(require,module,exports){
  2025. 'use strict';
  2026. var common = require('./common');
  2027. function Mark(name, buffer, position, line, column) {
  2028. this.name = name;
  2029. this.buffer = buffer;
  2030. this.position = position;
  2031. this.line = line;
  2032. this.column = column;
  2033. }
  2034. Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {
  2035. var head, start, tail, end, snippet;
  2036. if (!this.buffer) return null;
  2037. indent = indent || 4;
  2038. maxLength = maxLength || 75;
  2039. head = '';
  2040. start = this.position;
  2041. while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
  2042. start -= 1;
  2043. if (this.position - start > (maxLength / 2 - 1)) {
  2044. head = ' ... ';
  2045. start += 5;
  2046. break;
  2047. }
  2048. }
  2049. tail = '';
  2050. end = this.position;
  2051. while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
  2052. end += 1;
  2053. if (end - this.position > (maxLength / 2 - 1)) {
  2054. tail = ' ... ';
  2055. end -= 5;
  2056. break;
  2057. }
  2058. }
  2059. snippet = this.buffer.slice(start, end);
  2060. return common.repeat(' ', indent) + head + snippet + tail + '\n' +
  2061. common.repeat(' ', indent + this.position - start + head.length) + '^';
  2062. };
  2063. Mark.prototype.toString = function toString(compact) {
  2064. var snippet, where = '';
  2065. if (this.name) {
  2066. where += 'in "' + this.name + '" ';
  2067. }
  2068. where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
  2069. if (!compact) {
  2070. snippet = this.getSnippet();
  2071. if (snippet) {
  2072. where += ':\n' + snippet;
  2073. }
  2074. }
  2075. return where;
  2076. };
  2077. module.exports = Mark;
  2078. },{"./common":2}],7:[function(require,module,exports){
  2079. 'use strict';
  2080. /*eslint-disable max-len*/
  2081. var common = require('./common');
  2082. var YAMLException = require('./exception');
  2083. var Type = require('./type');
  2084. function compileList(schema, name, result) {
  2085. var exclude = [];
  2086. schema.include.forEach(function (includedSchema) {
  2087. result = compileList(includedSchema, name, result);
  2088. });
  2089. schema[name].forEach(function (currentType) {
  2090. result.forEach(function (previousType, previousIndex) {
  2091. if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) {
  2092. exclude.push(previousIndex);
  2093. }
  2094. });
  2095. result.push(currentType);
  2096. });
  2097. return result.filter(function (type, index) {
  2098. return exclude.indexOf(index) === -1;
  2099. });
  2100. }
  2101. function compileMap(/* lists... */) {
  2102. var result = {
  2103. scalar: {},
  2104. sequence: {},
  2105. mapping: {},
  2106. fallback: {}
  2107. }, index, length;
  2108. function collectType(type) {
  2109. result[type.kind][type.tag] = result['fallback'][type.tag] = type;
  2110. }
  2111. for (index = 0, length = arguments.length; index < length; index += 1) {
  2112. arguments[index].forEach(collectType);
  2113. }
  2114. return result;
  2115. }
  2116. function Schema(definition) {
  2117. this.include = definition.include || [];
  2118. this.implicit = definition.implicit || [];
  2119. this.explicit = definition.explicit || [];
  2120. this.implicit.forEach(function (type) {
  2121. if (type.loadKind && type.loadKind !== 'scalar') {
  2122. throw new YAMLException('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
  2123. }
  2124. });
  2125. this.compiledImplicit = compileList(this, 'implicit', []);
  2126. this.compiledExplicit = compileList(this, 'explicit', []);
  2127. this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
  2128. }
  2129. Schema.DEFAULT = null;
  2130. Schema.create = function createSchema() {
  2131. var schemas, types;
  2132. switch (arguments.length) {
  2133. case 1:
  2134. schemas = Schema.DEFAULT;
  2135. types = arguments[0];
  2136. break;
  2137. case 2:
  2138. schemas = arguments[0];
  2139. types = arguments[1];
  2140. break;
  2141. default:
  2142. throw new YAMLException('Wrong number of arguments for Schema.create function');
  2143. }
  2144. schemas = common.toArray(schemas);
  2145. types = common.toArray(types);
  2146. if (!schemas.every(function (schema) { return schema instanceof Schema; })) {
  2147. throw new YAMLException('Specified list of super schemas (or a single Schema object) contains a non-Schema object.');
  2148. }
  2149. if (!types.every(function (type) { return type instanceof Type; })) {
  2150. throw new YAMLException('Specified list of YAML types (or a single Type object) contains a non-Type object.');
  2151. }
  2152. return new Schema({
  2153. include: schemas,
  2154. explicit: types
  2155. });
  2156. };
  2157. module.exports = Schema;
  2158. },{"./common":2,"./exception":4,"./type":13}],8:[function(require,module,exports){
  2159. // Standard YAML's Core schema.
  2160. // http://www.yaml.org/spec/1.2/spec.html#id2804923
  2161. //
  2162. // NOTE: JS-YAML does not support schema-specific tag resolution restrictions.
  2163. // So, Core schema has no distinctions from JSON schema is JS-YAML.
  2164. 'use strict';
  2165. var Schema = require('../schema');
  2166. module.exports = new Schema({
  2167. include: [
  2168. require('./json')
  2169. ]
  2170. });
  2171. },{"../schema":7,"./json":12}],9:[function(require,module,exports){
  2172. // JS-YAML's default schema for `load` function.
  2173. // It is not described in the YAML specification.
  2174. //
  2175. // This schema is based on JS-YAML's default safe schema and includes
  2176. // JavaScript-specific types: !!js/undefined, !!js/regexp and !!js/function.
  2177. //
  2178. // Also this schema is used as default base schema at `Schema.create` function.
  2179. 'use strict';
  2180. var Schema = require('../schema');
  2181. module.exports = Schema.DEFAULT = new Schema({
  2182. include: [
  2183. require('./default_safe')
  2184. ],
  2185. explicit: [
  2186. require('../type/js/undefined'),
  2187. require('../type/js/regexp'),
  2188. require('../type/js/function')
  2189. ]
  2190. });
  2191. },{"../schema":7,"../type/js/function":18,"../type/js/regexp":19,"../type/js/undefined":20,"./default_safe":10}],10:[function(require,module,exports){
  2192. // JS-YAML's default schema for `safeLoad` function.
  2193. // It is not described in the YAML specification.
  2194. //
  2195. // This schema is based on standard YAML's Core schema and includes most of
  2196. // extra types described at YAML tag repository. (http://yaml.org/type/)
  2197. 'use strict';
  2198. var Schema = require('../schema');
  2199. module.exports = new Schema({
  2200. include: [
  2201. require('./core')
  2202. ],
  2203. implicit: [
  2204. require('../type/timestamp'),
  2205. require('../type/merge')
  2206. ],
  2207. explicit: [
  2208. require('../type/binary'),
  2209. require('../type/omap'),
  2210. require('../type/pairs'),
  2211. require('../type/set')
  2212. ]
  2213. });
  2214. },{"../schema":7,"../type/binary":14,"../type/merge":22,"../type/omap":24,"../type/pairs":25,"../type/set":27,"../type/timestamp":29,"./core":8}],11:[function(require,module,exports){
  2215. // Standard YAML's Failsafe schema.
  2216. // http://www.yaml.org/spec/1.2/spec.html#id2802346
  2217. 'use strict';
  2218. var Schema = require('../schema');
  2219. module.exports = new Schema({
  2220. explicit: [
  2221. require('../type/str'),
  2222. require('../type/seq'),
  2223. require('../type/map')
  2224. ]
  2225. });
  2226. },{"../schema":7,"../type/map":21,"../type/seq":26,"../type/str":28}],12:[function(require,module,exports){
  2227. // Standard YAML's JSON schema.
  2228. // http://www.yaml.org/spec/1.2/spec.html#id2803231
  2229. //
  2230. // NOTE: JS-YAML does not support schema-specific tag resolution restrictions.
  2231. // So, this schema is not such strict as defined in the YAML specification.
  2232. // It allows numbers in binary notaion, use `Null` and `NULL` as `null`, etc.
  2233. 'use strict';
  2234. var Schema = require('../schema');
  2235. module.exports = new Schema({
  2236. include: [
  2237. require('./failsafe')
  2238. ],
  2239. implicit: [
  2240. require('../type/null'),
  2241. require('../type/bool'),
  2242. require('../type/int'),
  2243. require('../type/float')
  2244. ]
  2245. });
  2246. },{"../schema":7,"../type/bool":15,"../type/float":16,"../type/int":17,"../type/null":23,"./failsafe":11}],13:[function(require,module,exports){
  2247. 'use strict';
  2248. var YAMLException = require('./exception');
  2249. var TYPE_CONSTRUCTOR_OPTIONS = [
  2250. 'kind',
  2251. 'resolve',
  2252. 'construct',
  2253. 'instanceOf',
  2254. 'predicate',
  2255. 'represent',
  2256. 'defaultStyle',
  2257. 'styleAliases'
  2258. ];
  2259. var YAML_NODE_KINDS = [
  2260. 'scalar',
  2261. 'sequence',
  2262. 'mapping'
  2263. ];
  2264. function compileStyleAliases(map) {
  2265. var result = {};
  2266. if (map !== null) {
  2267. Object.keys(map).forEach(function (style) {
  2268. map[style].forEach(function (alias) {
  2269. result[String(alias)] = style;
  2270. });
  2271. });
  2272. }
  2273. return result;
  2274. }
  2275. function Type(tag, options) {
  2276. options = options || {};
  2277. Object.keys(options).forEach(function (name) {
  2278. if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
  2279. throw new YAMLException('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
  2280. }
  2281. });
  2282. // TODO: Add tag format check.
  2283. this.tag = tag;
  2284. this.kind = options['kind'] || null;
  2285. this.resolve = options['resolve'] || function () { return true; };
  2286. this.construct = options['construct'] || function (data) { return data; };
  2287. this.instanceOf = options['instanceOf'] || null;
  2288. this.predicate = options['predicate'] || null;
  2289. this.represent = options['represent'] || null;
  2290. this.defaultStyle = options['defaultStyle'] || null;
  2291. this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
  2292. if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
  2293. throw new YAMLException('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
  2294. }
  2295. }
  2296. module.exports = Type;
  2297. },{"./exception":4}],14:[function(require,module,exports){
  2298. 'use strict';
  2299. /*eslint-disable no-bitwise*/
  2300. var NodeBuffer;
  2301. try {
  2302. // A trick for browserified version, to not include `Buffer` shim
  2303. var _require = require;
  2304. NodeBuffer = _require('buffer').Buffer;
  2305. } catch (__) {}
  2306. var Type = require('../type');
  2307. // [ 64, 65, 66 ] -> [ padding, CR, LF ]
  2308. var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
  2309. function resolveYamlBinary(data) {
  2310. if (data === null) return false;
  2311. var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
  2312. // Convert one by one.
  2313. for (idx = 0; idx < max; idx++) {
  2314. code = map.indexOf(data.charAt(idx));
  2315. // Skip CR/LF
  2316. if (code > 64) continue;
  2317. // Fail on illegal characters
  2318. if (code < 0) return false;
  2319. bitlen += 6;
  2320. }
  2321. // If there are any bits left, source was corrupted
  2322. return (bitlen % 8) === 0;
  2323. }
  2324. function constructYamlBinary(data) {
  2325. var idx, tailbits,
  2326. input = data.replace(/[\r\n=]/g, ''), // remove CR/LF & padding to simplify scan
  2327. max = input.length,
  2328. map = BASE64_MAP,
  2329. bits = 0,
  2330. result = [];
  2331. // Collect by 6*4 bits (3 bytes)
  2332. for (idx = 0; idx < max; idx++) {
  2333. if ((idx % 4 === 0) && idx) {
  2334. result.push((bits >> 16) & 0xFF);
  2335. result.push((bits >> 8) & 0xFF);
  2336. result.push(bits & 0xFF);
  2337. }
  2338. bits = (bits << 6) | map.indexOf(input.charAt(idx));
  2339. }
  2340. // Dump tail
  2341. tailbits = (max % 4) * 6;
  2342. if (tailbits === 0) {
  2343. result.push((bits >> 16) & 0xFF);
  2344. result.push((bits >> 8) & 0xFF);
  2345. result.push(bits & 0xFF);
  2346. } else if (tailbits === 18) {
  2347. result.push((bits >> 10) & 0xFF);
  2348. result.push((bits >> 2) & 0xFF);
  2349. } else if (tailbits === 12) {
  2350. result.push((bits >> 4) & 0xFF);
  2351. }
  2352. // Wrap into Buffer for NodeJS and leave Array for browser
  2353. if (NodeBuffer) return new NodeBuffer(result);
  2354. return result;
  2355. }
  2356. function representYamlBinary(object /*, style*/) {
  2357. var result = '', bits = 0, idx, tail,
  2358. max = object.length,
  2359. map = BASE64_MAP;
  2360. // Convert every three bytes to 4 ASCII characters.
  2361. for (idx = 0; idx < max; idx++) {
  2362. if ((idx % 3 === 0) && idx) {
  2363. result += map[(bits >> 18) & 0x3F];
  2364. result += map[(bits >> 12) & 0x3F];
  2365. result += map[(bits >> 6) & 0x3F];
  2366. result += map[bits & 0x3F];
  2367. }
  2368. bits = (bits << 8) + object[idx];
  2369. }
  2370. // Dump tail
  2371. tail = max % 3;
  2372. if (tail === 0) {
  2373. result += map[(bits >> 18) & 0x3F];
  2374. result += map[(bits >> 12) & 0x3F];
  2375. result += map[(bits >> 6) & 0x3F];
  2376. result += map[bits & 0x3F];
  2377. } else if (tail === 2) {
  2378. result += map[(bits >> 10) & 0x3F];
  2379. result += map[(bits >> 4) & 0x3F];
  2380. result += map[(bits << 2) & 0x3F];
  2381. result += map[64];
  2382. } else if (tail === 1) {
  2383. result += map[(bits >> 2) & 0x3F];
  2384. result += map[(bits << 4) & 0x3F];
  2385. result += map[64];
  2386. result += map[64];
  2387. }
  2388. return result;
  2389. }
  2390. function isBinary(object) {
  2391. return NodeBuffer && NodeBuffer.isBuffer(object);
  2392. }
  2393. module.exports = new Type('tag:yaml.org,2002:binary', {
  2394. kind: 'scalar',
  2395. resolve: resolveYamlBinary,
  2396. construct: constructYamlBinary,
  2397. predicate: isBinary,
  2398. represent: representYamlBinary
  2399. });
  2400. },{"../type":13}],15:[function(require,module,exports){
  2401. 'use strict';
  2402. var Type = require('../type');
  2403. function resolveYamlBoolean(data) {
  2404. if (data === null) return false;
  2405. var max = data.length;
  2406. return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
  2407. (max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
  2408. }
  2409. function constructYamlBoolean(data) {
  2410. return data === 'true' ||
  2411. data === 'True' ||
  2412. data === 'TRUE';
  2413. }
  2414. function isBoolean(object) {
  2415. return Object.prototype.toString.call(object) === '[object Boolean]';
  2416. }
  2417. module.exports = new Type('tag:yaml.org,2002:bool', {
  2418. kind: 'scalar',
  2419. resolve: resolveYamlBoolean,
  2420. construct: constructYamlBoolean,
  2421. predicate: isBoolean,
  2422. represent: {
  2423. lowercase: function (object) { return object ? 'true' : 'false'; },
  2424. uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
  2425. camelcase: function (object) { return object ? 'True' : 'False'; }
  2426. },
  2427. defaultStyle: 'lowercase'
  2428. });
  2429. },{"../type":13}],16:[function(require,module,exports){
  2430. 'use strict';
  2431. var common = require('../common');
  2432. var Type = require('../type');
  2433. var YAML_FLOAT_PATTERN = new RegExp(
  2434. '^(?:[-+]?(?:[0-9][0-9_]*)\\.[0-9_]*(?:[eE][-+][0-9]+)?' +
  2435. '|\\.[0-9_]+(?:[eE][-+][0-9]+)?' +
  2436. '|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' +
  2437. '|[-+]?\\.(?:inf|Inf|INF)' +
  2438. '|\\.(?:nan|NaN|NAN))$');
  2439. function resolveYamlFloat(data) {
  2440. if (data === null) return false;
  2441. if (!YAML_FLOAT_PATTERN.test(data)) return false;
  2442. return true;
  2443. }
  2444. function constructYamlFloat(data) {
  2445. var value, sign, base, digits;
  2446. value = data.replace(/_/g, '').toLowerCase();
  2447. sign = value[0] === '-' ? -1 : 1;
  2448. digits = [];
  2449. if ('+-'.indexOf(value[0]) >= 0) {
  2450. value = value.slice(1);
  2451. }
  2452. if (value === '.inf') {
  2453. return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
  2454. } else if (value === '.nan') {
  2455. return NaN;
  2456. } else if (value.indexOf(':') >= 0) {
  2457. value.split(':').forEach(function (v) {
  2458. digits.unshift(parseFloat(v, 10));
  2459. });
  2460. value = 0.0;
  2461. base = 1;
  2462. digits.forEach(function (d) {
  2463. value += d * base;
  2464. base *= 60;
  2465. });
  2466. return sign * value;
  2467. }
  2468. return sign * parseFloat(value, 10);
  2469. }
  2470. var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
  2471. function representYamlFloat(object, style) {
  2472. var res;
  2473. if (isNaN(object)) {
  2474. switch (style) {
  2475. case 'lowercase': return '.nan';
  2476. case 'uppercase': return '.NAN';
  2477. case 'camelcase': return '.NaN';
  2478. }
  2479. } else if (Number.POSITIVE_INFINITY === object) {
  2480. switch (style) {
  2481. case 'lowercase': return '.inf';
  2482. case 'uppercase': return '.INF';
  2483. case 'camelcase': return '.Inf';
  2484. }
  2485. } else if (Number.NEGATIVE_INFINITY === object) {
  2486. switch (style) {
  2487. case 'lowercase': return '-.inf';
  2488. case 'uppercase': return '-.INF';
  2489. case 'camelcase': return '-.Inf';
  2490. }
  2491. } else if (common.isNegativeZero(object)) {
  2492. return '-0.0';
  2493. }
  2494. res = object.toString(10);
  2495. // JS stringifier can build scientific format without dots: 5e-100,
  2496. // while YAML requres dot: 5.e-100. Fix it with simple hack
  2497. return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
  2498. }
  2499. function isFloat(object) {
  2500. return (Object.prototype.toString.call(object) === '[object Number]') &&
  2501. (object % 1 !== 0 || common.isNegativeZero(object));
  2502. }
  2503. module.exports = new Type('tag:yaml.org,2002:float', {
  2504. kind: 'scalar',
  2505. resolve: resolveYamlFloat,
  2506. construct: constructYamlFloat,
  2507. predicate: isFloat,
  2508. represent: representYamlFloat,
  2509. defaultStyle: 'lowercase'
  2510. });
  2511. },{"../common":2,"../type":13}],17:[function(require,module,exports){
  2512. 'use strict';
  2513. var common = require('../common');
  2514. var Type = require('../type');
  2515. function isHexCode(c) {
  2516. return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) ||
  2517. ((0x41/* A */ <= c) && (c <= 0x46/* F */)) ||
  2518. ((0x61/* a */ <= c) && (c <= 0x66/* f */));
  2519. }
  2520. function isOctCode(c) {
  2521. return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */));
  2522. }
  2523. function isDecCode(c) {
  2524. return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */));
  2525. }
  2526. function resolveYamlInteger(data) {
  2527. if (data === null) return false;
  2528. var max = data.length,
  2529. index = 0,
  2530. hasDigits = false,
  2531. ch;
  2532. if (!max) return false;
  2533. ch = data[index];
  2534. // sign
  2535. if (ch === '-' || ch === '+') {
  2536. ch = data[++index];
  2537. }
  2538. if (ch === '0') {
  2539. // 0
  2540. if (index + 1 === max) return true;
  2541. ch = data[++index];
  2542. // base 2, base 8, base 16
  2543. if (ch === 'b') {
  2544. // base 2
  2545. index++;
  2546. for (; index < max; index++) {
  2547. ch = data[index];
  2548. if (ch === '_') continue;
  2549. if (ch !== '0' && ch !== '1') return false;
  2550. hasDigits = true;
  2551. }
  2552. return hasDigits;
  2553. }
  2554. if (ch === 'x') {
  2555. // base 16
  2556. index++;
  2557. for (; index < max; index++) {
  2558. ch = data[index];
  2559. if (ch === '_') continue;
  2560. if (!isHexCode(data.charCodeAt(index))) return false;
  2561. hasDigits = true;
  2562. }
  2563. return hasDigits;
  2564. }
  2565. // base 8
  2566. for (; index < max; index++) {
  2567. ch = data[index];
  2568. if (ch === '_') continue;
  2569. if (!isOctCode(data.charCodeAt(index))) return false;
  2570. hasDigits = true;
  2571. }
  2572. return hasDigits;
  2573. }
  2574. // base 10 (except 0) or base 60
  2575. for (; index < max; index++) {
  2576. ch = data[index];
  2577. if (ch === '_') continue;
  2578. if (ch === ':') break;
  2579. if (!isDecCode(data.charCodeAt(index))) {
  2580. return false;
  2581. }
  2582. hasDigits = true;
  2583. }
  2584. if (!hasDigits) return false;
  2585. // if !base60 - done;
  2586. if (ch !== ':') return true;
  2587. // base60 almost not used, no needs to optimize
  2588. return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
  2589. }
  2590. function constructYamlInteger(data) {
  2591. var value = data, sign = 1, ch, base, digits = [];
  2592. if (value.indexOf('_') !== -1) {
  2593. value = value.replace(/_/g, '');
  2594. }
  2595. ch = value[0];
  2596. if (ch === '-' || ch === '+') {
  2597. if (ch === '-') sign = -1;
  2598. value = value.slice(1);
  2599. ch = value[0];
  2600. }
  2601. if (value === '0') return 0;
  2602. if (ch === '0') {
  2603. if (value[1] === 'b') return sign * parseInt(value.slice(2), 2);
  2604. if (value[1] === 'x') return sign * parseInt(value, 16);
  2605. return sign * parseInt(value, 8);
  2606. }
  2607. if (value.indexOf(':') !== -1) {
  2608. value.split(':').forEach(function (v) {
  2609. digits.unshift(parseInt(v, 10));
  2610. });
  2611. value = 0;
  2612. base = 1;
  2613. digits.forEach(function (d) {
  2614. value += (d * base);
  2615. base *= 60;
  2616. });
  2617. return sign * value;
  2618. }
  2619. return sign * parseInt(value, 10);
  2620. }
  2621. function isInteger(object) {
  2622. return (Object.prototype.toString.call(object)) === '[object Number]' &&
  2623. (object % 1 === 0 && !common.isNegativeZero(object));
  2624. }
  2625. module.exports = new Type('tag:yaml.org,2002:int', {
  2626. kind: 'scalar',
  2627. resolve: resolveYamlInteger,
  2628. construct: constructYamlInteger,
  2629. predicate: isInteger,
  2630. represent: {
  2631. binary: function (object) { return '0b' + object.toString(2); },
  2632. octal: function (object) { return '0' + object.toString(8); },
  2633. decimal: function (object) { return object.toString(10); },
  2634. hexadecimal: function (object) { return '0x' + object.toString(16).toUpperCase(); }
  2635. },
  2636. defaultStyle: 'decimal',
  2637. styleAliases: {
  2638. binary: [ 2, 'bin' ],
  2639. octal: [ 8, 'oct' ],
  2640. decimal: [ 10, 'dec' ],
  2641. hexadecimal: [ 16, 'hex' ]
  2642. }
  2643. });
  2644. },{"../common":2,"../type":13}],18:[function(require,module,exports){
  2645. 'use strict';
  2646. var esprima;
  2647. // Browserified version does not have esprima
  2648. //
  2649. // 1. For node.js just require module as deps
  2650. // 2. For browser try to require mudule via external AMD system.
  2651. // If not found - try to fallback to window.esprima. If not
  2652. // found too - then fail to parse.
  2653. //
  2654. try {
  2655. // workaround to exclude package from browserify list.
  2656. var _require = require;
  2657. esprima = _require('esprima');
  2658. } catch (_) {
  2659. /*global window */
  2660. if (typeof window !== 'undefined') esprima = window.esprima;
  2661. }
  2662. var Type = require('../../type');
  2663. function resolveJavascriptFunction(data) {
  2664. if (data === null) return false;
  2665. try {
  2666. var source = '(' + data + ')',
  2667. ast = esprima.parse(source, { range: true });
  2668. if (ast.type !== 'Program' ||
  2669. ast.body.length !== 1 ||
  2670. ast.body[0].type !== 'ExpressionStatement' ||
  2671. ast.body[0].expression.type !== 'FunctionExpression') {
  2672. return false;
  2673. }
  2674. return true;
  2675. } catch (err) {
  2676. return false;
  2677. }
  2678. }
  2679. function constructJavascriptFunction(data) {
  2680. /*jslint evil:true*/
  2681. var source = '(' + data + ')',
  2682. ast = esprima.parse(source, { range: true }),
  2683. params = [],
  2684. body;
  2685. if (ast.type !== 'Program' ||
  2686. ast.body.length !== 1 ||
  2687. ast.body[0].type !== 'ExpressionStatement' ||
  2688. ast.body[0].expression.type !== 'FunctionExpression') {
  2689. throw new Error('Failed to resolve function');
  2690. }
  2691. ast.body[0].expression.params.forEach(function (param) {
  2692. params.push(param.name);
  2693. });
  2694. body = ast.body[0].expression.body.range;
  2695. // Esprima's ranges include the first '{' and the last '}' characters on
  2696. // function expressions. So cut them out.
  2697. /*eslint-disable no-new-func*/
  2698. return new Function(params, source.slice(body[0] + 1, body[1] - 1));
  2699. }
  2700. function representJavascriptFunction(object /*, style*/) {
  2701. return object.toString();
  2702. }
  2703. function isFunction(object) {
  2704. return Object.prototype.toString.call(object) === '[object Function]';
  2705. }
  2706. module.exports = new Type('tag:yaml.org,2002:js/function', {
  2707. kind: 'scalar',
  2708. resolve: resolveJavascriptFunction,
  2709. construct: constructJavascriptFunction,
  2710. predicate: isFunction,
  2711. represent: representJavascriptFunction
  2712. });
  2713. },{"../../type":13}],19:[function(require,module,exports){
  2714. 'use strict';
  2715. var Type = require('../../type');
  2716. function resolveJavascriptRegExp(data) {
  2717. if (data === null) return false;
  2718. if (data.length === 0) return false;
  2719. var regexp = data,
  2720. tail = /\/([gim]*)$/.exec(data),
  2721. modifiers = '';
  2722. // if regexp starts with '/' it can have modifiers and must be properly closed
  2723. // `/foo/gim` - modifiers tail can be maximum 3 chars
  2724. if (regexp[0] === '/') {
  2725. if (tail) modifiers = tail[1];
  2726. if (modifiers.length > 3) return false;
  2727. // if expression starts with /, is should be properly terminated
  2728. if (regexp[regexp.length - modifiers.length - 1] !== '/') return false;
  2729. }
  2730. return true;
  2731. }
  2732. function constructJavascriptRegExp(data) {
  2733. var regexp = data,
  2734. tail = /\/([gim]*)$/.exec(data),
  2735. modifiers = '';
  2736. // `/foo/gim` - tail can be maximum 4 chars
  2737. if (regexp[0] === '/') {
  2738. if (tail) modifiers = tail[1];
  2739. regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
  2740. }
  2741. return new RegExp(regexp, modifiers);
  2742. }
  2743. function representJavascriptRegExp(object /*, style*/) {
  2744. var result = '/' + object.source + '/';
  2745. if (object.global) result += 'g';
  2746. if (object.multiline) result += 'm';
  2747. if (object.ignoreCase) result += 'i';
  2748. return result;
  2749. }
  2750. function isRegExp(object) {
  2751. return Object.prototype.toString.call(object) === '[object RegExp]';
  2752. }
  2753. module.exports = new Type('tag:yaml.org,2002:js/regexp', {
  2754. kind: 'scalar',
  2755. resolve: resolveJavascriptRegExp,
  2756. construct: constructJavascriptRegExp,
  2757. predicate: isRegExp,
  2758. represent: representJavascriptRegExp
  2759. });
  2760. },{"../../type":13}],20:[function(require,module,exports){
  2761. 'use strict';
  2762. var Type = require('../../type');
  2763. function resolveJavascriptUndefined() {
  2764. return true;
  2765. }
  2766. function constructJavascriptUndefined() {
  2767. /*eslint-disable no-undefined*/
  2768. return undefined;
  2769. }
  2770. function representJavascriptUndefined() {
  2771. return '';
  2772. }
  2773. function isUndefined(object) {
  2774. return typeof object === 'undefined';
  2775. }
  2776. module.exports = new Type('tag:yaml.org,2002:js/undefined', {
  2777. kind: 'scalar',
  2778. resolve: resolveJavascriptUndefined,
  2779. construct: constructJavascriptUndefined,
  2780. predicate: isUndefined,
  2781. represent: representJavascriptUndefined
  2782. });
  2783. },{"../../type":13}],21:[function(require,module,exports){
  2784. 'use strict';
  2785. var Type = require('../type');
  2786. module.exports = new Type('tag:yaml.org,2002:map', {
  2787. kind: 'mapping',
  2788. construct: function (data) { return data !== null ? data : {}; }
  2789. });
  2790. },{"../type":13}],22:[function(require,module,exports){
  2791. 'use strict';
  2792. var Type = require('../type');
  2793. function resolveYamlMerge(data) {
  2794. return data === '<<' || data === null;
  2795. }
  2796. module.exports = new Type('tag:yaml.org,2002:merge', {
  2797. kind: 'scalar',
  2798. resolve: resolveYamlMerge
  2799. });
  2800. },{"../type":13}],23:[function(require,module,exports){
  2801. 'use strict';
  2802. var Type = require('../type');
  2803. function resolveYamlNull(data) {
  2804. if (data === null) return true;
  2805. var max = data.length;
  2806. return (max === 1 && data === '~') ||
  2807. (max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'));
  2808. }
  2809. function constructYamlNull() {
  2810. return null;
  2811. }
  2812. function isNull(object) {
  2813. return object === null;
  2814. }
  2815. module.exports = new Type('tag:yaml.org,2002:null', {
  2816. kind: 'scalar',
  2817. resolve: resolveYamlNull,
  2818. construct: constructYamlNull,
  2819. predicate: isNull,
  2820. represent: {
  2821. canonical: function () { return '~'; },
  2822. lowercase: function () { return 'null'; },
  2823. uppercase: function () { return 'NULL'; },
  2824. camelcase: function () { return 'Null'; }
  2825. },
  2826. defaultStyle: 'lowercase'
  2827. });
  2828. },{"../type":13}],24:[function(require,module,exports){
  2829. 'use strict';
  2830. var Type = require('../type');
  2831. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  2832. var _toString = Object.prototype.toString;
  2833. function resolveYamlOmap(data) {
  2834. if (data === null) return true;
  2835. var objectKeys = [], index, length, pair, pairKey, pairHasKey,
  2836. object = data;
  2837. for (index = 0, length = object.length; index < length; index += 1) {
  2838. pair = object[index];
  2839. pairHasKey = false;
  2840. if (_toString.call(pair) !== '[object Object]') return false;
  2841. for (pairKey in pair) {
  2842. if (_hasOwnProperty.call(pair, pairKey)) {
  2843. if (!pairHasKey) pairHasKey = true;
  2844. else return false;
  2845. }
  2846. }
  2847. if (!pairHasKey) return false;
  2848. if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
  2849. else return false;
  2850. }
  2851. return true;
  2852. }
  2853. function constructYamlOmap(data) {
  2854. return data !== null ? data : [];
  2855. }
  2856. module.exports = new Type('tag:yaml.org,2002:omap', {
  2857. kind: 'sequence',
  2858. resolve: resolveYamlOmap,
  2859. construct: constructYamlOmap
  2860. });
  2861. },{"../type":13}],25:[function(require,module,exports){
  2862. 'use strict';
  2863. var Type = require('../type');
  2864. var _toString = Object.prototype.toString;
  2865. function resolveYamlPairs(data) {
  2866. if (data === null) return true;
  2867. var index, length, pair, keys, result,
  2868. object = data;
  2869. result = new Array(object.length);
  2870. for (index = 0, length = object.length; index < length; index += 1) {
  2871. pair = object[index];
  2872. if (_toString.call(pair) !== '[object Object]') return false;
  2873. keys = Object.keys(pair);
  2874. if (keys.length !== 1) return false;
  2875. result[index] = [ keys[0], pair[keys[0]] ];
  2876. }
  2877. return true;
  2878. }
  2879. function constructYamlPairs(data) {
  2880. if (data === null) return [];
  2881. var index, length, pair, keys, result,
  2882. object = data;
  2883. result = new Array(object.length);
  2884. for (index = 0, length = object.length; index < length; index += 1) {
  2885. pair = object[index];
  2886. keys = Object.keys(pair);
  2887. result[index] = [ keys[0], pair[keys[0]] ];
  2888. }
  2889. return result;
  2890. }
  2891. module.exports = new Type('tag:yaml.org,2002:pairs', {
  2892. kind: 'sequence',
  2893. resolve: resolveYamlPairs,
  2894. construct: constructYamlPairs
  2895. });
  2896. },{"../type":13}],26:[function(require,module,exports){
  2897. 'use strict';
  2898. var Type = require('../type');
  2899. module.exports = new Type('tag:yaml.org,2002:seq', {
  2900. kind: 'sequence',
  2901. construct: function (data) { return data !== null ? data : []; }
  2902. });
  2903. },{"../type":13}],27:[function(require,module,exports){
  2904. 'use strict';
  2905. var Type = require('../type');
  2906. var _hasOwnProperty = Object.prototype.hasOwnProperty;
  2907. function resolveYamlSet(data) {
  2908. if (data === null) return true;
  2909. var key, object = data;
  2910. for (key in object) {
  2911. if (_hasOwnProperty.call(object, key)) {
  2912. if (object[key] !== null) return false;
  2913. }
  2914. }
  2915. return true;
  2916. }
  2917. function constructYamlSet(data) {
  2918. return data !== null ? data : {};
  2919. }
  2920. module.exports = new Type('tag:yaml.org,2002:set', {
  2921. kind: 'mapping',
  2922. resolve: resolveYamlSet,
  2923. construct: constructYamlSet
  2924. });
  2925. },{"../type":13}],28:[function(require,module,exports){
  2926. 'use strict';
  2927. var Type = require('../type');
  2928. module.exports = new Type('tag:yaml.org,2002:str', {
  2929. kind: 'scalar',
  2930. construct: function (data) { return data !== null ? data : ''; }
  2931. });
  2932. },{"../type":13}],29:[function(require,module,exports){
  2933. 'use strict';
  2934. var Type = require('../type');
  2935. var YAML_DATE_REGEXP = new RegExp(
  2936. '^([0-9][0-9][0-9][0-9])' + // [1] year
  2937. '-([0-9][0-9])' + // [2] month
  2938. '-([0-9][0-9])$'); // [3] day
  2939. var YAML_TIMESTAMP_REGEXP = new RegExp(
  2940. '^([0-9][0-9][0-9][0-9])' + // [1] year
  2941. '-([0-9][0-9]?)' + // [2] month
  2942. '-([0-9][0-9]?)' + // [3] day
  2943. '(?:[Tt]|[ \\t]+)' + // ...
  2944. '([0-9][0-9]?)' + // [4] hour
  2945. ':([0-9][0-9])' + // [5] minute
  2946. ':([0-9][0-9])' + // [6] second
  2947. '(?:\\.([0-9]*))?' + // [7] fraction
  2948. '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
  2949. '(?::([0-9][0-9]))?))?$'); // [11] tz_minute
  2950. function resolveYamlTimestamp(data) {
  2951. if (data === null) return false;
  2952. if (YAML_DATE_REGEXP.exec(data) !== null) return true;
  2953. if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
  2954. return false;
  2955. }
  2956. function constructYamlTimestamp(data) {
  2957. var match, year, month, day, hour, minute, second, fraction = 0,
  2958. delta = null, tz_hour, tz_minute, date;
  2959. match = YAML_DATE_REGEXP.exec(data);
  2960. if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
  2961. if (match === null) throw new Error('Date resolve error');
  2962. // match: [1] year [2] month [3] day
  2963. year = +(match[1]);
  2964. month = +(match[2]) - 1; // JS month starts with 0
  2965. day = +(match[3]);
  2966. if (!match[4]) { // no hour
  2967. return new Date(Date.UTC(year, month, day));
  2968. }
  2969. // match: [4] hour [5] minute [6] second [7] fraction
  2970. hour = +(match[4]);
  2971. minute = +(match[5]);
  2972. second = +(match[6]);
  2973. if (match[7]) {
  2974. fraction = match[7].slice(0, 3);
  2975. while (fraction.length < 3) { // milli-seconds
  2976. fraction += '0';
  2977. }
  2978. fraction = +fraction;
  2979. }
  2980. // match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
  2981. if (match[9]) {
  2982. tz_hour = +(match[10]);
  2983. tz_minute = +(match[11] || 0);
  2984. delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
  2985. if (match[9] === '-') delta = -delta;
  2986. }
  2987. date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
  2988. if (delta) date.setTime(date.getTime() - delta);
  2989. return date;
  2990. }
  2991. function representYamlTimestamp(object /*, style*/) {
  2992. return object.toISOString();
  2993. }
  2994. module.exports = new Type('tag:yaml.org,2002:timestamp', {
  2995. kind: 'scalar',
  2996. resolve: resolveYamlTimestamp,
  2997. construct: constructYamlTimestamp,
  2998. instanceOf: Date,
  2999. represent: representYamlTimestamp
  3000. });
  3001. },{"../type":13}],"/":[function(require,module,exports){
  3002. 'use strict';
  3003. var yaml = require('./lib/js-yaml.js');
  3004. module.exports = yaml;
  3005. },{"./lib/js-yaml.js":1}]},{},[])("/")
  3006. });