
Product
Introducing Webhook Events for Alert Changes
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.
Convert a bytes (and octets) value to a more human-readable format. Choose between metric or IEC units.
Convert a bytes value to a more human-readable format. Choose between metric or IEC units, summarised below.
| Value | Metric |
|---|---|
| 1000 | kB kilobyte |
| 1000^2 | MB megabyte |
| 1000^3 | GB gigabyte |
| 1000^4 | TB terabyte |
| 1000^5 | PB petabyte |
| 1000^6 | EB exabyte |
| 1000^7 | ZB zettabyte |
| 1000^8 | YB yottabyte |
| Value | IEC |
|---|---|
| 1024 | KiB kibibyte |
| 1024^2 | MiB mebibyte |
| 1024^3 | GiB gibibyte |
| 1024^4 | TiB tebibyte |
| 1024^5 | PiB pebibyte |
| 1024^6 | EiB exbibyte |
| 1024^7 | ZiB zebibyte |
| 1024^8 | YiB yobibyte |
| Value | Metric (octet) |
|---|---|
| 1000 | ko kilooctet |
| 1000^2 | Mo megaoctet |
| 1000^3 | Go gigaoctet |
| 1000^4 | To teraoctet |
| 1000^5 | Po petaoctet |
| 1000^6 | Eo exaoctet |
| 1000^7 | Zo zettaoctet |
| 1000^8 | Yo yottaoctet |
| Value | IEC (octet) |
|---|---|
| 1024 | Kio kilooctet |
| 1024^2 | Mio mebioctet |
| 1024^3 | Gio gibioctet |
| 1024^4 | Tio tebioctet |
| 1024^5 | Pio pebioctet |
| 1024^6 | Eio exbioctet |
| 1024^7 | Zio zebioctet |
| 1024^8 | Yio yobioctet |
Example
const byteSize = require('byte-size')
Object ⏏Kind: Exported function
| Param | Type | Default | Description |
|---|---|---|---|
| bytes | number | the bytes value to convert. | |
| [options] | object | optional config. | |
| [options.precision] | number | 1 | number 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.
The filesize package is another utility for converting bytes into human-readable strings. It offers more customization options compared to byte-size, such as different rounding methods and support for various notations (e.g., binary, decimal).
The pretty-bytes package is a lightweight utility for converting bytes to a human-readable string. It is simpler and more straightforward than byte-size, focusing on ease of use and minimal configuration.
The bytes package provides utilities for parsing and formatting byte values. It is more versatile than byte-size, offering both conversion to human-readable strings and parsing from strings back to byte values.
FAQs
Convert a bytes or octets value (e.g. 34565346) to a human-readable string ('34.6 MB'). Choose between metric or IEC units.
We found that byte-size demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Product
Add real-time Socket webhook events to your workflows to automatically receive software supply chain alert changes in real time.

Security News
ENISA has become a CVE Program Root, giving the EU a central authority for coordinating vulnerability reporting, disclosure, and cross-border response.

Product
Socket now scans OpenVSX extensions, giving teams early detection of risky behaviors, hidden capabilities, and supply chain threats in developer tools.