cidr-tools
Advanced tools
Comparing version 10.0.0 to 10.0.1
@@ -7,7 +7,7 @@ type IPv4Address = string; | ||
type Networks = Network | Network[]; | ||
type IpVersion = 4 | 6 | 0; | ||
type ValidIpVersion = 4 | 6; | ||
type ParsedCidr = { | ||
cidr: string; | ||
ip: string; | ||
version: IpVersion; | ||
version: ValidIpVersion; | ||
prefix: string; | ||
@@ -21,7 +21,8 @@ start: bigint; | ||
}; | ||
export declare function normalizeCidr(cidr: Networks, { compress, hexify }?: NormalizeOpts): Networks; | ||
export declare function normalizeCidr(cidr: Network, opts?: NormalizeOpts): Network; | ||
export declare function normalizeCidr(cidr: Network[], opts?: NormalizeOpts): Network[]; | ||
export declare function parseCidr(str: Network): ParsedCidr; | ||
export declare function mergeCidr(nets: Networks): Network[]; | ||
export declare function excludeCidr(basenets: Networks, exclnets: Networks): any[]; | ||
export declare function expandCidr(nets: Networks): Networks[]; | ||
export declare function excludeCidr(base: Networks, excl: Networks): string[]; | ||
export declare function expandCidr(nets: Networks): string[]; | ||
export declare function overlapCidr(a: Networks, b: Networks): boolean; | ||
@@ -28,0 +29,0 @@ export declare function containsCidr(a: Networks, b: Networks): boolean; |
@@ -28,7 +28,7 @@ import { ipVersion, parseIp, stringifyIp, normalizeIp } from 'ip-bigint'; | ||
} | ||
function normalizeCidr(cidr, { compress = true, hexify = false } = {}) { | ||
function normalizeCidr(cidr, opts) { | ||
if (Array.isArray(cidr)) { | ||
return cidr.map((entry) => normalizeCidr(entry, { compress, hexify })); | ||
return cidr.map((entry) => normalizeCidr(entry, opts)); | ||
} else { | ||
return doNormalize(cidr, { compress, hexify }); | ||
return doNormalize(cidr, opts); | ||
} | ||
@@ -128,3 +128,4 @@ } | ||
let biggest = biggestPowerOfTwo(size); | ||
let start, end; | ||
let start; | ||
let end; | ||
if (size === biggest && part.start + size === part.end) { | ||
@@ -171,15 +172,15 @@ return [part]; | ||
for (const { start, end, version } of nets) { | ||
if (!maps[version][start]) | ||
maps[version][start] = {}; | ||
if (!maps[version][end]) | ||
maps[version][end] = {}; | ||
if (maps[version][start].start) { | ||
maps[version][start].start += 1; | ||
if (!maps[version][String(start)]) | ||
maps[version][String(start)] = {}; | ||
if (!maps[version][String(end)]) | ||
maps[version][String(end)] = {}; | ||
if (maps[version][String(start)].start) { | ||
maps[version][String(start)].start += 1; | ||
} else { | ||
maps[version][start].start = 1; | ||
maps[version][String(start)].start = 1; | ||
} | ||
if (maps[version][end].end) { | ||
maps[version][end].end += 1; | ||
if (maps[version][String(end)].end) { | ||
maps[version][String(end)].end += 1; | ||
} else { | ||
maps[version][end].end = 1; | ||
maps[version][String(end)].end = 1; | ||
} | ||
@@ -196,3 +197,3 @@ } | ||
for (const [index, number] of numbers.entries()) { | ||
const marker = maps[number]; | ||
const marker = maps[String(number)]; | ||
if (start === null && marker.start) { | ||
@@ -232,14 +233,16 @@ start = BigInt(number); | ||
} | ||
function excludeCidr(basenets, exclnets) { | ||
basenets = uniq(Array.isArray(basenets) ? basenets : [basenets]); | ||
exclnets = uniq(Array.isArray(exclnets) ? exclnets : [exclnets]); | ||
basenets = mergeCidr(basenets); | ||
exclnets = mergeCidr(exclnets); | ||
function excludeCidr(base, excl) { | ||
const basenets = mergeCidr(uniq(Array.isArray(base) ? base : [base])); | ||
const exclnets = mergeCidr(uniq(Array.isArray(excl) ? excl : [excl])); | ||
const bases = { 4: [], 6: [] }; | ||
const excls = { 4: [], 6: [] }; | ||
for (const basenet of basenets) { | ||
bases[cidrVersion(basenet)].push(basenet); | ||
const version = cidrVersion(basenet); | ||
if (version) | ||
bases[version].push(basenet); | ||
} | ||
for (const exclnet of exclnets) { | ||
excls[cidrVersion(exclnet)].push(exclnet); | ||
const version = cidrVersion(exclnet); | ||
if (version) | ||
excls[version].push(exclnet); | ||
} | ||
@@ -249,6 +252,6 @@ for (const v of [4, 6]) { | ||
for (const [index, basecidr] of bases[v].entries()) { | ||
const base = parseCidr(basecidr); | ||
const excl = parseCidr(exclcidr); | ||
const remainders = excludeNets(base, excl, v); | ||
if (base.cidr !== remainders.toString()) { | ||
const base2 = parseCidr(basecidr); | ||
const excl2 = parseCidr(exclcidr); | ||
const remainders = excludeNets(base2, excl2, v); | ||
if (base2.cidr !== remainders.toString()) { | ||
bases[v] = bases[v].concat(remainders); | ||
@@ -263,5 +266,5 @@ bases[v].splice(index, 1); | ||
function expandCidr(nets) { | ||
nets = uniq(Array.isArray(nets) ? nets : [nets]); | ||
const arr = uniq(Array.isArray(nets) ? nets : [nets]); | ||
const ips = []; | ||
for (const net of mergeCidr(nets)) { | ||
for (const net of mergeCidr(arr)) { | ||
const { start, end, version } = parseCidr(net); | ||
@@ -268,0 +271,0 @@ for (let number = start; number <= end; number++) { |
{ | ||
"name": "cidr-tools", | ||
"version": "10.0.0", | ||
"version": "10.0.1", | ||
"author": "silverwind <me@silverwind.io>", | ||
@@ -25,10 +25,9 @@ "description": "Tools to work with IPv4 and IPv6 CIDR", | ||
"eslint": "8.57.0", | ||
"eslint-config-silverwind": "85.1.4", | ||
"eslint-config-silverwind-typescript": "3.2.7", | ||
"typescript-config-silverwind": "4.3.1", | ||
"eslint-config-silverwind": "85.1.5", | ||
"eslint-config-silverwind-typescript": "3.2.8", | ||
"typescript-config-silverwind": "4.4.0", | ||
"updates": "16.1.1", | ||
"versions": "12.0.2", | ||
"vite": "5.2.11", | ||
"vite-config-silverwind": "1.0.3", | ||
"vite-plugin-dts": "3.9.1", | ||
"versions": "12.1.2", | ||
"vite": "5.2.12", | ||
"vite-config-silverwind": "2.1.4", | ||
"vitest": "1.6.0", | ||
@@ -35,0 +34,0 @@ "vitest-config-silverwind": "9.0.6" |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
16155
11
352
0