cidr-regex 4.0.2 → 4.0.4

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 +4 -3
  2. package/index.d.ts +33 -45
  3. package/package.json +8 -18
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)
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)
3
3
 
4
4
  > Regular expression for matching IP addresses in CIDR notation
5
5
 
@@ -10,7 +10,7 @@ $ npm i cidr-regex
10
10
  ```
11
11
 
12
12
  ```js
13
- const cidrRegex = require("cidr-regex");
13
+ import cidrRegex from "cidr-regex";
14
14
 
15
15
  // Contains a CIDR IP address?
16
16
  cidrRegex().test("foo 192.168.0.1/24");
@@ -50,9 +50,10 @@ Only match an exact string. Useful with `RegExp#test()` to check if a string is
50
50
 
51
51
  ## Related
52
52
 
53
+ - [ip-bigint](https://github.com/silverwind/ip-bigint) - Convert IPv4 and IPv6 addresses to native BigInt and vice-versa
54
+ - [ip-regex](https://github.com/sindresorhus/ip-regex) - Regular expression for matching IP addresses
53
55
  - [is-cidr](https://github.com/silverwind/is-cidr) - Check if a string is an IP address in CIDR notation
54
56
  - [is-ip](https://github.com/sindresorhus/is-ip) - Check if a string is an IP address
55
- - [ip-regex](https://github.com/sindresorhus/ip-regex) - Regular expression for matching IP addresses
56
57
  - [cidr-tools](https://github.com/silverwind/cidr-tools) - Tools to work with IPv4 and IPv6 CIDR network lists
57
58
 
58
59
  ## License
package/index.d.ts CHANGED
@@ -1,55 +1,43 @@
1
- declare namespace ip {
2
- interface Options {
3
- /**
4
- Only match an exact string. Useful with `RegExp#test()` to check if a string is a CIDR IP address. *(`false` matches any CIDR IP address in a string)*
5
-
6
- @default false
7
- */
8
- readonly exact?: boolean;
9
- }
10
- }
11
-
12
- declare const ip: {
1
+ export type Options = {
13
2
  /**
14
- Regular expression for matching IP addresses in CIDR notation.
15
-
16
- @returns A regex for matching both IPv4 and IPv6 CIDR IP addresses.
3
+ Only match an exact string. Useful with `RegExp#test()` to check if a string is an IP address. *(`false` matches any IP address in a string)*
17
4
 
18
- @example
19
- ```
20
- import cidrRegex = require("cidr-regex");
5
+ @default false
6
+ */
7
+ readonly exact?: boolean;
8
+ }
21
9
 
22
- // Contains a CIDR IP address?
23
- cidrRegex().test("foo 192.168.0.1/24");
24
- //=> true
10
+ /**
11
+ @returns A regex for matching IPv4 CIDRs.
12
+ */
13
+ export function v4(options?: Options): RegExp;
25
14
 
26
- // Is a CIDR IP address?
27
- cidrRegex({exact: true}).test("foo 192.168.0.1/24");
28
- //=> false
15
+ /**
16
+ @returns A regex for matching IPv6 CIDRs.
17
+ */
18
+ export function v6(options?: Options): RegExp;
29
19
 
30
- "foo 192.168.0.1/24 bar 1:2:3:4:5:6:7:8/64 baz".match(cidrRegex());
31
- //=> ["192.168.0.1/24", "1:2:3:4:5:6:7:8/64"]
32
- ```
33
- */
34
- (options?: ip.Options): RegExp;
20
+ /**
21
+ Regular expression for matching IP addresses in CIDR notation
35
22
 
36
- /**
37
- @returns A regex for matching IPv4 CIDR IP addresses.
38
- */
39
- v4(options?: ip.Options): RegExp;
23
+ @returns A regex for matching both IPv4 and IPv6 CIDRs.
40
24
 
41
- /**
42
- @returns A regex for matching IPv6 CIDR IP addresses.
25
+ @example
26
+ ```
27
+ // Contains a CIDR IP address?
28
+ cidrRegex().test("foo 192.168.0.1/24");
29
+ //=> true
43
30
 
44
- @example
45
- ```
46
- import cidrRegex = require("cidr-regex");
31
+ // Is a CIDR IP address?
32
+ cidrRegex({exact: true}).test("foo 192.168.0.1/24");
33
+ //=> false
47
34
 
48
- cidrRegex.v6({exact: true}).test("1:2:3:4:5:6:7:8/64");
49
- //=> true
50
- ```
51
- */
52
- v6(options?: ip.Options): RegExp;
53
- };
35
+ cidrRegex.v6({exact: true}).test("1:2:3:4:5:6:7:8/64");
36
+ //=> true
54
37
 
55
- export = ip;
38
+ // Extract CIDRs from string
39
+ "foo 192.168.0.1/24 bar 1:2:3:4:5:6:7:8/64 baz".match(cidrRegex());
40
+ //=> ["192.168.0.1/24", "1:2:3:4:5:6:7:8/64"]
41
+ ```
42
+ */
43
+ export default function cidrRegex(options?: Options): RegExp;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cidr-regex",
3
- "version": "4.0.2",
3
+ "version": "4.0.4",
4
4
  "description": "Regular expression for matching IP addresses in CIDR notation",
5
5
  "author": "silverwind <me@silverwind.io>",
6
6
  "contributors": [
@@ -18,26 +18,16 @@
18
18
  "index.js",
19
19
  "index.d.ts"
20
20
  ],
21
- "keywords": [
22
- "cidr",
23
- "regex",
24
- "notation",
25
- "cidr notation",
26
- "prefix",
27
- "prefixes",
28
- "ip",
29
- "ip address"
30
- ],
31
21
  "dependencies": {
32
22
  "ip-regex": "^5.0.0"
33
23
  },
34
24
  "devDependencies": {
35
- "eslint": "8.23.1",
36
- "eslint-config-silverwind": "54.0.2",
37
- "jest": "29.0.3",
38
- "jest-extended": "3.1.0",
39
- "tsd": "0.24.1",
40
- "updates": "13.1.5",
41
- "versions": "9.3.0"
25
+ "eslint": "8.57.0",
26
+ "eslint-config-silverwind": "83.0.1",
27
+ "tsd": "0.31.0",
28
+ "updates": "16.0.0",
29
+ "versions": "12.0.1",
30
+ "vitest": "1.4.0",
31
+ "vitest-config-silverwind": "7.0.3"
42
32
  }
43
33
  }