yaml 2.3.0-0 → 2.3.0-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 (93) hide show
  1. package/browser/dist/compose/compose-collection.js +1 -1
  2. package/browser/dist/compose/compose-scalar.js +1 -1
  3. package/browser/dist/compose/composer.js +1 -1
  4. package/browser/dist/compose/resolve-flow-collection.js +1 -1
  5. package/browser/dist/compose/util-map-includes.js +1 -1
  6. package/browser/dist/doc/Document.js +2 -4
  7. package/browser/dist/doc/anchors.js +1 -1
  8. package/browser/dist/doc/createNode.js +1 -1
  9. package/browser/dist/doc/directives.js +1 -1
  10. package/browser/dist/index.js +1 -1
  11. package/browser/dist/nodes/Alias.js +9 -2
  12. package/browser/dist/nodes/Collection.js +2 -1
  13. package/browser/dist/nodes/Node.js +25 -35
  14. package/browser/dist/nodes/Pair.js +1 -1
  15. package/browser/dist/nodes/Scalar.js +2 -1
  16. package/browser/dist/nodes/YAMLMap.js +1 -1
  17. package/browser/dist/nodes/YAMLSeq.js +1 -1
  18. package/browser/dist/nodes/addPairToJSMap.js +1 -1
  19. package/browser/dist/nodes/identity.js +36 -0
  20. package/browser/dist/nodes/toJS.js +1 -1
  21. package/browser/dist/schema/Schema.js +1 -1
  22. package/browser/dist/schema/common/map.js +1 -1
  23. package/browser/dist/schema/common/seq.js +1 -1
  24. package/browser/dist/schema/yaml-1.1/omap.js +2 -2
  25. package/browser/dist/schema/yaml-1.1/pairs.js +1 -1
  26. package/browser/dist/schema/yaml-1.1/set.js +1 -1
  27. package/browser/dist/stringify/stringify.js +1 -1
  28. package/browser/dist/stringify/stringifyCollection.js +1 -1
  29. package/browser/dist/stringify/stringifyDocument.js +1 -1
  30. package/browser/dist/stringify/stringifyPair.js +1 -1
  31. package/browser/dist/stringify/stringifyString.js +6 -6
  32. package/browser/dist/util.js +2 -0
  33. package/browser/dist/visit.js +1 -1
  34. package/dist/compose/compose-collection.d.ts +1 -1
  35. package/dist/compose/compose-collection.js +3 -3
  36. package/dist/compose/compose-scalar.js +7 -7
  37. package/dist/compose/composer.d.ts +1 -1
  38. package/dist/compose/composer.js +3 -3
  39. package/dist/compose/resolve-flow-collection.d.ts +1 -1
  40. package/dist/compose/resolve-flow-collection.js +2 -2
  41. package/dist/compose/util-map-includes.d.ts +3 -3
  42. package/dist/compose/util-map-includes.js +3 -3
  43. package/dist/doc/Document.d.ts +2 -1
  44. package/dist/doc/Document.js +12 -14
  45. package/dist/doc/anchors.d.ts +2 -2
  46. package/dist/doc/anchors.js +2 -2
  47. package/dist/doc/createNode.d.ts +1 -1
  48. package/dist/doc/createNode.js +8 -8
  49. package/dist/doc/directives.js +3 -3
  50. package/dist/index.d.ts +2 -1
  51. package/dist/index.js +9 -9
  52. package/dist/nodes/Alias.d.ts +1 -1
  53. package/dist/nodes/Alias.js +12 -5
  54. package/dist/nodes/Collection.d.ts +3 -2
  55. package/dist/nodes/Collection.js +10 -9
  56. package/dist/nodes/Node.d.ts +4 -17
  57. package/dist/nodes/Node.js +25 -51
  58. package/dist/nodes/Pair.d.ts +2 -2
  59. package/dist/nodes/Pair.js +4 -4
  60. package/dist/nodes/Scalar.js +2 -1
  61. package/dist/nodes/YAMLMap.d.ts +1 -1
  62. package/dist/nodes/YAMLMap.js +9 -9
  63. package/dist/nodes/YAMLSeq.d.ts +1 -1
  64. package/dist/nodes/YAMLSeq.js +5 -5
  65. package/dist/nodes/addPairToJSMap.js +7 -7
  66. package/dist/nodes/identity.d.ts +23 -0
  67. package/dist/nodes/identity.js +53 -0
  68. package/dist/nodes/toJS.d.ts +1 -4
  69. package/dist/nodes/toJS.js +2 -2
  70. package/dist/schema/Schema.d.ts +1 -1
  71. package/dist/schema/Schema.js +4 -4
  72. package/dist/schema/common/map.js +2 -2
  73. package/dist/schema/common/seq.js +2 -2
  74. package/dist/schema/core/schema.d.ts +1 -1
  75. package/dist/schema/json/schema.d.ts +1 -1
  76. package/dist/schema/tags.d.ts +1 -1
  77. package/dist/schema/yaml-1.1/omap.d.ts +1 -1
  78. package/dist/schema/yaml-1.1/omap.js +4 -4
  79. package/dist/schema/yaml-1.1/pairs.d.ts +1 -1
  80. package/dist/schema/yaml-1.1/pairs.js +5 -5
  81. package/dist/schema/yaml-1.1/schema.d.ts +1 -1
  82. package/dist/schema/yaml-1.1/set.js +5 -5
  83. package/dist/stringify/stringify.js +8 -8
  84. package/dist/stringify/stringifyCollection.js +8 -8
  85. package/dist/stringify/stringifyDocument.d.ts +3 -3
  86. package/dist/stringify/stringifyDocument.js +2 -2
  87. package/dist/stringify/stringifyPair.js +9 -9
  88. package/dist/stringify/stringifyString.js +6 -6
  89. package/dist/test-events.js +8 -8
  90. package/dist/util.d.ts +2 -0
  91. package/dist/util.js +4 -0
  92. package/dist/visit.js +18 -18
  93. package/package.json +7 -4
@@ -1,4 +1,4 @@
1
- import { isNode, isMap } from '../nodes/Node.js';
1
+ import { isNode, isMap } from '../nodes/identity.js';
2
2
  import { Scalar } from '../nodes/Scalar.js';
3
3
  import { resolveBlockMap } from './resolve-block-map.js';
4
4
  import { resolveBlockSeq } from './resolve-block-seq.js';
@@ -1,4 +1,4 @@
1
- import { SCALAR, isScalar } from '../nodes/Node.js';
1
+ import { SCALAR, isScalar } from '../nodes/identity.js';
2
2
  import { Scalar } from '../nodes/Scalar.js';
3
3
  import { resolveBlockScalar } from './resolve-block-scalar.js';
4
4
  import { resolveFlowScalar } from './resolve-flow-scalar.js';
@@ -1,7 +1,7 @@
1
1
  import { Directives } from '../doc/directives.js';
2
2
  import { Document } from '../doc/Document.js';
3
3
  import { YAMLWarning, YAMLParseError } from '../errors.js';
4
- import { isCollection, isPair } from '../nodes/Node.js';
4
+ import { isCollection, isPair } from '../nodes/identity.js';
5
5
  import { composeDoc } from './compose-doc.js';
6
6
  import { resolveEnd } from './resolve-end.js';
7
7
 
@@ -1,4 +1,4 @@
1
- import { isPair } from '../nodes/Node.js';
1
+ import { isPair } from '../nodes/identity.js';
2
2
  import { Pair } from '../nodes/Pair.js';
3
3
  import { YAMLMap } from '../nodes/YAMLMap.js';
4
4
  import { YAMLSeq } from '../nodes/YAMLSeq.js';
@@ -1,4 +1,4 @@
1
- import { isScalar } from '../nodes/Node.js';
1
+ import { isScalar } from '../nodes/identity.js';
2
2
 
3
3
  function mapIncludes(ctx, items, search) {
4
4
  const { uniqueKeys } = ctx.options;
@@ -1,10 +1,9 @@
1
1
  import { Alias } from '../nodes/Alias.js';
2
2
  import { isEmptyPath, collectionFromPath } from '../nodes/Collection.js';
3
- import { NODE_TYPE, DOC, isNode, isCollection, isScalar } from '../nodes/Node.js';
3
+ import { NODE_TYPE, DOC, isNode, isCollection, isScalar } from '../nodes/identity.js';
4
4
  import { Pair } from '../nodes/Pair.js';
5
5
  import { toJS } from '../nodes/toJS.js';
6
6
  import { Schema } from '../schema/Schema.js';
7
- import { stringify } from '../stringify/stringify.js';
8
7
  import { stringifyDocument } from '../stringify/stringifyDocument.js';
9
8
  import { anchorNames, findNewAnchor, createNodeAnchors } from './anchors.js';
10
9
  import { applyReviver } from './applyReviver.js';
@@ -295,8 +294,7 @@ class Document {
295
294
  keep: !json,
296
295
  mapAsMap: mapAsMap === true,
297
296
  mapKeyWarned: false,
298
- maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100,
299
- stringify
297
+ maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100
300
298
  };
301
299
  const res = toJS(this.contents, jsonArg ?? '', ctx);
302
300
  if (typeof onAnchor === 'function')
@@ -1,4 +1,4 @@
1
- import { isScalar, isCollection } from '../nodes/Node.js';
1
+ import { isScalar, isCollection } from '../nodes/identity.js';
2
2
  import { visit } from '../visit.js';
3
3
 
4
4
  /**
@@ -1,5 +1,5 @@
1
1
  import { Alias } from '../nodes/Alias.js';
2
- import { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/Node.js';
2
+ import { isNode, isPair, MAP, SEQ, isDocument } from '../nodes/identity.js';
3
3
  import { Scalar } from '../nodes/Scalar.js';
4
4
 
5
5
  const defaultTagPrefix = 'tag:yaml.org,2002:';
@@ -1,4 +1,4 @@
1
- import { isNode } from '../nodes/Node.js';
1
+ import { isNode } from '../nodes/identity.js';
2
2
  import { visit } from '../visit.js';
3
3
 
4
4
  const escapeChars = {
@@ -3,7 +3,7 @@ export { Document } from './doc/Document.js';
3
3
  export { Schema } from './schema/Schema.js';
4
4
  export { YAMLError, YAMLParseError, YAMLWarning } from './errors.js';
5
5
  export { Alias } from './nodes/Alias.js';
6
- export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/Node.js';
6
+ export { isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq } from './nodes/identity.js';
7
7
  export { Pair } from './nodes/Pair.js';
8
8
  export { Scalar } from './nodes/Scalar.js';
9
9
  export { YAMLMap } from './nodes/YAMLMap.js';
@@ -1,6 +1,8 @@
1
1
  import { anchorIsValid } from '../doc/anchors.js';
2
2
  import { visit } from '../visit.js';
3
- import { NodeBase, ALIAS, isAlias, isCollection, isPair } from './Node.js';
3
+ import { ALIAS, isAlias, isCollection, isPair } from './identity.js';
4
+ import { NodeBase } from './Node.js';
5
+ import { toJS } from './toJS.js';
4
6
 
5
7
  class Alias extends NodeBase {
6
8
  constructor(source) {
@@ -37,7 +39,12 @@ class Alias extends NodeBase {
37
39
  const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
38
40
  throw new ReferenceError(msg);
39
41
  }
40
- const data = anchors.get(source);
42
+ let data = anchors.get(source);
43
+ if (!data) {
44
+ // Resolve anchors for Node.prototype.toJS()
45
+ toJS(source, null, ctx);
46
+ data = anchors.get(source);
47
+ }
41
48
  /* istanbul ignore if */
42
49
  if (!data || data.res === undefined) {
43
50
  const msg = 'This should not happen: Alias anchor was not resolved?';
@@ -1,5 +1,6 @@
1
1
  import { createNode } from '../doc/createNode.js';
2
- import { NodeBase, isNode, isPair, isCollection, isScalar } from './Node.js';
2
+ import { isNode, isPair, isCollection, isScalar } from './identity.js';
3
+ import { NodeBase } from './Node.js';
3
4
 
4
5
  function collectionFromPath(schema, path, value) {
5
6
  let v = value;
@@ -1,37 +1,7 @@
1
- const ALIAS = Symbol.for('yaml.alias');
2
- const DOC = Symbol.for('yaml.document');
3
- const MAP = Symbol.for('yaml.map');
4
- const PAIR = Symbol.for('yaml.pair');
5
- const SCALAR = Symbol.for('yaml.scalar');
6
- const SEQ = Symbol.for('yaml.seq');
7
- const NODE_TYPE = Symbol.for('yaml.node.type');
8
- const isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS;
9
- const isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC;
10
- const isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP;
11
- const isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR;
12
- const isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR;
13
- const isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ;
14
- function isCollection(node) {
15
- if (node && typeof node === 'object')
16
- switch (node[NODE_TYPE]) {
17
- case MAP:
18
- case SEQ:
19
- return true;
20
- }
21
- return false;
22
- }
23
- function isNode(node) {
24
- if (node && typeof node === 'object')
25
- switch (node[NODE_TYPE]) {
26
- case ALIAS:
27
- case MAP:
28
- case SCALAR:
29
- case SEQ:
30
- return true;
31
- }
32
- return false;
33
- }
34
- const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
1
+ import { applyReviver } from '../doc/applyReviver.js';
2
+ import { NODE_TYPE, isDocument } from './identity.js';
3
+ import { toJS } from './toJS.js';
4
+
35
5
  class NodeBase {
36
6
  constructor(type) {
37
7
  Object.defineProperty(this, NODE_TYPE, { value: type });
@@ -43,6 +13,26 @@ class NodeBase {
43
13
  copy.range = this.range.slice();
44
14
  return copy;
45
15
  }
16
+ /** A plain JavaScript representation of this node. */
17
+ toJS(doc, { mapAsMap, maxAliasCount, onAnchor, reviver } = {}) {
18
+ if (!isDocument(doc))
19
+ throw new TypeError('A document argument is required');
20
+ const ctx = {
21
+ anchors: new Map(),
22
+ doc,
23
+ keep: true,
24
+ mapAsMap: mapAsMap === true,
25
+ mapKeyWarned: false,
26
+ maxAliasCount: typeof maxAliasCount === 'number' ? maxAliasCount : 100
27
+ };
28
+ const res = toJS(this, '', ctx);
29
+ if (typeof onAnchor === 'function')
30
+ for (const { count, res } of ctx.anchors.values())
31
+ onAnchor(res, count);
32
+ return typeof reviver === 'function'
33
+ ? applyReviver(reviver, { '': res }, '', res)
34
+ : res;
35
+ }
46
36
  }
47
37
 
48
- export { ALIAS, DOC, MAP, NODE_TYPE, NodeBase, PAIR, SCALAR, SEQ, hasAnchor, isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq };
38
+ export { NodeBase };
@@ -1,7 +1,7 @@
1
1
  import { createNode } from '../doc/createNode.js';
2
2
  import { stringifyPair } from '../stringify/stringifyPair.js';
3
3
  import { addPairToJSMap } from './addPairToJSMap.js';
4
- import { NODE_TYPE, PAIR, isNode } from './Node.js';
4
+ import { NODE_TYPE, PAIR, isNode } from './identity.js';
5
5
 
6
6
  function createPair(key, value, ctx) {
7
7
  const k = createNode(key, undefined, ctx);
@@ -1,4 +1,5 @@
1
- import { NodeBase, SCALAR } from './Node.js';
1
+ import { SCALAR } from './identity.js';
2
+ import { NodeBase } from './Node.js';
2
3
  import { toJS } from './toJS.js';
3
4
 
4
5
  const isScalarValue = (value) => !value || (typeof value !== 'function' && typeof value !== 'object');
@@ -1,7 +1,7 @@
1
1
  import { stringifyCollection } from '../stringify/stringifyCollection.js';
2
2
  import { addPairToJSMap } from './addPairToJSMap.js';
3
3
  import { Collection } from './Collection.js';
4
- import { isPair, isScalar, MAP } from './Node.js';
4
+ import { isPair, isScalar, MAP } from './identity.js';
5
5
  import { Pair } from './Pair.js';
6
6
  import { isScalarValue } from './Scalar.js';
7
7
 
@@ -1,6 +1,6 @@
1
1
  import { stringifyCollection } from '../stringify/stringifyCollection.js';
2
2
  import { Collection } from './Collection.js';
3
- import { SEQ, isScalar } from './Node.js';
3
+ import { SEQ, isScalar } from './identity.js';
4
4
  import { isScalarValue } from './Scalar.js';
5
5
  import { toJS } from './toJS.js';
6
6
 
@@ -1,6 +1,6 @@
1
1
  import { warn } from '../log.js';
2
2
  import { createStringifyContext } from '../stringify/stringify.js';
3
- import { isAlias, isSeq, isScalar, isMap, isNode } from './Node.js';
3
+ import { isAlias, isSeq, isScalar, isMap, isNode } from './identity.js';
4
4
  import { Scalar } from './Scalar.js';
5
5
  import { toJS } from './toJS.js';
6
6
 
@@ -0,0 +1,36 @@
1
+ const ALIAS = Symbol.for('yaml.alias');
2
+ const DOC = Symbol.for('yaml.document');
3
+ const MAP = Symbol.for('yaml.map');
4
+ const PAIR = Symbol.for('yaml.pair');
5
+ const SCALAR = Symbol.for('yaml.scalar');
6
+ const SEQ = Symbol.for('yaml.seq');
7
+ const NODE_TYPE = Symbol.for('yaml.node.type');
8
+ const isAlias = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === ALIAS;
9
+ const isDocument = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === DOC;
10
+ const isMap = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === MAP;
11
+ const isPair = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === PAIR;
12
+ const isScalar = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SCALAR;
13
+ const isSeq = (node) => !!node && typeof node === 'object' && node[NODE_TYPE] === SEQ;
14
+ function isCollection(node) {
15
+ if (node && typeof node === 'object')
16
+ switch (node[NODE_TYPE]) {
17
+ case MAP:
18
+ case SEQ:
19
+ return true;
20
+ }
21
+ return false;
22
+ }
23
+ function isNode(node) {
24
+ if (node && typeof node === 'object')
25
+ switch (node[NODE_TYPE]) {
26
+ case ALIAS:
27
+ case MAP:
28
+ case SCALAR:
29
+ case SEQ:
30
+ return true;
31
+ }
32
+ return false;
33
+ }
34
+ const hasAnchor = (node) => (isScalar(node) || isCollection(node)) && !!node.anchor;
35
+
36
+ export { ALIAS, DOC, MAP, NODE_TYPE, PAIR, SCALAR, SEQ, hasAnchor, isAlias, isCollection, isDocument, isMap, isNode, isPair, isScalar, isSeq };
@@ -1,4 +1,4 @@
1
- import { hasAnchor } from './Node.js';
1
+ import { hasAnchor } from './identity.js';
2
2
 
3
3
  /**
4
4
  * Recursively convert any node or its contents to native JavaScript
@@ -1,4 +1,4 @@
1
- import { MAP, SCALAR, SEQ } from '../nodes/Node.js';
1
+ import { MAP, SCALAR, SEQ } from '../nodes/identity.js';
2
2
  import { map } from './common/map.js';
3
3
  import { seq } from './common/seq.js';
4
4
  import { string } from './common/string.js';
@@ -1,4 +1,4 @@
1
- import { isMap } from '../../nodes/Node.js';
1
+ import { isMap } from '../../nodes/identity.js';
2
2
  import { createPair } from '../../nodes/Pair.js';
3
3
  import { YAMLMap } from '../../nodes/YAMLMap.js';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { createNode } from '../../doc/createNode.js';
2
- import { isSeq } from '../../nodes/Node.js';
2
+ import { isSeq } from '../../nodes/identity.js';
3
3
  import { YAMLSeq } from '../../nodes/YAMLSeq.js';
4
4
 
5
5
  function createSeq(schema, obj, ctx) {
@@ -1,7 +1,7 @@
1
- import { YAMLSeq } from '../../nodes/YAMLSeq.js';
1
+ import { isScalar, isPair } from '../../nodes/identity.js';
2
2
  import { toJS } from '../../nodes/toJS.js';
3
- import { isScalar, isPair } from '../../nodes/Node.js';
4
3
  import { YAMLMap } from '../../nodes/YAMLMap.js';
4
+ import { YAMLSeq } from '../../nodes/YAMLSeq.js';
5
5
  import { resolvePairs, createPairs } from './pairs.js';
6
6
 
7
7
  class YAMLOMap extends YAMLSeq {
@@ -1,4 +1,4 @@
1
- import { isSeq, isPair, isMap } from '../../nodes/Node.js';
1
+ import { isSeq, isPair, isMap } from '../../nodes/identity.js';
2
2
  import { Pair, createPair } from '../../nodes/Pair.js';
3
3
  import { Scalar } from '../../nodes/Scalar.js';
4
4
  import { YAMLSeq } from '../../nodes/YAMLSeq.js';
@@ -1,4 +1,4 @@
1
- import { isMap, isPair, isScalar } from '../../nodes/Node.js';
1
+ import { isMap, isPair, isScalar } from '../../nodes/identity.js';
2
2
  import { createPair, Pair } from '../../nodes/Pair.js';
3
3
  import { YAMLMap, findPair } from '../../nodes/YAMLMap.js';
4
4
 
@@ -1,5 +1,5 @@
1
1
  import { anchorIsValid } from '../doc/anchors.js';
2
- import { isPair, isAlias, isNode, isScalar, isCollection } from '../nodes/Node.js';
2
+ import { isPair, isAlias, isNode, isScalar, isCollection } from '../nodes/identity.js';
3
3
  import { stringifyComment } from './stringifyComment.js';
4
4
  import { stringifyString } from './stringifyString.js';
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { Collection } from '../nodes/Collection.js';
2
- import { isNode, isPair } from '../nodes/Node.js';
2
+ import { isNode, isPair } from '../nodes/identity.js';
3
3
  import { stringify } from './stringify.js';
4
4
  import { lineComment, indentComment } from './stringifyComment.js';
5
5
 
@@ -1,4 +1,4 @@
1
- import { isNode } from '../nodes/Node.js';
1
+ import { isNode } from '../nodes/identity.js';
2
2
  import { createStringifyContext, stringify } from './stringify.js';
3
3
  import { indentComment, lineComment } from './stringifyComment.js';
4
4
 
@@ -1,4 +1,4 @@
1
- import { isCollection, isNode, isScalar, isSeq } from '../nodes/Node.js';
1
+ import { isCollection, isNode, isScalar, isSeq } from '../nodes/identity.js';
2
2
  import { Scalar } from '../nodes/Scalar.js';
3
3
  import { stringify } from './stringify.js';
4
4
  import { lineComment, indentComment } from './stringifyComment.js';
@@ -1,8 +1,8 @@
1
1
  import { Scalar } from '../nodes/Scalar.js';
2
2
  import { foldFlowLines, FOLD_QUOTED, FOLD_FLOW, FOLD_BLOCK } from './foldFlowLines.js';
3
3
 
4
- const getFoldOptions = (ctx) => ({
5
- indentAtStart: ctx.indentAtStart,
4
+ const getFoldOptions = (ctx, isBlock) => ({
5
+ indentAtStart: isBlock ? ctx.indent.length : ctx.indentAtStart,
6
6
  lineWidth: ctx.options.lineWidth,
7
7
  minContentWidth: ctx.options.minContentWidth
8
8
  });
@@ -115,7 +115,7 @@ function doubleQuotedString(value, ctx) {
115
115
  str = start ? str + json.slice(start) : json;
116
116
  return implicitKey
117
117
  ? str
118
- : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx));
118
+ : foldFlowLines(str, indent, FOLD_QUOTED, getFoldOptions(ctx, false));
119
119
  }
120
120
  function singleQuotedString(value, ctx) {
121
121
  if (ctx.options.singleQuote === false ||
@@ -127,7 +127,7 @@ function singleQuotedString(value, ctx) {
127
127
  const res = "'" + value.replace(/'/g, "''").replace(/\n+/g, `$&\n${indent}`) + "'";
128
128
  return ctx.implicitKey
129
129
  ? res
130
- : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx));
130
+ : foldFlowLines(res, indent, FOLD_FLOW, getFoldOptions(ctx, false));
131
131
  }
132
132
  function quotedString(value, ctx) {
133
133
  const { singleQuote } = ctx.options;
@@ -234,7 +234,7 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
234
234
  .replace(/(?:^|\n)([\t ].*)(?:([\n\t ]*)\n(?![\n\t ]))?/g, '$1$2') // more-indented lines aren't folded
235
235
  // ^ more-ind. ^ empty ^ capture next empty lines only at end of indent
236
236
  .replace(/\n+/g, `$&${indent}`);
237
- const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx));
237
+ const body = foldFlowLines(`${start}${value}${end}`, indent, FOLD_BLOCK, getFoldOptions(ctx, true));
238
238
  return `${header}\n${indent}${body}`;
239
239
  }
240
240
  function plainString(item, ctx, onComment, onChompKeep) {
@@ -284,7 +284,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
284
284
  }
285
285
  return implicitKey
286
286
  ? str
287
- : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx));
287
+ : foldFlowLines(str, indent, FOLD_FLOW, getFoldOptions(ctx, false));
288
288
  }
289
289
  function stringifyString(item, ctx, onComment, onChompKeep) {
290
290
  const { implicitKey, inFlow } = ctx;
@@ -1,4 +1,6 @@
1
+ export { createNode } from './doc/createNode.js';
1
2
  export { debug, warn } from './log.js';
3
+ export { createPair } from './nodes/Pair.js';
2
4
  export { findPair } from './nodes/YAMLMap.js';
3
5
  export { toJS } from './nodes/toJS.js';
4
6
  export { map as mapTag } from './schema/common/map.js';
@@ -1,4 +1,4 @@
1
- import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/Node.js';
1
+ import { isDocument, isNode, isPair, isCollection, isMap, isSeq, isScalar, isAlias } from './nodes/identity.js';
2
2
 
3
3
  const BREAK = Symbol('break visit');
4
4
  const SKIP = Symbol('skip children');
@@ -1,4 +1,4 @@
1
- import { ParsedNode } from '../nodes/Node.js';
1
+ import type { ParsedNode } from '../nodes/Node.js';
2
2
  import type { BlockMap, BlockSequence, FlowCollection, SourceToken } from '../parse/cst.js';
3
3
  import type { ComposeContext, ComposeNode } from './compose-node.js';
4
4
  import type { ComposeErrorHandler } from './composer.js';
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../nodes/Node.js');
3
+ var identity = require('../nodes/identity.js');
4
4
  var Scalar = require('../nodes/Scalar.js');
5
5
  var resolveBlockMap = require('./resolve-block-map.js');
6
6
  var resolveBlockSeq = require('./resolve-block-seq.js');
@@ -33,7 +33,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
33
33
  coll.tag = Coll.tagName;
34
34
  return coll;
35
35
  }
36
- const expType = Node.isMap(coll) ? 'map' : 'seq';
36
+ const expType = identity.isMap(coll) ? 'map' : 'seq';
37
37
  let tag = ctx.schema.tags.find(t => t.collection === expType && t.tag === tagName);
38
38
  if (!tag) {
39
39
  const kt = ctx.schema.knownTags[tagName];
@@ -48,7 +48,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
48
48
  }
49
49
  }
50
50
  const res = tag.resolve(coll, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg), ctx.options);
51
- const node = Node.isNode(res)
51
+ const node = identity.isNode(res)
52
52
  ? res
53
53
  : new Scalar.Scalar(res);
54
54
  node.range = coll.range;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../nodes/Node.js');
3
+ var identity = require('../nodes/identity.js');
4
4
  var Scalar = require('../nodes/Scalar.js');
5
5
  var resolveBlockScalar = require('./resolve-block-scalar.js');
6
6
  var resolveFlowScalar = require('./resolve-flow-scalar.js');
@@ -16,11 +16,11 @@ function composeScalar(ctx, token, tagToken, onError) {
16
16
  ? findScalarTagByName(ctx.schema, value, tagName, tagToken, onError)
17
17
  : token.type === 'scalar'
18
18
  ? findScalarTagByTest(ctx, value, token, onError)
19
- : ctx.schema[Node.SCALAR];
19
+ : ctx.schema[identity.SCALAR];
20
20
  let scalar;
21
21
  try {
22
22
  const res = tag.resolve(value, msg => onError(tagToken ?? token, 'TAG_RESOLVE_FAILED', msg), ctx.options);
23
- scalar = Node.isScalar(res) ? res : new Scalar.Scalar(res);
23
+ scalar = identity.isScalar(res) ? res : new Scalar.Scalar(res);
24
24
  }
25
25
  catch (error) {
26
26
  const msg = error instanceof Error ? error.message : String(error);
@@ -41,7 +41,7 @@ function composeScalar(ctx, token, tagToken, onError) {
41
41
  }
42
42
  function findScalarTagByName(schema, value, tagName, tagToken, onError) {
43
43
  if (tagName === '!')
44
- return schema[Node.SCALAR]; // non-specific tag
44
+ return schema[identity.SCALAR]; // non-specific tag
45
45
  const matchWithTest = [];
46
46
  for (const tag of schema.tags) {
47
47
  if (!tag.collection && tag.tag === tagName) {
@@ -62,13 +62,13 @@ function findScalarTagByName(schema, value, tagName, tagToken, onError) {
62
62
  return kt;
63
63
  }
64
64
  onError(tagToken, 'TAG_RESOLVE_FAILED', `Unresolved tag: ${tagName}`, tagName !== 'tag:yaml.org,2002:str');
65
- return schema[Node.SCALAR];
65
+ return schema[identity.SCALAR];
66
66
  }
67
67
  function findScalarTagByTest({ directives, schema }, value, token, onError) {
68
- const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[Node.SCALAR];
68
+ const tag = schema.tags.find(tag => tag.default && tag.test?.test(value)) || schema[identity.SCALAR];
69
69
  if (schema.compat) {
70
70
  const compat = schema.compat.find(tag => tag.default && tag.test?.test(value)) ??
71
- schema[Node.SCALAR];
71
+ schema[identity.SCALAR];
72
72
  if (tag.tag !== compat.tag) {
73
73
  const ts = directives.tagString(tag.tag);
74
74
  const cs = directives.tagString(compat.tag);
@@ -1,7 +1,7 @@
1
1
  import { Directives } from '../doc/directives.js';
2
2
  import { Document } from '../doc/Document.js';
3
3
  import { ErrorCode, YAMLParseError, YAMLWarning } from '../errors.js';
4
- import { ParsedNode, Range } from '../nodes/Node.js';
4
+ import type { ParsedNode, Range } from '../nodes/Node.js';
5
5
  import type { DocumentOptions, ParseOptions, SchemaOptions } from '../options.js';
6
6
  import type { Token } from '../parse/cst.js';
7
7
  type ErrorSource = number | [number, number] | Range | {
@@ -3,7 +3,7 @@
3
3
  var directives = require('../doc/directives.js');
4
4
  var Document = require('../doc/Document.js');
5
5
  var errors = require('../errors.js');
6
- var Node = require('../nodes/Node.js');
6
+ var identity = require('../nodes/identity.js');
7
7
  var composeDoc = require('./compose-doc.js');
8
8
  var resolveEnd = require('./resolve-end.js');
9
9
 
@@ -83,9 +83,9 @@ class Composer {
83
83
  else if (afterEmptyLine || doc.directives.docStart || !dc) {
84
84
  doc.commentBefore = comment;
85
85
  }
86
- else if (Node.isCollection(dc) && !dc.flow && dc.items.length > 0) {
86
+ else if (identity.isCollection(dc) && !dc.flow && dc.items.length > 0) {
87
87
  let it = dc.items[0];
88
- if (Node.isPair(it))
88
+ if (identity.isPair(it))
89
89
  it = it.key;
90
90
  const cb = it.commentBefore;
91
91
  it.commentBefore = cb ? `${comment}\n${cb}` : comment;
@@ -3,4 +3,4 @@ import { YAMLSeq } from '../nodes/YAMLSeq.js';
3
3
  import type { FlowCollection } from '../parse/cst.js';
4
4
  import type { ComposeContext, ComposeNode } from './compose-node.js';
5
5
  import type { ComposeErrorHandler } from './composer.js';
6
- export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler): YAMLMap.Parsed<import("../nodes/Node.js").ParsedNode, import("../nodes/Node.js").ParsedNode | null> | YAMLSeq.Parsed<import("../nodes/Node.js").ParsedNode>;
6
+ export declare function resolveFlowCollection({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, fc: FlowCollection, onError: ComposeErrorHandler): YAMLMap.Parsed<import("../index.js").ParsedNode, import("../index.js").ParsedNode | null> | YAMLSeq.Parsed<import("../index.js").ParsedNode>;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../nodes/Node.js');
3
+ var identity = require('../nodes/identity.js');
4
4
  var Pair = require('../nodes/Pair.js');
5
5
  var YAMLMap = require('../nodes/YAMLMap.js');
6
6
  var YAMLSeq = require('../nodes/YAMLSeq.js');
@@ -75,7 +75,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
75
75
  }
76
76
  if (prevItemComment) {
77
77
  let prev = coll.items[coll.items.length - 1];
78
- if (Node.isPair(prev))
78
+ if (identity.isPair(prev))
79
79
  prev = prev.value ?? prev.key;
80
80
  if (prev.comment)
81
81
  prev.comment += '\n' + prevItemComment;
@@ -1,4 +1,4 @@
1
- import { ParsedNode } from '../nodes/Node';
2
- import { Pair } from '../nodes/Pair';
3
- import { ComposeContext } from './compose-node';
1
+ import type { ParsedNode } from '../nodes/Node.js';
2
+ import type { Pair } from '../nodes/Pair.js';
3
+ import type { ComposeContext } from './compose-node.js';
4
4
  export declare function mapIncludes(ctx: ComposeContext, items: Pair<ParsedNode>[], search: ParsedNode): boolean;
@@ -1,6 +1,6 @@
1
1
  'use strict';
2
2
 
3
- var Node = require('../nodes/Node.js');
3
+ var identity = require('../nodes/identity.js');
4
4
 
5
5
  function mapIncludes(ctx, items, search) {
6
6
  const { uniqueKeys } = ctx.options;
@@ -9,8 +9,8 @@ function mapIncludes(ctx, items, search) {
9
9
  const isEqual = typeof uniqueKeys === 'function'
10
10
  ? uniqueKeys
11
11
  : (a, b) => a === b ||
12
- (Node.isScalar(a) &&
13
- Node.isScalar(b) &&
12
+ (identity.isScalar(a) &&
13
+ identity.isScalar(b) &&
14
14
  a.value === b.value &&
15
15
  !(a.value === '<<' && ctx.schema.merge));
16
16
  return items.some(pair => isEqual(pair.key, search));
@@ -1,6 +1,7 @@
1
1
  import type { YAMLError, YAMLWarning } from '../errors.js';
2
2
  import { Alias } from '../nodes/Alias.js';
3
- import { Node, NodeType, NODE_TYPE, ParsedNode, Range } from '../nodes/Node.js';
3
+ import { NODE_TYPE } from '../nodes/identity.js';
4
+ import type { Node, NodeType, ParsedNode, Range } from '../nodes/Node.js';
4
5
  import { Pair } from '../nodes/Pair.js';
5
6
  import type { Scalar } from '../nodes/Scalar.js';
6
7
  import type { YAMLMap } from '../nodes/YAMLMap.js';