matchesAnyExtension function

bool matchesAnyExtension(
  1. String filePath,
  2. Set<String> extensions, {
  3. bool caseSensitive = true,
})

Checks if the provided filePath matches any of the specified extensions.

Notes:

  • If the extensions set is empty, the function will return true.
  • Specify caseSensitive as false to ignore case.

Implementation

bool matchesAnyExtension(
  String filePath,
  Set<String> extensions, {
  bool caseSensitive = true,
}) {
  if (extensions.isEmpty) return true;
  final extension = p.extension(filePath);
  return extensions.any((e) {
    final a = caseSensitive ? extension : extension.toLowerCase();
    final b = caseSensitive ? e : e.toLowerCase();
    return a == b;
  });
}