qs 6.0.1 → 6.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/.eslintrc +17 -0
- package/.travis.yml +66 -5
- package/CHANGELOG.md +115 -0
- package/README.md +85 -81
- package/bower.json +0 -1
- package/component.json +1 -1
- package/dist/qs.js +98 -178
- package/lib/index.js +6 -12
- package/lib/parse.js +47 -72
- package/lib/stringify.js +43 -69
- package/lib/utils.js +48 -85
- package/package.json +26 -11
- package/test/index.js +5 -0
- package/test/parse.js +249 -336
- package/test/stringify.js +170 -202
- package/test/utils.js +5 -26
package/test/stringify.js
CHANGED
|
@@ -1,291 +1,259 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
var test = require('tape');
|
|
4
|
+
var qs = require('../');
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
const lab = exports.lab = Lab.script();
|
|
19
|
-
const expect = Code.expect;
|
|
20
|
-
const describe = lab.experiment;
|
|
21
|
-
const it = lab.test;
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
describe('stringify()', () => {
|
|
25
|
-
|
|
26
|
-
it('stringifies a querystring object', (done) => {
|
|
27
|
-
|
|
28
|
-
expect(Qs.stringify({ a: 'b' })).to.equal('a=b');
|
|
29
|
-
expect(Qs.stringify({ a: 1 })).to.equal('a=1');
|
|
30
|
-
expect(Qs.stringify({ a: 1, b: 2 })).to.equal('a=1&b=2');
|
|
31
|
-
expect(Qs.stringify({ a: 'A_Z' })).to.equal('a=A_Z');
|
|
32
|
-
expect(Qs.stringify({ a: '€' })).to.equal('a=%E2%82%AC');
|
|
33
|
-
expect(Qs.stringify({ a: '' })).to.equal('a=%EE%80%80');
|
|
34
|
-
expect(Qs.stringify({ a: 'א' })).to.equal('a=%D7%90');
|
|
35
|
-
expect(Qs.stringify({ a: '𐐷' })).to.equal('a=%F0%90%90%B7');
|
|
36
|
-
done();
|
|
6
|
+
test('stringify()', function (t) {
|
|
7
|
+
t.test('stringifies a querystring object', function (st) {
|
|
8
|
+
st.equal(qs.stringify({ a: 'b' }), 'a=b');
|
|
9
|
+
st.equal(qs.stringify({ a: 1 }), 'a=1');
|
|
10
|
+
st.equal(qs.stringify({ a: 1, b: 2 }), 'a=1&b=2');
|
|
11
|
+
st.equal(qs.stringify({ a: 'A_Z' }), 'a=A_Z');
|
|
12
|
+
st.equal(qs.stringify({ a: '€' }), 'a=%E2%82%AC');
|
|
13
|
+
st.equal(qs.stringify({ a: '' }), 'a=%EE%80%80');
|
|
14
|
+
st.equal(qs.stringify({ a: 'א' }), 'a=%D7%90');
|
|
15
|
+
st.equal(qs.stringify({ a: '𐐷' }), 'a=%F0%90%90%B7');
|
|
16
|
+
st.end();
|
|
37
17
|
});
|
|
38
18
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
done();
|
|
19
|
+
t.test('stringifies a nested object', function (st) {
|
|
20
|
+
st.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
|
|
21
|
+
st.equal(qs.stringify({ a: { b: { c: { d: 'e' } } } }), 'a%5Bb%5D%5Bc%5D%5Bd%5D=e');
|
|
22
|
+
st.end();
|
|
44
23
|
});
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
24
|
+
|
|
25
|
+
t.test('stringifies a nested object with dots notation', function (st) {
|
|
26
|
+
st.equal(qs.stringify({ a: { b: 'c' } }, { allowDots: true }), 'a.b=c');
|
|
27
|
+
st.equal(qs.stringify({ a: { b: { c: { d: 'e' } } } }, { allowDots: true }), 'a.b.c.d=e');
|
|
28
|
+
st.end();
|
|
50
29
|
});
|
|
51
30
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
done();
|
|
31
|
+
t.test('stringifies an array value', function (st) {
|
|
32
|
+
st.equal(qs.stringify({ a: ['b', 'c', 'd'] }), 'a%5B0%5D=b&a%5B1%5D=c&a%5B2%5D=d');
|
|
33
|
+
st.end();
|
|
56
34
|
});
|
|
57
35
|
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
expect(Qs.stringify({ a: { b: 'c', d: null } }, { skipNulls: true })).to.equal('a%5Bb%5D=c');
|
|
62
|
-
done();
|
|
36
|
+
t.test('omits nulls when asked', function (st) {
|
|
37
|
+
st.equal(qs.stringify({ a: 'b', c: null }, { skipNulls: true }), 'a=b');
|
|
38
|
+
st.end();
|
|
63
39
|
});
|
|
64
40
|
|
|
65
|
-
it('omits array indices when asked', (done) => {
|
|
66
41
|
|
|
67
|
-
|
|
68
|
-
|
|
42
|
+
t.test('omits nested nulls when asked', function (st) {
|
|
43
|
+
st.equal(qs.stringify({ a: { b: 'c', d: null } }, { skipNulls: true }), 'a%5Bb%5D=c');
|
|
44
|
+
st.end();
|
|
69
45
|
});
|
|
70
46
|
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
done();
|
|
47
|
+
t.test('omits array indices when asked', function (st) {
|
|
48
|
+
st.equal(qs.stringify({ a: ['b', 'c', 'd'] }, { indices: false }), 'a=b&a=c&a=d');
|
|
49
|
+
st.end();
|
|
75
50
|
});
|
|
76
51
|
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
expect(Qs.stringify({ a: [{ b: { c: [1] } }] })).to.equal('a%5B0%5D%5Bb%5D%5Bc%5D%5B0%5D=1');
|
|
81
|
-
done();
|
|
52
|
+
t.test('stringifies a nested array value', function (st) {
|
|
53
|
+
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }), 'a%5Bb%5D%5B0%5D=c&a%5Bb%5D%5B1%5D=d');
|
|
54
|
+
st.end();
|
|
82
55
|
});
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
done();
|
|
56
|
+
|
|
57
|
+
t.test('stringifies a nested array value with dots notation', function (st) {
|
|
58
|
+
st.equal(qs.stringify({ a: { b: ['c', 'd'] } }, { allowDots: true, encode: false }), 'a.b[0]=c&a.b[1]=d');
|
|
59
|
+
st.end();
|
|
88
60
|
});
|
|
89
61
|
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
62
|
+
t.test('stringifies an object inside an array', function (st) {
|
|
63
|
+
st.equal(qs.stringify({ a: [{ b: 'c' }] }), 'a%5B0%5D%5Bb%5D=c');
|
|
64
|
+
st.equal(qs.stringify({ a: [{ b: { c: [1] } }] }), 'a%5B0%5D%5Bb%5D%5Bc%5D%5B0%5D=1');
|
|
65
|
+
st.end();
|
|
94
66
|
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
67
|
+
|
|
68
|
+
t.test('stringifies an object inside an array with dots notation', function (st) {
|
|
69
|
+
st.equal(qs.stringify({ a: [{ b: 'c' }] }, { allowDots: true, encode: false }), 'a[0].b=c');
|
|
70
|
+
st.equal(qs.stringify({ a: [{ b: { c: [1] } }] }, { allowDots: true, encode: false }), 'a[0].b.c[0]=1');
|
|
71
|
+
st.end();
|
|
100
72
|
});
|
|
101
73
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
done();
|
|
74
|
+
t.test('does not omit object keys when indices = false', function (st) {
|
|
75
|
+
st.equal(qs.stringify({ a: [{ b: 'c' }] }, { indices: false }), 'a%5Bb%5D=c');
|
|
76
|
+
st.end();
|
|
106
77
|
});
|
|
107
78
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
done();
|
|
79
|
+
t.test('uses indices notation for arrays when indices=true', function (st) {
|
|
80
|
+
st.equal(qs.stringify({ a: ['b', 'c'] }, { indices: true }), 'a%5B0%5D=b&a%5B1%5D=c');
|
|
81
|
+
st.end();
|
|
112
82
|
});
|
|
113
83
|
|
|
114
|
-
|
|
84
|
+
t.test('uses indices notation for arrays when no arrayFormat is specified', function (st) {
|
|
85
|
+
st.equal(qs.stringify({ a: ['b', 'c'] }), 'a%5B0%5D=b&a%5B1%5D=c');
|
|
86
|
+
st.end();
|
|
87
|
+
});
|
|
115
88
|
|
|
116
|
-
|
|
117
|
-
|
|
89
|
+
t.test('uses indices notation for arrays when no arrayFormat=indices', function (st) {
|
|
90
|
+
st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'indices' }), 'a%5B0%5D=b&a%5B1%5D=c');
|
|
91
|
+
st.end();
|
|
118
92
|
});
|
|
119
93
|
|
|
120
|
-
|
|
94
|
+
t.test('uses repeat notation for arrays when no arrayFormat=repeat', function (st) {
|
|
95
|
+
st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'repeat' }), 'a=b&a=c');
|
|
96
|
+
st.end();
|
|
97
|
+
});
|
|
121
98
|
|
|
122
|
-
|
|
123
|
-
|
|
99
|
+
t.test('uses brackets notation for arrays when no arrayFormat=brackets', function (st) {
|
|
100
|
+
st.equal(qs.stringify({ a: ['b', 'c'] }, { arrayFormat: 'brackets' }), 'a%5B%5D=b&a%5B%5D=c');
|
|
101
|
+
st.end();
|
|
124
102
|
});
|
|
125
103
|
|
|
126
|
-
|
|
104
|
+
t.test('stringifies a complicated object', function (st) {
|
|
105
|
+
st.equal(qs.stringify({ a: { b: 'c', d: 'e' } }), 'a%5Bb%5D=c&a%5Bd%5D=e');
|
|
106
|
+
st.end();
|
|
107
|
+
});
|
|
127
108
|
|
|
128
|
-
|
|
129
|
-
|
|
109
|
+
t.test('stringifies an empty value', function (st) {
|
|
110
|
+
st.equal(qs.stringify({ a: '' }), 'a=');
|
|
111
|
+
st.equal(qs.stringify({ a: null }, { strictNullHandling: true }), 'a');
|
|
130
112
|
|
|
131
|
-
|
|
132
|
-
|
|
113
|
+
st.equal(qs.stringify({ a: '', b: '' }), 'a=&b=');
|
|
114
|
+
st.equal(qs.stringify({ a: null, b: '' }, { strictNullHandling: true }), 'a&b=');
|
|
133
115
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
116
|
+
st.equal(qs.stringify({ a: { b: '' } }), 'a%5Bb%5D=');
|
|
117
|
+
st.equal(qs.stringify({ a: { b: null } }, { strictNullHandling: true }), 'a%5Bb%5D');
|
|
118
|
+
st.equal(qs.stringify({ a: { b: null } }, { strictNullHandling: false }), 'a%5Bb%5D=');
|
|
137
119
|
|
|
138
|
-
|
|
120
|
+
st.end();
|
|
139
121
|
});
|
|
140
122
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
const obj = Object.create(null);
|
|
123
|
+
t.test('stringifies an empty object', function (st) {
|
|
124
|
+
var obj = Object.create(null);
|
|
144
125
|
obj.a = 'b';
|
|
145
|
-
|
|
146
|
-
|
|
126
|
+
st.equal(qs.stringify(obj), 'a=b');
|
|
127
|
+
st.end();
|
|
147
128
|
});
|
|
148
129
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
done();
|
|
130
|
+
t.test('returns an empty string for invalid input', function (st) {
|
|
131
|
+
st.equal(qs.stringify(undefined), '');
|
|
132
|
+
st.equal(qs.stringify(false), '');
|
|
133
|
+
st.equal(qs.stringify(null), '');
|
|
134
|
+
st.equal(qs.stringify(''), '');
|
|
135
|
+
st.end();
|
|
156
136
|
});
|
|
157
137
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
const obj = {
|
|
138
|
+
t.test('stringifies an object with an empty object as a child', function (st) {
|
|
139
|
+
var obj = {
|
|
161
140
|
a: Object.create(null)
|
|
162
141
|
};
|
|
163
142
|
|
|
164
143
|
obj.a.b = 'c';
|
|
165
|
-
|
|
166
|
-
|
|
144
|
+
st.equal(qs.stringify(obj), 'a%5Bb%5D=c');
|
|
145
|
+
st.end();
|
|
167
146
|
});
|
|
168
147
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
expect(Qs.stringify({ a: undefined })).to.equal('');
|
|
148
|
+
t.test('drops keys with a value of undefined', function (st) {
|
|
149
|
+
st.equal(qs.stringify({ a: undefined }), '');
|
|
172
150
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
151
|
+
st.equal(qs.stringify({ a: { b: undefined, c: null } }, { strictNullHandling: true }), 'a%5Bc%5D');
|
|
152
|
+
st.equal(qs.stringify({ a: { b: undefined, c: null } }, { strictNullHandling: false }), 'a%5Bc%5D=');
|
|
153
|
+
st.equal(qs.stringify({ a: { b: undefined, c: '' } }), 'a%5Bc%5D=');
|
|
154
|
+
st.end();
|
|
177
155
|
});
|
|
178
156
|
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
done();
|
|
157
|
+
t.test('url encodes values', function (st) {
|
|
158
|
+
st.equal(qs.stringify({ a: 'b c' }), 'a=b%20c');
|
|
159
|
+
st.end();
|
|
183
160
|
});
|
|
184
161
|
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
done();
|
|
162
|
+
t.test('stringifies a date', function (st) {
|
|
163
|
+
var now = new Date();
|
|
164
|
+
var str = 'a=' + encodeURIComponent(now.toISOString());
|
|
165
|
+
st.equal(qs.stringify({ a: now }), str);
|
|
166
|
+
st.end();
|
|
191
167
|
});
|
|
192
168
|
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
done();
|
|
169
|
+
t.test('stringifies the weird object from qs', function (st) {
|
|
170
|
+
st.equal(qs.stringify({ 'my weird field': '~q1!2"\'w$5&7/z8)?' }), 'my%20weird%20field=~q1%212%22%27w%245%267%2Fz8%29%3F');
|
|
171
|
+
st.end();
|
|
197
172
|
});
|
|
198
173
|
|
|
199
|
-
|
|
200
|
-
|
|
174
|
+
t.test('skips properties that are part of the object prototype', function (st) {
|
|
201
175
|
Object.prototype.crash = 'test';
|
|
202
|
-
|
|
203
|
-
|
|
176
|
+
st.equal(qs.stringify({ a: 'b' }), 'a=b');
|
|
177
|
+
st.equal(qs.stringify({ a: { b: 'c' } }), 'a%5Bb%5D=c');
|
|
204
178
|
delete Object.prototype.crash;
|
|
205
|
-
|
|
179
|
+
st.end();
|
|
206
180
|
});
|
|
207
181
|
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
done();
|
|
182
|
+
t.test('stringifies boolean values', function (st) {
|
|
183
|
+
st.equal(qs.stringify({ a: true }), 'a=true');
|
|
184
|
+
st.equal(qs.stringify({ a: { b: true } }), 'a%5Bb%5D=true');
|
|
185
|
+
st.equal(qs.stringify({ b: false }), 'b=false');
|
|
186
|
+
st.equal(qs.stringify({ b: { c: false } }), 'b%5Bc%5D=false');
|
|
187
|
+
st.end();
|
|
215
188
|
});
|
|
216
189
|
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
done();
|
|
190
|
+
t.test('stringifies buffer values', function (st) {
|
|
191
|
+
st.equal(qs.stringify({ a: new Buffer('test') }), 'a=test');
|
|
192
|
+
st.equal(qs.stringify({ a: { b: new Buffer('test') } }), 'a%5Bb%5D=test');
|
|
193
|
+
st.end();
|
|
222
194
|
});
|
|
223
195
|
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
done();
|
|
196
|
+
t.test('stringifies an object using an alternative delimiter', function (st) {
|
|
197
|
+
st.equal(qs.stringify({ a: 'b', c: 'd' }, { delimiter: ';' }), 'a=b;c=d');
|
|
198
|
+
st.end();
|
|
228
199
|
});
|
|
229
200
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
const tempBuffer = global.Buffer;
|
|
201
|
+
t.test('doesn\'t blow up when Buffer global is missing', function (st) {
|
|
202
|
+
var tempBuffer = global.Buffer;
|
|
233
203
|
delete global.Buffer;
|
|
234
|
-
|
|
204
|
+
var result = qs.stringify({ a: 'b', c: 'd' });
|
|
235
205
|
global.Buffer = tempBuffer;
|
|
236
|
-
|
|
237
|
-
|
|
206
|
+
st.equal(result, 'a=b&c=d');
|
|
207
|
+
st.end();
|
|
238
208
|
});
|
|
239
209
|
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
done();
|
|
246
|
-
|
|
210
|
+
t.test('selects properties when filter=array', function (st) {
|
|
211
|
+
st.equal(qs.stringify({ a: 'b' }, { filter: ['a'] }), 'a=b');
|
|
212
|
+
st.equal(qs.stringify({ a: 1 }, { filter: [] }), '');
|
|
213
|
+
st.equal(qs.stringify({ a: { b: [1, 2, 3, 4], c: 'd' }, c: 'f' }, { filter: ['a', 'b', 0, 2] }), 'a%5Bb%5D%5B0%5D=1&a%5Bb%5D%5B2%5D=3');
|
|
214
|
+
st.end();
|
|
247
215
|
});
|
|
248
216
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
const filterFunc = function (prefix, value) {
|
|
254
|
-
|
|
217
|
+
t.test('supports custom representations when filter=function', function (st) {
|
|
218
|
+
var calls = 0;
|
|
219
|
+
var obj = { a: 'b', c: 'd', e: { f: new Date(1257894000000) } };
|
|
220
|
+
var filterFunc = function (prefix, value) {
|
|
255
221
|
calls++;
|
|
256
222
|
if (calls === 1) {
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
else if (prefix === 'c') {
|
|
223
|
+
st.equal(prefix, '', 'prefix is empty');
|
|
224
|
+
st.equal(value, obj);
|
|
225
|
+
} else if (prefix === 'c') {
|
|
261
226
|
return;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
expect(prefix).to.equal('e[f]');
|
|
227
|
+
} else if (value instanceof Date) {
|
|
228
|
+
st.equal(prefix, 'e[f]');
|
|
265
229
|
return value.getTime();
|
|
266
230
|
}
|
|
267
231
|
return value;
|
|
268
232
|
};
|
|
269
233
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
234
|
+
st.equal(qs.stringify(obj, { filter: filterFunc }), 'a=b&e%5Bf%5D=1257894000000');
|
|
235
|
+
st.equal(calls, 5);
|
|
236
|
+
st.end();
|
|
274
237
|
});
|
|
275
238
|
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
done();
|
|
239
|
+
t.test('can disable uri encoding', function (st) {
|
|
240
|
+
st.equal(qs.stringify({ a: 'b' }, { encode: false }), 'a=b');
|
|
241
|
+
st.equal(qs.stringify({ a: { b: 'c' } }, { encode: false }), 'a[b]=c');
|
|
242
|
+
st.equal(qs.stringify({ a: 'b', c: null }, { strictNullHandling: true, encode: false }), 'a=b&c');
|
|
243
|
+
st.end();
|
|
282
244
|
});
|
|
283
245
|
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
246
|
+
t.test('can sort the keys', function (st) {
|
|
247
|
+
var sort = function (a, b) { return a.localeCompare(b); };
|
|
248
|
+
st.equal(qs.stringify({ a: 'c', z: 'y', b: 'f' }, { sort: sort }), 'a=c&b=f&z=y');
|
|
249
|
+
st.equal(qs.stringify({ a: 'c', z: { j: 'a', i: 'b' }, b: 'f' }, { sort: sort }), 'a=c&b=f&z%5Bi%5D=b&z%5Bj%5D=a');
|
|
250
|
+
st.end();
|
|
251
|
+
});
|
|
252
|
+
|
|
253
|
+
t.test('can sort the keys at depth 3 or more too', function (st) {
|
|
254
|
+
var sort = function (a, b) { return a.localeCompare(b); };
|
|
255
|
+
st.equal(qs.stringify({ a: 'a', z: { zj: {zjb: 'zjb', zja: 'zja'}, zi: {zib: 'zib', zia: 'zia'} }, b: 'b' }, { sort: sort, encode: false }), 'a=a&b=b&z[zi][zia]=zia&z[zi][zib]=zib&z[zj][zja]=zja&z[zj][zjb]=zjb');
|
|
256
|
+
st.equal(qs.stringify({ a: 'a', z: { zj: {zjb: 'zjb', zja: 'zja'}, zi: {zib: 'zib', zia: 'zia'} }, b: 'b' }, { sort: null, encode: false }), 'a=a&z[zj][zjb]=zjb&z[zj][zja]=zja&z[zi][zib]=zib&z[zi][zia]=zia&b=b');
|
|
257
|
+
st.end();
|
|
290
258
|
});
|
|
291
259
|
});
|
package/test/utils.js
CHANGED
|
@@ -1,30 +1,9 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
var test = require('tape');
|
|
4
|
+
var utils = require('../lib/utils');
|
|
4
5
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
// Declare internals
|
|
11
|
-
|
|
12
|
-
const internals = {};
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
// Test shortcuts
|
|
16
|
-
|
|
17
|
-
const lab = exports.lab = Lab.script();
|
|
18
|
-
const expect = Code.expect;
|
|
19
|
-
const describe = lab.experiment;
|
|
20
|
-
const it = lab.test;
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
describe('merge()', () => {
|
|
24
|
-
|
|
25
|
-
it('can merge two objects with the same key', (done) => {
|
|
26
|
-
|
|
27
|
-
expect(Utils.merge({ a: 'b' }, { a: 'c' })).to.deep.equal({ a: ['b', 'c'] });
|
|
28
|
-
done();
|
|
29
|
-
});
|
|
6
|
+
test('merge()', function (t) {
|
|
7
|
+
t.deepEqual(utils.merge({ a: 'b' }, { a: 'c' }), { a: ['b', 'c'] }, 'merges two objects with the same key');
|
|
8
|
+
t.end();
|
|
30
9
|
});
|