UNPKG

58.8 kBJavaScriptView Raw
1(function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){
2var Dumper, Inline, Utils;
3
4Utils = require('./Utils');
5
6Inline = require('./Inline');
7
8Dumper = (function() {
9 function Dumper() {}
10
11 Dumper.indentation = 4;
12
13 Dumper.prototype.dump = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) {
14 var i, key, len, output, prefix, value, willBeInlined;
15 if (inline == null) {
16 inline = 0;
17 }
18 if (indent == null) {
19 indent = 0;
20 }
21 if (exceptionOnInvalidType == null) {
22 exceptionOnInvalidType = false;
23 }
24 if (objectEncoder == null) {
25 objectEncoder = null;
26 }
27 output = '';
28 prefix = (indent ? Utils.strRepeat(' ', indent) : '');
29 if (inline <= 0 || typeof input !== 'object' || input instanceof Date || Utils.isEmpty(input)) {
30 output += prefix + Inline.dump(input, exceptionOnInvalidType, objectEncoder);
31 } else {
32 if (input instanceof Array) {
33 for (i = 0, len = input.length; i < len; i++) {
34 value = input[i];
35 willBeInlined = inline - 1 <= 0 || typeof value !== 'object' || Utils.isEmpty(value);
36 output += prefix + '-' + (willBeInlined ? ' ' : "\n") + this.dump(value, inline - 1, (willBeInlined ? 0 : indent + this.indentation), exceptionOnInvalidType, objectEncoder) + (willBeInlined ? "\n" : '');
37 }
38 } else {
39 for (key in input) {
40 value = input[key];
41 willBeInlined = inline - 1 <= 0 || typeof value !== 'object' || Utils.isEmpty(value);
42 output += prefix + Inline.dump(key, exceptionOnInvalidType, objectEncoder) + ':' + (willBeInlined ? ' ' : "\n") + this.dump(value, inline - 1, (willBeInlined ? 0 : indent + this.indentation), exceptionOnInvalidType, objectEncoder) + (willBeInlined ? "\n" : '');
43 }
44 }
45 }
46 return output;
47 };
48
49 return Dumper;
50
51})();
52
53module.exports = Dumper;
54
55
56
57},{"./Inline":5,"./Utils":9}],2:[function(require,module,exports){
58var Escaper, Pattern;
59
60Pattern = require('./Pattern');
61
62Escaper = (function() {
63 var ch;
64
65 function Escaper() {}
66
67 Escaper.LIST_ESCAPEES = ['\\\\', '\\"', '"', "\x00", "\x01", "\x02", "\x03", "\x04", "\x05", "\x06", "\x07", "\x08", "\x09", "\x0a", "\x0b", "\x0c", "\x0d", "\x0e", "\x0f", "\x10", "\x11", "\x12", "\x13", "\x14", "\x15", "\x16", "\x17", "\x18", "\x19", "\x1a", "\x1b", "\x1c", "\x1d", "\x1e", "\x1f", (ch = String.fromCharCode)(0x0085), ch(0x00A0), ch(0x2028), ch(0x2029)];
68
69 Escaper.LIST_ESCAPED = ['\\"', '\\\\', '\\"', "\\0", "\\x01", "\\x02", "\\x03", "\\x04", "\\x05", "\\x06", "\\a", "\\b", "\\t", "\\n", "\\v", "\\f", "\\r", "\\x0e", "\\x0f", "\\x10", "\\x11", "\\x12", "\\x13", "\\x14", "\\x15", "\\x16", "\\x17", "\\x18", "\\x19", "\\x1a", "\\e", "\\x1c", "\\x1d", "\\x1e", "\\x1f", "\\N", "\\_", "\\L", "\\P"];
70
71 Escaper.MAPPING_ESCAPEES_TO_ESCAPED = (function() {
72 var i, j, mapping, ref;
73 mapping = {};
74 for (i = j = 0, ref = Escaper.LIST_ESCAPEES.length; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
75 mapping[Escaper.LIST_ESCAPEES[i]] = Escaper.LIST_ESCAPED[i];
76 }
77 return mapping;
78 })();
79
80 Escaper.PATTERN_CHARACTERS_TO_ESCAPE = new Pattern('[\\x00-\\x1f]|\xc2\x85|\xc2\xa0|\xe2\x80\xa8|\xe2\x80\xa9');
81
82 Escaper.PATTERN_MAPPING_ESCAPEES = new Pattern(Escaper.LIST_ESCAPEES.join('|'));
83
84 Escaper.PATTERN_SINGLE_QUOTING = new Pattern('[\\s\'":{}[\\],&*#?]|^[-?|<>=!%@`]');
85
86 Escaper.requiresDoubleQuoting = function(value) {
87 return this.PATTERN_CHARACTERS_TO_ESCAPE.test(value);
88 };
89
90 Escaper.escapeWithDoubleQuotes = function(value) {
91 var result;
92 result = this.PATTERN_MAPPING_ESCAPEES.replace(value, (function(_this) {
93 return function(str) {
94 return _this.MAPPING_ESCAPEES_TO_ESCAPED[str];
95 };
96 })(this));
97 return '"' + result + '"';
98 };
99
100 Escaper.requiresSingleQuoting = function(value) {
101 return this.PATTERN_SINGLE_QUOTING.test(value);
102 };
103
104 Escaper.escapeWithSingleQuotes = function(value) {
105 return "'" + value.replace(/'/g, "''") + "'";
106 };
107
108 return Escaper;
109
110})();
111
112module.exports = Escaper;
113
114
115
116},{"./Pattern":7}],3:[function(require,module,exports){
117var DumpException,
118 extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
119 hasProp = {}.hasOwnProperty;
120
121DumpException = (function(superClass) {
122 extend(DumpException, superClass);
123
124 function DumpException(message, parsedLine, snippet) {
125 this.message = message;
126 this.parsedLine = parsedLine;
127 this.snippet = snippet;
128 }
129
130 DumpException.prototype.toString = function() {
131 if ((this.parsedLine != null) && (this.snippet != null)) {
132 return '<DumpException> ' + this.message + ' (line ' + this.parsedLine + ': \'' + this.snippet + '\')';
133 } else {
134 return '<DumpException> ' + this.message;
135 }
136 };
137
138 return DumpException;
139
140})(Error);
141
142module.exports = DumpException;
143
144
145
146},{}],4:[function(require,module,exports){
147var ParseException,
148 extend = function(child, parent) { for (var key in parent) { if (hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; },
149 hasProp = {}.hasOwnProperty;
150
151ParseException = (function(superClass) {
152 extend(ParseException, superClass);
153
154 function ParseException(message, parsedLine, snippet) {
155 this.message = message;
156 this.parsedLine = parsedLine;
157 this.snippet = snippet;
158 }
159
160 ParseException.prototype.toString = function() {
161 if ((this.parsedLine != null) && (this.snippet != null)) {
162 return '<ParseException> ' + this.message + ' (line ' + this.parsedLine + ': \'' + this.snippet + '\')';
163 } else {
164 return '<ParseException> ' + this.message;
165 }
166 };
167
168 return ParseException;
169
170})(Error);
171
172module.exports = ParseException;
173
174
175
176},{}],5:[function(require,module,exports){
177var DumpException, Escaper, Inline, ParseException, Pattern, Unescaper, Utils,
178 indexOf = [].indexOf || function(item) { for (var i = 0, l = this.length; i < l; i++) { if (i in this && this[i] === item) return i; } return -1; };
179
180Pattern = require('./Pattern');
181
182Unescaper = require('./Unescaper');
183
184Escaper = require('./Escaper');
185
186Utils = require('./Utils');
187
188ParseException = require('./Exception/ParseException');
189
190DumpException = require('./Exception/DumpException');
191
192Inline = (function() {
193 function Inline() {}
194
195 Inline.REGEX_QUOTED_STRING = '(?:"(?:[^"\\\\]*(?:\\\\.[^"\\\\]*)*)"|\'(?:[^\']*(?:\'\'[^\']*)*)\')';
196
197 Inline.PATTERN_TRAILING_COMMENTS = new Pattern('^\\s*#.*$');
198
199 Inline.PATTERN_QUOTED_SCALAR = new Pattern('^' + Inline.REGEX_QUOTED_STRING);
200
201 Inline.PATTERN_THOUSAND_NUMERIC_SCALAR = new Pattern('^(-|\\+)?[0-9,]+(\\.[0-9]+)?$');
202
203 Inline.PATTERN_SCALAR_BY_DELIMITERS = {};
204
205 Inline.settings = {};
206
207 Inline.configure = function(exceptionOnInvalidType, objectDecoder) {
208 if (exceptionOnInvalidType == null) {
209 exceptionOnInvalidType = null;
210 }
211 if (objectDecoder == null) {
212 objectDecoder = null;
213 }
214 this.settings.exceptionOnInvalidType = exceptionOnInvalidType;
215 this.settings.objectDecoder = objectDecoder;
216 };
217
218 Inline.parse = function(value, exceptionOnInvalidType, objectDecoder) {
219 var context, result;
220 if (exceptionOnInvalidType == null) {
221 exceptionOnInvalidType = false;
222 }
223 if (objectDecoder == null) {
224 objectDecoder = null;
225 }
226 this.settings.exceptionOnInvalidType = exceptionOnInvalidType;
227 this.settings.objectDecoder = objectDecoder;
228 if (value == null) {
229 return '';
230 }
231 value = Utils.trim(value);
232 if (0 === value.length) {
233 return '';
234 }
235 context = {
236 exceptionOnInvalidType: exceptionOnInvalidType,
237 objectDecoder: objectDecoder,
238 i: 0
239 };
240 switch (value.charAt(0)) {
241 case '[':
242 result = this.parseSequence(value, context);
243 ++context.i;
244 break;
245 case '{':
246 result = this.parseMapping(value, context);
247 ++context.i;
248 break;
249 default:
250 result = this.parseScalar(value, null, ['"', "'"], context);
251 }
252 if (this.PATTERN_TRAILING_COMMENTS.replace(value.slice(context.i), '') !== '') {
253 throw new ParseException('Unexpected characters near "' + value.slice(context.i) + '".');
254 }
255 return result;
256 };
257
258 Inline.dump = function(value, exceptionOnInvalidType, objectEncoder) {
259 var ref, result, type;
260 if (exceptionOnInvalidType == null) {
261 exceptionOnInvalidType = false;
262 }
263 if (objectEncoder == null) {
264 objectEncoder = null;
265 }
266 if (value == null) {
267 return 'null';
268 }
269 type = typeof value;
270 if (type === 'object') {
271 if (value instanceof Date) {
272 return value.toISOString();
273 } else if (objectEncoder != null) {
274 result = objectEncoder(value);
275 if (typeof result === 'string' || (result != null)) {
276 return result;
277 }
278 }
279 return this.dumpObject(value);
280 }
281 if (type === 'boolean') {
282 return (value ? 'true' : 'false');
283 }
284 if (Utils.isDigits(value)) {
285 return (type === 'string' ? "'" + value + "'" : String(parseInt(value)));
286 }
287 if (Utils.isNumeric(value)) {
288 return (type === 'string' ? "'" + value + "'" : String(parseFloat(value)));
289 }
290 if (type === 'number') {
291 return (value === Infinity ? '.Inf' : (value === -Infinity ? '-.Inf' : (isNaN(value) ? '.NaN' : value)));
292 }
293 if (Escaper.requiresDoubleQuoting(value)) {
294 return Escaper.escapeWithDoubleQuotes(value);
295 }
296 if (Escaper.requiresSingleQuoting(value)) {
297 return Escaper.escapeWithSingleQuotes(value);
298 }
299 if ('' === value) {
300 return '""';
301 }
302 if (Utils.PATTERN_DATE.test(value)) {
303 return "'" + value + "'";
304 }
305 if ((ref = value.toLowerCase()) === 'null' || ref === '~' || ref === 'true' || ref === 'false') {
306 return "'" + value + "'";
307 }
308 return value;
309 };
310
311 Inline.dumpObject = function(value, exceptionOnInvalidType, objectSupport) {
312 var j, key, len1, output, val;
313 if (objectSupport == null) {
314 objectSupport = null;
315 }
316 if (value instanceof Array) {
317 output = [];
318 for (j = 0, len1 = value.length; j < len1; j++) {
319 val = value[j];
320 output.push(this.dump(val));
321 }
322 return '[' + output.join(', ') + ']';
323 } else {
324 output = [];
325 for (key in value) {
326 val = value[key];
327 output.push(this.dump(key) + ': ' + this.dump(val));
328 }
329 return '{' + output.join(', ') + '}';
330 }
331 };
332
333 Inline.parseScalar = function(scalar, delimiters, stringDelimiters, context, evaluate) {
334 var i, joinedDelimiters, match, output, pattern, ref, ref1, strpos, tmp;
335 if (delimiters == null) {
336 delimiters = null;
337 }
338 if (stringDelimiters == null) {
339 stringDelimiters = ['"', "'"];
340 }
341 if (context == null) {
342 context = null;
343 }
344 if (evaluate == null) {
345 evaluate = true;
346 }
347 if (context == null) {
348 context = {
349 exceptionOnInvalidType: this.settings.exceptionOnInvalidType,
350 objectDecoder: this.settings.objectDecoder,
351 i: 0
352 };
353 }
354 i = context.i;
355 if (ref = scalar.charAt(i), indexOf.call(stringDelimiters, ref) >= 0) {
356 output = this.parseQuotedScalar(scalar, context);
357 i = context.i;
358 if (delimiters != null) {
359 tmp = Utils.ltrim(scalar.slice(i), ' ');
360 if (!(ref1 = tmp.charAt(0), indexOf.call(delimiters, ref1) >= 0)) {
361 throw new ParseException('Unexpected characters (' + scalar.slice(i) + ').');
362 }
363 }
364 } else {
365 if (!delimiters) {
366 output = scalar.slice(i);
367 i += output.length;
368 strpos = output.indexOf(' #');
369 if (strpos !== -1) {
370 output = Utils.rtrim(output.slice(0, strpos));
371 }
372 } else {
373 joinedDelimiters = delimiters.join('|');
374 pattern = this.PATTERN_SCALAR_BY_DELIMITERS[joinedDelimiters];
375 if (pattern == null) {
376 pattern = new Pattern('^(.+?)(' + joinedDelimiters + ')');
377 this.PATTERN_SCALAR_BY_DELIMITERS[joinedDelimiters] = pattern;
378 }
379 if (match = pattern.exec(scalar.slice(i))) {
380 output = match[1];
381 i += output.length;
382 } else {
383 throw new ParseException('Malformed inline YAML string (' + scalar + ').');
384 }
385 }
386 if (evaluate) {
387 output = this.evaluateScalar(output, context);
388 }
389 }
390 context.i = i;
391 return output;
392 };
393
394 Inline.parseQuotedScalar = function(scalar, context) {
395 var i, match, output;
396 i = context.i;
397 if (!(match = this.PATTERN_QUOTED_SCALAR.exec(scalar.slice(i)))) {
398 throw new ParseException('Malformed inline YAML string (' + scalar.slice(i) + ').');
399 }
400 output = match[0].substr(1, match[0].length - 2);
401 if ('"' === scalar.charAt(i)) {
402 output = Unescaper.unescapeDoubleQuotedString(output);
403 } else {
404 output = Unescaper.unescapeSingleQuotedString(output);
405 }
406 i += match[0].length;
407 context.i = i;
408 return output;
409 };
410
411 Inline.parseSequence = function(sequence, context) {
412 var e, i, isQuoted, len, output, ref, value;
413 output = [];
414 len = sequence.length;
415 i = context.i;
416 i += 1;
417 while (i < len) {
418 context.i = i;
419 switch (sequence.charAt(i)) {
420 case '[':
421 output.push(this.parseSequence(sequence, context));
422 i = context.i;
423 break;
424 case '{':
425 output.push(this.parseMapping(sequence, context));
426 i = context.i;
427 break;
428 case ']':
429 return output;
430 case ',':
431 case ' ':
432 case "\n":
433 break;
434 default:
435 isQuoted = ((ref = sequence.charAt(i)) === '"' || ref === "'");
436 value = this.parseScalar(sequence, [',', ']'], ['"', "'"], context);
437 i = context.i;
438 if (!isQuoted && typeof value === 'string' && (value.indexOf(': ') !== -1 || value.indexOf(":\n") !== -1)) {
439 try {
440 value = this.parseMapping('{' + value + '}');
441 } catch (_error) {
442 e = _error;
443 }
444 }
445 output.push(value);
446 --i;
447 }
448 ++i;
449 }
450 throw new ParseException('Malformed inline YAML string ' + sequence);
451 };
452
453 Inline.parseMapping = function(mapping, context) {
454 var done, i, key, len, output, shouldContinueWhileLoop, value;
455 output = {};
456 len = mapping.length;
457 i = context.i;
458 i += 1;
459 shouldContinueWhileLoop = false;
460 while (i < len) {
461 context.i = i;
462 switch (mapping.charAt(i)) {
463 case ' ':
464 case ',':
465 case "\n":
466 ++i;
467 context.i = i;
468 shouldContinueWhileLoop = true;
469 break;
470 case '}':
471 return output;
472 }
473 if (shouldContinueWhileLoop) {
474 shouldContinueWhileLoop = false;
475 continue;
476 }
477 key = this.parseScalar(mapping, [':', ' ', "\n"], ['"', "'"], context, false);
478 i = context.i;
479 done = false;
480 while (i < len) {
481 context.i = i;
482 switch (mapping.charAt(i)) {
483 case '[':
484 value = this.parseSequence(mapping, context);
485 i = context.i;
486 if (output[key] === void 0) {
487 output[key] = value;
488 }
489 done = true;
490 break;
491 case '{':
492 value = this.parseMapping(mapping, context);
493 i = context.i;
494 if (output[key] === void 0) {
495 output[key] = value;
496 }
497 done = true;
498 break;
499 case ':':
500 case ' ':
501 case "\n":
502 break;
503 default:
504 value = this.parseScalar(mapping, [',', '}'], ['"', "'"], context);
505 i = context.i;
506 if (output[key] === void 0) {
507 output[key] = value;
508 }
509 done = true;
510 --i;
511 }
512 ++i;
513 if (done) {
514 break;
515 }
516 }
517 }
518 throw new ParseException('Malformed inline YAML string ' + mapping);
519 };
520
521 Inline.evaluateScalar = function(scalar, context) {
522 var cast, date, exceptionOnInvalidType, firstChar, firstSpace, firstWord, objectDecoder, raw, scalarLower, subValue, trimmedScalar;
523 scalar = Utils.trim(scalar);
524 scalarLower = scalar.toLowerCase();
525 switch (scalarLower) {
526 case 'null':
527 case '':
528 case '~':
529 return null;
530 case 'true':
531 return true;
532 case 'false':
533 return false;
534 case '.inf':
535 return Infinity;
536 case '.nan':
537 return NaN;
538 case '-.inf':
539 return Infinity;
540 default:
541 firstChar = scalarLower.charAt(0);
542 switch (firstChar) {
543 case '!':
544 firstSpace = scalar.indexOf(' ');
545 if (firstSpace === -1) {
546 firstWord = scalarLower;
547 } else {
548 firstWord = scalarLower.slice(0, firstSpace);
549 }
550 switch (firstWord) {
551 case '!':
552 if (firstSpace !== -1) {
553 return parseInt(this.parseScalar(scalar.slice(2)));
554 }
555 return null;
556 case '!str':
557 return Utils.ltrim(scalar.slice(4));
558 case '!!str':
559 return Utils.ltrim(scalar.slice(5));
560 case '!!int':
561 return parseInt(this.parseScalar(scalar.slice(5)));
562 case '!!bool':
563 return Utils.parseBoolean(this.parseScalar(scalar.slice(6)), false);
564 case '!!float':
565 return parseFloat(this.parseScalar(scalar.slice(7)));
566 case '!!timestamp':
567 return Utils.stringToDate(Utils.ltrim(scalar.slice(11)));
568 default:
569 if (context == null) {
570 context = {
571 exceptionOnInvalidType: this.settings.exceptionOnInvalidType,
572 objectDecoder: this.settings.objectDecoder,
573 i: 0
574 };
575 }
576 objectDecoder = context.objectDecoder, exceptionOnInvalidType = context.exceptionOnInvalidType;
577 if (objectDecoder) {
578 trimmedScalar = Utils.rtrim(scalar);
579 firstSpace = trimmedScalar.indexOf(' ');
580 if (firstSpace === -1) {
581 return objectDecoder(trimmedScalar, null);
582 } else {
583 subValue = Utils.ltrim(trimmedScalar.slice(firstSpace + 1));
584 if (!(subValue.length > 0)) {
585 subValue = null;
586 }
587 return objectDecoder(trimmedScalar.slice(0, firstSpace), subValue);
588 }
589 }
590 if (exceptionOnInvalidType) {
591 throw new ParseException('Custom object support when parsing a YAML file has been disabled.');
592 }
593 return null;
594 }
595 break;
596 case '0':
597 if ('0x' === scalar.slice(0, 2)) {
598 return Utils.hexDec(scalar);
599 } else if (Utils.isDigits(scalar)) {
600 return Utils.octDec(scalar);
601 } else if (Utils.isNumeric(scalar)) {
602 return parseFloat(scalar);
603 } else {
604 return scalar;
605 }
606 break;
607 case '+':
608 if (Utils.isDigits(scalar)) {
609 raw = scalar;
610 cast = parseInt(raw);
611 if (raw === String(cast)) {
612 return cast;
613 } else {
614 return raw;
615 }
616 } else if (Utils.isNumeric(scalar)) {
617 return parseFloat(scalar);
618 } else if (this.PATTERN_THOUSAND_NUMERIC_SCALAR.test(scalar)) {
619 return parseFloat(scalar.replace(',', ''));
620 }
621 return scalar;
622 case '-':
623 if (Utils.isDigits(scalar.slice(1))) {
624 if ('0' === scalar.charAt(1)) {
625 return -Utils.octDec(scalar.slice(1));
626 } else {
627 raw = scalar.slice(1);
628 cast = parseInt(raw);
629 if (raw === String(cast)) {
630 return -cast;
631 } else {
632 return -raw;
633 }
634 }
635 } else if (Utils.isNumeric(scalar)) {
636 return parseFloat(scalar);
637 } else if (this.PATTERN_THOUSAND_NUMERIC_SCALAR.test(scalar)) {
638 return parseFloat(scalar.replace(',', ''));
639 }
640 return scalar;
641 default:
642 if (date = Utils.stringToDate(scalar)) {
643 return date;
644 } else if (Utils.isNumeric(scalar)) {
645 return parseFloat(scalar);
646 } else if (this.PATTERN_THOUSAND_NUMERIC_SCALAR.test(scalar)) {
647 return parseFloat(scalar.replace(',', ''));
648 }
649 return scalar;
650 }
651 }
652 };
653
654 return Inline;
655
656})();
657
658module.exports = Inline;
659
660
661
662},{"./Escaper":2,"./Exception/DumpException":3,"./Exception/ParseException":4,"./Pattern":7,"./Unescaper":8,"./Utils":9}],6:[function(require,module,exports){
663var Inline, ParseException, Parser, Pattern, Utils;
664
665Inline = require('./Inline');
666
667Pattern = require('./Pattern');
668
669Utils = require('./Utils');
670
671ParseException = require('./Exception/ParseException');
672
673Parser = (function() {
674 Parser.prototype.PATTERN_FOLDED_SCALAR_ALL = new Pattern('^(?:(?<type>![^\\|>]*)\\s+)?(?<separator>\\||>)(?<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?<comments> +#.*)?$');
675
676 Parser.prototype.PATTERN_FOLDED_SCALAR_END = new Pattern('(?<separator>\\||>)(?<modifiers>\\+|\\-|\\d+|\\+\\d+|\\-\\d+|\\d+\\+|\\d+\\-)?(?<comments> +#.*)?$');
677
678 Parser.prototype.PATTERN_SEQUENCE_ITEM = new Pattern('^\\-((?<leadspaces>\\s+)(?<value>.+?))?\\s*$');
679
680 Parser.prototype.PATTERN_ANCHOR_VALUE = new Pattern('^&(?<ref>[^ ]+) *(?<value>.*)');
681
682 Parser.prototype.PATTERN_COMPACT_NOTATION = new Pattern('^(?<key>' + Inline.REGEX_QUOTED_STRING + '|[^ \'"\\{\\[].*?) *\\:(\\s+(?<value>.+?))?\\s*$');
683
684 Parser.prototype.PATTERN_MAPPING_ITEM = new Pattern('^(?<key>' + Inline.REGEX_QUOTED_STRING + '|[^ \'"\\[\\{].*?) *\\:(\\s+(?<value>.+?))?\\s*$');
685
686 Parser.prototype.PATTERN_DECIMAL = new Pattern('\\d+');
687
688 Parser.prototype.PATTERN_INDENT_SPACES = new Pattern('^ +');
689
690 Parser.prototype.PATTERN_TRAILING_LINES = new Pattern('(\n*)$');
691
692 Parser.prototype.PATTERN_YAML_HEADER = new Pattern('^\\%YAML[: ][\\d\\.]+.*\n');
693
694 Parser.prototype.PATTERN_LEADING_COMMENTS = new Pattern('^(\\#.*?\n)+');
695
696 Parser.prototype.PATTERN_DOCUMENT_MARKER_START = new Pattern('^\\-\\-\\-.*?\n');
697
698 Parser.prototype.PATTERN_DOCUMENT_MARKER_END = new Pattern('^\\.\\.\\.\\s*$');
699
700 Parser.prototype.PATTERN_FOLDED_SCALAR_BY_INDENTATION = {};
701
702 Parser.prototype.CONTEXT_NONE = 0;
703
704 Parser.prototype.CONTEXT_SEQUENCE = 1;
705
706 Parser.prototype.CONTEXT_MAPPING = 2;
707
708 function Parser(offset) {
709 this.offset = offset != null ? offset : 0;
710 this.lines = [];
711 this.currentLineNb = -1;
712 this.currentLine = '';
713 this.refs = {};
714 }
715
716 Parser.prototype.parse = function(value, exceptionOnInvalidType, objectDecoder) {
717 var alias, allowOverwrite, block, c, context, data, e, first, i, indent, isRef, j, k, key, l, lastKey, len, len1, len2, len3, lineCount, m, matches, mergeNode, n, name, parsed, parsedItem, parser, ref, ref1, ref2, refName, refValue, val, values;
718 if (exceptionOnInvalidType == null) {
719 exceptionOnInvalidType = false;
720 }
721 if (objectDecoder == null) {
722 objectDecoder = null;
723 }
724 this.currentLineNb = -1;
725 this.currentLine = '';
726 this.lines = this.cleanup(value).split("\n");
727 data = null;
728 context = this.CONTEXT_NONE;
729 allowOverwrite = false;
730 while (this.moveToNextLine()) {
731 if (this.isCurrentLineEmpty()) {
732 continue;
733 }
734 if ("\t" === this.currentLine[0]) {
735 throw new ParseException('A YAML file cannot contain tabs as indentation.', this.getRealCurrentLineNb() + 1, this.currentLine);
736 }
737 isRef = mergeNode = false;
738 if (values = this.PATTERN_SEQUENCE_ITEM.exec(this.currentLine)) {
739 if (this.CONTEXT_MAPPING === context) {
740 throw new ParseException('You cannot define a sequence item when in a mapping');
741 }
742 context = this.CONTEXT_SEQUENCE;
743 if (data == null) {
744 data = [];
745 }
746 if ((values.value != null) && (matches = this.PATTERN_ANCHOR_VALUE.exec(values.value))) {
747 isRef = matches.ref;
748 values.value = matches.value;
749 }
750 if (!(values.value != null) || '' === Utils.trim(values.value, ' ') || Utils.ltrim(values.value, ' ').indexOf('#') === 0) {
751 if (this.currentLineNb < this.lines.length - 1 && !this.isNextLineUnIndentedCollection()) {
752 c = this.getRealCurrentLineNb() + 1;
753 parser = new Parser(c);
754 parser.refs = this.refs;
755 data.push(parser.parse(this.getNextEmbedBlock(null, true), exceptionOnInvalidType, objectDecoder));
756 } else {
757 data.push(null);
758 }
759 } else {
760 if (((ref = values.leadspaces) != null ? ref.length : void 0) && (matches = this.PATTERN_COMPACT_NOTATION.exec(values.value))) {
761 c = this.getRealCurrentLineNb();
762 parser = new Parser(c);
763 parser.refs = this.refs;
764 block = values.value;
765 indent = this.getCurrentLineIndentation();
766 if (this.isNextLineIndented(false)) {
767 block += "\n" + this.getNextEmbedBlock(indent + values.leadspaces.length + 1, true);
768 }
769 data.push(parser.parse(block, exceptionOnInvalidType, objectDecoder));
770 } else {
771 data.push(this.parseValue(values.value, exceptionOnInvalidType, objectDecoder));
772 }
773 }
774 } else if ((values = this.PATTERN_MAPPING_ITEM.exec(this.currentLine)) && values.key.indexOf(' #') === -1) {
775 if (this.CONTEXT_SEQUENCE === context) {
776 throw new ParseException('You cannot define a mapping item when in a sequence');
777 }
778 context = this.CONTEXT_MAPPING;
779 if (data == null) {
780 data = {};
781 }
782 Inline.configure(exceptionOnInvalidType, objectDecoder);
783 try {
784 key = Inline.parseScalar(values.key);
785 } catch (_error) {
786 e = _error;
787 e.parsedLine = this.getRealCurrentLineNb() + 1;
788 e.snippet = this.currentLine;
789 throw e;
790 }
791 if ('<<' === key) {
792 mergeNode = true;
793 allowOverwrite = true;
794 if (((ref1 = values.value) != null ? ref1.indexOf('*') : void 0) === 0) {
795 refName = values.value.slice(1);
796 if (this.refs[refName] == null) {
797 throw new ParseException('Reference "' + refName + '" does not exist.', this.getRealCurrentLineNb() + 1, this.currentLine);
798 }
799 refValue = this.refs[refName];
800 if (typeof refValue !== 'object') {
801 throw new ParseException('YAML merge keys used with a scalar value instead of an object.', this.getRealCurrentLineNb() + 1, this.currentLine);
802 }
803 if (refValue instanceof Array) {
804 for (i = j = 0, len = refValue.length; j < len; i = ++j) {
805 value = refValue[i];
806 if (data[name = String(i)] == null) {
807 data[name] = value;
808 }
809 }
810 } else {
811 for (key in refValue) {
812 value = refValue[key];
813 if (data[key] == null) {
814 data[key] = value;
815 }
816 }
817 }
818 } else {
819 if ((values.value != null) && values.value !== '') {
820 value = values.value;
821 } else {
822 value = this.getNextEmbedBlock();
823 }
824 c = this.getRealCurrentLineNb() + 1;
825 parser = new Parser(c);
826 parser.refs = this.refs;
827 parsed = parser.parse(value, exceptionOnInvalidType);
828 if (typeof parsed !== 'object') {
829 throw new ParseException('YAML merge keys used with a scalar value instead of an object.', this.getRealCurrentLineNb() + 1, this.currentLine);
830 }
831 if (parsed instanceof Array) {
832 for (l = 0, len1 = parsed.length; l < len1; l++) {
833 parsedItem = parsed[l];
834 if (typeof parsedItem !== 'object') {
835 throw new ParseException('Merge items must be objects.', this.getRealCurrentLineNb() + 1, parsedItem);
836 }
837 if (parsedItem instanceof Array) {
838 for (i = m = 0, len2 = parsedItem.length; m < len2; i = ++m) {
839 value = parsedItem[i];
840 k = String(i);
841 if (!data.hasOwnProperty(k)) {
842 data[k] = value;
843 }
844 }
845 } else {
846 for (key in parsedItem) {
847 value = parsedItem[key];
848 if (!data.hasOwnProperty(key)) {
849 data[key] = value;
850 }
851 }
852 }
853 }
854 } else {
855 for (key in parsed) {
856 value = parsed[key];
857 if (!data.hasOwnProperty(key)) {
858 data[key] = value;
859 }
860 }
861 }
862 }
863 } else if ((values.value != null) && (matches = this.PATTERN_ANCHOR_VALUE.exec(values.value))) {
864 isRef = matches.ref;
865 values.value = matches.value;
866 }
867 if (mergeNode) {
868
869 } else if (!(values.value != null) || '' === Utils.trim(values.value, ' ') || Utils.ltrim(values.value, ' ').indexOf('#') === 0) {
870 if (!(this.isNextLineIndented()) && !(this.isNextLineUnIndentedCollection())) {
871 if (allowOverwrite || data[key] === void 0) {
872 data[key] = null;
873 }
874 } else {
875 c = this.getRealCurrentLineNb() + 1;
876 parser = new Parser(c);
877 parser.refs = this.refs;
878 val = parser.parse(this.getNextEmbedBlock(), exceptionOnInvalidType, objectDecoder);
879 if (allowOverwrite || data[key] === void 0) {
880 data[key] = val;
881 }
882 }
883 } else {
884 val = this.parseValue(values.value, exceptionOnInvalidType, objectDecoder);
885 if (allowOverwrite || data[key] === void 0) {
886 data[key] = val;
887 }
888 }
889 } else {
890 lineCount = this.lines.length;
891 if (1 === lineCount || (2 === lineCount && Utils.isEmpty(this.lines[1]))) {
892 try {
893 value = Inline.parse(this.lines[0], exceptionOnInvalidType, objectDecoder);
894 } catch (_error) {
895 e = _error;
896 e.parsedLine = this.getRealCurrentLineNb() + 1;
897 e.snippet = this.currentLine;
898 throw e;
899 }
900 if (typeof value === 'object') {
901 if (value instanceof Array) {
902 first = value[0];
903 } else {
904 for (key in value) {
905 first = value[key];
906 break;
907 }
908 }
909 if (typeof first === 'string' && first.indexOf('*') === 0) {
910 data = [];
911 for (n = 0, len3 = value.length; n < len3; n++) {
912 alias = value[n];
913 data.push(this.refs[alias.slice(1)]);
914 }
915 value = data;
916 }
917 }
918 return value;
919 } else if ((ref2 = Utils.ltrim(value).charAt(0)) === '[' || ref2 === '{') {
920 try {
921 return Inline.parse(value, exceptionOnInvalidType, objectDecoder);
922 } catch (_error) {
923 e = _error;
924 e.parsedLine = this.getRealCurrentLineNb() + 1;
925 e.snippet = this.currentLine;
926 throw e;
927 }
928 }
929 throw new ParseException('Unable to parse.', this.getRealCurrentLineNb() + 1, this.currentLine);
930 }
931 if (isRef) {
932 if (data instanceof Array) {
933 this.refs[isRef] = data[data.length - 1];
934 } else {
935 lastKey = null;
936 for (key in data) {
937 lastKey = key;
938 }
939 this.refs[isRef] = data[lastKey];
940 }
941 }
942 }
943 if (Utils.isEmpty(data)) {
944 return null;
945 } else {
946 return data;
947 }
948 };
949
950 Parser.prototype.getRealCurrentLineNb = function() {
951 return this.currentLineNb + this.offset;
952 };
953
954 Parser.prototype.getCurrentLineIndentation = function() {
955 return this.currentLine.length - Utils.ltrim(this.currentLine, ' ').length;
956 };
957
958 Parser.prototype.getNextEmbedBlock = function(indentation, includeUnindentedCollection) {
959 var data, indent, isItUnindentedCollection, newIndent, removeComments, removeCommentsPattern, unindentedEmbedBlock;
960 if (indentation == null) {
961 indentation = null;
962 }
963 if (includeUnindentedCollection == null) {
964 includeUnindentedCollection = false;
965 }
966 this.moveToNextLine();
967 if (indentation == null) {
968 newIndent = this.getCurrentLineIndentation();
969 unindentedEmbedBlock = this.isStringUnIndentedCollectionItem(this.currentLine);
970 if (!(this.isCurrentLineEmpty()) && 0 === newIndent && !unindentedEmbedBlock) {
971 throw new ParseException('Indentation problem.', this.getRealCurrentLineNb() + 1, this.currentLine);
972 }
973 } else {
974 newIndent = indentation;
975 }
976 data = [this.currentLine.slice(newIndent)];
977 if (!includeUnindentedCollection) {
978 isItUnindentedCollection = this.isStringUnIndentedCollectionItem(this.currentLine);
979 }
980 removeCommentsPattern = this.PATTERN_FOLDED_SCALAR_END;
981 removeComments = !removeCommentsPattern.test(this.currentLine);
982 while (this.moveToNextLine()) {
983 indent = this.getCurrentLineIndentation();
984 if (indent === newIndent) {
985 removeComments = !removeCommentsPattern.test(this.currentLine);
986 }
987 if (isItUnindentedCollection && !this.isStringUnIndentedCollectionItem(this.currentLine) && indent === newIndent) {
988 this.moveToPreviousLine();
989 break;
990 }
991 if (this.isCurrentLineBlank()) {
992 data.push(this.currentLine.slice(newIndent));
993 continue;
994 }
995 if (removeComments && this.isCurrentLineComment()) {
996 if (indent === newIndent) {
997 continue;
998 }
999 }
1000 if (indent >= newIndent) {
1001 data.push(this.currentLine.slice(newIndent));
1002 } else if (0 === indent) {
1003 this.moveToPreviousLine();
1004 break;
1005 } else {
1006 throw new ParseException('Indentation problem.', this.getRealCurrentLineNb() + 1, this.currentLine);
1007 }
1008 }
1009 return data.join("\n");
1010 };
1011
1012 Parser.prototype.moveToNextLine = function() {
1013 if (this.currentLineNb >= this.lines.length - 1) {
1014 return false;
1015 }
1016 this.currentLine = this.lines[++this.currentLineNb];
1017 return true;
1018 };
1019
1020 Parser.prototype.moveToPreviousLine = function() {
1021 this.currentLine = this.lines[--this.currentLineNb];
1022 };
1023
1024 Parser.prototype.parseValue = function(value, exceptionOnInvalidType, objectDecoder) {
1025 var e, foldedIndent, matches, modifiers, pos, ref, ref1, val;
1026 if (0 === value.indexOf('*')) {
1027 pos = value.indexOf('#');
1028 if (pos !== -1) {
1029 value = value.substr(1, pos - 2);
1030 } else {
1031 value = value.slice(1);
1032 }
1033 if (this.refs[value] === void 0) {
1034 throw new ParseException('Reference "' + value + '" does not exist.', this.currentLine);
1035 }
1036 return this.refs[value];
1037 }
1038 if (matches = this.PATTERN_FOLDED_SCALAR_ALL.exec(value)) {
1039 modifiers = (ref = matches.modifiers) != null ? ref : '';
1040 foldedIndent = Math.abs(parseInt(modifiers));
1041 if (isNaN(foldedIndent)) {
1042 foldedIndent = 0;
1043 }
1044 val = this.parseFoldedScalar(matches.separator, this.PATTERN_DECIMAL.replace(modifiers, ''), foldedIndent);
1045 if (matches.type != null) {
1046 Inline.configure(exceptionOnInvalidType, objectDecoder);
1047 return Inline.parseScalar(matches.type + ' ' + val);
1048 } else {
1049 return val;
1050 }
1051 }
1052 try {
1053 return Inline.parse(value, exceptionOnInvalidType, objectDecoder);
1054 } catch (_error) {
1055 e = _error;
1056 if (((ref1 = value.charAt(0)) === '[' || ref1 === '{') && e instanceof ParseException && this.isNextLineIndented()) {
1057 value += "\n" + this.getNextEmbedBlock();
1058 try {
1059 return Inline.parse(value, exceptionOnInvalidType, objectDecoder);
1060 } catch (_error) {
1061 e = _error;
1062 e.parsedLine = this.getRealCurrentLineNb() + 1;
1063 e.snippet = this.currentLine;
1064 throw e;
1065 }
1066 } else {
1067 e.parsedLine = this.getRealCurrentLineNb() + 1;
1068 e.snippet = this.currentLine;
1069 throw e;
1070 }
1071 }
1072 };
1073
1074 Parser.prototype.parseFoldedScalar = function(separator, indicator, indentation) {
1075 var isCurrentLineBlank, j, len, line, matches, newText, notEOF, pattern, ref, text;
1076 if (indicator == null) {
1077 indicator = '';
1078 }
1079 if (indentation == null) {
1080 indentation = 0;
1081 }
1082 notEOF = this.moveToNextLine();
1083 if (!notEOF) {
1084 return '';
1085 }
1086 isCurrentLineBlank = this.isCurrentLineBlank();
1087 text = '';
1088 while (notEOF && isCurrentLineBlank) {
1089 if (notEOF = this.moveToNextLine()) {
1090 text += "\n";
1091 isCurrentLineBlank = this.isCurrentLineBlank();
1092 }
1093 }
1094 if (0 === indentation) {
1095 if (matches = this.PATTERN_INDENT_SPACES.exec(this.currentLine)) {
1096 indentation = matches[0].length;
1097 }
1098 }
1099 if (indentation > 0) {
1100 pattern = this.PATTERN_FOLDED_SCALAR_BY_INDENTATION[indentation];
1101 if (pattern == null) {
1102 pattern = new Pattern('^ {' + indentation + '}(.*)$');
1103 Parser.prototype.PATTERN_FOLDED_SCALAR_BY_INDENTATION[indentation] = pattern;
1104 }
1105 while (notEOF && (isCurrentLineBlank || (matches = pattern.exec(this.currentLine)))) {
1106 if (isCurrentLineBlank) {
1107 text += this.currentLine.slice(indentation);
1108 } else {
1109 text += matches[1];
1110 }
1111 if (notEOF = this.moveToNextLine()) {
1112 text += "\n";
1113 isCurrentLineBlank = this.isCurrentLineBlank();
1114 }
1115 }
1116 } else if (notEOF) {
1117 text += "\n";
1118 }
1119 if (notEOF) {
1120 this.moveToPreviousLine();
1121 }
1122 if ('>' === separator) {
1123 newText = '';
1124 ref = text.split("\n");
1125 for (j = 0, len = ref.length; j < len; j++) {
1126 line = ref[j];
1127 if (line.length === 0 || line.charAt(0) === ' ') {
1128 newText = Utils.rtrim(newText, ' ') + line + "\n";
1129 } else {
1130 newText += line + ' ';
1131 }
1132 }
1133 text = newText;
1134 }
1135 if ('+' !== indicator) {
1136 text = Utils.rtrim(text);
1137 }
1138 if ('' === indicator) {
1139 text = this.PATTERN_TRAILING_LINES.replace(text, "\n");
1140 } else if ('-' === indicator) {
1141 text = this.PATTERN_TRAILING_LINES.replace(text, '');
1142 }
1143 return text;
1144 };
1145
1146 Parser.prototype.isNextLineIndented = function(ignoreComments) {
1147 var EOF, currentIndentation, ret;
1148 if (ignoreComments == null) {
1149 ignoreComments = true;
1150 }
1151 currentIndentation = this.getCurrentLineIndentation();
1152 EOF = !this.moveToNextLine();
1153 if (ignoreComments) {
1154 while (!EOF && this.isCurrentLineEmpty()) {
1155 EOF = !this.moveToNextLine();
1156 }
1157 } else {
1158 while (!EOF && this.isCurrentLineBlank()) {
1159 EOF = !this.moveToNextLine();
1160 }
1161 }
1162 if (EOF) {
1163 return false;
1164 }
1165 ret = false;
1166 if (this.getCurrentLineIndentation() > currentIndentation) {
1167 ret = true;
1168 }
1169 this.moveToPreviousLine();
1170 return ret;
1171 };
1172
1173 Parser.prototype.isCurrentLineEmpty = function() {
1174 var trimmedLine;
1175 trimmedLine = Utils.trim(this.currentLine, ' ');
1176 return trimmedLine.length === 0 || trimmedLine.charAt(0) === '#';
1177 };
1178
1179 Parser.prototype.isCurrentLineBlank = function() {
1180 return '' === Utils.trim(this.currentLine, ' ');
1181 };
1182
1183 Parser.prototype.isCurrentLineComment = function() {
1184 var ltrimmedLine;
1185 ltrimmedLine = Utils.ltrim(this.currentLine, ' ');
1186 return ltrimmedLine.charAt(0) === '#';
1187 };
1188
1189 Parser.prototype.cleanup = function(value) {
1190 var count, ref, ref1, ref2, trimmedValue;
1191 if (value.indexOf("\r") !== -1) {
1192 value = value.split("\r\n").join("\n").split("\r").join("\n");
1193 }
1194 count = 0;
1195 ref = this.PATTERN_YAML_HEADER.replaceAll(value, ''), value = ref[0], count = ref[1];
1196 this.offset += count;
1197 ref1 = this.PATTERN_LEADING_COMMENTS.replaceAll(value, '', 1), trimmedValue = ref1[0], count = ref1[1];
1198 if (count === 1) {
1199 this.offset += Utils.subStrCount(value, "\n") - Utils.subStrCount(trimmedValue, "\n");
1200 value = trimmedValue;
1201 }
1202 ref2 = this.PATTERN_DOCUMENT_MARKER_START.replaceAll(value, '', 1), trimmedValue = ref2[0], count = ref2[1];
1203 if (count === 1) {
1204 this.offset += Utils.subStrCount(value, "\n") - Utils.subStrCount(trimmedValue, "\n");
1205 value = trimmedValue;
1206 value = this.PATTERN_DOCUMENT_MARKER_END.replace(value, '');
1207 }
1208 return value;
1209 };
1210
1211 Parser.prototype.isNextLineUnIndentedCollection = function(currentIndentation) {
1212 var notEOF, ret;
1213 if (currentIndentation == null) {
1214 currentIndentation = null;
1215 }
1216 if (currentIndentation == null) {
1217 currentIndentation = this.getCurrentLineIndentation();
1218 }
1219 notEOF = this.moveToNextLine();
1220 while (notEOF && this.isCurrentLineEmpty()) {
1221 notEOF = this.moveToNextLine();
1222 }
1223 if (false === notEOF) {
1224 return false;
1225 }
1226 ret = false;
1227 if (this.getCurrentLineIndentation() === currentIndentation && this.isStringUnIndentedCollectionItem(this.currentLine)) {
1228 ret = true;
1229 }
1230 this.moveToPreviousLine();
1231 return ret;
1232 };
1233
1234 Parser.prototype.isStringUnIndentedCollectionItem = function() {
1235 return this.currentLine === '-' || this.currentLine.slice(0, 2) === '- ';
1236 };
1237
1238 return Parser;
1239
1240})();
1241
1242module.exports = Parser;
1243
1244
1245
1246},{"./Exception/ParseException":4,"./Inline":5,"./Pattern":7,"./Utils":9}],7:[function(require,module,exports){
1247var Pattern;
1248
1249Pattern = (function() {
1250 Pattern.prototype.regex = null;
1251
1252 Pattern.prototype.rawRegex = null;
1253
1254 Pattern.prototype.cleanedRegex = null;
1255
1256 Pattern.prototype.mapping = null;
1257
1258 function Pattern(rawRegex, modifiers) {
1259 var capturingBracketNumber, char, cleanedRegex, i, len, mapping, name, part, subChar;
1260 if (modifiers == null) {
1261 modifiers = '';
1262 }
1263 cleanedRegex = '';
1264 len = rawRegex.length;
1265 mapping = null;
1266 capturingBracketNumber = 0;
1267 i = 0;
1268 while (i < len) {
1269 char = rawRegex.charAt(i);
1270 if (char === '\\') {
1271 cleanedRegex += rawRegex.slice(i, +(i + 1) + 1 || 9e9);
1272 i++;
1273 } else if (char === '(') {
1274 if (i < len - 2) {
1275 part = rawRegex.slice(i, +(i + 2) + 1 || 9e9);
1276 if (part === '(?:') {
1277 i += 2;
1278 cleanedRegex += part;
1279 } else if (part === '(?<') {
1280 capturingBracketNumber++;
1281 i += 2;
1282 name = '';
1283 while (i + 1 < len) {
1284 subChar = rawRegex.charAt(i + 1);
1285 if (subChar === '>') {
1286 cleanedRegex += '(';
1287 i++;
1288 if (name.length > 0) {
1289 if (mapping == null) {
1290 mapping = {};
1291 }
1292 mapping[name] = capturingBracketNumber;
1293 }
1294 break;
1295 } else {
1296 name += subChar;
1297 }
1298 i++;
1299 }
1300 } else {
1301 cleanedRegex += char;
1302 capturingBracketNumber++;
1303 }
1304 } else {
1305 cleanedRegex += char;
1306 }
1307 } else {
1308 cleanedRegex += char;
1309 }
1310 i++;
1311 }
1312 this.rawRegex = rawRegex;
1313 this.cleanedRegex = cleanedRegex;
1314 this.regex = new RegExp(this.cleanedRegex, 'g' + modifiers.replace('g', ''));
1315 this.mapping = mapping;
1316 }
1317
1318 Pattern.prototype.exec = function(str) {
1319 var index, matches, name, ref;
1320 this.regex.lastIndex = 0;
1321 matches = this.regex.exec(str);
1322 if (matches == null) {
1323 return null;
1324 }
1325 if (this.mapping != null) {
1326 ref = this.mapping;
1327 for (name in ref) {
1328 index = ref[name];
1329 matches[name] = matches[index];
1330 }
1331 }
1332 return matches;
1333 };
1334
1335 Pattern.prototype.test = function(str) {
1336 this.regex.lastIndex = 0;
1337 return this.regex.test(str);
1338 };
1339
1340 Pattern.prototype.replace = function(str, replacement) {
1341 this.regex.lastIndex = 0;
1342 return str.replace(this.regex, replacement);
1343 };
1344
1345 Pattern.prototype.replaceAll = function(str, replacement, limit) {
1346 var count;
1347 if (limit == null) {
1348 limit = 0;
1349 }
1350 this.regex.lastIndex = 0;
1351 count = 0;
1352 while (this.regex.test(str) && (limit === 0 || count < limit)) {
1353 this.regex.lastIndex = 0;
1354 str = str.replace(this.regex, '');
1355 count++;
1356 }
1357 return [str, count];
1358 };
1359
1360 return Pattern;
1361
1362})();
1363
1364module.exports = Pattern;
1365
1366
1367
1368},{}],8:[function(require,module,exports){
1369var Pattern, Unescaper, Utils;
1370
1371Utils = require('./Utils');
1372
1373Pattern = require('./Pattern');
1374
1375Unescaper = (function() {
1376 function Unescaper() {}
1377
1378 Unescaper.PATTERN_ESCAPED_CHARACTER = new Pattern('\\\\([0abt\tnvfre "\\/\\\\N_LP]|x[0-9a-fA-F]{2}|u[0-9a-fA-F]{4}|U[0-9a-fA-F]{8})');
1379
1380 Unescaper.unescapeSingleQuotedString = function(value) {
1381 return value.replace('\'\'', '\'');
1382 };
1383
1384 Unescaper.unescapeDoubleQuotedString = function(value) {
1385 if (this._unescapeCallback == null) {
1386 this._unescapeCallback = (function(_this) {
1387 return function(str) {
1388 return _this.unescapeCharacter(str);
1389 };
1390 })(this);
1391 }
1392 return this.PATTERN_ESCAPED_CHARACTER.replace(value, this._unescapeCallback);
1393 };
1394
1395 Unescaper.unescapeCharacter = function(value) {
1396 var ch;
1397 ch = String.fromCharCode;
1398 switch (value.charAt(1)) {
1399 case '0':
1400 return ch(0);
1401 case 'a':
1402 return ch(7);
1403 case 'b':
1404 return ch(8);
1405 case 't':
1406 return "\t";
1407 case "\t":
1408 return "\t";
1409 case 'n':
1410 return "\n";
1411 case 'v':
1412 return ch(11);
1413 case 'f':
1414 return ch(12);
1415 case 'r':
1416 return ch(13);
1417 case 'e':
1418 return ch(27);
1419 case ' ':
1420 return ' ';
1421 case '"':
1422 return '"';
1423 case '/':
1424 return '/';
1425 case '\\':
1426 return '\\';
1427 case 'N':
1428 return ch(0x0085);
1429 case '_':
1430 return ch(0x00A0);
1431 case 'L':
1432 return ch(0x2028);
1433 case 'P':
1434 return ch(0x2029);
1435 case 'x':
1436 return Utils.utf8chr(Utils.hexDec(value.substr(2, 2)));
1437 case 'u':
1438 return Utils.utf8chr(Utils.hexDec(value.substr(2, 4)));
1439 case 'U':
1440 return Utils.utf8chr(Utils.hexDec(value.substr(2, 8)));
1441 default:
1442 return '';
1443 }
1444 };
1445
1446 return Unescaper;
1447
1448})();
1449
1450module.exports = Unescaper;
1451
1452
1453
1454},{"./Pattern":7,"./Utils":9}],9:[function(require,module,exports){
1455var Pattern, Utils;
1456
1457Pattern = require('./Pattern');
1458
1459Utils = (function() {
1460 function Utils() {}
1461
1462 Utils.REGEX_LEFT_TRIM_BY_CHAR = {};
1463
1464 Utils.REGEX_RIGHT_TRIM_BY_CHAR = {};
1465
1466 Utils.REGEX_SPACES = /\s+/g;
1467
1468 Utils.REGEX_DIGITS = /^\d+$/;
1469
1470 Utils.REGEX_OCTAL = /[^0-7]/gi;
1471
1472 Utils.REGEX_HEXADECIMAL = /[^a-f0-9]/gi;
1473
1474 Utils.PATTERN_DATE = new Pattern('^' + '(?<year>[0-9][0-9][0-9][0-9])' + '-(?<month>[0-9][0-9]?)' + '-(?<day>[0-9][0-9]?)' + '(?:(?:[Tt]|[ \t]+)' + '(?<hour>[0-9][0-9]?)' + ':(?<minute>[0-9][0-9])' + ':(?<second>[0-9][0-9])' + '(?:\.(?<fraction>[0-9]*))?' + '(?:[ \t]*(?<tz>Z|(?<tz_sign>[-+])(?<tz_hour>[0-9][0-9]?)' + '(?::(?<tz_minute>[0-9][0-9]))?))?)?' + '$', 'i');
1475
1476 Utils.LOCAL_TIMEZONE_OFFSET = new Date().getTimezoneOffset() * 60 * 1000;
1477
1478 Utils.trim = function(str, char) {
1479 var regexLeft, regexRight;
1480 if (char == null) {
1481 char = '\\s';
1482 }
1483 return str.trim();
1484 regexLeft = this.REGEX_LEFT_TRIM_BY_CHAR[char];
1485 if (regexLeft == null) {
1486 this.REGEX_LEFT_TRIM_BY_CHAR[char] = regexLeft = new RegExp('^' + char + '' + char + '*');
1487 }
1488 regexLeft.lastIndex = 0;
1489 regexRight = this.REGEX_RIGHT_TRIM_BY_CHAR[char];
1490 if (regexRight == null) {
1491 this.REGEX_RIGHT_TRIM_BY_CHAR[char] = regexRight = new RegExp(char + '' + char + '*$');
1492 }
1493 regexRight.lastIndex = 0;
1494 return str.replace(regexLeft, '').replace(regexRight, '');
1495 };
1496
1497 Utils.ltrim = function(str, char) {
1498 var regexLeft;
1499 if (char == null) {
1500 char = '\\s';
1501 }
1502 regexLeft = this.REGEX_LEFT_TRIM_BY_CHAR[char];
1503 if (regexLeft == null) {
1504 this.REGEX_LEFT_TRIM_BY_CHAR[char] = regexLeft = new RegExp('^' + char + '' + char + '*');
1505 }
1506 regexLeft.lastIndex = 0;
1507 return str.replace(regexLeft, '');
1508 };
1509
1510 Utils.rtrim = function(str, char) {
1511 var regexRight;
1512 if (char == null) {
1513 char = '\\s';
1514 }
1515 regexRight = this.REGEX_RIGHT_TRIM_BY_CHAR[char];
1516 if (regexRight == null) {
1517 this.REGEX_RIGHT_TRIM_BY_CHAR[char] = regexRight = new RegExp(char + '' + char + '*$');
1518 }
1519 regexRight.lastIndex = 0;
1520 return str.replace(regexRight, '');
1521 };
1522
1523 Utils.isEmpty = function(value) {
1524 return !value || value === '' || value === '0';
1525 };
1526
1527 Utils.subStrCount = function(string, subString, start, length) {
1528 var c, i, j, len, ref, sublen;
1529 c = 0;
1530 string = '' + string;
1531 subString = '' + subString;
1532 if (start != null) {
1533 string = string.slice(start);
1534 }
1535 if (length != null) {
1536 string = string.slice(0, length);
1537 }
1538 len = string.length;
1539 sublen = subString.length;
1540 for (i = j = 0, ref = len; 0 <= ref ? j < ref : j > ref; i = 0 <= ref ? ++j : --j) {
1541 if (subString === string.slice(i, sublen)) {
1542 c++;
1543 i += sublen - 1;
1544 }
1545 }
1546 return c;
1547 };
1548
1549 Utils.isDigits = function(input) {
1550 this.REGEX_DIGITS.lastIndex = 0;
1551 return this.REGEX_DIGITS.test(input);
1552 };
1553
1554 Utils.octDec = function(input) {
1555 this.REGEX_OCTAL.lastIndex = 0;
1556 return parseInt((input + '').replace(this.REGEX_OCTAL, ''), 8);
1557 };
1558
1559 Utils.hexDec = function(input) {
1560 this.REGEX_HEXADECIMAL.lastIndex = 0;
1561 input = this.trim(input);
1562 if ((input + '').slice(0, 2) === '0x') {
1563 input = (input + '').slice(2);
1564 }
1565 return parseInt((input + '').replace(this.REGEX_HEXADECIMAL, ''), 16);
1566 };
1567
1568 Utils.utf8chr = function(c) {
1569 var ch;
1570 ch = String.fromCharCode;
1571 if (0x80 > (c %= 0x200000)) {
1572 return ch(c);
1573 }
1574 if (0x800 > c) {
1575 return ch(0xC0 | c >> 6) + ch(0x80 | c & 0x3F);
1576 }
1577 if (0x10000 > c) {
1578 return ch(0xE0 | c >> 12) + ch(0x80 | c >> 6 & 0x3F) + ch(0x80 | c & 0x3F);
1579 }
1580 return ch(0xF0 | c >> 18) + ch(0x80 | c >> 12 & 0x3F) + ch(0x80 | c >> 6 & 0x3F) + ch(0x80 | c & 0x3F);
1581 };
1582
1583 Utils.parseBoolean = function(input, strict) {
1584 var lowerInput;
1585 if (strict == null) {
1586 strict = true;
1587 }
1588 if (typeof input === 'string') {
1589 lowerInput = input.toLowerCase();
1590 if (!strict) {
1591 if (lowerInput === 'no') {
1592 return false;
1593 }
1594 }
1595 if (lowerInput === '0') {
1596 return false;
1597 }
1598 if (lowerInput === 'false') {
1599 return false;
1600 }
1601 if (lowerInput === '') {
1602 return false;
1603 }
1604 return true;
1605 }
1606 return !!input;
1607 };
1608
1609 Utils.isNumeric = function(input) {
1610 this.REGEX_SPACES.lastIndex = 0;
1611 return typeof input === 'number' || typeof input === 'string' && !isNaN(input) && input.replace(this.REGEX_SPACES, '') !== '';
1612 };
1613
1614 Utils.stringToDate = function(str) {
1615 var date, day, fraction, hour, info, minute, month, second, tz_hour, tz_minute, tz_offset, year;
1616 if (!(str != null ? str.length : void 0)) {
1617 return null;
1618 }
1619 info = this.PATTERN_DATE.exec(str);
1620 if (!info) {
1621 return null;
1622 }
1623 year = parseInt(info.year, 10);
1624 month = parseInt(info.month, 10) - 1;
1625 day = parseInt(info.day, 10);
1626 if (info.hour == null) {
1627 date = new Date(Date.UTC(year, month, day));
1628 return date;
1629 }
1630 hour = parseInt(info.hour, 10);
1631 minute = parseInt(info.minute, 10);
1632 second = parseInt(info.second, 10);
1633 if (info.fraction != null) {
1634 fraction = info.fraction.slice(0, 3);
1635 while (fraction.length < 3) {
1636 fraction += '0';
1637 }
1638 fraction = parseInt(fraction, 10);
1639 } else {
1640 fraction = 0;
1641 }
1642 if (info.tz != null) {
1643 tz_hour = parseInt(info.tz_hour, 10);
1644 if (info.tz_minute != null) {
1645 tz_minute = parseInt(info.tz_minute, 10);
1646 } else {
1647 tz_minute = 0;
1648 }
1649 tz_offset = (tz_hour * 60 + tz_minute) * 60000;
1650 if ('-' === info.tz_sign) {
1651 tz_offset *= -1;
1652 }
1653 }
1654 date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
1655 if (tz_offset) {
1656 date.setTime(date.getTime() + tz_offset);
1657 }
1658 return date;
1659 };
1660
1661 Utils.strRepeat = function(str, number) {
1662 var i, res;
1663 res = '';
1664 i = 0;
1665 while (i < number) {
1666 res += str;
1667 i++;
1668 }
1669 return res;
1670 };
1671
1672 Utils.getStringFromFile = function(path, callback) {
1673 var data, fs, j, len1, name, ref, req, xhr;
1674 if (callback == null) {
1675 callback = null;
1676 }
1677 xhr = null;
1678 if (typeof window !== "undefined" && window !== null) {
1679 if (window.XMLHttpRequest) {
1680 xhr = new XMLHttpRequest();
1681 } else if (window.ActiveXObject) {
1682 ref = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP", "Microsoft.XMLHTTP"];
1683 for (j = 0, len1 = ref.length; j < len1; j++) {
1684 name = ref[j];
1685 try {
1686 xhr = new ActiveXObject(name);
1687 } catch (_error) {}
1688 }
1689 }
1690 }
1691 if (xhr != null) {
1692 if (callback != null) {
1693 xhr.onreadystatechange = function() {
1694 if (xhr.readyState === 4) {
1695 if (xhr.status === 200 || xhr.status === 0) {
1696 return callback(xhr.responseText);
1697 } else {
1698 return callback(null);
1699 }
1700 }
1701 };
1702 xhr.open('GET', path, true);
1703 return xhr.send(null);
1704 } else {
1705 xhr.open('GET', path, false);
1706 xhr.send(null);
1707 if (xhr.status === 200 || xhr.status === 0) {
1708 return xhr.responseText;
1709 }
1710 return null;
1711 }
1712 } else {
1713 req = require;
1714 fs = req('fs');
1715 if (callback != null) {
1716 return fs.readFile(path, function(err, data) {
1717 if (err) {
1718 return callback(null);
1719 } else {
1720 return callback(String(data));
1721 }
1722 });
1723 } else {
1724 data = fs.readFileSync(path);
1725 if (data != null) {
1726 return String(data);
1727 }
1728 return null;
1729 }
1730 }
1731 };
1732
1733 return Utils;
1734
1735})();
1736
1737module.exports = Utils;
1738
1739
1740
1741},{"./Pattern":7}],10:[function(require,module,exports){
1742var Dumper, Parser, Utils, Yaml;
1743
1744Parser = require('./Parser');
1745
1746Dumper = require('./Dumper');
1747
1748Utils = require('./Utils');
1749
1750Yaml = (function() {
1751 function Yaml() {}
1752
1753 Yaml.parse = function(input, exceptionOnInvalidType, objectDecoder) {
1754 if (exceptionOnInvalidType == null) {
1755 exceptionOnInvalidType = false;
1756 }
1757 if (objectDecoder == null) {
1758 objectDecoder = null;
1759 }
1760 return new Parser().parse(input, exceptionOnInvalidType, objectDecoder);
1761 };
1762
1763 Yaml.parseFile = function(path, callback, exceptionOnInvalidType, objectDecoder) {
1764 var input;
1765 if (callback == null) {
1766 callback = null;
1767 }
1768 if (exceptionOnInvalidType == null) {
1769 exceptionOnInvalidType = false;
1770 }
1771 if (objectDecoder == null) {
1772 objectDecoder = null;
1773 }
1774 if (callback != null) {
1775 return Utils.getStringFromFile(path, (function(_this) {
1776 return function(input) {
1777 var result;
1778 result = null;
1779 if (input != null) {
1780 result = _this.parse(input, exceptionOnInvalidType, objectDecoder);
1781 }
1782 callback(result);
1783 };
1784 })(this));
1785 } else {
1786 input = Utils.getStringFromFile(path);
1787 if (input != null) {
1788 return this.parse(input, exceptionOnInvalidType, objectDecoder);
1789 }
1790 return null;
1791 }
1792 };
1793
1794 Yaml.dump = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) {
1795 var yaml;
1796 if (inline == null) {
1797 inline = 2;
1798 }
1799 if (indent == null) {
1800 indent = 4;
1801 }
1802 if (exceptionOnInvalidType == null) {
1803 exceptionOnInvalidType = false;
1804 }
1805 if (objectEncoder == null) {
1806 objectEncoder = null;
1807 }
1808 yaml = new Dumper();
1809 yaml.indentation = indent;
1810 return yaml.dump(input, inline, 0, exceptionOnInvalidType, objectEncoder);
1811 };
1812
1813 Yaml.register = function() {
1814 var require_handler;
1815 require_handler = function(module, filename) {
1816 return module.exports = YAML.parseFile(filename);
1817 };
1818 if ((typeof require !== "undefined" && require !== null ? require.extensions : void 0) != null) {
1819 require.extensions['.yml'] = require_handler;
1820 return require.extensions['.yaml'] = require_handler;
1821 }
1822 };
1823
1824 Yaml.stringify = function(input, inline, indent, exceptionOnInvalidType, objectEncoder) {
1825 return this.dump(input, inline, indent, exceptionOnInvalidType, objectEncoder);
1826 };
1827
1828 Yaml.load = function(path, callback, exceptionOnInvalidType, objectDecoder) {
1829 return this.parseFile(path, callback, exceptionOnInvalidType, objectDecoder);
1830 };
1831
1832 return Yaml;
1833
1834})();
1835
1836if (typeof window !== "undefined" && window !== null) {
1837 window.YAML = Yaml;
1838}
1839
1840module.exports = Yaml;
1841
1842
1843
1844},{"./Dumper":1,"./Parser":6,"./Utils":9}]},{},[10]);