Created
October 23, 2013 01:11
-
-
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.
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
/** | |
* 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