23 lines
747 B
TypeScript
23 lines
747 B
TypeScript
/**
|
|
* Fixes incorrectly escaped HTML entities in AI model outputs
|
|
* @param text String potentially containing incorrectly escaped HTML entities from AI models
|
|
* @returns String with HTML entities converted back to normal characters
|
|
*/
|
|
export function fixModelHtmlEscaping(text: string): string {
|
|
return text
|
|
.replace(/>/g, ">")
|
|
.replace(/</g, "<")
|
|
.replace(/"/g, '"')
|
|
.replace(/&/g, "&")
|
|
.replace(/'/g, "'")
|
|
}
|
|
|
|
/**
|
|
* Removes invalid characters (like the replacement character �) from a string
|
|
* @param text String potentially containing invalid characters
|
|
* @returns String with invalid characters removed
|
|
*/
|
|
export function removeInvalidChars(text: string): string {
|
|
return text.replace(/\uFFFD/g, "")
|
|
}
|