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

[BUG] BigInt in object #88

Closed
wanghm25 opened this issue Jun 27, 2023 · 2 comments · Fixed by #89
Closed

[BUG] BigInt in object #88

wanghm25 opened this issue Jun 27, 2023 · 2 comments · Fixed by #89
Assignees
Labels

Comments

@wanghm25
Copy link

I found a problem with code like this (typescript):

import sizeof from "object-sizeof";

const obj = {
  num: BigInt(123123123123123123),
}

console.log(sizeof(obj));

And get error:

Error detected, return -1 TypeError: Do not know how to serialize a BigInt
    at JSON.stringify (<anonymous>)
    at objectSizeComplex (/Users/bytedance/node/node_modules/object-sizeof/indexv2.js:62:33)
...

The reason is, there is a JSON.stringify in objectSizeComplex:
const objectToString = JSON.stringify(potentialConversion)

I think,there should be a recursive call in objectSizeComplex

@lukahukur
Copy link

Ye, same issue

@lukahukur
Copy link

lukahukur commented Jul 1, 2023

   JSON.stringify(
        Object,
        (key, value) => (typeof value === 'bigint' ? value.toString() : value) // return everything else unchanged
      )

just add this

@miktam miktam self-assigned this Jul 2, 2023
@miktam miktam added the bug label Jul 2, 2023
miktam added a commit that referenced this issue Jul 2, 2023
@miktam miktam closed this as completed in #89 Jul 3, 2023
miktam added a commit that referenced this issue Jul 3, 2023
* Fix nested bigint calculation. Add support for more types of nested objects. Fixes #88
* Refactored for readability
* Added test for global symbol
* Grammar cleanup
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants