utils/path/path_utils library
Path manipulation utilities ported from Neomage TypeScript.
Provides path normalization, glob matching, gitignore parsing, prefix-based trie lookup, and file system watching primitives.
Classes
- FileEvent
- A file system event emitted by FileWatcher.
- FileWatcher
- Watches a file or directory for changes, emitting FileEvents.
- GitignoreParser
-
Parses
.gitignore-style patterns and determines whether paths are ignored. - GlobMatcher
- Compiles shell-style glob patterns to RegExp and matches paths.
-
PathTrie<
T> - Efficient prefix-based path lookup using a trie structure.
- WatcherConfig
- Configuration for FileWatcher.
Enums
- FileEventType
- The type of file system change observed.
Functions
-
changeExtension(
String path, String newExt) → String -
Returns
pathwith its extension changed tonewExt. -
expandHome(
String path) → String -
Expands a leading
~to the current user's home directory. -
findCommonAncestor(
List< String> paths) → String -
Finds the longest common ancestor directory of the given
paths. -
fromUri(
Uri uri) → String -
Converts a
file://uriback to a platform path string. -
getExtension(
String path) → String -
Returns the file extension of
pathincluding the dot, or empty string. -
isAbsolute(
String path) → bool -
Returns
trueifpathis an absolute path. -
isHidden(
String path) → bool -
Returns
truewhen the final component ofpathstarts with.. -
isSubPath(
String parent, String child) → bool -
Returns
trueifchildis a sub-path ofparent. -
joinPaths(
List< String> parts) → String -
Joins path
partswith the platform separator, normalizing the result. -
normalizePath(
String path) → String -
Normalizes a file-system path by collapsing separators, resolving
.and..segments, and converting backslashes to forward slashes. -
relativePath(
String from, String to) → String -
Computes the relative path from
fromtoto. -
sanitizePath(
String path) → String -
Removes dangerous characters from
paththat could cause security issues. -
splitPath(
String path) → ({String basename, String dir, String ext}) -
Splits
pathinto(directory, basename, extension). -
toUri(
String path) → Uri -
Converts a file-system
pathto afile://Uri.