33Match files using the patterns the shell uses.
44
55The most correct and second fastest glob implementation in
6- JavaScript. (See ** Comparison to Other JavaScript Glob
7- Implementations** at the bottom of this readme.)
6+ JavaScript. (See [ ** Comparison to Other JavaScript Glob
7+ Implementations** ] ( #comparisons-to-other-fnmatchglob-implementations )
8+ at the bottom of this readme.)
89
910![ a fun cartoon logo made of glob
1011characters] ( https://github.com/isaacs/node-glob/raw/main/logo/glob.png )
@@ -17,8 +18,9 @@ Install with npm
1718npm i glob
1819```
1920
20- ** Note** the npm package name is _ not_ ` node-glob ` that's a
21- different thing that was abandoned years ago. Just ` glob ` .
21+ > [ !NOTE]
22+ > The npm package name is _ not_ ` node-glob ` that's a
23+ > different thing that was abandoned years ago. Just ` glob ` .
2224
2325``` js
2426// load using import
@@ -90,8 +92,9 @@ g3.stream().on('data', path => {
9092// For example:
9193const results = await glob (' **' , { stat: true , withFileTypes: true })
9294
93- const timeSortedFiles = results .sort ((a , b ) => a .mtimeMs -
94- b .mtimeMs ) .map (path => path .fullpath ())
95+ const timeSortedFiles = results
96+ .sort ((a , b ) => a .mtimeMs - b .mtimeMs )
97+ .map (path => path .fullpath ())
9598
9699const groupReadableFiles = results
97100 .filter (path => path .mode & 0o040 )
@@ -136,13 +139,14 @@ const newFiles = await glob('**', {
136139})
137140```
138141
139- ** Note** Glob patterns should always use ` / ` as a path separator,
140- even on Windows systems, as ` \ ` is used to escape glob
141- characters. If you wish to use ` \ ` as a path separator _ instead
142- of_ using it as an escape character on Windows platforms, you may
143- set ` windowsPathsNoEscape:true ` in the options. In this mode,
144- special glob characters cannot be escaped, making it impossible
145- to match a literal ` * ` ` ? ` and so on in filenames.
142+ > [ !NOTE]
143+ > Glob patterns should always use ` / ` as a path separator,
144+ > even on Windows systems, as ` \ ` is used to escape glob
145+ > characters. If you wish to use ` \ ` as a path separator _ instead
146+ > of_ using it as an escape character on Windows platforms, you may
147+ > set ` windowsPathsNoEscape:true ` in the options. In this mode,
148+ > special glob characters cannot be escaped, making it impossible
149+ > to match a literal ` * ` ` ? ` and so on in filenames.
146150
147151## Command Line Interface
148152
@@ -363,9 +367,10 @@ Options object is required.
363367
364368See full options descriptions below.
365369
366- Note that a previous ` Glob ` object can be passed as the
367- ` GlobOptions ` to another ` Glob ` instantiation to re-use settings
368- and caches with a new pattern.
370+ > [ !NOTE]
371+ > A previous ` Glob ` object can be passed as the
372+ > ` GlobOptions ` to another ` Glob ` instantiation to re-use settings
373+ > and caches with a new pattern.
369374
370375Traversal functions can be called multiple times to run the walk
371376again.
@@ -430,35 +435,37 @@ share the previously loaded cache.
430435 is used as the starting point for absolute patterns that start
431436 with ` / ` , (but not drive letters or UNC paths on Windows).
432437
433- Note that this _ doesn't_ necessarily limit the walk to the
434- ` root ` directory, and doesn't affect the cwd starting point for
435- non-absolute patterns. A pattern containing ` .. ` will still be
436- able to traverse out of the root directory, if it is not an
437- actual root directory on the filesystem, and any non-absolute
438- patterns will be matched in the ` cwd ` . For example, the
439- pattern ` /../* ` with ` {root:'/some/path'} ` will return all
440- files in ` /some ` , not all files in ` /some/path ` . The pattern
441- ` * ` with ` {root:'/some/path'} ` will return all the entries in
442- the cwd, not the entries in ` /some/path ` .
443-
444- To start absolute and non-absolute patterns in the same
445- path, you can use ` {root:''} ` . However, be aware that on
446- Windows systems, a pattern like ` x:/* ` or ` //host/share/* ` will
447- _ always_ start in the ` x:/ ` or ` //host/share ` directory,
448- regardless of the ` root ` setting.
438+ > [ !NOTE] This _ doesn't_ necessarily limit the walk to the
439+ > ` root ` directory, and doesn't affect the cwd starting point
440+ > for non-absolute patterns. A pattern containing ` .. ` will
441+ > still be able to traverse out of the root directory, if it
442+ > is not an actual root directory on the filesystem, and any
443+ > non-absolute patterns will be matched in the ` cwd ` . For
444+ > example, the pattern ` /../* ` with ` {root:'/some/path'} `
445+ > will return all files in ` /some ` , not all files in
446+ > ` /some/path ` . The pattern ` * ` with ` {root:'/some/path'} `
447+ > will return all the entries in the cwd, not the entries in
448+ > ` /some/path ` .
449+
450+ To start absolute and non-absolute patterns in the same path,
451+ you can use ` {root:''} ` . However, be aware that on Windows
452+ systems, a pattern like ` x:/* ` or ` //host/share/* ` will
453+ _ always_ start in the ` x:/ ` or ` //host/share ` directory,
454+ regardless of the ` root ` setting.
449455
450456- ` windowsPathsNoEscape ` Use ` \\ ` as a path separator _ only_ , and
451457 _ never_ as an escape character. If set, all ` \\ ` characters are
452458 replaced with ` / ` in the pattern.
453459
454- Note that this makes it ** impossible** to match against paths
455- containing literal glob pattern characters, but allows matching
456- with patterns constructed using ` path.join() ` and
457- ` path.resolve() ` on Windows platforms, mimicking the (buggy!)
458- behavior of Glob v7 and before on Windows. Please use with
459- caution, and be mindful of [ the caveat below about Windows
460- paths] ( #windows ) . (For legacy reasons, this is also set if
461- ` allowWindowsEscape ` is set to the exact value ` false ` .)
460+ > [ !NOTE]
461+ > This makes it ** impossible** to match against paths
462+ > containing literal glob pattern characters, but allows matching
463+ > with patterns constructed using ` path.join() ` and
464+ > ` path.resolve() ` on Windows platforms, mimicking the (buggy!)
465+ > behavior of Glob v7 and before on Windows. Please use with
466+ > caution, and be mindful of [ the caveat below about Windows
467+ > paths] ( #windows ) . (For legacy reasons, this is also set if
468+ > ` allowWindowsEscape ` is set to the exact value ` false ` .)
462469
463470- ` dot ` Include ` .dot ` files in normal matches and ` globstar `
464471 matches. Note that an explicit dot in a portion of the pattern
@@ -493,11 +500,12 @@ share the previously loaded cache.
493500- ` nocase ` Perform a case-insensitive match. This defaults to
494501 ` true ` on macOS and Windows systems, and ` false ` on all others.
495502
496- ** Note** ` nocase ` should only be explicitly set when it is
497- known that the filesystem's case sensitivity differs from the
498- platform default. If set ` true ` on case-sensitive file
499- systems, or ` false ` on case-insensitive file systems, then the
500- walk may return more or less results than expected.
503+ > [ !NOTE]
504+ > ` nocase ` should only be explicitly set when it is
505+ > known that the filesystem's case sensitivity differs from the
506+ > platform default. If set ` true ` on case-sensitive file
507+ > systems, or ` false ` on case-insensitive file systems, then the
508+ > walk may return more or less results than expected.
501509
502510- ` maxDepth ` Specify a number to limit the depth of the directory
503511 traversal to this many levels below the ` cwd ` .
@@ -510,8 +518,9 @@ share the previously loaded cache.
510518- ` nodir ` Do not match directories, only files. (Note: to match
511519 _ only_ directories, put a ` / ` at the end of the pattern.)
512520
513- Note: when ` follow ` and ` nodir ` are both set, then symbolic
514- links to directories are also omitted.
521+ > [ !NOTE]
522+ > When ` follow ` and ` nodir ` are both set, then symbolic
523+ > links to directories are also omitted.
515524
516525- ` stat ` Call ` lstat() ` on all entries, whether required or not
517526 to determine whether it's a valid match. When used with
@@ -522,17 +531,18 @@ share the previously loaded cache.
522531- ` ignore ` string or string[ ] , or an object with ` ignored ` and
523532 ` childrenIgnored ` methods.
524533
525- If a string or string[ ] is provided, then this is treated as a
526- glob pattern or array of glob patterns to exclude from matches.
527- To ignore all children within a directory, as well as the entry
528- itself, append ` '/**' ` to the ignore pattern.
534+ If a string or string[ ] is provided, then this is treated as
535+ a glob pattern or array of glob patterns to exclude from
536+ matches. To ignore all children within a directory, as well
537+ as the entry itself, append ` '/**' ` to the ignore pattern.
529538
530- ** Note** ` ignore ` patterns are _ always_ in ` dot:true ` mode,
531- regardless of any other settings.
539+ > [ !NOTE]
540+ > ` ignore ` patterns are _ always_ in ` dot:true ` mode,
541+ > regardless of any other settings.
532542
533543 If an object is provided that has ` ignored(path) ` and/or
534544 ` childrenIgnored(path) ` methods, then these methods will be
535- called to determine whether any Path is a match or if its
545+ called to determine whether any Path is a match or if its
536546 children should be traversed, respectively.
537547
538548 The ` path ` argument to the methods will be a
@@ -553,8 +563,9 @@ share the previously loaded cache.
553563 it is not the first item in the pattern, or none if it is the
554564 first item in the pattern, following the same behavior as Bash.
555565
556- Note: when ` follow ` and ` nodir ` are both set, then symbolic
557- links to directories are also omitted.
566+ > [ !NOTE]
567+ > When ` follow ` and ` nodir ` are both set, then symbolic
568+ > links to directories are also omitted.
558569
559570- ` realpath ` Set to true to call ` fs.realpath ` on all of the
560571 results. In the case of an entry that cannot be resolved, the
@@ -620,12 +631,13 @@ share the previously loaded cache.
620631 ` false ` , and a custom ` Ignore ` is provided that does not have
621632 an ` add() ` method, then it will throw an error.
622633
623- ** Caveat** It _ only_ ignores matches that would be a descendant
624- of a previous match, and only if that descendant is matched
625- _ after_ the ancestor is encountered. Since the file system walk
626- happens in indeterminate order, it's possible that a match will
627- already be added before its ancestor, if multiple or braced
628- patterns are used.
634+ > [ !NOTE]
635+ > It _ only_ ignores matches that would be a descendant
636+ > of a previous match, and only if that descendant is matched
637+ > _ after_ the ancestor is encountered. Since the file system walk
638+ > happens in indeterminate order, it's possible that a match will
639+ > already be added before its ancestor, if multiple or braced
640+ > patterns are used.
629641
630642 For example:
631643
@@ -751,11 +763,12 @@ bsdglob and bash 5, where `**` only has special significance if
751763it is the only thing in a path part. That is, ` a/**/b ` will match
752764` a/x/y/b ` , but ` a/**b ` will not.
753765
754- Note that symlinked directories are not traversed as part of a
755- ` ** ` , though their contents may match against subsequent portions
756- of the pattern. This prevents infinite loops and duplicates and
757- the like. You can force glob to traverse symlinks with ` ** ` by
758- setting ` {follow:true} ` in the options.
766+ > [ !NOTE]
767+ > Symlinked directories are not traversed as part of a
768+ > ` ** ` , though their contents may match against subsequent portions
769+ > of the pattern. This prevents infinite loops and duplicates and
770+ > the like. You can force glob to traverse symlinks with ` ** ` by
771+ > setting ` {follow:true} ` in the options.
759772
760773There is no equivalent of the ` nonull ` option. A pattern that
761774does not find any matches simply resolves to nothing. (An empty
@@ -969,10 +982,11 @@ performing a glob pattern expansion as faithfully as possible to
969982the behavior of Bash and other sh-like shells, with as much speed
970983as possible.
971984
972- Note that prior versions of ` node-glob ` are _ not_ on this list.
973- Former versions of this module are far too slow for any cases
974- where performance matters at all, and were designed with APIs
975- that are extremely dated by current JavaScript standards.
985+ > [ !NOTE]
986+ > Prior versions of ` node-glob ` are _ not_ on this list.
987+ > Former versions of this module are far too slow for any cases
988+ > where performance matters at all, and were designed with APIs
989+ > that are extremely dated by current JavaScript standards.
976990
977991---
978992
0 commit comments