parse and stringify for handling TOML encoded data.
parse
stringify
Be sure to read the supported types as not every spec is supported at the moment and the handling in TypeScript side is a bit different.
Supported with warnings see Warning.
Due to the spec, there is no flag to detect regex properly in a TOML declaration. So the regex is stored as string.
For Binary / Octal / Hexadecimal numbers, they are stored as string to be not interpreted as Decimal.
Because local time does not exist in JavaScript, the local time is stored as a string.
At the moment only simple declarations like below are supported:
[[bin]]name = "deno"path = "cli/main.rs"[[bin]]name = "deno_core"path = "src/foo.rs"[[nib]]name = "node"path = "not_found" Copy
[[bin]]name = "deno"path = "cli/main.rs"[[bin]]name = "deno_core"path = "src/foo.rs"[[nib]]name = "node"path = "not_found"
will output:
{ "bin": [ { "name": "deno", "path": "cli/main.rs" }, { "name": "deno_core", "path": "src/foo.rs" } ], "nib": [{ "name": "node", "path": "not_found" }]} Copy
{ "bin": [ { "name": "deno", "path": "cli/main.rs" }, { "name": "deno_core", "path": "src/foo.rs" } ], "nib": [{ "name": "node", "path": "not_found" }]}
import { parse, stringify } from "@std/toml";import { assertEquals } from "@std/assert";const obj = { bin: [ { name: "deno", path: "cli/main.rs" }, { name: "deno_core", path: "src/foo.rs" }, ], nib: [{ name: "node", path: "not_found" }],};const tomlString = stringify(obj);assertEquals(tomlString, `[[bin]]name = "deno"path = "cli/main.rs"[[bin]]name = "deno_core"path = "src/foo.rs"[[nib]]name = "node"path = "not_found"`);const tomlObject = parse(tomlString);assertEquals(tomlObject, obj); Copy
import { parse, stringify } from "@std/toml";import { assertEquals } from "@std/assert";const obj = { bin: [ { name: "deno", path: "cli/main.rs" }, { name: "deno_core", path: "src/foo.rs" }, ], nib: [{ name: "node", path: "not_found" }],};const tomlString = stringify(obj);assertEquals(tomlString, `[[bin]]name = "deno"path = "cli/main.rs"[[bin]]name = "deno_core"path = "src/foo.rs"[[nib]]name = "node"path = "not_found"`);const tomlObject = parse(tomlString);assertEquals(tomlObject, obj);
parseandstringifyfor handling TOML encoded data.Be sure to read the supported types as not every spec is supported at the moment and the handling in TypeScript side is a bit different.
Supported types and handling
Supported with warnings see Warning.
Warning
String
Due to the spec, there is no flag to detect regex properly in a TOML declaration. So the regex is stored as string.
Integer
For Binary / Octal / Hexadecimal numbers, they are stored as string to be not interpreted as Decimal.
Local Time
Because local time does not exist in JavaScript, the local time is stored as a string.
Array of Tables
At the moment only simple declarations like below are supported:
will output: