urlencode3
v1.0.1
Published
encodeURIComponent with charset with typescript
Downloads
10
Maintainers
Readme
urlencode3
encodeURIComponent with charset with typescript, e.g.: gbk
Install
$ yarn add urlencode3
Usage
urlencode(string, charset)
import urlencode from 'urlencode3';
urlencode('苏千'); // default charset is utf8
urlencode('苏千', 'gbk'); // => '%CB%D5%C7%A7'
decode(string, charset)
urlencode.decode('%CB%D5%C7%A7', 'gbk'); // => '苏千'
parse(string, options)
// parse gbk querystring. support nest
urlencode.parse('nick=%CB%D5%C7%A7', {charset: 'gbk'});
// => {nick: '苏千'}
stringify(obj, options)
// stringify obj with gbk encoding. support nest
// equals: x[y][0][v][w]=%CE%ED%BF%D5
var str = 'x[y][0][v][w]=' + urlencode('雾空', 'gbk');
var obj = {'x' : {'y' : [{'v' : {'w' : '雾空'}}]}};
urlencode.stringify(obj, {charset: 'gbk'}).should.equal(str);
License
MIT