cidr-regex 3.1.0 → 3.1.1
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/index.js +12 -7
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -2,12 +2,17 @@
|
|
|
2
2
|
|
|
3
3
|
const ipRegex = require("ip-regex");
|
|
4
4
|
|
|
5
|
-
const
|
|
6
|
-
const v6 = `${ipRegex.v6().source}\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])`;
|
|
5
|
+
const defaultOpts = {exact: false};
|
|
7
6
|
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
new RegExp(`(?:${v4})|(?:${v6})`, "g");
|
|
7
|
+
const v4str = `${ipRegex.v4().source}\\/(3[0-2]|[12]?[0-9])`;
|
|
8
|
+
const v6str = `${ipRegex.v6().source}\\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])`;
|
|
11
9
|
|
|
12
|
-
|
|
13
|
-
|
|
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
|
|
12
|
+
const v4exact = new RegExp(`^${v4str}$`);
|
|
13
|
+
const v6exact = new RegExp(`^${v6str}$`);
|
|
14
|
+
const v46exact = new RegExp(`(?:^${v4str}$)|(?:^${v6str}$)`);
|
|
15
|
+
|
|
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");
|