@dbbrowne/yamlise
v0.1.2
Published
Convert JS objects to YAML with 0 dependencies.
Readme
Yamlise
A tiny, 0-dependency package to convert JS objects to YAML.
Contents
Usage
Install with NPM:
$ npm install @dbbrowne/yamlisevar yamlise = require('@dbbrowne/yamlise')
var dataInYamlForm = yamlise.to(data).to(data, paddingIncrement)
Where:
datais any JS object (primative or complex)paddingIncrement- OPTIONAL - string to represent depth in YAML. Defaults to " ".
Contributing
PRs or Github issues with MREs of unexpected behaviour (or whole test cases, or fixes) are very welcome!
Demos
Given a JS object:
var data = {
foo: [
{
bar: [
{
baz: ["apples", "bananas"],
},
],
quux: [
{
do: ["red thing", "blue thing"],
},
],
},
],
grault: {
name: "Bob",
age: 37,
grumpy: false,
nullish: null,
},
answer: 42,
regex: new RegExp('a1\.:d@2', 'g),
};var yamlise = require('@dbbrowne/yamlise')
console.log(yamlise.to(data))outputs to the console:
foo:
-
bar:
- baz:
- "apples"
- "bananas"
quux:
- do:
- "red thing"
- "blue thing"
grault:
name: "Bob"
age: 37
grumpy: false
nullish: null
answer: 42
regex: /a1\.:d@2/gRunning Tests
node yamlise.__test__.jsAny console output indicates test failure.
Known Issues
- Extra space after
:on lines where child is not primitive.
