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 🙏

© 2026 – Pkg Stats / Ryan Hefner

encoder.js

v0.0.2

Published

An encoding library in JavaScript

Downloads

20

Readme

encoder.js

An encoding library in JavaScript

build status

HTML encode and decode

HTML encode an input string

var encoder = require('encoder.js');
var input = '100 > 200 is incorrect';
var encoded = encoder.encodeHTML(input); //100 > 200 is incorrect

HTML decode an input string

var encoder = require('encoder.js');
var intput = '100 > 200 is incorrect';
var decoded = encoder.decodeHTML(input); //100 > 200 is incorrect

HTML attribute encode and decode

HTML attribute encode an input string, this method only encode 4 characters: &, <, ' and "

var encoder = require('encoder.js');
var input = '100<200';
var encoded = encoder.encodeHTMLAttr(input); //100&lt;200

// but '>' will be not encoded
input = '200>100';
encoded = encoder.encodeHTMLAttr(input); //200>100

To decode HTML attribute, use encoder.decodeHTML

JavaScript encode and decode

Characters '\r\t"\n\b\f' will be escaped to '\\r\\t\\"\\n\\b\\f'

var input = '\r\t"\n\b\f';
var encoded = encoder.encodeJavaScript(input); //\r\t\"\n\b\f

Any control character (code < 0x20) will be encoded

var input = String.fromCharCode(0) + String.fromCharCode(16) + String.fromCharCode(31);
var encoded = encoder.encodeJavaScript(input); //\u0000\u0010\u001f

Characters #133, #8232 and #8233 will be encoded

var input = String.fromCharCode(133) + String.fromCharCode(8232) + String.fromCharCode(8233);
var encoded = encoder.encodeJavaScript(input); //\u0085\u2028\u2029

XML encode and decode

XML encode has the same behavior as HTML encode except XML encode converts ' into &apos;

var input = '\'';
var encoded = encoder.xmlEncode(input); //&apos;

URI encode and decode

URI encode an input string

var encoder = require('./encoder.js');
var input = 'http://www.example.com/abc 123';
var encoded = encoder.encodeURI(input); //http://www.example.com/abc%20123

URI decode an input string

var encoder = require('./encoder.js');
var input = 'http://www.example.com/abc%20123';
var decoded = encoder.decodeURI(input); //http://www.example.com/abc 123

Base64 encode and decode

Base64 encode a string

var input = 'Hello World!';
var encoded = encoder.base64Encode(input); //"SGVsbG8gV29ybGQh"

Decode a base64 string

var input = 'SGVsbG8gV29ybGQh';
var encoded = encoder.base64Decode(input); //"Hello World!"

Test

Make sure mocha is installed globally

npm install mocha -g

Run npm test to run unit test

Dependencies

License

MIT