Last active
March 20, 2022 08:55
-
-
Save choyan/140b0a4bd40387fc8e4c83498d46aa28 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function getFileNameFromPath(filePath: string): string { | |
return filePath.substring(filePath.lastIndexOf('/') + 1); | |
} | |
function getShortName(fileName: string): string { | |
if (fileName.length > 30) { | |
return fileName.slice(0, 30) + '...' + fileName.split('.').pop(); | |
} | |
return fileName; | |
} | |
export function getFileName(fileName: string | void): string { | |
if (typeof fileName === 'string') { | |
if (fileName.includes('/')) { | |
return getShortName(getFileNameFromPath(fileName)); | |
} | |
return getShortName(fileName); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment