0.1.2 • Published 2 years ago

@dbbrowne/yamlise v0.1.2

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Yamlise

A tiny, 0-dependency package to convert JS objects to YAML.

Contents

Usage

Install with NPM:

$ npm install @dbbrowne/yamlise
var yamlise = require('@dbbrowne/yamlise')

var dataInYamlForm = yamlise.to(data)

.to(data, paddingIncrement)
Where:

  • data is 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/g

Running Tests

node yamlise.__test__.js

Any console output indicates test failure.

Known Issues

  1. Extra space after : on lines where child is not primitive.