@northguild/gmt
Version:
Date and time library for JavaScript and TypeScript, built on TC39 Temporal: time zones, DST, business days, ISO 8601 strings in and out. Never throws.
22 lines • 827 B
TypeScript
import { DateUnit } from "../../types/date-unit.js";
import "../../types/index.js";
/**
* Return true when `unit` is a valid DateUnit.
*
* - Valid units are: "year", "month", "week", "day".
* - Accepts any input type and returns false for non-string values.
* - Uses type assertion to narrow the type.
*
* @param unit candidate value of any type
* @returns boolean indicating validity
*
* @example isValidDateUnit("year") // true
* @example isValidDateUnit("month") // true
* @example isValidDateUnit("week") // true
* @example isValidDateUnit("day") // true
* @example isValidDateUnit("hour") // false
* @example isValidDateUnit("invalid") // false
* @example isValidDateUnit(123) // false
* @example isValidDateUnit(null) // false
*/
export declare function isValidDateUnit(unit: unknown): unit is DateUnit;