NodeJS module for converting and formating strings of bytes.
Format Byte isn't published to NPM. Add the following as a dependency in package.json
"format-byte": "Kemichal/format-byte"and then do npm install.
Require like a normal NodeJS module.
var fb = require('format-byte');Examples
// Print 3 terabyte as tebibytes, 2 decimals (default).
console.log(fb.toBinary('3TB'));
// 2.73 TiB
// Print 3 million bytes as mebibytes, one decimal.
console.log(fb.toBinary('3000000B', 1));
// 2.9 MiBArguments
input- Bytes as a string.decimals- Number of decimal points.
Examples
console.log(fb.toBinary('1024B'));
// 1.00 KiB
console.log(fb.toBinary('1024', 0));
// 1 KiBArguments
input- Bytes as a string.decimals- Number of decimal points.
Examples
console.log(fb.toBinary('1000B'));
// 1.00 KB
console.log(fb.toBinary('1000', 0));
// 1 KBArguments
input- Bytes as a string.
Examples
console.log(fb.toBytes('1KiB'));
// 1024