pid / speakingurl

Generate a slug – transliteration with a lot of options
http://pid.github.io/speakingurl/
BSD 3-Clause "New" or "Revised" License
1.12k stars 84 forks source link

Add option to remove underscores #103

Closed n-rook closed 7 years ago

n-rook commented 7 years ago

Today I learned underscores aren't allowed in domain hostnames! Whoops. As such, I'd like an option to get rid of underscores, and replace them with hyphens.

n-rook commented 7 years ago

I would be totally on board with submitting a PR for this by the way. I'm not sure what the right interface for it is, though. Something as literal as underscore: false? Or something more general?

leocaseiro commented 7 years ago

you can replace before call SpeakingURL, something like:

var getSlug = require('speakingurl');
var foo = "Schöner_Titel_läßt_grüßen!?"; 
var slug = getSlug(foo.replace('_', '-'); 
console.log(slug);

or if you have to remove _ and not convert to dashes, you can try:

var slug = getSlug(foo.replace('_', ''); 
pid commented 7 years ago

Use the custom option:

getSlug('Schöner_Titel_läßt_grüßen!?', { custom:{'_': '-'} } )

n-rook commented 7 years ago

Ah, you're right. I hadn't realized custom would still work on hyphens or underscores. Thanks!