Skip to content

Instantly share code, notes, and snippets.

@toky-nomena
Created November 15, 2023 21:50
Show Gist options
  • Save toky-nomena/0193482367d9fde7a085c413f63c23d0 to your computer and use it in GitHub Desktop.
Save toky-nomena/0193482367d9fde7a085c413f63c23d0 to your computer and use it in GitHub Desktop.
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