aboutsummaryrefslogtreecommitdiff
path: root/webAO/utils/tryUrls.ts
diff options
context:
space:
mode:
authorcaleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu>2022-03-24 00:42:24 -0400
committercaleb.mabry.15@cnu.edu <caleb.mabry.15@cnu.edu>2022-03-24 00:42:24 -0400
commit08916f6d4eb8db40e6e54f78c744071f3b5298d7 (patch)
tree04a311a423444705e7a36df230da8558f989ac68 /webAO/utils/tryUrls.ts
parente28fcc59a76772eae64ed480919cddb60a3b5fce (diff)
Adding typescript support and unit tests
Diffstat (limited to 'webAO/utils/tryUrls.ts')
-rw-r--r--webAO/utils/tryUrls.ts20
1 files changed, 20 insertions, 0 deletions
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