yaml 2.4.5 → 2.5.1

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 (37) hide show
  1. package/browser/dist/compose/compose-collection.js +15 -3
  2. package/browser/dist/compose/compose-node.js +1 -1
  3. package/browser/dist/compose/resolve-block-map.js +1 -1
  4. package/browser/dist/compose/resolve-flow-collection.js +2 -0
  5. package/browser/dist/compose/resolve-flow-scalar.js +1 -1
  6. package/browser/dist/compose/resolve-props.js +3 -3
  7. package/browser/dist/doc/applyReviver.js +1 -0
  8. package/browser/dist/log.js +0 -2
  9. package/browser/dist/nodes/Collection.js +0 -1
  10. package/browser/dist/parse/lexer.js +2 -6
  11. package/browser/dist/parse/parser.js +3 -1
  12. package/browser/dist/stringify/foldFlowLines.js +2 -0
  13. package/dist/cli.d.ts +1 -2
  14. package/dist/cli.mjs +8 -4
  15. package/dist/compose/compose-collection.d.ts +7 -1
  16. package/dist/compose/compose-collection.js +15 -3
  17. package/dist/compose/compose-node.d.ts +1 -0
  18. package/dist/compose/compose-node.js +1 -1
  19. package/dist/compose/resolve-block-map.d.ts +1 -2
  20. package/dist/compose/resolve-block-map.js +1 -1
  21. package/dist/compose/resolve-block-seq.d.ts +1 -1
  22. package/dist/compose/resolve-flow-collection.js +2 -0
  23. package/dist/compose/resolve-flow-scalar.js +1 -1
  24. package/dist/compose/resolve-props.d.ts +1 -1
  25. package/dist/compose/resolve-props.js +3 -3
  26. package/dist/doc/applyReviver.js +1 -0
  27. package/dist/log.js +0 -2
  28. package/dist/nodes/Collection.d.ts +0 -1
  29. package/dist/nodes/Collection.js +0 -1
  30. package/dist/nodes/Node.d.ts +1 -0
  31. package/dist/nodes/identity.d.ts +1 -1
  32. package/dist/parse/lexer.js +2 -6
  33. package/dist/parse/parser.js +3 -1
  34. package/dist/schema/yaml-1.1/omap.d.ts +3 -3
  35. package/dist/stringify/foldFlowLines.js +2 -0
  36. package/package.json +6 -8
  37. package/browser/dist/node_modules/tslib/tslib.es6.js +0 -21
@@ -23,10 +23,23 @@ function resolveCollection(CN, ctx, token, onError, tagName, tag) {
23
23
  coll.tag = tagName;
24
24
  return coll;
25
25
  }
26
- function composeCollection(CN, ctx, token, tagToken, onError) {
26
+ function composeCollection(CN, ctx, token, props, onError) {
27
+ const tagToken = props.tag;
27
28
  const tagName = !tagToken
28
29
  ? null
29
30
  : ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg));
31
+ if (token.type === 'block-seq') {
32
+ const { anchor, newlineAfterProp: nl } = props;
33
+ const lastProp = anchor && tagToken
34
+ ? anchor.offset > tagToken.offset
35
+ ? anchor
36
+ : tagToken
37
+ : (anchor ?? tagToken);
38
+ if (lastProp && (!nl || nl.offset < lastProp.offset)) {
39
+ const message = 'Missing newline after block sequence props';
40
+ onError(lastProp, 'MISSING_CHAR', message);
41
+ }
42
+ }
30
43
  const expType = token.type === 'block-map'
31
44
  ? 'map'
32
45
  : token.type === 'block-seq'
@@ -40,8 +53,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
40
53
  !tagName ||
41
54
  tagName === '!' ||
42
55
  (tagName === YAMLMap.tagName && expType === 'map') ||
43
- (tagName === YAMLSeq.tagName && expType === 'seq') ||
44
- !expType) {
56
+ (tagName === YAMLSeq.tagName && expType === 'seq')) {
45
57
  return resolveCollection(CN, ctx, token, onError, tagName);
46
58
  }
47
59
  let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType);
@@ -26,7 +26,7 @@ function composeNode(ctx, token, props, onError) {
26
26
  case 'block-map':
27
27
  case 'block-seq':
28
28
  case 'flow-collection':
29
- node = composeCollection(CN, ctx, token, tag, onError);
29
+ node = composeCollection(CN, ctx, token, props, onError);
30
30
  if (anchor)
31
31
  node.anchor = anchor.source.substring(1);
32
32
  break;
@@ -42,7 +42,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta
42
42
  }
43
43
  continue;
44
44
  }
45
- if (keyProps.hasNewlineAfterProp || containsNewline(key)) {
45
+ if (keyProps.newlineAfterProp || containsNewline(key)) {
46
46
  onError(key ?? start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
47
47
  }
48
48
  }
@@ -163,6 +163,8 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
163
163
  const map = new YAMLMap(ctx.schema);
164
164
  map.flow = true;
165
165
  map.items.push(pair);
166
+ const endRange = (valueNode ?? keyNode).range;
167
+ map.range = [keyNode.range[0], endRange[1], endRange[2]];
166
168
  coll.items.push(map);
167
169
  }
168
170
  offset = valueNode ? valueNode.range[2] : valueProps.end;
@@ -84,7 +84,7 @@ function foldLines(source) {
84
84
  first = new RegExp('(.*?)(?<![ \t])[ \t]*\r?\n', 'sy');
85
85
  line = new RegExp('[ \t]*(.*?)(?:(?<![ \t])[ \t]*)?\r?\n', 'sy');
86
86
  }
87
- catch (_) {
87
+ catch {
88
88
  first = /(.*?)[ \t]*\r?\n/sy;
89
89
  line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
90
90
  }
@@ -5,11 +5,11 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIn
5
5
  let comment = '';
6
6
  let commentSep = '';
7
7
  let hasNewline = false;
8
- let hasNewlineAfterProp = false;
9
8
  let reqSpace = false;
10
9
  let tab = null;
11
10
  let anchor = null;
12
11
  let tag = null;
12
+ let newlineAfterProp = null;
13
13
  let comma = null;
14
14
  let found = null;
15
15
  let start = null;
@@ -63,7 +63,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIn
63
63
  atNewline = true;
64
64
  hasNewline = true;
65
65
  if (anchor || tag)
66
- hasNewlineAfterProp = true;
66
+ newlineAfterProp = token;
67
67
  hasSpace = true;
68
68
  break;
69
69
  case 'anchor':
@@ -137,9 +137,9 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIn
137
137
  spaceBefore,
138
138
  comment,
139
139
  hasNewline,
140
- hasNewlineAfterProp,
141
140
  anchor,
142
141
  tag,
142
+ newlineAfterProp,
143
143
  end,
144
144
  start: start ?? end
145
145
  };
@@ -11,6 +11,7 @@ function applyReviver(reviver, obj, key, val) {
11
11
  for (let i = 0, len = val.length; i < len; ++i) {
12
12
  const v0 = val[i];
13
13
  const v1 = applyReviver(reviver, val, String(i), v0);
14
+ // eslint-disable-next-line @typescript-eslint/no-array-delete
14
15
  if (v1 === undefined)
15
16
  delete val[i];
16
17
  else if (v1 !== v0)
@@ -4,8 +4,6 @@ function debug(logLevel, ...messages) {
4
4
  }
5
5
  function warn(logLevel, warning) {
6
6
  if (logLevel === 'debug' || logLevel === 'warn') {
7
- // https://github.com/typescript-eslint/typescript-eslint/issues/7478
8
- // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
9
7
  if (typeof process !== 'undefined' && process.emitWarning)
10
8
  process.emitWarning(warning);
11
9
  else
@@ -143,6 +143,5 @@ class Collection extends NodeBase {
143
143
  }
144
144
  }
145
145
  }
146
- Collection.maxFlowStringSingleLineLength = 60;
147
146
 
148
147
  export { Collection, collectionFromPath, isEmptyPath };
@@ -290,15 +290,11 @@ class Lexer {
290
290
  if (!this.atEnd && !this.hasChars(4))
291
291
  return this.setNext('line-start');
292
292
  const s = this.peek(3);
293
- if (s === '---' && isEmpty(this.charAt(3))) {
293
+ if ((s === '---' || s === '...') && isEmpty(this.charAt(3))) {
294
294
  yield* this.pushCount(3);
295
295
  this.indentValue = 0;
296
296
  this.indentNext = 0;
297
- return 'doc';
298
- }
299
- else if (s === '...' && isEmpty(this.charAt(3))) {
300
- yield* this.pushCount(3);
301
- return 'stream';
297
+ return s === '---' ? 'doc' : 'stream';
302
298
  }
303
299
  }
304
300
  this.indentValue = yield* this.pushSpaces(false);
@@ -608,7 +608,9 @@ class Parser {
608
608
  const sep = it.sep;
609
609
  sep.push(this.sourceToken);
610
610
  // @ts-expect-error type guard is wrong here
611
- delete it.key, delete it.sep;
611
+ delete it.key;
612
+ // @ts-expect-error type guard is wrong here
613
+ delete it.sep;
612
614
  this.stack.push({
613
615
  type: 'block-map',
614
616
  offset: this.offset,
@@ -9,6 +9,8 @@ const FOLD_QUOTED = 'quoted';
9
9
  function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth = 80, minContentWidth = 20, onFold, onOverflow } = {}) {
10
10
  if (!lineWidth || lineWidth < 0)
11
11
  return text;
12
+ if (lineWidth < minContentWidth)
13
+ minContentWidth = 0;
12
14
  const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);
13
15
  if (text.length <= endStep)
14
16
  return text;
package/dist/cli.d.ts CHANGED
@@ -1,5 +1,4 @@
1
- /// <reference types="node" />
2
- export declare const help = "yaml: A command-line YAML processor and inspector\n\nReads stdin and writes output to stdout and errors & warnings to stderr.\n\nUsage:\n yaml Process a YAML stream, outputting it as YAML\n yaml cst Parse the CST of a YAML stream\n yaml lex Parse the lexical tokens of a YAML stream\n yaml valid Validate a YAML stream, returning 0 on success\n\nOptions:\n --help, -h Show this message.\n --json, -j Output JSON.\n\nAdditional options for bare \"yaml\" command:\n --doc, -d Output pretty-printed JS Document objects.\n --single, -1 Require the input to consist of a single YAML document.\n --strict, -s Stop on errors.\n --visit, -v Apply a visitor to each document (requires a path to import)\n --yaml 1.1 Set the YAML version. (default: 1.2)";
1
+ export declare const help = "yaml: A command-line YAML processor and inspector\n\nReads stdin and writes output to stdout and errors & warnings to stderr.\n\nUsage:\n yaml Process a YAML stream, outputting it as YAML\n yaml cst Parse the CST of a YAML stream\n yaml lex Parse the lexical tokens of a YAML stream\n yaml valid Validate a YAML stream, returning 0 on success\n\nOptions:\n --help, -h Show this message.\n --json, -j Output JSON.\n --indent 2 Output pretty-printed data, indented by the given number of spaces.\n\nAdditional options for bare \"yaml\" command:\n --doc, -d Output pretty-printed JS Document objects.\n --single, -1 Require the input to consist of a single YAML document.\n --strict, -s Stop on errors.\n --visit, -v Apply a visitor to each document (requires a path to import)\n --yaml 1.1 Set the YAML version. (default: 1.2)";
3
2
  export declare class UserError extends Error {
4
3
  static ARGS: number;
5
4
  static SINGLE: number;
package/dist/cli.mjs CHANGED
@@ -22,6 +22,7 @@ Usage:
22
22
  Options:
23
23
  --help, -h Show this message.
24
24
  --json, -j Output JSON.
25
+ --indent 2 Output pretty-printed data, indented by the given number of spaces.
25
26
 
26
27
  Additional options for bare "yaml" command:
27
28
  --doc, -d Output pretty-printed JS Document objects.
@@ -46,6 +47,7 @@ async function cli(stdin, done, argv) {
46
47
  options: {
47
48
  doc: { type: 'boolean', short: 'd' },
48
49
  help: { type: 'boolean', short: 'h' },
50
+ indent: { type: 'string', short: 'i' },
49
51
  json: { type: 'boolean', short: 'j' },
50
52
  single: { type: 'boolean', short: '1' },
51
53
  strict: { type: 'boolean', short: 's' },
@@ -58,6 +60,7 @@ async function cli(stdin, done, argv) {
58
60
  return done(new UserError(UserError.ARGS, error.message));
59
61
  }
60
62
  const { positionals: [mode], values: opt } = args;
63
+ let indent = Number(opt.indent);
61
64
  stdin.setEncoding('utf-8');
62
65
  // eslint-disable-next-line @typescript-eslint/prefer-nullish-coalescing
63
66
  switch (opt.help || mode) {
@@ -82,7 +85,7 @@ async function cli(stdin, done, argv) {
82
85
  for (const tok of lexer.lex('', false))
83
86
  add(tok);
84
87
  if (opt.json)
85
- console.log(JSON.stringify(data));
88
+ console.log(JSON.stringify(data, null, indent));
86
89
  done();
87
90
  });
88
91
  break;
@@ -104,7 +107,7 @@ async function cli(stdin, done, argv) {
104
107
  for (const tok of parser.parse('', false))
105
108
  add(tok);
106
109
  if (opt.json)
107
- console.log(JSON.stringify(data));
110
+ console.log(JSON.stringify(data, null, indent));
108
111
  done();
109
112
  });
110
113
  break;
@@ -153,7 +156,8 @@ async function cli(stdin, done, argv) {
153
156
  if (reqDocEnd)
154
157
  console.log('...');
155
158
  try {
156
- const str = String(doc);
159
+ indent || (indent = 2);
160
+ const str = doc.toString({ indent });
157
161
  console.log(str.endsWith('\n') ? str.slice(0, -1) : str);
158
162
  }
159
163
  catch (error) {
@@ -181,7 +185,7 @@ async function cli(stdin, done, argv) {
181
185
  return done(new UserError(UserError.SINGLE, 'Input stream contained no documents'));
182
186
  }
183
187
  if (mode !== 'valid' && opt.json) {
184
- console.log(JSON.stringify(opt.single ? data[0] : data));
188
+ console.log(JSON.stringify(opt.single ? data[0] : data, null, indent));
185
189
  }
186
190
  done();
187
191
  });
@@ -2,4 +2,10 @@ 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';
5
- export declare function composeCollection(CN: ComposeNode, ctx: ComposeContext, token: BlockMap | BlockSequence | FlowCollection, tagToken: SourceToken | null, onError: ComposeErrorHandler): ParsedNode;
5
+ interface Props {
6
+ anchor: SourceToken | null;
7
+ tag: SourceToken | null;
8
+ newlineAfterProp: SourceToken | null;
9
+ }
10
+ export declare function composeCollection(CN: ComposeNode, ctx: ComposeContext, token: BlockMap | BlockSequence | FlowCollection, props: Props, onError: ComposeErrorHandler): ParsedNode;
11
+ export {};
@@ -25,10 +25,23 @@ function resolveCollection(CN, ctx, token, onError, tagName, tag) {
25
25
  coll.tag = tagName;
26
26
  return coll;
27
27
  }
28
- function composeCollection(CN, ctx, token, tagToken, onError) {
28
+ function composeCollection(CN, ctx, token, props, onError) {
29
+ const tagToken = props.tag;
29
30
  const tagName = !tagToken
30
31
  ? null
31
32
  : ctx.directives.tagName(tagToken.source, msg => onError(tagToken, 'TAG_RESOLVE_FAILED', msg));
33
+ if (token.type === 'block-seq') {
34
+ const { anchor, newlineAfterProp: nl } = props;
35
+ const lastProp = anchor && tagToken
36
+ ? anchor.offset > tagToken.offset
37
+ ? anchor
38
+ : tagToken
39
+ : (anchor ?? tagToken);
40
+ if (lastProp && (!nl || nl.offset < lastProp.offset)) {
41
+ const message = 'Missing newline after block sequence props';
42
+ onError(lastProp, 'MISSING_CHAR', message);
43
+ }
44
+ }
32
45
  const expType = token.type === 'block-map'
33
46
  ? 'map'
34
47
  : token.type === 'block-seq'
@@ -42,8 +55,7 @@ function composeCollection(CN, ctx, token, tagToken, onError) {
42
55
  !tagName ||
43
56
  tagName === '!' ||
44
57
  (tagName === YAMLMap.YAMLMap.tagName && expType === 'map') ||
45
- (tagName === YAMLSeq.YAMLSeq.tagName && expType === 'seq') ||
46
- !expType) {
58
+ (tagName === YAMLSeq.YAMLSeq.tagName && expType === 'seq')) {
47
59
  return resolveCollection(CN, ctx, token, onError, tagName);
48
60
  }
49
61
  let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType);
@@ -15,6 +15,7 @@ interface Props {
15
15
  comment: string;
16
16
  anchor: SourceToken | null;
17
17
  tag: SourceToken | null;
18
+ newlineAfterProp: SourceToken | null;
18
19
  end: number;
19
20
  }
20
21
  declare const CN: {
@@ -28,7 +28,7 @@ function composeNode(ctx, token, props, onError) {
28
28
  case 'block-map':
29
29
  case 'block-seq':
30
30
  case 'flow-collection':
31
- node = composeCollection.composeCollection(CN, ctx, token, tag, onError);
31
+ node = composeCollection.composeCollection(CN, ctx, token, props, onError);
32
32
  if (anchor)
33
33
  node.anchor = anchor.source.substring(1);
34
34
  break;
@@ -1,7 +1,6 @@
1
- import type { ParsedNode } from '../nodes/Node.js';
2
1
  import { YAMLMap } from '../nodes/YAMLMap.js';
3
2
  import type { BlockMap } from '../parse/cst.js';
4
3
  import { CollectionTag } from '../schema/types.js';
5
4
  import type { ComposeContext, ComposeNode } from './compose-node.js';
6
5
  import type { ComposeErrorHandler } from './composer.js';
7
- export declare function resolveBlockMap({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bm: BlockMap, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLMap.Parsed<ParsedNode, ParsedNode | null>;
6
+ export declare function resolveBlockMap({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bm: BlockMap, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLMap.Parsed;
@@ -44,7 +44,7 @@ function resolveBlockMap({ composeNode, composeEmptyNode }, ctx, bm, onError, ta
44
44
  }
45
45
  continue;
46
46
  }
47
- if (keyProps.hasNewlineAfterProp || utilContainsNewline.containsNewline(key)) {
47
+ if (keyProps.newlineAfterProp || utilContainsNewline.containsNewline(key)) {
48
48
  onError(key ?? start[start.length - 1], 'MULTILINE_IMPLICIT_KEY', 'Implicit keys need to be on a single line');
49
49
  }
50
50
  }
@@ -3,4 +3,4 @@ import type { BlockSequence } from '../parse/cst.js';
3
3
  import { CollectionTag } from '../schema/types.js';
4
4
  import type { ComposeContext, ComposeNode } from './compose-node.js';
5
5
  import type { ComposeErrorHandler } from './composer.js';
6
- export declare function resolveBlockSeq({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bs: BlockSequence, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLSeq.Parsed<import("../index.js").ParsedNode>;
6
+ export declare function resolveBlockSeq({ composeNode, composeEmptyNode }: ComposeNode, ctx: ComposeContext, bs: BlockSequence, onError: ComposeErrorHandler, tag?: CollectionTag): YAMLSeq.Parsed;
@@ -165,6 +165,8 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
165
165
  const map = new YAMLMap.YAMLMap(ctx.schema);
166
166
  map.flow = true;
167
167
  map.items.push(pair);
168
+ const endRange = (valueNode ?? keyNode).range;
169
+ map.range = [keyNode.range[0], endRange[1], endRange[2]];
168
170
  coll.items.push(map);
169
171
  }
170
172
  offset = valueNode ? valueNode.range[2] : valueProps.end;
@@ -86,7 +86,7 @@ function foldLines(source) {
86
86
  first = new RegExp('(.*?)(?<![ \t])[ \t]*\r?\n', 'sy');
87
87
  line = new RegExp('[ \t]*(.*?)(?:(?<![ \t])[ \t]*)?\r?\n', 'sy');
88
88
  }
89
- catch (_) {
89
+ catch {
90
90
  first = /(.*?)[ \t]*\r?\n/sy;
91
91
  line = /[ \t]*(.*?)[ \t]*\r?\n/sy;
92
92
  }
@@ -15,9 +15,9 @@ export declare function resolveProps(tokens: SourceToken[], { flow, indicator, n
15
15
  spaceBefore: boolean;
16
16
  comment: string;
17
17
  hasNewline: boolean;
18
- hasNewlineAfterProp: boolean;
19
18
  anchor: SourceToken | null;
20
19
  tag: SourceToken | null;
20
+ newlineAfterProp: SourceToken | null;
21
21
  end: number;
22
22
  start: number;
23
23
  };
@@ -7,11 +7,11 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIn
7
7
  let comment = '';
8
8
  let commentSep = '';
9
9
  let hasNewline = false;
10
- let hasNewlineAfterProp = false;
11
10
  let reqSpace = false;
12
11
  let tab = null;
13
12
  let anchor = null;
14
13
  let tag = null;
14
+ let newlineAfterProp = null;
15
15
  let comma = null;
16
16
  let found = null;
17
17
  let start = null;
@@ -65,7 +65,7 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIn
65
65
  atNewline = true;
66
66
  hasNewline = true;
67
67
  if (anchor || tag)
68
- hasNewlineAfterProp = true;
68
+ newlineAfterProp = token;
69
69
  hasSpace = true;
70
70
  break;
71
71
  case 'anchor':
@@ -139,9 +139,9 @@ function resolveProps(tokens, { flow, indicator, next, offset, onError, parentIn
139
139
  spaceBefore,
140
140
  comment,
141
141
  hasNewline,
142
- hasNewlineAfterProp,
143
142
  anchor,
144
143
  tag,
144
+ newlineAfterProp,
145
145
  end,
146
146
  start: start ?? end
147
147
  };
@@ -13,6 +13,7 @@ function applyReviver(reviver, obj, key, val) {
13
13
  for (let i = 0, len = val.length; i < len; ++i) {
14
14
  const v0 = val[i];
15
15
  const v1 = applyReviver(reviver, val, String(i), v0);
16
+ // eslint-disable-next-line @typescript-eslint/no-array-delete
16
17
  if (v1 === undefined)
17
18
  delete val[i];
18
19
  else if (v1 !== v0)
package/dist/log.js CHANGED
@@ -6,8 +6,6 @@ function debug(logLevel, ...messages) {
6
6
  }
7
7
  function warn(logLevel, warning) {
8
8
  if (logLevel === 'debug' || logLevel === 'warn') {
9
- // https://github.com/typescript-eslint/typescript-eslint/issues/7478
10
- // eslint-disable-next-line @typescript-eslint/prefer-optional-chain
11
9
  if (typeof process !== 'undefined' && process.emitWarning)
12
10
  process.emitWarning(warning);
13
11
  else
@@ -4,7 +4,6 @@ import { NodeBase } from './Node.js';
4
4
  export declare function collectionFromPath(schema: Schema, path: unknown[], value: unknown): import("./Node.js").Node;
5
5
  export declare const isEmptyPath: (path: Iterable<unknown> | null | undefined) => path is null | undefined;
6
6
  export declare abstract class Collection extends NodeBase {
7
- static maxFlowStringSingleLineLength: number;
8
7
  schema: Schema | undefined;
9
8
  [NODE_TYPE]: symbol;
10
9
  items: unknown[];
@@ -145,7 +145,6 @@ class Collection extends Node.NodeBase {
145
145
  }
146
146
  }
147
147
  }
148
- Collection.maxFlowStringSingleLineLength = 60;
149
148
 
150
149
  exports.Collection = Collection;
151
150
  exports.collectionFromPath = collectionFromPath;
@@ -15,6 +15,7 @@ export type NodeType<T> = T extends string | number | bigint | boolean | null |
15
15
  [key: number]: any;
16
16
  } ? YAMLMap<NodeType<keyof T>, NodeType<T[keyof T]>> : Node;
17
17
  export type ParsedNode = Alias.Parsed | Scalar.Parsed | YAMLMap.Parsed | YAMLSeq.Parsed;
18
+ /** `[start, value-end, node-end]` */
18
19
  export type Range = [number, number, number];
19
20
  export declare abstract class NodeBase {
20
21
  readonly [NODE_TYPE]: symbol;
@@ -13,7 +13,7 @@ export declare const SCALAR: unique symbol;
13
13
  export declare const SEQ: unique symbol;
14
14
  export declare const NODE_TYPE: unique symbol;
15
15
  export declare const isAlias: (node: any) => node is Alias;
16
- export declare const isDocument: <T extends Node = Node>(node: any) => node is Document<T, true>;
16
+ export declare const isDocument: <T extends Node = Node>(node: any) => node is Document<T>;
17
17
  export declare const isMap: <K = unknown, V = unknown>(node: any) => node is YAMLMap<K, V>;
18
18
  export declare const isPair: <K = unknown, V = unknown>(node: any) => node is Pair<K, V>;
19
19
  export declare const isScalar: <T = unknown>(node: any) => node is Scalar<T>;
@@ -292,15 +292,11 @@ class Lexer {
292
292
  if (!this.atEnd && !this.hasChars(4))
293
293
  return this.setNext('line-start');
294
294
  const s = this.peek(3);
295
- if (s === '---' && isEmpty(this.charAt(3))) {
295
+ if ((s === '---' || s === '...') && isEmpty(this.charAt(3))) {
296
296
  yield* this.pushCount(3);
297
297
  this.indentValue = 0;
298
298
  this.indentNext = 0;
299
- return 'doc';
300
- }
301
- else if (s === '...' && isEmpty(this.charAt(3))) {
302
- yield* this.pushCount(3);
303
- return 'stream';
299
+ return s === '---' ? 'doc' : 'stream';
304
300
  }
305
301
  }
306
302
  this.indentValue = yield* this.pushSpaces(false);
@@ -612,7 +612,9 @@ class Parser {
612
612
  const sep = it.sep;
613
613
  sep.push(this.sourceToken);
614
614
  // @ts-expect-error type guard is wrong here
615
- delete it.key, delete it.sep;
615
+ delete it.key;
616
+ // @ts-expect-error type guard is wrong here
617
+ delete it.sep;
616
618
  this.stack.push({
617
619
  type: 'block-map',
618
620
  offset: this.offset,
@@ -9,12 +9,12 @@ export declare class YAMLOMap extends YAMLSeq {
9
9
  add: (pair: import("../../index.js").Pair<any, any> | {
10
10
  key: any;
11
11
  value: any;
12
- }, overwrite?: boolean | undefined) => void;
12
+ }, overwrite?: boolean) => void;
13
13
  delete: (key: unknown) => boolean;
14
14
  get: {
15
15
  (key: unknown, keepScalar: true): import("../../index.js").Scalar<any> | undefined;
16
- (key: unknown, keepScalar?: false | undefined): any;
17
- (key: unknown, keepScalar?: boolean | undefined): any;
16
+ (key: unknown, keepScalar?: false): any;
17
+ (key: unknown, keepScalar?: boolean): any;
18
18
  };
19
19
  has: (key: unknown) => boolean;
20
20
  set: (key: any, value: any) => void;
@@ -11,6 +11,8 @@ const FOLD_QUOTED = 'quoted';
11
11
  function foldFlowLines(text, indent, mode = 'flow', { indentAtStart, lineWidth = 80, minContentWidth = 20, onFold, onOverflow } = {}) {
12
12
  if (!lineWidth || lineWidth < 0)
13
13
  return text;
14
+ if (lineWidth < minContentWidth)
15
+ minContentWidth = 0;
14
16
  const endStep = Math.max(1 + minContentWidth, 1 + lineWidth - indent.length);
15
17
  if (text.length <= endStep)
16
18
  return text;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "yaml",
3
- "version": "2.4.5",
3
+ "version": "2.5.1",
4
4
  "license": "ISC",
5
5
  "author": "Eemeli Aro <eemeli@gmail.com>",
6
6
  "repository": "github:eemeli/yaml",
@@ -42,7 +42,7 @@
42
42
  "build:browser": "rollup -c config/rollup.browser-config.mjs",
43
43
  "build:node": "rollup -c config/rollup.node-config.mjs",
44
44
  "clean": "git clean -fdxe node_modules",
45
- "lint": "eslint src/",
45
+ "lint": "eslint config/ src/",
46
46
  "prettier": "prettier --write .",
47
47
  "prestart": "rollup --sourcemap -c config/rollup.node-config.mjs",
48
48
  "start": "node --enable-source-maps -i -e 'YAML=require(\"./dist/index.js\");const{parse,parseDocument,parseAllDocuments}=YAML'",
@@ -69,20 +69,17 @@
69
69
  },
70
70
  "devDependencies": {
71
71
  "@babel/core": "^7.12.10",
72
- "@babel/plugin-transform-class-properties": "^7.23.3",
73
- "@babel/plugin-transform-nullish-coalescing-operator": "^7.23.4",
74
72
  "@babel/plugin-transform-typescript": "^7.12.17",
75
73
  "@babel/preset-env": "^7.12.11",
74
+ "@eslint/js": "^9.9.1",
76
75
  "@rollup/plugin-babel": "^6.0.3",
77
76
  "@rollup/plugin-replace": "^5.0.2",
78
77
  "@rollup/plugin-typescript": "^11.0.0",
79
78
  "@types/jest": "^29.2.4",
80
79
  "@types/node": "^20.11.20",
81
- "@typescript-eslint/eslint-plugin": "^7.0.2",
82
- "@typescript-eslint/parser": "^7.0.2",
83
80
  "babel-jest": "^29.0.1",
84
81
  "cross-env": "^7.0.3",
85
- "eslint": "^8.2.0",
82
+ "eslint": "^9.9.1",
86
83
  "eslint-config-prettier": "^9.0.0",
87
84
  "fast-check": "^2.12.0",
88
85
  "jest": "^29.0.1",
@@ -90,7 +87,8 @@
90
87
  "prettier": "^3.0.2",
91
88
  "rollup": "^4.12.0",
92
89
  "tslib": "^2.1.0",
93
- "typescript": "^5.0.3"
90
+ "typescript": "^5.0.3",
91
+ "typescript-eslint": "^8.4.0"
94
92
  },
95
93
  "engines": {
96
94
  "node": ">= 14"
@@ -1,21 +0,0 @@
1
- /******************************************************************************
2
- Copyright (c) Microsoft Corporation.
3
-
4
- Permission to use, copy, modify, and/or distribute this software for any
5
- purpose with or without fee is hereby granted.
6
-
7
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
8
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
9
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
10
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
11
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
12
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
13
- PERFORMANCE OF THIS SOFTWARE.
14
- ***************************************************************************** */
15
- function __classPrivateFieldGet(receiver, state, kind, f) {
16
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
17
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
18
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
19
- }
20
-
21
- export { __classPrivateFieldGet };