From b5016bb39b5aad08abab0bbe6abebdd3fe900836 Mon Sep 17 00:00:00 2001 From: Mylloon Date: Wed, 27 Jul 2022 00:35:47 +0200 Subject: [PATCH] file ext stuff --- src/utils/misc.ts | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/utils/misc.ts b/src/utils/misc.ts index 0f76dd4..917fb74 100644 --- a/src/utils/misc.ts +++ b/src/utils/misc.ts @@ -36,3 +36,25 @@ export const removeExtension = (filename: string) => { return array.join('.'); }; + +/** + * Get extension from a filename. + * @param filename string of the filename + * @returns string of the extension if it exists + */ +export const getExtension = (filename: string) => { + const array = filename.split('.'); + + return array.pop(); +}; + +/** + * Define if a media is a media based on file extension. + * @param filename string of the filename + * @returns true is file is a media + */ +export const isImage = (filename: string) => { + return Boolean(getExtension(filename)?.match( + /jpg|jpeg|png|webp|gif/ + )); +};