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

feat: add skipThousandsSeparator option to to stringify #52

Draft
wants to merge 1 commit into
base: latest
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,13 @@ Also available with: `require('@iarna/toml/parse-string')`
Synchronously parse a TOML string and return an object.


## TOML.stringify(obj) → String [(example)](https://github.com/iarna/iarna-toml/blob/latest/examples/stringify.js)
## TOML.stringify(obj[, opts]) → String [(example)](https://github.com/iarna/iarna-toml/blob/latest/examples/stringify.js)

Also available with: `require('@iarna/toml/stringify')`

`opts.skipThousandsSeparator` controls if inserting thousands separators should
be skipped when stringifying numbers. Defaults to false.

Serialize an object as TOML.

## [your-object].toJSON
Expand All @@ -86,10 +89,13 @@ because `JSON` represents dates as strings and TOML can represent them natively.
[`moment`](https://www.npmjs.com/package/moment) objects are treated the
same as native `Date` objects, in this respect.

## TOML.stringify.value(obj) -> String
## TOML.stringify.value(obj[, opts]) -> String

Also available with: `require('@iarna/toml/stringify').value`

`opts.skipThousandsSeparator` controls if inserting thousands separators should
be skipped when stringifying numbers. Defaults to false.

Serialize a value as TOML would. This is a fragment and not a complete
valid TOML document.

Expand Down
11 changes: 9 additions & 2 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ interface FuncParse {
stream (): Transform
}

interface StringifyOptions {
/**
* Skip inserting thousands separators when stringifying numbers. Defaults to false.
*/
skipThousandsSeparator?: boolean
}

interface FuncStringify {
/**
* Serialize an object as TOML.
Expand All @@ -46,12 +53,12 @@ interface FuncStringify {
*
* `moment` objects are treated the same as native `Date` objects, in this respect.
*/
(obj: JsonMap): string
(obj: JsonMap, options?: StringifyOptions): string

/**
* Serialize a value as TOML would. This is a fragment and not a complete valid TOML document.
*/
value (any: AnyJson): string
value (any: AnyJson, options?: StringifyOptions): string
}

export const parse: FuncParse
Expand Down
Loading