filesize
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Filesize.js is a handy JavaScript library that provides a convenient way to obtain a human-readable string representing a file size from a number (which could be a float or an integer) or string. It offers a simple way to transform raw size data into a presentation that is comfortable and intuitive for human users to understand.
Using the filesize
library in your project is straightforward. First, you need to import the filesize
function from the library. The function can be used to convert a number, which represents a file size in bytes, into a human-readable string. For example, you can convert the byte value 265318
into the string "259.1 KB"
with the specific standard jedec
:
import {filesize} from "filesize";
filesize(265318, {standard: "jedec"}); // Output: "259.1 KB"
The library also supports various configuration options allowing you to customize the output according to your needs. For instance, you can set the base to 2, enable bit sizes, specify the symbol via exponent, activate full form of the measure unit, enable decimal end padding, and plenty more.
The library also provides a partial()
function which accepts a configuration object and returns a new function that applies this configuration upon call. This might be useful for reducing object creation in your code.
import {partial} from "filesize";
const size = partial({standard: "jedec"});
size(265318); // Output: "259.1 KB"
If you wish to delve deeper into the filesize
library's functionality or need more specific details about the configuration options and their defaults, refer to the library's README file on its GitHub page filesize. There is no separate dedicated documentation, as the README itself is comprehensive and includes all necessary details to use the library effectively.