Package Exports
- @travetto/yaml
- @travetto/yaml/__index__.ts
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
# or
yarn add @travetto/yamlIn 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';
export function main(): void {
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
$ trv main doc/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';
export function main(): void {
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
$ trv main doc/serialize.ts
name: Source
age: 20
fields:
sub:
- a
- b
- c
sub2:
- 1
- 2
- 3
sub3:
k: 5
v: 20