js-yaml.mjs 105 KB

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