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 10

bits (boolean)
Enables bit sizes, default is false

exponent (number)
Specifies the symbol via exponent, e.g. 2 is MiB 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 []

locale (string || boolean)
BCP 47 language tag to specify a locale, or `true` to use default locale, default is ""

localeOptions (object: overrides 'separator', requires string for 'locale' option)
Dictionary of options defined by ECMA-402 (Number.prototype.toLocaleString). Requires locale option to be explicitly passed as a string, otherwise is ignored.

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

pad (boolean)
Decimal place end padding, default is false

precision (number)
Sets precision of numerical output, default is 0

round (number)
Decimal place, default is 2

roundingMethod (string)
Rounding method, can be "round", "floor", or "ceil"; default is "round"

separator (string)
Decimal separator character, default is "."

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

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

symbols (object)
Dictionary of IEC/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