diff --git a/filenamify.js b/filenamify.js index 6d810b4..17890f8 100644 --- a/filenamify.js +++ b/filenamify.js @@ -27,8 +27,20 @@ export default function filenamify(string, options = {}) { string = string.replace(reTrailingPeriods, ''); if (replacement.length > 0) { + const startedWithDot = string[0] === '.'; + string = trimRepeated(string, replacement); string = string.length > 1 ? stripOuter(string, replacement) : string; + + // We removed the whole filename + if (!startedWithDot && string[0] === '.') { + string = replacement + string; + } + + // We removed the whole extension + if (string[string.length - 1] === '.') { + string += replacement; + } } string = windowsReservedNameRegex().test(string) ? string + replacement : string; diff --git a/test.js b/test.js index 0072651..8b52d86 100644 --- a/test.js +++ b/test.js @@ -17,6 +17,8 @@ test('filnamify()', t => { t.is(filenamify('..'), '!'); t.is(filenamify('./'), '!'); t.is(filenamify('../'), '!'); + t.is(filenamify('!.foo'), '!.foo'); + t.is(filenamify('foo.!'), 'foo.!'); t.is(filenamify('foo.bar.'), 'foo.bar'); t.is(filenamify('foo.bar..'), 'foo.bar'); t.is(filenamify('foo.bar...'), 'foo.bar');