Skip to content

CoerceToValidDateValue

cartographer


cartographer / coerceToValidDateValue

coerceToValidDateValue(value): string | number | Date | null

Defined in: types/types.ts:55

Coerce a field value to a valid Date constructor argument. Filters out non-date-like values and returns string | number | Date | null.

A potential date value

string | number | boolean | string[] | Date | null | undefined

string | number | Date | null

  • String, number, Date, or null (suitable for Date constructor)
const coerced1 = coerceToValidDateValue('2026-01-06'); // Returns: '2026-01-06'
const coerced2 = coerceToValidDateValue(new Date()); // Returns: Date object
const coerced3 = coerceToValidDateValue(true); // Returns: null (boolean not valid for Date)