query-string 6.13.8 → 9.3.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/base.d.ts +775 -0
- package/base.js +578 -0
- package/index.d.ts +16 -411
- package/index.js +2 -379
- package/license +1 -1
- package/package.json +26 -12
- package/readme.md +366 -56
package/index.d.ts
CHANGED
|
@@ -1,411 +1,16 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
queryString.parse('foo[]=1&foo[]=2&foo[]=3', {arrayFormat: 'bracket'});
|
|
18
|
-
//=> {foo: ['1', '2', '3']}
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
- `index`: Parse arrays with index representation:
|
|
22
|
-
|
|
23
|
-
```
|
|
24
|
-
import queryString = require('query-string');
|
|
25
|
-
|
|
26
|
-
queryString.parse('foo[0]=1&foo[1]=2&foo[3]=3', {arrayFormat: 'index'});
|
|
27
|
-
//=> {foo: ['1', '2', '3']}
|
|
28
|
-
```
|
|
29
|
-
|
|
30
|
-
- `comma`: Parse arrays with elements separated by comma:
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
import queryString = require('query-string');
|
|
34
|
-
|
|
35
|
-
queryString.parse('foo=1,2,3', {arrayFormat: 'comma'});
|
|
36
|
-
//=> {foo: ['1', '2', '3']}
|
|
37
|
-
```
|
|
38
|
-
|
|
39
|
-
- `separator`: Parse arrays with elements separated by a custom character:
|
|
40
|
-
|
|
41
|
-
```
|
|
42
|
-
import queryString = require('query-string');
|
|
43
|
-
|
|
44
|
-
queryString.parse('foo=1|2|3', {arrayFormat: 'separator', arrayFormatSeparator: '|'});
|
|
45
|
-
//=> {foo: ['1', '2', '3']}
|
|
46
|
-
```
|
|
47
|
-
|
|
48
|
-
- `none`: Parse arrays with elements using duplicate keys:
|
|
49
|
-
|
|
50
|
-
```
|
|
51
|
-
import queryString = require('query-string');
|
|
52
|
-
|
|
53
|
-
queryString.parse('foo=1&foo=2&foo=3');
|
|
54
|
-
//=> {foo: ['1', '2', '3']}
|
|
55
|
-
```
|
|
56
|
-
*/
|
|
57
|
-
readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'none';
|
|
58
|
-
|
|
59
|
-
/**
|
|
60
|
-
The character used to separate array elements when using `{arrayFormat: 'separator'}`.
|
|
61
|
-
|
|
62
|
-
@default ,
|
|
63
|
-
*/
|
|
64
|
-
readonly arrayFormatSeparator?: string;
|
|
65
|
-
|
|
66
|
-
/**
|
|
67
|
-
Supports both `Function` as a custom sorting function or `false` to disable sorting.
|
|
68
|
-
|
|
69
|
-
If omitted, keys are sorted using `Array#sort`, which means, converting them to strings and comparing strings in Unicode code point order.
|
|
70
|
-
|
|
71
|
-
@default true
|
|
72
|
-
|
|
73
|
-
@example
|
|
74
|
-
```
|
|
75
|
-
import queryString = require('query-string');
|
|
76
|
-
|
|
77
|
-
const order = ['c', 'a', 'b'];
|
|
78
|
-
|
|
79
|
-
queryString.parse('?a=one&b=two&c=three', {
|
|
80
|
-
sort: (itemLeft, itemRight) => order.indexOf(itemLeft) - order.indexOf(itemRight)
|
|
81
|
-
});
|
|
82
|
-
//=> {c: 'three', a: 'one', b: 'two'}
|
|
83
|
-
```
|
|
84
|
-
|
|
85
|
-
@example
|
|
86
|
-
```
|
|
87
|
-
import queryString = require('query-string');
|
|
88
|
-
|
|
89
|
-
queryString.parse('?a=one&c=three&b=two', {sort: false});
|
|
90
|
-
//=> {a: 'one', c: 'three', b: 'two'}
|
|
91
|
-
```
|
|
92
|
-
*/
|
|
93
|
-
readonly sort?: ((itemLeft: string, itemRight: string) => number) | false;
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
Parse the value as a number type instead of string type if it's a number.
|
|
97
|
-
|
|
98
|
-
@default false
|
|
99
|
-
|
|
100
|
-
@example
|
|
101
|
-
```
|
|
102
|
-
import queryString = require('query-string');
|
|
103
|
-
|
|
104
|
-
queryString.parse('foo=1', {parseNumbers: true});
|
|
105
|
-
//=> {foo: 1}
|
|
106
|
-
```
|
|
107
|
-
*/
|
|
108
|
-
readonly parseNumbers?: boolean;
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
Parse the value as a boolean type instead of string type if it's a boolean.
|
|
112
|
-
|
|
113
|
-
@default false
|
|
114
|
-
|
|
115
|
-
@example
|
|
116
|
-
```
|
|
117
|
-
import queryString = require('query-string');
|
|
118
|
-
|
|
119
|
-
queryString.parse('foo=true', {parseBooleans: true});
|
|
120
|
-
//=> {foo: true}
|
|
121
|
-
```
|
|
122
|
-
*/
|
|
123
|
-
readonly parseBooleans?: boolean;
|
|
124
|
-
|
|
125
|
-
/**
|
|
126
|
-
Parse the fragment identifier from the URL and add it to result object.
|
|
127
|
-
|
|
128
|
-
@default false
|
|
129
|
-
|
|
130
|
-
@example
|
|
131
|
-
```
|
|
132
|
-
import queryString = require('query-string');
|
|
133
|
-
|
|
134
|
-
queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
|
|
135
|
-
//=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
|
|
136
|
-
```
|
|
137
|
-
*/
|
|
138
|
-
readonly parseFragmentIdentifier?: boolean;
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
export interface ParsedQuery<T = string> {
|
|
142
|
-
[key: string]: T | T[] | null;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
Parse a query string into an object. Leading `?` or `#` are ignored, so you can pass `location.search` or `location.hash` directly.
|
|
147
|
-
|
|
148
|
-
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`.
|
|
149
|
-
|
|
150
|
-
@param query - The query string to parse.
|
|
151
|
-
*/
|
|
152
|
-
export function parse(query: string, options: {parseBooleans: true, parseNumbers: true} & ParseOptions): ParsedQuery<string | boolean | number>;
|
|
153
|
-
export function parse(query: string, options: {parseBooleans: true} & ParseOptions): ParsedQuery<string | boolean>;
|
|
154
|
-
export function parse(query: string, options: {parseNumbers: true} & ParseOptions): ParsedQuery<string | number>;
|
|
155
|
-
export function parse(query: string, options?: ParseOptions): ParsedQuery;
|
|
156
|
-
|
|
157
|
-
export interface ParsedUrl {
|
|
158
|
-
readonly url: string;
|
|
159
|
-
readonly query: ParsedQuery;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
The fragment identifier of the URL.
|
|
163
|
-
|
|
164
|
-
Present when the `parseFragmentIdentifier` option is `true`.
|
|
165
|
-
*/
|
|
166
|
-
readonly fragmentIdentifier?: string;
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
Extract the URL and the query string as an object.
|
|
171
|
-
|
|
172
|
-
If the `parseFragmentIdentifier` option is `true`, the object will also contain a `fragmentIdentifier` property.
|
|
173
|
-
|
|
174
|
-
@param url - The URL to parse.
|
|
175
|
-
|
|
176
|
-
@example
|
|
177
|
-
```
|
|
178
|
-
import queryString = require('query-string');
|
|
179
|
-
|
|
180
|
-
queryString.parseUrl('https://foo.bar?foo=bar');
|
|
181
|
-
//=> {url: 'https://foo.bar', query: {foo: 'bar'}}
|
|
182
|
-
|
|
183
|
-
queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
|
|
184
|
-
//=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
|
|
185
|
-
```
|
|
186
|
-
*/
|
|
187
|
-
export function parseUrl(url: string, options?: ParseOptions): ParsedUrl;
|
|
188
|
-
|
|
189
|
-
export interface StringifyOptions {
|
|
190
|
-
/**
|
|
191
|
-
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.
|
|
192
|
-
|
|
193
|
-
@default true
|
|
194
|
-
*/
|
|
195
|
-
readonly strict?: boolean;
|
|
196
|
-
|
|
197
|
-
/**
|
|
198
|
-
[URL encode](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) the keys and values.
|
|
199
|
-
|
|
200
|
-
@default true
|
|
201
|
-
*/
|
|
202
|
-
readonly encode?: boolean;
|
|
203
|
-
|
|
204
|
-
/**
|
|
205
|
-
@default 'none'
|
|
206
|
-
|
|
207
|
-
- `bracket`: Serialize arrays using bracket representation:
|
|
208
|
-
|
|
209
|
-
```
|
|
210
|
-
import queryString = require('query-string');
|
|
211
|
-
|
|
212
|
-
queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'bracket'});
|
|
213
|
-
//=> 'foo[]=1&foo[]=2&foo[]=3'
|
|
214
|
-
```
|
|
215
|
-
|
|
216
|
-
- `index`: Serialize arrays using index representation:
|
|
217
|
-
|
|
218
|
-
```
|
|
219
|
-
import queryString = require('query-string');
|
|
220
|
-
|
|
221
|
-
queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'index'});
|
|
222
|
-
//=> 'foo[0]=1&foo[1]=2&foo[2]=3'
|
|
223
|
-
```
|
|
224
|
-
|
|
225
|
-
- `comma`: Serialize arrays by separating elements with comma:
|
|
226
|
-
|
|
227
|
-
```
|
|
228
|
-
import queryString = require('query-string');
|
|
229
|
-
|
|
230
|
-
queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'comma'});
|
|
231
|
-
//=> 'foo=1,2,3'
|
|
232
|
-
```
|
|
233
|
-
|
|
234
|
-
- `separator`: Serialize arrays by separating elements with character:
|
|
235
|
-
|
|
236
|
-
```
|
|
237
|
-
import queryString = require('query-string');
|
|
238
|
-
|
|
239
|
-
queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'separator', arrayFormatSeparator: '|'});
|
|
240
|
-
//=> 'foo=1|2|3'
|
|
241
|
-
```
|
|
242
|
-
|
|
243
|
-
- `none`: Serialize arrays by using duplicate keys:
|
|
244
|
-
|
|
245
|
-
```
|
|
246
|
-
import queryString = require('query-string');
|
|
247
|
-
|
|
248
|
-
queryString.stringify({foo: [1, 2, 3]});
|
|
249
|
-
//=> 'foo=1&foo=2&foo=3'
|
|
250
|
-
```
|
|
251
|
-
*/
|
|
252
|
-
readonly arrayFormat?: 'bracket' | 'index' | 'comma' | 'separator' | 'none';
|
|
253
|
-
|
|
254
|
-
/**
|
|
255
|
-
The character used to separate array elements when using `{arrayFormat: 'separator'}`.
|
|
256
|
-
|
|
257
|
-
@default ,
|
|
258
|
-
*/
|
|
259
|
-
readonly arrayFormatSeparator?: string;
|
|
260
|
-
|
|
261
|
-
/**
|
|
262
|
-
Supports both `Function` as a custom sorting function or `false` to disable sorting.
|
|
263
|
-
|
|
264
|
-
If omitted, keys are sorted using `Array#sort`, which means, converting them to strings and comparing strings in Unicode code point order.
|
|
265
|
-
|
|
266
|
-
@default true
|
|
267
|
-
|
|
268
|
-
@example
|
|
269
|
-
```
|
|
270
|
-
import queryString = require('query-string');
|
|
271
|
-
|
|
272
|
-
const order = ['c', 'a', 'b'];
|
|
273
|
-
|
|
274
|
-
queryString.stringify({a: 1, b: 2, c: 3}, {
|
|
275
|
-
sort: (itemLeft, itemRight) => order.indexOf(itemLeft) - order.indexOf(itemRight)
|
|
276
|
-
});
|
|
277
|
-
//=> 'c=3&a=1&b=2'
|
|
278
|
-
```
|
|
279
|
-
|
|
280
|
-
@example
|
|
281
|
-
```
|
|
282
|
-
import queryString = require('query-string');
|
|
283
|
-
|
|
284
|
-
queryString.stringify({b: 1, c: 2, a: 3}, {sort: false});
|
|
285
|
-
//=> 'b=1&c=2&a=3'
|
|
286
|
-
```
|
|
287
|
-
*/
|
|
288
|
-
readonly sort?: ((itemLeft: string, itemRight: string) => number) | false;
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
Skip keys with `null` as the value.
|
|
292
|
-
|
|
293
|
-
Note that keys with `undefined` as the value are always skipped.
|
|
294
|
-
|
|
295
|
-
@default false
|
|
296
|
-
|
|
297
|
-
@example
|
|
298
|
-
```
|
|
299
|
-
import queryString = require('query-string');
|
|
300
|
-
|
|
301
|
-
queryString.stringify({a: 1, b: undefined, c: null, d: 4}, {
|
|
302
|
-
skipNull: true
|
|
303
|
-
});
|
|
304
|
-
//=> 'a=1&d=4'
|
|
305
|
-
|
|
306
|
-
queryString.stringify({a: undefined, b: null}, {
|
|
307
|
-
skipNull: true
|
|
308
|
-
});
|
|
309
|
-
//=> ''
|
|
310
|
-
```
|
|
311
|
-
*/
|
|
312
|
-
readonly skipNull?: boolean;
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
Skip keys with an empty string as the value.
|
|
316
|
-
|
|
317
|
-
@default false
|
|
318
|
-
|
|
319
|
-
@example
|
|
320
|
-
```
|
|
321
|
-
import queryString = require('query-string');
|
|
322
|
-
|
|
323
|
-
queryString.stringify({a: 1, b: '', c: '', d: 4}, {
|
|
324
|
-
skipEmptyString: true
|
|
325
|
-
});
|
|
326
|
-
//=> 'a=1&d=4'
|
|
327
|
-
```
|
|
328
|
-
|
|
329
|
-
@example
|
|
330
|
-
```
|
|
331
|
-
import queryString = require('query-string');
|
|
332
|
-
|
|
333
|
-
queryString.stringify({a: '', b: ''}, {
|
|
334
|
-
skipEmptyString: true
|
|
335
|
-
});
|
|
336
|
-
//=> ''
|
|
337
|
-
```
|
|
338
|
-
*/
|
|
339
|
-
readonly skipEmptyString?: boolean;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
export type Stringifiable = string | boolean | number | null | undefined;
|
|
343
|
-
|
|
344
|
-
export type StringifiableRecord = Record<
|
|
345
|
-
string,
|
|
346
|
-
Stringifiable | readonly Stringifiable[]
|
|
347
|
-
>;
|
|
348
|
-
|
|
349
|
-
/**
|
|
350
|
-
Stringify an object into a query string and sort the keys.
|
|
351
|
-
*/
|
|
352
|
-
export function stringify(
|
|
353
|
-
// TODO: Use the below instead when the following TS issues are fixed:
|
|
354
|
-
// - https://github.com/microsoft/TypeScript/issues/15300
|
|
355
|
-
// - https://github.com/microsoft/TypeScript/issues/42021
|
|
356
|
-
// Context: https://github.com/sindresorhus/query-string/issues/298
|
|
357
|
-
// object: StringifiableRecord,
|
|
358
|
-
object: Record<string, any>,
|
|
359
|
-
options?: StringifyOptions
|
|
360
|
-
): string;
|
|
361
|
-
|
|
362
|
-
/**
|
|
363
|
-
Extract a query string from a URL that can be passed into `.parse()`.
|
|
364
|
-
|
|
365
|
-
Note: This behaviour can be changed with the `skipNull` option.
|
|
366
|
-
*/
|
|
367
|
-
export function extract(url: string): string;
|
|
368
|
-
|
|
369
|
-
export interface UrlObject {
|
|
370
|
-
readonly url: string;
|
|
371
|
-
|
|
372
|
-
/**
|
|
373
|
-
Overrides queries in the `url` property.
|
|
374
|
-
*/
|
|
375
|
-
readonly query: StringifiableRecord;
|
|
376
|
-
|
|
377
|
-
/**
|
|
378
|
-
Overrides the fragment identifier in the `url` property.
|
|
379
|
-
*/
|
|
380
|
-
readonly fragmentIdentifier?: string;
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
Stringify an object into a URL with a query string and sorting the keys. The inverse of [`.parseUrl()`](https://github.com/sindresorhus/query-string#parseurlstring-options)
|
|
385
|
-
|
|
386
|
-
Query items in the `query` property overrides queries in the `url` property.
|
|
387
|
-
|
|
388
|
-
The `fragmentIdentifier` property overrides the fragment identifier in the `url` property.
|
|
389
|
-
|
|
390
|
-
@example
|
|
391
|
-
```
|
|
392
|
-
queryString.stringifyUrl({url: 'https://foo.bar', query: {foo: 'bar'}});
|
|
393
|
-
//=> 'https://foo.bar?foo=bar'
|
|
394
|
-
|
|
395
|
-
queryString.stringifyUrl({url: 'https://foo.bar?foo=baz', query: {foo: 'bar'}});
|
|
396
|
-
//=> 'https://foo.bar?foo=bar'
|
|
397
|
-
|
|
398
|
-
queryString.stringifyUrl({
|
|
399
|
-
url: 'https://foo.bar',
|
|
400
|
-
query: {
|
|
401
|
-
top: 'foo'
|
|
402
|
-
},
|
|
403
|
-
fragmentIdentifier: 'bar'
|
|
404
|
-
});
|
|
405
|
-
//=> 'https://foo.bar?top=foo#bar'
|
|
406
|
-
```
|
|
407
|
-
*/
|
|
408
|
-
export function stringifyUrl(
|
|
409
|
-
object: UrlObject,
|
|
410
|
-
options?: StringifyOptions
|
|
411
|
-
): string;
|
|
1
|
+
/// export * as default from './base.js';
|
|
2
|
+
|
|
3
|
+
// Workaround for TS missing feature.
|
|
4
|
+
import * as queryString from './base.js';
|
|
5
|
+
|
|
6
|
+
export default queryString;
|
|
7
|
+
|
|
8
|
+
export {
|
|
9
|
+
type ParseOptions,
|
|
10
|
+
type ParsedQuery,
|
|
11
|
+
type ParsedUrl,
|
|
12
|
+
type StringifyOptions,
|
|
13
|
+
type Stringifiable,
|
|
14
|
+
type StringifiableRecord,
|
|
15
|
+
type UrlObject,
|
|
16
|
+
} from './base.js';
|