From ec337664d127d13bd81d3acd77453ed76cd66ac3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ren=C4=81rs=20Vilnis?= Date: Fri, 21 Dec 2018 14:38:59 +0200 Subject: [PATCH] Add ip-regex v3 types --- types/ip-regex/index.d.ts | 23 +++++++++++++++-------- types/ip-regex/ip-regex-tests.ts | 16 +++++++++++----- 2 files changed, 26 insertions(+), 13 deletions(-) diff --git a/types/ip-regex/index.d.ts b/types/ip-regex/index.d.ts index c26cbaab3b..37d21b924a 100644 --- a/types/ip-regex/index.d.ts +++ b/types/ip-regex/index.d.ts @@ -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 +// Definitions by: Renārs Vilnis // 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; +} diff --git a/types/ip-regex/ip-regex-tests.ts b/types/ip-regex/ip-regex-tests.ts index dcaa72c72d..0af0b36eb1 100644 --- a/types/ip-regex/ip-regex-tests.ts +++ b/types/ip-regex/ip-regex-tests.ts @@ -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());