Skip to content

isValidDateUnit

isValidDateUnit(unit: unknown): unit is DateUnit

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.
ParameterTypeDescription
unitunknowncandidate value of any type

boolean indicating validity

import { isValidDateUnit } from "@northguild/gmt/plain/validate";
isValidDateUnit("year") // true
output 

plain/validate/isValidDateUnit.ts