cidr-tools
Advanced tools
Comparing version 10.0.1 to 10.1.0
@@ -13,2 +13,3 @@ type IPv4Address = string; | ||
prefix: string; | ||
prefixPresent: boolean; | ||
start: bigint; | ||
@@ -39,1 +40,2 @@ end: bigint; | ||
export default _default; | ||
//# sourceMappingURL=index.d.ts.map |
@@ -20,4 +20,4 @@ import { ipVersion, parseIp, stringifyIp, normalizeIp } from 'ip-bigint'; | ||
function doNormalize(cidr, { compress = true, hexify = false } = {}) { | ||
const { start, end, prefix, version } = parseCidr(cidr); | ||
if (start !== end) { | ||
const { start, end, prefix, version, prefixPresent } = parseCidr(cidr); | ||
if (start !== end || prefixPresent) { | ||
const ip = normalizeIp(stringifyIp({ number: start, version }), { compress, hexify }); | ||
@@ -60,2 +60,3 @@ return `${ip}/${prefix}`; | ||
parsed.prefix = prefix; | ||
parsed.prefixPresent = Boolean(cidrVer); | ||
const numBits = bits[version]; | ||
@@ -70,13 +71,9 @@ const ipBits = number.toString(2).padStart(numBits, "0"); | ||
function doNetsOverlap(a, b) { | ||
if (a.start > b.end) | ||
return false; | ||
if (b.start > a.end) | ||
return false; | ||
if (a.start > b.end) return false; | ||
if (b.start > a.end) return false; | ||
return true; | ||
} | ||
function netContains(a, b) { | ||
if (b.start < a.start) | ||
return false; | ||
if (b.end > a.end) | ||
return false; | ||
if (b.start < a.start) return false; | ||
if (b.end > a.end) return false; | ||
return true; | ||
@@ -116,4 +113,3 @@ } | ||
function biggestPowerOfTwo(num) { | ||
if (num === 0n) | ||
return 0n; | ||
if (num === 0n) return 0n; | ||
return 2n ** BigInt(String(num.toString(2).length - 1)); | ||
@@ -174,16 +170,6 @@ } | ||
for (const { start, end, version } of nets) { | ||
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][String(start)].start = 1; | ||
} | ||
if (maps[version][String(end)].end) { | ||
maps[version][String(end)].end += 1; | ||
} else { | ||
maps[version][String(end)].end = 1; | ||
} | ||
if (!maps[version][String(start)]) maps[version][String(start)] = { start: 0, end: 0 }; | ||
if (!maps[version][String(end)]) maps[version][String(end)] = { start: 0, end: 0 }; | ||
maps[version][String(start)].start += 1; | ||
maps[version][String(end)].end += 1; | ||
} | ||
@@ -200,12 +186,7 @@ return maps; | ||
const marker = maps[String(number)]; | ||
if (start === null && marker.start) { | ||
start = BigInt(number); | ||
} | ||
if (marker.end) { | ||
end = BigInt(number); | ||
} | ||
if (marker.start) | ||
depth += marker.start; | ||
if (marker.end) | ||
depth -= marker.end; | ||
if (start === null && marker.start) start = BigInt(number); | ||
if (marker.end) end = BigInt(number); | ||
if (start === null) continue; | ||
if (marker.start) depth += marker.start; | ||
if (marker.end) depth -= marker.end; | ||
const next = numbers[index + 1]; | ||
@@ -242,9 +223,7 @@ if (marker.end && depth === 0 && next && BigInt(next) - BigInt(number) > 1) { | ||
const version = cidrVersion(basenet); | ||
if (version) | ||
bases[version].push(basenet); | ||
if (version) bases[version].push(basenet); | ||
} | ||
for (const exclnet of exclnets) { | ||
const version = cidrVersion(exclnet); | ||
if (version) | ||
excls[version].push(exclnet); | ||
if (version) excls[version].push(exclnet); | ||
} | ||
@@ -251,0 +230,0 @@ for (const v of [4, 6]) { |
{ | ||
"name": "cidr-tools", | ||
"version": "10.0.1", | ||
"version": "10.1.0", | ||
"author": "silverwind <me@silverwind.io>", | ||
@@ -20,17 +20,17 @@ "description": "Tools to work with IPv4 and IPv6 CIDR", | ||
"dependencies": { | ||
"ip-bigint": "^8.1.0" | ||
"ip-bigint": "^8.1.1" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "20.12.12", | ||
"@types/node": "20.14.10", | ||
"eslint": "8.57.0", | ||
"eslint-config-silverwind": "85.1.5", | ||
"eslint-config-silverwind-typescript": "3.2.8", | ||
"typescript-config-silverwind": "4.4.0", | ||
"updates": "16.1.1", | ||
"eslint-config-silverwind": "88.2.4", | ||
"eslint-config-silverwind-typescript": "5.1.3", | ||
"typescript-config-silverwind": "5.1.3", | ||
"updates": "16.2.1", | ||
"versions": "12.1.2", | ||
"vite": "5.2.12", | ||
"vite-config-silverwind": "2.1.4", | ||
"vitest": "1.6.0", | ||
"vitest-config-silverwind": "9.0.6" | ||
"vite": "5.3.3", | ||
"vite-config-silverwind": "3.0.0", | ||
"vitest": "2.0.1", | ||
"vitest-config-silverwind": "9.1.0" | ||
} | ||
} |
@@ -81,2 +81,3 @@ # cidr-tools | ||
- `prefix` String: The network prefix, e.g. `64`. | ||
- `prefixPresent` Boolean: Whether the passed string has a network prefix. | ||
- `start` BigInt: Start number of the network. | ||
@@ -83,0 +84,0 @@ - `end` BigInt: End number of the 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
17344
5
94
332
Updatedip-bigint@^8.1.1