Tiny module to get a human readable file size from a byte count.
import humanSize from '@luxcium/human-size';
console.log(humanSize(10 * 1024 * 1024));
// prints "10MB"
console.log(humanSize(10 * 1024 * 1024, 2));
// prints "10.00MB"
console.log(humanSize(106168));
// prints "104KB"
console.log(humanSize(106168, 2));
// prints "103.68KB"
const SPACED = true;
console.log(humanSize(10 * 1024 * 1024, SPACED));
// prints "10 MB"
console.log(humanSize(10 * 1024 * 1024, 2, SPACED));
// prints "10.00 MB"
console.log(humanSize(106168, SPACED));
// prints "104 KB"
console.log(humanSize(106168, 2, SPACED));
// prints "103.68 KB"
Based on the work of Andrew Kelley (MIT © 2014-2022)
† Scientia est lux principium✨ ™