yaml 2.0.1 → 2.1.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 (83) hide show
  1. package/browser/dist/compose/compose-collection.js +1 -1
  2. package/browser/dist/compose/compose-doc.js +2 -2
  3. package/browser/dist/compose/compose-scalar.js +6 -7
  4. package/browser/dist/compose/composer.js +2 -3
  5. package/browser/dist/compose/resolve-block-map.js +5 -6
  6. package/browser/dist/compose/resolve-block-scalar.js +1 -1
  7. package/browser/dist/compose/resolve-flow-collection.js +3 -4
  8. package/browser/dist/compose/resolve-flow-scalar.js +1 -2
  9. package/browser/dist/compose/resolve-props.js +2 -2
  10. package/browser/dist/compose/util-empty-scalar-position.js +1 -1
  11. package/browser/dist/compose/util-flow-indent-check.js +1 -1
  12. package/browser/dist/doc/Document.js +6 -6
  13. package/browser/dist/doc/createNode.js +5 -7
  14. package/browser/dist/nodes/Collection.js +2 -1
  15. package/browser/dist/nodes/Pair.js +2 -2
  16. package/browser/dist/nodes/Scalar.js +1 -1
  17. package/browser/dist/nodes/YAMLMap.js +6 -7
  18. package/browser/dist/nodes/YAMLSeq.js +1 -9
  19. package/browser/dist/nodes/addPairToJSMap.js +1 -1
  20. package/browser/dist/nodes/toJS.js +1 -1
  21. package/browser/dist/parse/cst-scalar.js +1 -2
  22. package/browser/dist/parse/cst-visit.js +2 -2
  23. package/browser/dist/parse/lexer.js +1 -2
  24. package/browser/dist/parse/parser.js +10 -14
  25. package/browser/dist/public-api.js +3 -4
  26. package/browser/dist/schema/Schema.js +1 -1
  27. package/browser/dist/schema/yaml-1.1/omap.js +1 -1
  28. package/browser/dist/schema/yaml-1.1/pairs.js +1 -2
  29. package/browser/dist/schema/yaml-1.1/set.js +4 -0
  30. package/browser/dist/stringify/stringify.js +6 -8
  31. package/browser/dist/stringify/stringifyCollection.js +1 -2
  32. package/browser/dist/stringify/stringifyDocument.js +1 -2
  33. package/browser/dist/stringify/stringifyString.js +2 -2
  34. package/browser/dist/visit.js +5 -6
  35. package/dist/compose/compose-collection.js +1 -1
  36. package/dist/compose/compose-doc.js +2 -2
  37. package/dist/compose/compose-scalar.js +6 -7
  38. package/dist/compose/composer.js +2 -3
  39. package/dist/compose/resolve-block-map.js +5 -6
  40. package/dist/compose/resolve-block-scalar.js +1 -1
  41. package/dist/compose/resolve-flow-collection.js +3 -4
  42. package/dist/compose/resolve-flow-scalar.js +1 -2
  43. package/dist/compose/resolve-props.js +2 -2
  44. package/dist/compose/util-empty-scalar-position.js +1 -1
  45. package/dist/compose/util-flow-indent-check.js +1 -1
  46. package/dist/doc/Document.d.ts +10 -10
  47. package/dist/doc/Document.js +6 -6
  48. package/dist/doc/anchors.d.ts +1 -1
  49. package/dist/doc/createNode.js +5 -7
  50. package/dist/index.d.ts +2 -0
  51. package/dist/nodes/Collection.d.ts +2 -2
  52. package/dist/nodes/Collection.js +2 -1
  53. package/dist/nodes/Node.d.ts +14 -10
  54. package/dist/nodes/Pair.d.ts +1 -1
  55. package/dist/nodes/Pair.js +2 -2
  56. package/dist/nodes/Scalar.js +1 -1
  57. package/dist/nodes/YAMLMap.d.ts +6 -3
  58. package/dist/nodes/YAMLMap.js +6 -7
  59. package/dist/nodes/YAMLSeq.d.ts +4 -1
  60. package/dist/nodes/YAMLSeq.js +1 -9
  61. package/dist/nodes/addPairToJSMap.js +1 -1
  62. package/dist/nodes/toJS.js +1 -1
  63. package/dist/options.d.ts +2 -1
  64. package/dist/parse/cst-scalar.js +1 -2
  65. package/dist/parse/cst-visit.js +2 -2
  66. package/dist/parse/lexer.js +1 -2
  67. package/dist/parse/parser.js +10 -14
  68. package/dist/public-api.js +3 -4
  69. package/dist/schema/Schema.js +1 -1
  70. package/dist/schema/json-schema.d.ts +69 -0
  71. package/dist/schema/yaml-1.1/omap.d.ts +7 -3
  72. package/dist/schema/yaml-1.1/omap.js +1 -1
  73. package/dist/schema/yaml-1.1/pairs.js +1 -2
  74. package/dist/schema/yaml-1.1/set.d.ts +6 -2
  75. package/dist/schema/yaml-1.1/set.js +4 -0
  76. package/dist/stringify/stringify.js +6 -8
  77. package/dist/stringify/stringifyCollection.js +1 -2
  78. package/dist/stringify/stringifyDocument.js +1 -2
  79. package/dist/stringify/stringifyString.js +2 -2
  80. package/dist/test-events.js +2 -3
  81. package/dist/visit.js +5 -6
  82. package/package.json +3 -3
  83. package/dist/node_modules/tslib/tslib.es6.js +0 -76
@@ -6,9 +6,13 @@ import type { Pair } from './Pair.js';
6
6
  import type { Scalar } from './Scalar.js';
7
7
  import type { YAMLMap } from './YAMLMap.js';
8
8
  import type { YAMLSeq } from './YAMLSeq.js';
9
- export declare type Node = Alias | Scalar | YAMLMap | YAMLSeq;
9
+ export declare type Node<T = unknown> = Alias | Scalar<T> | YAMLMap<unknown, T> | YAMLSeq<T>;
10
+ /** Utility type mapper */
11
+ export declare type NodeType<T> = T extends string | number | bigint | boolean | null ? Scalar<T> : T extends Array<any> ? YAMLSeq<NodeType<T[number]>> : T extends {
12
+ [key: string | number]: any;
13
+ } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
10
14
  export declare type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
11
- export declare type Range = [number, number, number];
15
+ export declare type Range = [start: number, valueEnd: number, nodeEnd: number];
12
16
  export declare const ALIAS: unique symbol;
13
17
  export declare const DOC: unique symbol;
14
18
  export declare const MAP: unique symbol;
@@ -17,14 +21,14 @@ export declare const SCALAR: unique symbol;
17
21
  export declare const SEQ: unique symbol;
18
22
  export declare const NODE_TYPE: unique symbol;
19
23
  export declare const isAlias: (node: any) => node is Alias;
20
- export declare const isDocument: (node: any) => node is Document<unknown>;
21
- export declare const isMap: (node: any) => node is YAMLMap<unknown, unknown>;
22
- export declare const isPair: (node: any) => node is Pair<unknown, unknown>;
23
- export declare const isScalar: (node: any) => node is Scalar<unknown>;
24
- export declare const isSeq: (node: any) => node is YAMLSeq<unknown>;
25
- export declare function isCollection(node: any): node is YAMLMap | YAMLSeq;
26
- export declare function isNode(node: any): node is Node;
27
- export declare const hasAnchor: (node: unknown) => node is Scalar<unknown> | YAMLMap<unknown, unknown> | YAMLSeq<unknown>;
24
+ export declare const isDocument: <T extends Node<unknown> = Node<unknown>>(node: any) => node is Document<T>;
25
+ export declare const isMap: <K = unknown, V = unknown>(node: any) => node is YAMLMap<K, V>;
26
+ export declare const isPair: <K = unknown, V = unknown>(node: any) => node is Pair<K, V>;
27
+ export declare const isScalar: <T = unknown>(node: any) => node is Scalar<T>;
28
+ export declare const isSeq: <T = unknown>(node: any) => node is YAMLSeq<T>;
29
+ export declare function isCollection<K = unknown, V = unknown>(node: any): node is YAMLMap<K, V> | YAMLSeq<V>;
30
+ export declare function isNode<T = unknown>(node: any): node is Node<T>;
31
+ export declare const hasAnchor: <K = unknown, V = unknown>(node: unknown) => node is Scalar<V> | YAMLMap<K, V> | YAMLSeq<V>;
28
32
  export declare abstract class NodeBase {
29
33
  readonly [NODE_TYPE]: symbol;
30
34
  /** A comment on or immediately after this */
@@ -5,7 +5,7 @@ import type { StringifyContext } from '../stringify/stringify.js';
5
5
  import { addPairToJSMap } from './addPairToJSMap.js';
6
6
  import { NODE_TYPE } from './Node.js';
7
7
  import type { ToJSContext } from './toJS.js';
8
- export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node, import("./Alias.js").Alias | import("./Scalar.js").Scalar<unknown> | import("./YAMLMap.js").YAMLMap<unknown, unknown> | import("./YAMLSeq.js").YAMLSeq<unknown>>;
8
+ export declare function createPair(key: unknown, value: unknown, ctx: CreateNodeContext): Pair<import("./Node.js").Node<unknown>, import("./Alias.js").Alias | import("./Scalar.js").Scalar<unknown> | import("./YAMLMap.js").YAMLMap<unknown, unknown> | import("./YAMLSeq.js").YAMLSeq<unknown>>;
9
9
  export declare class Pair<K = unknown, V = unknown> {
10
10
  readonly [NODE_TYPE]: symbol;
11
11
  /** Always Node or null when parsed, but can be set to anything. */
@@ -25,11 +25,11 @@ class Pair {
25
25
  return new Pair(key, value);
26
26
  }
27
27
  toJSON(_, ctx) {
28
- const pair = (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
28
+ const pair = ctx?.mapAsMap ? new Map() : {};
29
29
  return addPairToJSMap.addPairToJSMap(ctx, pair, this);
30
30
  }
31
31
  toString(ctx, onComment, onChompKeep) {
32
- return (ctx === null || ctx === void 0 ? void 0 : ctx.doc)
32
+ return ctx?.doc
33
33
  ? stringifyPair.stringifyPair(this, ctx, onComment, onChompKeep)
34
34
  : JSON.stringify(this);
35
35
  }
@@ -10,7 +10,7 @@ class Scalar extends Node.NodeBase {
10
10
  this.value = value;
11
11
  }
12
12
  toJSON(arg, ctx) {
13
- return (ctx === null || ctx === void 0 ? void 0 : ctx.keep) ? this.value : toJS.toJS(this.value, arg, ctx);
13
+ return ctx?.keep ? this.value : toJS.toJS(this.value, arg, ctx);
14
14
  }
15
15
  toString() {
16
16
  return String(this.value);
@@ -4,6 +4,7 @@ import type { StringifyContext } from '../stringify/stringify.js';
4
4
  import { Collection } from './Collection.js';
5
5
  import { ParsedNode, Range } from './Node.js';
6
6
  import { Pair } from './Pair.js';
7
+ import { Scalar } from './Scalar.js';
7
8
  import type { ToJSContext } from './toJS.js';
8
9
  export declare function findPair<K = unknown, V = unknown>(items: Iterable<Pair<K, V>>, key: unknown): Pair<K, V> | undefined;
9
10
  export declare namespace YAMLMap {
@@ -27,9 +28,11 @@ export declare class YAMLMap<K = unknown, V = unknown> extends Collection {
27
28
  key: K;
28
29
  value: V;
29
30
  }, overwrite?: boolean): void;
30
- delete(key: K): boolean;
31
- get(key: K, keepScalar?: boolean): unknown;
32
- has(key: K): boolean;
31
+ delete(key: unknown): boolean;
32
+ get(key: unknown, keepScalar: true): Scalar<V> | undefined;
33
+ get(key: unknown, keepScalar?: false): V | undefined;
34
+ get(key: unknown, keepScalar?: boolean): V | Scalar<V> | undefined;
35
+ has(key: unknown): boolean;
33
36
  set(key: K, value: V): void;
34
37
  /**
35
38
  * @param ctx - Conversion context, originally set in Document#toJS()
@@ -34,18 +34,17 @@ class YAMLMap extends Collection.Collection {
34
34
  * collection will throw. Otherwise, overwrites the previous value.
35
35
  */
36
36
  add(pair, overwrite) {
37
- var _a;
38
37
  let _pair;
39
38
  if (Node.isPair(pair))
40
39
  _pair = pair;
41
40
  else if (!pair || typeof pair !== 'object' || !('key' in pair)) {
42
41
  // In TypeScript, this never happens.
43
- _pair = new Pair.Pair(pair, pair.value);
42
+ _pair = new Pair.Pair(pair, pair?.value);
44
43
  }
45
44
  else
46
45
  _pair = new Pair.Pair(pair.key, pair.value);
47
46
  const prev = findPair(this.items, _pair.key);
48
- const sortEntries = (_a = this.schema) === null || _a === void 0 ? void 0 : _a.sortMapEntries;
47
+ const sortEntries = this.schema?.sortMapEntries;
49
48
  if (prev) {
50
49
  if (!overwrite)
51
50
  throw new Error(`Key ${_pair.key} already set`);
@@ -75,8 +74,8 @@ class YAMLMap extends Collection.Collection {
75
74
  }
76
75
  get(key, keepScalar) {
77
76
  const it = findPair(this.items, key);
78
- const node = it === null || it === void 0 ? void 0 : it.value;
79
- return !keepScalar && Node.isScalar(node) ? node.value : node;
77
+ const node = it?.value;
78
+ return (!keepScalar && Node.isScalar(node) ? node.value : node) ?? undefined;
80
79
  }
81
80
  has(key) {
82
81
  return !!findPair(this.items, key);
@@ -90,8 +89,8 @@ class YAMLMap extends Collection.Collection {
90
89
  * @returns Instance of Type, Map, or Object
91
90
  */
92
91
  toJSON(_, ctx, Type) {
93
- const map = Type ? new Type() : (ctx === null || ctx === void 0 ? void 0 : ctx.mapAsMap) ? new Map() : {};
94
- if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
92
+ const map = Type ? new Type() : ctx?.mapAsMap ? new Map() : {};
93
+ if (ctx?.onCreate)
95
94
  ctx.onCreate(map);
96
95
  for (const item of this.items)
97
96
  addPairToJSMap.addPairToJSMap(ctx, map, item);
@@ -4,6 +4,7 @@ import type { StringifyContext } from '../stringify/stringify.js';
4
4
  import { Collection } from './Collection.js';
5
5
  import { ParsedNode, Range } from './Node.js';
6
6
  import type { Pair } from './Pair.js';
7
+ import { Scalar } from './Scalar.js';
7
8
  import { ToJSContext } from './toJS.js';
8
9
  export declare namespace YAMLSeq {
9
10
  interface Parsed<T extends ParsedNode | Pair<ParsedNode, ParsedNode | null> = ParsedNode> extends YAMLSeq<T> {
@@ -34,7 +35,9 @@ export declare class YAMLSeq<T = unknown> extends Collection {
34
35
  * `key` must contain a representation of an integer for this to succeed.
35
36
  * It may be wrapped in a `Scalar`.
36
37
  */
37
- get(key: unknown, keepScalar?: boolean): unknown;
38
+ get(key: unknown, keepScalar: true): Scalar<T> | undefined;
39
+ get(key: unknown, keepScalar?: false): T | undefined;
40
+ get(key: unknown, keepScalar?: boolean): T | Scalar<T> | undefined;
38
41
  /**
39
42
  * Checks if the collection includes a value with the key `key`.
40
43
  *
@@ -32,14 +32,6 @@ class YAMLSeq extends Collection.Collection {
32
32
  const del = this.items.splice(idx, 1);
33
33
  return del.length > 0;
34
34
  }
35
- /**
36
- * Returns item at `key`, or `undefined` if not found. By default unwraps
37
- * scalar values from their surrounding node; to disable set `keepScalar` to
38
- * `true` (collections are always returned intact).
39
- *
40
- * `key` must contain a representation of an integer for this to succeed.
41
- * It may be wrapped in a `Scalar`.
42
- */
43
35
  get(key, keepScalar) {
44
36
  const idx = asItemIndex(key);
45
37
  if (typeof idx !== 'number')
@@ -76,7 +68,7 @@ class YAMLSeq extends Collection.Collection {
76
68
  }
77
69
  toJSON(_, ctx) {
78
70
  const seq = [];
79
- if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
71
+ if (ctx?.onCreate)
80
72
  ctx.onCreate(seq);
81
73
  let i = 0;
82
74
  for (const item of this.items)
@@ -8,7 +8,7 @@ var toJS = require('./toJS.js');
8
8
 
9
9
  const MERGE_KEY = '<<';
10
10
  function addPairToJSMap(ctx, map, { key, value }) {
11
- if ((ctx === null || ctx === void 0 ? void 0 : ctx.doc.schema.merge) && isMergeKey(key)) {
11
+ if (ctx?.doc.schema.merge && isMergeKey(key)) {
12
12
  value = Node.isAlias(value) ? value.resolve(ctx.doc) : value;
13
13
  if (Node.isSeq(value))
14
14
  for (const it of value.items)
@@ -31,7 +31,7 @@ function toJS(value, arg, ctx) {
31
31
  ctx.onCreate(res);
32
32
  return res;
33
33
  }
34
- if (typeof value === 'bigint' && !(ctx === null || ctx === void 0 ? void 0 : ctx.keep))
34
+ if (typeof value === 'bigint' && !ctx?.keep)
35
35
  return Number(value);
36
36
  return value;
37
37
  }
package/dist/options.d.ts CHANGED
@@ -58,10 +58,11 @@ export declare type ParseOptions = {
58
58
  };
59
59
  export declare type DocumentOptions = {
60
60
  /**
61
+ * @internal
61
62
  * Used internally by Composer. If set and includes an explicit version,
62
63
  * that overrides the `version` option.
63
64
  */
64
- directives?: Directives;
65
+ _directives?: Directives;
65
66
  /**
66
67
  * Control the logging level during parsing
67
68
  *
@@ -40,7 +40,6 @@ function resolveAsScalar(token, strict = true, onError) {
40
40
  * @param context.type The preferred type of the scalar token. If undefined, the previous type of the `token` will be used, defaulting to `'PLAIN'`.
41
41
  */
42
42
  function createScalarToken(value, context) {
43
- var _a;
44
43
  const { implicitKey = false, indent, inFlow = false, offset = -1, type = 'PLAIN' } = context;
45
44
  const source = stringifyString.stringifyString({ type, value }, {
46
45
  implicitKey,
@@ -48,7 +47,7 @@ function createScalarToken(value, context) {
48
47
  inFlow,
49
48
  options: { blockQuote: true, lineWidth: -1 }
50
49
  });
51
- const end = (_a = context.end) !== null && _a !== void 0 ? _a : [
50
+ const end = context.end ?? [
52
51
  { type: 'newline', offset: -1, indent, source: '\n' }
53
52
  ];
54
53
  switch (source[0]) {
@@ -49,7 +49,7 @@ visit.REMOVE = REMOVE;
49
49
  visit.itemAtPath = (cst, path) => {
50
50
  let item = cst;
51
51
  for (const [field, index] of path) {
52
- const tok = item === null || item === void 0 ? void 0 : item[field];
52
+ const tok = item?.[field];
53
53
  if (tok && 'items' in tok) {
54
54
  item = tok.items[index];
55
55
  }
@@ -66,7 +66,7 @@ visit.itemAtPath = (cst, path) => {
66
66
  visit.parentCollection = (cst, path) => {
67
67
  const parent = visit.itemAtPath(cst, path.slice(0, -1));
68
68
  const field = path[path.length - 1][0];
69
- const coll = parent === null || parent === void 0 ? void 0 : parent[field];
69
+ const coll = parent?.[field];
70
70
  if (coll && 'items' in coll)
71
71
  return coll;
72
72
  throw new Error('Parent collection not found');
@@ -150,13 +150,12 @@ class Lexer {
150
150
  * @returns A generator of lexical tokens
151
151
  */
152
152
  *lex(source, incomplete = false) {
153
- var _a;
154
153
  if (source) {
155
154
  this.buffer = this.buffer ? this.buffer + source : source;
156
155
  this.lineEndPos = null;
157
156
  }
158
157
  this.atEnd = !incomplete;
159
- let next = (_a = this.next) !== null && _a !== void 0 ? _a : 'stream';
158
+ let next = this.next ?? 'stream';
160
159
  while (next && (incomplete || this.hasChars(1)))
161
160
  next = yield* this.parseNext(next);
162
161
  }
@@ -23,7 +23,7 @@ function findNonEmptyIndex(list) {
23
23
  return -1;
24
24
  }
25
25
  function isFlowToken(token) {
26
- switch (token === null || token === void 0 ? void 0 : token.type) {
26
+ switch (token?.type) {
27
27
  case 'alias':
28
28
  case 'scalar':
29
29
  case 'single-quoted-scalar':
@@ -35,13 +35,12 @@ function isFlowToken(token) {
35
35
  }
36
36
  }
37
37
  function getPrevProps(parent) {
38
- var _a;
39
38
  switch (parent.type) {
40
39
  case 'document':
41
40
  return parent.start;
42
41
  case 'block-map': {
43
42
  const it = parent.items[parent.items.length - 1];
44
- return (_a = it.sep) !== null && _a !== void 0 ? _a : it.start;
43
+ return it.sep ?? it.start;
45
44
  }
46
45
  case 'block-seq':
47
46
  return parent.items[parent.items.length - 1].start;
@@ -52,7 +51,6 @@ function getPrevProps(parent) {
52
51
  }
53
52
  /** Note: May modify input array */
54
53
  function getFirstKeyStartProps(prev) {
55
- var _a;
56
54
  if (prev.length === 0)
57
55
  return [];
58
56
  let i = prev.length;
@@ -66,7 +64,7 @@ function getFirstKeyStartProps(prev) {
66
64
  break loop;
67
65
  }
68
66
  }
69
- while (((_a = prev[++i]) === null || _a === void 0 ? void 0 : _a.type) === 'space') {
67
+ while (prev[++i]?.type === 'space') {
70
68
  /* loop */
71
69
  }
72
70
  return prev.splice(i, prev.length);
@@ -270,7 +268,7 @@ class Parser {
270
268
  return this.stack[this.stack.length - n];
271
269
  }
272
270
  *pop(error) {
273
- const token = error !== null && error !== void 0 ? error : this.stack.pop();
271
+ const token = error ?? this.stack.pop();
274
272
  /* istanbul ignore if should not happen */
275
273
  if (!token) {
276
274
  const message = 'Tried to pop an empty stack';
@@ -475,7 +473,6 @@ class Parser {
475
473
  }
476
474
  }
477
475
  *blockMap(map) {
478
- var _a;
479
476
  const it = map.items[map.items.length - 1];
480
477
  // it.sep is true-ish if pair already has key or : separator
481
478
  switch (this.type) {
@@ -484,8 +481,8 @@ class Parser {
484
481
  if (it.value) {
485
482
  const end = 'end' in it.value ? it.value.end : undefined;
486
483
  const last = Array.isArray(end) ? end[end.length - 1] : undefined;
487
- if ((last === null || last === void 0 ? void 0 : last.type) === 'comment')
488
- end === null || end === void 0 ? void 0 : end.push(this.sourceToken);
484
+ if (last?.type === 'comment')
485
+ end?.push(this.sourceToken);
489
486
  else
490
487
  map.items.push({ start: [this.sourceToken] });
491
488
  }
@@ -507,7 +504,7 @@ class Parser {
507
504
  else {
508
505
  if (this.atIndentedComment(it.start, map.indent)) {
509
506
  const prev = map.items[map.items.length - 2];
510
- const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
507
+ const end = prev?.value?.end;
511
508
  if (Array.isArray(end)) {
512
509
  Array.prototype.push.apply(end, it.start);
513
510
  end.push(this.sourceToken);
@@ -684,15 +681,14 @@ class Parser {
684
681
  yield* this.step();
685
682
  }
686
683
  *blockSequence(seq) {
687
- var _a;
688
684
  const it = seq.items[seq.items.length - 1];
689
685
  switch (this.type) {
690
686
  case 'newline':
691
687
  if (it.value) {
692
688
  const end = 'end' in it.value ? it.value.end : undefined;
693
689
  const last = Array.isArray(end) ? end[end.length - 1] : undefined;
694
- if ((last === null || last === void 0 ? void 0 : last.type) === 'comment')
695
- end === null || end === void 0 ? void 0 : end.push(this.sourceToken);
690
+ if (last?.type === 'comment')
691
+ end?.push(this.sourceToken);
696
692
  else
697
693
  seq.items.push({ start: [this.sourceToken] });
698
694
  }
@@ -706,7 +702,7 @@ class Parser {
706
702
  else {
707
703
  if (this.atIndentedComment(it.start, seq.indent)) {
708
704
  const prev = seq.items[seq.items.length - 2];
709
- const end = (_a = prev === null || prev === void 0 ? void 0 : prev.value) === null || _a === void 0 ? void 0 : _a.end;
705
+ const end = prev?.value?.end;
710
706
  if (Array.isArray(end)) {
711
707
  Array.prototype.push.apply(end, it.start);
712
708
  end.push(this.sourceToken);
@@ -23,7 +23,7 @@ function parseOptions(options) {
23
23
  */
24
24
  function parseAllDocuments(source, options = {}) {
25
25
  const { lineCounter, prettyErrors } = parseOptions(options);
26
- const parser$1 = new parser.Parser(lineCounter === null || lineCounter === void 0 ? void 0 : lineCounter.addNewLine);
26
+ const parser$1 = new parser.Parser(lineCounter?.addNewLine);
27
27
  const composer$1 = new composer.Composer(options);
28
28
  const docs = Array.from(composer$1.compose(parser$1.parse(source)));
29
29
  if (prettyErrors && lineCounter)
@@ -38,7 +38,7 @@ function parseAllDocuments(source, options = {}) {
38
38
  /** Parse an input string into a single YAML.Document */
39
39
  function parseDocument(source, options = {}) {
40
40
  const { lineCounter, prettyErrors } = parseOptions(options);
41
- const parser$1 = new parser.Parser(lineCounter === null || lineCounter === void 0 ? void 0 : lineCounter.addNewLine);
41
+ const parser$1 = new parser.Parser(lineCounter?.addNewLine);
42
42
  const composer$1 = new composer.Composer(options);
43
43
  // `doc` is always set by compose.end(true) at the very latest
44
44
  let doc = null;
@@ -77,7 +77,6 @@ function parse(src, reviver, options) {
77
77
  return doc.toJS(Object.assign({ reviver: _reviver }, options));
78
78
  }
79
79
  function stringify(value, replacer, options) {
80
- var _a;
81
80
  let _replacer = null;
82
81
  if (typeof replacer === 'function' || Array.isArray(replacer)) {
83
82
  _replacer = replacer;
@@ -92,7 +91,7 @@ function stringify(value, replacer, options) {
92
91
  options = indent < 1 ? undefined : indent > 8 ? { indent: 8 } : { indent };
93
92
  }
94
93
  if (value === undefined) {
95
- const { keepUndefined } = (_a = options !== null && options !== void 0 ? options : replacer) !== null && _a !== void 0 ? _a : {};
94
+ const { keepUndefined } = options ?? replacer ?? {};
96
95
  if (!keepUndefined)
97
96
  return undefined;
98
97
  }
@@ -18,7 +18,7 @@ class Schema {
18
18
  this.name = (typeof schema === 'string' && schema) || 'core';
19
19
  this.knownTags = resolveKnownTags ? tags.coreKnownTags : {};
20
20
  this.tags = tags.getTags(customTags, this.name);
21
- this.toStringOptions = toStringDefaults !== null && toStringDefaults !== void 0 ? toStringDefaults : null;
21
+ this.toStringOptions = toStringDefaults ?? null;
22
22
  Object.defineProperty(this, Node.MAP, { value: map.map });
23
23
  Object.defineProperty(this, Node.SCALAR, { value: string.string });
24
24
  Object.defineProperty(this, Node.SEQ, { value: seq.seq });
@@ -0,0 +1,69 @@
1
+ declare type JsonSchema = boolean | ArraySchema | ObjectSchema | NumberSchema | StringSchema;
2
+ declare type JsonType = 'array' | 'object' | 'string' | 'number' | 'integer' | 'boolean' | 'null';
3
+ interface CommonSchema {
4
+ type?: JsonType | JsonType[];
5
+ const?: unknown;
6
+ enum?: unknown[];
7
+ format?: string;
8
+ allOf?: JsonSchema[];
9
+ anyOf?: JsonSchema[];
10
+ oneOf?: JsonSchema[];
11
+ not?: JsonSchema;
12
+ if?: JsonSchema;
13
+ then?: JsonSchema;
14
+ else?: JsonSchema;
15
+ $id?: string;
16
+ $defs?: Record<string, JsonSchema>;
17
+ $anchor?: string;
18
+ $dynamicAnchor?: string;
19
+ $ref?: string;
20
+ $dynamicRef?: string;
21
+ $schema?: string;
22
+ $vocabulary?: Record<string, boolean>;
23
+ $comment?: string;
24
+ default?: unknown;
25
+ deprecated?: boolean;
26
+ readOnly?: boolean;
27
+ writeOnly?: boolean;
28
+ title?: string;
29
+ description?: string;
30
+ examples?: unknown[];
31
+ }
32
+ interface ArraySchema extends CommonSchema {
33
+ prefixItems?: JsonSchema[];
34
+ items?: JsonSchema;
35
+ contains?: JsonSchema;
36
+ unevaluatedItems?: JsonSchema;
37
+ maxItems?: number;
38
+ minItems?: number;
39
+ uniqueItems?: boolean;
40
+ maxContains?: number;
41
+ minContains?: number;
42
+ }
43
+ interface ObjectSchema extends CommonSchema {
44
+ properties?: Record<string, JsonSchema>;
45
+ patternProperties?: Record<string, JsonSchema>;
46
+ additionalProperties?: JsonSchema;
47
+ propertyNames?: JsonSchema;
48
+ unevaluatedProperties?: JsonSchema;
49
+ maxProperties?: number;
50
+ minProperties?: number;
51
+ required?: string[];
52
+ dependentRequired?: Record<string, string[]>;
53
+ dependentSchemas?: Record<string, JsonSchema>;
54
+ }
55
+ interface StringSchema extends CommonSchema {
56
+ maxLength?: number;
57
+ minLength?: number;
58
+ patter?: string;
59
+ contentEncoding?: string;
60
+ contentMediaType?: string;
61
+ contentSchema?: JsonSchema;
62
+ }
63
+ interface NumberSchema extends CommonSchema {
64
+ multipleOf?: number;
65
+ maximum?: number;
66
+ exclusiveMaximum?: number;
67
+ minimum?: number;
68
+ exclusiveMinimum?: number;
69
+ }
@@ -8,9 +8,13 @@ export declare class YAMLOMap extends YAMLSeq {
8
8
  key: any;
9
9
  value: any;
10
10
  }, overwrite?: boolean | undefined) => void;
11
- delete: (key: any) => boolean;
12
- get: (key: any, keepScalar?: boolean | undefined) => unknown;
13
- has: (key: any) => boolean;
11
+ delete: (key: unknown) => boolean;
12
+ get: {
13
+ (key: unknown, keepScalar: true): import("../../index.js").Scalar<any> | undefined;
14
+ (key: unknown, keepScalar?: false | undefined): any;
15
+ (key: unknown, keepScalar?: boolean | undefined): any;
16
+ };
17
+ has: (key: unknown) => boolean;
14
18
  set: (key: any, value: any) => void;
15
19
  /**
16
20
  * If `ctx` is given, the return type is actually `Map<unknown, unknown>`,
@@ -24,7 +24,7 @@ class YAMLOMap extends YAMLSeq.YAMLSeq {
24
24
  if (!ctx)
25
25
  return super.toJSON(_);
26
26
  const map = new Map();
27
- if (ctx === null || ctx === void 0 ? void 0 : ctx.onCreate)
27
+ if (ctx?.onCreate)
28
28
  ctx.onCreate(map);
29
29
  for (const pair of this.items) {
30
30
  let key, value;
@@ -6,7 +6,6 @@ var Scalar = require('../../nodes/Scalar.js');
6
6
  var YAMLSeq = require('../../nodes/YAMLSeq.js');
7
7
 
8
8
  function resolvePairs(seq, onError) {
9
- var _a;
10
9
  if (Node.isSeq(seq)) {
11
10
  for (let i = 0; i < seq.items.length; ++i) {
12
11
  let item = seq.items[i];
@@ -21,7 +20,7 @@ function resolvePairs(seq, onError) {
21
20
  ? `${item.commentBefore}\n${pair.key.commentBefore}`
22
21
  : item.commentBefore;
23
22
  if (item.comment) {
24
- const cn = (_a = pair.value) !== null && _a !== void 0 ? _a : pair.key;
23
+ const cn = pair.value ?? pair.key;
25
24
  cn.comment = cn.comment
26
25
  ? `${item.comment}\n${cn.comment}`
27
26
  : item.comment;
@@ -12,9 +12,13 @@ export declare class YAMLSet<T = unknown> extends YAMLMap<T, Scalar<null> | null
12
12
  key: T;
13
13
  value: Scalar<null> | null;
14
14
  }): void;
15
- get(key?: T, keepPair?: boolean): unknown;
15
+ /**
16
+ * If `keepPair` is `true`, returns the Pair matching `key`.
17
+ * Otherwise, returns the value of that Pair's key.
18
+ */
19
+ get(key: unknown, keepPair?: boolean): any;
16
20
  set(key: T, value: boolean): void;
17
- /** Will throw; `value` must be boolean */
21
+ /** @deprecated Will throw; `value` must be boolean */
18
22
  set(key: T, value: null): void;
19
23
  toJSON(_?: unknown, ctx?: ToJSContext): any;
20
24
  toString(ctx?: StringifyContext, onComment?: () => void, onChompKeep?: () => void): string;
@@ -24,6 +24,10 @@ class YAMLSet extends YAMLMap.YAMLMap {
24
24
  if (!prev)
25
25
  this.items.push(pair);
26
26
  }
27
+ /**
28
+ * If `keepPair` is `true`, returns the Pair matching `key`.
29
+ * Otherwise, returns the value of that Pair's key.
30
+ */
27
31
  get(key, keepPair) {
28
32
  const pair = YAMLMap.findPair(this.items, key);
29
33
  return !keepPair && Node.isPair(pair)
@@ -45,26 +45,25 @@ function createStringifyContext(doc, options) {
45
45
  };
46
46
  }
47
47
  function getTagObject(tags, item) {
48
- var _a, _b, _c, _d;
49
48
  if (item.tag) {
50
49
  const match = tags.filter(t => t.tag === item.tag);
51
50
  if (match.length > 0)
52
- return (_a = match.find(t => t.format === item.format)) !== null && _a !== void 0 ? _a : match[0];
51
+ return match.find(t => t.format === item.format) ?? match[0];
53
52
  }
54
53
  let tagObj = undefined;
55
54
  let obj;
56
55
  if (Node.isScalar(item)) {
57
56
  obj = item.value;
58
- const match = tags.filter(t => { var _a; return (_a = t.identify) === null || _a === void 0 ? void 0 : _a.call(t, obj); });
57
+ const match = tags.filter(t => t.identify?.(obj));
59
58
  tagObj =
60
- (_b = match.find(t => t.format === item.format)) !== null && _b !== void 0 ? _b : match.find(t => !t.format);
59
+ match.find(t => t.format === item.format) ?? match.find(t => !t.format);
61
60
  }
62
61
  else {
63
62
  obj = item;
64
63
  tagObj = tags.find(t => t.nodeClass && obj instanceof t.nodeClass);
65
64
  }
66
65
  if (!tagObj) {
67
- const name = (_d = (_c = obj === null || obj === void 0 ? void 0 : obj.constructor) === null || _c === void 0 ? void 0 : _c.name) !== null && _d !== void 0 ? _d : typeof obj;
66
+ const name = obj?.constructor?.name ?? typeof obj;
68
67
  throw new Error(`Tag not resolved for ${name} value`);
69
68
  }
70
69
  return tagObj;
@@ -85,13 +84,12 @@ function stringifyProps(node, tagObj, { anchors: anchors$1, doc }) {
85
84
  return props.join(' ');
86
85
  }
87
86
  function stringify(item, ctx, onComment, onChompKeep) {
88
- var _a, _b;
89
87
  if (Node.isPair(item))
90
88
  return item.toString(ctx, onComment, onChompKeep);
91
89
  if (Node.isAlias(item)) {
92
90
  if (ctx.doc.directives)
93
91
  return item.toString(ctx);
94
- if ((_a = ctx.resolvedAliases) === null || _a === void 0 ? void 0 : _a.has(item)) {
92
+ if (ctx.resolvedAliases?.has(item)) {
95
93
  throw new TypeError(`Cannot stringify circular structure without alias nodes`);
96
94
  }
97
95
  else {
@@ -110,7 +108,7 @@ function stringify(item, ctx, onComment, onChompKeep) {
110
108
  tagObj = getTagObject(ctx.doc.schema.tags, node);
111
109
  const props = stringifyProps(node, tagObj, ctx);
112
110
  if (props.length > 0)
113
- ctx.indentAtStart = ((_b = ctx.indentAtStart) !== null && _b !== void 0 ? _b : 0) + props.length + 1;
111
+ ctx.indentAtStart = (ctx.indentAtStart ?? 0) + props.length + 1;
114
112
  const str = typeof tagObj.stringify === 'function'
115
113
  ? tagObj.stringify(node, ctx, onComment, onChompKeep)
116
114
  : Node.isScalar(node)
@@ -6,8 +6,7 @@ var stringify = require('./stringify.js');
6
6
  var stringifyComment = require('./stringifyComment.js');
7
7
 
8
8
  function stringifyCollection(collection, ctx, options) {
9
- var _a;
10
- const flow = (_a = ctx.inFlow) !== null && _a !== void 0 ? _a : collection.flow;
9
+ const flow = ctx.inFlow ?? collection.flow;
11
10
  const stringify = flow ? stringifyFlowCollection : stringifyBlockCollection;
12
11
  return stringify(collection, ctx, options);
13
12
  }
@@ -5,7 +5,6 @@ var stringify = require('./stringify.js');
5
5
  var stringifyComment = require('./stringifyComment.js');
6
6
 
7
7
  function stringifyDocument(doc, options) {
8
- var _a;
9
8
  const lines = [];
10
9
  let hasDirectives = options.directives === true;
11
10
  if (options.directives !== false && doc.directives) {
@@ -57,7 +56,7 @@ function stringifyDocument(doc, options) {
57
56
  else {
58
57
  lines.push(stringify.stringify(doc.contents, ctx));
59
58
  }
60
- if ((_a = doc.directives) === null || _a === void 0 ? void 0 : _a.docEnd) {
59
+ if (doc.directives?.docEnd) {
61
60
  if (doc.comment) {
62
61
  const cs = commentString(doc.comment);
63
62
  if (cs.includes('\n')) {