quivr/frontend/lib/helpers/cloneFileWithSanitizedName.ts

9 lines
304 B
TypeScript

const removeSpecialCharacters = (input: string) =>
input.normalize("NFD").replace(/[^\w\s.]/g, "");
export const cloneFileWithSanitizedName = (file: File): File => {
const sanitizedFileName = removeSpecialCharacters(file.name);
return new File([file], sanitizedFileName, { type: file.type });
};