Created
January 2, 2012 10:48
-
-
Save jakebellacera/1550263 to your computer and use it in GitHub Desktop.
Parameterizes a string
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
| function parameterize(value) { | |
| // A simple function that parameterizes a string. | |
| // Example: "This is a title" == "this-is-a-title" | |
| if (typeof value === 'string' || value) { | |
| var output = value.replace(/[^a-zA-Z0-9\s]/g,""); | |
| output = output.toLowerCase(); | |
| return output.replace(/\s/g,'-'); | |
| } else { | |
| return false; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment