数値・時間フォーマット
金額・パーセンテージ・相対時間のフォーマットユーティリティ。
|
import { formatYen, formatPercentage, formatRelativeTime } from "@blueai/ui"Examples
formatYen
formatYen(1500)1,500円
formatYen(1234567)1,234,567円
formatYen(0)0円
formatYen(null)-
formatYen(1500) // → "1,500円"
formatYen(1234567) // → "1,234,567円"
formatYen(0) // → "0円"
formatYen(null) // → "-"formatPercentage
formatPercentage(25, 100)25.0%
formatPercentage(1, 3)33.3%
formatPercentage(0, 0)-
formatPercentage(7, 10, 0)70%
formatPercentage(1, 3, 2)33.33%
formatPercentage(25, 100) // → "25.0%"
formatPercentage(1, 3) // → "33.3%"
formatPercentage(0, 0) // → "-"
formatPercentage(7, 10, 0) // → "70%"
formatPercentage(1, 3, 2) // → "33.33%"formatRelativeTime
今たった今
5分前5分前
3時間前3時間前
2日前2日前
null-
formatRelativeTime(new Date()) // → "たった今"
formatRelativeTime(fiveMinAgo) // → "5分前"
formatRelativeTime(threeHoursAgo) // → "3時間前"
formatRelativeTime(twoDaysAgo) // → "2日前"
formatRelativeTime(null) // → "-"Props
| Prop | Type | Default | Description |
|---|---|---|---|
| formatYen(value)* | (number | null | undefined) => string | — | 数値を「1,234円」形式に変換。null/undefined → "-" |
| formatPercentage(n, d, decimals?)* | (number, number, number?) => string | — | 割合を「12.3%」形式に変換。分母が0 → "-"。decimals デフォルト1 |
| formatRelativeTime(date)* | (string | Date | null) => string | — | 日時を相対表示("たった今" / "N分前" / "N時間前" / "N日前")。30日以上前は YYYY/MM/DD |