19 lines
420 B
JavaScript
19 lines
420 B
JavaScript
![]() |
var makeString = require('./helper/makeString');
|
||
|
var escapeChars = require('./helper/escapeChars');
|
||
|
var reversedEscapeChars = {};
|
||
|
|
||
|
var regexString = "[";
|
||
|
for(var key in escapeChars) {
|
||
|
regexString += key;
|
||
|
}
|
||
|
regexString += "]";
|
||
|
|
||
|
var regex = new RegExp( regexString, 'g');
|
||
|
|
||
|
module.exports = function escapeHTML(str) {
|
||
|
|
||
|
return makeString(str).replace(regex, function(m) {
|
||
|
return '&' + escapeChars[m] + ';';
|
||
|
});
|
||
|
};
|