yaml 3.0.0-1 → 3.0.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.
@@ -46,8 +46,10 @@ function foldFlowLines(text, indent, mode = "flow", { indentAtStart, lineWidth =
46
46
  const folds = [];
47
47
  const escapedFolds = {};
48
48
  let end = lineWidth - indent.length;
49
- if (typeof indentAtStart === "number") if (indentAtStart > lineWidth - Math.max(2, minContentWidth)) folds.push(0);
50
- else end = lineWidth - indentAtStart;
49
+ if (typeof indentAtStart === "number") {
50
+ if (indentAtStart > lineWidth - Math.max(2, minContentWidth)) folds.push(0);
51
+ else end = lineWidth - indentAtStart;
52
+ }
51
53
  let split = void 0;
52
54
  let prev = void 0;
53
55
  let overflow = false;
@@ -84,23 +86,25 @@ function foldFlowLines(text, indent, mode = "flow", { indentAtStart, lineWidth =
84
86
  const next = text[i + 1];
85
87
  if (next && next !== " " && next !== "\n" && next !== " ") split = i;
86
88
  }
87
- if (i >= end) if (split) {
88
- folds.push(split);
89
- end = split + endStep;
90
- split = void 0;
91
- } else if (mode === "quoted") {
92
- while (prev === " " || prev === " ") {
93
- prev = ch;
94
- ch = text[i += 1];
95
- overflow = true;
96
- }
97
- const j = i > escEnd + 1 ? i - 2 : escStart - 1;
98
- if (escapedFolds[j]) return text;
99
- folds.push(j);
100
- escapedFolds[j] = true;
101
- end = j + endStep;
102
- split = void 0;
103
- } else overflow = true;
89
+ if (i >= end) {
90
+ if (split) {
91
+ folds.push(split);
92
+ end = split + endStep;
93
+ split = void 0;
94
+ } else if (mode === "quoted") {
95
+ while (prev === " " || prev === " ") {
96
+ prev = ch;
97
+ ch = text[i += 1];
98
+ overflow = true;
99
+ }
100
+ const j = i > escEnd + 1 ? i - 2 : escStart - 1;
101
+ if (escapedFolds[j]) return text;
102
+ folds.push(j);
103
+ escapedFolds[j] = true;
104
+ end = j + endStep;
105
+ split = void 0;
106
+ } else overflow = true;
107
+ }
104
108
  }
105
109
  prev = ch;
106
110
  }
@@ -251,7 +255,7 @@ function quotedString(value, ctx) {
251
255
  }
252
256
  let blockEndNewlines;
253
257
  try {
254
- blockEndNewlines = /* @__PURE__ */ new RegExp("(^|(?<!\n))\n+(?!\n|$)", "g");
258
+ blockEndNewlines = new RegExp("(^|(?<!\n))\n+(?!\n|$)", "g");
255
259
  } catch {
256
260
  blockEndNewlines = /\n+(?!\n|$)/g;
257
261
  }
@@ -325,7 +329,7 @@ function plainString(item, ctx, onComment, onChompKeep) {
325
329
  }
326
330
  const str = value.replace(/\n+/g, `$&\n${indent}`);
327
331
  if (actualString) {
328
- const test = (tag) => tag.default && tag.tag !== "tag:yaml.org,2002:str" && tag.test?.test(str);
332
+ const test = (tag) => tag.default && tag.tag !== "tag:yaml.org,2002:str" && tag.test?.(str);
329
333
  const { compat, tags } = ctx.doc.schema;
330
334
  if (tags.some(test) || compat?.some(test)) return quotedString(value, ctx);
331
335
  }
@@ -498,8 +502,10 @@ function debug(logLevel, ...messages) {
498
502
  if (logLevel === "debug") console.log(...messages);
499
503
  }
500
504
  function warn(logLevel, warning) {
501
- if (logLevel === "debug" || logLevel === "warn") if (typeof process !== "undefined" && typeof process.emitWarning === "function") process.emitWarning(warning);
502
- else console.warn(warning);
505
+ if (logLevel === "debug" || logLevel === "warn") {
506
+ if (typeof process !== "undefined" && typeof process.emitWarning === "function") process.emitWarning(warning);
507
+ else console.warn(warning);
508
+ }
503
509
  }
504
510
  //#endregion
505
511
  //#region src/schema/yaml-1.1/merge.ts
@@ -508,55 +514,86 @@ const merge = {
508
514
  identify: (value) => value === MERGE_KEY || typeof value === "symbol" && value.description === MERGE_KEY,
509
515
  default: "key",
510
516
  tag: "tag:yaml.org,2002:merge",
511
- test: /^<<$/,
517
+ test: (str) => str === MERGE_KEY,
512
518
  resolve: () => Object.assign(new Scalar(Symbol(MERGE_KEY)), { addToJSMap: addMergeToJSMap }),
513
519
  stringify: () => MERGE_KEY
514
520
  };
515
521
  const isMergeKey = (doc, key) => (merge.identify(key) || key instanceof Scalar && (!key.type || key.type === Scalar.PLAIN) && merge.identify(key.value)) && Boolean(doc.schema.tags.some((tag) => tag.tag === merge.tag && tag.default));
516
- function addMergeToJSMap(doc, ctx, map, value) {
517
- value = ctx && value instanceof Alias ? value.resolve(doc, ctx) : value;
518
- if (Array.isArray(value) && !(value instanceof YAMLMap)) for (const it of value) mergeValue(doc, ctx, map, it);
519
- else mergeValue(doc, ctx, map, value);
522
+ function addMergeToJSMap(doc, ctx, map, value, isPlainObject) {
523
+ const source = getMergeSource(doc, ctx, value);
524
+ if (Array.isArray(source)) for (const it of source) mergeValue(doc, ctx, map, it, isPlainObject);
525
+ else mergeValue(doc, ctx, map, value, isPlainObject);
520
526
  }
521
- function mergeValue(doc, ctx, map, value) {
522
- const srcMap = (value instanceof Alias ? value.resolve(doc, ctx) : value).toJS(doc, ctx, Map);
527
+ function mergeValue(doc, ctx, map, value, isPlainObject) {
528
+ const srcMap = getMergeSource(doc, ctx, value).toJS(doc, ctx, Map);
523
529
  if (!(srcMap instanceof Map)) throw new Error("Merge sources must be maps or map aliases");
524
530
  for (const [key, value] of srcMap) if (map instanceof Map) {
525
531
  if (!map.has(key)) map.set(key, value);
526
532
  } else if (map instanceof Set) map.add(key);
527
- else if (!Object.prototype.hasOwnProperty.call(map, key)) Object.defineProperty(map, key, {
528
- value,
529
- writable: true,
530
- enumerable: true,
531
- configurable: true
532
- });
533
+ else if (!Object.prototype.hasOwnProperty.call(map, key)) {
534
+ if (!isPlainObject || key === "__proto__" || key === "constructor") Object.defineProperty(map, key, {
535
+ value,
536
+ writable: true,
537
+ enumerable: true,
538
+ configurable: true
539
+ });
540
+ else map[key] = value;
541
+ }
533
542
  return map;
534
543
  }
544
+ function getMergeSource(doc, ctx, value) {
545
+ if (!(value instanceof Alias)) return value;
546
+ const source = value.resolve(doc, ctx);
547
+ if (!source) {
548
+ const msg = `Unresolved alias (the anchor must be set before the alias): ${value.source}`;
549
+ throw new ReferenceError(msg);
550
+ }
551
+ ctx.resolveAlias(doc, source);
552
+ return source;
553
+ }
535
554
  //#endregion
536
555
  //#region src/stringify/stringify.ts
556
+ const defaultStringifyOptions = {
557
+ blockQuote: true,
558
+ commentString: stringifyComment,
559
+ defaultKeyType: null,
560
+ defaultStringType: "PLAIN",
561
+ directives: null,
562
+ doubleQuotedAsJSON: false,
563
+ doubleQuotedMinMultiLineLength: 40,
564
+ falseStr: "false",
565
+ flowCollectionPadding: true,
566
+ indentSeq: true,
567
+ lineWidth: 80,
568
+ minContentWidth: 20,
569
+ nullStr: "null",
570
+ simpleKeys: false,
571
+ singleQuote: null,
572
+ sortMapEntries: false,
573
+ trailingComma: false,
574
+ trueStr: "true",
575
+ verifyAliasOrder: true
576
+ };
577
+ const resolvedCache = /* @__PURE__ */ new WeakMap();
578
+ function getResolvedOptions(schema) {
579
+ const key = schema.toStringOptions ?? defaultStringifyOptions;
580
+ let resolved = resolvedCache.get(key);
581
+ if (!resolved) {
582
+ resolved = schema.toStringOptions ? {
583
+ ...defaultStringifyOptions,
584
+ ...schema.toStringOptions
585
+ } : defaultStringifyOptions;
586
+ resolvedCache.set(key, resolved);
587
+ }
588
+ return resolved;
589
+ }
537
590
  const sortMapEntriesByKey = (a, b) => a.key < b.key ? -1 : a.key > b.key ? 1 : 0;
538
591
  function createStringifyContext(doc, options) {
539
- const opt = Object.assign({
540
- blockQuote: true,
541
- commentString: stringifyComment,
542
- defaultKeyType: null,
543
- defaultStringType: "PLAIN",
544
- directives: null,
545
- doubleQuotedAsJSON: false,
546
- doubleQuotedMinMultiLineLength: 40,
547
- falseStr: "false",
548
- flowCollectionPadding: true,
549
- indentSeq: true,
550
- lineWidth: 80,
551
- minContentWidth: 20,
552
- nullStr: "null",
553
- simpleKeys: false,
554
- singleQuote: null,
555
- sortMapEntries: false,
556
- trailingComma: false,
557
- trueStr: "true",
558
- verifyAliasOrder: true
559
- }, doc.schema.toStringOptions, options);
592
+ const resolved = getResolvedOptions(doc.schema);
593
+ const opt = options ? {
594
+ ...resolved,
595
+ ...options
596
+ } : resolved;
560
597
  let inFlow;
561
598
  switch (opt.collectionStyle) {
562
599
  case "block":
@@ -584,7 +621,7 @@ function getTagObject(tags, item) {
584
621
  const match = tags.filter((t) => t.tag === item.tag);
585
622
  if (match.length > 0) return match.find((t) => t.format === item.format) ?? match[0];
586
623
  }
587
- let tagObj = void 0;
624
+ let tagObj;
588
625
  let obj;
589
626
  if (item instanceof Scalar) {
590
627
  obj = item.value;
@@ -622,7 +659,7 @@ function stringify(node, ctx, onComment, onChompKeep) {
622
659
  if (ctx.doc.directives) return node.toString(ctx);
623
660
  if (ctx.resolvedAliases?.has(node)) throw new TypeError("Cannot stringify circular structure without alias nodes");
624
661
  if (ctx.resolvedAliases) ctx.resolvedAliases.add(node);
625
- else ctx.resolvedAliases = new Set([node]);
662
+ else ctx.resolvedAliases = /* @__PURE__ */ new Set([node]);
626
663
  node = node.resolve(ctx.doc) ?? null;
627
664
  }
628
665
  let tagObj = void 0;
@@ -636,9 +673,9 @@ function stringify(node, ctx, onComment, onChompKeep) {
636
673
  }
637
674
  //#endregion
638
675
  //#region src/nodes/addPairToJSMap.ts
639
- function addPairToJSMap(doc, ctx, map, { key, value }) {
640
- if ("addToJSMap" in key) key.addToJSMap?.(doc, ctx, map, value);
641
- else if (isMergeKey(doc, key)) addMergeToJSMap(doc, ctx, map, value);
676
+ function addPairToJSMap(doc, ctx, map, { key, value }, isPlainObject) {
677
+ if ("addToJSMap" in key) key.addToJSMap?.(doc, ctx, map, value, isPlainObject);
678
+ else if (isMergeKey(doc, key)) addMergeToJSMap(doc, ctx, map, value, isPlainObject);
642
679
  else {
643
680
  const jsKey = key.toJS(doc, ctx);
644
681
  if (map instanceof Map) map.set(jsKey, value ? value.toJS(doc, ctx) : value);
@@ -646,7 +683,7 @@ function addPairToJSMap(doc, ctx, map, { key, value }) {
646
683
  else {
647
684
  const stringKey = stringifyKey(doc, ctx, key, jsKey);
648
685
  const jsValue = value ? value.toJS(doc, ctx) : value;
649
- if (stringKey in map) Object.defineProperty(map, stringKey, {
686
+ if (!isPlainObject && stringKey in map || stringKey === "__proto__" || stringKey === "constructor") Object.defineProperty(map, stringKey, {
650
687
  value: jsValue,
651
688
  writable: true,
652
689
  enumerable: true,
@@ -660,8 +697,7 @@ function addPairToJSMap(doc, ctx, map, { key, value }) {
660
697
  function stringifyKey(doc, ctx, key, jsKey) {
661
698
  if (jsKey === null) return "";
662
699
  if (typeof jsKey !== "object") return String(jsKey);
663
- const strCtx = createStringifyContext(doc, {});
664
- strCtx.anchors = /* @__PURE__ */ new Set();
700
+ const strCtx = createStringifyContext(doc, void 0);
665
701
  for (const node of ctx.anchors.keys()) strCtx.anchors.add(node.anchor);
666
702
  strCtx.inFlow = true;
667
703
  strCtx.inStringifyKey = true;
@@ -676,28 +712,6 @@ function stringifyKey(doc, ctx, key, jsKey) {
676
712
  return strKey;
677
713
  }
678
714
  //#endregion
679
- //#region src/nodes/toJS.ts
680
- /** A context used in `node.toJS()` implementations */
681
- var ToJSContext = class {
682
- anchors = /* @__PURE__ */ new Map();
683
- /** Cached anchor and alias nodes in the order they occur in the document */
684
- aliasResolveCache;
685
- mapAsMap;
686
- mapKeyWarned = false;
687
- maxAliasCount;
688
- constructor(opt) {
689
- this.mapAsMap = opt?.mapAsMap === true;
690
- this.maxAliasCount = opt?.maxAliasCount ?? 100;
691
- }
692
- setAnchor(node, res) {
693
- this.anchors.set(node, {
694
- aliasCount: 0,
695
- count: 1,
696
- res
697
- });
698
- }
699
- };
700
- //#endregion
701
715
  //#region src/nodes/util-clone-map-or-set.ts
702
716
  function cloneMapOrSet(coll, schema) {
703
717
  schema ??= coll.schema;
@@ -834,9 +848,16 @@ var YAMLMap = class {
834
848
  }
835
849
  toJS(doc, ctx, Type) {
836
850
  ctx ??= new ToJSContext();
837
- const map = Type ? new Type() : ctx?.mapAsMap ? /* @__PURE__ */ new Map() : {};
851
+ let map;
852
+ let isPlainObject = false;
853
+ if (Type) map = new Type();
854
+ else if (ctx.mapAsMap) map = /* @__PURE__ */ new Map();
855
+ else {
856
+ map = {};
857
+ isPlainObject = true;
858
+ }
838
859
  if (this.anchor) ctx.setAnchor(this, map);
839
- for (const pair of this.values.values()) addPairToJSMap(doc, ctx, map, pair);
860
+ for (const pair of this.values.values()) addPairToJSMap(doc, ctx, map, pair, isPlainObject);
840
861
  return map;
841
862
  }
842
863
  toString(ctx, onComment, onChompKeep) {
@@ -1270,8 +1291,10 @@ var YAMLSet = class {
1270
1291
  let chompKeep = false;
1271
1292
  let res = null;
1272
1293
  for (const item of items) {
1273
- if (!chompKeep && item.spaceBefore) if (typeof res === "string") res += "\n";
1274
- else res = "";
1294
+ if (!chompKeep && item.spaceBefore) {
1295
+ if (typeof res === "string") res += "\n";
1296
+ else res = "";
1297
+ }
1275
1298
  let cb = item.commentBefore;
1276
1299
  if (cb && chompKeep) cb = cb.replace(/^\n+/, "");
1277
1300
  if (cb) {
@@ -1446,16 +1469,76 @@ var Pair = class Pair {
1446
1469
  this.value = value;
1447
1470
  }
1448
1471
  clone(schema) {
1449
- return new Pair(this.key.clone(schema), this.value?.clone(schema) ?? null);
1472
+ const key = this.key.clone(schema);
1473
+ const value = this.value?.clone(schema) ?? null;
1474
+ return new Pair(key, value);
1450
1475
  }
1451
1476
  toJS(doc, ctx) {
1452
- return addPairToJSMap(doc, ctx, ctx.mapAsMap ? /* @__PURE__ */ new Map() : {}, this);
1477
+ return addPairToJSMap(doc, ctx, ctx.mapAsMap ? /* @__PURE__ */ new Map() : {}, this, true);
1453
1478
  }
1454
1479
  toString(ctx, onComment, onChompKeep) {
1455
1480
  return ctx?.doc ? stringifyPair(this, ctx, onComment, onChompKeep) : JSON.stringify(this);
1456
1481
  }
1457
1482
  };
1458
1483
  //#endregion
1484
+ //#region src/nodes/toJS.ts
1485
+ /** A context used in `node.toJS()` implementations */
1486
+ var ToJSContext = class {
1487
+ anchors = /* @__PURE__ */ new Map();
1488
+ /** Cached anchor and alias nodes in the order they occur in the document */
1489
+ aliasResolveCache;
1490
+ mapAsMap;
1491
+ mapKeyWarned = false;
1492
+ maxAliasCount;
1493
+ constructor(opt) {
1494
+ this.mapAsMap = opt?.mapAsMap === true;
1495
+ this.maxAliasCount = opt?.maxAliasCount ?? 100;
1496
+ }
1497
+ setAnchor(node, res) {
1498
+ const anchor = this.anchors.get(node);
1499
+ if (anchor) anchor.res = res;
1500
+ else this.anchors.set(node, {
1501
+ aliasCount: 0,
1502
+ count: 1,
1503
+ res
1504
+ });
1505
+ }
1506
+ resolveAlias(doc, source) {
1507
+ let data = this.anchors.get(source);
1508
+ if (!data) {
1509
+ source.toJS(doc, this);
1510
+ data = this.anchors.get(source);
1511
+ }
1512
+ /* istanbul ignore if */
1513
+ if (data?.res === void 0) throw new ReferenceError("This should not happen: Alias anchor was not resolved?");
1514
+ if (this.maxAliasCount >= 0) {
1515
+ data.count += 1;
1516
+ data.aliasCount ||= this.#getAliasCount(doc, source);
1517
+ if (data.count * data.aliasCount > this.maxAliasCount) throw new ReferenceError("Excessive alias count indicates a resource exhaustion attack");
1518
+ }
1519
+ return data.res;
1520
+ }
1521
+ #getAliasCount(doc, node) {
1522
+ if (node instanceof Alias) {
1523
+ const source = node.resolve(doc, this);
1524
+ const anchor = source && this.anchors.get(source);
1525
+ return anchor ? anchor.count * anchor.aliasCount : 0;
1526
+ } else if (node instanceof Pair) {
1527
+ const kc = this.#getAliasCount(doc, node.key);
1528
+ const vc = this.#getAliasCount(doc, node.value);
1529
+ return Math.max(kc, vc);
1530
+ } else if (Array.isArray(node)) {
1531
+ let count = 0;
1532
+ for (const item of node) {
1533
+ const c = this.#getAliasCount(doc, item);
1534
+ if (c > count) count = c;
1535
+ }
1536
+ return count;
1537
+ }
1538
+ return 1;
1539
+ }
1540
+ };
1541
+ //#endregion
1459
1542
  //#region src/nodes/Alias.ts
1460
1543
  var Alias = class Alias {
1461
1544
  source;
@@ -1497,25 +1580,12 @@ var Alias = class Alias {
1497
1580
  toJS(doc, ctx) {
1498
1581
  if (!doc?.schema) throw new TypeError("A document argument is required");
1499
1582
  ctx ??= new ToJSContext();
1500
- const { anchors, maxAliasCount } = ctx;
1501
1583
  const source = this.resolve(doc, ctx);
1502
1584
  if (!source) {
1503
1585
  const msg = `Unresolved alias (the anchor must be set before the alias): ${this.source}`;
1504
1586
  throw new ReferenceError(msg);
1505
1587
  }
1506
- let data = anchors.get(source);
1507
- if (!data) {
1508
- source.toJS(doc, ctx);
1509
- data = anchors.get(source);
1510
- }
1511
- /* istanbul ignore if */
1512
- if (data?.res === void 0) throw new ReferenceError("This should not happen: Alias anchor was not resolved?");
1513
- if (maxAliasCount >= 0) {
1514
- data.count += 1;
1515
- data.aliasCount ||= getAliasCount(doc, ctx, source, anchors);
1516
- if (data.count * data.aliasCount > maxAliasCount) throw new ReferenceError("Excessive alias count indicates a resource exhaustion attack");
1517
- }
1518
- return data.res;
1588
+ return ctx.resolveAlias(doc, source);
1519
1589
  }
1520
1590
  toString(ctx, _onComment, _onChompKeep) {
1521
1591
  const src = `*${this.source}`;
@@ -1530,25 +1600,6 @@ var Alias = class Alias {
1530
1600
  return src;
1531
1601
  }
1532
1602
  };
1533
- function getAliasCount(doc, ctx, node, anchors) {
1534
- if (node instanceof Alias) {
1535
- const source = node.resolve(doc, ctx);
1536
- const anchor = anchors && source && anchors.get(source);
1537
- return anchor ? anchor.count * anchor.aliasCount : 0;
1538
- } else if (node instanceof Pair) {
1539
- const kc = getAliasCount(doc, ctx, node.key, anchors);
1540
- const vc = getAliasCount(doc, ctx, node.value, anchors);
1541
- return Math.max(kc, vc);
1542
- } else if (Array.isArray(node)) {
1543
- let count = 0;
1544
- for (const item of node) {
1545
- const c = getAliasCount(doc, ctx, item, anchors);
1546
- if (c > count) count = c;
1547
- }
1548
- return count;
1549
- }
1550
- return 1;
1551
- }
1552
1603
  //#endregion
1553
1604
  //#region src/schema/common/map.ts
1554
1605
  const map = {
@@ -1593,25 +1644,40 @@ const string = {
1593
1644
  };
1594
1645
  //#endregion
1595
1646
  //#region src/schema/common/null.ts
1647
+ const nullValues = /* @__PURE__ */ new Set([
1648
+ "",
1649
+ "~",
1650
+ "null",
1651
+ "Null",
1652
+ "NULL"
1653
+ ]);
1596
1654
  const nullTag = {
1597
1655
  identify: (value) => value == null,
1598
1656
  createNode: () => new Scalar(null),
1599
1657
  default: true,
1600
1658
  tag: "tag:yaml.org,2002:null",
1601
- test: /^(?:~|[Nn]ull|NULL)?$/,
1659
+ test: (value) => nullValues.has(value),
1602
1660
  resolve: () => new Scalar(null),
1603
- stringify: ({ source }, ctx) => typeof source === "string" && nullTag.test.test(source) ? source : ctx.options.nullStr
1661
+ stringify: ({ source }, ctx) => typeof source === "string" && nullTag.test(source) ? source : ctx.options.nullStr
1604
1662
  };
1605
1663
  //#endregion
1606
1664
  //#region src/schema/core/bool.ts
1665
+ const boolValues = /* @__PURE__ */ new Set([
1666
+ "true",
1667
+ "True",
1668
+ "TRUE",
1669
+ "false",
1670
+ "False",
1671
+ "FALSE"
1672
+ ]);
1607
1673
  const boolTag = {
1608
1674
  identify: (value) => typeof value === "boolean",
1609
1675
  default: true,
1610
1676
  tag: "tag:yaml.org,2002:bool",
1611
- test: /^(?:[Tt]rue|TRUE|[Ff]alse|FALSE)$/,
1677
+ test: (value) => boolValues.has(value),
1612
1678
  resolve: (str) => new Scalar(str[0] === "t" || str[0] === "T"),
1613
1679
  stringify({ source, value }, ctx) {
1614
- if (source && boolTag.test.test(source)) {
1680
+ if (source && boolTag.test(source)) {
1615
1681
  if (value === (source[0] === "t" || source[0] === "T")) return source;
1616
1682
  }
1617
1683
  return value ? ctx.options.trueStr : ctx.options.falseStr;
@@ -1619,10 +1685,16 @@ const boolTag = {
1619
1685
  };
1620
1686
  //#endregion
1621
1687
  //#region src/stringify/stringifyNumber.ts
1622
- function stringifyNumber({ format, minFractionDigits, tag, value }) {
1688
+ function stringifyNumber({ format, minFractionDigits, source, tag, value }, version = "1.2") {
1623
1689
  if (typeof value === "bigint") return String(value);
1624
1690
  const num = typeof value === "number" ? value : Number(value);
1625
- if (!isFinite(num)) return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
1691
+ if (!isFinite(num)) {
1692
+ if (typeof value === "number" && source) {
1693
+ const source_ = version === "1.1" ? source.replace(/_/g, "") : source;
1694
+ if (parseFloat(source_) === num) return source;
1695
+ }
1696
+ return isNaN(num) ? ".nan" : num < 0 ? "-.inf" : ".inf";
1697
+ }
1626
1698
  let n = Object.is(value, -0) ? "-0" : JSON.stringify(value);
1627
1699
  if (!format && minFractionDigits && (!tag || tag === "tag:yaml.org,2002:float") && /^-?\d/.test(n) && !n.includes("e")) {
1628
1700
  let i = n.indexOf(".");
@@ -1637,20 +1709,41 @@ function stringifyNumber({ format, minFractionDigits, tag, value }) {
1637
1709
  }
1638
1710
  //#endregion
1639
1711
  //#region src/schema/core/float.ts
1712
+ const floatNaNValues = /* @__PURE__ */ new Set([
1713
+ ".nan",
1714
+ ".NaN",
1715
+ ".NAN",
1716
+ ".inf",
1717
+ ".Inf",
1718
+ ".INF",
1719
+ "+.inf",
1720
+ "+.Inf",
1721
+ "+.INF",
1722
+ "-.inf",
1723
+ "-.Inf",
1724
+ "-.INF"
1725
+ ]);
1726
+ /** First char must be a digit, sign, or dot to match any float pattern */
1727
+ function couldBeFloat(value) {
1728
+ const c = value.charCodeAt(0);
1729
+ return c >= 48 && c <= 57 || c === 43 || c === 45 || c === 46;
1730
+ }
1731
+ const floatExpRe = /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/;
1732
+ const floatRe = /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/;
1640
1733
  const floatNaN$1 = {
1641
1734
  identify: (value) => typeof value === "number",
1642
1735
  default: true,
1643
1736
  tag: "tag:yaml.org,2002:float",
1644
- test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
1737
+ test: (value) => floatNaNValues.has(value),
1645
1738
  resolve: (str) => str.slice(-3).toLowerCase() === "nan" ? NaN : str[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
1646
- stringify: stringifyNumber
1739
+ stringify: (node) => stringifyNumber(node)
1647
1740
  };
1648
1741
  const floatExp$1 = {
1649
1742
  identify: (value) => typeof value === "number",
1650
1743
  default: true,
1651
1744
  tag: "tag:yaml.org,2002:float",
1652
1745
  format: "EXP",
1653
- test: /^[-+]?(?:\.[0-9]+|[0-9]+(?:\.[0-9]*)?)[eE][-+]?[0-9]+$/,
1746
+ test: (value) => couldBeFloat(value) && floatExpRe.test(value),
1654
1747
  resolve: (str) => parseFloat(str),
1655
1748
  stringify(node) {
1656
1749
  const num = Number(node.value);
@@ -1661,14 +1754,14 @@ const float$1 = {
1661
1754
  identify: (value) => typeof value === "number",
1662
1755
  default: true,
1663
1756
  tag: "tag:yaml.org,2002:float",
1664
- test: /^[-+]?(?:\.[0-9]+|[0-9]+\.[0-9]*)$/,
1757
+ test: (value) => couldBeFloat(value) && floatRe.test(value),
1665
1758
  resolve(str) {
1666
1759
  const node = new Scalar(parseFloat(str));
1667
1760
  const dot = str.indexOf(".");
1668
1761
  if (dot !== -1 && str[str.length - 1] === "0") node.minFractionDigits = str.length - dot - 1;
1669
1762
  return node;
1670
1763
  },
1671
- stringify: stringifyNumber
1764
+ stringify: (node) => stringifyNumber(node)
1672
1765
  };
1673
1766
  //#endregion
1674
1767
  //#region src/schema/core/int.ts
@@ -1679,12 +1772,39 @@ function intStringify$1(node, radix, prefix) {
1679
1772
  if (intIdentify$2(value) && value >= 0) return prefix + value.toString(radix);
1680
1773
  return stringifyNumber(node);
1681
1774
  }
1775
+ function isOctInt(value) {
1776
+ if (value.length < 3 || value[0] !== "0" || value[1] !== "o") return false;
1777
+ for (let i = 2; i < value.length; i++) {
1778
+ const c = value.charCodeAt(i);
1779
+ if (c < 48 || c > 55) return false;
1780
+ }
1781
+ return true;
1782
+ }
1783
+ function isInt(value) {
1784
+ let i = 0;
1785
+ if (value.length === 0) return false;
1786
+ if (value.charCodeAt(0) === 43 || value.charCodeAt(0) === 45) i = 1;
1787
+ if (i === value.length) return false;
1788
+ for (; i < value.length; i++) {
1789
+ const c = value.charCodeAt(i);
1790
+ if (c < 48 || c > 57) return false;
1791
+ }
1792
+ return true;
1793
+ }
1794
+ function isHexInt(value) {
1795
+ if (value.length < 3 || value[0] !== "0" || value[1] !== "x") return false;
1796
+ for (let i = 2; i < value.length; i++) {
1797
+ const c = value.charCodeAt(i);
1798
+ if (!(c >= 48 && c <= 57) && !(c >= 65 && c <= 70) && !(c >= 97 && c <= 102)) return false;
1799
+ }
1800
+ return true;
1801
+ }
1682
1802
  const intOct$1 = {
1683
1803
  identify: (value) => intIdentify$2(value) && value >= 0,
1684
1804
  default: true,
1685
1805
  tag: "tag:yaml.org,2002:int",
1686
1806
  format: "OCT",
1687
- test: /^0o[0-7]+$/,
1807
+ test: isOctInt,
1688
1808
  resolve: (str, _onError, opt) => intResolve$1(str, 2, 8, opt),
1689
1809
  stringify: (node) => intStringify$1(node, 8, "0o")
1690
1810
  };
@@ -1692,16 +1812,16 @@ const int$1 = {
1692
1812
  identify: intIdentify$2,
1693
1813
  default: true,
1694
1814
  tag: "tag:yaml.org,2002:int",
1695
- test: /^[-+]?[0-9]+$/,
1815
+ test: isInt,
1696
1816
  resolve: (str, _onError, opt) => intResolve$1(str, 0, 10, opt),
1697
- stringify: stringifyNumber
1817
+ stringify: (node) => stringifyNumber(node)
1698
1818
  };
1699
1819
  const intHex$1 = {
1700
1820
  identify: (value) => intIdentify$2(value) && value >= 0,
1701
1821
  default: true,
1702
1822
  tag: "tag:yaml.org,2002:int",
1703
1823
  format: "HEX",
1704
- test: /^0x[0-9a-fA-F]+$/,
1824
+ test: isHexInt,
1705
1825
  resolve: (str, _onError, opt) => intResolve$1(str, 2, 16, opt),
1706
1826
  stringify: (node) => intStringify$1(node, 16, "0x")
1707
1827
  };
@@ -1739,7 +1859,7 @@ const jsonScalars = [
1739
1859
  createNode: () => new Scalar(null),
1740
1860
  default: true,
1741
1861
  tag: "tag:yaml.org,2002:null",
1742
- test: /^null$/,
1862
+ test: (str) => str === "null",
1743
1863
  resolve: () => null,
1744
1864
  stringify: stringifyJSON
1745
1865
  },
@@ -1747,7 +1867,7 @@ const jsonScalars = [
1747
1867
  identify: (value) => typeof value === "boolean",
1748
1868
  default: true,
1749
1869
  tag: "tag:yaml.org,2002:bool",
1750
- test: /^true$|^false$/,
1870
+ test: (str) => str === "true" || str === "false",
1751
1871
  resolve: (str) => str === "true",
1752
1872
  stringify: stringifyJSON
1753
1873
  },
@@ -1755,7 +1875,7 @@ const jsonScalars = [
1755
1875
  identify: intIdentify$1,
1756
1876
  default: true,
1757
1877
  tag: "tag:yaml.org,2002:int",
1758
- test: /^-?(?:0|[1-9][0-9]*)$/,
1878
+ test: (str) => /^-?(?:0|[1-9][0-9]*)$/.test(str),
1759
1879
  resolve: (str, _onError, { intAsBigInt }) => intAsBigInt ? BigInt(str) : parseInt(str, 10),
1760
1880
  stringify: ({ value }) => intIdentify$1(value) ? value.toString() : JSON.stringify(value)
1761
1881
  },
@@ -1763,7 +1883,7 @@ const jsonScalars = [
1763
1883
  identify: (value) => typeof value === "number",
1764
1884
  default: true,
1765
1885
  tag: "tag:yaml.org,2002:float",
1766
- test: /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/,
1886
+ test: (str) => /^-?(?:0|[1-9][0-9]*)(?:\.[0-9]*)?(?:[eE][-+]?[0-9]+)?$/.test(str),
1767
1887
  resolve: (str) => parseFloat(str),
1768
1888
  stringify: stringifyJSON
1769
1889
  }
@@ -1771,7 +1891,7 @@ const jsonScalars = [
1771
1891
  const jsonError = {
1772
1892
  default: true,
1773
1893
  tag: "",
1774
- test: /^/,
1894
+ test: () => true,
1775
1895
  resolve(str, onError) {
1776
1896
  onError(`Unresolved plain scalar ${JSON.stringify(str)}`);
1777
1897
  return str;
@@ -1789,6 +1909,14 @@ const binary = {
1789
1909
  identify: (value) => value instanceof Uint8Array,
1790
1910
  default: false,
1791
1911
  tag: "tag:yaml.org,2002:binary",
1912
+ /**
1913
+ * Returns a Buffer in Node.js and an Uint8Array elsewhere
1914
+ *
1915
+ * To use the resulting buffer as an image, you'll want to do something like:
1916
+ *
1917
+ * const blob = new Blob([buffer], { type: 'image/jpeg' })
1918
+ * document.querySelector('#photo').src = URL.createObjectURL(blob)
1919
+ */
1792
1920
  resolve(src, onError) {
1793
1921
  if (typeof Buffer === "function") return Buffer.from(src, "base64");
1794
1922
  else if (typeof Uint8Array.fromBase64 === "function") return Uint8Array.fromBase64(src);
@@ -1855,11 +1983,12 @@ function createPairs(nc, iterable) {
1855
1983
  if (iterable && Symbol.iterator in Object(iterable)) for (let it of iterable) {
1856
1984
  if (typeof nc.replacer === "function") it = nc.replacer.call(iterable, String(i++), it);
1857
1985
  let key, value;
1858
- if (Array.isArray(it)) if (it.length === 2) {
1859
- key = it[0];
1860
- value = it[1];
1861
- } else throw new TypeError(`Expected [key, value] tuple: ${it}`);
1862
- else if (it && it instanceof Object) {
1986
+ if (Array.isArray(it)) {
1987
+ if (it.length === 2) {
1988
+ key = it[0];
1989
+ value = it[1];
1990
+ } else throw new TypeError(`Expected [key, value] tuple: ${it}`);
1991
+ } else if (it && it instanceof Object) {
1863
1992
  const keys = Object.keys(it);
1864
1993
  if (keys.length === 1) {
1865
1994
  key = keys[0];
@@ -1948,22 +2077,24 @@ const omap = {
1948
2077
  resolve(seq, onError) {
1949
2078
  const pairs = resolvePairs(seq, onError);
1950
2079
  const seenKeys = [];
1951
- for (const { key } of pairs) if (key instanceof Scalar) if (seenKeys.includes(key.value)) onError(`Ordered maps must not include duplicate keys: ${key.value}`);
1952
- else seenKeys.push(key.value);
2080
+ for (const { key } of pairs) if (key instanceof Scalar) {
2081
+ if (seenKeys.includes(key.value)) onError(`Ordered maps must not include duplicate keys: ${key.value}`);
2082
+ else seenKeys.push(key.value);
2083
+ }
1953
2084
  return Object.assign(new YAMLOMap(seq.schema), pairs);
1954
2085
  }
1955
2086
  };
1956
2087
  //#endregion
1957
2088
  //#region src/schema/yaml-1.1/bool.ts
1958
2089
  function boolStringify({ value, source }, ctx) {
1959
- if (source && (value ? trueTag : falseTag).test.test(source)) return source;
2090
+ if (source && (value ? trueTag : falseTag).test(source)) return source;
1960
2091
  return value ? ctx.options.trueStr : ctx.options.falseStr;
1961
2092
  }
1962
2093
  const trueTag = {
1963
2094
  identify: (value) => value === true,
1964
2095
  default: true,
1965
2096
  tag: "tag:yaml.org,2002:bool",
1966
- test: /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/,
2097
+ test: (str) => /^(?:Y|y|[Yy]es|YES|[Tt]rue|TRUE|[Oo]n|ON)$/.test(str),
1967
2098
  resolve: () => new Scalar(true),
1968
2099
  stringify: boolStringify
1969
2100
  };
@@ -1971,7 +2102,7 @@ const falseTag = {
1971
2102
  identify: (value) => value === false,
1972
2103
  default: true,
1973
2104
  tag: "tag:yaml.org,2002:bool",
1974
- test: /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/,
2105
+ test: (str) => /^(?:N|n|[Nn]o|NO|[Ff]alse|FALSE|[Oo]ff|OFF)$/.test(str),
1975
2106
  resolve: () => new Scalar(false),
1976
2107
  stringify: boolStringify
1977
2108
  };
@@ -1981,27 +2112,27 @@ const floatNaN = {
1981
2112
  identify: (value) => typeof value === "number",
1982
2113
  default: true,
1983
2114
  tag: "tag:yaml.org,2002:float",
1984
- test: /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/,
2115
+ test: (str) => /^(?:[-+]?\.(?:inf|Inf|INF)|\.nan|\.NaN|\.NAN)$/.test(str),
1985
2116
  resolve: (str) => str.slice(-3).toLowerCase() === "nan" ? NaN : str[0] === "-" ? Number.NEGATIVE_INFINITY : Number.POSITIVE_INFINITY,
1986
- stringify: stringifyNumber
2117
+ stringify: (node) => stringifyNumber(node, "1.1")
1987
2118
  };
1988
2119
  const floatExp = {
1989
2120
  identify: (value) => typeof value === "number",
1990
2121
  default: true,
1991
2122
  tag: "tag:yaml.org,2002:float",
1992
2123
  format: "EXP",
1993
- test: /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/,
2124
+ test: (str) => /^[-+]?(?:[0-9][0-9_]*)?(?:\.[0-9_]*)?[eE][-+]?[0-9]+$/.test(str),
1994
2125
  resolve: (str) => parseFloat(str.replace(/_/g, "")),
1995
2126
  stringify(node) {
1996
2127
  const num = Number(node.value);
1997
- return isFinite(num) ? num.toExponential() : stringifyNumber(node);
2128
+ return isFinite(num) ? num.toExponential() : stringifyNumber(node, "1.1");
1998
2129
  }
1999
2130
  };
2000
2131
  const float = {
2001
2132
  identify: (value) => typeof value === "number",
2002
2133
  default: true,
2003
2134
  tag: "tag:yaml.org,2002:float",
2004
- test: /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/,
2135
+ test: (str) => /^[-+]?(?:[0-9][0-9_]*)?\.[0-9_]*$/.test(str),
2005
2136
  resolve(str) {
2006
2137
  const node = new Scalar(parseFloat(str.replace(/_/g, "")));
2007
2138
  const dot = str.indexOf(".");
@@ -2011,7 +2142,7 @@ const float = {
2011
2142
  }
2012
2143
  return node;
2013
2144
  },
2014
- stringify: stringifyNumber
2145
+ stringify: (node) => stringifyNumber(node, "1.1")
2015
2146
  };
2016
2147
  //#endregion
2017
2148
  //#region src/schema/yaml-1.1/int.ts
@@ -2028,9 +2159,7 @@ function intResolve(str, offset, radix, { intAsBigInt }) {
2028
2159
  case 8:
2029
2160
  str = `0o${str}`;
2030
2161
  break;
2031
- case 16:
2032
- str = `0x${str}`;
2033
- break;
2162
+ case 16: str = `0x${str}`;
2034
2163
  }
2035
2164
  const n = BigInt(str);
2036
2165
  return sign === "-" ? BigInt(-1) * n : n;
@@ -2051,7 +2180,7 @@ const intBin = {
2051
2180
  default: true,
2052
2181
  tag: "tag:yaml.org,2002:int",
2053
2182
  format: "BIN",
2054
- test: /^[-+]?0b[0-1_]+$/,
2183
+ test: (str) => /^[-+]?0b[0-1_]+$/.test(str),
2055
2184
  resolve: (str, _onError, opt) => intResolve(str, 2, 2, opt),
2056
2185
  stringify: (node) => intStringify(node, 2, "0b")
2057
2186
  };
@@ -2060,7 +2189,7 @@ const intOct = {
2060
2189
  default: true,
2061
2190
  tag: "tag:yaml.org,2002:int",
2062
2191
  format: "OCT",
2063
- test: /^[-+]?0[0-7_]+$/,
2192
+ test: (str) => /^[-+]?0[0-7_]+$/.test(str),
2064
2193
  resolve: (str, _onError, opt) => intResolve(str, 1, 8, opt),
2065
2194
  stringify: (node) => intStringify(node, 8, "0")
2066
2195
  };
@@ -2068,16 +2197,16 @@ const int = {
2068
2197
  identify: intIdentify,
2069
2198
  default: true,
2070
2199
  tag: "tag:yaml.org,2002:int",
2071
- test: /^[-+]?[0-9][0-9_]*$/,
2200
+ test: (str) => /^[-+]?[0-9][0-9_]*$/.test(str),
2072
2201
  resolve: (str, _onError, opt) => intResolve(str, 0, 10, opt),
2073
- stringify: stringifyNumber
2202
+ stringify: (node) => stringifyNumber(node, "1.1")
2074
2203
  };
2075
2204
  const intHex = {
2076
2205
  identify: intIdentify,
2077
2206
  default: true,
2078
2207
  tag: "tag:yaml.org,2002:int",
2079
2208
  format: "HEX",
2080
- test: /^[-+]?0x[0-9a-fA-F_]+$/,
2209
+ test: (str) => /^[-+]?0x[0-9a-fA-F_]+$/.test(str),
2081
2210
  resolve: (str, _onError, opt) => intResolve(str, 2, 16, opt),
2082
2211
  stringify: (node) => intStringify(node, 16, "0x")
2083
2212
  };
@@ -2146,7 +2275,7 @@ const intTime = {
2146
2275
  default: true,
2147
2276
  tag: "tag:yaml.org,2002:int",
2148
2277
  format: "TIME",
2149
- test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,
2278
+ test: (str) => /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/.test(str),
2150
2279
  resolve: (str, _onError, { intAsBigInt }) => parseSexagesimal(str, intAsBigInt),
2151
2280
  stringify: stringifySexagesimal
2152
2281
  };
@@ -2155,17 +2284,18 @@ const floatTime = {
2155
2284
  default: true,
2156
2285
  tag: "tag:yaml.org,2002:float",
2157
2286
  format: "TIME",
2158
- test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,
2287
+ test: (str) => /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/.test(str),
2159
2288
  resolve: (str) => parseSexagesimal(str, false),
2160
2289
  stringify: stringifySexagesimal
2161
2290
  };
2291
+ const timestampRe = RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$");
2162
2292
  const timestamp = {
2163
2293
  identify: (value) => value instanceof Date,
2164
2294
  default: true,
2165
2295
  tag: "tag:yaml.org,2002:timestamp",
2166
- test: RegExp("^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$"),
2296
+ test: (str) => timestampRe.test(str),
2167
2297
  resolve(str) {
2168
- const match = str.match(timestamp.test);
2298
+ const match = str.match(timestampRe);
2169
2299
  if (!match) throw new Error("!!timestamp expects a date, starting with yyyy-mm-dd");
2170
2300
  const [, year, month, day, hour, minute, second] = match.map(Number);
2171
2301
  const millisec = match[7] ? Number((match[7] + "00").substr(1, 3)) : 0;
@@ -2207,7 +2337,7 @@ const schema = [
2207
2337
  ];
2208
2338
  //#endregion
2209
2339
  //#region src/schema/tags.ts
2210
- const schemas = new Map([
2340
+ const schemas = /* @__PURE__ */ new Map([
2211
2341
  ["core", schema$2],
2212
2342
  ["failsafe", [
2213
2343
  map,
@@ -2250,10 +2380,12 @@ function getTags(customTags, schemaName, addMergeTag) {
2250
2380
  const schemaTags = schemas.get(schemaName);
2251
2381
  if (schemaTags && !customTags) return addMergeTag && !schemaTags.includes(merge) ? [...schemaTags, merge] : schemaTags.slice();
2252
2382
  let tags = schemaTags;
2253
- if (!tags) if (Array.isArray(customTags)) tags = [];
2254
- else {
2255
- const keys = Array.from(schemas.keys()).filter((key) => key !== "yaml11").map((key) => JSON.stringify(key)).join(", ");
2256
- throw new Error(`Unknown schema "${schemaName}"; use one of ${keys} or define customTags array`);
2383
+ if (!tags) {
2384
+ if (Array.isArray(customTags)) tags = [];
2385
+ else {
2386
+ const keys = Array.from(schemas.keys()).filter((key) => key !== "yaml11").map((key) => JSON.stringify(key)).join(", ");
2387
+ throw new Error(`Unknown schema "${schemaName}"; use one of ${keys} or define customTags array`);
2388
+ }
2257
2389
  }
2258
2390
  if (Array.isArray(customTags)) for (const tag of customTags) tags = tags.concat(tag);
2259
2391
  else if (typeof customTags === "function") tags = customTags(tags.slice());
@@ -2321,27 +2453,27 @@ function stringifyDocument(doc, options) {
2321
2453
  lines.unshift(indentComment(cs, ""));
2322
2454
  }
2323
2455
  let chompKeep = false;
2324
- let contentComment = null;
2325
2456
  if (doc.value.spaceBefore && hasDirectives) lines.push("");
2326
2457
  if (doc.value.commentBefore) {
2327
2458
  const cs = commentString(doc.value.commentBefore);
2328
2459
  lines.push(indentComment(cs, ""));
2329
2460
  }
2330
2461
  ctx.forceBlockIndent = !!doc.comment;
2331
- contentComment = doc.value.comment;
2462
+ let contentComment = doc.value.comment;
2332
2463
  const onChompKeep = contentComment ? void 0 : () => chompKeep = true;
2333
2464
  let body = stringify(doc.value, ctx, () => contentComment = null, onChompKeep);
2334
2465
  if (contentComment) body += lineComment(body, "", commentString(contentComment));
2335
2466
  if ((body[0] === "|" || body[0] === ">") && lines[lines.length - 1] === "---") lines[lines.length - 1] = `--- ${body}`;
2336
2467
  else lines.push(body);
2337
- if (doc.directives?.docEnd) if (doc.comment) {
2338
- const cs = commentString(doc.comment);
2339
- if (cs.includes("\n")) {
2340
- lines.push("...");
2341
- lines.push(indentComment(cs, ""));
2342
- } else lines.push(`... ${cs}`);
2343
- } else lines.push("...");
2344
- else {
2468
+ if (doc.directives?.docEnd) {
2469
+ if (doc.comment) {
2470
+ const cs = commentString(doc.comment);
2471
+ if (cs.includes("\n")) {
2472
+ lines.push("...");
2473
+ lines.push(indentComment(cs, ""));
2474
+ } else lines.push(`... ${cs}`);
2475
+ } else lines.push("...");
2476
+ } else {
2345
2477
  let dc = doc.comment;
2346
2478
  if (dc && chompKeep) dc = dc.replace(/^\n+/, "");
2347
2479
  if (dc) {
@@ -2354,30 +2486,32 @@ function stringifyDocument(doc, options) {
2354
2486
  //#endregion
2355
2487
  //#region src/doc/applyReviver.ts
2356
2488
  function applyReviver(reviver, obj, key, val) {
2357
- if (val && typeof val === "object") if (Array.isArray(val)) for (let i = 0, len = val.length; i < len; ++i) {
2358
- const v0 = val[i];
2359
- const v1 = applyReviver(reviver, val, String(i), v0);
2360
- if (v1 === void 0) delete val[i];
2361
- else if (v1 !== v0) val[i] = v1;
2362
- }
2363
- else if (val instanceof Map) for (const k of Array.from(val.keys())) {
2364
- const v0 = val.get(k);
2365
- const v1 = applyReviver(reviver, val, k, v0);
2366
- if (v1 === void 0) val.delete(k);
2367
- else if (v1 !== v0) val.set(k, v1);
2368
- }
2369
- else if (val instanceof Set) for (const v0 of Array.from(val)) {
2370
- const v1 = applyReviver(reviver, val, v0, v0);
2371
- if (v1 === void 0) val.delete(v0);
2372
- else if (v1 !== v0) {
2373
- val.delete(v0);
2374
- val.add(v1);
2375
- }
2376
- }
2377
- else for (const [k, v0] of Object.entries(val)) {
2378
- const v1 = applyReviver(reviver, val, k, v0);
2379
- if (v1 === void 0) delete val[k];
2380
- else if (v1 !== v0) val[k] = v1;
2489
+ if (val && typeof val === "object") {
2490
+ if (Array.isArray(val)) for (let i = 0, len = val.length; i < len; ++i) {
2491
+ const v0 = val[i];
2492
+ const v1 = applyReviver(reviver, val, String(i), v0);
2493
+ if (v1 === void 0) delete val[i];
2494
+ else if (v1 !== v0) val[i] = v1;
2495
+ }
2496
+ else if (val instanceof Map) for (const k of Array.from(val.keys())) {
2497
+ const v0 = val.get(k);
2498
+ const v1 = applyReviver(reviver, val, k, v0);
2499
+ if (v1 === void 0) val.delete(k);
2500
+ else if (v1 !== v0) val.set(k, v1);
2501
+ }
2502
+ else if (val instanceof Set) for (const v0 of Array.from(val)) {
2503
+ const v1 = applyReviver(reviver, val, v0, v0);
2504
+ if (v1 === void 0) val.delete(v0);
2505
+ else if (v1 !== v0) {
2506
+ val.delete(v0);
2507
+ val.add(v1);
2508
+ }
2509
+ }
2510
+ else for (const [k, v0] of Object.entries(val)) {
2511
+ const v1 = applyReviver(reviver, val, k, v0);
2512
+ if (v1 === void 0) delete val[k];
2513
+ else if (v1 !== v0) val[k] = v1;
2514
+ }
2381
2515
  }
2382
2516
  return reviver.call(obj, key, val);
2383
2517
  }
@@ -2396,13 +2530,10 @@ var Document = class Document {
2396
2530
  options;
2397
2531
  /** Warnings encountered during parsing. */
2398
2532
  warnings = [];
2399
- constructor(value, replacer, options) {
2400
- let _replacer = null;
2401
- if (typeof replacer === "function" || Array.isArray(replacer)) _replacer = replacer;
2402
- else if (options === void 0 && replacer) {
2403
- options = replacer;
2404
- replacer = void 0;
2405
- }
2533
+ constructor(value, replacerOrOptions, options) {
2534
+ let replacer = null;
2535
+ if (typeof replacerOrOptions === "function" || Array.isArray(replacerOrOptions)) replacer = replacerOrOptions;
2536
+ else if (options === void 0 && replacerOrOptions) options = replacerOrOptions;
2406
2537
  const opt = Object.assign({
2407
2538
  intAsBigInt: false,
2408
2539
  keepSourceTokens: false,
@@ -2419,7 +2550,7 @@ var Document = class Document {
2419
2550
  if (this.directives.yaml.explicit) version = this.directives.yaml.version;
2420
2551
  } else this.directives = new Directives({ version });
2421
2552
  this.setSchema(version, options);
2422
- this.value = this.createNode(value, _replacer, options);
2553
+ this.value = this.createNode(value, replacer, options);
2423
2554
  }
2424
2555
  /**
2425
2556
  * Create a deep copy of this Document and its value.
@@ -2770,22 +2901,27 @@ function callVisitor(key, node, visitor, path) {
2770
2901
  function replaceNode(key, path, node) {
2771
2902
  const parent = path[path.length - 1];
2772
2903
  if (parent instanceof YAMLSeq) parent[key] = node;
2773
- else if (parent instanceof YAMLMap) if (node instanceof Pair) {
2774
- const entries = Array.from(parent.values);
2775
- entries[key] = [parent.keyOf(node, true), node];
2776
- parent.values = new Map(entries);
2777
- } else throw new Error("Cannot replace map pair with non-pair value");
2778
- else if (parent instanceof YAMLSet) if (isNode(node)) {
2779
- const entries = Array.from(parent.values);
2780
- entries[key] = [parent.keyOf(node, true), node];
2781
- parent.values = new Map(entries);
2782
- } else throw new Error("Cannot replace set value with non-node value");
2783
- else if (parent instanceof Pair) if (isNode(node)) if (key === "key") parent.key = node;
2784
- else parent.value = node;
2785
- else throw new Error(`Cannot replace pair ${key} with non-node value`);
2786
- else if (parent instanceof Document) if (node instanceof Scalar || isCollection(node)) parent.value = node;
2787
- else throw new Error("Cannot replace Document value with non-node value");
2788
- else {
2904
+ else if (parent instanceof YAMLMap) {
2905
+ if (node instanceof Pair) {
2906
+ const entries = Array.from(parent.values);
2907
+ entries[key] = [parent.keyOf(node, true), node];
2908
+ parent.values = new Map(entries);
2909
+ } else throw new Error("Cannot replace map pair with non-pair value");
2910
+ } else if (parent instanceof YAMLSet) {
2911
+ if (isNode(node)) {
2912
+ const entries = Array.from(parent.values);
2913
+ entries[key] = [parent.keyOf(node, true), node];
2914
+ parent.values = new Map(entries);
2915
+ } else throw new Error("Cannot replace set value with non-node value");
2916
+ } else if (parent instanceof Pair) {
2917
+ if (isNode(node)) {
2918
+ if (key === "key") parent.key = node;
2919
+ else parent.value = node;
2920
+ } else throw new Error(`Cannot replace pair ${key} with non-node value`);
2921
+ } else if (parent instanceof Document) {
2922
+ if (node instanceof Scalar || isCollection(node)) parent.value = node;
2923
+ else throw new Error("Cannot replace Document value with non-node value");
2924
+ } else {
2789
2925
  const pt = parent instanceof Alias ? "alias" : "scalar";
2790
2926
  throw new Error(`Cannot replace node with ${pt} parent`);
2791
2927
  }
@@ -2849,7 +2985,6 @@ var Directives = class Directives {
2849
2985
  version: "1.2"
2850
2986
  };
2851
2987
  this.tags = Object.assign({}, Directives.defaultTags);
2852
- break;
2853
2988
  }
2854
2989
  return res;
2855
2990
  }
@@ -2960,4 +3095,4 @@ var Directives = class Directives {
2960
3095
  }
2961
3096
  };
2962
3097
  //#endregion
2963
- export { Scalar as S, ToJSContext as _, Schema as a, stringifyString as b, seq as c, Pair as d, isCollection as f, YAMLMap as g, YAMLSeq as h, Document as i, map as l, YAMLSet as m, visit as n, stringifyNumber as o, isNode as p, visitAsync as r, string as s, Directives as t, Alias as u, debug as v, foldFlowLines as x, warn as y };
3098
+ export { Scalar as S, YAMLMap as _, Schema as a, stringifyString as b, seq as c, ToJSContext as d, Pair as f, YAMLSeq as g, YAMLSet as h, Document as i, map as l, isNode as m, visit as n, stringifyNumber as o, isCollection as p, visitAsync as r, string as s, Directives as t, Alias as u, debug as v, foldFlowLines as x, warn as y };