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

@boywithkeyboard/bytes

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@boywithkeyboard/bytes

A disk unit conversion library for JavaScript.

latest
Source
npmnpm
Version
6.0.1
Version published
Maintainers
0
Created
Source

bytes

Setup

Node.js

npm i @boywithkeyboard/bytes
import { bytes } from '@boywithkeyboard/bytes'

Deno

import { bytes } from 'https://esm.sh/@boywithkeyboard/bytes'

Usage

/*
 * Convert bytes to a readable size.
 */

bytes(100) // '100 B'
bytes(25000) // '25 KB'
bytes(50000000) // '50 MB'
bytes(1000000000000) // '1 TB'

bytes(100, { fmt: 'long' }) // '100 Bytes'
bytes(25000, { fmt: 'long' }) // '25 Kilobytes'
bytes(50000000, { fmt: 'long' }) // '50 Megabytes'
bytes(1000000000000, { fmt: 'long' }) // '1 Terabyte'

// Binary

bytes(25 * 1024, { unit: 'binary' }) // '25 KiB'
bytes(25 * 1024, { fmt: 'long', unit: 'binary' }) // '25 Kibibytes'

/*
 * Convert a readable size to bytes.
 */

bytes('100 B') // 100
bytes('25 KB') // 25*1000
bytes('50 MB') // 50*1000*1000
bytes('1 TB') // 1000*1000*1000*1000

bytes('100 Bytes') // 100
bytes('25 Kilobytes') // 25*1000*1000
bytes('50 Megabytes') // 50*1000*1000
bytes('1 Terabyte') // 1000*1000*1000*1000

// Binary

bytes('25 Kibibytes') // 25*1024
bytes('50 Mebibytes') // 50*1024*1024
bytes('1 Tebibyte') // 1*1024*1024*1024

Keywords

bytes

FAQs

Package last updated on 21 Jun 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