Skip to content

Commit 338189f

Browse files
VoltrexKeyvatargos
authored andcommitted
lib: simplify validators
Some of the validators can be simplified by removing unnecessary object parameters and using validators in another validators to keep consistency. PR-URL: #39753 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Antoine du Hamel <[email protected]> Reviewed-By: Zijian Liu <[email protected]>
1 parent de94611 commit 338189f

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

lib/internal/validators.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ const validateObject = hideStackFrames(
164164
}
165165
});
166166

167-
const validateArray = hideStackFrames((value, name, { minLength = 0 } = {}) => {
167+
const validateArray = hideStackFrames((value, name, minLength = 0) => {
168168
if (!ArrayIsArray(value)) {
169169
throw new ERR_INVALID_ARG_TYPE(name, 'Array', value);
170170
}
@@ -175,8 +175,7 @@ const validateArray = hideStackFrames((value, name, { minLength = 0 } = {}) => {
175175
});
176176

177177
function validateSignalName(signal, name = 'signal') {
178-
if (typeof signal !== 'string')
179-
throw new ERR_INVALID_ARG_TYPE(name, 'string', signal);
178+
validateString(signal, name);
180179

181180
if (signals[signal] === undefined) {
182181
if (signals[signal.toUpperCase()] !== undefined) {
@@ -208,7 +207,7 @@ function validateEncoding(data, encoding) {
208207

209208
// Check that the port number is not NaN when coerced to a number,
210209
// is an integer and that it falls within the legal range of port numbers.
211-
function validatePort(port, name = 'Port', { allowZero = true } = {}) {
210+
function validatePort(port, name = 'Port', allowZero = true) {
212211
if ((typeof port !== 'number' && typeof port !== 'string') ||
213212
(typeof port === 'string' && port.trim().length === 0) ||
214213
+port !== (+port >>> 0) ||

0 commit comments

Comments
 (0)