Created
May 5, 2022 17:27
-
-
Save mranawake/8cd0ae4de678809ae62becae6f8fbb6b to your computer and use it in GitHub Desktop.
Snake case function to use as an app script extension on your Google Sheets.
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
/** | |
* Save this as an app script function on yout Google Sheets and start using it. | |
* Usage: =SNAKE_CASE(A1) | |
*/ | |
function SNAKE_CASE(str) { | |
return str | |
.match(/[A-Z]{2,}(?=[A-Z][a-z0-9]*|\b)|[A-Z]?[a-z0-9]*|[A-Z]|[0-9]+/g) | |
.filter(Boolean) | |
.map(x => x.toLowerCase()) | |
.join("_"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment