hd-utils
Version:
A handy utils for modern JS developers
12 lines (11 loc) • 420 B
JavaScript
/**
* @description It takes a string and get the extension file type.
* @example getFileExtensionFromString("fileName.txt") => txt
* @param {string} str - string - The string to get the file extension from.
* @returns The file extension of the string.
*/
export default function getFileExtensionFromString(str) {
if (!str || typeof str !== 'string')
return '';
return str.split('.').at(-1) || '';
}