@unicom-cloud/utils 0.1.16 → 0.1.18

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.
Files changed (93) hide show
  1. package/class-name/index.js +5 -5
  2. package/constant/index.js +24 -2
  3. package/constant/platform.js +13 -12
  4. package/constant.js +24 -2
  5. package/content-disposition/index.js +3 -3
  6. package/date/convertTime.js +4 -4
  7. package/diff/index.js +7 -0
  8. package/diff/src/diff.d.ts +21 -0
  9. package/diff/src/diff.js +381 -0
  10. package/diff.js +7 -0
  11. package/filesize/types/constants.d.ts +81 -0
  12. package/filesize/types/filesize.d.ts +97 -0
  13. package/index.js +68 -58
  14. package/js-cookie/index.d.ts +116 -0
  15. package/js-cookie/index.js +4 -0
  16. package/js-cookie/src/api.js +56 -0
  17. package/js-cookie/src/assign.js +11 -0
  18. package/js-cookie/src/converter.js +14 -0
  19. package/jsCookie.js +4 -0
  20. package/lunar/lib/HolidayUtil.js +48 -49
  21. package/mitt/index.js +4 -0
  22. package/mitt/src/index.js +37 -0
  23. package/mitt.js +4 -0
  24. package/nzh/nzh.d.ts +74 -0
  25. package/package.json +1 -1
  26. package/pinyin/index.js +4 -0
  27. package/pinyin/simplified.js +4 -0
  28. package/pinyin/src/core.js +143 -0
  29. package/pinyin/src/simplified.js +8 -0
  30. package/pinyin/src/simplified_dict.js +410 -0
  31. package/pinyin/src/traditional.js +8 -0
  32. package/pinyin/src/traditional_dict.js +403 -0
  33. package/pinyin/traditional.js +4 -0
  34. package/pinyin.js +4 -0
  35. package/query-string/base.d.ts +717 -0
  36. package/query-string/base.js +268 -0
  37. package/query-string/index.d.ts +16 -0
  38. package/query-string/index.js +4 -0
  39. package/query-string/splitOnFirst.js +14 -0
  40. package/queryString.js +4 -0
  41. package/random/index.js +56 -35
  42. package/snapdom/src/api/preCache.js +51 -28
  43. package/snapdom/src/core/cache.js +1 -4
  44. package/snapdom/src/core/capture.js +45 -44
  45. package/snapdom/src/core/clone.js +82 -66
  46. package/snapdom/src/core/prepare.js +167 -45
  47. package/snapdom/src/modules/background.js +29 -19
  48. package/snapdom/src/modules/fonts.js +158 -111
  49. package/snapdom/src/modules/images.js +14 -9
  50. package/snapdom/src/modules/pseudo.js +52 -47
  51. package/snapdom/src/modules/styles.js +22 -22
  52. package/snapdom/src/modules/svgDefs.js +39 -20
  53. package/snapdom/src/utils/cssTools.js +58 -51
  54. package/snapdom/src/utils/helpers.js +197 -140
  55. package/snapdom/types/snapdom.d.ts +101 -0
  56. package/types/constant/index.d.ts +11 -0
  57. package/types/constant/platform.d.ts +1 -0
  58. package/types/diff/index.d.ts +2 -0
  59. package/types/diff/src/diff.d.ts +40 -0
  60. package/types/index.d.ts +6 -1
  61. package/types/js-cookie/index.d.ts +1 -0
  62. package/types/js-cookie/src/api.d.mts +2 -0
  63. package/types/js-cookie/src/assign.d.mts +1 -0
  64. package/types/js-cookie/src/converter.d.mts +5 -0
  65. package/types/mitt/index.d.ts +2 -0
  66. package/types/mitt/src/index.d.ts +29 -0
  67. package/types/pinyin/index.d.ts +1 -0
  68. package/types/pinyin/simplified.d.ts +1 -0
  69. package/types/pinyin/src/core.d.ts +3 -0
  70. package/types/pinyin/src/simplified.d.ts +4 -0
  71. package/types/pinyin/src/simplified_dict.d.ts +408 -0
  72. package/types/pinyin/src/traditional.d.ts +4 -0
  73. package/types/pinyin/src/traditional_dict.d.ts +401 -0
  74. package/types/pinyin/traditional.d.ts +1 -0
  75. package/types/query-string/base.d.ts +11 -0
  76. package/types/query-string/index.d.ts +2 -0
  77. package/types/query-string/splitOnFirst.d.ts +1 -0
  78. package/types/random/index.d.ts +14 -23
  79. package/types/snapdom/src/api/preCache.d.ts +2 -5
  80. package/types/snapdom/src/core/cache.d.ts +0 -3
  81. package/types/snapdom/src/core/clone.d.ts +1 -1
  82. package/types/snapdom/src/modules/background.d.ts +16 -6
  83. package/types/snapdom/src/modules/fonts.d.ts +5 -1
  84. package/types/snapdom/src/modules/pseudo.d.ts +1 -1
  85. package/types/snapdom/src/modules/styles.d.ts +1 -1
  86. package/types/snapdom/src/modules/svgDefs.d.ts +13 -13
  87. package/types/snapdom/src/utils/cssTools.d.ts +2 -10
  88. package/types/snapdom/src/utils/helpers.d.ts +13 -7
  89. package/types/turbo-stream/src/shared.d.ts +3 -3
  90. package/url-toolkit/src/url-toolkit.d.ts +22 -0
  91. package/event-emitter/index.js +0 -48
  92. package/eventEmitter.js +0 -4
  93. package/types/event-emitter/index.d.ts +0 -17
@@ -0,0 +1,717 @@
1
+ export type ParseOptions = {
2
+ /**
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
+ */
7
+ readonly decode?: boolean;
8
+
9
+ /**
10
+ @default 'none'
11
+
12
+ - `bracket`: Parse arrays with bracket representation:
13
+
14
+ ```
15
+ import queryString from 'query-string';
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 from '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 from '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 from 'query-string';
43
+
44
+ queryString.parse('foo=1|2|3', {arrayFormat: 'separator', arrayFormatSeparator: '|'});
45
+ //=> {foo: ['1', '2', '3']}
46
+ ```
47
+
48
+ - `bracket-separator`: Parse arrays (that are explicitly marked with brackets) with elements separated by a custom character:
49
+
50
+ ```
51
+ import queryString from 'query-string';
52
+
53
+ queryString.parse('foo[]', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'});
54
+ //=> {foo: []}
55
+
56
+ queryString.parse('foo[]=', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'});
57
+ //=> {foo: ['']}
58
+
59
+ queryString.parse('foo[]=1', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'});
60
+ //=> {foo: ['1']}
61
+
62
+ queryString.parse('foo[]=1|2|3', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'});
63
+ //=> {foo: ['1', '2', '3']}
64
+
65
+ queryString.parse('foo[]=1||3|||6', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'});
66
+ //=> {foo: ['1', '', 3, '', '', '6']}
67
+
68
+ queryString.parse('foo[]=1|2|3&bar=fluffy&baz[]=4', {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'});
69
+ //=> {foo: ['1', '2', '3'], bar: 'fluffy', baz:['4']}
70
+ ```
71
+
72
+ - `colon-list-separator`: Parse arrays with parameter names that are explicitly marked with `:list`:
73
+
74
+ ```
75
+ import queryString from 'query-string';
76
+
77
+ queryString.parse('foo:list=one&foo:list=two', {arrayFormat: 'colon-list-separator'});
78
+ //=> {foo: ['one', 'two']}
79
+ ```
80
+
81
+ - `none`: Parse arrays with elements using duplicate keys:
82
+
83
+ ```
84
+ import queryString from 'query-string';
85
+
86
+ queryString.parse('foo=1&foo=2&foo=3');
87
+ //=> {foo: ['1', '2', '3']}
88
+ ```
89
+ */
90
+ readonly arrayFormat?:
91
+ | 'bracket'
92
+ | 'index'
93
+ | 'comma'
94
+ | 'separator'
95
+ | 'bracket-separator'
96
+ | 'colon-list-separator'
97
+ | 'none';
98
+
99
+ /**
100
+ The character used to separate array elements when using `{arrayFormat: 'separator'}`.
101
+
102
+ @default ,
103
+ */
104
+ readonly arrayFormatSeparator?: string;
105
+
106
+ /**
107
+ Supports both `Function` as a custom sorting function or `false` to disable sorting.
108
+
109
+ If omitted, keys are sorted using `Array#sort`, which means, converting them to strings and comparing strings in Unicode code point order.
110
+
111
+ @default true
112
+
113
+ @example
114
+ ```
115
+ import queryString from 'query-string';
116
+
117
+ const order = ['c', 'a', 'b'];
118
+
119
+ queryString.parse('?a=one&b=two&c=three', {
120
+ sort: (itemLeft, itemRight) => order.indexOf(itemLeft) - order.indexOf(itemRight)
121
+ });
122
+ //=> {c: 'three', a: 'one', b: 'two'}
123
+ ```
124
+
125
+ @example
126
+ ```
127
+ import queryString from 'query-string';
128
+
129
+ queryString.parse('?a=one&c=three&b=two', {sort: false});
130
+ //=> {a: 'one', c: 'three', b: 'two'}
131
+ ```
132
+ */
133
+ readonly sort?: ((itemLeft: string, itemRight: string) => number) | false;
134
+
135
+ /**
136
+ Parse the value as a number type instead of string type if it's a number.
137
+
138
+ @default false
139
+
140
+ @example
141
+ ```
142
+ import queryString from 'query-string';
143
+
144
+ queryString.parse('foo=1', {parseNumbers: true});
145
+ //=> {foo: 1}
146
+ ```
147
+ */
148
+ readonly parseNumbers?: boolean;
149
+
150
+ /**
151
+ Parse the value as a boolean type instead of string type if it's a boolean.
152
+
153
+ @default false
154
+
155
+ @example
156
+ ```
157
+ import queryString from 'query-string';
158
+
159
+ queryString.parse('foo=true', {parseBooleans: true});
160
+ //=> {foo: true}
161
+ ```
162
+ */
163
+ readonly parseBooleans?: boolean;
164
+
165
+ /**
166
+ Parse the fragment identifier from the URL and add it to result object.
167
+
168
+ @default false
169
+
170
+ @example
171
+ ```
172
+ import queryString from 'query-string';
173
+
174
+ queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
175
+ //=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
176
+ ```
177
+ */
178
+ readonly parseFragmentIdentifier?: boolean;
179
+
180
+ /**
181
+ Specifies a schema for parsing query values with explicit type declarations. When defined, the types provided here take precedence over general parsing options such as `parseNumbers`, `parseBooleans`, and `arrayFormat`.
182
+
183
+ Use this option to explicitly define the type of a specific parameter—particularly useful in cases where the type might otherwise be ambiguous (e.g., phone numbers or IDs).
184
+
185
+ You can also provide a custom function to transform the value. The function will receive the raw string and should return the desired parsed result (see Example 4).
186
+
187
+ NOTE: Array types (`string[]`, `number[]`) are ignored if `arrayFormat` is set to `'none'`. (See Example 5.)
188
+
189
+ @default {}
190
+
191
+ @example
192
+ Parse `phoneNumber` as a string, overriding the `parseNumber` option:
193
+ ```
194
+ import queryString from 'query-string';
195
+
196
+ queryString.parse('?phoneNumber=%2B380951234567&id=1', {
197
+ parseNumbers: true,
198
+ types: {
199
+ phoneNumber: 'string',
200
+ }
201
+ });
202
+ //=> {phoneNumber: '+380951234567', id: 1}
203
+ ```
204
+
205
+ @example
206
+ Parse `items` as an array of strings, overriding the `parseNumber` option:
207
+ ```
208
+ import queryString from 'query-string';
209
+
210
+ queryString.parse('?age=20&items=1%2C2%2C3', {
211
+ parseNumber: true,
212
+ types: {
213
+ items: 'string[]',
214
+ }
215
+ });
216
+ //=> {age: 20, items: ['1', '2', '3']}
217
+ ```
218
+
219
+ @example
220
+ Force `age` to be parsed as a number even when `parseNumbers` is false:
221
+ ```
222
+ import queryString from 'query-string';
223
+
224
+ queryString.parse('?age=20&id=01234&zipcode=90210', {
225
+ types: {
226
+ age: 'number',
227
+ }
228
+ });
229
+ //=> {age: 20, id: '01234', zipcode: '90210'}
230
+ ```
231
+
232
+ @example
233
+ Use a custom parser function to transform the value of `age`:
234
+ ```
235
+ import queryString from 'query-string';
236
+
237
+ queryString.parse('?age=20&id=01234&zipcode=90210', {
238
+ types: {
239
+ age: (value) => value * 2,
240
+ }
241
+ });
242
+ //=> {age: 40, id: '01234', zipcode: '90210'}
243
+ ```
244
+
245
+ @example
246
+ Array types are ignored when `arrayFormat` is set to `'none'`:
247
+ ```
248
+ queryString.parse('ids=001%2C002%2C003&foods=apple%2Corange%2Cmango', {
249
+ arrayFormat: 'none',
250
+ types: {
251
+ ids: 'number[]',
252
+ foods: 'string[]',
253
+ },
254
+ }
255
+ //=> {ids:'001,002,003', foods:'apple,orange,mango'}
256
+ ```
257
+
258
+ @example
259
+ Parse a query using multiple type definitions:
260
+ ```
261
+ import queryString from 'query-string';
262
+
263
+ queryString.parse('?ids=001%2C002%2C003&items=1%2C2%2C3&price=22%2E00&numbers=1%2C2%2C3&double=5&number=20', {
264
+ arrayFormat: 'comma',
265
+ types: {
266
+ ids: 'string',
267
+ items: 'string[]',
268
+ price: 'string',
269
+ numbers: 'number[]',
270
+ double: (value) => value * 2,
271
+ number: 'number',
272
+ },
273
+ });
274
+ //=> {ids: '001,002,003', items: ['1', '2', '3'], price: '22.00', numbers: [1, 2, 3], double: 10, number: 20}
275
+ ```
276
+
277
+ @example
278
+ Force `flagged` to be parsed as a boolean even when `parseBooleans` is false:
279
+ ```
280
+ queryString.parse('?isAdmin=true&flagged=true&isOkay=0', {
281
+ parseBooleans: false,
282
+ types: {
283
+ flagged: 'boolean',
284
+ isOkay: 'boolean',
285
+ },
286
+ });
287
+ //=> {isAdmin: 'true', flagged: true, isOkay: false}
288
+ ```
289
+
290
+ Note: The `'boolean'` type also converts `'0'` and `'1'` to booleans, and treats valueless keys (e.g. `?flag`) as `true`.
291
+ */
292
+ readonly types?: Record<
293
+ string,
294
+ | 'boolean'
295
+ | 'number'
296
+ | 'string'
297
+ | 'string[]'
298
+ | 'number[]'
299
+ | ((value: string) => unknown)
300
+ >;
301
+ };
302
+
303
+ export type ParsedQuery<T = string> = Record<
304
+ string,
305
+ T | null | Array<T | null>
306
+ >;
307
+
308
+ /**
309
+ Parse a query string into an object. Leading `?` or `#` are ignored, so you can pass `location.search` or `location.hash` directly.
310
+
311
+ 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`.
312
+
313
+ @param query - The query string to parse.
314
+ */
315
+ export function parse(
316
+ query: string,
317
+ options: { parseBooleans: true; parseNumbers: true } & ParseOptions,
318
+ ): ParsedQuery<string | boolean | number>;
319
+ export function parse(
320
+ query: string,
321
+ options: { parseBooleans: true } & ParseOptions,
322
+ ): ParsedQuery<string | boolean>;
323
+ export function parse(
324
+ query: string,
325
+ options: { parseNumbers: true } & ParseOptions,
326
+ ): ParsedQuery<string | number>;
327
+ export function parse(query: string, options?: ParseOptions): ParsedQuery;
328
+
329
+ export type ParsedUrl = {
330
+ readonly url: string;
331
+ readonly query: ParsedQuery;
332
+
333
+ /**
334
+ The fragment identifier of the URL.
335
+
336
+ Present when the `parseFragmentIdentifier` option is `true`.
337
+ */
338
+ readonly fragmentIdentifier?: string;
339
+ };
340
+
341
+ /**
342
+ Extract the URL and the query string as an object.
343
+
344
+ If the `parseFragmentIdentifier` option is `true`, the object will also contain a `fragmentIdentifier` property.
345
+
346
+ @param url - The URL to parse.
347
+
348
+ @example
349
+ ```
350
+ import queryString from 'query-string';
351
+
352
+ queryString.parseUrl('https://foo.bar?foo=bar');
353
+ //=> {url: 'https://foo.bar', query: {foo: 'bar'}}
354
+
355
+ queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
356
+ //=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
357
+ ```
358
+ */
359
+ export function parseUrl(url: string, options?: ParseOptions): ParsedUrl;
360
+
361
+ export type StringifyOptions = {
362
+ /**
363
+ Strictly encode URI components. 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.
364
+
365
+ @default true
366
+ */
367
+ readonly strict?: boolean;
368
+
369
+ /**
370
+ [URL encode](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent) the keys and values.
371
+
372
+ @default true
373
+ */
374
+ readonly encode?: boolean;
375
+
376
+ /**
377
+ @default 'none'
378
+
379
+ - `bracket`: Serialize arrays using bracket representation:
380
+
381
+ ```
382
+ import queryString from 'query-string';
383
+
384
+ queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'bracket'});
385
+ //=> 'foo[]=1&foo[]=2&foo[]=3'
386
+ ```
387
+
388
+ - `index`: Serialize arrays using index representation:
389
+
390
+ ```
391
+ import queryString from 'query-string';
392
+
393
+ queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'index'});
394
+ //=> 'foo[0]=1&foo[1]=2&foo[2]=3'
395
+ ```
396
+
397
+ - `comma`: Serialize arrays by separating elements with comma:
398
+
399
+ ```
400
+ import queryString from 'query-string';
401
+
402
+ queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'comma'});
403
+ //=> 'foo=1,2,3'
404
+
405
+ queryString.stringify({foo: [1, null, '']}, {arrayFormat: 'comma'});
406
+ //=> 'foo=1,,'
407
+ // Note that typing information for null values is lost
408
+ // and `.parse('foo=1,,')` would return `{foo: [1, '', '']}`.
409
+ ```
410
+
411
+ - `separator`: Serialize arrays by separating elements with character:
412
+
413
+ ```
414
+ import queryString from 'query-string';
415
+
416
+ queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'separator', arrayFormatSeparator: '|'});
417
+ //=> 'foo=1|2|3'
418
+ ```
419
+
420
+ - `bracket-separator`: Serialize arrays by explicitly post-fixing array names with brackets and separating elements with a custom character:
421
+
422
+ ```
423
+ import queryString from 'query-string';
424
+
425
+ queryString.stringify({foo: []}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'});
426
+ //=> 'foo[]'
427
+
428
+ queryString.stringify({foo: ['']}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'});
429
+ //=> 'foo[]='
430
+
431
+ queryString.stringify({foo: [1]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'});
432
+ //=> 'foo[]=1'
433
+
434
+ queryString.stringify({foo: [1, 2, 3]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'});
435
+ //=> 'foo[]=1|2|3'
436
+
437
+ queryString.stringify({foo: [1, '', 3, null, null, 6]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'});
438
+ //=> 'foo[]=1||3|||6'
439
+
440
+ queryString.stringify({foo: [1, '', 3, null, null, 6]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|', skipNull: true});
441
+ //=> 'foo[]=1||3|6'
442
+
443
+ queryString.stringify({foo: [1, 2, 3], bar: 'fluffy', baz: [4]}, {arrayFormat: 'bracket-separator', arrayFormatSeparator: '|'});
444
+ //=> 'foo[]=1|2|3&bar=fluffy&baz[]=4'
445
+ ```
446
+
447
+ - `colon-list-separator`: Serialize arrays with parameter names that are explicitly marked with `:list`:
448
+
449
+ ```js
450
+ import queryString from 'query-string';
451
+
452
+ queryString.stringify({foo: ['one', 'two']}, {arrayFormat: 'colon-list-separator'});
453
+ //=> 'foo:list=one&foo:list=two'
454
+ ```
455
+
456
+ - `none`: Serialize arrays by using duplicate keys:
457
+
458
+ ```
459
+ import queryString from 'query-string';
460
+
461
+ queryString.stringify({foo: [1, 2, 3]});
462
+ //=> 'foo=1&foo=2&foo=3'
463
+ ```
464
+ */
465
+ readonly arrayFormat?:
466
+ | 'bracket'
467
+ | 'index'
468
+ | 'comma'
469
+ | 'separator'
470
+ | 'bracket-separator'
471
+ | 'colon-list-separator'
472
+ | 'none';
473
+
474
+ /**
475
+ The character used to separate array elements when using `{arrayFormat: 'separator'}`.
476
+
477
+ @default ,
478
+ */
479
+ readonly arrayFormatSeparator?: string;
480
+
481
+ /**
482
+ Supports both `Function` as a custom sorting function or `false` to disable sorting.
483
+
484
+ If omitted, keys are sorted using `Array#sort`, which means, converting them to strings and comparing strings in Unicode code point order.
485
+
486
+ @default true
487
+
488
+ @example
489
+ ```
490
+ import queryString from 'query-string';
491
+
492
+ const order = ['c', 'a', 'b'];
493
+
494
+ queryString.stringify({a: 1, b: 2, c: 3}, {
495
+ sort: (itemLeft, itemRight) => order.indexOf(itemLeft) - order.indexOf(itemRight)
496
+ });
497
+ //=> 'c=3&a=1&b=2'
498
+ ```
499
+
500
+ @example
501
+ ```
502
+ import queryString from 'query-string';
503
+
504
+ queryString.stringify({b: 1, c: 2, a: 3}, {sort: false});
505
+ //=> 'b=1&c=2&a=3'
506
+ ```
507
+ */
508
+ readonly sort?: ((itemLeft: string, itemRight: string) => number) | false;
509
+
510
+ /**
511
+ Skip keys with `null` as the value.
512
+
513
+ Note that keys with `undefined` as the value are always skipped.
514
+
515
+ @default false
516
+
517
+ @example
518
+ ```
519
+ import queryString from 'query-string';
520
+
521
+ queryString.stringify({a: 1, b: undefined, c: null, d: 4}, {
522
+ skipNull: true
523
+ });
524
+ //=> 'a=1&d=4'
525
+
526
+ queryString.stringify({a: undefined, b: null}, {
527
+ skipNull: true
528
+ });
529
+ //=> ''
530
+ ```
531
+ */
532
+ readonly skipNull?: boolean;
533
+
534
+ /**
535
+ Skip keys with an empty string as the value.
536
+
537
+ @default false
538
+
539
+ @example
540
+ ```
541
+ import queryString from 'query-string';
542
+
543
+ queryString.stringify({a: 1, b: '', c: '', d: 4}, {
544
+ skipEmptyString: true
545
+ });
546
+ //=> 'a=1&d=4'
547
+ ```
548
+
549
+ @example
550
+ ```
551
+ import queryString from 'query-string';
552
+
553
+ queryString.stringify({a: '', b: ''}, {
554
+ skipEmptyString: true
555
+ });
556
+ //=> ''
557
+ ```
558
+ */
559
+ readonly skipEmptyString?: boolean;
560
+ };
561
+
562
+ export type Stringifiable =
563
+ | string
564
+ | boolean
565
+ | number
566
+ | bigint
567
+ | null
568
+ | undefined;
569
+
570
+ export type StringifiableRecord = Record<
571
+ string,
572
+ Stringifiable | readonly Stringifiable[]
573
+ >;
574
+
575
+ /**
576
+ Stringify an object into a query string and sort the keys.
577
+ */
578
+ export function stringify(
579
+ // TODO: Use the below instead when the following TS issues are fixed:
580
+ // - https://github.com/microsoft/TypeScript/issues/15300
581
+ // - https://github.com/microsoft/TypeScript/issues/42021
582
+ // Context: https://github.com/sindresorhus/query-string/issues/298
583
+ // object: StringifiableRecord,
584
+ object: Record<string, any>,
585
+ options?: StringifyOptions,
586
+ ): string;
587
+
588
+ /**
589
+ Extract a query string from a URL that can be passed into `.parse()`.
590
+
591
+ Note: This behaviour can be changed with the `skipNull` option.
592
+ */
593
+ export function extract(url: string): string;
594
+
595
+ export type UrlObject = {
596
+ readonly url: string;
597
+
598
+ /**
599
+ Overrides queries in the `url` property.
600
+ */
601
+ readonly query?: StringifiableRecord;
602
+
603
+ /**
604
+ Overrides the fragment identifier in the `url` property.
605
+ */
606
+ readonly fragmentIdentifier?: string;
607
+ };
608
+
609
+ /**
610
+ 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)
611
+
612
+ Query items in the `query` property overrides queries in the `url` property.
613
+
614
+ The `fragmentIdentifier` property overrides the fragment identifier in the `url` property.
615
+
616
+ @example
617
+ ```
618
+ queryString.stringifyUrl({url: 'https://foo.bar', query: {foo: 'bar'}});
619
+ //=> 'https://foo.bar?foo=bar'
620
+
621
+ queryString.stringifyUrl({url: 'https://foo.bar?foo=baz', query: {foo: 'bar'}});
622
+ //=> 'https://foo.bar?foo=bar'
623
+
624
+ queryString.stringifyUrl({
625
+ url: 'https://foo.bar',
626
+ query: {
627
+ top: 'foo'
628
+ },
629
+ fragmentIdentifier: 'bar'
630
+ });
631
+ //=> 'https://foo.bar?top=foo#bar'
632
+ ```
633
+ */
634
+ export function stringifyUrl(
635
+ object: UrlObject,
636
+ options?: StringifyOptions,
637
+ ): string;
638
+
639
+ /**
640
+ Pick query parameters from a URL.
641
+
642
+ @param url - The URL containing the query parameters to pick.
643
+ @param keys - The names of the query parameters to keep. All other query parameters will be removed from the URL.
644
+ @param filter - A filter predicate that will be provided the name of each query parameter and its value. The `parseNumbers` and `parseBooleans` options also affect `value`.
645
+
646
+ @returns The URL with the picked query parameters.
647
+
648
+ @example
649
+ ```
650
+ queryString.pick('https://foo.bar?foo=1&bar=2#hello', ['foo']);
651
+ //=> 'https://foo.bar?foo=1#hello'
652
+
653
+ queryString.pick('https://foo.bar?foo=1&bar=2#hello', (name, value) => value === 2, {parseNumbers: true});
654
+ //=> 'https://foo.bar?bar=2#hello'
655
+ ```
656
+ */
657
+ export function pick(
658
+ url: string,
659
+ keys: readonly string[],
660
+ options?: ParseOptions & StringifyOptions,
661
+ ): string;
662
+ export function pick(
663
+ url: string,
664
+ filter: (key: string, value: string | boolean | number) => boolean,
665
+ options?: { parseBooleans: true; parseNumbers: true } & ParseOptions &
666
+ StringifyOptions,
667
+ ): string;
668
+ export function pick(
669
+ url: string,
670
+ filter: (key: string, value: string | boolean) => boolean,
671
+ options?: { parseBooleans: true } & ParseOptions & StringifyOptions,
672
+ ): string;
673
+ export function pick(
674
+ url: string,
675
+ filter: (key: string, value: string | number) => boolean,
676
+ options?: { parseNumbers: true } & ParseOptions & StringifyOptions,
677
+ ): string;
678
+
679
+ /**
680
+ Exclude query parameters from a URL. Like `.pick()` but reversed.
681
+
682
+ @param url - The URL containing the query parameters to exclude.
683
+ @param keys - The names of the query parameters to remove. All other query parameters will remain in the URL.
684
+ @param filter - A filter predicate that will be provided the name of each query parameter and its value. The `parseNumbers` and `parseBooleans` options also affect `value`.
685
+
686
+ @returns The URL without the excluded the query parameters.
687
+
688
+ @example
689
+ ```
690
+ queryString.exclude('https://foo.bar?foo=1&bar=2#hello', ['foo']);
691
+ //=> 'https://foo.bar?bar=2#hello'
692
+
693
+ queryString.exclude('https://foo.bar?foo=1&bar=2#hello', (name, value) => value === 2, {parseNumbers: true});
694
+ //=> 'https://foo.bar?foo=1#hello'
695
+ ```
696
+ */
697
+ export function exclude(
698
+ url: string,
699
+ keys: readonly string[],
700
+ options?: ParseOptions & StringifyOptions,
701
+ ): string;
702
+ export function exclude(
703
+ url: string,
704
+ filter: (key: string, value: string | boolean | number) => boolean,
705
+ options?: { parseBooleans: true; parseNumbers: true } & ParseOptions &
706
+ StringifyOptions,
707
+ ): string;
708
+ export function exclude(
709
+ url: string,
710
+ filter: (key: string, value: string | boolean) => boolean,
711
+ options?: { parseBooleans: true } & ParseOptions & StringifyOptions,
712
+ ): string;
713
+ export function exclude(
714
+ url: string,
715
+ filter: (key: string, value: string | number) => boolean,
716
+ options?: { parseNumbers: true } & ParseOptions & StringifyOptions,
717
+ ): string;