With the advent of Node.js and modern application endpoint routing, I find it surprising that there is no in-built function to convert any string into an URL-optimized slug.
If your application users write content and you want to make their content searchable with an SEO-friendly URL, a slugify function is practically inevitable. I run my Node.js applications on DigitalOcean droplets. If you want to give it a try with a $100 credit, simply follow this link:
DigitalOcean - The developer cloud
Helping millions of developers easily build, test, manage, and scale applications of any size - faster than ever…
In order to turn an article’s original title “Why Uber isn’t spelled Über” into a slug optimized for URLs, parse your string through this slugify function to get “why-uber-isnt-spelled-uber”. I’ve pasted this Slugify function in a public Gist here.
Added several more special characters.
Added special characters suggested by ahmet to support the Turkish language.