Conditions | 8 |
Paths | 10 |
Total Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | "use strict"; |
||
9 | const validate = (data, schema, format = "obj") => { |
||
10 | let returnError = null; |
||
11 | |||
12 | for (let key in schema) { |
||
13 | if (!schema[key].isRequired && !data.hasOwnProperty(key)) { |
||
14 | continue; |
||
15 | } else if (schema[key].isRequired && !data.hasOwnProperty(key)) { |
||
16 | returnError = schema[key].error("Any:required", key, schema[key]); |
||
17 | break; |
||
18 | } |
||
19 | |||
20 | returnError = schema[key].validate(data, key); |
||
21 | if (returnError) { |
||
22 | break; |
||
23 | } |
||
24 | } |
||
25 | |||
26 | return format === "json" ? JSON.stringify(returnError, null, 4) : returnError; |
||
27 | }; |
||
28 | |||
30 |