Skip to content

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), and beyond. Users can choose between binary and decimal units for flexibility.

ishan-18/filesizeformatter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

filesizeformatter

npm version

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:

  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.
  5. Create a pull request on the original repository.

Please follow the Code of Conduct and Contributing Guidelines when contributing.

Buy Me A Coffee

About

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), and beyond. Users can choose between binary and decimal units for flexibility.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published