Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@zz85
Created February 19, 2020 07:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zz85/7a726c8b635f531238692ef5423464a8 to your computer and use it in GitHub Desktop.
Save zz85/7a726c8b635f531238692ef5423464a8 to your computer and use it in GitHub Desktop.
Snake to Camel Case
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