Skip to content

Latest commit

 

History

History
40 lines (26 loc) · 822 Bytes

README.md

File metadata and controls

40 lines (26 loc) · 822 Bytes

@luxcium/human-size

Tiny module to get a human readable file size from a byte count.

Usage

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)

MIT © 2022-2024 Luxcium (Benjamin Vincent)

† Scientia est lux principium✨ ™