diff options
author | Voltrex <mohammadkeyvanzade94@gmail.com> | 2021-08-13 03:11:20 +0430 |
---|---|---|
committer | Danielle Adams <adamzdanielle@gmail.com> | 2021-08-16 16:35:26 -0400 |
commit | 5afdc1f4c04c18f047804e37425d8cc68ee6339e (patch) | |
tree | 69e8cf2eaca494ec550bf147d543c3affa1b2994 | |
parent | 5e1011238adc13d147d005b540c5d16ed85a86bc (diff) | |
download | node-new-5afdc1f4c04c18f047804e37425d8cc68ee6339e.tar.gz |
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: https://github.com/nodejs/node/pull/39753
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
Reviewed-By: Zijian Liu <lxxyxzj@gmail.com>
-rw-r--r-- | lib/internal/validators.js | 7 |
1 files changed, 3 insertions, 4 deletions
diff --git a/lib/internal/validators.js b/lib/internal/validators.js index 9bca0aa747..b3a7ee2655 100644 --- a/lib/internal/validators.js +++ b/lib/internal/validators.js @@ -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); } @@ -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) { @@ -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) || |