Created
November 15, 2023 21:50
-
-
Save toky-nomena/0193482367d9fde7a085c413f63c23d0 to your computer and use it in GitHub Desktop.
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
function transformToSnakeCase(input: string): string { | |
return input | |
.replace(/([a-z])([A-Z])/g, '$1_$2') // Insert underscore between lowercase and uppercase letters | |
.replace(/([0-9]+)([a-zA-Z])/g, '$1_$2') // Insert underscore between digits and letters | |
.replace(/([a-zA-Z])([0-9]+)/g, '$1_$2') // Insert underscore between letters and digits | |
.toUpperCase(); // Convert the result to uppercase | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment