From 08916f6d4eb8db40e6e54f78c744071f3b5298d7 Mon Sep 17 00:00:00 2001 From: "caleb.mabry.15@cnu.edu" Date: Thu, 24 Mar 2022 00:42:24 -0400 Subject: Adding typescript support and unit tests --- webAO/utils/tryUrls.ts | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 webAO/utils/tryUrls.ts (limited to 'webAO/utils/tryUrls.ts') diff --git a/webAO/utils/tryUrls.ts b/webAO/utils/tryUrls.ts new file mode 100644 index 0000000..14ef885 --- /dev/null +++ b/webAO/utils/tryUrls.ts @@ -0,0 +1,20 @@ +import fileExists from './fileExists' +import transparentPng from '../constants/transparentPng' +const urlExtensionsToTry = [ + '.png', + '.gif', + '.webp', + '.apng' +] +const tryUrls = async (url: string) => { + for (let i = 0; i < urlExtensionsToTry.length; i++) { + const extension = urlExtensionsToTry[i] + const fullFileUrl = url + extension + const exists = await fileExists(fullFileUrl); + if (exists) { + return fullFileUrl + } + } + return transparentPng +} +export default tryUrls \ No newline at end of file -- cgit