@@ -24,7 +24,7 @@ const {
2424 ERR_INVALID_ARG_VALUE ,
2525} = require ( 'internal/errors' ) . codes ;
2626
27- const { validateInt32 } = require ( 'internal/validators' ) ;
27+ const { validateInt32, validateString } = require ( 'internal/validators' ) ;
2828
2929class BlockList {
3030 constructor ( handle = new BlockListHandle ( ) ) {
@@ -52,10 +52,8 @@ class BlockList {
5252 }
5353
5454 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' ) ;
5957 family = family . toLowerCase ( ) ;
6058 if ( family !== 'ipv4' && family !== 'ipv6' )
6159 throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
@@ -64,12 +62,9 @@ class BlockList {
6462 }
6563
6664 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' ) ;
7368 family = family . toLowerCase ( ) ;
7469 if ( family !== 'ipv4' && family !== 'ipv6' )
7570 throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
@@ -80,10 +75,8 @@ class BlockList {
8075 }
8176
8277 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' ) ;
8780 family = family . toLowerCase ( ) ;
8881 let type ;
8982 switch ( family ) {
@@ -102,10 +95,8 @@ class BlockList {
10295 }
10396
10497 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' ) ;
109100 family = family . toLowerCase ( ) ;
110101 if ( family !== 'ipv4' && family !== 'ipv6' )
111102 throw new ERR_INVALID_ARG_VALUE ( 'family' , family ) ;
0 commit comments