Skip to content

Format Byte

Overview

FormatByte converts raw byte values into human-readable strings with appropriate unit suffixes (B, KB, MB, GB, TB, PB). Uses SI decimal prefixes (powers of 1000) by default.

Usage

import { formatByte } from "@paramanu/utilities-js"
formatByte(1500) // => "1.5 KB"
formatByte(1500000000) // => "1.5 GB"
formatByte(1000, { unit: "bit" }) // => "8 Kb"

Guidelines

  • Use for displaying file sizes, upload limits, and storage quotas
  • Set unit="bit" for network bandwidth display
  • The locale affects decimal separator formatting
  • Renders as a <span> by default; use the as prop to change the element

API

PropTypeDefaultDescription
valuenumber-The byte value to format
localestring"en-US"BCP 47 language tag
decimalsnumber2Maximum decimal places
unit"byte" | "bit""byte"Output unit system
asElementType"span"HTML element to render