urlencode2
v1.0.1
Published
encodeURIComponent with charset
Downloads
7
Maintainers
Readme
urlencode2
encodeURIComponent with charset, e.g.: gbk
Install
$ npm install urlencode2
Usage
urlencode(string, charset)
var urlencode = require('urlencode2');
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