Comparing version
21
index.js
@@ -8,14 +8,21 @@ "use strict"; | ||
constructor(cidr) { | ||
if(typeof cidr !== 'string') { | ||
this._isValid = false; | ||
return; | ||
} | ||
cidr.match(/:.\./) && (cidr = cidr.split(':').pop()); | ||
let ipAddressType = cidr.match(":")? ipAddress.Address6: ipAddress.Address4; | ||
let address = new ipAddressType(cidr); | ||
this._isValid = address.isValid(); | ||
if (this._isValid) { | ||
this.cidr = cidr; | ||
this.ipAddressType = ipAddressType; | ||
this.address = address; | ||
this.addressStart = address.startAddress(); | ||
this.addressEnd = address.endAddress(); | ||
if (!this._isValid) { | ||
return; | ||
} | ||
this.cidr = cidr; | ||
this.ipAddressType = ipAddressType; | ||
this.address = address; | ||
this.addressStart = address.startAddress(); | ||
this.addressEnd = address.endAddress(); | ||
} | ||
@@ -22,0 +29,0 @@ |
{ | ||
"name": "ip-cidr", | ||
"version": "2.0.11", | ||
"version": "2.0.12", | ||
"description": "Module for working with CIDR (v4, v6)", | ||
@@ -26,3 +26,3 @@ "main": "./index.js", | ||
"hooks": { | ||
"pre-commit": "npm run test && npm run build" | ||
"pre-commit": "npm run test && npm run build && git add ./dist/*" | ||
} | ||
@@ -29,0 +29,0 @@ }, |
@@ -9,2 +9,3 @@ "use strict"; | ||
let validCIDR = '5.5.5.8/29'; | ||
let validCIDRMapped = '5.5.5.8/29'; | ||
let validCIDRClear = '5.5.5.8'; | ||
@@ -34,2 +35,17 @@ let validCIDRStart = '5.5.5.8'; | ||
it('should be valid v6', function () { | ||
let cidr = new IPCIDR('2001:db8::/120'); | ||
assert.isOk(cidr.isValid(), 'check the status'); | ||
assert.equal(cidr.addressStart.addressMinusSuffix, '2001:0db8:0000:0000:0000:0000:0000:0000', 'check the start'); | ||
assert.equal(cidr.addressEnd.addressMinusSuffix, '2001:0db8:0000:0000:0000:0000:0000:00ff', 'check the end'); | ||
}); | ||
it('should be valid mapped cidr', function () { | ||
let cidr = new IPCIDR('::FFFF:' + validCIDRMapped); | ||
assert.isOk(cidr.isValid(), 'check the status'); | ||
assert.equal(cidr.addressStart.addressMinusSuffix, validCIDRStart, 'check the start'); | ||
assert.equal(cidr.addressEnd.addressMinusSuffix, validCIDREnd, 'check the end'); | ||
}); | ||
it('should be invalid', function () { | ||
@@ -45,3 +61,2 @@ let cidr = new IPCIDR(invalidCIDR); | ||
assert.equal(cidr.formatIP(cidr.address), validCIDRClear); | ||
const ipAddress = require('ip-address'); | ||
}); | ||
@@ -176,4 +191,4 @@ | ||
}); | ||
}) | ||
}); | ||
}); | ||
Sorry, the diff of this file is too big to display
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
URL strings
Supply chain riskPackage contains fragments of external URLs or IP addresses, which the package may be accessing at runtime.
Found 1 instance in 1 package
306479
0.36%9925
0.24%