Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 31 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ The most correct and second fastest glob implementation in
JavaScript. (See **Comparison to Other JavaScript Glob
Implementations** at the bottom of this readme.)

![a fun cartoon logo made of glob characters](https://github.com/isaacs/node-glob/raw/main/logo/glob.png)
![a fun cartoon logo made of glob
characters](https://github.com/isaacs/node-glob/raw/main/logo/glob.png)

## Usage

Expand Down Expand Up @@ -69,8 +70,9 @@ for (const file of g2) {
}

// you can also pass withFileTypes: true to get Path objects
// these are like a Dirent, but with some more added powers
// check out http://npm.im/path-scurry for more info on their API
// these are like a fs.Dirent, but with some more added powers
// check out https://isaacs.github.io/path-scurry/classes/PathBase.html
// for more info on their API
const g3 = new Glob('**/baz/**', { withFileTypes: true })
g3.stream().on('data', path => {
console.log(
Expand All @@ -88,9 +90,8 @@ g3.stream().on('data', path => {
// For example:
const results = await glob('**', { stat: true, withFileTypes: true })

const timeSortedFiles = results
.sort((a, b) => a.mtimeMs - b.mtimeMs)
.map(path => path.fullpath())
const timeSortedFiles = results .sort((a, b) => a.mtimeMs -
b.mtimeMs) .map(path => path.fullpath())

const groupReadableFiles = results
.filter(path => path.mode & 0o040)
Expand Down Expand Up @@ -534,6 +535,16 @@ share the previously loaded cache.
called to determine whether any Path is a match or if its
children should be traversed, respectively.

The `path` argument to the methods will be a
[`path-scurry`](https://isaacs.github.io/path-scurry/index.html)
[`Path`](https://isaacs.github.io/path-scurry/classes/PathBase)
object, which extends
[`fs.Dirent`](https://nodejs.org/docs/latest/api/fs.html#class-fsdirent)
with additional useful methods like
[`.fullpath()`](https://isaacs.github.io/path-scurry/classes/PathBase.html#fullpath),
[`.relative()`](https://isaacs.github.io/path-scurry/classes/PathBase.html#relative),
and more.

- `follow` Follow symlinked directories when expanding `**`
patterns. This can result in a lot of duplicate references in
the presence of cyclic links, and make performance quite bad.
Expand Down Expand Up @@ -574,24 +585,27 @@ share the previously loaded cache.
available, or `'linux'` if not. Setting `platform:'win32'` on
non-Windows systems may cause strange behavior.

- `withFileTypes` Return [PathScurry](http://npm.im/path-scurry)
`Path` objects instead of strings. These are similar to a
NodeJS `Dirent` object, but with additional methods and
properties.
- `withFileTypes` Return
[`path-scurry`](http://npm.im/path-scurry)
[`Path`](https://isaacs.github.io/path-scurry/classes/PathBase.html)
objects instead of strings. These are similar to a NodeJS
`fs.Dirent` object, but with additional methods and properties.

`withFileTypes` may not be used along with `absolute`.

- `signal` An AbortSignal which will cancel the Glob walk when
triggered.

- `fs` An override object to pass in custom filesystem methods.
See [PathScurry docs](http://npm.im/path-scurry) for what can
be overridden.

- `scurry` A [PathScurry](http://npm.im/path-scurry) object used
to traverse the file system. If the `nocase` option is set
explicitly, then any provided `scurry` object must match this
setting.
See [`path-scurry`
docs](https://isaacs.github.io/path-scurry/interfaces/FSOption.html)
for what can be overridden.

- `scurry` A
[`PathScurry`](https://isaacs.github.io/path-scurry/classes/PathScurryBase.html)
object used to traverse the file system. If the `nocase` option
is set explicitly, then any provided `scurry` object must match
this setting.

- `includeChildMatches` boolean, default `true`. Do not match any
children of any matches. For example, the pattern `**\/foo`
Expand Down
Loading