1 | export interface Options {
|
2 | /**
|
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)*
|
4 |
|
5 | @default false
|
6 | */
|
7 | readonly exact?: boolean;
|
8 |
|
9 | /**
|
10 | Include boundaries in the regex. When `true`, `192.168.0.2000000000` will report as an invalid IPv4 address. If this option is not set, the mentioned IPv4 address would report as valid (ignoring the trailing zeros).
|
11 |
|
12 | @default false
|
13 | */
|
14 | readonly includeBoundaries?: boolean;
|
15 | }
|
16 |
|
17 | declare const ipRegex: {
|
18 | /**
|
19 | Regular expression for matching IP addresses.
|
20 |
|
21 | @returns A regex for matching both IPv4 and IPv6.
|
22 |
|
23 | @example
|
24 | ```
|
25 | import ipRegex from 'ip-regex';
|
26 |
|
27 | // Contains an IP address?
|
28 | ipRegex().test('unicorn 192.168.0.1');
|
29 | //=> true
|
30 |
|
31 | // Is an IP address?
|
32 | ipRegex({exact: true}).test('unicorn 192.168.0.1');
|
33 | //=> false
|
34 |
|
35 | 'unicorn 192.168.0.1 cake 1:2:3:4:5:6:7:8 rainbow'.match(ipRegex());
|
36 | //=> ['192.168.0.1', '1:2:3:4:5:6:7:8']
|
37 |
|
38 | // Contains an IP address?
|
39 | ipRegex({includeBoundaries: true}).test('192.168.0.2000000000');
|
40 | //=> false
|
41 |
|
42 | // Matches an IP address?
|
43 | '192.168.0.2000000000'.match(ipRegex({includeBoundaries: true}));
|
44 | //=> null
|
45 | ```
|
46 | */
|
47 | (options?: Options): RegExp;
|
48 |
|
49 | /**
|
50 | @returns A regex for matching IPv4.
|
51 | */
|
52 | v4(options?: Options): RegExp;
|
53 |
|
54 | /**
|
55 | @returns A regex for matching IPv6.
|
56 |
|
57 | @example
|
58 | ```
|
59 | import ipRegex from 'ip-regex';
|
60 |
|
61 | ipRegex.v6({exact: true}).test('1:2:3:4:5:6:7:8');
|
62 | //=> true
|
63 | ```
|
64 | */
|
65 | v6(options?: Options): RegExp;
|
66 | };
|
67 |
|
68 | export default ipRegex;
|