Skip to content

Commit

Permalink
Added documentation on how to use qs-iconv with qs
Browse files Browse the repository at this point in the history
  • Loading branch information
martinheidegger committed May 10, 2016
1 parent d67d315 commit 1c250a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,24 @@ To completely skip rendering keys with `null` values, use the `skipNulls` flag:
var nullsSkipped = qs.stringify({ a: 'b', c: null}, { skipNulls: true });
assert.equal(nullsSkipped, 'a=b');
```

### Dealing with special character sets

By default the encoding and decoding of characters is done in `utf-8`. If you
wish to encode querystrings to a different character set (i.e.
[Shift JIS](https://en.wikipedia.org/wiki/Shift_JIS)) you can use the
[`qs-iconv`](https://github.com/martinheidegger/qs-iconv) library:

```javascript
var encoder = require('qs-iconv/encoder')('shift_jis');
var shiftJISEncoded = qs.stringify({ a: 'こんにちは!' }, { encoder: encoder });
assert.equal(shiftJISEncoded, 'a=%82%B1%82%F1%82%C9%82%BF%82%CD%81I');
```

This also works for decoding of query strings:

```javascript
var decoder = require('qs-iconv/decoder')('shift_jis');
var obj = qs.parse('a=%82%B1%82%F1%82%C9%82%BF%82%CD%81I', { decoder: decoder });
assert.deepEqual(obj, { a: 'こんにちは!' });
```
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
"@ljharb/eslint-config": "^4.0.0",
"parallelshell": "^2.0.0",
"iconv-lite": "^0.4.13",
"qs-iconv": "^1.0.1",
"evalmd": "^0.0.17"
},
"scripts": {
Expand Down

0 comments on commit 1c250a0

Please sign in to comment.