Skip to content

sarike/readable-bytes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

readable-bytes

Build Status

A simple useful util to convert bytes value to pretty string with proper unit.

Install

Install with npm:

npm install readable-bytes --save

or with yarn:

yarn add readable-bytes

Usage

import readableBytes from 'readable-bytes'

// base 10
readableBytes(1000) // 1 KB
readableBytes(1000 * 1000) // 1 MB

parseBytes(1000 * 1000) // { value: 1, unit: 'MB' }

// base 2
readableBytes(1024, 2) // 1KiB
readableBytes(1024 * 1024, 2) // 1MiB

The result will only keep two decimal places.

readableBytes(1001) // 1 KB
readableBytes(1060) // 1.06 KB
readableBytes(1069) // 1.07 KB

About

Convert bytes to pretty string with proper unit

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •