@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 (21 loc) • 872 B
JavaScript
// src/plain/validate/isValidDateDurationUnit.ts
/**
* Return true when `unit` is a valid DateDurationUnit.
*
* - Valid units are: "years", "months", "weeks", "days".
* - A value that is not a string, a `String` object included, returns `false`. A `true` result
* narrows the value to the unit type.
*
* @param unit any value; a string is checked against the date duration units
* @returns boolean indicating whether the unit is valid
*
* @example isValidDateDurationUnit("days") // true
* @example isValidDateDurationUnit("months") // true
* @example isValidDateDurationUnit("years") // true
* @example isValidDateDurationUnit("invalid") // false
* @example isValidDateDurationUnit(null) // false
*/
const isValidDateDurationUnit = (unit) => {
return unit === "years" || unit === "months" || unit === "weeks" || unit === "days";
};
export { isValidDateDurationUnit };