18 lines
619 B
TypeScript
18 lines
619 B
TypeScript
import { PlanTimeDefinition } from "../viewmodel/admin/unit/inspection/inspectionPlan.models";
|
|
|
|
export default abstract class TypeTester {
|
|
static testPlanTimeDefinition(val: string, key: string = "", throwErr: boolean = false): PlanTimeDefinition | null {
|
|
if (/^(\d+-(d|m|y)|\d+\/(\d+|\*))$/.test(val)) {
|
|
return val as PlanTimeDefinition;
|
|
} else if (throwErr) {
|
|
throw Error(
|
|
[
|
|
key,
|
|
"provided String does not match PlanTimeDefinition Format: ${number}-${'d'|'m'|'y'} or ${number}/${number|'*'}",
|
|
].join(": ")
|
|
);
|
|
} else {
|
|
return null;
|
|
}
|
|
}
|
|
}
|