-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
69 lines (60 loc) · 1.77 KB
/
test.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
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
const validanode = require('./validanode.js');
const messages = require('./localization/id_ID');
const customValidation = require('./my-custom-validation/custom');
const anotherCustomValidation = require('./my-custom-validation/another-custom');
const validator = new validanode();
validator.add(customValidation);
validator.add(anotherCustomValidation);
validator.localization(messages);
const {
START_WITH,
GREATER_THAN,
EMAIL
} = validator.TYPE_VALIDATOR;
const main = async () => {
data = {
username: 12,
password: 12,
re_password: 17,
numb_1: 12,
numb_2: 22,
email_google: "[email protected]",
email_yahoo: "[email protected]",
};
fields = [{
attribute: ['username', 'password', 're_password'],
rules: ["REQUIRED", "STRING"],
},
{
attribute: 'username',
rules: {
rule: START_WITH,
'property.value': 'defrindr_',
},
}, {
attribute: 're_password',
rules: {
rule: 'EQUAL_WITH',
'property.targetAttribute': 'password',
'property.message': 'Kolom {attribute} itu kudune podo karo {property.targetAttribute}',
},
}, {
attribute: 'numb_1',
rules: {
rule: GREATER_THAN.ATTRIBUTE,
'property.targetAttribute': 'numb_2',
},
}, {
attribute: 'email_yahoo',
rules: EMAIL.YAHOO,
}, {
attribute: 'email_google',
rules: EMAIL.GOOGLE,
}
];
err = await validator.check(fields, data);
if (err) return err;
}
(function () {
main().then(result => console.log(result));
})();