cidr-regex 5.0.1 → 5.0.3

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 CHANGED
@@ -1,5 +1,5 @@
1
1
  # cidr-regex
2
- [![](https://img.shields.io/npm/v/cidr-regex.svg?style=flat)](https://www.npmjs.org/package/cidr-regex) [![](https://img.shields.io/npm/dm/cidr-regex.svg)](https://www.npmjs.org/package/cidr-regex) [![](https://packagephobia.com/badge?p=cidr-regex)](https://packagephobia.com/result?p=cidr-regex)
2
+ [![](https://img.shields.io/npm/v/cidr-regex.svg?style=flat)](https://www.npmjs.org/package/cidr-regex) [![](https://img.shields.io/npm/dm/cidr-regex.svg)](https://www.npmjs.org/package/cidr-regex) [![](https://packagephobia.com/badge?p=cidr-regex)](https://packagephobia.com/result?p=cidr-regex) [![](https://depx.co/api/badge/cidr-regex)](https://depx.co/pkg/cidr-regex)
3
3
 
4
4
  > Regular expression for matching IP addresses in CIDR notation
5
5
 
package/dist/index.d.ts CHANGED
@@ -14,4 +14,3 @@ declare const cidrRegex: {
14
14
  export declare const v4: ({ exact }?: CidrRegexOptions) => RegExp;
15
15
  export declare const v6: ({ exact }?: CidrRegexOptions) => RegExp;
16
16
  export default cidrRegex;
17
- //# sourceMappingURL=index.d.ts.map
package/dist/index.js CHANGED
@@ -1,13 +1,20 @@
1
- import ipRegex from "ip-regex";
2
1
  const defaultOpts = { exact: false };
3
- const v4str = `${ipRegex.v4().source}\\/(3[0-2]|[12]?[0-9])`;
4
- const v6str = `${ipRegex.v6().source}\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])`;
5
- const v4exact = new RegExp(`^${v4str}$`);
6
- const v6exact = new RegExp(`^${v6str}$`);
7
- const v46exact = new RegExp(`(?:^${v4str}$)|(?:^${v6str}$)`);
8
- const cidrRegex = ({ exact } = defaultOpts) => exact ? v46exact : new RegExp(`(?:${v4str})|(?:${v6str})`, "g");
9
- const v4 = cidrRegex.v4 = ({ exact } = defaultOpts) => exact ? v4exact : new RegExp(v4str, "g");
10
- const v6 = cidrRegex.v6 = ({ exact } = defaultOpts) => exact ? v6exact : new RegExp(v6str, "g");
2
+ 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])";
3
+ 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])";
4
+ const v46src = `${v4src}|${v6src}`;
5
+ const v4exact = new RegExp(`^${v4src}$`);
6
+ const v6exact = new RegExp(`^${v6src}$`);
7
+ const v46exact = new RegExp(`^${v4src}$|^${v6src}$`);
8
+ const v4global = new RegExp(v4src, "g");
9
+ const v6global = new RegExp(v6src, "g");
10
+ const v46global = new RegExp(v46src, "g");
11
+ function resetRegex(re) {
12
+ re.lastIndex = 0;
13
+ return re;
14
+ }
15
+ const cidrRegex = ({ exact } = defaultOpts) => exact ? v46exact : resetRegex(v46global);
16
+ const v4 = cidrRegex.v4 = ({ exact } = defaultOpts) => exact ? v4exact : resetRegex(v4global);
17
+ const v6 = cidrRegex.v6 = ({ exact } = defaultOpts) => exact ? v6exact : resetRegex(v6global);
11
18
  export {
12
19
  cidrRegex as default,
13
20
  v4,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cidr-regex",
3
- "version": "5.0.1",
3
+ "version": "5.0.3",
4
4
  "description": "Regular expression for matching IP addresses in CIDR notation",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "contributors": [
@@ -19,20 +19,20 @@
19
19
  "engines": {
20
20
  "node": ">=20"
21
21
  },
22
- "dependencies": {
23
- "ip-regex": "5.0.0"
24
- },
25
22
  "devDependencies": {
26
- "@types/node": "24.5.2",
27
- "eslint": "9.36.0",
28
- "eslint-config-silverwind": "105.1.0",
29
- "typescript": "5.9.2",
30
- "typescript-config-silverwind": "10.0.1",
31
- "updates": "16.7.2",
32
- "versions": "13.1.2",
33
- "vite": "7.1.7",
34
- "vite-config-silverwind": "6.0.2",
35
- "vitest": "3.2.4",
36
- "vitest-config-silverwind": "10.2.0"
23
+ "@types/node": "25.0.10",
24
+ "@typescript/native-preview": "7.0.0-dev.20260212.1",
25
+ "eslint": "9.39.2",
26
+ "eslint-config-silverwind": "120.1.2",
27
+ "jest-extended": "7.0.0",
28
+ "typescript": "5.9.3",
29
+ "typescript-config-silverwind": "14.0.0",
30
+ "updates": "17.0.8",
31
+ "updates-config-silverwind": "1.0.3",
32
+ "versions": "14.0.3",
33
+ "vite": "7.3.1",
34
+ "vite-config-silverwind": "6.0.9",
35
+ "vitest": "4.0.18",
36
+ "vitest-config-silverwind": "10.6.1"
37
37
  }
38
- }
38
+ }
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../index.ts"],"names":[],"mappings":"AAEA,KAAK,gBAAgB,GAAG;IACtB;;;;MAIE;IACF,QAAQ,CAAC,KAAK,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAWF,QAAA,MAAM,SAAS;iBAAa,gBAAgB;mBACD,gBAAgB;mBAChB,gBAAgB;CAFmE,CAAC;AAC/H,eAAO,MAAM,EAAE,eAA4B,gBAAgB,WAA2D,CAAC;AACvH,eAAO,MAAM,EAAE,eAA4B,gBAAgB,WAA2D,CAAC;AACvH,eAAe,SAAS,CAAC"}