Last active
August 16, 2016 16:47
-
-
Save xeaone/fb0213c43e1811d28bfaf116c56baea3 to your computer and use it in GitHub Desktop.
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
function toCamelCase (string) { | |
var nextIndex = string.search('-') + 1; | |
var nextLetter = string.charAt(nextIndex).toString(); | |
var r = '-' + nextLetter; | |
var n = nextLetter.toUpperCase(); | |
return string.replace(r, n); | |
} | |
function fromCamelCase (string) { | |
var firstChar = string.charAt(0).toString(); | |
string = string.replace(firstChar, firstChar.toLowerCase()); | |
// replace upper case with hypeh and lower cased char | |
for (var i = 0; i < string.length; i++) { | |
var char = string[i]; | |
if (isUpperCase(char)) string = string.replace(char, '-' + char.toLowerCase()) ; | |
} | |
return string; | |
} | |
function isUpperCase (char) { | |
return (char >= 'A') && (char <= 'Z'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment