Extended YAML


License
MIT
Install
npm install xyaml@0.1.15

Documentation

Maintenance Maintaner Website shields.io made-with-Markdown made-for-VSCode GitHub license Profile views GitHub contributors GitHub issues

GitHub forks GitHub stars GitHub watchers GitHub followers

xyaml

YAML extensions

  • Including & importing yaml, json, js files
  • Expressions interpolation
  • JavaScript-functions in YAML-code
  • Evaluating instructions

Loading YAML-file

const xyaml = require('xyaml');

let data  = xyaml.loadFile('./data.yaml');

Extended YAML syntax

Example

# Plain properties
username: teniryte
email: teniryte@gmail.com
age: 25

# Interpolation
paths:
  users: /home
  home: ${users}/teniryte
  work: ${home}/work
  config: ${work}/config
  # Current scope link
  packages: ${self.work}/packages
  # Root scope link
  tools: ${root.paths.work}/tools
  current:
    # Parent scope link
    package: ${parent.packages}/1


# Embedded functions
math:
  base: 2
  methods:
    add: (a, b) => {
      return a + b + parent.base;
    };
    sub: (a, b) => {
      return a - b + parent.base;
    };

  results:
    # 5
    - ${methods.add(1, 2)}
    # 3
    - ${methods.sub(2, 1)}

# Include module (includes all module properties into current object)
included:
  ~include: logger.js
  ~include: https://cdn.cort.one/xyaml/test/fruits.yaml
  ~include: colors.yaml
  ~include: package.json
  # Include files fruits.yaml, languages.yaml
  ~include:
    - fruits
    - languages

# Import module (incapsulates module into it's own scope)
imported:
  logger: ~import logger.js
  fruits: ~import https://cdn.cort.one/xyaml/test/fruits.yaml
  package: ~import package.json

eval:
  - self.delete('math.add');

Import JavaScript module

readfiles.js

'use strict';

const fs = require('fs');
const path = require('path');

let [dirname] = process.argv;

module.exports = fs.readdirSync(path.resolve(__dirname, dirname));

data.yaml

files: ~import files.js ../../lib