cidr-tools
Advanced tools
Comparing version 6.1.0 to 6.2.0
13
index.js
@@ -25,17 +25,18 @@ import ipRegex from "ip-regex"; | ||
function doNormalize(cidr, {compress = true} = {}) { | ||
function doNormalize(cidr, {compress = true, hexify = false} = {}) { | ||
const {start, prefix, single, version} = parse(cidr); | ||
if (!single) { // cidr | ||
// set network address to first address | ||
return `${normalizeIp(stringifyIp({number: start, version}), {compress})}/${prefix}`; | ||
const ip = normalizeIp(stringifyIp({number: start, version}), {compress, hexify}); | ||
return `${ip}/${prefix}`; | ||
} else { // single ip | ||
return normalizeIp(cidr, {compress}); | ||
return normalizeIp(cidr, {compress, hexify}); | ||
} | ||
} | ||
export function normalize(cidr, {compress = true} = {}) { | ||
export function normalize(cidr, {compress = true, hexify = false} = {}) { | ||
if (Array.isArray(cidr)) { | ||
return cidr.map(entry => normalize(entry, {compress})); | ||
return cidr.map(entry => normalize(entry, {compress, hexify})); | ||
} else { | ||
return doNormalize(cidr, {compress}); | ||
return doNormalize(cidr, {compress, hexify}); | ||
} | ||
@@ -42,0 +43,0 @@ } |
{ | ||
"name": "cidr-tools", | ||
"version": "6.1.0", | ||
"version": "6.2.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.1.0", | ||
"ip-bigint": "7.2.0", | ||
"ip-regex": "5.0.0", | ||
@@ -25,0 +25,0 @@ "string-natural-compare": "3.0.1" |
@@ -71,3 +71,4 @@ # cidr-tools | ||
- `compress`: Whether to compress the IP. For IPv6, this means the "best representation" all-lowercase shortest possible form. Default: `true`. | ||
- `hexify`: Whether to convert IPv4-Mapped IPv6 addresses to hex. Default: `false`. | ||
© [silverwind](https://github.com/silverwind), distributed under BSD licence. |
14115
347
74
+ Addedip-bigint@7.2.0(transitive)
- Removedip-bigint@7.1.0(transitive)
Updatedip-bigint@7.2.0