Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs(toml): lint @std/toml docs #4799

Merged
merged 11 commits into from
May 30, 2024
1 change: 1 addition & 0 deletions _tools/check_docs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ const ENTRY_POINTS = [
"../internal/mod.ts",
"../jsonc/mod.ts",
"../media_types/mod.ts",
"../toml/mod.ts",
"../ulid/mod.ts",
"../webgpu/mod.ts",
"../http/mod.ts",
Expand Down
16 changes: 15 additions & 1 deletion toml/parse.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,21 @@ import { ParserFactory, Toml } from "./_parser.ts";

/**
* Parse parses TOML string into an object.
* @param tomlString
*
* @example Decode TOML string
* ```ts
* import { parse } from "./mod.ts";
* const tomlString = `title = "TOML Example"
* [owner]
* name = "Alice"
* bio = "Alice is a programmer."`;
*
* const obj = parse(tomlString);
* console.log(obj);
* // { title: "TOML Example", owner: { name: "Alice", bio: "Alice is a programmer." } }
* ```
* @param tomlString TOML string to be parsed.
* @returns The parsed JS object.
*/
export const parse: (tomlString: string) => Record<string, unknown> =
ParserFactory(Toml);
18 changes: 17 additions & 1 deletion toml/stringify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -260,9 +260,25 @@ class Dumper {

/**
* Stringify dumps source object into TOML string and returns it.
* @param srcObj
*
* @example Stringify an object
* ```ts
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please use an assertion from std/assert here? It ensures the example is correct. Ditto for other examples.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the assertions

* import { stringify } from "@std/toml";
*
* const obj = {
* title: "TOML Example",
* owner: {
* name: "Bob",
* bio: "Bob is a cool guy",
* }
* };
* const tomlString = stringify(obj);
* console.log(tomlString);
* ```
* @param srcObj source object
kt3k marked this conversation as resolved.
Show resolved Hide resolved
* @param [fmtOptions] format options
* @param [fmtOptions.keyAlignment] whether to align keys
kt3k marked this conversation as resolved.
Show resolved Hide resolved
* @returns TOML string
*/
export function stringify(
srcObj: Record<string, unknown>,
Expand Down
Loading