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