file ext stuff
This commit is contained in:
parent
a0fc0103f3
commit
b5016bb39b
1 changed files with 22 additions and 0 deletions
|
@ -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/
|
||||||
|
));
|
||||||
|
};
|
||||||
|
|
Loading…
Reference in a new issue