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

Lines changed: 24 additions & 0 deletions
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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy