Files
simple-react-app-kit/packages/lexical/src/date-value.ts
T
Maofeng 0d817537be feat(lexical): add declarative rich text editor
Introduce @workspace/lexical with composable actions, toolbars, embeds, rich-text nodes, media uploads, selection utilities, HTML serialization, and theme styling.\n\nLocalize built-in controls through MessageDescriptor catalogs for English and Simplified Chinese, while providing an English I18nProvider fallback for standalone editor use. Include focused unit coverage for actions, controls, serialization, plugins, public API, and catalogs.
2026-07-31 15:07:09 +08:00

30 lines
922 B
TypeScript

export function parseISODate(value: string): Date | undefined {
if (!isISODate(value)) return undefined
const [year, month, day] = value.split("-").map(Number)
return new Date(year!, month! - 1, day)
}
export function toISODate(date: Date): string {
const year = date.getFullYear()
const month = String(date.getMonth() + 1).padStart(2, "0")
const day = String(date.getDate()).padStart(2, "0")
return `${year}-${month}-${day}`
}
export function formatDate(date: Date, locale?: string): string {
return new Intl.DateTimeFormat(locale, { dateStyle: "long" }).format(date)
}
export function isISODate(value: string): boolean {
if (!/^\d{4}-\d{2}-\d{2}$/.test(value)) return false
const [year, month, day] = value.split("-").map(Number)
const date = new Date(year!, month! - 1, day)
return (
date.getFullYear() === year &&
date.getMonth() === month! - 1 &&
date.getDate() === day
)
}