Skip to content

Instantly share code, notes, and snippets.

@postpostmodern
Created August 20, 2012 21:40
Show Gist options
  • Save postpostmodern/3408148 to your computer and use it in GitHub Desktop.
Save postpostmodern/3408148 to your computer and use it in GitHub Desktop.
Cleans up a string for suitability as a css id or class
sanitizeForDomID = (str) ->
chars =
"ä": "ae"
"ö": "oe"
"ß": "ss"
"ü": "ue"
"æ": "ae"
"ø": "oe"
"å": "aa"
"é": "e"
"è": "e"
str = $.trim(str).toLowerCase()
for char, replacement of chars
str = str.replace char, replacement
str = str.replace /[^0-9a-z-_]/g, '-'
str = str.replace /-+/g, '-'
str = str.replace /-$/, ''
str
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment