js-yaml.js 104 KB

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