A practical TOML config reader written entirely in Lumen.
V1 is intentionally focused on common read-only config use cases. It does not read files, mutate process state, or attempt the whole TOML 1.0 surface.
import { getString, getInt, getBool, getArray, stringify } from "https://lumen-lang.org/package/std-contrib/toml/toml.ts";
let src = "[package]\nname = \"demo\"\nversion = 1\n";
let name = getString(src, "package.name", "");
let version = getInt(src, "package.version", 0);
let out = stringify(["package.name=demo", "package.version=1"]);
| API | Meaning |
|---|---|
parse(src: string): string[] | Parse into normalized path=value entries |
keys(src: string): string[] | Return normalized keys in document order |
has(src: string, key: string): bool | Return whether key exists |
get(src, key, fallback): string | Return the last raw value for key |
getString(src, key, fallback): string | Return a string value |
getInt(src, key, fallback): int | Return an integer value |
getBool(src, key, fallback): bool | Return a boolean value |
getArray(src, key): string[] | Return simple array items as strings |
stringify(entries: string[]): string | Serialize normalized path=value entries |
The npm TOML ecosystem usually exposes parse and stringify over JavaScript objects. Lumen does not yet have the same dynamic object shape, so this package uses normalized path=value entries as the stable interchange format for now.
# outside quotes[package][database.primary]"basic" and 'literal' quotes_ separators and negative valuestrue, false["a", "b"], [1, 2]get* returning the last valueTest:
lumen test packages/toml/toml.ts