Skip to content

Instantly share code, notes, and snippets.

@linuxenko
Created December 12, 2016 05:41
Show Gist options
  • Save linuxenko/50afb7f776f08ae93bbbf02f3e226888 to your computer and use it in GitHub Desktop.
Save linuxenko/50afb7f776f08ae93bbbf02f3e226888 to your computer and use it in GitHub Desktop.
var ESCAPED_CHARS = {
'&' : '&',
'>' : '>',
'<' : '&lt;',
'"' : '&quot;',
'\'': '&#x27;'
};
var UNSAFE_CHARS_REGEX = /[&><"']/g;
export default function (str) {
return ('' + str).replace(UNSAFE_CHARS_REGEX, function (match) {
return ESCAPED_CHARS[match];
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment