ai
Version:
AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.
18 lines (15 loc) • 463 B
text/typescript
/**
* Converts a data URL of type text/* to a text string.
*/
export function getTextFromDataUrl(dataUrl: string): string {
const [header, base64Content] = dataUrl.split(',');
const mediaType = header.split(';')[0].split(':')[1];
if (mediaType == null || base64Content == null) {
throw new Error('Invalid data URL format');
}
try {
return window.atob(base64Content);
} catch (error) {
throw new Error(`Error decoding data URL`);
}
}