-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidators.js
More file actions
89 lines (77 loc) · 2.1 KB
/
validators.js
File metadata and controls
89 lines (77 loc) · 2.1 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
var
attr_domains = require('./tmp_data/cigar_domain_values.js'),
util = require('util'),
validators = {};
validators.vitolaValidator = {
validator: function (val) {
return checkAgainstDomainVals(val, attr_domains.vitola);
},
msg: 'Value for vitola is invalid.'
};
validators.colorValidator = {
validator: function (val) {
return checkAgainstDomainVals(val, attr_domains.color);
},
msg: 'Value for color is invalid.'
};
validators.countryValidator = {
validator: function (val) {
return checkAgainstDomainVals(val, attr_domains.country);
},
msg: 'Value for country is invalid.'
};
validators.strengthValidator = {
validator: function (val) {
return checkAgainstDomainVals(val, attr_domains.strength);
},
msg: 'Value for strength is invalid.'
};
validators.wrappersValidator = {
validator: function (val) {
return checkAgainstDomainVals(val, attr_domains.wrappers);
},
msg: 'Value for wrappers is invalid.'
};
validators.bindersValidator = {
validator: function (val) {
return checkAgainstDomainVals(val, attr_domains.binders);
},
msg: 'Value for binders is invalid.'
};
validators.fillersValidator = {
validator: function (val) {
return checkAgainstDomainVals(val, attr_domains.fillers);
},
msg: 'Value for fillers is invalid.'
};
validators.URLValidator = {
validator: function (val) {
try {
check(val).isUrl();
} catch (e) {
return false;
}
return true;
},
msg: 'URL is not valid.'
};
function checkAgainstDomainVals(the_val, truth) {
if (util.isArray(the_val)) {
console.log(util.inspect(the_val));
if (the_val.length > 0) {
for (var i = 0; the_val[i]; i++) {
if (truth.indexOf(the_val[i]) == -1) {
return false;
}
}
}
return true;
} else {
if (truth.indexOf(the_val) == -1) {
return false;
}
return true;
}
return false;
}
module.exports = validators;