19 lines
439 B
TypeScript
19 lines
439 B
TypeScript
export function truncate(text: string, maxLength: number): string {
|
|
if (text.length > maxLength) {
|
|
return text.substring(0, maxLength) + '...'
|
|
}
|
|
return text
|
|
}
|
|
|
|
/**
|
|
* Escape HTML special characters to prevent XSS and rendering issues
|
|
*/
|
|
export function escapeHtml(text: string): string {
|
|
return text
|
|
.replace(/&/g, '&')
|
|
.replace(/</g, '<')
|
|
.replace(/>/g, '>')
|
|
.replace(/"/g, '"')
|
|
.replace(/'/g, ''')
|
|
}
|