🚀 DAY 5 OF LAUNCH WEEK:Introducing Webhook Events for Alert Changes.Learn more →
Socket
Book a DemoInstallSign in
Socket

byte-size

Package Overview
Dependencies
Maintainers
1
Versions
24
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

byte-size

Convert a bytes (and octets) value to a more human-readable format. Choose between metric or IEC units.

Source
npmnpm
Version
4.0.3
Version published
Maintainers
1
Created
Source

view on npm npm module downloads Build Status Coverage Status Dependency Status js-standard-style

byte-size

Convert a bytes value to a more human-readable format. Choose between metric or IEC units, summarised below.

ValueMetric
1000kB kilobyte
1000^2MB megabyte
1000^3GB gigabyte
1000^4TB terabyte
1000^5PB petabyte
1000^6EB exabyte
1000^7ZB zettabyte
1000^8YB yottabyte
ValueIEC
1024KiB kibibyte
1024^2MiB mebibyte
1024^3GiB gibibyte
1024^4TiB tebibyte
1024^5PiB pebibyte
1024^6EiB exbibyte
1024^7ZiB zebibyte
1024^8YiB yobibyte
ValueMetric (octet)
1000ko kilooctet
1000^2Mo megaoctet
1000^3Go gigaoctet
1000^4To teraoctet
1000^5Po petaoctet
1000^6Eo exaoctet
1000^7Zo zettaoctet
1000^8Yo yottaoctet
ValueIEC (octet)
1024Kio kilooctet
1024^2Mio mebioctet
1024^3Gio gibioctet
1024^4Tio tebioctet
1024^5Pio pebioctet
1024^6Eio exbioctet
1024^7Zio zebioctet
1024^8Yio yobioctet

Example

const byteSize = require('byte-size')

byteSize(bytes, [options]) ⇒ Object ⏏

Kind: Exported function

ParamTypeDefaultDescription
bytesnumberthe bytes value to convert.
[options]objectoptional config.
[options.precision]number1number of decimal places.
[options.units]string"metric"select 'metric', 'iec', 'metric_octet' or 'iec_octet' units.

Example

> const byteSize = require('byte-size')

> byteSize(1580)
{ value: '1.6', unit: 'kB' }

> byteSize(1580, { units: 'iec' })
{ value: '1.5', unit: 'KiB' }

> byteSize(1580, { units: 'iec', precision: 3 })
{ value: '1.543', unit: 'KiB' }

> byteSize(1580, { units: 'iec', precision: 0 })
{ value: '2', unit: 'KiB' }

> byteSize(1580, { units: 'metric_octet' })
{ value: '1.6', unit: 'ko' }

> byteSize(1580, { units: 'iec_octet' })
{ value: '1.5', unit: 'Kio' }

> byteSize(1580, { units: 'iec_octet' }).toString()
'1.5 Kio'

> const { value, unit }  = byteSize(1580, { units: 'iec_octet' })
> `${value} ${unit}`
'1.5 Kio'

© 2014-18 Lloyd Brookes <75pound@gmail.com>. Documented by jsdoc-to-markdown.

Keywords

convert

FAQs

Package last updated on 12 May 2018

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