@cdx-ui/formatters

中文文档
0.3.12发布于 2026/11/04MITTypeScriptESM + CJS近 30 天下载 3187

coverage

原始使用文档
文档目录11 节
  1. Wire vs display (dates)
  2. Exports
  3. Display (shared with banking UI formatters)
  4. Date wire
  5. Date display
  6. Ranges & segments
  7. Calendar / list copy
  8. Usage
  9. File layout
  10. Design notes
  11. License

@cdx-ui/formatters

coverage

Pure formatters for Forge UI and FI apps — turn wire values into human-readable UI strings (and the reverse for date wire ids). No React dependency.

Aligned in style with @candescent/ui-formatters (display helpers at package root; date helpers under dates/). Prefer named imports from @cdx-ui/formatters only — do not import date-fns or Intl wrappers from this package’s internals.

Wire vs display (dates)

RepresentationExampleUse for
Wire DateId / MonthId / DateTimeId'2026-07-28'Form state, APIs, pickers
Display string'7/28/26' / '28/07/2026'Labels, headers — never store

Exports

The tables below are a representative import guide, not an exhaustive list — src/index.ts (re-exporting dates/index.ts) is the authoritative export surface.

Display (shared with banking UI formatters)

ImportPurpose
formatNumberLocale decimal formatting (cached Intl.NumberFormat)

Date wire

ImportPurpose
parseDateId / formatDateId / isValidDateIdYYYY-MM-DD round-trip
parseMonthId / formatMonthId / isValidMonthIdYYYY-MM-01 month ids
parseDateTimeId / formatDateTimeId / isValidDateTimeIdLocal YYYY-MM-DDTHH:mm
todayDateId / todayMonthId / nowDateTimeIdDevice-local “now”
toMonthId / clampDateParts / clampMonthPartsConversions / clamping

Date display

ImportPurpose
formatDateForDisplayLocale dateStyle short/medium/long
formatMonthForDisplayMonth + year label
formatDateTimeForDisplayDate + time label
formatDateRangeForDisplayInclusive range label

Ranges & segments

ImportPurpose
normalizeDateRange / compareDateIds / eachDateIdInRangeRange math
dateRangeFromLastNDays / dateRangeAroundDayPresets
getDateFieldSegments / getDateTimeFieldSegmentsSegmented field metadata
parseDateSegment / formatDateSegment / applyDateSegmentChangeSegment edits

Calendar / list copy

ImportPurpose
formatCalendarMonthYear / getCalendarWeekdayLabelsCalendar chrome
formatMonthCalendarMonth / formatMonthCalendarYearMonth grid
formatDateTimeListDateRow / formatDateTimeListHour / …DateTime list columns

Usage

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

File layout

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)

Design notes

  • date-fns is used internally for wire parse/math; Intl for user-facing display and calendar labels.
  • Invalid / nullish inputs return '' or null as documented per helper — never throw for bad display input.
  • Package internals under dates/internal/ are not part of the public API.

License

License: MIT

MIT © 2026 Digital First Holdings LLC. The full license text ships in the package as LICENSE.

版本与发布记录

@cdx-ui/formatters 共发布 75 个版本,首次发布于 2026/08/12;过去 12 个月发布了 75 个版本。

版本发布日期距今
0.3.12latest2026/11/044 天前
0.3.112026/10/309 天前
0.3.102026/10/309 天前
0.3.92026/10/3010 天前
0.3.82026/10/2811 天前
0.3.72026/10/2713 天前

其他发布通道:staging → 0.1.0。

关于 @cdx-ui/formatters 的常见问题

如何安装 @cdx-ui/formatters?

在项目目录运行 npm install @cdx-ui/formatters,或使用 pnpm add / yarn add / bun add。

@cdx-ui/formatters 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cdx-ui/formatters 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cdx-ui/formatters 可以商用吗?

@cdx-ui/formatters 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cdx-ui/formatters 的下载量有多少?

根据 npm 官方下载统计,@cdx-ui/formatters 在 2026/10/10 – 2026/11/08 这 30 天内被下载 3,187 次,日均约 106 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cdx-ui/formatters 还在维护吗?

最新版本 0.3.12 发布于 2026/11/04(4 天前);至今共发布 75 个版本,其中过去 12 个月发布了 75 个;首次发布于 2026/08/12。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。