@heyhru/common-util-format
v0.2.2
Published
Shared formatting utilities for numbers, time, and phone numbers
Readme
@heyhru/common-util-format
Shared formatting utilities for numbers, time, and phone numbers. Works on both server and client.
Install
pnpm add @heyhru/common-util-formatAPI
Number
| Function | Description |
|---|---|
| formatNumber(num, decimals?) | Smart decimal formatting with trailing-zero removal |
| formatReward(reward) | Parse reward string (may include $) |
| formatTime(mins) | Minutes to short string ("5m") |
| formatAmount(amount) | USD formatting ("$10.00") |
Time
| Function | Description |
|---|---|
| normalizeTimestamp(ts) | Auto-detect seconds vs milliseconds |
| formatSecondsToHHMMSS(s) | "01:01:01" |
| formatSecondsToMMSS(s) | "02:05" |
| formatDateToHHMMSS(date) | "14:30:05" |
| formatTimestamp(ts) | "2024-01-01 00:00:00" |
| getCurrentTimeHHMMSS() | Current time as HH:MM:SS |
| formatDuration(s) | "1h 30min 5s" |
| formatDateToAMPM(date) | "2:30 PM" |
| getCurrentTime() | Current time as h:mm AM/PM |
| formatUnixToHHMM(ts) | Unix seconds to "14:30" |
Phone
| Function | Description |
|---|---|
| formatUsPhone(input) | "(123) 456-7890" |
| parseUsPhone(raw) | Strip +1 prefix |
| US_PHONE_FORMATTED_LENGTH | 14 |
