Skip to content

Commit 90a3bce

Browse files
mizozobuljharb
authored andcommitted
[meta] fix README.md (#399)
- `defaultEncoder`=> `defaultDecoder`
1 parent 9566d25 commit 90a3bce

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
@@ -254,6 +254,30 @@ var decoded = qs.parse('x=z', { decoder: function (str) {
254254
}})
255255
```
256256

257+
You can encode keys and values using different logic by using the type argument provided to the encoder:
258+
259+
```javascript
260+
var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str, defaultEncoder, charset, type) {
261+
if (type === 'key') {
262+
return // Encoded key
263+
} else if (type === 'value') {
264+
return // Encoded value
265+
}
266+
}})
267+
```
268+
269+
The type argument is also provided to the decoder:
270+
271+
```javascript
272+
var decoded = qs.parse('x=z', { decoder: function (str, defaultDecoder, charset, type) {
273+
if (type === 'key') {
274+
return // Decoded key
275+
} else if (type === 'value') {
276+
return // Decoded value
277+
}
278+
}})
279+
```
280+
257281
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.
258282

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

0 commit comments

Comments
 (0)