11export interface ParseOptions {
22 /**
3- * Decode the keys and values. URI components are decoded with [`decode-uri-component`](https://github.com/SamVerschueren/decode-uri-component).
4- *
5- * @default true
6- */
3+ Decode the keys and values. URI components are decoded with [`decode-uri-component`](https://github.com/SamVerschueren/decode-uri-component).
4+
5+ @default true
6+ */
77 readonly decode ?: boolean ;
88
99 /**
10- * @default 'none'
11- *
12- * - `bracket`: Parse arrays with bracket representation:
13- *
14- *
15- * queryString.parse('foo[]=1&foo[]=2&foo[]=3', {arrayFormat: 'bracket'});
16- * //=> foo: ['1', '2', '3']
17- *
18- * - `index`: Parse arrays with index representation:
19- *
20- *
21- * queryString.parse('foo[0]=1&foo[1]=2&foo[3]=3', {arrayFormat: 'index'});
22- * //=> foo: ['1', '2', '3']
23- *
24- * - `comma`: Parse arrays with elements separated by comma:
25- *
26- *
27- * queryString.parse('foo=1,2,3', {arrayFormat: 'comma'});
28- * //=> foo: ['1', '2', '3']
29- *
30- * - `none`: Parse arrays with elements using duplicate keys:
31- *
32- *
33- * queryString.parse('foo=1&foo=2&foo=3');
34- * //=> foo: ['1', '2', '3']
35- */
10+ @default 'none'
11+
12+ - `bracket`: Parse arrays with bracket representation:
13+
14+ ```
15+ queryString.parse('foo[]=1&foo[]=2&foo[]=3', {arrayFormat: 'bracket'});
16+ //=> foo: ['1', '2', '3']
17+ ```
18+
19+ - `index`: Parse arrays with index representation:
20+
21+ ```
22+ queryString.parse('foo[0]=1&foo[1]=2&foo[3]=3', {arrayFormat: 'index'});
23+ //=> foo: ['1', '2', '3']
24+ ```
25+
26+ - `comma`: Parse arrays with elements separated by comma:
27+
28+ ```
29+ queryString.parse('foo=1,2,3', {arrayFormat: 'comma'});
30+ //=> foo: ['1', '2', '3']
31+ ```
32+
33+ - `none`: Parse arrays with elements using duplicate keys:
34+
35+ ```
36+ queryString.parse('foo=1&foo=2&foo=3');
37+ //=> foo: ['1', '2', '3']
38+ ```
39+ */
3640 readonly arrayFormat ?: 'bracket' | 'index' | 'comma' | 'none' ;
3741
3842 /**
39- * Supports both `Function` as a custom sorting function or `false` to disable sorting.
40- *
41- * If omitted, keys are sorted using `Array#sort`, which means, converting them to strings and comparing strings in Unicode code point order.
42- *
43- * @default true
44- *
45- * @example
46- *
47- * const order = ['c', 'a', 'b'];
48- * queryString.parse('?a=one&b=two&c=three', {
49- * sort: (itemLeft, itemRight) => order.indexOf(itemLeft) - order.indexOf(itemRight)
50- * });
51- * // => {c: 'three', a: 'one', b: 'two'}
52- *
53- * queryString.parse('?a=one&c=three&b=two', {sort: false});
54- * // => {a: 'one', c: 'three', b: 'two'}
55- */
43+ Supports both `Function` as a custom sorting function or `false` to disable sorting.
44+
45+ If omitted, keys are sorted using `Array#sort`, which means, converting them to strings and comparing strings in Unicode code point order.
46+
47+ @default true
48+
49+ @example
50+ ```
51+ const order = ['c', 'a', 'b'];
52+
53+ queryString.parse('?a=one&b=two&c=three', {
54+ sort: (itemLeft, itemRight) => order.indexOf(itemLeft) - order.indexOf(itemRight)
55+ });
56+ // => {c: 'three', a: 'one', b: 'two'}
57+ ```
58+
59+ queryString.parse('?a=one&c=three&b=two', {sort: false});
60+ // => {a: 'one', c: 'three', b: 'two'}
61+ ```
62+ */
5663 readonly sort ?: ( ( itemLeft : string , itemRight : string ) => number ) | false ;
5764
5865 /**
59- * Parse the value as a number type instead of string type if it's a number.
60- *
61- * @default false
62- *
63- * @example
64- *
65- * queryString.parse('foo[]=1&foo[]=2&foo[]=3', {parseNumbers: true});
66- * //=> foo: [1, 2, 3]
67- */
66+ Parse the value as a number type instead of string type if it's a number.
67+
68+ @default false
69+
70+ @example
71+ ```
72+ queryString.parse('foo[]=1&foo[]=2&foo[]=3', {parseNumbers: true});
73+ //=> foo: [1, 2, 3]
74+ ```
75+ */
6876 readonly parseNumbers ?: boolean ;
6977}
7078
@@ -73,12 +81,12 @@ export interface ParsedQuery {
7381}
7482
7583/**
76- * Parse a query string into an object. Leading `?` or `#` are ignored, so you can pass `location.search` or `location.hash` directly.
77- *
78- * The returned object is created with [`Object.create(null)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create) and thus does not have a `prototype`.
79- *
80- * @param query - The query string to parse.
81- */
84+ Parse a query string into an object. Leading `?` or `#` are ignored, so you can pass `location.search` or `location.hash` directly.
85+
86+ The returned object is created with [`Object.create(null)`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/create) and thus does not have a `prototype`.
87+
88+ @param query - The query string to parse.
89+ */
8290export function parse ( query : string , options ?: ParseOptions ) : ParsedQuery ;
8391
8492export interface ParsedUrl {
@@ -87,91 +95,98 @@ export interface ParsedUrl {
8795}
8896
8997/**
90- * Extract the URL and the query string as an object.
91- *
92- * @param url - The URL to parse.
93- *
94- * @example
95- *
96- * queryString.parseUrl('https://foo.bar?foo=bar');
97- * //=> {url: 'https://foo.bar', query: {foo: 'bar'}}
98- */
98+ Extract the URL and the query string as an object.
99+
100+ @param url - The URL to parse.
101+
102+ @example
103+ ```
104+ queryString.parseUrl('https://foo.bar?foo=bar');
105+ //=> {url: 'https://foo.bar', query: {foo: 'bar'}}
106+ ```
107+ */
99108export function parseUrl ( url : string , options ?: ParseOptions ) : ParsedUrl ;
100109
101110export interface StringifyOptions {
102111 /**
103- * Strictly encode URI components with [`strict-uri-encode`](https://github.com/kevva/strict-uri-encode). It uses [`encodeURIComponent`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) if set to `false`. You probably [don't care](https://github.com/sindresorhus/query-string/issues/42) about this option.
104- *
105- * @default true
106- */
112+ Strictly encode URI components with [`strict-uri-encode`](https://github.com/kevva/strict-uri-encode). It uses [`encodeURIComponent`](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) if set to `false`. You probably [don't care](https://github.com/sindresorhus/query-string/issues/42) about this option.
113+
114+ @default true
115+ */
107116 readonly strict ?: boolean ;
108117
109118 /**
110- * [URL encode](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) the keys and values.
111- *
112- * @default true
113- */
119+ [URL encode](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) the keys and values.
120+
121+ @default true
122+ */
114123 readonly encode ?: boolean ;
115124
116125 /**
117- * @default 'none'
118- *
119- * - `bracket`: Serialize arrays using bracket representation:
120- *
121- *
122- * queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'bracket'});
123- * //=> 'foo[]=1&foo[]=2&foo[]=3'
124- *
125- * - `index`: Serialize arrays using index representation:
126- *
127- *
128- * queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'index'});
129- * //=> 'foo[0]=1&foo[1]=2&foo[3]=3'
130- *
131- * - `comma`: Serialize arrays by separating elements with comma:
132- *
133- *
134- * queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'comma'});
135- * //=> 'foo=1,2,3'
136- *
137- * - `none`: Serialize arrays by using duplicate keys:
138- *
139- *
140- * queryString.stringify({foo: [1, 2, 3]});
141- * //=> 'foo=1&foo=2&foo=3'
142- */
126+ @default 'none'
127+
128+ - `bracket`: Serialize arrays using bracket representation:
129+
130+ ```
131+ queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'bracket'});
132+ //=> 'foo[]=1&foo[]=2&foo[]=3'
133+ ```
134+
135+ - `index`: Serialize arrays using index representation:
136+
137+ ```
138+ queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'index'});
139+ //=> 'foo[0]=1&foo[1]=2&foo[3]=3'
140+ ```
141+
142+ - `comma`: Serialize arrays by separating elements with comma:
143+
144+ ```
145+ queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'comma'});
146+ //=> 'foo=1,2,3'
147+ ```
148+
149+ - `none`: Serialize arrays by using duplicate keys:
150+
151+ ```
152+ queryString.stringify({foo: [1, 2, 3]});
153+ //=> 'foo=1&foo=2&foo=3'
154+ ```
155+ */
143156 readonly arrayFormat ?: 'bracket' | 'index' | 'comma' | 'none' ;
144157
145158 /**
146- * Supports both `Function` as a custom sorting function or `false` to disable sorting.
147- *
148- * If omitted, keys are sorted using `Array#sort`, which means, converting them to strings and comparing strings in Unicode code point order.
149- *
150- * @default true
151- *
152- * @example
153- *
154- * const order = ['c', 'a', 'b'];
155- * queryString.stringify({a: 1, b: 2, c: 3}, {
156- * sort: (itemLeft, itemRight) => order.indexOf(itemLeft) - order.indexOf(itemRight)
157- * });
158- * // => 'c=3&a=1&b=2'
159- *
160- * queryString.stringify({b: 1, c: 2, a: 3}, {sort: false});
161- * // => 'b=1&c=2&a=3'
162- */
159+ Supports both `Function` as a custom sorting function or `false` to disable sorting.
160+
161+ If omitted, keys are sorted using `Array#sort`, which means, converting them to strings and comparing strings in Unicode code point order.
162+
163+ @default true
164+
165+ @example
166+ ```
167+ const order = ['c', 'a', 'b'];
168+
169+ queryString.stringify({a: 1, b: 2, c: 3}, {
170+ sort: (itemLeft, itemRight) => order.indexOf(itemLeft) - order.indexOf(itemRight)
171+ });
172+ // => 'c=3&a=1&b=2'
173+
174+ queryString.stringify({b: 1, c: 2, a: 3}, {sort: false});
175+ // => 'b=1&c=2&a=3'
176+ ```
177+ */
163178 readonly sort ?: ( ( itemLeft : string , itemRight : string ) => number ) | false ;
164179}
165180
166181/**
167- * Stringify an object into a query string and sorting the keys.
168- */
182+ Stringify an object into a query string and sort the keys.
183+ */
169184export function stringify (
170185 object : { [ key : string ] : any } ,
171186 options ?: StringifyOptions
172187) : string ;
173188
174189/**
175- * Extract a query string from a URL that can be passed into `.parse()`.
176- */
190+ Extract a query string from a URL that can be passed into `.parse()`.
191+ */
177192export function extract ( url : string ) : string ;
0 commit comments