Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add typings for proper-url-join #39197

Merged
merged 1 commit into from Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
59 changes: 59 additions & 0 deletions types/proper-url-join/index.d.ts
@@ -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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typescript prior to v3 compilation will fail at query-string import.


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 changes: 6 additions & 0 deletions types/proper-url-join/package.json
@@ -0,0 +1,6 @@
{
"private": true,
"dependencies": {
"query-string": "^6.3.0"
}
}
31 changes: 31 additions & 0 deletions types/proper-url-join/proper-url-join-tests.ts
@@ -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 changes: 23 additions & 0 deletions types/proper-url-join/tsconfig.json
@@ -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 change: 1 addition & 0 deletions types/proper-url-join/tslint.json
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }