sindresorhus / filenamify

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

Prevent overwriting replacement character in the original string #12

Closed rpeg closed 4 years ago

rpeg commented 4 years ago

Fixes #11. Now we trim repeat and outer reserved chars before doing a global replace with the replacement char, to preserve instances of that char present in the original string. IMO the other two cases mentioned there are handled correctly as is, since I take the purpose of the library as preserving as much of the original string as possible without redundancy.

Sidenote: I think the multiple similar regex definitions here could be simplified with ES6 string literals, but the linter barks at that.

sindresorhus commented 4 years ago

Sidenote: I think the multiple similar regex definitions here could be simplified with ES6 string literals, but the linter barks at that.

👍 What does it say?

sindresorhus commented 4 years ago

Would be good to explicitly document this behavior in the readme and index.d.ts.

sindresorhus commented 4 years ago

@rpeg Friendly bump :)

sindresorhus commented 4 years ago

Closing for lack of activity.