UNPKG

2.7 kBTypeScriptView Raw
1// Type definitions for qs 6.9
2// Project: https://github.com/ljharb/qs
3// Definitions by: Roman Korneev <https://github.com/RWander>
4// Leon Yu <https://github.com/leonyu>
5// Belinda Teh <https://github.com/tehbelinda>
6// Melvin Lee <https://github.com/zyml>
7// Arturs Vonda <https://github.com/artursvonda>
8// Carlos Bonetti <https://github.com/CarlosBonetti>
9// Dan Smith <https://github.com/dpsmith3>
10// Hunter Perrin <https://github.com/hperrin>
11// Jordan Harband <https://github.com/ljharb>
12// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
13export = QueryString;
14export as namespace qs;
15
16declare namespace QueryString {
17 type defaultEncoder = (str: any, defaultEncoder?: any, charset?: string) => string;
18 type defaultDecoder = (str: string, decoder?: any, charset?: string) => string;
19
20 interface IStringifyOptions {
21 delimiter?: string;
22 strictNullHandling?: boolean;
23 skipNulls?: boolean;
24 encode?: boolean;
25 encoder?: (str: any, defaultEncoder: defaultEncoder, charset: string, type: 'key' | 'value') => string;
26 filter?: Array<string | number> | ((prefix: string, value: any) => any);
27 arrayFormat?: 'indices' | 'brackets' | 'repeat' | 'comma';
28 indices?: boolean;
29 sort?: (a: any, b: any) => number;
30 serializeDate?: (d: Date) => string;
31 format?: 'RFC1738' | 'RFC3986';
32 encodeValuesOnly?: boolean;
33 addQueryPrefix?: boolean;
34 allowDots?: boolean;
35 charset?: 'utf-8' | 'iso-8859-1';
36 charsetSentinel?: boolean;
37 }
38
39 interface IParseOptions {
40 comma?: boolean;
41 delimiter?: string | RegExp;
42 depth?: number | false;
43 decoder?: (str: string, defaultDecoder: defaultDecoder, charset: string, type: 'key' | 'value') => any;
44 arrayLimit?: number;
45 parseArrays?: boolean;
46 allowDots?: boolean;
47 plainObjects?: boolean;
48 allowPrototypes?: boolean;
49 parameterLimit?: number;
50 strictNullHandling?: boolean;
51 ignoreQueryPrefix?: boolean;
52 charset?: 'utf-8' | 'iso-8859-1';
53 charsetSentinel?: boolean;
54 interpretNumericEntities?: boolean;
55 }
56
57 interface ParsedQs { [key: string]: undefined | string | string[] | ParsedQs | ParsedQs[] }
58
59 function stringify(obj: any, options?: IStringifyOptions): string;
60 function parse(str: string, options?: IParseOptions & { decoder?: never }): ParsedQs;
61 function parse(str: string | Record<string, string>, options?: IParseOptions): { [key: string]: unknown };
62}