JavaScript
Need help with urlencode?
Click the “chat” button below for chat support from the developer who created it, or find similar developers for support.
node-modules

Description

encodeURIComponent with charset

129 Stars 23 Forks Other 34 Commits 7 Opened issues

Services available

Need anything else?

urlencode Build Status Coverage Status

NPM

encodeURIComponent with charset, e.g.:

gbk

Install

$ npm install urlencode

Usage

var urlencode = require('urlencode');

console.log(urlencode('苏千')); // default is utf8 console.log(urlencode('苏千', 'gbk')); // '%CB%D5%C7%A7'

// decode gbk urlencode.decode('%CB%D5%C7%A7', 'gbk'); // '苏千'

// parse gbk querystring urlencode.parse('nick=%CB%D5%C7%A7', {charset: 'gbk'}); // {nick: '苏千'}

// stringify obj with gbk encoding var str = 'x[y][0][v][w]=' + urlencode('雾空', 'gbk'); // x[y][0][v][w]=%CE%ED%BF%D5 var obj = {'x' : {'y' : [{'v' : {'w' : '雾空'}}]}}; urlencode.stringify(obj, {charset: 'gbk'}).should.equal(str);

Benchmark

urlencode(str, encoding)

$ node benchmark/urlencode.js

node version: v0.10.26 urlencode(str) x 11,980 ops/sec ±1.13% (100 runs sampled) urlencode(str, "gbk") x 8,575 ops/sec ±1.58% (94 runs sampled) encodeURIComponent(str) x 11,677 ops/sec ±2.32% (93 runs sampled) Fastest is urlencode(str)

urlencode.decode(str, encoding)

$ node benchmark/urlencode.decode.js

node version: v0.10.26 urlencode.decode(str) x 26,027 ops/sec ±7.51% (73 runs sampled) urlencode.decode(str, "gbk") x 14,409 ops/sec ±1.72% (98 runs sampled) decodeURIComponent(str) x 36,052 ops/sec ±0.90% (96 runs sampled) urlencode.parse(qs, {charset: "gbk"}) x 16,401 ops/sec ±1.09% (98 runs sampled) urlencode.parse(qs, {charset: "utf8"}) x 23,381 ops/sec ±2.22% (93 runs sampled) Fastest is decodeURIComponent(str)

TODO

  • [x] stringify()

License

MIT

We use cookies. If you continue to browse the site, you agree to the use of cookies. For more information on our use of cookies please see our Privacy Policy.