Fidely UI v1 beta is now available!. 🚀

Formats

Utilities to format bytes, numbers, and relative time into human-readable strings.

Usage

The @fidely-ui/react package provides simple formatters to make displaying data more readable — such as converting file sizes, numeric values, and timestamps.

import { FormatBytes, FormatNumber, FormatRelativeTime } from '@fidely-ui/react'

Examples

Bytes

Use the FormatBytes component to convert raw byte values into human-readable formats.

50 byte

500 byte

50 kB

50 MB

1.45 kb

Numbers

Use the FormatNumber component to format numeric values based on locale and precision.

1,450.45

Relative Time

Use the FormatRelativeTime component to display dates as relative time (e.g., “3 minutes ago”, “yesterday”).

Edited 4 weeks ago

1 minute ago

1 hour ago

1 day ago

1 week ago

1 month ago

1 year ago

Props

FormatBytes

PropTypeDefaultDescription
valuenumber—The raw byte value to format.
unit`"bit" | "bytes""bytes"The base unit to start formatting from.

FormatNumber

PropTypeDefaultDescription
valuenumber—The numeric value to format.
stylestring-The style of the format.
unitkilometer | etc...-The unit value to display.
notation"standard" | "compact" | "scientific""standard"Controls how numbers are displayed (e.g., 1K, 1.2e+3).
minimumFractionDigitsnumber0Minimum number of decimal places to show.
maximumFractionDigitsnumber2Maximum number of decimal places to show.

FormatRelativeTime

PropTypeDefaultDescription
valueDate | string | number—The date or timestamp to format relative to now.
numeric"always" | "auto""auto"Whether to always show numeric values (3 days ago) or relative terms (yesterday).

On this page