UNPKG

@woosh/meep-engine

Version:

Pure JavaScript game engine. Fully featured and production ready.

30 lines (23 loc) 706 B
/** * Resolve URL to content and create a data URL from the content * @example 'cat.png' -> 'data:image/png;base64,....' * @param {string} url * @returns {string} */ export async function url_to_data_url(url) { return fetch(url) .then(response => { return response.blob(); }) .then(blob => { const fr = new FileReader(); return new Promise((resolve, reject) => { fr.onload = () => { resolve(fr.result); }; fr.onerror = reject; fr.onabort = reject; fr.readAsDataURL(blob); }); }); }