Created
February 19, 2019 16:24
-
-
Save cmjaimet/38d7aca612a63eaca812888c0161ddf6 to your computer and use it in GitHub Desktop.
zebqNv
This file contains hidden or 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
<h2>Convert camel case to snake case</h2> | |
<p>Enter a camel case string.</p> | |
<form> | |
<input type="text" id="camel" value="camelCaseWord" /> | |
<button id="butn" type="button">Go!</button> | |
</form> | |
<div id="output"></div> |
This file contains hidden or 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.getElementById('butn').addEventListener( 'click', function() { | |
let camel = document.getElementById( 'camel' ).value.trim(); | |
let output = camel.replace( /\s/g, '' ); | |
output = output.replace( /.[A-Z]/g, function( x ) { | |
return x[0]+"_"+x[1].toLowerCase(); | |
} ); | |
output = output.toLowerCase(); | |
document.getElementById( 'output' ).innerHTML = output; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment