GitHub 6248★

Trim the file extension from a file name

JavaScript version

const trimExt = (fileName) => (fileName.indexOf('.') === -1 ? fileName : fileName.split('.').slice(0, -1).join('.'));

TypeScript version

const trimExt = (fileName: string): string => (fileName.indexOf('.') === -1 ? fileName : fileName.split('.').slice(0, -1).join('.'));

Examples

trimExt('document'); // document
trimExt('document.pdf'); // document
trimExt('document.2020.pdf'); // document.2020
Follow me on and to get more useful contents.