toSnakeCase static method
Implementation
static String toSnakeCase(String input) {
if (input.isEmpty) return input;
final withUnderscores = input
.replaceAll(' ', '_')
.replaceAll('-', '_')
.replaceAllMapped(
RegExp(r'([a-z0-9])([A-Z])'),
(m) => '${m[1]}_${m[2]}',
)
.replaceAllMapped(
RegExp(r'([A-Z]+)([A-Z][a-z])'),
(m) => '${m[1]}_${m[2]}',
);
return withUnderscores.toLowerCase();
}