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