@@ -15,7 +15,6 @@ const {
15
15
validateTimeout,
16
16
validateTries,
17
17
emitInvalidHostnameWarning,
18
- emitTypeCoercionDeprecationWarning,
19
18
getDefaultVerbatim,
20
19
} = require ( 'internal/dns/utils' ) ;
21
20
const { codes, dnsException } = require ( 'internal/errors' ) ;
@@ -30,13 +29,16 @@ const {
30
29
QueryReqWrap
31
30
} = internalBinding ( 'cares_wrap' ) ;
32
31
const {
32
+ ERR_INVALID_ARG_TYPE ,
33
33
ERR_INVALID_ARG_VALUE ,
34
34
ERR_MISSING_ARGS ,
35
35
} = codes ;
36
36
const {
37
+ validateBoolean,
38
+ validateNumber,
39
+ validateOneOf,
37
40
validatePort,
38
41
validateString,
39
- validateOneOf,
40
42
} = require ( 'internal/validators' ) ;
41
43
42
44
const kPerfHooksDnsLookupContext = Symbol ( 'kPerfHooksDnsLookupContext' ) ;
@@ -120,9 +122,10 @@ function createLookupPromise(family, hostname, all, hints, verbatim) {
120
122
} ) ;
121
123
}
122
124
125
+ const validFamilies = [ 0 , 4 , 6 ] ;
123
126
function lookup ( hostname , options ) {
124
127
let hints = 0 ;
125
- let family = - 1 ;
128
+ let family = 0 ;
126
129
let all = false ;
127
130
let verbatim = getDefaultVerbatim ( ) ;
128
131
@@ -131,35 +134,31 @@ function lookup(hostname, options) {
131
134
validateString ( hostname , 'hostname' ) ;
132
135
}
133
136
134
- if ( options !== null && typeof options === 'object' ) {
135
- if ( options . hints != null && typeof options . hints !== 'number' ) {
136
- emitTypeCoercionDeprecationWarning ( ) ;
137
+ if ( typeof options === 'number' ) {
138
+ validateOneOf ( options , 'family' , validFamilies , true ) ;
139
+ family = options ;
140
+ } else if ( options !== undefined && typeof options !== 'object' ) {
141
+ throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'integer' , 'object' ] , options ) ;
142
+ } else {
143
+ if ( options ?. hints != null ) {
144
+ validateNumber ( options . hints , 'options.hints' ) ;
145
+ hints = options . hints >>> 0 ;
146
+ validateHints ( hints ) ;
137
147
}
138
- hints = options . hints >>> 0 ;
139
- if ( options . family != null && typeof options . family !== 'number' ) {
140
- emitTypeCoercionDeprecationWarning ( ) ;
148
+ if ( options ?. family != null ) {
149
+ validateOneOf ( options . family , ' options.family' , validFamilies , true ) ;
150
+ family = options . family ;
141
151
}
142
- family = options . family >>> 0 ;
143
- if ( options . all != null && typeof options . all !== 'boolean' ) {
144
- emitTypeCoercionDeprecationWarning ( ) ;
152
+ if ( options ?. all != null ) {
153
+ validateBoolean ( options . all , ' options.all' ) ;
154
+ all = options . all ;
145
155
}
146
- all = options . all === true ;
147
- if ( typeof options . verbatim === 'boolean' ) {
148
- verbatim = options . verbatim === true ;
149
- } else if ( options . verbatim != null ) {
150
- emitTypeCoercionDeprecationWarning ( ) ;
156
+ if ( options ?. verbatim != null ) {
157
+ validateBoolean ( options . verbatim , 'options.verbatim' ) ;
158
+ verbatim = options . verbatim ;
151
159
}
152
-
153
- validateHints ( hints ) ;
154
- } else {
155
- if ( options != null && typeof options !== 'number' ) {
156
- emitTypeCoercionDeprecationWarning ( ) ;
157
- }
158
- family = options >>> 0 ;
159
160
}
160
161
161
- validateOneOf ( family , 'family' , [ 0 , 4 , 6 ] , true ) ;
162
-
163
162
return createLookupPromise ( family , hostname , all , hints , verbatim ) ;
164
163
}
165
164
0 commit comments