query-string 5.0.1 → 5.1.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/index.js +12 -1
- package/package.json +43 -43
- package/readme.md +40 -2
package/index.js
CHANGED
|
@@ -176,9 +176,13 @@ exports.stringify = function (obj, opts) {
|
|
|
176
176
|
|
|
177
177
|
opts = objectAssign(defaults, opts);
|
|
178
178
|
|
|
179
|
+
if (opts.sort === false) {
|
|
180
|
+
opts.sort = function () {};
|
|
181
|
+
}
|
|
182
|
+
|
|
179
183
|
var formatter = encoderForArrayFormat(opts);
|
|
180
184
|
|
|
181
|
-
return obj ? Object.keys(obj).sort().map(function (key) {
|
|
185
|
+
return obj ? Object.keys(obj).sort(opts.sort).map(function (key) {
|
|
182
186
|
var val = obj[key];
|
|
183
187
|
|
|
184
188
|
if (val === undefined) {
|
|
@@ -208,3 +212,10 @@ exports.stringify = function (obj, opts) {
|
|
|
208
212
|
return x.length > 0;
|
|
209
213
|
}).join('&') : '';
|
|
210
214
|
};
|
|
215
|
+
|
|
216
|
+
exports.parseUrl = function (str, opts) {
|
|
217
|
+
return {
|
|
218
|
+
url: str.split('?')[0] || '',
|
|
219
|
+
query: this.parse(this.extract(str), opts)
|
|
220
|
+
};
|
|
221
|
+
};
|
package/package.json
CHANGED
|
@@ -1,45 +1,45 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
2
|
+
"name": "query-string",
|
|
3
|
+
"version": "5.1.0",
|
|
4
|
+
"description": "Parse and stringify URL query strings",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": "sindresorhus/query-string",
|
|
7
|
+
"author": {
|
|
8
|
+
"name": "Sindre Sorhus",
|
|
9
|
+
"email": "sindresorhus@gmail.com",
|
|
10
|
+
"url": "sindresorhus.com"
|
|
11
|
+
},
|
|
12
|
+
"engines": {
|
|
13
|
+
"node": ">=0.10.0"
|
|
14
|
+
},
|
|
15
|
+
"scripts": {
|
|
16
|
+
"test": "xo && ava"
|
|
17
|
+
},
|
|
18
|
+
"files": [
|
|
19
|
+
"index.js"
|
|
20
|
+
],
|
|
21
|
+
"keywords": [
|
|
22
|
+
"browser",
|
|
23
|
+
"querystring",
|
|
24
|
+
"query",
|
|
25
|
+
"string",
|
|
26
|
+
"qs",
|
|
27
|
+
"param",
|
|
28
|
+
"parameter",
|
|
29
|
+
"url",
|
|
30
|
+
"uri",
|
|
31
|
+
"parse",
|
|
32
|
+
"stringify",
|
|
33
|
+
"encode",
|
|
34
|
+
"decode"
|
|
35
|
+
],
|
|
36
|
+
"dependencies": {
|
|
37
|
+
"decode-uri-component": "^0.2.0",
|
|
38
|
+
"object-assign": "^4.1.0",
|
|
39
|
+
"strict-uri-encode": "^1.0.0"
|
|
40
|
+
},
|
|
41
|
+
"devDependencies": {
|
|
42
|
+
"ava": "^0.17.0",
|
|
43
|
+
"xo": "^0.16.0"
|
|
44
|
+
}
|
|
45
45
|
}
|
package/readme.md
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
# query-string [](https://travis-ci.org/sindresorhus/query-string)
|
|
2
2
|
|
|
3
|
-
> Parse and stringify URL [query strings](
|
|
3
|
+
> Parse and stringify URL [query strings](https://en.wikipedia.org/wiki/Query_string)
|
|
4
4
|
|
|
5
5
|
---
|
|
6
6
|
|
|
7
|
-
<p align="center"><b>🔥 Want to strengthen your core JavaScript skills and master ES6?</b><br>I would personally recommend this awesome <a href="https://ES6.io/friend/AWESOME">ES6 course</a> by Wes Bos
|
|
7
|
+
<p align="center"><b>🔥 Want to strengthen your core JavaScript skills and master ES6?</b><br>I would personally recommend this awesome <a href="https://ES6.io/friend/AWESOME">ES6 course</a> by Wes Bos.<br>Also check out his <a href="https://LearnNode.com/friend/AWESOME">Node.js</a>, <a href="https://ReactForBeginners.com/friend/AWESOME">React</a>, <a href="https://SublimeTextBook.com/friend/AWESOME">Sublime</a> courses.</p>
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
@@ -15,6 +15,10 @@
|
|
|
15
15
|
$ npm install query-string
|
|
16
16
|
```
|
|
17
17
|
|
|
18
|
+
<a href="https://www.patreon.com/sindresorhus">
|
|
19
|
+
<img src="https://c5.patreon.com/external/logo/become_a_patron_button@2x.png" width="160">
|
|
20
|
+
</a>
|
|
21
|
+
|
|
18
22
|
|
|
19
23
|
## Usage
|
|
20
24
|
|
|
@@ -133,10 +137,44 @@ queryString.stringify({foo: [1,2,3]});
|
|
|
133
137
|
// => foo=1&foo=2&foo=3
|
|
134
138
|
```
|
|
135
139
|
|
|
140
|
+
#### sort
|
|
141
|
+
|
|
142
|
+
Type: `Function` `boolean`
|
|
143
|
+
|
|
144
|
+
Supports both `Function` as a custom sorting function or `false` to disable sorting.
|
|
145
|
+
|
|
146
|
+
```js
|
|
147
|
+
const order = ['c', 'a', 'b'];
|
|
148
|
+
queryString.stringify({ a: 1, b: 2, c: 3}, {
|
|
149
|
+
sort: (m, n) => order.indexOf(m) >= order.indexOf(n)
|
|
150
|
+
});
|
|
151
|
+
// => 'c=3&a=1&b=2'
|
|
152
|
+
```
|
|
153
|
+
|
|
154
|
+
```js
|
|
155
|
+
queryString.stringify({ b: 1, c: 2, a: 3}, {sort: false});
|
|
156
|
+
// => 'c=3&a=1&b=2'
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
If omitted, keys are sorted using `Array#sort`, which means, converting them to strings and comparing strings in Unicode code point order.
|
|
160
|
+
|
|
136
161
|
### .extract(*string*)
|
|
137
162
|
|
|
138
163
|
Extract a query string from a URL that can be passed into `.parse()`.
|
|
139
164
|
|
|
165
|
+
### .parseUrl(*string*, *[options]*)
|
|
166
|
+
|
|
167
|
+
Extract the URL and the query string as an object.
|
|
168
|
+
|
|
169
|
+
The `options` are the same as for `.parse()`.
|
|
170
|
+
|
|
171
|
+
Returns an object with a `url` and `query` property.
|
|
172
|
+
|
|
173
|
+
```js
|
|
174
|
+
queryString.parseUrl('https://foo.bar?foo=bar');
|
|
175
|
+
//=> {url: 'https://foo.bar', query: {foo: 'bar'}}
|
|
176
|
+
```
|
|
177
|
+
|
|
140
178
|
|
|
141
179
|
## Nesting
|
|
142
180
|
|