Skip to content

Instantly share code, notes, and snippets.

@jacoborus
Forked from bentruyman/slug.js
Created April 11, 2012 03:19
Show Gist options
  • Save jacoborus/2356638 to your computer and use it in GitHub Desktop.
Save jacoborus/2356638 to your computer and use it in GitHub Desktop.
JS. Slug Generator - muy simple
// Generates a URL-friendly "slug" from a provided string.
// For example: "This Is Great!!!" transforms into "this-is-great"
function generateSlug (value) {
// 1) convert to lowercase
// 2) remove dashes and pluses
// 3) replace spaces with dashes
// 4) remove everything but alphanumeric characters and dashes
return value.toLowerCase().replace(/-+/g, '').replace(/\s+/g, '-').replace(/[^a-z0-9-]/g, '');
};
@yaadspace
Copy link

I added a feature to it to remove the %20 from a string - most times a url will fork

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment