From 1e389c33c21d7a00c8255d0e7efd8d65aae500dc Mon Sep 17 00:00:00 2001 From: ray-1337 <33544674+ray-1337@users.noreply.github.com> Date: Fri, 29 Jul 2022 00:20:18 +0200 Subject: [PATCH] optimized checkAppropriateIP --- src/Util.js | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/Util.js b/src/Util.js index 34688f1..54a2fe6 100644 --- a/src/Util.js +++ b/src/Util.js @@ -87,11 +87,7 @@ module.exports.checkAppropriateIP = function(address) { // https://blog.markhatton.co.uk/2011/03/15/regular-expressions-for-ip-addresses-cidr-ranges-and-hostnames/ // also support subnet/net mask let regex = new RegExp(/^(([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])\.){3}([0-9]|[1-9][0-9]|1[0-9]{2}|2[0-4][0-9]|25[0-5])(\/(3[0-2]|[1-2][0-9]|[0-9]))?$/gi); - if (!address.match(regex)) { - throw new Error(`The IP address is not matched with ${regex.toString()} regular expressions.`); - }; - - return true; + return address.match(regex) !== null ? true : false; }; // soon to be continued