0.0.1 • Published 1 year ago

simplify-bytes v0.0.1

Weekly downloads
-
License
MIT
Repository
-
Last release
1 year ago

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.

0.0.1

1 year ago