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.
|
|
|
|
|
2024-07-07 11:59:30 +00:00
|
|
|
import { parserFactory, toml } from "./_parser.ts";
|
2023-03-13 05:57:27 +00:00
|
|
|
|
|
|
|
/**
|
2024-06-05 12:35:38 +00:00
|
|
|
* Parses a {@link https://toml.io | TOML} string into an object.
|
2024-05-30 04:08:02 +00:00
|
|
|
*
|
2024-06-05 12:35:38 +00:00
|
|
|
* @example Usage
|
2024-05-30 04:08:02 +00:00
|
|
|
* ```ts
|
|
|
|
* import { parse } from "@std/toml/parse";
|
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-05-30 04:08:02 +00:00
|
|
|
*
|
|
|
|
* const tomlString = `title = "TOML Example"
|
|
|
|
* [owner]
|
|
|
|
* name = "Alice"
|
|
|
|
* bio = "Alice is a programmer."`;
|
|
|
|
*
|
|
|
|
* const obj = parse(tomlString);
|
|
|
|
* assertEquals(obj, { title: "TOML Example", owner: { name: "Alice", bio: "Alice is a programmer." } });
|
|
|
|
* ```
|
|
|
|
* @param tomlString TOML string to be parsed.
|
|
|
|
* @returns The parsed JS object.
|
2023-03-13 05:57:27 +00:00
|
|
|
*/
|
2024-06-05 12:35:38 +00:00
|
|
|
export function parse(tomlString: string): Record<string, unknown> {
|
2024-07-07 11:59:30 +00:00
|
|
|
return parserFactory(toml)(tomlString);
|
2024-06-05 12:35:38 +00:00
|
|
|
}
|