yaml 2.0.0-0 → 2.0.0-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.
@@ -1,7 +1,8 @@
1
- import { d as defaultTagPrefix, _ as _typeof, a as _createClass, b as _classCallCheck, c as _defineProperty, e as _createForOfIteratorHelper, Y as YAMLSyntaxError, T as Type, f as YAMLWarning, g as YAMLSemanticError, h as _slicedToArray, i as YAMLError, j as _inherits, k as _createSuper } from './PlainValue-6b68dc0e.js';
2
- import { D as Document$2, p as parse$1 } from './parse-6e806192.js';
3
- import { b as binaryOptions, a as boolOptions, i as intOptions, n as nullOptions, s as strOptions, N as Node, P as Pair, S as Scalar, c as stringifyString, A as Alias, Y as YAMLSeq, d as YAMLMap, M as Merge, C as Collection, r as resolveNode, e as createNode, f as isEmptyPath, g as collectionFromPath, t as toJSON, h as addComment } from './resolveSeq-3477c430.js';
4
- import { S as Schema } from './Schema-d14032c2.js';
1
+ import { d as defaultTagPrefix, _ as _typeof, a as _createClass, b as _classCallCheck, c as _defineProperty, e as _slicedToArray, Y as YAMLSemanticError, T as Type, f as defaultTags, g as YAMLWarning, h as _createForOfIteratorHelper, i as YAMLSyntaxError, C as Char, j as YAMLReferenceError, k as YAMLError } from './errors-2634d01a.js';
2
+ import { P as PlainValue, D as Document$1, p as parse$1 } from './parse-d1ba890f.js';
3
+ export { p as parseCST } from './parse-d1ba890f.js';
4
+ import { b as binaryOptions, a as boolOptions, i as intOptions, n as nullOptions, s as strOptions, N as Node, P as Pair, S as Scalar, c as stringifyString, A as Alias, Y as YAMLSeq, d as YAMLMap, C as Collection, r as resolveScalar, e as createNode, f as isEmptyPath, g as collectionFromPath, t as toJS, h as addComment } from './stringifyNumber-d8af95b1.js';
5
+ import { M as Merge, a as MERGE_KEY, S as Schema } from './Schema-ea978338.js';
5
6
 
6
7
  var defaultOptions = {
7
8
  anchorPrefix: 'a',
@@ -10,7 +11,7 @@ var defaultOptions = {
10
11
  indentSeq: true,
11
12
  keepCstNodes: false,
12
13
  keepNodeTypes: true,
13
- keepBlobsInJSON: true,
14
+ keepUndefined: false,
14
15
  mapAsMap: false,
15
16
  maxAliasCount: 100,
16
17
  prettyErrors: true,
@@ -224,7 +225,7 @@ var Anchors = /*#__PURE__*/function () {
224
225
  function Anchors(prefix) {
225
226
  _classCallCheck(this, Anchors);
226
227
 
227
- _defineProperty(this, "map", {});
228
+ _defineProperty(this, "map", Object.create(null));
228
229
 
229
230
  this.prefix = prefix;
230
231
  }
@@ -341,6 +342,58 @@ var Anchors = /*#__PURE__*/function () {
341
342
  return Anchors;
342
343
  }();
343
344
 
345
+ /**
346
+ * Applies the JSON.parse reviver algorithm as defined in the ECMA-262 spec,
347
+ * in section 24.5.1.1 "Runtime Semantics: InternalizeJSONProperty" of the
348
+ * 2021 edition: https://tc39.es/ecma262/#sec-json.parse
349
+ *
350
+ * Includes extensions for handling Map and Set objects.
351
+ */
352
+ function applyReviver(reviver, obj, key, val) {
353
+ if (val && _typeof(val) === 'object') {
354
+ if (Array.isArray(val)) {
355
+ for (var i = 0, len = val.length; i < len; ++i) {
356
+ var v0 = val[i];
357
+ var v1 = applyReviver(reviver, val, String(i), v0);
358
+ if (v1 === undefined) delete val[i];else if (v1 !== v0) val[i] = v1;
359
+ }
360
+ } else if (val instanceof Map) {
361
+ for (var _i = 0, _Array$from = Array.from(val.keys()); _i < _Array$from.length; _i++) {
362
+ var k = _Array$from[_i];
363
+
364
+ var _v = val.get(k);
365
+
366
+ var _v2 = applyReviver(reviver, val, k, _v);
367
+
368
+ if (_v2 === undefined) val.delete(k);else if (_v2 !== _v) val.set(k, _v2);
369
+ }
370
+ } else if (val instanceof Set) {
371
+ for (var _i2 = 0, _Array$from2 = Array.from(val); _i2 < _Array$from2.length; _i2++) {
372
+ var _v3 = _Array$from2[_i2];
373
+
374
+ var _v4 = applyReviver(reviver, val, _v3, _v3);
375
+
376
+ if (_v4 === undefined) val.delete(_v3);else if (_v4 !== _v3) {
377
+ val.delete(_v3);
378
+ val.add(_v4);
379
+ }
380
+ }
381
+ } else {
382
+ for (var _i3 = 0, _Object$entries = Object.entries(val); _i3 < _Object$entries.length; _i3++) {
383
+ var _Object$entries$_i = _slicedToArray(_Object$entries[_i3], 2),
384
+ _k = _Object$entries$_i[0],
385
+ _v5 = _Object$entries$_i[1];
386
+
387
+ var _v6 = applyReviver(reviver, val, _k, _v5);
388
+
389
+ if (_v6 === undefined) delete val[_k];else if (_v6 !== _v5) val[_k] = _v6;
390
+ }
391
+ }
392
+ }
393
+
394
+ return reviver.call(obj, key, val);
395
+ }
396
+
344
397
  var visit = function visit(node, tags) {
345
398
  if (node && _typeof(node) === 'object') {
346
399
  var tag = node.tag;
@@ -365,6 +418,934 @@ var listTagNames = function listTagNames(node) {
365
418
  return Object.keys(visit(node, {}));
366
419
  };
367
420
 
421
+ function resolveTagHandle(doc, node) {
422
+ var _node$tag = node.tag,
423
+ handle = _node$tag.handle,
424
+ suffix = _node$tag.suffix;
425
+ var prefix = doc.tagPrefixes.find(function (p) {
426
+ return p.handle === handle;
427
+ });
428
+
429
+ if (!prefix) {
430
+ var dtp = doc.getDefaults().tagPrefixes;
431
+ if (dtp) prefix = dtp.find(function (p) {
432
+ return p.handle === handle;
433
+ });
434
+ if (!prefix) throw new YAMLSemanticError(node, "The ".concat(handle, " tag handle is non-default and was not declared."));
435
+ }
436
+
437
+ if (!suffix) throw new YAMLSemanticError(node, "The ".concat(handle, " tag has no suffix."));
438
+
439
+ if (handle === '!' && (doc.version || doc.options.version) === '1.0') {
440
+ if (suffix[0] === '^') {
441
+ doc.warnings.push(new YAMLWarning(node, 'YAML 1.0 ^ tag expansion is not supported'));
442
+ return suffix;
443
+ }
444
+
445
+ if (/[:/]/.test(suffix)) {
446
+ // word/foo -> tag:word.yaml.org,2002:foo
447
+ var vocab = suffix.match(/^([a-z0-9-]+)\/(.*)/i);
448
+ return vocab ? "tag:".concat(vocab[1], ".yaml.org,2002:").concat(vocab[2]) : "tag:".concat(suffix);
449
+ }
450
+ }
451
+
452
+ return prefix.prefix + decodeURIComponent(suffix);
453
+ }
454
+
455
+ function resolveTagName(doc, node) {
456
+ var tag = node.tag,
457
+ type = node.type;
458
+ var nonSpecific = false;
459
+
460
+ if (tag) {
461
+ var handle = tag.handle,
462
+ suffix = tag.suffix,
463
+ verbatim = tag.verbatim;
464
+
465
+ if (verbatim) {
466
+ if (verbatim !== '!' && verbatim !== '!!') return verbatim;
467
+ var msg = "Verbatim tags aren't resolved, so ".concat(verbatim, " is invalid.");
468
+ doc.errors.push(new YAMLSemanticError(node, msg));
469
+ } else if (handle === '!' && !suffix) {
470
+ nonSpecific = true;
471
+ } else {
472
+ try {
473
+ return resolveTagHandle(doc, node);
474
+ } catch (error) {
475
+ doc.errors.push(error);
476
+ }
477
+ }
478
+ }
479
+
480
+ switch (type) {
481
+ case Type.BLOCK_FOLDED:
482
+ case Type.BLOCK_LITERAL:
483
+ case Type.QUOTE_DOUBLE:
484
+ case Type.QUOTE_SINGLE:
485
+ return defaultTags.STR;
486
+
487
+ case Type.FLOW_MAP:
488
+ case Type.MAP:
489
+ return defaultTags.MAP;
490
+
491
+ case Type.FLOW_SEQ:
492
+ case Type.SEQ:
493
+ return defaultTags.SEQ;
494
+
495
+ case Type.PLAIN:
496
+ return nonSpecific ? defaultTags.STR : null;
497
+
498
+ default:
499
+ return null;
500
+ }
501
+ }
502
+
503
+ function checkFlowCollectionEnd(errors, cst) {
504
+ var char, name;
505
+
506
+ switch (cst.type) {
507
+ case Type.FLOW_MAP:
508
+ char = '}';
509
+ name = 'flow map';
510
+ break;
511
+
512
+ case Type.FLOW_SEQ:
513
+ char = ']';
514
+ name = 'flow sequence';
515
+ break;
516
+
517
+ default:
518
+ errors.push(new YAMLSemanticError(cst, 'Not a flow collection!?'));
519
+ return;
520
+ }
521
+
522
+ var lastItem;
523
+
524
+ for (var i = cst.items.length - 1; i >= 0; --i) {
525
+ var item = cst.items[i];
526
+
527
+ if (!item || item.type !== Type.COMMENT) {
528
+ lastItem = item;
529
+ break;
530
+ }
531
+ }
532
+
533
+ if (lastItem && lastItem.char !== char) {
534
+ var msg = "Expected ".concat(name, " to end with ").concat(char);
535
+ var err;
536
+
537
+ if (typeof lastItem.offset === 'number') {
538
+ err = new YAMLSemanticError(cst, msg);
539
+ err.offset = lastItem.offset + 1;
540
+ } else {
541
+ err = new YAMLSemanticError(lastItem, msg);
542
+ if (lastItem.range && lastItem.range.end) err.offset = lastItem.range.end - lastItem.range.start;
543
+ }
544
+
545
+ errors.push(err);
546
+ }
547
+ }
548
+ function checkFlowCommentSpace(errors, comment) {
549
+ var prev = comment.context.src[comment.range.start - 1];
550
+
551
+ if (prev !== '\n' && prev !== '\t' && prev !== ' ') {
552
+ var msg = 'Comments must be separated from other tokens by white space characters';
553
+ errors.push(new YAMLSemanticError(comment, msg));
554
+ }
555
+ }
556
+ function getLongKeyError(source, key) {
557
+ var sk = String(key);
558
+ var k = sk.substr(0, 8) + '...' + sk.substr(-8);
559
+ return new YAMLSemanticError(source, "The \"".concat(k, "\" key is too long"));
560
+ }
561
+ function resolveComments(collection, comments) {
562
+ var _iterator = _createForOfIteratorHelper(comments),
563
+ _step;
564
+
565
+ try {
566
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
567
+ var _step$value = _step.value,
568
+ afterKey = _step$value.afterKey,
569
+ before = _step$value.before,
570
+ comment = _step$value.comment;
571
+ var item = collection.items[before];
572
+
573
+ if (!item) {
574
+ if (comment !== undefined) {
575
+ if (collection.comment) collection.comment += '\n' + comment;else collection.comment = comment;
576
+ }
577
+ } else {
578
+ if (afterKey && item.value) item = item.value;
579
+
580
+ if (comment === undefined) {
581
+ if (afterKey || !item.commentBefore) item.spaceBefore = true;
582
+ } else {
583
+ if (item.commentBefore) item.commentBefore += '\n' + comment;else item.commentBefore = comment;
584
+ }
585
+ }
586
+ }
587
+ } catch (err) {
588
+ _iterator.e(err);
589
+ } finally {
590
+ _iterator.f();
591
+ }
592
+ }
593
+
594
+ function resolveMap(doc, cst) {
595
+ var _ref = cst.type === Type.FLOW_MAP ? resolveFlowMapItems(doc, cst) : resolveBlockMapItems(doc, cst),
596
+ comments = _ref.comments,
597
+ items = _ref.items;
598
+
599
+ var map = new YAMLMap(doc.schema);
600
+ map.items = items;
601
+ resolveComments(map, comments);
602
+ var hasCollectionKey = false;
603
+
604
+ for (var i = 0; i < items.length; ++i) {
605
+ var iKey = items[i].key;
606
+ if (iKey instanceof Collection) hasCollectionKey = true;
607
+
608
+ if (doc.schema.merge && iKey && iKey.value === MERGE_KEY) {
609
+ items[i] = new Merge(items[i]);
610
+ var sources = items[i].value.items;
611
+ var error = null;
612
+ sources.some(function (node) {
613
+ if (node instanceof Alias) {
614
+ // During parsing, alias sources are CST nodes; to account for
615
+ // circular references their resolved values can't be used here.
616
+ var type = node.source.type;
617
+ if (type === Type.MAP || type === Type.FLOW_MAP) return false;
618
+ return error = 'Merge nodes aliases can only point to maps';
619
+ }
620
+
621
+ return error = 'Merge nodes can only have Alias nodes as values';
622
+ });
623
+ if (error) doc.errors.push(new YAMLSemanticError(cst, error));
624
+ } else {
625
+ for (var j = i + 1; j < items.length; ++j) {
626
+ var jKey = items[j].key;
627
+
628
+ if (iKey === jKey || iKey && jKey && Object.prototype.hasOwnProperty.call(iKey, 'value') && iKey.value === jKey.value) {
629
+ var msg = "Map keys must be unique; \"".concat(iKey, "\" is repeated");
630
+ doc.errors.push(new YAMLSemanticError(cst, msg));
631
+ break;
632
+ }
633
+ }
634
+ }
635
+ }
636
+
637
+ if (hasCollectionKey && !doc.options.mapAsMap) {
638
+ var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
639
+ doc.warnings.push(new YAMLWarning(cst, warn));
640
+ }
641
+
642
+ cst.resolved = map;
643
+ return map;
644
+ }
645
+
646
+ var valueHasPairComment = function valueHasPairComment(_ref2) {
647
+ var _ref2$context = _ref2.context,
648
+ lineStart = _ref2$context.lineStart,
649
+ node = _ref2$context.node,
650
+ src = _ref2$context.src,
651
+ props = _ref2.props;
652
+ if (props.length === 0) return false;
653
+ var start = props[0].start;
654
+ if (node && start > node.valueRange.start) return false;
655
+ if (src[start] !== Char.COMMENT) return false;
656
+
657
+ for (var i = lineStart; i < start; ++i) {
658
+ if (src[i] === '\n') return false;
659
+ }
660
+
661
+ return true;
662
+ };
663
+
664
+ function resolvePairComment(item, pair) {
665
+ if (!valueHasPairComment(item)) return;
666
+ var comment = item.getPropValue(0, Char.COMMENT, true);
667
+ var found = false;
668
+ var cb = pair.value.commentBefore;
669
+
670
+ if (cb && cb.startsWith(comment)) {
671
+ pair.value.commentBefore = cb.substr(comment.length + 1);
672
+ found = true;
673
+ } else {
674
+ var cc = pair.value.comment;
675
+
676
+ if (!item.node && cc && cc.startsWith(comment)) {
677
+ pair.value.comment = cc.substr(comment.length + 1);
678
+ found = true;
679
+ }
680
+ }
681
+
682
+ if (found) pair.comment = comment;
683
+ }
684
+
685
+ function resolveBlockMapItems(doc, cst) {
686
+ var comments = [];
687
+ var items = [];
688
+ var key = undefined;
689
+ var keyStart = null;
690
+
691
+ for (var i = 0; i < cst.items.length; ++i) {
692
+ var item = cst.items[i];
693
+
694
+ switch (item.type) {
695
+ case Type.BLANK_LINE:
696
+ comments.push({
697
+ afterKey: !!key,
698
+ before: items.length
699
+ });
700
+ break;
701
+
702
+ case Type.COMMENT:
703
+ comments.push({
704
+ afterKey: !!key,
705
+ before: items.length,
706
+ comment: item.comment
707
+ });
708
+ break;
709
+
710
+ case Type.MAP_KEY:
711
+ if (key !== undefined) items.push(new Pair(key));
712
+ if (item.error) doc.errors.push(item.error);
713
+ key = resolveNode(doc, item.node);
714
+ keyStart = null;
715
+ break;
716
+
717
+ case Type.MAP_VALUE:
718
+ {
719
+ if (key === undefined) key = null;
720
+ if (item.error) doc.errors.push(item.error);
721
+
722
+ if (!item.context.atLineStart && item.node && item.node.type === Type.MAP && !item.node.context.atLineStart) {
723
+ var msg = 'Nested mappings are not allowed in compact mappings';
724
+ doc.errors.push(new YAMLSemanticError(item.node, msg));
725
+ }
726
+
727
+ var valueNode = item.node;
728
+
729
+ if (!valueNode && item.props.length > 0) {
730
+ // Comments on an empty mapping value need to be preserved, so we
731
+ // need to construct a minimal empty node here to use instead of the
732
+ // missing `item.node`. -- eemeli/yaml#19
733
+ valueNode = new PlainValue(Type.PLAIN, []);
734
+ valueNode.context = {
735
+ parent: item,
736
+ src: item.context.src
737
+ };
738
+ var pos = item.range.start + 1;
739
+ valueNode.range = {
740
+ start: pos,
741
+ end: pos
742
+ };
743
+ valueNode.valueRange = {
744
+ start: pos,
745
+ end: pos
746
+ };
747
+
748
+ if (typeof item.range.origStart === 'number') {
749
+ var origPos = item.range.origStart + 1;
750
+ valueNode.range.origStart = valueNode.range.origEnd = origPos;
751
+ valueNode.valueRange.origStart = valueNode.valueRange.origEnd = origPos;
752
+ }
753
+ }
754
+
755
+ var pair = new Pair(key, resolveNode(doc, valueNode));
756
+ resolvePairComment(item, pair);
757
+ items.push(pair);
758
+
759
+ if (key && typeof keyStart === 'number') {
760
+ if (item.range.start > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
761
+ }
762
+
763
+ key = undefined;
764
+ keyStart = null;
765
+ }
766
+ break;
767
+
768
+ default:
769
+ if (key !== undefined) items.push(new Pair(key));
770
+ key = resolveNode(doc, item);
771
+ keyStart = item.range.start;
772
+ if (item.error) doc.errors.push(item.error);
773
+
774
+ next: for (var j = i + 1;; ++j) {
775
+ var nextItem = cst.items[j];
776
+
777
+ switch (nextItem && nextItem.type) {
778
+ case Type.BLANK_LINE:
779
+ case Type.COMMENT:
780
+ continue next;
781
+
782
+ case Type.MAP_VALUE:
783
+ break next;
784
+
785
+ default:
786
+ {
787
+ var _msg = 'Implicit map keys need to be followed by map values';
788
+ doc.errors.push(new YAMLSemanticError(item, _msg));
789
+ break next;
790
+ }
791
+ }
792
+ }
793
+
794
+ if (item.valueRangeContainsNewline) {
795
+ var _msg2 = 'Implicit map keys need to be on a single line';
796
+ doc.errors.push(new YAMLSemanticError(item, _msg2));
797
+ }
798
+
799
+ }
800
+ }
801
+
802
+ if (key !== undefined) items.push(new Pair(key));
803
+ return {
804
+ comments: comments,
805
+ items: items
806
+ };
807
+ }
808
+
809
+ function resolveFlowMapItems(doc, cst) {
810
+ var comments = [];
811
+ var items = [];
812
+ var key = undefined;
813
+ var explicitKey = false;
814
+ var next = '{';
815
+
816
+ for (var i = 0; i < cst.items.length; ++i) {
817
+ var item = cst.items[i];
818
+
819
+ if (typeof item.char === 'string') {
820
+ var char = item.char,
821
+ offset = item.offset;
822
+
823
+ if (char === '?' && key === undefined && !explicitKey) {
824
+ explicitKey = true;
825
+ next = ':';
826
+ continue;
827
+ }
828
+
829
+ if (char === ':') {
830
+ if (key === undefined) key = null;
831
+
832
+ if (next === ':') {
833
+ next = ',';
834
+ continue;
835
+ }
836
+ } else {
837
+ if (explicitKey) {
838
+ if (key === undefined && char !== ',') key = null;
839
+ explicitKey = false;
840
+ }
841
+
842
+ if (key !== undefined) {
843
+ items.push(new Pair(key));
844
+ key = undefined;
845
+
846
+ if (char === ',') {
847
+ next = ':';
848
+ continue;
849
+ }
850
+ }
851
+ }
852
+
853
+ if (char === '}') {
854
+ if (i === cst.items.length - 1) continue;
855
+ } else if (char === next) {
856
+ next = ':';
857
+ continue;
858
+ }
859
+
860
+ var msg = "Flow map contains an unexpected ".concat(char);
861
+ var err = new YAMLSyntaxError(cst, msg);
862
+ err.offset = offset;
863
+ doc.errors.push(err);
864
+ } else if (item.type === Type.BLANK_LINE) {
865
+ comments.push({
866
+ afterKey: !!key,
867
+ before: items.length
868
+ });
869
+ } else if (item.type === Type.COMMENT) {
870
+ checkFlowCommentSpace(doc.errors, item);
871
+ comments.push({
872
+ afterKey: !!key,
873
+ before: items.length,
874
+ comment: item.comment
875
+ });
876
+ } else if (key === undefined) {
877
+ if (next === ',') doc.errors.push(new YAMLSemanticError(item, 'Separator , missing in flow map'));
878
+ key = resolveNode(doc, item);
879
+ } else {
880
+ if (next !== ',') doc.errors.push(new YAMLSemanticError(item, 'Indicator : missing in flow map entry'));
881
+ items.push(new Pair(key, resolveNode(doc, item)));
882
+ key = undefined;
883
+ explicitKey = false;
884
+ }
885
+ }
886
+
887
+ checkFlowCollectionEnd(doc.errors, cst);
888
+ if (key !== undefined) items.push(new Pair(key));
889
+ return {
890
+ comments: comments,
891
+ items: items
892
+ };
893
+ }
894
+
895
+ function resolveSeq(doc, cst) {
896
+ var _ref = cst.type === Type.FLOW_SEQ ? resolveFlowSeqItems(doc, cst) : resolveBlockSeqItems(doc, cst),
897
+ comments = _ref.comments,
898
+ items = _ref.items;
899
+
900
+ var seq = new YAMLSeq(doc.schema);
901
+ seq.items = items;
902
+ resolveComments(seq, comments);
903
+
904
+ if (!doc.options.mapAsMap && items.some(function (it) {
905
+ return it instanceof Pair && it.key instanceof Collection;
906
+ })) {
907
+ var warn = 'Keys with collection values will be stringified as YAML due to JS Object restrictions. Use mapAsMap: true to avoid this.';
908
+ doc.warnings.push(new YAMLWarning(cst, warn));
909
+ }
910
+
911
+ cst.resolved = seq;
912
+ return seq;
913
+ }
914
+
915
+ function resolveBlockSeqItems(doc, cst) {
916
+ var comments = [];
917
+ var items = [];
918
+
919
+ for (var i = 0; i < cst.items.length; ++i) {
920
+ var item = cst.items[i];
921
+
922
+ switch (item.type) {
923
+ case Type.BLANK_LINE:
924
+ comments.push({
925
+ before: items.length
926
+ });
927
+ break;
928
+
929
+ case Type.COMMENT:
930
+ comments.push({
931
+ comment: item.comment,
932
+ before: items.length
933
+ });
934
+ break;
935
+
936
+ case Type.SEQ_ITEM:
937
+ if (item.error) doc.errors.push(item.error);
938
+ items.push(resolveNode(doc, item.node));
939
+
940
+ if (item.hasProps) {
941
+ var msg = 'Sequence items cannot have tags or anchors before the - indicator';
942
+ doc.errors.push(new YAMLSemanticError(item, msg));
943
+ }
944
+
945
+ break;
946
+
947
+ default:
948
+ if (item.error) doc.errors.push(item.error);
949
+ doc.errors.push(new YAMLSyntaxError(item, "Unexpected ".concat(item.type, " node in sequence")));
950
+ }
951
+ }
952
+
953
+ return {
954
+ comments: comments,
955
+ items: items
956
+ };
957
+ }
958
+
959
+ function resolveFlowSeqItems(doc, cst) {
960
+ var comments = [];
961
+ var items = [];
962
+ var explicitKey = false;
963
+ var key = undefined;
964
+ var keyStart = null;
965
+ var next = '[';
966
+ var prevItem = null;
967
+
968
+ for (var i = 0; i < cst.items.length; ++i) {
969
+ var item = cst.items[i];
970
+
971
+ if (typeof item.char === 'string') {
972
+ var char = item.char,
973
+ offset = item.offset;
974
+
975
+ if (char !== ':' && (explicitKey || key !== undefined)) {
976
+ if (explicitKey && key === undefined) key = next ? items.pop() : null;
977
+ items.push(new Pair(key));
978
+ explicitKey = false;
979
+ key = undefined;
980
+ keyStart = null;
981
+ }
982
+
983
+ if (char === next) {
984
+ next = null;
985
+ } else if (!next && char === '?') {
986
+ explicitKey = true;
987
+ } else if (next !== '[' && char === ':' && key === undefined) {
988
+ if (next === ',') {
989
+ key = items.pop();
990
+
991
+ if (key instanceof Pair) {
992
+ var msg = 'Chaining flow sequence pairs is invalid';
993
+ var err = new YAMLSemanticError(cst, msg);
994
+ err.offset = offset;
995
+ doc.errors.push(err);
996
+ }
997
+
998
+ if (!explicitKey && typeof keyStart === 'number') {
999
+ var keyEnd = item.range ? item.range.start : item.offset;
1000
+ if (keyEnd > keyStart + 1024) doc.errors.push(getLongKeyError(cst, key));
1001
+ var src = prevItem.context.src;
1002
+
1003
+ for (var _i = keyStart; _i < keyEnd; ++_i) {
1004
+ if (src[_i] === '\n') {
1005
+ var _msg = 'Implicit keys of flow sequence pairs need to be on a single line';
1006
+ doc.errors.push(new YAMLSemanticError(prevItem, _msg));
1007
+ break;
1008
+ }
1009
+ }
1010
+ }
1011
+ } else {
1012
+ key = null;
1013
+ }
1014
+
1015
+ keyStart = null;
1016
+ explicitKey = false;
1017
+ next = null;
1018
+ } else if (next === '[' || char !== ']' || i < cst.items.length - 1) {
1019
+ var _msg2 = "Flow sequence contains an unexpected ".concat(char);
1020
+
1021
+ var _err = new YAMLSyntaxError(cst, _msg2);
1022
+
1023
+ _err.offset = offset;
1024
+ doc.errors.push(_err);
1025
+ }
1026
+ } else if (item.type === Type.BLANK_LINE) {
1027
+ comments.push({
1028
+ before: items.length
1029
+ });
1030
+ } else if (item.type === Type.COMMENT) {
1031
+ checkFlowCommentSpace(doc.errors, item);
1032
+ comments.push({
1033
+ comment: item.comment,
1034
+ before: items.length
1035
+ });
1036
+ } else {
1037
+ if (next) {
1038
+ var _msg3 = "Expected a ".concat(next, " in flow sequence");
1039
+
1040
+ doc.errors.push(new YAMLSemanticError(item, _msg3));
1041
+ }
1042
+
1043
+ var value = resolveNode(doc, item);
1044
+
1045
+ if (key === undefined) {
1046
+ items.push(value);
1047
+ prevItem = item;
1048
+ } else {
1049
+ items.push(new Pair(key, value));
1050
+ key = undefined;
1051
+ }
1052
+
1053
+ keyStart = item.range.start;
1054
+ next = ',';
1055
+ }
1056
+ }
1057
+
1058
+ checkFlowCollectionEnd(doc.errors, cst);
1059
+ if (key !== undefined) items.push(new Pair(key));
1060
+ return {
1061
+ comments: comments,
1062
+ items: items
1063
+ };
1064
+ }
1065
+
1066
+ function resolveByTagName(_ref, tagName, value, onError) {
1067
+ var knownTags = _ref.knownTags,
1068
+ tags = _ref.tags;
1069
+ var matchWithTest = [];
1070
+
1071
+ var _iterator = _createForOfIteratorHelper(tags),
1072
+ _step;
1073
+
1074
+ try {
1075
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1076
+ var tag = _step.value;
1077
+
1078
+ if (tag.tag === tagName) {
1079
+ if (tag.test) {
1080
+ if (typeof value === 'string') matchWithTest.push(tag);else onError("The tag ".concat(tagName, " cannot be applied to a collection"));
1081
+ } else {
1082
+ var _res = tag.resolve(value, onError);
1083
+
1084
+ return _res instanceof Collection ? _res : new Scalar(_res);
1085
+ }
1086
+ }
1087
+ }
1088
+ } catch (err) {
1089
+ _iterator.e(err);
1090
+ } finally {
1091
+ _iterator.f();
1092
+ }
1093
+
1094
+ if (matchWithTest.length > 0) return resolveScalar(value, matchWithTest);
1095
+ var kt = knownTags[tagName];
1096
+
1097
+ if (kt) {
1098
+ tags.push(Object.assign({}, kt, {
1099
+ default: false,
1100
+ test: undefined
1101
+ }));
1102
+ var res = kt.resolve(value, onError);
1103
+ return res instanceof Collection ? res : new Scalar(res);
1104
+ }
1105
+
1106
+ return null;
1107
+ }
1108
+
1109
+ function resolveTag(doc, node, tagName) {
1110
+ var MAP = defaultTags.MAP,
1111
+ SEQ = defaultTags.SEQ,
1112
+ STR = defaultTags.STR;
1113
+ var value, fallback;
1114
+
1115
+ var onError = function onError(message) {
1116
+ return doc.errors.push(new YAMLSemanticError(node, message));
1117
+ };
1118
+
1119
+ try {
1120
+ switch (node.type) {
1121
+ case Type.FLOW_MAP:
1122
+ case Type.MAP:
1123
+ value = resolveMap(doc, node);
1124
+ fallback = MAP;
1125
+ if (tagName === SEQ || tagName === STR) onError("The tag ".concat(tagName, " cannot be applied to a mapping"));
1126
+ break;
1127
+
1128
+ case Type.FLOW_SEQ:
1129
+ case Type.SEQ:
1130
+ value = resolveSeq(doc, node);
1131
+ fallback = SEQ;
1132
+ if (tagName === MAP || tagName === STR) onError("The tag ".concat(tagName, " cannot be applied to a sequence"));
1133
+ break;
1134
+
1135
+ default:
1136
+ value = node.strValue || '';
1137
+
1138
+ if (typeof value !== 'string') {
1139
+ value.errors.forEach(function (error) {
1140
+ return doc.errors.push(error);
1141
+ });
1142
+ value = value.str;
1143
+ }
1144
+
1145
+ if (tagName === MAP || tagName === SEQ) onError("The tag ".concat(tagName, " cannot be applied to a scalar"));
1146
+ fallback = STR;
1147
+ }
1148
+
1149
+ var res = resolveByTagName(doc.schema, tagName, value, onError);
1150
+
1151
+ if (res) {
1152
+ if (tagName && node.tag) res.tag = tagName;
1153
+ return res;
1154
+ }
1155
+ } catch (error) {
1156
+ /* istanbul ignore if */
1157
+ if (!error.source) error.source = node;
1158
+ doc.errors.push(error);
1159
+ return null;
1160
+ }
1161
+
1162
+ try {
1163
+ if (!fallback) throw new Error("The tag ".concat(tagName, " is unavailable"));
1164
+ var msg = "The tag ".concat(tagName, " is unavailable, falling back to ").concat(fallback);
1165
+ doc.warnings.push(new YAMLWarning(node, msg));
1166
+
1167
+ var _res2 = resolveByTagName(doc.schema, fallback, value, onError);
1168
+
1169
+ _res2.tag = tagName;
1170
+ return _res2;
1171
+ } catch (error) {
1172
+ var refError = new YAMLReferenceError(node, error.message);
1173
+ refError.stack = error.stack;
1174
+ doc.errors.push(refError);
1175
+ return null;
1176
+ }
1177
+ }
1178
+
1179
+ var isCollectionItem = function isCollectionItem(node) {
1180
+ if (!node) return false;
1181
+ var type = node.type;
1182
+ return type === Type.MAP_KEY || type === Type.MAP_VALUE || type === Type.SEQ_ITEM;
1183
+ };
1184
+
1185
+ function resolveNodeProps(errors, node) {
1186
+ var comments = {
1187
+ before: [],
1188
+ after: []
1189
+ };
1190
+ var hasAnchor = false;
1191
+ var hasTag = false;
1192
+ var props = isCollectionItem(node.context.parent) ? node.context.parent.props.concat(node.props) : node.props;
1193
+
1194
+ var _iterator = _createForOfIteratorHelper(props),
1195
+ _step;
1196
+
1197
+ try {
1198
+ for (_iterator.s(); !(_step = _iterator.n()).done;) {
1199
+ var _step$value = _step.value,
1200
+ start = _step$value.start,
1201
+ end = _step$value.end;
1202
+
1203
+ switch (node.context.src[start]) {
1204
+ case Char.COMMENT:
1205
+ {
1206
+ if (!node.commentHasRequiredWhitespace(start)) {
1207
+ var msg = 'Comments must be separated from other tokens by white space characters';
1208
+ errors.push(new YAMLSemanticError(node, msg));
1209
+ }
1210
+
1211
+ var header = node.header,
1212
+ valueRange = node.valueRange;
1213
+ var cc = valueRange && (start > valueRange.start || header && start > header.start) ? comments.after : comments.before;
1214
+ cc.push(node.context.src.slice(start + 1, end));
1215
+ break;
1216
+ }
1217
+ // Actual anchor & tag resolution is handled by schema, here we just complain
1218
+
1219
+ case Char.ANCHOR:
1220
+ if (hasAnchor) {
1221
+ var _msg = 'A node can have at most one anchor';
1222
+ errors.push(new YAMLSemanticError(node, _msg));
1223
+ }
1224
+
1225
+ hasAnchor = true;
1226
+ break;
1227
+
1228
+ case Char.TAG:
1229
+ if (hasTag) {
1230
+ var _msg2 = 'A node can have at most one tag';
1231
+ errors.push(new YAMLSemanticError(node, _msg2));
1232
+ }
1233
+
1234
+ hasTag = true;
1235
+ break;
1236
+ }
1237
+ }
1238
+ } catch (err) {
1239
+ _iterator.e(err);
1240
+ } finally {
1241
+ _iterator.f();
1242
+ }
1243
+
1244
+ return {
1245
+ comments: comments,
1246
+ hasAnchor: hasAnchor,
1247
+ hasTag: hasTag
1248
+ };
1249
+ }
1250
+
1251
+ function resolveNodeValue(doc, node) {
1252
+ var anchors = doc.anchors,
1253
+ errors = doc.errors,
1254
+ schema = doc.schema;
1255
+
1256
+ if (node.type === Type.ALIAS) {
1257
+ var name = node.rawValue;
1258
+ var src = anchors.getNode(name);
1259
+
1260
+ if (!src) {
1261
+ var msg = "Aliased anchor not found: ".concat(name);
1262
+ errors.push(new YAMLReferenceError(node, msg));
1263
+ return null;
1264
+ } // Lazy resolution for circular references
1265
+
1266
+
1267
+ var res = new Alias(src);
1268
+
1269
+ anchors._cstAliases.push(res);
1270
+
1271
+ return res;
1272
+ }
1273
+
1274
+ var tagName = resolveTagName(doc, node);
1275
+ if (tagName) return resolveTag(doc, node, tagName);
1276
+
1277
+ if (node.type !== Type.PLAIN) {
1278
+ var _msg3 = "Failed to resolve ".concat(node.type, " node here");
1279
+
1280
+ errors.push(new YAMLSyntaxError(node, _msg3));
1281
+ return null;
1282
+ }
1283
+
1284
+ try {
1285
+ var str = node.strValue || '';
1286
+
1287
+ if (typeof str !== 'string') {
1288
+ str.errors.forEach(function (error) {
1289
+ return doc.errors.push(error);
1290
+ });
1291
+ str = str.str;
1292
+ }
1293
+
1294
+ return resolveScalar(str, schema.tags);
1295
+ } catch (error) {
1296
+ if (!error.source) error.source = node;
1297
+ errors.push(error);
1298
+ return null;
1299
+ }
1300
+ } // sets node.resolved on success
1301
+
1302
+
1303
+ function resolveNode(doc, node) {
1304
+ if (!node) return null;
1305
+ if (node.error) doc.errors.push(node.error);
1306
+
1307
+ var _resolveNodeProps = resolveNodeProps(doc.errors, node),
1308
+ comments = _resolveNodeProps.comments,
1309
+ hasAnchor = _resolveNodeProps.hasAnchor,
1310
+ hasTag = _resolveNodeProps.hasTag;
1311
+
1312
+ if (hasAnchor) {
1313
+ var anchors = doc.anchors;
1314
+ var name = node.anchor;
1315
+ var prev = anchors.getNode(name); // At this point, aliases for any preceding node with the same anchor
1316
+ // name have already been resolved, so it may safely be renamed.
1317
+
1318
+ if (prev) anchors.map[anchors.newName(name)] = prev; // During parsing, we need to store the CST node in anchors.map as
1319
+ // anchors need to be available during resolution to allow for
1320
+ // circular references.
1321
+
1322
+ anchors.map[name] = node;
1323
+ }
1324
+
1325
+ if (node.type === Type.ALIAS && (hasAnchor || hasTag)) {
1326
+ var msg = 'An alias node must not specify any properties';
1327
+ doc.errors.push(new YAMLSemanticError(node, msg));
1328
+ }
1329
+
1330
+ var res = resolveNodeValue(doc, node);
1331
+
1332
+ if (res) {
1333
+ res.range = [node.range.start, node.range.end];
1334
+ if (doc.options.keepCstNodes) res.cstNode = node;
1335
+ if (doc.options.keepNodeTypes) res.type = node.type;
1336
+ var cb = comments.before.join('\n');
1337
+
1338
+ if (cb) {
1339
+ res.commentBefore = res.commentBefore ? "".concat(res.commentBefore, "\n").concat(cb) : cb;
1340
+ }
1341
+
1342
+ var ca = comments.after.join('\n');
1343
+ if (ca) res.comment = res.comment ? "".concat(res.comment, "\n").concat(ca) : ca;
1344
+ }
1345
+
1346
+ return node.resolved = res;
1347
+ }
1348
+
368
1349
  function parseContents(doc, contents) {
369
1350
  var comments = {
370
1351
  before: [],
@@ -557,15 +1538,20 @@ function assertCollection(contents) {
557
1538
  }
558
1539
 
559
1540
  var Document = /*#__PURE__*/function () {
560
- function Document(value, options) {
1541
+ function Document(value, replacer, options) {
561
1542
  _classCallCheck(this, Document);
562
1543
 
563
- this.anchors = new Anchors(options.anchorPrefix);
1544
+ if (options === undefined && replacer && _typeof(replacer) === 'object' && !Array.isArray(replacer)) {
1545
+ options = replacer;
1546
+ replacer = undefined;
1547
+ }
1548
+
1549
+ this.options = Object.assign({}, defaultOptions, options);
1550
+ this.anchors = new Anchors(this.options.anchorPrefix);
564
1551
  this.commentBefore = null;
565
1552
  this.comment = null;
566
1553
  this.directivesEndMarker = null;
567
1554
  this.errors = [];
568
- this.options = options;
569
1555
  this.schema = null;
570
1556
  this.tagPrefixes = [];
571
1557
  this.version = null;
@@ -574,10 +1560,12 @@ var Document = /*#__PURE__*/function () {
574
1560
  if (value === undefined) {
575
1561
  // note that this.schema is left as null here
576
1562
  this.contents = null;
577
- } else if (value instanceof Document$2) {
1563
+ } else if (value instanceof Document$1) {
578
1564
  this.parse(value);
579
1565
  } else {
580
- this.contents = this.createNode(value);
1566
+ this.contents = this.createNode(value, {
1567
+ replacer: replacer
1568
+ });
581
1569
  }
582
1570
  }
583
1571
 
@@ -597,13 +1585,27 @@ var Document = /*#__PURE__*/function () {
597
1585
  key: "createNode",
598
1586
  value: function createNode$1(value) {
599
1587
  var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
1588
+ keepUndefined = _ref.keepUndefined,
600
1589
  onTagObj = _ref.onTagObj,
1590
+ replacer = _ref.replacer,
601
1591
  tag = _ref.tag,
602
1592
  wrapScalars = _ref.wrapScalars;
603
1593
 
604
1594
  this.setSchema();
1595
+ if (typeof replacer === 'function') value = replacer.call({
1596
+ '': value
1597
+ }, '', value);else if (Array.isArray(replacer)) {
1598
+ var keyToStr = function keyToStr(v) {
1599
+ return typeof v === 'number' || v instanceof String || v instanceof Number;
1600
+ };
1601
+
1602
+ var asStr = replacer.filter(keyToStr).map(String);
1603
+ if (asStr.length > 0) replacer = replacer.concat(asStr);
1604
+ }
1605
+ if (typeof keepUndefined !== 'boolean') keepUndefined = !!this.options.keepUndefined;
605
1606
  var aliasNodes = [];
606
1607
  var ctx = {
1608
+ keepUndefined: keepUndefined,
607
1609
  onAlias: function onAlias(source) {
608
1610
  var alias = new Alias(source);
609
1611
  aliasNodes.push(alias);
@@ -611,6 +1613,7 @@ var Document = /*#__PURE__*/function () {
611
1613
  },
612
1614
  onTagObj: onTagObj,
613
1615
  prevObjects: new Map(),
1616
+ replacer: replacer,
614
1617
  schema: this.schema,
615
1618
  wrapScalars: wrapScalars !== false
616
1619
  };
@@ -810,37 +1813,38 @@ var Document = /*#__PURE__*/function () {
810
1813
  }
811
1814
  }
812
1815
  }, {
813
- key: "toJSON",
814
- value: function toJSON$1(arg, onAnchor) {
815
- var _this = this;
816
-
817
- var _this$options = this.options,
818
- keepBlobsInJSON = _this$options.keepBlobsInJSON,
819
- mapAsMap = _this$options.mapAsMap,
820
- maxAliasCount = _this$options.maxAliasCount;
821
- var keep = keepBlobsInJSON && (typeof arg !== 'string' || !(this.contents instanceof Scalar));
1816
+ key: "toJS",
1817
+ value: function toJS$1() {
1818
+ var _ref2 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
1819
+ json = _ref2.json,
1820
+ jsonArg = _ref2.jsonArg,
1821
+ mapAsMap = _ref2.mapAsMap,
1822
+ onAnchor = _ref2.onAnchor,
1823
+ reviver = _ref2.reviver;
1824
+
1825
+ var anchorNodes = Object.values(this.anchors.map).map(function (node) {
1826
+ return [node, {
1827
+ alias: [],
1828
+ aliasCount: 0,
1829
+ count: 1
1830
+ }];
1831
+ });
1832
+ var anchors = anchorNodes.length > 0 ? new Map(anchorNodes) : null;
822
1833
  var ctx = {
1834
+ anchors: anchors,
823
1835
  doc: this,
824
1836
  indentStep: ' ',
825
- keep: keep,
826
- mapAsMap: keep && !!mapAsMap,
827
- maxAliasCount: maxAliasCount,
1837
+ keep: !json,
1838
+ mapAsMap: typeof mapAsMap === 'boolean' ? mapAsMap : !!this.options.mapAsMap,
1839
+ maxAliasCount: this.options.maxAliasCount,
828
1840
  stringify: stringify // Requiring directly in Pair would create circular dependencies
829
1841
 
830
1842
  };
831
- var anchorNames = Object.keys(this.anchors.map);
832
- if (anchorNames.length > 0) ctx.anchors = new Map(anchorNames.map(function (name) {
833
- return [_this.anchors.map[name], {
834
- alias: [],
835
- aliasCount: 0,
836
- count: 1
837
- }];
838
- }));
839
1843
 
840
- var res = toJSON(this.contents, arg, ctx);
1844
+ var res = toJS(this.contents, jsonArg || '', ctx);
841
1845
 
842
- if (typeof onAnchor === 'function' && ctx.anchors) {
843
- var _iterator3 = _createForOfIteratorHelper(ctx.anchors.values()),
1846
+ if (typeof onAnchor === 'function' && anchors) {
1847
+ var _iterator3 = _createForOfIteratorHelper(anchors.values()),
844
1848
  _step3;
845
1849
 
846
1850
  try {
@@ -857,7 +1861,19 @@ var Document = /*#__PURE__*/function () {
857
1861
  }
858
1862
  }
859
1863
 
860
- return res;
1864
+ return typeof reviver === 'function' ? applyReviver(reviver, {
1865
+ '': res
1866
+ }, '', res) : res;
1867
+ }
1868
+ }, {
1869
+ key: "toJSON",
1870
+ value: function toJSON(jsonArg, onAnchor) {
1871
+ return this.toJS({
1872
+ json: true,
1873
+ jsonArg: jsonArg,
1874
+ mapAsMap: false,
1875
+ onAnchor: onAnchor
1876
+ });
861
1877
  }
862
1878
  }, {
863
1879
  key: "toString",
@@ -886,9 +1902,9 @@ var Document = /*#__PURE__*/function () {
886
1902
  }
887
1903
 
888
1904
  var tagNames = this.listNonDefaultTags();
889
- this.tagPrefixes.forEach(function (_ref2) {
890
- var handle = _ref2.handle,
891
- prefix = _ref2.prefix;
1905
+ this.tagPrefixes.forEach(function (_ref3) {
1906
+ var handle = _ref3.handle,
1907
+ prefix = _ref3.prefix;
892
1908
 
893
1909
  if (tagNames.some(function (t) {
894
1910
  return t.indexOf(prefix) === 0;
@@ -905,7 +1921,7 @@ var Document = /*#__PURE__*/function () {
905
1921
  }
906
1922
 
907
1923
  var ctx = {
908
- anchors: {},
1924
+ anchors: Object.create(null),
909
1925
  doc: this,
910
1926
  indent: '',
911
1927
  indentStep: ' '.repeat(indentSize),
@@ -967,20 +1983,6 @@ function warn(warning, type) {
967
1983
  console.warn(type ? "".concat(type, ": ").concat(warning) : warning);
968
1984
  }
969
1985
 
970
- var Document$1 = /*#__PURE__*/function (_YAMLDocument) {
971
- _inherits(Document, _YAMLDocument);
972
-
973
- var _super = _createSuper(Document);
974
-
975
- function Document(contents, options) {
976
- _classCallCheck(this, Document);
977
-
978
- return _super.call(this, contents, Object.assign({}, defaultOptions, options));
979
- }
980
-
981
- return Document;
982
- }(Document);
983
-
984
1986
  function parseAllDocuments(src, options) {
985
1987
  var stream = [];
986
1988
  var prev;
@@ -991,7 +1993,7 @@ function parseAllDocuments(src, options) {
991
1993
  try {
992
1994
  for (_iterator.s(); !(_step = _iterator.n()).done;) {
993
1995
  var cstDoc = _step.value;
994
- var doc = new Document$1(undefined, options);
1996
+ var doc = new Document(undefined, null, options);
995
1997
  doc.parse(cstDoc, prev);
996
1998
  stream.push(doc);
997
1999
  prev = doc;
@@ -1004,10 +2006,9 @@ function parseAllDocuments(src, options) {
1004
2006
 
1005
2007
  return stream;
1006
2008
  }
1007
-
1008
2009
  function parseDocument(src, options) {
1009
2010
  var cst = parse$1(src);
1010
- var doc = new Document$1(cst[0], options);
2011
+ var doc = new Document(cst[0], null, options);
1011
2012
 
1012
2013
  if (cst.length > 1) {
1013
2014
  var errMsg = 'Source contains multiple documents; please use YAML.parseAllDocuments()';
@@ -1016,30 +2017,41 @@ function parseDocument(src, options) {
1016
2017
 
1017
2018
  return doc;
1018
2019
  }
2020
+ function parse(src, reviver, options) {
2021
+ if (options === undefined && reviver && _typeof(reviver) === 'object') {
2022
+ options = reviver;
2023
+ reviver = undefined;
2024
+ }
1019
2025
 
1020
- function parse(src, options) {
1021
2026
  var doc = parseDocument(src, options);
1022
2027
  doc.warnings.forEach(function (warning) {
1023
2028
  return warn(warning);
1024
2029
  });
1025
2030
  if (doc.errors.length > 0) throw doc.errors[0];
1026
- return doc.toJSON();
2031
+ return doc.toJS({
2032
+ reviver: reviver
2033
+ });
1027
2034
  }
2035
+ function stringify$1(value, replacer, options) {
2036
+ if (typeof options === 'string') options = options.length;
2037
+
2038
+ if (typeof options === 'number') {
2039
+ var indent = Math.round(options);
2040
+ options = indent < 1 ? undefined : indent > 8 ? {
2041
+ indent: 8
2042
+ } : {
2043
+ indent: indent
2044
+ };
2045
+ }
1028
2046
 
1029
- function stringify$1(value, options) {
1030
- if (value === undefined) return '\n';
1031
- return new Document$1(value, options).toString();
1032
- }
2047
+ if (value === undefined) {
2048
+ var _ref = options || replacer || {},
2049
+ keepUndefined = _ref.keepUndefined;
1033
2050
 
1034
- var YAML = {
1035
- defaultOptions: defaultOptions,
1036
- Document: Document$1,
1037
- parse: parse,
1038
- parseAllDocuments: parseAllDocuments,
1039
- parseCST: parse$1,
1040
- parseDocument: parseDocument,
1041
- scalarOptions: scalarOptions,
1042
- stringify: stringify$1
1043
- };
2051
+ if (!keepUndefined) return undefined;
2052
+ }
2053
+
2054
+ return new Document(value, replacer, options).toString();
2055
+ }
1044
2056
 
1045
- export { YAML };
2057
+ export { Document, defaultOptions, parse, parseAllDocuments, parseDocument, scalarOptions, stringify$1 as stringify };