20 lines
465 B
TypeScript
20 lines
465 B
TypeScript
|
|
/**
|
||
|
|
* Decodes HTML entities in a string
|
||
|
|
* @param text The text that may contain HTML entities
|
||
|
|
* @returns The decoded text
|
||
|
|
*/
|
||
|
|
export function decodeHTMLEntities(text: string): string {
|
||
|
|
const entityMap: Record<string, string> = {
|
||
|
|
'&': '&',
|
||
|
|
'<': '<',
|
||
|
|
'>': '>',
|
||
|
|
'"': '"',
|
||
|
|
''': "'",
|
||
|
|
'/': '/',
|
||
|
|
'`': '`',
|
||
|
|
'=': '='
|
||
|
|
};
|
||
|
|
|
||
|
|
return text.replace(/&[#\w]+;/g, (entity) => entityMap[entity] || entity);
|
||
|
|
}
|