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.
npm install filesizeformatter
const { fileSizeFormat } = require('filesizeformatter');
const exampleSize: number = 2048;
fileSizeFormat(exampleSize, false).then(result => {
console.log(result);
});
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
.
const { fileSizeFormat } = require('filesizeformatter');
const fileSize = 1024;
const exampleSize: number = 2048;
fileSizeFormat(exampleSize, false).then(result => {
console.log(result);
});
// Output: "2.00 KB"
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.