Skip to content

Commit 33b27f4

Browse files
mizozobuljharb
authored andcommitted
[meta] fix README.md (#399)
- `defaultEncoder`=> `defaultDecoder`
1 parent 54530e2 commit 33b27f4

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

README.md

+24
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,30 @@ var decoded = qs.parse('x=z', { decoder: function (str) {
323323
}})
324324
```
325325

326+
You can encode keys and values using different logic by using the type argument provided to the encoder:
327+
328+
```javascript
329+
var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str, defaultEncoder, charset, type) {
330+
if (type === 'key') {
331+
return // Encoded key
332+
} else if (type === 'value') {
333+
return // Encoded value
334+
}
335+
}})
336+
```
337+
338+
The type argument is also provided to the decoder:
339+
340+
```javascript
341+
var decoded = qs.parse('x=z', { decoder: function (str, defaultDecoder, charset, type) {
342+
if (type === 'key') {
343+
return // Decoded key
344+
} else if (type === 'value') {
345+
return // Decoded value
346+
}
347+
}})
348+
```
349+
326350
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.
327351

328352
When arrays are stringified, by default they are given explicit indices:

0 commit comments

Comments
 (0)