-
-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix filenames truncated by maxLength
not keeping their extension
#27
Fix filenames truncated by maxLength
not keeping their extension
#27
Conversation
filenamify.js
Outdated
@@ -31,7 +31,11 @@ export default function filenamify(string, options = {}) { | |||
} | |||
|
|||
string = filenameReservedRegex.windowsNames().test(string) ? string + replacement : string; | |||
string = string.slice(0, typeof options.maxLength === 'number' ? options.maxLength : MAX_FILENAME_LENGTH); | |||
const allowedLength = typeof options.maxLength === 'number' ? options.maxLength : MAX_FILENAME_LENGTH; | |||
if (allowedLength < string.length) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it reads better if string.length
comes first in this conditional.
Any reason you didn't go with my suggestion in #13 (comment) ? |
Hi @sindresorhus Please feel free to let me know if you have any concerns with extending this approach to filenamify and not keeping it restricted to filenamify-path. |
maxLength
not keeping their extension
Maybe this could be updated to also account for a few specific "double" extensions such as |
@papb I don't think it makes sense to handle such extension automatically. That would be surprising behavior. Maybe there could be an option to define a set of known double extensions or something. It's not something I need, so if you need it, open an issue with a proper proposal. |
Fixes #13
Excludes the extension, truncates the string to the required length, appends the extension.
Example -
Input : very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_long_filename.txt
Output
very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_very_.txt