Files
outline/shared/utils/csv.ts
2025-03-13 00:23:48 +00:00

32 lines
745 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/* eslint-disable no-control-regex */
/**
* Helper class for CSV operations.
*/
export class CSVHelper {
/**
* Sanitizes a value for CSV output.
*
* @param value The value to sanitize.
* @returns The sanitized value.
*/
public static sanitizeValue(value: string): string {
if (!value) {
return "";
}
return (
value
.toString()
// Formula triggers
.replace(/^([+\-=@<>±÷×])/u, "'$1")
// Control characters
.replace(/[\u0000-\u001F\u007F-\u009F]/gu, "")
// Zero-width spaces
.replace(/[\u200B-\u200D\uFEFF]/g, "")
// Bidirectional control
.replace(/[\u202A-\u202E\u2066-\u2069]/g, "")
);
}
}