toSnakeCaseSafe static method

String toSnakeCaseSafe(
  1. String input
)

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;
}