query-string 8.1.0 → 9.0.0
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 +2 -2
- package/base.js +12 -17
- package/package.json +8 -7
- package/readme.md +3 -2
package/base.d.ts
CHANGED
|
@@ -220,7 +220,7 @@ export function parseUrl(url: string, options?: ParseOptions): ParsedUrl;
|
|
|
220
220
|
|
|
221
221
|
export type StringifyOptions = {
|
|
222
222
|
/**
|
|
223
|
-
Strictly encode URI components
|
|
223
|
+
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.
|
|
224
224
|
|
|
225
225
|
@default true
|
|
226
226
|
*/
|
|
@@ -412,7 +412,7 @@ export type StringifyOptions = {
|
|
|
412
412
|
readonly skipEmptyString?: boolean;
|
|
413
413
|
};
|
|
414
414
|
|
|
415
|
-
export type Stringifiable = string | boolean | number | null | undefined; // eslint-disable-line @typescript-eslint/ban-types
|
|
415
|
+
export type Stringifiable = string | boolean | number | bigint | null | undefined; // eslint-disable-line @typescript-eslint/ban-types
|
|
416
416
|
|
|
417
417
|
export type StringifiableRecord = Record<
|
|
418
418
|
string,
|
package/base.js
CHANGED
|
@@ -5,7 +5,7 @@ import {includeKeys} from 'filter-obj';
|
|
|
5
5
|
const isNullOrUndefined = value => value === null || value === undefined;
|
|
6
6
|
|
|
7
7
|
// eslint-disable-next-line unicorn/prefer-code-point
|
|
8
|
-
const strictUriEncode = string => encodeURIComponent(string).
|
|
8
|
+
const strictUriEncode = string => encodeURIComponent(string).replaceAll(/[!'()*]/g, x => `%${x.charCodeAt(0).toString(16).toUpperCase()}`);
|
|
9
9
|
|
|
10
10
|
const encodeFragmentIdentifier = Symbol('encodeFragmentIdentifier');
|
|
11
11
|
|
|
@@ -87,7 +87,7 @@ function encoderForArrayFormat(options) {
|
|
|
87
87
|
case 'comma':
|
|
88
88
|
case 'separator':
|
|
89
89
|
case 'bracket-separator': {
|
|
90
|
-
const
|
|
90
|
+
const keyValueSeparator = options.arrayFormat === 'bracket-separator'
|
|
91
91
|
? '[]='
|
|
92
92
|
: '=';
|
|
93
93
|
|
|
@@ -104,7 +104,7 @@ function encoderForArrayFormat(options) {
|
|
|
104
104
|
value = value === null ? '' : value;
|
|
105
105
|
|
|
106
106
|
if (result.length === 0) {
|
|
107
|
-
return [[encode(key, options),
|
|
107
|
+
return [[encode(key, options), keyValueSeparator, encode(value, options)].join('')];
|
|
108
108
|
}
|
|
109
109
|
|
|
110
110
|
return [[result, encode(value, options)].join(options.arrayFormatSeparator)];
|
|
@@ -353,7 +353,7 @@ export function parse(query, options) {
|
|
|
353
353
|
continue;
|
|
354
354
|
}
|
|
355
355
|
|
|
356
|
-
const parameter_ = options.decode ? parameter.
|
|
356
|
+
const parameter_ = options.decode ? parameter.replaceAll('+', ' ') : parameter;
|
|
357
357
|
|
|
358
358
|
let [key, value] = splitOnFirst(parameter_, '=');
|
|
359
359
|
|
|
@@ -385,13 +385,7 @@ export function parse(query, options) {
|
|
|
385
385
|
// eslint-disable-next-line unicorn/no-array-reduce
|
|
386
386
|
return (options.sort === true ? Object.keys(returnValue).sort() : Object.keys(returnValue).sort(options.sort)).reduce((result, key) => {
|
|
387
387
|
const value = returnValue[key];
|
|
388
|
-
|
|
389
|
-
// Sort object keys, not values
|
|
390
|
-
result[key] = keysSorter(value);
|
|
391
|
-
} else {
|
|
392
|
-
result[key] = value;
|
|
393
|
-
}
|
|
394
|
-
|
|
388
|
+
result[key] = Boolean(value) && typeof value === 'object' && !Array.isArray(value) ? keysSorter(value) : value;
|
|
395
389
|
return result;
|
|
396
390
|
}, Object.create(null));
|
|
397
391
|
}
|
|
@@ -401,10 +395,13 @@ export function stringify(object, options) {
|
|
|
401
395
|
return '';
|
|
402
396
|
}
|
|
403
397
|
|
|
404
|
-
options = {
|
|
398
|
+
options = {
|
|
399
|
+
encode: true,
|
|
405
400
|
strict: true,
|
|
406
401
|
arrayFormat: 'none',
|
|
407
|
-
arrayFormatSeparator: ',',
|
|
402
|
+
arrayFormatSeparator: ',',
|
|
403
|
+
...options,
|
|
404
|
+
};
|
|
408
405
|
|
|
409
406
|
validateArrayFormatSeparator(options.arrayFormatSeparator);
|
|
410
407
|
|
|
@@ -490,12 +487,10 @@ export function stringifyUrl(object, options) {
|
|
|
490
487
|
};
|
|
491
488
|
|
|
492
489
|
let queryString = stringify(query, options);
|
|
493
|
-
|
|
494
|
-
queryString = `?${queryString}`;
|
|
495
|
-
}
|
|
490
|
+
queryString &&= `?${queryString}`;
|
|
496
491
|
|
|
497
492
|
let hash = getHash(object.url);
|
|
498
|
-
if (object.fragmentIdentifier) {
|
|
493
|
+
if (typeof object.fragmentIdentifier === 'string') {
|
|
499
494
|
const urlObjectForFragmentEncode = new URL(url);
|
|
500
495
|
urlObjectForFragmentEncode.hash = object.fragmentIdentifier;
|
|
501
496
|
hash = options[encodeFragmentIdentifier] ? urlObjectForFragmentEncode.hash : `#${object.fragmentIdentifier}`;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "query-string",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "9.0.0",
|
|
4
4
|
"description": "Parse and stringify URL query strings",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/query-string",
|
|
@@ -15,8 +15,9 @@
|
|
|
15
15
|
"types": "./index.d.ts",
|
|
16
16
|
"default": "./index.js"
|
|
17
17
|
},
|
|
18
|
+
"sideEffects": false,
|
|
18
19
|
"engines": {
|
|
19
|
-
"node": ">=
|
|
20
|
+
"node": ">=18"
|
|
20
21
|
},
|
|
21
22
|
"scripts": {
|
|
22
23
|
"benchmark": "node benchmark.js",
|
|
@@ -50,12 +51,12 @@
|
|
|
50
51
|
"split-on-first": "^3.0.0"
|
|
51
52
|
},
|
|
52
53
|
"devDependencies": {
|
|
53
|
-
"ava": "^
|
|
54
|
+
"ava": "^6.1.1",
|
|
54
55
|
"benchmark": "^2.1.4",
|
|
55
|
-
"deep-equal": "^2.
|
|
56
|
-
"fast-check": "^3.
|
|
57
|
-
"tsd": "^0.
|
|
58
|
-
"xo": "^0.
|
|
56
|
+
"deep-equal": "^2.2.3",
|
|
57
|
+
"fast-check": "^3.15.1",
|
|
58
|
+
"tsd": "^0.30.7",
|
|
59
|
+
"xo": "^0.57.0"
|
|
59
60
|
},
|
|
60
61
|
"tsd": {
|
|
61
62
|
"compilerOptions": {
|
package/readme.md
CHANGED
|
@@ -44,7 +44,8 @@
|
|
|
44
44
|
npm install query-string
|
|
45
45
|
```
|
|
46
46
|
|
|
47
|
-
|
|
47
|
+
> [!WARNING]
|
|
48
|
+
> Remember the hyphen! Do not install the deprecated [`querystring`](https://github.com/Gozala/querystring) package!
|
|
48
49
|
|
|
49
50
|
For browser usage, this package targets the latest version of Chrome, Firefox, and Safari.
|
|
50
51
|
|
|
@@ -236,7 +237,7 @@ Type: `object`
|
|
|
236
237
|
Type: `boolean`\
|
|
237
238
|
Default: `true`
|
|
238
239
|
|
|
239
|
-
Strictly encode URI components
|
|
240
|
+
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.
|
|
240
241
|
|
|
241
242
|
##### encode
|
|
242
243
|
|