UNPKG

907 BJavaScriptView Raw
1/**
2 * @name isDate
3 * @category Common Helpers
4 * @summary Is the given value a date?
5 *
6 * @description
7 * Returns true if the given value is an instance of Date. The function works for dates transferred across iframes.
8 *
9 * @param value - The value to check
10 *
11 * @returns True if the given value is a date
12 *
13 * @example
14 * // For a valid date:
15 * const result = isDate(new Date())
16 * //=> true
17 *
18 * @example
19 * // For an invalid date:
20 * const result = isDate(new Date(NaN))
21 * //=> true
22 *
23 * @example
24 * // For some value:
25 * const result = isDate('2014-02-31')
26 * //=> false
27 *
28 * @example
29 * // For an object:
30 * const result = isDate({})
31 * //=> false
32 */
33export function isDate(value) {
34 return (
35 value instanceof Date ||
36 (typeof value === "object" &&
37 Object.prototype.toString.call(value) === "[object Date]")
38 );
39}
40
41// Fallback for modularized imports:
42export default isDate;