cidr-tools
Advanced tools
Comparing version 4.0.0 to 4.1.0
@@ -16,3 +16,3 @@ type IPv4Address = string; | ||
normalize(cidr: Network): Network; | ||
contains(networkA: Network, networkB: Network): boolean; | ||
contains(networksA: Networks, networksB: Networks): boolean; | ||
} | ||
@@ -19,0 +19,0 @@ |
26
index.js
@@ -378,11 +378,25 @@ "use strict"; | ||
module.exports.contains = (a, b) => { | ||
const aParsed = parse(a); | ||
const bParsed = parse(b); | ||
const aNets = uniq(Array.isArray(a) ? a : [a]); | ||
const bNets = uniq(Array.isArray(b) ? b : [b]); | ||
// version mismatch | ||
if (aParsed.address.v4 !== bParsed.address.v4) { | ||
return false; | ||
const numExpected = bNets.length; | ||
let numFound = 0; | ||
for (const a of aNets) { | ||
const aParsed = parse(a); | ||
for (const b of bNets) { | ||
const bParsed = parse(b); | ||
// version mismatch | ||
if (aParsed.address.v4 !== bParsed.address.v4) { | ||
continue; | ||
} | ||
if (contains(aParsed, bParsed)) { | ||
numFound++; | ||
continue; | ||
} | ||
} | ||
} | ||
return contains(aParsed, bParsed); | ||
return numFound === numExpected; | ||
}; |
{ | ||
"name": "cidr-tools", | ||
"version": "4.0.0", | ||
"version": "4.1.0", | ||
"author": "silverwind <me@silverwind.io>", | ||
@@ -5,0 +5,0 @@ "description": "Tools to work with IPv4 and IPv6 CIDR network lists", |
@@ -55,6 +55,6 @@ # cidr-tools | ||
- `networkA` *String*: A CIDR or IP address. | ||
- `networkB` *String*: A CIDR or IP address. | ||
- `networksA` *String* or *Array*: One or more CIDR or IP address. | ||
- `networksB` *String* or *Array*: One or more CIDR or IP address. | ||
Returns a boolean that indicates whether `networksA` fully contains `networksB`. | ||
Returns a boolean that indicates whether `networksA` fully contain all `networksB`. | ||
@@ -61,0 +61,0 @@ ### cidrTools.normalize(network) |
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
15571
346