convertFileSize

A utility function to convert file sizes from bytes to a human-readable format (KB, MB, GB).
> convertFileSize(sizeInBytes: number, decimalPlaces: number = 1): string
Parameters
  • sizeInBytes: The size in bytes to be converted.
  • decimalPlaces: The number of decimal places to include in the converted size, default: 1. Useful for displaying a rounded value.
  • Returns: A string that represents the file size in the appropriate unit (Bytes, KB, MB, GB).

Example

import { convertFileSize } from "@explita/daily-toolset";

console.log(convertFileSize(500));            // "500 Bytes"
console.log(convertFileSize(2048));           // "2.0 KB"
console.log(convertFileSize(1048576));        // "1.0 MB"
console.log(convertFileSize(1073741824, 2));  // "1.00 GB"