Created
December 12, 2016 05:41
-
-
Save linuxenko/50afb7f776f08ae93bbbf02f3e226888 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var ESCAPED_CHARS = { | |
'&' : '&', | |
'>' : '>', | |
'<' : '<', | |
'"' : '"', | |
'\'': ''' | |
}; | |
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