@@ -28,11 +28,10 @@ const kHandle = Symbol('kHandle');
28
28
const { owner_symbol } = internalBinding ( 'symbols' ) ;
29
29
30
30
const {
31
- ERR_INVALID_ARG_TYPE ,
32
31
ERR_INVALID_ARG_VALUE ,
33
32
} = require ( 'internal/errors' ) . codes ;
34
33
35
- const { validateInt32 } = require ( 'internal/validators' ) ;
34
+ const { validateInt32, validateString } = require ( 'internal/validators' ) ;
36
35
37
36
class BlockList extends JSTransferable {
38
37
constructor ( ) {
@@ -56,10 +55,8 @@ class BlockList extends JSTransferable {
56
55
}
57
56
58
57
addAddress ( address , family = 'ipv4' ) {
59
- if ( typeof address !== 'string' )
60
- throw new ERR_INVALID_ARG_TYPE ( 'address' , 'string' , address ) ;
61
- if ( typeof family !== 'string' )
62
- throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
58
+ validateString ( address , 'address' ) ;
59
+ validateString ( family , 'family' ) ;
63
60
family = family . toLowerCase ( ) ;
64
61
if ( family !== 'ipv4' && family !== 'ipv6' )
65
62
throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
@@ -68,12 +65,9 @@ class BlockList extends JSTransferable {
68
65
}
69
66
70
67
addRange ( start , end , family = 'ipv4' ) {
71
- if ( typeof start !== 'string' )
72
- throw new ERR_INVALID_ARG_TYPE ( 'start' , 'string' , start ) ;
73
- if ( typeof end !== 'string' )
74
- throw new ERR_INVALID_ARG_TYPE ( 'end' , 'string' , end ) ;
75
- if ( typeof family !== 'string' )
76
- throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
68
+ validateString ( start , 'start' ) ;
69
+ validateString ( end , 'end' ) ;
70
+ validateString ( family , 'family' ) ;
77
71
family = family . toLowerCase ( ) ;
78
72
if ( family !== 'ipv4' && family !== 'ipv6' )
79
73
throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
@@ -84,10 +78,8 @@ class BlockList extends JSTransferable {
84
78
}
85
79
86
80
addSubnet ( network , prefix , family = 'ipv4' ) {
87
- if ( typeof network !== 'string' )
88
- throw new ERR_INVALID_ARG_TYPE ( 'network' , 'string' , network ) ;
89
- if ( typeof family !== 'string' )
90
- throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
81
+ validateString ( network , 'network' ) ;
82
+ validateString ( family , 'family' ) ;
91
83
family = family . toLowerCase ( ) ;
92
84
let type ;
93
85
switch ( family ) {
@@ -106,10 +98,8 @@ class BlockList extends JSTransferable {
106
98
}
107
99
108
100
check ( address , family = 'ipv4' ) {
109
- if ( typeof address !== 'string' )
110
- throw new ERR_INVALID_ARG_TYPE ( 'address' , 'string' , address ) ;
111
- if ( typeof family !== 'string' )
112
- throw new ERR_INVALID_ARG_TYPE ( 'family' , 'string' , family ) ;
101
+ validateString ( address , 'address' ) ;
102
+ validateString ( family , 'family' ) ;
113
103
family = family . toLowerCase ( ) ;
114
104
if ( family !== 'ipv4' && family !== 'ipv6' )
115
105
throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
0 commit comments