@digipair/skill-yaml 0.94.0-4 → 0.95.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/{dist/index.cjs.js → index.cjs.js} +445 -432
- package/index.d.ts +1 -0
- package/{dist/index.esm.js → index.esm.js} +443 -432
- package/libs/skill-yaml/src/index.d.ts +1 -0
- package/{dist → libs/skill-yaml}/src/lib/skill-yaml.d.ts +0 -1
- package/package.json +5 -21
- package/README.md +0 -7
- package/dist/src/index.d.ts +0 -2
- package/dist/src/index.d.ts.map +0 -1
- package/dist/src/lib/skill-yaml.d.ts.map +0 -1
- package/dist/src/lib/skill-yaml.spec.d.ts +0 -2
- package/dist/src/lib/skill-yaml.spec.d.ts.map +0 -1
- /package/{dist/index.d.ts → index.cjs.d.ts} +0 -0
- /package/{dist/schema.fr.json → schema.fr.json} +0 -0
- /package/{dist/schema.json → schema.json} +0 -0
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
3
5
|
/*! js-yaml 4.1.0 https://github.com/nodeca/js-yaml @license MIT */ function _instanceof(left, right) {
|
|
4
6
|
if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
|
|
5
7
|
return !!right[Symbol.hasInstance](left);
|
|
@@ -7,15 +9,11 @@
|
|
|
7
9
|
return left instanceof right;
|
|
8
10
|
}
|
|
9
11
|
}
|
|
10
|
-
function _type_of(obj) {
|
|
11
|
-
"@swc/helpers - typeof";
|
|
12
|
-
return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj;
|
|
13
|
-
}
|
|
14
12
|
function isNothing(subject) {
|
|
15
|
-
return typeof subject ===
|
|
13
|
+
return typeof subject === "undefined" || subject === null;
|
|
16
14
|
}
|
|
17
15
|
function isObject(subject) {
|
|
18
|
-
return
|
|
16
|
+
return typeof subject === "object" && subject !== null;
|
|
19
17
|
}
|
|
20
18
|
function toArray(sequence) {
|
|
21
19
|
if (Array.isArray(sequence)) return sequence;
|
|
@@ -36,7 +34,7 @@ function extend(target, source) {
|
|
|
36
34
|
return target;
|
|
37
35
|
}
|
|
38
36
|
function repeat(string, count) {
|
|
39
|
-
var result =
|
|
37
|
+
var result = "", cycle;
|
|
40
38
|
for(cycle = 0; cycle < count; cycle += 1){
|
|
41
39
|
result += string;
|
|
42
40
|
}
|
|
@@ -61,21 +59,21 @@ var common = {
|
|
|
61
59
|
};
|
|
62
60
|
// YAML error class. http://stackoverflow.com/questions/8458984
|
|
63
61
|
function formatError(exception, compact) {
|
|
64
|
-
var where =
|
|
62
|
+
var where = "", message = exception.reason || "(unknown reason)";
|
|
65
63
|
if (!exception.mark) return message;
|
|
66
64
|
if (exception.mark.name) {
|
|
67
65
|
where += 'in "' + exception.mark.name + '" ';
|
|
68
66
|
}
|
|
69
|
-
where +=
|
|
67
|
+
where += "(" + (exception.mark.line + 1) + ":" + (exception.mark.column + 1) + ")";
|
|
70
68
|
if (!compact && exception.mark.snippet) {
|
|
71
|
-
where +=
|
|
69
|
+
where += "\n\n" + exception.mark.snippet;
|
|
72
70
|
}
|
|
73
|
-
return message +
|
|
71
|
+
return message + " " + where;
|
|
74
72
|
}
|
|
75
73
|
function YAMLException$1(reason, mark) {
|
|
76
74
|
// Super constructor
|
|
77
75
|
Error.call(this);
|
|
78
|
-
this.name =
|
|
76
|
+
this.name = "YAMLException";
|
|
79
77
|
this.reason = reason;
|
|
80
78
|
this.mark = mark;
|
|
81
79
|
this.message = formatError(this, false);
|
|
@@ -85,44 +83,44 @@ function YAMLException$1(reason, mark) {
|
|
|
85
83
|
Error.captureStackTrace(this, this.constructor);
|
|
86
84
|
} else {
|
|
87
85
|
// FF, IE 10+ and Safari 6+. Fallback for others
|
|
88
|
-
this.stack = new Error().stack ||
|
|
86
|
+
this.stack = new Error().stack || "";
|
|
89
87
|
}
|
|
90
88
|
}
|
|
91
89
|
// Inherit from Error
|
|
92
90
|
YAMLException$1.prototype = Object.create(Error.prototype);
|
|
93
91
|
YAMLException$1.prototype.constructor = YAMLException$1;
|
|
94
92
|
YAMLException$1.prototype.toString = function toString(compact) {
|
|
95
|
-
return this.name +
|
|
93
|
+
return this.name + ": " + formatError(this, compact);
|
|
96
94
|
};
|
|
97
95
|
var exception = YAMLException$1;
|
|
98
96
|
// get snippet for a single line, respecting maxLength
|
|
99
97
|
function getLine(buffer, lineStart, lineEnd, position, maxLineLength) {
|
|
100
|
-
var head =
|
|
101
|
-
var tail =
|
|
98
|
+
var head = "";
|
|
99
|
+
var tail = "";
|
|
102
100
|
var maxHalfLength = Math.floor(maxLineLength / 2) - 1;
|
|
103
101
|
if (position - lineStart > maxHalfLength) {
|
|
104
|
-
head =
|
|
102
|
+
head = " ... ";
|
|
105
103
|
lineStart = position - maxHalfLength + head.length;
|
|
106
104
|
}
|
|
107
105
|
if (lineEnd - position > maxHalfLength) {
|
|
108
|
-
tail =
|
|
106
|
+
tail = " ...";
|
|
109
107
|
lineEnd = position + maxHalfLength - tail.length;
|
|
110
108
|
}
|
|
111
109
|
return {
|
|
112
|
-
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g,
|
|
110
|
+
str: head + buffer.slice(lineStart, lineEnd).replace(/\t/g, "→") + tail,
|
|
113
111
|
pos: position - lineStart + head.length // relative position
|
|
114
112
|
};
|
|
115
113
|
}
|
|
116
114
|
function padStart(string, max) {
|
|
117
|
-
return common.repeat(
|
|
115
|
+
return common.repeat(" ", max - string.length) + string;
|
|
118
116
|
}
|
|
119
117
|
function makeSnippet(mark, options) {
|
|
120
118
|
options = Object.create(options || null);
|
|
121
119
|
if (!mark.buffer) return null;
|
|
122
120
|
if (!options.maxLength) options.maxLength = 79;
|
|
123
|
-
if (typeof options.indent !==
|
|
124
|
-
if (typeof options.linesBefore !==
|
|
125
|
-
if (typeof options.linesAfter !==
|
|
121
|
+
if (typeof options.indent !== "number") options.indent = 1;
|
|
122
|
+
if (typeof options.linesBefore !== "number") options.linesBefore = 3;
|
|
123
|
+
if (typeof options.linesAfter !== "number") options.linesAfter = 2;
|
|
126
124
|
var re = /\r?\n|\r|\0/g;
|
|
127
125
|
var lineStarts = [
|
|
128
126
|
0
|
|
@@ -138,41 +136,41 @@ function makeSnippet(mark, options) {
|
|
|
138
136
|
}
|
|
139
137
|
}
|
|
140
138
|
if (foundLineNo < 0) foundLineNo = lineStarts.length - 1;
|
|
141
|
-
var result =
|
|
139
|
+
var result = "", i, line;
|
|
142
140
|
var lineNoLength = Math.min(mark.line + options.linesAfter, lineEnds.length).toString().length;
|
|
143
141
|
var maxLineLength = options.maxLength - (options.indent + lineNoLength + 3);
|
|
144
142
|
for(i = 1; i <= options.linesBefore; i++){
|
|
145
143
|
if (foundLineNo - i < 0) break;
|
|
146
144
|
line = getLine(mark.buffer, lineStarts[foundLineNo - i], lineEnds[foundLineNo - i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo - i]), maxLineLength);
|
|
147
|
-
result = common.repeat(
|
|
145
|
+
result = common.repeat(" ", options.indent) + padStart((mark.line - i + 1).toString(), lineNoLength) + " | " + line.str + "\n" + result;
|
|
148
146
|
}
|
|
149
147
|
line = getLine(mark.buffer, lineStarts[foundLineNo], lineEnds[foundLineNo], mark.position, maxLineLength);
|
|
150
|
-
result += common.repeat(
|
|
151
|
-
result += common.repeat(
|
|
148
|
+
result += common.repeat(" ", options.indent) + padStart((mark.line + 1).toString(), lineNoLength) + " | " + line.str + "\n";
|
|
149
|
+
result += common.repeat("-", options.indent + lineNoLength + 3 + line.pos) + "^" + "\n";
|
|
152
150
|
for(i = 1; i <= options.linesAfter; i++){
|
|
153
151
|
if (foundLineNo + i >= lineEnds.length) break;
|
|
154
152
|
line = getLine(mark.buffer, lineStarts[foundLineNo + i], lineEnds[foundLineNo + i], mark.position - (lineStarts[foundLineNo] - lineStarts[foundLineNo + i]), maxLineLength);
|
|
155
|
-
result += common.repeat(
|
|
153
|
+
result += common.repeat(" ", options.indent) + padStart((mark.line + i + 1).toString(), lineNoLength) + " | " + line.str + "\n";
|
|
156
154
|
}
|
|
157
|
-
return result.replace(/\n$/,
|
|
155
|
+
return result.replace(/\n$/, "");
|
|
158
156
|
}
|
|
159
157
|
var snippet = makeSnippet;
|
|
160
158
|
var TYPE_CONSTRUCTOR_OPTIONS = [
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
159
|
+
"kind",
|
|
160
|
+
"multi",
|
|
161
|
+
"resolve",
|
|
162
|
+
"construct",
|
|
163
|
+
"instanceOf",
|
|
164
|
+
"predicate",
|
|
165
|
+
"represent",
|
|
166
|
+
"representName",
|
|
167
|
+
"defaultStyle",
|
|
168
|
+
"styleAliases"
|
|
171
169
|
];
|
|
172
170
|
var YAML_NODE_KINDS = [
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
171
|
+
"scalar",
|
|
172
|
+
"sequence",
|
|
173
|
+
"mapping"
|
|
176
174
|
];
|
|
177
175
|
function compileStyleAliases(map) {
|
|
178
176
|
var result = {};
|
|
@@ -195,20 +193,20 @@ function Type$1(tag, options) {
|
|
|
195
193
|
// TODO: Add tag format check.
|
|
196
194
|
this.options = options; // keep original options in case user wants to extend this type later
|
|
197
195
|
this.tag = tag;
|
|
198
|
-
this.kind = options[
|
|
199
|
-
this.resolve = options[
|
|
196
|
+
this.kind = options["kind"] || null;
|
|
197
|
+
this.resolve = options["resolve"] || function() {
|
|
200
198
|
return true;
|
|
201
199
|
};
|
|
202
|
-
this.construct = options[
|
|
200
|
+
this.construct = options["construct"] || function(data) {
|
|
203
201
|
return data;
|
|
204
202
|
};
|
|
205
|
-
this.instanceOf = options[
|
|
206
|
-
this.predicate = options[
|
|
207
|
-
this.represent = options[
|
|
208
|
-
this.representName = options[
|
|
209
|
-
this.defaultStyle = options[
|
|
210
|
-
this.multi = options[
|
|
211
|
-
this.styleAliases = compileStyleAliases(options[
|
|
203
|
+
this.instanceOf = options["instanceOf"] || null;
|
|
204
|
+
this.predicate = options["predicate"] || null;
|
|
205
|
+
this.represent = options["represent"] || null;
|
|
206
|
+
this.representName = options["representName"] || null;
|
|
207
|
+
this.defaultStyle = options["defaultStyle"] || null;
|
|
208
|
+
this.multi = options["multi"] || false;
|
|
209
|
+
this.styleAliases = compileStyleAliases(options["styleAliases"] || null);
|
|
212
210
|
if (YAML_NODE_KINDS.indexOf(this.kind) === -1) {
|
|
213
211
|
throw new exception('Unknown kind "' + this.kind + '" is specified for "' + tag + '" YAML type.');
|
|
214
212
|
}
|
|
@@ -243,9 +241,9 @@ function compileMap() {
|
|
|
243
241
|
function collectType(type) {
|
|
244
242
|
if (type.multi) {
|
|
245
243
|
result.multi[type.kind].push(type);
|
|
246
|
-
result.multi[
|
|
244
|
+
result.multi["fallback"].push(type);
|
|
247
245
|
} else {
|
|
248
|
-
result[type.kind][type.tag] = result[
|
|
246
|
+
result[type.kind][type.tag] = result["fallback"][type.tag] = type;
|
|
249
247
|
}
|
|
250
248
|
}
|
|
251
249
|
for(index = 0, length = arguments.length; index < length; index += 1){
|
|
@@ -270,47 +268,47 @@ Schema$1.prototype.extend = function extend(definition) {
|
|
|
270
268
|
if (definition.implicit) implicit = implicit.concat(definition.implicit);
|
|
271
269
|
if (definition.explicit) explicit = explicit.concat(definition.explicit);
|
|
272
270
|
} else {
|
|
273
|
-
throw new exception(
|
|
271
|
+
throw new exception("Schema.extend argument should be a Type, [ Type ], " + "or a schema definition ({ implicit: [...], explicit: [...] })");
|
|
274
272
|
}
|
|
275
273
|
implicit.forEach(function(type$1) {
|
|
276
274
|
if (!_instanceof(type$1, type)) {
|
|
277
|
-
throw new exception(
|
|
275
|
+
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
278
276
|
}
|
|
279
|
-
if (type$1.loadKind && type$1.loadKind !==
|
|
280
|
-
throw new exception(
|
|
277
|
+
if (type$1.loadKind && type$1.loadKind !== "scalar") {
|
|
278
|
+
throw new exception("There is a non-scalar type in the implicit list of a schema. Implicit resolving of such types is not supported.");
|
|
281
279
|
}
|
|
282
280
|
if (type$1.multi) {
|
|
283
|
-
throw new exception(
|
|
281
|
+
throw new exception("There is a multi type in the implicit list of a schema. Multi tags can only be listed as explicit.");
|
|
284
282
|
}
|
|
285
283
|
});
|
|
286
284
|
explicit.forEach(function(type$1) {
|
|
287
285
|
if (!_instanceof(type$1, type)) {
|
|
288
|
-
throw new exception(
|
|
286
|
+
throw new exception("Specified list of YAML types (or a single Type object) contains a non-Type object.");
|
|
289
287
|
}
|
|
290
288
|
});
|
|
291
289
|
var result = Object.create(Schema$1.prototype);
|
|
292
290
|
result.implicit = (this.implicit || []).concat(implicit);
|
|
293
291
|
result.explicit = (this.explicit || []).concat(explicit);
|
|
294
|
-
result.compiledImplicit = compileList(result,
|
|
295
|
-
result.compiledExplicit = compileList(result,
|
|
292
|
+
result.compiledImplicit = compileList(result, "implicit");
|
|
293
|
+
result.compiledExplicit = compileList(result, "explicit");
|
|
296
294
|
result.compiledTypeMap = compileMap(result.compiledImplicit, result.compiledExplicit);
|
|
297
295
|
return result;
|
|
298
296
|
};
|
|
299
297
|
var schema = Schema$1;
|
|
300
|
-
var str = new type(
|
|
301
|
-
kind:
|
|
298
|
+
var str = new type("tag:yaml.org,2002:str", {
|
|
299
|
+
kind: "scalar",
|
|
302
300
|
construct: function construct(data) {
|
|
303
|
-
return data !== null ? data :
|
|
301
|
+
return data !== null ? data : "";
|
|
304
302
|
}
|
|
305
303
|
});
|
|
306
|
-
var seq = new type(
|
|
307
|
-
kind:
|
|
304
|
+
var seq = new type("tag:yaml.org,2002:seq", {
|
|
305
|
+
kind: "sequence",
|
|
308
306
|
construct: function construct(data) {
|
|
309
307
|
return data !== null ? data : [];
|
|
310
308
|
}
|
|
311
309
|
});
|
|
312
|
-
var map = new type(
|
|
313
|
-
kind:
|
|
310
|
+
var map = new type("tag:yaml.org,2002:map", {
|
|
311
|
+
kind: "mapping",
|
|
314
312
|
construct: function construct(data) {
|
|
315
313
|
return data !== null ? data : {};
|
|
316
314
|
}
|
|
@@ -325,7 +323,7 @@ var failsafe = new schema({
|
|
|
325
323
|
function resolveYamlNull(data) {
|
|
326
324
|
if (data === null) return true;
|
|
327
325
|
var max = data.length;
|
|
328
|
-
return max === 1 && data ===
|
|
326
|
+
return max === 1 && data === "~" || max === 4 && (data === "null" || data === "Null" || data === "NULL");
|
|
329
327
|
}
|
|
330
328
|
function constructYamlNull() {
|
|
331
329
|
return null;
|
|
@@ -333,58 +331,58 @@ function constructYamlNull() {
|
|
|
333
331
|
function isNull(object) {
|
|
334
332
|
return object === null;
|
|
335
333
|
}
|
|
336
|
-
var _null = new type(
|
|
337
|
-
kind:
|
|
334
|
+
var _null = new type("tag:yaml.org,2002:null", {
|
|
335
|
+
kind: "scalar",
|
|
338
336
|
resolve: resolveYamlNull,
|
|
339
337
|
construct: constructYamlNull,
|
|
340
338
|
predicate: isNull,
|
|
341
339
|
represent: {
|
|
342
340
|
canonical: function canonical() {
|
|
343
|
-
return
|
|
341
|
+
return "~";
|
|
344
342
|
},
|
|
345
343
|
lowercase: function lowercase() {
|
|
346
|
-
return
|
|
344
|
+
return "null";
|
|
347
345
|
},
|
|
348
346
|
uppercase: function uppercase() {
|
|
349
|
-
return
|
|
347
|
+
return "NULL";
|
|
350
348
|
},
|
|
351
349
|
camelcase: function camelcase() {
|
|
352
|
-
return
|
|
350
|
+
return "Null";
|
|
353
351
|
},
|
|
354
352
|
empty: function empty() {
|
|
355
|
-
return
|
|
353
|
+
return "";
|
|
356
354
|
}
|
|
357
355
|
},
|
|
358
|
-
defaultStyle:
|
|
356
|
+
defaultStyle: "lowercase"
|
|
359
357
|
});
|
|
360
358
|
function resolveYamlBoolean(data) {
|
|
361
359
|
if (data === null) return false;
|
|
362
360
|
var max = data.length;
|
|
363
|
-
return max === 4 && (data ===
|
|
361
|
+
return max === 4 && (data === "true" || data === "True" || data === "TRUE") || max === 5 && (data === "false" || data === "False" || data === "FALSE");
|
|
364
362
|
}
|
|
365
363
|
function constructYamlBoolean(data) {
|
|
366
|
-
return data ===
|
|
364
|
+
return data === "true" || data === "True" || data === "TRUE";
|
|
367
365
|
}
|
|
368
366
|
function isBoolean(object) {
|
|
369
|
-
return Object.prototype.toString.call(object) ===
|
|
367
|
+
return Object.prototype.toString.call(object) === "[object Boolean]";
|
|
370
368
|
}
|
|
371
|
-
var bool = new type(
|
|
372
|
-
kind:
|
|
369
|
+
var bool = new type("tag:yaml.org,2002:bool", {
|
|
370
|
+
kind: "scalar",
|
|
373
371
|
resolve: resolveYamlBoolean,
|
|
374
372
|
construct: constructYamlBoolean,
|
|
375
373
|
predicate: isBoolean,
|
|
376
374
|
represent: {
|
|
377
375
|
lowercase: function lowercase(object) {
|
|
378
|
-
return object ?
|
|
376
|
+
return object ? "true" : "false";
|
|
379
377
|
},
|
|
380
378
|
uppercase: function uppercase(object) {
|
|
381
|
-
return object ?
|
|
379
|
+
return object ? "TRUE" : "FALSE";
|
|
382
380
|
},
|
|
383
381
|
camelcase: function camelcase(object) {
|
|
384
|
-
return object ?
|
|
382
|
+
return object ? "True" : "False";
|
|
385
383
|
}
|
|
386
384
|
},
|
|
387
|
-
defaultStyle:
|
|
385
|
+
defaultStyle: "lowercase"
|
|
388
386
|
});
|
|
389
387
|
function isHexCode(c) {
|
|
390
388
|
return 0x30 /* 0 */ <= c && c <= 0x39 /* 9 */ || 0x41 /* A */ <= c && c <= 0x46 /* F */ || 0x61 /* a */ <= c && c <= 0x66 /* f */ ;
|
|
@@ -401,149 +399,149 @@ function resolveYamlInteger(data) {
|
|
|
401
399
|
if (!max) return false;
|
|
402
400
|
ch = data[index];
|
|
403
401
|
// sign
|
|
404
|
-
if (ch ===
|
|
402
|
+
if (ch === "-" || ch === "+") {
|
|
405
403
|
ch = data[++index];
|
|
406
404
|
}
|
|
407
|
-
if (ch ===
|
|
405
|
+
if (ch === "0") {
|
|
408
406
|
// 0
|
|
409
407
|
if (index + 1 === max) return true;
|
|
410
408
|
ch = data[++index];
|
|
411
409
|
// base 2, base 8, base 16
|
|
412
|
-
if (ch ===
|
|
410
|
+
if (ch === "b") {
|
|
413
411
|
// base 2
|
|
414
412
|
index++;
|
|
415
413
|
for(; index < max; index++){
|
|
416
414
|
ch = data[index];
|
|
417
|
-
if (ch ===
|
|
418
|
-
if (ch !==
|
|
415
|
+
if (ch === "_") continue;
|
|
416
|
+
if (ch !== "0" && ch !== "1") return false;
|
|
419
417
|
hasDigits = true;
|
|
420
418
|
}
|
|
421
|
-
return hasDigits && ch !==
|
|
419
|
+
return hasDigits && ch !== "_";
|
|
422
420
|
}
|
|
423
|
-
if (ch ===
|
|
421
|
+
if (ch === "x") {
|
|
424
422
|
// base 16
|
|
425
423
|
index++;
|
|
426
424
|
for(; index < max; index++){
|
|
427
425
|
ch = data[index];
|
|
428
|
-
if (ch ===
|
|
426
|
+
if (ch === "_") continue;
|
|
429
427
|
if (!isHexCode(data.charCodeAt(index))) return false;
|
|
430
428
|
hasDigits = true;
|
|
431
429
|
}
|
|
432
|
-
return hasDigits && ch !==
|
|
430
|
+
return hasDigits && ch !== "_";
|
|
433
431
|
}
|
|
434
|
-
if (ch ===
|
|
432
|
+
if (ch === "o") {
|
|
435
433
|
// base 8
|
|
436
434
|
index++;
|
|
437
435
|
for(; index < max; index++){
|
|
438
436
|
ch = data[index];
|
|
439
|
-
if (ch ===
|
|
437
|
+
if (ch === "_") continue;
|
|
440
438
|
if (!isOctCode(data.charCodeAt(index))) return false;
|
|
441
439
|
hasDigits = true;
|
|
442
440
|
}
|
|
443
|
-
return hasDigits && ch !==
|
|
441
|
+
return hasDigits && ch !== "_";
|
|
444
442
|
}
|
|
445
443
|
}
|
|
446
444
|
// base 10 (except 0)
|
|
447
445
|
// value should not start with `_`;
|
|
448
|
-
if (ch ===
|
|
446
|
+
if (ch === "_") return false;
|
|
449
447
|
for(; index < max; index++){
|
|
450
448
|
ch = data[index];
|
|
451
|
-
if (ch ===
|
|
449
|
+
if (ch === "_") continue;
|
|
452
450
|
if (!isDecCode(data.charCodeAt(index))) {
|
|
453
451
|
return false;
|
|
454
452
|
}
|
|
455
453
|
hasDigits = true;
|
|
456
454
|
}
|
|
457
455
|
// Should have digits and should not end with `_`
|
|
458
|
-
if (!hasDigits || ch ===
|
|
456
|
+
if (!hasDigits || ch === "_") return false;
|
|
459
457
|
return true;
|
|
460
458
|
}
|
|
461
459
|
function constructYamlInteger(data) {
|
|
462
460
|
var value = data, sign = 1, ch;
|
|
463
|
-
if (value.indexOf(
|
|
464
|
-
value = value.replace(/_/g,
|
|
461
|
+
if (value.indexOf("_") !== -1) {
|
|
462
|
+
value = value.replace(/_/g, "");
|
|
465
463
|
}
|
|
466
464
|
ch = value[0];
|
|
467
|
-
if (ch ===
|
|
468
|
-
if (ch ===
|
|
465
|
+
if (ch === "-" || ch === "+") {
|
|
466
|
+
if (ch === "-") sign = -1;
|
|
469
467
|
value = value.slice(1);
|
|
470
468
|
ch = value[0];
|
|
471
469
|
}
|
|
472
|
-
if (value ===
|
|
473
|
-
if (ch ===
|
|
474
|
-
if (value[1] ===
|
|
475
|
-
if (value[1] ===
|
|
476
|
-
if (value[1] ===
|
|
470
|
+
if (value === "0") return 0;
|
|
471
|
+
if (ch === "0") {
|
|
472
|
+
if (value[1] === "b") return sign * parseInt(value.slice(2), 2);
|
|
473
|
+
if (value[1] === "x") return sign * parseInt(value.slice(2), 16);
|
|
474
|
+
if (value[1] === "o") return sign * parseInt(value.slice(2), 8);
|
|
477
475
|
}
|
|
478
476
|
return sign * parseInt(value, 10);
|
|
479
477
|
}
|
|
480
478
|
function isInteger(object) {
|
|
481
|
-
return Object.prototype.toString.call(object) ===
|
|
479
|
+
return Object.prototype.toString.call(object) === "[object Number]" && object % 1 === 0 && !common.isNegativeZero(object);
|
|
482
480
|
}
|
|
483
|
-
var int = new type(
|
|
484
|
-
kind:
|
|
481
|
+
var int = new type("tag:yaml.org,2002:int", {
|
|
482
|
+
kind: "scalar",
|
|
485
483
|
resolve: resolveYamlInteger,
|
|
486
484
|
construct: constructYamlInteger,
|
|
487
485
|
predicate: isInteger,
|
|
488
486
|
represent: {
|
|
489
487
|
binary: function binary(obj) {
|
|
490
|
-
return obj >= 0 ?
|
|
488
|
+
return obj >= 0 ? "0b" + obj.toString(2) : "-0b" + obj.toString(2).slice(1);
|
|
491
489
|
},
|
|
492
490
|
octal: function octal(obj) {
|
|
493
|
-
return obj >= 0 ?
|
|
491
|
+
return obj >= 0 ? "0o" + obj.toString(8) : "-0o" + obj.toString(8).slice(1);
|
|
494
492
|
},
|
|
495
493
|
decimal: function decimal(obj) {
|
|
496
494
|
return obj.toString(10);
|
|
497
495
|
},
|
|
498
496
|
/* eslint-disable max-len */ hexadecimal: function hexadecimal(obj) {
|
|
499
|
-
return obj >= 0 ?
|
|
497
|
+
return obj >= 0 ? "0x" + obj.toString(16).toUpperCase() : "-0x" + obj.toString(16).toUpperCase().slice(1);
|
|
500
498
|
}
|
|
501
499
|
},
|
|
502
|
-
defaultStyle:
|
|
500
|
+
defaultStyle: "decimal",
|
|
503
501
|
styleAliases: {
|
|
504
502
|
binary: [
|
|
505
503
|
2,
|
|
506
|
-
|
|
504
|
+
"bin"
|
|
507
505
|
],
|
|
508
506
|
octal: [
|
|
509
507
|
8,
|
|
510
|
-
|
|
508
|
+
"oct"
|
|
511
509
|
],
|
|
512
510
|
decimal: [
|
|
513
511
|
10,
|
|
514
|
-
|
|
512
|
+
"dec"
|
|
515
513
|
],
|
|
516
514
|
hexadecimal: [
|
|
517
515
|
16,
|
|
518
|
-
|
|
516
|
+
"hex"
|
|
519
517
|
]
|
|
520
518
|
}
|
|
521
519
|
});
|
|
522
520
|
var YAML_FLOAT_PATTERN = new RegExp(// 2.5e4, 2.5 and integers
|
|
523
|
-
|
|
521
|
+
"^(?:[-+]?(?:[0-9][0-9_]*)(?:\\.[0-9_]*)?(?:[eE][-+]?[0-9]+)?" + // .2e4, .2
|
|
524
522
|
// special case, seems not from spec
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
523
|
+
"|\\.[0-9_]+(?:[eE][-+]?[0-9]+)?" + // .inf
|
|
524
|
+
"|[-+]?\\.(?:inf|Inf|INF)" + // .nan
|
|
525
|
+
"|\\.(?:nan|NaN|NAN))$");
|
|
528
526
|
function resolveYamlFloat(data) {
|
|
529
527
|
if (data === null) return false;
|
|
530
528
|
if (!YAML_FLOAT_PATTERN.test(data) || // Quick hack to not allow integers end with `_`
|
|
531
529
|
// Probably should update regexp & check speed
|
|
532
|
-
data[data.length - 1] ===
|
|
530
|
+
data[data.length - 1] === "_") {
|
|
533
531
|
return false;
|
|
534
532
|
}
|
|
535
533
|
return true;
|
|
536
534
|
}
|
|
537
535
|
function constructYamlFloat(data) {
|
|
538
536
|
var value, sign;
|
|
539
|
-
value = data.replace(/_/g,
|
|
540
|
-
sign = value[0] ===
|
|
541
|
-
if (
|
|
537
|
+
value = data.replace(/_/g, "").toLowerCase();
|
|
538
|
+
sign = value[0] === "-" ? -1 : 1;
|
|
539
|
+
if ("+-".indexOf(value[0]) >= 0) {
|
|
542
540
|
value = value.slice(1);
|
|
543
541
|
}
|
|
544
|
-
if (value ===
|
|
542
|
+
if (value === ".inf") {
|
|
545
543
|
return sign === 1 ? Number.POSITIVE_INFINITY : Number.NEGATIVE_INFINITY;
|
|
546
|
-
} else if (value ===
|
|
544
|
+
} else if (value === ".nan") {
|
|
547
545
|
return NaN;
|
|
548
546
|
}
|
|
549
547
|
return sign * parseFloat(value, 10);
|
|
@@ -553,49 +551,49 @@ function representYamlFloat(object, style) {
|
|
|
553
551
|
var res;
|
|
554
552
|
if (isNaN(object)) {
|
|
555
553
|
switch(style){
|
|
556
|
-
case
|
|
557
|
-
return
|
|
558
|
-
case
|
|
559
|
-
return
|
|
560
|
-
case
|
|
561
|
-
return
|
|
554
|
+
case "lowercase":
|
|
555
|
+
return ".nan";
|
|
556
|
+
case "uppercase":
|
|
557
|
+
return ".NAN";
|
|
558
|
+
case "camelcase":
|
|
559
|
+
return ".NaN";
|
|
562
560
|
}
|
|
563
561
|
} else if (Number.POSITIVE_INFINITY === object) {
|
|
564
562
|
switch(style){
|
|
565
|
-
case
|
|
566
|
-
return
|
|
567
|
-
case
|
|
568
|
-
return
|
|
569
|
-
case
|
|
570
|
-
return
|
|
563
|
+
case "lowercase":
|
|
564
|
+
return ".inf";
|
|
565
|
+
case "uppercase":
|
|
566
|
+
return ".INF";
|
|
567
|
+
case "camelcase":
|
|
568
|
+
return ".Inf";
|
|
571
569
|
}
|
|
572
570
|
} else if (Number.NEGATIVE_INFINITY === object) {
|
|
573
571
|
switch(style){
|
|
574
|
-
case
|
|
575
|
-
return
|
|
576
|
-
case
|
|
577
|
-
return
|
|
578
|
-
case
|
|
579
|
-
return
|
|
572
|
+
case "lowercase":
|
|
573
|
+
return "-.inf";
|
|
574
|
+
case "uppercase":
|
|
575
|
+
return "-.INF";
|
|
576
|
+
case "camelcase":
|
|
577
|
+
return "-.Inf";
|
|
580
578
|
}
|
|
581
579
|
} else if (common.isNegativeZero(object)) {
|
|
582
|
-
return
|
|
580
|
+
return "-0.0";
|
|
583
581
|
}
|
|
584
582
|
res = object.toString(10);
|
|
585
583
|
// JS stringifier can build scientific format without dots: 5e-100,
|
|
586
584
|
// while YAML requres dot: 5.e-100. Fix it with simple hack
|
|
587
|
-
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace(
|
|
585
|
+
return SCIENTIFIC_WITHOUT_DOT.test(res) ? res.replace("e", ".e") : res;
|
|
588
586
|
}
|
|
589
587
|
function isFloat(object) {
|
|
590
|
-
return Object.prototype.toString.call(object) ===
|
|
588
|
+
return Object.prototype.toString.call(object) === "[object Number]" && (object % 1 !== 0 || common.isNegativeZero(object));
|
|
591
589
|
}
|
|
592
|
-
var float = new type(
|
|
593
|
-
kind:
|
|
590
|
+
var float = new type("tag:yaml.org,2002:float", {
|
|
591
|
+
kind: "scalar",
|
|
594
592
|
resolve: resolveYamlFloat,
|
|
595
593
|
construct: constructYamlFloat,
|
|
596
594
|
predicate: isFloat,
|
|
597
595
|
represent: representYamlFloat,
|
|
598
|
-
defaultStyle:
|
|
596
|
+
defaultStyle: "lowercase"
|
|
599
597
|
});
|
|
600
598
|
var json = failsafe.extend({
|
|
601
599
|
implicit: [
|
|
@@ -606,19 +604,19 @@ var json = failsafe.extend({
|
|
|
606
604
|
]
|
|
607
605
|
});
|
|
608
606
|
var core = json;
|
|
609
|
-
var YAML_DATE_REGEXP = new RegExp(
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
var YAML_TIMESTAMP_REGEXP = new RegExp(
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
607
|
+
var YAML_DATE_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])" + // [1] year
|
|
608
|
+
"-([0-9][0-9])" + // [2] month
|
|
609
|
+
"-([0-9][0-9])$"); // [3] day
|
|
610
|
+
var YAML_TIMESTAMP_REGEXP = new RegExp("^([0-9][0-9][0-9][0-9])" + // [1] year
|
|
611
|
+
"-([0-9][0-9]?)" + // [2] month
|
|
612
|
+
"-([0-9][0-9]?)" + // [3] day
|
|
613
|
+
"(?:[Tt]|[ \\t]+)" + // ...
|
|
614
|
+
"([0-9][0-9]?)" + // [4] hour
|
|
615
|
+
":([0-9][0-9])" + // [5] minute
|
|
616
|
+
":([0-9][0-9])" + // [6] second
|
|
617
|
+
"(?:\\.([0-9]*))?" + // [7] fraction
|
|
618
|
+
"(?:[ \\t]*(Z|([-+])([0-9][0-9]?)" + // [8] tz [9] tz_sign [10] tz_hour
|
|
619
|
+
"(?::([0-9][0-9]))?))?$"); // [11] tz_minute
|
|
622
620
|
function resolveYamlTimestamp(data) {
|
|
623
621
|
if (data === null) return false;
|
|
624
622
|
if (YAML_DATE_REGEXP.exec(data) !== null) return true;
|
|
@@ -629,7 +627,7 @@ function constructYamlTimestamp(data) {
|
|
|
629
627
|
var match, year, month, day, hour, minute, second, fraction = 0, delta = null, tz_hour, tz_minute, date;
|
|
630
628
|
match = YAML_DATE_REGEXP.exec(data);
|
|
631
629
|
if (match === null) match = YAML_TIMESTAMP_REGEXP.exec(data);
|
|
632
|
-
if (match === null) throw new Error(
|
|
630
|
+
if (match === null) throw new Error("Date resolve error");
|
|
633
631
|
// match: [1] year [2] month [3] day
|
|
634
632
|
year = +match[1];
|
|
635
633
|
month = +match[2] - 1; // JS month starts with 0
|
|
@@ -644,7 +642,7 @@ function constructYamlTimestamp(data) {
|
|
|
644
642
|
if (match[7]) {
|
|
645
643
|
fraction = match[7].slice(0, 3);
|
|
646
644
|
while(fraction.length < 3){
|
|
647
|
-
fraction +=
|
|
645
|
+
fraction += "0";
|
|
648
646
|
}
|
|
649
647
|
fraction = +fraction;
|
|
650
648
|
}
|
|
@@ -653,7 +651,7 @@ function constructYamlTimestamp(data) {
|
|
|
653
651
|
tz_hour = +match[10];
|
|
654
652
|
tz_minute = +(match[11] || 0);
|
|
655
653
|
delta = (tz_hour * 60 + tz_minute) * 60000; // delta in mili-seconds
|
|
656
|
-
if (match[9] ===
|
|
654
|
+
if (match[9] === "-") delta = -delta;
|
|
657
655
|
}
|
|
658
656
|
date = new Date(Date.UTC(year, month, day, hour, minute, second, fraction));
|
|
659
657
|
if (delta) date.setTime(date.getTime() - delta);
|
|
@@ -662,22 +660,22 @@ function constructYamlTimestamp(data) {
|
|
|
662
660
|
function representYamlTimestamp(object /*, style*/ ) {
|
|
663
661
|
return object.toISOString();
|
|
664
662
|
}
|
|
665
|
-
var timestamp = new type(
|
|
666
|
-
kind:
|
|
663
|
+
var timestamp = new type("tag:yaml.org,2002:timestamp", {
|
|
664
|
+
kind: "scalar",
|
|
667
665
|
resolve: resolveYamlTimestamp,
|
|
668
666
|
construct: constructYamlTimestamp,
|
|
669
667
|
instanceOf: Date,
|
|
670
668
|
represent: representYamlTimestamp
|
|
671
669
|
});
|
|
672
670
|
function resolveYamlMerge(data) {
|
|
673
|
-
return data ===
|
|
671
|
+
return data === "<<" || data === null;
|
|
674
672
|
}
|
|
675
|
-
var merge = new type(
|
|
676
|
-
kind:
|
|
673
|
+
var merge = new type("tag:yaml.org,2002:merge", {
|
|
674
|
+
kind: "scalar",
|
|
677
675
|
resolve: resolveYamlMerge
|
|
678
676
|
});
|
|
679
677
|
/*eslint-disable no-bitwise*/ // [ 64, 65, 66 ] -> [ padding, CR, LF ]
|
|
680
|
-
var BASE64_MAP =
|
|
678
|
+
var BASE64_MAP = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=\n\r";
|
|
681
679
|
function resolveYamlBinary(data) {
|
|
682
680
|
if (data === null) return false;
|
|
683
681
|
var code, idx, bitlen = 0, max = data.length, map = BASE64_MAP;
|
|
@@ -694,7 +692,7 @@ function resolveYamlBinary(data) {
|
|
|
694
692
|
return bitlen % 8 === 0;
|
|
695
693
|
}
|
|
696
694
|
function constructYamlBinary(data) {
|
|
697
|
-
var idx, tailbits, input = data.replace(/[\r\n=]/g,
|
|
695
|
+
var idx, tailbits, input = data.replace(/[\r\n=]/g, ""), max = input.length, map = BASE64_MAP, bits = 0, result = [];
|
|
698
696
|
// Collect by 6*4 bits (3 bytes)
|
|
699
697
|
for(idx = 0; idx < max; idx++){
|
|
700
698
|
if (idx % 4 === 0 && idx) {
|
|
@@ -719,7 +717,7 @@ function constructYamlBinary(data) {
|
|
|
719
717
|
return new Uint8Array(result);
|
|
720
718
|
}
|
|
721
719
|
function representYamlBinary(object /*, style*/ ) {
|
|
722
|
-
var result =
|
|
720
|
+
var result = "", bits = 0, idx, tail, max = object.length, map = BASE64_MAP;
|
|
723
721
|
// Convert every three bytes to 4 ASCII characters.
|
|
724
722
|
for(idx = 0; idx < max; idx++){
|
|
725
723
|
if (idx % 3 === 0 && idx) {
|
|
@@ -751,10 +749,10 @@ function representYamlBinary(object /*, style*/ ) {
|
|
|
751
749
|
return result;
|
|
752
750
|
}
|
|
753
751
|
function isBinary(obj) {
|
|
754
|
-
return Object.prototype.toString.call(obj) ===
|
|
752
|
+
return Object.prototype.toString.call(obj) === "[object Uint8Array]";
|
|
755
753
|
}
|
|
756
|
-
var binary = new type(
|
|
757
|
-
kind:
|
|
754
|
+
var binary = new type("tag:yaml.org,2002:binary", {
|
|
755
|
+
kind: "scalar",
|
|
758
756
|
resolve: resolveYamlBinary,
|
|
759
757
|
construct: constructYamlBinary,
|
|
760
758
|
predicate: isBinary,
|
|
@@ -768,7 +766,7 @@ function resolveYamlOmap(data) {
|
|
|
768
766
|
for(index = 0, length = object.length; index < length; index += 1){
|
|
769
767
|
pair = object[index];
|
|
770
768
|
pairHasKey = false;
|
|
771
|
-
if (_toString$2.call(pair) !==
|
|
769
|
+
if (_toString$2.call(pair) !== "[object Object]") return false;
|
|
772
770
|
for(pairKey in pair){
|
|
773
771
|
if (_hasOwnProperty$3.call(pair, pairKey)) {
|
|
774
772
|
if (!pairHasKey) pairHasKey = true;
|
|
@@ -784,8 +782,8 @@ function resolveYamlOmap(data) {
|
|
|
784
782
|
function constructYamlOmap(data) {
|
|
785
783
|
return data !== null ? data : [];
|
|
786
784
|
}
|
|
787
|
-
var omap = new type(
|
|
788
|
-
kind:
|
|
785
|
+
var omap = new type("tag:yaml.org,2002:omap", {
|
|
786
|
+
kind: "sequence",
|
|
789
787
|
resolve: resolveYamlOmap,
|
|
790
788
|
construct: constructYamlOmap
|
|
791
789
|
});
|
|
@@ -796,7 +794,7 @@ function resolveYamlPairs(data) {
|
|
|
796
794
|
result = new Array(object.length);
|
|
797
795
|
for(index = 0, length = object.length; index < length; index += 1){
|
|
798
796
|
pair = object[index];
|
|
799
|
-
if (_toString$1.call(pair) !==
|
|
797
|
+
if (_toString$1.call(pair) !== "[object Object]") return false;
|
|
800
798
|
keys = Object.keys(pair);
|
|
801
799
|
if (keys.length !== 1) return false;
|
|
802
800
|
result[index] = [
|
|
@@ -820,8 +818,8 @@ function constructYamlPairs(data) {
|
|
|
820
818
|
}
|
|
821
819
|
return result;
|
|
822
820
|
}
|
|
823
|
-
var pairs = new type(
|
|
824
|
-
kind:
|
|
821
|
+
var pairs = new type("tag:yaml.org,2002:pairs", {
|
|
822
|
+
kind: "sequence",
|
|
825
823
|
resolve: resolveYamlPairs,
|
|
826
824
|
construct: constructYamlPairs
|
|
827
825
|
});
|
|
@@ -839,8 +837,8 @@ function resolveYamlSet(data) {
|
|
|
839
837
|
function constructYamlSet(data) {
|
|
840
838
|
return data !== null ? data : {};
|
|
841
839
|
}
|
|
842
|
-
var set = new type(
|
|
843
|
-
kind:
|
|
840
|
+
var set = new type("tag:yaml.org,2002:set", {
|
|
841
|
+
kind: "mapping",
|
|
844
842
|
resolve: resolveYamlSet,
|
|
845
843
|
construct: constructYamlSet
|
|
846
844
|
});
|
|
@@ -914,7 +912,7 @@ function fromDecimalCode(c) {
|
|
|
914
912
|
return -1;
|
|
915
913
|
}
|
|
916
914
|
function simpleEscapeSequence(c) {
|
|
917
|
-
/* eslint-disable indent */ return c === 0x30 /* 0 */ ?
|
|
915
|
+
/* 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" : "";
|
|
918
916
|
}
|
|
919
917
|
function charFromCodepoint(c) {
|
|
920
918
|
if (c <= 0xFFFF) {
|
|
@@ -932,14 +930,14 @@ for(var i = 0; i < 256; i++){
|
|
|
932
930
|
}
|
|
933
931
|
function State$1(input, options) {
|
|
934
932
|
this.input = input;
|
|
935
|
-
this.filename = options[
|
|
936
|
-
this.schema = options[
|
|
937
|
-
this.onWarning = options[
|
|
933
|
+
this.filename = options["filename"] || null;
|
|
934
|
+
this.schema = options["schema"] || _default;
|
|
935
|
+
this.onWarning = options["onWarning"] || null;
|
|
938
936
|
// (Hidden) Remove? makes the loader to expect YAML 1.1 documents
|
|
939
937
|
// if such documents have no explicit %YAML directive
|
|
940
|
-
this.legacy = options[
|
|
941
|
-
this.json = options[
|
|
942
|
-
this.listener = options[
|
|
938
|
+
this.legacy = options["legacy"] || false;
|
|
939
|
+
this.json = options["json"] || false;
|
|
940
|
+
this.listener = options["listener"] || null;
|
|
943
941
|
this.implicitTypes = this.schema.compiledImplicit;
|
|
944
942
|
this.typeMap = this.schema.compiledTypeMap;
|
|
945
943
|
this.length = input.length;
|
|
@@ -983,46 +981,46 @@ var directiveHandlers = {
|
|
|
983
981
|
YAML: function handleYamlDirective(state, name, args) {
|
|
984
982
|
var match, major, minor;
|
|
985
983
|
if (state.version !== null) {
|
|
986
|
-
throwError(state,
|
|
984
|
+
throwError(state, "duplication of %YAML directive");
|
|
987
985
|
}
|
|
988
986
|
if (args.length !== 1) {
|
|
989
|
-
throwError(state,
|
|
987
|
+
throwError(state, "YAML directive accepts exactly one argument");
|
|
990
988
|
}
|
|
991
989
|
match = /^([0-9]+)\.([0-9]+)$/.exec(args[0]);
|
|
992
990
|
if (match === null) {
|
|
993
|
-
throwError(state,
|
|
991
|
+
throwError(state, "ill-formed argument of the YAML directive");
|
|
994
992
|
}
|
|
995
993
|
major = parseInt(match[1], 10);
|
|
996
994
|
minor = parseInt(match[2], 10);
|
|
997
995
|
if (major !== 1) {
|
|
998
|
-
throwError(state,
|
|
996
|
+
throwError(state, "unacceptable YAML version of the document");
|
|
999
997
|
}
|
|
1000
998
|
state.version = args[0];
|
|
1001
999
|
state.checkLineBreaks = minor < 2;
|
|
1002
1000
|
if (minor !== 1 && minor !== 2) {
|
|
1003
|
-
throwWarning(state,
|
|
1001
|
+
throwWarning(state, "unsupported YAML version of the document");
|
|
1004
1002
|
}
|
|
1005
1003
|
},
|
|
1006
1004
|
TAG: function handleTagDirective(state, name, args) {
|
|
1007
1005
|
var handle, prefix;
|
|
1008
1006
|
if (args.length !== 2) {
|
|
1009
|
-
throwError(state,
|
|
1007
|
+
throwError(state, "TAG directive accepts exactly two arguments");
|
|
1010
1008
|
}
|
|
1011
1009
|
handle = args[0];
|
|
1012
1010
|
prefix = args[1];
|
|
1013
1011
|
if (!PATTERN_TAG_HANDLE.test(handle)) {
|
|
1014
|
-
throwError(state,
|
|
1012
|
+
throwError(state, "ill-formed tag handle (first argument) of the TAG directive");
|
|
1015
1013
|
}
|
|
1016
1014
|
if (_hasOwnProperty$1.call(state.tagMap, handle)) {
|
|
1017
1015
|
throwError(state, 'there is a previously declared suffix for "' + handle + '" tag handle');
|
|
1018
1016
|
}
|
|
1019
1017
|
if (!PATTERN_TAG_URI.test(prefix)) {
|
|
1020
|
-
throwError(state,
|
|
1018
|
+
throwError(state, "ill-formed tag prefix (second argument) of the TAG directive");
|
|
1021
1019
|
}
|
|
1022
1020
|
try {
|
|
1023
1021
|
prefix = decodeURIComponent(prefix);
|
|
1024
1022
|
} catch (err) {
|
|
1025
|
-
throwError(state,
|
|
1023
|
+
throwError(state, "tag prefix is malformed: " + prefix);
|
|
1026
1024
|
}
|
|
1027
1025
|
state.tagMap[handle] = prefix;
|
|
1028
1026
|
}
|
|
@@ -1035,11 +1033,11 @@ function captureSegment(state, start, end, checkJson) {
|
|
|
1035
1033
|
for(_position = 0, _length = _result.length; _position < _length; _position += 1){
|
|
1036
1034
|
_character = _result.charCodeAt(_position);
|
|
1037
1035
|
if (!(_character === 0x09 || 0x20 <= _character && _character <= 0x10FFFF)) {
|
|
1038
|
-
throwError(state,
|
|
1036
|
+
throwError(state, "expected valid JSON character");
|
|
1039
1037
|
}
|
|
1040
1038
|
}
|
|
1041
1039
|
} else if (PATTERN_NON_PRINTABLE.test(_result)) {
|
|
1042
|
-
throwError(state,
|
|
1040
|
+
throwError(state, "the stream contains non-printable characters");
|
|
1043
1041
|
}
|
|
1044
1042
|
state.result += _result;
|
|
1045
1043
|
}
|
|
@@ -1047,7 +1045,7 @@ function captureSegment(state, start, end, checkJson) {
|
|
|
1047
1045
|
function mergeMappings(state, destination, source, overridableKeys) {
|
|
1048
1046
|
var sourceKeys, key, index, quantity;
|
|
1049
1047
|
if (!common.isObject(source)) {
|
|
1050
|
-
throwError(state,
|
|
1048
|
+
throwError(state, "cannot merge mappings; the provided source object is unacceptable");
|
|
1051
1049
|
}
|
|
1052
1050
|
sourceKeys = Object.keys(source);
|
|
1053
1051
|
for(index = 0, quantity = sourceKeys.length; index < quantity; index += 1){
|
|
@@ -1067,24 +1065,24 @@ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valu
|
|
|
1067
1065
|
keyNode = Array.prototype.slice.call(keyNode);
|
|
1068
1066
|
for(index = 0, quantity = keyNode.length; index < quantity; index += 1){
|
|
1069
1067
|
if (Array.isArray(keyNode[index])) {
|
|
1070
|
-
throwError(state,
|
|
1068
|
+
throwError(state, "nested arrays are not supported inside keys");
|
|
1071
1069
|
}
|
|
1072
|
-
if (
|
|
1073
|
-
keyNode[index] =
|
|
1070
|
+
if (typeof keyNode === "object" && _class(keyNode[index]) === "[object Object]") {
|
|
1071
|
+
keyNode[index] = "[object Object]";
|
|
1074
1072
|
}
|
|
1075
1073
|
}
|
|
1076
1074
|
}
|
|
1077
1075
|
// Avoid code execution in load() via toString property
|
|
1078
1076
|
// (still use its own toString for arrays, timestamps,
|
|
1079
1077
|
// and whatever user schema extensions happen to have @@toStringTag)
|
|
1080
|
-
if (
|
|
1081
|
-
keyNode =
|
|
1078
|
+
if (typeof keyNode === "object" && _class(keyNode) === "[object Object]") {
|
|
1079
|
+
keyNode = "[object Object]";
|
|
1082
1080
|
}
|
|
1083
1081
|
keyNode = String(keyNode);
|
|
1084
1082
|
if (_result === null) {
|
|
1085
1083
|
_result = {};
|
|
1086
1084
|
}
|
|
1087
|
-
if (keyTag ===
|
|
1085
|
+
if (keyTag === "tag:yaml.org,2002:merge") {
|
|
1088
1086
|
if (Array.isArray(valueNode)) {
|
|
1089
1087
|
for(index = 0, quantity = valueNode.length; index < quantity; index += 1){
|
|
1090
1088
|
mergeMappings(state, _result, valueNode[index], overridableKeys);
|
|
@@ -1097,10 +1095,10 @@ function storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, valu
|
|
|
1097
1095
|
state.line = startLine || state.line;
|
|
1098
1096
|
state.lineStart = startLineStart || state.lineStart;
|
|
1099
1097
|
state.position = startPos || state.position;
|
|
1100
|
-
throwError(state,
|
|
1098
|
+
throwError(state, "duplicated mapping key");
|
|
1101
1099
|
}
|
|
1102
1100
|
// used for this specific key only because Object.defineProperty is slow
|
|
1103
|
-
if (keyNode ===
|
|
1101
|
+
if (keyNode === "__proto__") {
|
|
1104
1102
|
Object.defineProperty(_result, keyNode, {
|
|
1105
1103
|
configurable: true,
|
|
1106
1104
|
enumerable: true,
|
|
@@ -1125,7 +1123,7 @@ function readLineBreak(state) {
|
|
|
1125
1123
|
state.position++;
|
|
1126
1124
|
}
|
|
1127
1125
|
} else {
|
|
1128
|
-
throwError(state,
|
|
1126
|
+
throwError(state, "a line break is expected");
|
|
1129
1127
|
}
|
|
1130
1128
|
state.line += 1;
|
|
1131
1129
|
state.lineStart = state.position;
|
|
@@ -1159,7 +1157,7 @@ function skipSeparationSpace(state, allowComments, checkIndent) {
|
|
|
1159
1157
|
}
|
|
1160
1158
|
}
|
|
1161
1159
|
if (checkIndent !== -1 && lineBreaks !== 0 && state.lineIndent < checkIndent) {
|
|
1162
|
-
throwWarning(state,
|
|
1160
|
+
throwWarning(state, "deficient indentation");
|
|
1163
1161
|
}
|
|
1164
1162
|
return lineBreaks;
|
|
1165
1163
|
}
|
|
@@ -1179,9 +1177,9 @@ function testDocumentSeparator(state) {
|
|
|
1179
1177
|
}
|
|
1180
1178
|
function writeFoldedLines(state, count) {
|
|
1181
1179
|
if (count === 1) {
|
|
1182
|
-
state.result +=
|
|
1180
|
+
state.result += " ";
|
|
1183
1181
|
} else if (count > 1) {
|
|
1184
|
-
state.result += common.repeat(
|
|
1182
|
+
state.result += common.repeat("\n", count - 1);
|
|
1185
1183
|
}
|
|
1186
1184
|
}
|
|
1187
1185
|
function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|
@@ -1196,8 +1194,8 @@ function readPlainScalar(state, nodeIndent, withinFlowCollection) {
|
|
|
1196
1194
|
return false;
|
|
1197
1195
|
}
|
|
1198
1196
|
}
|
|
1199
|
-
state.kind =
|
|
1200
|
-
state.result =
|
|
1197
|
+
state.kind = "scalar";
|
|
1198
|
+
state.result = "";
|
|
1201
1199
|
captureStart = captureEnd = state.position;
|
|
1202
1200
|
hasPendingContent = false;
|
|
1203
1201
|
while(ch !== 0){
|
|
@@ -1255,8 +1253,8 @@ function readSingleQuotedScalar(state, nodeIndent) {
|
|
|
1255
1253
|
if (ch !== 0x27 /* ' */ ) {
|
|
1256
1254
|
return false;
|
|
1257
1255
|
}
|
|
1258
|
-
state.kind =
|
|
1259
|
-
state.result =
|
|
1256
|
+
state.kind = "scalar";
|
|
1257
|
+
state.result = "";
|
|
1260
1258
|
state.position++;
|
|
1261
1259
|
captureStart = captureEnd = state.position;
|
|
1262
1260
|
while((ch = state.input.charCodeAt(state.position)) !== 0){
|
|
@@ -1275,13 +1273,13 @@ function readSingleQuotedScalar(state, nodeIndent) {
|
|
|
1275
1273
|
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1276
1274
|
captureStart = captureEnd = state.position;
|
|
1277
1275
|
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1278
|
-
throwError(state,
|
|
1276
|
+
throwError(state, "unexpected end of the document within a single quoted scalar");
|
|
1279
1277
|
} else {
|
|
1280
1278
|
state.position++;
|
|
1281
1279
|
captureEnd = state.position;
|
|
1282
1280
|
}
|
|
1283
1281
|
}
|
|
1284
|
-
throwError(state,
|
|
1282
|
+
throwError(state, "unexpected end of the stream within a single quoted scalar");
|
|
1285
1283
|
}
|
|
1286
1284
|
function readDoubleQuotedScalar(state, nodeIndent) {
|
|
1287
1285
|
var captureStart, captureEnd, hexLength, hexResult, tmp, ch;
|
|
@@ -1289,8 +1287,8 @@ function readDoubleQuotedScalar(state, nodeIndent) {
|
|
|
1289
1287
|
if (ch !== 0x22 /* " */ ) {
|
|
1290
1288
|
return false;
|
|
1291
1289
|
}
|
|
1292
|
-
state.kind =
|
|
1293
|
-
state.result =
|
|
1290
|
+
state.kind = "scalar";
|
|
1291
|
+
state.result = "";
|
|
1294
1292
|
state.position++;
|
|
1295
1293
|
captureStart = captureEnd = state.position;
|
|
1296
1294
|
while((ch = state.input.charCodeAt(state.position)) !== 0){
|
|
@@ -1315,13 +1313,13 @@ function readDoubleQuotedScalar(state, nodeIndent) {
|
|
|
1315
1313
|
if ((tmp = fromHexCode(ch)) >= 0) {
|
|
1316
1314
|
hexResult = (hexResult << 4) + tmp;
|
|
1317
1315
|
} else {
|
|
1318
|
-
throwError(state,
|
|
1316
|
+
throwError(state, "expected hexadecimal character");
|
|
1319
1317
|
}
|
|
1320
1318
|
}
|
|
1321
1319
|
state.result += charFromCodepoint(hexResult);
|
|
1322
1320
|
state.position++;
|
|
1323
1321
|
} else {
|
|
1324
|
-
throwError(state,
|
|
1322
|
+
throwError(state, "unknown escape sequence");
|
|
1325
1323
|
}
|
|
1326
1324
|
captureStart = captureEnd = state.position;
|
|
1327
1325
|
} else if (is_EOL(ch)) {
|
|
@@ -1329,13 +1327,13 @@ function readDoubleQuotedScalar(state, nodeIndent) {
|
|
|
1329
1327
|
writeFoldedLines(state, skipSeparationSpace(state, false, nodeIndent));
|
|
1330
1328
|
captureStart = captureEnd = state.position;
|
|
1331
1329
|
} else if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
1332
|
-
throwError(state,
|
|
1330
|
+
throwError(state, "unexpected end of the document within a double quoted scalar");
|
|
1333
1331
|
} else {
|
|
1334
1332
|
state.position++;
|
|
1335
1333
|
captureEnd = state.position;
|
|
1336
1334
|
}
|
|
1337
1335
|
}
|
|
1338
|
-
throwError(state,
|
|
1336
|
+
throwError(state, "unexpected end of the stream within a double quoted scalar");
|
|
1339
1337
|
}
|
|
1340
1338
|
function readFlowCollection(state, nodeIndent) {
|
|
1341
1339
|
var readNext = true, _line, _lineStart, _pos, _tag = state.tag, _result, _anchor = state.anchor, following, terminator, isPair, isExplicitPair, isMapping, overridableKeys = Object.create(null), keyNode, keyTag, valueNode, ch;
|
|
@@ -1362,11 +1360,11 @@ function readFlowCollection(state, nodeIndent) {
|
|
|
1362
1360
|
state.position++;
|
|
1363
1361
|
state.tag = _tag;
|
|
1364
1362
|
state.anchor = _anchor;
|
|
1365
|
-
state.kind = isMapping ?
|
|
1363
|
+
state.kind = isMapping ? "mapping" : "sequence";
|
|
1366
1364
|
state.result = _result;
|
|
1367
1365
|
return true;
|
|
1368
1366
|
} else if (!readNext) {
|
|
1369
|
-
throwError(state,
|
|
1367
|
+
throwError(state, "missed comma between flow collection entries");
|
|
1370
1368
|
} else if (ch === 0x2C /* , */ ) {
|
|
1371
1369
|
// "flow collection entries can never be completely empty", as per YAML 1.2, section 7.4
|
|
1372
1370
|
throwError(state, "expected the node content, but found ','");
|
|
@@ -1412,7 +1410,7 @@ function readFlowCollection(state, nodeIndent) {
|
|
|
1412
1410
|
readNext = false;
|
|
1413
1411
|
}
|
|
1414
1412
|
}
|
|
1415
|
-
throwError(state,
|
|
1413
|
+
throwError(state, "unexpected end of the stream within a flow collection");
|
|
1416
1414
|
}
|
|
1417
1415
|
function readBlockScalar(state, nodeIndent) {
|
|
1418
1416
|
var captureStart, folding, chomping = CHOMPING_CLIP, didReadContent = false, detectedIndent = false, textIndent = nodeIndent, emptyLines = 0, atMoreIndented = false, tmp, ch;
|
|
@@ -1424,24 +1422,24 @@ function readBlockScalar(state, nodeIndent) {
|
|
|
1424
1422
|
} else {
|
|
1425
1423
|
return false;
|
|
1426
1424
|
}
|
|
1427
|
-
state.kind =
|
|
1428
|
-
state.result =
|
|
1425
|
+
state.kind = "scalar";
|
|
1426
|
+
state.result = "";
|
|
1429
1427
|
while(ch !== 0){
|
|
1430
1428
|
ch = state.input.charCodeAt(++state.position);
|
|
1431
1429
|
if (ch === 0x2B /* + */ || ch === 0x2D /* - */ ) {
|
|
1432
1430
|
if (CHOMPING_CLIP === chomping) {
|
|
1433
1431
|
chomping = ch === 0x2B /* + */ ? CHOMPING_KEEP : CHOMPING_STRIP;
|
|
1434
1432
|
} else {
|
|
1435
|
-
throwError(state,
|
|
1433
|
+
throwError(state, "repeat of a chomping mode identifier");
|
|
1436
1434
|
}
|
|
1437
1435
|
} else if ((tmp = fromDecimalCode(ch)) >= 0) {
|
|
1438
1436
|
if (tmp === 0) {
|
|
1439
|
-
throwError(state,
|
|
1437
|
+
throwError(state, "bad explicit indentation width of a block scalar; it cannot be less than one");
|
|
1440
1438
|
} else if (!detectedIndent) {
|
|
1441
1439
|
textIndent = nodeIndent + tmp - 1;
|
|
1442
1440
|
detectedIndent = true;
|
|
1443
1441
|
} else {
|
|
1444
|
-
throwError(state,
|
|
1442
|
+
throwError(state, "repeat of an indentation width identifier");
|
|
1445
1443
|
}
|
|
1446
1444
|
} else {
|
|
1447
1445
|
break;
|
|
@@ -1476,10 +1474,10 @@ function readBlockScalar(state, nodeIndent) {
|
|
|
1476
1474
|
if (state.lineIndent < textIndent) {
|
|
1477
1475
|
// Perform the chomping.
|
|
1478
1476
|
if (chomping === CHOMPING_KEEP) {
|
|
1479
|
-
state.result += common.repeat(
|
|
1477
|
+
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1480
1478
|
} else if (chomping === CHOMPING_CLIP) {
|
|
1481
1479
|
if (didReadContent) {
|
|
1482
|
-
state.result +=
|
|
1480
|
+
state.result += "\n";
|
|
1483
1481
|
}
|
|
1484
1482
|
}
|
|
1485
1483
|
break;
|
|
@@ -1490,24 +1488,24 @@ function readBlockScalar(state, nodeIndent) {
|
|
|
1490
1488
|
if (is_WHITE_SPACE(ch)) {
|
|
1491
1489
|
atMoreIndented = true;
|
|
1492
1490
|
// except for the first content line (cf. Example 8.1)
|
|
1493
|
-
state.result += common.repeat(
|
|
1491
|
+
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1494
1492
|
// End of more-indented block.
|
|
1495
1493
|
} else if (atMoreIndented) {
|
|
1496
1494
|
atMoreIndented = false;
|
|
1497
|
-
state.result += common.repeat(
|
|
1495
|
+
state.result += common.repeat("\n", emptyLines + 1);
|
|
1498
1496
|
// Just one line break - perceive as the same line.
|
|
1499
1497
|
} else if (emptyLines === 0) {
|
|
1500
1498
|
if (didReadContent) {
|
|
1501
|
-
state.result +=
|
|
1499
|
+
state.result += " ";
|
|
1502
1500
|
}
|
|
1503
1501
|
// Several line breaks - perceive as different lines.
|
|
1504
1502
|
} else {
|
|
1505
|
-
state.result += common.repeat(
|
|
1503
|
+
state.result += common.repeat("\n", emptyLines);
|
|
1506
1504
|
}
|
|
1507
1505
|
// Literal style: just add exact number of line breaks between content lines.
|
|
1508
1506
|
} else {
|
|
1509
1507
|
// Keep all line breaks except the header line break.
|
|
1510
|
-
state.result += common.repeat(
|
|
1508
|
+
state.result += common.repeat("\n", didReadContent ? 1 + emptyLines : emptyLines);
|
|
1511
1509
|
}
|
|
1512
1510
|
didReadContent = true;
|
|
1513
1511
|
detectedIndent = true;
|
|
@@ -1532,7 +1530,7 @@ function readBlockSequence(state, nodeIndent) {
|
|
|
1532
1530
|
while(ch !== 0){
|
|
1533
1531
|
if (state.firstTabInLine !== -1) {
|
|
1534
1532
|
state.position = state.firstTabInLine;
|
|
1535
|
-
throwError(state,
|
|
1533
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
1536
1534
|
}
|
|
1537
1535
|
if (ch !== 0x2D /* - */ ) {
|
|
1538
1536
|
break;
|
|
@@ -1556,7 +1554,7 @@ function readBlockSequence(state, nodeIndent) {
|
|
|
1556
1554
|
skipSeparationSpace(state, true, -1);
|
|
1557
1555
|
ch = state.input.charCodeAt(state.position);
|
|
1558
1556
|
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
1559
|
-
throwError(state,
|
|
1557
|
+
throwError(state, "bad indentation of a sequence entry");
|
|
1560
1558
|
} else if (state.lineIndent < nodeIndent) {
|
|
1561
1559
|
break;
|
|
1562
1560
|
}
|
|
@@ -1564,7 +1562,7 @@ function readBlockSequence(state, nodeIndent) {
|
|
|
1564
1562
|
if (detected) {
|
|
1565
1563
|
state.tag = _tag;
|
|
1566
1564
|
state.anchor = _anchor;
|
|
1567
|
-
state.kind =
|
|
1565
|
+
state.kind = "sequence";
|
|
1568
1566
|
state.result = _result;
|
|
1569
1567
|
return true;
|
|
1570
1568
|
}
|
|
@@ -1582,7 +1580,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
1582
1580
|
while(ch !== 0){
|
|
1583
1581
|
if (!atExplicitKey && state.firstTabInLine !== -1) {
|
|
1584
1582
|
state.position = state.firstTabInLine;
|
|
1585
|
-
throwError(state,
|
|
1583
|
+
throwError(state, "tab characters must not be used in indentation");
|
|
1586
1584
|
}
|
|
1587
1585
|
following = state.input.charCodeAt(state.position + 1);
|
|
1588
1586
|
_line = state.line; // Save the current line.
|
|
@@ -1604,7 +1602,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
1604
1602
|
atExplicitKey = false;
|
|
1605
1603
|
allowCompact = true;
|
|
1606
1604
|
} else {
|
|
1607
|
-
throwError(state,
|
|
1605
|
+
throwError(state, "incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line");
|
|
1608
1606
|
}
|
|
1609
1607
|
state.position += 1;
|
|
1610
1608
|
ch = following;
|
|
@@ -1626,7 +1624,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
1626
1624
|
if (ch === 0x3A /* : */ ) {
|
|
1627
1625
|
ch = state.input.charCodeAt(++state.position);
|
|
1628
1626
|
if (!is_WS_OR_EOL(ch)) {
|
|
1629
|
-
throwError(state,
|
|
1627
|
+
throwError(state, "a whitespace character is expected after the key-value separator within a block mapping");
|
|
1630
1628
|
}
|
|
1631
1629
|
if (atExplicitKey) {
|
|
1632
1630
|
storeMappingPair(state, _result, overridableKeys, keyTag, keyNode, null, _keyLine, _keyLineStart, _keyPos);
|
|
@@ -1638,14 +1636,14 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
1638
1636
|
keyTag = state.tag;
|
|
1639
1637
|
keyNode = state.result;
|
|
1640
1638
|
} else if (detected) {
|
|
1641
|
-
throwError(state,
|
|
1639
|
+
throwError(state, "can not read an implicit mapping pair; a colon is missed");
|
|
1642
1640
|
} else {
|
|
1643
1641
|
state.tag = _tag;
|
|
1644
1642
|
state.anchor = _anchor;
|
|
1645
1643
|
return true; // Keep the result of `composeNode`.
|
|
1646
1644
|
}
|
|
1647
1645
|
} else if (detected) {
|
|
1648
|
-
throwError(state,
|
|
1646
|
+
throwError(state, "can not read a block mapping entry; a multiline key may not be an implicit key");
|
|
1649
1647
|
} else {
|
|
1650
1648
|
state.tag = _tag;
|
|
1651
1649
|
state.anchor = _anchor;
|
|
@@ -1676,7 +1674,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
1676
1674
|
ch = state.input.charCodeAt(state.position);
|
|
1677
1675
|
}
|
|
1678
1676
|
if ((state.line === _line || state.lineIndent > nodeIndent) && ch !== 0) {
|
|
1679
|
-
throwError(state,
|
|
1677
|
+
throwError(state, "bad indentation of a mapping entry");
|
|
1680
1678
|
} else if (state.lineIndent < nodeIndent) {
|
|
1681
1679
|
break;
|
|
1682
1680
|
}
|
|
@@ -1692,7 +1690,7 @@ function readBlockMapping(state, nodeIndent, flowIndent) {
|
|
|
1692
1690
|
if (detected) {
|
|
1693
1691
|
state.tag = _tag;
|
|
1694
1692
|
state.anchor = _anchor;
|
|
1695
|
-
state.kind =
|
|
1693
|
+
state.kind = "mapping";
|
|
1696
1694
|
state.result = _result;
|
|
1697
1695
|
}
|
|
1698
1696
|
return detected;
|
|
@@ -1702,7 +1700,7 @@ function readTagProperty(state) {
|
|
|
1702
1700
|
ch = state.input.charCodeAt(state.position);
|
|
1703
1701
|
if (ch !== 0x21 /* ! */ ) return false;
|
|
1704
1702
|
if (state.tag !== null) {
|
|
1705
|
-
throwError(state,
|
|
1703
|
+
throwError(state, "duplication of a tag property");
|
|
1706
1704
|
}
|
|
1707
1705
|
ch = state.input.charCodeAt(++state.position);
|
|
1708
1706
|
if (ch === 0x3C /* < */ ) {
|
|
@@ -1710,10 +1708,10 @@ function readTagProperty(state) {
|
|
|
1710
1708
|
ch = state.input.charCodeAt(++state.position);
|
|
1711
1709
|
} else if (ch === 0x21 /* ! */ ) {
|
|
1712
1710
|
isNamed = true;
|
|
1713
|
-
tagHandle =
|
|
1711
|
+
tagHandle = "!!";
|
|
1714
1712
|
ch = state.input.charCodeAt(++state.position);
|
|
1715
1713
|
} else {
|
|
1716
|
-
tagHandle =
|
|
1714
|
+
tagHandle = "!";
|
|
1717
1715
|
}
|
|
1718
1716
|
_position = state.position;
|
|
1719
1717
|
if (isVerbatim) {
|
|
@@ -1724,7 +1722,7 @@ function readTagProperty(state) {
|
|
|
1724
1722
|
tagName = state.input.slice(_position, state.position);
|
|
1725
1723
|
ch = state.input.charCodeAt(++state.position);
|
|
1726
1724
|
} else {
|
|
1727
|
-
throwError(state,
|
|
1725
|
+
throwError(state, "unexpected end of the stream within a verbatim tag");
|
|
1728
1726
|
}
|
|
1729
1727
|
} else {
|
|
1730
1728
|
while(ch !== 0 && !is_WS_OR_EOL(ch)){
|
|
@@ -1732,37 +1730,37 @@ function readTagProperty(state) {
|
|
|
1732
1730
|
if (!isNamed) {
|
|
1733
1731
|
tagHandle = state.input.slice(_position - 1, state.position + 1);
|
|
1734
1732
|
if (!PATTERN_TAG_HANDLE.test(tagHandle)) {
|
|
1735
|
-
throwError(state,
|
|
1733
|
+
throwError(state, "named tag handle cannot contain such characters");
|
|
1736
1734
|
}
|
|
1737
1735
|
isNamed = true;
|
|
1738
1736
|
_position = state.position + 1;
|
|
1739
1737
|
} else {
|
|
1740
|
-
throwError(state,
|
|
1738
|
+
throwError(state, "tag suffix cannot contain exclamation marks");
|
|
1741
1739
|
}
|
|
1742
1740
|
}
|
|
1743
1741
|
ch = state.input.charCodeAt(++state.position);
|
|
1744
1742
|
}
|
|
1745
1743
|
tagName = state.input.slice(_position, state.position);
|
|
1746
1744
|
if (PATTERN_FLOW_INDICATORS.test(tagName)) {
|
|
1747
|
-
throwError(state,
|
|
1745
|
+
throwError(state, "tag suffix cannot contain flow indicator characters");
|
|
1748
1746
|
}
|
|
1749
1747
|
}
|
|
1750
1748
|
if (tagName && !PATTERN_TAG_URI.test(tagName)) {
|
|
1751
|
-
throwError(state,
|
|
1749
|
+
throwError(state, "tag name cannot contain such characters: " + tagName);
|
|
1752
1750
|
}
|
|
1753
1751
|
try {
|
|
1754
1752
|
tagName = decodeURIComponent(tagName);
|
|
1755
1753
|
} catch (err) {
|
|
1756
|
-
throwError(state,
|
|
1754
|
+
throwError(state, "tag name is malformed: " + tagName);
|
|
1757
1755
|
}
|
|
1758
1756
|
if (isVerbatim) {
|
|
1759
1757
|
state.tag = tagName;
|
|
1760
1758
|
} else if (_hasOwnProperty$1.call(state.tagMap, tagHandle)) {
|
|
1761
1759
|
state.tag = state.tagMap[tagHandle] + tagName;
|
|
1762
|
-
} else if (tagHandle ===
|
|
1763
|
-
state.tag =
|
|
1764
|
-
} else if (tagHandle ===
|
|
1765
|
-
state.tag =
|
|
1760
|
+
} else if (tagHandle === "!") {
|
|
1761
|
+
state.tag = "!" + tagName;
|
|
1762
|
+
} else if (tagHandle === "!!") {
|
|
1763
|
+
state.tag = "tag:yaml.org,2002:" + tagName;
|
|
1766
1764
|
} else {
|
|
1767
1765
|
throwError(state, 'undeclared tag handle "' + tagHandle + '"');
|
|
1768
1766
|
}
|
|
@@ -1773,7 +1771,7 @@ function readAnchorProperty(state) {
|
|
|
1773
1771
|
ch = state.input.charCodeAt(state.position);
|
|
1774
1772
|
if (ch !== 0x26 /* & */ ) return false;
|
|
1775
1773
|
if (state.anchor !== null) {
|
|
1776
|
-
throwError(state,
|
|
1774
|
+
throwError(state, "duplication of an anchor property");
|
|
1777
1775
|
}
|
|
1778
1776
|
ch = state.input.charCodeAt(++state.position);
|
|
1779
1777
|
_position = state.position;
|
|
@@ -1781,7 +1779,7 @@ function readAnchorProperty(state) {
|
|
|
1781
1779
|
ch = state.input.charCodeAt(++state.position);
|
|
1782
1780
|
}
|
|
1783
1781
|
if (state.position === _position) {
|
|
1784
|
-
throwError(state,
|
|
1782
|
+
throwError(state, "name of an anchor node must contain at least one character");
|
|
1785
1783
|
}
|
|
1786
1784
|
state.anchor = state.input.slice(_position, state.position);
|
|
1787
1785
|
return true;
|
|
@@ -1796,7 +1794,7 @@ function readAlias(state) {
|
|
|
1796
1794
|
ch = state.input.charCodeAt(++state.position);
|
|
1797
1795
|
}
|
|
1798
1796
|
if (state.position === _position) {
|
|
1799
|
-
throwError(state,
|
|
1797
|
+
throwError(state, "name of an alias node must contain at least one character");
|
|
1800
1798
|
}
|
|
1801
1799
|
alias = state.input.slice(_position, state.position);
|
|
1802
1800
|
if (!_hasOwnProperty$1.call(state.anchorMap, alias)) {
|
|
@@ -1809,7 +1807,7 @@ function readAlias(state) {
|
|
|
1809
1807
|
function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact) {
|
|
1810
1808
|
var allowBlockStyles, allowBlockScalars, allowBlockCollections, indentStatus = 1, atNewLine = false, hasContent = false, typeIndex, typeQuantity, typeList, type, flowIndent, blockIndent;
|
|
1811
1809
|
if (state.listener !== null) {
|
|
1812
|
-
state.listener(
|
|
1810
|
+
state.listener("open", state);
|
|
1813
1811
|
}
|
|
1814
1812
|
state.tag = null;
|
|
1815
1813
|
state.anchor = null;
|
|
@@ -1864,12 +1862,12 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
|
|
|
1864
1862
|
} else if (readAlias(state)) {
|
|
1865
1863
|
hasContent = true;
|
|
1866
1864
|
if (state.tag !== null || state.anchor !== null) {
|
|
1867
|
-
throwError(state,
|
|
1865
|
+
throwError(state, "alias node should not have any properties");
|
|
1868
1866
|
}
|
|
1869
1867
|
} else if (readPlainScalar(state, flowIndent, CONTEXT_FLOW_IN === nodeContext)) {
|
|
1870
1868
|
hasContent = true;
|
|
1871
1869
|
if (state.tag === null) {
|
|
1872
|
-
state.tag =
|
|
1870
|
+
state.tag = "?";
|
|
1873
1871
|
}
|
|
1874
1872
|
}
|
|
1875
1873
|
if (state.anchor !== null) {
|
|
@@ -1886,14 +1884,14 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
|
|
|
1886
1884
|
if (state.anchor !== null) {
|
|
1887
1885
|
state.anchorMap[state.anchor] = state.result;
|
|
1888
1886
|
}
|
|
1889
|
-
} else if (state.tag ===
|
|
1887
|
+
} else if (state.tag === "?") {
|
|
1890
1888
|
// Implicit resolving is not allowed for non-scalar types, and '?'
|
|
1891
1889
|
// non-specific tag is only automatically assigned to plain scalars.
|
|
1892
1890
|
//
|
|
1893
1891
|
// We only need to check kind conformity in case user explicitly assigns '?'
|
|
1894
1892
|
// tag, for example like this: "!<?> [0]"
|
|
1895
1893
|
//
|
|
1896
|
-
if (state.result !== null && state.kind !==
|
|
1894
|
+
if (state.result !== null && state.kind !== "scalar") {
|
|
1897
1895
|
throwError(state, 'unacceptable node kind for !<?> tag; it should be "scalar", not "' + state.kind + '"');
|
|
1898
1896
|
}
|
|
1899
1897
|
for(typeIndex = 0, typeQuantity = state.implicitTypes.length; typeIndex < typeQuantity; typeIndex += 1){
|
|
@@ -1907,13 +1905,13 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
|
|
|
1907
1905
|
break;
|
|
1908
1906
|
}
|
|
1909
1907
|
}
|
|
1910
|
-
} else if (state.tag !==
|
|
1911
|
-
if (_hasOwnProperty$1.call(state.typeMap[state.kind ||
|
|
1912
|
-
type = state.typeMap[state.kind ||
|
|
1908
|
+
} else if (state.tag !== "!") {
|
|
1909
|
+
if (_hasOwnProperty$1.call(state.typeMap[state.kind || "fallback"], state.tag)) {
|
|
1910
|
+
type = state.typeMap[state.kind || "fallback"][state.tag];
|
|
1913
1911
|
} else {
|
|
1914
1912
|
// looking for multi type
|
|
1915
1913
|
type = null;
|
|
1916
|
-
typeList = state.typeMap.multi[state.kind ||
|
|
1914
|
+
typeList = state.typeMap.multi[state.kind || "fallback"];
|
|
1917
1915
|
for(typeIndex = 0, typeQuantity = typeList.length; typeIndex < typeQuantity; typeIndex += 1){
|
|
1918
1916
|
if (state.tag.slice(0, typeList[typeIndex].tag.length) === typeList[typeIndex].tag) {
|
|
1919
1917
|
type = typeList[typeIndex];
|
|
@@ -1922,13 +1920,13 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
|
|
|
1922
1920
|
}
|
|
1923
1921
|
}
|
|
1924
1922
|
if (!type) {
|
|
1925
|
-
throwError(state,
|
|
1923
|
+
throwError(state, "unknown tag !<" + state.tag + ">");
|
|
1926
1924
|
}
|
|
1927
1925
|
if (state.result !== null && type.kind !== state.kind) {
|
|
1928
|
-
throwError(state,
|
|
1926
|
+
throwError(state, "unacceptable node kind for !<" + state.tag + '> tag; it should be "' + type.kind + '", not "' + state.kind + '"');
|
|
1929
1927
|
}
|
|
1930
1928
|
if (!type.resolve(state.result, state.tag)) {
|
|
1931
|
-
throwError(state,
|
|
1929
|
+
throwError(state, "cannot resolve a node with !<" + state.tag + "> explicit tag");
|
|
1932
1930
|
} else {
|
|
1933
1931
|
state.result = type.construct(state.result, state.tag);
|
|
1934
1932
|
if (state.anchor !== null) {
|
|
@@ -1937,7 +1935,7 @@ function composeNode(state, parentIndent, nodeContext, allowToSeek, allowCompact
|
|
|
1937
1935
|
}
|
|
1938
1936
|
}
|
|
1939
1937
|
if (state.listener !== null) {
|
|
1940
|
-
state.listener(
|
|
1938
|
+
state.listener("close", state);
|
|
1941
1939
|
}
|
|
1942
1940
|
return state.tag !== null || state.anchor !== null || hasContent;
|
|
1943
1941
|
}
|
|
@@ -1962,7 +1960,7 @@ function readDocument(state) {
|
|
|
1962
1960
|
directiveName = state.input.slice(_position, state.position);
|
|
1963
1961
|
directiveArgs = [];
|
|
1964
1962
|
if (directiveName.length < 1) {
|
|
1965
|
-
throwError(state,
|
|
1963
|
+
throwError(state, "directive name must not be less than one character in length");
|
|
1966
1964
|
}
|
|
1967
1965
|
while(ch !== 0){
|
|
1968
1966
|
while(is_WHITE_SPACE(ch)){
|
|
@@ -1993,12 +1991,12 @@ function readDocument(state) {
|
|
|
1993
1991
|
state.position += 3;
|
|
1994
1992
|
skipSeparationSpace(state, true, -1);
|
|
1995
1993
|
} else if (hasDirectives) {
|
|
1996
|
-
throwError(state,
|
|
1994
|
+
throwError(state, "directives end mark is expected");
|
|
1997
1995
|
}
|
|
1998
1996
|
composeNode(state, state.lineIndent - 1, CONTEXT_BLOCK_OUT, false, true);
|
|
1999
1997
|
skipSeparationSpace(state, true, -1);
|
|
2000
1998
|
if (state.checkLineBreaks && PATTERN_NON_ASCII_LINE_BREAKS.test(state.input.slice(documentStart, state.position))) {
|
|
2001
|
-
throwWarning(state,
|
|
1999
|
+
throwWarning(state, "non-ASCII line breaks are interpreted as content");
|
|
2002
2000
|
}
|
|
2003
2001
|
state.documents.push(state.result);
|
|
2004
2002
|
if (state.position === state.lineStart && testDocumentSeparator(state)) {
|
|
@@ -2009,7 +2007,7 @@ function readDocument(state) {
|
|
|
2009
2007
|
return;
|
|
2010
2008
|
}
|
|
2011
2009
|
if (state.position < state.length - 1) {
|
|
2012
|
-
throwError(state,
|
|
2010
|
+
throwError(state, "end of the stream or a document separator is expected");
|
|
2013
2011
|
} else {
|
|
2014
2012
|
return;
|
|
2015
2013
|
}
|
|
@@ -2020,7 +2018,7 @@ function loadDocuments(input, options) {
|
|
|
2020
2018
|
if (input.length !== 0) {
|
|
2021
2019
|
// Add tailing `\n` if not exists
|
|
2022
2020
|
if (input.charCodeAt(input.length - 1) !== 0x0A /* LF */ && input.charCodeAt(input.length - 1) !== 0x0D /* CR */ ) {
|
|
2023
|
-
input +=
|
|
2021
|
+
input += "\n";
|
|
2024
2022
|
}
|
|
2025
2023
|
// Strip BOM
|
|
2026
2024
|
if (input.charCodeAt(0) === 0xFEFF) {
|
|
@@ -2028,13 +2026,13 @@ function loadDocuments(input, options) {
|
|
|
2028
2026
|
}
|
|
2029
2027
|
}
|
|
2030
2028
|
var state = new State$1(input, options);
|
|
2031
|
-
var nullpos = input.indexOf(
|
|
2029
|
+
var nullpos = input.indexOf("\0");
|
|
2032
2030
|
if (nullpos !== -1) {
|
|
2033
2031
|
state.position = nullpos;
|
|
2034
|
-
throwError(state,
|
|
2032
|
+
throwError(state, "null byte is not allowed in input");
|
|
2035
2033
|
}
|
|
2036
2034
|
// Use 0 as string terminator. That significantly simplifies bounds check.
|
|
2037
|
-
state.input +=
|
|
2035
|
+
state.input += "\0";
|
|
2038
2036
|
while(state.input.charCodeAt(state.position) === 0x20 /* Space */ ){
|
|
2039
2037
|
state.lineIndent += 1;
|
|
2040
2038
|
state.position += 1;
|
|
@@ -2044,6 +2042,19 @@ function loadDocuments(input, options) {
|
|
|
2044
2042
|
}
|
|
2045
2043
|
return state.documents;
|
|
2046
2044
|
}
|
|
2045
|
+
function loadAll$1(input, iterator, options) {
|
|
2046
|
+
if (iterator !== null && typeof iterator === "object" && typeof options === "undefined") {
|
|
2047
|
+
options = iterator;
|
|
2048
|
+
iterator = null;
|
|
2049
|
+
}
|
|
2050
|
+
var documents = loadDocuments(input, options);
|
|
2051
|
+
if (typeof iterator !== "function") {
|
|
2052
|
+
return documents;
|
|
2053
|
+
}
|
|
2054
|
+
for(var index = 0, length = documents.length; index < length; index += 1){
|
|
2055
|
+
iterator(documents[index]);
|
|
2056
|
+
}
|
|
2057
|
+
}
|
|
2047
2058
|
function load$1(input, options) {
|
|
2048
2059
|
var documents = loadDocuments(input, options);
|
|
2049
2060
|
if (documents.length === 0) {
|
|
@@ -2051,10 +2062,12 @@ function load$1(input, options) {
|
|
|
2051
2062
|
} else if (documents.length === 1) {
|
|
2052
2063
|
return documents[0];
|
|
2053
2064
|
}
|
|
2054
|
-
throw new exception(
|
|
2065
|
+
throw new exception("expected a single document in the stream, but found more");
|
|
2055
2066
|
}
|
|
2067
|
+
var loadAll_1 = loadAll$1;
|
|
2056
2068
|
var load_1 = load$1;
|
|
2057
2069
|
var loader = {
|
|
2070
|
+
loadAll: loadAll_1,
|
|
2058
2071
|
load: load_1
|
|
2059
2072
|
};
|
|
2060
2073
|
/*eslint-disable no-use-before-define*/ var _toString = Object.prototype.toString;
|
|
@@ -2085,38 +2098,38 @@ var CHAR_LEFT_CURLY_BRACKET = 0x7B; /* { */
|
|
|
2085
2098
|
var CHAR_VERTICAL_LINE = 0x7C; /* | */
|
|
2086
2099
|
var CHAR_RIGHT_CURLY_BRACKET = 0x7D; /* } */
|
|
2087
2100
|
var ESCAPE_SEQUENCES = {};
|
|
2088
|
-
ESCAPE_SEQUENCES[0x00] =
|
|
2089
|
-
ESCAPE_SEQUENCES[0x07] =
|
|
2090
|
-
ESCAPE_SEQUENCES[0x08] =
|
|
2091
|
-
ESCAPE_SEQUENCES[0x09] =
|
|
2092
|
-
ESCAPE_SEQUENCES[0x0A] =
|
|
2093
|
-
ESCAPE_SEQUENCES[0x0B] =
|
|
2094
|
-
ESCAPE_SEQUENCES[0x0C] =
|
|
2095
|
-
ESCAPE_SEQUENCES[0x0D] =
|
|
2096
|
-
ESCAPE_SEQUENCES[0x1B] =
|
|
2101
|
+
ESCAPE_SEQUENCES[0x00] = "\\0";
|
|
2102
|
+
ESCAPE_SEQUENCES[0x07] = "\\a";
|
|
2103
|
+
ESCAPE_SEQUENCES[0x08] = "\\b";
|
|
2104
|
+
ESCAPE_SEQUENCES[0x09] = "\\t";
|
|
2105
|
+
ESCAPE_SEQUENCES[0x0A] = "\\n";
|
|
2106
|
+
ESCAPE_SEQUENCES[0x0B] = "\\v";
|
|
2107
|
+
ESCAPE_SEQUENCES[0x0C] = "\\f";
|
|
2108
|
+
ESCAPE_SEQUENCES[0x0D] = "\\r";
|
|
2109
|
+
ESCAPE_SEQUENCES[0x1B] = "\\e";
|
|
2097
2110
|
ESCAPE_SEQUENCES[0x22] = '\\"';
|
|
2098
|
-
ESCAPE_SEQUENCES[0x5C] =
|
|
2099
|
-
ESCAPE_SEQUENCES[0x85] =
|
|
2100
|
-
ESCAPE_SEQUENCES[0xA0] =
|
|
2101
|
-
ESCAPE_SEQUENCES[0x2028] =
|
|
2102
|
-
ESCAPE_SEQUENCES[0x2029] =
|
|
2111
|
+
ESCAPE_SEQUENCES[0x5C] = "\\\\";
|
|
2112
|
+
ESCAPE_SEQUENCES[0x85] = "\\N";
|
|
2113
|
+
ESCAPE_SEQUENCES[0xA0] = "\\_";
|
|
2114
|
+
ESCAPE_SEQUENCES[0x2028] = "\\L";
|
|
2115
|
+
ESCAPE_SEQUENCES[0x2029] = "\\P";
|
|
2103
2116
|
var DEPRECATED_BOOLEANS_SYNTAX = [
|
|
2104
|
-
|
|
2105
|
-
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2110
|
-
|
|
2111
|
-
|
|
2112
|
-
|
|
2113
|
-
|
|
2114
|
-
|
|
2115
|
-
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2117
|
+
"y",
|
|
2118
|
+
"Y",
|
|
2119
|
+
"yes",
|
|
2120
|
+
"Yes",
|
|
2121
|
+
"YES",
|
|
2122
|
+
"on",
|
|
2123
|
+
"On",
|
|
2124
|
+
"ON",
|
|
2125
|
+
"n",
|
|
2126
|
+
"N",
|
|
2127
|
+
"no",
|
|
2128
|
+
"No",
|
|
2129
|
+
"NO",
|
|
2130
|
+
"off",
|
|
2131
|
+
"Off",
|
|
2132
|
+
"OFF"
|
|
2120
2133
|
];
|
|
2121
2134
|
var DEPRECATED_BASE60_SYNTAX = /^[-+]?[0-9_]+(?::[0-9_]+)+(?:\.[0-9_]*)?$/;
|
|
2122
2135
|
function compileStyleMap(schema, map) {
|
|
@@ -2127,10 +2140,10 @@ function compileStyleMap(schema, map) {
|
|
|
2127
2140
|
for(index = 0, length = keys.length; index < length; index += 1){
|
|
2128
2141
|
tag = keys[index];
|
|
2129
2142
|
style = String(map[tag]);
|
|
2130
|
-
if (tag.slice(0, 2) ===
|
|
2131
|
-
tag =
|
|
2143
|
+
if (tag.slice(0, 2) === "!!") {
|
|
2144
|
+
tag = "tag:yaml.org,2002:" + tag.slice(2);
|
|
2132
2145
|
}
|
|
2133
|
-
type = schema.compiledTypeMap[
|
|
2146
|
+
type = schema.compiledTypeMap["fallback"][tag];
|
|
2134
2147
|
if (type && _hasOwnProperty.call(type.styleAliases, style)) {
|
|
2135
2148
|
style = type.styleAliases[style];
|
|
2136
2149
|
}
|
|
@@ -2142,47 +2155,47 @@ function encodeHex(character) {
|
|
|
2142
2155
|
var string, handle, length;
|
|
2143
2156
|
string = character.toString(16).toUpperCase();
|
|
2144
2157
|
if (character <= 0xFF) {
|
|
2145
|
-
handle =
|
|
2158
|
+
handle = "x";
|
|
2146
2159
|
length = 2;
|
|
2147
2160
|
} else if (character <= 0xFFFF) {
|
|
2148
|
-
handle =
|
|
2161
|
+
handle = "u";
|
|
2149
2162
|
length = 4;
|
|
2150
2163
|
} else if (character <= 0xFFFFFFFF) {
|
|
2151
|
-
handle =
|
|
2164
|
+
handle = "U";
|
|
2152
2165
|
length = 8;
|
|
2153
2166
|
} else {
|
|
2154
|
-
throw new exception(
|
|
2167
|
+
throw new exception("code point within a string may not be greater than 0xFFFFFFFF");
|
|
2155
2168
|
}
|
|
2156
|
-
return
|
|
2169
|
+
return "\\" + handle + common.repeat("0", length - string.length) + string;
|
|
2157
2170
|
}
|
|
2158
2171
|
var QUOTING_TYPE_SINGLE = 1, QUOTING_TYPE_DOUBLE = 2;
|
|
2159
2172
|
function State(options) {
|
|
2160
|
-
this.schema = options[
|
|
2161
|
-
this.indent = Math.max(1, options[
|
|
2162
|
-
this.noArrayIndent = options[
|
|
2163
|
-
this.skipInvalid = options[
|
|
2164
|
-
this.flowLevel = common.isNothing(options[
|
|
2165
|
-
this.styleMap = compileStyleMap(this.schema, options[
|
|
2166
|
-
this.sortKeys = options[
|
|
2167
|
-
this.lineWidth = options[
|
|
2168
|
-
this.noRefs = options[
|
|
2169
|
-
this.noCompatMode = options[
|
|
2170
|
-
this.condenseFlow = options[
|
|
2171
|
-
this.quotingType = options[
|
|
2172
|
-
this.forceQuotes = options[
|
|
2173
|
-
this.replacer = typeof options[
|
|
2173
|
+
this.schema = options["schema"] || _default;
|
|
2174
|
+
this.indent = Math.max(1, options["indent"] || 2);
|
|
2175
|
+
this.noArrayIndent = options["noArrayIndent"] || false;
|
|
2176
|
+
this.skipInvalid = options["skipInvalid"] || false;
|
|
2177
|
+
this.flowLevel = common.isNothing(options["flowLevel"]) ? -1 : options["flowLevel"];
|
|
2178
|
+
this.styleMap = compileStyleMap(this.schema, options["styles"] || null);
|
|
2179
|
+
this.sortKeys = options["sortKeys"] || false;
|
|
2180
|
+
this.lineWidth = options["lineWidth"] || 80;
|
|
2181
|
+
this.noRefs = options["noRefs"] || false;
|
|
2182
|
+
this.noCompatMode = options["noCompatMode"] || false;
|
|
2183
|
+
this.condenseFlow = options["condenseFlow"] || false;
|
|
2184
|
+
this.quotingType = options["quotingType"] === '"' ? QUOTING_TYPE_DOUBLE : QUOTING_TYPE_SINGLE;
|
|
2185
|
+
this.forceQuotes = options["forceQuotes"] || false;
|
|
2186
|
+
this.replacer = typeof options["replacer"] === "function" ? options["replacer"] : null;
|
|
2174
2187
|
this.implicitTypes = this.schema.compiledImplicit;
|
|
2175
2188
|
this.explicitTypes = this.schema.compiledExplicit;
|
|
2176
2189
|
this.tag = null;
|
|
2177
|
-
this.result =
|
|
2190
|
+
this.result = "";
|
|
2178
2191
|
this.duplicates = [];
|
|
2179
2192
|
this.usedDuplicates = null;
|
|
2180
2193
|
}
|
|
2181
2194
|
// Indents every line in a string. Empty lines (\n only) are not indented.
|
|
2182
2195
|
function indentString(string, spaces) {
|
|
2183
|
-
var ind = common.repeat(
|
|
2196
|
+
var ind = common.repeat(" ", spaces), position = 0, next = -1, result = "", line, length = string.length;
|
|
2184
2197
|
while(position < length){
|
|
2185
|
-
next = string.indexOf(
|
|
2198
|
+
next = string.indexOf("\n", position);
|
|
2186
2199
|
if (next === -1) {
|
|
2187
2200
|
line = string.slice(position);
|
|
2188
2201
|
position = length;
|
|
@@ -2190,13 +2203,13 @@ function indentString(string, spaces) {
|
|
|
2190
2203
|
line = string.slice(position, next + 1);
|
|
2191
2204
|
position = next + 1;
|
|
2192
2205
|
}
|
|
2193
|
-
if (line.length && line !==
|
|
2206
|
+
if (line.length && line !== "\n") result += ind;
|
|
2194
2207
|
result += line;
|
|
2195
2208
|
}
|
|
2196
2209
|
return result;
|
|
2197
2210
|
}
|
|
2198
2211
|
function generateNextLine(state, level) {
|
|
2199
|
-
return
|
|
2212
|
+
return "\n" + common.repeat(" ", state.indent * level);
|
|
2200
2213
|
}
|
|
2201
2214
|
function testImplicitResolving(state, str) {
|
|
2202
2215
|
var index, length, type;
|
|
@@ -2312,7 +2325,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te
|
|
|
2312
2325
|
// Check if any line can be folded.
|
|
2313
2326
|
if (shouldTrackWidth) {
|
|
2314
2327
|
hasFoldableLine = hasFoldableLine || // Foldable line = too long, and not more-indented.
|
|
2315
|
-
i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !==
|
|
2328
|
+
i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
|
|
2316
2329
|
previousLineBreak = i;
|
|
2317
2330
|
}
|
|
2318
2331
|
} else if (!isPrintable(char)) {
|
|
@@ -2322,7 +2335,7 @@ function chooseScalarStyle(string, singleLineOnly, indentPerLevel, lineWidth, te
|
|
|
2322
2335
|
prevChar = char;
|
|
2323
2336
|
}
|
|
2324
2337
|
// in case the end is missing a \n
|
|
2325
|
-
hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !==
|
|
2338
|
+
hasFoldableLine = hasFoldableLine || shouldTrackWidth && i - previousLineBreak - 1 > lineWidth && string[previousLineBreak + 1] !== " ";
|
|
2326
2339
|
}
|
|
2327
2340
|
// Although every style can represent \n without escaping, prefer block styles
|
|
2328
2341
|
// for multiline, since they're more readable and they don't add empty lines.
|
|
@@ -2382,28 +2395,28 @@ function writeScalar(state, string, level, iskey, inblock) {
|
|
|
2382
2395
|
case STYLE_SINGLE:
|
|
2383
2396
|
return "'" + string.replace(/'/g, "''") + "'";
|
|
2384
2397
|
case STYLE_LITERAL:
|
|
2385
|
-
return
|
|
2398
|
+
return "|" + blockHeader(string, state.indent) + dropEndingNewline(indentString(string, indent));
|
|
2386
2399
|
case STYLE_FOLDED:
|
|
2387
|
-
return
|
|
2400
|
+
return ">" + blockHeader(string, state.indent) + dropEndingNewline(indentString(foldString(string, lineWidth), indent));
|
|
2388
2401
|
case STYLE_DOUBLE:
|
|
2389
2402
|
return '"' + escapeString(string) + '"';
|
|
2390
2403
|
default:
|
|
2391
|
-
throw new exception(
|
|
2404
|
+
throw new exception("impossible error: invalid scalar style");
|
|
2392
2405
|
}
|
|
2393
2406
|
}();
|
|
2394
2407
|
}
|
|
2395
2408
|
// Pre-conditions: string is valid for a block scalar, 1 <= indentPerLevel <= 9.
|
|
2396
2409
|
function blockHeader(string, indentPerLevel) {
|
|
2397
|
-
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) :
|
|
2410
|
+
var indentIndicator = needIndentIndicator(string) ? String(indentPerLevel) : "";
|
|
2398
2411
|
// note the special case: the string '\n' counts as a "trailing" empty line.
|
|
2399
|
-
var clip = string[string.length - 1] ===
|
|
2400
|
-
var keep = clip && (string[string.length - 2] ===
|
|
2401
|
-
var chomp = keep ?
|
|
2402
|
-
return indentIndicator + chomp +
|
|
2412
|
+
var clip = string[string.length - 1] === "\n";
|
|
2413
|
+
var keep = clip && (string[string.length - 2] === "\n" || string === "\n");
|
|
2414
|
+
var chomp = keep ? "+" : clip ? "" : "-";
|
|
2415
|
+
return indentIndicator + chomp + "\n";
|
|
2403
2416
|
}
|
|
2404
2417
|
// (See the note for writeScalar.)
|
|
2405
2418
|
function dropEndingNewline(string) {
|
|
2406
|
-
return string[string.length - 1] ===
|
|
2419
|
+
return string[string.length - 1] === "\n" ? string.slice(0, -1) : string;
|
|
2407
2420
|
}
|
|
2408
2421
|
// Note: a long line without a suitable break point will exceed the width limit.
|
|
2409
2422
|
// Pre-conditions: every char in str isPrintable, str.length > 0, width > 0.
|
|
@@ -2415,20 +2428,20 @@ function foldString(string, width) {
|
|
|
2415
2428
|
var lineRe = /(\n+)([^\n]*)/g;
|
|
2416
2429
|
// first line (possibly an empty line)
|
|
2417
2430
|
var result = function() {
|
|
2418
|
-
var nextLF = string.indexOf(
|
|
2431
|
+
var nextLF = string.indexOf("\n");
|
|
2419
2432
|
nextLF = nextLF !== -1 ? nextLF : string.length;
|
|
2420
2433
|
lineRe.lastIndex = nextLF;
|
|
2421
2434
|
return foldLine(string.slice(0, nextLF), width);
|
|
2422
2435
|
}();
|
|
2423
2436
|
// If we haven't reached the first content line yet, don't add an extra \n.
|
|
2424
|
-
var prevMoreIndented = string[0] ===
|
|
2437
|
+
var prevMoreIndented = string[0] === "\n" || string[0] === " ";
|
|
2425
2438
|
var moreIndented;
|
|
2426
2439
|
// rest of the lines
|
|
2427
2440
|
var match;
|
|
2428
2441
|
while(match = lineRe.exec(string)){
|
|
2429
2442
|
var prefix = match[1], line = match[2];
|
|
2430
|
-
moreIndented = line[0] ===
|
|
2431
|
-
result += prefix + (!prevMoreIndented && !moreIndented && line !==
|
|
2443
|
+
moreIndented = line[0] === " ";
|
|
2444
|
+
result += prefix + (!prevMoreIndented && !moreIndented && line !== "" ? "\n" : "") + foldLine(line, width);
|
|
2432
2445
|
prevMoreIndented = moreIndented;
|
|
2433
2446
|
}
|
|
2434
2447
|
return result;
|
|
@@ -2438,13 +2451,13 @@ function foldString(string, width) {
|
|
|
2438
2451
|
// otherwise settles for the shortest line over the limit.
|
|
2439
2452
|
// NB. More-indented lines *cannot* be folded, as that would add an extra \n.
|
|
2440
2453
|
function foldLine(line, width) {
|
|
2441
|
-
if (line ===
|
|
2454
|
+
if (line === "" || line[0] === " ") return line;
|
|
2442
2455
|
// Since a more-indented line adds a \n, breaks can't be followed by a space.
|
|
2443
2456
|
var breakRe = / [^ ]/g; // note: the match index will always be <= length-2.
|
|
2444
2457
|
var match;
|
|
2445
2458
|
// start is an inclusive index. end, curr, and next are exclusive.
|
|
2446
2459
|
var start = 0, end, curr = 0, next = 0;
|
|
2447
|
-
var result =
|
|
2460
|
+
var result = "";
|
|
2448
2461
|
// Invariants: 0 <= start <= length-1.
|
|
2449
2462
|
// 0 <= curr <= next <= max(0, length-2). curr - start <= width.
|
|
2450
2463
|
// Inside the loop:
|
|
@@ -2454,7 +2467,7 @@ function foldLine(line, width) {
|
|
|
2454
2467
|
// maintain invariant: curr - start <= width
|
|
2455
2468
|
if (next - start > width) {
|
|
2456
2469
|
end = curr > start ? curr : next; // derive end <= length-2
|
|
2457
|
-
result +=
|
|
2470
|
+
result += "\n" + line.slice(start, end);
|
|
2458
2471
|
// skip the space that was output as \n
|
|
2459
2472
|
start = end + 1; // derive start <= length-1
|
|
2460
2473
|
}
|
|
@@ -2462,10 +2475,10 @@ function foldLine(line, width) {
|
|
|
2462
2475
|
}
|
|
2463
2476
|
// By the invariants, start <= length-1, so there is something left over.
|
|
2464
2477
|
// It is either the whole string or a part starting from non-whitespace.
|
|
2465
|
-
result +=
|
|
2478
|
+
result += "\n";
|
|
2466
2479
|
// Insert a break if the remainder is too long and there is a break available.
|
|
2467
2480
|
if (line.length - start > width && curr > start) {
|
|
2468
|
-
result += line.slice(start, curr) +
|
|
2481
|
+
result += line.slice(start, curr) + "\n" + line.slice(curr + 1);
|
|
2469
2482
|
} else {
|
|
2470
2483
|
result += line.slice(start);
|
|
2471
2484
|
}
|
|
@@ -2473,7 +2486,7 @@ function foldLine(line, width) {
|
|
|
2473
2486
|
}
|
|
2474
2487
|
// Escapes a double-quoted string.
|
|
2475
2488
|
function escapeString(string) {
|
|
2476
|
-
var result =
|
|
2489
|
+
var result = "";
|
|
2477
2490
|
var char = 0;
|
|
2478
2491
|
var escapeSeq;
|
|
2479
2492
|
for(var i = 0; i < string.length; char >= 0x10000 ? i += 2 : i++){
|
|
@@ -2489,49 +2502,49 @@ function escapeString(string) {
|
|
|
2489
2502
|
return result;
|
|
2490
2503
|
}
|
|
2491
2504
|
function writeFlowSequence(state, level, object) {
|
|
2492
|
-
var _result =
|
|
2505
|
+
var _result = "", _tag = state.tag, index, length, value;
|
|
2493
2506
|
for(index = 0, length = object.length; index < length; index += 1){
|
|
2494
2507
|
value = object[index];
|
|
2495
2508
|
if (state.replacer) {
|
|
2496
2509
|
value = state.replacer.call(object, String(index), value);
|
|
2497
2510
|
}
|
|
2498
2511
|
// Write only valid elements, put null instead of invalid elements.
|
|
2499
|
-
if (writeNode(state, level, value, false, false) || typeof value ===
|
|
2500
|
-
if (_result !==
|
|
2512
|
+
if (writeNode(state, level, value, false, false) || typeof value === "undefined" && writeNode(state, level, null, false, false)) {
|
|
2513
|
+
if (_result !== "") _result += "," + (!state.condenseFlow ? " " : "");
|
|
2501
2514
|
_result += state.dump;
|
|
2502
2515
|
}
|
|
2503
2516
|
}
|
|
2504
2517
|
state.tag = _tag;
|
|
2505
|
-
state.dump =
|
|
2518
|
+
state.dump = "[" + _result + "]";
|
|
2506
2519
|
}
|
|
2507
2520
|
function writeBlockSequence(state, level, object, compact) {
|
|
2508
|
-
var _result =
|
|
2521
|
+
var _result = "", _tag = state.tag, index, length, value;
|
|
2509
2522
|
for(index = 0, length = object.length; index < length; index += 1){
|
|
2510
2523
|
value = object[index];
|
|
2511
2524
|
if (state.replacer) {
|
|
2512
2525
|
value = state.replacer.call(object, String(index), value);
|
|
2513
2526
|
}
|
|
2514
2527
|
// Write only valid elements, put null instead of invalid elements.
|
|
2515
|
-
if (writeNode(state, level + 1, value, true, true, false, true) || typeof value ===
|
|
2516
|
-
if (!compact || _result !==
|
|
2528
|
+
if (writeNode(state, level + 1, value, true, true, false, true) || typeof value === "undefined" && writeNode(state, level + 1, null, true, true, false, true)) {
|
|
2529
|
+
if (!compact || _result !== "") {
|
|
2517
2530
|
_result += generateNextLine(state, level);
|
|
2518
2531
|
}
|
|
2519
2532
|
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2520
|
-
_result +=
|
|
2533
|
+
_result += "-";
|
|
2521
2534
|
} else {
|
|
2522
|
-
_result +=
|
|
2535
|
+
_result += "- ";
|
|
2523
2536
|
}
|
|
2524
2537
|
_result += state.dump;
|
|
2525
2538
|
}
|
|
2526
2539
|
}
|
|
2527
2540
|
state.tag = _tag;
|
|
2528
|
-
state.dump = _result ||
|
|
2541
|
+
state.dump = _result || "[]"; // Empty sequence if no valid values.
|
|
2529
2542
|
}
|
|
2530
2543
|
function writeFlowMapping(state, level, object) {
|
|
2531
|
-
var _result =
|
|
2544
|
+
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, pairBuffer;
|
|
2532
2545
|
for(index = 0, length = objectKeyList.length; index < length; index += 1){
|
|
2533
|
-
pairBuffer =
|
|
2534
|
-
if (_result !==
|
|
2546
|
+
pairBuffer = "";
|
|
2547
|
+
if (_result !== "") pairBuffer += ", ";
|
|
2535
2548
|
if (state.condenseFlow) pairBuffer += '"';
|
|
2536
2549
|
objectKey = objectKeyList[index];
|
|
2537
2550
|
objectValue = object[objectKey];
|
|
@@ -2541,8 +2554,8 @@ function writeFlowMapping(state, level, object) {
|
|
|
2541
2554
|
if (!writeNode(state, level, objectKey, false, false)) {
|
|
2542
2555
|
continue; // Skip this pair because of invalid key;
|
|
2543
2556
|
}
|
|
2544
|
-
if (state.dump.length > 1024) pairBuffer +=
|
|
2545
|
-
pairBuffer += state.dump + (state.condenseFlow ? '"' :
|
|
2557
|
+
if (state.dump.length > 1024) pairBuffer += "? ";
|
|
2558
|
+
pairBuffer += state.dump + (state.condenseFlow ? '"' : "") + ":" + (state.condenseFlow ? "" : " ");
|
|
2546
2559
|
if (!writeNode(state, level, objectValue, false, false)) {
|
|
2547
2560
|
continue; // Skip this pair because of invalid value.
|
|
2548
2561
|
}
|
|
@@ -2551,24 +2564,24 @@ function writeFlowMapping(state, level, object) {
|
|
|
2551
2564
|
_result += pairBuffer;
|
|
2552
2565
|
}
|
|
2553
2566
|
state.tag = _tag;
|
|
2554
|
-
state.dump =
|
|
2567
|
+
state.dump = "{" + _result + "}";
|
|
2555
2568
|
}
|
|
2556
2569
|
function writeBlockMapping(state, level, object, compact) {
|
|
2557
|
-
var _result =
|
|
2570
|
+
var _result = "", _tag = state.tag, objectKeyList = Object.keys(object), index, length, objectKey, objectValue, explicitPair, pairBuffer;
|
|
2558
2571
|
// Allow sorting keys so that the output file is deterministic
|
|
2559
2572
|
if (state.sortKeys === true) {
|
|
2560
2573
|
// Default sorting
|
|
2561
2574
|
objectKeyList.sort();
|
|
2562
|
-
} else if (typeof state.sortKeys ===
|
|
2575
|
+
} else if (typeof state.sortKeys === "function") {
|
|
2563
2576
|
// Custom sort function
|
|
2564
2577
|
objectKeyList.sort(state.sortKeys);
|
|
2565
2578
|
} else if (state.sortKeys) {
|
|
2566
2579
|
// Something is wrong
|
|
2567
|
-
throw new exception(
|
|
2580
|
+
throw new exception("sortKeys must be a boolean or a function");
|
|
2568
2581
|
}
|
|
2569
2582
|
for(index = 0, length = objectKeyList.length; index < length; index += 1){
|
|
2570
|
-
pairBuffer =
|
|
2571
|
-
if (!compact || _result !==
|
|
2583
|
+
pairBuffer = "";
|
|
2584
|
+
if (!compact || _result !== "") {
|
|
2572
2585
|
pairBuffer += generateNextLine(state, level);
|
|
2573
2586
|
}
|
|
2574
2587
|
objectKey = objectKeyList[index];
|
|
@@ -2579,12 +2592,12 @@ function writeBlockMapping(state, level, object, compact) {
|
|
|
2579
2592
|
if (!writeNode(state, level + 1, objectKey, true, true, true)) {
|
|
2580
2593
|
continue; // Skip this pair because of invalid key.
|
|
2581
2594
|
}
|
|
2582
|
-
explicitPair = state.tag !== null && state.tag !==
|
|
2595
|
+
explicitPair = state.tag !== null && state.tag !== "?" || state.dump && state.dump.length > 1024;
|
|
2583
2596
|
if (explicitPair) {
|
|
2584
2597
|
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2585
|
-
pairBuffer +=
|
|
2598
|
+
pairBuffer += "?";
|
|
2586
2599
|
} else {
|
|
2587
|
-
pairBuffer +=
|
|
2600
|
+
pairBuffer += "? ";
|
|
2588
2601
|
}
|
|
2589
2602
|
}
|
|
2590
2603
|
pairBuffer += state.dump;
|
|
@@ -2595,23 +2608,23 @@ function writeBlockMapping(state, level, object, compact) {
|
|
|
2595
2608
|
continue; // Skip this pair because of invalid value.
|
|
2596
2609
|
}
|
|
2597
2610
|
if (state.dump && CHAR_LINE_FEED === state.dump.charCodeAt(0)) {
|
|
2598
|
-
pairBuffer +=
|
|
2611
|
+
pairBuffer += ":";
|
|
2599
2612
|
} else {
|
|
2600
|
-
pairBuffer +=
|
|
2613
|
+
pairBuffer += ": ";
|
|
2601
2614
|
}
|
|
2602
2615
|
pairBuffer += state.dump;
|
|
2603
2616
|
// Both key and value are valid.
|
|
2604
2617
|
_result += pairBuffer;
|
|
2605
2618
|
}
|
|
2606
2619
|
state.tag = _tag;
|
|
2607
|
-
state.dump = _result ||
|
|
2620
|
+
state.dump = _result || "{}"; // Empty mapping if no valid pairs.
|
|
2608
2621
|
}
|
|
2609
2622
|
function detectType(state, object, explicit) {
|
|
2610
2623
|
var _result, typeList, index, length, type, style;
|
|
2611
2624
|
typeList = explicit ? state.explicitTypes : state.implicitTypes;
|
|
2612
2625
|
for(index = 0, length = typeList.length; index < length; index += 1){
|
|
2613
2626
|
type = typeList[index];
|
|
2614
|
-
if ((type.instanceOf || type.predicate) && (!type.instanceOf ||
|
|
2627
|
+
if ((type.instanceOf || type.predicate) && (!type.instanceOf || typeof object === "object" && _instanceof(object, type.instanceOf)) && (!type.predicate || type.predicate(object))) {
|
|
2615
2628
|
if (explicit) {
|
|
2616
2629
|
if (type.multi && type.representName) {
|
|
2617
2630
|
state.tag = type.representName(object);
|
|
@@ -2619,16 +2632,16 @@ function detectType(state, object, explicit) {
|
|
|
2619
2632
|
state.tag = type.tag;
|
|
2620
2633
|
}
|
|
2621
2634
|
} else {
|
|
2622
|
-
state.tag =
|
|
2635
|
+
state.tag = "?";
|
|
2623
2636
|
}
|
|
2624
2637
|
if (type.represent) {
|
|
2625
2638
|
style = state.styleMap[type.tag] || type.defaultStyle;
|
|
2626
|
-
if (_toString.call(type.represent) ===
|
|
2639
|
+
if (_toString.call(type.represent) === "[object Function]") {
|
|
2627
2640
|
_result = type.represent(object, style);
|
|
2628
2641
|
} else if (_hasOwnProperty.call(type.represent, style)) {
|
|
2629
2642
|
_result = type.represent[style](object, style);
|
|
2630
2643
|
} else {
|
|
2631
|
-
throw new exception(
|
|
2644
|
+
throw new exception("!<" + type.tag + '> tag resolver accepts not "' + style + '" style');
|
|
2632
2645
|
}
|
|
2633
2646
|
state.dump = _result;
|
|
2634
2647
|
}
|
|
@@ -2652,33 +2665,33 @@ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
|
2652
2665
|
if (block) {
|
|
2653
2666
|
block = state.flowLevel < 0 || state.flowLevel > level;
|
|
2654
2667
|
}
|
|
2655
|
-
var objectOrArray = type ===
|
|
2668
|
+
var objectOrArray = type === "[object Object]" || type === "[object Array]", duplicateIndex, duplicate;
|
|
2656
2669
|
if (objectOrArray) {
|
|
2657
2670
|
duplicateIndex = state.duplicates.indexOf(object);
|
|
2658
2671
|
duplicate = duplicateIndex !== -1;
|
|
2659
2672
|
}
|
|
2660
|
-
if (state.tag !== null && state.tag !==
|
|
2673
|
+
if (state.tag !== null && state.tag !== "?" || duplicate || state.indent !== 2 && level > 0) {
|
|
2661
2674
|
compact = false;
|
|
2662
2675
|
}
|
|
2663
2676
|
if (duplicate && state.usedDuplicates[duplicateIndex]) {
|
|
2664
|
-
state.dump =
|
|
2677
|
+
state.dump = "*ref_" + duplicateIndex;
|
|
2665
2678
|
} else {
|
|
2666
2679
|
if (objectOrArray && duplicate && !state.usedDuplicates[duplicateIndex]) {
|
|
2667
2680
|
state.usedDuplicates[duplicateIndex] = true;
|
|
2668
2681
|
}
|
|
2669
|
-
if (type ===
|
|
2682
|
+
if (type === "[object Object]") {
|
|
2670
2683
|
if (block && Object.keys(state.dump).length !== 0) {
|
|
2671
2684
|
writeBlockMapping(state, level, state.dump, compact);
|
|
2672
2685
|
if (duplicate) {
|
|
2673
|
-
state.dump =
|
|
2686
|
+
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
2674
2687
|
}
|
|
2675
2688
|
} else {
|
|
2676
2689
|
writeFlowMapping(state, level, state.dump);
|
|
2677
2690
|
if (duplicate) {
|
|
2678
|
-
state.dump =
|
|
2691
|
+
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
2679
2692
|
}
|
|
2680
2693
|
}
|
|
2681
|
-
} else if (type ===
|
|
2694
|
+
} else if (type === "[object Array]") {
|
|
2682
2695
|
if (block && state.dump.length !== 0) {
|
|
2683
2696
|
if (state.noArrayIndent && !isblockseq && level > 0) {
|
|
2684
2697
|
writeBlockSequence(state, level - 1, state.dump, compact);
|
|
@@ -2686,25 +2699,25 @@ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
|
2686
2699
|
writeBlockSequence(state, level, state.dump, compact);
|
|
2687
2700
|
}
|
|
2688
2701
|
if (duplicate) {
|
|
2689
|
-
state.dump =
|
|
2702
|
+
state.dump = "&ref_" + duplicateIndex + state.dump;
|
|
2690
2703
|
}
|
|
2691
2704
|
} else {
|
|
2692
2705
|
writeFlowSequence(state, level, state.dump);
|
|
2693
2706
|
if (duplicate) {
|
|
2694
|
-
state.dump =
|
|
2707
|
+
state.dump = "&ref_" + duplicateIndex + " " + state.dump;
|
|
2695
2708
|
}
|
|
2696
2709
|
}
|
|
2697
|
-
} else if (type ===
|
|
2698
|
-
if (state.tag !==
|
|
2710
|
+
} else if (type === "[object String]") {
|
|
2711
|
+
if (state.tag !== "?") {
|
|
2699
2712
|
writeScalar(state, state.dump, level, iskey, inblock);
|
|
2700
2713
|
}
|
|
2701
|
-
} else if (type ===
|
|
2714
|
+
} else if (type === "[object Undefined]") {
|
|
2702
2715
|
return false;
|
|
2703
2716
|
} else {
|
|
2704
2717
|
if (state.skipInvalid) return false;
|
|
2705
|
-
throw new exception(
|
|
2718
|
+
throw new exception("unacceptable kind of an object to dump " + type);
|
|
2706
2719
|
}
|
|
2707
|
-
if (state.tag !== null && state.tag !==
|
|
2720
|
+
if (state.tag !== null && state.tag !== "?") {
|
|
2708
2721
|
// Need to encode all characters except those allowed by the spec:
|
|
2709
2722
|
//
|
|
2710
2723
|
// [35] ns-dec-digit ::= [#x30-#x39] /* 0-9 */
|
|
@@ -2718,15 +2731,15 @@ function writeNode(state, level, object, block, compact, iskey, isblockseq) {
|
|
|
2718
2731
|
//
|
|
2719
2732
|
// Also need to encode '!' because it has special meaning (end of tag prefix).
|
|
2720
2733
|
//
|
|
2721
|
-
tagStr = encodeURI(state.tag[0] ===
|
|
2722
|
-
if (state.tag[0] ===
|
|
2723
|
-
tagStr =
|
|
2724
|
-
} else if (tagStr.slice(0, 18) ===
|
|
2725
|
-
tagStr =
|
|
2734
|
+
tagStr = encodeURI(state.tag[0] === "!" ? state.tag.slice(1) : state.tag).replace(/!/g, "%21");
|
|
2735
|
+
if (state.tag[0] === "!") {
|
|
2736
|
+
tagStr = "!" + tagStr;
|
|
2737
|
+
} else if (tagStr.slice(0, 18) === "tag:yaml.org,2002:") {
|
|
2738
|
+
tagStr = "!!" + tagStr.slice(18);
|
|
2726
2739
|
} else {
|
|
2727
|
-
tagStr =
|
|
2740
|
+
tagStr = "!<" + tagStr + ">";
|
|
2728
2741
|
}
|
|
2729
|
-
state.dump = tagStr +
|
|
2742
|
+
state.dump = tagStr + " " + state.dump;
|
|
2730
2743
|
}
|
|
2731
2744
|
}
|
|
2732
2745
|
return true;
|
|
@@ -2741,7 +2754,7 @@ function getDuplicateReferences(object, state) {
|
|
|
2741
2754
|
}
|
|
2742
2755
|
function inspectNode(object, objects, duplicatesIndexes) {
|
|
2743
2756
|
var objectKeyList, index, length;
|
|
2744
|
-
if (object !== null &&
|
|
2757
|
+
if (object !== null && typeof object === "object") {
|
|
2745
2758
|
index = objects.indexOf(object);
|
|
2746
2759
|
if (index !== -1) {
|
|
2747
2760
|
if (duplicatesIndexes.indexOf(index) === -1) {
|
|
@@ -2769,11 +2782,11 @@ function dump$1(input, options) {
|
|
|
2769
2782
|
var value = input;
|
|
2770
2783
|
if (state.replacer) {
|
|
2771
2784
|
value = state.replacer.call({
|
|
2772
|
-
|
|
2773
|
-
},
|
|
2785
|
+
"": value
|
|
2786
|
+
}, "", value);
|
|
2774
2787
|
}
|
|
2775
|
-
if (writeNode(state, 0, value, true, true)) return state.dump +
|
|
2776
|
-
return
|
|
2788
|
+
if (writeNode(state, 0, value, true, true)) return state.dump + "\n";
|
|
2789
|
+
return "";
|
|
2777
2790
|
}
|
|
2778
2791
|
var dump_1 = dump$1;
|
|
2779
2792
|
var dumper = {
|