@@ -71,7 +71,12 @@ function parseFileMode(value, name, def) {
71
71
}
72
72
73
73
/**
74
- * @type {(function(unknown, string, number=, number=): void) }
74
+ * @function validateInteger
75
+ * @param {* } value
76
+ * @param {string } name
77
+ * @param {number } [min]
78
+ * @param {number } [max]
79
+ * @returns {asserts value is number }
75
80
*/
76
81
const validateInteger = hideStackFrames (
77
82
( value , name , min = NumberMIN_SAFE_INTEGER , max = NumberMAX_SAFE_INTEGER ) => {
@@ -85,7 +90,12 @@ const validateInteger = hideStackFrames(
85
90
) ;
86
91
87
92
/**
88
- * @type {(function(unknown, string, number=, number=): void) }
93
+ * @function validateInt32
94
+ * @param {* } value
95
+ * @param {string } name
96
+ * @param {number } [min]
97
+ * @param {number } [max]
98
+ * @returns {asserts value is number }
89
99
*/
90
100
const validateInt32 = hideStackFrames (
91
101
( value , name , min = - 2147483648 , max = 2147483647 ) => {
@@ -103,7 +113,12 @@ const validateInt32 = hideStackFrames(
103
113
) ;
104
114
105
115
/**
106
- * @type {(function(unknown, string, boolean=): void) }
116
+ * @function validateUint32
117
+ * @param {* } value
118
+ * @param {string } name
119
+ * @param {number } [min]
120
+ * @param {number } [max]
121
+ * @returns {asserts value is number }
107
122
*/
108
123
const validateUint32 = hideStackFrames ( ( value , name , positive = false ) => {
109
124
if ( typeof value !== 'number' ) {
@@ -120,11 +135,25 @@ const validateUint32 = hideStackFrames((value, name, positive = false) => {
120
135
}
121
136
} ) ;
122
137
138
+ /**
139
+ * @function validateString
140
+ * @param {* } value
141
+ * @param {string } name
142
+ * @returns {asserts value is string }
143
+ */
123
144
function validateString ( value , name ) {
124
145
if ( typeof value !== 'string' )
125
146
throw new ERR_INVALID_ARG_TYPE ( name , 'string' , value ) ;
126
147
}
127
148
149
+ /**
150
+ * @function validateNumber
151
+ * @param {* } value
152
+ * @param {string } name
153
+ * @param {number } [min]
154
+ * @param {number } [max]
155
+ * @returns {asserts value is number }
156
+ */
128
157
function validateNumber ( value , name , min = undefined , max ) {
129
158
if ( typeof value !== 'number' )
130
159
throw new ERR_INVALID_ARG_TYPE ( name , 'number' , value ) ;
@@ -139,7 +168,11 @@ function validateNumber(value, name, min = undefined, max) {
139
168
}
140
169
141
170
/**
142
- * @type {(function(unknown, string, unknown[]): void) }
171
+ * @function validateOneOf
172
+ * @template T
173
+ * @param {T } value
174
+ * @param {string } name
175
+ * @param {T[] } oneOf
143
176
*/
144
177
const validateOneOf = hideStackFrames ( ( value , name , oneOf ) => {
145
178
if ( ! ArrayPrototypeIncludes ( oneOf , value ) ) {
@@ -152,6 +185,12 @@ const validateOneOf = hideStackFrames((value, name, oneOf) => {
152
185
}
153
186
} ) ;
154
187
188
+ /**
189
+ * @function validateBoolean
190
+ * @param {* } value
191
+ * @param {string } name
192
+ * @returns {asserts value is boolean }
193
+ */
155
194
function validateBoolean ( value , name ) {
156
195
if ( typeof value !== 'boolean' )
157
196
throw new ERR_INVALID_ARG_TYPE ( name , 'boolean' , value ) ;
@@ -164,11 +203,10 @@ function getOwnPropertyValueOrDefault(options, key, defaultValue) {
164
203
}
165
204
166
205
/**
167
- * @type {(function(unknown, string, {
168
- * allowArray?: boolean,
169
- * allowFunction?: boolean,
170
- * nullable?: boolean
171
- * }): void)}
206
+ * @function validateObject
207
+ * @param {* } value
208
+ * @param {string } name
209
+ * @param {{allowArray: boolean=, allowFunction: boolean=, nullable: boolean=} } [options]
172
210
*/
173
211
const validateObject = hideStackFrames (
174
212
( value , name , options ) => {
@@ -185,7 +223,11 @@ const validateObject = hideStackFrames(
185
223
} ) ;
186
224
187
225
/**
188
- * @type {(function(unknown, string, number=): void) }
226
+ * @function validateArray
227
+ * @param {* } value
228
+ * @param {string } name
229
+ * @param {number } [minLength]
230
+ * @returns {asserts value is unknown[] }
189
231
*/
190
232
const validateArray = hideStackFrames ( ( value , name , minLength = 0 ) => {
191
233
if ( ! ArrayIsArray ( value ) ) {
@@ -197,6 +239,12 @@ const validateArray = hideStackFrames((value, name, minLength = 0) => {
197
239
}
198
240
} ) ;
199
241
242
+ /**
243
+ * @function validateSignalName
244
+ * @param {* } signal
245
+ * @param {string } name
246
+ * @returns {asserts signal is keyof signals }
247
+ */
200
248
function validateSignalName ( signal , name = 'signal' ) {
201
249
validateString ( signal , name ) ;
202
250
@@ -211,7 +259,9 @@ function validateSignalName(signal, name = 'signal') {
211
259
}
212
260
213
261
/**
214
- * @type {(function(unknown, string=): void) }
262
+ * @function validateBuffer
263
+ * @param {* } buffer
264
+ * @param {string } [name='buffer']
215
265
*/
216
266
const validateBuffer = hideStackFrames ( ( buffer , name = 'buffer' ) => {
217
267
if ( ! isArrayBufferView ( buffer ) ) {
@@ -221,6 +271,11 @@ const validateBuffer = hideStackFrames((buffer, name = 'buffer') => {
221
271
}
222
272
} ) ;
223
273
274
+ /**
275
+ * @function validateEncoding
276
+ * @param {string } data
277
+ * @param {string } encoding
278
+ */
224
279
function validateEncoding ( data , encoding ) {
225
280
const normalizedEncoding = normalizeEncoding ( encoding ) ;
226
281
const length = data . length ;
@@ -245,7 +300,9 @@ function validatePort(port, name = 'Port', allowZero = true) {
245
300
}
246
301
247
302
/**
248
- * @type {(function(unknown, string): void) }
303
+ * @function validateAbortSignal
304
+ * @param {string } signal
305
+ * @param {string } name
249
306
*/
250
307
const validateAbortSignal = hideStackFrames ( ( signal , name ) => {
251
308
if ( signal !== undefined &&
@@ -257,29 +314,45 @@ const validateAbortSignal = hideStackFrames((signal, name) => {
257
314
} ) ;
258
315
259
316
/**
260
- * @type {(function(unknown, string): void) }
317
+ * @function validateFunction
318
+ * @param {* } value
319
+ * @param {string } name
320
+ * @returns {asserts value is Function }
261
321
*/
262
322
const validateFunction = hideStackFrames ( ( value , name ) => {
263
323
if ( typeof value !== 'function' )
264
324
throw new ERR_INVALID_ARG_TYPE ( name , 'Function' , value ) ;
265
325
} ) ;
266
326
267
327
/**
268
- * @type {(function(unknown, string): void) }
328
+ * @function validatePlainFunction
329
+ * @param {* } value
330
+ * @param {string } name
331
+ * @returns {asserts value is Function }
269
332
*/
270
333
const validatePlainFunction = hideStackFrames ( ( value , name ) => {
271
334
if ( typeof value !== 'function' || isAsyncFunction ( value ) )
272
335
throw new ERR_INVALID_ARG_TYPE ( name , 'Function' , value ) ;
273
336
} ) ;
274
337
275
338
/**
276
- * @type {(function(unknown, string): void) }
339
+ * @function validateUndefined
340
+ * @param {* } value
341
+ * @param {string } name
342
+ * @returns {asserts name is undefined }
277
343
*/
278
344
const validateUndefined = hideStackFrames ( ( value , name ) => {
279
345
if ( value !== undefined )
280
346
throw new ERR_INVALID_ARG_TYPE ( name , 'undefined' , value ) ;
281
347
} ) ;
282
348
349
+ /**
350
+ * @function validateUnion
351
+ * @template T
352
+ * @param {T } value
353
+ * @param {string } name
354
+ * @param {T[] } union
355
+ */
283
356
function validateUnion ( value , name , union ) {
284
357
if ( ! ArrayPrototypeIncludes ( union , value ) ) {
285
358
throw new ERR_INVALID_ARG_TYPE ( name , `('${ ArrayPrototypeJoin ( union , '|' ) } ')` , value ) ;
0 commit comments