New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details
Socket
Book a DemoSign in
Socket

simplify-bytes

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

simplify-bytes

Simplifies bytes to a human-readable size string

latest
npmnpm
Version
0.0.1
Version published
Weekly downloads
3
50%
Maintainers
1
Weekly downloads
 
Created
Source

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.

Keywords

simplify

FAQs

Package last updated on 07 Mar 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts