dodo / node-slug

slugifies even utf-8 chars!
MIT License
1.07k stars 94 forks source link

Striping punctuations #11

Closed thom4parisot closed 10 years ago

thom4parisot commented 11 years ago

Hello,

thanks for your module. It works really really well :-) Except that at some point, it keeps some chars which are unusual for slugs.

Actually Devil May Cry 3 : l'Eveil de Dante is converted as devil-may-cry-3-:-l'eveil-de-dante. It would be cleaner to be converted as devil-may-cry-3-leveil-de-dante.

Do you have any plan to support that? Or do you recommend a nice way to achieve such a result?

dodo commented 11 years ago

glad that you like it :)

since the results of slug() are standard conform with what an URL can contain i don't plan on stripping : out. but how about a blacklist option for characters? would that help you?

wyoumans commented 10 years ago

I agree. While some punctuation may technically be part of a url slug, it is cleaner to strip them out. I am using this for a CMS and keep running into ! in the URLs. Maybe an option to strip out non-word characters (/\W/)?

Thanks for the project.

Currently slug('yo! yo? yo& yo=') yields yo!-yo-yoand-yo which seems odd. I would expect it to yield yo-yo-yo-yo

dodo commented 10 years ago

Your problems are very specific and i still think the trade off between 'option' versus 'you do it' doesn't really pay off, or i'm just unable to see it.

function myslug(str, opts) {return slug(str.replace(/[!:&]/g,''), opts);}

> myslug("Devil May Cry 3 : l'Eveil de Dante")
'Devil-May-Cry-3-l\'Eveil-de-Dante'
> myslug("yo! yo? yo& yo=")
'yo-yo-yo-yo'
wyoumans commented 10 years ago

Fair enough.

jbraithwaite commented 10 years ago

If this library is for making URL safe slugs, it should follow RFC 1738 and not allow: