@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.
27 lines (25 loc) • 849 B
JavaScript
import { isDateUnitName } from "../../internal/unitNames.js";
// src/plain/validate/isValidDateUnit.ts
/**
* 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
*/
function isValidDateUnit(unit) {
return isDateUnitName(unit);
}
export { isValidDateUnit };