Skip to content

Instantly share code, notes, and snippets.

@Tolluset
Created January 13, 2021 14:19
Embed
What would you like to do?
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