Skip to content

Commit 695e81c

Browse files
ffflorianamcasey
authored andcommitted
Add types for append-query (DefinitelyTyped#35997)
1 parent 8d45842 commit 695e81c

File tree

4 files changed

+68
-0
lines changed

4 files changed

+68
-0
lines changed
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import appendQuery = require('append-query');
2+
3+
appendQuery('http://example.com/foo', 'bar=baz&beep=boop');
4+
5+
appendQuery('http://example.com/?foo=bar', 'hello=world');
6+
7+
appendQuery('http://example.com/', { beep: 'boop' });
8+
9+
appendQuery('http://example.com/', { nothing: null });
10+
11+
appendQuery('http://example.com/', { preEncoded: '%22hello%2C%20world!%22' }, { encodeComponents: false });
12+
13+
appendQuery('http://example.com/?test=1', { test: null }, { removeNull: true });

types/append-query/index.d.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Type definitions for append-query 2.0
2+
// Project: https://github.com/lakenen/node-append-query
3+
// Definitions by: Florian Keller <https://github.com/ffflorian>
4+
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
5+
6+
declare namespace appendQuery {
7+
interface Query {
8+
[index: string]: string | null;
9+
}
10+
11+
interface Options {
12+
/**
13+
* whether or not to encode appended passed params using `encodeURIComponent`.
14+
* Default: `true`.
15+
*/
16+
encodeComponents?: boolean;
17+
/**
18+
* whether or not to remove params for `null` properties in the query object.
19+
* Default: `false` (properties will be preserved with no value).
20+
*/
21+
removeNull?: boolean;
22+
}
23+
}
24+
25+
/**
26+
* @param url a string URL to append to
27+
* @param query a string or object containing query params to append
28+
*/
29+
declare function appendQuery(url: string, query: string | appendQuery.Query, options?: appendQuery.Options): string;
30+
31+
export = appendQuery;

types/append-query/tsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"compilerOptions": {
3+
"module": "commonjs",
4+
"lib": [
5+
"es6"
6+
],
7+
"noImplicitAny": true,
8+
"noImplicitThis": true,
9+
"strictNullChecks": true,
10+
"strictFunctionTypes": true,
11+
"baseUrl": "../",
12+
"typeRoots": [
13+
"../"
14+
],
15+
"types": [],
16+
"noEmit": true,
17+
"forceConsistentCasingInFileNames": true
18+
},
19+
"files": [
20+
"index.d.ts",
21+
"append-query-tests.ts"
22+
]
23+
}

types/append-query/tslint.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{ "extends": "dtslint/dt.json" }

0 commit comments

Comments
 (0)