Skip to content

isValid

Checks if a value is a valid Date instance (not Invalid Date).

Unlike isDate (in type/), this also verifies that the internal timestamp is not NaN.

Available since v2.0.0

import { isValid } from '@helpers4/date';
// or, from the all-in-one package (same code, one install):
import { isValid } from 'helpers4/date';
isValid(value: unknown): value is Date
ParameterTypeDescription
valueunknownThe value to check

value is Date — True if value is a Date instance with a valid time value

isValid(new Date())          // => true
isValid(new Date('invalid')) // => false
isValid('2023-01-01')        // => false (not a Date instance)

View source on GitHub