Coder Social home page Coder Social logo

urlencode's Introduction

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

  • stringify()

License

MIT

urlencode's People

Contributors

aleafs avatar alsotang avatar denghongcai avatar fengmk2 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.