@@ -14,20 +14,20 @@ import 'package:path/path.dart' as p;
14
14
15
15
// ░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░░
16
16
17
- /// Returns the base name of a given file path.
17
+ /// Returns the base name of a given file [ path] .
18
18
String getBaseName (String path) {
19
19
final localSystemFilePath = toLocalSystemPathFormat (path);
20
20
return p.basename (localSystemFilePath);
21
21
}
22
22
23
- /// Returns the directory path of a given file path.
23
+ /// Returns the directory path of a given file [ path] .
24
24
String getDirPath (String path) {
25
25
final localSystemFilePath = toLocalSystemPathFormat (path);
26
26
return p.dirname (localSystemFilePath);
27
27
}
28
28
29
- /// Checks if the provided path contains any of the specified components. This
30
- /// operation is case-insensitive.
29
+ /// Checks if the provided [ path] contains any of the specified [ components] .
30
+ /// This operation is case-insensitive.
31
31
bool pathContainsComponent (String path, Set <String > components) {
32
32
final localSystemFilePath = toLocalSystemPathFormat (path);
33
33
final a = p.split (localSystemFilePath).map ((e) => e.toLowerCase ());
@@ -39,7 +39,7 @@ bool pathContainsComponent(String path, Set<String> components) {
39
39
return false ;
40
40
}
41
41
42
- /// Checks if the provided path matches any of the specified path patterns .
42
+ /// Checks if the provided [ path] matches any of the specified [pathPatterns] .
43
43
bool matchesAnyPathPattern (String path, Set <String > pathPatterns) {
44
44
if (pathPatterns.isNotEmpty) {
45
45
final localSystemFilePath = toLocalSystemPathFormat (path);
@@ -51,48 +51,68 @@ bool matchesAnyPathPattern(String path, Set<String> pathPatterns) {
51
51
return true ;
52
52
}
53
53
54
- /// Converts the given path to a consistent, local path format.
54
+ /// Checks if the provided [filePath] matches any of the specified [extensions] .
55
+ ///
56
+ /// Notes:
57
+ ///
58
+ /// - If the [extensions] set is empty, the function will return true.
59
+ /// - Specify [caseSensitive] as false to ignore case.
60
+ bool matchesAnyExtension (
61
+ String filePath,
62
+ Set <String > extensions, {
63
+ bool caseSensitive = true ,
64
+ }) {
65
+ if (extensions.isEmpty) return true ;
66
+ final extension = p.extension (filePath);
67
+ return extensions.any ((e) {
68
+ final a = caseSensitive ? extension : extension .toLowerCase ();
69
+ final b = caseSensitive ? e : e.toLowerCase ();
70
+ return a == b;
71
+ });
72
+ }
73
+
74
+ /// Converts the given [filePath] to a consistent, local path format.
55
75
String getFileNameWithoutExtension (String filePath) {
56
76
final localSystemFilePath = toLocalSystemPathFormat (filePath);
57
77
return p.basenameWithoutExtension (localSystemFilePath);
58
78
}
59
79
60
- /// Replaces all forward slashes with the local path separator.
80
+ /// Replaces all forward slashes in [path] with the local path separator.
61
81
String toLocalSystemPathFormat (String path) {
62
82
return path.split (RegExp (r'[\\/]' )).join (p.separator);
63
83
}
64
84
65
- /// Replaces all backslashes with forward slashes.
85
+ /// Replaces all backslashes in [path] with forward slashes.
66
86
String toUnixSystemPathFormat (String path) {
67
87
return path.split (RegExp (r'[\\/]' )).join ('/' );
68
88
}
69
89
70
- /// Replaces all forward slashes with backslashes.
90
+ /// Replaces all forward slashes in [path] with backslashes.
71
91
String toWindowsSystemPathFormat (String path) {
72
92
return path.split (RegExp (r'[\\/]' )).join ('\\ ' );
73
93
}
74
94
75
- /// Checks if the provided file is a private Dart file (starts with an
95
+ /// Checks if the provided [filePath] is a private file (starts with an
76
96
/// underscore).
77
97
bool isPrivateFileName (String filePath) {
78
98
final fileName = getBaseName (filePath);
79
99
return fileName.startsWith ('_' );
80
100
}
81
101
82
- /// Checks if the file name matches the specified beginning and ending types.
102
+ /// Checks if the file name extracted from [filePath] matches the specified
103
+ /// beginning type [begType] and ending type [endType] .
104
+ ///
83
105
/// Returns a tuple with the match status and the file name.
84
- (bool , String ) isMatchingFileName (
106
+ ({ bool status , String fileName} ) isMatchingFileName (
85
107
String filePath,
86
108
String begType,
87
109
String endType,
88
110
) {
89
111
final fileName = getBaseName (filePath);
90
- final a =
91
- begType.isEmpty ? true : fileName.startsWith ('${begType .toLowerCase ()}_' );
92
- final b =
93
- endType.isEmpty ? true : fileName.endsWith ('.$endType ' .toLowerCase ());
112
+ final a = begType.isEmpty ? true : fileName.startsWith ('${begType .toLowerCase ()}_' );
113
+ final b = endType.isEmpty ? true : fileName.endsWith ('.$endType ' .toLowerCase ());
94
114
final c = a && b;
95
- return (c, fileName);
115
+ return (status : c, fileName : fileName);
96
116
}
97
117
98
118
/// Combines multiple [pathSets] into a single set, returning all possible
0 commit comments