Skip to content

isValidFiscalPattern

isValidFiscalPattern(pattern: unknown): pattern is FiscalPattern

Return true when pattern is a valid FiscalPattern.

  • Valid patterns are: “4-5-4” (the NRF retail calendar), “4-4-5”, “5-4-4”.
  • Accepts any input type and returns false for non-string values.
  • Uses type assertion to narrow the type.
  • getFiscalPeriod returns null for a pattern it does not recognise — the same sentinel it returns for a date it cannot place. Check the pattern here to tell a misconfigured calendar apart from an unusable date: a pattern read from config, an env var or a form is a bare string until something narrows it.
ParameterTypeDescription
patternunknowncandidate value of any type

boolean indicating validity

import { isValidFiscalPattern } from "@northguild/gmt/calendar/validate";
isValidFiscalPattern("4-5-4") // true (the NRF retail calendar)
output 

calendar/validate/isValidFiscalPattern.ts