Format Byte
A utility component for displaying file sizes in a human-readable format. Automatically converts bytes to appropriate units (KB, MB, GB, TB) and supports multiple display formats and locales.
Anatomy
<script>
import { FormatByte } from "@saas-ui/svelte/utilities/format-byte";
</script>
<!-- Basic usage -->
<FormatByte value={1024} />
<!-- With unit type -->
<FormatByte value={1024} unit="bit" />
<!-- With custom locale -->
<FormatByte value={1024} locale="de-DE" />
<!-- With unit display format -->
<FormatByte value={1024} unitDisplay="long" />Examples
Basic Accessibility
<Text size="lg">
File size: <FormatByte {value} {unit} {unitDisplay} {locale} />
</Text> Format Bits Accessibility
unit prop set to bit to display values in bit units (bit, kbit, Mbit, Gbit, Tbit).
<Text size="lg">
File size: <FormatByte value={1450.45} unit="bit" />
</Text> Locale Accessibility
locale prop to format numbers according to different regional conventions.
<Stack>
<HStack>
<Text size="md" weight="medium" class="w-16">de-DE</Text>
<LocaleProvider locale="de-DE">
<Text size="lg">
<FormatByte value={1450.45} />
</Text>
</LocaleProvider>
</HStack>
<HStack>
<Text size="md" weight="medium" class="w-16">zh-CN</Text>
<LocaleProvider locale="zh-CN">
<Text size="lg">
<FormatByte value={1450.45} />
</Text>
</LocaleProvider>
</HStack>
</Stack> Sizes Accessibility
<Stack>
<Text size="lg">
<FormatByte value={50} />
</Text>
<Text size="lg">
<FormatByte value={5000} />
</Text>
<Text size="lg">
<FormatByte value={5000000} />
</Text>
<Text size="lg">
<FormatByte value={5000000000} />
</Text>
</Stack> Unit Display Accessibility
unitDisplay prop to control unit format: short (kB), narrow (kB without space), or long (kilobytes).
<Stack>
<Text size="lg">
<FormatByte value={50345.53} unitDisplay="narrow" />
</Text>
<Text size="lg">
<FormatByte value={50345.53} unitDisplay="short" />
</Text>
<Text size="lg">
<FormatByte value={50345.53} unitDisplay="long" />
</Text>
</Stack>Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | - | The byte size to format. |
unit | byte | bit | byte | The unit granularity to display. |
unitDisplay | long | short | narrow | short | The unit display format. |
locale | text | - | The locale to use for formatting. If not provided, uses the locale from LocaleProvider context. |