@@ -24,7 +24,7 @@ const {
24
24
ERR_INVALID_ARG_VALUE ,
25
25
} = require ( 'internal/errors' ) . codes ;
26
26
27
- const { validateInt32 } = require ( 'internal/validators' ) ;
27
+ const { validateInt32, validateString } = require ( 'internal/validators' ) ;
28
28
29
29
class BlockList {
30
30
constructor ( handle = new BlockListHandle ( ) ) {
@@ -52,10 +52,8 @@ class BlockList {
52
52
}
53
53
54
54
addAddress ( address , family = 'ipv4' ) {
55
- if ( typeof address !== 'string' )
56
- throw new ERR_INVALID_ARG_TYPE ( 'address' , 'string' , address ) ;
57
- if ( typeof family !== 'string' )
58
- throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
55
+ validateString ( address , 'address' ) ;
56
+ validateString ( family , 'family' ) ;
59
57
family = family . toLowerCase ( ) ;
60
58
if ( family !== 'ipv4' && family !== 'ipv6' )
61
59
throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
@@ -64,12 +62,9 @@ class BlockList {
64
62
}
65
63
66
64
addRange ( start , end , family = 'ipv4' ) {
67
- if ( typeof start !== 'string' )
68
- throw new ERR_INVALID_ARG_TYPE ( 'start' , 'string' , start ) ;
69
- if ( typeof end !== 'string' )
70
- throw new ERR_INVALID_ARG_TYPE ( 'end' , 'string' , end ) ;
71
- if ( typeof family !== 'string' )
72
- throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
65
+ validateString ( start , 'start' ) ;
66
+ validateString ( end , 'end' ) ;
67
+ validateString ( family , 'family' ) ;
73
68
family = family . toLowerCase ( ) ;
74
69
if ( family !== 'ipv4' && family !== 'ipv6' )
75
70
throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
@@ -80,10 +75,8 @@ class BlockList {
80
75
}
81
76
82
77
addSubnet ( network , prefix , family = 'ipv4' ) {
83
- if ( typeof network !== 'string' )
84
- throw new ERR_INVALID_ARG_TYPE ( 'network' , 'string' , network ) ;
85
- if ( typeof family !== 'string' )
86
- throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
78
+ validateString ( network , 'network' ) ;
79
+ validateString ( family , 'family' ) ;
87
80
family = family . toLowerCase ( ) ;
88
81
let type ;
89
82
switch ( family ) {
@@ -102,10 +95,8 @@ class BlockList {
102
95
}
103
96
104
97
check ( address , family = 'ipv4' ) {
105
- if ( typeof address !== 'string' )
106
- throw new ERR_INVALID_ARG_TYPE ( 'address' , 'string' , address ) ;
107
- if ( typeof family !== 'string' )
108
- throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
98
+ validateString ( address , 'address' ) ;
99
+ validateString ( family , 'family' ) ;
109
100
family = family . toLowerCase ( ) ;
110
101
if ( family !== 'ipv4' && family !== 'ipv6' )
111
102
throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
0 commit comments