Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

js-yaml.js 105KB

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