yaml 1.8.3 → 1.10.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.
Files changed (163) hide show
  1. package/README.md +4 -4
  2. package/browser/dist/PlainValue-ff5147c6.js +1277 -0
  3. package/browser/dist/Schema-2bf2c74e.js +679 -0
  4. package/browser/dist/index.js +923 -38
  5. package/browser/dist/legacy-exports.js +3 -0
  6. package/browser/dist/parse-cst.js +1904 -0
  7. package/browser/dist/resolveSeq-04825f30.js +2373 -0
  8. package/browser/dist/types.js +4 -0
  9. package/browser/dist/util.js +2 -0
  10. package/browser/dist/warnings-0e4b70d3.js +499 -0
  11. package/browser/index.js +1 -1
  12. package/browser/map.js +2 -2
  13. package/browser/pair.js +2 -2
  14. package/browser/parse-cst.js +1 -1
  15. package/browser/scalar.js +2 -2
  16. package/browser/schema.js +8 -6
  17. package/browser/seq.js +2 -2
  18. package/browser/types/binary.js +3 -2
  19. package/browser/types/omap.js +3 -2
  20. package/browser/types/pairs.js +3 -2
  21. package/browser/types/set.js +3 -2
  22. package/browser/types/timestamp.js +6 -6
  23. package/browser/types.js +1 -11
  24. package/browser/util.js +1 -15
  25. package/dist/Document-2cf6b08c.js +757 -0
  26. package/dist/PlainValue-ec8e588e.js +876 -0
  27. package/dist/Schema-42e9705c.js +522 -0
  28. package/dist/index.js +21 -43
  29. package/dist/legacy-exports.js +16 -0
  30. package/dist/parse-cst.js +1747 -0
  31. package/dist/resolveSeq-4a68b39b.js +2115 -0
  32. package/dist/test-events.js +11 -14
  33. package/dist/types.js +23 -0
  34. package/dist/util.js +19 -0
  35. package/dist/warnings-39684f17.js +416 -0
  36. package/index.d.ts +372 -0
  37. package/index.js +1 -1
  38. package/map.js +2 -2
  39. package/package.json +32 -45
  40. package/pair.js +2 -2
  41. package/parse-cst.d.ts +187 -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 +407 -0
  52. package/types.js +16 -10
  53. package/types.mjs +15 -18
  54. package/util.d.ts +86 -0
  55. package/util.js +14 -13
  56. package/util.mjs +13 -19
  57. package/browser/dist/Anchors.js +0 -133
  58. package/browser/dist/Document.js +0 -819
  59. package/browser/dist/addComment.js +0 -8
  60. package/browser/dist/constants.js +0 -26
  61. package/browser/dist/cst/Alias.js +0 -42
  62. package/browser/dist/cst/BlankLine.js +0 -56
  63. package/browser/dist/cst/BlockValue.js +0 -247
  64. package/browser/dist/cst/Collection.js +0 -274
  65. package/browser/dist/cst/CollectionItem.js +0 -136
  66. package/browser/dist/cst/Comment.js +0 -40
  67. package/browser/dist/cst/Directive.js +0 -72
  68. package/browser/dist/cst/Document.js +0 -282
  69. package/browser/dist/cst/FlowCollection.js +0 -216
  70. package/browser/dist/cst/Node.js +0 -388
  71. package/browser/dist/cst/ParseContext.js +0 -248
  72. package/browser/dist/cst/PlainValue.js +0 -166
  73. package/browser/dist/cst/QuoteDouble.js +0 -241
  74. package/browser/dist/cst/QuoteSingle.js +0 -116
  75. package/browser/dist/cst/Range.js +0 -67
  76. package/browser/dist/cst/parse.js +0 -48
  77. package/browser/dist/cst/source-utils.js +0 -168
  78. package/browser/dist/errors.js +0 -112
  79. package/browser/dist/foldFlowLines.js +0 -138
  80. package/browser/dist/listTagNames.js +0 -28
  81. package/browser/dist/schema/Alias.js +0 -139
  82. package/browser/dist/schema/Collection.js +0 -267
  83. package/browser/dist/schema/Map.js +0 -178
  84. package/browser/dist/schema/Merge.js +0 -127
  85. package/browser/dist/schema/Node.js +0 -7
  86. package/browser/dist/schema/Pair.js +0 -171
  87. package/browser/dist/schema/Scalar.js +0 -38
  88. package/browser/dist/schema/Seq.js +0 -114
  89. package/browser/dist/schema/index.js +0 -382
  90. package/browser/dist/schema/parseMap.js +0 -312
  91. package/browser/dist/schema/parseSeq.js +0 -168
  92. package/browser/dist/schema/parseUtils.js +0 -110
  93. package/browser/dist/stringify.js +0 -331
  94. package/browser/dist/tags/core.js +0 -126
  95. package/browser/dist/tags/failsafe/index.js +0 -4
  96. package/browser/dist/tags/failsafe/map.js +0 -56
  97. package/browser/dist/tags/failsafe/seq.js +0 -43
  98. package/browser/dist/tags/failsafe/string.js +0 -28
  99. package/browser/dist/tags/index.js +0 -36
  100. package/browser/dist/tags/json.js +0 -76
  101. package/browser/dist/tags/options.js +0 -23
  102. package/browser/dist/tags/yaml-1.1/binary.js +0 -87
  103. package/browser/dist/tags/yaml-1.1/index.js +0 -157
  104. package/browser/dist/tags/yaml-1.1/omap.js +0 -142
  105. package/browser/dist/tags/yaml-1.1/pairs.js +0 -81
  106. package/browser/dist/tags/yaml-1.1/set.js +0 -114
  107. package/browser/dist/tags/yaml-1.1/timestamp.js +0 -97
  108. package/browser/dist/test-events.js +0 -163
  109. package/browser/dist/toJSON.js +0 -20
  110. package/browser/dist/warnings.js +0 -28
  111. package/dist/Anchors.js +0 -125
  112. package/dist/Document.js +0 -710
  113. package/dist/addComment.js +0 -17
  114. package/dist/constants.js +0 -34
  115. package/dist/cst/Alias.js +0 -38
  116. package/dist/cst/BlankLine.js +0 -56
  117. package/dist/cst/BlockValue.js +0 -248
  118. package/dist/cst/Collection.js +0 -271
  119. package/dist/cst/CollectionItem.js +0 -140
  120. package/dist/cst/Comment.js +0 -38
  121. package/dist/cst/Directive.js +0 -64
  122. package/dist/cst/Document.js +0 -281
  123. package/dist/cst/FlowCollection.js +0 -218
  124. package/dist/cst/Node.js +0 -365
  125. package/dist/cst/ParseContext.js +0 -258
  126. package/dist/cst/PlainValue.js +0 -161
  127. package/dist/cst/QuoteDouble.js +0 -237
  128. package/dist/cst/QuoteSingle.js +0 -113
  129. package/dist/cst/Range.js +0 -63
  130. package/dist/cst/parse.js +0 -55
  131. package/dist/cst/source-utils.js +0 -178
  132. package/dist/errors.js +0 -102
  133. package/dist/foldFlowLines.js +0 -146
  134. package/dist/listTagNames.js +0 -38
  135. package/dist/schema/Alias.js +0 -110
  136. package/dist/schema/Collection.js +0 -188
  137. package/dist/schema/Map.js +0 -103
  138. package/dist/schema/Merge.js +0 -80
  139. package/dist/schema/Node.js +0 -10
  140. package/dist/schema/Pair.js +0 -161
  141. package/dist/schema/Scalar.js +0 -31
  142. package/dist/schema/Seq.js +0 -78
  143. package/dist/schema/index.js +0 -315
  144. package/dist/schema/parseMap.js +0 -343
  145. package/dist/schema/parseSeq.js +0 -180
  146. package/dist/schema/parseUtils.js +0 -104
  147. package/dist/stringify.js +0 -358
  148. package/dist/tags/core.js +0 -114
  149. package/dist/tags/failsafe/index.js +0 -17
  150. package/dist/tags/failsafe/map.js +0 -37
  151. package/dist/tags/failsafe/seq.js +0 -34
  152. package/dist/tags/failsafe/string.js +0 -40
  153. package/dist/tags/index.js +0 -62
  154. package/dist/tags/json.js +0 -60
  155. package/dist/tags/options.js +0 -35
  156. package/dist/tags/yaml-1.1/binary.js +0 -97
  157. package/dist/tags/yaml-1.1/index.js +0 -131
  158. package/dist/tags/yaml-1.1/omap.js +0 -105
  159. package/dist/tags/yaml-1.1/pairs.js +0 -80
  160. package/dist/tags/yaml-1.1/set.js +0 -91
  161. package/dist/tags/yaml-1.1/timestamp.js +0 -93
  162. package/dist/toJSON.js +0 -23
  163. package/dist/warnings.js +0 -39
@@ -1,110 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _constants = require("../constants");
9
-
10
- var _errors = require("../errors");
11
-
12
- var _toJSON = _interopRequireDefault(require("../toJSON"));
13
-
14
- var _Collection = _interopRequireDefault(require("./Collection"));
15
-
16
- var _Node = _interopRequireDefault(require("./Node"));
17
-
18
- var _Pair = _interopRequireDefault(require("./Pair"));
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- 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; }
23
-
24
- const getAliasCount = (node, anchors) => {
25
- if (node instanceof Alias) {
26
- const anchor = anchors.find(a => a.node === node.source);
27
- return anchor.count * anchor.aliasCount;
28
- } else if (node instanceof _Collection.default) {
29
- let count = 0;
30
-
31
- for (const item of node.items) {
32
- const c = getAliasCount(item, anchors);
33
- if (c > count) count = c;
34
- }
35
-
36
- return count;
37
- } else if (node instanceof _Pair.default) {
38
- const kc = getAliasCount(node.key, anchors);
39
- const vc = getAliasCount(node.value, anchors);
40
- return Math.max(kc, vc);
41
- }
42
-
43
- return 1;
44
- };
45
-
46
- class Alias extends _Node.default {
47
- static stringify({
48
- range,
49
- source
50
- }, {
51
- anchors,
52
- doc,
53
- implicitKey,
54
- inStringifyKey
55
- }) {
56
- let anchor = Object.keys(anchors).find(a => anchors[a] === source);
57
- if (!anchor && inStringifyKey) anchor = doc.anchors.getName(source) || doc.anchors.newName();
58
- if (anchor) return `*${anchor}${implicitKey ? ' ' : ''}`;
59
- const msg = doc.anchors.getName(source) ? 'Alias node must be after source node' : 'Source node not found for alias node';
60
- throw new Error(`${msg} [${range}]`);
61
- }
62
-
63
- constructor(source) {
64
- super();
65
- this.source = source;
66
- this.type = _constants.Type.ALIAS;
67
- }
68
-
69
- set tag(t) {
70
- throw new Error('Alias nodes cannot have tags');
71
- }
72
-
73
- toJSON(arg, ctx) {
74
- if (!ctx) return (0, _toJSON.default)(this.source, arg, ctx);
75
- const {
76
- anchors,
77
- maxAliasCount
78
- } = ctx;
79
- const anchor = anchors.find(a => a.node === this.source);
80
- /* istanbul ignore if */
81
-
82
- if (!anchor || anchor.res === undefined) {
83
- const msg = 'This should not happen: Alias anchor was not resolved?';
84
- if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
85
- }
86
-
87
- if (maxAliasCount >= 0) {
88
- anchor.count += 1;
89
- if (anchor.aliasCount === 0) anchor.aliasCount = getAliasCount(this.source, anchors);
90
-
91
- if (anchor.count * anchor.aliasCount > maxAliasCount) {
92
- const msg = 'Excessive alias count indicates a resource exhaustion attack';
93
- if (this.cstNode) throw new _errors.YAMLReferenceError(this.cstNode, msg);else throw new ReferenceError(msg);
94
- }
95
- }
96
-
97
- return anchor.res;
98
- } // Only called when stringifying an alias mapping key while constructing
99
- // Object output.
100
-
101
-
102
- toString(ctx) {
103
- return Alias.stringify(this, ctx);
104
- }
105
-
106
- }
107
-
108
- exports.default = Alias;
109
-
110
- _defineProperty(Alias, "default", true);
@@ -1,188 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.isEmptyPath = void 0;
7
-
8
- var _addComment = _interopRequireDefault(require("../addComment"));
9
-
10
- var _Node = _interopRequireDefault(require("./Node"));
11
-
12
- var _Pair = _interopRequireDefault(require("./Pair"));
13
-
14
- var _Scalar = _interopRequireDefault(require("./Scalar"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- 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; }
19
-
20
- function collectionFromPath(schema, path, value) {
21
- let v = value;
22
-
23
- for (let i = path.length - 1; i >= 0; --i) {
24
- const k = path[i];
25
- const o = Number.isInteger(k) && k >= 0 ? [] : {};
26
- o[k] = v;
27
- v = o;
28
- }
29
-
30
- return schema.createNode(v, false);
31
- } // null, undefined, or an empty non-string iterable (e.g. [])
32
-
33
-
34
- const isEmptyPath = path => path == null || typeof path === 'object' && path[Symbol.iterator]().next().done;
35
-
36
- exports.isEmptyPath = isEmptyPath;
37
-
38
- class Collection extends _Node.default {
39
- constructor(schema) {
40
- super();
41
-
42
- _defineProperty(this, "items", []);
43
-
44
- this.schema = schema;
45
- }
46
-
47
- addIn(path, value) {
48
- if (isEmptyPath(path)) this.add(value);else {
49
- const [key, ...rest] = path;
50
- const node = this.get(key, true);
51
- 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}`);
52
- }
53
- }
54
-
55
- deleteIn([key, ...rest]) {
56
- if (rest.length === 0) return this.delete(key);
57
- const node = this.get(key, true);
58
- if (node instanceof Collection) return node.deleteIn(rest);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
59
- }
60
-
61
- getIn([key, ...rest], keepScalar) {
62
- const node = this.get(key, true);
63
- if (rest.length === 0) return !keepScalar && node instanceof _Scalar.default ? node.value : node;else return node instanceof Collection ? node.getIn(rest, keepScalar) : undefined;
64
- }
65
-
66
- hasAllNullValues() {
67
- return this.items.every(node => {
68
- if (!(node instanceof _Pair.default)) return false;
69
- const n = node.value;
70
- return n == null || n instanceof _Scalar.default && n.value == null && !n.commentBefore && !n.comment && !n.tag;
71
- });
72
- }
73
-
74
- hasIn([key, ...rest]) {
75
- if (rest.length === 0) return this.has(key);
76
- const node = this.get(key, true);
77
- return node instanceof Collection ? node.hasIn(rest) : false;
78
- }
79
-
80
- setIn([key, ...rest], value) {
81
- if (rest.length === 0) {
82
- this.set(key, value);
83
- } else {
84
- const node = this.get(key, true);
85
- 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}`);
86
- }
87
- } // overridden in implementations
88
-
89
- /* istanbul ignore next */
90
-
91
-
92
- toJSON() {
93
- return null;
94
- }
95
-
96
- toString(ctx, {
97
- blockItem,
98
- flowChars,
99
- isMap,
100
- itemIndent
101
- }, onComment, onChompKeep) {
102
- const {
103
- doc,
104
- indent
105
- } = ctx;
106
- const inFlow = this.type && this.type.substr(0, 4) === 'FLOW' || ctx.inFlow;
107
- if (inFlow) itemIndent += ' ';
108
- const allNullValues = isMap && this.hasAllNullValues();
109
- ctx = Object.assign({}, ctx, {
110
- allNullValues,
111
- indent: itemIndent,
112
- inFlow,
113
- type: null
114
- });
115
- let chompKeep = false;
116
- let hasItemWithNewLine = false;
117
- const nodes = this.items.reduce((nodes, item, i) => {
118
- let comment;
119
-
120
- if (item) {
121
- if (!chompKeep && item.spaceBefore) nodes.push({
122
- type: 'comment',
123
- str: ''
124
- });
125
- if (item.commentBefore) item.commentBefore.match(/^.*$/gm).forEach(line => {
126
- nodes.push({
127
- type: 'comment',
128
- str: `#${line}`
129
- });
130
- });
131
- if (item.comment) comment = item.comment;
132
- 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;
133
- }
134
-
135
- chompKeep = false;
136
- let str = doc.schema.stringify(item, ctx, () => comment = null, () => chompKeep = true);
137
- if (inFlow && !hasItemWithNewLine && str.includes('\n')) hasItemWithNewLine = true;
138
- if (inFlow && i < this.items.length - 1) str += ',';
139
- str = (0, _addComment.default)(str, itemIndent, comment);
140
- if (chompKeep && (comment || inFlow)) chompKeep = false;
141
- nodes.push({
142
- type: 'item',
143
- str
144
- });
145
- return nodes;
146
- }, []);
147
- let str;
148
-
149
- if (nodes.length === 0) {
150
- str = flowChars.start + flowChars.end;
151
- } else if (inFlow) {
152
- const {
153
- start,
154
- end
155
- } = flowChars;
156
- const strings = nodes.map(n => n.str);
157
-
158
- if (hasItemWithNewLine || strings.reduce((sum, str) => sum + str.length + 2, 2) > Collection.maxFlowStringSingleLineLength) {
159
- str = start;
160
-
161
- for (const s of strings) {
162
- str += s ? `\n ${indent}${s}` : '\n';
163
- }
164
-
165
- str += `\n${indent}${end}`;
166
- } else {
167
- str = `${start} ${strings.join(' ')} ${end}`;
168
- }
169
- } else {
170
- const strings = nodes.map(blockItem);
171
- str = strings.shift();
172
-
173
- for (const s of strings) str += s ? `\n${indent}${s}` : '\n';
174
- }
175
-
176
- if (this.comment) {
177
- str += '\n' + this.comment.replace(/^/gm, `${indent}#`);
178
- if (onComment) onComment();
179
- } else if (chompKeep && onChompKeep) onChompKeep();
180
-
181
- return str;
182
- }
183
-
184
- }
185
-
186
- exports.default = Collection;
187
-
188
- _defineProperty(Collection, "maxFlowStringSingleLineLength", 60);
@@ -1,103 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.findPair = findPair;
7
- exports.default = void 0;
8
-
9
- var _Collection = _interopRequireDefault(require("./Collection"));
10
-
11
- var _Pair = _interopRequireDefault(require("./Pair"));
12
-
13
- var _Scalar = _interopRequireDefault(require("./Scalar"));
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
- function findPair(items, key) {
18
- const k = key instanceof _Scalar.default ? key.value : key;
19
-
20
- for (const it of items) {
21
- if (it instanceof _Pair.default) {
22
- if (it.key === key || it.key === k) return it;
23
- if (it.key && it.key.value === k) return it;
24
- }
25
- }
26
-
27
- return undefined;
28
- }
29
-
30
- class YAMLMap extends _Collection.default {
31
- add(pair, overwrite) {
32
- if (!pair) pair = new _Pair.default(pair);else if (!(pair instanceof _Pair.default)) pair = new _Pair.default(pair.key || pair, pair.value);
33
- const prev = findPair(this.items, pair.key);
34
- const sortEntries = this.schema && this.schema.sortMapEntries;
35
-
36
- if (prev) {
37
- if (overwrite) prev.value = pair.value;else throw new Error(`Key ${pair.key} already set`);
38
- } else if (sortEntries) {
39
- const i = this.items.findIndex(item => sortEntries(pair, item) < 0);
40
- if (i === -1) this.items.push(pair);else this.items.splice(i, 0, pair);
41
- } else {
42
- this.items.push(pair);
43
- }
44
- }
45
-
46
- delete(key) {
47
- const it = findPair(this.items, key);
48
- if (!it) return false;
49
- const del = this.items.splice(this.items.indexOf(it), 1);
50
- return del.length > 0;
51
- }
52
-
53
- get(key, keepScalar) {
54
- const it = findPair(this.items, key);
55
- const node = it && it.value;
56
- return !keepScalar && node instanceof _Scalar.default ? node.value : node;
57
- }
58
-
59
- has(key) {
60
- return !!findPair(this.items, key);
61
- }
62
-
63
- set(key, value) {
64
- this.add(new _Pair.default(key, value), true);
65
- }
66
- /**
67
- * @param {*} arg ignored
68
- * @param {*} ctx Conversion context, originally set in Document#toJSON()
69
- * @param {Class} Type If set, forces the returned collection type
70
- * @returns {*} Instance of Type, Map, or Object
71
- */
72
-
73
-
74
- toJSON(_, ctx, Type) {
75
- const map = Type ? new Type() : ctx && ctx.mapAsMap ? new Map() : {};
76
- if (ctx && ctx.onCreate) ctx.onCreate(map);
77
-
78
- for (const item of this.items) item.addToJSMap(ctx, map);
79
-
80
- return map;
81
- }
82
-
83
- toString(ctx, onComment, onChompKeep) {
84
- if (!ctx) return JSON.stringify(this);
85
-
86
- for (const item of this.items) {
87
- if (!(item instanceof _Pair.default)) throw new Error(`Map items must all be pairs; found ${JSON.stringify(item)} instead`);
88
- }
89
-
90
- return super.toString(ctx, {
91
- blockItem: n => n.str,
92
- flowChars: {
93
- start: '{',
94
- end: '}'
95
- },
96
- isMap: true,
97
- itemIndent: ctx.indent || ''
98
- }, onComment, onChompKeep);
99
- }
100
-
101
- }
102
-
103
- exports.default = YAMLMap;
@@ -1,80 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.MERGE_KEY = void 0;
7
-
8
- var _Map = _interopRequireDefault(require("./Map"));
9
-
10
- var _Pair = _interopRequireDefault(require("./Pair"));
11
-
12
- var _Scalar = _interopRequireDefault(require("./Scalar"));
13
-
14
- var _Seq = _interopRequireDefault(require("./Seq"));
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- const MERGE_KEY = '<<';
19
- exports.MERGE_KEY = MERGE_KEY;
20
-
21
- class Merge extends _Pair.default {
22
- constructor(pair) {
23
- if (pair instanceof _Pair.default) {
24
- let seq = pair.value;
25
-
26
- if (!(seq instanceof _Seq.default)) {
27
- seq = new _Seq.default();
28
- seq.items.push(pair.value);
29
- seq.range = pair.value.range;
30
- }
31
-
32
- super(pair.key, seq);
33
- this.range = pair.range;
34
- } else {
35
- super(new _Scalar.default(MERGE_KEY), new _Seq.default());
36
- }
37
-
38
- this.type = 'MERGE_PAIR';
39
- } // If the value associated with a merge key is a single mapping node, each of
40
- // its key/value pairs is inserted into the current mapping, unless the key
41
- // already exists in it. If the value associated with the merge key is a
42
- // sequence, then this sequence is expected to contain mapping nodes and each
43
- // of these nodes is merged in turn according to its order in the sequence.
44
- // Keys in mapping nodes earlier in the sequence override keys specified in
45
- // later mapping nodes. -- http://yaml.org/type/merge.html
46
-
47
-
48
- addToJSMap(ctx, map) {
49
- for (const {
50
- source
51
- } of this.value.items) {
52
- if (!(source instanceof _Map.default)) throw new Error('Merge sources must be maps');
53
- const srcMap = source.toJSON(null, ctx, Map);
54
-
55
- for (const [key, value] of srcMap) {
56
- if (map instanceof Map) {
57
- if (!map.has(key)) map.set(key, value);
58
- } else if (map instanceof Set) {
59
- map.add(key);
60
- } else {
61
- if (!Object.prototype.hasOwnProperty.call(map, key)) map[key] = value;
62
- }
63
- }
64
- }
65
-
66
- return map;
67
- }
68
-
69
- toString(ctx, onComment) {
70
- const seq = this.value;
71
- if (seq.items.length > 1) return super.toString(ctx, onComment);
72
- this.value = seq.items[0];
73
- const str = super.toString(ctx, onComment);
74
- this.value = seq;
75
- return str;
76
- }
77
-
78
- }
79
-
80
- exports.default = Merge;
@@ -1,10 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- class Node {}
9
-
10
- exports.default = Node;
@@ -1,161 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _addComment = _interopRequireDefault(require("../addComment"));
9
-
10
- var _constants = require("../constants");
11
-
12
- var _toJSON = _interopRequireDefault(require("../toJSON"));
13
-
14
- var _Collection = _interopRequireDefault(require("./Collection"));
15
-
16
- var _Node = _interopRequireDefault(require("./Node"));
17
-
18
- var _Scalar = _interopRequireDefault(require("./Scalar"));
19
-
20
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
-
22
- // Published as 'yaml/pair'
23
- const stringifyKey = (key, jsKey, ctx) => {
24
- if (jsKey === null) return '';
25
- if (typeof jsKey !== 'object') return String(jsKey);
26
- if (key instanceof _Node.default && ctx && ctx.doc) return key.toString({
27
- anchors: {},
28
- doc: ctx.doc,
29
- indent: '',
30
- inFlow: true,
31
- inStringifyKey: true
32
- });
33
- return JSON.stringify(jsKey);
34
- };
35
-
36
- class Pair extends _Node.default {
37
- constructor(key, value = null) {
38
- super();
39
- this.key = key;
40
- this.value = value;
41
- this.type = 'PAIR';
42
- }
43
-
44
- get commentBefore() {
45
- return this.key && this.key.commentBefore;
46
- }
47
-
48
- set commentBefore(cb) {
49
- if (this.key == null) this.key = new _Scalar.default(null);
50
- this.key.commentBefore = cb;
51
- }
52
-
53
- addToJSMap(ctx, map) {
54
- const key = (0, _toJSON.default)(this.key, '', ctx);
55
-
56
- if (map instanceof Map) {
57
- const value = (0, _toJSON.default)(this.value, key, ctx);
58
- map.set(key, value);
59
- } else if (map instanceof Set) {
60
- map.add(key);
61
- } else {
62
- const stringKey = stringifyKey(this.key, key, ctx);
63
- map[stringKey] = (0, _toJSON.default)(this.value, stringKey, ctx);
64
- }
65
-
66
- return map;
67
- }
68
-
69
- toJSON(_, ctx) {
70
- const pair = ctx && ctx.mapAsMap ? new Map() : {};
71
- return this.addToJSMap(ctx, pair);
72
- }
73
-
74
- toString(ctx, onComment, onChompKeep) {
75
- if (!ctx || !ctx.doc) return JSON.stringify(this);
76
- const {
77
- simpleKeys
78
- } = ctx.doc.options;
79
- let {
80
- key,
81
- value
82
- } = this;
83
- let keyComment = key instanceof _Node.default && key.comment;
84
-
85
- if (simpleKeys) {
86
- if (keyComment) {
87
- throw new Error('With simple keys, key nodes cannot have comments');
88
- }
89
-
90
- if (key instanceof _Collection.default) {
91
- const msg = 'With simple keys, collection cannot be used as a key value';
92
- throw new Error(msg);
93
- }
94
- }
95
-
96
- const explicitKey = !simpleKeys && (!key || keyComment || key instanceof _Collection.default || key.type === _constants.Type.BLOCK_FOLDED || key.type === _constants.Type.BLOCK_LITERAL);
97
- const {
98
- doc,
99
- indent
100
- } = ctx;
101
- ctx = Object.assign({}, ctx, {
102
- implicitKey: !explicitKey,
103
- indent: indent + ' '
104
- });
105
- let chompKeep = false;
106
- let str = doc.schema.stringify(key, ctx, () => keyComment = null, () => chompKeep = true);
107
- str = (0, _addComment.default)(str, ctx.indent, keyComment);
108
-
109
- if (ctx.allNullValues && !simpleKeys) {
110
- if (this.comment) {
111
- str = (0, _addComment.default)(str, ctx.indent, this.comment);
112
- if (onComment) onComment();
113
- } else if (chompKeep && !keyComment && onChompKeep) onChompKeep();
114
-
115
- return ctx.inFlow ? str : `? ${str}`;
116
- }
117
-
118
- str = explicitKey ? `? ${str}\n${indent}:` : `${str}:`;
119
-
120
- if (this.comment) {
121
- // expected (but not strictly required) to be a single-line comment
122
- str = (0, _addComment.default)(str, ctx.indent, this.comment);
123
- if (onComment) onComment();
124
- }
125
-
126
- let vcb = '';
127
- let valueComment = null;
128
-
129
- if (value instanceof _Node.default) {
130
- if (value.spaceBefore) vcb = '\n';
131
-
132
- if (value.commentBefore) {
133
- const cs = value.commentBefore.replace(/^/gm, `${ctx.indent}#`);
134
- vcb += `\n${cs}`;
135
- }
136
-
137
- valueComment = value.comment;
138
- } else if (value && typeof value === 'object') {
139
- value = doc.schema.createNode(value, true);
140
- }
141
-
142
- ctx.implicitKey = false;
143
- if (!explicitKey && !this.comment && value instanceof _Scalar.default) ctx.indentAtStart = str.length + 1;
144
- chompKeep = false;
145
- const valueStr = doc.schema.stringify(value, ctx, () => valueComment = null, () => chompKeep = true);
146
- let ws = ' ';
147
-
148
- if (vcb || this.comment) {
149
- ws = `${vcb}\n${ctx.indent}`;
150
- } else if (!explicitKey && value instanceof _Collection.default) {
151
- const flow = valueStr[0] === '[' || valueStr[0] === '{';
152
- if (!flow || valueStr.includes('\n')) ws = `\n${ctx.indent}`;
153
- }
154
-
155
- if (chompKeep && !valueComment && onChompKeep) onChompKeep();
156
- return (0, _addComment.default)(str + ws + valueStr, ctx.indent, valueComment);
157
- }
158
-
159
- }
160
-
161
- exports.default = Pair;
@@ -1,31 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = void 0;
7
-
8
- var _toJSON = _interopRequireDefault(require("../toJSON"));
9
-
10
- var _Node = _interopRequireDefault(require("./Node"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
-
14
- // Published as 'yaml/scalar'
15
- class Scalar extends _Node.default {
16
- constructor(value) {
17
- super();
18
- this.value = value;
19
- }
20
-
21
- toJSON(arg, ctx) {
22
- return ctx && ctx.keep ? this.value : (0, _toJSON.default)(this.value, arg, ctx);
23
- }
24
-
25
- toString() {
26
- return String(this.value);
27
- }
28
-
29
- }
30
-
31
- exports.default = Scalar;