readable-size
Converts bytes into human readable size units: B, KB, MB, GB, TB, PB, EB, ZB, YB.
Installation
npm install --save readable-size
Examples
; // '1 B'; // '1023 B'; // '1.00 KB'; // '1.00 KB'; // '976 KB'; // '999 KB'; // '0.97 MB'; // '0.99 MB'; // '1.00 MB'; // '1.00 MB'; // '953 MB'; // '999 MB'; // '0.97 GB'; // '0.99 GB'; // '1.00 TB'
Output
The output is one of 'string'
, 'array'
, 'object'
, or function type.
'string'
; // '1.00 KB'; // '1.00 (KB)'
'array'
; // [ '1.00', 'KB' ]
'object'
; // { size: '1.00', unit: 'KB' }
function
;
Separators
English
const options = separator: thousands: ',' decimal: '.' ;; // '999 B'; // '1,000 B'; // '1.00 KB'
French
const options = separator: thousands: ' ' decimal: ',' ;; // '999 B'; // '1 000 B'; // '1,00 KB'
Dutch
const options = separator: thousands: '.' decimal: ',' ;; // '999 B'; // '1.000 B'; // '1,00 KB'
Options
separator
(boolean) Enable separators, default is false
(object) Specifies the thousands and decimal separators, default is:
separator: thousands: ',' decimal: '.'
output
('string') The output is defined by the format string, default is '{{size}} {{unit}}'
('array') The output is [size, unit]
('object') The output is { size, unit }
(function) A user-defined output function:
{ unit = 'B': 'bytes' unit || unit; return ` `;}
format
(string) The format string, default is '{{size}} {{unit}}'
License
MIT