mirror of
https://github.com/nodejs/node.git
synced 2024-12-01 16:10:02 +01:00
62e96096fa
Switch to using the more efficient module.exports = {} where possible. PR-URL: https://github.com/nodejs/node/pull/11406 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Michaël Zasso <targos@protonmail.com>
22 lines
594 B
JavaScript
22 lines
594 B
JavaScript
'use strict';
|
|
|
|
// 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 !== 'number' && typeof port !== 'string') ||
|
|
(typeof port === 'string' && port.trim().length === 0))
|
|
return false;
|
|
return +port === (+port >>> 0) && port <= 0xFFFF;
|
|
}
|
|
|
|
|
|
function assertPort(port) {
|
|
if (typeof port !== 'undefined' && !isLegalPort(port))
|
|
throw new RangeError('"port" argument must be >= 0 and < 65536');
|
|
}
|
|
|
|
module.exports = {
|
|
isLegalPort,
|
|
assertPort
|
|
};
|