JSPM

  • Created
  • Published
  • Downloads 29
  • Score
    100M100P100Q98272F
  • License MIT

Simple YAML support, provides only clean subset of yaml

Package Exports

  • @travetto/yaml

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (@travetto/yaml) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

YAML

Simple YAML support, provides only clean subset of yaml

Install: @travetto/yaml

npm install @travetto/yaml

In the desire to provide a minimal footprint, the framework provides a minimal YAML parser/serializer to handle standard configuration structure.

YamlUtil is the main access point for this module, and will expose two method, parse and serialize.

Code: Simple YAML Parsing

import { YamlUtil } from '@travetto/yaml/src/util';

const obj = YamlUtil.parse(`
name: Source
age: 20
fields:
  sub: 
    - a
    - b 
    - c
  sub2: [1,2,3]
  sub3: {"k":5, "v":20}
`);

console.log(JSON.stringify(obj, null, 2));

Terminal: Simple YAML Parsing

$ alt/docs/src/parse.ts -r @travetto/boot/register alt/docs/src/parse.ts

{
  "name": "Source",
  "age": 20,
  "fields": {
    "sub": [
      "a",
      "b",
      "c"
    ],
    "sub2": [
      1,
      2,
      3
    ],
    "sub3": {
      "k": 5,
      "v": 20
    }
  }
}

Code: Simple YAML Serialization

import { YamlUtil } from '@travetto/yaml/src/util';

const text = YamlUtil.serialize({
  name: 'Source',
  age: 20,
  fields: {
    sub: [
      'a',
      'b',
      'c'
    ],
    sub2: [1, 2, 3],
    sub3: { k: 5, v: 20 }
  }
});

console.log(text);

Terminal: Simple YAML Serialization

$ alt/docs/src/serialize.ts -r @travetto/boot/register alt/docs/src/serialize.ts

name: Source
age: 20
fields:
  sub:
    - a
    - b
    - c
  sub2:
    - 1
    - 2
    - 3
  sub3:
    k: 5
    v: 20