Skip to content

Commit 5afdc1f

Browse files
VoltrexKeyvadanielleadams
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 <jasnell@gmail.com> Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com> Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
1 parent 5e10112 commit 5afdc1f

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
@@ -155,7 +155,7 @@ const validateObject = hideStackFrames(
155155
}
156156
});
157157

158-
const validateArray = hideStackFrames((value, name, { minLength = 0 } = {}) => {
158+
const validateArray = hideStackFrames((value, name, minLength = 0) => {
159159
if (!ArrayIsArray(value)) {
160160
throw new ERR_INVALID_ARG_TYPE(name, 'Array', value);
161161
}
@@ -166,8 +166,7 @@ const validateArray = hideStackFrames((value, name, { minLength = 0 } = {}) => {
166166
});
167167

168168
function validateSignalName(signal, name = 'signal') {
169-
if (typeof signal !== 'string')
170-
throw new ERR_INVALID_ARG_TYPE(name, 'string', signal);
169+
validateString(signal, name);
171170

172171
if (signals[signal] === undefined) {
173172
if (signals[StringPrototypeToUpperCase(signal)] !== undefined) {
@@ -199,7 +198,7 @@ function validateEncoding(data, encoding) {
199198

200199
// Check that the port number is not NaN when coerced to a number,
201200
// is an integer and that it falls within the legal range of port numbers.
202-
function validatePort(port, name = 'Port', { allowZero = true } = {}) {
201+
function validatePort(port, name = 'Port', allowZero = true) {
203202
if ((typeof port !== 'number' && typeof port !== 'string') ||
204203
(typeof port === 'string' && StringPrototypeTrim(port).length === 0) ||
205204
+port !== (+port >>> 0) ||

0 commit comments

Comments
 (0)