tweak(phone/utils): Moved isImageValid util to common dir

This commit is contained in:
Taso authored and Taso committed 2021-03-03 22:19:59 -05:00
1 parent 18c1676c01
commit 41b50d6429
3 files changed
+18 -18

No files matched your search

+16
View File
@@ -0,0 +1,16 @@
/**
* Returns a Promise that validates that the URL successfully
* loads in the browser. If the URL doesn't load the promise is
* rejected.
* @param {string} link - a URL we are trying to validate
* @returns {Promise<string>} link - Will resolve the promise with the link string
* if valid. Will reject if failed.
*/
export function isImageValid(link: string): Promise<string> {
return new Promise((res, rej) => {
const image = new Image();
image.src = link;
image.onerror = () => rej(`Invalid image, ${link}`);
image.onload = () => res(link);
});
}