toKebabCase property
String
get
toKebabCase
Converts a string to kebab-case.
Example: 'Hello World' becomes 'hello-world'
Implementation
String get toKebabCase {
if (isEmpty) return '';
final result = RegExp(r'(?<=[a-z])[A-Z]').allMatches(this).fold(this,
(String result, Match m) {
return result.replaceRange(m.start, m.end, '-${m.group(0)}');
});
return result.toLowerCase().replaceAll(RegExp(r'[\s_]+'), '-');
}