sindresorhus / filenamify

Convert a string to a valid safe filename

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Option to avoid removing repeated replacement

alexander-akait opened this issue · comments

Usage:

const filenamofy = require('filenamify');

const safeFilename = filenamify('/path/to/file---name.ext', { replacement: '-' });

Now:
/path/to/file---name.ext -> path-to-file-name.ext

Feature request (maybe keepRepeat: true or better name):
/path/to/file---name.ext -> path-to-file---name.ext

What's the use-case? I don't really see any good reason to preserve duplicate replacement characters like that.

@sindresorhus create css classes based on filesystem path, useful for css-loader, we already have same logic inside

Alright. PR welcome.

Some name ideas:

  • condenseReplacements
  • preserveRepeatedReplacements
  • removeRepeatedReplacements

@sindresorhus the replacement is done at filenamify.js#L30 using the tream-repeat library. We should implement the change in that library first I believe. I will open an issue and link it with this one.

It seems that I missunderstood the question. I though we wanted to replace all the occurances of repeated characters, except a specific one. I'm closing the issue on tream-repeat repo.

Is there any particular reason why #18 has been refused? I have a similar fix for this issue and was wondering if it would be welcomed.

This was fixed in 7d4846f.