UNPKG

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