yaml 2.8.0 → 2.8.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -20,6 +20,8 @@ This requirement may be updated between minor versions of the library.
20
20
 
21
21
  For more information, see the project's documentation site: [**eemeli.org/yaml**](https://eemeli.org/yaml/)
22
22
 
23
+ For build instructions and contribution guidelines, see [docs/CONTRIBUTING.md](docs/CONTRIBUTING.md).
24
+
23
25
  To install:
24
26
 
25
27
  ```sh
@@ -30,26 +32,6 @@ deno add jsr:@eemeli/yaml
30
32
 
31
33
  **Note:** These docs are for `yaml@2`. For v1, see the [v1.10.0 tag](https://github.com/eemeli/yaml/tree/v1.10.0) for the source and [eemeli.org/yaml/v1](https://eemeli.org/yaml/v1/) for the documentation.
32
34
 
33
- The development and maintenance of this library is [sponsored](https://github.com/sponsors/eemeli) by:
34
-
35
- <p align="center" width="100%">
36
- <a href="https://www.scipress.io/"
37
- ><img
38
- width="150"
39
- align="top"
40
- src="https://eemeli.org/yaml/images/scipress.svg"
41
- alt="Scipress"
42
- /></a>
43
- &nbsp; &nbsp;
44
- <a href="https://manifest.build/"
45
- ><img
46
- width="150"
47
- align="top"
48
- src="https://eemeli.org/yaml/images/manifest.svg"
49
- alt="Manifest"
50
- /></a>
51
- </p>
52
-
53
35
  ## API Overview
54
36
 
55
37
  The API provided by `yaml` has three layers, depending on how deep you need to go: [Parse & Stringify](https://eemeli.org/yaml/#parse-amp-stringify), [Documents](https://eemeli.org/yaml/#documents), and the underlying [Lexer/Parser/Composer](https://eemeli.org/yaml/#parsing-yaml).
@@ -59,7 +59,7 @@ function composeCollection(CN, ctx, token, props, onError) {
59
59
  let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType);
60
60
  if (!tag) {
61
61
  const kt = ctx.schema.knownTags[tagName];
62
- if (kt && kt.collection === expType) {
62
+ if (kt?.collection === expType) {
63
63
  ctx.schema.tags.push(Object.assign({}, kt, { default: false }));
64
64
  tag = kt;
65
65
  }
@@ -22,7 +22,7 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, ta
22
22
  });
23
23
  if (!props.found) {
24
24
  if (props.anchor || props.tag || value) {
25
- if (value && value.type === 'block-seq')
25
+ if (value?.type === 'block-seq')
26
26
  onError(props.end, 'BAD_INDENT', 'All sequence items must start at the same column');
27
27
  else
28
28
  onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
@@ -133,7 +133,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
133
133
  }
134
134
  }
135
135
  else if (value) {
136
- if ('source' in value && value.source && value.source[0] === ':')
136
+ if ('source' in value && value.source?.[0] === ':')
137
137
  onError(value, 'MISSING_CHAR', `Missing space after : in ${fcName}`);
138
138
  else
139
139
  onError(valueProps.start, 'MISSING_CHAR', `Missing , or : between ${fcName} items`);
@@ -177,7 +177,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
177
177
  const expectedEnd = isMap ? '}' : ']';
178
178
  const [ce, ...ee] = fc.end;
179
179
  let cePos = offset;
180
- if (ce && ce.source === expectedEnd)
180
+ if (ce?.source === expectedEnd)
181
181
  cePos = ce.offset + ce.source.length;
182
182
  else {
183
183
  const name = fcName[0].toUpperCase() + fcName.substring(1);
@@ -46,7 +46,7 @@ const prettifyError = (src, lc) => (error) => {
46
46
  if (/[^ ]/.test(lineStr)) {
47
47
  let count = 1;
48
48
  const end = error.linePos[1];
49
- if (end && end.line === line && end.col > col) {
49
+ if (end?.line === line && end.col > col) {
50
50
  count = Math.max(1, Math.min(end.col - col, 80 - ci));
51
51
  }
52
52
  const pointer = ' '.repeat(ci) + '^'.repeat(count);
@@ -59,7 +59,7 @@ class Alias extends NodeBase {
59
59
  data = anchors.get(source);
60
60
  }
61
61
  /* istanbul ignore if */
62
- if (!data || data.res === undefined) {
62
+ if (data?.res === undefined) {
63
63
  const msg = 'This should not happen: Alias anchor was not resolved?';
64
64
  throw new ReferenceError(msg);
65
65
  }
@@ -226,7 +226,7 @@ class Parser {
226
226
  }
227
227
  *step() {
228
228
  const top = this.peek(1);
229
- if (this.type === 'doc-end' && (!top || top.type !== 'doc-end')) {
229
+ if (this.type === 'doc-end' && top?.type !== 'doc-end') {
230
230
  while (this.stack.length > 0)
231
231
  yield* this.pop();
232
232
  this.stack.push({
@@ -758,7 +758,7 @@ class Parser {
758
758
  do {
759
759
  yield* this.pop();
760
760
  top = this.peek(1);
761
- } while (top && top.type === 'flow-collection');
761
+ } while (top?.type === 'flow-collection');
762
762
  }
763
763
  else if (fc.end.length === 0) {
764
764
  switch (this.type) {
@@ -4,7 +4,7 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) {
4
4
  const num = typeof value === 'number' ? value : Number(value);
5
5
  if (!isFinite(num))
6
6
  return isNaN(num) ? '.nan' : num < 0 ? '-.inf' : '.inf';
7
- let n = JSON.stringify(value);
7
+ let n = Object.is(value, -0) ? '-0' : JSON.stringify(value);
8
8
  if (!format &&
9
9
  minFractionDigits &&
10
10
  (!tag || tag === 'tag:yaml.org,2002:float') &&
@@ -101,7 +101,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
101
101
  ws += `\n${indentComment(cs, ctx.indent)}`;
102
102
  }
103
103
  if (valueStr === '' && !ctx.inFlow) {
104
- if (ws === '\n')
104
+ if (ws === '\n' && valueComment)
105
105
  ws = '\n\n';
106
106
  }
107
107
  else {
@@ -159,7 +159,7 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
159
159
  const { blockQuote, commentString, lineWidth } = ctx.options;
160
160
  // 1. Block can't end in whitespace unless the last line is non-empty.
161
161
  // 2. Strings consisting of only whitespace are best rendered explicitly.
162
- if (!blockQuote || /\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
162
+ if (!blockQuote || /\n[\t ]+$/.test(value)) {
163
163
  return quotedString(value, ctx);
164
164
  }
165
165
  const indent = ctx.indent ||
@@ -61,7 +61,7 @@ function composeCollection(CN, ctx, token, props, onError) {
61
61
  let tag = ctx.schema.tags.find(t => t.tag === tagName && t.collection === expType);
62
62
  if (!tag) {
63
63
  const kt = ctx.schema.knownTags[tagName];
64
- if (kt && kt.collection === expType) {
64
+ if (kt?.collection === expType) {
65
65
  ctx.schema.tags.push(Object.assign({}, kt, { default: false }));
66
66
  tag = kt;
67
67
  }
@@ -24,7 +24,7 @@ function resolveBlockSeq({ composeNode, composeEmptyNode }, ctx, bs, onError, ta
24
24
  });
25
25
  if (!props.found) {
26
26
  if (props.anchor || props.tag || value) {
27
- if (value && value.type === 'block-seq')
27
+ if (value?.type === 'block-seq')
28
28
  onError(props.end, 'BAD_INDENT', 'All sequence items must start at the same column');
29
29
  else
30
30
  onError(offset, 'MISSING_CHAR', 'Sequence item without - indicator');
@@ -135,7 +135,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
135
135
  }
136
136
  }
137
137
  else if (value) {
138
- if ('source' in value && value.source && value.source[0] === ':')
138
+ if ('source' in value && value.source?.[0] === ':')
139
139
  onError(value, 'MISSING_CHAR', `Missing space after : in ${fcName}`);
140
140
  else
141
141
  onError(valueProps.start, 'MISSING_CHAR', `Missing , or : between ${fcName} items`);
@@ -179,7 +179,7 @@ function resolveFlowCollection({ composeNode, composeEmptyNode }, ctx, fc, onErr
179
179
  const expectedEnd = isMap ? '}' : ']';
180
180
  const [ce, ...ee] = fc.end;
181
181
  let cePos = offset;
182
- if (ce && ce.source === expectedEnd)
182
+ if (ce?.source === expectedEnd)
183
183
  cePos = ce.offset + ce.source.length;
184
184
  else {
185
185
  const name = fcName[0].toUpperCase() + fcName.substring(1);
package/dist/errors.js CHANGED
@@ -48,7 +48,7 @@ const prettifyError = (src, lc) => (error) => {
48
48
  if (/[^ ]/.test(lineStr)) {
49
49
  let count = 1;
50
50
  const end = error.linePos[1];
51
- if (end && end.line === line && end.col > col) {
51
+ if (end?.line === line && end.col > col) {
52
52
  count = Math.max(1, Math.min(end.col - col, 80 - ci));
53
53
  }
54
54
  const pointer = ' '.repeat(ci) + '^'.repeat(count);
@@ -61,7 +61,7 @@ class Alias extends Node.NodeBase {
61
61
  data = anchors.get(source);
62
62
  }
63
63
  /* istanbul ignore if */
64
- if (!data || data.res === undefined) {
64
+ if (data?.res === undefined) {
65
65
  const msg = 'This should not happen: Alias anchor was not resolved?';
66
66
  throw new ReferenceError(msg);
67
67
  }
@@ -231,7 +231,7 @@ class Parser {
231
231
  }
232
232
  *step() {
233
233
  const top = this.peek(1);
234
- if (this.type === 'doc-end' && (!top || top.type !== 'doc-end')) {
234
+ if (this.type === 'doc-end' && top?.type !== 'doc-end') {
235
235
  while (this.stack.length > 0)
236
236
  yield* this.pop();
237
237
  this.stack.push({
@@ -763,7 +763,7 @@ class Parser {
763
763
  do {
764
764
  yield* this.pop();
765
765
  top = this.peek(1);
766
- } while (top && top.type === 'flow-collection');
766
+ } while (top?.type === 'flow-collection');
767
767
  }
768
768
  else if (fc.end.length === 0) {
769
769
  switch (this.type) {
@@ -6,7 +6,7 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) {
6
6
  const num = typeof value === 'number' ? value : Number(value);
7
7
  if (!isFinite(num))
8
8
  return isNaN(num) ? '.nan' : num < 0 ? '-.inf' : '.inf';
9
- let n = JSON.stringify(value);
9
+ let n = Object.is(value, -0) ? '-0' : JSON.stringify(value);
10
10
  if (!format &&
11
11
  minFractionDigits &&
12
12
  (!tag || tag === 'tag:yaml.org,2002:float') &&
@@ -103,7 +103,7 @@ function stringifyPair({ key, value }, ctx, onComment, onChompKeep) {
103
103
  ws += `\n${stringifyComment.indentComment(cs, ctx.indent)}`;
104
104
  }
105
105
  if (valueStr === '' && !ctx.inFlow) {
106
- if (ws === '\n')
106
+ if (ws === '\n' && valueComment)
107
107
  ws = '\n\n';
108
108
  }
109
109
  else {
@@ -161,7 +161,7 @@ function blockString({ comment, type, value }, ctx, onComment, onChompKeep) {
161
161
  const { blockQuote, commentString, lineWidth } = ctx.options;
162
162
  // 1. Block can't end in whitespace unless the last line is non-empty.
163
163
  // 2. Strings consisting of only whitespace are best rendered explicitly.
164
- if (!blockQuote || /\n[\t ]+$/.test(value) || /^\s*$/.test(value)) {
164
+ if (!blockQuote || /\n[\t ]+$/.test(value)) {
165
165
  return quotedString(value, ctx);
166
166
  }
167
167
  const indent = ctx.indent ||
package/package.json CHANGED
@@ -1,8 +1,9 @@
1
1
  {
2
2
  "name": "yaml",
3
- "version": "2.8.0",
3
+ "version": "2.8.2",
4
4
  "license": "ISC",
5
5
  "author": "Eemeli Aro <eemeli@gmail.com>",
6
+ "funding": "https://github.com/sponsors/eemeli",
6
7
  "repository": "github:eemeli/yaml",
7
8
  "description": "JavaScript parser and stringifier for YAML",
8
9
  "keywords": [
@@ -73,16 +74,16 @@
73
74
  "@babel/preset-env": "^7.12.11",
74
75
  "@eslint/js": "^9.9.1",
75
76
  "@rollup/plugin-babel": "^6.0.3",
76
- "@rollup/plugin-replace": "^5.0.2",
77
+ "@rollup/plugin-replace": "^6.0.3",
77
78
  "@rollup/plugin-typescript": "^12.1.1",
78
79
  "@types/jest": "^29.2.4",
79
80
  "@types/node": "^20.11.20",
80
81
  "babel-jest": "^29.0.1",
81
- "cross-env": "^7.0.3",
82
82
  "eslint": "^9.9.1",
83
- "eslint-config-prettier": "^9.0.0",
83
+ "eslint-config-prettier": "^10.1.8",
84
84
  "fast-check": "^2.12.0",
85
85
  "jest": "^29.0.1",
86
+ "jest-resolve": "^29.7.0",
86
87
  "jest-ts-webcompat-resolver": "^1.0.0",
87
88
  "prettier": "^3.0.2",
88
89
  "rollup": "^4.12.0",