Comparing version 3.0.9 to 3.0.10
@@ -54,2 +54,3 @@ import { Address4, Address6 } from "ip-address"; | ||
export function isValidAddress(address: string): boolean; | ||
export function isValidCIDR(address: string): boolean; | ||
export function createAddress(address: string): Address; | ||
@@ -56,0 +57,0 @@ } |
13
index.js
@@ -204,2 +204,15 @@ "use strict"; | ||
IPCIDR.isValidCIDR = function (address) { | ||
if(typeof address !== 'string' || !address.match('/')) { | ||
return false; | ||
} | ||
try { | ||
return !!this.createAddress(address); | ||
} | ||
catch(err) { | ||
return false; | ||
} | ||
} | ||
module.exports = IPCIDR; |
{ | ||
"name": "ip-cidr", | ||
"version": "3.0.9", | ||
"version": "3.0.10", | ||
"description": "Module for working with CIDR (v4, v6)", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -14,3 +14,3 @@ # Install | ||
if(!IPCIDR.isValidAddress(address)) { | ||
if(!IPCIDR.isValidCIDR(address)) { | ||
return; | ||
@@ -52,4 +52,7 @@ } | ||
### .isValidAddress(address) | ||
to check the address is valid or not | ||
to check the address is valid or not (ip or cidr) | ||
### .isValidCIDR(address) | ||
to check the address is valid (only cidr) | ||
### .createAddress(address) | ||
@@ -56,0 +59,0 @@ to create an object address from the string |
@@ -66,2 +66,30 @@ "use strict"; | ||
describe(".isValidAddress()", function () { | ||
it('check a wrong address', function () {; | ||
assert.isFalse(IPCIDR.isValidAddress('wrong')); | ||
}); | ||
it('check an ip address', function () {; | ||
assert.isTrue(IPCIDR.isValidAddress('1.1.1.1')); | ||
}); | ||
it('check CIDR', function () {; | ||
assert.isTrue(IPCIDR.isValidAddress('1.1.1.1/24')); | ||
}); | ||
}); | ||
describe(".isValidCIDR()", function () { | ||
it('check a wrong address', function () {; | ||
assert.isFalse(IPCIDR.isValidCIDR('wrong')); | ||
}); | ||
it('check an ip address', function () {; | ||
assert.isFalse(IPCIDR.isValidCIDR('1.1.1.1')); | ||
}); | ||
it('check CIDR', function () {; | ||
assert.isTrue(IPCIDR.isValidCIDR('1.1.1.1/24')); | ||
}); | ||
}); | ||
describe(".prototype.contains()", function () { | ||
@@ -68,0 +96,0 @@ describe("check as string", function () { |
Sorry, the diff of this file is too big to display
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
136861
3682
88