mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 14:57:10 +00:00
Merge pull request #12175 from TonyPythoneer/patch-13
Update query-string.d.ts
This commit is contained in:
@@ -2,13 +2,34 @@
|
||||
|
||||
import qs = require('query-string');
|
||||
|
||||
qs.stringify({ foo: 'bar' });
|
||||
qs.stringify({ foo: 'bar', bar: 'baz' });
|
||||
qs.stringify({ foo: 'bar' }, {strict: false})
|
||||
|
||||
qs.parse('?foo=bar');
|
||||
qs.parse('#foo=bar');
|
||||
qs.parse('&foo=bar&foo=baz');
|
||||
namespace stringify_tests {
|
||||
let result: string;
|
||||
// test obj
|
||||
result = qs.stringify({
|
||||
str: 'bar',
|
||||
strArray: ['baz'],
|
||||
num: 123,
|
||||
numArray: [456],
|
||||
bool: true,
|
||||
boolArray: [false],
|
||||
});
|
||||
|
||||
qs.extract('http://foo.bar/?abc=def&hij=klm');
|
||||
qs.extract('http://foo.bar/?foo=bar');
|
||||
// test options
|
||||
result = qs.stringify({ foo: 'bar' }, { strict: false })
|
||||
result = qs.stringify({ foo: 'bar' }, { encode: false })
|
||||
result = qs.stringify({ foo: 'bar' }, { strict: false, encode: false })
|
||||
}
|
||||
|
||||
namespace parse_tests {
|
||||
let result: { [key: string]: string | string[] };
|
||||
result = qs.parse('?foo=bar');
|
||||
result = qs.parse('#foo=bar');
|
||||
result = qs.parse('&foo=bar&foo=baz');
|
||||
}
|
||||
|
||||
namespace extract_tests {
|
||||
let result: string;
|
||||
result = qs.extract('http://foo.bar/?abc=def&hij=klm');
|
||||
result = qs.extract('http://foo.bar/?foo=bar');
|
||||
}
|
||||
|
||||
Vendored
+6
-2
@@ -4,19 +4,23 @@
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
|
||||
declare module "query-string" {
|
||||
type value = string | boolean | number;
|
||||
|
||||
interface StringifyOptions { strict?: boolean; encode?: boolean; }
|
||||
|
||||
/**
|
||||
* Parse a query string into an object.
|
||||
* Leading ? or # are ignored, so you can pass location.search or location.hash directly.
|
||||
* @param str
|
||||
*/
|
||||
export function parse(str: string): any;
|
||||
export function parse(str: string): { [key: string]: string | string[] };
|
||||
|
||||
/**
|
||||
* Stringify an object into a query string, sorting the keys.
|
||||
*
|
||||
* @param obj
|
||||
*/
|
||||
export function stringify(obj: any, options?: {strict: boolean}): string;
|
||||
export function stringify(obj: { [key: string]: value | value[] }, options?: StringifyOptions): string;
|
||||
|
||||
/**
|
||||
* Extract a query string from a URL that can be passed into .parse().
|
||||
|
||||
Reference in New Issue
Block a user