is_ static method

bool is_(
  1. dynamic pattern,
  2. String value
)

Determines if value matches the given pattern. Asterisks are wildcards.

Str.is_('foo.*', 'foo.bar'); // true
Str.is_(['admin/*', 'user/*'], 'admin/profile'); // true

Implementation

// ignore: non_constant_identifier_names
static bool is_(dynamic pattern, String value) {
  final patterns = pattern is List ? pattern : [pattern];
  for (final p in patterns) {
    final s = p.toString();
    if (s == value) return true;
    final escaped = RegExp.escape(s).replaceAll(r'\*', '.*');
    if (RegExp('^$escaped\$').hasMatch(value)) return true;
  }
  return false;
}