From 1556184ca6acde6472f856495bce51f366b1547b Mon Sep 17 00:00:00 2001 From: Steve Hipwell Date: Wed, 19 Oct 2016 13:43:58 +0100 Subject: [PATCH] Added valid-url.d.ts (#12042) --- valid-url/valid-url-tests.ts | 24 ++++++++++++++++++ valid-url/valid-url.d.ts | 47 ++++++++++++++++++++++++++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 valid-url/valid-url-tests.ts create mode 100644 valid-url/valid-url.d.ts diff --git a/valid-url/valid-url-tests.ts b/valid-url/valid-url-tests.ts new file mode 100644 index 0000000000..b30f17a836 --- /dev/null +++ b/valid-url/valid-url-tests.ts @@ -0,0 +1,24 @@ +/// + +import validUrl = require('valid-url'); + +function testIsUri() { + validUrl.isUri("http://github.com/"); +} + +function testIsHttpUri() { + validUrl.isHttpUri("http://github.com/"); +} + +function testIsHttpsUri() { + validUrl.isHttpsUri("https://github.com/"); +} + +function testIsWebUri() { + validUrl.isWebUri("https://github.com/"); +} + +testIsUri(); +testIsHttpUri(); +testIsHttpsUri(); +testIsWebUri(); diff --git a/valid-url/valid-url.d.ts b/valid-url/valid-url.d.ts new file mode 100644 index 0000000000..494c872e1e --- /dev/null +++ b/valid-url/valid-url.d.ts @@ -0,0 +1,47 @@ +// Type definitions for valid-url v1.0.9 +// Project: https://github.com/ogt/valid-url +// Definitions by: Steve Hipwell +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare module 'valid-url' { + + /** + * Is the value a well-formed uri? + * Returns the untainted URI if the test value appears to be well-formed. Note that you may really want one of the more practical methods like is_http_uri or is_https_uri, since the URI standard (RFC 3986) allows a lot of things you probably don't want. + * @param {string} value - The potential URI to test. + * @returns {string} - The untainted RFC 3986 URI on success, undefined on failure. + */ + export function isUri(value: any): string; + + /** + * Is the value a well-formed HTTP uri? + * Specialized version of isUri() that only likes http:// urls. As a result, it can also do a much more thorough job validating. Also, unlike isUri() it is more concerned with only allowing real-world URIs through. Things like relative hostnames are allowed by the standards, but probably aren't wise. Conversely, null paths aren't allowed per RFC 2616 (should be '/' instead), but are allowed by this function. + * + * This function only works for fully-qualified URIs. /bob.html won't work. See RFC 3986 for the appropriate method to turn a relative URI into an absolute one given its context. + * + * Note that you probably want to either call this in combo with is_https_uri(). + * i.e. if(isHttpUri(uri) || isHttpsUri(uri)) console.log('Good'); + * or use the convenience method isWebUri which is equivalent. + * @param {string} value - The potential URI to test. + * @returns {string} - The untainted RFC 3986 URI on success, undefined on failure. + */ + export function isHttpUri(value: any): string; + + + /** + * Is the value a well-formed HTTPS uri? + *See is_http_uri() for details. This version only likes the https URI scheme. Otherwise it's identical to is_http_uri(). + * @param {string} value - The potential URI to test. + * @returns {string} - The untainted RFC 3986 URI on success, undefined on failure. + */ + export function isHttpsUri(value: any): string; + + /** + * Is the value a well-formed HTTP or HTTPS uri? + * This is just a convenience method that combines isHttpUri and isHttpsUri to accept most common real-world URLs. + * @param {string} value - The potential URI to test. + * @returns {string} - The untainted RFC 3986 URI on success, undefined on failure. + */ + export function isWebUri(value: any): string; + +}