1.0.0 • Published 9 months ago
node-size v1.0.0
node-size
Convert byte/bit numbers to human-readable format and reverse. This modules supports both IEC and SI/JEDEC formats (1000 and 1024 divisions).
Installation
In order to install it you can run:
$ npm install node-size --saveUsage
Simple usage:
import { humanReadableSize } from 'node-size';
let input = 10362;
let output = humanReadableSize(input);
console.log(output); // prints '10.12 kB'IEC standard usage:
import { humanReadableSize, SIZE_FORMAT } from 'node-size';
let input = 10120;
let output = humanReadableSize(input, SIZE_FORMAT.IEC);
console.log(output); // prints '10.12 KiB'Changing default format:
import { setDefaultSizeFormat, humanReadableSize, SIZE_FORMAT } from 'node-size';
setDefaultSizeFormat(SIZE_FORMAT.IEC);
let input = 10120;
let output = humanReadableSize(input);
console.log(output); // prints '10.12 KiB'Machine-readable usage:
import { machineReadableSize, SIZE_FORMAT } from 'node-size';
let input = "1 MiB";
let output = size.machineReadableSize(input, SIZE_FORMAT.IEC);
console.log(output); // prints '10000000' (number)Available values for SIZE_FORMAT:
- SI - divides/multiplies by 1024
- JEDEC - same as SI
- IEC - divides/multiplies by 1000