File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+ const Joi = require ( "joi" ) ;
3
+
4
+ const schema = Joi . object ( ) . keys ( {
5
+ username : Joi . string ( ) . required ( ) ,
6
+ email : Joi . string ( ) . email ( ) . required ( )
7
+ } ) ;
8
+
9
+ let username = "Roger Brown" ;
10
+ let email = "roger@example" ;
11
+ let correct = "[email protected] " ;
12
+
13
+ let data = { username, email } ;
14
+ console . log ( data ) ;
15
+ let correctData = { username : username , email : correct } ;
16
+ console . log ( correctData ) ;
17
+
18
+ let { error, value} = schema . validate ( data ) ;
19
+ console . error ( error ) ;
20
+ console . log ( value ) ;
21
+ let { err, val} = schema . validate ( correctData ) ;
22
+ if ( err ) {
23
+ console . error ( err ) ;
24
+ console . log ( val ) ;
25
+ }
26
+
27
+ async function main ( ) {
28
+ try {
29
+ await schema . validateAsync ( data ) ;
30
+ }
31
+ catch ( err ) {
32
+ console . error ( err . message ) ;
33
+ }
34
+ try {
35
+ await schema . validateAsync ( correctData ) ;
36
+ }
37
+ catch ( err ) {
38
+ console . error ( err . message ) ;
39
+ }
40
+ }
41
+
42
+ main ( ) ;
Original file line number Diff line number Diff line change
1
+ #!/usr/bin/env node
2
+ const Joi = require ( "@hapi/joi" ) ;
3
+
4
+ console . log ( Joi . version ) ;
You can’t perform that action at this time.
0 commit comments