umami/src/lib/yup.ts

19 lines
400 B
TypeScript
Raw Normal View History

2023-11-15 04:44:32 +01:00
import moment from 'moment-timezone';
2023-08-20 07:23:15 +02:00
import * as yup from 'yup';
2023-09-25 22:31:25 +02:00
import { UNIT_TYPES } from './constants';
2023-08-20 07:23:15 +02:00
2023-10-13 21:53:01 +02:00
export const TimezoneTest = yup
.string()
.default('UTC')
.test(
'timezone',
() => `Invalid timezone`,
value => moment.tz.zone(value) !== null,
);
2023-09-25 22:31:25 +02:00
export const UnitTypeTest = yup.string().test(
'unit',
() => `Invalid unit`,
2023-09-26 21:30:35 +02:00
value => UNIT_TYPES.includes(value),
2023-09-25 22:19:56 +02:00
);