Comparing version 0.0.10 to 0.0.11
@@ -711,3 +711,3 @@ /** | ||
* Hostname may not contain other characters, such as the underscore character (_) | ||
* oTher DNS names may contain the underscore. | ||
* other DNS names may contain the underscore. | ||
*/ | ||
@@ -730,2 +730,3 @@ is.dnsAddress = function(value) { | ||
* Test is a value is a valid ipv4, ipv6 or DNS name. | ||
* Aliases: hostAddr, hostAddress. | ||
* @param {Any} value to test if a host address. | ||
@@ -745,3 +746,3 @@ * @return {Boolean} true if a host address, false otherwise. | ||
is.port = function(value) { | ||
if (!is.positiveInt(value) || value > 65535) | ||
if (!is.num(value) || is.negativeInt(value) || value > 65535) | ||
return false; | ||
@@ -751,1 +752,23 @@ return true; | ||
/** | ||
* Test if a number is a valid TCP port in the range 0-1023. | ||
* Alias: is.sysPort. | ||
* @param {Any} value to test if its a valid TCP port | ||
*/ | ||
is.systemPort = function(value) { | ||
if (is.port(value) && value < 1024) | ||
return true; | ||
return false; | ||
}; | ||
is.sysPort = is.systemPort; | ||
/** | ||
* Test if a number is a valid TCP port in the range 1024-65535. | ||
* @param {Any} value to test if its a valid TCP port | ||
*/ | ||
is.userPort = function(value) { | ||
if (is.port(value) && value > 1023) | ||
return true; | ||
return false; | ||
}; | ||
{ | ||
"name" : "is2" | ||
, "version" : "0.0.10" | ||
, "version" : "0.0.11" | ||
, "description" : "A type checking library where each exported function returns either true or false and does not throw. Also added tests." | ||
@@ -5,0 +5,0 @@ , "tags" : [ "utilities", "JavaScript", "node.js", "validation", "type", "checking" ] |
@@ -609,2 +609,21 @@ is2 | ||
### systemPort\(value\) | ||
Test if a value is a valid TCP/IP system port number in the range 0 - 1023. | ||
Alias: sysPort | ||
##### Params: | ||
* **Any** *value* to test. | ||
##### Returns: | ||
* **Boolean** true if 'value' is a valid system port number, and false otherwise. | ||
### userPort\(value\) | ||
Test if a value is a valid TCP/IP user port number in the range 1024 - 65535. | ||
##### Params: | ||
* **Any** *value* to test. | ||
##### Returns: | ||
* **Boolean** true if 'value' is a valid user port number, and false otherwise. | ||
## License | ||
@@ -611,0 +630,0 @@ The MIT License (MIT) |
@@ -812,2 +812,5 @@ 'use strict'; | ||
it('Should return true for valid port numbers ', function() { | ||
assert.equal(false, is.port(-11)); | ||
assert.equal(false, is.port(-11)); | ||
assert.equal(true, is.port(0)); | ||
assert.equal(true, is.port(1)); | ||
@@ -817,7 +820,11 @@ assert.equal(true, is.port(10)); | ||
assert.equal(true, is.port(65535)); | ||
assert.equal(false, is.port(65536)); | ||
}); | ||
it('Should return false for invalid port numbers ', function() { | ||
assert.equal(false, is.port(0)); | ||
assert.equal(false, is.port(-1100)); | ||
assert.equal(false, is.port(-10)); | ||
assert.equal(false, is.port(-1100)); | ||
assert.equal(true, is.port(0)); | ||
assert.equal(true, is.port(10)); | ||
assert.equal(true, is.port(65535)); | ||
assert.equal(false, is.port(65536)); | ||
@@ -834,1 +841,26 @@ assert.equal(false, is.port()); | ||
}); | ||
describe('is.systemPort', function() { | ||
it('Should return true for valid port numbers 0-1023 ', function() { | ||
assert.equal(false, is.systemPort(-1)); | ||
assert.equal(true, is.systemPort(0)); | ||
assert.equal(true, is.systemPort(1)); | ||
assert.equal(true, is.systemPort(1023)); | ||
assert.equal(false, is.systemPort(1024)); | ||
assert.equal(false, is.systemPort(10000)); | ||
}); | ||
}); | ||
describe('is.userPort', function() { | ||
it('Should return true for valid port numbers 1024-65535 ', function() { | ||
assert.equal(false, is.userPort(-1)); | ||
assert.equal(false, is.userPort(0)); | ||
assert.equal(false, is.userPort(1)); | ||
assert.equal(false, is.userPort(1023)); | ||
assert.equal(true, is.userPort(1024)); | ||
assert.equal(true, is.userPort(1025)); | ||
assert.equal(true, is.userPort(65535)); | ||
assert.equal(false, is.userPort(65536)); | ||
}); | ||
}); | ||
213395
1999
649