Created
January 16, 2021 19:04
-
-
Save steveshead/a18cfcdab090214d34686f62bc55f35f to your computer and use it in GitHub Desktop.
[Javascript - convert and append] - using a textarea and button, convert underscore_case to camelCase, pad and append
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
document.body.append(document.createElement('textarea')); | |
document.body.append(document.createElement('button')); | |
document.querySelector('button').addEventListener('click', function () { | |
const text = document.querySelector('textarea').value; | |
const rows = text.split('\n'); | |
for (const [i, row] of rows.entries()) { | |
const [first, second] = row.toLowerCase().trim().split('_'); | |
const output = `${first}${second.replace(second[0], second[0].toUpperCase())}`; | |
console.log(`${output.padEnd(20)}${'✅'.repeat(i + 1)}`); | |
} | |
}); | |
/* Test Data | |
underscore_case | |
first_name | |
Some_Variable | |
calculate_AGE | |
delayed_departure | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment