convertDocument
convertDocument(
text,options):Promise<ConvertResult>
Defined in: packages/core/src/convert/index.ts:96
Convert document text to YAML, JSON or TOML.
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
text | string |
options | ConvertOptions |
Returns
Section titled “Returns”Promise<ConvertResult>
Remarks
Section titled “Remarks”The output is the authored document, not the validated one: no defaults
are filled in and no sugar is expanded. Any document that parses converts,
whether or not it validates; validation says which.
Losses are reported, not fatal: comments (with their lines), each alias and
merge key (written out in full), and, going to TOML, a null where leaving
the key out means the same thing (a setFilter action’s filter, a
GeoJSON feature’s property). The conversion fails, naming the path, for any
other null going to TOML, inf or nan going to JSON, and an integer past
2^53. !html converts to {"$html": …} and back, so it is not a loss.
The promise never rejects because of what the text says. It rejects only
when a reader chunk cannot be downloaded (a FormatError of code
"chunk").
Example
Section titled “Example”const result = await convertDocument(yamlText, { to: "toml" });if (result.success) { for (const loss of result.losses) console.warn(loss.message); console.log(result.text);}