@@ -42,7 +42,6 @@ const {
42
42
Resolver,
43
43
validateHints,
44
44
emitInvalidHostnameWarning,
45
- emitTypeCoercionDeprecationWarning,
46
45
getDefaultVerbatim,
47
46
setDefaultResultOrder,
48
47
} = require ( 'internal/dns/utils' ) ;
@@ -52,10 +51,12 @@ const {
52
51
ERR_MISSING_ARGS ,
53
52
} = errors . codes ;
54
53
const {
54
+ validateBoolean,
55
55
validateFunction,
56
+ validateNumber,
57
+ validateOneOf,
56
58
validatePort,
57
59
validateString,
58
- validateOneOf,
59
60
} = require ( 'internal/validators' ) ;
60
61
61
62
const {
@@ -107,9 +108,10 @@ function onlookupall(err, addresses) {
107
108
108
109
// Easy DNS A/AAAA look up
109
110
// lookup(hostname, [options,] callback)
111
+ const validFamilies = [ 0 , 4 , 6 ] ;
110
112
function lookup ( hostname , options , callback ) {
111
113
let hints = 0 ;
112
- let family = - 1 ;
114
+ let family = 0 ;
113
115
let all = false ;
114
116
let verbatim = getDefaultVerbatim ( ) ;
115
117
@@ -121,39 +123,36 @@ function lookup(hostname, options, callback) {
121
123
if ( typeof options === 'function' ) {
122
124
callback = options ;
123
125
family = 0 ;
126
+ } else if ( typeof options === 'number' ) {
127
+ validateFunction ( callback , 'callback' ) ;
128
+
129
+ validateOneOf ( options , 'family' , validFamilies , true ) ;
130
+ family = options ;
131
+ } else if ( options !== undefined && typeof options !== 'object' ) {
132
+ validateFunction ( arguments . length === 2 ? options : callback , 'callback' ) ;
133
+ throw new ERR_INVALID_ARG_TYPE ( 'options' , [ 'integer' , 'object' ] , options ) ;
124
134
} else {
125
135
validateFunction ( callback , 'callback' ) ;
126
136
127
- if ( options !== null && typeof options === 'object' ) {
128
- if ( options . hints != null && typeof options . hints !== 'number' ) {
129
- emitTypeCoercionDeprecationWarning ( ) ;
130
- }
137
+ if ( options ?. hints != null ) {
138
+ validateNumber ( options . hints , 'options.hints' ) ;
131
139
hints = options . hints >>> 0 ;
132
- if ( options . family != null && typeof options . family !== 'number' ) {
133
- emitTypeCoercionDeprecationWarning ( ) ;
134
- }
135
- family = options . family >>> 0 ;
136
- if ( options . all != null && typeof options . all !== 'boolean' ) {
137
- emitTypeCoercionDeprecationWarning ( ) ;
138
- }
139
- all = options . all === true ;
140
- if ( typeof options . verbatim === 'boolean' ) {
141
- verbatim = options . verbatim === true ;
142
- } else if ( options . verbatim != null ) {
143
- emitTypeCoercionDeprecationWarning ( ) ;
144
- }
145
-
146
140
validateHints ( hints ) ;
147
- } else {
148
- if ( options != null && typeof options !== 'number' ) {
149
- emitTypeCoercionDeprecationWarning ( ) ;
150
- }
151
- family = options >>> 0 ;
141
+ }
142
+ if ( options ?. family != null ) {
143
+ validateOneOf ( options . family , 'options.family' , validFamilies , true ) ;
144
+ family = options . family ;
145
+ }
146
+ if ( options ?. all != null ) {
147
+ validateBoolean ( options . all , 'options.all' ) ;
148
+ all = options . all ;
149
+ }
150
+ if ( options ?. verbatim != null ) {
151
+ validateBoolean ( options . verbatim , 'options.verbatim' ) ;
152
+ verbatim = options . verbatim ;
152
153
}
153
154
}
154
155
155
- validateOneOf ( family , 'family' , [ 0 , 4 , 6 ] ) ;
156
-
157
156
if ( ! hostname ) {
158
157
emitInvalidHostnameWarning ( hostname ) ;
159
158
if ( all ) {
0 commit comments