sindresorhus / filenamify

Convert a string to a valid safe filename
MIT License
490 stars 26 forks source link

Fix filenames truncated by `maxLength` not keeping their extension #27

Closed aakriti-kedia closed 3 years ago

aakriti-kedia commented 3 years ago

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_veryvery.txt

sindresorhus commented 3 years ago

Any reason you didn't go with my suggestion in https://github.com/sindresorhus/filenamify/issues/13#issuecomment-584898873 ?

aakriti-kedia commented 3 years ago

Any reason you didn't go with my suggestion in #13 (comment) ?

Hi @sindresorhus My thought process was that if this code is part of filenamify instead of filenamify-path, all the processing related to filename would be dealt in filenamify and abstracted from filenamify-path. As per the logic - If the filename is long, we wish to truncate the filename and not its path - as this is an operation on the filename, it would make sense if it resides in filenamify.

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.

papb commented 2 years ago

Maybe this could be updated to also account for a few specific "double" extensions such as .tar.gz and .tar.bz2?

sindresorhus commented 2 years ago

@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.