cidr-regex 6.0.0 → 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/dist/index.d.ts CHANGED
@@ -24,4 +24,4 @@ declare const v6: ({
24
24
  exact
25
25
  }?: CidrRegexOptions) => RegExp;
26
26
  //#endregion
27
- export { cidrRegex as default, v4, v6 };
27
+ export { CidrRegexOptions, cidrRegex as default, v4, v6 };
package/dist/index.js CHANGED
@@ -1,21 +1,23 @@
1
1
  //#region index.ts
2
- const defaultOpts = { exact: false };
3
- const v4src = "(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}\\/(3[0-2]|[12]?[0-9])";
4
- const v6src = "(?:(?:[a-fA-F\\d]{1,4}:){7}(?:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){6}(?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|:[a-fA-F\\d]{1,4}|:)|(?:[a-fA-F\\d]{1,4}:){5}(?::(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,2}|:)|(?:[a-fA-F\\d]{1,4}:){4}(?:(?::[a-fA-F\\d]{1,4})?:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,3}|:)|(?:[a-fA-F\\d]{1,4}:){3}(?:(?::[a-fA-F\\d]{1,4}){0,2}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,4}|:)|(?:[a-fA-F\\d]{1,4}:){2}(?:(?::[a-fA-F\\d]{1,4}){0,3}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,5}|:)|[a-fA-F\\d]{1,4}:(?:(?::[a-fA-F\\d]{1,4}){0,4}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,6}|:)|:(?:(?::[a-fA-F\\d]{1,4}){0,5}:(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)(?:\\.(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)){3}|(?::[a-fA-F\\d]{1,4}){1,7}|:))(?:%[0-9a-zA-Z]+)?\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])";
5
- const v46src = `${v4src}|${v6src}`;
2
+ const octet = "(?:25[0-5]|2[0-4]\\d|1\\d\\d|[1-9]\\d|\\d)";
3
+ const v4dotted = `${octet}(?:\\.${octet}){3}`;
4
+ const hex = "[\\dA-Fa-f]{1,4}";
5
+ const v4src = `${v4dotted}/(?:3[0-2]|[12]?\\d)`;
6
+ const v6src = `(?:(?:${hex}:){7}(?:${hex}|:)|(?:${hex}:){6}(?:${v4dotted}|:${hex}|:)|(?:${hex}:){5}(?::${v4dotted}|(?::${hex}){1,2}|:)|(?:${hex}:){4}(?:(?::${hex})?:${v4dotted}|(?::${hex}){1,3}|:)|(?:${hex}:){3}(?:(?::${hex}){0,2}:${v4dotted}|(?::${hex}){1,4}|:)|(?:${hex}:){2}(?:(?::${hex}){0,3}:${v4dotted}|(?::${hex}){1,5}|:)|${hex}:(?:(?::${hex}){0,4}:${v4dotted}|(?::${hex}){1,6}|:)|:(?:(?::${hex}){0,5}:${v4dotted}|(?::${hex}){1,7}|:))(?:%[\\dA-Za-z]+)?/(?:12[0-8]|1[01]\\d|[1-9]?\\d)`;
7
+ const v6srcFast = `(?=[\\dA-Fa-f:])${v6src}`;
6
8
  const v4exact = new RegExp(`^${v4src}$`);
7
9
  const v6exact = new RegExp(`^${v6src}$`);
8
- const v46exact = new RegExp(`^${v4src}$|^${v6src}$`);
10
+ const v46exact = new RegExp(`^(?:${v4src}|${v6src})$`);
9
11
  const v4global = new RegExp(v4src, "g");
10
- const v6global = new RegExp(v6src, "g");
11
- const v46global = new RegExp(v46src, "g");
12
+ const v6global = new RegExp(v6srcFast, "g");
13
+ const v46global = new RegExp(`${v4src}|${v6srcFast}`, "g");
12
14
  function resetRegex(re) {
13
15
  re.lastIndex = 0;
14
16
  return re;
15
17
  }
16
- const cidrRegex = ({ exact } = defaultOpts) => exact ? v46exact : resetRegex(v46global);
17
- const v4 = cidrRegex.v4 = ({ exact } = defaultOpts) => exact ? v4exact : resetRegex(v4global);
18
- const v6 = cidrRegex.v6 = ({ exact } = defaultOpts) => exact ? v6exact : resetRegex(v6global);
18
+ const cidrRegex = ({ exact } = {}) => exact ? v46exact : resetRegex(v46global);
19
+ const v4 = cidrRegex.v4 = ({ exact } = {}) => exact ? v4exact : resetRegex(v4global);
20
+ const v6 = cidrRegex.v6 = ({ exact } = {}) => exact ? v6exact : resetRegex(v6global);
19
21
 
20
22
  //#endregion
21
23
  export { cidrRegex as default, v4, v6 };
package/package.json CHANGED
@@ -1,12 +1,15 @@
1
1
  {
2
2
  "name": "cidr-regex",
3
- "version": "6.0.0",
3
+ "version": "7.0.0",
4
4
  "description": "Regular expression for matching IP addresses in CIDR notation",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "contributors": [
7
7
  "Felipe Apostol <flipjs.io@gmail.com> (http://flipjs.io/)"
8
8
  ],
9
- "repository": "silverwind/cidr-regex",
9
+ "repository": {
10
+ "type": "git",
11
+ "url": "silverwind/cidr-regex"
12
+ },
10
13
  "keywords": [
11
14
  "cidr",
12
15
  "regex",
@@ -33,19 +36,19 @@
33
36
  "node": ">=22"
34
37
  },
35
38
  "devDependencies": {
36
- "@types/node": "25.6.0",
37
- "@typescript/native-preview": "7.0.0-dev.20260427.1",
38
- "eslint": "10.2.1",
39
- "eslint-config-silverwind": "132.0.0",
39
+ "@types/node": "25.7.0",
40
+ "@typescript/native-preview": "7.0.0-dev.20260512.1",
41
+ "eslint": "10.3.0",
42
+ "eslint-config-silverwind": "133.0.1",
40
43
  "jest-extended": "7.0.0",
41
- "tsdown": "0.21.10",
42
- "tsdown-config-silverwind": "3.0.0",
44
+ "tsdown": "0.22.0",
45
+ "tsdown-config-silverwind": "3.0.1",
43
46
  "typescript": "6.0.3",
44
47
  "typescript-config-silverwind": "18.0.0",
45
- "updates": "17.16.4",
46
- "updates-config-silverwind": "3.0.0",
47
- "versions": "15.0.1",
48
- "vitest": "4.1.5",
49
- "vitest-config-silverwind": "11.3.3"
48
+ "updates": "17.16.10",
49
+ "updates-config-silverwind": "4.0.0",
50
+ "versions": "15.0.3",
51
+ "vitest": "4.1.6",
52
+ "vitest-config-silverwind": "11.3.4"
50
53
  }
51
54
  }