toKebabCase method

String toKebabCase()

Convert string to kebab case.

Implementation

String toKebabCase() {
  if (this == null) {
    throw ArgumentError('string: $this');
  }
  return this!.splitMapJoin(RegExp(r'[_\s]+'),
      onMatch: (match) => match.group(0)!.toLowerCase(),
      onNonMatch: (nonMatch) =>
          nonMatch[0].toLowerCase() +
          nonMatch.substring(1).replaceAllMapped(RegExp(r'[A-Z]'),
              (match) => '-${match.group(0)!.toLowerCase()}'));
}