cidr-tools 13.0.1 → 13.0.2

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/dist/index.d.ts CHANGED
@@ -22,19 +22,19 @@ type NormalizeOpts = {
22
22
  hexify?: boolean;
23
23
  };
24
24
  /** Returns a string or array (depending on input) with a normalized representation. Will not include a prefix on single IPs. Will set network address to the start of the network. */
25
- declare function normalizeCidr<T extends Networks>(cidr: T, opts?: NormalizeOpts): T;
25
+ export declare function normalizeCidr<T extends Networks>(cidr: T, opts?: NormalizeOpts): T;
26
26
  /** Returns a `parsed` Object which is used internally by this module. It can be used to test whether the passed network is IPv4 or IPv6 or to work with the BigInts directly. */
27
- declare function parseCidr(str: Network, opts?: CidrOpts): ParsedCidr;
27
+ export declare function parseCidr(str: Network, opts?: CidrOpts): ParsedCidr;
28
28
  /** Returns an array of merged networks */
29
- declare function mergeCidr(nets: Networks, opts?: CidrOpts): Array<Network>;
29
+ export declare function mergeCidr(nets: Networks, opts?: CidrOpts): Array<Network>;
30
30
  /** Returns an array of merged remaining networks of the subtraction of `excludeNetworks` from `baseNetworks`. */
31
- declare function excludeCidr(base: Networks, excl: Networks, opts?: CidrOpts): Array<Network>;
31
+ export declare function excludeCidr(base: Networks, excl: Networks, opts?: CidrOpts): Array<Network>;
32
32
  /** Returns a generator for individual IPs contained in the networks. */
33
- declare function expandCidr(nets: Networks, opts?: CidrOpts): Generator<Network>;
33
+ export declare function expandCidr(nets: Networks, opts?: CidrOpts): Generator<Network>;
34
34
  /** Returns a boolean that indicates if `networksA` overlap (intersect) with `networksB`. */
35
- declare function overlapCidr(a: Networks, b: Networks, opts?: CidrOpts): boolean;
35
+ export declare function overlapCidr(a: Networks, b: Networks, opts?: CidrOpts): boolean;
36
36
  /** Returns a boolean that indicates whether `networksA` fully contain all `networksB`. */
37
- declare function containsCidr(a: Networks, b: Networks, opts?: CidrOpts): boolean;
37
+ export declare function containsCidr(a: Networks, b: Networks, opts?: CidrOpts): boolean;
38
38
  declare const _default: {
39
39
  mergeCidr: typeof mergeCidr;
40
40
  excludeCidr: typeof excludeCidr;
@@ -45,4 +45,4 @@ declare const _default: {
45
45
  parseCidr: typeof parseCidr;
46
46
  };
47
47
  //#endregion
48
- export { containsCidr, _default as default, excludeCidr, expandCidr, mergeCidr, normalizeCidr, overlapCidr, parseCidr };
48
+ export { _default as default };
package/dist/index.js CHANGED
@@ -135,10 +135,11 @@ function doNormalize(cidr, opts) {
135
135
  hexify
136
136
  });
137
137
  const start = hostBits > 0 ? number & hostNotMasks[hostBits] : number;
138
+ const startMapped = ipv4mapped && start >> 32n === 65535n;
138
139
  return stringifyIp({
139
140
  number: start,
140
141
  version,
141
- ipv4mapped: ipv4mapped && start >> 32n === 65535n,
142
+ ipv4mapped: startMapped,
142
143
  scopeid
143
144
  }, {
144
145
  compress,
@@ -487,32 +488,36 @@ function overlapCidr(a, b, opts) {
487
488
  if (net.version === 4) v4b.push(net);
488
489
  else v6b.push(net);
489
490
  }
490
- if (v4a.length > 0 && v4b.length > 0) if (v4a.length === 1 || v4b.length === 1) {
491
- const bIsSingle = v4b.length === 1;
492
- const one = bIsSingle ? v4b[0] : v4a[0];
493
- for (const el of bIsSingle ? v4a : v4b) if (one.start <= el.end && el.start <= one.end) return true;
494
- } else {
495
- v4a.sort(cmpV4Start);
496
- v4b.sort(cmpV4Start);
497
- let i = 0, j = 0;
498
- while (i < v4a.length && j < v4b.length) {
499
- if (v4a[i].start <= v4b[j].end && v4b[j].start <= v4a[i].end) return true;
500
- if (v4a[i].end < v4b[j].end) i++;
501
- else j++;
491
+ if (v4a.length > 0 && v4b.length > 0) {
492
+ if (v4a.length === 1 || v4b.length === 1) {
493
+ const bIsSingle = v4b.length === 1;
494
+ const one = bIsSingle ? v4b[0] : v4a[0];
495
+ for (const el of bIsSingle ? v4a : v4b) if (one.start <= el.end && el.start <= one.end) return true;
496
+ } else {
497
+ v4a.sort(cmpV4Start);
498
+ v4b.sort(cmpV4Start);
499
+ let i = 0, j = 0;
500
+ while (i < v4a.length && j < v4b.length) {
501
+ if (v4a[i].start <= v4b[j].end && v4b[j].start <= v4a[i].end) return true;
502
+ if (v4a[i].end < v4b[j].end) i++;
503
+ else j++;
504
+ }
502
505
  }
503
506
  }
504
- if (v6a.length > 0 && v6b.length > 0) if (v6a.length === 1 || v6b.length === 1) {
505
- const bIsSingle = v6b.length === 1;
506
- const one = bIsSingle ? v6b[0] : v6a[0];
507
- for (const el of bIsSingle ? v6a : v6b) if (one.start <= el.end && el.start <= one.end) return true;
508
- } else {
509
- v6a.sort(cmpV6Start);
510
- v6b.sort(cmpV6Start);
511
- let i = 0, j = 0;
512
- while (i < v6a.length && j < v6b.length) {
513
- if (v6a[i].start <= v6b[j].end && v6b[j].start <= v6a[i].end) return true;
514
- if (v6a[i].end < v6b[j].end) i++;
515
- else j++;
507
+ if (v6a.length > 0 && v6b.length > 0) {
508
+ if (v6a.length === 1 || v6b.length === 1) {
509
+ const bIsSingle = v6b.length === 1;
510
+ const one = bIsSingle ? v6b[0] : v6a[0];
511
+ for (const el of bIsSingle ? v6a : v6b) if (one.start <= el.end && el.start <= one.end) return true;
512
+ } else {
513
+ v6a.sort(cmpV6Start);
514
+ v6b.sort(cmpV6Start);
515
+ let i = 0, j = 0;
516
+ while (i < v6a.length && j < v6b.length) {
517
+ if (v6a[i].start <= v6b[j].end && v6b[j].start <= v6a[i].end) return true;
518
+ if (v6a[i].end < v6b[j].end) i++;
519
+ else j++;
520
+ }
516
521
  }
517
522
  }
518
523
  return false;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cidr-tools",
3
- "version": "13.0.1",
3
+ "version": "13.0.2",
4
4
  "author": "silverwind <me@silverwind.io>",
5
5
  "description": "Tools to work with IPv4 and IPv6 CIDR",
6
6
  "keywords": [
@@ -13,7 +13,7 @@
13
13
  ],
14
14
  "repository": {
15
15
  "type": "git",
16
- "url": "silverwind/cidr-tools"
16
+ "url": "git+https://github.com/silverwind/cidr-tools.git"
17
17
  },
18
18
  "license": "BSD-2-Clause",
19
19
  "type": "module",
@@ -29,24 +29,24 @@
29
29
  "bun": "*"
30
30
  },
31
31
  "dependencies": {
32
- "cidr-regex": "^7.1.0",
32
+ "cidr-regex": "^7.1.1",
33
33
  "ip-bigint": "^10.0.1"
34
34
  },
35
35
  "devDependencies": {
36
- "@types/node": "26.1.2",
36
+ "@types/node": "26.6.2",
37
37
  "@typescript/native-preview": "7.0.0-dev.20260707.2",
38
- "@vitest/coverage-v8": "4.1.10",
39
- "eslint": "10.8.0",
40
- "eslint-config-silverwind": "143.0.0",
38
+ "@vitest/coverage-v8": "5.0.2",
39
+ "eslint": "10.11.0",
40
+ "eslint-config-silverwind": "151.0.1",
41
41
  "jest-extended": "7.0.0",
42
- "tsdown": "0.22.14",
43
- "tsdown-config-silverwind": "4.0.3",
42
+ "tsdown": "0.23.0",
43
+ "tsdown-config-silverwind": "4.1.2",
44
44
  "typescript": "6.0.3",
45
- "typescript-config-silverwind": "20.0.3",
46
- "updates": "17.19.2",
47
- "updates-config-silverwind": "4.0.4",
48
- "versions": "15.1.4",
49
- "vitest": "4.1.10",
50
- "vitest-config-silverwind": "11.4.0"
45
+ "typescript-config-silverwind": "21.0.1",
46
+ "updates": "19.0.0",
47
+ "updates-config-silverwind": "4.0.7",
48
+ "versions": "15.5.1",
49
+ "vitest": "5.0.2",
50
+ "vitest-config-silverwind": "12.0.4"
51
51
  }
52
52
  }