cidr-tools
Advanced tools
Comparing version 3.0.6 to 4.0.0
@@ -16,2 +16,3 @@ type IPv4Address = string; | ||
normalize(cidr: Network): Network; | ||
contains(networkA: Network, networkB: Network): boolean; | ||
} | ||
@@ -18,0 +19,0 @@ |
42
index.js
@@ -64,3 +64,4 @@ "use strict"; | ||
function doNetsOverlap(a, b) { | ||
// utility function that returns boundaries of two networks | ||
function getBoundaries(a, b) { | ||
const aStart = a.start({type: "bigInteger"}); | ||
@@ -70,3 +71,9 @@ const bStart = b.start({type: "bigInteger"}); | ||
const bEnd = b.end({type: "bigInteger"}); | ||
return {aStart, bStart, aEnd, bEnd}; | ||
} | ||
// returns whether networks fully or partially overlap | ||
function doNetsOverlap(a, b) { | ||
const {aStart, bStart, aEnd, bEnd} = getBoundaries(a, b); | ||
// aaa | ||
@@ -83,8 +90,20 @@ // bbb | ||
// returns whether network a fully contains network b; | ||
function contains(a, b) { | ||
const {aStart, bStart, aEnd, bEnd} = getBoundaries(a, b); | ||
// aaa | ||
// bbbb | ||
if (bStart.compareTo(aStart) < 0) return false; // a starts after b | ||
// aaa | ||
// bbbb | ||
if (bEnd.compareTo(aEnd) > 0) return false; // b starts after a | ||
return true; | ||
} | ||
// exclude b from a and return remainder cidrs | ||
function excludeNets(a, b, v) { | ||
const aStart = a.start({type: "bigInteger"}); | ||
const bStart = b.start({type: "bigInteger"}); | ||
const aEnd = a.end({type: "bigInteger"}); | ||
const bEnd = b.end({type: "bigInteger"}); | ||
const {aStart, bStart, aEnd, bEnd} = getBoundaries(a, b); | ||
const parts = []; | ||
@@ -347,2 +366,3 @@ | ||
// version mismatch | ||
if (aParsed.address.v4 !== bParsed.address.v4) { | ||
@@ -360,1 +380,13 @@ continue; | ||
}; | ||
module.exports.contains = (a, b) => { | ||
const aParsed = parse(a); | ||
const bParsed = parse(b); | ||
// version mismatch | ||
if (aParsed.address.v4 !== bParsed.address.v4) { | ||
return false; | ||
} | ||
return contains(aParsed, bParsed); | ||
}; |
{ | ||
"name": "cidr-tools", | ||
"version": "3.0.6", | ||
"version": "4.0.0", | ||
"author": "silverwind <me@silverwind.io>", | ||
@@ -9,3 +9,3 @@ "description": "Tools to work with IPv4 and IPv6 CIDR network lists", | ||
"engines": { | ||
"node": ">=10" | ||
"node": ">=12.17.0" | ||
}, | ||
@@ -39,12 +39,8 @@ "keywords": [ | ||
"devDependencies": { | ||
"eslint": "8.4.1", | ||
"eslint-config-silverwind": "47.1.0", | ||
"jest": "27.4.5", | ||
"updates": "12.2.3", | ||
"versions": "9.1.1" | ||
}, | ||
"jest": { | ||
"verbose": false, | ||
"testTimeout": 30000 | ||
"eslint": "8.9.0", | ||
"eslint-config-silverwind": "48.1.0", | ||
"jest": "27.5.1", | ||
"updates": "13.0.0", | ||
"versions": "9.2.1" | ||
} | ||
} |
@@ -53,2 +53,9 @@ # cidr-tools | ||
### cidrTools.contains(networkA, networkB) | ||
- `networkA` *String*: A CIDR or IP address. | ||
- `networkB` *String*: A CIDR or IP address. | ||
Returns a boolean that indicates whether `networksA` fully contains `networksB`. | ||
### cidrTools.normalize(network) | ||
@@ -55,0 +62,0 @@ |
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
15194
334
67