Last active
August 29, 2015 14:19
-
-
Save mrofi/e1271c963e97461ca542 to your computer and use it in GitHub Desktop.
case in string
This file contains hidden or 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
// convert space to undersocre (snake case) | |
string.toLowerCase().split(' ').join('_'); | |
// convert underscore to space | |
string.split('_').join(' '); | |
// camelize | |
function camelize(str) { | |
return str.replace(/(?:^\w|[A-Z]|\b\w|\s+)/g, function(match, index) { | |
if (+match === 0) return ""; // or if (/\s+/.test(match)) for white spaces | |
return index == 0 ? match.toLowerCase() : match.toUpperCase(); | |
}); | |
} | |
// credits : http://stackoverflow.com/questions/2970525/converting-any-string-into-camel-case | |
// Capitalize | |
String.prototype.capitalize = function() { | |
return this.charAt(0).toUpperCase() + this.slice(1); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment