21 lines
403 B
JavaScript
21 lines
403 B
JavaScript
// https://stackoverflow.com/a/6020820
|
|
|
|
// List of HTML entities for escaping.
|
|
const htmlEscapes = {
|
|
'&': '&',
|
|
'<': '<',
|
|
'>': '>',
|
|
'"': '"',
|
|
"'": ''',
|
|
'/': '/',
|
|
}
|
|
|
|
const htmlEscaper = /[&<>"'\/]/g
|
|
|
|
// Escape a string for HTML interpolation.
|
|
const escape = string => {
|
|
return ('' + string).replace(htmlEscaper, match => htmlEscapes[match])
|
|
}
|
|
|
|
export default escape
|