Created
December 4, 2014 18:40
-
-
Save alanthai/ec8edb4cf638181ff407 to your computer and use it in GitHub Desktop.
Change snake to camel, camel to snake, uppercase and lowercase functions
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
function snakeToCamel(str) { | |
return str.replace(/(\_[a-z])/g, function(char){return char[1].toUpperCase();}); | |
} | |
function camelToSnake(str) { | |
return str.replace(/([A-Z])/g, function(char){return "_" + char.toLowerCase();}); | |
} | |
function upperCaseFirst(str) { | |
return str[0].toUpperCase() + str.slice(1); | |
} | |
function lowerCaseFirst(str) { | |
return str[0].toLowerCase() + str.slice(1); | |
} | |
function changeCase(str) { | |
return str.replace(/[A-Za-z]/g, function(char) { | |
var upper = char.toUpperCase(); | |
return upper === char ? upper : char.toLowerCase(); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment