Add ip-regex v3 types

This commit is contained in:
Renārs Vilnis
2018-12-21 14:38:59 +02:00
parent d6dfad1821
commit ec337664d1
2 changed files with 26 additions and 13 deletions
+15 -8
View File
@@ -1,12 +1,19 @@
// Type definitions for ip-regex 2.0
// Type definitions for ip-regex 3.0
// Project: https://github.com/sindresorhus/ip-regex
// Definitions by: Daniel Perez Alvarez <https://github.com/unindented>
// Definitions by: Renārs Vilnis <https://github.com/renarsvilnis>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
/** Regular expression for matching IP addresses (IPv4 & IPv6). */
declare function ipRegex(options?: {
/** Only match an exact string. Useful with RegExp#test to check if a string is an IP address. */
exact?: boolean;
}): RegExp;
// tslint:disable-next-line no-single-declare-module no-declare-current-package
declare module "ip-regex" {
function ipRegex(options?: ipRegex.IpRegexOptions): RegExp;
export = ipRegex;
namespace ipRegex {
interface IpRegexOptions {
exact?: boolean;
}
function v4(options?: IpRegexOptions): RegExp;
function v6(options?: IpRegexOptions): RegExp;
}
export = ipRegex;
}
+11 -5
View File
@@ -1,7 +1,13 @@
import ipRegex = require('ip-regex');
ipRegex().test('unicorn 192.168.0.1');
ipRegex({exact: true}).test('unicorn 192.168.0.1');
import * as ipRegex from 'ip-regex';
ipRegex().test('unicorn 192.168.0.1 cake 1:2:3:4:5:6:7:8 rainbow');
ipRegex({exact: true}).test('unicorn 192.168.0.1 cake 1:2:3:4:5:6:7:8 rainbow');
'unicorn 192.168.0.1 cake 1:2:3:4:5:6:7:8 rainbow'.match(ipRegex());
ipRegex.v4().test('unicorn 192.168.0.1');
ipRegex.v4({exact: true}).test('unicorn 192.168.0.1');
'unicorn 192.168.0.1'.match(ipRegex.v4());
ipRegex.v6().test('cake 1:2:3:4:5:6:7:8 rainbow');
ipRegex.v6({exact: true}).test('cake 1:2:3:4:5:6:7:8 rainbow');
'cake 1:2:3:4:5:6:7:8 rainbow'.match(ipRegex.v6());