From 6cbbfef994930bc47581d592124e82b58e55ac7b Mon Sep 17 00:00:00 2001 From: Evan Lucas Date: Tue, 26 Jan 2016 08:12:41 -0600 Subject: net: move isLegalPort to internal/net isLegalPort can be used in more places than just net.js. This change moves it to a new internal net module in preparation for using it in the dns module. PR-URL: https://github.com/nodejs/node/pull/4882 Reviewed-By: Colin Ihrig Reviewed-By: Ben Noordhuis Reviewed-By: James M Snell Reviewed-By: Sakthipriyan Vairamani --- lib/internal/net.js | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 lib/internal/net.js (limited to 'lib/internal/net.js') diff --git a/lib/internal/net.js b/lib/internal/net.js new file mode 100644 index 0000000000..effc6485d2 --- /dev/null +++ b/lib/internal/net.js @@ -0,0 +1,11 @@ +'use strict'; + +module.exports = { isLegalPort }; + +// 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 isLegalPort(port) { + if (typeof port === 'string' && port.trim() === '') + return false; + return +port === (port >>> 0) && port >= 0 && port <= 0xFFFF; +} -- cgit v1.2.3