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

Support BigInt values #146

Merged
merged 2 commits into from
Mar 28, 2020
Merged

Support BigInt values #146

merged 2 commits into from
Mar 28, 2020

Conversation

eemeli
Copy link
Owner

@eemeli eemeli commented Mar 21, 2020

The JavaScript number is a 64-bit floating-point value, which means that for large values (above Number.MIN_SAFE_INTEGER, 2**53 - 1) it is unable to represent integers with complete accuracy. To help with that, BigInt is now a part of the ECMAScript 2020 spec.

This PR adds support for stringifying BigInt values, and if the asBigInt scalar option is set, to parse all integers into BigInts. I also added YAML.scalarOptions as a more user-friendly endpoint for scalar options:

YAML.parse('42')
// 42

YAML.scalarOptions.int.asBigInt = true
const n = YAML.parse('42')
// 42n

YAML.stringify(n)
// '42\n'

@eemeli eemeli added the enhancement New feature or request label Mar 21, 2020
* Support stringifying BigInt values
* Add guards against HEX & OCT ints with negative or float values
* Add guards & BigInt support also to YAML 1.1 schema
* Add option to resolve ints as BigInt; fix yaml-1.1 int resolvers
* Add BigInt support to "json" schema
@eemeli eemeli merged commit 1d73cf0 into master Mar 28, 2020
eemeli added a commit that referenced this pull request Mar 28, 2020
* Support stringifying BigInt values
* Add guards against HEX & OCT ints with negative or float values
* Add guards & BigInt support also to YAML 1.1 schema
* Add option to resolve ints as BigInt; fix yaml-1.1 int resolvers
* Add BigInt support to "json" schema
@eemeli eemeli deleted the bigint branch March 28, 2020 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant