sindresorhus / pretty-bytes

Convert bytes to a human readable string: 1337 → 1.34 kB
MIT License
1.11k stars 82 forks source link

Throws for BigInt #54

Open brunnerh opened 5 years ago

brunnerh commented 5 years ago

The function Number.isFinite returns false for all arguments of type bigint. So the formatting function throws immediately. It would be helpful if bigint would be supported as well. I would like to use it with Node's fs.stat, which now can return bigint values for file sizes.

(I tested how the function would behave without the check, and unfortunately the Math functions do not support bigint arguments: Cannot convert a BigInt value to a number at Math.log)

sindresorhus commented 5 years ago

PR welcome. For the one that wants to work on this, you need to update the readme, the TypeScript definitions, and add tests.

niktekusho commented 5 years ago

PR welcome. For the one that wants to work on this, you need to update the readme, the TypeScript definitions, and add tests.

Since official support for BigInts in Node.js comes from v10.4.0 and at the moment support for it is not the best (what about Math functions?), should this be postponed at least until Node 8 goes EOL? (2019-12-31)

If not, should we use something along the lines of big-integer to provide support for them (which anyway doesn't solve the Math.log issue)?

iansan5653 commented 4 years ago

Alternatively to waiting, just add { "engines" : { "node" : ">=10.4.0" } } to package.json for the new version.