
Forge UI 和 FI 应用程序的纯格式化器——将线条值转换为人可读的 UI 字符串
(和日期线标识的倒置). 无反应依赖.
样式与 @candescent/ui-formatters (在软件包根上显示帮助者;在下面显示日期帮助者)
dates/) (中文(简体) ). 优先进口 @cdx-ui/formatters 仅 - 不导入 date-fns 或者说 Intl
包件的内部包装.
电线对显示( 日期)
| 代表权 | 示例 | 用于 |
线 DateId 编号 : MonthId 编号 : DateTimeId | '2026-07-28' | 表格状态、 API 、 拾取器 |
| 显示 字符串 | '7/28/26' 编号 : '28/07/2026' | 标签、信头——永远不存储 |
出口
下表是有代表性的进口指南,并非详尽无遗的清单 src/index.ts (再出口) dates/index.ts)是权威导出表面.
| 导入 | 目的 |
formatNumber | 地方小数格式化(已刻出) Intl.NumberFormat(中文(简体) ) |
日期线
| 导入 | 目的 |
parseDateId 编号 : formatDateId 编号 : isValidDateId | YYYY-MM-DD 往返 |
parseMonthId 编号 : formatMonthId 编号 : isValidMonthId | YYYY-MM-01 月编号 |
parseDateTimeId 编号 : formatDateTimeId 编号 : isValidDateTimeId | 当地 YYYY-MM-DDTHH:mm |
todayDateId 编号 : todayMonthId 编号 : nowDateTimeId | 设备本地“ 现在” |
toMonthId 编号 : clampDateParts 编号 : clampMonthParts | 转换/夹住 |
显示日期
| 导入 | 目的 |
formatDateForDisplay | 语言 dateStyle 短/中/长 |
formatMonthForDisplay | 月加年标签 |
formatDateTimeForDisplay | 日期+时间标签 |
formatDateRangeForDisplay | 包含范围标签 |
区域( C)
| 导入 | 目的 |
normalizeDateRange 编号 : compareDateIds 编号 : eachDateIdInRange | 范围数学 |
dateRangeFromLastNDays 编号 : dateRangeAroundDay | 预设 |
getDateFieldSegments 编号 : getDateTimeFieldSegments | 分块字段元数据 |
parseDateSegment 编号 : formatDateSegment 编号 : applyDateSegmentChange | 片段编辑 |
日历/ 列表副本
| 导入 | 目的 |
formatCalendarMonthYear 编号 : getCalendarWeekdayLabels | 日历铬 |
formatMonthCalendarMonth 编号 : formatMonthCalendarYear | 月网格 |
formatDateTimeListDateRow 编号 : formatDateTimeListHour /... (中文(简体) ) | 日期时间列表列 |
使用量
import {
formatDateId,
formatDateForDisplay,
formatNumber,
normalizeDateRange,
type DateId,
} from '@cdx-ui/formatters';
formatNumber(3247.19); // '3,247.19'
const id: DateId = formatDateId({ year: 2026, month: 7, day: 28 }); // '2026-07-28'
formatDateForDisplay(id, { locale: 'en-US' }); // e.g. '7/28/26'
normalizeDateRange({ startId: '2026-07-28', endId: '2026-07-01' });
// → { startId: '2026-07-01', endId: '2026-07-28' }
pnpm --filter @cdx-ui/formatters test
文件布局
src/
formatNumber.ts # shared display helper (merge target with ui-formatters)
types.ts / utils.ts # package-private (not barrel-exported)
__tests__/ # one test file per public helper
dates/
types.ts
index.ts # date barrel (re-exported from package root)
wire/ # DateId / MonthId parse, format, validate, today
display/ # locale-aware format*ForDisplay
ranges/ # compare, normalize, presets
segments/ # segmented field helpers
calendar/ # calendar + list row copy
datetime/ # DateTimeId + list hour/minute/period
labels/ # date-component accessibility label helpers
internal/ # private adapters (not public API)
设计说明
- 日期 - fns a. 用于内部的线剖面; 输入 用于显示和日历标签.
- 无效/ 无效输入返回
'' 或者说 null 如每个帮助者所记录的 —— 绝不因显示输入不当而丢出.
- 软件包内部
dates/internal/ 不属于公共API.
许可证

麻省理工学院 2026 Digital First Holdings LLC. 包装的许可证全文 LICENSE。 。 。 .