std/toml
2019-03-29 10:51:23 -04:00
..
testdata toml: fix parsing comments (#311) 2019-03-29 10:51:23 -04:00
parser_test.ts toml: fix parsing comments (#311) 2019-03-29 10:51:23 -04:00
parser.ts toml: fix parsing comments (#311) 2019-03-29 10:51:23 -04:00
README.md Add TOML module (#300) 2019-03-28 12:31:15 -04:00
test.ts Add TOML module (#300) 2019-03-28 12:31:15 -04:00

TOML

This module parse TOML files. It follows as much as possible the TOML specs. Be sure to read the supported types as not every specs 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

  • Regex : 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.

Inline Table

Inline tables are supported but nested inline property name are not. See below:

animal = { type = { name = "pug" } } # Supported
animal = { type.name = "pug" }
# not supported. Will output { "animal" : {"type.name":"pug"} }

Array of Tables

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"

will output:

{
  "bin": [
    { "name": "deno", "path": "cli/main.rs" },
    { "name": "deno_core", "path": "src/foo.rs" }
  ],
  "nib": [{ "name": "node", "path": "not_found" }]
}

Usage

import { parseFile, parse } from "./parser.ts";

const tomlObject = parseFile("file.toml");

const tomlString = 'foo.bar = "Deno"';
const tomlObject22 = parse(tomlString);