Home Reference Source

YAML

Usage

Both yaml.parse() and yaml.stringify() accepts the data to be parsed/stringified as the first argument, and an option's object as the second.

Parse

const assert = require('assert'')
const { yaml } = require('parserblade')
const input = 'series: Bleach\nseasons: 16'
const result = yaml.parse(data)
assert.deepStrictEqual(
  result,
  { series: 'Bleach', seasons: 16 }
)

Stringify

const assert = require('assert'')
const { yaml } = require('parserblade')
const input = { series: 'Bleach', seasons: 16 }
const result = yaml.parse(data)
assert.equal(
  result,
  'series: Bleach\nseasons: 16'
)

Valid

Just checks if given string is a valid YAML

const assert = require('assert')
const { yaml } = require('parserblade')
const result = yaml.valid('[name:\nStardew')

assert.equal(
  result,
  false
)