Skip to content

Commit f8510a1

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

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
@@ -245,6 +245,30 @@ var decoded = qs.parse('x=z', { decoder: function (str) {
245245
}})
246246
```
247247

248+
You can encode keys and values using different logic by using the type argument provided to the encoder:
249+
250+
```javascript
251+
var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str, defaultEncoder, charset, type) {
252+
if (type === 'key') {
253+
return // Encoded key
254+
} else if (type === 'value') {
255+
return // Encoded value
256+
}
257+
}})
258+
```
259+
260+
The type argument is also provided to the decoder:
261+
262+
```javascript
263+
var decoded = qs.parse('x=z', { decoder: function (str, defaultDecoder, charset, type) {
264+
if (type === 'key') {
265+
return // Decoded key
266+
} else if (type === 'value') {
267+
return // Decoded value
268+
}
269+
}})
270+
```
271+
248272
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.
249273

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

0 commit comments

Comments
 (0)