Skip to content

Instantly share code, notes, and snippets.

@tolluset
Created January 13, 2021 14:19
Show Gist options
  • Save tolluset/365bdf1e77776ff53950ed4ce4577946 to your computer and use it in GitHub Desktop.
Save tolluset/365bdf1e77776ff53950ed4ce4577946 to your computer and use it in GitHub Desktop.
decoder for html by ts
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