Skip to content

Instantly share code, notes, and snippets.

@thewinterwind
Created October 23, 2013 01:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thewinterwind/7110879 to your computer and use it in GitHub Desktop.
Save thewinterwind/7110879 to your computer and use it in GitHub Desktop.
Grab a URL segment and return it as a lowercase string, or with first character capitalized.
/**
* Return the first url segment and capitalize if necessary
* @param {Boolean} flag if capitalization is needed or not
* @return {String} formatted URL segment
*/
function get_label(capitalize) {
var first_segment = window.location.pathname.split('/')[1];
if (capitalize) {
return first_segment.toLowerCase().charAt(0).toUpperCase() + first_segment.slice(1);
}
return first_segment.toLowerCase();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment