18 lines
390 B
JavaScript
18 lines
390 B
JavaScript
var makeString = require('./helper/makeString');
|
|
var escapeChars = require('./helper/escapeChars');
|
|
|
|
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] + ';';
|
|
});
|
|
};
|