toKebabCase method

  1. @useResult
String toKebabCase([
  1. Pattern? separators
])

Kebab-cases this string.

wordSeparators is used to separate words if separators is not given.

'camelCase'.toKebabCase(); // 'camel-case'

'PascalCase'.toKebabCase(); // 'pascal-case'

'SCREAMING_CASE'.toKebabCase(); // 'screaming-case'

'snake_case'.toKebabCase(); // 'snake-case'

'kebab-case'.toKebabCase(); // 'kebab-case'

'Title Case'.toKebabCase(); // 'title-case'

'Sentence case'.toKebabCase(); // 'sentence-case'

Implementation

@useResult String toKebabCase([Pattern? separators]) => split(separators ?? wordSeparators)
  .where((e) => e.isNotEmpty)
  .join('-')
  .toLowerCase();