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