From 839b1f271c2150349960062979b4d3e4bb1e8eef Mon Sep 17 00:00:00 2001 From: Martti Laine Date: Fri, 23 Dec 2016 23:06:39 +0200 Subject: [PATCH] [Docs] Show example of sort option --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index ac1e7f16..6f47a9fc 100644 --- a/README.md +++ b/README.md @@ -301,6 +301,15 @@ assert.equal( ); ``` +You may use the `sort` option to affect the order of parameter keys: + +```javascript +function alphabeticalSort(a, b) { + return a.localeCompare(b); +} +assert.equal(qs.stringify({ a: 'c', z: 'y', b : 'f' }, { sort: alphabeticalSort }), 'a=c&b=f&z=y'); +``` + Finally, you can use the `filter` option to restrict which keys will be included in the stringified output. If you pass a function, it will be called for each key to obtain the replacement value. Otherwise, if you pass an array, it will be used to select properties and array indices for stringification: