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
npm install filesizeformatter
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.
``bash`
npm install filesizeformatter
javascript
const { fileSizeFormat } = require('filesizeformatter');const exampleSize: number = 2048;
fileSizeFormat(exampleSize, false).then(result => {
console.log(result);
});
`$3
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
`javascript
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:
1. Fork the repository.
2. Create a new branch for your feature or bug fix: git checkout -b feature/your-feature-name.
3. Commit your changes: git commit -m "Add your feature or fix".
4. Push your branch to your fork: git push origin feature/your-feature-name.`Please follow the Code of Conduct and Contributing Guidelines when contributing.
