glob-parent
Extract the non-magic parent path from a glob — foo/bar/*.js → foo/bar,
path/**/x → path. The directory a file watcher should actually watch. A faithful
Rust port of the glob-parent npm
package (used by gulp, chokidar, and many others), bundling ports of is-glob and
is-extglob. Zero dependencies and #![no_std].
use glob_parent;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
assert_eq!;
Why glob-parent?
To watch the files a glob matches, you first need the deepest real directory it lives under — everything before the first wildcard, brace set, bracket class, or extglob. Getting that right means understanding glob syntax (including escapes and enclosures that span path separators), which is exactly what the canonical JS module does. This ports it faithfully.
[]
= "0.1"
API
| Item | Purpose |
|---|---|
glob_parent(glob) |
The non-magic parent path |
glob_parent_with_options(glob, flip_backslashes) |
Control the Windows backslash flip |
is_glob(s) |
Whether s looks like a glob (the is-glob strict check) |
is_extglob(s) |
Whether s contains an extglob (@(…), !(…), …) |
Behavior
- Returns the path up to (but not including) the first segment containing glob
magic; a pattern with no parent yields
".". - Understands
*,?,**, brace sets{a,b}, bracket classes[a-z], extglobs@(…)/!(…)/+(…)/?(…)/*(…), and backslash escapes. - A trailing path separator is preserved as a directory.
- On Windows, backslashes are flipped to forward slashes (when the input has no
forward slash); elsewhere backslashes are escapes. Control this with
glob_parent_with_options.
License
Licensed under either of Apache-2.0 or MIT at your option.