file ext stuff

This commit is contained in:
Mylloon 2022-07-27 00:35:47 +02:00
parent a0fc0103f3
commit b5016bb39b
Signed by: Anri
GPG key ID: A82D63DFF8D1317F

View file

@ -36,3 +36,25 @@ export const removeExtension = (filename: string) => {
return array.join('.'); 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/
));
};