From f6f5dd36ff8d44d8e6d32cc054f35236925d05ed Mon Sep 17 00:00:00 2001 From: ray-1337 <33544674+ray-1337@users.noreply.github.com> Date: Fri, 29 Jul 2022 00:19:19 +0200 Subject: [PATCH] optimized checkAppropriatePort --- src/Util.js | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/Util.js b/src/Util.js index 1dc85e8..34688f1 100644 --- a/src/Util.js +++ b/src/Util.js @@ -72,16 +72,11 @@ module.exports.checkPlatformExact = async function () { }; module.exports.checkAppropriatePort = function(port) { - if (typeof port !== "number") { - throw new Error("The port must be type of number."); - }; + const portLimit = Math.round(2 ** 16 - 1); - let portLimit = Math.round(2 ** 16 - 1); - if (port <= 0 || port > portLimit) { - throw new Error("Exceeded port limit."); - }; + if (typeof port !== "number") throw new Error("The port must be type of number."); - return true; + return (port > 0 || port <= portLimit) ? true : false; }; module.exports.checkAppropriateIP = function(address) {