yaml 1.9.1 → 1.10.2

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.
Files changed (162) hide show
  1. package/README.md +25 -25
  2. package/browser/dist/PlainValue-b8036b75.js +1275 -0
  3. package/browser/dist/Schema-e94716c8.js +682 -0
  4. package/browser/dist/index.js +860 -27
  5. package/browser/dist/legacy-exports.js +3 -0
  6. package/browser/dist/package.json +1 -0
  7. package/browser/dist/parse-cst.js +1904 -0
  8. package/browser/dist/resolveSeq-492ab440.js +2419 -0
  9. package/browser/dist/types.js +4 -0
  10. package/browser/dist/util.js +2 -0
  11. package/browser/dist/warnings-df54cb69.js +499 -0
  12. package/browser/index.js +1 -1
  13. package/browser/map.js +2 -4
  14. package/browser/pair.js +2 -4
  15. package/browser/parse-cst.js +1 -1
  16. package/browser/scalar.js +2 -4
  17. package/browser/schema.js +7 -10
  18. package/browser/seq.js +2 -4
  19. package/browser/types/binary.js +7 -5
  20. package/browser/types/omap.js +3 -4
  21. package/browser/types/pairs.js +3 -4
  22. package/browser/types/set.js +3 -4
  23. package/browser/types/timestamp.js +9 -5
  24. package/browser/types.js +1 -13
  25. package/browser/util.js +1 -18
  26. package/dist/Document-9b4560a1.js +757 -0
  27. package/dist/PlainValue-ec8e588e.js +876 -0
  28. package/dist/Schema-88e323a7.js +525 -0
  29. package/dist/index.js +20 -84
  30. package/dist/legacy-exports.js +16 -0
  31. package/dist/parse-cst.js +1753 -0
  32. package/dist/resolveSeq-d03cb037.js +2161 -0
  33. package/dist/test-events.js +11 -9
  34. package/dist/types.js +23 -0
  35. package/dist/util.js +19 -0
  36. package/dist/warnings-1000a372.js +416 -0
  37. package/index.d.ts +23 -9
  38. package/map.js +2 -2
  39. package/package.json +27 -42
  40. package/pair.js +2 -2
  41. package/parse-cst.d.ts +4 -0
  42. package/parse-cst.js +1 -1
  43. package/scalar.js +2 -2
  44. package/schema.js +8 -6
  45. package/seq.js +2 -2
  46. package/types/binary.js +3 -2
  47. package/types/omap.js +3 -2
  48. package/types/pairs.js +3 -2
  49. package/types/set.js +3 -2
  50. package/types/timestamp.js +6 -6
  51. package/types.d.ts +113 -98
  52. package/types.js +16 -11
  53. package/types.mjs +15 -19
  54. package/util.js +14 -14
  55. package/util.mjs +13 -20
  56. package/browser/dist/Anchors.js +0 -130
  57. package/browser/dist/Document.js +0 -824
  58. package/browser/dist/addComment.js +0 -8
  59. package/browser/dist/constants.js +0 -26
  60. package/browser/dist/cst/Alias.js +0 -46
  61. package/browser/dist/cst/BlankLine.js +0 -52
  62. package/browser/dist/cst/BlockValue.js +0 -251
  63. package/browser/dist/cst/Collection.js +0 -278
  64. package/browser/dist/cst/CollectionItem.js +0 -140
  65. package/browser/dist/cst/Comment.js +0 -44
  66. package/browser/dist/cst/Directive.js +0 -76
  67. package/browser/dist/cst/Document.js +0 -286
  68. package/browser/dist/cst/FlowCollection.js +0 -220
  69. package/browser/dist/cst/Node.js +0 -386
  70. package/browser/dist/cst/ParseContext.js +0 -246
  71. package/browser/dist/cst/PlainValue.js +0 -170
  72. package/browser/dist/cst/QuoteDouble.js +0 -245
  73. package/browser/dist/cst/QuoteSingle.js +0 -120
  74. package/browser/dist/cst/Range.js +0 -64
  75. package/browser/dist/cst/parse.js +0 -48
  76. package/browser/dist/cst/source-utils.js +0 -168
  77. package/browser/dist/errors.js +0 -127
  78. package/browser/dist/foldFlowLines.js +0 -138
  79. package/browser/dist/listTagNames.js +0 -28
  80. package/browser/dist/schema/Alias.js +0 -135
  81. package/browser/dist/schema/Collection.js +0 -260
  82. package/browser/dist/schema/Map.js +0 -161
  83. package/browser/dist/schema/Merge.js +0 -118
  84. package/browser/dist/schema/Node.js +0 -4
  85. package/browser/dist/schema/Pair.js +0 -194
  86. package/browser/dist/schema/Scalar.js +0 -42
  87. package/browser/dist/schema/Seq.js +0 -116
  88. package/browser/dist/schema/index.js +0 -368
  89. package/browser/dist/schema/parseMap.js +0 -312
  90. package/browser/dist/schema/parseSeq.js +0 -168
  91. package/browser/dist/schema/parseUtils.js +0 -106
  92. package/browser/dist/stringify.js +0 -332
  93. package/browser/dist/tags/core.js +0 -141
  94. package/browser/dist/tags/failsafe/index.js +0 -4
  95. package/browser/dist/tags/failsafe/map.js +0 -53
  96. package/browser/dist/tags/failsafe/seq.js +0 -39
  97. package/browser/dist/tags/failsafe/string.js +0 -28
  98. package/browser/dist/tags/index.js +0 -36
  99. package/browser/dist/tags/json.js +0 -77
  100. package/browser/dist/tags/options.js +0 -26
  101. package/browser/dist/tags/yaml-1.1/binary.js +0 -87
  102. package/browser/dist/tags/yaml-1.1/index.js +0 -189
  103. package/browser/dist/tags/yaml-1.1/omap.js +0 -137
  104. package/browser/dist/tags/yaml-1.1/pairs.js +0 -78
  105. package/browser/dist/tags/yaml-1.1/set.js +0 -118
  106. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
  107. package/browser/dist/test-events.js +0 -163
  108. package/browser/dist/toJSON.js +0 -19
  109. package/browser/dist/warnings.js +0 -39
  110. package/dist/Anchors.js +0 -120
  111. package/dist/Document.js +0 -714
  112. package/dist/addComment.js +0 -14
  113. package/dist/constants.js +0 -31
  114. package/dist/cst/Alias.js +0 -33
  115. package/dist/cst/BlankLine.js +0 -40
  116. package/dist/cst/BlockValue.js +0 -243
  117. package/dist/cst/Collection.js +0 -266
  118. package/dist/cst/CollectionItem.js +0 -135
  119. package/dist/cst/Comment.js +0 -33
  120. package/dist/cst/Directive.js +0 -59
  121. package/dist/cst/Document.js +0 -276
  122. package/dist/cst/FlowCollection.js +0 -213
  123. package/dist/cst/Node.js +0 -360
  124. package/dist/cst/ParseContext.js +0 -253
  125. package/dist/cst/PlainValue.js +0 -156
  126. package/dist/cst/QuoteDouble.js +0 -232
  127. package/dist/cst/QuoteSingle.js +0 -108
  128. package/dist/cst/Range.js +0 -60
  129. package/dist/cst/parse.js +0 -50
  130. package/dist/cst/source-utils.js +0 -175
  131. package/dist/errors.js +0 -97
  132. package/dist/foldFlowLines.js +0 -143
  133. package/dist/listTagNames.js +0 -33
  134. package/dist/schema/Alias.js +0 -105
  135. package/dist/schema/Collection.js +0 -184
  136. package/dist/schema/Map.js +0 -98
  137. package/dist/schema/Merge.js +0 -75
  138. package/dist/schema/Node.js +0 -7
  139. package/dist/schema/Pair.js +0 -174
  140. package/dist/schema/Scalar.js +0 -26
  141. package/dist/schema/Seq.js +0 -73
  142. package/dist/schema/index.js +0 -310
  143. package/dist/schema/parseMap.js +0 -334
  144. package/dist/schema/parseSeq.js +0 -175
  145. package/dist/schema/parseUtils.js +0 -101
  146. package/dist/stringify.js +0 -352
  147. package/dist/tags/core.js +0 -121
  148. package/dist/tags/failsafe/index.js +0 -12
  149. package/dist/tags/failsafe/map.js +0 -32
  150. package/dist/tags/failsafe/seq.js +0 -29
  151. package/dist/tags/failsafe/string.js +0 -37
  152. package/dist/tags/index.js +0 -53
  153. package/dist/tags/json.js +0 -64
  154. package/dist/tags/options.js +0 -36
  155. package/dist/tags/yaml-1.1/binary.js +0 -94
  156. package/dist/tags/yaml-1.1/index.js +0 -162
  157. package/dist/tags/yaml-1.1/omap.js +0 -100
  158. package/dist/tags/yaml-1.1/pairs.js +0 -75
  159. package/dist/tags/yaml-1.1/set.js +0 -82
  160. package/dist/tags/yaml-1.1/timestamp.js +0 -90
  161. package/dist/toJSON.js +0 -21
  162. package/dist/warnings.js +0 -48
@@ -1,184 +0,0 @@
1
- "use strict";
2
-
3
- exports.Collection = exports.isEmptyPath = void 0;
4
-
5
- var _addComment = require("../addComment");
6
-
7
- var _constants = require("../constants");
8
-
9
- var _Node = require("./Node");
10
-
11
- var _Scalar = require("./Scalar");
12
-
13
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
14
-
15
- function collectionFromPath(schema, path, value) {
16
- let v = value;
17
-
18
- for (let i = path.length - 1; i >= 0; --i) {
19
- const k = path[i];
20
- const o = Number.isInteger(k) && k >= 0 ? [] : {};
21
- o[k] = v;
22
- v = o;
23
- }
24
-
25
- return schema.createNode(v, false);
26
- } // null, undefined, or an empty non-string iterable (e.g. [])
27
-
28
-
29
- const isEmptyPath = path => path == null || typeof path === 'object' && path[Symbol.iterator]().next().done;
30
-
31
- exports.isEmptyPath = isEmptyPath;
32
-
33
- class Collection extends _Node.Node {
34
- constructor(schema) {
35
- super();
36
-
37
- _defineProperty(this, "items", []);
38
-
39
- this.schema = schema;
40
- }
41
-
42
- addIn(path, value) {
43
- if (isEmptyPath(path)) this.add(value);else {
44
- const [key, ...rest] = path;
45
- const node = this.get(key, true);
46
- if (node instanceof Collection) node.addIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
47
- }
48
- }
49
-
50
- deleteIn([key, ...rest]) {
51
- if (rest.length === 0) return this.delete(key);
52
- const node = this.get(key, true);
53
- if (node instanceof Collection) return node.deleteIn(rest);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
54
- }
55
-
56
- getIn([key, ...rest], keepScalar) {
57
- const node = this.get(key, true);
58
- if (rest.length === 0) return !keepScalar && node instanceof _Scalar.Scalar ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined;
59
- }
60
-
61
- hasAllNullValues() {
62
- return this.items.every(node => {
63
- if (!node || node.type !== 'PAIR') return false;
64
- const n = node.value;
65
- return n == null || n instanceof _Scalar.Scalar && n.value == null && !n.commentBefore && !n.comment && !n.tag;
66
- });
67
- }
68
-
69
- hasIn([key, ...rest]) {
70
- if (rest.length === 0) return this.has(key);
71
- const node = this.get(key, true);
72
- return node instanceof Collection ? node.hasIn(rest) : false;
73
- }
74
-
75
- setIn([key, ...rest], value) {
76
- if (rest.length === 0) {
77
- this.set(key, value);
78
- } else {
79
- const node = this.get(key, true);
80
- if (node instanceof Collection) node.setIn(rest, value);else if (node === undefined && this.schema) this.set(key, collectionFromPath(this.schema, rest, value));else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
81
- }
82
- } // overridden in implementations
83
-
84
- /* istanbul ignore next */
85
-
86
-
87
- toJSON() {
88
- return null;
89
- }
90
-
91
- toString(ctx, {
92
- blockItem,
93
- flowChars,
94
- isMap,
95
- itemIndent
96
- }, onComment, onChompKeep) {
97
- const {
98
- doc,
99
- indent,
100
- indentStep
101
- } = ctx;
102
- const inFlow = this.type === _constants.Type.FLOW_MAP || this.type === _constants.Type.FLOW_SEQ || ctx.inFlow;
103
- if (inFlow) itemIndent += indentStep;
104
- const allNullValues = isMap && this.hasAllNullValues();
105
- ctx = Object.assign({}, ctx, {
106
- allNullValues,
107
- indent: itemIndent,
108
- inFlow,
109
- type: null
110
- });
111
- let chompKeep = false;
112
- let hasItemWithNewLine = false;
113
- const nodes = this.items.reduce((nodes, item, i) => {
114
- let comment;
115
-
116
- if (item) {
117
- if (!chompKeep && item.spaceBefore) nodes.push({
118
- type: 'comment',
119
- str: ''
120
- });
121
- if (item.commentBefore) item.commentBefore.match(/^.*$/gm).forEach(line => {
122
- nodes.push({
123
- type: 'comment',
124
- str: `#${line}`
125
- });
126
- });
127
- if (item.comment) comment = item.comment;
128
- if (inFlow && (!chompKeep && item.spaceBefore || item.commentBefore || item.comment || item.key && (item.key.commentBefore || item.key.comment) || item.value && (item.value.commentBefore || item.value.comment))) hasItemWithNewLine = true;
129
- }
130
-
131
- chompKeep = false;
132
- let str = doc.schema.stringify(item, ctx, () => comment = null, () => chompKeep = true);
133
- if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true;
134
- if (inFlow && i < this.items.length - 1) str += ',';
135
- str = (0, _addComment.addComment)(str, itemIndent, comment);
136
- if (chompKeep && (comment || inFlow)) chompKeep = false;
137
- nodes.push({
138
- type: 'item',
139
- str
140
- });
141
- return nodes;
142
- }, []);
143
- let str;
144
-
145
- if (nodes.length === 0) {
146
- str = flowChars.start + flowChars.end;
147
- } else if (inFlow) {
148
- const {
149
- start,
150
- end
151
- } = flowChars;
152
- const strings = nodes.map(n => n.str);
153
-
154
- if (hasItemWithNewLine || strings.reduce((sum, str) => sum + str.length + 2, 2) > Collection.maxFlowStringSingleLineLength) {
155
- str = start;
156
-
157
- for (const s of strings) {
158
- str += s ? `\n${indentStep}${indent}${s}` : '\n';
159
- }
160
-
161
- str += `\n${indent}${end}`;
162
- } else {
163
- str = `${start} ${strings.join(' ')} ${end}`;
164
- }
165
- } else {
166
- const strings = nodes.map(blockItem);
167
- str = strings.shift();
168
-
169
- for (const s of strings) str += s ? `\n${indent}${s}` : '\n';
170
- }
171
-
172
- if (this.comment) {
173
- str += '\n' + this.comment.replace(/^/gm, `${indent}#`);
174
- if (onComment) onComment();
175
- } else if (chompKeep && onChompKeep) onChompKeep();
176
-
177
- return str;
178
- }
179
-
180
- }
181
-
182
- exports.Collection = Collection;
183
-
184
- _defineProperty(Collection, "maxFlowStringSingleLineLength", 60);
@@ -1,98 +0,0 @@
1
- "use strict";
2
-
3
- exports.findPair = findPair;
4
- exports.YAMLMap = void 0;
5
-
6
- var _Collection = require("./Collection");
7
-
8
- var _Pair = require("./Pair");
9
-
10
- var _Scalar = require("./Scalar");
11
-
12
- function findPair(items, key) {
13
- const k = key instanceof _Scalar.Scalar ? key.value : key;
14
-
15
- for (const it of items) {
16
- if (it instanceof _Pair.Pair) {
17
- if (it.key === key || it.key === k) return it;
18
- if (it.key && it.key.value === k) return it;
19
- }
20
- }
21
-
22
- return undefined;
23
- }
24
-
25
- class YAMLMap extends _Collection.Collection {
26
- add(pair, overwrite) {
27
- if (!pair) pair = new _Pair.Pair(pair);else if (!(pair instanceof _Pair.Pair)) pair = new _Pair.Pair(pair.key || pair, pair.value);
28
- const prev = findPair(this.items, pair.key);
29
- const sortEntries = this.schema && this.schema.sortMapEntries;
30
-
31
- if (prev) {
32
- if (overwrite) prev.value = pair.value;else throw new Error(`Key ${pair.key} already set`);
33
- } else if (sortEntries) {
34
- const i = this.items.findIndex(item => sortEntries(pair, item) < 0);
35
- if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair);
36
- } else {
37
- this.items.push(pair);
38
- }
39
- }
40
-
41
- delete(key) {
42
- const it = findPair(this.items, key);
43
- if (!it) return false;
44
- const del = this.items.splice(this.items.indexOf(it), 1);
45
- return del.length > 0;
46
- }
47
-
48
- get(key, keepScalar) {
49
- const it = findPair(this.items, key);
50
- const node = it && it.value;
51
- return !keepScalar && node instanceof _Scalar.Scalar ? node.value : node;
52
- }
53
-
54
- has(key) {
55
- return !!findPair(this.items, key);
56
- }
57
-
58
- set(key, value) {
59
- this.add(new _Pair.Pair(key, value), true);
60
- }
61
- /**
62
- * @param {*} arg ignored
63
- * @param {*} ctx Conversion context, originally set in Document#toJSON()
64
- * @param {Class} Type If set, forces the returned collection type
65
- * @returns {*} Instance of Type, Map, or Object
66
- */
67
-
68
-
69
- toJSON(_, ctx, Type) {
70
- const map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
71
- if (ctx && ctx.onCreate) ctx.onCreate(map);
72
-
73
- for (const item of this.items) item.addToJSMap(ctx, map);
74
-
75
- return map;
76
- }
77
-
78
- toString(ctx, onComment, onChompKeep) {
79
- if (!ctx) return JSON.stringify(this);
80
-
81
- for (const item of this.items) {
82
- if (!(item instanceof _Pair.Pair)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
83
- }
84
-
85
- return super.toString(ctx, {
86
- blockItem: n => n.str,
87
- flowChars: {
88
- start: '{',
89
- end: '}'
90
- },
91
- isMap: true,
92
- itemIndent: ctx.indent || ''
93
- }, onComment, onChompKeep);
94
- }
95
-
96
- }
97
-
98
- exports.YAMLMap = YAMLMap;
@@ -1,75 +0,0 @@
1
- "use strict";
2
-
3
- exports.Merge = exports.MERGE_KEY = void 0;
4
-
5
- var _Map = require("./Map");
6
-
7
- var _Pair = require("./Pair");
8
-
9
- var _Scalar = require("./Scalar");
10
-
11
- var _Seq = require("./Seq");
12
-
13
- const MERGE_KEY = '<<';
14
- exports.MERGE_KEY = MERGE_KEY;
15
-
16
- class Merge extends _Pair.Pair {
17
- constructor(pair) {
18
- if (pair instanceof _Pair.Pair) {
19
- let seq = pair.value;
20
-
21
- if (!(seq instanceof _Seq.YAMLSeq)) {
22
- seq = new _Seq.YAMLSeq();
23
- seq.items.push(pair.value);
24
- seq.range = pair.value.range;
25
- }
26
-
27
- super(pair.key, seq);
28
- this.range = pair.range;
29
- } else {
30
- super(new _Scalar.Scalar(MERGE_KEY), new _Seq.YAMLSeq());
31
- }
32
-
33
- this.type = _Pair.Pair.Type.MERGE_PAIR;
34
- } // If the value associated with a merge key is a single mapping node, each of
35
- // its key/value pairs is inserted into the current mapping, unless the key
36
- // already exists in it. If the value associated with the merge key is a
37
- // sequence, then this sequence is expected to contain mapping nodes and each
38
- // of these nodes is merged in turn according to its order in the sequence.
39
- // Keys in mapping nodes earlier in the sequence override keys specified in
40
- // later mapping nodes. -- http://yaml.org/type/merge.html
41
-
42
-
43
- addToJSMap(ctx, map) {
44
- for (const {
45
- source
46
- } of this.value.items) {
47
- if (!(source instanceof _Map.YAMLMap)) throw new Error('Merge sources must be maps');
48
- const srcMap = source.toJSON(null, ctx, Map);
49
-
50
- for (const [key, value] of srcMap) {
51
- if (map instanceof Map) {
52
- if (!map.has(key)) map.set(key, value);
53
- } else if (map instanceof Set) {
54
- map.add(key);
55
- } else {
56
- if (!Object.prototype.hasOwnProperty.call(map, key)) map[key] = value;
57
- }
58
- }
59
- }
60
-
61
- return map;
62
- }
63
-
64
- toString(ctx, onComment) {
65
- const seq = this.value;
66
- if (seq.items.length > 1) return super.toString(ctx, onComment);
67
- this.value = seq.items[0];
68
- const str = super.toString(ctx, onComment);
69
- this.value = seq;
70
- return str;
71
- }
72
-
73
- }
74
-
75
- exports.Merge = Merge;
@@ -1,7 +0,0 @@
1
- "use strict";
2
-
3
- exports.Node = void 0;
4
-
5
- class Node {}
6
-
7
- exports.Node = Node;
@@ -1,174 +0,0 @@
1
- "use strict";
2
-
3
- exports.Pair = void 0;
4
-
5
- var _addComment = require("../addComment");
6
-
7
- var _constants = require("../constants");
8
-
9
- var _toJSON = require("../toJSON");
10
-
11
- var _Collection = require("./Collection");
12
-
13
- var _Node = require("./Node");
14
-
15
- var _Scalar = require("./Scalar");
16
-
17
- var _Seq = require("./Seq");
18
-
19
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
20
-
21
- const stringifyKey = (key, jsKey, ctx) => {
22
- if (jsKey === null) return '';
23
- if (typeof jsKey !== 'object') return String(jsKey);
24
- if (key instanceof _Node.Node && ctx && ctx.doc) return key.toString({
25
- anchors: {},
26
- doc: ctx.doc,
27
- indent: '',
28
- indentStep: ctx.indentStep,
29
- inFlow: true,
30
- inStringifyKey: true
31
- });
32
- return JSON.stringify(jsKey);
33
- };
34
-
35
- class Pair extends _Node.Node {
36
- constructor(key, value = null) {
37
- super();
38
- this.key = key;
39
- this.value = value;
40
- this.type = Pair.Type.PAIR;
41
- }
42
-
43
- get commentBefore() {
44
- return this.key && this.key.commentBefore;
45
- }
46
-
47
- set commentBefore(cb) {
48
- if (this.key == null) this.key = new _Scalar.Scalar(null);
49
- this.key.commentBefore = cb;
50
- }
51
-
52
- addToJSMap(ctx, map) {
53
- const key = (0, _toJSON.toJSON)(this.key, '', ctx);
54
-
55
- if (map instanceof Map) {
56
- const value = (0, _toJSON.toJSON)(this.value, key, ctx);
57
- map.set(key, value);
58
- } else if (map instanceof Set) {
59
- map.add(key);
60
- } else {
61
- const stringKey = stringifyKey(this.key, key, ctx);
62
- map[stringKey] = (0, _toJSON.toJSON)(this.value, stringKey, ctx);
63
- }
64
-
65
- return map;
66
- }
67
-
68
- toJSON(_, ctx) {
69
- const pair = ctx && ctx.mapAsMap ? new Map() : {};
70
- return this.addToJSMap(ctx, pair);
71
- }
72
-
73
- toString(ctx, onComment, onChompKeep) {
74
- if (!ctx || !ctx.doc) return JSON.stringify(this);
75
- const {
76
- indent: indentSize,
77
- indentSeq,
78
- simpleKeys
79
- } = ctx.doc.options;
80
- let {
81
- key,
82
- value
83
- } = this;
84
- let keyComment = key instanceof _Node.Node && key.comment;
85
-
86
- if (simpleKeys) {
87
- if (keyComment) {
88
- throw new Error('With simple keys, key nodes cannot have comments');
89
- }
90
-
91
- if (key instanceof _Collection.Collection) {
92
- const msg = 'With simple keys, collection cannot be used as a key value';
93
- throw new Error(msg);
94
- }
95
- }
96
-
97
- const explicitKey = !simpleKeys && (!key || keyComment || key instanceof _Collection.Collection || key.type === _constants.Type.BLOCK_FOLDED || key.type === _constants.Type.BLOCK_LITERAL);
98
- const {
99
- doc,
100
- indent,
101
- indentStep
102
- } = ctx;
103
- ctx = Object.assign({}, ctx, {
104
- implicitKey: !explicitKey,
105
- indent: indent + indentStep
106
- });
107
- let chompKeep = false;
108
- let str = doc.schema.stringify(key, ctx, () => keyComment = null, () => chompKeep = true);
109
- str = (0, _addComment.addComment)(str, ctx.indent, keyComment);
110
-
111
- if (ctx.allNullValues && !simpleKeys) {
112
- if (this.comment) {
113
- str = (0, _addComment.addComment)(str, ctx.indent, this.comment);
114
- if (onComment) onComment();
115
- } else if (chompKeep && !keyComment && onChompKeep) onChompKeep();
116
-
117
- return ctx.inFlow ? str : `? ${str}`;
118
- }
119
-
120
- str = explicitKey ? `? ${str}\n${indent}:` : `${str}:`;
121
-
122
- if (this.comment) {
123
- // expected (but not strictly required) to be a single-line comment
124
- str = (0, _addComment.addComment)(str, ctx.indent, this.comment);
125
- if (onComment) onComment();
126
- }
127
-
128
- let vcb = '';
129
- let valueComment = null;
130
-
131
- if (value instanceof _Node.Node) {
132
- if (value.spaceBefore) vcb = '\n';
133
-
134
- if (value.commentBefore) {
135
- const cs = value.commentBefore.replace(/^/gm, `${ctx.indent}#`);
136
- vcb += `\n${cs}`;
137
- }
138
-
139
- valueComment = value.comment;
140
- } else if (value && typeof value === 'object') {
141
- value = doc.schema.createNode(value, true);
142
- }
143
-
144
- ctx.implicitKey = false;
145
- if (!explicitKey && !this.comment && value instanceof _Scalar.Scalar) ctx.indentAtStart = str.length + 1;
146
- chompKeep = false;
147
-
148
- if (!indentSeq && indentSize >= 2 && !ctx.inFlow && !explicitKey && value instanceof _Seq.YAMLSeq && value.type !== _constants.Type.FLOW_SEQ && !value.tag && !doc.anchors.getName(value)) {
149
- // If indentSeq === false, consider '- ' as part of indentation where possible
150
- ctx.indent = ctx.indent.substr(2);
151
- }
152
-
153
- const valueStr = doc.schema.stringify(value, ctx, () => valueComment = null, () => chompKeep = true);
154
- let ws = ' ';
155
-
156
- if (vcb || this.comment) {
157
- ws = `${vcb}\n${ctx.indent}`;
158
- } else if (!explicitKey && value instanceof _Collection.Collection) {
159
- const flow = valueStr[0] === '[' || valueStr[0] === '{';
160
- if (!flow || valueStr.includes('\n')) ws = `\n${ctx.indent}`;
161
- }
162
-
163
- if (chompKeep && !valueComment && onChompKeep) onChompKeep();
164
- return (0, _addComment.addComment)(str + ws + valueStr, ctx.indent, valueComment);
165
- }
166
-
167
- }
168
-
169
- exports.Pair = Pair;
170
-
171
- _defineProperty(Pair, "Type", {
172
- PAIR: 'PAIR',
173
- MERGE_PAIR: 'MERGE_PAIR'
174
- });
@@ -1,26 +0,0 @@
1
- "use strict";
2
-
3
- exports.Scalar = void 0;
4
-
5
- var _toJSON = require("../toJSON");
6
-
7
- var _Node = require("./Node");
8
-
9
- // Published as 'yaml/scalar'
10
- class Scalar extends _Node.Node {
11
- constructor(value) {
12
- super();
13
- this.value = value;
14
- }
15
-
16
- toJSON(arg, ctx) {
17
- return ctx && ctx.keep ? this.value : (0, _toJSON.toJSON)(this.value, arg, ctx);
18
- }
19
-
20
- toString() {
21
- return String(this.value);
22
- }
23
-
24
- }
25
-
26
- exports.Scalar = Scalar;
@@ -1,73 +0,0 @@
1
- "use strict";
2
-
3
- exports.YAMLSeq = void 0;
4
-
5
- var _toJSON = require("../toJSON");
6
-
7
- var _Collection = require("./Collection");
8
-
9
- var _Scalar = require("./Scalar");
10
-
11
- // Published as 'yaml/seq'
12
- function asItemIndex(key) {
13
- let idx = key instanceof _Scalar.Scalar ? key.value : key;
14
- if (idx && typeof idx === 'string') idx = Number(idx);
15
- return Number.isInteger(idx) && idx >= 0 ? idx : null;
16
- }
17
-
18
- class YAMLSeq extends _Collection.Collection {
19
- add(value) {
20
- this.items.push(value);
21
- }
22
-
23
- delete(key) {
24
- const idx = asItemIndex(key);
25
- if (typeof idx !== 'number') return false;
26
- const del = this.items.splice(idx, 1);
27
- return del.length > 0;
28
- }
29
-
30
- get(key, keepScalar) {
31
- const idx = asItemIndex(key);
32
- if (typeof idx !== 'number') return undefined;
33
- const it = this.items[idx];
34
- return !keepScalar && it instanceof _Scalar.Scalar ? it.value : it;
35
- }
36
-
37
- has(key) {
38
- const idx = asItemIndex(key);
39
- return typeof idx === 'number' && idx < this.items.length;
40
- }
41
-
42
- set(key, value) {
43
- const idx = asItemIndex(key);
44
- if (typeof idx !== 'number') throw new Error(`Expected a valid index, not ${key}.`);
45
- this.items[idx] = value;
46
- }
47
-
48
- toJSON(_, ctx) {
49
- const seq = [];
50
- if (ctx && ctx.onCreate) ctx.onCreate(seq);
51
- let i = 0;
52
-
53
- for (const item of this.items) seq.push((0, _toJSON.toJSON)(item, String(i++), ctx));
54
-
55
- return seq;
56
- }
57
-
58
- toString(ctx, onComment, onChompKeep) {
59
- if (!ctx) return JSON.stringify(this);
60
- return super.toString(ctx, {
61
- blockItem: n => n.type === 'comment' ? n.str : `- ${n.str}`,
62
- flowChars: {
63
- start: '[',
64
- end: ']'
65
- },
66
- isMap: false,
67
- itemIndent: (ctx.indent || '') + ' '
68
- }, onComment, onChompKeep);
69
- }
70
-
71
- }
72
-
73
- exports.YAMLSeq = YAMLSeq;