export function truncateString(str: string, num: number) { if (str.length > num) { return str.slice(0, num) + '…'; } else { return str; } } export function convertImageToBase64(imageUrl: string) { return new Promise((resolve, reject) => { // Create a new request for the image fetch(imageUrl) .then((response) => response.blob()) // Get the image as a Blob .then((blob) => { const reader = new FileReader(); reader.onloadend = () => { const base64data = reader.result; // This will be the base64-encoded image resolve(base64data); }; reader.onerror = reject; reader.readAsDataURL(blob); // Read the Blob as a Data URL (base64 string) }) .catch(reject); }); } export function splitOnLast(str: string, delimiter: string) { const lastIndex = str.lastIndexOf(delimiter); if (lastIndex === -1) { return [str]; // No delimiter found } const firstPart = str.slice(0, lastIndex); const secondPart = str.slice(lastIndex + delimiter.length); return [firstPart, secondPart]; }