UNPKG

410 BJavaScriptView Raw
1var toString = require('../lang/toString');
2
3 /**
4 * Escapes a string for insertion into HTML.
5 */
6 function escapeHtml(str){
7 str = toString(str)
8 .replace(/&/g, '&')
9 .replace(/</g, '&lt;')
10 .replace(/>/g, '&gt;')
11 .replace(/'/g, '&#39;')
12 .replace(/"/g, '&quot;');
13 return str;
14 }
15
16 module.exports = escapeHtml;
17
18