UNPKG

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