summaryrefslogtreecommitdiff
path: root/lib/internal/net.js
blob: ce8f549bdfa6130de24046cbc2042fbcfc87595e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
'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;
}

module.exports = {
  isLegalPort
};