cidr-tools 6.4.2 → 7.0.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 +2 -0
- package/index.js +8 -21
- package/package.json +3 -5
package/README.md
CHANGED
|
@@ -20,6 +20,8 @@ parse("::/64"); // => {cidr: "::/64", version: 6, prefix: "64", start: 0n, end:
|
|
|
20
20
|
|
|
21
21
|
All functions take CIDR addresses or single IP addresses. On single addresses, a prefix of `/32` or `/128` is assumed. Function that return networks will return a merged and sorted set of networks with IPv4 sorted before IPv6.
|
|
22
22
|
|
|
23
|
+
It is expected that the passed CIDRs and IPs are validated as the module's own input validation is rudimentary. You are encouraged to use modules like [is-cidr](https://github.com/silverwind/is-cidr) and [is-ip](https://github.com/sindresorhus/is-ip) to validate before passing to this module.
|
|
24
|
+
|
|
23
25
|
This module requires [BigInt](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/BigInt#browser_compatibility) support in your environment.
|
|
24
26
|
|
|
25
27
|
### merge(networks)
|
package/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import
|
|
2
|
-
import cidrRegex from "cidr-regex";
|
|
1
|
+
import {parseIp, stringifyIp, normalizeIp, ipVersion} from "ip-bigint";
|
|
3
2
|
import naturalCompare from "string-natural-compare";
|
|
4
|
-
import {parseIp, stringifyIp, normalizeIp} from "ip-bigint";
|
|
5
3
|
|
|
6
4
|
const bits = {
|
|
7
5
|
4: 32,
|
|
@@ -9,18 +7,7 @@ const bits = {
|
|
|
9
7
|
};
|
|
10
8
|
|
|
11
9
|
const uniq = arr => Array.from(new Set(arr));
|
|
12
|
-
|
|
13
|
-
export function isIP(ip) {
|
|
14
|
-
if (ipRegex.v4({exact: true}).test(ip)) return 4;
|
|
15
|
-
if (ipRegex.v6({exact: true}).test(ip)) return 6;
|
|
16
|
-
return 0;
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function isCidr(ip) {
|
|
20
|
-
if (cidrRegex.v4({exact: true}).test(ip)) return 4;
|
|
21
|
-
if (cidrRegex.v6({exact: true}).test(ip)) return 6;
|
|
22
|
-
return 0;
|
|
23
|
-
}
|
|
10
|
+
const cidrVersion = cidr => cidr.includes("/") ? ipVersion(cidr) : 0;
|
|
24
11
|
|
|
25
12
|
function doNormalize(cidr, {compress = true, hexify = false} = {}) {
|
|
26
13
|
const {start, prefix, single, version} = parse(cidr);
|
|
@@ -42,15 +29,15 @@ export function normalize(cidr, {compress = true, hexify = false} = {}) {
|
|
|
42
29
|
}
|
|
43
30
|
|
|
44
31
|
export function parse(str) {
|
|
45
|
-
const
|
|
32
|
+
const cidrVer = cidrVersion(str);
|
|
46
33
|
const parsed = Object.create(null);
|
|
47
34
|
parsed.single = false;
|
|
48
35
|
|
|
49
|
-
if (
|
|
36
|
+
if (cidrVer) {
|
|
50
37
|
parsed.cidr = str;
|
|
51
|
-
parsed.version =
|
|
38
|
+
parsed.version = cidrVer;
|
|
52
39
|
} else {
|
|
53
|
-
const version =
|
|
40
|
+
const version = ipVersion(str);
|
|
54
41
|
if (version) {
|
|
55
42
|
parsed.cidr = `${str}/${bits[version]}`;
|
|
56
43
|
parsed.version = version;
|
|
@@ -310,11 +297,11 @@ export function exclude(basenets, exclnets) {
|
|
|
310
297
|
const excls = {4: [], 6: []};
|
|
311
298
|
|
|
312
299
|
for (const basenet of basenets) {
|
|
313
|
-
bases[
|
|
300
|
+
bases[cidrVersion(basenet)].push(basenet);
|
|
314
301
|
}
|
|
315
302
|
|
|
316
303
|
for (const exclnet of exclnets) {
|
|
317
|
-
excls[
|
|
304
|
+
excls[cidrVersion(exclnet)].push(exclnet);
|
|
318
305
|
}
|
|
319
306
|
|
|
320
307
|
for (const v of [4, 6]) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cidr-tools",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "7.0.0",
|
|
4
4
|
"author": "silverwind <me@silverwind.io>",
|
|
5
5
|
"description": "Tools to work with IPv4 and IPv6 CIDR",
|
|
6
6
|
"repository": "silverwind/cidr-tools",
|
|
@@ -11,21 +11,19 @@
|
|
|
11
11
|
"types": "./index.d.ts",
|
|
12
12
|
"sideEffects": false,
|
|
13
13
|
"engines": {
|
|
14
|
-
"node": ">=
|
|
14
|
+
"node": ">=18"
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"./index.js",
|
|
18
18
|
"./index.d.ts"
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
|
-
"cidr-regex": "4.0.3",
|
|
22
21
|
"ip-bigint": "7.3.0",
|
|
23
|
-
"ip-regex": "5.0.0",
|
|
24
22
|
"string-natural-compare": "3.0.1"
|
|
25
23
|
},
|
|
26
24
|
"devDependencies": {
|
|
27
25
|
"eslint": "8.49.0",
|
|
28
|
-
"eslint-config-silverwind": "
|
|
26
|
+
"eslint-config-silverwind": "75.0.6",
|
|
29
27
|
"tsd": "0.29.0",
|
|
30
28
|
"updates": "15.0.2",
|
|
31
29
|
"versions": "11.1.0",
|