Files
ontime/packages/utils/src/validate-events/validateEvent.ts
T
Carlos Valente 1849b4d39f Deps migration (#1988)
* chore: migrate eslint to oxlint

* chore: migrate prettier to oxfmt

* chore: migrate typescript

* chore: toThrow should have a expected value

* chore: cast test value as Day

* chore: small title fix

* chore: mocks should be hoisted

* chore: incorrect async useage

* chore: test should be inside description

* chore: test sohuld include an expeced

* chore: oxfmt

---------

Co-authored-by: alex-Arc <omnivox@LAPTOP-RC5SNBVV.localdomain>
2026-03-08 16:22:12 +01:00

35 lines
1.3 KiB
TypeScript

import { EndAction, TimeStrategy, TimerType } from 'ontime-types';
/**
* Check if a given value is a valid time strategy, returns the fallback otherwise
* @param {TimeStrategy} maybeTimeStrategy
* @returns {TimeStrategy}
*/
export function validateTimeStrategy(maybeTimeStrategy: unknown, fallback = TimeStrategy.LockDuration): TimeStrategy {
return Object.values(TimeStrategy).includes(maybeTimeStrategy as TimeStrategy)
? (maybeTimeStrategy as TimeStrategy)
: fallback;
}
/**
* Checks if given value is a valid type of EndAction, returns the fallback otherwise
* @param {EndAction} maybeAction
* @param {EndAction} [fallback]
*/
export function validateEndAction(maybeAction: unknown, fallback = EndAction.None): EndAction {
return Object.values(EndAction).includes(maybeAction as EndAction) ? (maybeAction as EndAction) : fallback;
}
/**
* Checks if given value is a valid type of TimerType, returns the fallback otherwise
* @param {TimerType} maybeTimerType
* @param {TimerType} [fallback]
*/
export function validateTimerType(maybeTimerType: unknown, fallback = TimerType.CountDown): TimerType {
return Object.values(TimerType).includes(maybeTimerType as TimerType) ? (maybeTimerType as TimerType) : fallback;
}
export function isKnownTimerType(maybeTimerType: unknown) {
return Object.values(TimerType).includes(maybeTimerType as TimerType);
}