Skip to content

@origints/toml

Full TOML 1.0 spec support with source position tracking, type-safe navigation, and proper datetime handling.

Terminal window
npm install @origints/toml @origints/core
  • 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
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 }
.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())
)
// [[servers]]
// name = "alpha"
// ip = "10.0.0.1"
.emit((out, $) => out
.add('serverNames', $.get('servers').array(s => s.get('name').string()))
)
.emit((out, $) => out
.add('tags', $.get('tags').strings())
.add('ports', $.get('ports').numbers())
)
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)
ExportDescription
parseToml(options?)Transform AST for Planner.mapIn()
parseTomlImplSync transform implementation
parseTomlAsyncImplAsync transform implementation
registerTomlTransforms(registry)Register TOML transforms
TomlNodeNavigable wrapper
toJson(node, options?)Convert to JSON

MIT