Skip to content

Instantly share code, notes, and snippets.

@loickreitmann
Created April 14, 2011 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save loickreitmann/920801 to your computer and use it in GitHub Desktop.
Save loickreitmann/920801 to your computer and use it in GitHub Desktop.
Converts a string to dashed.
/**
* toDashed: converts string to dashed
*/
String.prototype.toDashed = function () {
return this.replace(/^\s+|\s+$/g, "")
.toLowerCase()
.replace(/-/g, '')
.replace(/(\s[a-z0-9])/g, function ($1) {
return $1.replace(/\s/, '-');
})
.replace(/[^a-z0-9-]/g, '');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment