cidr-tools 12.0.3 → 12.1.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/dist/index.d.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region index.d.ts
2
2
  type Network = string;
3
- type Networks = Network | Array<Network>;
3
+ type Networks = Network | ReadonlyArray<Network>;
4
4
  type ValidIpVersion = 4 | 6;
5
5
  type ParsedCidr = {
6
6
  cidr: string;
@@ -16,7 +16,7 @@ type NormalizeOpts = {
16
16
  hexify?: boolean;
17
17
  };
18
18
  /** 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. */
19
- declare function normalizeCidr<T extends Network | Array<Network>>(cidr: T, opts?: NormalizeOpts): T;
19
+ declare function normalizeCidr<T extends Networks>(cidr: T, opts?: NormalizeOpts): T;
20
20
  /** 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. */
21
21
  declare function parseCidr(str: Network): ParsedCidr;
22
22
  /** Returns an array of merged networks */
package/dist/index.js CHANGED
@@ -107,7 +107,7 @@ function doNormalize(cidr, opts) {
107
107
  }
108
108
  /** 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. */
109
109
  function normalizeCidr(cidr, opts) {
110
- return Array.isArray(cidr) ? cidr.map((entry) => doNormalize(entry, opts)) : doNormalize(cidr, opts);
110
+ return typeof cidr === "string" ? doNormalize(cidr, opts) : cidr.map((entry) => doNormalize(entry, opts));
111
111
  }
112
112
  /** 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. */
113
113
  function parseCidr(str) {
@@ -362,7 +362,7 @@ function subtractSorted6(bases, excls) {
362
362
  }
363
363
  /** Returns an array of merged networks */
364
364
  function mergeCidr(nets) {
365
- const arr = Array.isArray(nets) ? nets : [nets];
365
+ const arr = typeof nets === "string" ? [nets] : nets;
366
366
  const v4 = [];
367
367
  const v6 = [];
368
368
  for (const s of arr) {
@@ -377,8 +377,8 @@ function mergeCidr(nets) {
377
377
  }
378
378
  /** Returns an array of merged remaining networks of the subtraction of `excludeNetworks` from `baseNetworks`. */
379
379
  function excludeCidr(base, excl) {
380
- const baseArr = Array.isArray(base) ? base : [base];
381
- const exclArr = Array.isArray(excl) ? excl : [excl];
380
+ const baseArr = typeof base === "string" ? [base] : base;
381
+ const exclArr = typeof excl === "string" ? [excl] : excl;
382
382
  const v4base = [], v6base = [];
383
383
  const v4excl = [], v6excl = [];
384
384
  for (const s of baseArr) {
@@ -406,7 +406,7 @@ function excludeCidr(base, excl) {
406
406
  }
407
407
  /** Returns a generator for individual IPs contained in the networks. */
408
408
  function* expandCidr(nets) {
409
- const arr = Array.isArray(nets) ? nets : [nets];
409
+ const arr = typeof nets === "string" ? [nets] : nets;
410
410
  const v4 = [];
411
411
  const v6 = [];
412
412
  for (const s of arr) {
@@ -455,7 +455,7 @@ function* expandCidr(nets) {
455
455
  }
456
456
  /** Returns a boolean that indicates if `networksA` overlap (intersect) with `networksB`. */
457
457
  function overlapCidr(a, b) {
458
- if (!Array.isArray(a) && !Array.isArray(b)) {
458
+ if (typeof a === "string" && typeof b === "string") {
459
459
  if (parseIPv4Range(a)) {
460
460
  const startA = rangeV4Start, endA = rangeV4End;
461
461
  if (parseIPv4Range(b)) return startA <= rangeV4End && rangeV4Start <= endA;
@@ -468,8 +468,8 @@ function overlapCidr(a, b) {
468
468
  if (pa.version !== pb.version) return false;
469
469
  return pa.start <= pb.end && pb.start <= pa.end;
470
470
  }
471
- const aArr = Array.isArray(a) ? a : [a];
472
- const bArr = Array.isArray(b) ? b : [b];
471
+ const aArr = typeof a === "string" ? [a] : a;
472
+ const bArr = typeof b === "string" ? [b] : b;
473
473
  const v4a = [], v6a = [];
474
474
  const v4b = [], v6b = [];
475
475
  for (const s of aArr) {
@@ -518,7 +518,7 @@ function overlapCidr(a, b) {
518
518
  }
519
519
  /** Returns a boolean that indicates whether `networksA` fully contain all `networksB`. */
520
520
  function containsCidr(a, b) {
521
- if (!Array.isArray(a) && !Array.isArray(b)) {
521
+ if (typeof a === "string" && typeof b === "string") {
522
522
  if (parseIPv4Range(a)) {
523
523
  const startA = rangeV4Start, endA = rangeV4End;
524
524
  if (parseIPv4Range(b)) return startA <= rangeV4Start && endA >= rangeV4End;
@@ -531,8 +531,8 @@ function containsCidr(a, b) {
531
531
  if (pa.version !== pb.version) return false;
532
532
  return pa.start <= pb.start && pa.end >= pb.end;
533
533
  }
534
- const aArr = Array.isArray(a) ? a : [a];
535
- const bArr = Array.isArray(b) ? b : [b];
534
+ const aArr = typeof a === "string" ? [a] : a;
535
+ const bArr = typeof b === "string" ? [b] : b;
536
536
  const v4a = [], v6a = [];
537
537
  const v4b = [], v6b = [];
538
538
  for (const s of aArr) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cidr-tools",
3
- "version": "12.0.3",
3
+ "version": "12.1.0",
4
4
  "author": "silverwind <me@silverwind.io>",
5
5
  "description": "Tools to work with IPv4 and IPv6 CIDR",
6
6
  "keywords": [
@@ -32,20 +32,20 @@
32
32
  "ip-bigint": "^9.0.6"
33
33
  },
34
34
  "devDependencies": {
35
- "@types/node": "25.9.2",
36
- "@typescript/native-preview": "7.0.0-dev.20260609.1",
37
- "@vitest/coverage-v8": "4.1.8",
38
- "eslint": "10.4.1",
39
- "eslint-config-silverwind": "135.0.1",
35
+ "@types/node": "25.9.3",
36
+ "@typescript/native-preview": "7.0.0-dev.20260616.1",
37
+ "@vitest/coverage-v8": "4.1.9",
38
+ "eslint": "10.5.0",
39
+ "eslint-config-silverwind": "136.0.10",
40
40
  "jest-extended": "7.0.0",
41
- "tsdown": "0.22.2",
41
+ "tsdown": "0.22.3",
42
42
  "tsdown-config-silverwind": "3.0.3",
43
43
  "typescript": "6.0.3",
44
44
  "typescript-config-silverwind": "20.0.0",
45
45
  "updates": "17.18.0",
46
46
  "updates-config-silverwind": "4.0.0",
47
47
  "versions": "15.1.1",
48
- "vitest": "4.1.8",
48
+ "vitest": "4.1.9",
49
49
  "vitest-config-silverwind": "11.3.6"
50
50
  }
51
51
  }