Skip to content

Instantly share code, notes, and snippets.

@val314159
Last active March 31, 2016 01:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save val314159/9ab1fd1a551679d958b5c42e43732696 to your computer and use it in GitHub Desktop.
Save val314159/9ab1fd1a551679d958b5c42e43732696 to your computer and use it in GitHub Desktop.
HTML encoding / decoding

Escape2

HTML encoding / decoding

Install:

npm install escape2

Browser:

<script src="node_modules/escape2/index.js"></script>;

Node:

var escape2=require('escape2');

Use:

var enc = escape2.encode('<&>');
var dec = escape2.decode(enc);
escape2={
encode:function(text){
text = text.replace(/&/g,'&amp;');
text = text.replace(/</g, '&lt;');
text = text.replace(/>/g, '&gt;');
return text;
},
decode:function(text){
text = text.replace( /&gt;/g,'>');
text = text.replace( /&lt;/g,'<');
text = text.replace(/&amp;/g,'&');
return text;
}
};
module.exports=escape2;
{
"name":"escape2",
"description":"HTML encoding / decoding",
"repository":"https://gist.github.com/val314159/9ab1fd1a551679d958b5c42e43732696",
"main":"index.js",
"license":"MIT",
"version":"0.0.2"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment