qs 0.6.5 → 1.0.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/.jshintignore +1 -0
- package/.jshintrc +10 -0
- package/.npmignore +18 -7
- package/.travis.yml +4 -0
- package/LICENSE +28 -0
- package/Makefile +8 -0
- package/README.md +120 -0
- package/index.js +1 -387
- package/lib/index.js +15 -0
- package/lib/parse.js +151 -0
- package/lib/stringify.js +52 -0
- package/lib/utils.js +131 -0
- package/package.json +22 -13
- package/test/parse.js +236 -0
- package/test/stringify.js +123 -0
- package/.gitmodules +0 -6
- package/Readme.md +0 -58
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Load modules
|
|
2
|
+
|
|
3
|
+
var Lab = require('lab');
|
|
4
|
+
var Qs = require('../');
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
// Declare internals
|
|
8
|
+
|
|
9
|
+
var internals = {};
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
// Test shortcuts
|
|
13
|
+
|
|
14
|
+
var expect = Lab.expect;
|
|
15
|
+
var before = Lab.before;
|
|
16
|
+
var after = Lab.after;
|
|
17
|
+
var describe = Lab.experiment;
|
|
18
|
+
var it = Lab.test;
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
describe('#stringify', function () {
|
|
22
|
+
|
|
23
|
+
it('stringifies a querystring object', function (done) {
|
|
24
|
+
|
|
25
|
+
expect(Qs.stringify({ a: 'b' })).to.equal('a=b');
|
|
26
|
+
expect(Qs.stringify({ a: 1 })).to.equal('a=1');
|
|
27
|
+
expect(Qs.stringify({ a: 1, b: 2 })).to.equal('a=1&b=2');
|
|
28
|
+
done();
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('stringifies a nested object', function (done) {
|
|
32
|
+
|
|
33
|
+
expect(Qs.stringify({ a: { b: 'c' } })).to.equal('a[b]=c');
|
|
34
|
+
expect(Qs.stringify({ a: { b: { c: { d: 'e' } } } })).to.equal('a[b][c][d]=e');
|
|
35
|
+
done();
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it('stringifies an array value', function (done) {
|
|
39
|
+
|
|
40
|
+
expect(Qs.stringify({ a: ['b', 'c', 'd'] })).to.equal('a[0]=b&a[1]=c&a[2]=d');
|
|
41
|
+
done();
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it('stringifies a nested array value', function (done) {
|
|
45
|
+
|
|
46
|
+
expect(Qs.stringify({ a: { b: ['c', 'd'] } })).to.equal('a[b][0]=c&a[b][1]=d');
|
|
47
|
+
done();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('stringifies an object inside an array', function (done) {
|
|
51
|
+
|
|
52
|
+
expect(Qs.stringify({ a: [{ b: 'c' }] })).to.equal('a[0][b]=c');
|
|
53
|
+
expect(Qs.stringify({ a: [{ b: { c: [1] } }] })).to.equal('a[0][b][c][0]=1');
|
|
54
|
+
done();
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('stringifies a complicated object', function (done) {
|
|
58
|
+
|
|
59
|
+
expect(Qs.stringify({ a: { b: 'c', d: 'e' } })).to.equal('a[b]=c&a[d]=e');
|
|
60
|
+
done();
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it('stringifies an empty value', function (done) {
|
|
64
|
+
|
|
65
|
+
expect(Qs.stringify({ a: '' })).to.equal('a=');
|
|
66
|
+
expect(Qs.stringify({ a: '', b: '' })).to.equal('a=&b=');
|
|
67
|
+
expect(Qs.stringify({ a: null })).to.equal('a');
|
|
68
|
+
expect(Qs.stringify({ a: { b: null } })).to.equal('a[b]');
|
|
69
|
+
done();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it('drops keys with a value of undefined', function (done) {
|
|
73
|
+
|
|
74
|
+
expect(Qs.stringify({ a: undefined })).to.equal('');
|
|
75
|
+
expect(Qs.stringify({ a: { b: undefined, c: null } })).to.equal('a[c]');
|
|
76
|
+
done();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('url encodes values', function (done) {
|
|
80
|
+
|
|
81
|
+
expect(Qs.stringify({ a: 'b c' })).to.equal('a=b%20c');
|
|
82
|
+
done();
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it('stringifies a date', function (done) {
|
|
86
|
+
|
|
87
|
+
var now = new Date();
|
|
88
|
+
var str = 'a=' + encodeURIComponent(now.toISOString());
|
|
89
|
+
expect(Qs.stringify({ a: now })).to.equal(str);
|
|
90
|
+
done();
|
|
91
|
+
});
|
|
92
|
+
|
|
93
|
+
it('stringifies the weird object from qs', function (done) {
|
|
94
|
+
|
|
95
|
+
expect(Qs.stringify({ 'my weird field': 'q1!2"\'w$5&7/z8)?' })).to.equal('my%20weird%20field=q1!2%22\'w%245%267%2Fz8)%3F');
|
|
96
|
+
done();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it('skips properties that are part of the object prototype', function (done) {
|
|
100
|
+
|
|
101
|
+
Object.prototype.crash = 'test';
|
|
102
|
+
expect(Qs.stringify({ a: 'b'})).to.equal('a=b');
|
|
103
|
+
expect(Qs.stringify({ a: { b: 'c' } })).to.equal('a[b]=c');
|
|
104
|
+
delete Object.prototype.crash;
|
|
105
|
+
done();
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('stringifies boolean values', function (done) {
|
|
109
|
+
|
|
110
|
+
expect(Qs.stringify({ a: true })).to.equal('a=true');
|
|
111
|
+
expect(Qs.stringify({ a: { b: true } })).to.equal('a[b]=true');
|
|
112
|
+
expect(Qs.stringify({ b: false })).to.equal('b=false');
|
|
113
|
+
expect(Qs.stringify({ b: { c: false } })).to.equal('b[c]=false');
|
|
114
|
+
done();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it('stringifies buffer values', function (done) {
|
|
118
|
+
|
|
119
|
+
expect(Qs.stringify({ a: new Buffer('test') })).to.equal('a=test');
|
|
120
|
+
expect(Qs.stringify({ a: { b: new Buffer('test') } })).to.equal('a[b]=test');
|
|
121
|
+
done();
|
|
122
|
+
});
|
|
123
|
+
});
|
package/.gitmodules
DELETED
package/Readme.md
DELETED
|
@@ -1,58 +0,0 @@
|
|
|
1
|
-
# node-querystring
|
|
2
|
-
|
|
3
|
-
query string parser for node and the browser supporting nesting, as it was removed from `0.3.x`, so this library provides the previous and commonly desired behaviour (and twice as fast). Used by [express](http://expressjs.com), [connect](http://senchalabs.github.com/connect) and others.
|
|
4
|
-
|
|
5
|
-
## Installation
|
|
6
|
-
|
|
7
|
-
$ npm install qs
|
|
8
|
-
|
|
9
|
-
## Examples
|
|
10
|
-
|
|
11
|
-
```js
|
|
12
|
-
var qs = require('qs');
|
|
13
|
-
|
|
14
|
-
qs.parse('user[name][first]=Tobi&user[email]=tobi@learnboost.com');
|
|
15
|
-
// => { user: { name: { first: 'Tobi' }, email: 'tobi@learnboost.com' } }
|
|
16
|
-
|
|
17
|
-
qs.stringify({ user: { name: 'Tobi', email: 'tobi@learnboost.com' }})
|
|
18
|
-
// => user[name]=Tobi&user[email]=tobi%40learnboost.com
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
## Testing
|
|
22
|
-
|
|
23
|
-
Install dev dependencies:
|
|
24
|
-
|
|
25
|
-
$ npm install -d
|
|
26
|
-
|
|
27
|
-
and execute:
|
|
28
|
-
|
|
29
|
-
$ make test
|
|
30
|
-
|
|
31
|
-
browser:
|
|
32
|
-
|
|
33
|
-
$ open test/browser/index.html
|
|
34
|
-
|
|
35
|
-
## License
|
|
36
|
-
|
|
37
|
-
(The MIT License)
|
|
38
|
-
|
|
39
|
-
Copyright (c) 2010 TJ Holowaychuk <tj@vision-media.ca>
|
|
40
|
-
|
|
41
|
-
Permission is hereby granted, free of charge, to any person obtaining
|
|
42
|
-
a copy of this software and associated documentation files (the
|
|
43
|
-
'Software'), to deal in the Software without restriction, including
|
|
44
|
-
without limitation the rights to use, copy, modify, merge, publish,
|
|
45
|
-
distribute, sublicense, and/or sell copies of the Software, and to
|
|
46
|
-
permit persons to whom the Software is furnished to do so, subject to
|
|
47
|
-
the following conditions:
|
|
48
|
-
|
|
49
|
-
The above copyright notice and this permission notice shall be
|
|
50
|
-
included in all copies or substantial portions of the Software.
|
|
51
|
-
|
|
52
|
-
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
|
|
53
|
-
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
54
|
-
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
55
|
-
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
56
|
-
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
57
|
-
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
58
|
-
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|