Skip to content

Instantly share code, notes, and snippets.

@choyan
Last active March 20, 2022 08:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save choyan/140b0a4bd40387fc8e4c83498d46aa28 to your computer and use it in GitHub Desktop.
Save choyan/140b0a4bd40387fc8e4c83498d46aa28 to your computer and use it in GitHub Desktop.
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