Skip to content

Instantly share code, notes, and snippets.

@celsopalmeiraneto
Created July 30, 2018 16:19
Show Gist options
  • Save celsopalmeiraneto/ba5e10f3ae18f11c2f18db8cd32df568 to your computer and use it in GitHub Desktop.
Save celsopalmeiraneto/ba5e10f3ae18f11c2f18db8cd32df568 to your computer and use it in GitHub Desktop.
function convertCamelCaseToSnakeCase(text) {
const inputLines = text.split('\n');
const outputLines = inputLines.map((line) => {
return Array.from(line).reduce((acc, v, i) => {
if (i == 0) {
acc += v.toLocaleLowerCase();
return acc;
}
if (v.toLocaleUpperCase() == v) {
acc += '_';
}
acc += v.toLocaleLowerCase();
return acc;
}, '');
});
return outputLines.join('\n');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment