Escape string for use in html
npm install html-escapeEscape a string to be safe for use in html. &, <, ', and "
characters are replaced with with their [named character references][]:&, <, ', and ". Escaped strings will be safe
for use in the following contexts:
* [RCDATA][] and [DATA][html-data] (content of all elements except for
and )
* [Single-quoted attribute values][html-single-attribute] '
* [Double-quoted attribute values][html-double-attribute] "
[named character references]: https://html.spec.whatwg.org/multipage/syntax.html#named-character-references
[html-data]: https://html.spec.whatwg.org/multipage/syntax.html#data-state
[rcdata]: https://html.spec.whatwg.org/multipage/syntax.html#rcdata-state
[html-single-attribute]: https://html.spec.whatwg.org/multipage/syntax.html#attribute-value-(single-quoted)-state
[html-double-attribute]: https://html.spec.whatwg.org/multipage/syntax.html#attribute-value-(double-quoted)-state
`` " + escape(xssAttempt) + " Hello <script>while(1);</script> world!js`
var escape = require("html-escape");
var xssAttempt = "Hello world!";
// Output safe html
console.log("
// "
```
npm install html-escape