sindresorhus / slugify

Slugify a string
MIT License
2.56k stars 81 forks source link

Initial work on character preservation option. #70

Closed aegatlin closed 1 year ago

aegatlin commented 2 years ago

Fixes #55

I wanted to preserve the HTML fragment, #, in my use-case for slugify. I saw #55 and thought I'd kick off the PR for it.

aegatlin commented 2 years ago

hmm, I actually just realized # should probably be treated as a one-time occurrence and not something that should be allowed repeatedly in a slug... 🤔

We could still keep this and modify the allowSet to exclude #, and then address that separately. Let me know what you think 👍

sindresorhus commented 2 years ago

and then address that separately

Address it how?

aegatlin commented 2 years ago

what I'm doing in my workflow to slugify urls is basically...

const [a, b] = s.split('#')
const slug = `${slugify(a)}#${slugify(b)}`

But, this depends on the extent to which you want slugify === urlify.

sindresorhus commented 2 years ago

I think if the user sets # as a preserved, it's up to them to ensure it works in a URL. I don't think we should have any special handling.

aegatlin commented 2 years ago

Sounds good to me. I think the PR is ready to review, then. 😀👍