Something went wrong. Try again.
Website hub for the atmosphere community, aggregating posts, events, regional, and more
Something went wrong. Try again.
660 B · 17 lines
TypeScript
123456789101112131415161718/** * A date, or undefined for anything that isn't one — never an Invalid Date. * * Takes `unknown` because that's what a raw record field is: callers shouldn't * have to assert a type they haven't checked yet. Undefined rather than null so * an absent date spreads straight into an optional field, like * `asNonEmptyString` below. */export function parseDate(value: unknown) { if (typeof value !== 'string') return undefined; const parsed = new Date(value); return isNaN(parsed.getTime()) ? undefined : parsed;}
export function asNonEmptyString(value: unknown) { return typeof value === 'string' && value.length > 0 ? value : undefined;}