js-yaml.js 104 KB

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