cidr-tools 6.0.1 → 6.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -2
- package/index.js +10 -5
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -60,10 +60,14 @@ Returns a boolean that indicates if `networksA` overlap (intersect) with `networ
|
|
|
60
60
|
|
|
61
61
|
Returns a boolean that indicates whether `networksA` fully contain all `networksB`.
|
|
62
62
|
|
|
63
|
-
### normalize(networks)
|
|
63
|
+
### normalize(networks, [opts])
|
|
64
64
|
|
|
65
65
|
- `networks` *String* or *Array*: One or more CIDR or IP address.
|
|
66
66
|
|
|
67
|
-
Returns a string or array (depending on input) with a normalized representation
|
|
67
|
+
Returns a string or array (depending on input) with a normalized representation. Will not include a prefix on single IPs.
|
|
68
|
+
|
|
69
|
+
`opts`: Options `Object`
|
|
70
|
+
- `compress`: Whether to compress the IP. For IPv6, this means the "best representation" all-lowercase shortest possible form. Default: `true`.
|
|
71
|
+
- `hexify`: Whether to convert IPv4-Mapped IPv6 addresses to hex. Default: `false`.
|
|
68
72
|
|
|
69
73
|
© [silverwind](https://github.com/silverwind), distributed under BSD licence.
|
package/index.js
CHANGED
|
@@ -22,18 +22,23 @@ function isCidr(ip) {
|
|
|
22
22
|
return 0;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
function doNormalize(cidr) {
|
|
25
|
+
function doNormalize(cidr, {compress = true, hexify = false} = {}) {
|
|
26
26
|
const {start, prefix, single, version} = parse(cidr);
|
|
27
27
|
if (!single) { // cidr
|
|
28
28
|
// set network address to first address
|
|
29
|
-
|
|
29
|
+
const ip = normalizeIp(stringifyIp({number: start, version}), {compress, hexify});
|
|
30
|
+
return `${ip}/${prefix}`;
|
|
30
31
|
} else { // single ip
|
|
31
|
-
return normalizeIp(cidr);
|
|
32
|
+
return normalizeIp(cidr, {compress, hexify});
|
|
32
33
|
}
|
|
33
34
|
}
|
|
34
35
|
|
|
35
|
-
export function normalize(cidr) {
|
|
36
|
-
|
|
36
|
+
export function normalize(cidr, {compress = true, hexify = false} = {}) {
|
|
37
|
+
if (Array.isArray(cidr)) {
|
|
38
|
+
return cidr.map(entry => normalize(entry, {compress, hexify}));
|
|
39
|
+
} else {
|
|
40
|
+
return doNormalize(cidr, {compress, hexify});
|
|
41
|
+
}
|
|
37
42
|
}
|
|
38
43
|
|
|
39
44
|
function parse(str) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cidr-tools",
|
|
3
|
-
"version": "6.0
|
|
3
|
+
"version": "6.2.0",
|
|
4
4
|
"author": "silverwind <me@silverwind.io>",
|
|
5
5
|
"description": "Tools to work with IPv4 and IPv6 CIDR network lists",
|
|
6
6
|
"repository": "silverwind/cidr-tools",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"cidr-regex": "4.0.3",
|
|
22
|
-
"ip-bigint": "7.0
|
|
22
|
+
"ip-bigint": "7.2.0",
|
|
23
23
|
"ip-regex": "5.0.0",
|
|
24
24
|
"string-natural-compare": "3.0.1"
|
|
25
25
|
},
|
|
@@ -28,6 +28,6 @@
|
|
|
28
28
|
"eslint-config-silverwind": "73.0.0",
|
|
29
29
|
"updates": "14.1.1",
|
|
30
30
|
"versions": "11.0.1",
|
|
31
|
-
"vitest": "0.31.
|
|
31
|
+
"vitest": "0.31.4"
|
|
32
32
|
}
|
|
33
33
|
}
|