mirror of
https://github.com/nodejs/node.git
synced 2025-05-01 08:42:45 +00:00

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 <cjihrig@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
12 lines
359 B
JavaScript
12 lines
359 B
JavaScript
'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;
|
|
}
|