underscore method

String underscore()

Converts a camelized string into all lower case separated by underscores.

Implementation

String underscore() {
  if (this == null) {
    throw ArgumentError('string: $this');
  }
  if (this!.isEmpty) {
    return '';
  }
  return this!
      .replaceAllMapped(RegExp(r'([A-Z])'), (match) => '_${match[1]}')
      .toLowerCase();
}