pathExists method

bool pathExists(
  1. String url,
  2. RegExp pathPattern, {
  3. Map<String, String?>? queryParams,
})

Checks if the given url matches with the given filters. url must conform to uri parsing.

Implementation

bool pathExists(
  String url,
  RegExp pathPattern, {
  Map<String, String?>? queryParams,
}) {
  if (!pathPattern.hasMatch(url)) return false;

  var hasMatch = true;

  final uri = Uri.parse(url);
  if (queryParams != null) {
    for (final entry in queryParams.entries) {
      hasMatch &= uri.queryParameters.containsKey(entry.key);
      if (entry.value != null) {
        hasMatch &= uri.queryParameters[entry.key] == entry.value;
      }
      if (!hasMatch) break;
    }
  }

  return hasMatch;
}