Skip to content

Kemichal/format-byte

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Build Status

Format Byte

NodeJS module for converting and formating strings of bytes.

Usage

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 MiB

Functions

toBinary(input, [decimals])

Arguments

  • 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 KiB

toDecimal(input, [decimals])

Arguments

  • 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 KB

toBytes(input)

Arguments

  • input - Bytes as a string.

Examples

console.log(fb.toBytes('1KiB'));
// 1024

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published