toSnakeCase static method

String toSnakeCase(
  1. String camelCase
)

Converts camelCase to UPPER_SNAKE_CASE. e.g. baseUrl -> BASE_URL, debugMode -> DEBUG_MODE

Implementation

static String toSnakeCase(String camelCase) {
  return camelCase
      .replaceAllMapped(RegExp(r'([A-Z])'), (m) => '_${m.group(0)}')
      .toUpperCase()
      .replaceAll(RegExp(r'^_'), '');
}