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(ini): improve ini docs #5020

Merged
merged 7 commits into from
Jun 11, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
docs: add stringify examples
kt3k committed Jun 10, 2024
commit 34a3e35adbe5819f78d94d0925f1f59459831bf2
51 changes: 51 additions & 0 deletions ini/stringify.ts
Original file line number Diff line number Diff line change
@@ -16,6 +16,57 @@ export interface StringifyOptions extends FormattingOptions {
/**
* Compile an object into an INI config string. Provide formatting options to modify the output.
*
* @example Usage
* ```ts
* import { stringify } from "@std/ini/stringify";
* import { assertEquals } from "@std/assert/assert-equals";
*
* const str = stringify({
* key1: "value1",
* key2: "value2",
* section1: {
* foo: "bar",
* },
* section2: {
* hello: "world",
* },
* });
*
* assertEquals(str, `key1=value1
* key2=value2
* [section1]
* foo=bar
* [section2]
* hello=world`);
* ```
*
* @example Using replacer option
* ```ts
* import { stringify } from "@std/ini/stringify";
* import { assertEquals } from "@std/assert/assert-equals";
*
* const str = stringify({
* "section X": {
* date: new Date(),
* },
* "section Y": {
* name: "John"
* }
* }, {
* replacer(key, value, section) {
* if (section === "section X" && key === "date") {
* return value.toISOString().slice(0, 10);
* }
* return value;
* },
* });
*
* assertEquals(str, `[section X]
* date=2024-06-10
* [section Y]
* name=John`);
* ```
*
* @param object The object to stringify
* @param options The option to use
* @returns The INI string