Last active
January 30, 2020 06:29
-
-
Save NicmeisteR/520e5a13eebf46ca85fd99f2baee42d4 to your computer and use it in GitHub Desktop.
Helper Functions
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
/** | |
* 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