-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy patherrorValidation.js
More file actions
63 lines (52 loc) · 1.27 KB
/
errorValidation.js
File metadata and controls
63 lines (52 loc) · 1.27 KB
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import chalk from "chalk";
/**
* typeValidation
* @param {number} paramA
* @param {string} paramB
* @returns
*/
function typeValidation(paramA, paramB) {
const errors = [];
if (typeof paramA !== "number") {
errors.push(
`parameter of ${chalk.blue(
"str_length"
)} should be number, yet we got ${typeof paramA}`
);
}
if (typeof paramB !== "string") {
errors.push(
`parameter of ${chalk.blue(
"chosen_date_format"
)} should be string, yet we got ${typeof paramB}`
);
}
return errors;
}
/**
* valueValidation
* @param {number} paramA
* @param {string} paramB
* @returns
*/
function valueValidation(paramA, paramB) {
const errors = [];
const accepted_format = ["default", "usa"];
const limitLength = paramA < 6 || paramA > 8;
if (limitLength) {
errors.push(
`value of ${chalk.yellow("str_length")} should be a number ${chalk.green(
"6-8"
)} and, yet we got ${chalk.red(paramA)}`
);
}
if (!accepted_format.includes(paramB)) {
errors.push(
`format ${chalk.blue(paramB)} ${chalk.red(
"is not accepted"
)}. we only accept either ${accepted_format[0]} or ${accepted_format[1]}`
);
}
return errors;
}
export { typeValidation, valueValidation };