Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

3989 řádky
108 KiB

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