Comparing version 2.0.0 to 2.0.1
15
index.js
@@ -8,3 +8,3 @@ "use strict"; | ||
constructor(cidr) { | ||
let ipAddressType = cidr.match(":") ? ipAddress.Address6 : ipAddress.Address4; | ||
let ipAddressType = cidr.match(":")? ipAddress.Address6: ipAddress.Address4; | ||
let address = new ipAddressType(cidr); | ||
@@ -40,2 +40,15 @@ | ||
contains(address) { | ||
if(!(address instanceof ipAddress.Address6) && !(address instanceof ipAddress.Address4)) { | ||
if(typeof address == 'object') { | ||
address = this.ipAddressType.fromBigInteger(address); | ||
} | ||
else { | ||
address = new this.ipAddressType(address); | ||
} | ||
} | ||
return address.isInSubnet(this.address) | ||
} | ||
start(options) { | ||
@@ -42,0 +55,0 @@ return this.formatIP(this.addressStart, options); |
{ | ||
"name": "ip-cidr", | ||
"version": "2.0.0", | ||
"version": "2.0.1", | ||
"description": "Module for working with CIDR (v4, v6)", | ||
@@ -5,0 +5,0 @@ "main": "./index.js", |
@@ -41,2 +41,5 @@ # Install | ||
### .contains(address) | ||
check the address belongs to cidr | ||
### .start([options]) | ||
@@ -43,0 +46,0 @@ get start ip |
@@ -5,2 +5,4 @@ "use strict"; | ||
const IPCIDR = require('../index'); | ||
const BigInteger = require('jsbn').BigInteger; | ||
const ipAddress = require('ip-address'); | ||
@@ -42,2 +44,3 @@ let validCIDR = '5.5.5.8/29'; | ||
assert.equal(cidr.formatIP(cidr.address), validCIDRClear); | ||
const ipAddress = require('ip-address'); | ||
}); | ||
@@ -56,2 +59,40 @@ | ||
describe(".contains()", function () { | ||
describe("check as string", function () { | ||
it('should be true', function () { | ||
let cidr = new IPCIDR(validCIDR); | ||
assert.isTrue(cidr.contains('5.5.5.15')); | ||
}); | ||
it('should be false', function () { | ||
let cidr = new IPCIDR(validCIDR); | ||
assert.isFalse(cidr.contains('5.5.5.16')); | ||
}); | ||
}); | ||
describe("check as big integer", function () { | ||
it('should be true', function () { | ||
let cidr = new IPCIDR(validCIDR); | ||
assert.isTrue(cidr.contains(new BigInteger('84215055'))); | ||
}); | ||
it('should be false', function () { | ||
let cidr = new IPCIDR(validCIDR); | ||
assert.isFalse(cidr.contains(new BigInteger('84215056'))); | ||
}); | ||
}); | ||
describe("check as object", function () { | ||
it('should be true', function () { | ||
let cidr = new IPCIDR(validCIDR); | ||
assert.isTrue(cidr.contains(new ipAddress.Address4('5.5.5.15'))); | ||
}); | ||
it('should be false', function () { | ||
let cidr = new IPCIDR(validCIDR); | ||
assert.isFalse(cidr.contains(new ipAddress.Address4('5.5.5.16'))); | ||
}); | ||
}); | ||
}); | ||
describe("check methods", function () { | ||
@@ -58,0 +99,0 @@ it('.start()', 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
309864
10033
71