@origints/yaml
YAML parsing with support for single and multi-document streams, anchors, aliases, custom tags, and full source location tracking.
Installation
Section titled “Installation”npm install @origints/yaml @origints/coreFeatures
Section titled “Features”- Parse single or multi-document YAML streams
- Preserve anchors, aliases, and custom tags
- Full source location tracking for every node
- Navigation API with type-safe extraction
- JSON conversion with customizable options
Usage with Planner
Section titled “Usage with Planner”Extract from a YAML config
Section titled “Extract from a YAML config”import { Planner, loadFile, run } from '@origints/core'import { parseYaml } from '@origints/yaml'
const plan = new Planner() .in(loadFile('config.yaml')) .mapIn(parseYaml()) .emit((out, $) => out .add('host', $.get('database').get('host').string()) .add('port', $.get('database').get('port').number()) ) .compile()
const result = await run(plan, { readFile, registry })// result.value: { host: 'localhost', port: 5432 }Extract arrays
Section titled “Extract arrays”const plan = new Planner() .in(loadFile('users.yaml')) .mapIn(parseYaml()) .emit((out, $) => out .add('names', $.get('users').array(u => u.get('name').string())) .add('roles', $.get('users').array(u => u.get('role').string())) ) .compile()Convenience collection methods
Section titled “Convenience collection methods”.emit((out, $) => out .add('tags', $.get('tags').strings()) .add('ports', $.get('ports').numbers()))Multi-document YAML
Section titled “Multi-document YAML”import { parseYamlAll } from '@origints/yaml'
const plan = new Planner() .in(loadFile('multi.yaml')) .mapIn(parseYamlAll()) .emit((out, $) => out .add('names', $.array(doc => doc.get('name').string())) ) .compile()Standalone usage
Section titled “Standalone usage”import { parseYamlImpl, toJson, YamlNode } from '@origints/yaml'
const node = parseYamlImpl.execute(yamlString) as YamlNode
const name = node.get('name')if (name.ok) console.log(name.value.asString().value)
const json = toJson(node)if (json.ok) console.log(json.value)| Export | Description |
|---|---|
parseYaml(options?) | Transform AST for single-document YAML |
parseYamlAll(options?) | Transform AST for multi-document YAML |
parseYamlImpl | Sync transform implementation |
parseYamlAsyncImpl | Async transform implementation |
registerYamlTransforms(registry) | Register YAML transforms |
YamlNode | Navigable wrapper |
toJson(node, options?) | Convert to JSON |
License
Section titled “License”MIT