Data/File Size Formatting & Parsing Library – Bytes.js

Category: Javascript | June 21, 2024
Views Total:0 views
Official Page:Go to website
Last Update:June 21, 2024


Data/File Size Formatting & Parsing Library – Bytes.js


Bytes.js is a tiny utility library that converts raw byte values into user-friendly formats like “100 KB” or “50 MB”, and vice versa.

It can be useful when you need to display file sizes, data usage, or any other byte-related information in a human-readable format.

How to use it:

1. Install and import the Bytes.js with NPM.

$ npm install @boywithkeyboard/bytes
import { bytes } from '@boywithkeyboard/bytes'

2. The bytes() function is the core of this library. It takes a number or a string as an argument and returns a formatted size string or an array, depending on your preferences. For example, bytes(25000) will output 25 KB, while bytes('50 MB') will return 50000000.

// 50 MB
// 50 Megabytes
bytes(50000000, { 
  long: true 
// 50*1000*1000
bytes('50 Megabytes');


v6.0.1 (06/21/2024)

  • fix realease

v6.0.0 (05/16/2024)

  • A rewrite of bytes with an even smaller package size and optimized parsing.

v5.0.0 (03/21/2024)

  • This package is now pure ESM.

You Might Be Interested In:

Leave a Reply