Skip to content

Instantly share code, notes, and snippets.

@TravisMullen
Last active February 1, 2016 03:08
Show Gist options
  • Save TravisMullen/c37b774582db3b7b1711 to your computer and use it in GitHub Desktop.
Save TravisMullen/c37b774582db3b7b1711 to your computer and use it in GitHub Desktop.
build key from name to be used for indexing or clean URLs
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