Skip to main content
Version: 1.2.0

resolveDate

Using

Function that retrieves or resolves only date values. This function should handle various input types, resolving functions if encountered, and ultimately return an date if possible.

If the final resolved value is not an date or if a function remains unresolved within the specified depth, the function return undefined.

Arguments

ArgumentTypeDescriptionExample
valuedate
function
Value for resolve.new Date()
() => () => new Date('2024-05-01')
depthnumberDepth of maximum resolve.2

Returns

date | undefined — Returns the resolved date otherwise undefined.

Examples

resolveDate(new Date('2024-12-25'));
// Date object for 2024-12-25

resolveDate(() => () => new Date('2025-01-13'));
// Date object for 2025-01-13

resolveDate('text');
// undefined

resolveDate(() => new Date('1990-07-03'), 1);
// Date object for 1990-07-03

resolveDate(() => new Date('1990-07-03'), 2);
// Date object for 1990-07-03

resolveDate(() => new Date('1990-07-03'), 0);
// undefined

Resources

📦 Since:1.1.0
📦 Last updated:1.1.0
📦 Available in:1.3.0