yaml 1.7.1 → 1.8.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 (82) hide show
  1. package/browser/dist/Anchors.js +24 -39
  2. package/browser/dist/Document.js +86 -110
  3. package/browser/dist/addComment.js +2 -11
  4. package/browser/dist/constants.js +3 -11
  5. package/browser/dist/cst/Alias.js +19 -36
  6. package/browser/dist/cst/BlankLine.js +25 -38
  7. package/browser/dist/cst/BlockValue.js +29 -51
  8. package/browser/dist/cst/Collection.js +42 -65
  9. package/browser/dist/cst/CollectionItem.js +33 -55
  10. package/browser/dist/cst/Comment.js +19 -35
  11. package/browser/dist/cst/Directive.js +20 -56
  12. package/browser/dist/cst/Document.js +47 -71
  13. package/browser/dist/cst/FlowCollection.js +38 -61
  14. package/browser/dist/cst/Node.js +26 -46
  15. package/browser/dist/cst/ParseContext.js +100 -140
  16. package/browser/dist/cst/PlainValue.js +21 -38
  17. package/browser/dist/cst/QuoteDouble.js +26 -42
  18. package/browser/dist/cst/QuoteSingle.js +25 -41
  19. package/browser/dist/cst/Range.js +9 -19
  20. package/browser/dist/cst/parse.js +5 -16
  21. package/browser/dist/cst/source-utils.js +3 -14
  22. package/browser/dist/errors.js +42 -78
  23. package/browser/dist/foldFlowLines.js +4 -15
  24. package/browser/dist/index.js +24 -44
  25. package/browser/dist/listTagNames.js +10 -24
  26. package/browser/dist/schema/Alias.js +32 -49
  27. package/browser/dist/schema/Collection.js +54 -65
  28. package/browser/dist/schema/Map.js +39 -49
  29. package/browser/dist/schema/Merge.js +32 -52
  30. package/browser/dist/schema/Node.js +3 -12
  31. package/browser/dist/schema/Pair.js +40 -58
  32. package/browser/dist/schema/Scalar.js +18 -33
  33. package/browser/dist/schema/Seq.js +23 -40
  34. package/browser/dist/schema/index.js +66 -80
  35. package/browser/dist/schema/parseMap.js +52 -72
  36. package/browser/dist/schema/parseSeq.js +30 -45
  37. package/browser/dist/schema/parseUtils.js +12 -25
  38. package/browser/dist/stringify.js +39 -45
  39. package/browser/dist/tags/core.js +30 -37
  40. package/browser/dist/tags/failsafe/index.js +4 -17
  41. package/browser/dist/tags/failsafe/map.js +17 -26
  42. package/browser/dist/tags/failsafe/seq.js +7 -18
  43. package/browser/dist/tags/failsafe/string.js +7 -19
  44. package/browser/dist/tags/index.js +35 -49
  45. package/browser/dist/tags/json.js +11 -38
  46. package/browser/dist/tags/options.js +8 -20
  47. package/browser/dist/tags/yaml-1.1/binary.js +16 -29
  48. package/browser/dist/tags/yaml-1.1/index.js +34 -54
  49. package/browser/dist/tags/yaml-1.1/omap.js +39 -58
  50. package/browser/dist/tags/yaml-1.1/pairs.js +15 -34
  51. package/browser/dist/tags/yaml-1.1/set.js +35 -61
  52. package/browser/dist/tags/yaml-1.1/timestamp.js +6 -16
  53. package/browser/dist/test-events.js +7 -19
  54. package/browser/dist/toJSON.js +1 -8
  55. package/browser/dist/warnings.js +3 -15
  56. package/dist/Document.js +7 -7
  57. package/dist/cst/BlankLine.js +4 -0
  58. package/dist/cst/BlockValue.js +1 -1
  59. package/dist/cst/Directive.js +0 -16
  60. package/dist/cst/Node.js +0 -5
  61. package/dist/cst/ParseContext.js +41 -55
  62. package/dist/schema/Alias.js +1 -0
  63. package/dist/schema/Collection.js +22 -5
  64. package/dist/schema/Map.js +12 -5
  65. package/dist/schema/Merge.js +3 -4
  66. package/dist/schema/Pair.js +1 -0
  67. package/dist/schema/index.js +11 -5
  68. package/dist/schema/parseMap.js +3 -1
  69. package/dist/schema/parseUtils.js +5 -6
  70. package/dist/stringify.js +17 -8
  71. package/dist/tags/core.js +27 -10
  72. package/dist/tags/failsafe/map.js +5 -1
  73. package/dist/tags/failsafe/seq.js +1 -1
  74. package/dist/tags/index.js +13 -1
  75. package/dist/tags/json.js +2 -9
  76. package/dist/tags/yaml-1.1/index.js +6 -6
  77. package/dist/tags/yaml-1.1/omap.js +3 -5
  78. package/dist/tags/yaml-1.1/pairs.js +1 -1
  79. package/dist/tags/yaml-1.1/set.js +3 -1
  80. package/package.json +40 -16
  81. package/types.mjs +20 -0
  82. package/util.mjs +24 -0
@@ -33,6 +33,41 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
33
33
 
34
34
  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; }
35
35
 
36
+ function createNewNode(type, props) {
37
+ switch (type) {
38
+ case _constants.Type.ALIAS:
39
+ return new _Alias.default(type, props);
40
+
41
+ case _constants.Type.BLOCK_FOLDED:
42
+ case _constants.Type.BLOCK_LITERAL:
43
+ return new _BlockValue.default(type, props);
44
+
45
+ case _constants.Type.FLOW_MAP:
46
+ case _constants.Type.FLOW_SEQ:
47
+ return new _FlowCollection.default(type, props);
48
+
49
+ case _constants.Type.MAP_KEY:
50
+ case _constants.Type.MAP_VALUE:
51
+ case _constants.Type.SEQ_ITEM:
52
+ return new _CollectionItem.default(type, props);
53
+
54
+ case _constants.Type.COMMENT:
55
+ case _constants.Type.PLAIN:
56
+ return new _PlainValue.default(type, props);
57
+
58
+ case _constants.Type.QUOTE_DOUBLE:
59
+ return new _QuoteDouble.default(type, props);
60
+
61
+ case _constants.Type.QUOTE_SINGLE:
62
+ return new _QuoteSingle.default(type, props);
63
+
64
+ /* istanbul ignore next */
65
+
66
+ default:
67
+ return null;
68
+ // should never happen
69
+ }
70
+ }
36
71
  /**
37
72
  * @param {boolean} atLineStart - Node starts at beginning of line
38
73
  * @param {boolean} inFlow - true if currently in a flow context
@@ -42,6 +77,8 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
42
77
  * @param {Node} parent - The parent of the node
43
78
  * @param {string} src - Source of the YAML document
44
79
  */
80
+
81
+
45
82
  class ParseContext {
46
83
  static parseType(src, offset, inFlow) {
47
84
  switch (src[offset]) {
@@ -96,52 +133,14 @@ class ParseContext {
96
133
  type,
97
134
  valueStart
98
135
  } = context.parseProps(start);
99
- let node;
100
-
101
- switch (type) {
102
- case _constants.Type.ALIAS:
103
- node = new _Alias.default(type, props);
104
- break;
105
-
106
- case _constants.Type.BLOCK_FOLDED:
107
- case _constants.Type.BLOCK_LITERAL:
108
- node = new _BlockValue.default(type, props);
109
- break;
110
-
111
- case _constants.Type.FLOW_MAP:
112
- case _constants.Type.FLOW_SEQ:
113
- node = new _FlowCollection.default(type, props);
114
- break;
115
-
116
- case _constants.Type.MAP_KEY:
117
- case _constants.Type.MAP_VALUE:
118
- case _constants.Type.SEQ_ITEM:
119
- node = new _CollectionItem.default(type, props);
120
- break;
121
-
122
- case _constants.Type.COMMENT:
123
- case _constants.Type.PLAIN:
124
- node = new _PlainValue.default(type, props);
125
- break;
126
-
127
- case _constants.Type.QUOTE_DOUBLE:
128
- node = new _QuoteDouble.default(type, props);
129
- break;
130
-
131
- case _constants.Type.QUOTE_SINGLE:
132
- node = new _QuoteSingle.default(type, props);
133
- break;
134
-
135
- default:
136
- node.error = new _errors.YAMLSyntaxError(node, `Unknown node type: ${JSON.stringify(type)}`);
137
- node.range = new _Range.default(start, start + 1);
138
- return node;
139
- }
140
-
136
+ const node = createNewNode(type, props);
141
137
  let offset = node.parse(context, valueStart);
142
138
  node.range = new _Range.default(start, offset);
139
+ /* istanbul ignore if */
143
140
 
144
141
  if (offset <= start) {
142
+ // This should never happen, but if it does, let's make sure to at least
143
+ // step one character forward to avoid a busy loop.
145
144
  node.error = new Error(`Node#parse consumed no characters`);
146
145
  node.error.parseEnd = offset;
147
146
  node.error.source = node;
@@ -170,19 +169,6 @@ class ParseContext {
170
169
  this.parent = parent != null ? parent : orig.parent || {};
171
170
  this.root = orig.root;
172
171
  this.src = orig.src;
173
- } // for logging
174
-
175
-
176
- get pretty() {
177
- const obj = {
178
- start: `${this.lineStart} + ${this.indent}`,
179
- in: [],
180
- parent: this.parent.type
181
- };
182
- if (!this.atLineStart) obj.start += ' + N';
183
- if (this.inCollection) obj.in.push('collection');
184
- if (this.inFlow) obj.in.push('flow');
185
- return obj;
186
172
  }
187
173
 
188
174
  nodeStartsCollection(node) {
@@ -77,6 +77,7 @@ class Alias extends _Node.default {
77
77
  maxAliasCount
78
78
  } = ctx;
79
79
  const anchor = anchors.find(a => a.node === this.source);
80
+ /* istanbul ignore if */
80
81
 
81
82
  if (!anchor || anchor.res === undefined) {
82
83
  const msg = 'This should not happen: Alias anchor was not resolved?';
@@ -17,23 +17,38 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
17
17
 
18
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
19
 
20
- // null, undefined, or an empty non-string iterable (e.g. [])
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
+
21
34
  const isEmptyPath = path => path == null || typeof path === 'object' && path[Symbol.iterator]().next().done;
22
35
 
23
36
  exports.isEmptyPath = isEmptyPath;
24
37
 
25
38
  class Collection extends _Node.default {
26
- constructor(...args) {
27
- super(...args);
39
+ constructor(schema) {
40
+ super();
28
41
 
29
42
  _defineProperty(this, "items", []);
43
+
44
+ this.schema = schema;
30
45
  }
31
46
 
32
47
  addIn(path, value) {
33
48
  if (isEmptyPath(path)) this.add(value);else {
34
49
  const [key, ...rest] = path;
35
50
  const node = this.get(key, true);
36
- if (node instanceof Collection) node.addIn(rest, value);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
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}`);
37
52
  }
38
53
  }
39
54
 
@@ -67,10 +82,12 @@ class Collection extends _Node.default {
67
82
  this.set(key, value);
68
83
  } else {
69
84
  const node = this.get(key, true);
70
- if (node instanceof Collection) node.setIn(rest, value);else throw new Error(`Expected YAML collection at ${key}. Remaining path: ${rest}`);
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}`);
71
86
  }
72
87
  } // overridden in implementations
73
88
 
89
+ /* istanbul ignore next */
90
+
74
91
 
75
92
  toJSON() {
76
93
  return null;
@@ -28,11 +28,19 @@ function findPair(items, key) {
28
28
  }
29
29
 
30
30
  class YAMLMap extends _Collection.default {
31
- add(pair) {
31
+ add(pair, overwrite) {
32
32
  if (!pair) pair = new _Pair.default(pair);else if (!(pair instanceof _Pair.default)) pair = new _Pair.default(pair.key || pair, pair.value);
33
33
  const prev = findPair(this.items, pair.key);
34
- if (prev) throw new Error(`Key ${pair.key} already set`);
35
- this.items.push(pair);
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
+ }
36
44
  }
37
45
 
38
46
  delete(key) {
@@ -53,8 +61,7 @@ class YAMLMap extends _Collection.default {
53
61
  }
54
62
 
55
63
  set(key, value) {
56
- const prev = findPair(this.items, key);
57
- if (prev) prev.value = value;else this.items.push(new _Pair.default(key, value));
64
+ this.add(new _Pair.default(key, value), true);
58
65
  }
59
66
  /**
60
67
  * @param {*} arg ignored
@@ -46,10 +46,9 @@ class Merge extends _Pair.default {
46
46
 
47
47
 
48
48
  addToJSMap(ctx, map) {
49
- for (const _ref of this.value.items) {
50
- const {
51
- source
52
- } = _ref;
49
+ for (const {
50
+ source
51
+ } of this.value.items) {
53
52
  if (!(source instanceof _Map.default)) throw new Error('Merge sources must be maps');
54
53
  const srcMap = source.toJSON(null, ctx, Map);
55
54
 
@@ -140,6 +140,7 @@ class Pair extends _Node.default {
140
140
  }
141
141
 
142
142
  ctx.implicitKey = false;
143
+ if (!explicitKey && !this.comment && value instanceof _Scalar.default) ctx.indentAtStart = str.length + 1;
143
144
  chompKeep = false;
144
145
  const valueStr = doc.schema.stringify(value, ctx, () => valueComment = null, () => chompKeep = true);
145
146
  let ws = ' ';
@@ -44,10 +44,12 @@ class Schema {
44
44
  customTags,
45
45
  merge,
46
46
  schema,
47
+ sortMapEntries,
47
48
  tags: deprecatedCustomTags
48
49
  }) {
49
50
  this.merge = !!merge;
50
51
  this.name = schema;
52
+ this.sortMapEntries = sortMapEntries === true ? (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0 : sortMapEntries || null;
51
53
  this.tags = _tags.schemas[schema.replace(/\W/g, '')]; // 'yaml-1.1' -> 'yaml11'
52
54
 
53
55
  if (!this.tags) {
@@ -83,6 +85,7 @@ class Schema {
83
85
  }
84
86
 
85
87
  createNode(value, wrapScalars, tag, ctx) {
88
+ if (value instanceof _Node.default) return value;
86
89
  let tagObj;
87
90
 
88
91
  if (tag) {
@@ -113,7 +116,7 @@ class Schema {
113
116
  const obj = {};
114
117
 
115
118
  if (value && typeof value === 'object' && ctx.prevObjects) {
116
- const prev = ctx.prevObjects.find(o => o.value === value);
119
+ const prev = ctx.prevObjects.get(value);
117
120
 
118
121
  if (prev) {
119
122
  const alias = new _Alias.default(prev); // leaves source dirty; must be cleaned by caller
@@ -123,10 +126,11 @@ class Schema {
123
126
  }
124
127
 
125
128
  obj.value = value;
126
- ctx.prevObjects.push(obj);
129
+ ctx.prevObjects.set(value, obj);
127
130
  }
128
131
 
129
132
  obj.node = tagObj.createNode ? tagObj.createNode(this, value, ctx) : wrapScalars ? new _Scalar.default(value) : value;
133
+ if (tag && obj.node instanceof _Node.default) obj.node.tag = tag;
130
134
  return obj.node;
131
135
  }
132
136
 
@@ -186,6 +190,7 @@ class Schema {
186
190
  }
187
191
  }
188
192
  } catch (error) {
193
+ /* istanbul ignore if */
189
194
  if (!error.source) error.source = node;
190
195
  doc.errors.push(error);
191
196
  node.resolved = null;
@@ -200,6 +205,7 @@ class Schema {
200
205
  const res = this.resolveNode(doc, node, tagName);
201
206
  if (Object.prototype.hasOwnProperty.call(node, 'resolved')) return res;
202
207
  const fallback = isMap(node) ? Schema.defaultTags.MAP : isSeq(node) ? Schema.defaultTags.SEQ : Schema.defaultTags.STR;
208
+ /* istanbul ignore else */
203
209
 
204
210
  if (fallback) {
205
211
  doc.warnings.push(new _errors.YAMLWarning(node, `The tag ${tagName} is unavailable, falling back to ${fallback}`));
@@ -208,9 +214,8 @@ class Schema {
208
214
  return res;
209
215
  } else {
210
216
  doc.errors.push(new _errors.YAMLReferenceError(node, `The tag ${tagName} is unavailable`));
217
+ return null;
211
218
  }
212
-
213
- return null;
214
219
  }
215
220
 
216
221
  getTagObject(item) {
@@ -270,7 +275,7 @@ class Schema {
270
275
  const createCtx = {
271
276
  aliasNodes: [],
272
277
  onTagObj: o => tagObj = o,
273
- prevObjects: []
278
+ prevObjects: new Map()
274
279
  };
275
280
  item = this.createNode(item, true, null, createCtx);
276
281
  const {
@@ -292,6 +297,7 @@ class Schema {
292
297
  if (item instanceof _Pair.default) return item.toString(ctx, onComment, onChompKeep);
293
298
  if (!tagObj) tagObj = this.getTagObject(item);
294
299
  const props = this.stringifyProps(item, tagObj, ctx);
300
+ if (props.length > 0) ctx.indentAtStart = (ctx.indentAtStart || 0) + props.length + 1;
295
301
  const str = typeof tagObj.stringify === 'function' ? tagObj.stringify(item, ctx, onComment, onChompKeep) : item instanceof _Collection.default ? item.toString(ctx, onComment, onChompKeep) : (0, _stringify.stringifyString)(item, ctx, onComment, onChompKeep);
296
302
  return props ? item instanceof _Collection.default && str[0] !== '{' && str[0] !== '[' ? `${props}\n${ctx.indent}${str}` : `${props} ${str}` : str;
297
303
  }
@@ -23,7 +23,9 @@ var _Alias = _interopRequireDefault(require("./Alias"));
23
23
 
24
24
  var _Collection = _interopRequireDefault(require("./Collection"));
25
25
 
26
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
26
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
27
+
28
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
29
 
28
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
29
31
 
@@ -80,12 +80,11 @@ function checkKeyLength(errors, node, itemIdx, key, keyStart) {
80
80
  }
81
81
 
82
82
  function resolveComments(collection, comments) {
83
- for (const _ref of comments) {
84
- const {
85
- afterKey,
86
- before,
87
- comment
88
- } = _ref;
83
+ for (const {
84
+ afterKey,
85
+ before,
86
+ comment
87
+ } of comments) {
89
88
  let item = collection.items[before];
90
89
 
91
90
  if (!item) {
package/dist/stringify.js CHANGED
@@ -14,7 +14,15 @@ var _foldFlowLines = _interopRequireWildcard(require("./foldFlowLines"));
14
14
 
15
15
  var _options = require("./tags/options");
16
16
 
17
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
17
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
18
+
19
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
20
+
21
+ const getFoldOptions = ({
22
+ indentAtStart
23
+ }) => indentAtStart ? Object.assign({
24
+ indentAtStart
25
+ }, _options.strOptions.fold) : _options.strOptions.fold;
18
26
 
19
27
  function stringifyNumber({
20
28
  format,
@@ -56,10 +64,11 @@ function lineLengthOverLimit(str, limit) {
56
64
  return true;
57
65
  }
58
66
 
59
- function doubleQuotedString(value, {
60
- implicitKey,
61
- indent
62
- }) {
67
+ function doubleQuotedString(value, ctx) {
68
+ const {
69
+ implicitKey,
70
+ indent
71
+ } = ctx;
63
72
  const {
64
73
  jsonEncoding,
65
74
  minMultiLineLength
@@ -153,7 +162,7 @@ function doubleQuotedString(value, {
153
162
  }
154
163
 
155
164
  str = start ? str + json.slice(start) : json;
156
- return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, _options.strOptions.fold);
165
+ return implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_QUOTED, getFoldOptions(ctx));
157
166
  }
158
167
 
159
168
  function singleQuotedString(value, ctx) {
@@ -170,7 +179,7 @@ function singleQuotedString(value, ctx) {
170
179
  }
171
180
 
172
181
  const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
173
- return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold);
182
+ return implicitKey ? res : (0, _foldFlowLines.default)(res, indent, _foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
174
183
  }
175
184
 
176
185
  function blockString({
@@ -280,7 +289,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
280
289
  return doubleQuotedString(value, ctx);
281
290
  }
282
291
 
283
- const body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, _options.strOptions.fold);
292
+ const body = implicitKey ? str : (0, _foldFlowLines.default)(str, indent, _foldFlowLines.FOLD_FLOW, getFoldOptions(ctx));
284
293
 
285
294
  if (comment && !inFlow && (body.indexOf('\n') !== -1 || comment.indexOf('\n') !== -1)) {
286
295
  if (onComment) onComment();
package/dist/tags/core.js CHANGED
@@ -3,7 +3,7 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.default = void 0;
6
+ exports.default = exports.floatObj = exports.expObj = exports.nanObj = exports.hexObj = exports.intObj = exports.octObj = exports.boolObj = exports.nullObj = void 0;
7
7
 
8
8
  var _Scalar = _interopRequireDefault(require("../schema/Scalar"));
9
9
 
@@ -15,7 +15,7 @@ var _options = require("./options");
15
15
 
16
16
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
17
 
18
- var _default = _failsafe.default.concat([{
18
+ const nullObj = {
19
19
  identify: value => value == null,
20
20
  createNode: (schema, value, ctx) => ctx.wrapScalars ? new _Scalar.default(null) : null,
21
21
  default: true,
@@ -24,7 +24,9 @@ var _default = _failsafe.default.concat([{
24
24
  resolve: () => null,
25
25
  options: _options.nullOptions,
26
26
  stringify: () => _options.nullOptions.nullStr
27
- }, {
27
+ };
28
+ exports.nullObj = nullObj;
29
+ const boolObj = {
28
30
  identify: value => typeof value === 'boolean',
29
31
  default: true,
30
32
  tag: 'tag:yaml.org,2002:bool',
@@ -34,7 +36,9 @@ var _default = _failsafe.default.concat([{
34
36
  stringify: ({
35
37
  value
36
38
  }) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr
37
- }, {
39
+ };
40
+ exports.boolObj = boolObj;
41
+ const octObj = {
38
42
  identify: value => typeof value === 'number',
39
43
  default: true,
40
44
  tag: 'tag:yaml.org,2002:int',
@@ -44,14 +48,18 @@ var _default = _failsafe.default.concat([{
44
48
  stringify: ({
45
49
  value
46
50
  }) => '0o' + value.toString(8)
47
- }, {
51
+ };
52
+ exports.octObj = octObj;
53
+ const intObj = {
48
54
  identify: value => typeof value === 'number',
49
55
  default: true,
50
56
  tag: 'tag:yaml.org,2002:int',
51
57
  test: /^[-+]?[0-9]+$/,
52
58
  resolve: str => parseInt(str, 10),
53
59
  stringify: _stringify.stringifyNumber
54
- }, {
60
+ };
61
+ exports.intObj = intObj;
62
+ const hexObj = {
55
63
  identify: value => typeof value === 'number',
56
64
  default: true,
57
65
  tag: 'tag:yaml.org,2002:int',
@@ -61,14 +69,18 @@ var _default = _failsafe.default.concat([{
61
69
  stringify: ({
62
70
  value
63
71
  }) => '0x' + value.toString(16)
64
- }, {
72
+ };
73
+ exports.hexObj = hexObj;
74
+ const nanObj = {
65
75
  identify: value => typeof value === 'number',
66
76
  default: true,
67
77
  tag: 'tag:yaml.org,2002:float',
68
78
  test: /^(?:[-+]?\.inf|(\.nan))$/i,
69
79
  resolve: (str, nan) => nan ? NaN : str[0] === '-' ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
70
80
  stringify: _stringify.stringifyNumber
71
- }, {
81
+ };
82
+ exports.nanObj = nanObj;
83
+ const expObj = {
72
84
  identify: value => typeof value === 'number',
73
85
  default: true,
74
86
  tag: 'tag:yaml.org,2002:float',
@@ -78,7 +90,9 @@ var _default = _failsafe.default.concat([{
78
90
  stringify: ({
79
91
  value
80
92
  }) => Number(value).toExponential()
81
- }, {
93
+ };
94
+ exports.expObj = expObj;
95
+ const floatObj = {
82
96
  identify: value => typeof value === 'number',
83
97
  default: true,
84
98
  tag: 'tag:yaml.org,2002:float',
@@ -91,6 +105,9 @@ var _default = _failsafe.default.concat([{
91
105
  },
92
106
 
93
107
  stringify: _stringify.stringifyNumber
94
- }]);
108
+ };
109
+ exports.floatObj = floatObj;
110
+
111
+ var _default = _failsafe.default.concat([nullObj, boolObj, octObj, intObj, hexObj, nanObj, expObj, floatObj]);
95
112
 
96
113
  exports.default = _default;
@@ -12,7 +12,7 @@ var _parseMap = _interopRequireDefault(require("../../schema/parseMap"));
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
14
  function createMap(schema, obj, ctx) {
15
- const map = new _Map.default();
15
+ const map = new _Map.default(schema);
16
16
 
17
17
  if (obj instanceof Map) {
18
18
  for (const [key, value] of obj) map.items.push(schema.createPair(key, value, ctx));
@@ -20,6 +20,10 @@ function createMap(schema, obj, ctx) {
20
20
  for (const key of Object.keys(obj)) map.items.push(schema.createPair(key, obj[key], ctx));
21
21
  }
22
22
 
23
+ if (typeof schema.sortMapEntries === 'function') {
24
+ map.items.sort(schema.sortMapEntries);
25
+ }
26
+
23
27
  return map;
24
28
  }
25
29
 
@@ -12,7 +12,7 @@ var _Seq = _interopRequireDefault(require("../../schema/Seq"));
12
12
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
13
13
 
14
14
  function createSeq(schema, obj, ctx) {
15
- const seq = new _Seq.default();
15
+ const seq = new _Seq.default(schema);
16
16
 
17
17
  if (obj && obj[Symbol.iterator]) {
18
18
  for (const it of obj) {
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.tags = exports.schemas = void 0;
7
7
 
8
- var _core = _interopRequireDefault(require("./core"));
8
+ var _core = _interopRequireWildcard(require("./core"));
9
9
 
10
10
  var _failsafe = _interopRequireDefault(require("./failsafe"));
11
11
 
@@ -29,6 +29,10 @@ var _timestamp = require("./yaml-1.1/timestamp");
29
29
 
30
30
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
31
 
32
+ function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
33
+
34
+ function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
35
+
32
36
  const schemas = {
33
37
  core: _core.default,
34
38
  failsafe: _failsafe.default,
@@ -38,9 +42,17 @@ const schemas = {
38
42
  exports.schemas = schemas;
39
43
  const tags = {
40
44
  binary: _binary.default,
45
+ bool: _core.boolObj,
46
+ float: _core.floatObj,
47
+ floatExp: _core.expObj,
48
+ floatNaN: _core.nanObj,
41
49
  floatTime: _timestamp.floatTime,
50
+ int: _core.intObj,
51
+ intHex: _core.hexObj,
52
+ intOct: _core.octObj,
42
53
  intTime: _timestamp.intTime,
43
54
  map: _map.default,
55
+ null: _core.nullObj,
44
56
  omap: _omap.default,
45
57
  pairs: _pairs.default,
46
58
  seq: _seq.default,
package/dist/tags/json.js CHANGED
@@ -33,15 +33,8 @@ const schema = [_map.default, _seq.default, {
33
33
  identify: value => typeof value === 'boolean',
34
34
  default: true,
35
35
  tag: 'tag:yaml.org,2002:bool',
36
- test: /^true$/,
37
- resolve: () => true,
38
- stringify: value => JSON.stringify(value)
39
- }, {
40
- identify: value => typeof value === 'boolean',
41
- default: true,
42
- tag: 'tag:yaml.org,2002:bool',
43
- test: /^false$/,
44
- resolve: () => false,
36
+ test: /^true|false$/,
37
+ resolve: str => str === 'true',
45
38
  stringify: value => JSON.stringify(value)
46
39
  }, {
47
40
  identify: value => typeof value === 'number',
@@ -25,6 +25,10 @@ var _timestamp = require("./timestamp");
25
25
 
26
26
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
27
27
 
28
+ const boolStringify = ({
29
+ value
30
+ }) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr;
31
+
28
32
  var _default = _failsafe.default.concat([{
29
33
  identify: value => value == null,
30
34
  createNode: (schema, value, ctx) => ctx.wrapScalars ? new _Scalar.default(null) : null,
@@ -41,9 +45,7 @@ var _default = _failsafe.default.concat([{
41
45
  test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
42
46
  resolve: () => true,
43
47
  options: _options.boolOptions,
44
- stringify: ({
45
- value
46
- }) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr
48
+ stringify: boolStringify
47
49
  }, {
48
50
  identify: value => typeof value === 'boolean',
49
51
  default: true,
@@ -51,9 +53,7 @@ var _default = _failsafe.default.concat([{
51
53
  test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/i,
52
54
  resolve: () => false,
53
55
  options: _options.boolOptions,
54
- stringify: ({
55
- value
56
- }) => value ? _options.boolOptions.trueStr : _options.boolOptions.falseStr
56
+ stringify: boolStringify
57
57
  }, {
58
58
  identify: value => typeof value === 'number',
59
59
  default: true,
@@ -71,11 +71,9 @@ function parseOMap(doc, cst) {
71
71
  const pairs = (0, _pairs.parsePairs)(doc, cst);
72
72
  const seenKeys = [];
73
73
 
74
- for (const _ref of pairs.items) {
75
- const {
76
- key
77
- } = _ref;
78
-
74
+ for (const {
75
+ key
76
+ } of pairs.items) {
79
77
  if (key instanceof _Scalar.default) {
80
78
  if (seenKeys.includes(key.value)) {
81
79
  const msg = 'Ordered maps must not include duplicate keys';