query-string 6.12.0 → 6.13.2
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/index.d.ts +40 -2
- package/index.js +26 -7
- package/license +1 -1
- package/package.json +5 -3
- package/readme.md +41 -10
package/index.d.ts
CHANGED
|
@@ -121,10 +121,25 @@ export interface ParseOptions {
|
|
|
121
121
|
```
|
|
122
122
|
*/
|
|
123
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;
|
|
124
139
|
}
|
|
125
140
|
|
|
126
141
|
export interface ParsedQuery<T = string> {
|
|
127
|
-
[key: string]: T | T[] | null
|
|
142
|
+
[key: string]: T | T[] | null;
|
|
128
143
|
}
|
|
129
144
|
|
|
130
145
|
/**
|
|
@@ -142,11 +157,20 @@ export function parse(query: string, options?: ParseOptions): ParsedQuery;
|
|
|
142
157
|
export interface ParsedUrl {
|
|
143
158
|
readonly url: string;
|
|
144
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;
|
|
145
167
|
}
|
|
146
168
|
|
|
147
169
|
/**
|
|
148
170
|
Extract the URL and the query string as an object.
|
|
149
171
|
|
|
172
|
+
If the `parseFragmentIdentifier` option is `true`, the object will also contain a `fragmentIdentifier` property.
|
|
173
|
+
|
|
150
174
|
@param url - The URL to parse.
|
|
151
175
|
|
|
152
176
|
@example
|
|
@@ -155,6 +179,9 @@ import queryString = require('query-string');
|
|
|
155
179
|
|
|
156
180
|
queryString.parseUrl('https://foo.bar?foo=bar');
|
|
157
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'}
|
|
158
185
|
```
|
|
159
186
|
*/
|
|
160
187
|
export function parseUrl(url: string, options?: ParseOptions): ParsedUrl;
|
|
@@ -298,7 +325,7 @@ export interface StringifyOptions {
|
|
|
298
325
|
});
|
|
299
326
|
//=> 'a=1&d=4'
|
|
300
327
|
```
|
|
301
|
-
|
|
328
|
+
|
|
302
329
|
@example
|
|
303
330
|
```
|
|
304
331
|
import queryString = require('query-string');
|
|
@@ -332,6 +359,8 @@ Stringify an object into a URL with a query string and sorting the keys. The inv
|
|
|
332
359
|
|
|
333
360
|
Query items in the `query` property overrides queries in the `url` property.
|
|
334
361
|
|
|
362
|
+
The `fragmentIdentifier` property overrides the fragment identifier in the `url` property.
|
|
363
|
+
|
|
335
364
|
@example
|
|
336
365
|
```
|
|
337
366
|
queryString.stringifyUrl({url: 'https://foo.bar', query: {foo: 'bar'}});
|
|
@@ -339,6 +368,15 @@ queryString.stringifyUrl({url: 'https://foo.bar', query: {foo: 'bar'}});
|
|
|
339
368
|
|
|
340
369
|
queryString.stringifyUrl({url: 'https://foo.bar?foo=baz', query: {foo: 'bar'}});
|
|
341
370
|
//=> 'https://foo.bar?foo=bar'
|
|
371
|
+
|
|
372
|
+
queryString.stringifyUrl({
|
|
373
|
+
url: 'https://foo.bar',
|
|
374
|
+
query: {
|
|
375
|
+
top: 'foo'
|
|
376
|
+
},
|
|
377
|
+
fragmentIdentifier: 'bar'
|
|
378
|
+
});
|
|
379
|
+
//=> 'https://foo.bar?top=foo#bar'
|
|
342
380
|
```
|
|
343
381
|
*/
|
|
344
382
|
export function stringifyUrl(
|
package/index.js
CHANGED
|
@@ -246,7 +246,7 @@ function parse(input, options) {
|
|
|
246
246
|
|
|
247
247
|
// Missing `=` should be `null`:
|
|
248
248
|
// http://w3.org/TR/2012/WD-url-20120524/#collect-url-parameters
|
|
249
|
-
value = value === undefined ? null : options.arrayFormat
|
|
249
|
+
value = value === undefined ? null : ['comma', 'separator'].includes(options.arrayFormat) ? value : decode(value, options);
|
|
250
250
|
formatter(decode(key, options), value, ret);
|
|
251
251
|
}
|
|
252
252
|
|
|
@@ -338,22 +338,41 @@ exports.stringify = (object, options) => {
|
|
|
338
338
|
};
|
|
339
339
|
|
|
340
340
|
exports.parseUrl = (input, options) => {
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
341
|
+
options = Object.assign({
|
|
342
|
+
decode: true
|
|
343
|
+
}, options);
|
|
344
|
+
|
|
345
|
+
const [url, hash] = splitOnFirst(input, '#');
|
|
346
|
+
|
|
347
|
+
return Object.assign(
|
|
348
|
+
{
|
|
349
|
+
url: url.split('?')[0] || '',
|
|
350
|
+
query: parse(extract(input), options)
|
|
351
|
+
},
|
|
352
|
+
options && options.parseFragmentIdentifier && hash ? {fragmentIdentifier: decode(hash, options)} : {}
|
|
353
|
+
);
|
|
345
354
|
};
|
|
346
355
|
|
|
347
356
|
exports.stringifyUrl = (input, options) => {
|
|
357
|
+
options = Object.assign({
|
|
358
|
+
encode: true,
|
|
359
|
+
strict: true
|
|
360
|
+
}, options);
|
|
361
|
+
|
|
348
362
|
const url = removeHash(input.url).split('?')[0] || '';
|
|
349
363
|
const queryFromUrl = exports.extract(input.url);
|
|
350
|
-
const parsedQueryFromUrl = exports.parse(queryFromUrl);
|
|
351
|
-
|
|
364
|
+
const parsedQueryFromUrl = exports.parse(queryFromUrl, {sort: false});
|
|
365
|
+
|
|
352
366
|
const query = Object.assign(parsedQueryFromUrl, input.query);
|
|
353
367
|
let queryString = exports.stringify(query, options);
|
|
354
368
|
if (queryString) {
|
|
355
369
|
queryString = `?${queryString}`;
|
|
356
370
|
}
|
|
357
371
|
|
|
372
|
+
let hash = getHash(input.url);
|
|
373
|
+
if (input.fragmentIdentifier) {
|
|
374
|
+
hash = `#${encode(input.fragmentIdentifier, options)}`;
|
|
375
|
+
}
|
|
376
|
+
|
|
358
377
|
return `${url}${queryString}${hash}`;
|
|
359
378
|
};
|
package/license
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
MIT License
|
|
2
2
|
|
|
3
|
-
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (sindresorhus.com)
|
|
3
|
+
Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (http://sindresorhus.com)
|
|
4
4
|
|
|
5
5
|
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
|
6
6
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "query-string",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.13.2",
|
|
4
4
|
"description": "Parse and stringify URL query strings",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": "sindresorhus/query-string",
|
|
@@ -8,12 +8,13 @@
|
|
|
8
8
|
"author": {
|
|
9
9
|
"name": "Sindre Sorhus",
|
|
10
10
|
"email": "sindresorhus@gmail.com",
|
|
11
|
-
"url": "sindresorhus.com"
|
|
11
|
+
"url": "https://sindresorhus.com"
|
|
12
12
|
},
|
|
13
13
|
"engines": {
|
|
14
14
|
"node": ">=6"
|
|
15
15
|
},
|
|
16
16
|
"scripts": {
|
|
17
|
+
"benchmark": "node benchmark.js",
|
|
17
18
|
"test": "xo && ava && tsd"
|
|
18
19
|
},
|
|
19
20
|
"files": [
|
|
@@ -36,12 +37,13 @@
|
|
|
36
37
|
"searchparams"
|
|
37
38
|
],
|
|
38
39
|
"dependencies": {
|
|
39
|
-
"split-on-first": "^1.0.0",
|
|
40
40
|
"decode-uri-component": "^0.2.0",
|
|
41
|
+
"split-on-first": "^1.0.0",
|
|
41
42
|
"strict-uri-encode": "^2.0.0"
|
|
42
43
|
},
|
|
43
44
|
"devDependencies": {
|
|
44
45
|
"ava": "^1.4.1",
|
|
46
|
+
"benchmark": "^2.1.4",
|
|
45
47
|
"deep-equal": "^1.0.1",
|
|
46
48
|
"fast-check": "^1.5.0",
|
|
47
49
|
"tsd": "^0.7.3",
|
package/readme.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# query-string [](https://travis-ci.com/github/sindresorhus/query-string) [](https://bundlephobia.com/result?p=query-string)
|
|
2
2
|
|
|
3
3
|
> Parse and stringify URL [query strings](https://en.wikipedia.org/wiki/Query_string)
|
|
4
4
|
|
|
@@ -16,14 +16,9 @@
|
|
|
16
16
|
<sup>Special thanks to:</sup>
|
|
17
17
|
<br>
|
|
18
18
|
<br>
|
|
19
|
-
<a href="https://
|
|
20
|
-
<img src="https://sindresorhus.com/assets/thanks/
|
|
19
|
+
<a href="https://standardresume.co">
|
|
20
|
+
<img src="https://sindresorhus.com/assets/thanks/standard-resume-logo.svg" width="200"/>
|
|
21
21
|
</a>
|
|
22
|
-
<br>
|
|
23
|
-
<sub><b>Botpress is an open-source conversational assistant creation platform.</b></sub>
|
|
24
|
-
<br>
|
|
25
|
-
<sub>They <a href="https://github.com/botpress/botpress/blob/master/.github/CONTRIBUTING.md">welcome contributions</a> from anyone, whether you're into machine learning,<br>want to get started in open-source, or just have an improvement idea.</sub>
|
|
26
|
-
<br>
|
|
27
22
|
</p>
|
|
28
23
|
</div>
|
|
29
24
|
|
|
@@ -339,15 +334,40 @@ Note: This behaviour can be changed with the `skipNull` option.
|
|
|
339
334
|
|
|
340
335
|
Extract the URL and the query string as an object.
|
|
341
336
|
|
|
342
|
-
The `options` are the same as for `.parse()`.
|
|
343
|
-
|
|
344
337
|
Returns an object with a `url` and `query` property.
|
|
345
338
|
|
|
339
|
+
If the `parseFragmentIdentifier` option is `true`, the object will also contain a `fragmentIdentifier` property.
|
|
340
|
+
|
|
346
341
|
```js
|
|
347
342
|
const queryString = require('query-string');
|
|
348
343
|
|
|
349
344
|
queryString.parseUrl('https://foo.bar?foo=bar');
|
|
350
345
|
//=> {url: 'https://foo.bar', query: {foo: 'bar'}}
|
|
346
|
+
|
|
347
|
+
queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
|
|
348
|
+
//=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
|
|
349
|
+
```
|
|
350
|
+
|
|
351
|
+
#### options
|
|
352
|
+
|
|
353
|
+
Type: `object`
|
|
354
|
+
|
|
355
|
+
The options are the same as for `.parse()`.
|
|
356
|
+
|
|
357
|
+
Extra options are as below.
|
|
358
|
+
|
|
359
|
+
##### parseFragmentIdentifier
|
|
360
|
+
|
|
361
|
+
Parse the fragment identifier from the URL.
|
|
362
|
+
|
|
363
|
+
Type: `boolean`\
|
|
364
|
+
Default: `false`
|
|
365
|
+
|
|
366
|
+
```js
|
|
367
|
+
const queryString = require('query-string');
|
|
368
|
+
|
|
369
|
+
queryString.parseUrl('https://foo.bar?foo=bar#xyz', {parseFragmentIdentifier: true});
|
|
370
|
+
//=> {url: 'https://foo.bar', query: {foo: 'bar'}, fragmentIdentifier: 'xyz'}
|
|
351
371
|
```
|
|
352
372
|
|
|
353
373
|
### .stringifyUrl(object, options?)
|
|
@@ -360,12 +380,23 @@ Returns a string with the URL and a query string.
|
|
|
360
380
|
|
|
361
381
|
Query items in the `query` property overrides queries in the `url` property.
|
|
362
382
|
|
|
383
|
+
The `fragmentIdentifier` property overrides the fragment identifier in the `url` property.
|
|
384
|
+
|
|
363
385
|
```js
|
|
364
386
|
queryString.stringifyUrl({url: 'https://foo.bar', query: {foo: 'bar'}});
|
|
365
387
|
//=> 'https://foo.bar?foo=bar'
|
|
366
388
|
|
|
367
389
|
queryString.stringifyUrl({url: 'https://foo.bar?foo=baz', query: {foo: 'bar'}});
|
|
368
390
|
//=> 'https://foo.bar?foo=bar'
|
|
391
|
+
|
|
392
|
+
queryString.stringifyUrl({
|
|
393
|
+
url: 'https://foo.bar',
|
|
394
|
+
query: {
|
|
395
|
+
top: 'foo'
|
|
396
|
+
},
|
|
397
|
+
fragmentIdentifier: 'bar'
|
|
398
|
+
});
|
|
399
|
+
//=> 'https://foo.bar?top=foo#bar'
|
|
369
400
|
```
|
|
370
401
|
|
|
371
402
|
#### object
|