sindresorhus / filenamify

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

File names truncated by `maxLength` should keep their extension #13

Closed scowalt closed 3 years ago

scowalt commented 4 years ago
const unsafeName = "This? This is very long filename that will lose its extension when passed into filenamify, which could cause issues.csv";
const safeName = filenamify(unsafeName);
console.log(safeName); // "This! This is very long filename that will lose its extension when passed into filenamify, which cou" (length: 100)
// Ideal: "This! This is very long filename that will lose its extension when passed into filenamify, which.csv" (length: 100)

Perhaps this could be an option keepExtension, default to false to keep backwards compatibility.

sindresorhus commented 4 years ago

The filenamify() method is meant to accept a pure string, not an existing filename. There's filenamify.path(), but it doesn't currently work because of https://github.com/sindresorhus/filenamify/blob/120141454e7dc9cba84e58f94ce5fa3f79ee6565/index.js#L40. I don't remember why I added that. We could possibly remove it to allow filenames too.