cidr-tools 7.0.0 → 7.0.1

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.
Files changed (2) hide show
  1. package/index.js +14 -4
  2. package/package.json +5 -6
package/index.js CHANGED
@@ -1,5 +1,4 @@
1
1
  import {parseIp, stringifyIp, normalizeIp, ipVersion} from "ip-bigint";
2
- import naturalCompare from "string-natural-compare";
3
2
 
4
3
  const bits = {
5
4
  4: 32,
@@ -9,6 +8,17 @@ const bits = {
9
8
  const uniq = arr => Array.from(new Set(arr));
10
9
  const cidrVersion = cidr => cidr.includes("/") ? ipVersion(cidr) : 0;
11
10
 
11
+ // TODO: pass parsed objects in here
12
+ function compare(a, b) {
13
+ const {number: aNum, version: aVersion} = parseIp(a.replace(/\/.+/, ""));
14
+ const {number: bNum, version: bVersion} = parseIp(b.replace(/\/.+/, ""));
15
+ if (aVersion === bVersion) {
16
+ return aNum - bNum > 0n ? 1 : aNum - bNum < 0n ? -1 : 0;
17
+ } else {
18
+ return aVersion > bVersion;
19
+ }
20
+ }
21
+
12
22
  function doNormalize(cidr, {compress = true, hexify = false} = {}) {
13
23
  const {start, prefix, single, version} = parse(cidr);
14
24
  if (!single) { // cidr
@@ -253,7 +263,7 @@ export function merge(nets) {
253
263
  const end = {4: null, 6: null};
254
264
 
255
265
  for (const v of [4, 6]) {
256
- const numbers = Object.keys(maps[v]).sort(naturalCompare);
266
+ const numbers = Object.keys(maps[v]);
257
267
  let depth = 0;
258
268
 
259
269
  for (const [index, number] of numbers.entries()) {
@@ -283,7 +293,7 @@ export function merge(nets) {
283
293
  }
284
294
  }
285
295
 
286
- return [...merged[4].sort(naturalCompare), ...merged[6].sort(naturalCompare)];
296
+ return [...merged[4].sort(compare), ...merged[6].sort(compare)];
287
297
  }
288
298
 
289
299
  export function exclude(basenets, exclnets) {
@@ -318,7 +328,7 @@ export function exclude(basenets, exclnets) {
318
328
  }
319
329
  }
320
330
 
321
- return bases[4].concat(bases[6]);
331
+ return bases[4].concat(bases[6]).sort(compare);
322
332
  }
323
333
 
324
334
  export function expand(nets) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cidr-tools",
3
- "version": "7.0.0",
3
+ "version": "7.0.1",
4
4
  "author": "silverwind <me@silverwind.io>",
5
5
  "description": "Tools to work with IPv4 and IPv6 CIDR",
6
6
  "repository": "silverwind/cidr-tools",
@@ -18,16 +18,15 @@
18
18
  "./index.d.ts"
19
19
  ],
20
20
  "dependencies": {
21
- "ip-bigint": "7.3.0",
22
- "string-natural-compare": "3.0.1"
21
+ "ip-bigint": "7.3.0"
23
22
  },
24
23
  "devDependencies": {
25
- "eslint": "8.49.0",
26
- "eslint-config-silverwind": "75.0.6",
24
+ "eslint": "8.50.0",
25
+ "eslint-config-silverwind": "76.0.2",
27
26
  "tsd": "0.29.0",
28
27
  "updates": "15.0.2",
29
28
  "versions": "11.1.0",
30
- "vitest": "0.34.4",
29
+ "vitest": "0.34.5",
31
30
  "vitest-config-silverwind": "3.0.0"
32
31
  }
33
32
  }