mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-03 14:27:04 +00:00
Add ip-regex v3 types
This commit is contained in:
Vendored
+15
-8
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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());
|
||||
|
||||
Reference in New Issue
Block a user