Last active
February 1, 2016 03:08
-
-
Save TravisMullen/c37b774582db3b7b1711 to your computer and use it in GitHub Desktop.
build key from name to be used for indexing or clean URLs
This file contains 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 buildKey(name) { | |
var key = ''; | |
if (name !== undefined) { | |
key = name; | |
key = key.replace(/ /g, '-'); // purge spaces | |
key = key.replace(/&/g, 'and'); // clean ampersand | |
key = key.replace(/[^a-zA-Z0-9-]/g, ''); // remove all non-alphas and non-number and non-dashes | |
key = key.toLowerCase(); | |
} | |
return key; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment