Created
February 19, 2020 07:12
-
-
Save zz85/7a726c8b635f531238692ef5423464a8 to your computer and use it in GitHub Desktop.
Snake to Camel Case
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
m = /\s+(([A-Z0-9]+_)*([A-Z0-9]+))\s+/g | |
locations = []; | |
while (match = m.exec(x)) { | |
console.log(match) | |
str = match[1].split('_') | |
.map(s => s[0].toUpperCase() + s.substring(1).toLowerCase()) | |
.join('') | |
locations.push({ | |
o: match[0], p: match[1], | |
str, index: match.index, | |
}); | |
} | |
while (l = locations.pop()) { | |
x = x.substring(0, l.index) + | |
l.o.replace(l.p, l.str) + | |
x.substring(l.index + l.o.length) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment