Created
August 20, 2012 21:40
-
-
Save postpostmodern/3408148 to your computer and use it in GitHub Desktop.
Cleans up a string for suitability as a css id or class
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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