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/ + )); +};