Created
April 4, 2025 13:32
-
-
Save schalkneethling/0c7dcf6f074da178aa63ac16545946f6 to your computer and use it in GitHub Desktop.
Truncate a filename with JS
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 getFilename(filename, truncateAt = 15) { | |
if (filename.length <= truncateAt) { | |
return filename; | |
} | |
const extension = filename.slice(filename.lastIndexOf(".")); | |
const shortenedFilename = filename.slice(0, truncateAt); | |
return `${shortenedFilename}..${extension}`; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment