You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+24Lines changed: 24 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -267,6 +267,30 @@ var decoded = qs.parse('x=z', { decoder: function (str) {
267
267
}})
268
268
```
269
269
270
+
You can encode keys and values using different logic by using the type argument provided to the encoder:
271
+
272
+
```javascript
273
+
var encoded=qs.stringify({ a: { b:'c' } }, {encoder:function (str,defaultEncoder,charset,type) {
274
+
if (type==='key') {
275
+
return// Encoded key
276
+
}elseif (type==='value') {
277
+
return// Encoded value
278
+
}
279
+
}})
280
+
```
281
+
282
+
The type argument is also provided to the decoder:
283
+
284
+
```javascript
285
+
var decoded=qs.parse('x=z', {decoder:function (str,defaultDecoder,charset,type) {
286
+
if (type==='key') {
287
+
return// Decoded key
288
+
}elseif (type==='value') {
289
+
return// Decoded value
290
+
}
291
+
}})
292
+
```
293
+
270
294
Examples beyond this point will be shown as though the output is not URI encoded for clarity. Please note that the return values in these cases*will* be URI encoded during real usage.
271
295
272
296
When arrays are stringified, by default they are given explicit indices: