-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
121 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,13 @@ | ||
export { parseJSON5 } from "./json5"; | ||
export { parseJSON5, stringifyJSON5 } from "./json5"; | ||
export type { JSON5ParseOptions, JSON5StringifyOptions } from "./json5"; | ||
|
||
export { parseJSONC } from "./jsonc"; | ||
export { parseJSONC, stringifyJSONC } from "./jsonc"; | ||
export type { JSONCParseError, JSONCParseOptions } from "./jsonc"; | ||
|
||
export { parseYAML, stringifyYAML } from "./yaml"; | ||
export type { parseYAMLOptions, stringifyYAMLOptions } from "./yaml"; | ||
|
||
export { parseTOML, stringifyTOML } from "./toml"; | ||
export type { YAMLParseOptions, YAMLStringifyOptions } from "./yaml"; | ||
|
||
export { parseJSON, stringifyJSON } from "./json"; | ||
export type { JSONParseOptions, JSONStringifyOptions } from "./json"; | ||
|
||
export { parseTOML, stringifyTOML } from "./toml"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,26 +1,34 @@ | ||
import { getFormat, storeFormat } from "./_format"; | ||
import { parse, stringify } from "smol-toml"; | ||
|
||
// Source: https://github.com/squirrelchat/smol-toml | ||
|
||
/** | ||
* Converts a [TOML](https://toml.io/) string into an object. | ||
* | ||
* @NOTE Comments and indentation is not preserved after parsing. | ||
* | ||
* @template T The type of the return value. | ||
* @param text The TOML string to parse. | ||
* @returns The JavaScript value converted from the TOML string. | ||
*/ | ||
export function parseTOML<T = unknown>(text: string): T { | ||
return parse(text) as T; | ||
const obj = parse(text); | ||
storeFormat(text, obj, { preserveIndentation: false }); | ||
return obj as T; | ||
} | ||
|
||
/** | ||
* Converts a JavaScript value to a [TOML](https://toml.io/) string. | ||
* | ||
* @NOTE Comments and indentation is not preserved in the output. | ||
* | ||
* @param value | ||
* @param options | ||
* @returns The YAML string converted from the JavaScript value. | ||
*/ | ||
export function stringifyTOML(value: any): string { | ||
return stringify(value); | ||
const format = getFormat(value, { preserveIndentation: false }); | ||
const str = stringify(value); | ||
return format.whitespace.start + str + format.whitespace.end; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters