filesize.js

Try it!

Show `bit` sizes Unix mode (base 2)

 

Download

Latest version is available from Content Delivery Network

What does it do?

filesize.js is a tiny JavaScript library that creates a Global function named filesize().

It provides an easy way to get a human readable file size String.

How do I use it?

filesize.js can be loaded from npm, as an AMD module, or as a regular script.

filesize() accepts an optional descriptor Object as a second argument, so you can customize the output.

Optional settings

base (number)
Number base, default is 2

bits (boolean)
Enables bit sizes, default is false

exponent (number)
Specifies the SI suffix via exponent, e.g. 2 is MB for bytes, default is -1

fullform (boolean)
Enables full form of unit of measure, default is false

fullforms (array)
Array of full form overrides, default is []

output (string)
Output of function (array, exponent, object, or string), default is string

round (number)
Decimal place, default is 2

spacer (string)
Character between the result and suffix, default is " "

standard (string)
Standard unit of measure, can be "iec" or "jedec", default is "jedec"; can be overruled by "base"

symbols (object)
Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found

suffixes (object)
Deprecated: use 'symbols'
Dictionary of SI/JEDEC symbols to replace for localization, defaults to english if no match is found

unix (boolean)
Enables unix style human readable output, e.g ls -lh, default is false

Examples

Fork me on GitHub