cidr-tools
Advanced tools
Comparing version 6.0.1 to 6.1.0
14
index.js
@@ -25,14 +25,18 @@ import ipRegex from "ip-regex"; | ||
function doNormalize(cidr) { | ||
function doNormalize(cidr, {compress = true} = {}) { | ||
const {start, prefix, single, version} = parse(cidr); | ||
if (!single) { // cidr | ||
// set network address to first address | ||
return `${normalizeIp(stringifyIp({number: start, version}))}/${prefix}`; | ||
return `${normalizeIp(stringifyIp({number: start, version}), {compress})}/${prefix}`; | ||
} else { // single ip | ||
return normalizeIp(cidr); | ||
return normalizeIp(cidr, {compress}); | ||
} | ||
} | ||
export function normalize(cidr) { | ||
return Array.isArray(cidr) ? cidr.map(doNormalize) : doNormalize(cidr); | ||
export function normalize(cidr, {compress = true} = {}) { | ||
if (Array.isArray(cidr)) { | ||
return cidr.map(entry => normalize(entry, {compress})); | ||
} else { | ||
return doNormalize(cidr, {compress}); | ||
} | ||
} | ||
@@ -39,0 +43,0 @@ |
{ | ||
"name": "cidr-tools", | ||
"version": "6.0.1", | ||
"version": "6.1.0", | ||
"author": "silverwind <me@silverwind.io>", | ||
@@ -22,3 +22,3 @@ "description": "Tools to work with IPv4 and IPv6 CIDR network lists", | ||
"cidr-regex": "4.0.3", | ||
"ip-bigint": "7.0.2", | ||
"ip-bigint": "7.1.0", | ||
"ip-regex": "5.0.0", | ||
@@ -32,4 +32,4 @@ "string-natural-compare": "3.0.1" | ||
"versions": "11.0.1", | ||
"vitest": "0.31.3" | ||
"vitest": "0.31.4" | ||
} | ||
} |
@@ -63,8 +63,11 @@ # cidr-tools | ||
### normalize(networks) | ||
### normalize(networks, [opts]) | ||
- `networks` *String* or *Array*: One or more CIDR or IP address. | ||
Returns a string or array (depending on input) with a normalized representation of IPs or CIDRs. Will not include a prefix on single IPs. | ||
Returns a string or array (depending on input) with a normalized representation. Will not include a prefix on single IPs. | ||
`opts`: Options `Object` | ||
- `compress`: Whether to compress the IP. For IPv6, this means the "best representation" all-lowercase shortest possible form. Default: `true`. | ||
© [silverwind](https://github.com/silverwind), distributed under BSD licence. |
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
13946
346
73
+ Addedip-bigint@7.1.0(transitive)
- Removedip-bigint@7.0.2(transitive)
Updatedip-bigint@7.1.0