html-escape (original) (raw)

html-escape

Escape a string to be safe for use in html. &, <, ', and "characters are replaced with with their named character references:&amp;, &lt;, &apos;, and &quot;. Escaped strings will be safe for use in the following contexts:

Example

var escape = require("html-escape");

var xssAttempt = "Hello  world!";

// Output safe html

console.log("

" + escape(xssAttempt) + "

");

// "

Hello <script>while(1);</script> world!

"

Installation

npm install html-escape