22 lines
503 B
JavaScript
22 lines
503 B
JavaScript
|
|
|
|
var escape = module.exports = function escape(string, ignore) {
|
|
var pattern;
|
|
|
|
if (string === null || string === undefined) return;
|
|
|
|
ignore = (ignore || '').replace(/[^&"<>\']/g, '');
|
|
pattern = '([&"<>\'])'.replace(new RegExp('[' + ignore + ']', 'g'), '');
|
|
|
|
return string.replace(new RegExp(pattern, 'g'), function(str, item) {
|
|
return escape.map[item];
|
|
})
|
|
}
|
|
|
|
var map = escape.map = {
|
|
'>': '>'
|
|
, '<': '<'
|
|
, "'": '''
|
|
, '"': '"'
|
|
, '&': '&'
|
|
} |