1 | import type { Reviver } from './doc/applyReviver.js';
|
2 | import type { Directives } from './doc/directives.js';
|
3 | import type { LogLevelId } from './log.js';
|
4 | import type { ParsedNode } from './nodes/Node.js';
|
5 | import type { Pair } from './nodes/Pair.js';
|
6 | import type { Scalar } from './nodes/Scalar.js';
|
7 | import type { LineCounter } from './parse/line-counter.js';
|
8 | import type { Schema } from './schema/Schema.js';
|
9 | import type { Tags } from './schema/tags.js';
|
10 | import type { CollectionTag, ScalarTag } from './schema/types.js';
|
11 | export type ParseOptions = {
|
12 | /**
|
13 | * Whether integers should be parsed into BigInt rather than number values.
|
14 | *
|
15 | * Default: `false`
|
16 | *
|
17 | * https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/BigInt
|
18 | */
|
19 | intAsBigInt?: boolean;
|
20 | /**
|
21 | * Include a `srcToken` value on each parsed `Node`, containing the CST token
|
22 | * that was composed into this node.
|
23 | *
|
24 | * Default: `false`
|
25 | */
|
26 | keepSourceTokens?: boolean;
|
27 | /**
|
28 | * If set, newlines will be tracked, to allow for `lineCounter.linePos(offset)`
|
29 | * to provide the `{ line, col }` positions within the input.
|
30 | */
|
31 | lineCounter?: LineCounter;
|
32 | /**
|
33 | * Include line/col position & node type directly in parse errors.
|
34 | *
|
35 | * Default: `true`
|
36 | */
|
37 | prettyErrors?: boolean;
|
38 | /**
|
39 | * Detect and report errors that are required by the YAML 1.2 spec,
|
40 | * but are caused by unambiguous content.
|
41 | *
|
42 | * Default: `true`
|
43 | */
|
44 | strict?: boolean;
|
45 | /**
|
46 | * Parse all mapping keys as strings. Treat all non-scalar keys as errors.
|
47 | *
|
48 | * Default: `false`
|
49 | */
|
50 | stringKeys?: boolean;
|
51 | /**
|
52 | * YAML requires map keys to be unique. By default, this is checked by
|
53 | * comparing scalar values with `===`; deep equality is not checked for
|
54 | * aliases or collections. If merge keys are enabled by the schema,
|
55 | * multiple `<<` keys are allowed.
|
56 | *
|
57 | * Set `false` to disable, or provide your own comparator function to
|
58 | * customise. The comparator will be passed two `ParsedNode` values, and
|
59 | * is expected to return a `boolean` indicating their equality.
|
60 | *
|
61 | * Default: `true`
|
62 | */
|
63 | uniqueKeys?: boolean | ((a: ParsedNode, b: ParsedNode) => boolean);
|
64 | };
|
65 | export type DocumentOptions = {
|
66 | /**
|
67 | * @internal
|
68 | * Used internally by Composer. If set and includes an explicit version,
|
69 | * that overrides the `version` option.
|
70 | */
|
71 | _directives?: Directives;
|
72 | /**
|
73 | * Control the logging level during parsing
|
74 | *
|
75 | * Default: `'warn'`
|
76 | */
|
77 | logLevel?: LogLevelId;
|
78 | /**
|
79 | * The YAML version used by documents without a `%YAML` directive.
|
80 | *
|
81 | * Default: `"1.2"`
|
82 | */
|
83 | version?: '1.1' | '1.2' | 'next';
|
84 | };
|
85 | export type SchemaOptions = {
|
86 | /**
|
87 | * When parsing, warn about compatibility issues with the given schema.
|
88 | * When stringifying, use scalar styles that are parsed correctly
|
89 | * by the `compat` schema as well as the actual schema.
|
90 | *
|
91 | * Default: `null`
|
92 | */
|
93 | compat?: string | Tags | null;
|
94 | /**
|
95 | * Array of additional tags to include in the schema, or a function that may
|
96 | * modify the schema's base tag array.
|
97 | */
|
98 | customTags?: Tags | ((tags: Tags) => Tags) | null;
|
99 | /**
|
100 | * Enable support for `<<` merge keys.
|
101 | *
|
102 | * Default: `false` for YAML 1.2, `true` for earlier versions
|
103 | */
|
104 | merge?: boolean;
|
105 | /**
|
106 | * When using the `'core'` schema, support parsing values with these
|
107 | * explicit YAML 1.1 tags:
|
108 | *
|
109 | * `!!binary`, `!!omap`, `!!pairs`, `!!set`, `!!timestamp`.
|
110 | *
|
111 | * Default `true`
|
112 | */
|
113 | resolveKnownTags?: boolean;
|
114 | /**
|
115 | * The base schema to use.
|
116 | *
|
117 | * The core library has built-in support for the following:
|
118 | * - `'failsafe'`: A minimal schema that parses all scalars as strings
|
119 | * - `'core'`: The YAML 1.2 core schema
|
120 | * - `'json'`: The YAML 1.2 JSON schema, with minimal rules for JSON compatibility
|
121 | * - `'yaml-1.1'`: The YAML 1.1 schema
|
122 | *
|
123 | * If using another (custom) schema, the `customTags` array needs to
|
124 | * fully define the schema's tags.
|
125 | *
|
126 | * Default: `'core'` for YAML 1.2, `'yaml-1.1'` for earlier versions
|
127 | */
|
128 | schema?: string | Schema;
|
129 | /**
|
130 | * When adding to or stringifying a map, sort the entries.
|
131 | * If `true`, sort by comparing key values with `<`.
|
132 | * Does not affect item order when parsing.
|
133 | *
|
134 | * Default: `false`
|
135 | */
|
136 | sortMapEntries?: boolean | ((a: Pair, b: Pair) => number);
|
137 | /**
|
138 | * Override default values for `toString()` options.
|
139 | */
|
140 | toStringDefaults?: ToStringOptions;
|
141 | };
|
142 | export type CreateNodeOptions = {
|
143 | /**
|
144 | * During node construction, use anchors and aliases to keep strictly equal
|
145 | * non-null objects as equivalent in YAML.
|
146 | *
|
147 | * Default: `true`
|
148 | */
|
149 | aliasDuplicateObjects?: boolean;
|
150 | /**
|
151 | * Default prefix for anchors.
|
152 | *
|
153 | * Default: `'a'`, resulting in anchors `a1`, `a2`, etc.
|
154 | */
|
155 | anchorPrefix?: string;
|
156 | /** Force the top-level collection node to use flow style. */
|
157 | flow?: boolean;
|
158 | /**
|
159 | * Keep `undefined` object values when creating mappings, rather than
|
160 | * discarding them.
|
161 | *
|
162 | * Default: `false`
|
163 | */
|
164 | keepUndefined?: boolean | null;
|
165 | onTagObj?: (tagObj: ScalarTag | CollectionTag) => void;
|
166 | /**
|
167 | * Specify the top-level collection type, e.g. `"!!omap"`. Note that this
|
168 | * requires the corresponding tag to be available in this document's schema.
|
169 | */
|
170 | tag?: string;
|
171 | };
|
172 | export type ToJSOptions = {
|
173 | /**
|
174 | * Use Map rather than Object to represent mappings.
|
175 | *
|
176 | * Default: `false`
|
177 | */
|
178 | mapAsMap?: boolean;
|
179 | /**
|
180 | * Prevent exponential entity expansion attacks by limiting data aliasing count;
|
181 | * set to `-1` to disable checks; `0` disallows all alias nodes.
|
182 | *
|
183 | * Default: `100`
|
184 | */
|
185 | maxAliasCount?: number;
|
186 | /**
|
187 | * If defined, called with the resolved `value` and reference `count` for
|
188 | * each anchor in the document.
|
189 | */
|
190 | onAnchor?: (value: unknown, count: number) => void;
|
191 | /**
|
192 | * Optional function that may filter or modify the output JS value
|
193 | *
|
194 | * https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse#using_the_reviver_parameter
|
195 | */
|
196 | reviver?: Reviver;
|
197 | };
|
198 | export type ToStringOptions = {
|
199 | /**
|
200 | * Use block quote styles for scalar values where applicable.
|
201 | * Set to `false` to disable block quotes completely.
|
202 | *
|
203 | * Default: `true`
|
204 | */
|
205 | blockQuote?: boolean | 'folded' | 'literal';
|
206 | /**
|
207 | * Enforce `'block'` or `'flow'` style on maps and sequences.
|
208 | * Empty collections will always be stringified as `{}` or `[]`.
|
209 | *
|
210 | * Default: `'any'`, allowing each node to set its style separately
|
211 | * with its `flow: boolean` (default `false`) property.
|
212 | */
|
213 | collectionStyle?: 'any' | 'block' | 'flow';
|
214 | /**
|
215 | * Comment stringifier.
|
216 | * Output should be valid for the current schema.
|
217 | *
|
218 | * By default, empty comment lines are left empty,
|
219 | * lines consisting of a single space are replaced by `#`,
|
220 | * and all other lines are prefixed with a `#`.
|
221 | */
|
222 | commentString?: (comment: string) => string;
|
223 | /**
|
224 | * The default type of string literal used to stringify implicit key values.
|
225 | * Output may use other types if required to fully represent the value.
|
226 | *
|
227 | * If `null`, the value of `defaultStringType` is used.
|
228 | *
|
229 | * Default: `null`
|
230 | */
|
231 | defaultKeyType?: Scalar.Type | null;
|
232 | /**
|
233 | * The default type of string literal used to stringify values in general.
|
234 | * Output may use other types if required to fully represent the value.
|
235 | *
|
236 | * Default: `'PLAIN'`
|
237 | */
|
238 | defaultStringType?: Scalar.Type;
|
239 | /**
|
240 | * Include directives in the output.
|
241 | *
|
242 | * - If `true`, at least the document-start marker `---` is always included.
|
243 | * This does not force the `%YAML` directive to be included. To do that,
|
244 | * set `doc.directives.yaml.explicit = true`.
|
245 | * - If `false`, no directives or marker is ever included. If using the `%TAG`
|
246 | * directive, you are expected to include it manually in the stream before
|
247 | * its use.
|
248 | * - If `null`, directives and marker may be included if required.
|
249 | *
|
250 | * Default: `null`
|
251 | */
|
252 | directives?: boolean | null;
|
253 | /**
|
254 | * Restrict double-quoted strings to use JSON-compatible syntax.
|
255 | *
|
256 | * Default: `false`
|
257 | */
|
258 | doubleQuotedAsJSON?: boolean;
|
259 | /**
|
260 | * Minimum length for double-quoted strings to use multiple lines to
|
261 | * represent the value. Ignored if `doubleQuotedAsJSON` is set.
|
262 | *
|
263 | * Default: `40`
|
264 | */
|
265 | doubleQuotedMinMultiLineLength?: number;
|
266 | /**
|
267 | * String representation for `false`.
|
268 | * With the core schema, use `'false'`, `'False'`, or `'FALSE'`.
|
269 | *
|
270 | * Default: `'false'`
|
271 | */
|
272 | falseStr?: string;
|
273 | /**
|
274 | * When true, a single space of padding will be added inside the delimiters
|
275 | * of non-empty single-line flow collections.
|
276 | *
|
277 | * Default: `true`
|
278 | */
|
279 | flowCollectionPadding?: boolean;
|
280 | /**
|
281 | * The number of spaces to use when indenting code.
|
282 | *
|
283 | * Default: `2`
|
284 | */
|
285 | indent?: number;
|
286 | /**
|
287 | * Whether block sequences should be indented.
|
288 | *
|
289 | * Default: `true`
|
290 | */
|
291 | indentSeq?: boolean;
|
292 | /**
|
293 | * Maximum line width (set to `0` to disable folding).
|
294 | *
|
295 | * This is a soft limit, as only double-quoted semantics allow for inserting
|
296 | * a line break in the middle of a word, as well as being influenced by the
|
297 | * `minContentWidth` option.
|
298 | *
|
299 | * Default: `80`
|
300 | */
|
301 | lineWidth?: number;
|
302 | /**
|
303 | * Minimum line width for highly-indented content (set to `0` to disable).
|
304 | *
|
305 | * Default: `20`
|
306 | */
|
307 | minContentWidth?: number;
|
308 | /**
|
309 | * String representation for `null`.
|
310 | * With the core schema, use `'null'`, `'Null'`, `'NULL'`, `'~'`, or an empty
|
311 | * string `''`.
|
312 | *
|
313 | * Default: `'null'`
|
314 | */
|
315 | nullStr?: string;
|
316 | /**
|
317 | * Require keys to be scalars and to use implicit rather than explicit notation.
|
318 | *
|
319 | * Default: `false`
|
320 | */
|
321 | simpleKeys?: boolean;
|
322 | /**
|
323 | * Use 'single quote' rather than "double quote" where applicable.
|
324 | * Set to `false` to disable single quotes completely.
|
325 | *
|
326 | * Default: `null`
|
327 | */
|
328 | singleQuote?: boolean | null;
|
329 | /**
|
330 | * String representation for `true`.
|
331 | * With the core schema, use `'true'`, `'True'`, or `'TRUE'`.
|
332 | *
|
333 | * Default: `'true'`
|
334 | */
|
335 | trueStr?: string;
|
336 | /**
|
337 | * The anchor used by an alias must be defined before the alias node. As it's
|
338 | * possible for the document to be modified manually, the order may be
|
339 | * verified during stringification.
|
340 | *
|
341 | * Default: `'true'`
|
342 | */
|
343 | verifyAliasOrder?: boolean;
|
344 | };
|