Created
December 1, 2025 01:23
-
-
Save prof3ssorSt3v3/a80df5ee9833b6062e3e62b0c828221b to your computer and use it in GitHub Desktop.
Starter code for a utility file
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
| // Encode: converts '<tags> & "quotes"' to "<tags> & "quotes"" | |
| function encodeHtmlEntitiesDOM(str) { | |
| const div = document.createElement('div'); | |
| div.appendChild(document.createTextNode(str)); | |
| return div.innerHTML; | |
| } | |
| // Decode: converts "<tags> & "quotes"" back to '<tags> & "quotes"' | |
| function decodeHtmlEntitiesDOM(str) { | |
| const textarea = document.createElement('textarea'); | |
| textarea.innerHTML = String(str ?? ''); | |
| return textarea.value; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment