Created
January 13, 2021 14:19
-
-
Save tolluset/365bdf1e77776ff53950ed4ce4577946 to your computer and use it in GitHub Desktop.
decoder for html by ts
This file contains 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
const decodeHtmlEntity = function (str: string) { | |
return str.replace(/&#(\d+);/g, function (match: string, dec: number) { | |
return String.fromCharCode(dec) | |
}) | |
} | |
const encodeHtmlEntity = function (str: string) { | |
const buf = [] | |
for (let i = str.length - 1; i >= 0; i--) { | |
buf.unshift(['&#', str.charCodeAt(i), ';'].join('')) | |
} | |
return buf.join('') | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment