miktam / sizeof

Get size of a JavaScript object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

bigint support ?

Truth1984 opened this issue · comments

commented
var sizeof = require('object-sizeof');
sizeof(10n) == 0; //true
commented

Technically, your calculation is wrong.

const v8 = require("v8");
const so = require("object-sizeof");

so(2147483647) // 8
so(2147483648) // 8, wrong
so(21474836480) // 8, wrong
so("") // 0, wrong
so("A") // 2, wrong

v8.serialize("").byteLength // 4
v8.serialize(2147483647).byteLength // 8
v8.serialize(2147483648).byteLength // 11

v8.serialize(0).byteLength // 4
v8.serialize("A").byteLength // 5 ascii 4 + 1
v8.serialize("中").byteLength // 6 unicode 4 + 2

Here is what ChatGPT suggests regarding the calculating of bigint size in bytes

bigint