From 695e81c90dd52f5a68f1727d786e71a9825badf2 Mon Sep 17 00:00:00 2001 From: Florian Keller Date: Sat, 8 Jun 2019 03:32:11 +0200 Subject: [PATCH] Add types for append-query (#35997) --- types/append-query/append-query-tests.ts | 13 ++++++++++ types/append-query/index.d.ts | 31 ++++++++++++++++++++++++ types/append-query/tsconfig.json | 23 ++++++++++++++++++ types/append-query/tslint.json | 1 + 4 files changed, 68 insertions(+) create mode 100644 types/append-query/append-query-tests.ts create mode 100644 types/append-query/index.d.ts create mode 100644 types/append-query/tsconfig.json create mode 100644 types/append-query/tslint.json diff --git a/types/append-query/append-query-tests.ts b/types/append-query/append-query-tests.ts new file mode 100644 index 0000000000..2cc206a2be --- /dev/null +++ b/types/append-query/append-query-tests.ts @@ -0,0 +1,13 @@ +import appendQuery = require('append-query'); + +appendQuery('http://example.com/foo', 'bar=baz&beep=boop'); + +appendQuery('http://example.com/?foo=bar', 'hello=world'); + +appendQuery('http://example.com/', { beep: 'boop' }); + +appendQuery('http://example.com/', { nothing: null }); + +appendQuery('http://example.com/', { preEncoded: '%22hello%2C%20world!%22' }, { encodeComponents: false }); + +appendQuery('http://example.com/?test=1', { test: null }, { removeNull: true }); diff --git a/types/append-query/index.d.ts b/types/append-query/index.d.ts new file mode 100644 index 0000000000..c2550576fb --- /dev/null +++ b/types/append-query/index.d.ts @@ -0,0 +1,31 @@ +// Type definitions for append-query 2.0 +// Project: https://github.com/lakenen/node-append-query +// Definitions by: Florian Keller +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +declare namespace appendQuery { + interface Query { + [index: string]: string | null; + } + + interface Options { + /** + * whether or not to encode appended passed params using `encodeURIComponent`. + * Default: `true`. + */ + encodeComponents?: boolean; + /** + * whether or not to remove params for `null` properties in the query object. + * Default: `false` (properties will be preserved with no value). + */ + removeNull?: boolean; + } +} + +/** + * @param url a string URL to append to + * @param query a string or object containing query params to append + */ +declare function appendQuery(url: string, query: string | appendQuery.Query, options?: appendQuery.Options): string; + +export = appendQuery; diff --git a/types/append-query/tsconfig.json b/types/append-query/tsconfig.json new file mode 100644 index 0000000000..eed589a76b --- /dev/null +++ b/types/append-query/tsconfig.json @@ -0,0 +1,23 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": [ + "es6" + ], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": [ + "../" + ], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": [ + "index.d.ts", + "append-query-tests.ts" + ] +} diff --git a/types/append-query/tslint.json b/types/append-query/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/append-query/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }