diff --git a/packages/common/utils.js b/packages/common/utils.js index af8d2fd421154d70005fbbdcec1cfceeebc3a959..a270ffb67db80e0651a099c7f4c6f52ceda77d61 100644 --- a/packages/common/utils.js +++ b/packages/common/utils.js @@ -333,3 +333,29 @@ export async function getMimeTypeOfFile(file) { fileReader.readAsArrayBuffer(file.slice(0, 4)); }); } + +/** + * Get the basename of a filename + * + * @param str + * @returns {string} + */ +export const getBaseName = (str) => { + let base = String(str).substring(str.lastIndexOf('/') + 1); + + if (base.lastIndexOf(".") !== -1) { + base = base.substring(0, base.lastIndexOf(".")); + } + + return base; +}; + +/** + * Get the file extension of a filename + * + * @param str + * @returns {string} + */ +export const getFileExtension = (str) => { + return str.split('.').pop(); +};