mapped-yaml
A simple yaml parser providing source map as well.
npm i mapped-yaml
Usage
import { readFile } from 'fs/promises'
import { parse } from 'mapped-yaml'
async main() {
const content = await readFile('./stuff.yml', 'utf8')
const parsed = parse(content, './stuff.yml')
assert(parsed.object['hellow'].object === 'world')
assert(parsed.object['stuff'].object[0].object === 42)
assert(parsed.object['stuff'].object[1].object['foo'].object === 'bar')
console.log(parsed.object['stuff'].object[1].location)
console.log(
parsed.location.file.range(
parsed.object['stuff'].object[0].location.range,
{ surrounding: 1 }
)
)
}
hellow: world
stuff:
- 42
- foo: bar
⚠️ Line and character indexes are ZERO-BASED. ⚠️
Acknowledgement
This is a simple wrapper over yaml. If you don't need source mapping, most probably you should just use that package.