1 | 'use strict';
|
2 |
|
3 | Object.defineProperty(exports, '__esModule', { value: true });
|
4 |
|
5 | var path$4 = require('path');
|
6 | var stream = require('stream');
|
7 | var SVGIcons2SVGFontStream = require('svgicons2svgfont');
|
8 | var require$$0$2 = require('os');
|
9 | var require$$0 = require('parse-json');
|
10 | var require$$1 = require('resolve-from');
|
11 | var require$$0$1 = require('fs');
|
12 | var crypto = require('crypto');
|
13 | var deepmerge = require('deepmerge');
|
14 | var globby = require('globby');
|
15 | var nunjucks = require('nunjucks');
|
16 | var pLimit = require('p-limit');
|
17 | var svg2ttf = require('svg2ttf');
|
18 | var ttf2eot = require('ttf2eot');
|
19 | var ttf2woff = require('ttf2woff');
|
20 | var wawoff2 = require('wawoff2');
|
21 | var xml2js = require('xml2js');
|
22 |
|
23 | function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
24 |
|
25 | var path__default = _interopDefaultLegacy(path$4);
|
26 | var SVGIcons2SVGFontStream__default = _interopDefaultLegacy(SVGIcons2SVGFontStream);
|
27 | var require$$0__default$2 = _interopDefaultLegacy(require$$0$2);
|
28 | var require$$0__default = _interopDefaultLegacy(require$$0);
|
29 | var require$$1__default = _interopDefaultLegacy(require$$1);
|
30 | var require$$0__default$1 = _interopDefaultLegacy(require$$0$1);
|
31 | var crypto__default = _interopDefaultLegacy(crypto);
|
32 | var deepmerge__default = _interopDefaultLegacy(deepmerge);
|
33 | var globby__default = _interopDefaultLegacy(globby);
|
34 | var nunjucks__default = _interopDefaultLegacy(nunjucks);
|
35 | var pLimit__default = _interopDefaultLegacy(pLimit);
|
36 | var svg2ttf__default = _interopDefaultLegacy(svg2ttf);
|
37 | var ttf2eot__default = _interopDefaultLegacy(ttf2eot);
|
38 | var ttf2woff__default = _interopDefaultLegacy(ttf2woff);
|
39 | var wawoff2__default = _interopDefaultLegacy(wawoff2);
|
40 | var xml2js__default = _interopDefaultLegacy(xml2js);
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 | var __assign = function() {
|
58 | __assign = Object.assign || function __assign(t) {
|
59 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
60 | s = arguments[i];
|
61 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
62 | }
|
63 | return t;
|
64 | };
|
65 | return __assign.apply(this, arguments);
|
66 | };
|
67 |
|
68 | function __awaiter(thisArg, _arguments, P, generator) {
|
69 | function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
70 | return new (P || (P = Promise))(function (resolve, reject) {
|
71 | function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
72 | function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
73 | function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
74 | step((generator = generator.apply(thisArg, _arguments || [])).next());
|
75 | });
|
76 | }
|
77 |
|
78 | function __generator(thisArg, body) {
|
79 | var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
|
80 | return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
81 | function verb(n) { return function (v) { return step([n, v]); }; }
|
82 | function step(op) {
|
83 | if (f) throw new TypeError("Generator is already executing.");
|
84 | while (_) try {
|
85 | if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
86 | if (y = 0, t) op = [op[0] & 2, t.value];
|
87 | switch (op[0]) {
|
88 | case 0: case 1: t = op; break;
|
89 | case 4: _.label++; return { value: op[1], done: false };
|
90 | case 5: _.label++; y = op[1]; op = [0]; continue;
|
91 | case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
92 | default:
|
93 | if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
94 | if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
95 | if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
96 | if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
97 | if (t[2]) _.ops.pop();
|
98 | _.trys.pop(); continue;
|
99 | }
|
100 | op = body.call(thisArg, _);
|
101 | } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
102 | if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
103 | }
|
104 | }
|
105 |
|
106 | var getTemplateDirectory = function () { return path__default['default'].resolve(__dirname, "../templates"); };
|
107 | var getTemplateFilePath = function (template) {
|
108 | var templateDirectory = getTemplateDirectory();
|
109 | return templateDirectory + "/template." + template + ".njk";
|
110 | };
|
111 | var getBuiltInTemplates = function () {
|
112 | var templateDirectory = getTemplateDirectory();
|
113 | return {
|
114 | css: { path: path__default['default'].join(templateDirectory, "template.css.njk") },
|
115 | html: { path: path__default['default'].join(templateDirectory, "template.html.njk") },
|
116 | json: { path: path__default['default'].join(templateDirectory, "template.json.njk") },
|
117 | scss: { path: path__default['default'].join(templateDirectory, "template.scss.njk") },
|
118 | styl: { path: path__default['default'].join(templateDirectory, "template.styl.njk") }
|
119 | };
|
120 | };
|
121 |
|
122 | function commonjsRequire (path) {
|
123 | throw new Error('Could not dynamically require "' + path + '". Please configure the dynamicRequireTargets or/and ignoreDynamicRequires option of @rollup/plugin-commonjs appropriately for this require call to work.');
|
124 | }
|
125 |
|
126 | var jsYaml$1 = {};
|
127 |
|
128 | var loader$1 = {};
|
129 |
|
130 | var common$6 = {};
|
131 |
|
132 | function isNothing(subject) {
|
133 | return (typeof subject === 'undefined') || (subject === null);
|
134 | }
|
135 |
|
136 |
|
137 | function isObject(subject) {
|
138 | return (typeof subject === 'object') && (subject !== null);
|
139 | }
|
140 |
|
141 |
|
142 | function toArray(sequence) {
|
143 | if (Array.isArray(sequence)) return sequence;
|
144 | else if (isNothing(sequence)) return [];
|
145 |
|
146 | return [ sequence ];
|
147 | }
|
148 |
|
149 |
|
150 | function extend(target, source) {
|
151 | var index, length, key, sourceKeys;
|
152 |
|
153 | if (source) {
|
154 | sourceKeys = Object.keys(source);
|
155 |
|
156 | for (index = 0, length = sourceKeys.length; index < length; index += 1) {
|
157 | key = sourceKeys[index];
|
158 | target[key] = source[key];
|
159 | }
|
160 | }
|
161 |
|
162 | return target;
|
163 | }
|
164 |
|
165 |
|
166 | function repeat(string, count) {
|
167 | var result = '', cycle;
|
168 |
|
169 | for (cycle = 0; cycle < count; cycle += 1) {
|
170 | result += string;
|
171 | }
|
172 |
|
173 | return result;
|
174 | }
|
175 |
|
176 |
|
177 | function isNegativeZero(number) {
|
178 | return (number === 0) && (Number.NEGATIVE_INFINITY === 1 / number);
|
179 | }
|
180 |
|
181 |
|
182 | common$6.isNothing = isNothing;
|
183 | common$6.isObject = isObject;
|
184 | common$6.toArray = toArray;
|
185 | common$6.repeat = repeat;
|
186 | common$6.isNegativeZero = isNegativeZero;
|
187 | common$6.extend = extend;
|
188 |
|
189 | function YAMLException$4(reason, mark) {
|
190 |
|
191 | Error.call(this);
|
192 |
|
193 | this.name = 'YAMLException';
|
194 | this.reason = reason;
|
195 | this.mark = mark;
|
196 | this.message = (this.reason || '(unknown reason)') + (this.mark ? ' ' + this.mark.toString() : '');
|
197 |
|
198 |
|
199 | if (Error.captureStackTrace) {
|
200 |
|
201 | Error.captureStackTrace(this, this.constructor);
|
202 | } else {
|
203 |
|
204 | this.stack = (new Error()).stack || '';
|
205 | }
|
206 | }
|
207 |
|
208 |
|
209 |
|
210 | YAMLException$4.prototype = Object.create(Error.prototype);
|
211 | YAMLException$4.prototype.constructor = YAMLException$4;
|
212 |
|
213 |
|
214 | YAMLException$4.prototype.toString = function toString(compact) {
|
215 | var result = this.name + ': ';
|
216 |
|
217 | result += this.reason || '(unknown reason)';
|
218 |
|
219 | if (!compact && this.mark) {
|
220 | result += ' ' + this.mark.toString();
|
221 | }
|
222 |
|
223 | return result;
|
224 | };
|
225 |
|
226 |
|
227 | var exception = YAMLException$4;
|
228 |
|
229 | var common$5 = common$6;
|
230 |
|
231 |
|
232 | function Mark$1(name, buffer, position, line, column) {
|
233 | this.name = name;
|
234 | this.buffer = buffer;
|
235 | this.position = position;
|
236 | this.line = line;
|
237 | this.column = column;
|
238 | }
|
239 |
|
240 |
|
241 | Mark$1.prototype.getSnippet = function getSnippet(indent, maxLength) {
|
242 | var head, start, tail, end, snippet;
|
243 |
|
244 | if (!this.buffer) return null;
|
245 |
|
246 | indent = indent || 4;
|
247 | maxLength = maxLength || 75;
|
248 |
|
249 | head = '';
|
250 | start = this.position;
|
251 |
|
252 | while (start > 0 && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(start - 1)) === -1) {
|
253 | start -= 1;
|
254 | if (this.position - start > (maxLength / 2 - 1)) {
|
255 | head = ' ... ';
|
256 | start += 5;
|
257 | break;
|
258 | }
|
259 | }
|
260 |
|
261 | tail = '';
|
262 | end = this.position;
|
263 |
|
264 | while (end < this.buffer.length && '\x00\r\n\x85\u2028\u2029'.indexOf(this.buffer.charAt(end)) === -1) {
|
265 | end += 1;
|
266 | if (end - this.position > (maxLength / 2 - 1)) {
|
267 | tail = ' ... ';
|
268 | end -= 5;
|
269 | break;
|
270 | }
|
271 | }
|
272 |
|
273 | snippet = this.buffer.slice(start, end);
|
274 |
|
275 | return common$5.repeat(' ', indent) + head + snippet + tail + '\n' +
|
276 | common$5.repeat(' ', indent + this.position - start + head.length) + '^';
|
277 | };
|
278 |
|
279 |
|
280 | Mark$1.prototype.toString = function toString(compact) {
|
281 | var snippet, where = '';
|
282 |
|
283 | if (this.name) {
|
284 | where += 'in "' + this.name + '" ';
|
285 | }
|
286 |
|
287 | where += 'at line ' + (this.line + 1) + ', column ' + (this.column + 1);
|
288 |
|
289 | if (!compact) {
|
290 | snippet = this.getSnippet();
|
291 |
|
292 | if (snippet) {
|
293 | where += ':\n' + snippet;
|
294 | }
|
295 | }
|
296 |
|
297 | return where;
|
298 | };
|
299 |
|
300 |
|
301 | var mark = Mark$1;
|
302 |
|
303 | var YAMLException$3 = exception;
|
304 |
|
305 | var TYPE_CONSTRUCTOR_OPTIONS = [
|
306 | 'kind',
|
307 | 'resolve',
|
308 | 'construct',
|
309 | 'instanceOf',
|
310 | 'predicate',
|
311 | 'represent',
|
312 | 'defaultStyle',
|
313 | 'styleAliases'
|
314 | ];
|
315 |
|
316 | var YAML_NODE_KINDS = [
|
317 | 'scalar',
|
318 | 'sequence',
|
319 | 'mapping'
|
320 | ];
|
321 |
|
322 | function compileStyleAliases(map) {
|
323 | var result = {};
|
324 |
|
325 | if (map !== null) {
|
326 | Object.keys(map).forEach(function (style) {
|
327 | map[style].forEach(function (alias) {
|
328 | result[String(alias)] = style;
|
329 | });
|
330 | });
|
331 | }
|
332 |
|
333 | return result;
|
334 | }
|
335 |
|
336 | function Type$h(tag, options) {
|
337 | options = options || {};
|
338 |
|
339 | Object.keys(options).forEach(function (name) {
|
340 | if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
|
341 | throw new YAMLException$3('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
|
342 | }
|
343 | });
|
344 |
|
345 |
|
346 | this.tag = tag;
|
347 | this.kind = options['kind'] || null;
|
348 | this.resolve = options['resolve'] || function () { return true; };
|
349 | this.construct = options['construct'] || function (data) { return data; };
|
350 | this.instanceOf = options['instanceOf'] || null;
|
351 | this.predicate = options['predicate'] || null;
|
352 | this.represent = options['represent'] || null;
|
353 | this.defaultStyle = options['defaultStyle'] || null;
|
354 | this.styleAliases = compileStyleAliases(options['styleAliases'] || null);
|
355 |
|
356 | if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
357 | throw new YAMLException$3('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
358 | }
|
359 | }
|
360 |
|
361 | var type = Type$h;
|
362 |
|
363 |
|
364 |
|
365 | var common$4 = common$6;
|
366 | var YAMLException$2 = exception;
|
367 | var Type$g = type;
|
368 |
|
369 |
|
370 | function compileList(schema, name, result) {
|
371 | var exclude = [];
|
372 |
|
373 | schema.include.forEach(function (includedSchema) {
|
374 | result = compileList(includedSchema, name, result);
|
375 | });
|
376 |
|
377 | schema[name].forEach(function (currentType) {
|
378 | result.forEach(function (previousType, previousIndex) {
|
379 | if (previousType.tag === currentType.tag && previousType.kind === currentType.kind) {
|
380 | exclude.push(previousIndex);
|
381 | }
|
382 | });
|
383 |
|
384 | result.push(currentType);
|
385 | });
|
386 |
|
387 | return result.filter(function (type, index) {
|
388 | return exclude.indexOf(index) === -1;
|
389 | });
|
390 | }
|
391 |
|
392 |
|
393 | function compileMap(/* lists... */) {
|
394 | var result = {
|
395 | scalar: {},
|
396 | sequence: {},
|
397 | mapping: {},
|
398 | fallback: {}
|
399 | }, index, length;
|
400 |
|
401 | function collectType(type) {
|
402 | result[type.kind][type.tag] = result['fallback'][type.tag] = type;
|
403 | }
|
404 |
|
405 | for (index = 0, length = arguments.length; index < length; index += 1) {
|
406 | arguments[index].forEach(collectType);
|
407 | }
|
408 | return result;
|
409 | }
|
410 |
|
411 |
|
412 | function Schema$5(definition) {
|
413 | this.include = definition.include || [];
|
414 | this.implicit = definition.implicit || [];
|
415 | this.explicit = definition.explicit || [];
|
416 |
|
417 | this.implicit.forEach(function (type) {
|
418 | if (type.loadKind && type.loadKind !== 'scalar') {
|
419 | throw new YAMLException$2('There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.');
|
420 | }
|
421 | });
|
422 |
|
423 | this.compiledImplicit = compileList(this, 'implicit', []);
|
424 | this.compiledExplicit = compileList(this, 'explicit', []);
|
425 | this.compiledTypeMap = compileMap(this.compiledImplicit, this.compiledExplicit);
|
426 | }
|
427 |
|
428 |
|
429 | Schema$5.DEFAULT = null;
|
430 |
|
431 |
|
432 | Schema$5.create = function createSchema() {
|
433 | var schemas, types;
|
434 |
|
435 | switch (arguments.length) {
|
436 | case 1:
|
437 | schemas = Schema$5.DEFAULT;
|
438 | types = arguments[0];
|
439 | break;
|
440 |
|
441 | case 2:
|
442 | schemas = arguments[0];
|
443 | types = arguments[1];
|
444 | break;
|
445 |
|
446 | default:
|
447 | throw new YAMLException$2('Wrong number of arguments for Schema.create function');
|
448 | }
|
449 |
|
450 | schemas = common$4.toArray(schemas);
|
451 | types = common$4.toArray(types);
|
452 |
|
453 | if (!schemas.every(function (schema) { return schema instanceof Schema$5; })) {
|
454 | throw new YAMLException$2('Specified list of super schemas (or a single Schema object) contains a non-Schema object.');
|
455 | }
|
456 |
|
457 | if (!types.every(function (type) { return type instanceof Type$g; })) {
|
458 | throw new YAMLException$2('Specified list of YAML types (or a single Type object) contains a non-Type object.');
|
459 | }
|
460 |
|
461 | return new Schema$5({
|
462 | include: schemas,
|
463 | explicit: types
|
464 | });
|
465 | };
|
466 |
|
467 |
|
468 | var schema = Schema$5;
|
469 |
|
470 | var Type$f = type;
|
471 |
|
472 | var str = new Type$f('tag:yaml.org,2002:str', {
|
473 | kind: 'scalar',
|
474 | construct: function (data) { return data !== null ? data : ''; }
|
475 | });
|
476 |
|
477 | var Type$e = type;
|
478 |
|
479 | var seq = new Type$e('tag:yaml.org,2002:seq', {
|
480 | kind: 'sequence',
|
481 | construct: function (data) { return data !== null ? data : []; }
|
482 | });
|
483 |
|
484 | var Type$d = type;
|
485 |
|
486 | var map = new Type$d('tag:yaml.org,2002:map', {
|
487 | kind: 'mapping',
|
488 | construct: function (data) { return data !== null ? data : {}; }
|
489 | });
|
490 |
|
491 | var Schema$4 = schema;
|
492 |
|
493 |
|
494 | var failsafe = new Schema$4({
|
495 | explicit: [
|
496 | str,
|
497 | seq,
|
498 | map
|
499 | ]
|
500 | });
|
501 |
|
502 | var Type$c = type;
|
503 |
|
504 | function resolveYamlNull(data) {
|
505 | if (data === null) return true;
|
506 |
|
507 | var max = data.length;
|
508 |
|
509 | return (max === 1 && data === '~') ||
|
510 | (max === 4 && (data === 'null' || data === 'Null' || data === 'NULL'));
|
511 | }
|
512 |
|
513 | function constructYamlNull() {
|
514 | return null;
|
515 | }
|
516 |
|
517 | function isNull(object) {
|
518 | return object === null;
|
519 | }
|
520 |
|
521 | var _null = new Type$c('tag:yaml.org,2002:null', {
|
522 | kind: 'scalar',
|
523 | resolve: resolveYamlNull,
|
524 | construct: constructYamlNull,
|
525 | predicate: isNull,
|
526 | represent: {
|
527 | canonical: function () { return '~'; },
|
528 | lowercase: function () { return 'null'; },
|
529 | uppercase: function () { return 'NULL'; },
|
530 | camelcase: function () { return 'Null'; }
|
531 | },
|
532 | defaultStyle: 'lowercase'
|
533 | });
|
534 |
|
535 | var Type$b = type;
|
536 |
|
537 | function resolveYamlBoolean(data) {
|
538 | if (data === null) return false;
|
539 |
|
540 | var max = data.length;
|
541 |
|
542 | return (max === 4 && (data === 'true' || data === 'True' || data === 'TRUE')) ||
|
543 | (max === 5 && (data === 'false' || data === 'False' || data === 'FALSE'));
|
544 | }
|
545 |
|
546 | function constructYamlBoolean(data) {
|
547 | return data === 'true' ||
|
548 | data === 'True' ||
|
549 | data === 'TRUE';
|
550 | }
|
551 |
|
552 | function isBoolean(object) {
|
553 | return Object.prototype.toString.call(object) === '[object Boolean]';
|
554 | }
|
555 |
|
556 | var bool = new Type$b('tag:yaml.org,2002:bool', {
|
557 | kind: 'scalar',
|
558 | resolve: resolveYamlBoolean,
|
559 | construct: constructYamlBoolean,
|
560 | predicate: isBoolean,
|
561 | represent: {
|
562 | lowercase: function (object) { return object ? 'true' : 'false'; },
|
563 | uppercase: function (object) { return object ? 'TRUE' : 'FALSE'; },
|
564 | camelcase: function (object) { return object ? 'True' : 'False'; }
|
565 | },
|
566 | defaultStyle: 'lowercase'
|
567 | });
|
568 |
|
569 | var common$3 = common$6;
|
570 | var Type$a = type;
|
571 |
|
572 | function isHexCode(c) {
|
573 | return ((0x30 <= c) && (c <= 0x39)) ||
|
574 | ((0x41 <= c) && (c <= 0x46)) ||
|
575 | ((0x61 <= c) && (c <= 0x66));
|
576 | }
|
577 |
|
578 | function isOctCode(c) {
|
579 | return ((0x30 <= c) && (c <= 0x37));
|
580 | }
|
581 |
|
582 | function isDecCode(c) {
|
583 | return ((0x30 <= c) && (c <= 0x39));
|
584 | }
|
585 |
|
586 | function resolveYamlInteger(data) {
|
587 | if (data === null) return false;
|
588 |
|
589 | var max = data.length,
|
590 | index = 0,
|
591 | hasDigits = false,
|
592 | ch;
|
593 |
|
594 | if (!max) return false;
|
595 |
|
596 | ch = data[index];
|
597 |
|
598 |
|
599 | if (ch === '-' || ch === '+') {
|
600 | ch = data[++index];
|
601 | }
|
602 |
|
603 | if (ch === '0') {
|
604 |
|
605 | if (index + 1 === max) return true;
|
606 | ch = data[++index];
|
607 |
|
608 |
|
609 |
|
610 | if (ch === 'b') {
|
611 |
|
612 | index++;
|
613 |
|
614 | for (; index < max; index++) {
|
615 | ch = data[index];
|
616 | if (ch === '_') continue;
|
617 | if (ch !== '0' && ch !== '1') return false;
|
618 | hasDigits = true;
|
619 | }
|
620 | return hasDigits && ch !== '_';
|
621 | }
|
622 |
|
623 |
|
624 | if (ch === 'x') {
|
625 |
|
626 | index++;
|
627 |
|
628 | for (; index < max; index++) {
|
629 | ch = data[index];
|
630 | if (ch === '_') continue;
|
631 | if (!isHexCode(data.charCodeAt(index))) return false;
|
632 | hasDigits = true;
|
633 | }
|
634 | return hasDigits && ch !== '_';
|
635 | }
|
636 |
|
637 |
|
638 | for (; index < max; index++) {
|
639 | ch = data[index];
|
640 | if (ch === '_') continue;
|
641 | if (!isOctCode(data.charCodeAt(index))) return false;
|
642 | hasDigits = true;
|
643 | }
|
644 | return hasDigits && ch !== '_';
|
645 | }
|
646 |
|
647 |
|
648 |
|
649 |
|
650 | if (ch === '_') return false;
|
651 |
|
652 | for (; index < max; index++) {
|
653 | ch = data[index];
|
654 | if (ch === '_') continue;
|
655 | if (ch === ':') break;
|
656 | if (!isDecCode(data.charCodeAt(index))) {
|
657 | return false;
|
658 | }
|
659 | hasDigits = true;
|
660 | }
|
661 |
|
662 |
|
663 | if (!hasDigits || ch === '_') return false;
|
664 |
|
665 |
|
666 | if (ch !== ':') return true;
|
667 |
|
668 |
|
669 | return /^(:[0-5]?[0-9])+$/.test(data.slice(index));
|
670 | }
|
671 |
|
672 | function constructYamlInteger(data) {
|
673 | var value = data, sign = 1, ch, base, digits = [];
|
674 |
|
675 | if (value.indexOf('_') !== -1) {
|
676 | value = value.replace(/_/g, '');
|
677 | }
|
678 |
|
679 | ch = value[0];
|
680 |
|
681 | if (ch === '-' || ch === '+') {
|
682 | if (ch === '-') sign = -1;
|
683 | value = value.slice(1);
|
684 | ch = value[0];
|
685 | }
|
686 |
|
687 | if (value === '0') return 0;
|
688 |
|
689 | if (ch === '0') {
|
690 | if (value[1] === 'b') return sign * parseInt(value.slice(2), 2);
|
691 | if (value[1] === 'x') return sign * parseInt(value, 16);
|
692 | return sign * parseInt(value, 8);
|
693 | }
|
694 |
|
695 | if (value.indexOf(':') !== -1) {
|
696 | value.split(':').forEach(function (v) {
|
697 | digits.unshift(parseInt(v, 10));
|
698 | });
|
699 |
|
700 | value = 0;
|
701 | base = 1;
|
702 |
|
703 | digits.forEach(function (d) {
|
704 | value += (d * base);
|
705 | base *= 60;
|
706 | });
|
707 |
|
708 | return sign * value;
|
709 |
|
710 | }
|
711 |
|
712 | return sign * parseInt(value, 10);
|
713 | }
|
714 |
|
715 | function isInteger(object) {
|
716 | return (Object.prototype.toString.call(object)) === '[object Number]' &&
|
717 | (object % 1 === 0 && !common$3.isNegativeZero(object));
|
718 | }
|
719 |
|
720 | var int = new Type$a('tag:yaml.org,2002:int', {
|
721 | kind: 'scalar',
|
722 | resolve: resolveYamlInteger,
|
723 | construct: constructYamlInteger,
|
724 | predicate: isInteger,
|
725 | represent: {
|
726 | binary: function (obj) { return obj >= 0 ? '0b' + obj.toString(2) : '-0b' + obj.toString(2).slice(1); },
|
727 | octal: function (obj) { return obj >= 0 ? '0' + obj.toString(8) : '-0' + obj.toString(8).slice(1); },
|
728 | decimal: function (obj) { return obj.toString(10); },
|
729 |
|
730 | hexadecimal: function (obj) { return obj >= 0 ? '0x' + obj.toString(16).toUpperCase() : '-0x' + obj.toString(16).toUpperCase().slice(1); }
|
731 | },
|
732 | defaultStyle: 'decimal',
|
733 | styleAliases: {
|
734 | binary: [ 2, 'bin' ],
|
735 | octal: [ 8, 'oct' ],
|
736 | decimal: [ 10, 'dec' ],
|
737 | hexadecimal: [ 16, 'hex' ]
|
738 | }
|
739 | });
|
740 |
|
741 | var common$2 = common$6;
|
742 | var Type$9 = type;
|
743 |
|
744 | var YAML_FLOAT_PATTERN = new RegExp(
|
745 |
|
746 | '^(?:[-+]?(?:0|[1-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?' +
|
747 |
|
748 |
|
749 | '|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?' +
|
750 |
|
751 | '|[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\\.[0-9_]*' +
|
752 |
|
753 | '|[-+]?\\.(?:inf|Inf|INF)' +
|
754 |
|
755 | '|\\.(?:nan|NaN|NAN))$');
|
756 |
|
757 | function resolveYamlFloat(data) {
|
758 | if (data === null) return false;
|
759 |
|
760 | if (!YAML_FLOAT_PATTERN.test(data) ||
|
761 |
|
762 |
|
763 | data[data.length - 1] === '_') {
|
764 | return false;
|
765 | }
|
766 |
|
767 | return true;
|
768 | }
|
769 |
|
770 | function constructYamlFloat(data) {
|
771 | var value, sign, base, digits;
|
772 |
|
773 | value = data.replace(/_/g, '').toLowerCase();
|
774 | sign = value[0] === '-' ? -1 : 1;
|
775 | digits = [];
|
776 |
|
777 | if ('+-'.indexOf(value[0]) >= 0) {
|
778 | value = value.slice(1);
|
779 | }
|
780 |
|
781 | if (value === '.inf') {
|
782 | return (sign === 1) ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
783 |
|
784 | } else if (value === '.nan') {
|
785 | return NaN;
|
786 |
|
787 | } else if (value.indexOf(':') >= 0) {
|
788 | value.split(':').forEach(function (v) {
|
789 | digits.unshift(parseFloat(v, 10));
|
790 | });
|
791 |
|
792 | value = 0.0;
|
793 | base = 1;
|
794 |
|
795 | digits.forEach(function (d) {
|
796 | value += d * base;
|
797 | base *= 60;
|
798 | });
|
799 |
|
800 | return sign * value;
|
801 |
|
802 | }
|
803 | return sign * parseFloat(value, 10);
|
804 | }
|
805 |
|
806 |
|
807 | var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
|
808 |
|
809 | function representYamlFloat(object, style) {
|
810 | var res;
|
811 |
|
812 | if (isNaN(object)) {
|
813 | switch (style) {
|
814 | case 'lowercase': return '.nan';
|
815 | case 'uppercase': return '.NAN';
|
816 | case 'camelcase': return '.NaN';
|
817 | }
|
818 | } else if (Number.POSITIVE_INFINITY === object) {
|
819 | switch (style) {
|
820 | case 'lowercase': return '.inf';
|
821 | case 'uppercase': return '.INF';
|
822 | case 'camelcase': return '.Inf';
|
823 | }
|
824 | } else if (Number.NEGATIVE_INFINITY === object) {
|
825 | switch (style) {
|
826 | case 'lowercase': return '-.inf';
|
827 | case 'uppercase': return '-.INF';
|
828 | case 'camelcase': return '-.Inf';
|
829 | }
|
830 | } else if (common$2.isNegativeZero(object)) {
|
831 | return '-0.0';
|
832 | }
|
833 |
|
834 | res = object.toString(10);
|
835 |
|
836 |
|
837 |
|
838 |
|
839 | return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace('e', '.e') : res;
|
840 | }
|
841 |
|
842 | function isFloat(object) {
|
843 | return (Object.prototype.toString.call(object) === '[object Number]') &&
|
844 | (object % 1 !== 0 || common$2.isNegativeZero(object));
|
845 | }
|
846 |
|
847 | var float = new Type$9('tag:yaml.org,2002:float', {
|
848 | kind: 'scalar',
|
849 | resolve: resolveYamlFloat,
|
850 | construct: constructYamlFloat,
|
851 | predicate: isFloat,
|
852 | represent: representYamlFloat,
|
853 | defaultStyle: 'lowercase'
|
854 | });
|
855 |
|
856 | var Schema$3 = schema;
|
857 |
|
858 |
|
859 | var json = new Schema$3({
|
860 | include: [
|
861 | failsafe
|
862 | ],
|
863 | implicit: [
|
864 | _null,
|
865 | bool,
|
866 | int,
|
867 | float
|
868 | ]
|
869 | });
|
870 |
|
871 | var Schema$2 = schema;
|
872 |
|
873 |
|
874 | var core = new Schema$2({
|
875 | include: [
|
876 | json
|
877 | ]
|
878 | });
|
879 |
|
880 | var Type$8 = type;
|
881 |
|
882 | var YAML_DATE_REGEXP = new RegExp(
|
883 | '^([0-9][0-9][0-9][0-9])' +
|
884 | '-([0-9][0-9])' +
|
885 | '-([0-9][0-9])$');
|
886 |
|
887 | var YAML_TIMESTAMP_REGEXP = new RegExp(
|
888 | '^([0-9][0-9][0-9][0-9])' +
|
889 | '-([0-9][0-9]?)' +
|
890 | '-([0-9][0-9]?)' +
|
891 | '(?:[Tt]|[ \\t]+)' +
|
892 | '([0-9][0-9]?)' +
|
893 | ':([0-9][0-9])' +
|
894 | ':([0-9][0-9])' +
|
895 | '(?:\\.([0-9]*))?' +
|
896 | '(?:[ \\t]*(Z|([-+])([0-9][0-9]?)' +
|
897 | '(?::([0-9][0-9]))?))?$');
|
898 |
|
899 | function resolveYamlTimestamp(data) {
|
900 | if (data === null) return false;
|
901 | if (YAML_DATE_REGEXP.exec(data) !== null) return true;
|
902 | if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
|
903 | return false;
|
904 | }
|
905 |
|
906 | function constructYamlTimestamp(data) {
|
907 | var match, year, month, day, hour, minute, second, fraction = 0,
|
908 | delta = null, tz_hour, tz_minute, date;
|
909 |
|
910 | match = YAML_DATE_REGEXP.exec(data);
|
911 | if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
|
912 |
|
913 | if (match === null) throw new Error('Date resolve error');
|
914 |
|
915 |
|
916 |
|
917 | year = +(match[1]);
|
918 | month = +(match[2]) - 1;
|
919 | day = +(match[3]);
|
920 |
|
921 | if (!match[4]) {
|
922 | return new Date(Date.UTC(year, month, day));
|
923 | }
|
924 |
|
925 |
|
926 |
|
927 | hour = +(match[4]);
|
928 | minute = +(match[5]);
|
929 | second = +(match[6]);
|
930 |
|
931 | if (match[7]) {
|
932 | fraction = match[7].slice(0, 3);
|
933 | while (fraction.length < 3) {
|
934 | fraction += '0';
|
935 | }
|
936 | fraction = +fraction;
|
937 | }
|
938 |
|
939 |
|
940 |
|
941 | if (match[9]) {
|
942 | tz_hour = +(match[10]);
|
943 | tz_minute = +(match[11] || 0);
|
944 | delta = (tz_hour * 60 + tz_minute) * 60000;
|
945 | if (match[9] === '-') delta = -delta;
|
946 | }
|
947 |
|
948 | date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
949 |
|
950 | if (delta) date.setTime(date.getTime() - delta);
|
951 |
|
952 | return date;
|
953 | }
|
954 |
|
955 | function representYamlTimestamp(object /*, style*/) {
|
956 | return object.toISOString();
|
957 | }
|
958 |
|
959 | var timestamp = new Type$8('tag:yaml.org,2002:timestamp', {
|
960 | kind: 'scalar',
|
961 | resolve: resolveYamlTimestamp,
|
962 | construct: constructYamlTimestamp,
|
963 | instanceOf: Date,
|
964 | represent: representYamlTimestamp
|
965 | });
|
966 |
|
967 | var Type$7 = type;
|
968 |
|
969 | function resolveYamlMerge(data) {
|
970 | return data === '<<' || data === null;
|
971 | }
|
972 |
|
973 | var merge = new Type$7('tag:yaml.org,2002:merge', {
|
974 | kind: 'scalar',
|
975 | resolve: resolveYamlMerge
|
976 | });
|
977 |
|
978 |
|
979 |
|
980 | var NodeBuffer;
|
981 |
|
982 | try {
|
983 |
|
984 | var _require$1 = commonjsRequire;
|
985 | NodeBuffer = _require$1('buffer').Buffer;
|
986 | } catch (__) {}
|
987 |
|
988 | var Type$6 = type;
|
989 |
|
990 |
|
991 |
|
992 | var BASE64_MAP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r';
|
993 |
|
994 |
|
995 | function resolveYamlBinary(data) {
|
996 | if (data === null) return false;
|
997 |
|
998 | var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
|
999 |
|
1000 |
|
1001 | for (idx = 0; idx < max; idx++) {
|
1002 | code = map.indexOf(data.charAt(idx));
|
1003 |
|
1004 |
|
1005 | if (code > 64) continue;
|
1006 |
|
1007 |
|
1008 | if (code < 0) return false;
|
1009 |
|
1010 | bitlen += 6;
|
1011 | }
|
1012 |
|
1013 |
|
1014 | return (bitlen % 8) === 0;
|
1015 | }
|
1016 |
|
1017 | function constructYamlBinary(data) {
|
1018 | var idx, tailbits,
|
1019 | input = data.replace(/[\r\n=]/g, ''),
|
1020 | max = input.length,
|
1021 | map = BASE64_MAP,
|
1022 | bits = 0,
|
1023 | result = [];
|
1024 |
|
1025 |
|
1026 |
|
1027 | for (idx = 0; idx < max; idx++) {
|
1028 | if ((idx % 4 === 0) && idx) {
|
1029 | result.push((bits >> 16) & 0xFF);
|
1030 | result.push((bits >> 8) & 0xFF);
|
1031 | result.push(bits & 0xFF);
|
1032 | }
|
1033 |
|
1034 | bits = (bits << 6) | map.indexOf(input.charAt(idx));
|
1035 | }
|
1036 |
|
1037 |
|
1038 |
|
1039 | tailbits = (max % 4) * 6;
|
1040 |
|
1041 | if (tailbits === 0) {
|
1042 | result.push((bits >> 16) & 0xFF);
|
1043 | result.push((bits >> 8) & 0xFF);
|
1044 | result.push(bits & 0xFF);
|
1045 | } else if (tailbits === 18) {
|
1046 | result.push((bits >> 10) & 0xFF);
|
1047 | result.push((bits >> 2) & 0xFF);
|
1048 | } else if (tailbits === 12) {
|
1049 | result.push((bits >> 4) & 0xFF);
|
1050 | }
|
1051 |
|
1052 |
|
1053 | if (NodeBuffer) {
|
1054 |
|
1055 | return NodeBuffer.from ? NodeBuffer.from(result) : new NodeBuffer(result);
|
1056 | }
|
1057 |
|
1058 | return result;
|
1059 | }
|
1060 |
|
1061 | function representYamlBinary(object /*, style*/) {
|
1062 | var result = '', bits = 0, idx, tail,
|
1063 | max = object.length,
|
1064 | map = BASE64_MAP;
|
1065 |
|
1066 |
|
1067 |
|
1068 | for (idx = 0; idx < max; idx++) {
|
1069 | if ((idx % 3 === 0) && idx) {
|
1070 | result += map[(bits >> 18) & 0x3F];
|
1071 | result += map[(bits >> 12) & 0x3F];
|
1072 | result += map[(bits >> 6) & 0x3F];
|
1073 | result += map[bits & 0x3F];
|
1074 | }
|
1075 |
|
1076 | bits = (bits << 8) + object[idx];
|
1077 | }
|
1078 |
|
1079 |
|
1080 |
|
1081 | tail = max % 3;
|
1082 |
|
1083 | if (tail === 0) {
|
1084 | result += map[(bits >> 18) & 0x3F];
|
1085 | result += map[(bits >> 12) & 0x3F];
|
1086 | result += map[(bits >> 6) & 0x3F];
|
1087 | result += map[bits & 0x3F];
|
1088 | } else if (tail === 2) {
|
1089 | result += map[(bits >> 10) & 0x3F];
|
1090 | result += map[(bits >> 4) & 0x3F];
|
1091 | result += map[(bits << 2) & 0x3F];
|
1092 | result += map[64];
|
1093 | } else if (tail === 1) {
|
1094 | result += map[(bits >> 2) & 0x3F];
|
1095 | result += map[(bits << 4) & 0x3F];
|
1096 | result += map[64];
|
1097 | result += map[64];
|
1098 | }
|
1099 |
|
1100 | return result;
|
1101 | }
|
1102 |
|
1103 | function isBinary$1(object) {
|
1104 | return NodeBuffer && NodeBuffer.isBuffer(object);
|
1105 | }
|
1106 |
|
1107 | var binary = new Type$6('tag:yaml.org,2002:binary', {
|
1108 | kind: 'scalar',
|
1109 | resolve: resolveYamlBinary,
|
1110 | construct: constructYamlBinary,
|
1111 | predicate: isBinary$1,
|
1112 | represent: representYamlBinary
|
1113 | });
|
1114 |
|
1115 | var Type$5 = type;
|
1116 |
|
1117 | var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
|
1118 | var _toString$2 = Object.prototype.toString;
|
1119 |
|
1120 | function resolveYamlOmap(data) {
|
1121 | if (data === null) return true;
|
1122 |
|
1123 | var objectKeys = [], index, length, pair, pairKey, pairHasKey,
|
1124 | object = data;
|
1125 |
|
1126 | for (index = 0, length = object.length; index < length; index += 1) {
|
1127 | pair = object[index];
|
1128 | pairHasKey = false;
|
1129 |
|
1130 | if (_toString$2.call(pair) !== '[object Object]') return false;
|
1131 |
|
1132 | for (pairKey in pair) {
|
1133 | if (_hasOwnProperty$3.call(pair, pairKey)) {
|
1134 | if (!pairHasKey) pairHasKey = true;
|
1135 | else return false;
|
1136 | }
|
1137 | }
|
1138 |
|
1139 | if (!pairHasKey) return false;
|
1140 |
|
1141 | if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
|
1142 | else return false;
|
1143 | }
|
1144 |
|
1145 | return true;
|
1146 | }
|
1147 |
|
1148 | function constructYamlOmap(data) {
|
1149 | return data !== null ? data : [];
|
1150 | }
|
1151 |
|
1152 | var omap = new Type$5('tag:yaml.org,2002:omap', {
|
1153 | kind: 'sequence',
|
1154 | resolve: resolveYamlOmap,
|
1155 | construct: constructYamlOmap
|
1156 | });
|
1157 |
|
1158 | var Type$4 = type;
|
1159 |
|
1160 | var _toString$1 = Object.prototype.toString;
|
1161 |
|
1162 | function resolveYamlPairs(data) {
|
1163 | if (data === null) return true;
|
1164 |
|
1165 | var index, length, pair, keys, result,
|
1166 | object = data;
|
1167 |
|
1168 | result = new Array(object.length);
|
1169 |
|
1170 | for (index = 0, length = object.length; index < length; index += 1) {
|
1171 | pair = object[index];
|
1172 |
|
1173 | if (_toString$1.call(pair) !== '[object Object]') return false;
|
1174 |
|
1175 | keys = Object.keys(pair);
|
1176 |
|
1177 | if (keys.length !== 1) return false;
|
1178 |
|
1179 | result[index] = [ keys[0], pair[keys[0]] ];
|
1180 | }
|
1181 |
|
1182 | return true;
|
1183 | }
|
1184 |
|
1185 | function constructYamlPairs(data) {
|
1186 | if (data === null) return [];
|
1187 |
|
1188 | var index, length, pair, keys, result,
|
1189 | object = data;
|
1190 |
|
1191 | result = new Array(object.length);
|
1192 |
|
1193 | for (index = 0, length = object.length; index < length; index += 1) {
|
1194 | pair = object[index];
|
1195 |
|
1196 | keys = Object.keys(pair);
|
1197 |
|
1198 | result[index] = [ keys[0], pair[keys[0]] ];
|
1199 | }
|
1200 |
|
1201 | return result;
|
1202 | }
|
1203 |
|
1204 | var pairs = new Type$4('tag:yaml.org,2002:pairs', {
|
1205 | kind: 'sequence',
|
1206 | resolve: resolveYamlPairs,
|
1207 | construct: constructYamlPairs
|
1208 | });
|
1209 |
|
1210 | var Type$3 = type;
|
1211 |
|
1212 | var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
|
1213 |
|
1214 | function resolveYamlSet(data) {
|
1215 | if (data === null) return true;
|
1216 |
|
1217 | var key, object = data;
|
1218 |
|
1219 | for (key in object) {
|
1220 | if (_hasOwnProperty$2.call(object, key)) {
|
1221 | if (object[key] !== null) return false;
|
1222 | }
|
1223 | }
|
1224 |
|
1225 | return true;
|
1226 | }
|
1227 |
|
1228 | function constructYamlSet(data) {
|
1229 | return data !== null ? data : {};
|
1230 | }
|
1231 |
|
1232 | var set = new Type$3('tag:yaml.org,2002:set', {
|
1233 | kind: 'mapping',
|
1234 | resolve: resolveYamlSet,
|
1235 | construct: constructYamlSet
|
1236 | });
|
1237 |
|
1238 | var Schema$1 = schema;
|
1239 |
|
1240 |
|
1241 | var default_safe = new Schema$1({
|
1242 | include: [
|
1243 | core
|
1244 | ],
|
1245 | implicit: [
|
1246 | timestamp,
|
1247 | merge
|
1248 | ],
|
1249 | explicit: [
|
1250 | binary,
|
1251 | omap,
|
1252 | pairs,
|
1253 | set
|
1254 | ]
|
1255 | });
|
1256 |
|
1257 | var Type$2 = type;
|
1258 |
|
1259 | function resolveJavascriptUndefined() {
|
1260 | return true;
|
1261 | }
|
1262 |
|
1263 | function constructJavascriptUndefined() {
|
1264 |
|
1265 | return undefined;
|
1266 | }
|
1267 |
|
1268 | function representJavascriptUndefined() {
|
1269 | return '';
|
1270 | }
|
1271 |
|
1272 | function isUndefined(object) {
|
1273 | return typeof object === 'undefined';
|
1274 | }
|
1275 |
|
1276 | var _undefined = new Type$2('tag:yaml.org,2002:js/undefined', {
|
1277 | kind: 'scalar',
|
1278 | resolve: resolveJavascriptUndefined,
|
1279 | construct: constructJavascriptUndefined,
|
1280 | predicate: isUndefined,
|
1281 | represent: representJavascriptUndefined
|
1282 | });
|
1283 |
|
1284 | var Type$1 = type;
|
1285 |
|
1286 | function resolveJavascriptRegExp(data) {
|
1287 | if (data === null) return false;
|
1288 | if (data.length === 0) return false;
|
1289 |
|
1290 | var regexp = data,
|
1291 | tail = /\/([gim]*)$/.exec(data),
|
1292 | modifiers = '';
|
1293 |
|
1294 |
|
1295 |
|
1296 | if (regexp[0] === '/') {
|
1297 | if (tail) modifiers = tail[1];
|
1298 |
|
1299 | if (modifiers.length > 3) return false;
|
1300 |
|
1301 | if (regexp[regexp.length - modifiers.length - 1] !== '/') return false;
|
1302 | }
|
1303 |
|
1304 | return true;
|
1305 | }
|
1306 |
|
1307 | function constructJavascriptRegExp(data) {
|
1308 | var regexp = data,
|
1309 | tail = /\/([gim]*)$/.exec(data),
|
1310 | modifiers = '';
|
1311 |
|
1312 |
|
1313 | if (regexp[0] === '/') {
|
1314 | if (tail) modifiers = tail[1];
|
1315 | regexp = regexp.slice(1, regexp.length - modifiers.length - 1);
|
1316 | }
|
1317 |
|
1318 | return new RegExp(regexp, modifiers);
|
1319 | }
|
1320 |
|
1321 | function representJavascriptRegExp(object /*, style*/) {
|
1322 | var result = '/' + object.source + '/';
|
1323 |
|
1324 | if (object.global) result += 'g';
|
1325 | if (object.multiline) result += 'm';
|
1326 | if (object.ignoreCase) result += 'i';
|
1327 |
|
1328 | return result;
|
1329 | }
|
1330 |
|
1331 | function isRegExp(object) {
|
1332 | return Object.prototype.toString.call(object) === '[object RegExp]';
|
1333 | }
|
1334 |
|
1335 | var regexp = new Type$1('tag:yaml.org,2002:js/regexp', {
|
1336 | kind: 'scalar',
|
1337 | resolve: resolveJavascriptRegExp,
|
1338 | construct: constructJavascriptRegExp,
|
1339 | predicate: isRegExp,
|
1340 | represent: representJavascriptRegExp
|
1341 | });
|
1342 |
|
1343 | var esprima;
|
1344 |
|
1345 |
|
1346 |
|
1347 |
|
1348 |
|
1349 |
|
1350 |
|
1351 |
|
1352 | try {
|
1353 |
|
1354 | var _require = commonjsRequire;
|
1355 | esprima = _require('esprima');
|
1356 | } catch (_) {
|
1357 |
|
1358 |
|
1359 | if (typeof window !== 'undefined') esprima = window.esprima;
|
1360 | }
|
1361 |
|
1362 | var Type = type;
|
1363 |
|
1364 | function resolveJavascriptFunction(data) {
|
1365 | if (data === null) return false;
|
1366 |
|
1367 | try {
|
1368 | var source = '(' + data + ')',
|
1369 | ast = esprima.parse(source, { range: true });
|
1370 |
|
1371 | if (ast.type !== 'Program' ||
|
1372 | ast.body.length !== 1 ||
|
1373 | ast.body[0].type !== 'ExpressionStatement' ||
|
1374 | (ast.body[0].expression.type !== 'ArrowFunctionExpression' &&
|
1375 | ast.body[0].expression.type !== 'FunctionExpression')) {
|
1376 | return false;
|
1377 | }
|
1378 |
|
1379 | return true;
|
1380 | } catch (err) {
|
1381 | return false;
|
1382 | }
|
1383 | }
|
1384 |
|
1385 | function constructJavascriptFunction(data) {
|
1386 |
|
1387 |
|
1388 | var source = '(' + data + ')',
|
1389 | ast = esprima.parse(source, { range: true }),
|
1390 | params = [],
|
1391 | body;
|
1392 |
|
1393 | if (ast.type !== 'Program' ||
|
1394 | ast.body.length !== 1 ||
|
1395 | ast.body[0].type !== 'ExpressionStatement' ||
|
1396 | (ast.body[0].expression.type !== 'ArrowFunctionExpression' &&
|
1397 | ast.body[0].expression.type !== 'FunctionExpression')) {
|
1398 | throw new Error('Failed to resolve function');
|
1399 | }
|
1400 |
|
1401 | ast.body[0].expression.params.forEach(function (param) {
|
1402 | params.push(param.name);
|
1403 | });
|
1404 |
|
1405 | body = ast.body[0].expression.body.range;
|
1406 |
|
1407 |
|
1408 |
|
1409 | if (ast.body[0].expression.body.type === 'BlockStatement') {
|
1410 |
|
1411 | return new Function(params, source.slice(body[0] + 1, body[1] - 1));
|
1412 | }
|
1413 |
|
1414 |
|
1415 |
|
1416 | return new Function(params, 'return ' + source.slice(body[0], body[1]));
|
1417 | }
|
1418 |
|
1419 | function representJavascriptFunction(object /*, style*/) {
|
1420 | return object.toString();
|
1421 | }
|
1422 |
|
1423 | function isFunction$1(object) {
|
1424 | return Object.prototype.toString.call(object) === '[object Function]';
|
1425 | }
|
1426 |
|
1427 | var _function = new Type('tag:yaml.org,2002:js/function', {
|
1428 | kind: 'scalar',
|
1429 | resolve: resolveJavascriptFunction,
|
1430 | construct: constructJavascriptFunction,
|
1431 | predicate: isFunction$1,
|
1432 | represent: representJavascriptFunction
|
1433 | });
|
1434 |
|
1435 | var Schema = schema;
|
1436 |
|
1437 |
|
1438 | var default_full = Schema.DEFAULT = new Schema({
|
1439 | include: [
|
1440 | default_safe
|
1441 | ],
|
1442 | explicit: [
|
1443 | _undefined,
|
1444 | regexp,
|
1445 | _function
|
1446 | ]
|
1447 | });
|
1448 |
|
1449 |
|
1450 |
|
1451 | var common$1 = common$6;
|
1452 | var YAMLException$1 = exception;
|
1453 | var Mark = mark;
|
1454 | var DEFAULT_SAFE_SCHEMA$1 = default_safe;
|
1455 | var DEFAULT_FULL_SCHEMA$1 = default_full;
|
1456 |
|
1457 |
|
1458 | var _hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
1459 |
|
1460 |
|
1461 | var CONTEXT_FLOW_IN = 1;
|
1462 | var CONTEXT_FLOW_OUT = 2;
|
1463 | var CONTEXT_BLOCK_IN = 3;
|
1464 | var CONTEXT_BLOCK_OUT = 4;
|
1465 |
|
1466 |
|
1467 | var CHOMPING_CLIP = 1;
|
1468 | var CHOMPING_STRIP = 2;
|
1469 | var CHOMPING_KEEP = 3;
|
1470 |
|
1471 |
|
1472 | var PATTERN_NON_PRINTABLE = /[\x00-\x08\x0B\x0C\x0E-\x1F\x7F-\x84\x86-\x9F\uFFFE\uFFFF]|[\uD800-\uDBFF](?![\uDC00-\uDFFF])|(?:[^\uD800-\uDBFF]|^)[\uDC00-\uDFFF]/;
|
1473 | var PATTERN_NON_ASCII_LINE_BREAKS = /[\x85\u2028\u2029]/;
|
1474 | var PATTERN_FLOW_INDICATORS = /[,\[\]\{\}]/;
|
1475 | var PATTERN_TAG_HANDLE = /^(?:!|!!|![a-z\-]+!)$/i;
|
1476 | var PATTERN_TAG_URI = /^(?:!|[^,\[\]\{\}])(?:%[0-9a-f]{2}|[0-9a-z\-#;\/\?:@&=\+\$,_\.!~\*'\(\)\[\]])*$/i;
|
1477 |
|
1478 |
|
1479 | function _class(obj) { return Object.prototype.toString.call(obj); }
|
1480 |
|
1481 | function is_EOL(c) {
|
1482 | return (c === 0x0A) || (c === 0x0D);
|
1483 | }
|
1484 |
|
1485 | function is_WHITE_SPACE(c) {
|
1486 | return (c === 0x09) || (c === 0x20);
|
1487 | }
|
1488 |
|
1489 | function is_WS_OR_EOL(c) {
|
1490 | return (c === 0x09) ||
|
1491 | (c === 0x20) ||
|
1492 | (c === 0x0A) ||
|
1493 | (c === 0x0D);
|
1494 | }
|
1495 |
|
1496 | function is_FLOW_INDICATOR(c) {
|
1497 | return c === 0x2C ||
|
1498 | c === 0x5B ||
|
1499 | c === 0x5D ||
|
1500 | c === 0x7B ||
|
1501 | c === 0x7D;
|
1502 | }
|
1503 |
|
1504 | function fromHexCode(c) {
|
1505 | var lc;
|
1506 |
|
1507 | if ((0x30 <= c) && (c <= 0x39)) {
|
1508 | return c - 0x30;
|
1509 | }
|
1510 |
|
1511 |
|
1512 | lc = c | 0x20;
|
1513 |
|
1514 | if ((0x61 <= lc) && (lc <= 0x66)) {
|
1515 | return lc - 0x61 + 10;
|
1516 | }
|
1517 |
|
1518 | return -1;
|
1519 | }
|
1520 |
|
1521 | function escapedHexLen(c) {
|
1522 | if (c === 0x78) { return 2; }
|
1523 | if (c === 0x75) { return 4; }
|
1524 | if (c === 0x55) { return 8; }
|
1525 | return 0;
|
1526 | }
|
1527 |
|
1528 | function fromDecimalCode(c) {
|
1529 | if ((0x30 <= c) && (c <= 0x39)) {
|
1530 | return c - 0x30;
|
1531 | }
|
1532 |
|
1533 | return -1;
|
1534 | }
|
1535 |
|
1536 | function simpleEscapeSequence(c) {
|
1537 |
|
1538 | return (c === 0x30) ? '\x00' :
|
1539 | (c === 0x61) ? '\x07' :
|
1540 | (c === 0x62) ? '\x08' :
|
1541 | (c === 0x74) ? '\x09' :
|
1542 | (c === 0x09) ? '\x09' :
|
1543 | (c === 0x6E) ? '\x0A' :
|
1544 | (c === 0x76) ? '\x0B' :
|
1545 | (c === 0x66) ? '\x0C' :
|
1546 | (c === 0x72) ? '\x0D' :
|
1547 | (c === 0x65) ? '\x1B' :
|
1548 | (c === 0x20) ? ' ' :
|
1549 | (c === 0x22) ? '\x22' :
|
1550 | (c === 0x2F) ? '/' :
|
1551 | (c === 0x5C) ? '\x5C' :
|
1552 | (c === 0x4E) ? '\x85' :
|
1553 | (c === 0x5F) ? '\xA0' :
|
1554 | (c === 0x4C) ? '\u2028' :
|
1555 | (c === 0x50) ? '\u2029' : '';
|
1556 | }
|
1557 |
|
1558 | function charFromCodepoint(c) {
|
1559 | if (c <= 0xFFFF) {
|
1560 | return String.fromCharCode(c);
|
1561 | }
|
1562 |
|
1563 |
|
1564 | return String.fromCharCode(
|
1565 | ((c - 0x010000) >> 10) + 0xD800,
|
1566 | ((c - 0x010000) & 0x03FF) + 0xDC00
|
1567 | );
|
1568 | }
|
1569 |
|
1570 | var simpleEscapeCheck = new Array(256);
|
1571 | var simpleEscapeMap = new Array(256);
|
1572 | for (var i = 0; i < 256; i++) {
|
1573 | simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
|
1574 | simpleEscapeMap[i] = simpleEscapeSequence(i);
|
1575 | }
|
1576 |
|
1577 |
|
1578 | function State$1(input, options) {
|
1579 | this.input = input;
|
1580 |
|
1581 | this.filename = options['filename'] || null;
|
1582 | this.schema = options['schema'] || DEFAULT_FULL_SCHEMA$1;
|
1583 | this.onWarning = options['onWarning'] || null;
|
1584 | this.legacy = options['legacy'] || false;
|
1585 | this.json = options['json'] || false;
|
1586 | this.listener = options['listener'] || null;
|
1587 |
|
1588 | this.implicitTypes = this.schema.compiledImplicit;
|
1589 | this.typeMap = this.schema.compiledTypeMap;
|
1590 |
|
1591 | this.length = input.length;
|
1592 | this.position = 0;
|
1593 | this.line = 0;
|
1594 | this.lineStart = 0;
|
1595 | this.lineIndent = 0;
|
1596 |
|
1597 | this.documents = [];
|
1598 |
|
1599 | |
1600 |
|
1601 |
|
1602 |
|
1603 |
|
1604 |
|
1605 |
|
1606 |
|
1607 |
|
1608 |
|
1609 | }
|
1610 |
|
1611 |
|
1612 | function generateError(state, message) {
|
1613 | return new YAMLException$1(
|
1614 | message,
|
1615 | new Mark(state.filename, state.input, state.position, state.line, (state.position - state.lineStart)));
|
1616 | }
|
1617 |
|
1618 | function throwError(state, message) {
|
1619 | throw generateError(state, message);
|
1620 | }
|
1621 |
|
1622 | function throwWarning(state, message) {
|
1623 | if (state.onWarning) {
|
1624 | state.onWarning.call(null, generateError(state, message));
|
1625 | }
|
1626 | }
|
1627 |
|
1628 |
|
1629 | var directiveHandlers = {
|
1630 |
|
1631 | YAML: function handleYamlDirective(state, name, args) {
|
1632 |
|
1633 | var match, major, minor;
|
1634 |
|
1635 | if (state.version !== null) {
|
1636 | throwError(state, 'duplication of %YAML directive');
|
1637 | }
|
1638 |
|
1639 | if (args.length !== 1) {
|
1640 | throwError(state, 'YAML directive accepts exactly one argument');
|
1641 | }
|
1642 |
|
1643 | match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
1644 |
|
1645 | if (match === null) {
|
1646 | throwError(state, 'ill-formed argument of the YAML directive');
|
1647 | }
|
1648 |
|
1649 | major = parseInt(match[1], 10);
|
1650 | minor = parseInt(match[2], 10);
|
1651 |
|
1652 | if (major !== 1) {
|
1653 | throwError(state, 'unacceptable YAML version of the document');
|
1654 | }
|
1655 |
|
1656 | state.version = args[0];
|
1657 | state.checkLineBreaks = (minor < 2);
|
1658 |
|
1659 | if (minor !== 1 && minor !== 2) {
|
1660 | throwWarning(state, 'unsupported YAML version of the document');
|
1661 | }
|
1662 | },
|
1663 |
|
1664 | TAG: function handleTagDirective(state, name, args) {
|
1665 |
|
1666 | var handle, prefix;
|
1667 |
|
1668 | if (args.length !== 2) {
|
1669 | throwError(state, 'TAG directive accepts exactly two arguments');
|
1670 | }
|
1671 |
|
1672 | handle = args[0];
|
1673 | prefix = args[1];
|
1674 |
|
1675 | if (!PATTERN_TAG_HANDLE.test(handle)) {
|
1676 | throwError(state, 'ill-formed tag handle (first argument) of the TAG directive');
|
1677 | }
|
1678 |
|
1679 | if (_hasOwnProperty$1.call(state.tagMap, handle)) {
|
1680 | throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
1681 | }
|
1682 |
|
1683 | if (!PATTERN_TAG_URI.test(prefix)) {
|
1684 | throwError(state, 'ill-formed tag prefix (second argument) of the TAG directive');
|
1685 | }
|
1686 |
|
1687 | state.tagMap[handle] = prefix;
|
1688 | }
|
1689 | };
|
1690 |
|
1691 |
|
1692 | function captureSegment(state, start, end, checkJson) {
|
1693 | var _position, _length, _character, _result;
|
1694 |
|
1695 | if (start < end) {
|
1696 | _result = state.input.slice(start, end);
|
1697 |
|
1698 | if (checkJson) {
|
1699 | for (_position = 0, _length = _result.length; _position < _length; _position += 1) {
|
1700 | _character = _result.charCodeAt(_position);
|
1701 | if (!(_character === 0x09 ||
|
1702 | (0x20 <= _character && _character <= 0x10FFFF))) {
|
1703 | throwError(state, 'expected valid JSON character');
|
1704 | }
|
1705 | }
|
1706 | } else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
1707 | throwError(state, 'the stream contains non-printable characters');
|
1708 | }
|
1709 |
|
1710 | state.result += _result;
|
1711 | }
|
1712 | }
|
1713 |
|
1714 | function mergeMappings(state, destination, source, overridableKeys) {
|
1715 | var sourceKeys, key, index, quantity;
|
1716 |
|
1717 | if (!common$1.isObject(source)) {
|
1718 | throwError(state, 'cannot merge mappings; the provided source object is unacceptable');
|
1719 | }
|
1720 |
|
1721 | sourceKeys = Object.keys(source);
|
1722 |
|
1723 | for (index = 0, quantity = sourceKeys.length; index < quantity; index += 1) {
|
1724 | key = sourceKeys[index];
|
1725 |
|
1726 | if (!_hasOwnProperty$1.call(destination, key)) {
|
1727 | destination[key] = source[key];
|
1728 | overridableKeys[key] = true;
|
1729 | }
|
1730 | }
|
1731 | }
|
1732 |
|
1733 | function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, startLine, startPos) {
|
1734 | var index, quantity;
|
1735 |
|
1736 |
|
1737 |
|
1738 |
|
1739 | if (Array.isArray(keyNode)) {
|
1740 | keyNode = Array.prototype.slice.call(keyNode);
|
1741 |
|
1742 | for (index = 0, quantity = keyNode.length; index < quantity; index += 1) {
|
1743 | if (Array.isArray(keyNode[index])) {
|
1744 | throwError(state, 'nested arrays are not supported inside keys');
|
1745 | }
|
1746 |
|
1747 | if (typeof keyNode === 'object' && _class(keyNode[index]) === '[object Object]') {
|
1748 | keyNode[index] = '[object Object]';
|
1749 | }
|
1750 | }
|
1751 | }
|
1752 |
|
1753 |
|
1754 |
|
1755 |
|
1756 | if (typeof keyNode === 'object' && _class(keyNode) === '[object Object]') {
|
1757 | keyNode = '[object Object]';
|
1758 | }
|
1759 |
|
1760 |
|
1761 | keyNode = String(keyNode);
|
1762 |
|
1763 | if (_result === null) {
|
1764 | _result = {};
|
1765 | }
|
1766 |
|
1767 | if (keyTag === 'tag:yaml.org,2002:merge') {
|
1768 | if (Array.isArray(valueNode)) {
|
1769 | for (index = 0, quantity = valueNode.length; index < quantity; index += 1) {
|
1770 | mergeMappings(state, _result, valueNode[index], overridableKeys);
|
1771 | }
|
1772 | } else {
|
1773 | mergeMappings(state, _result, valueNode, overridableKeys);
|
1774 | }
|
1775 | } else {
|
1776 | if (!state.json &&
|
1777 | !_hasOwnProperty$1.call(overridableKeys, keyNode) &&
|
1778 | _hasOwnProperty$1.call(_result, keyNode)) {
|
1779 | state.line = startLine || state.line;
|
1780 | state.position = startPos || state.position;
|
1781 | throwError(state, 'duplicated mapping key');
|
1782 | }
|
1783 | _result[keyNode] = valueNode;
|
1784 | delete overridableKeys[keyNode];
|
1785 | }
|
1786 |
|
1787 | return _result;
|
1788 | }
|
1789 |
|
1790 | function readLineBreak(state) {
|
1791 | var ch;
|
1792 |
|
1793 | ch = state.input.charCodeAt(state.position);
|
1794 |
|
1795 | if (ch === 0x0A) {
|
1796 | state.position++;
|
1797 | } else if (ch === 0x0D) {
|
1798 | state.position++;
|
1799 | if (state.input.charCodeAt(state.position) === 0x0A) {
|
1800 | state.position++;
|
1801 | }
|
1802 | } else {
|
1803 | throwError(state, 'a line break is expected');
|
1804 | }
|
1805 |
|
1806 | state.line += 1;
|
1807 | state.lineStart = state.position;
|
1808 | }
|
1809 |
|
1810 | function skipSeparationSpace(state, allowComments, checkIndent) {
|
1811 | var lineBreaks = 0,
|
1812 | ch = state.input.charCodeAt(state.position);
|
1813 |
|
1814 | while (ch !== 0) {
|
1815 | while (is_WHITE_SPACE(ch)) {
|
1816 | ch = state.input.charCodeAt(++state.position);
|
1817 | }
|
1818 |
|
1819 | if (allowComments && ch === 0x23) {
|
1820 | do {
|
1821 | ch = state.input.charCodeAt(++state.position);
|
1822 | } while (ch !== 0x0A && ch !== 0x0D && ch !== 0);
|
1823 | }
|
1824 |
|
1825 | if (is_EOL(ch)) {
|
1826 | readLineBreak(state);
|
1827 |
|
1828 | ch = state.input.charCodeAt(state.position);
|
1829 | lineBreaks++;
|
1830 | state.lineIndent = 0;
|
1831 |
|
1832 | while (ch === 0x20) {
|
1833 | state.lineIndent++;
|
1834 | ch = state.input.charCodeAt(++state.position);
|
1835 | }
|
1836 | } else {
|
1837 | break;
|
1838 | }
|
1839 | }
|
1840 |
|
1841 | if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
1842 | throwWarning(state, 'deficient indentation');
|
1843 | }
|
1844 |
|
1845 | return lineBreaks;
|
1846 | }
|
1847 |
|
1848 | function testDocumentSeparator(state) {
|
1849 | var _position = state.position,
|
1850 | ch;
|
1851 |
|
1852 | ch = state.input.charCodeAt(_position);
|
1853 |
|
1854 |
|
1855 |
|
1856 | if ((ch === 0x2D || ch === 0x2E) &&
|
1857 | ch === state.input.charCodeAt(_position + 1) &&
|
1858 | ch === state.input.charCodeAt(_position + 2)) {
|
1859 |
|
1860 | _position += 3;
|
1861 |
|
1862 | ch = state.input.charCodeAt(_position);
|
1863 |
|
1864 | if (ch === 0 || is_WS_OR_EOL(ch)) {
|
1865 | return true;
|
1866 | }
|
1867 | }
|
1868 |
|
1869 | return false;
|
1870 | }
|
1871 |
|
1872 | function writeFoldedLines(state, count) {
|
1873 | if (count === 1) {
|
1874 | state.result += ' ';
|
1875 | } else if (count > 1) {
|
1876 | state.result += common$1.repeat('\n', count - 1);
|
1877 | }
|
1878 | }
|
1879 |
|
1880 |
|
1881 | function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
1882 | var preceding,
|
1883 | following,
|
1884 | captureStart,
|
1885 | captureEnd,
|
1886 | hasPendingContent,
|
1887 | _line,
|
1888 | _lineStart,
|
1889 | _lineIndent,
|
1890 | _kind = state.kind,
|
1891 | _result = state.result,
|
1892 | ch;
|
1893 |
|
1894 | ch = state.input.charCodeAt(state.position);
|
1895 |
|
1896 | if (is_WS_OR_EOL(ch) ||
|
1897 | is_FLOW_INDICATOR(ch) ||
|
1898 | ch === 0x23 ||
|
1899 | ch === 0x26 ||
|
1900 | ch === 0x2A ||
|
1901 | ch === 0x21 ||
|
1902 | ch === 0x7C ||
|
1903 | ch === 0x3E ||
|
1904 | ch === 0x27 ||
|
1905 | ch === 0x22 ||
|
1906 | ch === 0x25 ||
|
1907 | ch === 0x40 ||
|
1908 | ch === 0x60) {
|
1909 | return false;
|
1910 | }
|
1911 |
|
1912 | if (ch === 0x3F || ch === 0x2D) {
|
1913 | following = state.input.charCodeAt(state.position + 1);
|
1914 |
|
1915 | if (is_WS_OR_EOL(following) ||
|
1916 | withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
1917 | return false;
|
1918 | }
|
1919 | }
|
1920 |
|
1921 | state.kind = 'scalar';
|
1922 | state.result = '';
|
1923 | captureStart = captureEnd = state.position;
|
1924 | hasPendingContent = false;
|
1925 |
|
1926 | while (ch !== 0) {
|
1927 | if (ch === 0x3A) {
|
1928 | following = state.input.charCodeAt(state.position + 1);
|
1929 |
|
1930 | if (is_WS_OR_EOL(following) ||
|
1931 | withinFlowCollection && is_FLOW_INDICATOR(following)) {
|
1932 | break;
|
1933 | }
|
1934 |
|
1935 | } else if (ch === 0x23) {
|
1936 | preceding = state.input.charCodeAt(state.position - 1);
|
1937 |
|
1938 | if (is_WS_OR_EOL(preceding)) {
|
1939 | break;
|
1940 | }
|
1941 |
|
1942 | } else if ((state.position === state.lineStart && testDocumentSeparator(state)) ||
|
1943 | withinFlowCollection && is_FLOW_INDICATOR(ch)) {
|
1944 | break;
|
1945 |
|
1946 | } else if (is_EOL(ch)) {
|
1947 | _line = state.line;
|
1948 | _lineStart = state.lineStart;
|
1949 | _lineIndent = state.lineIndent;
|
1950 | skipSeparationSpace(state, false, -1);
|
1951 |
|
1952 | if (state.lineIndent >= nodeIndent) {
|
1953 | hasPendingContent = true;
|
1954 | ch = state.input.charCodeAt(state.position);
|
1955 | continue;
|
1956 | } else {
|
1957 | state.position = captureEnd;
|
1958 | state.line = _line;
|
1959 | state.lineStart = _lineStart;
|
1960 | state.lineIndent = _lineIndent;
|
1961 | break;
|
1962 | }
|
1963 | }
|
1964 |
|
1965 | if (hasPendingContent) {
|
1966 | captureSegment(state, captureStart, captureEnd, false);
|
1967 | writeFoldedLines(state, state.line - _line);
|
1968 | captureStart = captureEnd = state.position;
|
1969 | hasPendingContent = false;
|
1970 | }
|
1971 |
|
1972 | if (!is_WHITE_SPACE(ch)) {
|
1973 | captureEnd = state.position + 1;
|
1974 | }
|
1975 |
|
1976 | ch = state.input.charCodeAt(++state.position);
|
1977 | }
|
1978 |
|
1979 | captureSegment(state, captureStart, captureEnd, false);
|
1980 |
|
1981 | if (state.result) {
|
1982 | return true;
|
1983 | }
|
1984 |
|
1985 | state.kind = _kind;
|
1986 | state.result = _result;
|
1987 | return false;
|
1988 | }
|
1989 |
|
1990 | function readSingleQuotedScalar(state, nodeIndent) {
|
1991 | var ch,
|
1992 | captureStart, captureEnd;
|
1993 |
|
1994 | ch = state.input.charCodeAt(state.position);
|
1995 |
|
1996 | if (ch !== 0x27) {
|
1997 | return false;
|
1998 | }
|
1999 |
|
2000 | state.kind = 'scalar';
|
2001 | state.result = '';
|
2002 | state.position++;
|
2003 | captureStart = captureEnd = state.position;
|
2004 |
|
2005 | while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
2006 | if (ch === 0x27) {
|
2007 | captureSegment(state, captureStart, state.position, true);
|
2008 | ch = state.input.charCodeAt(++state.position);
|
2009 |
|
2010 | if (ch === 0x27) {
|
2011 | captureStart = state.position;
|
2012 | state.position++;
|
2013 | captureEnd = state.position;
|
2014 | } else {
|
2015 | return true;
|
2016 | }
|
2017 |
|
2018 | } else if (is_EOL(ch)) {
|
2019 | captureSegment(state, captureStart, captureEnd, true);
|
2020 | writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
2021 | captureStart = captureEnd = state.position;
|
2022 |
|
2023 | } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
2024 | throwError(state, 'unexpected end of the document within a single quoted scalar');
|
2025 |
|
2026 | } else {
|
2027 | state.position++;
|
2028 | captureEnd = state.position;
|
2029 | }
|
2030 | }
|
2031 |
|
2032 | throwError(state, 'unexpected end of the stream within a single quoted scalar');
|
2033 | }
|
2034 |
|
2035 | function readDoubleQuotedScalar(state, nodeIndent) {
|
2036 | var captureStart,
|
2037 | captureEnd,
|
2038 | hexLength,
|
2039 | hexResult,
|
2040 | tmp,
|
2041 | ch;
|
2042 |
|
2043 | ch = state.input.charCodeAt(state.position);
|
2044 |
|
2045 | if (ch !== 0x22) {
|
2046 | return false;
|
2047 | }
|
2048 |
|
2049 | state.kind = 'scalar';
|
2050 | state.result = '';
|
2051 | state.position++;
|
2052 | captureStart = captureEnd = state.position;
|
2053 |
|
2054 | while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
2055 | if (ch === 0x22) {
|
2056 | captureSegment(state, captureStart, state.position, true);
|
2057 | state.position++;
|
2058 | return true;
|
2059 |
|
2060 | } else if (ch === 0x5C) {
|
2061 | captureSegment(state, captureStart, state.position, true);
|
2062 | ch = state.input.charCodeAt(++state.position);
|
2063 |
|
2064 | if (is_EOL(ch)) {
|
2065 | skipSeparationSpace(state, false, nodeIndent);
|
2066 |
|
2067 |
|
2068 | } else if (ch < 256 && simpleEscapeCheck[ch]) {
|
2069 | state.result += simpleEscapeMap[ch];
|
2070 | state.position++;
|
2071 |
|
2072 | } else if ((tmp = escapedHexLen(ch)) > 0) {
|
2073 | hexLength = tmp;
|
2074 | hexResult = 0;
|
2075 |
|
2076 | for (; hexLength > 0; hexLength--) {
|
2077 | ch = state.input.charCodeAt(++state.position);
|
2078 |
|
2079 | if ((tmp = fromHexCode(ch)) >= 0) {
|
2080 | hexResult = (hexResult << 4) + tmp;
|
2081 |
|
2082 | } else {
|
2083 | throwError(state, 'expected hexadecimal character');
|
2084 | }
|
2085 | }
|
2086 |
|
2087 | state.result += charFromCodepoint(hexResult);
|
2088 |
|
2089 | state.position++;
|
2090 |
|
2091 | } else {
|
2092 | throwError(state, 'unknown escape sequence');
|
2093 | }
|
2094 |
|
2095 | captureStart = captureEnd = state.position;
|
2096 |
|
2097 | } else if (is_EOL(ch)) {
|
2098 | captureSegment(state, captureStart, captureEnd, true);
|
2099 | writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
2100 | captureStart = captureEnd = state.position;
|
2101 |
|
2102 | } else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
2103 | throwError(state, 'unexpected end of the document within a double quoted scalar');
|
2104 |
|
2105 | } else {
|
2106 | state.position++;
|
2107 | captureEnd = state.position;
|
2108 | }
|
2109 | }
|
2110 |
|
2111 | throwError(state, 'unexpected end of the stream within a double quoted scalar');
|
2112 | }
|
2113 |
|
2114 | function readFlowCollection(state, nodeIndent) {
|
2115 | var readNext = true,
|
2116 | _line,
|
2117 | _tag = state.tag,
|
2118 | _result,
|
2119 | _anchor = state.anchor,
|
2120 | following,
|
2121 | terminator,
|
2122 | isPair,
|
2123 | isExplicitPair,
|
2124 | isMapping,
|
2125 | overridableKeys = {},
|
2126 | keyNode,
|
2127 | keyTag,
|
2128 | valueNode,
|
2129 | ch;
|
2130 |
|
2131 | ch = state.input.charCodeAt(state.position);
|
2132 |
|
2133 | if (ch === 0x5B) {
|
2134 | terminator = 0x5D;
|
2135 | isMapping = false;
|
2136 | _result = [];
|
2137 | } else if (ch === 0x7B) {
|
2138 | terminator = 0x7D;
|
2139 | isMapping = true;
|
2140 | _result = {};
|
2141 | } else {
|
2142 | return false;
|
2143 | }
|
2144 |
|
2145 | if (state.anchor !== null) {
|
2146 | state.anchorMap[state.anchor] = _result;
|
2147 | }
|
2148 |
|
2149 | ch = state.input.charCodeAt(++state.position);
|
2150 |
|
2151 | while (ch !== 0) {
|
2152 | skipSeparationSpace(state, true, nodeIndent);
|
2153 |
|
2154 | ch = state.input.charCodeAt(state.position);
|
2155 |
|
2156 | if (ch === terminator) {
|
2157 | state.position++;
|
2158 | state.tag = _tag;
|
2159 | state.anchor = _anchor;
|
2160 | state.kind = isMapping ? 'mapping' : 'sequence';
|
2161 | state.result = _result;
|
2162 | return true;
|
2163 | } else if (!readNext) {
|
2164 | throwError(state, 'missed comma between flow collection entries');
|
2165 | }
|
2166 |
|
2167 | keyTag = keyNode = valueNode = null;
|
2168 | isPair = isExplicitPair = false;
|
2169 |
|
2170 | if (ch === 0x3F) {
|
2171 | following = state.input.charCodeAt(state.position + 1);
|
2172 |
|
2173 | if (is_WS_OR_EOL(following)) {
|
2174 | isPair = isExplicitPair = true;
|
2175 | state.position++;
|
2176 | skipSeparationSpace(state, true, nodeIndent);
|
2177 | }
|
2178 | }
|
2179 |
|
2180 | _line = state.line;
|
2181 | composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
2182 | keyTag = state.tag;
|
2183 | keyNode = state.result;
|
2184 | skipSeparationSpace(state, true, nodeIndent);
|
2185 |
|
2186 | ch = state.input.charCodeAt(state.position);
|
2187 |
|
2188 | if ((isExplicitPair || state.line === _line) && ch === 0x3A) {
|
2189 | isPair = true;
|
2190 | ch = state.input.charCodeAt(++state.position);
|
2191 | skipSeparationSpace(state, true, nodeIndent);
|
2192 | composeNode(state, nodeIndent, CONTEXT_FLOW_IN, false, true);
|
2193 | valueNode = state.result;
|
2194 | }
|
2195 |
|
2196 | if (isMapping) {
|
2197 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode);
|
2198 | } else if (isPair) {
|
2199 | _result.push(storeMappingPair(state, null, overridableKeys, keyTag, keyNode, valueNode));
|
2200 | } else {
|
2201 | _result.push(keyNode);
|
2202 | }
|
2203 |
|
2204 | skipSeparationSpace(state, true, nodeIndent);
|
2205 |
|
2206 | ch = state.input.charCodeAt(state.position);
|
2207 |
|
2208 | if (ch === 0x2C) {
|
2209 | readNext = true;
|
2210 | ch = state.input.charCodeAt(++state.position);
|
2211 | } else {
|
2212 | readNext = false;
|
2213 | }
|
2214 | }
|
2215 |
|
2216 | throwError(state, 'unexpected end of the stream within a flow collection');
|
2217 | }
|
2218 |
|
2219 | function readBlockScalar(state, nodeIndent) {
|
2220 | var captureStart,
|
2221 | folding,
|
2222 | chomping = CHOMPING_CLIP,
|
2223 | didReadContent = false,
|
2224 | detectedIndent = false,
|
2225 | textIndent = nodeIndent,
|
2226 | emptyLines = 0,
|
2227 | atMoreIndented = false,
|
2228 | tmp,
|
2229 | ch;
|
2230 |
|
2231 | ch = state.input.charCodeAt(state.position);
|
2232 |
|
2233 | if (ch === 0x7C) {
|
2234 | folding = false;
|
2235 | } else if (ch === 0x3E) {
|
2236 | folding = true;
|
2237 | } else {
|
2238 | return false;
|
2239 | }
|
2240 |
|
2241 | state.kind = 'scalar';
|
2242 | state.result = '';
|
2243 |
|
2244 | while (ch !== 0) {
|
2245 | ch = state.input.charCodeAt(++state.position);
|
2246 |
|
2247 | if (ch === 0x2B || ch === 0x2D) {
|
2248 | if (CHOMPING_CLIP === chomping) {
|
2249 | chomping = (ch === 0x2B) ? CHOMPING_KEEP : CHOMPING_STRIP;
|
2250 | } else {
|
2251 | throwError(state, 'repeat of a chomping mode identifier');
|
2252 | }
|
2253 |
|
2254 | } else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
2255 | if (tmp === 0) {
|
2256 | throwError(state, 'bad explicit indentation width of a block scalar; it cannot be less than one');
|
2257 | } else if (!detectedIndent) {
|
2258 | textIndent = nodeIndent + tmp - 1;
|
2259 | detectedIndent = true;
|
2260 | } else {
|
2261 | throwError(state, 'repeat of an indentation width identifier');
|
2262 | }
|
2263 |
|
2264 | } else {
|
2265 | break;
|
2266 | }
|
2267 | }
|
2268 |
|
2269 | if (is_WHITE_SPACE(ch)) {
|
2270 | do { ch = state.input.charCodeAt(++state.position); }
|
2271 | while (is_WHITE_SPACE(ch));
|
2272 |
|
2273 | if (ch === 0x23) {
|
2274 | do { ch = state.input.charCodeAt(++state.position); }
|
2275 | while (!is_EOL(ch) && (ch !== 0));
|
2276 | }
|
2277 | }
|
2278 |
|
2279 | while (ch !== 0) {
|
2280 | readLineBreak(state);
|
2281 | state.lineIndent = 0;
|
2282 |
|
2283 | ch = state.input.charCodeAt(state.position);
|
2284 |
|
2285 | while ((!detectedIndent || state.lineIndent < textIndent) &&
|
2286 | (ch === 0x20)) {
|
2287 | state.lineIndent++;
|
2288 | ch = state.input.charCodeAt(++state.position);
|
2289 | }
|
2290 |
|
2291 | if (!detectedIndent && state.lineIndent > textIndent) {
|
2292 | textIndent = state.lineIndent;
|
2293 | }
|
2294 |
|
2295 | if (is_EOL(ch)) {
|
2296 | emptyLines++;
|
2297 | continue;
|
2298 | }
|
2299 |
|
2300 |
|
2301 | if (state.lineIndent < textIndent) {
|
2302 |
|
2303 |
|
2304 | if (chomping === CHOMPING_KEEP) {
|
2305 | state.result += common$1.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
2306 | } else if (chomping === CHOMPING_CLIP) {
|
2307 | if (didReadContent) {
|
2308 | state.result += '\n';
|
2309 | }
|
2310 | }
|
2311 |
|
2312 |
|
2313 | break;
|
2314 | }
|
2315 |
|
2316 |
|
2317 | if (folding) {
|
2318 |
|
2319 |
|
2320 | if (is_WHITE_SPACE(ch)) {
|
2321 | atMoreIndented = true;
|
2322 |
|
2323 | state.result += common$1.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
2324 |
|
2325 |
|
2326 | } else if (atMoreIndented) {
|
2327 | atMoreIndented = false;
|
2328 | state.result += common$1.repeat('\n', emptyLines + 1);
|
2329 |
|
2330 |
|
2331 | } else if (emptyLines === 0) {
|
2332 | if (didReadContent) {
|
2333 | state.result += ' ';
|
2334 | }
|
2335 |
|
2336 |
|
2337 | } else {
|
2338 | state.result += common$1.repeat('\n', emptyLines);
|
2339 | }
|
2340 |
|
2341 |
|
2342 | } else {
|
2343 |
|
2344 | state.result += common$1.repeat('\n', didReadContent ? 1 + emptyLines : emptyLines);
|
2345 | }
|
2346 |
|
2347 | didReadContent = true;
|
2348 | detectedIndent = true;
|
2349 | emptyLines = 0;
|
2350 | captureStart = state.position;
|
2351 |
|
2352 | while (!is_EOL(ch) && (ch !== 0)) {
|
2353 | ch = state.input.charCodeAt(++state.position);
|
2354 | }
|
2355 |
|
2356 | captureSegment(state, captureStart, state.position, false);
|
2357 | }
|
2358 |
|
2359 | return true;
|
2360 | }
|
2361 |
|
2362 | function readBlockSequence(state, nodeIndent) {
|
2363 | var _line,
|
2364 | _tag = state.tag,
|
2365 | _anchor = state.anchor,
|
2366 | _result = [],
|
2367 | following,
|
2368 | detected = false,
|
2369 | ch;
|
2370 |
|
2371 | if (state.anchor !== null) {
|
2372 | state.anchorMap[state.anchor] = _result;
|
2373 | }
|
2374 |
|
2375 | ch = state.input.charCodeAt(state.position);
|
2376 |
|
2377 | while (ch !== 0) {
|
2378 |
|
2379 | if (ch !== 0x2D) {
|
2380 | break;
|
2381 | }
|
2382 |
|
2383 | following = state.input.charCodeAt(state.position + 1);
|
2384 |
|
2385 | if (!is_WS_OR_EOL(following)) {
|
2386 | break;
|
2387 | }
|
2388 |
|
2389 | detected = true;
|
2390 | state.position++;
|
2391 |
|
2392 | if (skipSeparationSpace(state, true, -1)) {
|
2393 | if (state.lineIndent <= nodeIndent) {
|
2394 | _result.push(null);
|
2395 | ch = state.input.charCodeAt(state.position);
|
2396 | continue;
|
2397 | }
|
2398 | }
|
2399 |
|
2400 | _line = state.line;
|
2401 | composeNode(state, nodeIndent, CONTEXT_BLOCK_IN, false, true);
|
2402 | _result.push(state.result);
|
2403 | skipSeparationSpace(state, true, -1);
|
2404 |
|
2405 | ch = state.input.charCodeAt(state.position);
|
2406 |
|
2407 | if ((state.line === _line || state.lineIndent > nodeIndent) && (ch !== 0)) {
|
2408 | throwError(state, 'bad indentation of a sequence entry');
|
2409 | } else if (state.lineIndent < nodeIndent) {
|
2410 | break;
|
2411 | }
|
2412 | }
|
2413 |
|
2414 | if (detected) {
|
2415 | state.tag = _tag;
|
2416 | state.anchor = _anchor;
|
2417 | state.kind = 'sequence';
|
2418 | state.result = _result;
|
2419 | return true;
|
2420 | }
|
2421 | return false;
|
2422 | }
|
2423 |
|
2424 | function readBlockMapping(state, nodeIndent, flowIndent) {
|
2425 | var following,
|
2426 | allowCompact,
|
2427 | _line,
|
2428 | _pos,
|
2429 | _tag = state.tag,
|
2430 | _anchor = state.anchor,
|
2431 | _result = {},
|
2432 | overridableKeys = {},
|
2433 | keyTag = null,
|
2434 | keyNode = null,
|
2435 | valueNode = null,
|
2436 | atExplicitKey = false,
|
2437 | detected = false,
|
2438 | ch;
|
2439 |
|
2440 | if (state.anchor !== null) {
|
2441 | state.anchorMap[state.anchor] = _result;
|
2442 | }
|
2443 |
|
2444 | ch = state.input.charCodeAt(state.position);
|
2445 |
|
2446 | while (ch !== 0) {
|
2447 | following = state.input.charCodeAt(state.position + 1);
|
2448 | _line = state.line;
|
2449 | _pos = state.position;
|
2450 |
|
2451 |
|
2452 |
|
2453 |
|
2454 |
|
2455 | if ((ch === 0x3F || ch === 0x3A) && is_WS_OR_EOL(following)) {
|
2456 |
|
2457 | if (ch === 0x3F) {
|
2458 | if (atExplicitKey) {
|
2459 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
2460 | keyTag = keyNode = valueNode = null;
|
2461 | }
|
2462 |
|
2463 | detected = true;
|
2464 | atExplicitKey = true;
|
2465 | allowCompact = true;
|
2466 |
|
2467 | } else if (atExplicitKey) {
|
2468 |
|
2469 | atExplicitKey = false;
|
2470 | allowCompact = true;
|
2471 |
|
2472 | } else {
|
2473 | throwError(state, 'incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line');
|
2474 | }
|
2475 |
|
2476 | state.position += 1;
|
2477 | ch = following;
|
2478 |
|
2479 |
|
2480 |
|
2481 |
|
2482 | } else if (composeNode(state, flowIndent, CONTEXT_FLOW_OUT, false, true)) {
|
2483 |
|
2484 | if (state.line === _line) {
|
2485 | ch = state.input.charCodeAt(state.position);
|
2486 |
|
2487 | while (is_WHITE_SPACE(ch)) {
|
2488 | ch = state.input.charCodeAt(++state.position);
|
2489 | }
|
2490 |
|
2491 | if (ch === 0x3A) {
|
2492 | ch = state.input.charCodeAt(++state.position);
|
2493 |
|
2494 | if (!is_WS_OR_EOL(ch)) {
|
2495 | throwError(state, 'a whitespace character is expected after the key-value separator within a block mapping');
|
2496 | }
|
2497 |
|
2498 | if (atExplicitKey) {
|
2499 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
2500 | keyTag = keyNode = valueNode = null;
|
2501 | }
|
2502 |
|
2503 | detected = true;
|
2504 | atExplicitKey = false;
|
2505 | allowCompact = false;
|
2506 | keyTag = state.tag;
|
2507 | keyNode = state.result;
|
2508 |
|
2509 | } else if (detected) {
|
2510 | throwError(state, 'can not read an implicit mapping pair; a colon is missed');
|
2511 |
|
2512 | } else {
|
2513 | state.tag = _tag;
|
2514 | state.anchor = _anchor;
|
2515 | return true;
|
2516 | }
|
2517 |
|
2518 | } else if (detected) {
|
2519 | throwError(state, 'can not read a block mapping entry; a multiline key may not be an implicit key');
|
2520 |
|
2521 | } else {
|
2522 | state.tag = _tag;
|
2523 | state.anchor = _anchor;
|
2524 | return true;
|
2525 | }
|
2526 |
|
2527 | } else {
|
2528 | break;
|
2529 | }
|
2530 |
|
2531 |
|
2532 |
|
2533 |
|
2534 | if (state.line === _line || state.lineIndent > nodeIndent) {
|
2535 | if (composeNode(state, nodeIndent, CONTEXT_BLOCK_OUT, true, allowCompact)) {
|
2536 | if (atExplicitKey) {
|
2537 | keyNode = state.result;
|
2538 | } else {
|
2539 | valueNode = state.result;
|
2540 | }
|
2541 | }
|
2542 |
|
2543 | if (!atExplicitKey) {
|
2544 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valueNode, _line, _pos);
|
2545 | keyTag = keyNode = valueNode = null;
|
2546 | }
|
2547 |
|
2548 | skipSeparationSpace(state, true, -1);
|
2549 | ch = state.input.charCodeAt(state.position);
|
2550 | }
|
2551 |
|
2552 | if (state.lineIndent > nodeIndent && (ch !== 0)) {
|
2553 | throwError(state, 'bad indentation of a mapping entry');
|
2554 | } else if (state.lineIndent < nodeIndent) {
|
2555 | break;
|
2556 | }
|
2557 | }
|
2558 |
|
2559 |
|
2560 |
|
2561 |
|
2562 |
|
2563 |
|
2564 | if (atExplicitKey) {
|
2565 | storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null);
|
2566 | }
|
2567 |
|
2568 |
|
2569 | if (detected) {
|
2570 | state.tag = _tag;
|
2571 | state.anchor = _anchor;
|
2572 | state.kind = 'mapping';
|
2573 | state.result = _result;
|
2574 | }
|
2575 |
|
2576 | return detected;
|
2577 | }
|
2578 |
|
2579 | function readTagProperty(state) {
|
2580 | var _position,
|
2581 | isVerbatim = false,
|
2582 | isNamed = false,
|
2583 | tagHandle,
|
2584 | tagName,
|
2585 | ch;
|
2586 |
|
2587 | ch = state.input.charCodeAt(state.position);
|
2588 |
|
2589 | if (ch !== 0x21) return false;
|
2590 |
|
2591 | if (state.tag !== null) {
|
2592 | throwError(state, 'duplication of a tag property');
|
2593 | }
|
2594 |
|
2595 | ch = state.input.charCodeAt(++state.position);
|
2596 |
|
2597 | if (ch === 0x3C) {
|
2598 | isVerbatim = true;
|
2599 | ch = state.input.charCodeAt(++state.position);
|
2600 |
|
2601 | } else if (ch === 0x21) {
|
2602 | isNamed = true;
|
2603 | tagHandle = '!!';
|
2604 | ch = state.input.charCodeAt(++state.position);
|
2605 |
|
2606 | } else {
|
2607 | tagHandle = '!';
|
2608 | }
|
2609 |
|
2610 | _position = state.position;
|
2611 |
|
2612 | if (isVerbatim) {
|
2613 | do { ch = state.input.charCodeAt(++state.position); }
|
2614 | while (ch !== 0 && ch !== 0x3E);
|
2615 |
|
2616 | if (state.position < state.length) {
|
2617 | tagName = state.input.slice(_position, state.position);
|
2618 | ch = state.input.charCodeAt(++state.position);
|
2619 | } else {
|
2620 | throwError(state, 'unexpected end of the stream within a verbatim tag');
|
2621 | }
|
2622 | } else {
|
2623 | while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
2624 |
|
2625 | if (ch === 0x21) {
|
2626 | if (!isNamed) {
|
2627 | tagHandle = state.input.slice(_position - 1, state.position + 1);
|
2628 |
|
2629 | if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
2630 | throwError(state, 'named tag handle cannot contain such characters');
|
2631 | }
|
2632 |
|
2633 | isNamed = true;
|
2634 | _position = state.position + 1;
|
2635 | } else {
|
2636 | throwError(state, 'tag suffix cannot contain exclamation marks');
|
2637 | }
|
2638 | }
|
2639 |
|
2640 | ch = state.input.charCodeAt(++state.position);
|
2641 | }
|
2642 |
|
2643 | tagName = state.input.slice(_position, state.position);
|
2644 |
|
2645 | if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
2646 | throwError(state, 'tag suffix cannot contain flow indicator characters');
|
2647 | }
|
2648 | }
|
2649 |
|
2650 | if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
2651 | throwError(state, 'tag name cannot contain such characters: ' + tagName);
|
2652 | }
|
2653 |
|
2654 | if (isVerbatim) {
|
2655 | state.tag = tagName;
|
2656 |
|
2657 | } else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
|
2658 | state.tag = state.tagMap[tagHandle] + tagName;
|
2659 |
|
2660 | } else if (tagHandle === '!') {
|
2661 | state.tag = '!' + tagName;
|
2662 |
|
2663 | } else if (tagHandle === '!!') {
|
2664 | state.tag = 'tag:yaml.org,2002:' + tagName;
|
2665 |
|
2666 | } else {
|
2667 | throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
2668 | }
|
2669 |
|
2670 | return true;
|
2671 | }
|
2672 |
|
2673 | function readAnchorProperty(state) {
|
2674 | var _position,
|
2675 | ch;
|
2676 |
|
2677 | ch = state.input.charCodeAt(state.position);
|
2678 |
|
2679 | if (ch !== 0x26) return false;
|
2680 |
|
2681 | if (state.anchor !== null) {
|
2682 | throwError(state, 'duplication of an anchor property');
|
2683 | }
|
2684 |
|
2685 | ch = state.input.charCodeAt(++state.position);
|
2686 | _position = state.position;
|
2687 |
|
2688 | while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
2689 | ch = state.input.charCodeAt(++state.position);
|
2690 | }
|
2691 |
|
2692 | if (state.position === _position) {
|
2693 | throwError(state, 'name of an anchor node must contain at least one character');
|
2694 | }
|
2695 |
|
2696 | state.anchor = state.input.slice(_position, state.position);
|
2697 | return true;
|
2698 | }
|
2699 |
|
2700 | function readAlias(state) {
|
2701 | var _position, alias,
|
2702 | ch;
|
2703 |
|
2704 | ch = state.input.charCodeAt(state.position);
|
2705 |
|
2706 | if (ch !== 0x2A) return false;
|
2707 |
|
2708 | ch = state.input.charCodeAt(++state.position);
|
2709 | _position = state.position;
|
2710 |
|
2711 | while (ch !== 0 && !is_WS_OR_EOL(ch) && !is_FLOW_INDICATOR(ch)) {
|
2712 | ch = state.input.charCodeAt(++state.position);
|
2713 | }
|
2714 |
|
2715 | if (state.position === _position) {
|
2716 | throwError(state, 'name of an alias node must contain at least one character');
|
2717 | }
|
2718 |
|
2719 | alias = state.input.slice(_position, state.position);
|
2720 |
|
2721 | if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
|
2722 | throwError(state, 'unidentified alias "' + alias + '"');
|
2723 | }
|
2724 |
|
2725 | state.result = state.anchorMap[alias];
|
2726 | skipSeparationSpace(state, true, -1);
|
2727 | return true;
|
2728 | }
|
2729 |
|
2730 | function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
2731 | var allowBlockStyles,
|
2732 | allowBlockScalars,
|
2733 | allowBlockCollections,
|
2734 | indentStatus = 1,
|
2735 | atNewLine = false,
|
2736 | hasContent = false,
|
2737 | typeIndex,
|
2738 | typeQuantity,
|
2739 | type,
|
2740 | flowIndent,
|
2741 | blockIndent;
|
2742 |
|
2743 | if (state.listener !== null) {
|
2744 | state.listener('open', state);
|
2745 | }
|
2746 |
|
2747 | state.tag = null;
|
2748 | state.anchor = null;
|
2749 | state.kind = null;
|
2750 | state.result = null;
|
2751 |
|
2752 | allowBlockStyles = allowBlockScalars = allowBlockCollections =
|
2753 | CONTEXT_BLOCK_OUT === nodeContext ||
|
2754 | CONTEXT_BLOCK_IN === nodeContext;
|
2755 |
|
2756 | if (allowToSeek) {
|
2757 | if (skipSeparationSpace(state, true, -1)) {
|
2758 | atNewLine = true;
|
2759 |
|
2760 | if (state.lineIndent > parentIndent) {
|
2761 | indentStatus = 1;
|
2762 | } else if (state.lineIndent === parentIndent) {
|
2763 | indentStatus = 0;
|
2764 | } else if (state.lineIndent < parentIndent) {
|
2765 | indentStatus = -1;
|
2766 | }
|
2767 | }
|
2768 | }
|
2769 |
|
2770 | if (indentStatus === 1) {
|
2771 | while (readTagProperty(state) || readAnchorProperty(state)) {
|
2772 | if (skipSeparationSpace(state, true, -1)) {
|
2773 | atNewLine = true;
|
2774 | allowBlockCollections = allowBlockStyles;
|
2775 |
|
2776 | if (state.lineIndent > parentIndent) {
|
2777 | indentStatus = 1;
|
2778 | } else if (state.lineIndent === parentIndent) {
|
2779 | indentStatus = 0;
|
2780 | } else if (state.lineIndent < parentIndent) {
|
2781 | indentStatus = -1;
|
2782 | }
|
2783 | } else {
|
2784 | allowBlockCollections = false;
|
2785 | }
|
2786 | }
|
2787 | }
|
2788 |
|
2789 | if (allowBlockCollections) {
|
2790 | allowBlockCollections = atNewLine || allowCompact;
|
2791 | }
|
2792 |
|
2793 | if (indentStatus === 1 || CONTEXT_BLOCK_OUT === nodeContext) {
|
2794 | if (CONTEXT_FLOW_IN === nodeContext || CONTEXT_FLOW_OUT === nodeContext) {
|
2795 | flowIndent = parentIndent;
|
2796 | } else {
|
2797 | flowIndent = parentIndent + 1;
|
2798 | }
|
2799 |
|
2800 | blockIndent = state.position - state.lineStart;
|
2801 |
|
2802 | if (indentStatus === 1) {
|
2803 | if (allowBlockCollections &&
|
2804 | (readBlockSequence(state, blockIndent) ||
|
2805 | readBlockMapping(state, blockIndent, flowIndent)) ||
|
2806 | readFlowCollection(state, flowIndent)) {
|
2807 | hasContent = true;
|
2808 | } else {
|
2809 | if ((allowBlockScalars && readBlockScalar(state, flowIndent)) ||
|
2810 | readSingleQuotedScalar(state, flowIndent) ||
|
2811 | readDoubleQuotedScalar(state, flowIndent)) {
|
2812 | hasContent = true;
|
2813 |
|
2814 | } else if (readAlias(state)) {
|
2815 | hasContent = true;
|
2816 |
|
2817 | if (state.tag !== null || state.anchor !== null) {
|
2818 | throwError(state, 'alias node should not have any properties');
|
2819 | }
|
2820 |
|
2821 | } else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
2822 | hasContent = true;
|
2823 |
|
2824 | if (state.tag === null) {
|
2825 | state.tag = '?';
|
2826 | }
|
2827 | }
|
2828 |
|
2829 | if (state.anchor !== null) {
|
2830 | state.anchorMap[state.anchor] = state.result;
|
2831 | }
|
2832 | }
|
2833 | } else if (indentStatus === 0) {
|
2834 |
|
2835 |
|
2836 | hasContent = allowBlockCollections && readBlockSequence(state, blockIndent);
|
2837 | }
|
2838 | }
|
2839 |
|
2840 | if (state.tag !== null && state.tag !== '!') {
|
2841 | if (state.tag === '?') {
|
2842 |
|
2843 |
|
2844 |
|
2845 |
|
2846 |
|
2847 |
|
2848 | if (state.result !== null && state.kind !== 'scalar') {
|
2849 | throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
|
2850 | }
|
2851 |
|
2852 | for (typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1) {
|
2853 | type = state.implicitTypes[typeIndex];
|
2854 |
|
2855 | if (type.resolve(state.result)) {
|
2856 | state.result = type.construct(state.result);
|
2857 | state.tag = type.tag;
|
2858 | if (state.anchor !== null) {
|
2859 | state.anchorMap[state.anchor] = state.result;
|
2860 | }
|
2861 | break;
|
2862 | }
|
2863 | }
|
2864 | } else if (_hasOwnProperty$1.call(state.typeMap[state.kind || 'fallback'], state.tag)) {
|
2865 | type = state.typeMap[state.kind || 'fallback'][state.tag];
|
2866 |
|
2867 | if (state.result !== null && type.kind !== state.kind) {
|
2868 | throwError(state, 'unacceptable node kind for !<' + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
|
2869 | }
|
2870 |
|
2871 | if (!type.resolve(state.result)) {
|
2872 | throwError(state, 'cannot resolve a node with !<' + state.tag + '> explicit tag');
|
2873 | } else {
|
2874 | state.result = type.construct(state.result);
|
2875 | if (state.anchor !== null) {
|
2876 | state.anchorMap[state.anchor] = state.result;
|
2877 | }
|
2878 | }
|
2879 | } else {
|
2880 | throwError(state, 'unknown tag !<' + state.tag + '>');
|
2881 | }
|
2882 | }
|
2883 |
|
2884 | if (state.listener !== null) {
|
2885 | state.listener('close', state);
|
2886 | }
|
2887 | return state.tag !== null || state.anchor !== null || hasContent;
|
2888 | }
|
2889 |
|
2890 | function readDocument(state) {
|
2891 | var documentStart = state.position,
|
2892 | _position,
|
2893 | directiveName,
|
2894 | directiveArgs,
|
2895 | hasDirectives = false,
|
2896 | ch;
|
2897 |
|
2898 | state.version = null;
|
2899 | state.checkLineBreaks = state.legacy;
|
2900 | state.tagMap = {};
|
2901 | state.anchorMap = {};
|
2902 |
|
2903 | while ((ch = state.input.charCodeAt(state.position)) !== 0) {
|
2904 | skipSeparationSpace(state, true, -1);
|
2905 |
|
2906 | ch = state.input.charCodeAt(state.position);
|
2907 |
|
2908 | if (state.lineIndent > 0 || ch !== 0x25) {
|
2909 | break;
|
2910 | }
|
2911 |
|
2912 | hasDirectives = true;
|
2913 | ch = state.input.charCodeAt(++state.position);
|
2914 | _position = state.position;
|
2915 |
|
2916 | while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
2917 | ch = state.input.charCodeAt(++state.position);
|
2918 | }
|
2919 |
|
2920 | directiveName = state.input.slice(_position, state.position);
|
2921 | directiveArgs = [];
|
2922 |
|
2923 | if (directiveName.length < 1) {
|
2924 | throwError(state, 'directive name must not be less than one character in length');
|
2925 | }
|
2926 |
|
2927 | while (ch !== 0) {
|
2928 | while (is_WHITE_SPACE(ch)) {
|
2929 | ch = state.input.charCodeAt(++state.position);
|
2930 | }
|
2931 |
|
2932 | if (ch === 0x23) {
|
2933 | do { ch = state.input.charCodeAt(++state.position); }
|
2934 | while (ch !== 0 && !is_EOL(ch));
|
2935 | break;
|
2936 | }
|
2937 |
|
2938 | if (is_EOL(ch)) break;
|
2939 |
|
2940 | _position = state.position;
|
2941 |
|
2942 | while (ch !== 0 && !is_WS_OR_EOL(ch)) {
|
2943 | ch = state.input.charCodeAt(++state.position);
|
2944 | }
|
2945 |
|
2946 | directiveArgs.push(state.input.slice(_position, state.position));
|
2947 | }
|
2948 |
|
2949 | if (ch !== 0) readLineBreak(state);
|
2950 |
|
2951 | if (_hasOwnProperty$1.call(directiveHandlers, directiveName)) {
|
2952 | directiveHandlers[directiveName](state, directiveName, directiveArgs);
|
2953 | } else {
|
2954 | throwWarning(state, 'unknown document directive "' + directiveName + '"');
|
2955 | }
|
2956 | }
|
2957 |
|
2958 | skipSeparationSpace(state, true, -1);
|
2959 |
|
2960 | if (state.lineIndent === 0 &&
|
2961 | state.input.charCodeAt(state.position) === 0x2D &&
|
2962 | state.input.charCodeAt(state.position + 1) === 0x2D &&
|
2963 | state.input.charCodeAt(state.position + 2) === 0x2D) {
|
2964 | state.position += 3;
|
2965 | skipSeparationSpace(state, true, -1);
|
2966 |
|
2967 | } else if (hasDirectives) {
|
2968 | throwError(state, 'directives end mark is expected');
|
2969 | }
|
2970 |
|
2971 | composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
2972 | skipSeparationSpace(state, true, -1);
|
2973 |
|
2974 | if (state.checkLineBreaks &&
|
2975 | PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
2976 | throwWarning(state, 'non-ASCII line breaks are interpreted as content');
|
2977 | }
|
2978 |
|
2979 | state.documents.push(state.result);
|
2980 |
|
2981 | if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
2982 |
|
2983 | if (state.input.charCodeAt(state.position) === 0x2E) {
|
2984 | state.position += 3;
|
2985 | skipSeparationSpace(state, true, -1);
|
2986 | }
|
2987 | return;
|
2988 | }
|
2989 |
|
2990 | if (state.position < (state.length - 1)) {
|
2991 | throwError(state, 'end of the stream or a document separator is expected');
|
2992 | } else {
|
2993 | return;
|
2994 | }
|
2995 | }
|
2996 |
|
2997 |
|
2998 | function loadDocuments(input, options) {
|
2999 | input = String(input);
|
3000 | options = options || {};
|
3001 |
|
3002 | if (input.length !== 0) {
|
3003 |
|
3004 |
|
3005 | if (input.charCodeAt(input.length - 1) !== 0x0A &&
|
3006 | input.charCodeAt(input.length - 1) !== 0x0D) {
|
3007 | input += '\n';
|
3008 | }
|
3009 |
|
3010 |
|
3011 | if (input.charCodeAt(0) === 0xFEFF) {
|
3012 | input = input.slice(1);
|
3013 | }
|
3014 | }
|
3015 |
|
3016 | var state = new State$1(input, options);
|
3017 |
|
3018 | var nullpos = input.indexOf('\0');
|
3019 |
|
3020 | if (nullpos !== -1) {
|
3021 | state.position = nullpos;
|
3022 | throwError(state, 'null byte is not allowed in input');
|
3023 | }
|
3024 |
|
3025 |
|
3026 | state.input += '\0';
|
3027 |
|
3028 | while (state.input.charCodeAt(state.position) === 0x20) {
|
3029 | state.lineIndent += 1;
|
3030 | state.position += 1;
|
3031 | }
|
3032 |
|
3033 | while (state.position < (state.length - 1)) {
|
3034 | readDocument(state);
|
3035 | }
|
3036 |
|
3037 | return state.documents;
|
3038 | }
|
3039 |
|
3040 |
|
3041 | function loadAll(input, iterator, options) {
|
3042 | if (iterator !== null && typeof iterator === 'object' && typeof options === 'undefined') {
|
3043 | options = iterator;
|
3044 | iterator = null;
|
3045 | }
|
3046 |
|
3047 | var documents = loadDocuments(input, options);
|
3048 |
|
3049 | if (typeof iterator !== 'function') {
|
3050 | return documents;
|
3051 | }
|
3052 |
|
3053 | for (var index = 0, length = documents.length; index < length; index += 1) {
|
3054 | iterator(documents[index]);
|
3055 | }
|
3056 | }
|
3057 |
|
3058 |
|
3059 | function load(input, options) {
|
3060 | var documents = loadDocuments(input, options);
|
3061 |
|
3062 | if (documents.length === 0) {
|
3063 |
|
3064 | return undefined;
|
3065 | } else if (documents.length === 1) {
|
3066 | return documents[0];
|
3067 | }
|
3068 | throw new YAMLException$1('expected a single document in the stream, but found more');
|
3069 | }
|
3070 |
|
3071 |
|
3072 | function safeLoadAll(input, iterator, options) {
|
3073 | if (typeof iterator === 'object' && iterator !== null && typeof options === 'undefined') {
|
3074 | options = iterator;
|
3075 | iterator = null;
|
3076 | }
|
3077 |
|
3078 | return loadAll(input, iterator, common$1.extend({ schema: DEFAULT_SAFE_SCHEMA$1 }, options));
|
3079 | }
|
3080 |
|
3081 |
|
3082 | function safeLoad(input, options) {
|
3083 | return load(input, common$1.extend({ schema: DEFAULT_SAFE_SCHEMA$1 }, options));
|
3084 | }
|
3085 |
|
3086 |
|
3087 | loader$1.loadAll = loadAll;
|
3088 | loader$1.load = load;
|
3089 | loader$1.safeLoadAll = safeLoadAll;
|
3090 | loader$1.safeLoad = safeLoad;
|
3091 |
|
3092 | var dumper$1 = {};
|
3093 |
|
3094 |
|
3095 |
|
3096 | var common = common$6;
|
3097 | var YAMLException = exception;
|
3098 | var DEFAULT_FULL_SCHEMA = default_full;
|
3099 | var DEFAULT_SAFE_SCHEMA = default_safe;
|
3100 |
|
3101 | var _toString = Object.prototype.toString;
|
3102 | var _hasOwnProperty = Object.prototype.hasOwnProperty;
|
3103 |
|
3104 | var CHAR_TAB = 0x09;
|
3105 | var CHAR_LINE_FEED = 0x0A;
|
3106 | var CHAR_CARRIAGE_RETURN = 0x0D;
|
3107 | var CHAR_SPACE = 0x20;
|
3108 | var CHAR_EXCLAMATION = 0x21;
|
3109 | var CHAR_DOUBLE_QUOTE = 0x22;
|
3110 | var CHAR_SHARP = 0x23;
|
3111 | var CHAR_PERCENT = 0x25;
|
3112 | var CHAR_AMPERSAND = 0x26;
|
3113 | var CHAR_SINGLE_QUOTE = 0x27;
|
3114 | var CHAR_ASTERISK = 0x2A;
|
3115 | var CHAR_COMMA = 0x2C;
|
3116 | var CHAR_MINUS = 0x2D;
|
3117 | var CHAR_COLON = 0x3A;
|
3118 | var CHAR_EQUALS = 0x3D;
|
3119 | var CHAR_GREATER_THAN = 0x3E;
|
3120 | var CHAR_QUESTION = 0x3F;
|
3121 | var CHAR_COMMERCIAL_AT = 0x40;
|
3122 | var CHAR_LEFT_SQUARE_BRACKET = 0x5B;
|
3123 | var CHAR_RIGHT_SQUARE_BRACKET = 0x5D;
|
3124 | var CHAR_GRAVE_ACCENT = 0x60;
|
3125 | var CHAR_LEFT_CURLY_BRACKET = 0x7B;
|
3126 | var CHAR_VERTICAL_LINE = 0x7C;
|
3127 | var CHAR_RIGHT_CURLY_BRACKET = 0x7D;
|
3128 |
|
3129 | var ESCAPE_SEQUENCES = {};
|
3130 |
|
3131 | ESCAPE_SEQUENCES[0x00] = '\\0';
|
3132 | ESCAPE_SEQUENCES[0x07] = '\\a';
|
3133 | ESCAPE_SEQUENCES[0x08] = '\\b';
|
3134 | ESCAPE_SEQUENCES[0x09] = '\\t';
|
3135 | ESCAPE_SEQUENCES[0x0A] = '\\n';
|
3136 | ESCAPE_SEQUENCES[0x0B] = '\\v';
|
3137 | ESCAPE_SEQUENCES[0x0C] = '\\f';
|
3138 | ESCAPE_SEQUENCES[0x0D] = '\\r';
|
3139 | ESCAPE_SEQUENCES[0x1B] = '\\e';
|
3140 | ESCAPE_SEQUENCES[0x22] = '\\"';
|
3141 | ESCAPE_SEQUENCES[0x5C] = '\\\\';
|
3142 | ESCAPE_SEQUENCES[0x85] = '\\N';
|
3143 | ESCAPE_SEQUENCES[0xA0] = '\\_';
|
3144 | ESCAPE_SEQUENCES[0x2028] = '\\L';
|
3145 | ESCAPE_SEQUENCES[0x2029] = '\\P';
|
3146 |
|
3147 | var DEPRECATED_BOOLEANS_SYNTAX = [
|
3148 | 'y', 'Y', 'yes', 'Yes', 'YES', 'on', 'On', 'ON',
|
3149 | 'n', 'N', 'no', 'No', 'NO', 'off', 'Off', 'OFF'
|
3150 | ];
|
3151 |
|
3152 | function compileStyleMap(schema, map) {
|
3153 | var result, keys, index, length, tag, style, type;
|
3154 |
|
3155 | if (map === null) return {};
|
3156 |
|
3157 | result = {};
|
3158 | keys = Object.keys(map);
|
3159 |
|
3160 | for (index = 0, length = keys.length; index < length; index += 1) {
|
3161 | tag = keys[index];
|
3162 | style = String(map[tag]);
|
3163 |
|
3164 | if (tag.slice(0, 2) === '!!') {
|
3165 | tag = 'tag:yaml.org,2002:' + tag.slice(2);
|
3166 | }
|
3167 | type = schema.compiledTypeMap['fallback'][tag];
|
3168 |
|
3169 | if (type && _hasOwnProperty.call(type.styleAliases, style)) {
|
3170 | style = type.styleAliases[style];
|
3171 | }
|
3172 |
|
3173 | result[tag] = style;
|
3174 | }
|
3175 |
|
3176 | return result;
|
3177 | }
|
3178 |
|
3179 | function encodeHex(character) {
|
3180 | var string, handle, length;
|
3181 |
|
3182 | string = character.toString(16).toUpperCase();
|
3183 |
|
3184 | if (character <= 0xFF) {
|
3185 | handle = 'x';
|
3186 | length = 2;
|
3187 | } else if (character <= 0xFFFF) {
|
3188 | handle = 'u';
|
3189 | length = 4;
|
3190 | } else if (character <= 0xFFFFFFFF) {
|
3191 | handle = 'U';
|
3192 | length = 8;
|
3193 | } else {
|
3194 | throw new YAMLException('code point within a string may not be greater than 0xFFFFFFFF');
|
3195 | }
|
3196 |
|
3197 | return '\\' + handle + common.repeat('0', length - string.length) + string;
|
3198 | }
|
3199 |
|
3200 | function State(options) {
|
3201 | this.schema = options['schema'] || DEFAULT_FULL_SCHEMA;
|
3202 | this.indent = Math.max(1, (options['indent'] || 2));
|
3203 | this.noArrayIndent = options['noArrayIndent'] || false;
|
3204 | this.skipInvalid = options['skipInvalid'] || false;
|
3205 | this.flowLevel = (common.isNothing(options['flowLevel']) ? -1 : options['flowLevel']);
|
3206 | this.styleMap = compileStyleMap(this.schema, options['styles'] || null);
|
3207 | this.sortKeys = options['sortKeys'] || false;
|
3208 | this.lineWidth = options['lineWidth'] || 80;
|
3209 | this.noRefs = options['noRefs'] || false;
|
3210 | this.noCompatMode = options['noCompatMode'] || false;
|
3211 | this.condenseFlow = options['condenseFlow'] || false;
|
3212 |
|
3213 | this.implicitTypes = this.schema.compiledImplicit;
|
3214 | this.explicitTypes = this.schema.compiledExplicit;
|
3215 |
|
3216 | this.tag = null;
|
3217 | this.result = '';
|
3218 |
|
3219 | this.duplicates = [];
|
3220 | this.usedDuplicates = null;
|
3221 | }
|
3222 |
|
3223 |
|
3224 | function indentString(string, spaces) {
|
3225 | var ind = common.repeat(' ', spaces),
|
3226 | position = 0,
|
3227 | next = -1,
|
3228 | result = '',
|
3229 | line,
|
3230 | length = string.length;
|
3231 |
|
3232 | while (position < length) {
|
3233 | next = string.indexOf('\n', position);
|
3234 | if (next === -1) {
|
3235 | line = string.slice(position);
|
3236 | position = length;
|
3237 | } else {
|
3238 | line = string.slice(position, next + 1);
|
3239 | position = next + 1;
|
3240 | }
|
3241 |
|
3242 | if (line.length && line !== '\n') result += ind;
|
3243 |
|
3244 | result += line;
|
3245 | }
|
3246 |
|
3247 | return result;
|
3248 | }
|
3249 |
|
3250 | function generateNextLine(state, level) {
|
3251 | return '\n' + common.repeat(' ', state.indent * level);
|
3252 | }
|
3253 |
|
3254 | function testImplicitResolving(state, str) {
|
3255 | var index, length, type;
|
3256 |
|
3257 | for (index = 0, length = state.implicitTypes.length; index < length; index += 1) {
|
3258 | type = state.implicitTypes[index];
|
3259 |
|
3260 | if (type.resolve(str)) {
|
3261 | return true;
|
3262 | }
|
3263 | }
|
3264 |
|
3265 | return false;
|
3266 | }
|
3267 |
|
3268 |
|
3269 | function isWhitespace(c) {
|
3270 | return c === CHAR_SPACE || c === CHAR_TAB;
|
3271 | }
|
3272 |
|
3273 |
|
3274 |
|
3275 |
|
3276 |
|
3277 | function isPrintable(c) {
|
3278 | return (0x00020 <= c && c <= 0x00007E)
|
3279 | || ((0x000A1 <= c && c <= 0x00D7FF) && c !== 0x2028 && c !== 0x2029)
|
3280 | || ((0x0E000 <= c && c <= 0x00FFFD) && c !== 0xFEFF )
|
3281 | || (0x10000 <= c && c <= 0x10FFFF);
|
3282 | }
|
3283 |
|
3284 |
|
3285 |
|
3286 |
|
3287 |
|
3288 |
|
3289 |
|
3290 | function isNsChar(c) {
|
3291 | return isPrintable(c) && !isWhitespace(c)
|
3292 |
|
3293 | && c !== 0xFEFF
|
3294 |
|
3295 | && c !== CHAR_CARRIAGE_RETURN
|
3296 | && c !== CHAR_LINE_FEED;
|
3297 | }
|
3298 |
|
3299 |
|
3300 | function isPlainSafe(c, prev) {
|
3301 |
|
3302 |
|
3303 | return isPrintable(c) && c !== 0xFEFF
|
3304 |
|
3305 | && c !== CHAR_COMMA
|
3306 | && c !== CHAR_LEFT_SQUARE_BRACKET
|
3307 | && c !== CHAR_RIGHT_SQUARE_BRACKET
|
3308 | && c !== CHAR_LEFT_CURLY_BRACKET
|
3309 | && c !== CHAR_RIGHT_CURLY_BRACKET
|
3310 |
|
3311 |
|
3312 | && c !== CHAR_COLON
|
3313 | && ((c !== CHAR_SHARP) || (prev && isNsChar(prev)));
|
3314 | }
|
3315 |
|
3316 |
|
3317 | function isPlainSafeFirst(c) {
|
3318 |
|
3319 |
|
3320 | return isPrintable(c) && c !== 0xFEFF
|
3321 | && !isWhitespace(c)
|
3322 |
|
3323 |
|
3324 | && c !== CHAR_MINUS
|
3325 | && c !== CHAR_QUESTION
|
3326 | && c !== CHAR_COLON
|
3327 | && c !== CHAR_COMMA
|
3328 | && c !== CHAR_LEFT_SQUARE_BRACKET
|
3329 | && c !== CHAR_RIGHT_SQUARE_BRACKET
|
3330 | && c !== CHAR_LEFT_CURLY_BRACKET
|
3331 | && c !== CHAR_RIGHT_CURLY_BRACKET
|
3332 |
|
3333 | && c !== CHAR_SHARP
|
3334 | && c !== CHAR_AMPERSAND
|
3335 | && c !== CHAR_ASTERISK
|
3336 | && c !== CHAR_EXCLAMATION
|
3337 | && c !== CHAR_VERTICAL_LINE
|
3338 | && c !== CHAR_EQUALS
|
3339 | && c !== CHAR_GREATER_THAN
|
3340 | && c !== CHAR_SINGLE_QUOTE
|
3341 | && c !== CHAR_DOUBLE_QUOTE
|
3342 |
|
3343 | && c !== CHAR_PERCENT
|
3344 | && c !== CHAR_COMMERCIAL_AT
|
3345 | && c !== CHAR_GRAVE_ACCENT;
|
3346 | }
|
3347 |
|
3348 |
|
3349 | function needIndentIndicator(string) {
|
3350 | var leadingSpaceRe = /^\n* /;
|
3351 | return leadingSpaceRe.test(string);
|
3352 | }
|
3353 |
|
3354 | var STYLE_PLAIN = 1,
|
3355 | STYLE_SINGLE = 2,
|
3356 | STYLE_LITERAL = 3,
|
3357 | STYLE_FOLDED = 4,
|
3358 | STYLE_DOUBLE = 5;
|
3359 |
|
3360 |
|
3361 |
|
3362 |
|
3363 |
|
3364 |
|
3365 |
|
3366 |
|
3367 | function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType) {
|
3368 | var i;
|
3369 | var char, prev_char;
|
3370 | var hasLineBreak = false;
|
3371 | var hasFoldableLine = false;
|
3372 | var shouldTrackWidth = lineWidth !== -1;
|
3373 | var previousLineBreak = -1;
|
3374 | var plain = isPlainSafeFirst(string.charCodeAt(0))
|
3375 | && !isWhitespace(string.charCodeAt(string.length - 1));
|
3376 |
|
3377 | if (singleLineOnly) {
|
3378 |
|
3379 |
|
3380 | for (i = 0; i < string.length; i++) {
|
3381 | char = string.charCodeAt(i);
|
3382 | if (!isPrintable(char)) {
|
3383 | return STYLE_DOUBLE;
|
3384 | }
|
3385 | prev_char = i > 0 ? string.charCodeAt(i - 1) : null;
|
3386 | plain = plain && isPlainSafe(char, prev_char);
|
3387 | }
|
3388 | } else {
|
3389 |
|
3390 | for (i = 0; i < string.length; i++) {
|
3391 | char = string.charCodeAt(i);
|
3392 | if (char === CHAR_LINE_FEED) {
|
3393 | hasLineBreak = true;
|
3394 |
|
3395 | if (shouldTrackWidth) {
|
3396 | hasFoldableLine = hasFoldableLine ||
|
3397 |
|
3398 | (i - previousLineBreak - 1 > lineWidth &&
|
3399 | string[previousLineBreak + 1] !== ' ');
|
3400 | previousLineBreak = i;
|
3401 | }
|
3402 | } else if (!isPrintable(char)) {
|
3403 | return STYLE_DOUBLE;
|
3404 | }
|
3405 | prev_char = i > 0 ? string.charCodeAt(i - 1) : null;
|
3406 | plain = plain && isPlainSafe(char, prev_char);
|
3407 | }
|
3408 |
|
3409 | hasFoldableLine = hasFoldableLine || (shouldTrackWidth &&
|
3410 | (i - previousLineBreak - 1 > lineWidth &&
|
3411 | string[previousLineBreak + 1] !== ' '));
|
3412 | }
|
3413 |
|
3414 |
|
3415 |
|
3416 | if (!hasLineBreak && !hasFoldableLine) {
|
3417 |
|
3418 |
|
3419 | return plain && !testAmbiguousType(string)
|
3420 | ? STYLE_PLAIN : STYLE_SINGLE;
|
3421 | }
|
3422 |
|
3423 | if (indentPerLevel > 9 && needIndentIndicator(string)) {
|
3424 | return STYLE_DOUBLE;
|
3425 | }
|
3426 |
|
3427 |
|
3428 | return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
|
3429 | }
|
3430 |
|
3431 |
|
3432 |
|
3433 |
|
3434 |
|
3435 |
|
3436 |
|
3437 | function writeScalar(state, string, level, iskey) {
|
3438 | state.dump = (function () {
|
3439 | if (string.length === 0) {
|
3440 | return "''";
|
3441 | }
|
3442 | if (!state.noCompatMode &&
|
3443 | DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1) {
|
3444 | return "'" + string + "'";
|
3445 | }
|
3446 |
|
3447 | var indent = state.indent * Math.max(1, level);
|
3448 |
|
3449 |
|
3450 |
|
3451 |
|
3452 |
|
3453 |
|
3454 |
|
3455 | var lineWidth = state.lineWidth === -1
|
3456 | ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
|
3457 |
|
3458 |
|
3459 | var singleLineOnly = iskey
|
3460 |
|
3461 | || (state.flowLevel > -1 && level >= state.flowLevel);
|
3462 | function testAmbiguity(string) {
|
3463 | return testImplicitResolving(state, string);
|
3464 | }
|
3465 |
|
3466 | switch (chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity)) {
|
3467 | case STYLE_PLAIN:
|
3468 | return string;
|
3469 | case STYLE_SINGLE:
|
3470 | return "'" + string.replace(/'/g, "''") + "'";
|
3471 | case STYLE_LITERAL:
|
3472 | return '|' + blockHeader(string, state.indent)
|
3473 | + dropEndingNewline(indentString(string, indent));
|
3474 | case STYLE_FOLDED:
|
3475 | return '>' + blockHeader(string, state.indent)
|
3476 | + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
3477 | case STYLE_DOUBLE:
|
3478 | return '"' + escapeString(string) + '"';
|
3479 | default:
|
3480 | throw new YAMLException('impossible error: invalid scalar style');
|
3481 | }
|
3482 | }());
|
3483 | }
|
3484 |
|
3485 |
|
3486 | function blockHeader(string, indentPerLevel) {
|
3487 | var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : '';
|
3488 |
|
3489 |
|
3490 | var clip = string[string.length - 1] === '\n';
|
3491 | var keep = clip && (string[string.length - 2] === '\n' || string === '\n');
|
3492 | var chomp = keep ? '+' : (clip ? '' : '-');
|
3493 |
|
3494 | return indentIndicator + chomp + '\n';
|
3495 | }
|
3496 |
|
3497 |
|
3498 | function dropEndingNewline(string) {
|
3499 | return string[string.length - 1] === '\n' ? string.slice(0, -1) : string;
|
3500 | }
|
3501 |
|
3502 |
|
3503 |
|
3504 | function foldString(string, width) {
|
3505 |
|
3506 |
|
3507 |
|
3508 |
|
3509 | var lineRe = /(\n+)([^\n]*)/g;
|
3510 |
|
3511 |
|
3512 | var result = (function () {
|
3513 | var nextLF = string.indexOf('\n');
|
3514 | nextLF = nextLF !== -1 ? nextLF : string.length;
|
3515 | lineRe.lastIndex = nextLF;
|
3516 | return foldLine(string.slice(0, nextLF), width);
|
3517 | }());
|
3518 |
|
3519 | var prevMoreIndented = string[0] === '\n' || string[0] === ' ';
|
3520 | var moreIndented;
|
3521 |
|
3522 |
|
3523 | var match;
|
3524 | while ((match = lineRe.exec(string))) {
|
3525 | var prefix = match[1], line = match[2];
|
3526 | moreIndented = (line[0] === ' ');
|
3527 | result += prefix
|
3528 | + (!prevMoreIndented && !moreIndented && line !== ''
|
3529 | ? '\n' : '')
|
3530 | + foldLine(line, width);
|
3531 | prevMoreIndented = moreIndented;
|
3532 | }
|
3533 |
|
3534 | return result;
|
3535 | }
|
3536 |
|
3537 |
|
3538 |
|
3539 |
|
3540 |
|
3541 | function foldLine(line, width) {
|
3542 | if (line === '' || line[0] === ' ') return line;
|
3543 |
|
3544 |
|
3545 | var breakRe = / [^ ]/g;
|
3546 | var match;
|
3547 |
|
3548 | var start = 0, end, curr = 0, next = 0;
|
3549 | var result = '';
|
3550 |
|
3551 |
|
3552 |
|
3553 |
|
3554 |
|
3555 | while ((match = breakRe.exec(line))) {
|
3556 | next = match.index;
|
3557 |
|
3558 | if (next - start > width) {
|
3559 | end = (curr > start) ? curr : next;
|
3560 | result += '\n' + line.slice(start, end);
|
3561 |
|
3562 | start = end + 1;
|
3563 | }
|
3564 | curr = next;
|
3565 | }
|
3566 |
|
3567 |
|
3568 |
|
3569 | result += '\n';
|
3570 |
|
3571 | if (line.length - start > width && curr > start) {
|
3572 | result += line.slice(start, curr) + '\n' + line.slice(curr + 1);
|
3573 | } else {
|
3574 | result += line.slice(start);
|
3575 | }
|
3576 |
|
3577 | return result.slice(1);
|
3578 | }
|
3579 |
|
3580 |
|
3581 | function escapeString(string) {
|
3582 | var result = '';
|
3583 | var char, nextChar;
|
3584 | var escapeSeq;
|
3585 |
|
3586 | for (var i = 0; i < string.length; i++) {
|
3587 | char = string.charCodeAt(i);
|
3588 |
|
3589 | if (char >= 0xD800 && char <= 0xDBFF) {
|
3590 | nextChar = string.charCodeAt(i + 1);
|
3591 | if (nextChar >= 0xDC00 && nextChar <= 0xDFFF) {
|
3592 |
|
3593 | result += encodeHex((char - 0xD800) * 0x400 + nextChar - 0xDC00 + 0x10000);
|
3594 |
|
3595 | i++; continue;
|
3596 | }
|
3597 | }
|
3598 | escapeSeq = ESCAPE_SEQUENCES[char];
|
3599 | result += !escapeSeq && isPrintable(char)
|
3600 | ? string[i]
|
3601 | : escapeSeq || encodeHex(char);
|
3602 | }
|
3603 |
|
3604 | return result;
|
3605 | }
|
3606 |
|
3607 | function writeFlowSequence(state, level, object) {
|
3608 | var _result = '',
|
3609 | _tag = state.tag,
|
3610 | index,
|
3611 | length;
|
3612 |
|
3613 | for (index = 0, length = object.length; index < length; index += 1) {
|
3614 |
|
3615 | if (writeNode(state, level, object[index], false, false)) {
|
3616 | if (index !== 0) _result += ',' + (!state.condenseFlow ? ' ' : '');
|
3617 | _result += state.dump;
|
3618 | }
|
3619 | }
|
3620 |
|
3621 | state.tag = _tag;
|
3622 | state.dump = '[' + _result + ']';
|
3623 | }
|
3624 |
|
3625 | function writeBlockSequence(state, level, object, compact) {
|
3626 | var _result = '',
|
3627 | _tag = state.tag,
|
3628 | index,
|
3629 | length;
|
3630 |
|
3631 | for (index = 0, length = object.length; index < length; index += 1) {
|
3632 |
|
3633 | if (writeNode(state, level + 1, object[index], true, true)) {
|
3634 | if (!compact || index !== 0) {
|
3635 | _result += generateNextLine(state, level);
|
3636 | }
|
3637 |
|
3638 | if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
3639 | _result += '-';
|
3640 | } else {
|
3641 | _result += '- ';
|
3642 | }
|
3643 |
|
3644 | _result += state.dump;
|
3645 | }
|
3646 | }
|
3647 |
|
3648 | state.tag = _tag;
|
3649 | state.dump = _result || '[]';
|
3650 | }
|
3651 |
|
3652 | function writeFlowMapping(state, level, object) {
|
3653 | var _result = '',
|
3654 | _tag = state.tag,
|
3655 | objectKeyList = Object.keys(object),
|
3656 | index,
|
3657 | length,
|
3658 | objectKey,
|
3659 | objectValue,
|
3660 | pairBuffer;
|
3661 |
|
3662 | for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
3663 |
|
3664 | pairBuffer = '';
|
3665 | if (index !== 0) pairBuffer += ', ';
|
3666 |
|
3667 | if (state.condenseFlow) pairBuffer += '"';
|
3668 |
|
3669 | objectKey = objectKeyList[index];
|
3670 | objectValue = object[objectKey];
|
3671 |
|
3672 | if (!writeNode(state, level, objectKey, false, false)) {
|
3673 | continue;
|
3674 | }
|
3675 |
|
3676 | if (state.dump.length > 1024) pairBuffer += '? ';
|
3677 |
|
3678 | pairBuffer += state.dump + (state.condenseFlow ? '"' : '') + ':' + (state.condenseFlow ? '' : ' ');
|
3679 |
|
3680 | if (!writeNode(state, level, objectValue, false, false)) {
|
3681 | continue;
|
3682 | }
|
3683 |
|
3684 | pairBuffer += state.dump;
|
3685 |
|
3686 |
|
3687 | _result += pairBuffer;
|
3688 | }
|
3689 |
|
3690 | state.tag = _tag;
|
3691 | state.dump = '{' + _result + '}';
|
3692 | }
|
3693 |
|
3694 | function writeBlockMapping(state, level, object, compact) {
|
3695 | var _result = '',
|
3696 | _tag = state.tag,
|
3697 | objectKeyList = Object.keys(object),
|
3698 | index,
|
3699 | length,
|
3700 | objectKey,
|
3701 | objectValue,
|
3702 | explicitPair,
|
3703 | pairBuffer;
|
3704 |
|
3705 |
|
3706 | if (state.sortKeys === true) {
|
3707 |
|
3708 | objectKeyList.sort();
|
3709 | } else if (typeof state.sortKeys === 'function') {
|
3710 |
|
3711 | objectKeyList.sort(state.sortKeys);
|
3712 | } else if (state.sortKeys) {
|
3713 |
|
3714 | throw new YAMLException('sortKeys must be a boolean or a function');
|
3715 | }
|
3716 |
|
3717 | for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
3718 | pairBuffer = '';
|
3719 |
|
3720 | if (!compact || index !== 0) {
|
3721 | pairBuffer += generateNextLine(state, level);
|
3722 | }
|
3723 |
|
3724 | objectKey = objectKeyList[index];
|
3725 | objectValue = object[objectKey];
|
3726 |
|
3727 | if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
3728 | continue;
|
3729 | }
|
3730 |
|
3731 | explicitPair = (state.tag !== null && state.tag !== '?') ||
|
3732 | (state.dump && state.dump.length > 1024);
|
3733 |
|
3734 | if (explicitPair) {
|
3735 | if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
3736 | pairBuffer += '?';
|
3737 | } else {
|
3738 | pairBuffer += '? ';
|
3739 | }
|
3740 | }
|
3741 |
|
3742 | pairBuffer += state.dump;
|
3743 |
|
3744 | if (explicitPair) {
|
3745 | pairBuffer += generateNextLine(state, level);
|
3746 | }
|
3747 |
|
3748 | if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
|
3749 | continue;
|
3750 | }
|
3751 |
|
3752 | if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
3753 | pairBuffer += ':';
|
3754 | } else {
|
3755 | pairBuffer += ': ';
|
3756 | }
|
3757 |
|
3758 | pairBuffer += state.dump;
|
3759 |
|
3760 |
|
3761 | _result += pairBuffer;
|
3762 | }
|
3763 |
|
3764 | state.tag = _tag;
|
3765 | state.dump = _result || '{}';
|
3766 | }
|
3767 |
|
3768 | function detectType(state, object, explicit) {
|
3769 | var _result, typeList, index, length, type, style;
|
3770 |
|
3771 | typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
3772 |
|
3773 | for (index = 0, length = typeList.length; index < length; index += 1) {
|
3774 | type = typeList[index];
|
3775 |
|
3776 | if ((type.instanceOf || type.predicate) &&
|
3777 | (!type.instanceOf || ((typeof object === 'object') && (object instanceof type.instanceOf))) &&
|
3778 | (!type.predicate || type.predicate(object))) {
|
3779 |
|
3780 | state.tag = explicit ? type.tag : '?';
|
3781 |
|
3782 | if (type.represent) {
|
3783 | style = state.styleMap[type.tag] || type.defaultStyle;
|
3784 |
|
3785 | if (_toString.call(type.represent) === '[object Function]') {
|
3786 | _result = type.represent(object, style);
|
3787 | } else if (_hasOwnProperty.call(type.represent, style)) {
|
3788 | _result = type.represent[style](object, style);
|
3789 | } else {
|
3790 | throw new YAMLException('!<' + type.tag + '> tag resolver accepts not "' + style + '" style');
|
3791 | }
|
3792 |
|
3793 | state.dump = _result;
|
3794 | }
|
3795 |
|
3796 | return true;
|
3797 | }
|
3798 | }
|
3799 |
|
3800 | return false;
|
3801 | }
|
3802 |
|
3803 |
|
3804 |
|
3805 |
|
3806 | function writeNode(state, level, object, block, compact, iskey) {
|
3807 | state.tag = null;
|
3808 | state.dump = object;
|
3809 |
|
3810 | if (!detectType(state, object, false)) {
|
3811 | detectType(state, object, true);
|
3812 | }
|
3813 |
|
3814 | var type = _toString.call(state.dump);
|
3815 |
|
3816 | if (block) {
|
3817 | block = (state.flowLevel < 0 || state.flowLevel > level);
|
3818 | }
|
3819 |
|
3820 | var objectOrArray = type === '[object Object]' || type === '[object Array]',
|
3821 | duplicateIndex,
|
3822 | duplicate;
|
3823 |
|
3824 | if (objectOrArray) {
|
3825 | duplicateIndex = state.duplicates.indexOf(object);
|
3826 | duplicate = duplicateIndex !== -1;
|
3827 | }
|
3828 |
|
3829 | if ((state.tag !== null && state.tag !== '?') || duplicate || (state.indent !== 2 && level > 0)) {
|
3830 | compact = false;
|
3831 | }
|
3832 |
|
3833 | if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
3834 | state.dump = '*ref_' + duplicateIndex;
|
3835 | } else {
|
3836 | if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
3837 | state.usedDuplicates[duplicateIndex] = true;
|
3838 | }
|
3839 | if (type === '[object Object]') {
|
3840 | if (block && (Object.keys(state.dump).length !== 0)) {
|
3841 | writeBlockMapping(state, level, state.dump, compact);
|
3842 | if (duplicate) {
|
3843 | state.dump = '&ref_' + duplicateIndex + state.dump;
|
3844 | }
|
3845 | } else {
|
3846 | writeFlowMapping(state, level, state.dump);
|
3847 | if (duplicate) {
|
3848 | state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
|
3849 | }
|
3850 | }
|
3851 | } else if (type === '[object Array]') {
|
3852 | var arrayLevel = (state.noArrayIndent && (level > 0)) ? level - 1 : level;
|
3853 | if (block && (state.dump.length !== 0)) {
|
3854 | writeBlockSequence(state, arrayLevel, state.dump, compact);
|
3855 | if (duplicate) {
|
3856 | state.dump = '&ref_' + duplicateIndex + state.dump;
|
3857 | }
|
3858 | } else {
|
3859 | writeFlowSequence(state, arrayLevel, state.dump);
|
3860 | if (duplicate) {
|
3861 | state.dump = '&ref_' + duplicateIndex + ' ' + state.dump;
|
3862 | }
|
3863 | }
|
3864 | } else if (type === '[object String]') {
|
3865 | if (state.tag !== '?') {
|
3866 | writeScalar(state, state.dump, level, iskey);
|
3867 | }
|
3868 | } else {
|
3869 | if (state.skipInvalid) return false;
|
3870 | throw new YAMLException('unacceptable kind of an object to dump ' + type);
|
3871 | }
|
3872 |
|
3873 | if (state.tag !== null && state.tag !== '?') {
|
3874 | state.dump = '!<' + state.tag + '> ' + state.dump;
|
3875 | }
|
3876 | }
|
3877 |
|
3878 | return true;
|
3879 | }
|
3880 |
|
3881 | function getDuplicateReferences(object, state) {
|
3882 | var objects = [],
|
3883 | duplicatesIndexes = [],
|
3884 | index,
|
3885 | length;
|
3886 |
|
3887 | inspectNode(object, objects, duplicatesIndexes);
|
3888 |
|
3889 | for (index = 0, length = duplicatesIndexes.length; index < length; index += 1) {
|
3890 | state.duplicates.push(objects[duplicatesIndexes[index]]);
|
3891 | }
|
3892 | state.usedDuplicates = new Array(length);
|
3893 | }
|
3894 |
|
3895 | function inspectNode(object, objects, duplicatesIndexes) {
|
3896 | var objectKeyList,
|
3897 | index,
|
3898 | length;
|
3899 |
|
3900 | if (object !== null && typeof object === 'object') {
|
3901 | index = objects.indexOf(object);
|
3902 | if (index !== -1) {
|
3903 | if (duplicatesIndexes.indexOf(index) === -1) {
|
3904 | duplicatesIndexes.push(index);
|
3905 | }
|
3906 | } else {
|
3907 | objects.push(object);
|
3908 |
|
3909 | if (Array.isArray(object)) {
|
3910 | for (index = 0, length = object.length; index < length; index += 1) {
|
3911 | inspectNode(object[index], objects, duplicatesIndexes);
|
3912 | }
|
3913 | } else {
|
3914 | objectKeyList = Object.keys(object);
|
3915 |
|
3916 | for (index = 0, length = objectKeyList.length; index < length; index += 1) {
|
3917 | inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
|
3918 | }
|
3919 | }
|
3920 | }
|
3921 | }
|
3922 | }
|
3923 |
|
3924 | function dump(input, options) {
|
3925 | options = options || {};
|
3926 |
|
3927 | var state = new State(options);
|
3928 |
|
3929 | if (!state.noRefs) getDuplicateReferences(input, state);
|
3930 |
|
3931 | if (writeNode(state, 0, input, true, true)) return state.dump + '\n';
|
3932 |
|
3933 | return '';
|
3934 | }
|
3935 |
|
3936 | function safeDump(input, options) {
|
3937 | return dump(input, common.extend({ schema: DEFAULT_SAFE_SCHEMA }, options));
|
3938 | }
|
3939 |
|
3940 | dumper$1.dump = dump;
|
3941 | dumper$1.safeDump = safeDump;
|
3942 |
|
3943 | var loader = loader$1;
|
3944 | var dumper = dumper$1;
|
3945 |
|
3946 |
|
3947 | function deprecated(name) {
|
3948 | return function () {
|
3949 | throw new Error('Function ' + name + ' is deprecated and cannot be used.');
|
3950 | };
|
3951 | }
|
3952 |
|
3953 |
|
3954 | jsYaml$1.Type = type;
|
3955 | jsYaml$1.Schema = schema;
|
3956 | jsYaml$1.FAILSAFE_SCHEMA = failsafe;
|
3957 | jsYaml$1.JSON_SCHEMA = json;
|
3958 | jsYaml$1.CORE_SCHEMA = core;
|
3959 | jsYaml$1.DEFAULT_SAFE_SCHEMA = default_safe;
|
3960 | jsYaml$1.DEFAULT_FULL_SCHEMA = default_full;
|
3961 | jsYaml$1.load = loader.load;
|
3962 | jsYaml$1.loadAll = loader.loadAll;
|
3963 | jsYaml$1.safeLoad = loader.safeLoad;
|
3964 | jsYaml$1.safeLoadAll = loader.safeLoadAll;
|
3965 | jsYaml$1.dump = dumper.dump;
|
3966 | jsYaml$1.safeDump = dumper.safeDump;
|
3967 | jsYaml$1.YAMLException = exception;
|
3968 |
|
3969 |
|
3970 | jsYaml$1.MINIMAL_SCHEMA = failsafe;
|
3971 | jsYaml$1.SAFE_SCHEMA = default_safe;
|
3972 | jsYaml$1.DEFAULT_SCHEMA = default_full;
|
3973 |
|
3974 |
|
3975 | jsYaml$1.scan = deprecated('scan');
|
3976 | jsYaml$1.parse = deprecated('parse');
|
3977 | jsYaml$1.compose = deprecated('compose');
|
3978 | jsYaml$1.addConstructor = deprecated('addConstructor');
|
3979 |
|
3980 | var yaml$1 = jsYaml$1;
|
3981 |
|
3982 |
|
3983 | var jsYaml = yaml$1;
|
3984 |
|
3985 | var callsites$1 = () => {
|
3986 | const _ = Error.prepareStackTrace;
|
3987 | Error.prepareStackTrace = (_, stack) => stack;
|
3988 | const stack = new Error().stack.slice(1);
|
3989 | Error.prepareStackTrace = _;
|
3990 | return stack;
|
3991 | };
|
3992 |
|
3993 | const callsites = callsites$1;
|
3994 |
|
3995 | var callerCallsite$1 = () => {
|
3996 | const c = callsites();
|
3997 | let caller;
|
3998 |
|
3999 | for (let i = 0; i < c.length; i++) {
|
4000 | const hasReceiver = c[i].getTypeName() !== null;
|
4001 |
|
4002 | if (hasReceiver) {
|
4003 | caller = i;
|
4004 | break;
|
4005 | }
|
4006 | }
|
4007 |
|
4008 | return c[caller];
|
4009 | };
|
4010 |
|
4011 | const callerCallsite = callerCallsite$1;
|
4012 |
|
4013 | var callerPath$1 = () => callerCallsite().getFileName();
|
4014 |
|
4015 | const path$3 = path__default['default'];
|
4016 | const resolveFrom = require$$1__default['default'];
|
4017 | const callerPath = callerPath$1;
|
4018 |
|
4019 | var importFresh$1 = moduleId => {
|
4020 | if (typeof moduleId !== 'string') {
|
4021 | throw new TypeError('Expected a string');
|
4022 | }
|
4023 |
|
4024 | const filePath = resolveFrom(path$3.dirname(callerPath()), moduleId);
|
4025 |
|
4026 |
|
4027 | if (require.cache[filePath] && require.cache[filePath].parent) {
|
4028 | let i = require.cache[filePath].parent.children.length;
|
4029 |
|
4030 | while (i--) {
|
4031 | if (require.cache[filePath].parent.children[i].id === filePath) {
|
4032 | require.cache[filePath].parent.children.splice(i, 1);
|
4033 | }
|
4034 | }
|
4035 | }
|
4036 |
|
4037 |
|
4038 | delete require.cache[filePath];
|
4039 |
|
4040 |
|
4041 | return commonjsRequire(filePath);
|
4042 | };
|
4043 |
|
4044 | const parseJson = require$$0__default['default'];
|
4045 | const yaml = jsYaml;
|
4046 | const importFresh = importFresh$1;
|
4047 |
|
4048 | function loadJs(filepath ) {
|
4049 | const result = importFresh(filepath);
|
4050 | return result;
|
4051 | }
|
4052 |
|
4053 | function loadJson(filepath , content ) {
|
4054 | try {
|
4055 | return parseJson(content);
|
4056 | } catch (err) {
|
4057 | err.message = `JSON Error in ${filepath}:\n${err.message}`;
|
4058 | throw err;
|
4059 | }
|
4060 | }
|
4061 |
|
4062 | function loadYaml(filepath , content ) {
|
4063 | return yaml.safeLoad(content, { filename: filepath });
|
4064 | }
|
4065 |
|
4066 | var loaders$2 = {
|
4067 | loadJs,
|
4068 | loadJson,
|
4069 | loadYaml,
|
4070 | };
|
4071 |
|
4072 | const fs$2 = require$$0__default$1['default'];
|
4073 |
|
4074 |
|
4075 |
|
4076 |
|
4077 |
|
4078 | function readFile$1(filepath , options ) {
|
4079 | options = options || {};
|
4080 | const throwNotFound = options.throwNotFound || false;
|
4081 |
|
4082 | return new Promise((resolve, reject) => {
|
4083 | fs$2.readFile(filepath, 'utf8', (err, content) => {
|
4084 | if (err && err.code === 'ENOENT' && !throwNotFound) {
|
4085 | return resolve(null);
|
4086 | }
|
4087 | if (err) return reject(err);
|
4088 | resolve(content);
|
4089 | });
|
4090 | });
|
4091 | }
|
4092 |
|
4093 | readFile$1.sync = function readFileSync(
|
4094 | filepath ,
|
4095 | options
|
4096 | ) {
|
4097 | options = options || {};
|
4098 | const throwNotFound = options.throwNotFound || false;
|
4099 |
|
4100 | try {
|
4101 | return fs$2.readFileSync(filepath, 'utf8');
|
4102 | } catch (err) {
|
4103 | if (err.code === 'ENOENT' && !throwNotFound) {
|
4104 | return null;
|
4105 | }
|
4106 | throw err;
|
4107 | }
|
4108 | };
|
4109 |
|
4110 | var readFile_1 = readFile$1;
|
4111 |
|
4112 | function cacheWrapper$1 (cache , key , fn ) {
|
4113 | if (!cache) {
|
4114 | return fn();
|
4115 | }
|
4116 |
|
4117 | const cached = cache.get(key);
|
4118 | if (cached !== undefined) {
|
4119 | return cached;
|
4120 | }
|
4121 |
|
4122 | const result = fn();
|
4123 | cache.set(key, result);
|
4124 | return result;
|
4125 | }
|
4126 |
|
4127 | var cacheWrapper_1 = cacheWrapper$1;
|
4128 |
|
4129 |
|
4130 |
|
4131 |
|
4132 |
|
4133 |
|
4134 |
|
4135 |
|
4136 | var fs$1 = require$$0__default$1['default'];
|
4137 |
|
4138 |
|
4139 |
|
4140 |
|
4141 |
|
4142 | function isDirectory$1(filepath, cb) {
|
4143 | if (typeof cb !== 'function') {
|
4144 | throw new Error('expected a callback function');
|
4145 | }
|
4146 |
|
4147 | if (typeof filepath !== 'string') {
|
4148 | cb(new Error('expected filepath to be a string'));
|
4149 | return;
|
4150 | }
|
4151 |
|
4152 | fs$1.stat(filepath, function(err, stats) {
|
4153 | if (err) {
|
4154 | if (err.code === 'ENOENT') {
|
4155 | cb(null, false);
|
4156 | return;
|
4157 | }
|
4158 | cb(err);
|
4159 | return;
|
4160 | }
|
4161 | cb(null, stats.isDirectory());
|
4162 | });
|
4163 | }
|
4164 |
|
4165 |
|
4166 |
|
4167 |
|
4168 |
|
4169 | isDirectory$1.sync = function isDirectorySync(filepath) {
|
4170 | if (typeof filepath !== 'string') {
|
4171 | throw new Error('expected filepath to be a string');
|
4172 | }
|
4173 |
|
4174 | try {
|
4175 | var stat = fs$1.statSync(filepath);
|
4176 | return stat.isDirectory();
|
4177 | } catch (err) {
|
4178 | if (err.code === 'ENOENT') {
|
4179 | return false;
|
4180 | } else {
|
4181 | throw err;
|
4182 | }
|
4183 | }
|
4184 | return false;
|
4185 | };
|
4186 |
|
4187 |
|
4188 |
|
4189 |
|
4190 |
|
4191 | var isDirectory_1 = isDirectory$1;
|
4192 |
|
4193 | const path$2 = path__default['default'];
|
4194 | const isDirectory = isDirectory_1;
|
4195 |
|
4196 | function getDirectory$1(filepath ) {
|
4197 | return new Promise((resolve, reject) => {
|
4198 | return isDirectory(filepath, (err, filepathIsDirectory) => {
|
4199 | if (err) {
|
4200 | return reject(err);
|
4201 | }
|
4202 | return resolve(filepathIsDirectory ? filepath : path$2.dirname(filepath));
|
4203 | });
|
4204 | });
|
4205 | }
|
4206 |
|
4207 | getDirectory$1.sync = function getDirectorySync(filepath ) {
|
4208 | return isDirectory.sync(filepath) ? filepath : path$2.dirname(filepath);
|
4209 | };
|
4210 |
|
4211 | var getDirectory_1 = getDirectory$1;
|
4212 |
|
4213 |
|
4214 |
|
4215 |
|
4216 |
|
4217 |
|
4218 | function getPropertyByPath$1(source , path ) {
|
4219 | if (typeof path === 'string' && source.hasOwnProperty(path)) {
|
4220 | return source[path];
|
4221 | }
|
4222 |
|
4223 | const parsedPath = typeof path === 'string' ? path.split('.') : path;
|
4224 | return parsedPath.reduce((previous, key) => {
|
4225 | if (previous === undefined) {
|
4226 | return previous;
|
4227 | }
|
4228 | return previous[key];
|
4229 | }, source);
|
4230 | }
|
4231 |
|
4232 | var getPropertyByPath_1 = getPropertyByPath$1;
|
4233 |
|
4234 | const path$1 = path__default['default'];
|
4235 | const loaders$1 = loaders$2;
|
4236 | const readFile = readFile_1;
|
4237 | const cacheWrapper = cacheWrapper_1;
|
4238 | const getDirectory = getDirectory_1;
|
4239 | const getPropertyByPath = getPropertyByPath_1;
|
4240 |
|
4241 | const MODE_SYNC = 'sync';
|
4242 |
|
4243 |
|
4244 |
|
4245 |
|
4246 |
|
4247 |
|
4248 |
|
4249 | class Explorer {
|
4250 |
|
4251 |
|
4252 |
|
4253 |
|
4254 |
|
4255 |
|
4256 | constructor(options ) {
|
4257 | this.loadCache = options.cache ? new Map() : null;
|
4258 | this.loadSyncCache = options.cache ? new Map() : null;
|
4259 | this.searchCache = options.cache ? new Map() : null;
|
4260 | this.searchSyncCache = options.cache ? new Map() : null;
|
4261 | this.config = options;
|
4262 | this.validateConfig();
|
4263 | }
|
4264 |
|
4265 | clearLoadCache() {
|
4266 | if (this.loadCache) {
|
4267 | this.loadCache.clear();
|
4268 | }
|
4269 | if (this.loadSyncCache) {
|
4270 | this.loadSyncCache.clear();
|
4271 | }
|
4272 | }
|
4273 |
|
4274 | clearSearchCache() {
|
4275 | if (this.searchCache) {
|
4276 | this.searchCache.clear();
|
4277 | }
|
4278 | if (this.searchSyncCache) {
|
4279 | this.searchSyncCache.clear();
|
4280 | }
|
4281 | }
|
4282 |
|
4283 | clearCaches() {
|
4284 | this.clearLoadCache();
|
4285 | this.clearSearchCache();
|
4286 | }
|
4287 |
|
4288 | validateConfig() {
|
4289 | const config = this.config;
|
4290 |
|
4291 | config.searchPlaces.forEach(place => {
|
4292 | const loaderKey = path$1.extname(place) || 'noExt';
|
4293 | const loader = config.loaders[loaderKey];
|
4294 | if (!loader) {
|
4295 | throw new Error(
|
4296 | `No loader specified for ${getExtensionDescription(
|
4297 | place
|
4298 | )}, so searchPlaces item "${place}" is invalid`
|
4299 | );
|
4300 | }
|
4301 | });
|
4302 | }
|
4303 |
|
4304 | search(searchFrom ) {
|
4305 | searchFrom = searchFrom || process.cwd();
|
4306 | return getDirectory(searchFrom).then(dir => {
|
4307 | return this.searchFromDirectory(dir);
|
4308 | });
|
4309 | }
|
4310 |
|
4311 | searchFromDirectory(dir ) {
|
4312 | const absoluteDir = path$1.resolve(process.cwd(), dir);
|
4313 | const run = () => {
|
4314 | return this.searchDirectory(absoluteDir).then(result => {
|
4315 | const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
|
4316 | if (nextDir) {
|
4317 | return this.searchFromDirectory(nextDir);
|
4318 | }
|
4319 | return this.config.transform(result);
|
4320 | });
|
4321 | };
|
4322 |
|
4323 | if (this.searchCache) {
|
4324 | return cacheWrapper(this.searchCache, absoluteDir, run);
|
4325 | }
|
4326 | return run();
|
4327 | }
|
4328 |
|
4329 | searchSync(searchFrom ) {
|
4330 | searchFrom = searchFrom || process.cwd();
|
4331 | const dir = getDirectory.sync(searchFrom);
|
4332 | return this.searchFromDirectorySync(dir);
|
4333 | }
|
4334 |
|
4335 | searchFromDirectorySync(dir ) {
|
4336 | const absoluteDir = path$1.resolve(process.cwd(), dir);
|
4337 | const run = () => {
|
4338 | const result = this.searchDirectorySync(absoluteDir);
|
4339 | const nextDir = this.nextDirectoryToSearch(absoluteDir, result);
|
4340 | if (nextDir) {
|
4341 | return this.searchFromDirectorySync(nextDir);
|
4342 | }
|
4343 | return this.config.transform(result);
|
4344 | };
|
4345 |
|
4346 | if (this.searchSyncCache) {
|
4347 | return cacheWrapper(this.searchSyncCache, absoluteDir, run);
|
4348 | }
|
4349 | return run();
|
4350 | }
|
4351 |
|
4352 | searchDirectory(dir ) {
|
4353 | return this.config.searchPlaces.reduce((prevResultPromise, place) => {
|
4354 | return prevResultPromise.then(prevResult => {
|
4355 | if (this.shouldSearchStopWithResult(prevResult)) {
|
4356 | return prevResult;
|
4357 | }
|
4358 | return this.loadSearchPlace(dir, place);
|
4359 | });
|
4360 | }, Promise.resolve(null));
|
4361 | }
|
4362 |
|
4363 | searchDirectorySync(dir ) {
|
4364 | let result = null;
|
4365 | for (const place of this.config.searchPlaces) {
|
4366 | result = this.loadSearchPlaceSync(dir, place);
|
4367 | if (this.shouldSearchStopWithResult(result)) break;
|
4368 | }
|
4369 | return result;
|
4370 | }
|
4371 |
|
4372 | shouldSearchStopWithResult(result ) {
|
4373 | if (result === null) return false;
|
4374 | if (result.isEmpty && this.config.ignoreEmptySearchPlaces) return false;
|
4375 | return true;
|
4376 | }
|
4377 |
|
4378 | loadSearchPlace(dir , place ) {
|
4379 | const filepath = path$1.join(dir, place);
|
4380 | return readFile(filepath).then(content => {
|
4381 | return this.createCosmiconfigResult(filepath, content);
|
4382 | });
|
4383 | }
|
4384 |
|
4385 | loadSearchPlaceSync(dir , place ) {
|
4386 | const filepath = path$1.join(dir, place);
|
4387 | const content = readFile.sync(filepath);
|
4388 | return this.createCosmiconfigResultSync(filepath, content);
|
4389 | }
|
4390 |
|
4391 | nextDirectoryToSearch(
|
4392 | currentDir ,
|
4393 | currentResult
|
4394 | ) {
|
4395 | if (this.shouldSearchStopWithResult(currentResult)) {
|
4396 | return null;
|
4397 | }
|
4398 | const nextDir = nextDirUp(currentDir);
|
4399 | if (nextDir === currentDir || currentDir === this.config.stopDir) {
|
4400 | return null;
|
4401 | }
|
4402 | return nextDir;
|
4403 | }
|
4404 |
|
4405 | loadPackageProp(filepath , content ) {
|
4406 | const parsedContent = loaders$1.loadJson(filepath, content);
|
4407 | const packagePropValue = getPropertyByPath(
|
4408 | parsedContent,
|
4409 | this.config.packageProp
|
4410 | );
|
4411 | return packagePropValue || null;
|
4412 | }
|
4413 |
|
4414 | getLoaderEntryForFile(filepath ) {
|
4415 | if (path$1.basename(filepath) === 'package.json') {
|
4416 | const loader = this.loadPackageProp.bind(this);
|
4417 | return { sync: loader, async: loader };
|
4418 | }
|
4419 |
|
4420 | const loaderKey = path$1.extname(filepath) || 'noExt';
|
4421 | return this.config.loaders[loaderKey] || {};
|
4422 | }
|
4423 |
|
4424 | getSyncLoaderForFile(filepath ) {
|
4425 | const entry = this.getLoaderEntryForFile(filepath);
|
4426 | if (!entry.sync) {
|
4427 | throw new Error(
|
4428 | `No sync loader specified for ${getExtensionDescription(filepath)}`
|
4429 | );
|
4430 | }
|
4431 | return entry.sync;
|
4432 | }
|
4433 |
|
4434 | getAsyncLoaderForFile(filepath ) {
|
4435 | const entry = this.getLoaderEntryForFile(filepath);
|
4436 | const loader = entry.async || entry.sync;
|
4437 | if (!loader) {
|
4438 | throw new Error(
|
4439 | `No async loader specified for ${getExtensionDescription(filepath)}`
|
4440 | );
|
4441 | }
|
4442 | return loader;
|
4443 | }
|
4444 |
|
4445 | loadFileContent(
|
4446 | mode ,
|
4447 | filepath ,
|
4448 | content
|
4449 | ) {
|
4450 | if (content === null) {
|
4451 | return null;
|
4452 | }
|
4453 | if (content.trim() === '') {
|
4454 | return undefined;
|
4455 | }
|
4456 | const loader =
|
4457 | mode === MODE_SYNC
|
4458 | ? this.getSyncLoaderForFile(filepath)
|
4459 | : this.getAsyncLoaderForFile(filepath);
|
4460 | return loader(filepath, content);
|
4461 | }
|
4462 |
|
4463 | loadedContentToCosmiconfigResult(
|
4464 | filepath ,
|
4465 | loadedContent
|
4466 | ) {
|
4467 | if (loadedContent === null) {
|
4468 | return null;
|
4469 | }
|
4470 | if (loadedContent === undefined) {
|
4471 | return { filepath, config: undefined, isEmpty: true };
|
4472 | }
|
4473 | return { config: loadedContent, filepath };
|
4474 | }
|
4475 |
|
4476 | createCosmiconfigResult(
|
4477 | filepath ,
|
4478 | content
|
4479 | ) {
|
4480 | return Promise.resolve()
|
4481 | .then(() => {
|
4482 | return this.loadFileContent('async', filepath, content);
|
4483 | })
|
4484 | .then(loaderResult => {
|
4485 | return this.loadedContentToCosmiconfigResult(filepath, loaderResult);
|
4486 | });
|
4487 | }
|
4488 |
|
4489 | createCosmiconfigResultSync(
|
4490 | filepath ,
|
4491 | content
|
4492 | ) {
|
4493 | const loaderResult = this.loadFileContent('sync', filepath, content);
|
4494 | return this.loadedContentToCosmiconfigResult(filepath, loaderResult);
|
4495 | }
|
4496 |
|
4497 | validateFilePath(filepath ) {
|
4498 | if (!filepath) {
|
4499 | throw new Error('load and loadSync must pass a non-empty string');
|
4500 | }
|
4501 | }
|
4502 |
|
4503 | load(filepath ) {
|
4504 | return Promise.resolve().then(() => {
|
4505 | this.validateFilePath(filepath);
|
4506 | const absoluteFilePath = path$1.resolve(process.cwd(), filepath);
|
4507 | return cacheWrapper(this.loadCache, absoluteFilePath, () => {
|
4508 | return readFile(absoluteFilePath, { throwNotFound: true })
|
4509 | .then(content => {
|
4510 | return this.createCosmiconfigResult(absoluteFilePath, content);
|
4511 | })
|
4512 | .then(this.config.transform);
|
4513 | });
|
4514 | });
|
4515 | }
|
4516 |
|
4517 | loadSync(filepath ) {
|
4518 | this.validateFilePath(filepath);
|
4519 | const absoluteFilePath = path$1.resolve(process.cwd(), filepath);
|
4520 | return cacheWrapper(this.loadSyncCache, absoluteFilePath, () => {
|
4521 | const content = readFile.sync(absoluteFilePath, { throwNotFound: true });
|
4522 | const result = this.createCosmiconfigResultSync(
|
4523 | absoluteFilePath,
|
4524 | content
|
4525 | );
|
4526 | return this.config.transform(result);
|
4527 | });
|
4528 | }
|
4529 | }
|
4530 |
|
4531 | var createExplorer$1 = function createExplorer(options ) {
|
4532 | const explorer = new Explorer(options);
|
4533 |
|
4534 | return {
|
4535 | search: explorer.search.bind(explorer),
|
4536 | searchSync: explorer.searchSync.bind(explorer),
|
4537 | load: explorer.load.bind(explorer),
|
4538 | loadSync: explorer.loadSync.bind(explorer),
|
4539 | clearLoadCache: explorer.clearLoadCache.bind(explorer),
|
4540 | clearSearchCache: explorer.clearSearchCache.bind(explorer),
|
4541 | clearCaches: explorer.clearCaches.bind(explorer),
|
4542 | };
|
4543 | };
|
4544 |
|
4545 | function nextDirUp(dir ) {
|
4546 | return path$1.dirname(dir);
|
4547 | }
|
4548 |
|
4549 | function getExtensionDescription(filepath ) {
|
4550 | const ext = path$1.extname(filepath);
|
4551 | return ext ? `extension "${ext}"` : 'files without extensions';
|
4552 | }
|
4553 |
|
4554 | const os = require$$0__default$2['default'];
|
4555 | const createExplorer = createExplorer$1;
|
4556 | const loaders = loaders$2;
|
4557 |
|
4558 | var dist = cosmiconfig;
|
4559 |
|
4560 | function cosmiconfig(
|
4561 | moduleName ,
|
4562 | options
|
4563 |
|
4564 |
|
4565 |
|
4566 |
|
4567 |
|
4568 |
|
4569 |
|
4570 |
|
4571 | ) {
|
4572 | options = options || {};
|
4573 | const defaults = {
|
4574 | packageProp: moduleName,
|
4575 | searchPlaces: [
|
4576 | 'package.json',
|
4577 | `.${moduleName}rc`,
|
4578 | `.${moduleName}rc.json`,
|
4579 | `.${moduleName}rc.yaml`,
|
4580 | `.${moduleName}rc.yml`,
|
4581 | `.${moduleName}rc.js`,
|
4582 | `${moduleName}.config.js`,
|
4583 | ],
|
4584 | ignoreEmptySearchPlaces: true,
|
4585 | stopDir: os.homedir(),
|
4586 | cache: true,
|
4587 | transform: identity,
|
4588 | };
|
4589 | const normalizedOptions = Object.assign(
|
4590 | {},
|
4591 | defaults,
|
4592 | options,
|
4593 | {
|
4594 | loaders: normalizeLoaders(options.loaders),
|
4595 | }
|
4596 | );
|
4597 |
|
4598 | return createExplorer(normalizedOptions);
|
4599 | }
|
4600 |
|
4601 | cosmiconfig.loadJs = loaders.loadJs;
|
4602 | cosmiconfig.loadJson = loaders.loadJson;
|
4603 | cosmiconfig.loadYaml = loaders.loadYaml;
|
4604 |
|
4605 | function normalizeLoaders(rawLoaders ) {
|
4606 | const defaults = {
|
4607 | '.js': { sync: loaders.loadJs, async: loaders.loadJs },
|
4608 | '.json': { sync: loaders.loadJson, async: loaders.loadJson },
|
4609 | '.yaml': { sync: loaders.loadYaml, async: loaders.loadYaml },
|
4610 | '.yml': { sync: loaders.loadYaml, async: loaders.loadYaml },
|
4611 | noExt: { sync: loaders.loadYaml, async: loaders.loadYaml },
|
4612 | };
|
4613 |
|
4614 | if (!rawLoaders) {
|
4615 | return defaults;
|
4616 | }
|
4617 |
|
4618 | return Object.keys(rawLoaders).reduce((result, ext) => {
|
4619 | const entry = rawLoaders && rawLoaders[ext];
|
4620 | if (typeof entry === 'function') {
|
4621 | result[ext] = { sync: entry, async: entry };
|
4622 | } else {
|
4623 | result[ext] = entry;
|
4624 | }
|
4625 | return result;
|
4626 | }, defaults);
|
4627 | }
|
4628 |
|
4629 | function identity(x) {
|
4630 | return x;
|
4631 | }
|
4632 |
|
4633 |
|
4634 |
|
4635 | const testExpression = /(^|\/|\\)(?:((?:u[0-9a-f]{4,6},?)+)-)(.+)\.svg$/i;
|
4636 |
|
4637 | function fileSorter(fileA, fileB) {
|
4638 | const hasUnicodeA = testExpression.test(fileA);
|
4639 | const hasUnicodeB = testExpression.test(fileB);
|
4640 |
|
4641 | if (hasUnicodeA == hasUnicodeB) {
|
4642 |
|
4643 | const fileA_ = fileA.substr(0, fileA.lastIndexOf('.'));
|
4644 | const fileB_ = fileB.substr(0, fileB.lastIndexOf('.'));
|
4645 | return fileA_ < fileB_ ? -1 : 1;
|
4646 | } else {
|
4647 |
|
4648 | return (hasUnicodeA ? 0 : 1) - (hasUnicodeB ? 0 : 1);
|
4649 | }
|
4650 | }
|
4651 |
|
4652 | var filesorter = fileSorter;
|
4653 |
|
4654 | var callBind$6 = {exports: {}};
|
4655 |
|
4656 |
|
4657 |
|
4658 | var ERROR_MESSAGE = 'Function.prototype.bind called on incompatible ';
|
4659 | var slice$1 = Array.prototype.slice;
|
4660 | var toStr$7 = Object.prototype.toString;
|
4661 | var funcType = '[object Function]';
|
4662 |
|
4663 | var implementation$8 = function bind(that) {
|
4664 | var target = this;
|
4665 | if (typeof target !== 'function' || toStr$7.call(target) !== funcType) {
|
4666 | throw new TypeError(ERROR_MESSAGE + target);
|
4667 | }
|
4668 | var args = slice$1.call(arguments, 1);
|
4669 |
|
4670 | var bound;
|
4671 | var binder = function () {
|
4672 | if (this instanceof bound) {
|
4673 | var result = target.apply(
|
4674 | this,
|
4675 | args.concat(slice$1.call(arguments))
|
4676 | );
|
4677 | if (Object(result) === result) {
|
4678 | return result;
|
4679 | }
|
4680 | return this;
|
4681 | } else {
|
4682 | return target.apply(
|
4683 | that,
|
4684 | args.concat(slice$1.call(arguments))
|
4685 | );
|
4686 | }
|
4687 | };
|
4688 |
|
4689 | var boundLength = Math.max(0, target.length - args.length);
|
4690 | var boundArgs = [];
|
4691 | for (var i = 0; i < boundLength; i++) {
|
4692 | boundArgs.push('$' + i);
|
4693 | }
|
4694 |
|
4695 | bound = Function('binder', 'return function (' + boundArgs.join(',') + '){ return binder.apply(this,arguments); }')(binder);
|
4696 |
|
4697 | if (target.prototype) {
|
4698 | var Empty = function Empty() {};
|
4699 | Empty.prototype = target.prototype;
|
4700 | bound.prototype = new Empty();
|
4701 | Empty.prototype = null;
|
4702 | }
|
4703 |
|
4704 | return bound;
|
4705 | };
|
4706 |
|
4707 | var implementation$7 = implementation$8;
|
4708 |
|
4709 | var functionBind = Function.prototype.bind || implementation$7;
|
4710 |
|
4711 |
|
4712 | var shams = function hasSymbols() {
|
4713 | if (typeof Symbol !== 'function' || typeof Object.getOwnPropertySymbols !== 'function') { return false; }
|
4714 | if (typeof Symbol.iterator === 'symbol') { return true; }
|
4715 |
|
4716 | var obj = {};
|
4717 | var sym = Symbol('test');
|
4718 | var symObj = Object(sym);
|
4719 | if (typeof sym === 'string') { return false; }
|
4720 |
|
4721 | if (Object.prototype.toString.call(sym) !== '[object Symbol]') { return false; }
|
4722 | if (Object.prototype.toString.call(symObj) !== '[object Symbol]') { return false; }
|
4723 |
|
4724 |
|
4725 |
|
4726 |
|
4727 |
|
4728 |
|
4729 |
|
4730 |
|
4731 |
|
4732 | var symVal = 42;
|
4733 | obj[sym] = symVal;
|
4734 | for (sym in obj) { return false; }
|
4735 | if (typeof Object.keys === 'function' && Object.keys(obj).length !== 0) { return false; }
|
4736 |
|
4737 | if (typeof Object.getOwnPropertyNames === 'function' && Object.getOwnPropertyNames(obj).length !== 0) { return false; }
|
4738 |
|
4739 | var syms = Object.getOwnPropertySymbols(obj);
|
4740 | if (syms.length !== 1 || syms[0] !== sym) { return false; }
|
4741 |
|
4742 | if (!Object.prototype.propertyIsEnumerable.call(obj, sym)) { return false; }
|
4743 |
|
4744 | if (typeof Object.getOwnPropertyDescriptor === 'function') {
|
4745 | var descriptor = Object.getOwnPropertyDescriptor(obj, sym);
|
4746 | if (descriptor.value !== symVal || descriptor.enumerable !== true) { return false; }
|
4747 | }
|
4748 |
|
4749 | return true;
|
4750 | };
|
4751 |
|
4752 | var origSymbol = typeof Symbol !== 'undefined' && Symbol;
|
4753 | var hasSymbolSham = shams;
|
4754 |
|
4755 | var hasSymbols$4 = function hasNativeSymbols() {
|
4756 | if (typeof origSymbol !== 'function') { return false; }
|
4757 | if (typeof Symbol !== 'function') { return false; }
|
4758 | if (typeof origSymbol('foo') !== 'symbol') { return false; }
|
4759 | if (typeof Symbol('bar') !== 'symbol') { return false; }
|
4760 |
|
4761 | return hasSymbolSham();
|
4762 | };
|
4763 |
|
4764 | var bind$1 = functionBind;
|
4765 |
|
4766 | var src = bind$1.call(Function.call, Object.prototype.hasOwnProperty);
|
4767 |
|
4768 | var undefined$1;
|
4769 |
|
4770 | var $SyntaxError = SyntaxError;
|
4771 | var $Function = Function;
|
4772 | var $TypeError$3 = TypeError;
|
4773 |
|
4774 |
|
4775 | var getEvalledConstructor = function (expressionSyntax) {
|
4776 | try {
|
4777 | return $Function('"use strict"; return (' + expressionSyntax + ').constructor;')();
|
4778 | } catch (e) {}
|
4779 | };
|
4780 |
|
4781 | var $gOPD = Object.getOwnPropertyDescriptor;
|
4782 | if ($gOPD) {
|
4783 | try {
|
4784 | $gOPD({}, '');
|
4785 | } catch (e) {
|
4786 | $gOPD = null;
|
4787 | }
|
4788 | }
|
4789 |
|
4790 | var throwTypeError = function () {
|
4791 | throw new $TypeError$3();
|
4792 | };
|
4793 | var ThrowTypeError = $gOPD
|
4794 | ? (function () {
|
4795 | try {
|
4796 |
|
4797 | arguments.callee;
|
4798 | return throwTypeError;
|
4799 | } catch (calleeThrows) {
|
4800 | try {
|
4801 |
|
4802 | return $gOPD(arguments, 'callee').get;
|
4803 | } catch (gOPDthrows) {
|
4804 | return throwTypeError;
|
4805 | }
|
4806 | }
|
4807 | }())
|
4808 | : throwTypeError;
|
4809 |
|
4810 | var hasSymbols$3 = hasSymbols$4();
|
4811 |
|
4812 | var getProto = Object.getPrototypeOf || function (x) { return x.__proto__; };
|
4813 |
|
4814 | var needsEval = {};
|
4815 |
|
4816 | var TypedArray = typeof Uint8Array === 'undefined' ? undefined$1 : getProto(Uint8Array);
|
4817 |
|
4818 | var INTRINSICS = {
|
4819 | '%AggregateError%': typeof AggregateError === 'undefined' ? undefined$1 : AggregateError,
|
4820 | '%Array%': Array,
|
4821 | '%ArrayBuffer%': typeof ArrayBuffer === 'undefined' ? undefined$1 : ArrayBuffer,
|
4822 | '%ArrayIteratorPrototype%': hasSymbols$3 ? getProto([][Symbol.iterator]()) : undefined$1,
|
4823 | '%AsyncFromSyncIteratorPrototype%': undefined$1,
|
4824 | '%AsyncFunction%': needsEval,
|
4825 | '%AsyncGenerator%': needsEval,
|
4826 | '%AsyncGeneratorFunction%': needsEval,
|
4827 | '%AsyncIteratorPrototype%': needsEval,
|
4828 | '%Atomics%': typeof Atomics === 'undefined' ? undefined$1 : Atomics,
|
4829 | '%BigInt%': typeof BigInt === 'undefined' ? undefined$1 : BigInt,
|
4830 | '%Boolean%': Boolean,
|
4831 | '%DataView%': typeof DataView === 'undefined' ? undefined$1 : DataView,
|
4832 | '%Date%': Date,
|
4833 | '%decodeURI%': decodeURI,
|
4834 | '%decodeURIComponent%': decodeURIComponent,
|
4835 | '%encodeURI%': encodeURI,
|
4836 | '%encodeURIComponent%': encodeURIComponent,
|
4837 | '%Error%': Error,
|
4838 | '%eval%': eval,
|
4839 | '%EvalError%': EvalError,
|
4840 | '%Float32Array%': typeof Float32Array === 'undefined' ? undefined$1 : Float32Array,
|
4841 | '%Float64Array%': typeof Float64Array === 'undefined' ? undefined$1 : Float64Array,
|
4842 | '%FinalizationRegistry%': typeof FinalizationRegistry === 'undefined' ? undefined$1 : FinalizationRegistry,
|
4843 | '%Function%': $Function,
|
4844 | '%GeneratorFunction%': needsEval,
|
4845 | '%Int8Array%': typeof Int8Array === 'undefined' ? undefined$1 : Int8Array,
|
4846 | '%Int16Array%': typeof Int16Array === 'undefined' ? undefined$1 : Int16Array,
|
4847 | '%Int32Array%': typeof Int32Array === 'undefined' ? undefined$1 : Int32Array,
|
4848 | '%isFinite%': isFinite,
|
4849 | '%isNaN%': isNaN,
|
4850 | '%IteratorPrototype%': hasSymbols$3 ? getProto(getProto([][Symbol.iterator]())) : undefined$1,
|
4851 | '%JSON%': typeof JSON === 'object' ? JSON : undefined$1,
|
4852 | '%Map%': typeof Map === 'undefined' ? undefined$1 : Map,
|
4853 | '%MapIteratorPrototype%': typeof Map === 'undefined' || !hasSymbols$3 ? undefined$1 : getProto(new Map()[Symbol.iterator]()),
|
4854 | '%Math%': Math,
|
4855 | '%Number%': Number,
|
4856 | '%Object%': Object,
|
4857 | '%parseFloat%': parseFloat,
|
4858 | '%parseInt%': parseInt,
|
4859 | '%Promise%': typeof Promise === 'undefined' ? undefined$1 : Promise,
|
4860 | '%Proxy%': typeof Proxy === 'undefined' ? undefined$1 : Proxy,
|
4861 | '%RangeError%': RangeError,
|
4862 | '%ReferenceError%': ReferenceError,
|
4863 | '%Reflect%': typeof Reflect === 'undefined' ? undefined$1 : Reflect,
|
4864 | '%RegExp%': RegExp,
|
4865 | '%Set%': typeof Set === 'undefined' ? undefined$1 : Set,
|
4866 | '%SetIteratorPrototype%': typeof Set === 'undefined' || !hasSymbols$3 ? undefined$1 : getProto(new Set()[Symbol.iterator]()),
|
4867 | '%SharedArrayBuffer%': typeof SharedArrayBuffer === 'undefined' ? undefined$1 : SharedArrayBuffer,
|
4868 | '%String%': String,
|
4869 | '%StringIteratorPrototype%': hasSymbols$3 ? getProto(''[Symbol.iterator]()) : undefined$1,
|
4870 | '%Symbol%': hasSymbols$3 ? Symbol : undefined$1,
|
4871 | '%SyntaxError%': $SyntaxError,
|
4872 | '%ThrowTypeError%': ThrowTypeError,
|
4873 | '%TypedArray%': TypedArray,
|
4874 | '%TypeError%': $TypeError$3,
|
4875 | '%Uint8Array%': typeof Uint8Array === 'undefined' ? undefined$1 : Uint8Array,
|
4876 | '%Uint8ClampedArray%': typeof Uint8ClampedArray === 'undefined' ? undefined$1 : Uint8ClampedArray,
|
4877 | '%Uint16Array%': typeof Uint16Array === 'undefined' ? undefined$1 : Uint16Array,
|
4878 | '%Uint32Array%': typeof Uint32Array === 'undefined' ? undefined$1 : Uint32Array,
|
4879 | '%URIError%': URIError,
|
4880 | '%WeakMap%': typeof WeakMap === 'undefined' ? undefined$1 : WeakMap,
|
4881 | '%WeakRef%': typeof WeakRef === 'undefined' ? undefined$1 : WeakRef,
|
4882 | '%WeakSet%': typeof WeakSet === 'undefined' ? undefined$1 : WeakSet
|
4883 | };
|
4884 |
|
4885 | var doEval = function doEval(name) {
|
4886 | var value;
|
4887 | if (name === '%AsyncFunction%') {
|
4888 | value = getEvalledConstructor('async function () {}');
|
4889 | } else if (name === '%GeneratorFunction%') {
|
4890 | value = getEvalledConstructor('function* () {}');
|
4891 | } else if (name === '%AsyncGeneratorFunction%') {
|
4892 | value = getEvalledConstructor('async function* () {}');
|
4893 | } else if (name === '%AsyncGenerator%') {
|
4894 | var fn = doEval('%AsyncGeneratorFunction%');
|
4895 | if (fn) {
|
4896 | value = fn.prototype;
|
4897 | }
|
4898 | } else if (name === '%AsyncIteratorPrototype%') {
|
4899 | var gen = doEval('%AsyncGenerator%');
|
4900 | if (gen) {
|
4901 | value = getProto(gen.prototype);
|
4902 | }
|
4903 | }
|
4904 |
|
4905 | INTRINSICS[name] = value;
|
4906 |
|
4907 | return value;
|
4908 | };
|
4909 |
|
4910 | var LEGACY_ALIASES = {
|
4911 | '%ArrayBufferPrototype%': ['ArrayBuffer', 'prototype'],
|
4912 | '%ArrayPrototype%': ['Array', 'prototype'],
|
4913 | '%ArrayProto_entries%': ['Array', 'prototype', 'entries'],
|
4914 | '%ArrayProto_forEach%': ['Array', 'prototype', 'forEach'],
|
4915 | '%ArrayProto_keys%': ['Array', 'prototype', 'keys'],
|
4916 | '%ArrayProto_values%': ['Array', 'prototype', 'values'],
|
4917 | '%AsyncFunctionPrototype%': ['AsyncFunction', 'prototype'],
|
4918 | '%AsyncGenerator%': ['AsyncGeneratorFunction', 'prototype'],
|
4919 | '%AsyncGeneratorPrototype%': ['AsyncGeneratorFunction', 'prototype', 'prototype'],
|
4920 | '%BooleanPrototype%': ['Boolean', 'prototype'],
|
4921 | '%DataViewPrototype%': ['DataView', 'prototype'],
|
4922 | '%DatePrototype%': ['Date', 'prototype'],
|
4923 | '%ErrorPrototype%': ['Error', 'prototype'],
|
4924 | '%EvalErrorPrototype%': ['EvalError', 'prototype'],
|
4925 | '%Float32ArrayPrototype%': ['Float32Array', 'prototype'],
|
4926 | '%Float64ArrayPrototype%': ['Float64Array', 'prototype'],
|
4927 | '%FunctionPrototype%': ['Function', 'prototype'],
|
4928 | '%Generator%': ['GeneratorFunction', 'prototype'],
|
4929 | '%GeneratorPrototype%': ['GeneratorFunction', 'prototype', 'prototype'],
|
4930 | '%Int8ArrayPrototype%': ['Int8Array', 'prototype'],
|
4931 | '%Int16ArrayPrototype%': ['Int16Array', 'prototype'],
|
4932 | '%Int32ArrayPrototype%': ['Int32Array', 'prototype'],
|
4933 | '%JSONParse%': ['JSON', 'parse'],
|
4934 | '%JSONStringify%': ['JSON', 'stringify'],
|
4935 | '%MapPrototype%': ['Map', 'prototype'],
|
4936 | '%NumberPrototype%': ['Number', 'prototype'],
|
4937 | '%ObjectPrototype%': ['Object', 'prototype'],
|
4938 | '%ObjProto_toString%': ['Object', 'prototype', 'toString'],
|
4939 | '%ObjProto_valueOf%': ['Object', 'prototype', 'valueOf'],
|
4940 | '%PromisePrototype%': ['Promise', 'prototype'],
|
4941 | '%PromiseProto_then%': ['Promise', 'prototype', 'then'],
|
4942 | '%Promise_all%': ['Promise', 'all'],
|
4943 | '%Promise_reject%': ['Promise', 'reject'],
|
4944 | '%Promise_resolve%': ['Promise', 'resolve'],
|
4945 | '%RangeErrorPrototype%': ['RangeError', 'prototype'],
|
4946 | '%ReferenceErrorPrototype%': ['ReferenceError', 'prototype'],
|
4947 | '%RegExpPrototype%': ['RegExp', 'prototype'],
|
4948 | '%SetPrototype%': ['Set', 'prototype'],
|
4949 | '%SharedArrayBufferPrototype%': ['SharedArrayBuffer', 'prototype'],
|
4950 | '%StringPrototype%': ['String', 'prototype'],
|
4951 | '%SymbolPrototype%': ['Symbol', 'prototype'],
|
4952 | '%SyntaxErrorPrototype%': ['SyntaxError', 'prototype'],
|
4953 | '%TypedArrayPrototype%': ['TypedArray', 'prototype'],
|
4954 | '%TypeErrorPrototype%': ['TypeError', 'prototype'],
|
4955 | '%Uint8ArrayPrototype%': ['Uint8Array', 'prototype'],
|
4956 | '%Uint8ClampedArrayPrototype%': ['Uint8ClampedArray', 'prototype'],
|
4957 | '%Uint16ArrayPrototype%': ['Uint16Array', 'prototype'],
|
4958 | '%Uint32ArrayPrototype%': ['Uint32Array', 'prototype'],
|
4959 | '%URIErrorPrototype%': ['URIError', 'prototype'],
|
4960 | '%WeakMapPrototype%': ['WeakMap', 'prototype'],
|
4961 | '%WeakSetPrototype%': ['WeakSet', 'prototype']
|
4962 | };
|
4963 |
|
4964 | var bind = functionBind;
|
4965 | var hasOwn = src;
|
4966 | var $concat = bind.call(Function.call, Array.prototype.concat);
|
4967 | var $spliceApply = bind.call(Function.apply, Array.prototype.splice);
|
4968 | var $replace$1 = bind.call(Function.call, String.prototype.replace);
|
4969 | var $strSlice$1 = bind.call(Function.call, String.prototype.slice);
|
4970 |
|
4971 |
|
4972 | var rePropName = /[^%.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|%$))/g;
|
4973 | var reEscapeChar = /\\(\\)?/g;
|
4974 | var stringToPath = function stringToPath(string) {
|
4975 | var first = $strSlice$1(string, 0, 1);
|
4976 | var last = $strSlice$1(string, -1);
|
4977 | if (first === '%' && last !== '%') {
|
4978 | throw new $SyntaxError('invalid intrinsic syntax, expected closing `%`');
|
4979 | } else if (last === '%' && first !== '%') {
|
4980 | throw new $SyntaxError('invalid intrinsic syntax, expected opening `%`');
|
4981 | }
|
4982 | var result = [];
|
4983 | $replace$1(string, rePropName, function (match, number, quote, subString) {
|
4984 | result[result.length] = quote ? $replace$1(subString, reEscapeChar, '$1') : number || match;
|
4985 | });
|
4986 | return result;
|
4987 | };
|
4988 |
|
4989 |
|
4990 | var getBaseIntrinsic = function getBaseIntrinsic(name, allowMissing) {
|
4991 | var intrinsicName = name;
|
4992 | var alias;
|
4993 | if (hasOwn(LEGACY_ALIASES, intrinsicName)) {
|
4994 | alias = LEGACY_ALIASES[intrinsicName];
|
4995 | intrinsicName = '%' + alias[0] + '%';
|
4996 | }
|
4997 |
|
4998 | if (hasOwn(INTRINSICS, intrinsicName)) {
|
4999 | var value = INTRINSICS[intrinsicName];
|
5000 | if (value === needsEval) {
|
5001 | value = doEval(intrinsicName);
|
5002 | }
|
5003 | if (typeof value === 'undefined' && !allowMissing) {
|
5004 | throw new $TypeError$3('intrinsic ' + name + ' exists, but is not available. Please file an issue!');
|
5005 | }
|
5006 |
|
5007 | return {
|
5008 | alias: alias,
|
5009 | name: intrinsicName,
|
5010 | value: value
|
5011 | };
|
5012 | }
|
5013 |
|
5014 | throw new $SyntaxError('intrinsic ' + name + ' does not exist!');
|
5015 | };
|
5016 |
|
5017 | var getIntrinsic = function GetIntrinsic(name, allowMissing) {
|
5018 | if (typeof name !== 'string' || name.length === 0) {
|
5019 | throw new $TypeError$3('intrinsic name must be a non-empty string');
|
5020 | }
|
5021 | if (arguments.length > 1 && typeof allowMissing !== 'boolean') {
|
5022 | throw new $TypeError$3('"allowMissing" argument must be a boolean');
|
5023 | }
|
5024 |
|
5025 | var parts = stringToPath(name);
|
5026 | var intrinsicBaseName = parts.length > 0 ? parts[0] : '';
|
5027 |
|
5028 | var intrinsic = getBaseIntrinsic('%' + intrinsicBaseName + '%', allowMissing);
|
5029 | var intrinsicRealName = intrinsic.name;
|
5030 | var value = intrinsic.value;
|
5031 | var skipFurtherCaching = false;
|
5032 |
|
5033 | var alias = intrinsic.alias;
|
5034 | if (alias) {
|
5035 | intrinsicBaseName = alias[0];
|
5036 | $spliceApply(parts, $concat([0, 1], alias));
|
5037 | }
|
5038 |
|
5039 | for (var i = 1, isOwn = true; i < parts.length; i += 1) {
|
5040 | var part = parts[i];
|
5041 | var first = $strSlice$1(part, 0, 1);
|
5042 | var last = $strSlice$1(part, -1);
|
5043 | if (
|
5044 | (
|
5045 | (first === '"' || first === "'" || first === '`')
|
5046 | || (last === '"' || last === "'" || last === '`')
|
5047 | )
|
5048 | && first !== last
|
5049 | ) {
|
5050 | throw new $SyntaxError('property names with quotes must have matching quotes');
|
5051 | }
|
5052 | if (part === 'constructor' || !isOwn) {
|
5053 | skipFurtherCaching = true;
|
5054 | }
|
5055 |
|
5056 | intrinsicBaseName += '.' + part;
|
5057 | intrinsicRealName = '%' + intrinsicBaseName + '%';
|
5058 |
|
5059 | if (hasOwn(INTRINSICS, intrinsicRealName)) {
|
5060 | value = INTRINSICS[intrinsicRealName];
|
5061 | } else if (value != null) {
|
5062 | if (!(part in value)) {
|
5063 | if (!allowMissing) {
|
5064 | throw new $TypeError$3('base intrinsic for ' + name + ' exists, but the property is not available.');
|
5065 | }
|
5066 | return void undefined$1;
|
5067 | }
|
5068 | if ($gOPD && (i + 1) >= parts.length) {
|
5069 | var desc = $gOPD(value, part);
|
5070 | isOwn = !!desc;
|
5071 |
|
5072 |
|
5073 |
|
5074 |
|
5075 |
|
5076 |
|
5077 |
|
5078 |
|
5079 | if (isOwn && 'get' in desc && !('originalValue' in desc.get)) {
|
5080 | value = desc.get;
|
5081 | } else {
|
5082 | value = value[part];
|
5083 | }
|
5084 | } else {
|
5085 | isOwn = hasOwn(value, part);
|
5086 | value = value[part];
|
5087 | }
|
5088 |
|
5089 | if (isOwn && !skipFurtherCaching) {
|
5090 | INTRINSICS[intrinsicRealName] = value;
|
5091 | }
|
5092 | }
|
5093 | }
|
5094 | return value;
|
5095 | };
|
5096 |
|
5097 | (function (module) {
|
5098 |
|
5099 | var bind = functionBind;
|
5100 | var GetIntrinsic = getIntrinsic;
|
5101 |
|
5102 | var $apply = GetIntrinsic('%Function.prototype.apply%');
|
5103 | var $call = GetIntrinsic('%Function.prototype.call%');
|
5104 | var $reflectApply = GetIntrinsic('%Reflect.apply%', true) || bind.call($call, $apply);
|
5105 |
|
5106 | var $gOPD = GetIntrinsic('%Object.getOwnPropertyDescriptor%', true);
|
5107 | var $defineProperty = GetIntrinsic('%Object.defineProperty%', true);
|
5108 | var $max = GetIntrinsic('%Math.max%');
|
5109 |
|
5110 | if ($defineProperty) {
|
5111 | try {
|
5112 | $defineProperty({}, 'a', { value: 1 });
|
5113 | } catch (e) {
|
5114 |
|
5115 | $defineProperty = null;
|
5116 | }
|
5117 | }
|
5118 |
|
5119 | module.exports = function callBind(originalFunction) {
|
5120 | var func = $reflectApply(bind, $call, arguments);
|
5121 | if ($gOPD && $defineProperty) {
|
5122 | var desc = $gOPD(func, 'length');
|
5123 | if (desc.configurable) {
|
5124 |
|
5125 | $defineProperty(
|
5126 | func,
|
5127 | 'length',
|
5128 | { value: 1 + $max(0, originalFunction.length - (arguments.length - 1)) }
|
5129 | );
|
5130 | }
|
5131 | }
|
5132 | return func;
|
5133 | };
|
5134 |
|
5135 | var applyBind = function applyBind() {
|
5136 | return $reflectApply(bind, $apply, arguments);
|
5137 | };
|
5138 |
|
5139 | if ($defineProperty) {
|
5140 | $defineProperty(module.exports, 'apply', { value: applyBind });
|
5141 | } else {
|
5142 | module.exports.apply = applyBind;
|
5143 | }
|
5144 | }(callBind$6));
|
5145 |
|
5146 |
|
5147 |
|
5148 | var callBind$5 = callBind$6.exports;
|
5149 |
|
5150 | var toStr$6 = Object.prototype.toString;
|
5151 |
|
5152 | var isArguments = function isArguments(value) {
|
5153 | var str = toStr$6.call(value);
|
5154 | var isArgs = str === '[object Arguments]';
|
5155 | if (!isArgs) {
|
5156 | isArgs = str !== '[object Array]' &&
|
5157 | value !== null &&
|
5158 | typeof value === 'object' &&
|
5159 | typeof value.length === 'number' &&
|
5160 | value.length >= 0 &&
|
5161 | toStr$6.call(value.callee) === '[object Function]';
|
5162 | }
|
5163 | return isArgs;
|
5164 | };
|
5165 |
|
5166 | var keysShim$1;
|
5167 | if (!Object.keys) {
|
5168 |
|
5169 | var has = Object.prototype.hasOwnProperty;
|
5170 | var toStr$5 = Object.prototype.toString;
|
5171 | var isArgs$1 = isArguments;
|
5172 | var isEnumerable = Object.prototype.propertyIsEnumerable;
|
5173 | var hasDontEnumBug = !isEnumerable.call({ toString: null }, 'toString');
|
5174 | var hasProtoEnumBug = isEnumerable.call(function () {}, 'prototype');
|
5175 | var dontEnums = [
|
5176 | 'toString',
|
5177 | 'toLocaleString',
|
5178 | 'valueOf',
|
5179 | 'hasOwnProperty',
|
5180 | 'isPrototypeOf',
|
5181 | 'propertyIsEnumerable',
|
5182 | 'constructor'
|
5183 | ];
|
5184 | var equalsConstructorPrototype = function (o) {
|
5185 | var ctor = o.constructor;
|
5186 | return ctor && ctor.prototype === o;
|
5187 | };
|
5188 | var excludedKeys = {
|
5189 | $applicationCache: true,
|
5190 | $console: true,
|
5191 | $external: true,
|
5192 | $frame: true,
|
5193 | $frameElement: true,
|
5194 | $frames: true,
|
5195 | $innerHeight: true,
|
5196 | $innerWidth: true,
|
5197 | $onmozfullscreenchange: true,
|
5198 | $onmozfullscreenerror: true,
|
5199 | $outerHeight: true,
|
5200 | $outerWidth: true,
|
5201 | $pageXOffset: true,
|
5202 | $pageYOffset: true,
|
5203 | $parent: true,
|
5204 | $scrollLeft: true,
|
5205 | $scrollTop: true,
|
5206 | $scrollX: true,
|
5207 | $scrollY: true,
|
5208 | $self: true,
|
5209 | $webkitIndexedDB: true,
|
5210 | $webkitStorageInfo: true,
|
5211 | $window: true
|
5212 | };
|
5213 | var hasAutomationEqualityBug = (function () {
|
5214 |
|
5215 | if (typeof window === 'undefined') { return false; }
|
5216 | for (var k in window) {
|
5217 | try {
|
5218 | if (!excludedKeys['$' + k] && has.call(window, k) && window[k] !== null && typeof window[k] === 'object') {
|
5219 | try {
|
5220 | equalsConstructorPrototype(window[k]);
|
5221 | } catch (e) {
|
5222 | return true;
|
5223 | }
|
5224 | }
|
5225 | } catch (e) {
|
5226 | return true;
|
5227 | }
|
5228 | }
|
5229 | return false;
|
5230 | }());
|
5231 | var equalsConstructorPrototypeIfNotBuggy = function (o) {
|
5232 |
|
5233 | if (typeof window === 'undefined' || !hasAutomationEqualityBug) {
|
5234 | return equalsConstructorPrototype(o);
|
5235 | }
|
5236 | try {
|
5237 | return equalsConstructorPrototype(o);
|
5238 | } catch (e) {
|
5239 | return false;
|
5240 | }
|
5241 | };
|
5242 |
|
5243 | keysShim$1 = function keys(object) {
|
5244 | var isObject = object !== null && typeof object === 'object';
|
5245 | var isFunction = toStr$5.call(object) === '[object Function]';
|
5246 | var isArguments = isArgs$1(object);
|
5247 | var isString = isObject && toStr$5.call(object) === '[object String]';
|
5248 | var theKeys = [];
|
5249 |
|
5250 | if (!isObject && !isFunction && !isArguments) {
|
5251 | throw new TypeError('Object.keys called on a non-object');
|
5252 | }
|
5253 |
|
5254 | var skipProto = hasProtoEnumBug && isFunction;
|
5255 | if (isString && object.length > 0 && !has.call(object, 0)) {
|
5256 | for (var i = 0; i < object.length; ++i) {
|
5257 | theKeys.push(String(i));
|
5258 | }
|
5259 | }
|
5260 |
|
5261 | if (isArguments && object.length > 0) {
|
5262 | for (var j = 0; j < object.length; ++j) {
|
5263 | theKeys.push(String(j));
|
5264 | }
|
5265 | } else {
|
5266 | for (var name in object) {
|
5267 | if (!(skipProto && name === 'prototype') && has.call(object, name)) {
|
5268 | theKeys.push(String(name));
|
5269 | }
|
5270 | }
|
5271 | }
|
5272 |
|
5273 | if (hasDontEnumBug) {
|
5274 | var skipConstructor = equalsConstructorPrototypeIfNotBuggy(object);
|
5275 |
|
5276 | for (var k = 0; k < dontEnums.length; ++k) {
|
5277 | if (!(skipConstructor && dontEnums[k] === 'constructor') && has.call(object, dontEnums[k])) {
|
5278 | theKeys.push(dontEnums[k]);
|
5279 | }
|
5280 | }
|
5281 | }
|
5282 | return theKeys;
|
5283 | };
|
5284 | }
|
5285 | var implementation$6 = keysShim$1;
|
5286 |
|
5287 | var slice = Array.prototype.slice;
|
5288 | var isArgs = isArguments;
|
5289 |
|
5290 | var origKeys = Object.keys;
|
5291 | var keysShim = origKeys ? function keys(o) { return origKeys(o); } : implementation$6;
|
5292 |
|
5293 | var originalKeys = Object.keys;
|
5294 |
|
5295 | keysShim.shim = function shimObjectKeys() {
|
5296 | if (Object.keys) {
|
5297 | var keysWorksWithArguments = (function () {
|
5298 |
|
5299 | var args = Object.keys(arguments);
|
5300 | return args && args.length === arguments.length;
|
5301 | }(1, 2));
|
5302 | if (!keysWorksWithArguments) {
|
5303 | Object.keys = function keys(object) {
|
5304 | if (isArgs(object)) {
|
5305 | return originalKeys(slice.call(object));
|
5306 | }
|
5307 | return originalKeys(object);
|
5308 | };
|
5309 | }
|
5310 | } else {
|
5311 | Object.keys = keysShim;
|
5312 | }
|
5313 | return Object.keys || keysShim;
|
5314 | };
|
5315 |
|
5316 | var objectKeys = keysShim;
|
5317 |
|
5318 | var keys = objectKeys;
|
5319 | var hasSymbols$2 = typeof Symbol === 'function' && typeof Symbol('foo') === 'symbol';
|
5320 |
|
5321 | var toStr$4 = Object.prototype.toString;
|
5322 | var concat = Array.prototype.concat;
|
5323 | var origDefineProperty = Object.defineProperty;
|
5324 |
|
5325 | var isFunction = function (fn) {
|
5326 | return typeof fn === 'function' && toStr$4.call(fn) === '[object Function]';
|
5327 | };
|
5328 |
|
5329 | var arePropertyDescriptorsSupported = function () {
|
5330 | var obj = {};
|
5331 | try {
|
5332 | origDefineProperty(obj, 'x', { enumerable: false, value: obj });
|
5333 |
|
5334 | for (var _ in obj) {
|
5335 | return false;
|
5336 | }
|
5337 | return obj.x === obj;
|
5338 | } catch (e) {
|
5339 | return false;
|
5340 | }
|
5341 | };
|
5342 | var supportsDescriptors = origDefineProperty && arePropertyDescriptorsSupported();
|
5343 |
|
5344 | var defineProperty = function (object, name, value, predicate) {
|
5345 | if (name in object && (!isFunction(predicate) || !predicate())) {
|
5346 | return;
|
5347 | }
|
5348 | if (supportsDescriptors) {
|
5349 | origDefineProperty(object, name, {
|
5350 | configurable: true,
|
5351 | enumerable: false,
|
5352 | value: value,
|
5353 | writable: true
|
5354 | });
|
5355 | } else {
|
5356 | object[name] = value;
|
5357 | }
|
5358 | };
|
5359 |
|
5360 | var defineProperties = function (object, map) {
|
5361 | var predicates = arguments.length > 2 ? arguments[2] : {};
|
5362 | var props = keys(map);
|
5363 | if (hasSymbols$2) {
|
5364 | props = concat.call(props, Object.getOwnPropertySymbols(map));
|
5365 | }
|
5366 | for (var i = 0; i < props.length; i += 1) {
|
5367 | defineProperty(object, props[i], map[props[i]], predicates[props[i]]);
|
5368 | }
|
5369 | };
|
5370 |
|
5371 | defineProperties.supportsDescriptors = !!supportsDescriptors;
|
5372 |
|
5373 | var defineProperties_1 = defineProperties;
|
5374 |
|
5375 | var GetIntrinsic$6 = getIntrinsic;
|
5376 |
|
5377 | var callBind$4 = callBind$6.exports;
|
5378 |
|
5379 | var $indexOf = callBind$4(GetIntrinsic$6('String.prototype.indexOf'));
|
5380 |
|
5381 | var callBound$4 = function callBoundIntrinsic(name, allowMissing) {
|
5382 | var intrinsic = GetIntrinsic$6(name, !!allowMissing);
|
5383 | if (typeof intrinsic === 'function' && $indexOf(name, '.prototype.') > -1) {
|
5384 | return callBind$4(intrinsic);
|
5385 | }
|
5386 | return intrinsic;
|
5387 | };
|
5388 |
|
5389 | var GetIntrinsic$5 = getIntrinsic;
|
5390 |
|
5391 | var $test = GetIntrinsic$5('RegExp.prototype.test');
|
5392 |
|
5393 | var callBind$3 = callBind$6.exports;
|
5394 |
|
5395 | var regexTester$1 = function regexTester(regex) {
|
5396 | return callBind$3($test, regex);
|
5397 | };
|
5398 |
|
5399 | var isPrimitive$4 = function isPrimitive(value) {
|
5400 | return value === null || (typeof value !== 'function' && typeof value !== 'object');
|
5401 | };
|
5402 |
|
5403 | var isPrimitive$3 = function isPrimitive(value) {
|
5404 | return value === null || (typeof value !== 'function' && typeof value !== 'object');
|
5405 | };
|
5406 |
|
5407 | var fnToStr = Function.prototype.toString;
|
5408 | var reflectApply = typeof Reflect === 'object' && Reflect !== null && Reflect.apply;
|
5409 | var badArrayLike;
|
5410 | var isCallableMarker;
|
5411 | if (typeof reflectApply === 'function' && typeof Object.defineProperty === 'function') {
|
5412 | try {
|
5413 | badArrayLike = Object.defineProperty({}, 'length', {
|
5414 | get: function () {
|
5415 | throw isCallableMarker;
|
5416 | }
|
5417 | });
|
5418 | isCallableMarker = {};
|
5419 |
|
5420 | reflectApply(function () { throw 42; }, null, badArrayLike);
|
5421 | } catch (_) {
|
5422 | if (_ !== isCallableMarker) {
|
5423 | reflectApply = null;
|
5424 | }
|
5425 | }
|
5426 | } else {
|
5427 | reflectApply = null;
|
5428 | }
|
5429 |
|
5430 | var constructorRegex = /^\s*class\b/;
|
5431 | var isES6ClassFn = function isES6ClassFunction(value) {
|
5432 | try {
|
5433 | var fnStr = fnToStr.call(value);
|
5434 | return constructorRegex.test(fnStr);
|
5435 | } catch (e) {
|
5436 | return false;
|
5437 | }
|
5438 | };
|
5439 |
|
5440 | var tryFunctionObject = function tryFunctionToStr(value) {
|
5441 | try {
|
5442 | if (isES6ClassFn(value)) { return false; }
|
5443 | fnToStr.call(value);
|
5444 | return true;
|
5445 | } catch (e) {
|
5446 | return false;
|
5447 | }
|
5448 | };
|
5449 | var toStr$3 = Object.prototype.toString;
|
5450 | var fnClass = '[object Function]';
|
5451 | var genClass = '[object GeneratorFunction]';
|
5452 | var hasToStringTag$1 = typeof Symbol === 'function' && typeof Symbol.toStringTag === 'symbol';
|
5453 |
|
5454 | var documentDotAll = typeof document === 'object' && typeof document.all === 'undefined' && document.all !== undefined ? document.all : {};
|
5455 |
|
5456 | var isCallable$2 = reflectApply
|
5457 | ? function isCallable(value) {
|
5458 | if (value === documentDotAll) { return true; }
|
5459 | if (!value) { return false; }
|
5460 | if (typeof value !== 'function' && typeof value !== 'object') { return false; }
|
5461 | if (typeof value === 'function' && !value.prototype) { return true; }
|
5462 | try {
|
5463 | reflectApply(value, null, badArrayLike);
|
5464 | } catch (e) {
|
5465 | if (e !== isCallableMarker) { return false; }
|
5466 | }
|
5467 | return !isES6ClassFn(value);
|
5468 | }
|
5469 | : function isCallable(value) {
|
5470 | if (value === documentDotAll) { return true; }
|
5471 | if (!value) { return false; }
|
5472 | if (typeof value !== 'function' && typeof value !== 'object') { return false; }
|
5473 | if (typeof value === 'function' && !value.prototype) { return true; }
|
5474 | if (hasToStringTag$1) { return tryFunctionObject(value); }
|
5475 | if (isES6ClassFn(value)) { return false; }
|
5476 | var strClass = toStr$3.call(value);
|
5477 | return strClass === fnClass || strClass === genClass;
|
5478 | };
|
5479 |
|
5480 | var getDay = Date.prototype.getDay;
|
5481 | var tryDateObject = function tryDateGetDayCall(value) {
|
5482 | try {
|
5483 | getDay.call(value);
|
5484 | return true;
|
5485 | } catch (e) {
|
5486 | return false;
|
5487 | }
|
5488 | };
|
5489 |
|
5490 | var toStr$2 = Object.prototype.toString;
|
5491 | var dateClass = '[object Date]';
|
5492 | var hasToStringTag = typeof Symbol === 'function' && !!Symbol.toStringTag;
|
5493 |
|
5494 | var isDateObject = function isDateObject(value) {
|
5495 | if (typeof value !== 'object' || value === null) {
|
5496 | return false;
|
5497 | }
|
5498 | return hasToStringTag ? tryDateObject(value) : toStr$2.call(value) === dateClass;
|
5499 | };
|
5500 |
|
5501 | var isSymbol$1 = {exports: {}};
|
5502 |
|
5503 | var toStr$1 = Object.prototype.toString;
|
5504 | var hasSymbols$1 = hasSymbols$4();
|
5505 |
|
5506 | if (hasSymbols$1) {
|
5507 | var symToStr = Symbol.prototype.toString;
|
5508 | var symStringRegex = /^Symbol\(.*\)$/;
|
5509 | var isSymbolObject = function isRealSymbolObject(value) {
|
5510 | if (typeof value.valueOf() !== 'symbol') {
|
5511 | return false;
|
5512 | }
|
5513 | return symStringRegex.test(symToStr.call(value));
|
5514 | };
|
5515 |
|
5516 | isSymbol$1.exports = function isSymbol(value) {
|
5517 | if (typeof value === 'symbol') {
|
5518 | return true;
|
5519 | }
|
5520 | if (toStr$1.call(value) !== '[object Symbol]') {
|
5521 | return false;
|
5522 | }
|
5523 | try {
|
5524 | return isSymbolObject(value);
|
5525 | } catch (e) {
|
5526 | return false;
|
5527 | }
|
5528 | };
|
5529 | } else {
|
5530 |
|
5531 | isSymbol$1.exports = function isSymbol(value) {
|
5532 |
|
5533 | return false ;
|
5534 | };
|
5535 | }
|
5536 |
|
5537 | var hasSymbols = typeof Symbol === 'function' && typeof Symbol.iterator === 'symbol';
|
5538 |
|
5539 | var isPrimitive$2 = isPrimitive$3;
|
5540 | var isCallable$1 = isCallable$2;
|
5541 | var isDate = isDateObject;
|
5542 | var isSymbol = isSymbol$1.exports;
|
5543 |
|
5544 | var ordinaryToPrimitive = function OrdinaryToPrimitive(O, hint) {
|
5545 | if (typeof O === 'undefined' || O === null) {
|
5546 | throw new TypeError('Cannot call method on ' + O);
|
5547 | }
|
5548 | if (typeof hint !== 'string' || (hint !== 'number' && hint !== 'string')) {
|
5549 | throw new TypeError('hint must be "string" or "number"');
|
5550 | }
|
5551 | var methodNames = hint === 'string' ? ['toString', 'valueOf'] : ['valueOf', 'toString'];
|
5552 | var method, result, i;
|
5553 | for (i = 0; i < methodNames.length; ++i) {
|
5554 | method = O[methodNames[i]];
|
5555 | if (isCallable$1(method)) {
|
5556 | result = method.call(O);
|
5557 | if (isPrimitive$2(result)) {
|
5558 | return result;
|
5559 | }
|
5560 | }
|
5561 | }
|
5562 | throw new TypeError('No default value');
|
5563 | };
|
5564 |
|
5565 | var GetMethod = function GetMethod(O, P) {
|
5566 | var func = O[P];
|
5567 | if (func !== null && typeof func !== 'undefined') {
|
5568 | if (!isCallable$1(func)) {
|
5569 | throw new TypeError(func + ' returned for property ' + P + ' of object ' + O + ' is not a function');
|
5570 | }
|
5571 | return func;
|
5572 | }
|
5573 | return void 0;
|
5574 | };
|
5575 |
|
5576 |
|
5577 | var es2015 = function ToPrimitive(input) {
|
5578 | if (isPrimitive$2(input)) {
|
5579 | return input;
|
5580 | }
|
5581 | var hint = 'default';
|
5582 | if (arguments.length > 1) {
|
5583 | if (arguments[1] === String) {
|
5584 | hint = 'string';
|
5585 | } else if (arguments[1] === Number) {
|
5586 | hint = 'number';
|
5587 | }
|
5588 | }
|
5589 |
|
5590 | var exoticToPrim;
|
5591 | if (hasSymbols) {
|
5592 | if (Symbol.toPrimitive) {
|
5593 | exoticToPrim = GetMethod(input, Symbol.toPrimitive);
|
5594 | } else if (isSymbol(input)) {
|
5595 | exoticToPrim = Symbol.prototype.valueOf;
|
5596 | }
|
5597 | }
|
5598 | if (typeof exoticToPrim !== 'undefined') {
|
5599 | var result = exoticToPrim.call(input, hint);
|
5600 | if (isPrimitive$2(result)) {
|
5601 | return result;
|
5602 | }
|
5603 | throw new TypeError('unable to convert exotic object to primitive');
|
5604 | }
|
5605 | if (hint === 'default' && (isDate(input) || isSymbol(input))) {
|
5606 | hint = 'string';
|
5607 | }
|
5608 | return ordinaryToPrimitive(input, hint === 'default' ? 'number' : hint);
|
5609 | };
|
5610 |
|
5611 | var toPrimitive = es2015;
|
5612 |
|
5613 |
|
5614 |
|
5615 | var ToPrimitive$3 = function ToPrimitive(input) {
|
5616 | if (arguments.length > 1) {
|
5617 | return toPrimitive(input, arguments[1]);
|
5618 | }
|
5619 | return toPrimitive(input);
|
5620 | };
|
5621 |
|
5622 | var GetIntrinsic$4 = getIntrinsic;
|
5623 |
|
5624 | var $TypeError$2 = GetIntrinsic$4('%TypeError%');
|
5625 | var $Number = GetIntrinsic$4('%Number%');
|
5626 | var $RegExp = GetIntrinsic$4('%RegExp%');
|
5627 | var $parseInteger = GetIntrinsic$4('%parseInt%');
|
5628 |
|
5629 | var callBound$3 = callBound$4;
|
5630 | var regexTester = regexTester$1;
|
5631 | var isPrimitive$1 = isPrimitive$4;
|
5632 |
|
5633 | var $strSlice = callBound$3('String.prototype.slice');
|
5634 | var isBinary = regexTester(/^0b[01]+$/i);
|
5635 | var isOctal = regexTester(/^0o[0-7]+$/i);
|
5636 | var isInvalidHexLiteral = regexTester(/^[-+]0x[0-9a-f]+$/i);
|
5637 | var nonWS = ['\u0085', '\u200b', '\ufffe'].join('');
|
5638 | var nonWSregex = new $RegExp('[' + nonWS + ']', 'g');
|
5639 | var hasNonWS = regexTester(nonWSregex);
|
5640 |
|
5641 |
|
5642 |
|
5643 | var ws = [
|
5644 | '\x09\x0A\x0B\x0C\x0D\x20\xA0\u1680\u180E\u2000\u2001\u2002\u2003',
|
5645 | '\u2004\u2005\u2006\u2007\u2008\u2009\u200A\u202F\u205F\u3000\u2028',
|
5646 | '\u2029\uFEFF'
|
5647 | ].join('');
|
5648 | var trimRegex = new RegExp('(^[' + ws + ']+)|([' + ws + ']+$)', 'g');
|
5649 | var $replace = callBound$3('String.prototype.replace');
|
5650 | var $trim = function (value) {
|
5651 | return $replace(value, trimRegex, '');
|
5652 | };
|
5653 |
|
5654 | var ToPrimitive$2 = ToPrimitive$3;
|
5655 |
|
5656 |
|
5657 |
|
5658 | var ToNumber$4 = function ToNumber(argument) {
|
5659 | var value = isPrimitive$1(argument) ? argument : ToPrimitive$2(argument, $Number);
|
5660 | if (typeof value === 'symbol') {
|
5661 | throw new $TypeError$2('Cannot convert a Symbol value to a number');
|
5662 | }
|
5663 | if (typeof value === 'string') {
|
5664 | if (isBinary(value)) {
|
5665 | return ToNumber($parseInteger($strSlice(value, 2), 2));
|
5666 | } else if (isOctal(value)) {
|
5667 | return ToNumber($parseInteger($strSlice(value, 2), 8));
|
5668 | } else if (hasNonWS(value) || isInvalidHexLiteral(value)) {
|
5669 | return NaN;
|
5670 | } else {
|
5671 | var trimmed = $trim(value);
|
5672 | if (trimmed !== value) {
|
5673 | return ToNumber(trimmed);
|
5674 | }
|
5675 | }
|
5676 | }
|
5677 | return $Number(value);
|
5678 | };
|
5679 |
|
5680 | var GetIntrinsic$3 = getIntrinsic;
|
5681 |
|
5682 | var $abs$1 = GetIntrinsic$3('%Math.abs%');
|
5683 |
|
5684 |
|
5685 |
|
5686 | var abs$3 = function abs(x) {
|
5687 | return $abs$1(x);
|
5688 | };
|
5689 |
|
5690 |
|
5691 | var $floor$1 = Math.floor;
|
5692 |
|
5693 |
|
5694 |
|
5695 | var floor$3 = function floor(x) {
|
5696 |
|
5697 | return $floor$1(x);
|
5698 | };
|
5699 |
|
5700 | var _isNaN = Number.isNaN || function isNaN(a) {
|
5701 | return a !== a;
|
5702 | };
|
5703 |
|
5704 | var $isNaN$2 = Number.isNaN || function (a) { return a !== a; };
|
5705 |
|
5706 | var _isFinite = Number.isFinite || function (x) { return typeof x === 'number' && !$isNaN$2(x) && x !== Infinity && x !== -Infinity; };
|
5707 |
|
5708 | var abs$2 = abs$3;
|
5709 | var floor$2 = floor$3;
|
5710 |
|
5711 | var $isNaN$1 = _isNaN;
|
5712 | var $isFinite$1 = _isFinite;
|
5713 |
|
5714 |
|
5715 |
|
5716 | var IsInteger$1 = function IsInteger(argument) {
|
5717 | if (typeof argument !== 'number' || $isNaN$1(argument) || !$isFinite$1(argument)) {
|
5718 | return false;
|
5719 | }
|
5720 | var absValue = abs$2(argument);
|
5721 | return floor$2(absValue) === absValue;
|
5722 | };
|
5723 |
|
5724 |
|
5725 |
|
5726 | var callBound$2 = callBound$4;
|
5727 |
|
5728 |
|
5729 |
|
5730 | var ToNumber$3 = ToNumber$4;
|
5731 | var IsInteger = IsInteger$1;
|
5732 | var callBound$1 = callBound$2;
|
5733 | var callBind$2 = callBind$5;
|
5734 |
|
5735 | var ArrayPush = callBound$1('Array.prototype.push');
|
5736 | var StringFromCharCodeSpread = callBind$2.apply(String.fromCharCode, null);
|
5737 |
|
5738 | var implementation$5 = function fromCodePoint(_ /* fromCodePoint.length is 1 */) {
|
5739 | var MAX_SIZE = 0x4000;
|
5740 | var codeUnits = [];
|
5741 | var highSurrogate;
|
5742 | var lowSurrogate;
|
5743 | var index = -1;
|
5744 | var length = arguments.length;
|
5745 | if (!length) {
|
5746 | return '';
|
5747 | }
|
5748 | var result = '';
|
5749 | while (++index < length) {
|
5750 | var codePoint = ToNumber$3(arguments[index]);
|
5751 | if (
|
5752 | !IsInteger(codePoint) ||
|
5753 | codePoint < 0 || codePoint > 0x10FFFF
|
5754 | ) {
|
5755 | throw RangeError('Invalid code point: ' + codePoint);
|
5756 | }
|
5757 | if (codePoint <= 0xFFFF) {
|
5758 | ArrayPush(codeUnits, codePoint);
|
5759 | } else {
|
5760 |
|
5761 | codePoint -= 0x10000;
|
5762 | highSurrogate = (codePoint >> 10) + 0xD800;
|
5763 | lowSurrogate = (codePoint % 0x400) + 0xDC00;
|
5764 | ArrayPush(codeUnits, highSurrogate, lowSurrogate);
|
5765 | }
|
5766 | if (index + 1 == length || codeUnits.length > MAX_SIZE) {
|
5767 | result += StringFromCharCodeSpread(codeUnits);
|
5768 | codeUnits.length = 0;
|
5769 | }
|
5770 | }
|
5771 | return result;
|
5772 | };
|
5773 |
|
5774 |
|
5775 |
|
5776 | var implementation$4 = implementation$5;
|
5777 |
|
5778 | var polyfill$1 = function getPolyfill() {
|
5779 | return String.fromCodePoint || implementation$4;
|
5780 | };
|
5781 |
|
5782 |
|
5783 |
|
5784 | var define$3 = defineProperties_1;
|
5785 |
|
5786 | var getPolyfill$3 = polyfill$1;
|
5787 |
|
5788 | var shim$3 = function shimFromCodePoint() {
|
5789 | var polyfill = getPolyfill$3();
|
5790 |
|
5791 | if (String.fromCodePoint !== polyfill) {
|
5792 | define$3(String, { fromCodePoint: polyfill });
|
5793 | }
|
5794 |
|
5795 | return polyfill;
|
5796 | };
|
5797 |
|
5798 |
|
5799 |
|
5800 | var callBind$1 = callBind$5;
|
5801 | var define$2 = defineProperties_1;
|
5802 |
|
5803 | var implementation$3 = implementation$5;
|
5804 | var getPolyfill$2 = polyfill$1;
|
5805 | var shim$2 = shim$3;
|
5806 |
|
5807 | var boundFromCodePoint = callBind$1(getPolyfill$2(), String);
|
5808 |
|
5809 | define$2(boundFromCodePoint, {
|
5810 | getPolyfill: getPolyfill$2,
|
5811 | implementation: implementation$3,
|
5812 | shim: shim$2
|
5813 | });
|
5814 |
|
5815 | var GetIntrinsic$2 = getIntrinsic;
|
5816 |
|
5817 | var $TypeError$1 = GetIntrinsic$2('%TypeError%');
|
5818 |
|
5819 |
|
5820 |
|
5821 | var CheckObjectCoercible = function CheckObjectCoercible(value, optMessage) {
|
5822 | if (value == null) {
|
5823 | throw new $TypeError$1(optMessage || ('Cannot call method on ' + value));
|
5824 | }
|
5825 | return value;
|
5826 | };
|
5827 |
|
5828 | var RequireObjectCoercible$1 = CheckObjectCoercible;
|
5829 |
|
5830 | var GetIntrinsic$1 = getIntrinsic;
|
5831 |
|
5832 | var $String = GetIntrinsic$1('%String%');
|
5833 | var $TypeError = GetIntrinsic$1('%TypeError%');
|
5834 |
|
5835 |
|
5836 |
|
5837 | var ToString$1 = function ToString(argument) {
|
5838 | if (typeof argument === 'symbol') {
|
5839 | throw new $TypeError('Cannot convert a Symbol value to a string');
|
5840 | }
|
5841 | return $String(argument);
|
5842 | };
|
5843 |
|
5844 | var GetIntrinsic = getIntrinsic;
|
5845 |
|
5846 | var $abs = GetIntrinsic('%Math.abs%');
|
5847 |
|
5848 |
|
5849 |
|
5850 | var abs$1 = function abs(x) {
|
5851 | return $abs(x);
|
5852 | };
|
5853 |
|
5854 |
|
5855 | var $floor = Math.floor;
|
5856 |
|
5857 |
|
5858 |
|
5859 | var floor$1 = function floor(x) {
|
5860 |
|
5861 | return $floor(x);
|
5862 | };
|
5863 |
|
5864 | var toStr = Object.prototype.toString;
|
5865 |
|
5866 | var isPrimitive = isPrimitive$3;
|
5867 |
|
5868 | var isCallable = isCallable$2;
|
5869 |
|
5870 |
|
5871 | var ES5internalSlots = {
|
5872 | '[[DefaultValue]]': function (O) {
|
5873 | var actualHint;
|
5874 | if (arguments.length > 1) {
|
5875 | actualHint = arguments[1];
|
5876 | } else {
|
5877 | actualHint = toStr.call(O) === '[object Date]' ? String : Number;
|
5878 | }
|
5879 |
|
5880 | if (actualHint === String || actualHint === Number) {
|
5881 | var methods = actualHint === String ? ['toString', 'valueOf'] : ['valueOf', 'toString'];
|
5882 | var value, i;
|
5883 | for (i = 0; i < methods.length; ++i) {
|
5884 | if (isCallable(O[methods[i]])) {
|
5885 | value = O[methods[i]]();
|
5886 | if (isPrimitive(value)) {
|
5887 | return value;
|
5888 | }
|
5889 | }
|
5890 | }
|
5891 | throw new TypeError('No default value');
|
5892 | }
|
5893 | throw new TypeError('invalid [[DefaultValue]] hint supplied');
|
5894 | }
|
5895 | };
|
5896 |
|
5897 |
|
5898 | var es5 = function ToPrimitive(input) {
|
5899 | if (isPrimitive(input)) {
|
5900 | return input;
|
5901 | }
|
5902 | if (arguments.length > 1) {
|
5903 | return ES5internalSlots['[[DefaultValue]]'](input, arguments[1]);
|
5904 | }
|
5905 | return ES5internalSlots['[[DefaultValue]]'](input);
|
5906 | };
|
5907 |
|
5908 |
|
5909 |
|
5910 | var ToPrimitive$1 = es5;
|
5911 |
|
5912 | var ToPrimitive = ToPrimitive$1;
|
5913 |
|
5914 |
|
5915 |
|
5916 | var ToNumber$2 = function ToNumber(value) {
|
5917 | var prim = ToPrimitive(value, Number);
|
5918 | if (typeof prim !== 'string') {
|
5919 | return +prim;
|
5920 | }
|
5921 |
|
5922 |
|
5923 | var trimmed = prim.replace(/^[ \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u0085]+|[ \t\x0b\f\xa0\ufeff\n\r\u2028\u2029\u1680\u180e\u2000\u2001\u2002\u2003\u2004\u2005\u2006\u2007\u2008\u2009\u200a\u202f\u205f\u3000\u0085]+$/g, '');
|
5924 | if ((/^0[ob]|^[+-]0x/).test(trimmed)) {
|
5925 | return NaN;
|
5926 | }
|
5927 |
|
5928 | return +trimmed;
|
5929 | };
|
5930 |
|
5931 | var sign = function sign(number) {
|
5932 | return number >= 0 ? 1 : -1;
|
5933 | };
|
5934 |
|
5935 | var abs = abs$1;
|
5936 | var floor = floor$1;
|
5937 | var ToNumber$1 = ToNumber$2;
|
5938 |
|
5939 | var $isNaN = _isNaN;
|
5940 | var $isFinite = _isFinite;
|
5941 | var $sign = sign;
|
5942 |
|
5943 |
|
5944 |
|
5945 | var ToInteger$2 = function ToInteger(value) {
|
5946 | var number = ToNumber$1(value);
|
5947 | if ($isNaN(number)) { return 0; }
|
5948 | if (number === 0 || !$isFinite(number)) { return number; }
|
5949 | return $sign(number) * floor(abs(number));
|
5950 | };
|
5951 |
|
5952 | var ES5ToInteger = ToInteger$2;
|
5953 |
|
5954 | var ToNumber = ToNumber$4;
|
5955 |
|
5956 |
|
5957 |
|
5958 | var ToInteger$1 = function ToInteger(value) {
|
5959 | var number = ToNumber(value);
|
5960 | return ES5ToInteger(number);
|
5961 | };
|
5962 |
|
5963 |
|
5964 |
|
5965 | var callBound = callBound$2;
|
5966 | var RequireObjectCoercible = RequireObjectCoercible$1;
|
5967 | var ToString = ToString$1;
|
5968 | var ToInteger = ToInteger$1;
|
5969 | var StringCharCodeAt = callBound('String.prototype.charCodeAt');
|
5970 |
|
5971 | var implementation$2 = function codePointAt(position) {
|
5972 | var O = RequireObjectCoercible(this);
|
5973 | var string = ToString(O);
|
5974 | var size = string.length;
|
5975 | var index = ToInteger(position);
|
5976 |
|
5977 | if (index < 0 || index >= size) {
|
5978 | return undefined;
|
5979 | }
|
5980 |
|
5981 | var first = StringCharCodeAt(string, index);
|
5982 | var second;
|
5983 | if (
|
5984 | first >= 0xD800 && first <= 0xDBFF &&
|
5985 | size > index + 1
|
5986 | ) {
|
5987 | second = StringCharCodeAt(string, index + 1);
|
5988 | if (second >= 0xDC00 && second <= 0xDFFF) {
|
5989 |
|
5990 | return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
|
5991 | }
|
5992 | }
|
5993 | return first;
|
5994 | };
|
5995 |
|
5996 |
|
5997 |
|
5998 | var implementation$1 = implementation$2;
|
5999 |
|
6000 | var polyfill = function getPolyfill() {
|
6001 | return String.prototype.codePointAt || implementation$1;
|
6002 | };
|
6003 |
|
6004 |
|
6005 |
|
6006 | var define$1 = defineProperties_1;
|
6007 |
|
6008 | var getPolyfill$1 = polyfill;
|
6009 |
|
6010 | var shim$1 = function shimCodePointAt() {
|
6011 | var polyfill = getPolyfill$1();
|
6012 |
|
6013 | if (String.prototype.codePointAt !== polyfill) {
|
6014 | define$1(String.prototype, { codePointAt: polyfill });
|
6015 | }
|
6016 |
|
6017 | return polyfill;
|
6018 | };
|
6019 |
|
6020 |
|
6021 |
|
6022 | var callBind = callBind$5;
|
6023 | var define = defineProperties_1;
|
6024 |
|
6025 | var implementation = implementation$2;
|
6026 | var getPolyfill = polyfill;
|
6027 | var shim = shim$1;
|
6028 |
|
6029 | var boundCodePointAt = callBind(getPolyfill());
|
6030 |
|
6031 | define(boundCodePointAt, {
|
6032 | getPolyfill: getPolyfill,
|
6033 | implementation: implementation,
|
6034 | shim: shim
|
6035 | });
|
6036 |
|
6037 |
|
6038 |
|
6039 | const path = path__default['default'];
|
6040 | const fs = require$$0__default$1['default'];
|
6041 |
|
6042 |
|
6043 |
|
6044 |
|
6045 | function getMetadataService(options = {}) {
|
6046 | let usedUnicodes = [];
|
6047 |
|
6048 |
|
6049 | options.prependUnicode = !!options.prependUnicode;
|
6050 | options.startUnicode =
|
6051 | 'number' === typeof options.startUnicode ? options.startUnicode : 0xea01;
|
6052 | options.log = options.log || console.log;
|
6053 | options.err = options.err || console.err;
|
6054 |
|
6055 |
|
6056 | if ('undefined' !== typeof options.appendUnicode) {
|
6057 | throw new Error(
|
6058 | 'The "appendUnicode" option was renamed "prependUnicode".' +
|
6059 | ' See https://github.com/nfroidure/gulp-svgicons2svgfont/issues/33'
|
6060 | );
|
6061 | }
|
6062 |
|
6063 | return function getMetadataFromFile(file, cb) {
|
6064 | const basename = path.basename(file);
|
6065 | const metadata = {
|
6066 | path: file,
|
6067 | name: '',
|
6068 | unicode: [],
|
6069 | renamed: false,
|
6070 | };
|
6071 | const matches = basename.match(/^(?:((?:u[0-9a-f]{4,6},?)+)-)?(.+)\.svg$/i);
|
6072 |
|
6073 | metadata.name =
|
6074 | matches && matches[2] ? matches[2] : 'icon' + options.startUnicode;
|
6075 | if (matches && matches[1]) {
|
6076 | metadata.unicode = matches[1].split(',').map((match) => {
|
6077 | match = match.substr(1);
|
6078 | return match
|
6079 | .split('u')
|
6080 | .map((code) => String.fromCodePoint(parseInt(code, 16)))
|
6081 | .join('');
|
6082 | });
|
6083 | if (-1 !== usedUnicodes.indexOf(metadata.unicode[0])) {
|
6084 | cb(
|
6085 | new Error(
|
6086 | 'The unicode codepoint of the glyph ' +
|
6087 | metadata.name +
|
6088 | ' seems to be already used by another glyph.'
|
6089 | )
|
6090 | );
|
6091 | return;
|
6092 | }
|
6093 | usedUnicodes.push(...metadata.unicode);
|
6094 | } else {
|
6095 | do {
|
6096 | metadata.unicode[0] = String.fromCodePoint(options.startUnicode++);
|
6097 | } while (usedUnicodes.includes(metadata.unicode[0]));
|
6098 | usedUnicodes.push(metadata.unicode[0]);
|
6099 | if (options.prependUnicode) {
|
6100 | metadata.renamed = true;
|
6101 | metadata.path = path.join(
|
6102 | path.dirname(file),
|
6103 | 'u' +
|
6104 | metadata.unicode[0].codePointAt(0).toString(16).toUpperCase() +
|
6105 | '-' +
|
6106 | basename
|
6107 | );
|
6108 | fs.rename(file, metadata.path, (err) => {
|
6109 | if (err) {
|
6110 | cb(
|
6111 | new Error(
|
6112 | 'Could not save codepoint: ' +
|
6113 | 'u' +
|
6114 | metadata.unicode[0]
|
6115 | .codePointAt(0)
|
6116 | .toString(16)
|
6117 | .toUpperCase() +
|
6118 | ' for ' +
|
6119 | basename
|
6120 | )
|
6121 | );
|
6122 | return;
|
6123 | }
|
6124 | cb(null, metadata);
|
6125 | });
|
6126 | }
|
6127 | }
|
6128 | if (!metadata.renamed) {
|
6129 | setImmediate(() => cb(null, metadata));
|
6130 | }
|
6131 | };
|
6132 | }
|
6133 |
|
6134 | var metadata = getMetadataService;
|
6135 |
|
6136 | var buildConfig = function (options) { return __awaiter(void 0, void 0, void 0, function () {
|
6137 | var searchPath, configPath, configExplorer, config;
|
6138 | return __generator(this, function (_a) {
|
6139 | switch (_a.label) {
|
6140 | case 0:
|
6141 | searchPath = process.cwd();
|
6142 | configPath = null;
|
6143 | if (options.configFile) {
|
6144 | searchPath = null;
|
6145 | configPath = path__default['default'].resolve(process.cwd(), options.configFile);
|
6146 | }
|
6147 | configExplorer = dist("webfont");
|
6148 | return [4 , configExplorer.search(searchPath)];
|
6149 | case 1:
|
6150 | config = _a.sent();
|
6151 | if (!configPath) return [3 , 3];
|
6152 | return [4 , configExplorer.load(configPath)];
|
6153 | case 2:
|
6154 | config = _a.sent();
|
6155 | _a.label = 3;
|
6156 | case 3:
|
6157 | if (!config) {
|
6158 | return [2 , {}];
|
6159 | }
|
6160 | return [2 , config];
|
6161 | }
|
6162 | });
|
6163 | }); };
|
6164 | var getGlyphsData = function (files, options) {
|
6165 | var metadataProvider = options.metadataProvider ||
|
6166 | metadata({
|
6167 | prependUnicode: options.prependUnicode,
|
6168 | startUnicode: options.startUnicode
|
6169 | });
|
6170 | var xmlParser = new xml2js__default['default'].Parser();
|
6171 | var throttle = pLimit__default['default'](options.maxConcurrency);
|
6172 | return Promise.all(files.map(function (srcPath) { return throttle(function () { return new Promise(function (resolve, reject) {
|
6173 | var glyph = require$$0__default$1['default'].createReadStream(srcPath);
|
6174 | var glyphContents = "";
|
6175 |
|
6176 | return glyph.
|
6177 | on("error", function (glyphError) { return reject(glyphError); }).
|
6178 | on("data", function (data) {
|
6179 | glyphContents += data.toString();
|
6180 | }).
|
6181 | on("end", function () {
|
6182 |
|
6183 | if (glyphContents.length === 0) {
|
6184 | return reject(new Error("Empty file " + srcPath));
|
6185 | }
|
6186 | return xmlParser.parseString(glyphContents, function (error) {
|
6187 | if (error) {
|
6188 | return reject(error);
|
6189 | }
|
6190 | var glyphData = {
|
6191 | contents: glyphContents,
|
6192 | srcPath: srcPath
|
6193 | };
|
6194 | return resolve(glyphData);
|
6195 | });
|
6196 | });
|
6197 | }); }); })).then(function (glyphsData) {
|
6198 | var sortedGlyphsData = glyphsData;
|
6199 | if (options.sort) {
|
6200 | var sortCallback = function (fileA, fileB) { return filesorter(fileA.srcPath, fileB.srcPath); };
|
6201 | sortedGlyphsData = glyphsData.sort(sortCallback);
|
6202 | }
|
6203 | return Promise.all(sortedGlyphsData.map(function (glyphData) { return new Promise(function (resolve, reject) {
|
6204 | metadataProvider(glyphData.srcPath, function (error, metadata) {
|
6205 | if (error) {
|
6206 | return reject(error);
|
6207 | }
|
6208 | metadata.unicode.push(metadata.name.replace(/-/gu, "_"));
|
6209 | glyphData.metadata = metadata;
|
6210 | return resolve(glyphData);
|
6211 | });
|
6212 | }); }));
|
6213 | });
|
6214 | };
|
6215 | var toSvg = function (glyphsData, options) {
|
6216 | var result = "";
|
6217 | return new Promise(function (resolve, reject) {
|
6218 | var log = function () {
|
6219 | Function.prototype();
|
6220 | };
|
6221 | if (options.verbose) {
|
6222 |
|
6223 | log = console.log.bind(console);
|
6224 | }
|
6225 | var fontStream = new SVGIcons2SVGFontStream__default['default']({
|
6226 | ascent: options.ascent,
|
6227 | centerHorizontally: options.centerHorizontally,
|
6228 | descent: options.descent,
|
6229 | fixedWidth: options.fixedWidth,
|
6230 | fontHeight: options.fontHeight,
|
6231 | fontId: options.fontId,
|
6232 | fontName: options.fontName,
|
6233 | fontStyle: options.fontStyle,
|
6234 | fontWeight: options.fontWeight,
|
6235 | log: log,
|
6236 | metadata: options.metadata,
|
6237 | normalize: options.normalize,
|
6238 | round: options.round
|
6239 | }).
|
6240 | on("finish", function () { return resolve(result); }).
|
6241 | on("data", function (data) {
|
6242 | result += data;
|
6243 | }).
|
6244 | on("error", function (error) { return reject(error); });
|
6245 | glyphsData.forEach(function (glyphData) {
|
6246 | var glyphStream = new stream.Readable();
|
6247 | glyphStream.push(glyphData.contents);
|
6248 | glyphStream.push(null);
|
6249 |
|
6250 |
|
6251 | glyphStream.metadata = glyphData.metadata;
|
6252 | fontStream.write(glyphStream);
|
6253 | });
|
6254 | fontStream.end();
|
6255 | });
|
6256 | };
|
6257 | var toTtf = function (buffer, options) { return Buffer.from(svg2ttf__default['default'](buffer, options).buffer); };
|
6258 | var toEot = function (buffer) { return Buffer.from(ttf2eot__default['default'](buffer).buffer); };
|
6259 | var toWoff = function (buffer, options) { return Buffer.from(ttf2woff__default['default'](buffer, options).buffer); };
|
6260 | var toWoff2 = function (buffer) { return wawoff2__default['default'].compress(buffer); };
|
6261 | var webfont = function (initialOptions) { return __awaiter(void 0, void 0, void 0, function () {
|
6262 | var options, config, foundFiles, filteredFiles, result, _a, _b, ttfOptions, _c, builtInTemplates, templateFilePath, builtInPath, resolvedTemplateFilePath, hashOption, nunjucksOptions;
|
6263 | return __generator(this, function (_d) {
|
6264 | switch (_d.label) {
|
6265 | case 0:
|
6266 | if (!initialOptions || !initialOptions.files) {
|
6267 | throw new Error("You must pass webfont a `files` glob");
|
6268 | }
|
6269 | options = __assign({ centerHorizontally: false, descent: 0, fixedWidth: false, fontHeight: null, fontId: null, fontName: "webfont", fontStyle: "", fontWeight: "", formats: ["svg", "ttf", "eot", "woff", "woff2"], formatsOptions: {
|
6270 | ttf: {
|
6271 | copyright: null,
|
6272 | ts: null,
|
6273 | version: null
|
6274 | }
|
6275 | }, glyphTransformFn: null,
|
6276 | |
6277 |
|
6278 |
|
6279 |
|
6280 | maxConcurrency: 100, metadata: null, metadataProvider: null, normalize: false, prependUnicode: false, round: 10e12, sort: true, startUnicode: 0xea01, template: null, templateCacheString: null, templateClassName: null, templateFontName: null, templateFontPath: "./", verbose: false }, initialOptions);
|
6281 | return [4 , buildConfig({
|
6282 | configFile: options.configFile
|
6283 | })];
|
6284 | case 1:
|
6285 | config = _d.sent();
|
6286 | if (Object.keys(config).length > 0) {
|
6287 |
|
6288 | options = deepmerge__default['default'](options, config.config, {
|
6289 | arrayMerge: function (_destinationArray, sourceArray) { return sourceArray; }
|
6290 | });
|
6291 |
|
6292 | options.filePath = config.filepath;
|
6293 | }
|
6294 | return [4 , globby__default['default']([].concat(options.files))];
|
6295 | case 2:
|
6296 | foundFiles = _d.sent();
|
6297 | filteredFiles = foundFiles.filter(function (foundFile) { return path__default['default'].extname(foundFile) === ".svg"; });
|
6298 | if (filteredFiles.length === 0) {
|
6299 | throw new Error("Files glob patterns specified did not match any files");
|
6300 | }
|
6301 | result = {};
|
6302 | _a = result;
|
6303 | return [4 , getGlyphsData(filteredFiles, options)];
|
6304 | case 3:
|
6305 | _a.glyphsData = (_d.sent());
|
6306 | _b = result;
|
6307 | return [4 , toSvg(result.glyphsData, options)];
|
6308 | case 4:
|
6309 | _b.svg = (_d.sent());
|
6310 | ttfOptions = {};
|
6311 | if (options.formatsOptions && options.formatsOptions.ttf) {
|
6312 | ttfOptions = options.formatsOptions.ttf;
|
6313 | }
|
6314 | result.ttf = toTtf(result.svg, ttfOptions);
|
6315 | result.hash = crypto__default['default'].createHash("md5").update(result.svg).
|
6316 | digest("hex");
|
6317 | if (options.formats.includes("eot")) {
|
6318 | result.eot = toEot(result.ttf);
|
6319 | }
|
6320 | if (options.formats.includes("woff")) {
|
6321 | result.woff = toWoff(result.ttf, { metadata: options.metadata });
|
6322 | }
|
6323 | if (!options.formats.includes("woff2")) return [3 , 6];
|
6324 | _c = result;
|
6325 | return [4 , toWoff2(result.ttf)];
|
6326 | case 5:
|
6327 | _c.woff2 = _d.sent();
|
6328 | _d.label = 6;
|
6329 | case 6:
|
6330 | if (options.template) {
|
6331 | builtInTemplates = getBuiltInTemplates();
|
6332 | templateFilePath = void 0;
|
6333 | if (Object.keys(builtInTemplates).includes(options.template)) {
|
6334 | result.usedBuildInTemplate = true;
|
6335 | builtInPath = path__default['default'].resolve(__dirname, "../..");
|
6336 | nunjucks__default['default'].configure(builtInPath);
|
6337 | templateFilePath = getTemplateFilePath(options.template);
|
6338 | }
|
6339 | else {
|
6340 | resolvedTemplateFilePath = path__default['default'].resolve(options.template);
|
6341 | nunjucks__default['default'].configure(path__default['default'].dirname(resolvedTemplateFilePath));
|
6342 | templateFilePath = path__default['default'].resolve(resolvedTemplateFilePath);
|
6343 | }
|
6344 | hashOption = {};
|
6345 | if (options.addHashInFontUrl) {
|
6346 | hashOption = { hash: result.hash };
|
6347 | }
|
6348 | nunjucksOptions = deepmerge__default['default'].all([
|
6349 | {
|
6350 | glyphs: result.glyphsData.map(function (glyphData) {
|
6351 | if (typeof options.glyphTransformFn === "function") {
|
6352 | glyphData.metadata = options.glyphTransformFn(glyphData.metadata);
|
6353 | }
|
6354 | return glyphData.metadata;
|
6355 | })
|
6356 | },
|
6357 | options,
|
6358 | {
|
6359 | cacheString: options.templateCacheString || Date.now(),
|
6360 | className: options.templateClassName || options.fontName,
|
6361 | fontName: options.templateFontName || options.fontName,
|
6362 | fontPath: options.templateFontPath.replace(/\/?$/u, "/")
|
6363 | },
|
6364 | hashOption,
|
6365 | ]);
|
6366 | result.template = nunjucks__default['default'].render(templateFilePath, nunjucksOptions);
|
6367 | }
|
6368 | if (!options.formats.includes("svg")) {
|
6369 | delete result.svg;
|
6370 | }
|
6371 | if (!options.formats.includes("ttf")) {
|
6372 | delete result.ttf;
|
6373 | }
|
6374 | result.config = options;
|
6375 | return [2 , result];
|
6376 | }
|
6377 | });
|
6378 | }); };
|
6379 |
|
6380 | exports.default = webfont;
|
6381 | exports.webfont = webfont;
|