1.0.2 • Published 8 months ago

convert-bytes v1.0.2

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

convert-bytes

A simple utility to convert bytes to human-readable file sizes.

Installation

You can install this package using npm or yarn:

npm install convert-bytes

Usage

Here's how you can use the convertBytes function in your JavaScript code:

// Import the function (ES6 modules)
import convertBytes from 'convert-bytes';

// Or require it (CommonJS)
// const convertBytes = require('convert-bytes');

// Use the function
const fileSize = convertBytes(1024); // 1.00 KB

The convertBytes function takes two arguments: bytes (the size in bytes you want to convert) and precision (optional, the number of decimal places to round the result to).

Example

import convertBytes from 'convert-bytes';

const fileSize1 = convertBytes(1024); // 1.00 KB
const fileSize2 = convertBytes(1024 * 1024 * 5, 3); // 5.000 MB

License

This package is released under the MIT License.