formatTomlErrorfunctionfunction formatTomlError(e: TomlError): stringA TOML error as one line: 3:14: expected a value.
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] } } }formatTomlErrorfunctionfunction formatTomlError(e: TomlError): stringA TOML error as one line: 3:14: expected a value.
isTomlDateTimefunctionfunction isTomlDateTime(v: TomlValue): v is TomlDateTimeWhether a TOML value is a date or time.
isTomlTablefunctionfunction isTomlTable(v: TomlValue): v is TomlTableWhether a TOML value is a table (not an array, not a date or time).
parseTomlfunctionfunction parseToml(text: string): Result<TomlTable, TomlError>TOML text read as a table, or where and why it is not TOML.
tomlKeyfunctionno test imports itfunction tomlKey(k: string): stringA key as TOML writes it: bare where it can be, else a basic string.
tomlStringfunctionno test imports itfunction tomlString(s: string): stringA string as a TOML basic string: ", \ and every control character escaped.
toTomlfunctionfunction toToml(table: TomlTable): stringA table as TOML text: plain values first, then each table under its header and each array of tables under [[...]], ending in a line break.
TomlDateTimetypeno test imports ittype 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 ittype 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.
TomlTabletypetype TomlTable = { readonly [key: string]: TomlValue };A TOML table: its keys in the order they were defined.
TomlValuetypetype TomlValue = string | number | boolean | TomlDateTime | readonly TomlValue[] | TomlTable;A TOML value.