Skip to content

parseDocumentText

parseDocumentText(text, options): Promise<FormattedParseResult<{[key: string]: any; }>>

Defined in: packages/core/src/parser/document-text.ts:108

Read document text in YAML, JSON or TOML and validate it.

ParameterType
textstring
optionsParseDocumentTextOptions & object

Promise<FormattedParseResult<{[key: string]: any; }>>

The format comes from options.format, else from options.signals, else from the text itself: a first { is JSON, key = value lines with no key: line are TOML, and anything else is YAML.

The promise never rejects because of what the text says: a syntax error, an invalid document or an unexpected exception all resolve as an error result. Every result, and every error in it, carries format.

const result = await parseDocumentText(text, {
kind: "map",
signals: { url: "maps/city.json" },
});
if (!result.success) console.error(result.format, result.errors);

parseDocumentText(text, options): Promise<FormattedParseResult<{[key: string]: any; }>>

Defined in: packages/core/src/parser/document-text.ts:112

Read document text in YAML, JSON or TOML and validate it.

ParameterType
textstring
optionsParseDocumentTextOptions & object

Promise<FormattedParseResult<{[key: string]: any; }>>

The format comes from options.format, else from options.signals, else from the text itself: a first { is JSON, key = value lines with no key: line are TOML, and anything else is YAML.

The promise never rejects because of what the text says: a syntax error, an invalid document or an unexpected exception all resolve as an error result. Every result, and every error in it, carries format.

const result = await parseDocumentText(text, {
kind: "map",
signals: { url: "maps/city.json" },
});
if (!result.success) console.error(result.format, result.errors);

parseDocumentText(text, options?): Promise<DocumentTextResult>

Defined in: packages/core/src/parser/document-text.ts:116

Read document text in YAML, JSON or TOML and validate it.

ParameterType
textstring
options?ParseDocumentTextOptions & object

Promise<DocumentTextResult>

The format comes from options.format, else from options.signals, else from the text itself: a first { is JSON, key = value lines with no key: line are TOML, and anything else is YAML.

The promise never rejects because of what the text says: a syntax error, an invalid document or an unexpected exception all resolve as an error result. Every result, and every error in it, carries format.

const result = await parseDocumentText(text, {
kind: "map",
signals: { url: "maps/city.json" },
});
if (!result.success) console.error(result.format, result.errors);