Toggle menu

html

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,"&lt;")
        .replace(/>/g,"&gt;")
        .replace(/"/g,"&quot;")
        .replace(/'/g,"&apos;");
},
unescape: function(str) {
    if (str === null || !str.toString) { return ""; }
    return str.toString()
        .replace(/&apos;/g,"'")
        .replace(/&quot;/g,"\"")
        .replace(/&gt;/g,">")
        .replace(/&lt;/g,"<")
        .replace(/&amp;/g,"&");
},

MethodDescription
HTML.escapeEscapes HTML
HTML.unescapeUnescapes 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": "&lt;p&gt;Hello&lt;/p&gt;"
}

Last modified on 10 March 2020

Share this page

Facebook icon Twitter icon email icon

Print

print icon