| 1 | /*! js-yaml 3.14.2 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 | // set a property of a literal object, while protecting against prototype pollution,
|
|---|
| 1125 | // see https://github.com/nodeca/js-yaml/issues/164 for more details
|
|---|
| 1126 | function setProperty(object, key, value) {
|
|---|
| 1127 | // used for this specific key only because Object.defineProperty is slow
|
|---|
| 1128 | if (key === '__proto__') {
|
|---|
| 1129 | Object.defineProperty(object, key, {
|
|---|
| 1130 | configurable: true,
|
|---|
| 1131 | enumerable: true,
|
|---|
| 1132 | writable: true,
|
|---|
| 1133 | value: value
|
|---|
| 1134 | });
|
|---|
| 1135 | } else {
|
|---|
| 1136 | object[key] = value;
|
|---|
| 1137 | }
|
|---|
| 1138 | }
|
|---|
| 1139 |
|
|---|
| 1140 | var simpleEscapeCheck = new Array(256); // integer, for fast access
|
|---|
| 1141 | var simpleEscapeMap = new Array(256);
|
|---|
| 1142 | for (var i = 0; i < 256; i++) {
|
|---|
| 1143 | simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
|---|
| 1144 | simpleEscapeMap[i] = simpleEscapeSequence(i);
|
|---|
| 1145 | }
|
|---|
| 1146 |
|
|---|
| 1147 |
|
|---|
| 1148 | function State(input, options) {
|
|---|
| 1149 | this.input = input;
|
|---|
| 1150 |
|
|---|
| 1151 | this.filename = options['filename'] || null;
|
|---|
| 1152 | this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
|
|---|
| 1153 | this.onWarning = options['onWarning'] || null;
|
|---|
| 1154 | this.legacy = options['legacy'] || false;
|
|---|
| 1155 | this.json = options['json'] || false;
|
|---|
| 1156 | this.listener = options['listener'] || null;
|
|---|
| 1157 |
|
|---|
| 1158 | this.implicitTypes = this.schema.compiledImplicit;
|
|---|
| 1159 | this.typeMap = this.schema.compiledTypeMap;
|
|---|
| 1160 |
|
|---|
| 1161 | this.length = input.length;
|
|---|
| 1162 | this.position = 0;
|
|---|
| 1163 | this.line = 0;
|
|---|
| 1164 | this.lineStart = 0;
|
|---|
| 1165 | this.lineIndent = 0;
|
|---|
| 1166 |
|
|---|
| 1167 | this.documents = [];
|
|---|
| 1168 |
|
|---|
| 1169 | /*
|
|---|
| 1170 | this.version;
|
|---|
| 1171 | this.checkLineBreaks;
|
|---|
| 1172 | this.tagMap;
|
|---|
| 1173 | this.anchorMap;
|
|---|
| 1174 | this.tag;
|
|---|
| 1175 | this.anchor;
|
|---|
| 1176 | this.kind;
|
|---|
| 1177 | this.result;*/
|
|---|
| 1178 |
|
|---|
| 1179 | }
|
|---|
| 1180 |
|
|---|
| 1181 |
|
|---|
| 1182 | function generateError(state, message) {
|
|---|
| 1183 | return new YAMLException(
|
|---|
| 1184 | message,
|
|---|
| 1185 | new Mark(state.filename, state.input, state.position, state.line, (state.position - state.lineStart)));
|
|---|
| 1186 | }
|
|---|
| 1187 |
|
|---|
| 1188 | function throwError(state, message) {
|
|---|
| 1189 | throw generateError(state, message);
|
|---|
| 1190 | }
|
|---|
| 1191 |
|
|---|
| 1192 | function throwWarning(state, message) {
|
|---|
| 1193 | if (state.onWarning) {
|
|---|
| 1194 | state.onWarning.call(null, generateError(state, message));
|
|---|
| 1195 | }
|
|---|
| 1196 | }
|
|---|
| 1197 |
|
|---|
| 1198 |
|
|---|
| 1199 | var directiveHandlers = {
|
|---|
| 1200 |
|
|---|
| 1201 | YAML: function handleYamlDirective(state, name, args) {
|
|---|
| 1202 |
|
|---|
| 1203 | var match, major, minor;
|
|---|
| 1204 |
|
|---|
| 1205 | if (state.version !== null) {
|
|---|
| 1206 | throwError(state, 'duplication of %YAML directive');
|
|---|
| 1207 | }
|
|---|
| 1208 |
|
|---|
| 1209 | if (args.length !== 1) {
|
|---|
| 1210 | throwError(state, 'YAML directive accepts exactly one argument');
|
|---|
| 1211 | }
|
|---|
| 1212 |
|
|---|
| 1213 | match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|---|
| 1214 |
|
|---|
| 1215 | if (match === null) {
|
|---|
| 1216 | throwError(state, 'ill-formed argument of the YAML directive');
|
|---|
| 1217 | }
|
|---|
| 1218 |
|
|---|
| 1219 | major = parseInt(match[1], 10);
|
|---|
| 1220 | minor = parseInt(match[2], 10);
|
|---|
| 1221 |
|
|---|
| 1222 | if (major !== 1) {
|
|---|
| 1223 | throwError(state, 'unacceptable YAML version of the document');
|
|---|
| 1224 | }
|
|---|
| 1225 |
|
|---|
| 1226 | state.version = args[0];
|
|---|
| 1227 | state.checkLineBreaks = (minor < 2);
|
|---|
| 1228 |
|
|---|
| 1229 | if (minor !== 1 && minor !== 2) {
|
|---|
| 1230 | throwWarning(state, 'unsupported YAML version of the document');
|
|---|
| 1231 | }
|
|---|
| 1232 | },
|
|---|
| 1233 |
|
|---|
| 1234 | TAG: function handleTagDirective(state, name, args) {
|
|---|
| 1235 |
|
|---|
| 1236 | var handle, prefix;
|
|---|
| 1237 |
|
|---|
| 1238 | if (args.length !== 2) {
|
|---|
| 1239 | throwError(state, 'TAG directive accepts exactly two arguments');
|
|---|
| 1240 | }
|
|---|
| 1241 |
|
|---|
| 1242 | handle = args[0];
|
|---|
| 1243 | prefix = args[1];
|
|---|
| 1244 |
|
|---|
| 1245 | if (!PATTERN_TAG_HANDLE.test(handle)) {
|
|---|
| 1246 | throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
|
|---|
| 1247 | }
|
|---|
| 1248 |
|
|---|
| 1249 | if (_hasOwnProperty.call(state.tagMap, handle)) {
|
|---|
| 1250 | throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
|---|
| 1251 | }
|
|---|
| 1252 |
|
|---|
| 1253 | if (!PATTERN_TAG_URI.test(prefix)) {
|
|---|
| 1254 | throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
|
|---|
| 1255 | }
|
|---|
| 1256 |
|
|---|
| 1257 | state.tagMap[handle] = prefix;
|
|---|
| 1258 | }
|
|---|
| 1259 | };
|
|---|
| 1260 |
|
|---|
| 1261 |
|
|---|
| 1262 | function captureSegment(state, start, end, checkJson) {
|
|---|
| 1263 | var _position, _length, _character, _result;
|
|---|
| 1264 |
|
|---|
| 1265 | if (start < end) {
|
|---|
| 1266 | _result = state.input.slice(start, end);
|
|---|
| 1267 |
|
|---|
| 1268 | if (checkJson) {
|
|---|
| 1269 | for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
|
|---|
| 1270 | _character = _result.charCodeAt(_position);
|
|---|
| 1271 | if (!(_character === 0x09 ||
|
|---|
| 1272 | (0x20 <= _character && _character <= 0x10FFFF))) {
|
|---|
| 1273 | throwError(state, 'expected valid JSON character');
|
|---|
| 1274 | }
|
|---|
| 1275 | }
|
|---|
| 1276 | } else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
|---|
| 1277 | throwError(state, 'the stream contains non-printable characters');
|
|---|
| 1278 | }
|
|---|
| 1279 |
|
|---|
| 1280 | state.result += _result;
|
|---|
| 1281 | }
|
|---|
| 1282 | }
|
|---|
| 1283 |
|
|---|
| 1284 | function mergeMappings(state, destination, source, overridableKeys) {
|
|---|
| 1285 | var sourceKeys, key, index, quantity;
|
|---|
| 1286 |
|
|---|
| 1287 | if (!common.isObject(source)) {
|
|---|
| 1288 | throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
|
|---|
| 1289 | }
|
|---|
| 1290 |
|
|---|
| 1291 | sourceKeys = Object.keys(source);
|
|---|
| 1292 |
|
|---|
| 1293 | for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
|
|---|
| 1294 | key = sourceKeys[index];
|
|---|
| 1295 |
|
|---|
| 1296 | if (!_hasOwnProperty.call(destination, key)) {
|
|---|
| 1297 | setProperty(destination, key, source[key]);
|
|---|
| 1298 | overridableKeys[key] = true;
|
|---|
| 1299 | }
|
|---|
| 1300 | }
|
|---|
| 1301 | }
|
|---|
| 1302 |
|
|---|
| 1303 | function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
|
|---|
| 1304 | var index, quantity;
|
|---|
| 1305 |
|
|---|
| 1306 | // The output is a plain object here, so keys can only be strings.
|
|---|
| 1307 | // We need to convert keyNode to a string, but doing so can hang the process
|
|---|
| 1308 | // (deeply nested arrays that explode exponentially using aliases).
|
|---|
| 1309 | if (Array.isArray(keyNode)) {
|
|---|
| 1310 | keyNode = Array.prototype.slice.call(keyNode);
|
|---|
| 1311 |
|
|---|
| 1312 | for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
|
|---|
| 1313 | if (Array.isArray(keyNode[index])) {
|
|---|
| 1314 | throwError(state, 'nested arrays are not supported inside keys');
|
|---|
| 1315 | }
|
|---|
| 1316 |
|
|---|
| 1317 | if (typeof keyNode === 'object' && _class(keyNode[index]) === '[object Object]') {
|
|---|
| 1318 | keyNode[index] = '[object Object]';
|
|---|
| 1319 | }
|
|---|
| 1320 | }
|
|---|
| 1321 | }
|
|---|
| 1322 |
|
|---|
| 1323 | // Avoid code execution in load() via toString property
|
|---|
| 1324 | // (still use its own toString for arrays, timestamps,
|
|---|
| 1325 | // and whatever user schema extensions happen to have @@toStringTag)
|
|---|
| 1326 | if (typeof keyNode === 'object' && _class(keyNode) === '[object Object]') {
|
|---|
| 1327 | keyNode = '[object Object]';
|
|---|
| 1328 | }
|
|---|
| 1329 |
|
|---|
| 1330 |
|
|---|
| 1331 | keyNode = String(keyNode);
|
|---|
| 1332 |
|
|---|
| 1333 | if (_result === null) {
|
|---|
| 1334 | _result = {};
|
|---|
| 1335 | }
|
|---|
| 1336 |
|
|---|
| 1337 | if (keyTag === 'tag:yaml.org,2002:merge') {
|
|---|
| 1338 | if (Array.isArray(valueNode)) {
|
|---|
| 1339 | for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
|
|---|
| 1340 | mergeMappings(state, _result, valueNode[index], overridableKeys);
|
|---|
| 1341 | }
|
|---|
| 1342 | } else {
|
|---|
| 1343 | mergeMappings(state, _result, valueNode, overridableKeys);
|
|---|
| 1344 | }
|
|---|
| 1345 | } else {
|
|---|
| 1346 | if (!state.json &&
|
|---|
| 1347 | !_hasOwnProperty.call(overridableKeys, keyNode) &&
|
|---|
| 1348 | _hasOwnProperty.call(_result, keyNode)) {
|
|---|
| 1349 | state.line = startLine || state.line;
|
|---|
| 1350 | state.position = startPos || state.position;
|
|---|
| 1351 | throwError(state, 'duplicated mapping key');
|
|---|
| 1352 | }
|
|---|
| 1353 | setProperty(_result, keyNode, valueNode);
|
|---|
| 1354 | delete overridableKeys[keyNode];
|
|---|
| 1355 | }
|
|---|
| 1356 |
|
|---|
| 1357 | return _result;
|
|---|
| 1358 | }
|
|---|
| 1359 |
|
|---|
| 1360 | function readLineBreak(state) {
|
|---|
| 1361 | var ch;
|
|---|
| 1362 |
|
|---|
| 1363 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1364 |
|
|---|
| 1365 | if (ch === 0x0A/* LF */) {
|
|---|
| 1366 | state.position++;
|
|---|
| 1367 | } else if (ch === 0x0D/* CR */) {
|
|---|
| 1368 | state.position++;
|
|---|
| 1369 | if (state.input.charCodeAt(state.position) === 0x0A/* LF */) {
|
|---|
| 1370 | state.position++;
|
|---|
| 1371 | }
|
|---|
| 1372 | } else {
|
|---|
| 1373 | throwError(state, 'a line break is expected');
|
|---|
| 1374 | }
|
|---|
| 1375 |
|
|---|
| 1376 | state.line += 1;
|
|---|
| 1377 | state.lineStart = state.position;
|
|---|
| 1378 | }
|
|---|
| 1379 |
|
|---|
| 1380 | function skipSeparationSpace(state, allowComments, checkIndent) {
|
|---|
| 1381 | var lineBreaks = 0,
|
|---|
| 1382 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1383 |
|
|---|
| 1384 | while (ch !== 0) {
|
|---|
| 1385 | while (is_WHITE_SPACE(ch)) {
|
|---|
| 1386 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1387 | }
|
|---|
| 1388 |
|
|---|
| 1389 | if (allowComments && ch === 0x23/* # */) {
|
|---|
| 1390 | do {
|
|---|
| 1391 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1392 | } while (ch !== 0x0A/* LF */ && ch !== 0x0D/* CR */ && ch !== 0);
|
|---|
| 1393 | }
|
|---|
| 1394 |
|
|---|
| 1395 | if (is_EOL(ch)) {
|
|---|
| 1396 | readLineBreak(state);
|
|---|
| 1397 |
|
|---|
| 1398 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1399 | lineBreaks++;
|
|---|
| 1400 | state.lineIndent = 0;
|
|---|
| 1401 |
|
|---|
| 1402 | while (ch === 0x20/* Space */) {
|
|---|
| 1403 | state.lineIndent++;
|
|---|
| 1404 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1405 | }
|
|---|
| 1406 | } else {
|
|---|
| 1407 | break;
|
|---|
| 1408 | }
|
|---|
| 1409 | }
|
|---|
| 1410 |
|
|---|
| 1411 | if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
|---|
| 1412 | throwWarning(state, 'deficient indentation');
|
|---|
| 1413 | }
|
|---|
| 1414 |
|
|---|
| 1415 | return lineBreaks;
|
|---|
| 1416 | }
|
|---|
| 1417 |
|
|---|
| 1418 | function testDocumentSeparator(state) {
|
|---|
| 1419 | var _position = state.position,
|
|---|
| 1420 | ch;
|
|---|
| 1421 |
|
|---|
| 1422 | ch = state.input.charCodeAt(_position);
|
|---|
| 1423 |
|
|---|
| 1424 | // Condition state.position === state.lineStart is tested
|
|---|
| 1425 | // in parent on each call, for efficiency. No needs to test here again.
|
|---|
| 1426 | if ((ch === 0x2D/* - */ || ch === 0x2E/* . */) &&
|
|---|
| 1427 | ch === state.input.charCodeAt(_position + 1) &&
|
|---|
| 1428 | ch === state.input.charCodeAt(_position + 2)) {
|
|---|
| 1429 |
|
|---|
| 1430 | _position += 3;
|
|---|
| 1431 |
|
|---|
| 1432 | ch = state.input.charCodeAt(_position);
|
|---|
| 1433 |
|
|---|
| 1434 | if (ch === 0 || is_WS_OR_EOL(ch)) {
|
|---|
| 1435 | return true;
|
|---|
| 1436 | }
|
|---|
| 1437 | }
|
|---|
| 1438 |
|
|---|
| 1439 | return false;
|
|---|
| 1440 | }
|
|---|
| 1441 |
|
|---|
| 1442 | function writeFoldedLines(state, count) {
|
|---|
| 1443 | if (count === 1) {
|
|---|
| 1444 | state.result += ' ';
|
|---|
| 1445 | } else if (count > 1) {
|
|---|
| 1446 | state.result += common.repeat('\n', count - 1);
|
|---|
| 1447 | }
|
|---|
| 1448 | }
|
|---|
| 1449 |
|
|---|
| 1450 |
|
|---|
| 1451 | function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|---|
| 1452 | var preceding,
|
|---|
| 1453 | following,
|
|---|
| 1454 | captureStart,
|
|---|
| 1455 | captureEnd,
|
|---|
| 1456 | hasPendingContent,
|
|---|
| 1457 | _line,
|
|---|
| 1458 | _lineStart,
|
|---|
| 1459 | _lineIndent,
|
|---|
| 1460 | _kind = state.kind,
|
|---|
| 1461 | _result = state.result,
|
|---|
| 1462 | ch;
|
|---|
| 1463 |
|
|---|
| 1464 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1465 |
|
|---|
| 1466 | if (is_WS_OR_EOL(ch) ||
|
|---|
| 1467 | is_FLOW_INDICATOR(ch) ||
|
|---|
| 1468 | ch === 0x23/* # */ ||
|
|---|
| 1469 | ch === 0x26/* & */ ||
|
|---|
| 1470 | ch === 0x2A/* * */ ||
|
|---|
| 1471 | ch === 0x21/* ! */ ||
|
|---|
| 1472 | ch === 0x7C/* | */ ||
|
|---|
| 1473 | ch === 0x3E/* > */ ||
|
|---|
| 1474 | ch === 0x27/* ' */ ||
|
|---|
| 1475 | ch === 0x22/* " */ ||
|
|---|
| 1476 | ch === 0x25/* % */ ||
|
|---|
| 1477 | ch === 0x40/* @ */ ||
|
|---|
| 1478 | ch === 0x60/* ` */) {
|
|---|
| 1479 | return false;
|
|---|
| 1480 | }
|
|---|
| 1481 |
|
|---|
| 1482 | if (ch === 0x3F/* ? */ || ch === 0x2D/* - */) {
|
|---|
| 1483 | following = state.input.charCodeAt(state.position + 1);
|
|---|
| 1484 |
|
|---|
| 1485 | if (is_WS_OR_EOL(following) ||
|
|---|
| 1486 | withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|---|
| 1487 | return false;
|
|---|
| 1488 | }
|
|---|
| 1489 | }
|
|---|
| 1490 |
|
|---|
| 1491 | state.kind = 'scalar';
|
|---|
| 1492 | state.result = '';
|
|---|
| 1493 | captureStart = captureEnd = state.position;
|
|---|
| 1494 | hasPendingContent = false;
|
|---|
| 1495 |
|
|---|
| 1496 | while (ch !== 0) {
|
|---|
| 1497 | if (ch === 0x3A/* : */) {
|
|---|
| 1498 | following = state.input.charCodeAt(state.position + 1);
|
|---|
| 1499 |
|
|---|
| 1500 | if (is_WS_OR_EOL(following) ||
|
|---|
| 1501 | withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
|---|
| 1502 | break;
|
|---|
| 1503 | }
|
|---|
| 1504 |
|
|---|
| 1505 | } else if (ch === 0x23/* # */) {
|
|---|
| 1506 | preceding = state.input.charCodeAt(state.position - 1);
|
|---|
| 1507 |
|
|---|
| 1508 | if (is_WS_OR_EOL(preceding)) {
|
|---|
| 1509 | break;
|
|---|
| 1510 | }
|
|---|
| 1511 |
|
|---|
| 1512 | } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
|
|---|
| 1513 | withinFlowCollection && is_FLOW_INDICATOR(ch)) {
|
|---|
| 1514 | break;
|
|---|
| 1515 |
|
|---|
| 1516 | } else if (is_EOL(ch)) {
|
|---|
| 1517 | _line = state.line;
|
|---|
| 1518 | _lineStart = state.lineStart;
|
|---|
| 1519 | _lineIndent = state.lineIndent;
|
|---|
| 1520 | skipSeparationSpace(state, false, -1);
|
|---|
| 1521 |
|
|---|
| 1522 | if (state.lineIndent >= nodeIndent) {
|
|---|
| 1523 | hasPendingContent = true;
|
|---|
| 1524 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1525 | continue;
|
|---|
| 1526 | } else {
|
|---|
| 1527 | state.position = captureEnd;
|
|---|
| 1528 | state.line = _line;
|
|---|
| 1529 | state.lineStart = _lineStart;
|
|---|
| 1530 | state.lineIndent = _lineIndent;
|
|---|
| 1531 | break;
|
|---|
| 1532 | }
|
|---|
| 1533 | }
|
|---|
| 1534 |
|
|---|
| 1535 | if (hasPendingContent) {
|
|---|
| 1536 | captureSegment(state, captureStart, captureEnd, false);
|
|---|
| 1537 | writeFoldedLines(state, state.line - _line);
|
|---|
| 1538 | captureStart = captureEnd = state.position;
|
|---|
| 1539 | hasPendingContent = false;
|
|---|
| 1540 | }
|
|---|
| 1541 |
|
|---|
| 1542 | if (!is_WHITE_SPACE(ch)) {
|
|---|
| 1543 | captureEnd = state.position + 1;
|
|---|
| 1544 | }
|
|---|
| 1545 |
|
|---|
| 1546 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1547 | }
|
|---|
| 1548 |
|
|---|
| 1549 | captureSegment(state, captureStart, captureEnd, false);
|
|---|
| 1550 |
|
|---|
| 1551 | if (state.result) {
|
|---|
| 1552 | return true;
|
|---|
| 1553 | }
|
|---|
| 1554 |
|
|---|
| 1555 | state.kind = _kind;
|
|---|
| 1556 | state.result = _result;
|
|---|
| 1557 | return false;
|
|---|
| 1558 | }
|
|---|
| 1559 |
|
|---|
| 1560 | function readSingleQuotedScalar(state, nodeIndent) {
|
|---|
| 1561 | var ch,
|
|---|
| 1562 | captureStart, captureEnd;
|
|---|
| 1563 |
|
|---|
| 1564 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1565 |
|
|---|
| 1566 | if (ch !== 0x27/* ' */) {
|
|---|
| 1567 | return false;
|
|---|
| 1568 | }
|
|---|
| 1569 |
|
|---|
| 1570 | state.kind = 'scalar';
|
|---|
| 1571 | state.result = '';
|
|---|
| 1572 | state.position++;
|
|---|
| 1573 | captureStart = captureEnd = state.position;
|
|---|
| 1574 |
|
|---|
| 1575 | while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|---|
| 1576 | if (ch === 0x27/* ' */) {
|
|---|
| 1577 | captureSegment(state, captureStart, state.position, true);
|
|---|
| 1578 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1579 |
|
|---|
| 1580 | if (ch === 0x27/* ' */) {
|
|---|
| 1581 | captureStart = state.position;
|
|---|
| 1582 | state.position++;
|
|---|
| 1583 | captureEnd = state.position;
|
|---|
| 1584 | } else {
|
|---|
| 1585 | return true;
|
|---|
| 1586 | }
|
|---|
| 1587 |
|
|---|
| 1588 | } else if (is_EOL(ch)) {
|
|---|
| 1589 | captureSegment(state, captureStart, captureEnd, true);
|
|---|
| 1590 | writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|---|
| 1591 | captureStart = captureEnd = state.position;
|
|---|
| 1592 |
|
|---|
| 1593 | } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|---|
| 1594 | throwError(state, 'unexpected end of the document within a single quoted scalar');
|
|---|
| 1595 |
|
|---|
| 1596 | } else {
|
|---|
| 1597 | state.position++;
|
|---|
| 1598 | captureEnd = state.position;
|
|---|
| 1599 | }
|
|---|
| 1600 | }
|
|---|
| 1601 |
|
|---|
| 1602 | throwError(state, 'unexpected end of the stream within a single quoted scalar');
|
|---|
| 1603 | }
|
|---|
| 1604 |
|
|---|
| 1605 | function readDoubleQuotedScalar(state, nodeIndent) {
|
|---|
| 1606 | var captureStart,
|
|---|
| 1607 | captureEnd,
|
|---|
| 1608 | hexLength,
|
|---|
| 1609 | hexResult,
|
|---|
| 1610 | tmp,
|
|---|
| 1611 | ch;
|
|---|
| 1612 |
|
|---|
| 1613 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1614 |
|
|---|
| 1615 | if (ch !== 0x22/* " */) {
|
|---|
| 1616 | return false;
|
|---|
| 1617 | }
|
|---|
| 1618 |
|
|---|
| 1619 | state.kind = 'scalar';
|
|---|
| 1620 | state.result = '';
|
|---|
| 1621 | state.position++;
|
|---|
| 1622 | captureStart = captureEnd = state.position;
|
|---|
| 1623 |
|
|---|
| 1624 | while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|---|
| 1625 | if (ch === 0x22/* " */) {
|
|---|
| 1626 | captureSegment(state, captureStart, state.position, true);
|
|---|
| 1627 | state.position++;
|
|---|
| 1628 | return true;
|
|---|
| 1629 |
|
|---|
| 1630 | } else if (ch === 0x5C/* \ */) {
|
|---|
| 1631 | captureSegment(state, captureStart, state.position, true);
|
|---|
| 1632 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1633 |
|
|---|
| 1634 | if (is_EOL(ch)) {
|
|---|
| 1635 | skipSeparationSpace(state, false, nodeIndent);
|
|---|
| 1636 |
|
|---|
| 1637 | // TODO: rework to inline fn with no type cast?
|
|---|
| 1638 | } else if (ch < 256 && simpleEscapeCheck[ch]) {
|
|---|
| 1639 | state.result += simpleEscapeMap[ch];
|
|---|
| 1640 | state.position++;
|
|---|
| 1641 |
|
|---|
| 1642 | } else if ((tmp = escapedHexLen(ch)) > 0) {
|
|---|
| 1643 | hexLength = tmp;
|
|---|
| 1644 | hexResult = 0;
|
|---|
| 1645 |
|
|---|
| 1646 | for (; hexLength > 0; hexLength--) {
|
|---|
| 1647 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1648 |
|
|---|
| 1649 | if ((tmp = fromHexCode(ch)) >= 0) {
|
|---|
| 1650 | hexResult = (hexResult << 4) + tmp;
|
|---|
| 1651 |
|
|---|
| 1652 | } else {
|
|---|
| 1653 | throwError(state, 'expected hexadecimal character');
|
|---|
| 1654 | }
|
|---|
| 1655 | }
|
|---|
| 1656 |
|
|---|
| 1657 | state.result += charFromCodepoint(hexResult);
|
|---|
| 1658 |
|
|---|
| 1659 | state.position++;
|
|---|
| 1660 |
|
|---|
| 1661 | } else {
|
|---|
| 1662 | throwError(state, 'unknown escape sequence');
|
|---|
| 1663 | }
|
|---|
| 1664 |
|
|---|
| 1665 | captureStart = captureEnd = state.position;
|
|---|
| 1666 |
|
|---|
| 1667 | } else if (is_EOL(ch)) {
|
|---|
| 1668 | captureSegment(state, captureStart, captureEnd, true);
|
|---|
| 1669 | writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|---|
| 1670 | captureStart = captureEnd = state.position;
|
|---|
| 1671 |
|
|---|
| 1672 | } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|---|
| 1673 | throwError(state, 'unexpected end of the document within a double quoted scalar');
|
|---|
| 1674 |
|
|---|
| 1675 | } else {
|
|---|
| 1676 | state.position++;
|
|---|
| 1677 | captureEnd = state.position;
|
|---|
| 1678 | }
|
|---|
| 1679 | }
|
|---|
| 1680 |
|
|---|
| 1681 | throwError(state, 'unexpected end of the stream within a double quoted scalar');
|
|---|
| 1682 | }
|
|---|
| 1683 |
|
|---|
| 1684 | function readFlowCollection(state, nodeIndent) {
|
|---|
| 1685 | var readNext = true,
|
|---|
| 1686 | _line,
|
|---|
| 1687 | _tag = state.tag,
|
|---|
| 1688 | _result,
|
|---|
| 1689 | _anchor = state.anchor,
|
|---|
| 1690 | following,
|
|---|
| 1691 | terminator,
|
|---|
| 1692 | isPair,
|
|---|
| 1693 | isExplicitPair,
|
|---|
| 1694 | isMapping,
|
|---|
| 1695 | overridableKeys = {},
|
|---|
| 1696 | keyNode,
|
|---|
| 1697 | keyTag,
|
|---|
| 1698 | valueNode,
|
|---|
| 1699 | ch;
|
|---|
| 1700 |
|
|---|
| 1701 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1702 |
|
|---|
| 1703 | if (ch === 0x5B/* [ */) {
|
|---|
| 1704 | terminator = 0x5D;/* ] */
|
|---|
| 1705 | isMapping = false;
|
|---|
| 1706 | _result = [];
|
|---|
| 1707 | } else if (ch === 0x7B/* { */) {
|
|---|
| 1708 | terminator = 0x7D;/* } */
|
|---|
| 1709 | isMapping = true;
|
|---|
| 1710 | _result = {};
|
|---|
| 1711 | } else {
|
|---|
| 1712 | return false;
|
|---|
| 1713 | }
|
|---|
| 1714 |
|
|---|
| 1715 | if (state.anchor !== null) {
|
|---|
| 1716 | state.anchorMap[state.anchor] = _result;
|
|---|
| 1717 | }
|
|---|
| 1718 |
|
|---|
| 1719 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1720 |
|
|---|
| 1721 | while (ch !== 0) {
|
|---|
| 1722 | skipSeparationSpace(state, true, nodeIndent);
|
|---|
| 1723 |
|
|---|
| 1724 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1725 |
|
|---|
| 1726 | if (ch === terminator) {
|
|---|
| 1727 | state.position++;
|
|---|
| 1728 | state.tag = _tag;
|
|---|
| 1729 | state.anchor = _anchor;
|
|---|
| 1730 | state.kind = isMapping ? 'mapping' : 'sequence';
|
|---|
| 1731 | state.result = _result;
|
|---|
| 1732 | return true;
|
|---|
| 1733 | } else if (!readNext) {
|
|---|
| 1734 | throwError(state, 'missed comma between flow collection entries');
|
|---|
| 1735 | }
|
|---|
| 1736 |
|
|---|
| 1737 | keyTag = keyNode = valueNode = null;
|
|---|
| 1738 | isPair = isExplicitPair = false;
|
|---|
| 1739 |
|
|---|
| 1740 | if (ch === 0x3F/* ? */) {
|
|---|
| 1741 | following = state.input.charCodeAt(state.position + 1);
|
|---|
| 1742 |
|
|---|
| 1743 | if (is_WS_OR_EOL(following)) {
|
|---|
| 1744 | isPair = isExplicitPair = true;
|
|---|
| 1745 | state.position++;
|
|---|
| 1746 | skipSeparationSpace(state, true, nodeIndent);
|
|---|
| 1747 | }
|
|---|
| 1748 | }
|
|---|
| 1749 |
|
|---|
| 1750 | _line = state.line;
|
|---|
| 1751 | composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|---|
| 1752 | keyTag = state.tag;
|
|---|
| 1753 | keyNode = state.result;
|
|---|
| 1754 | skipSeparationSpace(state, true, nodeIndent);
|
|---|
| 1755 |
|
|---|
| 1756 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1757 |
|
|---|
| 1758 | if ((isExplicitPair || state.line === _line) && ch === 0x3A/* : */) {
|
|---|
| 1759 | isPair = true;
|
|---|
| 1760 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1761 | skipSeparationSpace(state, true, nodeIndent);
|
|---|
| 1762 | composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
|---|
| 1763 | valueNode = state.result;
|
|---|
| 1764 | }
|
|---|
| 1765 |
|
|---|
| 1766 | if (isMapping) {
|
|---|
| 1767 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
|
|---|
| 1768 | } else if (isPair) {
|
|---|
| 1769 | _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
|
|---|
| 1770 | } else {
|
|---|
| 1771 | _result.push(keyNode);
|
|---|
| 1772 | }
|
|---|
| 1773 |
|
|---|
| 1774 | skipSeparationSpace(state, true, nodeIndent);
|
|---|
| 1775 |
|
|---|
| 1776 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1777 |
|
|---|
| 1778 | if (ch === 0x2C/* , */) {
|
|---|
| 1779 | readNext = true;
|
|---|
| 1780 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1781 | } else {
|
|---|
| 1782 | readNext = false;
|
|---|
| 1783 | }
|
|---|
| 1784 | }
|
|---|
| 1785 |
|
|---|
| 1786 | throwError(state, 'unexpected end of the stream within a flow collection');
|
|---|
| 1787 | }
|
|---|
| 1788 |
|
|---|
| 1789 | function readBlockScalar(state, nodeIndent) {
|
|---|
| 1790 | var captureStart,
|
|---|
| 1791 | folding,
|
|---|
| 1792 | chomping = CHOMPING_CLIP,
|
|---|
| 1793 | didReadContent = false,
|
|---|
| 1794 | detectedIndent = false,
|
|---|
| 1795 | textIndent = nodeIndent,
|
|---|
| 1796 | emptyLines = 0,
|
|---|
| 1797 | atMoreIndented = false,
|
|---|
| 1798 | tmp,
|
|---|
| 1799 | ch;
|
|---|
| 1800 |
|
|---|
| 1801 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1802 |
|
|---|
| 1803 | if (ch === 0x7C/* | */) {
|
|---|
| 1804 | folding = false;
|
|---|
| 1805 | } else if (ch === 0x3E/* > */) {
|
|---|
| 1806 | folding = true;
|
|---|
| 1807 | } else {
|
|---|
| 1808 | return false;
|
|---|
| 1809 | }
|
|---|
| 1810 |
|
|---|
| 1811 | state.kind = 'scalar';
|
|---|
| 1812 | state.result = '';
|
|---|
| 1813 |
|
|---|
| 1814 | while (ch !== 0) {
|
|---|
| 1815 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1816 |
|
|---|
| 1817 | if (ch === 0x2B/* + */ || ch === 0x2D/* - */) {
|
|---|
| 1818 | if (CHOMPING_CLIP === chomping) {
|
|---|
| 1819 | chomping = (ch === 0x2B/* + */) ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|---|
| 1820 | } else {
|
|---|
| 1821 | throwError(state, 'repeat of a chomping mode identifier');
|
|---|
| 1822 | }
|
|---|
| 1823 |
|
|---|
| 1824 | } else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
|---|
| 1825 | if (tmp === 0) {
|
|---|
| 1826 | throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
|
|---|
| 1827 | } else if (!detectedIndent) {
|
|---|
| 1828 | textIndent = nodeIndent + tmp - 1;
|
|---|
| 1829 | detectedIndent = true;
|
|---|
| 1830 | } else {
|
|---|
| 1831 | throwError(state, 'repeat of an indentation width identifier');
|
|---|
| 1832 | }
|
|---|
| 1833 |
|
|---|
| 1834 | } else {
|
|---|
| 1835 | break;
|
|---|
| 1836 | }
|
|---|
| 1837 | }
|
|---|
| 1838 |
|
|---|
| 1839 | if (is_WHITE_SPACE(ch)) {
|
|---|
| 1840 | do { ch = state.input.charCodeAt(++state.position); }
|
|---|
| 1841 | while (is_WHITE_SPACE(ch));
|
|---|
| 1842 |
|
|---|
| 1843 | if (ch === 0x23/* # */) {
|
|---|
| 1844 | do { ch = state.input.charCodeAt(++state.position); }
|
|---|
| 1845 | while (!is_EOL(ch) && (ch !== 0));
|
|---|
| 1846 | }
|
|---|
| 1847 | }
|
|---|
| 1848 |
|
|---|
| 1849 | while (ch !== 0) {
|
|---|
| 1850 | readLineBreak(state);
|
|---|
| 1851 | state.lineIndent = 0;
|
|---|
| 1852 |
|
|---|
| 1853 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1854 |
|
|---|
| 1855 | while ((!detectedIndent || state.lineIndent < textIndent) &&
|
|---|
| 1856 | (ch === 0x20/* Space */)) {
|
|---|
| 1857 | state.lineIndent++;
|
|---|
| 1858 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1859 | }
|
|---|
| 1860 |
|
|---|
| 1861 | if (!detectedIndent && state.lineIndent > textIndent) {
|
|---|
| 1862 | textIndent = state.lineIndent;
|
|---|
| 1863 | }
|
|---|
| 1864 |
|
|---|
| 1865 | if (is_EOL(ch)) {
|
|---|
| 1866 | emptyLines++;
|
|---|
| 1867 | continue;
|
|---|
| 1868 | }
|
|---|
| 1869 |
|
|---|
| 1870 | // End of the scalar.
|
|---|
| 1871 | if (state.lineIndent < textIndent) {
|
|---|
| 1872 |
|
|---|
| 1873 | // Perform the chomping.
|
|---|
| 1874 | if (chomping === CHOMPING_KEEP) {
|
|---|
| 1875 | state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
|---|
| 1876 | } else if (chomping === CHOMPING_CLIP) {
|
|---|
| 1877 | if (didReadContent) { // i.e. only if the scalar is not empty.
|
|---|
| 1878 | state.result += '\n';
|
|---|
| 1879 | }
|
|---|
| 1880 | }
|
|---|
| 1881 |
|
|---|
| 1882 | // Break this `while` cycle and go to the funciton's epilogue.
|
|---|
| 1883 | break;
|
|---|
| 1884 | }
|
|---|
| 1885 |
|
|---|
| 1886 | // Folded style: use fancy rules to handle line breaks.
|
|---|
| 1887 | if (folding) {
|
|---|
| 1888 |
|
|---|
| 1889 | // Lines starting with white space characters (more-indented lines) are not folded.
|
|---|
| 1890 | if (is_WHITE_SPACE(ch)) {
|
|---|
| 1891 | atMoreIndented = true;
|
|---|
| 1892 | // except for the first content line (cf. Example 8.1)
|
|---|
| 1893 | state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
|---|
| 1894 |
|
|---|
| 1895 | // End of more-indented block.
|
|---|
| 1896 | } else if (atMoreIndented) {
|
|---|
| 1897 | atMoreIndented = false;
|
|---|
| 1898 | state.result += common.repeat('\n', emptyLines + 1);
|
|---|
| 1899 |
|
|---|
| 1900 | // Just one line break - perceive as the same line.
|
|---|
| 1901 | } else if (emptyLines === 0) {
|
|---|
| 1902 | if (didReadContent) { // i.e. only if we have already read some scalar content.
|
|---|
| 1903 | state.result += ' ';
|
|---|
| 1904 | }
|
|---|
| 1905 |
|
|---|
| 1906 | // Several line breaks - perceive as different lines.
|
|---|
| 1907 | } else {
|
|---|
| 1908 | state.result += common.repeat('\n', emptyLines);
|
|---|
| 1909 | }
|
|---|
| 1910 |
|
|---|
| 1911 | // Literal style: just add exact number of line breaks between content lines.
|
|---|
| 1912 | } else {
|
|---|
| 1913 | // Keep all line breaks except the header line break.
|
|---|
| 1914 | state.result += common.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
|---|
| 1915 | }
|
|---|
| 1916 |
|
|---|
| 1917 | didReadContent = true;
|
|---|
| 1918 | detectedIndent = true;
|
|---|
| 1919 | emptyLines = 0;
|
|---|
| 1920 | captureStart = state.position;
|
|---|
| 1921 |
|
|---|
| 1922 | while (!is_EOL(ch) && (ch !== 0)) {
|
|---|
| 1923 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 1924 | }
|
|---|
| 1925 |
|
|---|
| 1926 | captureSegment(state, captureStart, state.position, false);
|
|---|
| 1927 | }
|
|---|
| 1928 |
|
|---|
| 1929 | return true;
|
|---|
| 1930 | }
|
|---|
| 1931 |
|
|---|
| 1932 | function readBlockSequence(state, nodeIndent) {
|
|---|
| 1933 | var _line,
|
|---|
| 1934 | _tag = state.tag,
|
|---|
| 1935 | _anchor = state.anchor,
|
|---|
| 1936 | _result = [],
|
|---|
| 1937 | following,
|
|---|
| 1938 | detected = false,
|
|---|
| 1939 | ch;
|
|---|
| 1940 |
|
|---|
| 1941 | if (state.anchor !== null) {
|
|---|
| 1942 | state.anchorMap[state.anchor] = _result;
|
|---|
| 1943 | }
|
|---|
| 1944 |
|
|---|
| 1945 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1946 |
|
|---|
| 1947 | while (ch !== 0) {
|
|---|
| 1948 |
|
|---|
| 1949 | if (ch !== 0x2D/* - */) {
|
|---|
| 1950 | break;
|
|---|
| 1951 | }
|
|---|
| 1952 |
|
|---|
| 1953 | following = state.input.charCodeAt(state.position + 1);
|
|---|
| 1954 |
|
|---|
| 1955 | if (!is_WS_OR_EOL(following)) {
|
|---|
| 1956 | break;
|
|---|
| 1957 | }
|
|---|
| 1958 |
|
|---|
| 1959 | detected = true;
|
|---|
| 1960 | state.position++;
|
|---|
| 1961 |
|
|---|
| 1962 | if (skipSeparationSpace(state, true, -1)) {
|
|---|
| 1963 | if (state.lineIndent <= nodeIndent) {
|
|---|
| 1964 | _result.push(null);
|
|---|
| 1965 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1966 | continue;
|
|---|
| 1967 | }
|
|---|
| 1968 | }
|
|---|
| 1969 |
|
|---|
| 1970 | _line = state.line;
|
|---|
| 1971 | composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
|---|
| 1972 | _result.push(state.result);
|
|---|
| 1973 | skipSeparationSpace(state, true, -1);
|
|---|
| 1974 |
|
|---|
| 1975 | ch = state.input.charCodeAt(state.position);
|
|---|
| 1976 |
|
|---|
| 1977 | if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
|
|---|
| 1978 | throwError(state, 'bad indentation of a sequence entry');
|
|---|
| 1979 | } else if (state.lineIndent < nodeIndent) {
|
|---|
| 1980 | break;
|
|---|
| 1981 | }
|
|---|
| 1982 | }
|
|---|
| 1983 |
|
|---|
| 1984 | if (detected) {
|
|---|
| 1985 | state.tag = _tag;
|
|---|
| 1986 | state.anchor = _anchor;
|
|---|
| 1987 | state.kind = 'sequence';
|
|---|
| 1988 | state.result = _result;
|
|---|
| 1989 | return true;
|
|---|
| 1990 | }
|
|---|
| 1991 | return false;
|
|---|
| 1992 | }
|
|---|
| 1993 |
|
|---|
| 1994 | function readBlockMapping(state, nodeIndent, flowIndent) {
|
|---|
| 1995 | var following,
|
|---|
| 1996 | allowCompact,
|
|---|
| 1997 | _line,
|
|---|
| 1998 | _pos,
|
|---|
| 1999 | _tag = state.tag,
|
|---|
| 2000 | _anchor = state.anchor,
|
|---|
| 2001 | _result = {},
|
|---|
| 2002 | overridableKeys = {},
|
|---|
| 2003 | keyTag = null,
|
|---|
| 2004 | keyNode = null,
|
|---|
| 2005 | valueNode = null,
|
|---|
| 2006 | atExplicitKey = false,
|
|---|
| 2007 | detected = false,
|
|---|
| 2008 | ch;
|
|---|
| 2009 |
|
|---|
| 2010 | if (state.anchor !== null) {
|
|---|
| 2011 | state.anchorMap[state.anchor] = _result;
|
|---|
| 2012 | }
|
|---|
| 2013 |
|
|---|
| 2014 | ch = state.input.charCodeAt(state.position);
|
|---|
| 2015 |
|
|---|
| 2016 | while (ch !== 0) {
|
|---|
| 2017 | following = state.input.charCodeAt(state.position + 1);
|
|---|
| 2018 | _line = state.line; // Save the current line.
|
|---|
| 2019 | _pos = state.position;
|
|---|
| 2020 |
|
|---|
| 2021 | //
|
|---|
| 2022 | // Explicit notation case. There are two separate blocks:
|
|---|
| 2023 | // first for the key (denoted by "?") and second for the value (denoted by ":")
|
|---|
| 2024 | //
|
|---|
| 2025 | if ((ch === 0x3F/* ? */ || ch === 0x3A/* : */) && is_WS_OR_EOL(following)) {
|
|---|
| 2026 |
|
|---|
| 2027 | if (ch === 0x3F/* ? */) {
|
|---|
| 2028 | if (atExplicitKey) {
|
|---|
| 2029 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
|---|
| 2030 | keyTag = keyNode = valueNode = null;
|
|---|
| 2031 | }
|
|---|
| 2032 |
|
|---|
| 2033 | detected = true;
|
|---|
| 2034 | atExplicitKey = true;
|
|---|
| 2035 | allowCompact = true;
|
|---|
| 2036 |
|
|---|
| 2037 | } else if (atExplicitKey) {
|
|---|
| 2038 | // i.e. 0x3A/* : */ === character after the explicit key.
|
|---|
| 2039 | atExplicitKey = false;
|
|---|
| 2040 | allowCompact = true;
|
|---|
| 2041 |
|
|---|
| 2042 | } else {
|
|---|
| 2043 | throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line');
|
|---|
| 2044 | }
|
|---|
| 2045 |
|
|---|
| 2046 | state.position += 1;
|
|---|
| 2047 | ch = following;
|
|---|
| 2048 |
|
|---|
| 2049 | //
|
|---|
| 2050 | // Implicit notation case. Flow-style node as the key first, then ":", and the value.
|
|---|
| 2051 | //
|
|---|
| 2052 | } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
|---|
| 2053 |
|
|---|
| 2054 | if (state.line === _line) {
|
|---|
| 2055 | ch = state.input.charCodeAt(state.position);
|
|---|
| 2056 |
|
|---|
| 2057 | while (is_WHITE_SPACE(ch)) {
|
|---|
| 2058 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2059 | }
|
|---|
| 2060 |
|
|---|
| 2061 | if (ch === 0x3A/* : */) {
|
|---|
| 2062 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2063 |
|
|---|
| 2064 | if (!is_WS_OR_EOL(ch)) {
|
|---|
| 2065 | throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
|
|---|
| 2066 | }
|
|---|
| 2067 |
|
|---|
| 2068 | if (atExplicitKey) {
|
|---|
| 2069 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
|---|
| 2070 | keyTag = keyNode = valueNode = null;
|
|---|
| 2071 | }
|
|---|
| 2072 |
|
|---|
| 2073 | detected = true;
|
|---|
| 2074 | atExplicitKey = false;
|
|---|
| 2075 | allowCompact = false;
|
|---|
| 2076 | keyTag = state.tag;
|
|---|
| 2077 | keyNode = state.result;
|
|---|
| 2078 |
|
|---|
| 2079 | } else if (detected) {
|
|---|
| 2080 | throwError(state, 'can not read an implicit mapping pair; a colon is missed');
|
|---|
| 2081 |
|
|---|
| 2082 | } else {
|
|---|
| 2083 | state.tag = _tag;
|
|---|
| 2084 | state.anchor = _anchor;
|
|---|
| 2085 | return true; // Keep the result of `composeNode`.
|
|---|
| 2086 | }
|
|---|
| 2087 |
|
|---|
| 2088 | } else if (detected) {
|
|---|
| 2089 | throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
|
|---|
| 2090 |
|
|---|
| 2091 | } else {
|
|---|
| 2092 | state.tag = _tag;
|
|---|
| 2093 | state.anchor = _anchor;
|
|---|
| 2094 | return true; // Keep the result of `composeNode`.
|
|---|
| 2095 | }
|
|---|
| 2096 |
|
|---|
| 2097 | } else {
|
|---|
| 2098 | break; // Reading is done. Go to the epilogue.
|
|---|
| 2099 | }
|
|---|
| 2100 |
|
|---|
| 2101 | //
|
|---|
| 2102 | // Common reading code for both explicit and implicit notations.
|
|---|
| 2103 | //
|
|---|
| 2104 | if (state.line === _line || state.lineIndent > nodeIndent) {
|
|---|
| 2105 | if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
|---|
| 2106 | if (atExplicitKey) {
|
|---|
| 2107 | keyNode = state.result;
|
|---|
| 2108 | } else {
|
|---|
| 2109 | valueNode = state.result;
|
|---|
| 2110 | }
|
|---|
| 2111 | }
|
|---|
| 2112 |
|
|---|
| 2113 | if (!atExplicitKey) {
|
|---|
| 2114 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos);
|
|---|
| 2115 | keyTag = keyNode = valueNode = null;
|
|---|
| 2116 | }
|
|---|
| 2117 |
|
|---|
| 2118 | skipSeparationSpace(state, true, -1);
|
|---|
| 2119 | ch = state.input.charCodeAt(state.position);
|
|---|
| 2120 | }
|
|---|
| 2121 |
|
|---|
| 2122 | if (state.lineIndent > nodeIndent && (ch !== 0)) {
|
|---|
| 2123 | throwError(state, 'bad indentation of a mapping entry');
|
|---|
| 2124 | } else if (state.lineIndent < nodeIndent) {
|
|---|
| 2125 | break;
|
|---|
| 2126 | }
|
|---|
| 2127 | }
|
|---|
| 2128 |
|
|---|
| 2129 | //
|
|---|
| 2130 | // Epilogue.
|
|---|
| 2131 | //
|
|---|
| 2132 |
|
|---|
| 2133 | // Special case: last mapping's node contains only the key in explicit notation.
|
|---|
| 2134 | if (atExplicitKey) {
|
|---|
| 2135 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
|---|
| 2136 | }
|
|---|
| 2137 |
|
|---|
| 2138 | // Expose the resulting mapping.
|
|---|
| 2139 | if (detected) {
|
|---|
| 2140 | state.tag = _tag;
|
|---|
| 2141 | state.anchor = _anchor;
|
|---|
| 2142 | state.kind = 'mapping';
|
|---|
| 2143 | state.result = _result;
|
|---|
| 2144 | }
|
|---|
| 2145 |
|
|---|
| 2146 | return detected;
|
|---|
| 2147 | }
|
|---|
| 2148 |
|
|---|
| 2149 | function readTagProperty(state) {
|
|---|
| 2150 | var _position,
|
|---|
| 2151 | isVerbatim = false,
|
|---|
| 2152 | isNamed = false,
|
|---|
| 2153 | tagHandle,
|
|---|
| 2154 | tagName,
|
|---|
| 2155 | ch;
|
|---|
| 2156 |
|
|---|
| 2157 | ch = state.input.charCodeAt(state.position);
|
|---|
| 2158 |
|
|---|
| 2159 | if (ch !== 0x21/* ! */) return false;
|
|---|
| 2160 |
|
|---|
| 2161 | if (state.tag !== null) {
|
|---|
| 2162 | throwError(state, 'duplication of a tag property');
|
|---|
| 2163 | }
|
|---|
| 2164 |
|
|---|
| 2165 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2166 |
|
|---|
| 2167 | if (ch === 0x3C/* < */) {
|
|---|
| 2168 | isVerbatim = true;
|
|---|
| 2169 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2170 |
|
|---|
| 2171 | } else if (ch === 0x21/* ! */) {
|
|---|
| 2172 | isNamed = true;
|
|---|
| 2173 | tagHandle = '!!';
|
|---|
| 2174 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2175 |
|
|---|
| 2176 | } else {
|
|---|
| 2177 | tagHandle = '!';
|
|---|
| 2178 | }
|
|---|
| 2179 |
|
|---|
| 2180 | _position = state.position;
|
|---|
| 2181 |
|
|---|
| 2182 | if (isVerbatim) {
|
|---|
| 2183 | do { ch = state.input.charCodeAt(++state.position); }
|
|---|
| 2184 | while (ch !== 0 && ch !== 0x3E/* > */);
|
|---|
| 2185 |
|
|---|
| 2186 | if (state.position < state.length) {
|
|---|
| 2187 | tagName = state.input.slice(_position, state.position);
|
|---|
| 2188 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2189 | } else {
|
|---|
| 2190 | throwError(state, 'unexpected end of the stream within a verbatim tag');
|
|---|
| 2191 | }
|
|---|
| 2192 | } else {
|
|---|
| 2193 | while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|---|
| 2194 |
|
|---|
| 2195 | if (ch === 0x21/* ! */) {
|
|---|
| 2196 | if (!isNamed) {
|
|---|
| 2197 | tagHandle = state.input.slice(_position - 1, state.position + 1);
|
|---|
| 2198 |
|
|---|
| 2199 | if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|---|
| 2200 | throwError(state, 'named tag handle cannot contain such characters');
|
|---|
| 2201 | }
|
|---|
| 2202 |
|
|---|
| 2203 | isNamed = true;
|
|---|
| 2204 | _position = state.position + 1;
|
|---|
| 2205 | } else {
|
|---|
| 2206 | throwError(state, 'tag suffix cannot contain exclamation marks');
|
|---|
| 2207 | }
|
|---|
| 2208 | }
|
|---|
| 2209 |
|
|---|
| 2210 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2211 | }
|
|---|
| 2212 |
|
|---|
| 2213 | tagName = state.input.slice(_position, state.position);
|
|---|
| 2214 |
|
|---|
| 2215 | if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|---|
| 2216 | throwError(state, 'tag suffix cannot contain flow indicator characters');
|
|---|
| 2217 | }
|
|---|
| 2218 | }
|
|---|
| 2219 |
|
|---|
| 2220 | if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
|---|
| 2221 | throwError(state, 'tag name cannot contain such characters: ' + tagName);
|
|---|
| 2222 | }
|
|---|
| 2223 |
|
|---|
| 2224 | if (isVerbatim) {
|
|---|
| 2225 | state.tag = tagName;
|
|---|
| 2226 |
|
|---|
| 2227 | } else if (_hasOwnProperty.call(state.tagMap, tagHandle)) {
|
|---|
| 2228 | state.tag = state.tagMap[tagHandle] + tagName;
|
|---|
| 2229 |
|
|---|
| 2230 | } else if (tagHandle === '!') {
|
|---|
| 2231 | state.tag = '!' + tagName;
|
|---|
| 2232 |
|
|---|
| 2233 | } else if (tagHandle === '!!') {
|
|---|
| 2234 | state.tag = 'tag:yaml.org,2002:' + tagName;
|
|---|
| 2235 |
|
|---|
| 2236 | } else {
|
|---|
| 2237 | throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
|---|
| 2238 | }
|
|---|
| 2239 |
|
|---|
| 2240 | return true;
|
|---|
| 2241 | }
|
|---|
| 2242 |
|
|---|
| 2243 | function readAnchorProperty(state) {
|
|---|
| 2244 | var _position,
|
|---|
| 2245 | ch;
|
|---|
| 2246 |
|
|---|
| 2247 | ch = state.input.charCodeAt(state.position);
|
|---|
| 2248 |
|
|---|
| 2249 | if (ch !== 0x26/* & */) return false;
|
|---|
| 2250 |
|
|---|
| 2251 | if (state.anchor !== null) {
|
|---|
| 2252 | throwError(state, 'duplication of an anchor property');
|
|---|
| 2253 | }
|
|---|
| 2254 |
|
|---|
| 2255 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2256 | _position = state.position;
|
|---|
| 2257 |
|
|---|
| 2258 | while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|---|
| 2259 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2260 | }
|
|---|
| 2261 |
|
|---|
| 2262 | if (state.position === _position) {
|
|---|
| 2263 | throwError(state, 'name of an anchor node must contain at least one character');
|
|---|
| 2264 | }
|
|---|
| 2265 |
|
|---|
| 2266 | state.anchor = state.input.slice(_position, state.position);
|
|---|
| 2267 | return true;
|
|---|
| 2268 | }
|
|---|
| 2269 |
|
|---|
| 2270 | function readAlias(state) {
|
|---|
| 2271 | var _position, alias,
|
|---|
| 2272 | ch;
|
|---|
| 2273 |
|
|---|
| 2274 | ch = state.input.charCodeAt(state.position);
|
|---|
| 2275 |
|
|---|
| 2276 | if (ch !== 0x2A/* * */) return false;
|
|---|
| 2277 |
|
|---|
| 2278 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2279 | _position = state.position;
|
|---|
| 2280 |
|
|---|
| 2281 | while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
|---|
| 2282 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2283 | }
|
|---|
| 2284 |
|
|---|
| 2285 | if (state.position === _position) {
|
|---|
| 2286 | throwError(state, 'name of an alias node must contain at least one character');
|
|---|
| 2287 | }
|
|---|
| 2288 |
|
|---|
| 2289 | alias = state.input.slice(_position, state.position);
|
|---|
| 2290 |
|
|---|
| 2291 | if (!_hasOwnProperty.call(state.anchorMap, alias)) {
|
|---|
| 2292 | throwError(state, 'unidentified alias "' + alias + '"');
|
|---|
| 2293 | }
|
|---|
| 2294 |
|
|---|
| 2295 | state.result = state.anchorMap[alias];
|
|---|
| 2296 | skipSeparationSpace(state, true, -1);
|
|---|
| 2297 | return true;
|
|---|
| 2298 | }
|
|---|
| 2299 |
|
|---|
| 2300 | function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
|---|
| 2301 | var allowBlockStyles,
|
|---|
| 2302 | allowBlockScalars,
|
|---|
| 2303 | allowBlockCollections,
|
|---|
| 2304 | indentStatus = 1, // 1: this>parent, 0: this=parent, -1: this<parent
|
|---|
| 2305 | atNewLine = false,
|
|---|
| 2306 | hasContent = false,
|
|---|
| 2307 | typeIndex,
|
|---|
| 2308 | typeQuantity,
|
|---|
| 2309 | type,
|
|---|
| 2310 | flowIndent,
|
|---|
| 2311 | blockIndent;
|
|---|
| 2312 |
|
|---|
| 2313 | if (state.listener !== null) {
|
|---|
| 2314 | state.listener('open', state);
|
|---|
| 2315 | }
|
|---|
| 2316 |
|
|---|
| 2317 | state.tag = null;
|
|---|
| 2318 | state.anchor = null;
|
|---|
| 2319 | state.kind = null;
|
|---|
| 2320 | state.result = null;
|
|---|
| 2321 |
|
|---|
| 2322 | allowBlockStyles = allowBlockScalars = allowBlockCollections =
|
|---|
| 2323 | CONTEXT_BLOCK_OUT === nodeContext ||
|
|---|
| 2324 | CONTEXT_BLOCK_IN === nodeContext;
|
|---|
| 2325 |
|
|---|
| 2326 | if (allowToSeek) {
|
|---|
| 2327 | if (skipSeparationSpace(state, true, -1)) {
|
|---|
| 2328 | atNewLine = true;
|
|---|
| 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 | }
|
|---|
| 2338 | }
|
|---|
| 2339 |
|
|---|
| 2340 | if (indentStatus === 1) {
|
|---|
| 2341 | while (readTagProperty(state) || readAnchorProperty(state)) {
|
|---|
| 2342 | if (skipSeparationSpace(state, true, -1)) {
|
|---|
| 2343 | atNewLine = true;
|
|---|
| 2344 | allowBlockCollections = allowBlockStyles;
|
|---|
| 2345 |
|
|---|
| 2346 | if (state.lineIndent > parentIndent) {
|
|---|
| 2347 | indentStatus = 1;
|
|---|
| 2348 | } else if (state.lineIndent === parentIndent) {
|
|---|
| 2349 | indentStatus = 0;
|
|---|
| 2350 | } else if (state.lineIndent < parentIndent) {
|
|---|
| 2351 | indentStatus = -1;
|
|---|
| 2352 | }
|
|---|
| 2353 | } else {
|
|---|
| 2354 | allowBlockCollections = false;
|
|---|
| 2355 | }
|
|---|
| 2356 | }
|
|---|
| 2357 | }
|
|---|
| 2358 |
|
|---|
| 2359 | if (allowBlockCollections) {
|
|---|
| 2360 | allowBlockCollections = atNewLine || allowCompact;
|
|---|
| 2361 | }
|
|---|
| 2362 |
|
|---|
| 2363 | if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
|
|---|
| 2364 | if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
|
|---|
| 2365 | flowIndent = parentIndent;
|
|---|
| 2366 | } else {
|
|---|
| 2367 | flowIndent = parentIndent + 1;
|
|---|
| 2368 | }
|
|---|
| 2369 |
|
|---|
| 2370 | blockIndent = state.position - state.lineStart;
|
|---|
| 2371 |
|
|---|
| 2372 | if (indentStatus === 1) {
|
|---|
| 2373 | if (allowBlockCollections &&
|
|---|
| 2374 | (readBlockSequence(state, blockIndent) ||
|
|---|
| 2375 | readBlockMapping(state, blockIndent, flowIndent)) ||
|
|---|
| 2376 | readFlowCollection(state, flowIndent)) {
|
|---|
| 2377 | hasContent = true;
|
|---|
| 2378 | } else {
|
|---|
| 2379 | if ((allowBlockScalars && readBlockScalar(state, flowIndent)) ||
|
|---|
| 2380 | readSingleQuotedScalar(state, flowIndent) ||
|
|---|
| 2381 | readDoubleQuotedScalar(state, flowIndent)) {
|
|---|
| 2382 | hasContent = true;
|
|---|
| 2383 |
|
|---|
| 2384 | } else if (readAlias(state)) {
|
|---|
| 2385 | hasContent = true;
|
|---|
| 2386 |
|
|---|
| 2387 | if (state.tag !== null || state.anchor !== null) {
|
|---|
| 2388 | throwError(state, 'alias node should not have any properties');
|
|---|
| 2389 | }
|
|---|
| 2390 |
|
|---|
| 2391 | } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
|---|
| 2392 | hasContent = true;
|
|---|
| 2393 |
|
|---|
| 2394 | if (state.tag === null) {
|
|---|
| 2395 | state.tag = '?';
|
|---|
| 2396 | }
|
|---|
| 2397 | }
|
|---|
| 2398 |
|
|---|
| 2399 | if (state.anchor !== null) {
|
|---|
| 2400 | state.anchorMap[state.anchor] = state.result;
|
|---|
| 2401 | }
|
|---|
| 2402 | }
|
|---|
| 2403 | } else if (indentStatus === 0) {
|
|---|
| 2404 | // Special case: block sequences are allowed to have same indentation level as the parent.
|
|---|
| 2405 | // http://www.yaml.org/spec/1.2/spec.html#id2799784
|
|---|
| 2406 | hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
|
|---|
| 2407 | }
|
|---|
| 2408 | }
|
|---|
| 2409 |
|
|---|
| 2410 | if (state.tag !== null && state.tag !== '!') {
|
|---|
| 2411 | if (state.tag === '?') {
|
|---|
| 2412 | // Implicit resolving is not allowed for non-scalar types, and '?'
|
|---|
| 2413 | // non-specific tag is only automatically assigned to plain scalars.
|
|---|
| 2414 | //
|
|---|
| 2415 | // We only need to check kind conformity in case user explicitly assigns '?'
|
|---|
| 2416 | // tag, for example like this: "!<?> [0]"
|
|---|
| 2417 | //
|
|---|
| 2418 | if (state.result !== null && state.kind !== 'scalar') {
|
|---|
| 2419 | throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
|
|---|
| 2420 | }
|
|---|
| 2421 |
|
|---|
| 2422 | for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
|
|---|
| 2423 | type = state.implicitTypes[typeIndex];
|
|---|
| 2424 |
|
|---|
| 2425 | if (type.resolve(state.result)) { // `state.result` updated in resolver if matched
|
|---|
| 2426 | state.result = type.construct(state.result);
|
|---|
| 2427 | state.tag = type.tag;
|
|---|
| 2428 | if (state.anchor !== null) {
|
|---|
| 2429 | state.anchorMap[state.anchor] = state.result;
|
|---|
| 2430 | }
|
|---|
| 2431 | break;
|
|---|
| 2432 | }
|
|---|
| 2433 | }
|
|---|
| 2434 | } else if (_hasOwnProperty.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
|
|---|
| 2435 | type = state.typeMap[state.kind || 'fallback'][state.tag];
|
|---|
| 2436 |
|
|---|
| 2437 | if (state.result !== null && type.kind !== state.kind) {
|
|---|
| 2438 | throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
|
|---|
| 2439 | }
|
|---|
| 2440 |
|
|---|
| 2441 | if (!type.resolve(state.result)) { // `state.result` updated in resolver if matched
|
|---|
| 2442 | throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
|
|---|
| 2443 | } else {
|
|---|
| 2444 | state.result = type.construct(state.result);
|
|---|
| 2445 | if (state.anchor !== null) {
|
|---|
| 2446 | state.anchorMap[state.anchor] = state.result;
|
|---|
| 2447 | }
|
|---|
| 2448 | }
|
|---|
| 2449 | } else {
|
|---|
| 2450 | throwError(state, 'unknown tag !<' + state.tag + '>');
|
|---|
| 2451 | }
|
|---|
| 2452 | }
|
|---|
| 2453 |
|
|---|
| 2454 | if (state.listener !== null) {
|
|---|
| 2455 | state.listener('close', state);
|
|---|
| 2456 | }
|
|---|
| 2457 | return state.tag !== null || state.anchor !== null || hasContent;
|
|---|
| 2458 | }
|
|---|
| 2459 |
|
|---|
| 2460 | function readDocument(state) {
|
|---|
| 2461 | var documentStart = state.position,
|
|---|
| 2462 | _position,
|
|---|
| 2463 | directiveName,
|
|---|
| 2464 | directiveArgs,
|
|---|
| 2465 | hasDirectives = false,
|
|---|
| 2466 | ch;
|
|---|
| 2467 |
|
|---|
| 2468 | state.version = null;
|
|---|
| 2469 | state.checkLineBreaks = state.legacy;
|
|---|
| 2470 | state.tagMap = {};
|
|---|
| 2471 | state.anchorMap = {};
|
|---|
| 2472 |
|
|---|
| 2473 | while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
|---|
| 2474 | skipSeparationSpace(state, true, -1);
|
|---|
| 2475 |
|
|---|
| 2476 | ch = state.input.charCodeAt(state.position);
|
|---|
| 2477 |
|
|---|
| 2478 | if (state.lineIndent > 0 || ch !== 0x25/* % */) {
|
|---|
| 2479 | break;
|
|---|
| 2480 | }
|
|---|
| 2481 |
|
|---|
| 2482 | hasDirectives = true;
|
|---|
| 2483 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2484 | _position = state.position;
|
|---|
| 2485 |
|
|---|
| 2486 | while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|---|
| 2487 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2488 | }
|
|---|
| 2489 |
|
|---|
| 2490 | directiveName = state.input.slice(_position, state.position);
|
|---|
| 2491 | directiveArgs = [];
|
|---|
| 2492 |
|
|---|
| 2493 | if (directiveName.length < 1) {
|
|---|
| 2494 | throwError(state, 'directive name must not be less than one character in length');
|
|---|
| 2495 | }
|
|---|
| 2496 |
|
|---|
| 2497 | while (ch !== 0) {
|
|---|
| 2498 | while (is_WHITE_SPACE(ch)) {
|
|---|
| 2499 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2500 | }
|
|---|
| 2501 |
|
|---|
| 2502 | if (ch === 0x23/* # */) {
|
|---|
| 2503 | do { ch = state.input.charCodeAt(++state.position); }
|
|---|
| 2504 | while (ch !== 0 && !is_EOL(ch));
|
|---|
| 2505 | break;
|
|---|
| 2506 | }
|
|---|
| 2507 |
|
|---|
| 2508 | if (is_EOL(ch)) break;
|
|---|
| 2509 |
|
|---|
| 2510 | _position = state.position;
|
|---|
| 2511 |
|
|---|
| 2512 | while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
|---|
| 2513 | ch = state.input.charCodeAt(++state.position);
|
|---|
| 2514 | }
|
|---|
| 2515 |
|
|---|
| 2516 | directiveArgs.push(state.input.slice(_position, state.position));
|
|---|
| 2517 | }
|
|---|
| 2518 |
|
|---|
| 2519 | if (ch !== 0) readLineBreak(state);
|
|---|
| 2520 |
|
|---|
| 2521 | if (_hasOwnProperty.call(directiveHandlers, directiveName)) {
|
|---|
| 2522 | directiveHandlers[directiveName](state, directiveName, directiveArgs);
|
|---|
| 2523 | } else {
|
|---|
| 2524 | throwWarning(state, 'unknown document directive "' + directiveName + '"');
|
|---|
| 2525 | }
|
|---|
| 2526 | }
|
|---|
| 2527 |
|
|---|
| 2528 | skipSeparationSpace(state, true, -1);
|
|---|
| 2529 |
|
|---|
| 2530 | if (state.lineIndent === 0 &&
|
|---|
| 2531 | state.input.charCodeAt(state.position) === 0x2D/* - */ &&
|
|---|
| 2532 | state.input.charCodeAt(state.position + 1) === 0x2D/* - */ &&
|
|---|
| 2533 | state.input.charCodeAt(state.position + 2) === 0x2D/* - */) {
|
|---|
| 2534 | state.position += 3;
|
|---|
| 2535 | skipSeparationSpace(state, true, -1);
|
|---|
| 2536 |
|
|---|
| 2537 | } else if (hasDirectives) {
|
|---|
| 2538 | throwError(state, 'directives end mark is expected');
|
|---|
| 2539 | }
|
|---|
| 2540 |
|
|---|
| 2541 | composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
|---|
| 2542 | skipSeparationSpace(state, true, -1);
|
|---|
| 2543 |
|
|---|
| 2544 | if (state.checkLineBreaks &&
|
|---|
| 2545 | PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
|---|
| 2546 | throwWarning(state, 'non-ASCII line breaks are interpreted as content');
|
|---|
| 2547 | }
|
|---|
| 2548 |
|
|---|
| 2549 | state.documents.push(state.result);
|
|---|
| 2550 |
|
|---|
| 2551 | if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|---|
| 2552 |
|
|---|
| 2553 | if (state.input.charCodeAt(state.position) === 0x2E/* . */) {
|
|---|
| 2554 | state.position += 3;
|
|---|
| 2555 | skipSeparationSpace(state, true, -1);
|
|---|
| 2556 | }
|
|---|
| 2557 | return;
|
|---|
| 2558 | }
|
|---|
| 2559 |
|
|---|
| 2560 | if (state.position < (state.length - 1)) {
|
|---|
| 2561 | throwError(state, 'end of the stream or a document separator is expected');
|
|---|
| 2562 | } else {
|
|---|
| 2563 | return;
|
|---|
| 2564 | }
|
|---|
| 2565 | }
|
|---|
| 2566 |
|
|---|
| 2567 |
|
|---|
| 2568 | function loadDocuments(input, options) {
|
|---|
| 2569 | input = String(input);
|
|---|
| 2570 | options = options || {};
|
|---|
| 2571 |
|
|---|
| 2572 | if (input.length !== 0) {
|
|---|
| 2573 |
|
|---|
| 2574 | // Add tailing `\n` if not exists
|
|---|
| 2575 | if (input.charCodeAt(input.length - 1) !== 0x0A/* LF */ &&
|
|---|
| 2576 | input.charCodeAt(input.length - 1) !== 0x0D/* CR */) {
|
|---|
| 2577 | input += '\n';
|
|---|
| 2578 | }
|
|---|
| 2579 |
|
|---|
| 2580 | // Strip BOM
|
|---|
| 2581 | if (input.charCodeAt(0) === 0xFEFF) {
|
|---|
| 2582 | input = input.slice(1);
|
|---|
| 2583 | }
|
|---|
| 2584 | }
|
|---|
| 2585 |
|
|---|
| 2586 | var state = new State(input, options);
|
|---|
| 2587 |
|
|---|
| 2588 | var nullpos = input.indexOf('\0');
|
|---|
| 2589 |
|
|---|
| 2590 | if (nullpos !== -1) {
|
|---|
| 2591 | state.position = nullpos;
|
|---|
| 2592 | throwError(state, 'null byte is not allowed in input');
|
|---|
| 2593 | }
|
|---|
| 2594 |
|
|---|
| 2595 | // Use 0 as string terminator. That significantly simplifies bounds check.
|
|---|
| 2596 | state.input += '\0';
|
|---|
| 2597 |
|
|---|
| 2598 | while (state.input.charCodeAt(state.position) === 0x20/* Space */) {
|
|---|
| 2599 | state.lineIndent += 1;
|
|---|
| 2600 | state.position += 1;
|
|---|
| 2601 | }
|
|---|
| 2602 |
|
|---|
| 2603 | while (state.position < (state.length - 1)) {
|
|---|
| 2604 | readDocument(state);
|
|---|
| 2605 | }
|
|---|
| 2606 |
|
|---|
| 2607 | return state.documents;
|
|---|
| 2608 | }
|
|---|
| 2609 |
|
|---|
| 2610 |
|
|---|
| 2611 | function loadAll(input, iterator, options) {
|
|---|
| 2612 | if (iterator !== null && typeof iterator === 'object' && typeof options === 'undefined') {
|
|---|
| 2613 | options = iterator;
|
|---|
| 2614 | iterator = null;
|
|---|
| 2615 | }
|
|---|
| 2616 |
|
|---|
| 2617 | var documents = loadDocuments(input, options);
|
|---|
| 2618 |
|
|---|
| 2619 | if (typeof iterator !== 'function') {
|
|---|
| 2620 | return documents;
|
|---|
| 2621 | }
|
|---|
| 2622 |
|
|---|
| 2623 | for (var index = 0, length = documents.length; index < length; index += 1) {
|
|---|
| 2624 | iterator(documents[index]);
|
|---|
| 2625 | }
|
|---|
| 2626 | }
|
|---|
| 2627 |
|
|---|
| 2628 |
|
|---|
| 2629 | function load(input, options) {
|
|---|
| 2630 | var documents = loadDocuments(input, options);
|
|---|
| 2631 |
|
|---|
| 2632 | if (documents.length === 0) {
|
|---|
| 2633 | /*eslint-disable no-undefined*/
|
|---|
| 2634 | return undefined;
|
|---|
| 2635 | } else if (documents.length === 1) {
|
|---|
| 2636 | return documents[0];
|
|---|
| 2637 | }
|
|---|
| 2638 | throw new YAMLException('expected a single document in the stream, but found more');
|
|---|
| 2639 | }
|
|---|
| 2640 |
|
|---|
| 2641 |
|
|---|
| 2642 | function safeLoadAll(input, iterator, options) {
|
|---|
| 2643 | if (typeof iterator === 'object' && iterator !== null && typeof options === 'undefined') {
|
|---|
| 2644 | options = iterator;
|
|---|
| 2645 | iterator = null;
|
|---|
| 2646 | }
|
|---|
| 2647 |
|
|---|
| 2648 | return loadAll(input, iterator, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
|
|---|
| 2649 | }
|
|---|
| 2650 |
|
|---|
| 2651 |
|
|---|
| 2652 | function safeLoad(input, options) {
|
|---|
| 2653 | return load(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
|
|---|
| 2654 | }
|
|---|
| 2655 |
|
|---|
| 2656 |
|
|---|
| 2657 | module.exports.loadAll = loadAll;
|
|---|
| 2658 | module.exports.load = load;
|
|---|
| 2659 | module.exports.safeLoadAll = safeLoadAll;
|
|---|
| 2660 | module.exports.safeLoad = safeLoad;
|
|---|
| 2661 |
|
|---|
| 2662 | },{"./common":2,"./exception":4,"./mark":6,"./schema/default_full":9,"./schema/default_safe":10}],6:[function(require,module,exports){
|
|---|
| 2663 | 'use strict';
|
|---|
| 2664 |
|
|---|
| 2665 |
|
|---|
| 2666 | var common = require('./common');
|
|---|
| 2667 |
|
|---|
| 2668 |
|
|---|
| 2669 | function Mark(name, buffer, position, line, column) {
|
|---|
| 2670 | this.name = name;
|
|---|
| 2671 | this.buffer = buffer;
|
|---|
| 2672 | this.position = position;
|
|---|
| 2673 | this.line = line;
|
|---|
| 2674 | this.column = column;
|
|---|
| 2675 | }
|
|---|
| 2676 |
|
|---|
| 2677 |
|
|---|
| 2678 | Mark.prototype.getSnippet = function getSnippet(indent, maxLength) {
|
|---|
| 2679 | var head, start, tail, end, snippet;
|
|---|
| 2680 |
|
|---|
| 2681 | if (!this.buffer) return null;
|
|---|
| 2682 |
|
|---|
| 2683 | indent = indent || 4;
|
|---|
| 2684 | maxLength = maxLength || 75;
|
|---|
| 2685 |
|
|---|
| 2686 | head = '';
|
|---|
| 2687 | start = this.position;
|
|---|
| 2688 |
|
|---|
| 2689 | while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
|
|---|
| 2690 | start -= 1;
|
|---|
| 2691 | if (this.position - start > (maxLength / 2 - 1)) {
|
|---|
| 2692 | head = ' ... ';
|
|---|
| 2693 | start += 5;
|
|---|
| 2694 | break;
|
|---|
| 2695 | }
|
|---|
| 2696 | }
|
|---|
| 2697 |
|
|---|
| 2698 | tail = '';
|
|---|
| 2699 | end = this.position;
|
|---|
| 2700 |
|
|---|
| 2701 | while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
|
|---|
| 2702 | end += 1;
|
|---|
| 2703 | if (end - this.position > (maxLength / 2 - 1)) {
|
|---|
| 2704 | tail = ' ... ';
|
|---|
| 2705 | end -= 5;
|
|---|
| 2706 | break;
|
|---|
| 2707 | }
|
|---|
| 2708 | }
|
|---|
| 2709 |
|
|---|
| 2710 | snippet = this.buffer.slice(start, end);
|
|---|
| 2711 |
|
|---|
| 2712 | return common.repeat(' ', indent) + head + snippet + tail + '\n' +
|
|---|
| 2713 | common.repeat(' ', indent + this.position - start + head.length) + '^';
|
|---|
| 2714 | };
|
|---|
| 2715 |
|
|---|
| 2716 |
|
|---|
| 2717 | Mark.prototype.toString = function toString(compact) {
|
|---|
| 2718 | var snippet, where = '';
|
|---|
| 2719 |
|
|---|
| 2720 | if (this.name) {
|
|---|
| 2721 | where += 'in "' + this.name + '" ';
|
|---|
| 2722 | }
|
|---|
| 2723 |
|
|---|
| 2724 | where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
|
|---|
| 2725 |
|
|---|
| 2726 | if (!compact) {
|
|---|
| 2727 | snippet = this.getSnippet();
|
|---|
| 2728 |
|
|---|
| 2729 | if (snippet) {
|
|---|
| 2730 | where += ':\n' + snippet;
|
|---|
| 2731 | }
|
|---|
| 2732 | }
|
|---|
| 2733 |
|
|---|
| 2734 | return where;
|
|---|
| 2735 | };
|
|---|
| 2736 |
|
|---|
| 2737 |
|
|---|
| 2738 | module.exports = Mark;
|
|---|
| 2739 |
|
|---|
| 2740 | },{"./common":2}],7:[function(require,module,exports){
|
|---|
| 2741 | 'use strict';
|
|---|
| 2742 |
|
|---|
| 2743 | /*eslint-disable max-len*/
|
|---|
| 2744 |
|
|---|
| 2745 | var common = require('./common');
|
|---|
| 2746 | var YAMLException = require('./exception');
|
|---|
| 2747 | var Type = require('./type');
|
|---|
| 2748 |
|
|---|
| 2749 |
|
|---|
| 2750 | function compileList(schema, name, result) {
|
|---|
| 2751 | var exclude = [];
|
|---|
| 2752 |
|
|---|
| 2753 | schema.include.forEach(function (includedSchema) {
|
|---|
| 2754 | result = compileList(includedSchema, name, result);
|
|---|
| 2755 | });
|
|---|
| 2756 |
|
|---|
| 2757 | schema[name].forEach(function (currentType) {
|
|---|
| 2758 | result.forEach(function (previousType, previousIndex) {
|
|---|
| 2759 | if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) {
|
|---|
| 2760 | exclude.push(previousIndex);
|
|---|
| 2761 | }
|
|---|
| 2762 | });
|
|---|
| 2763 |
|
|---|
| 2764 | result.push(currentType);
|
|---|
| 2765 | });
|
|---|
| 2766 |
|
|---|
| 2767 | return result.filter(function (type, index) {
|
|---|
| 2768 | return exclude.indexOf(index) === -1;
|
|---|
| 2769 | });
|
|---|
| 2770 | }
|
|---|
| 2771 |
|
|---|
| 2772 |
|
|---|
| 2773 | function compileMap(/* lists... */) {
|
|---|
| 2774 | var result = {
|
|---|
| 2775 | scalar: {},
|
|---|
| 2776 | sequence: {},
|
|---|
| 2777 | mapping: {},
|
|---|
| 2778 | fallback: {}
|
|---|
| 2779 | }, index, length;
|
|---|
| 2780 |
|
|---|
| 2781 | function collectType(type) {
|
|---|
| 2782 | result[type.kind][type.tag] = result['fallback'][type.tag] = type;
|
|---|
| 2783 | }
|
|---|
| 2784 |
|
|---|
| 2785 | for (index = 0, length = arguments.length; index < length; index += 1) {
|
|---|
| 2786 | arguments[index].forEach(collectType);
|
|---|
| 2787 | }
|
|---|
| 2788 | return result;
|
|---|
| 2789 | }
|
|---|
| 2790 |
|
|---|
| 2791 |
|
|---|
| 2792 | function Schema(definition) {
|
|---|
| 2793 | this.include = definition.include || [];
|
|---|
| 2794 | this.implicit = definition.implicit || [];
|
|---|
| 2795 | this.explicit = definition.explicit || [];
|
|---|
| 2796 |
|
|---|
| 2797 | this.implicit.forEach(function (type) {
|
|---|
| 2798 | if (type.loadKind && type.loadKind !== 'scalar') {
|
|---|
| 2799 | throw new YAMLException('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
|
|---|
| 2800 | }
|
|---|
| 2801 | });
|
|---|
| 2802 |
|
|---|
| 2803 | this.compiledImplicit = compileList(this, 'implicit', []);
|
|---|
| 2804 | this.compiledExplicit = compileList(this, 'explicit', []);
|
|---|
| 2805 | this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
|
|---|
| 2806 | }
|
|---|
| 2807 |
|
|---|
| 2808 |
|
|---|
| 2809 | Schema.DEFAULT = null;
|
|---|
| 2810 |
|
|---|
| 2811 |
|
|---|
| 2812 | Schema.create = function createSchema() {
|
|---|
| 2813 | var schemas, types;
|
|---|
| 2814 |
|
|---|
| 2815 | switch (arguments.length) {
|
|---|
| 2816 | case 1:
|
|---|
| 2817 | schemas = Schema.DEFAULT;
|
|---|
| 2818 | types = arguments[0];
|
|---|
| 2819 | break;
|
|---|
| 2820 |
|
|---|
| 2821 | case 2:
|
|---|
| 2822 | schemas = arguments[0];
|
|---|
| 2823 | types = arguments[1];
|
|---|
| 2824 | break;
|
|---|
| 2825 |
|
|---|
| 2826 | default:
|
|---|
| 2827 | throw new YAMLException('Wrong number of arguments for Schema.create function');
|
|---|
| 2828 | }
|
|---|
| 2829 |
|
|---|
| 2830 | schemas = common.toArray(schemas);
|
|---|
| 2831 | types = common.toArray(types);
|
|---|
| 2832 |
|
|---|
| 2833 | if (!schemas.every(function (schema) { return schema instanceof Schema; })) {
|
|---|
| 2834 | throw new YAMLException('Specified list of super schemas (or a single Schema object) contains a non-Schema object.');
|
|---|
| 2835 | }
|
|---|
| 2836 |
|
|---|
| 2837 | if (!types.every(function (type) { return type instanceof Type; })) {
|
|---|
| 2838 | throw new YAMLException('Specified list of YAML types (or a single Type object) contains a non-Type object.');
|
|---|
| 2839 | }
|
|---|
| 2840 |
|
|---|
| 2841 | return new Schema({
|
|---|
| 2842 | include: schemas,
|
|---|
| 2843 | explicit: types
|
|---|
| 2844 | });
|
|---|
| 2845 | };
|
|---|
| 2846 |
|
|---|
| 2847 |
|
|---|
| 2848 | module.exports = Schema;
|
|---|
| 2849 |
|
|---|
| 2850 | },{"./common":2,"./exception":4,"./type":13}],8:[function(require,module,exports){
|
|---|
| 2851 | // Standard YAML's Core schema.
|
|---|
| 2852 | // http://www.yaml.org/spec/1.2/spec.html#id2804923
|
|---|
| 2853 | //
|
|---|
| 2854 | // NOTE: JS-YAML does not support schema-specific tag resolution restrictions.
|
|---|
| 2855 | // So, Core schema has no distinctions from JSON schema is JS-YAML.
|
|---|
| 2856 |
|
|---|
| 2857 |
|
|---|
| 2858 | 'use strict';
|
|---|
| 2859 |
|
|---|
| 2860 |
|
|---|
| 2861 | var Schema = require('../schema');
|
|---|
| 2862 |
|
|---|
| 2863 |
|
|---|
| 2864 | module.exports = new Schema({
|
|---|
| 2865 | include: [
|
|---|
| 2866 | require('./json')
|
|---|
| 2867 | ]
|
|---|
| 2868 | });
|
|---|
| 2869 |
|
|---|
| 2870 | },{"../schema":7,"./json":12}],9:[function(require,module,exports){
|
|---|
| 2871 | // JS-YAML's default schema for `load` function.
|
|---|
| 2872 | // It is not described in the YAML specification.
|
|---|
| 2873 | //
|
|---|
| 2874 | // This schema is based on JS-YAML's default safe schema and includes
|
|---|
| 2875 | // JavaScript-specific types: !!js/undefined, !!js/regexp and !!js/function.
|
|---|
| 2876 | //
|
|---|
| 2877 | // Also this schema is used as default base schema at `Schema.create` function.
|
|---|
| 2878 |
|
|---|
| 2879 |
|
|---|
| 2880 | 'use strict';
|
|---|
| 2881 |
|
|---|
| 2882 |
|
|---|
| 2883 | var Schema = require('../schema');
|
|---|
| 2884 |
|
|---|
| 2885 |
|
|---|
| 2886 | module.exports = Schema.DEFAULT = new Schema({
|
|---|
| 2887 | include: [
|
|---|
| 2888 | require('./default_safe')
|
|---|
| 2889 | ],
|
|---|
| 2890 | explicit: [
|
|---|
| 2891 | require('../type/js/undefined'),
|
|---|
| 2892 | require('../type/js/regexp'),
|
|---|
| 2893 | require('../type/js/function')
|
|---|
| 2894 | ]
|
|---|
| 2895 | });
|
|---|
| 2896 |
|
|---|
| 2897 | },{"../schema":7,"../type/js/function":18,"../type/js/regexp":19,"../type/js/undefined":20,"./default_safe":10}],10:[function(require,module,exports){
|
|---|
| 2898 | // JS-YAML's default schema for `safeLoad` function.
|
|---|
| 2899 | // It is not described in the YAML specification.
|
|---|
| 2900 | //
|
|---|
| 2901 | // This schema is based on standard YAML's Core schema and includes most of
|
|---|
| 2902 | // extra types described at YAML tag repository. (http://yaml.org/type/)
|
|---|
| 2903 |
|
|---|
| 2904 |
|
|---|
| 2905 | 'use strict';
|
|---|
| 2906 |
|
|---|
| 2907 |
|
|---|
| 2908 | var Schema = require('../schema');
|
|---|
| 2909 |
|
|---|
| 2910 |
|
|---|
| 2911 | module.exports = new Schema({
|
|---|
| 2912 | include: [
|
|---|
| 2913 | require('./core')
|
|---|
| 2914 | ],
|
|---|
| 2915 | implicit: [
|
|---|
| 2916 | require('../type/timestamp'),
|
|---|
| 2917 | require('../type/merge')
|
|---|
| 2918 | ],
|
|---|
| 2919 | explicit: [
|
|---|
| 2920 | require('../type/binary'),
|
|---|
| 2921 | require('../type/omap'),
|
|---|
| 2922 | require('../type/pairs'),
|
|---|
| 2923 | require('../type/set')
|
|---|
| 2924 | ]
|
|---|
| 2925 | });
|
|---|
| 2926 |
|
|---|
| 2927 | },{"../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){
|
|---|
| 2928 | // Standard YAML's Failsafe schema.
|
|---|
| 2929 | // http://www.yaml.org/spec/1.2/spec.html#id2802346
|
|---|
| 2930 |
|
|---|
| 2931 |
|
|---|
| 2932 | 'use strict';
|
|---|
| 2933 |
|
|---|
| 2934 |
|
|---|
| 2935 | var Schema = require('../schema');
|
|---|
| 2936 |
|
|---|
| 2937 |
|
|---|
| 2938 | module.exports = new Schema({
|
|---|
| 2939 | explicit: [
|
|---|
| 2940 | require('../type/str'),
|
|---|
| 2941 | require('../type/seq'),
|
|---|
| 2942 | require('../type/map')
|
|---|
| 2943 | ]
|
|---|
| 2944 | });
|
|---|
| 2945 |
|
|---|
| 2946 | },{"../schema":7,"../type/map":21,"../type/seq":26,"../type/str":28}],12:[function(require,module,exports){
|
|---|
| 2947 | // Standard YAML's JSON schema.
|
|---|
| 2948 | // http://www.yaml.org/spec/1.2/spec.html#id2803231
|
|---|
| 2949 | //
|
|---|
| 2950 | // NOTE: JS-YAML does not support schema-specific tag resolution restrictions.
|
|---|
| 2951 | // So, this schema is not such strict as defined in the YAML specification.
|
|---|
| 2952 | // It allows numbers in binary notaion, use `Null` and `NULL` as `null`, etc.
|
|---|
| 2953 |
|
|---|
| 2954 |
|
|---|
| 2955 | 'use strict';
|
|---|
| 2956 |
|
|---|
| 2957 |
|
|---|
| 2958 | var Schema = require('../schema');
|
|---|
| 2959 |
|
|---|
| 2960 |
|
|---|
| 2961 | module.exports = new Schema({
|
|---|
| 2962 | include: [
|
|---|
| 2963 | require('./failsafe')
|
|---|
| 2964 | ],
|
|---|
| 2965 | implicit: [
|
|---|
| 2966 | require('../type/null'),
|
|---|
| 2967 | require('../type/bool'),
|
|---|
| 2968 | require('../type/int'),
|
|---|
| 2969 | require('../type/float')
|
|---|
| 2970 | ]
|
|---|
| 2971 | });
|
|---|
| 2972 |
|
|---|
| 2973 | },{"../schema":7,"../type/bool":15,"../type/float":16,"../type/int":17,"../type/null":23,"./failsafe":11}],13:[function(require,module,exports){
|
|---|
| 2974 | 'use strict';
|
|---|
| 2975 |
|
|---|
| 2976 | var YAMLException = require('./exception');
|
|---|
| 2977 |
|
|---|
| 2978 | var TYPE_CONSTRUCTOR_OPTIONS = [
|
|---|
| 2979 | 'kind',
|
|---|
| 2980 | 'resolve',
|
|---|
| 2981 | 'construct',
|
|---|
| 2982 | 'instanceOf',
|
|---|
| 2983 | 'predicate',
|
|---|
| 2984 | 'represent',
|
|---|
| 2985 | 'defaultStyle',
|
|---|
| 2986 | 'styleAliases'
|
|---|
| 2987 | ];
|
|---|
| 2988 |
|
|---|
| 2989 | var YAML_NODE_KINDS = [
|
|---|
| 2990 | 'scalar',
|
|---|
| 2991 | 'sequence',
|
|---|
| 2992 | 'mapping'
|
|---|
| 2993 | ];
|
|---|
| 2994 |
|
|---|
| 2995 | function compileStyleAliases(map) {
|
|---|
| 2996 | var result = {};
|
|---|
| 2997 |
|
|---|
| 2998 | if (map !== null) {
|
|---|
| 2999 | Object.keys(map).forEach(function (style) {
|
|---|
| 3000 | map[style].forEach(function (alias) {
|
|---|
| 3001 | result[String(alias)] = style;
|
|---|
| 3002 | });
|
|---|
| 3003 | });
|
|---|
| 3004 | }
|
|---|
| 3005 |
|
|---|
| 3006 | return result;
|
|---|
| 3007 | }
|
|---|
| 3008 |
|
|---|
| 3009 | function Type(tag, options) {
|
|---|
| 3010 | options = options || {};
|
|---|
| 3011 |
|
|---|
| 3012 | Object.keys(options).forEach(function (name) {
|
|---|
| 3013 | if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
|
|---|
| 3014 | throw new YAMLException('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
|
|---|
| 3015 | }
|
|---|
| 3016 | });
|
|---|
| 3017 |
|
|---|
| 3018 | // TODO: Add tag format check.
|
|---|
| 3019 | this.tag = tag;
|
|---|
| 3020 | this.kind = options['kind'] || null;
|
|---|
| 3021 | this.resolve = options['resolve'] || function () { return true; };
|
|---|
| 3022 | this.construct = options['construct'] || function (data) { return data; };
|
|---|
| 3023 | this.instanceOf = options['instanceOf'] || null;
|
|---|
| 3024 | this.predicate = options['predicate'] || null;
|
|---|
| 3025 | this.represent = options['represent'] || null;
|
|---|
| 3026 | this.defaultStyle = options['defaultStyle'] || null;
|
|---|
| 3027 | this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
|
|---|
| 3028 |
|
|---|
| 3029 | if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
|---|
| 3030 | throw new YAMLException('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
|---|
| 3031 | }
|
|---|
| 3032 | }
|
|---|
| 3033 |
|
|---|
| 3034 | module.exports = Type;
|
|---|
| 3035 |
|
|---|
| 3036 | },{"./exception":4}],14:[function(require,module,exports){
|
|---|
| 3037 | 'use strict';
|
|---|
| 3038 |
|
|---|
| 3039 | /*eslint-disable no-bitwise*/
|
|---|
| 3040 |
|
|---|
| 3041 | var NodeBuffer;
|
|---|
| 3042 |
|
|---|
| 3043 | try {
|
|---|
| 3044 | // A trick for browserified version, to not include `Buffer` shim
|
|---|
| 3045 | var _require = require;
|
|---|
| 3046 | NodeBuffer = _require('buffer').Buffer;
|
|---|
| 3047 | } catch (__) {}
|
|---|
| 3048 |
|
|---|
| 3049 | var Type = require('../type');
|
|---|
| 3050 |
|
|---|
| 3051 |
|
|---|
| 3052 | // [ 64, 65, 66 ] -> [ padding, CR, LF ]
|
|---|
| 3053 | var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
|
|---|
| 3054 |
|
|---|
| 3055 |
|
|---|
| 3056 | function resolveYamlBinary(data) {
|
|---|
| 3057 | if (data === null) return false;
|
|---|
| 3058 |
|
|---|
| 3059 | var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
|
|---|
| 3060 |
|
|---|
| 3061 | // Convert one by one.
|
|---|
| 3062 | for (idx = 0; idx < max; idx++) {
|
|---|
| 3063 | code = map.indexOf(data.charAt(idx));
|
|---|
| 3064 |
|
|---|
| 3065 | // Skip CR/LF
|
|---|
| 3066 | if (code > 64) continue;
|
|---|
| 3067 |
|
|---|
| 3068 | // Fail on illegal characters
|
|---|
| 3069 | if (code < 0) return false;
|
|---|
| 3070 |
|
|---|
| 3071 | bitlen += 6;
|
|---|
| 3072 | }
|
|---|
| 3073 |
|
|---|
| 3074 | // If there are any bits left, source was corrupted
|
|---|
| 3075 | return (bitlen % 8) === 0;
|
|---|
| 3076 | }
|
|---|
| 3077 |
|
|---|
| 3078 | function constructYamlBinary(data) {
|
|---|
| 3079 | var idx, tailbits,
|
|---|
| 3080 | input = data.replace(/[\r\n=]/g, ''), // remove CR/LF & padding to simplify scan
|
|---|
| 3081 | max = input.length,
|
|---|
| 3082 | map = BASE64_MAP,
|
|---|
| 3083 | bits = 0,
|
|---|
| 3084 | result = [];
|
|---|
| 3085 |
|
|---|
| 3086 | // Collect by 6*4 bits (3 bytes)
|
|---|
| 3087 |
|
|---|
| 3088 | for (idx = 0; idx < max; idx++) {
|
|---|
| 3089 | if ((idx % 4 === 0) && idx) {
|
|---|
| 3090 | result.push((bits >> 16) & 0xFF);
|
|---|
| 3091 | result.push((bits >> 8) & 0xFF);
|
|---|
| 3092 | result.push(bits & 0xFF);
|
|---|
| 3093 | }
|
|---|
| 3094 |
|
|---|
| 3095 | bits = (bits << 6) | map.indexOf(input.charAt(idx));
|
|---|
| 3096 | }
|
|---|
| 3097 |
|
|---|
| 3098 | // Dump tail
|
|---|
| 3099 |
|
|---|
| 3100 | tailbits = (max % 4) * 6;
|
|---|
| 3101 |
|
|---|
| 3102 | if (tailbits === 0) {
|
|---|
| 3103 | result.push((bits >> 16) & 0xFF);
|
|---|
| 3104 | result.push((bits >> 8) & 0xFF);
|
|---|
| 3105 | result.push(bits & 0xFF);
|
|---|
| 3106 | } else if (tailbits === 18) {
|
|---|
| 3107 | result.push((bits >> 10) & 0xFF);
|
|---|
| 3108 | result.push((bits >> 2) & 0xFF);
|
|---|
| 3109 | } else if (tailbits === 12) {
|
|---|
| 3110 | result.push((bits >> 4) & 0xFF);
|
|---|
| 3111 | }
|
|---|
| 3112 |
|
|---|
| 3113 | // Wrap into Buffer for NodeJS and leave Array for browser
|
|---|
| 3114 | if (NodeBuffer) {
|
|---|
| 3115 | // Support node 6.+ Buffer API when available
|
|---|
| 3116 | return NodeBuffer.from ? NodeBuffer.from(result) : new NodeBuffer(result);
|
|---|
| 3117 | }
|
|---|
| 3118 |
|
|---|
| 3119 | return result;
|
|---|
| 3120 | }
|
|---|
| 3121 |
|
|---|
| 3122 | function representYamlBinary(object /*, style*/) {
|
|---|
| 3123 | var result = '', bits = 0, idx, tail,
|
|---|
| 3124 | max = object.length,
|
|---|
| 3125 | map = BASE64_MAP;
|
|---|
| 3126 |
|
|---|
| 3127 | // Convert every three bytes to 4 ASCII characters.
|
|---|
| 3128 |
|
|---|
| 3129 | for (idx = 0; idx < max; idx++) {
|
|---|
| 3130 | if ((idx % 3 === 0) && idx) {
|
|---|
| 3131 | result += map[(bits >> 18) & 0x3F];
|
|---|
| 3132 | result += map[(bits >> 12) & 0x3F];
|
|---|
| 3133 | result += map[(bits >> 6) & 0x3F];
|
|---|
| 3134 | result += map[bits & 0x3F];
|
|---|
| 3135 | }
|
|---|
| 3136 |
|
|---|
| 3137 | bits = (bits << 8) + object[idx];
|
|---|
| 3138 | }
|
|---|
| 3139 |
|
|---|
| 3140 | // Dump tail
|
|---|
| 3141 |
|
|---|
| 3142 | tail = max % 3;
|
|---|
| 3143 |
|
|---|
| 3144 | if (tail === 0) {
|
|---|
| 3145 | result += map[(bits >> 18) & 0x3F];
|
|---|
| 3146 | result += map[(bits >> 12) & 0x3F];
|
|---|
| 3147 | result += map[(bits >> 6) & 0x3F];
|
|---|
| 3148 | result += map[bits & 0x3F];
|
|---|
| 3149 | } else if (tail === 2) {
|
|---|
| 3150 | result += map[(bits >> 10) & 0x3F];
|
|---|
| 3151 | result += map[(bits >> 4) & 0x3F];
|
|---|
| 3152 | result += map[(bits << 2) & 0x3F];
|
|---|
| 3153 | result += map[64];
|
|---|
| 3154 | } else if (tail === 1) {
|
|---|
| 3155 | result += map[(bits >> 2) & 0x3F];
|
|---|
| 3156 | result += map[(bits << 4) & 0x3F];
|
|---|
| 3157 | result += map[64];
|
|---|
| 3158 | result += map[64];
|
|---|
| 3159 | }
|
|---|
| 3160 |
|
|---|
| 3161 | return result;
|
|---|
| 3162 | }
|
|---|
| 3163 |
|
|---|
| 3164 | function isBinary(object) {
|
|---|
| 3165 | return NodeBuffer && NodeBuffer.isBuffer(object);
|
|---|
| 3166 | }
|
|---|
| 3167 |
|
|---|
| 3168 | module.exports = new Type('tag:yaml.org,2002:binary', {
|
|---|
| 3169 | kind: 'scalar',
|
|---|
| 3170 | resolve: resolveYamlBinary,
|
|---|
| 3171 | construct: constructYamlBinary,
|
|---|
| 3172 | predicate: isBinary,
|
|---|
| 3173 | represent: representYamlBinary
|
|---|
| 3174 | });
|
|---|
| 3175 |
|
|---|
| 3176 | },{"../type":13}],15:[function(require,module,exports){
|
|---|
| 3177 | 'use strict';
|
|---|
| 3178 |
|
|---|
| 3179 | var Type = require('../type');
|
|---|
| 3180 |
|
|---|
| 3181 | function resolveYamlBoolean(data) {
|
|---|
| 3182 | if (data === null) return false;
|
|---|
| 3183 |
|
|---|
| 3184 | var max = data.length;
|
|---|
| 3185 |
|
|---|
| 3186 | return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
|
|---|
| 3187 | (max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
|
|---|
| 3188 | }
|
|---|
| 3189 |
|
|---|
| 3190 | function constructYamlBoolean(data) {
|
|---|
| 3191 | return data === 'true' ||
|
|---|
| 3192 | data === 'True' ||
|
|---|
| 3193 | data === 'TRUE';
|
|---|
| 3194 | }
|
|---|
| 3195 |
|
|---|
| 3196 | function isBoolean(object) {
|
|---|
| 3197 | return Object.prototype.toString.call(object) === '[object Boolean]';
|
|---|
| 3198 | }
|
|---|
| 3199 |
|
|---|
| 3200 | module.exports = new Type('tag:yaml.org,2002:bool', {
|
|---|
| 3201 | kind: 'scalar',
|
|---|
| 3202 | resolve: resolveYamlBoolean,
|
|---|
| 3203 | construct: constructYamlBoolean,
|
|---|
| 3204 | predicate: isBoolean,
|
|---|
| 3205 | represent: {
|
|---|
| 3206 | lowercase: function (object) { return object ? 'true' : 'false'; },
|
|---|
| 3207 | uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
|
|---|
| 3208 | camelcase: function (object) { return object ? 'True' : 'False'; }
|
|---|
| 3209 | },
|
|---|
| 3210 | defaultStyle: 'lowercase'
|
|---|
| 3211 | });
|
|---|
| 3212 |
|
|---|
| 3213 | },{"../type":13}],16:[function(require,module,exports){
|
|---|
| 3214 | 'use strict';
|
|---|
| 3215 |
|
|---|
| 3216 | var common = require('../common');
|
|---|
| 3217 | var Type = require('../type');
|
|---|
| 3218 |
|
|---|
| 3219 | var YAML_FLOAT_PATTERN = new RegExp(
|
|---|
| 3220 | // 2.5e4, 2.5 and integers
|
|---|
| 3221 | '^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' +
|
|---|
| 3222 | // .2e4, .2
|
|---|
| 3223 | // special case, seems not from spec
|
|---|
| 3224 | '|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' +
|
|---|
| 3225 | // 20:59
|
|---|
| 3226 | '|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' +
|
|---|
| 3227 | // .inf
|
|---|
| 3228 | '|[-+]?\\.(?:inf|Inf|INF)' +
|
|---|
| 3229 | // .nan
|
|---|
| 3230 | '|\\.(?:nan|NaN|NAN))$');
|
|---|
| 3231 |
|
|---|
| 3232 | function resolveYamlFloat(data) {
|
|---|
| 3233 | if (data === null) return false;
|
|---|
| 3234 |
|
|---|
| 3235 | if (!YAML_FLOAT_PATTERN.test(data) ||
|
|---|
| 3236 | // Quick hack to not allow integers end with `_`
|
|---|
| 3237 | // Probably should update regexp & check speed
|
|---|
| 3238 | data[data.length - 1] === '_') {
|
|---|
| 3239 | return false;
|
|---|
| 3240 | }
|
|---|
| 3241 |
|
|---|
| 3242 | return true;
|
|---|
| 3243 | }
|
|---|
| 3244 |
|
|---|
| 3245 | function constructYamlFloat(data) {
|
|---|
| 3246 | var value, sign, base, digits;
|
|---|
| 3247 |
|
|---|
| 3248 | value = data.replace(/_/g, '').toLowerCase();
|
|---|
| 3249 | sign = value[0] === '-' ? -1 : 1;
|
|---|
| 3250 | digits = [];
|
|---|
| 3251 |
|
|---|
| 3252 | if ('+-'.indexOf(value[0]) >= 0) {
|
|---|
| 3253 | value = value.slice(1);
|
|---|
| 3254 | }
|
|---|
| 3255 |
|
|---|
| 3256 | if (value === '.inf') {
|
|---|
| 3257 | return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|---|
| 3258 |
|
|---|
| 3259 | } else if (value === '.nan') {
|
|---|
| 3260 | return NaN;
|
|---|
| 3261 |
|
|---|
| 3262 | } else if (value.indexOf(':') >= 0) {
|
|---|
| 3263 | value.split(':').forEach(function (v) {
|
|---|
| 3264 | digits.unshift(parseFloat(v, 10));
|
|---|
| 3265 | });
|
|---|
| 3266 |
|
|---|
| 3267 | value = 0.0;
|
|---|
| 3268 | base = 1;
|
|---|
| 3269 |
|
|---|
| 3270 | digits.forEach(function (d) {
|
|---|
| 3271 | value += d * base;
|
|---|
| 3272 | base *= 60;
|
|---|
| 3273 | });
|
|---|
| 3274 |
|
|---|
| 3275 | return sign * value;
|
|---|
| 3276 |
|
|---|
| 3277 | }
|
|---|
| 3278 | return sign * parseFloat(value, 10);
|
|---|
| 3279 | }
|
|---|
| 3280 |
|
|---|
| 3281 |
|
|---|
| 3282 | var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
|
|---|
| 3283 |
|
|---|
| 3284 | function representYamlFloat(object, style) {
|
|---|
| 3285 | var res;
|
|---|
| 3286 |
|
|---|
| 3287 | if (isNaN(object)) {
|
|---|
| 3288 | switch (style) {
|
|---|
| 3289 | case 'lowercase': return '.nan';
|
|---|
| 3290 | case 'uppercase': return '.NAN';
|
|---|
| 3291 | case 'camelcase': return '.NaN';
|
|---|
| 3292 | }
|
|---|
| 3293 | } else if (Number.POSITIVE_INFINITY === object) {
|
|---|
| 3294 | switch (style) {
|
|---|
| 3295 | case 'lowercase': return '.inf';
|
|---|
| 3296 | case 'uppercase': return '.INF';
|
|---|
| 3297 | case 'camelcase': return '.Inf';
|
|---|
| 3298 | }
|
|---|
| 3299 | } else if (Number.NEGATIVE_INFINITY === object) {
|
|---|
| 3300 | switch (style) {
|
|---|
| 3301 | case 'lowercase': return '-.inf';
|
|---|
| 3302 | case 'uppercase': return '-.INF';
|
|---|
| 3303 | case 'camelcase': return '-.Inf';
|
|---|
| 3304 | }
|
|---|
| 3305 | } else if (common.isNegativeZero(object)) {
|
|---|
| 3306 | return '-0.0';
|
|---|
| 3307 | }
|
|---|
| 3308 |
|
|---|
| 3309 | res = object.toString(10);
|
|---|
| 3310 |
|
|---|
| 3311 | // JS stringifier can build scientific format without dots: 5e-100,
|
|---|
| 3312 | // while YAML requres dot: 5.e-100. Fix it with simple hack
|
|---|
| 3313 |
|
|---|
| 3314 | return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
|
|---|
| 3315 | }
|
|---|
| 3316 |
|
|---|
| 3317 | function isFloat(object) {
|
|---|
| 3318 | return (Object.prototype.toString.call(object) === '[object Number]') &&
|
|---|
| 3319 | (object % 1 !== 0 || common.isNegativeZero(object));
|
|---|
| 3320 | }
|
|---|
| 3321 |
|
|---|
| 3322 | module.exports = new Type('tag:yaml.org,2002:float', {
|
|---|
| 3323 | kind: 'scalar',
|
|---|
| 3324 | resolve: resolveYamlFloat,
|
|---|
| 3325 | construct: constructYamlFloat,
|
|---|
| 3326 | predicate: isFloat,
|
|---|
| 3327 | represent: representYamlFloat,
|
|---|
| 3328 | defaultStyle: 'lowercase'
|
|---|
| 3329 | });
|
|---|
| 3330 |
|
|---|
| 3331 | },{"../common":2,"../type":13}],17:[function(require,module,exports){
|
|---|
| 3332 | 'use strict';
|
|---|
| 3333 |
|
|---|
| 3334 | var common = require('../common');
|
|---|
| 3335 | var Type = require('../type');
|
|---|
| 3336 |
|
|---|
| 3337 | function isHexCode(c) {
|
|---|
| 3338 | return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */)) ||
|
|---|
| 3339 | ((0x41/* A */ <= c) && (c <= 0x46/* F */)) ||
|
|---|
| 3340 | ((0x61/* a */ <= c) && (c <= 0x66/* f */));
|
|---|
| 3341 | }
|
|---|
| 3342 |
|
|---|
| 3343 | function isOctCode(c) {
|
|---|
| 3344 | return ((0x30/* 0 */ <= c) && (c <= 0x37/* 7 */));
|
|---|
| 3345 | }
|
|---|
| 3346 |
|
|---|
| 3347 | function isDecCode(c) {
|
|---|
| 3348 | return ((0x30/* 0 */ <= c) && (c <= 0x39/* 9 */));
|
|---|
| 3349 | }
|
|---|
| 3350 |
|
|---|
| 3351 | function resolveYamlInteger(data) {
|
|---|
| 3352 | if (data === null) return false;
|
|---|
| 3353 |
|
|---|
| 3354 | var max = data.length,
|
|---|
| 3355 | index = 0,
|
|---|
| 3356 | hasDigits = false,
|
|---|
| 3357 | ch;
|
|---|
| 3358 |
|
|---|
| 3359 | if (!max) return false;
|
|---|
| 3360 |
|
|---|
| 3361 | ch = data[index];
|
|---|
| 3362 |
|
|---|
| 3363 | // sign
|
|---|
| 3364 | if (ch === '-' || ch === '+') {
|
|---|
| 3365 | ch = data[++index];
|
|---|
| 3366 | }
|
|---|
| 3367 |
|
|---|
| 3368 | if (ch === '0') {
|
|---|
| 3369 | // 0
|
|---|
| 3370 | if (index + 1 === max) return true;
|
|---|
| 3371 | ch = data[++index];
|
|---|
| 3372 |
|
|---|
| 3373 | // base 2, base 8, base 16
|
|---|
| 3374 |
|
|---|
| 3375 | if (ch === 'b') {
|
|---|
| 3376 | // base 2
|
|---|
| 3377 | index++;
|
|---|
| 3378 |
|
|---|
| 3379 | for (; index < max; index++) {
|
|---|
| 3380 | ch = data[index];
|
|---|
| 3381 | if (ch === '_') continue;
|
|---|
| 3382 | if (ch !== '0' && ch !== '1') return false;
|
|---|
| 3383 | hasDigits = true;
|
|---|
| 3384 | }
|
|---|
| 3385 | return hasDigits && ch !== '_';
|
|---|
| 3386 | }
|
|---|
| 3387 |
|
|---|
| 3388 |
|
|---|
| 3389 | if (ch === 'x') {
|
|---|
| 3390 | // base 16
|
|---|
| 3391 | index++;
|
|---|
| 3392 |
|
|---|
| 3393 | for (; index < max; index++) {
|
|---|
| 3394 | ch = data[index];
|
|---|
| 3395 | if (ch === '_') continue;
|
|---|
| 3396 | if (!isHexCode(data.charCodeAt(index))) return false;
|
|---|
| 3397 | hasDigits = true;
|
|---|
| 3398 | }
|
|---|
| 3399 | return hasDigits && ch !== '_';
|
|---|
| 3400 | }
|
|---|
| 3401 |
|
|---|
| 3402 | // base 8
|
|---|
| 3403 | for (; index < max; index++) {
|
|---|
| 3404 | ch = data[index];
|
|---|
| 3405 | if (ch === '_') continue;
|
|---|
| 3406 | if (!isOctCode(data.charCodeAt(index))) return false;
|
|---|
| 3407 | hasDigits = true;
|
|---|
| 3408 | }
|
|---|
| 3409 | return hasDigits && ch !== '_';
|
|---|
| 3410 | }
|
|---|
| 3411 |
|
|---|
| 3412 | // base 10 (except 0) or base 60
|
|---|
| 3413 |
|
|---|
| 3414 | // value should not start with `_`;
|
|---|
| 3415 | if (ch === '_') return false;
|
|---|
| 3416 |
|
|---|
| 3417 | for (; index < max; index++) {
|
|---|
| 3418 | ch = data[index];
|
|---|
| 3419 | if (ch === '_') continue;
|
|---|
| 3420 | if (ch === ':') break;
|
|---|
| 3421 | if (!isDecCode(data.charCodeAt(index))) {
|
|---|
| 3422 | return false;
|
|---|
| 3423 | }
|
|---|
| 3424 | hasDigits = true;
|
|---|
| 3425 | }
|
|---|
| 3426 |
|
|---|
| 3427 | // Should have digits and should not end with `_`
|
|---|
| 3428 | if (!hasDigits || ch === '_') return false;
|
|---|
| 3429 |
|
|---|
| 3430 | // if !base60 - done;
|
|---|
| 3431 | if (ch !== ':') return true;
|
|---|
| 3432 |
|
|---|
| 3433 | // base60 almost not used, no needs to optimize
|
|---|
| 3434 | return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
|
|---|
| 3435 | }
|
|---|
| 3436 |
|
|---|
| 3437 | function constructYamlInteger(data) {
|
|---|
| 3438 | var value = data, sign = 1, ch, base, digits = [];
|
|---|
| 3439 |
|
|---|
| 3440 | if (value.indexOf('_') !== -1) {
|
|---|
| 3441 | value = value.replace(/_/g, '');
|
|---|
| 3442 | }
|
|---|
| 3443 |
|
|---|
| 3444 | ch = value[0];
|
|---|
| 3445 |
|
|---|
| 3446 | if (ch === '-' || ch === '+') {
|
|---|
| 3447 | if (ch === '-') sign = -1;
|
|---|
| 3448 | value = value.slice(1);
|
|---|
| 3449 | ch = value[0];
|
|---|
| 3450 | }
|
|---|
| 3451 |
|
|---|
| 3452 | if (value === '0') return 0;
|
|---|
| 3453 |
|
|---|
| 3454 | if (ch === '0') {
|
|---|
| 3455 | if (value[1] === 'b') return sign * parseInt(value.slice(2), 2);
|
|---|
| 3456 | if (value[1] === 'x') return sign * parseInt(value, 16);
|
|---|
| 3457 | return sign * parseInt(value, 8);
|
|---|
| 3458 | }
|
|---|
| 3459 |
|
|---|
| 3460 | if (value.indexOf(':') !== -1) {
|
|---|
| 3461 | value.split(':').forEach(function (v) {
|
|---|
| 3462 | digits.unshift(parseInt(v, 10));
|
|---|
| 3463 | });
|
|---|
| 3464 |
|
|---|
| 3465 | value = 0;
|
|---|
| 3466 | base = 1;
|
|---|
| 3467 |
|
|---|
| 3468 | digits.forEach(function (d) {
|
|---|
| 3469 | value += (d * base);
|
|---|
| 3470 | base *= 60;
|
|---|
| 3471 | });
|
|---|
| 3472 |
|
|---|
| 3473 | return sign * value;
|
|---|
| 3474 |
|
|---|
| 3475 | }
|
|---|
| 3476 |
|
|---|
| 3477 | return sign * parseInt(value, 10);
|
|---|
| 3478 | }
|
|---|
| 3479 |
|
|---|
| 3480 | function isInteger(object) {
|
|---|
| 3481 | return (Object.prototype.toString.call(object)) === '[object Number]' &&
|
|---|
| 3482 | (object % 1 === 0 && !common.isNegativeZero(object));
|
|---|
| 3483 | }
|
|---|
| 3484 |
|
|---|
| 3485 | module.exports = new Type('tag:yaml.org,2002:int', {
|
|---|
| 3486 | kind: 'scalar',
|
|---|
| 3487 | resolve: resolveYamlInteger,
|
|---|
| 3488 | construct: constructYamlInteger,
|
|---|
| 3489 | predicate: isInteger,
|
|---|
| 3490 | represent: {
|
|---|
| 3491 | binary: function (obj) { return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1); },
|
|---|
| 3492 | octal: function (obj) { return obj >= 0 ? '0' + obj.toString(8) : '-0' + obj.toString(8).slice(1); },
|
|---|
| 3493 | decimal: function (obj) { return obj.toString(10); },
|
|---|
| 3494 | /* eslint-disable max-len */
|
|---|
| 3495 | hexadecimal: function (obj) { return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1); }
|
|---|
| 3496 | },
|
|---|
| 3497 | defaultStyle: 'decimal',
|
|---|
| 3498 | styleAliases: {
|
|---|
| 3499 | binary: [ 2, 'bin' ],
|
|---|
| 3500 | octal: [ 8, 'oct' ],
|
|---|
| 3501 | decimal: [ 10, 'dec' ],
|
|---|
| 3502 | hexadecimal: [ 16, 'hex' ]
|
|---|
| 3503 | }
|
|---|
| 3504 | });
|
|---|
| 3505 |
|
|---|
| 3506 | },{"../common":2,"../type":13}],18:[function(require,module,exports){
|
|---|
| 3507 | 'use strict';
|
|---|
| 3508 |
|
|---|
| 3509 | var esprima;
|
|---|
| 3510 |
|
|---|
| 3511 | // Browserified version does not have esprima
|
|---|
| 3512 | //
|
|---|
| 3513 | // 1. For node.js just require module as deps
|
|---|
| 3514 | // 2. For browser try to require mudule via external AMD system.
|
|---|
| 3515 | // If not found - try to fallback to window.esprima. If not
|
|---|
| 3516 | // found too - then fail to parse.
|
|---|
| 3517 | //
|
|---|
| 3518 | try {
|
|---|
| 3519 | // workaround to exclude package from browserify list.
|
|---|
| 3520 | var _require = require;
|
|---|
| 3521 | esprima = _require('esprima');
|
|---|
| 3522 | } catch (_) {
|
|---|
| 3523 | /* eslint-disable no-redeclare */
|
|---|
| 3524 | /* global window */
|
|---|
| 3525 | if (typeof window !== 'undefined') esprima = window.esprima;
|
|---|
| 3526 | }
|
|---|
| 3527 |
|
|---|
| 3528 | var Type = require('../../type');
|
|---|
| 3529 |
|
|---|
| 3530 | function resolveJavascriptFunction(data) {
|
|---|
| 3531 | if (data === null) return false;
|
|---|
| 3532 |
|
|---|
| 3533 | try {
|
|---|
| 3534 | var source = '(' + data + ')',
|
|---|
| 3535 | ast = esprima.parse(source, { range: true });
|
|---|
| 3536 |
|
|---|
| 3537 | if (ast.type !== 'Program' ||
|
|---|
| 3538 | ast.body.length !== 1 ||
|
|---|
| 3539 | ast.body[0].type !== 'ExpressionStatement' ||
|
|---|
| 3540 | (ast.body[0].expression.type !== 'ArrowFunctionExpression' &&
|
|---|
| 3541 | ast.body[0].expression.type !== 'FunctionExpression')) {
|
|---|
| 3542 | return false;
|
|---|
| 3543 | }
|
|---|
| 3544 |
|
|---|
| 3545 | return true;
|
|---|
| 3546 | } catch (err) {
|
|---|
| 3547 | return false;
|
|---|
| 3548 | }
|
|---|
| 3549 | }
|
|---|
| 3550 |
|
|---|
| 3551 | function constructJavascriptFunction(data) {
|
|---|
| 3552 | /*jslint evil:true*/
|
|---|
| 3553 |
|
|---|
| 3554 | var source = '(' + data + ')',
|
|---|
| 3555 | ast = esprima.parse(source, { range: true }),
|
|---|
| 3556 | params = [],
|
|---|
| 3557 | body;
|
|---|
| 3558 |
|
|---|
| 3559 | if (ast.type !== 'Program' ||
|
|---|
| 3560 | ast.body.length !== 1 ||
|
|---|
| 3561 | ast.body[0].type !== 'ExpressionStatement' ||
|
|---|
| 3562 | (ast.body[0].expression.type !== 'ArrowFunctionExpression' &&
|
|---|
| 3563 | ast.body[0].expression.type !== 'FunctionExpression')) {
|
|---|
| 3564 | throw new Error('Failed to resolve function');
|
|---|
| 3565 | }
|
|---|
| 3566 |
|
|---|
| 3567 | ast.body[0].expression.params.forEach(function (param) {
|
|---|
| 3568 | params.push(param.name);
|
|---|
| 3569 | });
|
|---|
| 3570 |
|
|---|
| 3571 | body = ast.body[0].expression.body.range;
|
|---|
| 3572 |
|
|---|
| 3573 | // Esprima's ranges include the first '{' and the last '}' characters on
|
|---|
| 3574 | // function expressions. So cut them out.
|
|---|
| 3575 | if (ast.body[0].expression.body.type === 'BlockStatement') {
|
|---|
| 3576 | /*eslint-disable no-new-func*/
|
|---|
| 3577 | return new Function(params, source.slice(body[0] + 1, body[1] - 1));
|
|---|
| 3578 | }
|
|---|
| 3579 | // ES6 arrow functions can omit the BlockStatement. In that case, just return
|
|---|
| 3580 | // the body.
|
|---|
| 3581 | /*eslint-disable no-new-func*/
|
|---|
| 3582 | return new Function(params, 'return ' + source.slice(body[0], body[1]));
|
|---|
| 3583 | }
|
|---|
| 3584 |
|
|---|
| 3585 | function representJavascriptFunction(object /*, style*/) {
|
|---|
| 3586 | return object.toString();
|
|---|
| 3587 | }
|
|---|
| 3588 |
|
|---|
| 3589 | function isFunction(object) {
|
|---|
| 3590 | return Object.prototype.toString.call(object) === '[object Function]';
|
|---|
| 3591 | }
|
|---|
| 3592 |
|
|---|
| 3593 | module.exports = new Type('tag:yaml.org,2002:js/function', {
|
|---|
| 3594 | kind: 'scalar',
|
|---|
| 3595 | resolve: resolveJavascriptFunction,
|
|---|
| 3596 | construct: constructJavascriptFunction,
|
|---|
| 3597 | predicate: isFunction,
|
|---|
| 3598 | represent: representJavascriptFunction
|
|---|
| 3599 | });
|
|---|
| 3600 |
|
|---|
| 3601 | },{"../../type":13}],19:[function(require,module,exports){
|
|---|
| 3602 | 'use strict';
|
|---|
| 3603 |
|
|---|
| 3604 | var Type = require('../../type');
|
|---|
| 3605 |
|
|---|
| 3606 | function resolveJavascriptRegExp(data) {
|
|---|
| 3607 | if (data === null) return false;
|
|---|
| 3608 | if (data.length === 0) return false;
|
|---|
| 3609 |
|
|---|
| 3610 | var regexp = data,
|
|---|
| 3611 | tail = /\/([gim]*)$/.exec(data),
|
|---|
| 3612 | modifiers = '';
|
|---|
| 3613 |
|
|---|
| 3614 | // if regexp starts with '/' it can have modifiers and must be properly closed
|
|---|
| 3615 | // `/foo/gim` - modifiers tail can be maximum 3 chars
|
|---|
| 3616 | if (regexp[0] === '/') {
|
|---|
| 3617 | if (tail) modifiers = tail[1];
|
|---|
| 3618 |
|
|---|
| 3619 | if (modifiers.length > 3) return false;
|
|---|
| 3620 | // if expression starts with /, is should be properly terminated
|
|---|
| 3621 | if (regexp[regexp.length - modifiers.length - 1] !== '/') return false;
|
|---|
| 3622 | }
|
|---|
| 3623 |
|
|---|
| 3624 | return true;
|
|---|
| 3625 | }
|
|---|
| 3626 |
|
|---|
| 3627 | function constructJavascriptRegExp(data) {
|
|---|
| 3628 | var regexp = data,
|
|---|
| 3629 | tail = /\/([gim]*)$/.exec(data),
|
|---|
| 3630 | modifiers = '';
|
|---|
| 3631 |
|
|---|
| 3632 | // `/foo/gim` - tail can be maximum 4 chars
|
|---|
| 3633 | if (regexp[0] === '/') {
|
|---|
| 3634 | if (tail) modifiers = tail[1];
|
|---|
| 3635 | regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
|
|---|
| 3636 | }
|
|---|
| 3637 |
|
|---|
| 3638 | return new RegExp(regexp, modifiers);
|
|---|
| 3639 | }
|
|---|
| 3640 |
|
|---|
| 3641 | function representJavascriptRegExp(object /*, style*/) {
|
|---|
| 3642 | var result = '/' + object.source + '/';
|
|---|
| 3643 |
|
|---|
| 3644 | if (object.global) result += 'g';
|
|---|
| 3645 | if (object.multiline) result += 'm';
|
|---|
| 3646 | if (object.ignoreCase) result += 'i';
|
|---|
| 3647 |
|
|---|
| 3648 | return result;
|
|---|
| 3649 | }
|
|---|
| 3650 |
|
|---|
| 3651 | function isRegExp(object) {
|
|---|
| 3652 | return Object.prototype.toString.call(object) === '[object RegExp]';
|
|---|
| 3653 | }
|
|---|
| 3654 |
|
|---|
| 3655 | module.exports = new Type('tag:yaml.org,2002:js/regexp', {
|
|---|
| 3656 | kind: 'scalar',
|
|---|
| 3657 | resolve: resolveJavascriptRegExp,
|
|---|
| 3658 | construct: constructJavascriptRegExp,
|
|---|
| 3659 | predicate: isRegExp,
|
|---|
| 3660 | represent: representJavascriptRegExp
|
|---|
| 3661 | });
|
|---|
| 3662 |
|
|---|
| 3663 | },{"../../type":13}],20:[function(require,module,exports){
|
|---|
| 3664 | 'use strict';
|
|---|
| 3665 |
|
|---|
| 3666 | var Type = require('../../type');
|
|---|
| 3667 |
|
|---|
| 3668 | function resolveJavascriptUndefined() {
|
|---|
| 3669 | return true;
|
|---|
| 3670 | }
|
|---|
| 3671 |
|
|---|
| 3672 | function constructJavascriptUndefined() {
|
|---|
| 3673 | /*eslint-disable no-undefined*/
|
|---|
| 3674 | return undefined;
|
|---|
| 3675 | }
|
|---|
| 3676 |
|
|---|
| 3677 | function representJavascriptUndefined() {
|
|---|
| 3678 | return '';
|
|---|
| 3679 | }
|
|---|
| 3680 |
|
|---|
| 3681 | function isUndefined(object) {
|
|---|
| 3682 | return typeof object === 'undefined';
|
|---|
| 3683 | }
|
|---|
| 3684 |
|
|---|
| 3685 | module.exports = new Type('tag:yaml.org,2002:js/undefined', {
|
|---|
| 3686 | kind: 'scalar',
|
|---|
| 3687 | resolve: resolveJavascriptUndefined,
|
|---|
| 3688 | construct: constructJavascriptUndefined,
|
|---|
| 3689 | predicate: isUndefined,
|
|---|
| 3690 | represent: representJavascriptUndefined
|
|---|
| 3691 | });
|
|---|
| 3692 |
|
|---|
| 3693 | },{"../../type":13}],21:[function(require,module,exports){
|
|---|
| 3694 | 'use strict';
|
|---|
| 3695 |
|
|---|
| 3696 | var Type = require('../type');
|
|---|
| 3697 |
|
|---|
| 3698 | module.exports = new Type('tag:yaml.org,2002:map', {
|
|---|
| 3699 | kind: 'mapping',
|
|---|
| 3700 | construct: function (data) { return data !== null ? data : {}; }
|
|---|
| 3701 | });
|
|---|
| 3702 |
|
|---|
| 3703 | },{"../type":13}],22:[function(require,module,exports){
|
|---|
| 3704 | 'use strict';
|
|---|
| 3705 |
|
|---|
| 3706 | var Type = require('../type');
|
|---|
| 3707 |
|
|---|
| 3708 | function resolveYamlMerge(data) {
|
|---|
| 3709 | return data === '<<' || data === null;
|
|---|
| 3710 | }
|
|---|
| 3711 |
|
|---|
| 3712 | module.exports = new Type('tag:yaml.org,2002:merge', {
|
|---|
| 3713 | kind: 'scalar',
|
|---|
| 3714 | resolve: resolveYamlMerge
|
|---|
| 3715 | });
|
|---|
| 3716 |
|
|---|
| 3717 | },{"../type":13}],23:[function(require,module,exports){
|
|---|
| 3718 | 'use strict';
|
|---|
| 3719 |
|
|---|
| 3720 | var Type = require('../type');
|
|---|
| 3721 |
|
|---|
| 3722 | function resolveYamlNull(data) {
|
|---|
| 3723 | if (data === null) return true;
|
|---|
| 3724 |
|
|---|
| 3725 | var max = data.length;
|
|---|
| 3726 |
|
|---|
| 3727 | return (max === 1 && data === '~') ||
|
|---|
| 3728 | (max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'));
|
|---|
| 3729 | }
|
|---|
| 3730 |
|
|---|
| 3731 | function constructYamlNull() {
|
|---|
| 3732 | return null;
|
|---|
| 3733 | }
|
|---|
| 3734 |
|
|---|
| 3735 | function isNull(object) {
|
|---|
| 3736 | return object === null;
|
|---|
| 3737 | }
|
|---|
| 3738 |
|
|---|
| 3739 | module.exports = new Type('tag:yaml.org,2002:null', {
|
|---|
| 3740 | kind: 'scalar',
|
|---|
| 3741 | resolve: resolveYamlNull,
|
|---|
| 3742 | construct: constructYamlNull,
|
|---|
| 3743 | predicate: isNull,
|
|---|
| 3744 | represent: {
|
|---|
| 3745 | canonical: function () { return '~'; },
|
|---|
| 3746 | lowercase: function () { return 'null'; },
|
|---|
| 3747 | uppercase: function () { return 'NULL'; },
|
|---|
| 3748 | camelcase: function () { return 'Null'; }
|
|---|
| 3749 | },
|
|---|
| 3750 | defaultStyle: 'lowercase'
|
|---|
| 3751 | });
|
|---|
| 3752 |
|
|---|
| 3753 | },{"../type":13}],24:[function(require,module,exports){
|
|---|
| 3754 | 'use strict';
|
|---|
| 3755 |
|
|---|
| 3756 | var Type = require('../type');
|
|---|
| 3757 |
|
|---|
| 3758 | var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|---|
| 3759 | var _toString = Object.prototype.toString;
|
|---|
| 3760 |
|
|---|
| 3761 | function resolveYamlOmap(data) {
|
|---|
| 3762 | if (data === null) return true;
|
|---|
| 3763 |
|
|---|
| 3764 | var objectKeys = [], index, length, pair, pairKey, pairHasKey,
|
|---|
| 3765 | object = data;
|
|---|
| 3766 |
|
|---|
| 3767 | for (index = 0, length = object.length; index < length; index += 1) {
|
|---|
| 3768 | pair = object[index];
|
|---|
| 3769 | pairHasKey = false;
|
|---|
| 3770 |
|
|---|
| 3771 | if (_toString.call(pair) !== '[object Object]') return false;
|
|---|
| 3772 |
|
|---|
| 3773 | for (pairKey in pair) {
|
|---|
| 3774 | if (_hasOwnProperty.call(pair, pairKey)) {
|
|---|
| 3775 | if (!pairHasKey) pairHasKey = true;
|
|---|
| 3776 | else return false;
|
|---|
| 3777 | }
|
|---|
| 3778 | }
|
|---|
| 3779 |
|
|---|
| 3780 | if (!pairHasKey) return false;
|
|---|
| 3781 |
|
|---|
| 3782 | if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
|
|---|
| 3783 | else return false;
|
|---|
| 3784 | }
|
|---|
| 3785 |
|
|---|
| 3786 | return true;
|
|---|
| 3787 | }
|
|---|
| 3788 |
|
|---|
| 3789 | function constructYamlOmap(data) {
|
|---|
| 3790 | return data !== null ? data : [];
|
|---|
| 3791 | }
|
|---|
| 3792 |
|
|---|
| 3793 | module.exports = new Type('tag:yaml.org,2002:omap', {
|
|---|
| 3794 | kind: 'sequence',
|
|---|
| 3795 | resolve: resolveYamlOmap,
|
|---|
| 3796 | construct: constructYamlOmap
|
|---|
| 3797 | });
|
|---|
| 3798 |
|
|---|
| 3799 | },{"../type":13}],25:[function(require,module,exports){
|
|---|
| 3800 | 'use strict';
|
|---|
| 3801 |
|
|---|
| 3802 | var Type = require('../type');
|
|---|
| 3803 |
|
|---|
| 3804 | var _toString = Object.prototype.toString;
|
|---|
| 3805 |
|
|---|
| 3806 | function resolveYamlPairs(data) {
|
|---|
| 3807 | if (data === null) return true;
|
|---|
| 3808 |
|
|---|
| 3809 | var index, length, pair, keys, result,
|
|---|
| 3810 | object = data;
|
|---|
| 3811 |
|
|---|
| 3812 | result = new Array(object.length);
|
|---|
| 3813 |
|
|---|
| 3814 | for (index = 0, length = object.length; index < length; index += 1) {
|
|---|
| 3815 | pair = object[index];
|
|---|
| 3816 |
|
|---|
| 3817 | if (_toString.call(pair) !== '[object Object]') return false;
|
|---|
| 3818 |
|
|---|
| 3819 | keys = Object.keys(pair);
|
|---|
| 3820 |
|
|---|
| 3821 | if (keys.length !== 1) return false;
|
|---|
| 3822 |
|
|---|
| 3823 | result[index] = [ keys[0], pair[keys[0]] ];
|
|---|
| 3824 | }
|
|---|
| 3825 |
|
|---|
| 3826 | return true;
|
|---|
| 3827 | }
|
|---|
| 3828 |
|
|---|
| 3829 | function constructYamlPairs(data) {
|
|---|
| 3830 | if (data === null) return [];
|
|---|
| 3831 |
|
|---|
| 3832 | var index, length, pair, keys, result,
|
|---|
| 3833 | object = data;
|
|---|
| 3834 |
|
|---|
| 3835 | result = new Array(object.length);
|
|---|
| 3836 |
|
|---|
| 3837 | for (index = 0, length = object.length; index < length; index += 1) {
|
|---|
| 3838 | pair = object[index];
|
|---|
| 3839 |
|
|---|
| 3840 | keys = Object.keys(pair);
|
|---|
| 3841 |
|
|---|
| 3842 | result[index] = [ keys[0], pair[keys[0]] ];
|
|---|
| 3843 | }
|
|---|
| 3844 |
|
|---|
| 3845 | return result;
|
|---|
| 3846 | }
|
|---|
| 3847 |
|
|---|
| 3848 | module.exports = new Type('tag:yaml.org,2002:pairs', {
|
|---|
| 3849 | kind: 'sequence',
|
|---|
| 3850 | resolve: resolveYamlPairs,
|
|---|
| 3851 | construct: constructYamlPairs
|
|---|
| 3852 | });
|
|---|
| 3853 |
|
|---|
| 3854 | },{"../type":13}],26:[function(require,module,exports){
|
|---|
| 3855 | 'use strict';
|
|---|
| 3856 |
|
|---|
| 3857 | var Type = require('../type');
|
|---|
| 3858 |
|
|---|
| 3859 | module.exports = new Type('tag:yaml.org,2002:seq', {
|
|---|
| 3860 | kind: 'sequence',
|
|---|
| 3861 | construct: function (data) { return data !== null ? data : []; }
|
|---|
| 3862 | });
|
|---|
| 3863 |
|
|---|
| 3864 | },{"../type":13}],27:[function(require,module,exports){
|
|---|
| 3865 | 'use strict';
|
|---|
| 3866 |
|
|---|
| 3867 | var Type = require('../type');
|
|---|
| 3868 |
|
|---|
| 3869 | var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
|---|
| 3870 |
|
|---|
| 3871 | function resolveYamlSet(data) {
|
|---|
| 3872 | if (data === null) return true;
|
|---|
| 3873 |
|
|---|
| 3874 | var key, object = data;
|
|---|
| 3875 |
|
|---|
| 3876 | for (key in object) {
|
|---|
| 3877 | if (_hasOwnProperty.call(object, key)) {
|
|---|
| 3878 | if (object[key] !== null) return false;
|
|---|
| 3879 | }
|
|---|
| 3880 | }
|
|---|
| 3881 |
|
|---|
| 3882 | return true;
|
|---|
| 3883 | }
|
|---|
| 3884 |
|
|---|
| 3885 | function constructYamlSet(data) {
|
|---|
| 3886 | return data !== null ? data : {};
|
|---|
| 3887 | }
|
|---|
| 3888 |
|
|---|
| 3889 | module.exports = new Type('tag:yaml.org,2002:set', {
|
|---|
| 3890 | kind: 'mapping',
|
|---|
| 3891 | resolve: resolveYamlSet,
|
|---|
| 3892 | construct: constructYamlSet
|
|---|
| 3893 | });
|
|---|
| 3894 |
|
|---|
| 3895 | },{"../type":13}],28:[function(require,module,exports){
|
|---|
| 3896 | 'use strict';
|
|---|
| 3897 |
|
|---|
| 3898 | var Type = require('../type');
|
|---|
| 3899 |
|
|---|
| 3900 | module.exports = new Type('tag:yaml.org,2002:str', {
|
|---|
| 3901 | kind: 'scalar',
|
|---|
| 3902 | construct: function (data) { return data !== null ? data : ''; }
|
|---|
| 3903 | });
|
|---|
| 3904 |
|
|---|
| 3905 | },{"../type":13}],29:[function(require,module,exports){
|
|---|
| 3906 | 'use strict';
|
|---|
| 3907 |
|
|---|
| 3908 | var Type = require('../type');
|
|---|
| 3909 |
|
|---|
| 3910 | var YAML_DATE_REGEXP = new RegExp(
|
|---|
| 3911 | '^([0-9][0-9][0-9][0-9])' + // [1] year
|
|---|
| 3912 | '-([0-9][0-9])' + // [2] month
|
|---|
| 3913 | '-([0-9][0-9])$'); // [3] day
|
|---|
| 3914 |
|
|---|
| 3915 | var YAML_TIMESTAMP_REGEXP = new RegExp(
|
|---|
| 3916 | '^([0-9][0-9][0-9][0-9])' + // [1] year
|
|---|
| 3917 | '-([0-9][0-9]?)' + // [2] month
|
|---|
| 3918 | '-([0-9][0-9]?)' + // [3] day
|
|---|
| 3919 | '(?:[Tt]|[ \\t]+)' + // ...
|
|---|
| 3920 | '([0-9][0-9]?)' + // [4] hour
|
|---|
| 3921 | ':([0-9][0-9])' + // [5] minute
|
|---|
| 3922 | ':([0-9][0-9])' + // [6] second
|
|---|
| 3923 | '(?:\\.([0-9]*))?' + // [7] fraction
|
|---|
| 3924 | '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' + // [8] tz [9] tz_sign [10] tz_hour
|
|---|
| 3925 | '(?::([0-9][0-9]))?))?$'); // [11] tz_minute
|
|---|
| 3926 |
|
|---|
| 3927 | function resolveYamlTimestamp(data) {
|
|---|
| 3928 | if (data === null) return false;
|
|---|
| 3929 | if (YAML_DATE_REGEXP.exec(data) !== null) return true;
|
|---|
| 3930 | if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
|
|---|
| 3931 | return false;
|
|---|
| 3932 | }
|
|---|
| 3933 |
|
|---|
| 3934 | function constructYamlTimestamp(data) {
|
|---|
| 3935 | var match, year, month, day, hour, minute, second, fraction = 0,
|
|---|
| 3936 | delta = null, tz_hour, tz_minute, date;
|
|---|
| 3937 |
|
|---|
| 3938 | match = YAML_DATE_REGEXP.exec(data);
|
|---|
| 3939 | if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
|
|---|
| 3940 |
|
|---|
| 3941 | if (match === null) throw new Error('Date resolve error');
|
|---|
| 3942 |
|
|---|
| 3943 | // match: [1] year [2] month [3] day
|
|---|
| 3944 |
|
|---|
| 3945 | year = +(match[1]);
|
|---|
| 3946 | month = +(match[2]) - 1; // JS month starts with 0
|
|---|
| 3947 | day = +(match[3]);
|
|---|
| 3948 |
|
|---|
| 3949 | if (!match[4]) { // no hour
|
|---|
| 3950 | return new Date(Date.UTC(year, month, day));
|
|---|
| 3951 | }
|
|---|
| 3952 |
|
|---|
| 3953 | // match: [4] hour [5] minute [6] second [7] fraction
|
|---|
| 3954 |
|
|---|
| 3955 | hour = +(match[4]);
|
|---|
| 3956 | minute = +(match[5]);
|
|---|
| 3957 | second = +(match[6]);
|
|---|
| 3958 |
|
|---|
| 3959 | if (match[7]) {
|
|---|
| 3960 | fraction = match[7].slice(0, 3);
|
|---|
| 3961 | while (fraction.length < 3) { // milli-seconds
|
|---|
| 3962 | fraction += '0';
|
|---|
| 3963 | }
|
|---|
| 3964 | fraction = +fraction;
|
|---|
| 3965 | }
|
|---|
| 3966 |
|
|---|
| 3967 | // match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
|
|---|
| 3968 |
|
|---|
| 3969 | if (match[9]) {
|
|---|
| 3970 | tz_hour = +(match[10]);
|
|---|
| 3971 | tz_minute = +(match[11] || 0);
|
|---|
| 3972 | delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
|
|---|
| 3973 | if (match[9] === '-') delta = -delta;
|
|---|
| 3974 | }
|
|---|
| 3975 |
|
|---|
| 3976 | date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|---|
| 3977 |
|
|---|
| 3978 | if (delta) date.setTime(date.getTime() - delta);
|
|---|
| 3979 |
|
|---|
| 3980 | return date;
|
|---|
| 3981 | }
|
|---|
| 3982 |
|
|---|
| 3983 | function representYamlTimestamp(object /*, style*/) {
|
|---|
| 3984 | return object.toISOString();
|
|---|
| 3985 | }
|
|---|
| 3986 |
|
|---|
| 3987 | module.exports = new Type('tag:yaml.org,2002:timestamp', {
|
|---|
| 3988 | kind: 'scalar',
|
|---|
| 3989 | resolve: resolveYamlTimestamp,
|
|---|
| 3990 | construct: constructYamlTimestamp,
|
|---|
| 3991 | instanceOf: Date,
|
|---|
| 3992 | represent: representYamlTimestamp
|
|---|
| 3993 | });
|
|---|
| 3994 |
|
|---|
| 3995 | },{"../type":13}],"/":[function(require,module,exports){
|
|---|
| 3996 | 'use strict';
|
|---|
| 3997 |
|
|---|
| 3998 |
|
|---|
| 3999 | var yaml = require('./lib/js-yaml.js');
|
|---|
| 4000 |
|
|---|
| 4001 |
|
|---|
| 4002 | module.exports = yaml;
|
|---|
| 4003 |
|
|---|
| 4004 | },{"./lib/js-yaml.js":1}]},{},[])("/")
|
|---|
| 4005 | });
|
|---|