cidr-tools
Advanced tools
Comparing version 10.1.1 to 11.0.0
@@ -26,3 +26,3 @@ type IPv4Address = string; | ||
export declare function excludeCidr(base: Networks, excl: Networks): Network[]; | ||
export declare function expandCidr(nets: Networks): Network[]; | ||
export declare function expandCidr(nets: Networks): Generator<Network>; | ||
export declare function overlapCidr(a: Networks, b: Networks): boolean; | ||
@@ -29,0 +29,0 @@ export declare function containsCidr(a: Networks, b: Networks): boolean; |
@@ -237,12 +237,10 @@ import { ipVersion, parseIp, stringifyIp, normalizeIp } from 'ip-bigint'; | ||
} | ||
function expandCidr(nets) { | ||
function* expandCidr(nets) { | ||
const arr = uniq(Array.isArray(nets) ? nets : [nets]); | ||
const ips = []; | ||
for (const net of mergeCidr(arr)) { | ||
const { start, end, version } = parseCidr(net); | ||
for (let number = start; number <= end; number++) { | ||
ips.push(stringifyIp({ number, version })); | ||
yield normalizeCidr(stringifyIp({ number, version })); | ||
} | ||
} | ||
return ips.map((ip) => normalizeCidr(ip)); | ||
} | ||
@@ -249,0 +247,0 @@ function overlapCidr(a, b) { |
{ | ||
"name": "cidr-tools", | ||
"version": "10.1.1", | ||
"version": "11.0.0", | ||
"author": "silverwind <me@silverwind.io>", | ||
@@ -5,0 +5,0 @@ "description": "Tools to work with IPv4 and IPv6 CIDR", |
@@ -10,9 +10,22 @@ # cidr-tools | ||
mergeCidr(["1.0.0.0/24", "1.0.1.0/24"]); //=> ["1.0.0.0/23"] | ||
excludeCidr(["::1/127"], "::1/128") //=> ["::/128"] | ||
expandCidr(["2001:db8::/126"]) //=> ["2001:db8::", "2001:db8::1", "2001:db8::2", "2001:db8::3"] | ||
overlapCidr("1.0.0.0/24", "1.0.0.128/25") //=> true | ||
containsCidr(["1.0.0.0/24", "2.0.0.0/24"], "1.0.0.1") //=> true | ||
normalizeCidr("::ffff/64") //=> "::/64" | ||
parseCidr("::/64"); // => {cidr: "::/64", version: 6, prefix: "64", start: 0n, end: 18446744073709551615n} | ||
mergeCidr(["1.0.0.0/24", "1.0.1.0/24"]); | ||
//=> ["1.0.0.0/23"] | ||
excludeCidr(["::1/127"], "::1/128"); | ||
//=> ["::/128"] | ||
Array.from(expandCidr(["2001:db8::/126"])); | ||
//=> ["2001:db8::", "2001:db8::1", "2001:db8::2", "2001:db8::3"] | ||
overlapCidr("1.0.0.0/24", "1.0.0.128/25"); | ||
//=> true | ||
containsCidr(["1.0.0.0/24", "2.0.0.0/24"], "1.0.0.1"); | ||
//=> true | ||
normalizeCidr("::ffff/64"); | ||
//=> "::/64" | ||
parseCidr("::/64"); | ||
// => {cidr: "::/64", version: 6, prefix: "64", start: 0n, end: 18446744073709551615n} | ||
``` | ||
@@ -45,3 +58,3 @@ | ||
Returns an array of individual IPs contained in the networks. | ||
Returns a generator for individual IPs contained in the networks. Be aware that asking for expansions of big networks can result in long runtimes and possibly high memory usage. One million IPs takes about 2 seconds on modern hardware. | ||
@@ -48,0 +61,0 @@ ### overlapCidr(networksA, networksB) |
Sorry, the diff of this file is not supported yet
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
17524
107
329