npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

urlencode

v2.0.0

Published

encodeURIComponent with charset

Downloads

676,173

Readme

urlencode

NPM version Node.js CI Test coverage Known Vulnerabilities npm download

encodeURIComponent with charset, e.g.: gbk

Install

npm install urlencode

Usage

import { encode, decode, parse, stringify } from 'urlencode';

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

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

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

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

Benchmark

encode(str, encoding)

$ node benchmark/urlencode.cjs

node version: v21.1.0
"苏千测试\n, 哈哈, haha"

  urlencode Benchmark
  node version: v21.1.0, date: Sat Oct 28 2023 21:01:00 GMT+0800 (中国标准时间)
  Starting...
  4 tests completed.

  urlencode(str)          x 4,617,242 ops/sec ±2.60% (95 runs sampled)
  urlencode(str, "gbk")   x 1,122,430 ops/sec ±2.20% (95 runs sampled)
  encodeURIComponent(str) x 4,608,523 ops/sec ±2.94% (93 runs sampled)
  encodeUTF8(str)         x   833,170 ops/sec ±1.37% (96 runs sampled)

node version: v20.9.0
"苏千测试\n, 哈哈, haha"

  urlencode Benchmark
  node version: v20.9.0, date: Sat Oct 28 2023 21:01:37 GMT+0800 (中国标准时间)
  Starting...
  4 tests completed.

  urlencode(str)          x 4,304,468 ops/sec ±2.83% (89 runs sampled)
  urlencode(str, "gbk")   x 1,005,759 ops/sec ±2.10% (90 runs sampled)
  encodeURIComponent(str) x 4,289,880 ops/sec ±2.99% (92 runs sampled)
  encodeUTF8(str)         x   827,841 ops/sec ±1.06% (96 runs sampled)

node version: v18.18.0
"苏千测试\n, 哈哈, haha"

  urlencode Benchmark
  node version: v18.18.0, date: Sat Oct 28 2023 19:34:06 GMT+0800 (中国标准时间)
  Starting...
  4 tests completed.

  urlencode(str)          x 4,597,865 ops/sec ±0.22% (96 runs sampled)
  urlencode(str, "gbk")   x   633,620 ops/sec ±15.31% (71 runs sampled)
  encodeURIComponent(str) x 3,902,229 ops/sec ±2.49% (87 runs sampled)
  encodeUTF8(str)         x   510,456 ops/sec ±26.76% (88 runs sampled)

node version: v16.20.2
"苏千测试\n, 哈哈, haha"

  urlencode Benchmark
  node version: v16.20.2, date: Sat Oct 28 2023 21:02:11 GMT+0800 (中国标准时间)
  Starting...
  4 tests completed.

  urlencode(str)          x 4,438,372 ops/sec ±1.80% (93 runs sampled)
  urlencode(str, "gbk")   x 1,175,761 ops/sec ±0.68% (95 runs sampled)
  encodeURIComponent(str) x 4,374,525 ops/sec ±1.96% (97 runs sampled)
  encodeUTF8(str)         x   751,616 ops/sec ±2.49% (86 runs sampled)

decode(str, encoding)

$ node benchmark/urlencode.decode.cjs

node version: v21.1.0, date: "2023-10-28T12:51:20.191Z"

  urlencode.decode Benchmark
  node version: v21.1.0, date: Sat Oct 28 2023 20:51:20 GMT+0800 (中国标准时间)
  Starting...
  7 tests completed.

  urlencode.decode(str)                        x 515,410 ops/sec ±1.95% (91 runs sampled)
  urlencode.decode(str, "gbk")                 x  54,018 ops/sec ±3.17% (78 runs sampled)
  decodeURIComponent(str)                      x 313,204 ops/sec ±2.93% (78 runs sampled)
  urlencode.parse(qs, {charset: "gbk"})        x 311,613 ops/sec ±1.26% (95 runs sampled)
  urlencode.stringify(data, {charset: "gbk"})  x 316,558 ops/sec ±1.55% (93 runs sampled)
  urlencode.parse(qs, {charset: "utf8"})       x 490,744 ops/sec ±1.25% (94 runs sampled)
  urlencode.stringify(data, {charset: "utf8"}) x 357,206 ops/sec ±0.46% (97 runs sampled)

node version: v20.9.0, date: "2023-10-28T12:49:57.236Z"

  urlencode.decode Benchmark
  node version: v20.9.0, date: Sat Oct 28 2023 20:49:57 GMT+0800 (中国标准时间)
  Starting...
  7 tests completed.

  urlencode.decode(str)                        x 573,899 ops/sec ±0.62% (95 runs sampled)
  urlencode.decode(str, "gbk")                 x  83,184 ops/sec ±0.13% (100 runs sampled)
  decodeURIComponent(str)                      x 573,371 ops/sec ±1.67% (93 runs sampled)
  urlencode.parse(qs, {charset: "gbk"})        x 303,202 ops/sec ±0.70% (100 runs sampled)
  urlencode.stringify(data, {charset: "gbk"})  x 319,546 ops/sec ±0.29% (99 runs sampled)
  urlencode.parse(qs, {charset: "utf8"})       x 462,578 ops/sec ±0.25% (98 runs sampled)
  urlencode.stringify(data, {charset: "utf8"}) x 343,487 ops/sec ±0.17% (100 runs sampled)

node version: v18.18.0, date: "2023-10-28T12:44:56.355Z"

  urlencode.decode Benchmark
  node version: v18.18.0, date: Sat Oct 28 2023 20:44:56 GMT+0800 (中国标准时间)
  Starting...
  7 tests completed.

  urlencode.decode(str)                        x 550,451 ops/sec ±1.74% (98 runs sampled)
  urlencode.decode(str, "gbk")                 x  67,311 ops/sec ±1.16% (96 runs sampled)
  decodeURIComponent(str)                      x 569,461 ops/sec ±0.30% (93 runs sampled)
  urlencode.parse(qs, {charset: "gbk"})        x 293,407 ops/sec ±0.90% (97 runs sampled)
  urlencode.stringify(data, {charset: "gbk"})  x 234,162 ops/sec ±4.55% (75 runs sampled)
  urlencode.parse(qs, {charset: "utf8"})       x 316,697 ops/sec ±4.37% (78 runs sampled)
  urlencode.stringify(data, {charset: "utf8"}) x 192,787 ops/sec ±4.58% (80 runs sampled)

node version: v16.20.2, date: "2023-10-28T12:47:38.431Z"

  urlencode.decode Benchmark
  node version: v16.20.2, date: Sat Oct 28 2023 20:47:38 GMT+0800 (中国标准时间)
  Starting...
  7 tests completed.

  urlencode.decode(str)                        x 537,995 ops/sec ±2.07% (96 runs sampled)
  urlencode.decode(str, "gbk")                 x  78,073 ops/sec ±0.17% (99 runs sampled)
  decodeURIComponent(str)                      x 558,509 ops/sec ±0.48% (96 runs sampled)
  urlencode.parse(qs, {charset: "gbk"})        x 252,590 ops/sec ±2.87% (90 runs sampled)
  urlencode.stringify(data, {charset: "gbk"})  x 287,978 ops/sec ±2.47% (92 runs sampled)
  urlencode.parse(qs, {charset: "utf8"})       x 416,600 ops/sec ±0.72% (93 runs sampled)
  urlencode.stringify(data, {charset: "utf8"}) x 281,319 ops/sec ±2.43% (85 runs sampled)

License

MIT