toSnakeCaseSafe static method
Safely converts any input to snake_case.
Handles spaces, hyphens, and mixed case by converting everything to lowercase and replacing spaces/hyphens with underscores.
Implementation
static String toSnakeCaseSafe(String input) {
// handle input that may already be snake_case or mixed
final lower =
input.trim().toLowerCase().replaceAll(' ', '_').replaceAll('-', '_');
return lower;
}