filesize.js
filesize.js is a nano(350 b) library to make file size bytes human-readable. e.g. 20.4 Kb.
Install
npm install filesize.js
Usage
The unique API is: fileSize(bytes[, fixed=1, spec='jedec']);.
bytes
: Number of file size bytes.fixed
: Number of decimal, default is1
.spec
: String of file size spec, default isjedec
.
// bytes.; // '120.6 Kb' // fixed, `1` is default.; // '121 Kb'; // '1120.5625 Kb' // specs, `jedec` / `iec / si`.// `jedec` is default.; // '120.56 Kib'; // '123 kb'
Test
npm install
npm test
Spec
- jedec: Unit is
['b', 'Kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb']
, and the power is 1024. - iec: Unit is
['b', 'Kib', 'Mib', 'Gib', 'Tib', 'Pib', 'Eib', 'Zib', 'Yib']
, and the power is 1024. - si: Unit is
['b', 'kb', 'Mb', 'Gb', 'Tb', 'Pb', 'Eb', 'Zb', 'Yb']
, and the power is 1000.
More specs waiting for your issues / pull requests.
LICENSE
MIT@hustcc.