Simplifies bytes to a human-readable size string.
$ npm i -save simplify-bytes
or
$ yarn add simplify-bytes
import { simplifyBytes, simplifyBiBytes } from 'simplify-bytes';
simplifyBytes(200); // '200B'
simplifyBytes(2048); // '2.048KB'
simplifyBytes(20480); // '20.48KB'
simplifyBiBytes(200); // '200B'
simplifyBiBytes(2048); // '2KiB'
simplifyBiBytes(20480); // '20KiB'
Type: number
Number to format.
Type: number
| object
Optional settings.
-
If
number
: Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.simplifyBytes(2048, 1); // '2.0KB' simplifyBytes(2048, 2); // '2.05KB'
-
If
object
:
binary
Type:boolean
Default:false
Format the value using the binary-prefix or si-prefix.\- If
false
: Using the si-prefix (base 1000). - If
true
: Using the binary-prefix (base 1024).
simplifyBytes(2048, {binary: true}); // '2KiB', same as using: simplifyBiBytes(2048).
decimals
Type:number
Number of digits after the decimal point. Must be in the range 0 - 20, inclusive.simplifyBytes(2048, {decimals: 2}); // '2.05KB', same as using: simplifyBytes(2048, 2).
separator
Type:string
Character between the number and unit.simplifyBytes(2048, {separator: ' '}); // '2.048 KB'
- If
Format the value using the binary-prefix.
Type: number
Number to format.
Type: number
| object
Optional settings. The arguments are the same as the 'simplifyBytes' method, except that 'binary' is true.