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