snake static method

String snake(
  1. String text
)

Converts a string to snake_case.

Implementation

static String snake(String text) {
  if (text.isEmpty) return '';
  return text
      .replaceAllMapped(
        RegExp(r'([a-z0-9])([A-Z])'),
        (Match m) => '${m[1]}_${m[2]}',
      )
      .toLowerCase()
      .replaceAll('-', '_');
}