Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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