yaml 1.8.2 → 1.9.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.
Files changed (142) hide show
  1. package/browser/dist/Anchors.js +10 -13
  2. package/browser/dist/Document.js +72 -67
  3. package/browser/dist/addComment.js +1 -1
  4. package/browser/dist/cst/Alias.js +12 -8
  5. package/browser/dist/cst/BlankLine.js +16 -20
  6. package/browser/dist/cst/BlockValue.js +14 -10
  7. package/browser/dist/cst/Collection.js +17 -13
  8. package/browser/dist/cst/CollectionItem.js +15 -11
  9. package/browser/dist/cst/Comment.js +13 -9
  10. package/browser/dist/cst/Directive.js +13 -9
  11. package/browser/dist/cst/Document.js +17 -13
  12. package/browser/dist/cst/FlowCollection.js +17 -13
  13. package/browser/dist/cst/Node.js +3 -5
  14. package/browser/dist/cst/ParseContext.js +12 -14
  15. package/browser/dist/cst/PlainValue.js +12 -8
  16. package/browser/dist/cst/QuoteDouble.js +13 -9
  17. package/browser/dist/cst/QuoteSingle.js +13 -9
  18. package/browser/dist/cst/Range.js +2 -5
  19. package/browser/dist/cst/parse.js +3 -3
  20. package/browser/dist/errors.js +23 -8
  21. package/browser/dist/foldFlowLines.js +1 -1
  22. package/browser/dist/index.js +71 -21
  23. package/browser/dist/listTagNames.js +5 -5
  24. package/browser/dist/schema/Alias.js +30 -34
  25. package/browser/dist/schema/Collection.js +40 -47
  26. package/browser/dist/schema/Map.js +39 -56
  27. package/browser/dist/schema/Merge.js +37 -46
  28. package/browser/dist/schema/Node.js +2 -5
  29. package/browser/dist/schema/Pair.js +36 -13
  30. package/browser/dist/schema/Scalar.js +13 -9
  31. package/browser/dist/schema/Seq.js +27 -25
  32. package/browser/dist/schema/index.js +25 -39
  33. package/browser/dist/schema/parseMap.js +8 -8
  34. package/browser/dist/schema/parseSeq.js +5 -5
  35. package/browser/dist/schema/parseUtils.js +11 -15
  36. package/browser/dist/stringify.js +2 -1
  37. package/browser/dist/tags/core.js +39 -23
  38. package/browser/dist/tags/failsafe/index.js +4 -4
  39. package/browser/dist/tags/failsafe/map.js +15 -18
  40. package/browser/dist/tags/failsafe/seq.js +14 -18
  41. package/browser/dist/tags/failsafe/string.js +1 -1
  42. package/browser/dist/tags/index.js +10 -10
  43. package/browser/dist/tags/json.js +27 -26
  44. package/browser/dist/tags/options.js +3 -0
  45. package/browser/dist/tags/yaml-1.1/binary.js +10 -8
  46. package/browser/dist/tags/yaml-1.1/index.js +75 -43
  47. package/browser/dist/tags/yaml-1.1/omap.js +34 -39
  48. package/browser/dist/tags/yaml-1.1/pairs.js +17 -20
  49. package/browser/dist/tags/yaml-1.1/set.js +27 -23
  50. package/browser/dist/test-events.js +4 -4
  51. package/browser/dist/toJSON.js +3 -4
  52. package/browser/dist/warnings.js +29 -18
  53. package/browser/index.js +1 -1
  54. package/browser/map.js +4 -2
  55. package/browser/pair.js +4 -2
  56. package/browser/parse-cst.js +1 -1
  57. package/browser/scalar.js +4 -2
  58. package/browser/schema.js +11 -6
  59. package/browser/seq.js +4 -2
  60. package/browser/types/binary.js +5 -6
  61. package/browser/types/omap.js +4 -2
  62. package/browser/types/pairs.js +4 -2
  63. package/browser/types/set.js +4 -2
  64. package/browser/types/timestamp.js +5 -9
  65. package/browser/types.js +12 -10
  66. package/browser/util.js +16 -13
  67. package/dist/Anchors.js +13 -18
  68. package/dist/Document.js +52 -48
  69. package/dist/addComment.js +1 -4
  70. package/dist/constants.js +0 -3
  71. package/dist/cst/Alias.js +8 -13
  72. package/dist/cst/BlankLine.js +8 -24
  73. package/dist/cst/BlockValue.js +12 -17
  74. package/dist/cst/Collection.js +22 -27
  75. package/dist/cst/CollectionItem.js +16 -21
  76. package/dist/cst/Comment.js +6 -11
  77. package/dist/cst/Directive.js +7 -12
  78. package/dist/cst/Document.js +23 -28
  79. package/dist/cst/FlowCollection.js +21 -26
  80. package/dist/cst/Node.js +4 -9
  81. package/dist/cst/ParseContext.js +38 -43
  82. package/dist/cst/PlainValue.js +10 -15
  83. package/dist/cst/QuoteDouble.js +9 -14
  84. package/dist/cst/QuoteSingle.js +9 -14
  85. package/dist/cst/Range.js +2 -5
  86. package/dist/cst/parse.js +5 -10
  87. package/dist/cst/source-utils.js +0 -3
  88. package/dist/errors.js +4 -9
  89. package/dist/foldFlowLines.js +1 -4
  90. package/dist/index.js +59 -17
  91. package/dist/listTagNames.js +9 -14
  92. package/dist/schema/Alias.js +12 -17
  93. package/dist/schema/Collection.js +16 -20
  94. package/dist/schema/Map.js +12 -17
  95. package/dist/schema/Merge.js +13 -18
  96. package/dist/schema/Node.js +2 -5
  97. package/dist/schema/Pair.js +44 -31
  98. package/dist/schema/Scalar.js +6 -11
  99. package/dist/schema/Seq.js +9 -14
  100. package/dist/schema/index.js +22 -27
  101. package/dist/schema/parseMap.js +19 -28
  102. package/dist/schema/parseSeq.js +10 -15
  103. package/dist/schema/parseUtils.js +0 -3
  104. package/dist/stringify.js +6 -12
  105. package/dist/tags/core.js +34 -26
  106. package/dist/tags/failsafe/index.js +6 -11
  107. package/dist/tags/failsafe/map.js +8 -13
  108. package/dist/tags/failsafe/seq.js +8 -13
  109. package/dist/tags/failsafe/string.js +3 -6
  110. package/dist/tags/index.js +20 -29
  111. package/dist/tags/json.js +26 -22
  112. package/dist/tags/options.js +5 -4
  113. package/dist/tags/yaml-1.1/binary.js +11 -11
  114. package/dist/tags/yaml-1.1/index.js +69 -38
  115. package/dist/tags/yaml-1.1/omap.js +19 -24
  116. package/dist/tags/yaml-1.1/pairs.js +12 -17
  117. package/dist/tags/yaml-1.1/set.js +12 -21
  118. package/dist/tags/yaml-1.1/timestamp.js +0 -3
  119. package/dist/test-events.js +4 -9
  120. package/dist/toJSON.js +3 -5
  121. package/dist/warnings.js +31 -22
  122. package/index.d.ts +358 -0
  123. package/index.js +1 -1
  124. package/map.js +1 -1
  125. package/package.json +29 -23
  126. package/pair.js +1 -1
  127. package/parse-cst.d.ts +187 -0
  128. package/parse-cst.js +1 -1
  129. package/scalar.js +1 -1
  130. package/schema.js +2 -2
  131. package/seq.js +1 -1
  132. package/types/binary.js +1 -1
  133. package/types/omap.js +1 -1
  134. package/types/pairs.js +1 -1
  135. package/types/set.js +1 -1
  136. package/types/timestamp.js +1 -1
  137. package/types.d.ts +393 -0
  138. package/types.js +7 -6
  139. package/types.mjs +6 -5
  140. package/util.d.ts +86 -0
  141. package/util.js +6 -5
  142. package/util.mjs +4 -3
@@ -1,43 +1,34 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = exports.YAMLSet = void 0;
3
+ exports.set = exports.YAMLSet = void 0;
7
4
 
8
5
  var _errors = require("../../errors");
9
6
 
10
- var _Map = _interopRequireWildcard(require("../../schema/Map"));
7
+ var _Map = require("../../schema/Map");
11
8
 
12
- var _Pair = _interopRequireDefault(require("../../schema/Pair"));
9
+ var _Pair = require("../../schema/Pair");
13
10
 
14
- var _parseMap = _interopRequireDefault(require("../../schema/parseMap"));
11
+ var _parseMap = require("../../schema/parseMap");
15
12
 
16
- var _Scalar = _interopRequireDefault(require("../../schema/Scalar"));
17
-
18
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
19
-
20
- function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function () { return cache; }; return cache; }
21
-
22
- function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
13
+ var _Scalar = require("../../schema/Scalar");
23
14
 
24
15
  function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
25
16
 
26
- class YAMLSet extends _Map.default {
17
+ class YAMLSet extends _Map.YAMLMap {
27
18
  constructor() {
28
19
  super();
29
20
  this.tag = YAMLSet.tag;
30
21
  }
31
22
 
32
23
  add(key) {
33
- const pair = key instanceof _Pair.default ? key : new _Pair.default(key);
24
+ const pair = key instanceof _Pair.Pair ? key : new _Pair.Pair(key);
34
25
  const prev = (0, _Map.findPair)(this.items, pair.key);
35
26
  if (!prev) this.items.push(pair);
36
27
  }
37
28
 
38
29
  get(key, keepPair) {
39
30
  const pair = (0, _Map.findPair)(this.items, key);
40
- return !keepPair && pair instanceof _Pair.default ? pair.key instanceof _Scalar.default ? pair.key.value : pair.key : pair;
31
+ return !keepPair && pair instanceof _Pair.Pair ? pair.key instanceof _Scalar.Scalar ? pair.key.value : pair.key : pair;
41
32
  }
42
33
 
43
34
  set(key, value) {
@@ -47,7 +38,7 @@ class YAMLSet extends _Map.default {
47
38
  if (prev && !value) {
48
39
  this.items.splice(this.items.indexOf(prev), 1);
49
40
  } else if (!prev && value) {
50
- this.items.push(new _Pair.default(key));
41
+ this.items.push(new _Pair.Pair(key));
51
42
  }
52
43
  }
53
44
 
@@ -67,7 +58,7 @@ exports.YAMLSet = YAMLSet;
67
58
  _defineProperty(YAMLSet, "tag", 'tag:yaml.org,2002:set');
68
59
 
69
60
  function parseSet(doc, cst) {
70
- const map = (0, _parseMap.default)(doc, cst);
61
+ const map = (0, _parseMap.parseMap)(doc, cst);
71
62
  if (!map.hasAllNullValues()) throw new _errors.YAMLSemanticError(cst, 'Set items must all have null values');
72
63
  return Object.assign(new YAMLSet(), map);
73
64
  }
@@ -80,7 +71,7 @@ function createSet(schema, iterable, ctx) {
80
71
  return set;
81
72
  }
82
73
 
83
- var _default = {
74
+ const set = {
84
75
  identify: value => value instanceof Set,
85
76
  nodeClass: YAMLSet,
86
77
  default: false,
@@ -88,4 +79,4 @@ var _default = {
88
79
  resolve: parseSet,
89
80
  createNode: createSet
90
81
  };
91
- exports.default = _default;
82
+ exports.set = set;
@@ -1,8 +1,5 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
3
  exports.timestamp = exports.floatTime = exports.intTime = void 0;
7
4
 
8
5
  var _stringify = require("../../stringify");
@@ -1,15 +1,10 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = testEvents;
3
+ exports.testEvents = testEvents;
7
4
 
8
- var _parse = _interopRequireDefault(require("./cst/parse"));
5
+ var _parse = require("./cst/parse");
9
6
 
10
- var _Document = _interopRequireDefault(require("./Document"));
11
-
12
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
7
+ var _Document = require("./Document");
13
8
 
14
9
  // test harness for yaml-test-suite event tests
15
10
  function testEvents(src, options) {
@@ -18,7 +13,7 @@ function testEvents(src, options) {
18
13
  keepNodeTypes: true,
19
14
  version: '1.2'
20
15
  }, options);
21
- const docs = (0, _parse.default)(src).map(cstDoc => new _Document.default(opt).parse(cstDoc));
16
+ const docs = (0, _parse.parse)(src).map(cstDoc => new _Document.Document(opt).parse(cstDoc));
22
17
  const errDoc = docs.find(doc => doc.errors.length > 0);
23
18
  const error = errDoc ? errDoc.errors[0].message : null;
24
19
  const events = ['+STR'];
package/dist/toJSON.js CHANGED
@@ -1,15 +1,12 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.default = toJSON;
3
+ exports.toJSON = toJSON;
7
4
 
8
5
  function toJSON(value, arg, ctx) {
9
6
  if (Array.isArray(value)) return value.map((v, i) => toJSON(v, String(i), ctx));
10
7
 
11
8
  if (value && typeof value.toJSON === 'function') {
12
- const anchor = ctx && ctx.anchors && ctx.anchors.find(a => a.node === value);
9
+ const anchor = ctx && ctx.anchors && ctx.anchors.get(value);
13
10
  if (anchor) ctx.onCreate = res => {
14
11
  anchor.res = res;
15
12
  delete ctx.onCreate;
@@ -19,5 +16,6 @@ function toJSON(value, arg, ctx) {
19
16
  return res;
20
17
  }
21
18
 
19
+ if ((!ctx || !ctx.keep) && typeof value === 'bigint') return Number(value);
22
20
  return value;
23
21
  }
package/dist/warnings.js CHANGED
@@ -1,39 +1,48 @@
1
1
  "use strict";
2
2
 
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
3
  exports.warn = warn;
7
4
  exports.warnFileDeprecation = warnFileDeprecation;
8
5
  exports.warnOptionDeprecation = warnOptionDeprecation;
9
6
 
10
- /* global global, console */
7
+ /* global console, process, YAML_SILENCE_DEPRECATION_WARNINGS, YAML_SILENCE_WARNINGS */
8
+ function shouldWarn(deprecation) {
9
+ const env = typeof process !== 'undefined' && process.env || {};
10
+
11
+ if (deprecation) {
12
+ if (typeof YAML_SILENCE_DEPRECATION_WARNINGS !== 'undefined') return !YAML_SILENCE_DEPRECATION_WARNINGS;
13
+ return !env.YAML_SILENCE_DEPRECATION_WARNINGS;
14
+ }
15
+
16
+ if (typeof YAML_SILENCE_WARNINGS !== 'undefined') return !YAML_SILENCE_WARNINGS;
17
+ return !env.YAML_SILENCE_WARNINGS;
18
+ }
19
+
11
20
  function warn(warning, type) {
12
- if (global && global._YAML_SILENCE_WARNINGS) return;
13
- const {
14
- emitWarning
15
- } = global && global.process; // This will throw in Jest if `warning` is an Error instance due to
16
- // https://github.com/facebook/jest/issues/2549
17
-
18
- if (emitWarning) emitWarning(warning, type);else {
19
- // eslint-disable-next-line no-console
20
- console.warn(type ? `${type}: ${warning}` : warning);
21
+ if (shouldWarn(false)) {
22
+ const emit = typeof process !== 'undefined' && process.emitWarning; // This will throw in Jest if `warning` is an Error instance due to
23
+ // https://github.com/facebook/jest/issues/2549
24
+
25
+ if (emit) emit(warning, type);else {
26
+ // eslint-disable-next-line no-console
27
+ console.warn(type ? `${type}: ${warning}` : warning);
28
+ }
21
29
  }
22
30
  }
23
31
 
24
32
  function warnFileDeprecation(filename) {
25
- if (global && global._YAML_SILENCE_DEPRECATION_WARNINGS) return;
26
- const path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/');
27
- warn(`The endpoint 'yaml/${path}' will be removed in a future release.`, 'DeprecationWarning');
33
+ if (shouldWarn(true)) {
34
+ const path = filename.replace(/.*yaml[/\\]/i, '').replace(/\.js$/, '').replace(/\\/g, '/');
35
+ warn(`The endpoint 'yaml/${path}' will be removed in a future release.`, 'DeprecationWarning');
36
+ }
28
37
  }
29
38
 
30
39
  const warned = {};
31
40
 
32
41
  function warnOptionDeprecation(name, alternative) {
33
- if (global && global._YAML_SILENCE_DEPRECATION_WARNINGS) return;
34
- if (warned[name]) return;
35
- warned[name] = true;
36
- let msg = `The option '${name}' will be removed in a future release`;
37
- msg += alternative ? `, use '${alternative}' instead.` : '.';
38
- warn(msg, 'DeprecationWarning');
42
+ if (!warned[name] && shouldWarn(true)) {
43
+ warned[name] = true;
44
+ let msg = `The option '${name}' will be removed in a future release`;
45
+ msg += alternative ? `, use '${alternative}' instead.` : '.';
46
+ warn(msg, 'DeprecationWarning');
47
+ }
39
48
  }
package/index.d.ts ADDED
@@ -0,0 +1,358 @@
1
+ import { CST } from './parse-cst'
2
+ import { AST, Scalar, Schema, YAMLMap, YAMLSeq } from './types'
3
+ import { Type, YAMLError, YAMLWarning } from './util'
4
+
5
+ export { AST, CST }
6
+ export { default as parseCST } from './parse-cst'
7
+
8
+ /**
9
+ * `yaml` defines document-specific options in three places: as an argument of
10
+ * parse, create and stringify calls, in the values of `YAML.defaultOptions`,
11
+ * and in the version-dependent `YAML.Document.defaults` object. Values set in
12
+ * `YAML.defaultOptions` override version-dependent defaults, and argument
13
+ * options override both.
14
+ */
15
+ export const defaultOptions: Options
16
+
17
+ export interface Options extends Schema.Options {
18
+ /**
19
+ * Default prefix for anchors.
20
+ *
21
+ * Default: `'a'`, resulting in anchors `a1`, `a2`, etc.
22
+ */
23
+ anchorPrefix?: string
24
+ /**
25
+ * The number of spaces to use when indenting code.
26
+ *
27
+ * Default: `2`
28
+ */
29
+ indent?: number
30
+ /**
31
+ * Whether block sequences should be indented.
32
+ *
33
+ * Default: `true`
34
+ */
35
+ indentSeq?: boolean
36
+ /**
37
+ * Allow non-JSON JavaScript objects to remain in the `toJSON` output.
38
+ * Relevant with the YAML 1.1 `!!timestamp` and `!!binary` tags as well as BigInts.
39
+ *
40
+ * Default: `true`
41
+ */
42
+ keepBlobsInJSON?: boolean
43
+ /**
44
+ * Include references in the AST to each node's corresponding CST node.
45
+ *
46
+ * Default: `false`
47
+ */
48
+ keepCstNodes?: boolean
49
+ /**
50
+ * Store the original node type when parsing documents.
51
+ *
52
+ * Default: `true`
53
+ */
54
+ keepNodeTypes?: boolean
55
+ /**
56
+ * When outputting JS, use Map rather than Object to represent mappings.
57
+ *
58
+ * Default: `false`
59
+ */
60
+ mapAsMap?: boolean
61
+ /**
62
+ * Prevent exponential entity expansion attacks by limiting data aliasing count;
63
+ * set to `-1` to disable checks; `0` disallows all alias nodes.
64
+ *
65
+ * Default: `100`
66
+ */
67
+ maxAliasCount?: number
68
+ /**
69
+ * Include line position & node type directly in errors; drop their verbose source and context.
70
+ *
71
+ * Default: `false`
72
+ */
73
+ prettyErrors?: boolean
74
+ /**
75
+ * When stringifying, require keys to be scalars and to use implicit rather than explicit notation.
76
+ *
77
+ * Default: `false`
78
+ */
79
+ simpleKeys?: boolean
80
+ /**
81
+ * The YAML version used by documents without a `%YAML` directive.
82
+ *
83
+ * Default: `"1.2"`
84
+ */
85
+ version?: '1.0' | '1.1' | '1.2'
86
+ }
87
+
88
+ /**
89
+ * Some customization options are availabe to control the parsing and
90
+ * stringification of scalars. Note that these values are used by all documents.
91
+ */
92
+ export const scalarOptions: {
93
+ binary: scalarOptions.Binary
94
+ bool: scalarOptions.Bool
95
+ int: scalarOptions.Int
96
+ null: scalarOptions.Null
97
+ str: scalarOptions.Str
98
+ }
99
+ export namespace scalarOptions {
100
+ interface Binary {
101
+ /**
102
+ * The type of string literal used to stringify `!!binary` values.
103
+ *
104
+ * Default: `'BLOCK_LITERAL'`
105
+ */
106
+ defaultType: Scalar.Type
107
+ /**
108
+ * Maximum line width for `!!binary`.
109
+ *
110
+ * Default: `76`
111
+ */
112
+ lineWidth: number
113
+ }
114
+
115
+ interface Bool {
116
+ /**
117
+ * String representation for `true`. With the core schema, use `'true' | 'True' | 'TRUE'`.
118
+ *
119
+ * Default: `'true'`
120
+ */
121
+ trueStr: string
122
+ /**
123
+ * String representation for `false`. With the core schema, use `'false' | 'False' | 'FALSE'`.
124
+ *
125
+ * Default: `'false'`
126
+ */
127
+ falseStr: string
128
+ }
129
+
130
+ interface Int {
131
+ /**
132
+ * Whether integers should be parsed into BigInt values.
133
+ *
134
+ * Default: `false`
135
+ */
136
+ asBigInt: false
137
+ }
138
+
139
+ interface Null {
140
+ /**
141
+ * String representation for `null`. With the core schema, use `'null' | 'Null' | 'NULL' | '~' | ''`.
142
+ *
143
+ * Default: `'null'`
144
+ */
145
+ nullStr: string
146
+ }
147
+
148
+ interface Str {
149
+ /**
150
+ * The default type of string literal used to stringify values
151
+ *
152
+ * Default: `'PLAIN'`
153
+ */
154
+ defaultType: Scalar.Type
155
+ doubleQuoted: {
156
+ /**
157
+ * Whether to restrict double-quoted strings to use JSON-compatible syntax.
158
+ *
159
+ * Default: `false`
160
+ */
161
+ jsonEncoding: boolean
162
+ /**
163
+ * Minimum length to use multiple lines to represent the value.
164
+ *
165
+ * Default: `40`
166
+ */
167
+ minMultiLineLength: number
168
+ }
169
+ fold: {
170
+ /**
171
+ * Maximum line width (set to `0` to disable folding).
172
+ *
173
+ * Default: `80`
174
+ */
175
+ lineWidth: number
176
+ /**
177
+ * Minimum width for highly-indented content.
178
+ *
179
+ * Default: `20`
180
+ */
181
+ minContentWidth: number
182
+ }
183
+ }
184
+ }
185
+
186
+ export class Document extends AST.Collection {
187
+ cstNode?: CST.Document
188
+ constructor(options?: Options)
189
+ tag: never
190
+ type: Type.DOCUMENT
191
+ /**
192
+ * Anchors associated with the document's nodes;
193
+ * also provides alias & merge node creators.
194
+ */
195
+ anchors: Document.Anchors
196
+ /** The document contents. */
197
+ contents: AST.AstNode | null
198
+ /** Errors encountered during parsing. */
199
+ errors: YAMLError[]
200
+ /**
201
+ * The schema used with the document. Use `setSchema()` to change or
202
+ * initialise.
203
+ */
204
+ schema?: Schema
205
+ /**
206
+ * Array of prefixes; each will have a string `handle` that
207
+ * starts and ends with `!` and a string `prefix` that the handle will be replaced by.
208
+ */
209
+ tagPrefixes: Document.TagPrefix[]
210
+ /**
211
+ * The parsed version of the source document;
212
+ * if true-ish, stringified output will include a `%YAML` directive.
213
+ */
214
+ version?: string
215
+ /** Warnings encountered during parsing. */
216
+ warnings: YAMLWarning[]
217
+ /**
218
+ * List the tags used in the document that are not in the default
219
+ * `tag:yaml.org,2002:` namespace.
220
+ */
221
+ listNonDefaultTags(): string[]
222
+ /** Parse a CST into this document */
223
+ parse(cst: CST.Document): this
224
+ /**
225
+ * When a document is created with `new YAML.Document()`, the schema object is
226
+ * not set as it may be influenced by parsed directives; call this with no
227
+ * arguments to set it manually, or with arguments to change the schema used
228
+ * by the document.
229
+ **/
230
+ setSchema(
231
+ id?: Options['version'] | Schema.Name,
232
+ customTags?: (Schema.TagId | Schema.Tag)[]
233
+ ): void
234
+ /** Set `handle` as a shorthand string for the `prefix` tag namespace. */
235
+ setTagPrefix(handle: string, prefix: string): void
236
+ /**
237
+ * A plain JavaScript representation of the document `contents`.
238
+ *
239
+ * @param arg Used by `JSON.stringify` to indicate the array index or property
240
+ * name. If its value is a `string` and the document `contents` has a scalar
241
+ * value, the `keepBlobsInJSON` option has no effect.
242
+ * @param onAnchor If defined, called with the resolved `value` and reference
243
+ * `count` for each anchor in the document.
244
+ * */
245
+ toJSON(arg?: string, onAnchor?: (value: any, count: number) => void): any
246
+ /** A YAML representation of the document. */
247
+ toString(): string
248
+ }
249
+
250
+ export namespace Document {
251
+ interface Parsed extends Document {
252
+ /** The schema used with the document. */
253
+ schema: Schema
254
+ }
255
+
256
+ interface Anchors {
257
+ /**
258
+ * Create a new `Alias` node, adding the required anchor for `node`.
259
+ * If `name` is empty, a new anchor name will be generated.
260
+ */
261
+ createAlias(node: AST.Node, name?: string): AST.Alias
262
+ /**
263
+ * Create a new `Merge` node with the given source nodes.
264
+ * Non-`Alias` sources will be automatically wrapped.
265
+ */
266
+ createMergePair(...nodes: AST.Node[]): AST.Merge
267
+ /** The anchor name associated with `node`, if set. */
268
+ getName(node: AST.Node): undefined | string
269
+ /** The node associated with the anchor `name`, if set. */
270
+ getNode(name: string): undefined | AST.Node
271
+ /**
272
+ * Find an available anchor name with the given `prefix` and a
273
+ * numerical suffix.
274
+ */
275
+ newName(prefix: string): string
276
+ /**
277
+ * Associate an anchor with `node`. If `name` is empty, a new name will be generated.
278
+ * To remove an anchor, use `setAnchor(null, name)`.
279
+ */
280
+ setAnchor(node: AST.Node | null, name?: string): void | string
281
+ }
282
+
283
+ interface TagPrefix {
284
+ handle: string
285
+ prefix: string
286
+ }
287
+ }
288
+
289
+ /**
290
+ * Recursively turns objects into collections. Generic objects as well as `Map`
291
+ * and its descendants become mappings, while arrays and other iterable objects
292
+ * result in sequences.
293
+ *
294
+ * The primary purpose of this function is to enable attaching comments or other
295
+ * metadata to a value, or to otherwise exert more fine-grained control over the
296
+ * stringified output. To that end, you'll need to assign its return value to
297
+ * the `contents` of a Document (or somewhere within said contents), as the
298
+ * document's schema is required for YAML string output.
299
+ *
300
+ * @param wrapScalars If undefined or `true`, also wraps plain values in
301
+ * `Scalar` objects; if `false` and `value` is not an object, it will be
302
+ * returned directly.
303
+ * @param tag Use to specify the collection type, e.g. `"!!omap"`. Note that
304
+ * this requires the corresponding tag to be available based on the default
305
+ * options. To use a specific document's schema, use `doc.schema.createNode`.
306
+ */
307
+ export function createNode(
308
+ value: any,
309
+ wrapScalars?: true,
310
+ tag?: string
311
+ ): YAMLMap | YAMLSeq | Scalar
312
+
313
+ /**
314
+ * YAML.createNode recursively turns objects into Map and arrays to Seq collections.
315
+ * Its primary use is to enable attaching comments or other metadata to a value,
316
+ * or to otherwise exert more fine-grained control over the stringified output.
317
+ *
318
+ * Doesn't wrap plain values in Scalar objects.
319
+ */
320
+ export function createNode(
321
+ value: any,
322
+ wrapScalars: false,
323
+ tag?: string
324
+ ): YAMLMap | YAMLSeq | string | number | boolean | null
325
+
326
+ /**
327
+ * Parse an input string into a single YAML.Document.
328
+ */
329
+ export function parseDocument(str: string, options?: Options): Document.Parsed
330
+
331
+ /**
332
+ * Parse the input as a stream of YAML documents.
333
+ *
334
+ * Documents should be separated from each other by `...` or `---` marker lines.
335
+ */
336
+ export function parseAllDocuments(
337
+ str: string,
338
+ options?: Options
339
+ ): Document.Parsed[]
340
+
341
+ /**
342
+ * Parse an input string into JavaScript.
343
+ *
344
+ * Only supports input consisting of a single YAML document; for multi-document
345
+ * support you should use `YAML.parseAllDocuments`. May throw on error, and may
346
+ * log warnings using `console.warn`.
347
+ *
348
+ * @param str A string with YAML formatting.
349
+ * @returns The value will match the type of the root value of the parsed YAML
350
+ * document, so Maps become objects, Sequences arrays, and scalars result in
351
+ * nulls, booleans, numbers and strings.
352
+ */
353
+ export function parse(str: string, options?: Options): any
354
+
355
+ /**
356
+ * @returns Will always include \n as the last character, as is expected of YAML documents.
357
+ */
358
+ export function stringify(value: any, options?: Options): string
package/index.js CHANGED
@@ -1 +1 @@
1
- module.exports = require('./dist').default
1
+ module.exports = require('./dist').YAML
package/map.js CHANGED
@@ -1,2 +1,2 @@
1
- module.exports = require('./dist/schema/Map').default
1
+ module.exports = require('./dist/schema/Map').YAMLMap
2
2
  require('./dist/warnings').warnFileDeprecation(__filename)