Skip to content

Commit

Permalink
[Docs] Show example of sort option
Browse files Browse the repository at this point in the history
  • Loading branch information
codeclown authored and ljharb committed Dec 23, 2016
1 parent ec3bc8e commit 839b1f2
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.md
Expand Up @@ -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:
Expand Down

0 comments on commit 839b1f2

Please sign in to comment.