Skip to content

Commit 12ac1c4

Browse files
mizozobuljharb
authored andcommitted
[meta] fix README.md (#399)
- `defaultEncoder`=> `defaultDecoder`
1 parent 0338716 commit 12ac1c4

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
@@ -267,6 +267,30 @@ var decoded = qs.parse('x=z', { decoder: function (str) {
267267
}})
268268
```
269269

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+
} else if (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+
} else if (type === 'value') {
289+
return // Decoded value
290+
}
291+
}})
292+
```
293+
270294
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.
271295

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

0 commit comments

Comments
 (0)