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

add support for builtin "bigint" and other libraries for handling big numbers #21

Merged
merged 4 commits into from
May 9, 2022

Conversation

sseide
Copy link
Contributor

@sseide sseide commented May 6, 2020

This PR adds handling of the Javascript built-in datatyp "BigInt" (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt) and supports some other Javascript libraries to work with big numbers (list added in the README).

The other libraries are optional and recognition must be enabled with new option parameter to the jsonViewer() method. The current default handling is not changed.

The reason behind this patch is that javascripts "Number" type only supports a subset of the number range of other languages, its roughy equivalent to other "float" data types. All numbers from "long" or "double" like data types cannot be displayed with it. As the JSON spec defines no ranges for numbers big values can only be handled with special libraries in Javascript without changing the values or loosing precision. Current version of the json-viewer does not display such numbers but all fields of the objects needed to cunstruct these numbers, therefore displaying wrong informations for such special cases (examples inside the README)

Adding this PR would really help us in our own project (Redis-Commander) to display values stored inside a Redis DB correctly..

Thanks,
Stefan Seide

@sseide
Copy link
Contributor Author

sseide commented May 9, 2022

Hi @abodelot - any change this PR gets merged to have bigint support as well?
I merged latest changes from master (the security fix) and added tests to check for correct conversion of bigger integers.

"bigint" is supported by all current browsers for years now (only old IE11 missing - https://caniuse.com/?search=bigint) and the change does not throw an error in browsers not supporting it. Therefore it would be really good to fix the display error in this library.

Thanks in advance

@abodelot
Copy link
Owner

abodelot commented May 9, 2022

Hi @sseide!

First, thank you for your contribution and sorry about the lack of feedback! I didn't attend to this project for a while.

I think that your PR would be a great addition.

@abodelot abodelot merged commit 192b8f6 into abodelot:master May 9, 2022
@sseide sseide deleted the big_number_support branch May 19, 2022 18:51
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.

None yet

2 participants