18 lines
276 B
JavaScript
18 lines
276 B
JavaScript
|
const escapeCodes = {
|
||
|
'&': '&',
|
||
|
'<': '<',
|
||
|
'>': '>',
|
||
|
"'": ''',
|
||
|
'"': '"'
|
||
|
};
|
||
|
|
||
|
let format = {};
|
||
|
|
||
|
format.escape = function (str) {
|
||
|
return str.replaceAll(
|
||
|
/[&<>'"]/g,
|
||
|
tag => escapeCodes[tag]
|
||
|
)
|
||
|
};
|
||
|
|
||
|
export default format;
|