Skip to content

Instantly share code, notes, and snippets.

@lerouxb
Created May 2, 2014 09:23
Show Gist options
  • Select an option

  • Save lerouxb/97d678a5a9de16149844 to your computer and use it in GitHub Desktop.

Select an option

Save lerouxb/97d678a5a9de16149844 to your computer and use it in GitHub Desktop.
Turn names/titles/whatever into url/filename-friendly bits.
slugify = (title) ->
title
.toLowerCase()
.replace(/\ /g, '-') # spaces to dashes
.replace(/[^\w-]+/g, '') # remove anything that's not ascii A-Za-z0-9
.replace(/[-]+/g, '-') # remove consecutive dashes
@lerouxb

lerouxb commented May 2, 2014

Copy link
Copy Markdown
Author

Python has unicodedata.normalize() which is really handy for converting accented characters into ascii characters which is arguably better than just stripping them. Could be nice to try and do that for JavaScript too.

https://docs.python.org/2/library/unicodedata.html

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