Skip to content

Commit c69137c

Browse files
committed
Export validators list
Also document functions
1 parent 9f0d6a3 commit c69137c

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

lib/validate.js

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,18 @@
11

22
// Add validator names here
33
const validators = ['type', 'length', 'value', 'func', 'model', 'date'];
4-
// const validators = ['type', 'length', 'value', 'func'];
54

65
// Turn validator names to validator instances.
76
for (let i = 0; i < validators.length; i++) {
87
validators[i] = validator(validators[i]);
98
}
109

11-
// Validate
10+
/**
11+
* Validate
12+
*
13+
* @param data {Object} Data to validate
14+
* @param model {Object} Model to apply validations
15+
*/
1216
function validate(data, model) {
1317
for (let i = 0; i < validators.length; i++) {
1418
if (!validators[i].check(data, model)) {
@@ -20,13 +24,17 @@ function validate(data, model) {
2024
return true;
2125
}
2226

23-
// Create new validator instances
27+
/**
28+
* Create new validator instances
29+
*/
2430
function validator(name) {
2531
return {
2632
name: name,
2733
check: require('./validators/' + name),
2834
};
2935
}
3036

31-
32-
module.exports = { check: validate };
37+
module.exports = {
38+
validators: validators,
39+
check: validate
40+
};

0 commit comments

Comments
 (0)