blob: b4db849d016e17934c32bc31b60827084762b635 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
import filesExist from "./filesExist";
import transparentPng from '../constants/transparentPng'
/**
* This function takes a list of urls and returns the first one that exists.
* If none is found, return a transparent png.
* The function will always return a value that is appriopriate for an img src.
* @param urls The list of urls to try
* @returns The image source of the first url that exists, or a transparent png if none exist
*/
export default async function findImgSrc(urls: string[]): Promise<string> {
return filesExist(urls).then((url) => {
if (url !== null) {
return url;
}
// If none of the images exist, return a transparent png
return transparentPng;
});
}
|