diff --git a/query-string/index.d.ts b/query-string/index.d.ts index dcc9bfafb5..4021bb524b 100644 --- a/query-string/index.d.ts +++ b/query-string/index.d.ts @@ -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 +// Definitions by: Sam Verschueren , Tanguy Krotoff // 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(). diff --git a/query-string/query-string-tests.ts b/query-string/query-string-tests.ts index c5ec7b624d..32dd186c83 100644 --- a/query-string/query-string-tests.ts +++ b/query-string/query-string-tests.ts @@ -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'); } diff --git a/query-string/tslint.json b/query-string/tslint.json new file mode 100644 index 0000000000..cfdf2986e5 --- /dev/null +++ b/query-string/tslint.json @@ -0,0 +1,6 @@ +{ + "extends": "../tslint.json", + "rules": { + "no-single-declare-module": false + } +}