@@ -97,6 +97,43 @@ const timeSortedFiles = results
9797const groupReadableFiles = results
9898 .filter (path => path .mode & 0o040 )
9999 .map (path => path .fullpath ())
100+
101+ // custom ignores can be done like this, for example by saying
102+ // you'll ignore all markdown files, and all folders named 'docs'
103+ const customIgnoreResults = await glob (' **' , {
104+ ignore: {
105+ ignored : (p ) => / \. md$ / .test (p .name ),
106+ childrenIgnored : (p ) => p .isNamed (' docs' ),
107+ },
108+ })
109+
110+ // another fun use case, only return files with the same name as
111+ // their parent folder, plus either `.ts` or `.js`
112+ const folderNamedModules = await glob (' **/*.{ts,js}' , {
113+ ignore: {
114+ ignored : (p ) => {
115+ const pp = p .parent
116+ return ! (p .isNamed (pp .name + ' .ts' ) || p .isNamed (pp .name + ' .js' ))
117+ }
118+ }
119+ })
120+
121+ // find all files edited in the last hour
122+ const newFiles = await glob (' **' , {
123+ // need stat so we have mtime
124+ stat: true ,
125+ // only want the files, not the dirs
126+ nodir: true ,
127+ ignore: {
128+ ignored : (p ) => {
129+ return (new Date () - p .mtime ) <= (60 * 60 * 1000 )
130+ },
131+ // could add similar childrenIgnored here as well, but
132+ // directory mtime is inconsistent across platforms, so
133+ // probably better not to, unless you know the system
134+ // tracks this reliably.
135+ }
136+ })
100137```
101138
102139** Note** Glob patterns should always use ` / ` as a path separator,
@@ -342,14 +379,22 @@ share the previously loaded cache.
342379 as modified time, permissions, and so on. Note that this will
343380 incur a performance cost due to the added system calls.
344381
345- - ` ignore ` string or string[ ] . A glob pattern or array of glob
346- patterns to exclude from matches. To ignore all children within
347- a directory, as well as the entry itself, append ` /**' ` to the
348- ignore pattern.
382+ - ` ignore ` string or string[ ] , or an object with ` ignore ` and
383+ ` ignoreChildren ` methods.
384+
385+ If a string or string[ ] is provided, then this is treated as a
386+ glob pattern or array of glob patterns to exclude from matches.
387+ To ignore all children within a directory, as well as the entry
388+ itself, append ` '/**' ` to the ignore pattern.
349389
350390 ** Note** ` ignore ` patterns are _ always_ in ` dot:true ` mode,
351391 regardless of any other settings.
352392
393+ If an object is provided that has ` ignored(path) ` and/or
394+ ` childrenIgnored(path) ` methods, then these methods will be
395+ called to determine whether any Path is a match or if its
396+ children should be traversed, respectively.
397+
353398- ` follow ` Follow symlinked directories when expanding ` ** `
354399 patterns. This can result in a lot of duplicate references in
355400 the presence of cyclic links, and make performance quite bad.
0 commit comments