diff --git a/types/proper-url-join/index.d.ts b/types/proper-url-join/index.d.ts new file mode 100644 index 0000000000..cc94892151 --- /dev/null +++ b/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 +// 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; + }; + /** + * [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): string; +} + +declare const urlJoin: urlJoin; + +export default urlJoin; diff --git a/types/proper-url-join/package.json b/types/proper-url-join/package.json new file mode 100644 index 0000000000..d0e4392187 --- /dev/null +++ b/types/proper-url-join/package.json @@ -0,0 +1,6 @@ +{ + "private": true, + "dependencies": { + "query-string": "^6.3.0" + } +} diff --git a/types/proper-url-join/proper-url-join-tests.ts b/types/proper-url-join/proper-url-join-tests.ts new file mode 100644 index 0000000000..da5aaba172 --- /dev/null +++ b/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'); diff --git a/types/proper-url-join/tsconfig.json b/types/proper-url-join/tsconfig.json new file mode 100644 index 0000000000..310ad27e1e --- /dev/null +++ b/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" + ] +} diff --git a/types/proper-url-join/tslint.json b/types/proper-url-join/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/proper-url-join/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }