UNPKG

2.62 kBTypeScriptView Raw
1import { Composer } from './compose/composer.js';
2import type { Reviver } from './doc/applyReviver.js';
3import { Document, Replacer } from './doc/Document.js';
4import type { ParsedNode } from './nodes/Node.js';
5import type { CreateNodeOptions, DocumentOptions, ParseOptions, SchemaOptions, ToJSOptions, ToStringOptions } from './options.js';
6export interface EmptyStream extends Array<Document.Parsed>, ReturnType<Composer['streamInfo']> {
7 empty: true;
8}
9/**
10 * Parse the input as a stream of YAML documents.
11 *
12 * Documents should be separated from each other by `...` or `---` marker lines.
13 *
14 * @returns If an empty `docs` array is returned, it will be of type
15 * EmptyStream and contain additional stream information. In
16 * TypeScript, you should use `'empty' in docs` as a type guard for it.
17 */
18export declare function parseAllDocuments<T extends ParsedNode = ParsedNode>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<T>[] | EmptyStream;
19/** Parse an input string into a single YAML.Document */
20export declare function parseDocument<T extends ParsedNode = ParsedNode>(source: string, options?: ParseOptions & DocumentOptions & SchemaOptions): Document.Parsed<T>;
21/**
22 * Parse an input string into JavaScript.
23 *
24 * Only supports input consisting of a single YAML document; for multi-document
25 * support you should use `YAML.parseAllDocuments`. May throw on error, and may
26 * log warnings using `console.warn`.
27 *
28 * @param str - A string with YAML formatting.
29 * @param reviver - A reviver function, as in `JSON.parse()`
30 * @returns The value will match the type of the root value of the parsed YAML
31 * document, so Maps become objects, Sequences arrays, and scalars result in
32 * nulls, booleans, numbers and strings.
33 */
34export declare function parse(src: string, options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions): any;
35export declare function parse(src: string, reviver: Reviver, options?: ParseOptions & DocumentOptions & SchemaOptions & ToJSOptions): any;
36/**
37 * Stringify a value as a YAML document.
38 *
39 * @param replacer - A replacer array or function, as in `JSON.stringify()`
40 * @returns Will always include `\n` as the last character, as is expected of YAML documents.
41 */
42export declare function stringify(value: any, options?: DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions): string;
43export declare function stringify(value: any, replacer?: Replacer | null, options?: string | number | (DocumentOptions & SchemaOptions & ParseOptions & CreateNodeOptions & ToStringOptions)): string;