Used to escape or unescape HTML.
Executed
Server-side
Details
var html = require('html');
The following replacements are performed.
escape: function(str) {
if (str === null || !str.toString) { return ""; }
return str.toString()
.replace(/&/g,"&")
.replace(/</g,"<")
.replace(/>/g,">")
.replace(/"/g,""")
.replace(/'/g,"'");
},
unescape: function(str) {
if (str === null || !str.toString) { return ""; }
return str.toString()
.replace(/'/g,"'")
.replace(/"/g,"\"")
.replace(/>/g,">")
.replace(/</g,"<")
.replace(/&/g,"&");
},
Method | Description |
---|---|
HTML.escape | Escapes HTML |
HTML.unescape | Unescapes HTML |
Example
function( params, credentials ) {
var html = require('html');
var result = html.HTML.escape('<p>Hello</p>');
return result;
}
{
"jsonrpc": "2.0",
"id": 198,
"result": "<p>Hello</p>"
}