beenotung / compress-json

Store JSON data in space efficient manner
https://www.npmjs.com/package/compress-json
BSD 2-Clause "Simplified" License
108 stars 6 forks source link

SyntaxError: Cannot convert exponential number to a BigInt #9

Closed Trudko closed 2 years ago

Trudko commented 2 years ago

Compress-JSON is converting number to a Big Int. BigInt doesn't work with exponential numbers in string form so

import { compress } from "compress-json";

const data = {
    a: 1.23456789123789e22,
};

compress(data);

will fail with:

SyntaxError: Cannot convert 22+e98732198765432 to a BigInt
    at BigInt (<anonymous>)
    at int_str_to_s (/Users/my-user/test/node_modules/compress-json/dist/number.js:105:31)
    at Object.num_to_s (/Users/my-user/test/node_modules/compress-json/dist/number.js:96:9)
    at Object.encodeNum (/Users/my-user/test/node_modules/compress-json/dist/encode.js:6:31)
    at addValue (/Users/my-user/test/node_modules/compress-json/dist/memory.js:145:46)
    at Object.addValue (/Users/my-user/test/node_modules/compress-json/dist/memory.js:137:31)
    at compress (/Users/my-user/test/node_modules/compress-json/dist/core.js:9:27)
beenotung commented 2 years ago

Thanks for the report, already having idea on how to fix it

beenotung commented 2 years ago

The reported bug is fixed in https://github.com/beenotung/compress-json/commit/f9c83c99b67ceb45be8f8e5b8f389cda88b42f64 and the patched version is release as compress-json@2.1.2

@Trudko you may update the package version then confirm if it works for your case :rocket:

Trudko commented 2 years ago

@beenotung works like a charm :)