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

Stringify BigInts #12

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Stringify BigInts #12

wants to merge 1 commit into from

Conversation

ntr-808
Copy link

@ntr-808 ntr-808 commented Mar 12, 2021

I ran into issues using https://github.com/trentm/node-bunyan which makes use of this library.

This PR simply converts BigInts to strings, which I think is reasonable because

> BigInt('11111111111111111111111111111111111');
11111111111111111111111111111111111n

BigNumber.js similarly uses strings as an intermediate representation.

I ran into issues using https://github.com/trentm/node-bunyan which makes use of this library.

This PR simply converts BigInts to strings, which I think is reasonable because 
```
> BigInt('11111111111111111111111111111111111');
11111111111111111111111111111111111n
```

BigNumber.js similarly uses strings as an intermediate representation.
@TwitchBronBron
Copy link

Any chance this could get merged and released soon?

@TwitchBronBron
Copy link

For those who are interested, I worked around this issue in rokucommunity/logger#3 by using the replacer 2nd argument.

const safeJsonStringify = require('safe-json-stringify');
const theObjectToStringify = {
    someBigInt: BigInt('123')
};
const jsonString = safeJsonStringify(theObjectToStringify, (key, value) => {
    //if it's a BigInt, return the string value instead
    return typeof value === 'bigint' ? value.toString() : value;
});

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants