2024-01-01 21:11:32 +00:00
|
|
|
// Copyright 2018-2024 the Deno authors. All rights reserved. MIT license.
|
2023-03-18 12:36:00 +00:00
|
|
|
// This module is browser compatible.
|
|
|
|
|
2023-03-13 05:57:27 +00:00
|
|
|
/**
|
|
|
|
* {@linkcode parse} and {@linkcode stringify} for handling
|
2024-06-05 12:35:38 +00:00
|
|
|
* {@link https://toml.io | 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.
|
2023-03-13 05:57:27 +00:00
|
|
|
*
|
|
|
|
* ## Supported types and handling
|
|
|
|
*
|
2024-01-31 22:19:46 +00:00
|
|
|
* - [x] [Keys](https://toml.io/en/latest#keys)
|
|
|
|
* - [ ] [String](https://toml.io/en/latest#string)
|
|
|
|
* - [x] [Multiline String](https://toml.io/en/latest#string)
|
|
|
|
* - [x] [Literal String](https://toml.io/en/latest#string)
|
|
|
|
* - [ ] [Integer](https://toml.io/en/latest#integer)
|
|
|
|
* - [x] [Float](https://toml.io/en/latest#float)
|
|
|
|
* - [x] [Boolean](https://toml.io/en/latest#boolean)
|
|
|
|
* - [x] [Offset Date-time](https://toml.io/en/latest#offset-date-time)
|
|
|
|
* - [x] [Local Date-time](https://toml.io/en/latest#local-date-time)
|
|
|
|
* - [x] [Local Date](https://toml.io/en/latest#local-date)
|
|
|
|
* - [ ] [Local Time](https://toml.io/en/latest#local-time)
|
|
|
|
* - [x] [Table](https://toml.io/en/latest#table)
|
|
|
|
* - [x] [Inline Table](https://toml.io/en/latest#inline-table)
|
|
|
|
* - [ ] [Array of Tables](https://toml.io/en/latest#array-of-tables)
|
|
|
|
*
|
|
|
|
* _Supported with warnings see [Warning](#Warning)._
|
|
|
|
*
|
|
|
|
* ### Warning
|
2023-03-13 05:57:27 +00:00
|
|
|
*
|
|
|
|
* #### String
|
|
|
|
*
|
2024-06-05 12:35:38 +00:00
|
|
|
* Due to the spec, there is no flag to detect regex properly in a TOML
|
|
|
|
* declaration. So the regex is stored as string.
|
2023-03-13 05:57:27 +00:00
|
|
|
*
|
|
|
|
* #### 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:
|
|
|
|
*
|
|
|
|
* ```toml
|
|
|
|
* [[bin]]
|
|
|
|
* name = "deno"
|
|
|
|
* path = "cli/main.rs"
|
|
|
|
*
|
|
|
|
* [[bin]]
|
|
|
|
* name = "deno_core"
|
|
|
|
* path = "src/foo.rs"
|
|
|
|
*
|
|
|
|
* [[nib]]
|
|
|
|
* name = "node"
|
|
|
|
* path = "not_found"
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* will output:
|
|
|
|
*
|
|
|
|
* ```json
|
|
|
|
* {
|
|
|
|
* "bin": [
|
|
|
|
* { "name": "deno", "path": "cli/main.rs" },
|
|
|
|
* { "name": "deno_core", "path": "src/foo.rs" }
|
|
|
|
* ],
|
|
|
|
* "nib": [{ "name": "node", "path": "not_found" }]
|
|
|
|
* }
|
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* ```ts
|
2024-06-03 04:10:27 +00:00
|
|
|
* import { parse, stringify } from "@std/toml";
|
refactor(assert,async,bytes,cli,collections,crypto,csv,data-structures,datetime,dotenv,encoding,expect,fmt,front-matter,fs,html,http,ini,internal,io,json,jsonc,log,media-types,msgpack,net,path,semver,streams,testing,text,toml,ulid,url,uuid,webgpu,yaml): import from `@std/assert` (#5199)
* refactor: import from `@std/assert`
* update
2024-06-30 08:30:10 +00:00
|
|
|
* import { assertEquals } from "@std/assert";
|
2024-06-03 04:10:27 +00:00
|
|
|
*
|
2023-03-13 05:57:27 +00:00
|
|
|
* const obj = {
|
|
|
|
* bin: [
|
|
|
|
* { name: "deno", path: "cli/main.rs" },
|
|
|
|
* { name: "deno_core", path: "src/foo.rs" },
|
|
|
|
* ],
|
|
|
|
* nib: [{ name: "node", path: "not_found" }],
|
|
|
|
* };
|
|
|
|
*
|
2024-06-03 04:10:27 +00:00
|
|
|
* const tomlString = stringify(obj);
|
|
|
|
* assertEquals(tomlString, `
|
|
|
|
* [[bin]]
|
|
|
|
* name = "deno"
|
|
|
|
* path = "cli/main.rs"
|
2023-03-13 05:57:27 +00:00
|
|
|
*
|
2024-06-03 04:10:27 +00:00
|
|
|
* [[bin]]
|
|
|
|
* name = "deno_core"
|
|
|
|
* path = "src/foo.rs"
|
2023-03-13 05:57:27 +00:00
|
|
|
*
|
2024-06-03 04:10:27 +00:00
|
|
|
* [[nib]]
|
|
|
|
* name = "node"
|
|
|
|
* path = "not_found"
|
|
|
|
* `);
|
2023-03-13 05:57:27 +00:00
|
|
|
*
|
|
|
|
* const tomlObject = parse(tomlString);
|
2024-06-03 04:10:27 +00:00
|
|
|
* assertEquals(tomlObject, obj);
|
2023-03-13 05:57:27 +00:00
|
|
|
* ```
|
|
|
|
*
|
|
|
|
* @module
|
|
|
|
*/
|
|
|
|
|
|
|
|
export * from "./stringify.ts";
|
|
|
|
export * from "./parse.ts";
|