UNPKG

3.5 kBTypeScriptView Raw
1export = QueryString;
2export as namespace qs;
3
4declare namespace QueryString {
5 type defaultEncoder = (str: any, defaultEncoder?: any, charset?: string) => string;
6 type defaultDecoder = (str: string, decoder?: any, charset?: string) => string;
7
8 type BooleanOptional = boolean | undefined;
9
10 interface IStringifyBaseOptions {
11 delimiter?: string | undefined;
12 strictNullHandling?: boolean | undefined;
13 skipNulls?: boolean | undefined;
14 encode?: boolean | undefined;
15 encoder?:
16 | ((str: any, defaultEncoder: defaultEncoder, charset: string, type: "key" | "value") => string)
17 | undefined;
18 filter?: Array<string | number> | ((prefix: string, value: any) => any) | undefined;
19 arrayFormat?: "indices" | "brackets" | "repeat" | "comma" | undefined;
20 indices?: boolean | undefined;
21 sort?: ((a: string, b: string) => number) | undefined;
22 serializeDate?: ((d: Date) => string) | undefined;
23 format?: "RFC1738" | "RFC3986" | undefined;
24 encodeValuesOnly?: boolean | undefined;
25 addQueryPrefix?: boolean | undefined;
26 charset?: "utf-8" | "iso-8859-1" | undefined;
27 charsetSentinel?: boolean | undefined;
28 allowEmptyArrays?: boolean | undefined;
29 commaRoundTrip?: boolean | undefined;
30 }
31
32 type IStringifyDynamicOptions<AllowDots extends BooleanOptional> = AllowDots extends true
33 ? { allowDots?: AllowDots; encodeDotInKeys?: boolean }
34 : { allowDots?: boolean; encodeDotInKeys?: false };
35
36 type IStringifyOptions<AllowDots extends BooleanOptional = undefined> =
37 & IStringifyBaseOptions
38 & IStringifyDynamicOptions<AllowDots>;
39
40 interface IParseBaseOptions {
41 comma?: boolean | undefined;
42 delimiter?: string | RegExp | undefined;
43 depth?: number | false | undefined;
44 decoder?:
45 | ((str: string, defaultDecoder: defaultDecoder, charset: string, type: "key" | "value") => any)
46 | undefined;
47 arrayLimit?: number | undefined;
48 parseArrays?: boolean | undefined;
49 plainObjects?: boolean | undefined;
50 allowPrototypes?: boolean | undefined;
51 allowSparse?: boolean | undefined;
52 parameterLimit?: number | undefined;
53 strictNullHandling?: boolean | undefined;
54 ignoreQueryPrefix?: boolean | undefined;
55 charset?: "utf-8" | "iso-8859-1" | undefined;
56 charsetSentinel?: boolean | undefined;
57 interpretNumericEntities?: boolean | undefined;
58 allowEmptyArrays?: boolean | undefined;
59 duplicates?: "combine" | "first" | "last" | undefined;
60 }
61
62 type IParseDynamicOptions<AllowDots extends BooleanOptional> = AllowDots extends true
63 ? { allowDots?: AllowDots; decodeDotInKeys?: boolean }
64 : { allowDots?: boolean; decodeDotInKeys?: false };
65
66 type IParseOptions<AllowDots extends BooleanOptional = undefined> =
67 & IParseBaseOptions
68 & IParseDynamicOptions<AllowDots>;
69
70 interface ParsedQs {
71 [key: string]: undefined | string | string[] | ParsedQs | ParsedQs[];
72 }
73
74 function stringify(obj: any, options?: IStringifyOptions<BooleanOptional>): string;
75 function parse(str: string, options?: IParseOptions<BooleanOptional> & { decoder?: never | undefined }): ParsedQs;
76 function parse(
77 str: string | Record<string, string>,
78 options?: IParseOptions<BooleanOptional>,
79 ): { [key: string]: unknown };
80}
81
\No newline at end of file