@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.
25 lines (24 loc) • 1.02 kB
JavaScript
// src/calendar/validate/isValidFiscalYearLabel.ts
/**
* Return true when `value` is a valid FiscalYearLabel: the rule that picks the calendar year
* naming a fiscal year.
*
* - Valid values are `"startYear"`, `"endYear"` and `"majorityYear"`.
* - Accepts any input type and returns false for non-string values.
* - Use it to narrow a value read from config, an env var or a form before building a
* `FiscalCalendar` or passing `getQuarter` its options.
*
* @param value candidate value of any type
* @returns boolean indicating validity
*
* @example isValidFiscalYearLabel("startYear") // true
* @example isValidFiscalYearLabel("endYear") // true
* @example isValidFiscalYearLabel("majorityYear") // true
* @example isValidFiscalYearLabel("fiscalYear") // false
* @example isValidFiscalYearLabel(null) // false
*/
function isValidFiscalYearLabel(value) {
if (typeof value !== "string") return false;
return value === "startYear" || value === "endYear" || value === "majorityYear";
}
export { isValidFiscalYearLabel };