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