API Reference
YAML
A YAML 1.2 parser and serializer for Node.js with full comment and anchor preservation.
Official Documentation ↗CompatibilityThis documentation covers version
v2.4. Check the official docs for the latest API surface.Installation
npm
npm install yamlMethods
No methods match this filter.
The yaml package parses and writes YAML while offering a document model that keeps comments and formatting.
Key Features
- YAML 1.2 core schema by default
- parseDocument retains comments and anchors
- Multiple documents and custom tags
Usage Notes
Pin a version and check the official docs for the API surface you depend on before upgrading.
Errors
The following points are quoted verbatim from the official documentation (https://eemeli.org/yaml/). Any error type, throw condition or recovery step not stated there is left unspecified; this page does not infer exception classes or return values.
- Used by: parse() , parseDocument() , parseAllDocuments() , stringify() , new Composer() , and new Document() Name Type Default Description logLevel ‘warn’ ⎮ ‘error’ ⎮ ‘silent’ ‘warn’ Control the verbosity of parse() . (https://eemeli.org/yaml/)
- Set to ‘error’ to silence warnings, and to ‘silent’ to also silence most errors (not recommended). (https://eemeli.org/yaml/)
- If you’d like to silence these, set the logLevel option to ‘error’ . (https://eemeli.org/yaml/)
Security notes
Quoted from the official documentation (https://eemeli.org/yaml/); this is not a complete threat model.
- Inside double-quoted strings / is now a valid escape for the / character. (https://eemeli.org/yaml/)
FAQ
- Does it preserve comments?
- Yes with parseDocument. The Document retains comments and CST nodes so edits can be written back without losing formatting.
- Is YAML.parse safe?
- Yes. It uses the YAML 1.2 core schema and does not instantiate arbitrary JavaScript types unless a custom schema is supplied.
- How do I read multiple documents?
- Use YAML.parseAllDocuments(src), which returns one Document per --- separator, then call toJS on each.
Report a problem with this API docOpens a pre-filled issue on GitHub.