filesizeformatter
v1.0.1
Published
A versatile and lightweight utility to format file sizes, providing both human-readable and customizable representations. This library supports various size units, including bits, bytes, kilobytes (KB), kibibytes (KiB), megabytes (MB), mebibytes (MiB), an
Downloads
15
Maintainers
Readme
filesizeformatter
Description
filesizeformatter
is a lightweight and simple-to-use Node.js package to format file sizes. It provides a function to convert file sizes from bytes to human-readable units like kilobytes, megabytes, gigabytes, etc.
Installation
npm install filesizeformatter
Usage
const { fileSizeFormat } = require('filesizeformatter');
const exampleSize: number = 2048;
fileSizeFormat(exampleSize, false).then(result => {
console.log(result);
});
Options
size
: The file size in bytes.
useBinaryUnits
: (Optional) If set to true
, uses binary units (e.g., KiB, MiB) instead of decimal units (e.g., KB, MB). Default is false
.
Example
const { fileSizeFormat } = require('filesizeformatter');
const fileSize = 1024;
const exampleSize: number = 2048;
fileSizeFormat(exampleSize, false).then(result => {
console.log(result);
});
// Output: "2.00 KB"
Contributing
Contributions to filesizeformatter
are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch for your feature or bug fix:
git checkout -b feature/your-feature-name.
- Commit your changes:
git commit -m "Add your feature or fix".
- Push your branch to your fork:
git push origin feature/your-feature-name.
- Create a pull request on the original repository.
Please follow the Code of Conduct and Contributing Guidelines when contributing.