From 271b8ec0aa47105cff01e5e849a6f34f23e30bf3 Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Sat, 22 Jul 2017 21:21:48 +0200 Subject: [PATCH] [normalize-url] correct typings, add tests, export namespace (#18292) --- types/normalize-url/index.d.ts | 28 +++++++++++----------- types/normalize-url/normalize-url-tests.ts | 17 +++++++++++++ types/normalize-url/tsconfig.json | 5 ++-- 3 files changed, 34 insertions(+), 16 deletions(-) create mode 100644 types/normalize-url/normalize-url-tests.ts diff --git a/types/normalize-url/index.d.ts b/types/normalize-url/index.d.ts index 94cf9ee522..ec70be130b 100644 --- a/types/normalize-url/index.d.ts +++ b/types/normalize-url/index.d.ts @@ -1,21 +1,21 @@ // Type definitions for normalize-url 1.9 // Project: https://github.com/sindresorhus/normalize-url // Definitions by: odin3 +// BendingBender // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped -declare namespace NormalizeUrl { - interface NormalizeUrlArgs { - normalizeProtocol?: boolean; - normalizeHttps?: boolean; - stripFragment?: boolean; - stripWWW?: boolean; - removeQueryParameters?: string[]; - removeTrailingSlash?: boolean; - removeDirectoryIndex?: RegExp[]; - } - - // tslint:disable-next-line align - function normalizeUrl(url: string, args?: NormalizeUrlArgs): string; +declare namespace normalizeUrl { + interface Options { + normalizeProtocol?: boolean; + normalizeHttps?: boolean; + stripFragment?: boolean; + stripWWW?: boolean; + removeQueryParameters?: Array; + removeTrailingSlash?: boolean; + removeDirectoryIndex?: Array; + } } -export = NormalizeUrl.normalizeUrl; +declare function normalizeUrl(url: string, options?: normalizeUrl.Options): string; + +export = normalizeUrl; diff --git a/types/normalize-url/normalize-url-tests.ts b/types/normalize-url/normalize-url-tests.ts new file mode 100644 index 0000000000..961be30c0d --- /dev/null +++ b/types/normalize-url/normalize-url-tests.ts @@ -0,0 +1,17 @@ +import normalizeUrl = require('normalize-url'); + +let str: string; +str = normalizeUrl('sindresorhus.com'); +str = normalizeUrl('HTTP://xn--xample-hva.com:80/?b=bar&a=foo'); + +normalizeUrl('//sindresorhus.com:80/', {normalizeProtocol: false}); +normalizeUrl('https://sindresorhus.com:80/', {normalizeHttps: true}); +normalizeUrl('sindresorhus.com/about.html#contact', {stripFragment: false}); +normalizeUrl('http://www.sindresorhus.com/about.html#contact', {stripWWW: false}); +normalizeUrl('www.sindresorhus.com?foo=bar&ref=test_ref', { + removeQueryParameters: ['ref', /test/] +}); +normalizeUrl('http://sindresorhus.com/', {removeTrailingSlash: false}); +normalizeUrl('www.sindresorhus.com/foo/default.php', { + removeDirectoryIndex: [/^default\.[a-z]+$/, 'foo'] +}); diff --git a/types/normalize-url/tsconfig.json b/types/normalize-url/tsconfig.json index 27e01ecd7b..8d9596fd6f 100644 --- a/types/normalize-url/tsconfig.json +++ b/types/normalize-url/tsconfig.json @@ -16,6 +16,7 @@ "forceConsistentCasingInFileNames": true }, "files": [ - "index.d.ts" + "index.d.ts", + "normalize-url-tests.ts" ] -} \ No newline at end of file +}