@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.
20 lines • 858 B
TypeScript
import { DateTimeUnit } from "../../types/date-time-unit.js";
import "../../types/index.js";
/**
* Return true when `unit` is a valid DateTimeUnit.
*
* - Valid units are: "year", "month", "week", "day", "hour", "minute", "second", "millisecond", "microsecond", "nanosecond".
* - 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 isValidDateTimeUnit("year") // true
* @example isValidDateTimeUnit("month") // true
* @example isValidDateTimeUnit("weeks") // false
* @example isValidDateTimeUnit("invalid") // false
* @example isValidDateTimeUnit(123) // false
* @example isValidDateTimeUnit(null) // false
*/
export declare function isValidDateTimeUnit(unit: unknown): unit is DateTimeUnit;