@azury/byte
TypeScript icon, indicating that this package has built-in type declarations

3.3.0 • Public • Published

byte

Setup

Deno

import byte from 'https://deno.land/x/byte@v3.3.0/byte.ts'

Node.js

npm i @azury/byte
// ESM
import byte from '@azury/byte'

// CommonJS
const byte = require('@azury/byte')

Browser

<script src="https://cdn.jsdelivr.net/npm/@azury/byte@3.3.0"></script>

Usage

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

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

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

byte(100, { format: 'array' }) // [100, 'B']
byte(25000, { format: 'array' }) // [25, 'KB']
byte(50000000, { long: true, format: 'array' }) // [50, 'Megabytes']
byte(1000000000000, { long: true, format: 'array' }) // [1, 'Terabyte']

// binary prefix

byte(25 * 1024, { prefix: 'binary' }) // '25 KiB'
byte(25 * 1024, { long: true, prefix: 'binary' }) // '25 Kibibytes'

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

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

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

// binary prefix

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

Configuration

  • long
  • format - string | array
  • prefix - binary | metric

Readme

Keywords

none

Package Sidebar

Install

npm i @azury/byte

Weekly Downloads

1

Version

3.3.0

License

Apache-2.0

Unpacked Size

19.3 kB

Total Files

7

Last publish

Collaborators

  • boywithkeyboard