toSlug method

String toSlug()

Converts the string to a slug (URL-friendly format).

Example:

'Hello World!'.toSlug(); // 'hello-world'

Implementation

String toSlug() {
  return toLowerCase()
      .replaceAll(RegExp(r'[^\w\s-]'), '')
      .replaceAll(RegExp(r'[-\s]+'), '-')
      .trim();
}