[normalize-url] correct typings, add tests, export namespace (#18292)

This commit is contained in:
Dimitri Benin
2017-07-22 21:21:48 +02:00
committed by Wesley Wigham
parent 4cfe41dc6b
commit 271b8ec0aa
3 changed files with 34 additions and 16 deletions

View File

@@ -1,21 +1,21 @@
// Type definitions for normalize-url 1.9
// Project: https://github.com/sindresorhus/normalize-url
// Definitions by: odin3 <https://github.com/odin3>
// BendingBender <https://github.com/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<RegExp | string>;
removeTrailingSlash?: boolean;
removeDirectoryIndex?: Array<RegExp | string>;
}
}
export = NormalizeUrl.normalizeUrl;
declare function normalizeUrl(url: string, options?: normalizeUrl.Options): string;
export = normalizeUrl;

View File

@@ -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']
});

View File

@@ -16,6 +16,7 @@
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts"
"index.d.ts",
"normalize-url-tests.ts"
]
}
}