Created
September 8, 2022 06:53
-
-
Save oscarmarina/e8892ff62b803c7c563c8658eb0b06aa to your computer and use it in GitHub Desktop.
Escapes a string for use in HTML.
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
| export const escapeHTML = (str) => | |
| str.replace( | |
| /[&<>'"]/g, | |
| (character) => | |
| ({ | |
| '&': '&', | |
| '<': '<', | |
| '>': '>', | |
| "'": ''', | |
| '"': '"', | |
| }[character] || character) | |
| ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment