Skip to content

Instantly share code, notes, and snippets.

@NicmeisteR
Last active January 30, 2020 06:29
Show Gist options
  • Save NicmeisteR/520e5a13eebf46ca85fd99f2baee42d4 to your computer and use it in GitHub Desktop.
Save NicmeisteR/520e5a13eebf46ca85fd99f2baee42d4 to your computer and use it in GitHub Desktop.
Helper Functions
/**
* This returns proper names by removing dashes.
*
* @param {string} name
* @returns string
*/
export function fixName(name) {
if (name.includes("-")) {
return name.split('-').join(' ');
}
else if (name.includes("_")) {
return name.split('_').join(' ');
}
else {
return titleCase(name);
}
}
/**
* This returns the string in title case.
*
* @param {string} string
* @returns string
*/
export function titleCase(string) {
let sentence = string.toLowerCase().split(" ");
for(let i = 0; i< sentence.length; i++){
sentence[i] = sentence[i][0].toUpperCase() + sentence[i].slice(1);
}
return sentence.join(" ");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment