cidr-regex 3.1.1 → 4.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.
Files changed (3) hide show
  1. package/README.md +1 -0
  2. package/index.js +6 -9
  3. package/package.json +11 -12
package/README.md CHANGED
@@ -53,6 +53,7 @@ Only match an exact string. Useful with `RegExp#test()` to check if a string is
53
53
  - [is-cidr](https://github.com/silverwind/is-cidr) - Check if a string is an IP address in CIDR notation
54
54
  - [is-ip](https://github.com/sindresorhus/is-ip) - Check if a string is an IP address
55
55
  - [ip-regex](https://github.com/sindresorhus/ip-regex) - Regular expression for matching IP addresses
56
+ - [cidr-tools](https://github.com/silverwind/cidr-tools) - Tools to work with IPv4 and IPv6 CIDR network lists
56
57
 
57
58
  ## License
58
59
 
package/index.js CHANGED
@@ -1,18 +1,15 @@
1
- "use strict";
2
-
3
- const ipRegex = require("ip-regex");
1
+ import ipRegex from "ip-regex";
4
2
 
5
3
  const defaultOpts = {exact: false};
6
-
7
4
  const v4str = `${ipRegex.v4().source}\\/(3[0-2]|[12]?[0-9])`;
8
5
  const v6str = `${ipRegex.v6().source}\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])`;
9
6
 
10
- // can not precompile the non-exact regexes because global flag makes the regex object stateful
11
- // which would require the user to reset .lastIndex on subsequent calls
7
+ // pre-compile only the exact regexes as global flag makes regex objects stateful
12
8
  const v4exact = new RegExp(`^${v4str}$`);
13
9
  const v6exact = new RegExp(`^${v6str}$`);
14
10
  const v46exact = new RegExp(`(?:^${v4str}$)|(?:^${v6str}$)`);
15
11
 
16
- module.exports = ({exact} = defaultOpts) => exact ? v46exact : new RegExp(`(?:${v4str})|(?:${v6str})`, "g");
17
- module.exports.v4 = ({exact} = defaultOpts) => exact ? v4exact : new RegExp(v4str, "g");
18
- module.exports.v6 = ({exact} = defaultOpts) => exact ? v6exact : new RegExp(v6str, "g");
12
+ const cidrRegex = ({exact} = defaultOpts) => exact ? v46exact : new RegExp(`(?:${v4str})|(?:${v6str})`, "g");
13
+ export const v4 = cidrRegex.v4 = ({exact} = defaultOpts) => exact ? v4exact : new RegExp(v4str, "g");
14
+ export const v6 = cidrRegex.v6 = ({exact} = defaultOpts) => exact ? v6exact : new RegExp(v6str, "g");
15
+ export default cidrRegex;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cidr-regex",
3
- "version": "3.1.1",
3
+ "version": "4.0.0",
4
4
  "description": "Regular expression for matching IP addresses in CIDR notation",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "contributors": [
@@ -8,11 +8,10 @@
8
8
  ],
9
9
  "repository": "silverwind/cidr-regex",
10
10
  "license": "BSD-2-Clause",
11
- "scripts": {
12
- "test": "make test"
13
- },
11
+ "type": "module",
12
+ "sideEffects": false,
14
13
  "engines": {
15
- "node": ">=10"
14
+ "node": ">=14"
16
15
  },
17
16
  "files": [
18
17
  "index.js",
@@ -29,14 +28,14 @@
29
28
  "ip address"
30
29
  ],
31
30
  "dependencies": {
32
- "ip-regex": "^4.1.0"
31
+ "ip-regex": "^5.0.0"
33
32
  },
34
33
  "devDependencies": {
35
- "eslint": "7.8.1",
36
- "eslint-config-silverwind": "18.0.8",
37
- "jest": "26.4.2",
38
- "tsd": "0.13.1",
39
- "updates": "10.3.6",
40
- "versions": "8.4.3"
34
+ "eslint": "8.23.1",
35
+ "eslint-config-silverwind": "54.0.2",
36
+ "jest": "29.0.3",
37
+ "tsd": "0.24.1",
38
+ "updates": "13.1.5",
39
+ "versions": "9.3.0"
41
40
  }
42
41
  }