@origints/toml
Full TOML 1.0 spec support with source position tracking, type-safe navigation, and proper datetime handling.
Installation
Section titled “Installation”npm install @origints/toml @origints/coreFeatures
Section titled “Features”- Full TOML 1.0 spec support
- Source position tracking for all nodes
- Type-safe navigation with Result types
- Proper datetime handling (offset, local date/time)
- JSON conversion with customizable options
Usage with Planner
Section titled “Usage with Planner”Extract from a TOML config
Section titled “Extract from a TOML config”import { Planner, loadFile, run } from '@origints/core'import { parseToml } from '@origints/toml'
const plan = new Planner() .in(loadFile('config.toml')) .mapIn(parseToml()) .emit((out, $) => out .add('host', $.get('server').get('host').string()) .add('port', $.get('server').get('port').number()) .add('debug', $.get('server').get('debug').boolean()) ) .compile()
const result = await run(plan, { readFile, registry })// result.value: { host: 'localhost', port: 8080, debug: false }Nested tables
Section titled “Nested tables”.emit((out, $) => out .add('dbHost', $.get('database').get('host').string()) .add('poolMin', $.get('database').get('pool').get('min').number()) .add('poolMax', $.get('database').get('pool').get('max').number()))Array of tables
Section titled “Array of tables”// [[servers]]// name = "alpha"// ip = "10.0.0.1"
.emit((out, $) => out .add('serverNames', $.get('servers').array(s => s.get('name').string())))Convenience collection methods
Section titled “Convenience collection methods”.emit((out, $) => out .add('tags', $.get('tags').strings()) .add('ports', $.get('ports').numbers()))Standalone usage
Section titled “Standalone usage”import { parseTomlImpl, toJson, TomlNode } from '@origints/toml'
const node = parseTomlImpl.execute(tomlString) as TomlNode
const host = node.get('server')if (host.ok) console.log(host.value.get('host').value.asString().value)
const json = toJson(node)if (json.ok) console.log(json.value)| Export | Description |
|---|---|
parseToml(options?) | Transform AST for Planner.mapIn() |
parseTomlImpl | Sync transform implementation |
parseTomlAsyncImpl | Async transform implementation |
registerTomlTransforms(registry) | Register TOML transforms |
TomlNode | Navigable wrapper |
toJson(node, options?) | Convert to JSON |
License
Section titled “License”MIT