-
Notifications
You must be signed in to change notification settings - Fork 30k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add typings for proper-url-join (#39197)
- Loading branch information
1 parent
439a7d5
commit dca759d
Showing
5 changed files
with
120 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Type definitions for proper-url-join 2.0 | ||
// Project: https://github.com/moxystudio/js-proper-url-join | ||
// Definitions by: Jules Sam. Randolph <https://github.com/jsamr> | ||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped | ||
// TypeScript Version: 3.0 | ||
|
||
import { StringifyOptions } from 'query-string'; | ||
|
||
export interface Options { | ||
/** | ||
* Add a leading slash. | ||
* | ||
* **Default**: `true` | ||
*/ | ||
leadingSlash?: boolean; | ||
/** | ||
* Add a trailing slash. | ||
* | ||
* **Default**: `false` | ||
*/ | ||
trailingSlash?: boolean; | ||
/** | ||
* Protocol relative URLs. | ||
* | ||
* **Default**: `false` | ||
*/ | ||
protocolRelative?: boolean; | ||
/** | ||
* Query string object that will be properly stringified and appended to the url. | ||
* It will be merged with the query string in the url, if it exists. | ||
*/ | ||
query?: { | ||
[k: string]: string|number|ReadonlyArray<string|number>; | ||
}; | ||
/** | ||
* [query-string](https://github.com/sindresorhus/query-string#stringifyobject-options) singify method options to be considered when stringifying the query. | ||
*/ | ||
queryOptions?: StringifyOptions; | ||
} | ||
|
||
export type PathArg = string|null|undefined|number; | ||
|
||
interface urlJoin { | ||
(p1: PathArg, options?: Options): string; | ||
(p1: PathArg, p2: PathArg, options?: Options): string; | ||
(p1: PathArg, p2: PathArg, p3: PathArg, options?: Options): string; | ||
(p1: PathArg, p2: PathArg, p3: PathArg, p4: PathArg, options?: Options): string; | ||
(p1: PathArg, p2: PathArg, p3: PathArg, p4: PathArg, p5: PathArg, options?: Options): string; | ||
(p1: PathArg, p2: PathArg, p3: PathArg, p4: PathArg, p5: PathArg, p6: PathArg, options?: Options): string; | ||
(p1: PathArg, p2: PathArg, p3: PathArg, p4: PathArg, p5: PathArg, p6: PathArg, p7: PathArg, options?: Options): string; | ||
(p1: PathArg, p2: PathArg, p3: PathArg, p4: PathArg, p5: PathArg, p6: PathArg, p7: PathArg, p8: PathArg, options?: Options): string; | ||
(p1: PathArg, p2: PathArg, p3: PathArg, p4: PathArg, p5: PathArg, p6: PathArg, p7: PathArg, p8: PathArg, p9: PathArg, options?: Options): string; | ||
(p1: PathArg, p2: PathArg, p3: PathArg, p4: PathArg, p5: PathArg, p6: PathArg, p7: PathArg, p8: PathArg, p9: PathArg, p10: PathArg, options?: Options): string; | ||
(p1: PathArg, p2: PathArg, p3: PathArg, p4: PathArg, p5: PathArg, p6: PathArg, p7: PathArg, p8: PathArg, p9: PathArg, p10: PathArg, p11: PathArg, ...args: Array<PathArg|Options>): string; | ||
} | ||
|
||
declare const urlJoin: urlJoin; | ||
|
||
export default urlJoin; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"private": true, | ||
"dependencies": { | ||
"query-string": "^6.3.0" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import urlJoin from 'proper-url-join'; | ||
|
||
urlJoin('foo', 'bar'); // /foo/bar | ||
urlJoin('/foo/', '/bar/'); // /foo/bar | ||
urlJoin('foo', '', 'bar'); // /foo/bar | ||
urlJoin('foo', undefined, 'bar'); // /foo/bar | ||
urlJoin('foo', null, 'bar'); // /foo/bar | ||
|
||
// With leading & trailing slash options | ||
urlJoin('foo', 'bar', { leadingSlash: false }); // foo/bar | ||
urlJoin('foo', 'bar', { trailingSlash: true }); // /foo/bar/ | ||
urlJoin('foo', 'bar', { leadingSlash: false, trailingSlash: true }); // foo/bar/ | ||
|
||
// Absolute URLs | ||
urlJoin('http://google.com', 'foo'); // http://google.com/foo | ||
|
||
// Protocol relative URLs | ||
urlJoin('//google.com', 'foo', { protocolRelative: true }); // //google.com/foo | ||
|
||
// With query string as an url part | ||
urlJoin('foo', 'bar?queryString'); // /foo/bar?queryString | ||
urlJoin('foo', 'bar?queryString', { trailingSlash: true }); // /foo/bar/?queryString | ||
|
||
// With query string as an object | ||
urlJoin('foo', { query: { biz: 'buz', foo: 'bar' } }); // /foo?biz=buz&foo=bar | ||
|
||
// With both query string as an url part and an object | ||
urlJoin('foo', 'bar?queryString', { query: { biz: 'buz', foo: 'bar' } }); | ||
|
||
// $ExpectError | ||
urlJoin('foo', 'bar?queryString', { query: { biz: 'buz', foo: 'bar' } }, 'wrong'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"compilerOptions": { | ||
"module": "commonjs", | ||
"lib": [ | ||
"es6" | ||
], | ||
"noImplicitAny": true, | ||
"noImplicitThis": true, | ||
"strictFunctionTypes": true, | ||
"strictNullChecks": true, | ||
"baseUrl": "../", | ||
"typeRoots": [ | ||
"../" | ||
], | ||
"types": [], | ||
"noEmit": true, | ||
"forceConsistentCasingInFileNames": true | ||
}, | ||
"files": [ | ||
"index.d.ts", | ||
"proper-url-join-tests.ts" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{ "extends": "dtslint/dt.json" } |