delvedor / yaml-template

Declare js objects with style using yaml syntax.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

yaml-template

js-standard-style Build Status

Declare js objects with style using yaml syntax.
Use es6 template strings to declare your object and use this module as tagged template to convert it to a js object.

Install

npm i yaml-template --save

Usage

const yaml = require('yaml-template')

const obj = yaml`
  array:
    - value: 2
    - value: 4
    - value: 6
`

console.log(obj)
// {
//   array: [
//     { value: 2 },
//     { value: 4 },
//     { value: 6 }
//   ]
// }

It can be super useful if you must declare json schema (less brackets!)

var schema = {
  querystring: {
    type: 'object',
    properties: {
      name: { type: 'string' },
      excitement: { type: 'integer' }
    }
  },
  responses: {
    200: {
      type: 'object',
      properties: {
        hello: { type: 'string' }
      }
    }
  }
}

// will become

var schema = yaml`
  querystring:
    type: object
    properties:
      name:
        type: string
      excitement:
        type: string
  responses:
    200:
      responses:
        type: object
        properties:
          hello:
            type: string
`

Acknowledgements

This project is kindly sponsored by LetzDoIt.
The parser is done by js-yaml and the implementation is inspired by 2ality.

License

MIT

Copyright © 2017 Tomas Della Vedova

About

Declare js objects with style using yaml syntax.

License:MIT License


Languages

Language:JavaScript 100.0%