$ npm install yaml
JavaScript parser and stringifier for YAML 1.2
Note: yaml 0.x and 1.x are rather different implementations. For the earlier yaml, see tj/js-yaml.
npm install yaml@next
import { resolve } from 'yaml'
const yaml =
`YAML:
- A human-readable data serialization language
- https://en.wikipedia.org/wiki/YAML
yaml:
- A complete JavaScript implementation
- https://www.npmjs.com/package/yaml
`
const doc = resolve(yaml)[0]
doc.toJSON()
/*
* { YAML:
* [ 'A human-readable data serialization language',
* 'https://en.wikipedia.org/wiki/YAML' ],
* yaml:
* [ 'A complete JavaScript implementation',
* 'https://www.npmjs.com/package/yaml' ] }
*/
doc.toString() === yaml
The reason why this project exists is to have a tool that's capable of properly generating and handling YAML files with comments, specifically to provide context for translation strings that have been lifted out of JS source code. We're not there quite yet, as the prerequisite for that is having a complete and functioning YAML library.
The AST level of the library has been released separately, and is fully functional.
!!yaml.<< merge keys (default-enabled, disable with merge: false option)in.yaml, in.json, and out.yaml files across all of the yaml-test-suite test cases (note: A few of the tests are not in agreement with the spec, so this requires the use of a custom branch until the relevant pull requests and issues are resolved)Map and Seq collections have toJSON() methods for bare JavaScript Object and Array outputerrors arrayDocument#toString() produces idempotent YAML from all non-error spec examples and test suite casesAST#toString() works completely, but is clumsy to useDocument, Map and Seq need constructors accepting plain JS objects© 2010 - cnpmjs.org x YWFE | Home | YWFE