mirror of
https://github.com/gosticks/DefinitelyTyped.git
synced 2026-10-04 06:47:03 +00:00
Update query-string to version 4.3
This commit is contained in:
Vendored
+14
-6
@@ -1,26 +1,34 @@
|
||||
// Type definitions for query-string v3.0.0
|
||||
// Type definitions for query-string 4.3
|
||||
// Project: https://github.com/sindresorhus/query-string
|
||||
// Definitions by: Sam Verschueren <https://github.com/SamVerschueren>
|
||||
// Definitions by: Sam Verschueren <https://github.com/SamVerschueren>, Tanguy Krotoff <https://github.com/tkrotoff>
|
||||
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
|
||||
// TypeScript Version: 2.2
|
||||
|
||||
declare module "query-string" {
|
||||
|
||||
|
||||
interface StringifyOptions { strict?: boolean; encode?: boolean; }
|
||||
interface ParseOptions {
|
||||
arrayFormat?: 'bracket' | 'index' | 'none';
|
||||
}
|
||||
|
||||
/**
|
||||
* 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): { [key: string]: string | string[] | null };
|
||||
export function parse(str: string, options?: ParseOptions): any;
|
||||
|
||||
interface StringifyOptions {
|
||||
strict?: boolean;
|
||||
encode?: boolean;
|
||||
arrayFormat?: 'bracket' | 'index' | 'none';
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify an object into a query string, sorting the keys.
|
||||
*
|
||||
* @param obj
|
||||
*/
|
||||
export function stringify(obj: any, options?: StringifyOptions): string;
|
||||
export function stringify(obj: object, options?: StringifyOptions): string;
|
||||
|
||||
/**
|
||||
* Extract a query string from a URL that can be passed into .parse().
|
||||
|
||||
@@ -1,34 +1,34 @@
|
||||
|
||||
import qs = require('query-string');
|
||||
|
||||
import * as queryString from 'query-string';
|
||||
|
||||
namespace stringify_tests {
|
||||
let result: string;
|
||||
// test obj
|
||||
result = qs.stringify({
|
||||
result = queryString.stringify({
|
||||
str: 'bar',
|
||||
strArray: ['baz'],
|
||||
num: 123,
|
||||
numArray: [456],
|
||||
bool: true,
|
||||
boolArray: [false],
|
||||
boolArray: [false]
|
||||
});
|
||||
|
||||
// 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 })
|
||||
result = queryString.stringify({ foo: 'bar' }, { strict: false });
|
||||
result = queryString.stringify({ foo: 'bar' }, { encode: false });
|
||||
result = queryString.stringify({ foo: 'bar' }, { strict: false, encode: false });
|
||||
}
|
||||
|
||||
namespace parse_tests {
|
||||
let result: { [key: string]: string | string[] | null };
|
||||
result = qs.parse('?foo=bar');
|
||||
result = qs.parse('#foo=bar');
|
||||
result = qs.parse('&foo=bar&foo=baz');
|
||||
let fooBar: { foo: 'bar' };
|
||||
fooBar = queryString.parse('?foo=bar');
|
||||
fooBar = queryString.parse('#foo=bar');
|
||||
|
||||
let fooBarBaz: { foo: ['bar', 'baz'] };
|
||||
fooBarBaz = queryString.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');
|
||||
result = queryString.extract('http://foo.bar/?abc=def&hij=klm');
|
||||
result = queryString.extract('http://foo.bar/?foo=bar');
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
{
|
||||
"extends": "../tslint.json",
|
||||
"rules": {
|
||||
"no-single-declare-module": false
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user