From f8510a125b6963af3964b5b885adf68e04ffee83 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 53afe2f3..e6e32130 100644 --- a/README.md +++ b/README.md @@ -245,6 +245,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: