toSlug static method

String toSlug(
  1. String text
)

Convert string to slug

text - The text to convert Returns URL-friendly slug

Implementation

static String toSlug(String text) {
  return text
      .toLowerCase()
      .replaceAll(RegExp(r'[^\w\s-]'), '')
      .replaceAll(RegExp(r'[\s_-]+'), '-')
      .replaceAll(RegExp(r'^-+|-+$'), '');
}