-
Notifications
You must be signed in to change notification settings - Fork 1
/
example.html
46 lines (40 loc) · 985 Bytes
/
example.html
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
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<script type="text/javascript" src="dist/trava.js"></script>
<script type="text/javascript">
let data = {
a: 1,
b: '',
c: 123,
};
console.log(Trava(Trava.Keys({
a: n => n,
b: str => 'a',
c: Trava.Required(n => n < 1000 ? new Trava.ValidationError('less than 1000!') : n),
}), data));
const ordata = {
a: 'qwe',
b: 1,
email: '[email protected]',
phone: '9012012329',
};
console.log(Trava([
Trava.Keys({
a: n => Number.isInteger(n) ? n : new Trava.ValidationError('NOT A NUMBER!'),
b: Trava.Optional(),
}),
obj => {
if (!(Boolean(obj.email) ^ Boolean(obj.phone))) return new Trava.ValidationError('NO DATA FIELDS!');
return obj;
}
], ordata));
console.log(Trava({
a: Trava.Each(Trava.Check(String), 'custom req'),
}, {a: [null]}));
</script>
</body>
</html>