@digipair/skill-yaml 0.55.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/index.cjs.js ADDED
@@ -0,0 +1,1542 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ /*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */ function _instanceof(left, right) {
6
+ if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
7
+ return !!right[Symbol.hasInstance](left);
8
+ } else {
9
+ return left instanceof right;
10
+ }
11
+ }
12
+ function isNothing(subject) {
13
+ return typeof subject === "undefined" || subject === null;
14
+ }
15
+ function isObject(subject) {
16
+ return typeof subject === "object" && subject !== null;
17
+ }
18
+ function toArray(sequence) {
19
+ if (Array.isArray(sequence)) return sequence;
20
+ else if (isNothing(sequence)) return [];
21
+ return [
22
+ sequence
23
+ ];
24
+ }
25
+ function extend(target, source) {
26
+ var index, length, key, sourceKeys;
27
+ if (source) {
28
+ sourceKeys = Object.keys(source);
29
+ for(index = 0, length = sourceKeys.length; index < length; index += 1){
30
+ key = sourceKeys[index];
31
+ target[key] = source[key];
32
+ }
33
+ }
34
+ return target;
35
+ }
36
+ function repeat(string, count) {
37
+ var result = "", cycle;
38
+ for(cycle = 0; cycle < count; cycle += 1){
39
+ result += string;
40
+ }
41
+ return result;
42
+ }
43
+ function isNegativeZero(number) {
44
+ return number === 0 && Number.NEGATIVE_INFINITY === 1 / number;
45
+ }
46
+ var isNothing_1 = isNothing;
47
+ var isObject_1 = isObject;
48
+ var toArray_1 = toArray;
49
+ var repeat_1 = repeat;
50
+ var isNegativeZero_1 = isNegativeZero;
51
+ var extend_1 = extend;
52
+ var common = {
53
+ isNothing: isNothing_1,
54
+ isObject: isObject_1,
55
+ toArray: toArray_1,
56
+ repeat: repeat_1,
57
+ isNegativeZero: isNegativeZero_1,
58
+ extend: extend_1
59
+ };
60
+ // YAML error class. http://stackoverflow.com/questions/8458984
61
+ function formatError(exception, compact) {
62
+ var where = "", message = exception.reason || "(unknown reason)";
63
+ if (!exception.mark) return message;
64
+ if (exception.mark.name) {
65
+ where += 'in "' + exception.mark.name + '" ';
66
+ }
67
+ where += "(" + (exception.mark.line + 1) + ":" + (exception.mark.column + 1) + ")";
68
+ if (!compact && exception.mark.snippet) {
69
+ where += "\n\n" + exception.mark.snippet;
70
+ }
71
+ return message + " " + where;
72
+ }
73
+ function YAMLException$1(reason, mark) {
74
+ // Super constructor
75
+ Error.call(this);
76
+ this.name = "YAMLException";
77
+ this.reason = reason;
78
+ this.mark = mark;
79
+ this.message = formatError(this, false);
80
+ // Include stack trace in error object
81
+ if (Error.captureStackTrace) {
82
+ // Chrome and NodeJS
83
+ Error.captureStackTrace(this, this.constructor);
84
+ } else {
85
+ // FF, IE 10+ and Safari 6+. Fallback for others
86
+ this.stack = new Error().stack || "";
87
+ }
88
+ }
89
+ // Inherit from Error
90
+ YAMLException$1.prototype = Object.create(Error.prototype);
91
+ YAMLException$1.prototype.constructor = YAMLException$1;
92
+ YAMLException$1.prototype.toString = function toString(compact) {
93
+ return this.name + ": " + formatError(this, compact);
94
+ };
95
+ var exception = YAMLException$1;
96
+ var TYPE_CONSTRUCTOR_OPTIONS = [
97
+ "kind",
98
+ "multi",
99
+ "resolve",
100
+ "construct",
101
+ "instanceOf",
102
+ "predicate",
103
+ "represent",
104
+ "representName",
105
+ "defaultStyle",
106
+ "styleAliases"
107
+ ];
108
+ var YAML_NODE_KINDS = [
109
+ "scalar",
110
+ "sequence",
111
+ "mapping"
112
+ ];
113
+ function compileStyleAliases(map) {
114
+ var result = {};
115
+ if (map !== null) {
116
+ Object.keys(map).forEach(function(style) {
117
+ map[style].forEach(function(alias) {
118
+ result[String(alias)] = style;
119
+ });
120
+ });
121
+ }
122
+ return result;
123
+ }
124
+ function Type$1(tag, options) {
125
+ options = options || {};
126
+ Object.keys(options).forEach(function(name) {
127
+ if (TYPE_CONSTRUCTOR_OPTIONS.indexOf(name) === -1) {
128
+ throw new exception('Unknown option "' + name + '" is met in definition of "' + tag + '" YAML type.');
129
+ }
130
+ });
131
+ // TODO: Add tag format check.
132
+ this.options = options; // keep original options in case user wants to extend this type later
133
+ this.tag = tag;
134
+ this.kind = options["kind"] || null;
135
+ this.resolve = options["resolve"] || function() {
136
+ return true;
137
+ };
138
+ this.construct = options["construct"] || function(data) {
139
+ return data;
140
+ };
141
+ this.instanceOf = options["instanceOf"] || null;
142
+ this.predicate = options["predicate"] || null;
143
+ this.represent = options["represent"] || null;
144
+ this.representName = options["representName"] || null;
145
+ this.defaultStyle = options["defaultStyle"] || null;
146
+ this.multi = options["multi"] || false;
147
+ this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
148
+ if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
149
+ throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
150
+ }
151
+ }
152
+ var type = Type$1;
153
+ /*eslint-disable max-len*/ function compileList(schema, name) {
154
+ var result = [];
155
+ schema[name].forEach(function(currentType) {
156
+ var newIndex = result.length;
157
+ result.forEach(function(previousType, previousIndex) {
158
+ if (previousType.tag === currentType.tag && previousType.kind === currentType.kind && previousType.multi === currentType.multi) {
159
+ newIndex = previousIndex;
160
+ }
161
+ });
162
+ result[newIndex] = currentType;
163
+ });
164
+ return result;
165
+ }
166
+ function compileMap() {
167
+ var result = {
168
+ scalar: {},
169
+ sequence: {},
170
+ mapping: {},
171
+ fallback: {},
172
+ multi: {
173
+ scalar: [],
174
+ sequence: [],
175
+ mapping: [],
176
+ fallback: []
177
+ }
178
+ }, index, length;
179
+ function collectType(type) {
180
+ if (type.multi) {
181
+ result.multi[type.kind].push(type);
182
+ result.multi["fallback"].push(type);
183
+ } else {
184
+ result[type.kind][type.tag] = result["fallback"][type.tag] = type;
185
+ }
186
+ }
187
+ for(index = 0, length = arguments.length; index < length; index += 1){
188
+ arguments[index].forEach(collectType);
189
+ }
190
+ return result;
191
+ }
192
+ function Schema$1(definition) {
193
+ return this.extend(definition);
194
+ }
195
+ Schema$1.prototype.extend = function extend(definition) {
196
+ var implicit = [];
197
+ var explicit = [];
198
+ if (_instanceof(definition, type)) {
199
+ // Schema.extend(type)
200
+ explicit.push(definition);
201
+ } else if (Array.isArray(definition)) {
202
+ // Schema.extend([ type1, type2, ... ])
203
+ explicit = explicit.concat(definition);
204
+ } else if (definition && (Array.isArray(definition.implicit) || Array.isArray(definition.explicit))) {
205
+ // Schema.extend({ explicit: [ type1, type2, ... ], implicit: [ type1, type2, ... ] })
206
+ if (definition.implicit) implicit = implicit.concat(definition.implicit);
207
+ if (definition.explicit) explicit = explicit.concat(definition.explicit);
208
+ } else {
209
+ throw new exception("Schema.extend argument should be a Type, [ Type ], " + "or a schema definition ({ implicit: [...], explicit: [...] })");
210
+ }
211
+ implicit.forEach(function(type$1) {
212
+ if (!_instanceof(type$1, type)) {
213
+ throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
214
+ }
215
+ if (type$1.loadKind && type$1.loadKind !== "scalar") {
216
+ throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
217
+ }
218
+ if (type$1.multi) {
219
+ throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
220
+ }
221
+ });
222
+ explicit.forEach(function(type$1) {
223
+ if (!_instanceof(type$1, type)) {
224
+ throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
225
+ }
226
+ });
227
+ var result = Object.create(Schema$1.prototype);
228
+ result.implicit = (this.implicit || []).concat(implicit);
229
+ result.explicit = (this.explicit || []).concat(explicit);
230
+ result.compiledImplicit = compileList(result, "implicit");
231
+ result.compiledExplicit = compileList(result, "explicit");
232
+ result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
233
+ return result;
234
+ };
235
+ var schema = Schema$1;
236
+ var str = new type("tag:yaml.org,2002:str", {
237
+ kind: "scalar",
238
+ construct: function construct(data) {
239
+ return data !== null ? data : "";
240
+ }
241
+ });
242
+ var seq = new type("tag:yaml.org,2002:seq", {
243
+ kind: "sequence",
244
+ construct: function construct(data) {
245
+ return data !== null ? data : [];
246
+ }
247
+ });
248
+ var map = new type("tag:yaml.org,2002:map", {
249
+ kind: "mapping",
250
+ construct: function construct(data) {
251
+ return data !== null ? data : {};
252
+ }
253
+ });
254
+ var failsafe = new schema({
255
+ explicit: [
256
+ str,
257
+ seq,
258
+ map
259
+ ]
260
+ });
261
+ function resolveYamlNull(data) {
262
+ if (data === null) return true;
263
+ var max = data.length;
264
+ return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
265
+ }
266
+ function constructYamlNull() {
267
+ return null;
268
+ }
269
+ function isNull(object) {
270
+ return object === null;
271
+ }
272
+ var _null = new type("tag:yaml.org,2002:null", {
273
+ kind: "scalar",
274
+ resolve: resolveYamlNull,
275
+ construct: constructYamlNull,
276
+ predicate: isNull,
277
+ represent: {
278
+ canonical: function canonical() {
279
+ return "~";
280
+ },
281
+ lowercase: function lowercase() {
282
+ return "null";
283
+ },
284
+ uppercase: function uppercase() {
285
+ return "NULL";
286
+ },
287
+ camelcase: function camelcase() {
288
+ return "Null";
289
+ },
290
+ empty: function empty() {
291
+ return "";
292
+ }
293
+ },
294
+ defaultStyle: "lowercase"
295
+ });
296
+ function resolveYamlBoolean(data) {
297
+ if (data === null) return false;
298
+ var max = data.length;
299
+ return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
300
+ }
301
+ function constructYamlBoolean(data) {
302
+ return data === "true" || data === "True" || data === "TRUE";
303
+ }
304
+ function isBoolean(object) {
305
+ return Object.prototype.toString.call(object) === "[object Boolean]";
306
+ }
307
+ var bool = new type("tag:yaml.org,2002:bool", {
308
+ kind: "scalar",
309
+ resolve: resolveYamlBoolean,
310
+ construct: constructYamlBoolean,
311
+ predicate: isBoolean,
312
+ represent: {
313
+ lowercase: function lowercase(object) {
314
+ return object ? "true" : "false";
315
+ },
316
+ uppercase: function uppercase(object) {
317
+ return object ? "TRUE" : "FALSE";
318
+ },
319
+ camelcase: function camelcase(object) {
320
+ return object ? "True" : "False";
321
+ }
322
+ },
323
+ defaultStyle: "lowercase"
324
+ });
325
+ function isHexCode(c) {
326
+ return 0x30 /* 0 */ <= c && c <= 0x39 /* 9 */ || 0x41 /* A */ <= c && c <= 0x46 /* F */ || 0x61 /* a */ <= c && c <= 0x66 /* f */ ;
327
+ }
328
+ function isOctCode(c) {
329
+ return 0x30 /* 0 */ <= c && c <= 0x37 /* 7 */ ;
330
+ }
331
+ function isDecCode(c) {
332
+ return 0x30 /* 0 */ <= c && c <= 0x39 /* 9 */ ;
333
+ }
334
+ function resolveYamlInteger(data) {
335
+ if (data === null) return false;
336
+ var max = data.length, index = 0, hasDigits = false, ch;
337
+ if (!max) return false;
338
+ ch = data[index];
339
+ // sign
340
+ if (ch === "-" || ch === "+") {
341
+ ch = data[++index];
342
+ }
343
+ if (ch === "0") {
344
+ // 0
345
+ if (index + 1 === max) return true;
346
+ ch = data[++index];
347
+ // base 2, base 8, base 16
348
+ if (ch === "b") {
349
+ // base 2
350
+ index++;
351
+ for(; index < max; index++){
352
+ ch = data[index];
353
+ if (ch === "_") continue;
354
+ if (ch !== "0" && ch !== "1") return false;
355
+ hasDigits = true;
356
+ }
357
+ return hasDigits && ch !== "_";
358
+ }
359
+ if (ch === "x") {
360
+ // base 16
361
+ index++;
362
+ for(; index < max; index++){
363
+ ch = data[index];
364
+ if (ch === "_") continue;
365
+ if (!isHexCode(data.charCodeAt(index))) return false;
366
+ hasDigits = true;
367
+ }
368
+ return hasDigits && ch !== "_";
369
+ }
370
+ if (ch === "o") {
371
+ // base 8
372
+ index++;
373
+ for(; index < max; index++){
374
+ ch = data[index];
375
+ if (ch === "_") continue;
376
+ if (!isOctCode(data.charCodeAt(index))) return false;
377
+ hasDigits = true;
378
+ }
379
+ return hasDigits && ch !== "_";
380
+ }
381
+ }
382
+ // base 10 (except 0)
383
+ // value should not start with `_`;
384
+ if (ch === "_") return false;
385
+ for(; index < max; index++){
386
+ ch = data[index];
387
+ if (ch === "_") continue;
388
+ if (!isDecCode(data.charCodeAt(index))) {
389
+ return false;
390
+ }
391
+ hasDigits = true;
392
+ }
393
+ // Should have digits and should not end with `_`
394
+ if (!hasDigits || ch === "_") return false;
395
+ return true;
396
+ }
397
+ function constructYamlInteger(data) {
398
+ var value = data, sign = 1, ch;
399
+ if (value.indexOf("_") !== -1) {
400
+ value = value.replace(/_/g, "");
401
+ }
402
+ ch = value[0];
403
+ if (ch === "-" || ch === "+") {
404
+ if (ch === "-") sign = -1;
405
+ value = value.slice(1);
406
+ ch = value[0];
407
+ }
408
+ if (value === "0") return 0;
409
+ if (ch === "0") {
410
+ if (value[1] === "b") return sign * parseInt(value.slice(2), 2);
411
+ if (value[1] === "x") return sign * parseInt(value.slice(2), 16);
412
+ if (value[1] === "o") return sign * parseInt(value.slice(2), 8);
413
+ }
414
+ return sign * parseInt(value, 10);
415
+ }
416
+ function isInteger(object) {
417
+ return Object.prototype.toString.call(object) === "[object Number]" && object % 1 === 0 && !common.isNegativeZero(object);
418
+ }
419
+ var int = new type("tag:yaml.org,2002:int", {
420
+ kind: "scalar",
421
+ resolve: resolveYamlInteger,
422
+ construct: constructYamlInteger,
423
+ predicate: isInteger,
424
+ represent: {
425
+ binary: function binary(obj) {
426
+ return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
427
+ },
428
+ octal: function octal(obj) {
429
+ return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
430
+ },
431
+ decimal: function decimal(obj) {
432
+ return obj.toString(10);
433
+ },
434
+ /* eslint-disable max-len */ hexadecimal: function hexadecimal(obj) {
435
+ return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
436
+ }
437
+ },
438
+ defaultStyle: "decimal",
439
+ styleAliases: {
440
+ binary: [
441
+ 2,
442
+ "bin"
443
+ ],
444
+ octal: [
445
+ 8,
446
+ "oct"
447
+ ],
448
+ decimal: [
449
+ 10,
450
+ "dec"
451
+ ],
452
+ hexadecimal: [
453
+ 16,
454
+ "hex"
455
+ ]
456
+ }
457
+ });
458
+ var YAML_FLOAT_PATTERN = new RegExp(// 2.5e4, 2.5 and integers
459
+ "^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?" + // .2e4, .2
460
+ // special case, seems not from spec
461
+ "|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?" + // .inf
462
+ "|[-+]?\\.(?:inf|Inf|INF)" + // .nan
463
+ "|\\.(?:nan|NaN|NAN))$");
464
+ function resolveYamlFloat(data) {
465
+ if (data === null) return false;
466
+ if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
467
+ // Probably should update regexp & check speed
468
+ data[data.length - 1] === "_") {
469
+ return false;
470
+ }
471
+ return true;
472
+ }
473
+ function constructYamlFloat(data) {
474
+ var value, sign;
475
+ value = data.replace(/_/g, "").toLowerCase();
476
+ sign = value[0] === "-" ? -1 : 1;
477
+ if ("+-".indexOf(value[0]) >= 0) {
478
+ value = value.slice(1);
479
+ }
480
+ if (value === ".inf") {
481
+ return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
482
+ } else if (value === ".nan") {
483
+ return NaN;
484
+ }
485
+ return sign * parseFloat(value, 10);
486
+ }
487
+ var SCIENTIFIC_WITHOUT_DOT = /^[-+]?[0-9]+e/;
488
+ function representYamlFloat(object, style) {
489
+ var res;
490
+ if (isNaN(object)) {
491
+ switch(style){
492
+ case "lowercase":
493
+ return ".nan";
494
+ case "uppercase":
495
+ return ".NAN";
496
+ case "camelcase":
497
+ return ".NaN";
498
+ }
499
+ } else if (Number.POSITIVE_INFINITY === object) {
500
+ switch(style){
501
+ case "lowercase":
502
+ return ".inf";
503
+ case "uppercase":
504
+ return ".INF";
505
+ case "camelcase":
506
+ return ".Inf";
507
+ }
508
+ } else if (Number.NEGATIVE_INFINITY === object) {
509
+ switch(style){
510
+ case "lowercase":
511
+ return "-.inf";
512
+ case "uppercase":
513
+ return "-.INF";
514
+ case "camelcase":
515
+ return "-.Inf";
516
+ }
517
+ } else if (common.isNegativeZero(object)) {
518
+ return "-0.0";
519
+ }
520
+ res = object.toString(10);
521
+ // JS stringifier can build scientific format without dots: 5e-100,
522
+ // while YAML requres dot: 5.e-100. Fix it with simple hack
523
+ return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
524
+ }
525
+ function isFloat(object) {
526
+ return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
527
+ }
528
+ var float = new type("tag:yaml.org,2002:float", {
529
+ kind: "scalar",
530
+ resolve: resolveYamlFloat,
531
+ construct: constructYamlFloat,
532
+ predicate: isFloat,
533
+ represent: representYamlFloat,
534
+ defaultStyle: "lowercase"
535
+ });
536
+ var json = failsafe.extend({
537
+ implicit: [
538
+ _null,
539
+ bool,
540
+ int,
541
+ float
542
+ ]
543
+ });
544
+ var core = json;
545
+ var YAML_DATE_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])" + // [1] year
546
+ "-([0-9][0-9])" + // [2] month
547
+ "-([0-9][0-9])$"); // [3] day
548
+ var YAML_TIMESTAMP_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])" + // [1] year
549
+ "-([0-9][0-9]?)" + // [2] month
550
+ "-([0-9][0-9]?)" + // [3] day
551
+ "(?:[Tt]|[ \\t]+)" + // ...
552
+ "([0-9][0-9]?)" + // [4] hour
553
+ ":([0-9][0-9])" + // [5] minute
554
+ ":([0-9][0-9])" + // [6] second
555
+ "(?:\\.([0-9]*))?" + // [7] fraction
556
+ "(?:[ \\t]*(Z|([-+])([0-9][0-9]?)" + // [8] tz [9] tz_sign [10] tz_hour
557
+ "(?::([0-9][0-9]))?))?$"); // [11] tz_minute
558
+ function resolveYamlTimestamp(data) {
559
+ if (data === null) return false;
560
+ if (YAML_DATE_REGEXP.exec(data) !== null) return true;
561
+ if (YAML_TIMESTAMP_REGEXP.exec(data) !== null) return true;
562
+ return false;
563
+ }
564
+ function constructYamlTimestamp(data) {
565
+ var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
566
+ match = YAML_DATE_REGEXP.exec(data);
567
+ if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
568
+ if (match === null) throw new Error("Date resolve error");
569
+ // match: [1] year [2] month [3] day
570
+ year = +match[1];
571
+ month = +match[2] - 1; // JS month starts with 0
572
+ day = +match[3];
573
+ if (!match[4]) {
574
+ return new Date(Date.UTC(year, month, day));
575
+ }
576
+ // match: [4] hour [5] minute [6] second [7] fraction
577
+ hour = +match[4];
578
+ minute = +match[5];
579
+ second = +match[6];
580
+ if (match[7]) {
581
+ fraction = match[7].slice(0, 3);
582
+ while(fraction.length < 3){
583
+ fraction += "0";
584
+ }
585
+ fraction = +fraction;
586
+ }
587
+ // match: [8] tz [9] tz_sign [10] tz_hour [11] tz_minute
588
+ if (match[9]) {
589
+ tz_hour = +match[10];
590
+ tz_minute = +(match[11] || 0);
591
+ delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
592
+ if (match[9] === "-") delta = -delta;
593
+ }
594
+ date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
595
+ if (delta) date.setTime(date.getTime() - delta);
596
+ return date;
597
+ }
598
+ function representYamlTimestamp(object /*, style*/ ) {
599
+ return object.toISOString();
600
+ }
601
+ var timestamp = new type("tag:yaml.org,2002:timestamp", {
602
+ kind: "scalar",
603
+ resolve: resolveYamlTimestamp,
604
+ construct: constructYamlTimestamp,
605
+ instanceOf: Date,
606
+ represent: representYamlTimestamp
607
+ });
608
+ function resolveYamlMerge(data) {
609
+ return data === "<<" || data === null;
610
+ }
611
+ var merge = new type("tag:yaml.org,2002:merge", {
612
+ kind: "scalar",
613
+ resolve: resolveYamlMerge
614
+ });
615
+ /*eslint-disable no-bitwise*/ // [ 64, 65, 66 ] -> [ padding, CR, LF ]
616
+ var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";
617
+ function resolveYamlBinary(data) {
618
+ if (data === null) return false;
619
+ var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
620
+ // Convert one by one.
621
+ for(idx = 0; idx < max; idx++){
622
+ code = map.indexOf(data.charAt(idx));
623
+ // Skip CR/LF
624
+ if (code > 64) continue;
625
+ // Fail on illegal characters
626
+ if (code < 0) return false;
627
+ bitlen += 6;
628
+ }
629
+ // If there are any bits left, source was corrupted
630
+ return bitlen % 8 === 0;
631
+ }
632
+ function constructYamlBinary(data) {
633
+ var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map = BASE64_MAP, bits = 0, result = [];
634
+ // Collect by 6*4 bits (3 bytes)
635
+ for(idx = 0; idx < max; idx++){
636
+ if (idx % 4 === 0 && idx) {
637
+ result.push(bits >> 16 & 0xFF);
638
+ result.push(bits >> 8 & 0xFF);
639
+ result.push(bits & 0xFF);
640
+ }
641
+ bits = bits << 6 | map.indexOf(input.charAt(idx));
642
+ }
643
+ // Dump tail
644
+ tailbits = max % 4 * 6;
645
+ if (tailbits === 0) {
646
+ result.push(bits >> 16 & 0xFF);
647
+ result.push(bits >> 8 & 0xFF);
648
+ result.push(bits & 0xFF);
649
+ } else if (tailbits === 18) {
650
+ result.push(bits >> 10 & 0xFF);
651
+ result.push(bits >> 2 & 0xFF);
652
+ } else if (tailbits === 12) {
653
+ result.push(bits >> 4 & 0xFF);
654
+ }
655
+ return new Uint8Array(result);
656
+ }
657
+ function representYamlBinary(object /*, style*/ ) {
658
+ var result = "", bits = 0, idx, tail, max = object.length, map = BASE64_MAP;
659
+ // Convert every three bytes to 4 ASCII characters.
660
+ for(idx = 0; idx < max; idx++){
661
+ if (idx % 3 === 0 && idx) {
662
+ result += map[bits >> 18 & 0x3F];
663
+ result += map[bits >> 12 & 0x3F];
664
+ result += map[bits >> 6 & 0x3F];
665
+ result += map[bits & 0x3F];
666
+ }
667
+ bits = (bits << 8) + object[idx];
668
+ }
669
+ // Dump tail
670
+ tail = max % 3;
671
+ if (tail === 0) {
672
+ result += map[bits >> 18 & 0x3F];
673
+ result += map[bits >> 12 & 0x3F];
674
+ result += map[bits >> 6 & 0x3F];
675
+ result += map[bits & 0x3F];
676
+ } else if (tail === 2) {
677
+ result += map[bits >> 10 & 0x3F];
678
+ result += map[bits >> 4 & 0x3F];
679
+ result += map[bits << 2 & 0x3F];
680
+ result += map[64];
681
+ } else if (tail === 1) {
682
+ result += map[bits >> 2 & 0x3F];
683
+ result += map[bits << 4 & 0x3F];
684
+ result += map[64];
685
+ result += map[64];
686
+ }
687
+ return result;
688
+ }
689
+ function isBinary(obj) {
690
+ return Object.prototype.toString.call(obj) === "[object Uint8Array]";
691
+ }
692
+ var binary = new type("tag:yaml.org,2002:binary", {
693
+ kind: "scalar",
694
+ resolve: resolveYamlBinary,
695
+ construct: constructYamlBinary,
696
+ predicate: isBinary,
697
+ represent: representYamlBinary
698
+ });
699
+ var _hasOwnProperty$3 = Object.prototype.hasOwnProperty;
700
+ var _toString$2 = Object.prototype.toString;
701
+ function resolveYamlOmap(data) {
702
+ if (data === null) return true;
703
+ var objectKeys = [], index, length, pair, pairKey, pairHasKey, object = data;
704
+ for(index = 0, length = object.length; index < length; index += 1){
705
+ pair = object[index];
706
+ pairHasKey = false;
707
+ if (_toString$2.call(pair) !== "[object Object]") return false;
708
+ for(pairKey in pair){
709
+ if (_hasOwnProperty$3.call(pair, pairKey)) {
710
+ if (!pairHasKey) pairHasKey = true;
711
+ else return false;
712
+ }
713
+ }
714
+ if (!pairHasKey) return false;
715
+ if (objectKeys.indexOf(pairKey) === -1) objectKeys.push(pairKey);
716
+ else return false;
717
+ }
718
+ return true;
719
+ }
720
+ function constructYamlOmap(data) {
721
+ return data !== null ? data : [];
722
+ }
723
+ var omap = new type("tag:yaml.org,2002:omap", {
724
+ kind: "sequence",
725
+ resolve: resolveYamlOmap,
726
+ construct: constructYamlOmap
727
+ });
728
+ var _toString$1 = Object.prototype.toString;
729
+ function resolveYamlPairs(data) {
730
+ if (data === null) return true;
731
+ var index, length, pair, keys, result, object = data;
732
+ result = new Array(object.length);
733
+ for(index = 0, length = object.length; index < length; index += 1){
734
+ pair = object[index];
735
+ if (_toString$1.call(pair) !== "[object Object]") return false;
736
+ keys = Object.keys(pair);
737
+ if (keys.length !== 1) return false;
738
+ result[index] = [
739
+ keys[0],
740
+ pair[keys[0]]
741
+ ];
742
+ }
743
+ return true;
744
+ }
745
+ function constructYamlPairs(data) {
746
+ if (data === null) return [];
747
+ var index, length, pair, keys, result, object = data;
748
+ result = new Array(object.length);
749
+ for(index = 0, length = object.length; index < length; index += 1){
750
+ pair = object[index];
751
+ keys = Object.keys(pair);
752
+ result[index] = [
753
+ keys[0],
754
+ pair[keys[0]]
755
+ ];
756
+ }
757
+ return result;
758
+ }
759
+ var pairs = new type("tag:yaml.org,2002:pairs", {
760
+ kind: "sequence",
761
+ resolve: resolveYamlPairs,
762
+ construct: constructYamlPairs
763
+ });
764
+ var _hasOwnProperty$2 = Object.prototype.hasOwnProperty;
765
+ function resolveYamlSet(data) {
766
+ if (data === null) return true;
767
+ var key, object = data;
768
+ for(key in object){
769
+ if (_hasOwnProperty$2.call(object, key)) {
770
+ if (object[key] !== null) return false;
771
+ }
772
+ }
773
+ return true;
774
+ }
775
+ function constructYamlSet(data) {
776
+ return data !== null ? data : {};
777
+ }
778
+ var set = new type("tag:yaml.org,2002:set", {
779
+ kind: "mapping",
780
+ resolve: resolveYamlSet,
781
+ construct: constructYamlSet
782
+ });
783
+ var _default = core.extend({
784
+ implicit: [
785
+ timestamp,
786
+ merge
787
+ ],
788
+ explicit: [
789
+ binary,
790
+ omap,
791
+ pairs,
792
+ set
793
+ ]
794
+ });
795
+ function simpleEscapeSequence(c) {
796
+ /* eslint-disable indent */ return c === 0x30 /* 0 */ ? "\0" : c === 0x61 /* a */ ? "\x07" : c === 0x62 /* b */ ? "\b" : c === 0x74 /* t */ ? " " : c === 0x09 /* Tab */ ? " " : c === 0x6E /* n */ ? "\n" : c === 0x76 /* v */ ? "\v" : c === 0x66 /* f */ ? "\f" : c === 0x72 /* r */ ? "\r" : c === 0x65 /* e */ ? "\x1b" : c === 0x20 /* Space */ ? " " : c === 0x22 /* " */ ? '"' : c === 0x2F /* / */ ? "/" : c === 0x5C /* \ */ ? "\\" : c === 0x4E /* N */ ? "\x85" : c === 0x5F /* _ */ ? "\xa0" : c === 0x4C /* L */ ? "\u2028" : c === 0x50 /* P */ ? "\u2029" : "";
797
+ }
798
+ var simpleEscapeCheck = new Array(256); // integer, for fast access
799
+ var simpleEscapeMap = new Array(256);
800
+ for(var i = 0; i < 256; i++){
801
+ simpleEscapeCheck[i] = simpleEscapeSequence(i) ? 1 : 0;
802
+ simpleEscapeMap[i] = simpleEscapeSequence(i);
803
+ }
804
+ /*eslint-disable no-use-before-define*/ var _toString = Object.prototype.toString;
805
+ var _hasOwnProperty = Object.prototype.hasOwnProperty;
806
+ var CHAR_BOM = 0xFEFF;
807
+ var CHAR_TAB = 0x09; /* Tab */
808
+ var CHAR_LINE_FEED = 0x0A; /* LF */
809
+ var CHAR_CARRIAGE_RETURN = 0x0D; /* CR */
810
+ var CHAR_SPACE = 0x20; /* Space */
811
+ var CHAR_EXCLAMATION = 0x21; /* ! */
812
+ var CHAR_DOUBLE_QUOTE = 0x22; /* " */
813
+ var CHAR_SHARP = 0x23; /* # */
814
+ var CHAR_PERCENT = 0x25; /* % */
815
+ var CHAR_AMPERSAND = 0x26; /* & */
816
+ var CHAR_SINGLE_QUOTE = 0x27; /* ' */
817
+ var CHAR_ASTERISK = 0x2A; /* * */
818
+ var CHAR_COMMA = 0x2C; /* , */
819
+ var CHAR_MINUS = 0x2D; /* - */
820
+ var CHAR_COLON = 0x3A; /* : */
821
+ var CHAR_EQUALS = 0x3D; /* = */
822
+ var CHAR_GREATER_THAN = 0x3E; /* > */
823
+ var CHAR_QUESTION = 0x3F; /* ? */
824
+ var CHAR_COMMERCIAL_AT = 0x40; /* @ */
825
+ var CHAR_LEFT_SQUARE_BRACKET = 0x5B; /* [ */
826
+ var CHAR_RIGHT_SQUARE_BRACKET = 0x5D; /* ] */
827
+ var CHAR_GRAVE_ACCENT = 0x60; /* ` */
828
+ var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */
829
+ var CHAR_VERTICAL_LINE = 0x7C; /* | */
830
+ var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */
831
+ var ESCAPE_SEQUENCES = {};
832
+ ESCAPE_SEQUENCES[0x00] = "\\0";
833
+ ESCAPE_SEQUENCES[0x07] = "\\a";
834
+ ESCAPE_SEQUENCES[0x08] = "\\b";
835
+ ESCAPE_SEQUENCES[0x09] = "\\t";
836
+ ESCAPE_SEQUENCES[0x0A] = "\\n";
837
+ ESCAPE_SEQUENCES[0x0B] = "\\v";
838
+ ESCAPE_SEQUENCES[0x0C] = "\\f";
839
+ ESCAPE_SEQUENCES[0x0D] = "\\r";
840
+ ESCAPE_SEQUENCES[0x1B] = "\\e";
841
+ ESCAPE_SEQUENCES[0x22] = '\\"';
842
+ ESCAPE_SEQUENCES[0x5C] = "\\\\";
843
+ ESCAPE_SEQUENCES[0x85] = "\\N";
844
+ ESCAPE_SEQUENCES[0xA0] = "\\_";
845
+ ESCAPE_SEQUENCES[0x2028] = "\\L";
846
+ ESCAPE_SEQUENCES[0x2029] = "\\P";
847
+ var DEPRECATED_BOOLEANS_SYNTAX = [
848
+ "y",
849
+ "Y",
850
+ "yes",
851
+ "Yes",
852
+ "YES",
853
+ "on",
854
+ "On",
855
+ "ON",
856
+ "n",
857
+ "N",
858
+ "no",
859
+ "No",
860
+ "NO",
861
+ "off",
862
+ "Off",
863
+ "OFF"
864
+ ];
865
+ var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
866
+ function compileStyleMap(schema, map) {
867
+ var result, keys, index, length, tag, style, type;
868
+ if (map === null) return {};
869
+ result = {};
870
+ keys = Object.keys(map);
871
+ for(index = 0, length = keys.length; index < length; index += 1){
872
+ tag = keys[index];
873
+ style = String(map[tag]);
874
+ if (tag.slice(0, 2) === "!!") {
875
+ tag = "tag:yaml.org,2002:" + tag.slice(2);
876
+ }
877
+ type = schema.compiledTypeMap["fallback"][tag];
878
+ if (type && _hasOwnProperty.call(type.styleAliases, style)) {
879
+ style = type.styleAliases[style];
880
+ }
881
+ result[tag] = style;
882
+ }
883
+ return result;
884
+ }
885
+ function encodeHex(character) {
886
+ var string, handle, length;
887
+ string = character.toString(16).toUpperCase();
888
+ if (character <= 0xFF) {
889
+ handle = "x";
890
+ length = 2;
891
+ } else if (character <= 0xFFFF) {
892
+ handle = "u";
893
+ length = 4;
894
+ } else if (character <= 0xFFFFFFFF) {
895
+ handle = "U";
896
+ length = 8;
897
+ } else {
898
+ throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
899
+ }
900
+ return "\\" + handle + common.repeat("0", length - string.length) + string;
901
+ }
902
+ var QUOTING_TYPE_SINGLE = 1, QUOTING_TYPE_DOUBLE = 2;
903
+ function State(options) {
904
+ this.schema = options["schema"] || _default;
905
+ this.indent = Math.max(1, options["indent"] || 2);
906
+ this.noArrayIndent = options["noArrayIndent"] || false;
907
+ this.skipInvalid = options["skipInvalid"] || false;
908
+ this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
909
+ this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
910
+ this.sortKeys = options["sortKeys"] || false;
911
+ this.lineWidth = options["lineWidth"] || 80;
912
+ this.noRefs = options["noRefs"] || false;
913
+ this.noCompatMode = options["noCompatMode"] || false;
914
+ this.condenseFlow = options["condenseFlow"] || false;
915
+ this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
916
+ this.forceQuotes = options["forceQuotes"] || false;
917
+ this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
918
+ this.implicitTypes = this.schema.compiledImplicit;
919
+ this.explicitTypes = this.schema.compiledExplicit;
920
+ this.tag = null;
921
+ this.result = "";
922
+ this.duplicates = [];
923
+ this.usedDuplicates = null;
924
+ }
925
+ // Indents every line in a string. Empty lines (\n only) are not indented.
926
+ function indentString(string, spaces) {
927
+ var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
928
+ while(position < length){
929
+ next = string.indexOf("\n", position);
930
+ if (next === -1) {
931
+ line = string.slice(position);
932
+ position = length;
933
+ } else {
934
+ line = string.slice(position, next + 1);
935
+ position = next + 1;
936
+ }
937
+ if (line.length && line !== "\n") result += ind;
938
+ result += line;
939
+ }
940
+ return result;
941
+ }
942
+ function generateNextLine(state, level) {
943
+ return "\n" + common.repeat(" ", state.indent * level);
944
+ }
945
+ function testImplicitResolving(state, str) {
946
+ var index, length, type;
947
+ for(index = 0, length = state.implicitTypes.length; index < length; index += 1){
948
+ type = state.implicitTypes[index];
949
+ if (type.resolve(str)) {
950
+ return true;
951
+ }
952
+ }
953
+ return false;
954
+ }
955
+ // [33] s-white ::= s-space | s-tab
956
+ function isWhitespace(c) {
957
+ return c === CHAR_SPACE || c === CHAR_TAB;
958
+ }
959
+ // Returns true if the character can be printed without escaping.
960
+ // From YAML 1.2: "any allowed characters known to be non-printable
961
+ // should also be escaped. [However,] This isn’t mandatory"
962
+ // Derived from nb-char - \t - #x85 - #xA0 - #x2028 - #x2029.
963
+ function isPrintable(c) {
964
+ return 0x00020 <= c && c <= 0x00007E || 0x000A1 <= c && c <= 0x00D7FF && c !== 0x2028 && c !== 0x2029 || 0x0E000 <= c && c <= 0x00FFFD && c !== CHAR_BOM || 0x10000 <= c && c <= 0x10FFFF;
965
+ }
966
+ // [34] ns-char ::= nb-char - s-white
967
+ // [27] nb-char ::= c-printable - b-char - c-byte-order-mark
968
+ // [26] b-char ::= b-line-feed | b-carriage-return
969
+ // Including s-white (for some reason, examples doesn't match specs in this aspect)
970
+ // ns-char ::= c-printable - b-line-feed - b-carriage-return - c-byte-order-mark
971
+ function isNsCharOrWhitespace(c) {
972
+ return isPrintable(c) && c !== CHAR_BOM && c !== CHAR_CARRIAGE_RETURN && c !== CHAR_LINE_FEED;
973
+ }
974
+ // [127] ns-plain-safe(c) ::= c = flow-out ⇒ ns-plain-safe-out
975
+ // c = flow-in ⇒ ns-plain-safe-in
976
+ // c = block-key ⇒ ns-plain-safe-out
977
+ // c = flow-key ⇒ ns-plain-safe-in
978
+ // [128] ns-plain-safe-out ::= ns-char
979
+ // [129] ns-plain-safe-in ::= ns-char - c-flow-indicator
980
+ // [130] ns-plain-char(c) ::= ( ns-plain-safe(c) - “:” - “#” )
981
+ // | ( /* An ns-char preceding */ “#” )
982
+ // | ( “:” /* Followed by an ns-plain-safe(c) */ )
983
+ function isPlainSafe(c, prev, inblock) {
984
+ var cIsNsCharOrWhitespace = isNsCharOrWhitespace(c);
985
+ var cIsNsChar = cIsNsCharOrWhitespace && !isWhitespace(c);
986
+ return(// ns-plain-safe
987
+ (inblock ? cIsNsCharOrWhitespace : cIsNsCharOrWhitespace && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET) && c !== CHAR_SHARP // false on '#'
988
+ && !(prev === CHAR_COLON && !cIsNsChar // false on ': '
989
+ ) || isNsCharOrWhitespace(prev) && !isWhitespace(prev) && c === CHAR_SHARP // change to true on '[^ ]#'
990
+ || prev === CHAR_COLON && cIsNsChar); // change to true on ':[^ ]'
991
+ }
992
+ // Simplified test for values allowed as the first character in plain style.
993
+ function isPlainSafeFirst(c) {
994
+ // Uses a subset of ns-char - c-indicator
995
+ // where ns-char = nb-char - s-white.
996
+ // No support of ( ( “?” | “:” | “-” ) /* Followed by an ns-plain-safe(c)) */ ) part
997
+ return isPrintable(c) && c !== CHAR_BOM && !isWhitespace(c) // - s-white
998
+ && c !== CHAR_MINUS && c !== CHAR_QUESTION && c !== CHAR_COLON && c !== CHAR_COMMA && c !== CHAR_LEFT_SQUARE_BRACKET && c !== CHAR_RIGHT_SQUARE_BRACKET && c !== CHAR_LEFT_CURLY_BRACKET && c !== CHAR_RIGHT_CURLY_BRACKET && c !== CHAR_SHARP && c !== CHAR_AMPERSAND && c !== CHAR_ASTERISK && c !== CHAR_EXCLAMATION && c !== CHAR_VERTICAL_LINE && c !== CHAR_EQUALS && c !== CHAR_GREATER_THAN && c !== CHAR_SINGLE_QUOTE && c !== CHAR_DOUBLE_QUOTE && c !== CHAR_PERCENT && c !== CHAR_COMMERCIAL_AT && c !== CHAR_GRAVE_ACCENT;
999
+ }
1000
+ // Simplified test for values allowed as the last character in plain style.
1001
+ function isPlainSafeLast(c) {
1002
+ // just not whitespace or colon, it will be checked to be plain character later
1003
+ return !isWhitespace(c) && c !== CHAR_COLON;
1004
+ }
1005
+ // Same as 'string'.codePointAt(pos), but works in older browsers.
1006
+ function codePointAt(string, pos) {
1007
+ var first = string.charCodeAt(pos), second;
1008
+ if (first >= 0xD800 && first <= 0xDBFF && pos + 1 < string.length) {
1009
+ second = string.charCodeAt(pos + 1);
1010
+ if (second >= 0xDC00 && second <= 0xDFFF) {
1011
+ // https://mathiasbynens.be/notes/javascript-encoding#surrogate-formulae
1012
+ return (first - 0xD800) * 0x400 + second - 0xDC00 + 0x10000;
1013
+ }
1014
+ }
1015
+ return first;
1016
+ }
1017
+ // Determines whether block indentation indicator is required.
1018
+ function needIndentIndicator(string) {
1019
+ var leadingSpaceRe = /^\n* /;
1020
+ return leadingSpaceRe.test(string);
1021
+ }
1022
+ var STYLE_PLAIN = 1, STYLE_SINGLE = 2, STYLE_LITERAL = 3, STYLE_FOLDED = 4, STYLE_DOUBLE = 5;
1023
+ // Determines which scalar styles are possible and returns the preferred style.
1024
+ // lineWidth = -1 => no limit.
1025
+ // Pre-conditions: str.length > 0.
1026
+ // Post-conditions:
1027
+ // STYLE_PLAIN or STYLE_SINGLE => no \n are in the string.
1028
+ // STYLE_LITERAL => no lines are suitable for folding (or lineWidth is -1).
1029
+ // STYLE_FOLDED => a line > lineWidth and can be folded (and lineWidth != -1).
1030
+ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, testAmbiguousType, quotingType, forceQuotes, inblock) {
1031
+ var i;
1032
+ var char = 0;
1033
+ var prevChar = null;
1034
+ var hasLineBreak = false;
1035
+ var hasFoldableLine = false; // only checked if shouldTrackWidth
1036
+ var shouldTrackWidth = lineWidth !== -1;
1037
+ var previousLineBreak = -1; // count the first line correctly
1038
+ var plain = isPlainSafeFirst(codePointAt(string, 0)) && isPlainSafeLast(codePointAt(string, string.length - 1));
1039
+ if (singleLineOnly || forceQuotes) {
1040
+ // Case: no block styles.
1041
+ // Check for disallowed characters to rule out plain and single.
1042
+ for(i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++){
1043
+ char = codePointAt(string, i);
1044
+ if (!isPrintable(char)) {
1045
+ return STYLE_DOUBLE;
1046
+ }
1047
+ plain = plain && isPlainSafe(char, prevChar, inblock);
1048
+ prevChar = char;
1049
+ }
1050
+ } else {
1051
+ // Case: block styles permitted.
1052
+ for(i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++){
1053
+ char = codePointAt(string, i);
1054
+ if (char === CHAR_LINE_FEED) {
1055
+ hasLineBreak = true;
1056
+ // Check if any line can be folded.
1057
+ if (shouldTrackWidth) {
1058
+ hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
1059
+ i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
1060
+ previousLineBreak = i;
1061
+ }
1062
+ } else if (!isPrintable(char)) {
1063
+ return STYLE_DOUBLE;
1064
+ }
1065
+ plain = plain && isPlainSafe(char, prevChar, inblock);
1066
+ prevChar = char;
1067
+ }
1068
+ // in case the end is missing a \n
1069
+ hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
1070
+ }
1071
+ // Although every style can represent \n without escaping, prefer block styles
1072
+ // for multiline, since they're more readable and they don't add empty lines.
1073
+ // Also prefer folding a super-long line.
1074
+ if (!hasLineBreak && !hasFoldableLine) {
1075
+ // Strings interpretable as another type have to be quoted;
1076
+ // e.g. the string 'true' vs. the boolean true.
1077
+ if (plain && !forceQuotes && !testAmbiguousType(string)) {
1078
+ return STYLE_PLAIN;
1079
+ }
1080
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
1081
+ }
1082
+ // Edge case: block indentation indicator can only have one digit.
1083
+ if (indentPerLevel > 9 && needIndentIndicator(string)) {
1084
+ return STYLE_DOUBLE;
1085
+ }
1086
+ // At this point we know block styles are valid.
1087
+ // Prefer literal style unless we want to fold.
1088
+ if (!forceQuotes) {
1089
+ return hasFoldableLine ? STYLE_FOLDED : STYLE_LITERAL;
1090
+ }
1091
+ return quotingType === QUOTING_TYPE_DOUBLE ? STYLE_DOUBLE : STYLE_SINGLE;
1092
+ }
1093
+ // Note: line breaking/folding is implemented for only the folded style.
1094
+ // NB. We drop the last trailing newline (if any) of a returned block scalar
1095
+ // since the dumper adds its own newline. This always works:
1096
+ // • No ending newline => unaffected; already using strip "-" chomping.
1097
+ // • Ending newline => removed then restored.
1098
+ // Importantly, this keeps the "+" chomp indicator from gaining an extra line.
1099
+ function writeScalar(state, string, level, iskey, inblock) {
1100
+ state.dump = function() {
1101
+ if (string.length === 0) {
1102
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? '""' : "''";
1103
+ }
1104
+ if (!state.noCompatMode) {
1105
+ if (DEPRECATED_BOOLEANS_SYNTAX.indexOf(string) !== -1 || DEPRECATED_BASE60_SYNTAX.test(string)) {
1106
+ return state.quotingType === QUOTING_TYPE_DOUBLE ? '"' + string + '"' : "'" + string + "'";
1107
+ }
1108
+ }
1109
+ var indent = state.indent * Math.max(1, level); // no 0-indent scalars
1110
+ // As indentation gets deeper, let the width decrease monotonically
1111
+ // to the lower bound min(state.lineWidth, 40).
1112
+ // Note that this implies
1113
+ // state.lineWidth ≤ 40 + state.indent: width is fixed at the lower bound.
1114
+ // state.lineWidth > 40 + state.indent: width decreases until the lower bound.
1115
+ // This behaves better than a constant minimum width which disallows narrower options,
1116
+ // or an indent threshold which causes the width to suddenly increase.
1117
+ var lineWidth = state.lineWidth === -1 ? -1 : Math.max(Math.min(state.lineWidth, 40), state.lineWidth - indent);
1118
+ // Without knowing if keys are implicit/explicit, assume implicit for safety.
1119
+ var singleLineOnly = iskey || state.flowLevel > -1 && level >= state.flowLevel;
1120
+ function testAmbiguity(string) {
1121
+ return testImplicitResolving(state, string);
1122
+ }
1123
+ switch(chooseScalarStyle(string, singleLineOnly, state.indent, lineWidth, testAmbiguity, state.quotingType, state.forceQuotes && !iskey, inblock)){
1124
+ case STYLE_PLAIN:
1125
+ return string;
1126
+ case STYLE_SINGLE:
1127
+ return "'" + string.replace(/'/g, "''") + "'";
1128
+ case STYLE_LITERAL:
1129
+ return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
1130
+ case STYLE_FOLDED:
1131
+ return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
1132
+ case STYLE_DOUBLE:
1133
+ return '"' + escapeString(string) + '"';
1134
+ default:
1135
+ throw new exception("impossible error: invalid scalar style");
1136
+ }
1137
+ }();
1138
+ }
1139
+ // Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
1140
+ function blockHeader(string, indentPerLevel) {
1141
+ var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
1142
+ // note the special case: the string '\n' counts as a "trailing" empty line.
1143
+ var clip = string[string.length - 1] === "\n";
1144
+ var keep = clip && (string[string.length - 2] === "\n" || string === "\n");
1145
+ var chomp = keep ? "+" : clip ? "" : "-";
1146
+ return indentIndicator + chomp + "\n";
1147
+ }
1148
+ // (See the note for writeScalar.)
1149
+ function dropEndingNewline(string) {
1150
+ return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
1151
+ }
1152
+ // Note: a long line without a suitable break point will exceed the width limit.
1153
+ // Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
1154
+ function foldString(string, width) {
1155
+ // In folded style, $k$ consecutive newlines output as $k+1$ newlines—
1156
+ // unless they're before or after a more-indented line, or at the very
1157
+ // beginning or end, in which case $k$ maps to $k$.
1158
+ // Therefore, parse each chunk as newline(s) followed by a content line.
1159
+ var lineRe = /(\n+)([^\n]*)/g;
1160
+ // first line (possibly an empty line)
1161
+ var result = function() {
1162
+ var nextLF = string.indexOf("\n");
1163
+ nextLF = nextLF !== -1 ? nextLF : string.length;
1164
+ lineRe.lastIndex = nextLF;
1165
+ return foldLine(string.slice(0, nextLF), width);
1166
+ }();
1167
+ // If we haven't reached the first content line yet, don't add an extra \n.
1168
+ var prevMoreIndented = string[0] === "\n" || string[0] === " ";
1169
+ var moreIndented;
1170
+ // rest of the lines
1171
+ var match;
1172
+ while(match = lineRe.exec(string)){
1173
+ var prefix = match[1], line = match[2];
1174
+ moreIndented = line[0] === " ";
1175
+ result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
1176
+ prevMoreIndented = moreIndented;
1177
+ }
1178
+ return result;
1179
+ }
1180
+ // Greedy line breaking.
1181
+ // Picks the longest line under the limit each time,
1182
+ // otherwise settles for the shortest line over the limit.
1183
+ // NB. More-indented lines *cannot* be folded, as that would add an extra \n.
1184
+ function foldLine(line, width) {
1185
+ if (line === "" || line[0] === " ") return line;
1186
+ // Since a more-indented line adds a \n, breaks can't be followed by a space.
1187
+ var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
1188
+ var match;
1189
+ // start is an inclusive index. end, curr, and next are exclusive.
1190
+ var start = 0, end, curr = 0, next = 0;
1191
+ var result = "";
1192
+ // Invariants: 0 <= start <= length-1.
1193
+ // 0 <= curr <= next <= max(0, length-2). curr - start <= width.
1194
+ // Inside the loop:
1195
+ // A match implies length >= 2, so curr and next are <= length-2.
1196
+ while(match = breakRe.exec(line)){
1197
+ next = match.index;
1198
+ // maintain invariant: curr - start <= width
1199
+ if (next - start > width) {
1200
+ end = curr > start ? curr : next; // derive end <= length-2
1201
+ result += "\n" + line.slice(start, end);
1202
+ // skip the space that was output as \n
1203
+ start = end + 1; // derive start <= length-1
1204
+ }
1205
+ curr = next;
1206
+ }
1207
+ // By the invariants, start <= length-1, so there is something left over.
1208
+ // It is either the whole string or a part starting from non-whitespace.
1209
+ result += "\n";
1210
+ // Insert a break if the remainder is too long and there is a break available.
1211
+ if (line.length - start > width && curr > start) {
1212
+ result += line.slice(start, curr) + "\n" + line.slice(curr + 1);
1213
+ } else {
1214
+ result += line.slice(start);
1215
+ }
1216
+ return result.slice(1); // drop extra \n joiner
1217
+ }
1218
+ // Escapes a double-quoted string.
1219
+ function escapeString(string) {
1220
+ var result = "";
1221
+ var char = 0;
1222
+ var escapeSeq;
1223
+ for(var i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++){
1224
+ char = codePointAt(string, i);
1225
+ escapeSeq = ESCAPE_SEQUENCES[char];
1226
+ if (!escapeSeq && isPrintable(char)) {
1227
+ result += string[i];
1228
+ if (char >= 0x10000) result += string[i + 1];
1229
+ } else {
1230
+ result += escapeSeq || encodeHex(char);
1231
+ }
1232
+ }
1233
+ return result;
1234
+ }
1235
+ function writeFlowSequence(state, level, object) {
1236
+ var _result = "", _tag = state.tag, index, length, value;
1237
+ for(index = 0, length = object.length; index < length; index += 1){
1238
+ value = object[index];
1239
+ if (state.replacer) {
1240
+ value = state.replacer.call(object, String(index), value);
1241
+ }
1242
+ // Write only valid elements, put null instead of invalid elements.
1243
+ if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
1244
+ if (_result !== "") _result += "," + (!state.condenseFlow ? " " : "");
1245
+ _result += state.dump;
1246
+ }
1247
+ }
1248
+ state.tag = _tag;
1249
+ state.dump = "[" + _result + "]";
1250
+ }
1251
+ function writeBlockSequence(state, level, object, compact) {
1252
+ var _result = "", _tag = state.tag, index, length, value;
1253
+ for(index = 0, length = object.length; index < length; index += 1){
1254
+ value = object[index];
1255
+ if (state.replacer) {
1256
+ value = state.replacer.call(object, String(index), value);
1257
+ }
1258
+ // Write only valid elements, put null instead of invalid elements.
1259
+ if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
1260
+ if (!compact || _result !== "") {
1261
+ _result += generateNextLine(state, level);
1262
+ }
1263
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
1264
+ _result += "-";
1265
+ } else {
1266
+ _result += "- ";
1267
+ }
1268
+ _result += state.dump;
1269
+ }
1270
+ }
1271
+ state.tag = _tag;
1272
+ state.dump = _result || "[]"; // Empty sequence if no valid values.
1273
+ }
1274
+ function writeFlowMapping(state, level, object) {
1275
+ var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
1276
+ for(index = 0, length = objectKeyList.length; index < length; index += 1){
1277
+ pairBuffer = "";
1278
+ if (_result !== "") pairBuffer += ", ";
1279
+ if (state.condenseFlow) pairBuffer += '"';
1280
+ objectKey = objectKeyList[index];
1281
+ objectValue = object[objectKey];
1282
+ if (state.replacer) {
1283
+ objectValue = state.replacer.call(object, objectKey, objectValue);
1284
+ }
1285
+ if (!writeNode(state, level, objectKey, false, false)) {
1286
+ continue; // Skip this pair because of invalid key;
1287
+ }
1288
+ if (state.dump.length > 1024) pairBuffer += "? ";
1289
+ pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
1290
+ if (!writeNode(state, level, objectValue, false, false)) {
1291
+ continue; // Skip this pair because of invalid value.
1292
+ }
1293
+ pairBuffer += state.dump;
1294
+ // Both key and value are valid.
1295
+ _result += pairBuffer;
1296
+ }
1297
+ state.tag = _tag;
1298
+ state.dump = "{" + _result + "}";
1299
+ }
1300
+ function writeBlockMapping(state, level, object, compact) {
1301
+ var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
1302
+ // Allow sorting keys so that the output file is deterministic
1303
+ if (state.sortKeys === true) {
1304
+ // Default sorting
1305
+ objectKeyList.sort();
1306
+ } else if (typeof state.sortKeys === "function") {
1307
+ // Custom sort function
1308
+ objectKeyList.sort(state.sortKeys);
1309
+ } else if (state.sortKeys) {
1310
+ // Something is wrong
1311
+ throw new exception("sortKeys must be a boolean or a function");
1312
+ }
1313
+ for(index = 0, length = objectKeyList.length; index < length; index += 1){
1314
+ pairBuffer = "";
1315
+ if (!compact || _result !== "") {
1316
+ pairBuffer += generateNextLine(state, level);
1317
+ }
1318
+ objectKey = objectKeyList[index];
1319
+ objectValue = object[objectKey];
1320
+ if (state.replacer) {
1321
+ objectValue = state.replacer.call(object, objectKey, objectValue);
1322
+ }
1323
+ if (!writeNode(state, level + 1, objectKey, true, true, true)) {
1324
+ continue; // Skip this pair because of invalid key.
1325
+ }
1326
+ explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
1327
+ if (explicitPair) {
1328
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
1329
+ pairBuffer += "?";
1330
+ } else {
1331
+ pairBuffer += "? ";
1332
+ }
1333
+ }
1334
+ pairBuffer += state.dump;
1335
+ if (explicitPair) {
1336
+ pairBuffer += generateNextLine(state, level);
1337
+ }
1338
+ if (!writeNode(state, level + 1, objectValue, true, explicitPair)) {
1339
+ continue; // Skip this pair because of invalid value.
1340
+ }
1341
+ if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
1342
+ pairBuffer += ":";
1343
+ } else {
1344
+ pairBuffer += ": ";
1345
+ }
1346
+ pairBuffer += state.dump;
1347
+ // Both key and value are valid.
1348
+ _result += pairBuffer;
1349
+ }
1350
+ state.tag = _tag;
1351
+ state.dump = _result || "{}"; // Empty mapping if no valid pairs.
1352
+ }
1353
+ function detectType(state, object, explicit) {
1354
+ var _result, typeList, index, length, type, style;
1355
+ typeList = explicit ? state.explicitTypes : state.implicitTypes;
1356
+ for(index = 0, length = typeList.length; index < length; index += 1){
1357
+ type = typeList[index];
1358
+ if ((type.instanceOf || type.predicate) && (!type.instanceOf || typeof object === "object" && _instanceof(object, type.instanceOf)) && (!type.predicate || type.predicate(object))) {
1359
+ if (explicit) {
1360
+ if (type.multi && type.representName) {
1361
+ state.tag = type.representName(object);
1362
+ } else {
1363
+ state.tag = type.tag;
1364
+ }
1365
+ } else {
1366
+ state.tag = "?";
1367
+ }
1368
+ if (type.represent) {
1369
+ style = state.styleMap[type.tag] || type.defaultStyle;
1370
+ if (_toString.call(type.represent) === "[object Function]") {
1371
+ _result = type.represent(object, style);
1372
+ } else if (_hasOwnProperty.call(type.represent, style)) {
1373
+ _result = type.represent[style](object, style);
1374
+ } else {
1375
+ throw new exception("!<" + type.tag + '> tag resolver accepts not "' + style + '" style');
1376
+ }
1377
+ state.dump = _result;
1378
+ }
1379
+ return true;
1380
+ }
1381
+ }
1382
+ return false;
1383
+ }
1384
+ // Serializes `object` and writes it to global `result`.
1385
+ // Returns true on success, or false on invalid object.
1386
+ //
1387
+ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
1388
+ state.tag = null;
1389
+ state.dump = object;
1390
+ if (!detectType(state, object, false)) {
1391
+ detectType(state, object, true);
1392
+ }
1393
+ var type = _toString.call(state.dump);
1394
+ var inblock = block;
1395
+ var tagStr;
1396
+ if (block) {
1397
+ block = state.flowLevel < 0 || state.flowLevel > level;
1398
+ }
1399
+ var objectOrArray = type === "[object Object]" || type === "[object Array]", duplicateIndex, duplicate;
1400
+ if (objectOrArray) {
1401
+ duplicateIndex = state.duplicates.indexOf(object);
1402
+ duplicate = duplicateIndex !== -1;
1403
+ }
1404
+ if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
1405
+ compact = false;
1406
+ }
1407
+ if (duplicate && state.usedDuplicates[duplicateIndex]) {
1408
+ state.dump = "*ref_" + duplicateIndex;
1409
+ } else {
1410
+ if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
1411
+ state.usedDuplicates[duplicateIndex] = true;
1412
+ }
1413
+ if (type === "[object Object]") {
1414
+ if (block && Object.keys(state.dump).length !== 0) {
1415
+ writeBlockMapping(state, level, state.dump, compact);
1416
+ if (duplicate) {
1417
+ state.dump = "&ref_" + duplicateIndex + state.dump;
1418
+ }
1419
+ } else {
1420
+ writeFlowMapping(state, level, state.dump);
1421
+ if (duplicate) {
1422
+ state.dump = "&ref_" + duplicateIndex + " " + state.dump;
1423
+ }
1424
+ }
1425
+ } else if (type === "[object Array]") {
1426
+ if (block && state.dump.length !== 0) {
1427
+ if (state.noArrayIndent && !isblockseq && level > 0) {
1428
+ writeBlockSequence(state, level - 1, state.dump, compact);
1429
+ } else {
1430
+ writeBlockSequence(state, level, state.dump, compact);
1431
+ }
1432
+ if (duplicate) {
1433
+ state.dump = "&ref_" + duplicateIndex + state.dump;
1434
+ }
1435
+ } else {
1436
+ writeFlowSequence(state, level, state.dump);
1437
+ if (duplicate) {
1438
+ state.dump = "&ref_" + duplicateIndex + " " + state.dump;
1439
+ }
1440
+ }
1441
+ } else if (type === "[object String]") {
1442
+ if (state.tag !== "?") {
1443
+ writeScalar(state, state.dump, level, iskey, inblock);
1444
+ }
1445
+ } else if (type === "[object Undefined]") {
1446
+ return false;
1447
+ } else {
1448
+ if (state.skipInvalid) return false;
1449
+ throw new exception("unacceptable kind of an object to dump " + type);
1450
+ }
1451
+ if (state.tag !== null && state.tag !== "?") {
1452
+ // Need to encode all characters except those allowed by the spec:
1453
+ //
1454
+ // [35] ns-dec-digit ::= [#x30-#x39] /* 0-9 */
1455
+ // [36] ns-hex-digit ::= ns-dec-digit
1456
+ // | [#x41-#x46] /* A-F */ | [#x61-#x66] /* a-f */
1457
+ // [37] ns-ascii-letter ::= [#x41-#x5A] /* A-Z */ | [#x61-#x7A] /* a-z */
1458
+ // [38] ns-word-char ::= ns-dec-digit | ns-ascii-letter | “-”
1459
+ // [39] ns-uri-char ::= “%” ns-hex-digit ns-hex-digit | ns-word-char | “#”
1460
+ // | “;” | “/” | “?” | “:” | “@” | “&” | “=” | “+” | “$” | “,”
1461
+ // | “_” | “.” | “!” | “~” | “*” | “'” | “(” | “)” | “[” | “]”
1462
+ //
1463
+ // Also need to encode '!' because it has special meaning (end of tag prefix).
1464
+ //
1465
+ tagStr = encodeURI(state.tag[0] === "!" ? state.tag.slice(1) : state.tag).replace(/!/g, "%21");
1466
+ if (state.tag[0] === "!") {
1467
+ tagStr = "!" + tagStr;
1468
+ } else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
1469
+ tagStr = "!!" + tagStr.slice(18);
1470
+ } else {
1471
+ tagStr = "!<" + tagStr + ">";
1472
+ }
1473
+ state.dump = tagStr + " " + state.dump;
1474
+ }
1475
+ }
1476
+ return true;
1477
+ }
1478
+ function getDuplicateReferences(object, state) {
1479
+ var objects = [], duplicatesIndexes = [], index, length;
1480
+ inspectNode(object, objects, duplicatesIndexes);
1481
+ for(index = 0, length = duplicatesIndexes.length; index < length; index += 1){
1482
+ state.duplicates.push(objects[duplicatesIndexes[index]]);
1483
+ }
1484
+ state.usedDuplicates = new Array(length);
1485
+ }
1486
+ function inspectNode(object, objects, duplicatesIndexes) {
1487
+ var objectKeyList, index, length;
1488
+ if (object !== null && typeof object === "object") {
1489
+ index = objects.indexOf(object);
1490
+ if (index !== -1) {
1491
+ if (duplicatesIndexes.indexOf(index) === -1) {
1492
+ duplicatesIndexes.push(index);
1493
+ }
1494
+ } else {
1495
+ objects.push(object);
1496
+ if (Array.isArray(object)) {
1497
+ for(index = 0, length = object.length; index < length; index += 1){
1498
+ inspectNode(object[index], objects, duplicatesIndexes);
1499
+ }
1500
+ } else {
1501
+ objectKeyList = Object.keys(object);
1502
+ for(index = 0, length = objectKeyList.length; index < length; index += 1){
1503
+ inspectNode(object[objectKeyList[index]], objects, duplicatesIndexes);
1504
+ }
1505
+ }
1506
+ }
1507
+ }
1508
+ }
1509
+ function dump$1(input, options) {
1510
+ options = options || {};
1511
+ var state = new State(options);
1512
+ if (!state.noRefs) getDuplicateReferences(input, state);
1513
+ var value = input;
1514
+ if (state.replacer) {
1515
+ value = state.replacer.call({
1516
+ "": value
1517
+ }, "", value);
1518
+ }
1519
+ if (writeNode(state, 0, value, true, true)) return state.dump + "\n";
1520
+ return "";
1521
+ }
1522
+ var dump_1 = dump$1;
1523
+ var dumper = {
1524
+ dump: dump_1
1525
+ };
1526
+ var dump$2 = dumper.dump;
1527
+
1528
+ let YamlService = class YamlService {
1529
+ async load(params, _pinsSettingsList, context) {
1530
+ const { yaml, options = {} } = params;
1531
+ return yaml.load(yaml, options);
1532
+ }
1533
+ async dump(params, _pinsSettingsList, context) {
1534
+ const { data, options = {} } = params;
1535
+ return dump$2(data, options);
1536
+ }
1537
+ };
1538
+ const load = (params, pinsSettingsList, context)=>new YamlService().load(params, pinsSettingsList, context);
1539
+ const dump = (params, pinsSettingsList, context)=>new YamlService().dump(params, pinsSettingsList, context);
1540
+
1541
+ exports.dump = dump;
1542
+ exports.load = load;