You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

27 lines
552 B
TypeScript

8 months ago
export default (data: string): string => {
let text = ''
for (let i = 0; i < data.length; i++) {
switch (data.charCodeAt(i)) {
case 34: // "
text += '&quot;'
break
case 38: // &
text += '&amp;'
break
case 39: // '
text += '&#x27;' // modified from escape-html; used to be '&#39'
break
case 60: // <
text += '&lt;'
break
case 62: // >
text += '&gt;'
break
default:
text += data[i]
break
}
}
return text
}