IF Commons GitHub

toml

Written to: 1 requirement: 1 proved, 0 partly, 0 failing, 0 with no test recorded. 0001-formats FR-003

TOML 1.0.0 (https://toml.io/en/v1.0.0), read and written with no outside package (commons 0001-formats FR-003). The reader takes the whole language (bare, quoted and dotted keys; tables, arrays of tables and inline tables; the four kinds of string; decimal, hexadecimal, octal and binary integers; floats with inf and nan; the four kinds of date and time) and holds to its rules: no key or table defined twice, an inline table or a static array never extended, a table made by dotted keys never reopened by a header. It gives a typed TomlTable, or the line and column where the text stops being TOML. An integer outside JavaScript's safe range is refused rather than rounded. A date or time stays as its text, with its kind. The writer gives TOML the reader reads back as the same table. Replaces @std/toml in erga.

import { parseToml } from "./toml.ts";
parseToml('[server]\nhost = "127.0.0.1"\nports = [8000, 8001]\n');
// { kind: "ok", value: { server: { host: "127.0.0.1", ports: [8000, 8001] } } }

Source: commons/formats/src/toml.ts

7 of 11 exports are imported by a test of the run. A test that imports an export may not call it or check what it returns.

formatTomlErrorfunction
function formatTomlError(e: TomlError): string

A TOML error as one line: 3:14: expected a value.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

isTomlDateTimefunction
function isTomlDateTime(v: TomlValue): v is TomlDateTime

Whether a TOML value is a date or time.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

isTomlTablefunction
function isTomlTable(v: TomlValue): v is TomlTable

Whether a TOML value is a table (not an array, not a date or time).

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

parseTomlfunction
function parseToml(text: string): Result<TomlTable, TomlError>

TOML text read as a table, or where and why it is not TOML.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

tomlKeyfunctionno test imports it
function tomlKey(k: string): string

A key as TOML writes it: bare where it can be, else a basic string.

tomlStringfunctionno test imports it
function tomlString(s: string): string

A string as a TOML basic string: ", \ and every control character escaped.

toTomlfunction
function toToml(table: TomlTable): string

A table as TOML text: plain values first, then each table under its header and each array of tables under [[...]], ending in a line break.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

TomlDateTimetypeno test imports it
type TomlDateTime = {
  readonly kind: "offset-date-time" | "local-date-time" | "local-date" | "local-time";
  readonly text: string;
};

A date, a time, or both, as TOML wrote it (a space between date and time made T), with which of the four it is.

TomlErrortypeno test imports it
type TomlError = { readonly kind: "toml"; readonly line: number; readonly column: number; readonly message: string };

Where a text stops being TOML, and why. Lines and columns count from 1.

TomlTabletype
type TomlTable = { readonly [key: string]: TomlValue };

A TOML table: its keys in the order they were defined.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

TomlValuetype
type TomlValue = string | number | boolean | TomlDateTime | readonly TomlValue[] | TomlTable;

A TOML value.

Imported by 11 tests of the run (11 passed, 0 failed): the library's results

Titles, headings, exports, tables, columns and requirements. Esc closes.