forked from syntaxbullet/AuroraBot-discord
15 lines
401 B
TypeScript
15 lines
401 B
TypeScript
|
|
/**
|
|
* Escapes unsafe characters in a string to prevent XSS.
|
|
* @param unsafe - The raw string to escape.
|
|
* @returns The escaped string safe for HTML insertion.
|
|
*/
|
|
export function escapeHtml(unsafe: string): string {
|
|
return unsafe
|
|
.replace(/&/g, "&")
|
|
.replace(/</g, "<")
|
|
.replace(/>/g, ">")
|
|
.replace(/"/g, """)
|
|
.replace(/'/g, "'");
|
|
}
|