toKebabCase method

String toKebabCase()

Converts a string to kebab-case.

'helloWorld'.toKebabCase() // 'hello-world'

Implementation

String toKebabCase() {
  if (isEmpty) return '';
  return replaceAllMapped(
    RegExp(r'(?<=[a-z0-9])([A-Z])'),
    (m) => '-${m[1]}',
  ).replaceAll(RegExp(r'[\s_]+'), '-').toLowerCase();
}