From 12ac1c403aaa04d1a34844f514ed9f9abfb76e64 Mon Sep 17 00:00:00 2001 From: Sou Mizobuchi <27652080+mizozobu@users.noreply.github.com> Date: Thu, 11 Mar 2021 17:19:51 +0900 Subject: [PATCH] [meta] fix README.md (#399) - `defaultEncoder`=> `defaultDecoder` --- README.md | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/README.md b/README.md index cb64e0f6..b882be70 100644 --- a/README.md +++ b/README.md @@ -267,6 +267,30 @@ var decoded = qs.parse('x=z', { decoder: function (str) { }}) ``` +You can encode keys and values using different logic by using the type argument provided to the encoder: + +```javascript +var encoded = qs.stringify({ a: { b: 'c' } }, { encoder: function (str, defaultEncoder, charset, type) { + if (type === 'key') { + return // Encoded key + } else if (type === 'value') { + return // Encoded value + } +}}) +``` + +The type argument is also provided to the decoder: + +```javascript +var decoded = qs.parse('x=z', { decoder: function (str, defaultDecoder, charset, type) { + if (type === 'key') { + return // Decoded key + } else if (type === 'value') { + return // Decoded value + } +}}) +``` + 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. When arrays are stringified, by default they are given explicit indices: