simplify-bytes

0.0.1 • Public • Published

simplify-bytes

Simplifies bytes to a human-readable size string.

Installation

$ npm i -save simplify-bytes

or

$ yarn add simplify-bytes

Quick Start

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'

Methods

simplifyBytes(value, options?)

value

Type: number
Number to format.

options

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'

simplifyBiBytes(value, options?)

Format the value using the binary-prefix.

value

Type: number
Number to format.

options

Type: number | object
Optional settings. The arguments are the same as the 'simplifyBytes' method, except that 'binary' is true.

Package Sidebar

Install

npm i simplify-bytes

Weekly Downloads

2

Version

0.0.1

License

MIT

Unpacked Size

5.58 kB

Total Files

4

Last publish

Collaborators

  • haoqichan