Skip to content

Commit

Permalink
lib: simplify validators
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
VoltrexKeyva authored and danielleadams committed Aug 16, 2021
1 parent 5e10112 commit 5afdc1f
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/internal/validators.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ const validateObject = hideStackFrames(
}
});

const validateArray = hideStackFrames((value, name, { minLength = 0 } = {}) => {
const validateArray = hideStackFrames((value, name, minLength = 0) => {
if (!ArrayIsArray(value)) {
throw new ERR_INVALID_ARG_TYPE(name, 'Array', value);
}
Expand All @@ -166,8 +166,7 @@ const validateArray = hideStackFrames((value, name, { minLength = 0 } = {}) => {
});

function validateSignalName(signal, name = 'signal') {
if (typeof signal !== 'string')
throw new ERR_INVALID_ARG_TYPE(name, 'string', signal);
validateString(signal, name);

if (signals[signal] === undefined) {
if (signals[StringPrototypeToUpperCase(signal)] !== undefined) {
Expand Down Expand Up @@ -199,7 +198,7 @@ function validateEncoding(data, encoding) {

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

0 comments on commit 5afdc1f

Please sign in to comment.