forked from bcgov/startup-sample-project-aws-containers
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvalidation.js
39 lines (33 loc) · 933 Bytes
/
validation.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
const yup = require('yup');
// const provinces = [
// 'Alberta',
// 'British Columbia',
// 'Manitoba',
// 'New Brunswick',
// 'Newfoundland and Labrador',
// 'Nova Scotia',
// 'Ontario',
// 'Prince Edward Island',
// 'Québec',
// 'Saskatchewan',
// 'Nunavut',
// 'Northwest Territories',
// 'Yukon',
// 'Other',
// ];
// const validateDateString = (s) => {
// if (/^\d{4}\/\d{2}\/\d{2}$/.test(s) === false) return false;
// const date = Date.parse(s);
// return typeof date === 'number' && !Number.isNaN(date);
// };
// const validateUniqueArray = (a) => (
// Array.isArray(a) && new Set(a).size === a.length
// );
const GreetingSchema = yup.object().noUnknown().shape({
// Greeting
greeting: yup.string().required('Greeting selection is required'),
});
const validate = async (schema, data) => schema.validate(data, { strict: true });
module.exports = {
GreetingSchema, validate,
};