Add typings for proper-url-join (#39197)

This commit is contained in:
Jules Sam. Randolph
2019-10-17 14:58:21 -07:00
committed by Andrew Branch
parent 439a7d5bc1
commit dca759d8d8
5 changed files with 120 additions and 0 deletions
+59
View File
@@ -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;
+6
View File
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"query-string": "^6.3.0"
}
}
@@ -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');
+23
View File
@@ -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"
]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }