mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 06:28:51 +00:00
tweak(phone/utils): Moved isImageValid util to common dir
This commit is contained in:
1 parent
18c1676c01
commit
41b50d6429
3 files changed
+18
-18
No files matched your search
@@ -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);
|
||||
});
|
||||
}
|
||||
Reference in new issue
Block a user