1.0.3 • Published 5 months ago

simple-file-size-formatter v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

File Size Formatter

A simple utility to format file sizes into human-readable formats (e.g., 1024 bytes1 KB). Lightweight and dependency-free.

Features

  • Multiple Units: Supports Bytes, KB, MB, GB, etc.
  • Custom Precision: Customize the number of decimals.
  • Zero Dependencies: No extra libraries required.

Installation

Install via npm:

npm install simple-file-size-formatter

Usage

Import the function and use it in your project:

import { formatFileSize } from 'simple-file-size-formatter';

const sizeInBytes = 1024;
console.log(formatFileSize(sizeInBytes)); // Output: "1 KB"

Customize the decimal precision:

const sizeInBytes = 1234567;
console.log(formatFileSize(sizeInBytes, 3)); // Output: "1.177 MB"

API

formatFileSize(bytes: number, decimalPrecision?: number): string

  • bytes: File size in bytes.
  • decimalPrecision: (Optional) Number of decimals (default is 2).

Returns a formatted string with the appropriate unit.

License

Licensed under the MIT License.

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago