Add types for append-query (#35997)

This commit is contained in:
Florian Keller 2019-06-08 03:32:11 +02:00 committed by Andrew Casey
parent 8d45842583
commit 695e81c90d
4 changed files with 68 additions and 0 deletions

View File

@ -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 });

31
types/append-query/index.d.ts vendored Normal file
View File

@ -0,0 +1,31 @@
// Type definitions for append-query 2.0
// Project: https://github.com/lakenen/node-append-query
// Definitions by: Florian Keller <https://github.com/ffflorian>
// 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;

View File

@ -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"
]
}

View File

@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }