qs 5.0.0 → 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/.travis.yml +4 -4
- package/CHANGELOG.md +6 -1
- package/README.md +11 -4
- package/bower.json +1 -1
- package/component.json +15 -0
- package/dist/qs.js +3 -2
- package/lib/stringify.js +28 -7
- package/package.json +11 -9
- package/test/stringify.js +21 -0
package/.travis.yml
CHANGED
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
|
|
2
|
-
## [**
|
|
2
|
+
## [**5.1.0**](https://github.com/hapijs/qs/issues?milestone=29&state=open)
|
|
3
|
+
- [**#117**](https://github.com/hapijs/qs/issues/117) make URI encoding stringified results optional
|
|
4
|
+
- [**#106**](https://github.com/hapijs/qs/issues/106) Add flag `skipNulls` to optionally skip null values in stringify
|
|
5
|
+
|
|
6
|
+
## [**5.0.0**](https://github.com/hapijs/qs/issues?milestone=28&state=closed)
|
|
7
|
+
- [**#114**](https://github.com/hapijs/qs/issues/114) default allowDots to false
|
|
3
8
|
- [**#100**](https://github.com/hapijs/qs/issues/100) include dist to npm
|
|
4
9
|
|
|
5
10
|
## [**4.0.0**](https://github.com/hapijs/qs/issues?milestone=26&state=closed)
|
package/README.md
CHANGED
|
@@ -23,7 +23,7 @@ var str = Qs.stringify(obj); // 'a=c'
|
|
|
23
23
|
Qs.parse(string, [options]);
|
|
24
24
|
```
|
|
25
25
|
|
|
26
|
-
**qs** allows you to create nested objects within your query strings, by surrounding the name of sub-keys with square brackets `[]
|
|
26
|
+
**qs** allows you to create nested objects within your query strings, by surrounding the name of sub-keys with square brackets `[]`.
|
|
27
27
|
For example, the string `'foo[bar]=baz'` converts to:
|
|
28
28
|
|
|
29
29
|
```javascript
|
|
@@ -118,11 +118,11 @@ Qs.parse('a=b;c=d,e=f', { delimiter: /[;,]/ });
|
|
|
118
118
|
// { a: 'b', c: 'd', e: 'f' }
|
|
119
119
|
```
|
|
120
120
|
|
|
121
|
-
Option `allowDots` can be used to
|
|
121
|
+
Option `allowDots` can be used to enable dot notation:
|
|
122
122
|
|
|
123
123
|
```javascript
|
|
124
|
-
Qs.parse('a.b=c', { allowDots:
|
|
125
|
-
// {
|
|
124
|
+
Qs.parse('a.b=c', { allowDots: true });
|
|
125
|
+
// { a: { b: 'c' } }
|
|
126
126
|
```
|
|
127
127
|
|
|
128
128
|
### Parsing Arrays
|
|
@@ -315,3 +315,10 @@ Qs.parse('a&b=', { strictNullHandling: true });
|
|
|
315
315
|
// { a: null, b: '' }
|
|
316
316
|
|
|
317
317
|
```
|
|
318
|
+
|
|
319
|
+
To completely skip rendering keys with `null` values, use the `skipNulls` flag:
|
|
320
|
+
|
|
321
|
+
```javascript
|
|
322
|
+
qs.stringify({ a: 'b', c: null}, { skipNulls: true })
|
|
323
|
+
// 'a=b'
|
|
324
|
+
```
|
package/bower.json
CHANGED
package/component.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "qs",
|
|
3
|
+
"repository": "hapijs/qs",
|
|
4
|
+
"description": "query-string parser / stringifier with nesting support",
|
|
5
|
+
"version": "5.1.0",
|
|
6
|
+
"keywords": ["querystring", "query", "parser"],
|
|
7
|
+
"main": "lib/index.js",
|
|
8
|
+
"scripts": [
|
|
9
|
+
"lib/index.js",
|
|
10
|
+
"lib/parse.js",
|
|
11
|
+
"lib/stringify.js",
|
|
12
|
+
"lib/utils.js"
|
|
13
|
+
],
|
|
14
|
+
"license": "BSD-3-Clause"
|
|
15
|
+
}
|
package/dist/qs.js
CHANGED
|
@@ -30,7 +30,8 @@ var internals = {
|
|
|
30
30
|
parameterLimit: 1000,
|
|
31
31
|
strictNullHandling: false,
|
|
32
32
|
plainObjects: false,
|
|
33
|
-
allowPrototypes: false
|
|
33
|
+
allowPrototypes: false,
|
|
34
|
+
allowDots: false
|
|
34
35
|
};
|
|
35
36
|
|
|
36
37
|
|
|
@@ -175,7 +176,7 @@ module.exports = function (str, options) {
|
|
|
175
176
|
options.depth = typeof options.depth === 'number' ? options.depth : internals.depth;
|
|
176
177
|
options.arrayLimit = typeof options.arrayLimit === 'number' ? options.arrayLimit : internals.arrayLimit;
|
|
177
178
|
options.parseArrays = options.parseArrays !== false;
|
|
178
|
-
options.allowDots = options.allowDots
|
|
179
|
+
options.allowDots = typeof options.allowDots === 'boolean' ? options.allowDots : internals.allowDots;
|
|
179
180
|
options.plainObjects = typeof options.plainObjects === 'boolean' ? options.plainObjects : internals.plainObjects;
|
|
180
181
|
options.allowPrototypes = typeof options.allowPrototypes === 'boolean' ? options.allowPrototypes : internals.allowPrototypes;
|
|
181
182
|
options.parameterLimit = typeof options.parameterLimit === 'number' ? options.parameterLimit : internals.parameterLimit;
|
package/lib/stringify.js
CHANGED
|
@@ -21,11 +21,13 @@ var internals = {
|
|
|
21
21
|
return prefix;
|
|
22
22
|
}
|
|
23
23
|
},
|
|
24
|
-
strictNullHandling: false
|
|
24
|
+
strictNullHandling: false,
|
|
25
|
+
skipNulls: false,
|
|
26
|
+
encode: true
|
|
25
27
|
};
|
|
26
28
|
|
|
27
29
|
|
|
28
|
-
internals.stringify = function (obj, prefix, generateArrayPrefix, strictNullHandling, filter) {
|
|
30
|
+
internals.stringify = function (obj, prefix, generateArrayPrefix, strictNullHandling, skipNulls, encode, filter) {
|
|
29
31
|
|
|
30
32
|
if (typeof filter === 'function') {
|
|
31
33
|
obj = filter(prefix, obj);
|
|
@@ -38,7 +40,7 @@ internals.stringify = function (obj, prefix, generateArrayPrefix, strictNullHand
|
|
|
38
40
|
}
|
|
39
41
|
else if (obj === null) {
|
|
40
42
|
if (strictNullHandling) {
|
|
41
|
-
return Utils.encode(prefix);
|
|
43
|
+
return encode ? Utils.encode(prefix) : prefix;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
obj = '';
|
|
@@ -48,7 +50,10 @@ internals.stringify = function (obj, prefix, generateArrayPrefix, strictNullHand
|
|
|
48
50
|
typeof obj === 'number' ||
|
|
49
51
|
typeof obj === 'boolean') {
|
|
50
52
|
|
|
51
|
-
|
|
53
|
+
if (encode) {
|
|
54
|
+
return [Utils.encode(prefix) + '=' + Utils.encode(obj)];
|
|
55
|
+
}
|
|
56
|
+
return [prefix + '=' + obj];
|
|
52
57
|
}
|
|
53
58
|
|
|
54
59
|
var values = [];
|
|
@@ -61,11 +66,17 @@ internals.stringify = function (obj, prefix, generateArrayPrefix, strictNullHand
|
|
|
61
66
|
for (var i = 0, il = objKeys.length; i < il; ++i) {
|
|
62
67
|
var key = objKeys[i];
|
|
63
68
|
|
|
69
|
+
if (skipNulls &&
|
|
70
|
+
obj[key] === null) {
|
|
71
|
+
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
|
|
64
75
|
if (Array.isArray(obj)) {
|
|
65
|
-
values = values.concat(internals.stringify(obj[key], generateArrayPrefix(prefix, key), generateArrayPrefix, strictNullHandling, filter));
|
|
76
|
+
values = values.concat(internals.stringify(obj[key], generateArrayPrefix(prefix, key), generateArrayPrefix, strictNullHandling, skipNulls, encode, filter));
|
|
66
77
|
}
|
|
67
78
|
else {
|
|
68
|
-
values = values.concat(internals.stringify(obj[key], prefix + '[' + key + ']', generateArrayPrefix, strictNullHandling, filter));
|
|
79
|
+
values = values.concat(internals.stringify(obj[key], prefix + '[' + key + ']', generateArrayPrefix, strictNullHandling, skipNulls, encode, filter));
|
|
69
80
|
}
|
|
70
81
|
}
|
|
71
82
|
|
|
@@ -78,6 +89,8 @@ module.exports = function (obj, options) {
|
|
|
78
89
|
options = options || {};
|
|
79
90
|
var delimiter = typeof options.delimiter === 'undefined' ? internals.delimiter : options.delimiter;
|
|
80
91
|
var strictNullHandling = typeof options.strictNullHandling === 'boolean' ? options.strictNullHandling : internals.strictNullHandling;
|
|
92
|
+
var skipNulls = typeof options.skipNulls === 'boolean' ? options.skipNulls : internals.skipNulls;
|
|
93
|
+
var encode = typeof options.encode === 'boolean' ? options.encode : internals.encode;
|
|
81
94
|
var objKeys;
|
|
82
95
|
var filter;
|
|
83
96
|
if (typeof options.filter === 'function') {
|
|
@@ -112,9 +125,17 @@ module.exports = function (obj, options) {
|
|
|
112
125
|
if (!objKeys) {
|
|
113
126
|
objKeys = Object.keys(obj);
|
|
114
127
|
}
|
|
128
|
+
|
|
115
129
|
for (var i = 0, il = objKeys.length; i < il; ++i) {
|
|
116
130
|
var key = objKeys[i];
|
|
117
|
-
|
|
131
|
+
|
|
132
|
+
if (skipNulls &&
|
|
133
|
+
obj[key] === null) {
|
|
134
|
+
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
keys = keys.concat(internals.stringify(obj[key], key, generateArrayPrefix, strictNullHandling, skipNulls, encode, filter));
|
|
118
139
|
}
|
|
119
140
|
|
|
120
141
|
return keys.join(delimiter);
|
package/package.json
CHANGED
|
@@ -1,9 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qs",
|
|
3
|
-
"version": "5.0.0",
|
|
4
3
|
"description": "A querystring parser that supports nesting and arrays, with a depth limit",
|
|
5
4
|
"homepage": "https://github.com/hapijs/qs",
|
|
5
|
+
"version": "5.1.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/hapijs/qs.git"
|
|
9
|
+
},
|
|
6
10
|
"main": "lib/index.js",
|
|
11
|
+
"keywords": [
|
|
12
|
+
"querystring",
|
|
13
|
+
"qs"
|
|
14
|
+
],
|
|
15
|
+
"engines": ">=0.10.40",
|
|
7
16
|
"dependencies": {},
|
|
8
17
|
"devDependencies": {
|
|
9
18
|
"browserify": "^10.2.1",
|
|
@@ -12,16 +21,9 @@
|
|
|
12
21
|
},
|
|
13
22
|
"scripts": {
|
|
14
23
|
"test": "lab -a code -t 100 -L",
|
|
24
|
+
"test-tap": "lab -a code -r tap -o tests.tap",
|
|
15
25
|
"test-cov-html": "lab -a code -r html -o coverage.html",
|
|
16
26
|
"dist": "browserify --standalone Qs lib/index.js > dist/qs.js"
|
|
17
27
|
},
|
|
18
|
-
"repository": {
|
|
19
|
-
"type": "git",
|
|
20
|
-
"url": "https://github.com/hapijs/qs.git"
|
|
21
|
-
},
|
|
22
|
-
"keywords": [
|
|
23
|
-
"querystring",
|
|
24
|
-
"qs"
|
|
25
|
-
],
|
|
26
28
|
"license": "BSD-3-Clause"
|
|
27
29
|
}
|
package/test/stringify.js
CHANGED
|
@@ -47,6 +47,19 @@ describe('stringify()', function () {
|
|
|
47
47
|
done();
|
|
48
48
|
});
|
|
49
49
|
|
|
50
|
+
it('omits nulls when asked', function (done) {
|
|
51
|
+
|
|
52
|
+
expect(Qs.stringify({ a: 'b', c: null }, { skipNulls: true })).to.equal('a=b');
|
|
53
|
+
done();
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
it('omits nested nulls when asked', function (done) {
|
|
58
|
+
|
|
59
|
+
expect(Qs.stringify({ a: { b: 'c', d: null } }, { skipNulls: true })).to.equal('a%5Bb%5D=c');
|
|
60
|
+
done();
|
|
61
|
+
});
|
|
62
|
+
|
|
50
63
|
it('omits array indices when asked', function (done) {
|
|
51
64
|
|
|
52
65
|
expect(Qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false })).to.equal('a=b&a=c&a=d');
|
|
@@ -257,4 +270,12 @@ describe('stringify()', function () {
|
|
|
257
270
|
done();
|
|
258
271
|
|
|
259
272
|
});
|
|
273
|
+
|
|
274
|
+
it('can disable uri encoding', function (done) {
|
|
275
|
+
|
|
276
|
+
expect(Qs.stringify({ a: 'b' }, { encode: false })).to.equal('a=b');
|
|
277
|
+
expect(Qs.stringify({ a: { b: 'c' } }, { encode: false })).to.equal('a[b]=c');
|
|
278
|
+
expect(Qs.stringify({ a: 'b', c: null }, { strictNullHandling: true, encode: false })).to.equal('a=b&c');
|
|
279
|
+
done();
|
|
280
|
+
});
|
|
260
281
|
});
|