mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-06-06 06:19:58 +08:00
[normalize-url] correct typings, add tests, export namespace (#18292)
This commit is contained in:
committed by
Wesley Wigham
parent
4cfe41dc6b
commit
271b8ec0aa
28
types/normalize-url/index.d.ts
vendored
28
types/normalize-url/index.d.ts
vendored
@@ -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;
|
||||
|
||||
17
types/normalize-url/normalize-url-tests.ts
Normal file
17
types/normalize-url/normalize-url-tests.ts
Normal 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']
|
||||
});
|
||||
@@ -16,6 +16,7 @@
|
||||
"forceConsistentCasingInFileNames": true
|
||||
},
|
||||
"files": [
|
||||
"index.d.ts"
|
||||
"index.d.ts",
|
||||
"normalize-url-tests.ts"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user