convertToKebabCase function

String convertToKebabCase(
  1. String camelCase
)

Convert a camelCase string to kebab-case.

This is used to convert camelCase Dart identifiers to kebab-case Discord Slash Command argument names.

You might also be interested in:

  • Name, for setting a custom name to use for slash command argument names.

Implementation

String convertToKebabCase(String camelCase) {
  Iterable<String> split = camelCase.split('');
  String res = '';

  for (final char in split) {
    if (char != char.toLowerCase() && res.isNotEmpty) {
      res += '-';
    }
    res += char.toLowerCase();
  }

  return res;
}