file-size-pretty
v1.2.0
Published
Convert file sizes like 34892823 into human-readable formats like 33.2 MB.
Maintainers
Readme
# file-size-pretty
Convert file sizes in bytes into human-readable strings — like `117.7 MB` or `1.5 GB`.
## Features
- Converts raw byte sizes into KB, MB, GB, etc.
- Lightweight and dependency-free
- Supports decimal precision
- Works in Node.js and browser environments
## Installation
npm install file-size-pretty
## Usage
```js
const fileSizePretty = require('file-size-pretty');
console.log(fileSizePretty(1000)); // "1000 B"
console.log(fileSizePretty(1024)); // "1 KB" (default: binary)
console.log(fileSizePretty(1000, 1, { standard: 'si' })); // "1 kB"
console.log(fileSizePretty(1000000, 2, { standard: 'si' })); // "1 MB"
import fileSizePretty from 'file-size-pretty'
console.log(fileSizePretty(9999999)) //simple testing
API
fileSizePretty(bytes, decimals = 1)
| Parameter | Type | Description |
|-----------|--------|----------------------------------------|
| bytes | number | File size in bytes |
| decimals| number | Number of decimal places (default: 1)|
Returns
A human-readable string with the appropriate size unit.
Example Output
| Input Bytes | Output |
|------------------|-------------|
| 0 | "0 B" |
| 500 | "500 B" |
| 1048576 | "1 MB" |
| 1073741824 | "1 GB" |
| 1099511627776 | "1 TB" |
License
MIT
Made with ❤️ by Ruman Ahmed
# file-size-pretty