mirror of
https://github.com/cpvalente/ontime.git
synced 2026-08-12 10:53:51 +00:00
1849b4d39f
* 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>
35 lines
1.3 KiB
TypeScript
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);
|
|
}
|