toSnakeCase method
Convert string to snake case.
Implementation
String toSnakeCase() {
if (this == null) {
throw ArgumentError('string: $this');
}
return this!.splitMapJoin(RegExp(r'[_\s]+'),
onMatch: (match) => match.group(0)!.toLowerCase(),
onNonMatch: (nonMatch) =>
nonMatch[0].toLowerCase() +
nonMatch.substring(1).replaceAllMapped(RegExp(r'[A-Z]'),
(match) => '_${match.group(0)!.toLowerCase()}'));
}