library comparison
Syntax
tinyglobby
supports the same glob syntax picomatch
(the underlying matching library) provides.
globby
and fast-glob
use micromatch
under the hood, a library that wraps around picomatch
to support advanced brace expansions at the cost of four subdependencies.
Brace expansions
Despite mentioning the opposite in its README, picomatch
does support brace expansions, although the support is pretty minimal.
This leads to the following differences in brace patterns:
- Zero-padded ranges ("
{01..03}
") are not supported - Step ranges ("
{1..5..2}
") are not evaluated
In practice, this does not really affect users, as apparently these are features only used very rarely if at all. tinyglobby
has never come across a user report of something breaking after switching due to the lack of these brace features.
Trailing slashes
In other glob libraries, patterns with trailing slashes (like src/
) generally only match directories.
tinyglobby
ignores the trailing slash, making patterns like that also match files.
The reason for this is that fast-glob
ignores trailing slashes on static patterns, and changing it in tinyglobby
could break the code of some users that migrate from fast-glob
and use static patterns like src/index.ts/
.
Proper handling of trailing slashes might be added in a future major release.
See outslept/glob-comparison for an in-depth comparison of syntax features across glob libraries.
Options
expandDirectories
tinyglobby
enables the expandDirectories
option by default. This option works the same as globby
's expandDirectories
option, with the difference that it only supports setting it to a boolean.
This option is enabled by default for the purpose of matching globby
, but it should be disabled if not migrating from that library. No other glob library has this functionality.
As such it's strongly recommended to set it to false
, unless you are explicitly migrating from globby
and you want it to keep working the same way.
import { glob } from 'tinyglobby';
await glob('src/*.ts', {
expandDirectories: false
});
deep
The deep
option works in a different way than globby
and fast-glob
.
globby
and fast-glob
follow the following rule:
- At each directory, compute the directory's level (number of path segments relative to the leading static part of a pattern).
- If the level is greater than or equal to
deep
, stop descending into that directory.
In contrast, for performance and other technical reasons, tinyglobby
's approach is different. It uses fdir
's maxDepth
option, which makes it limit the depth when crawling subdirectories.
Results
Format
The format of the results is not affected in any way by the patterns used. This means that providing an absolute pattern will not result in an absolute path being returned. Use the absolute
option if you want the returned paths to be absolute.
This doesn't happen in any other glob library, so it's important to keep it in mind for some use cases.
import assert from 'node:assert/strict';
import { glob as nativeGlob } from 'node:fs/promises';
import { glob } from 'tinyglobby';
const files = await glob(['./package.json', '/home/meow/project/luigi.png'], {
expandDirectories: false
});
const files2 = await Array.fromAsync(
nativeGlob(['./package.json', '/home/meow/project/luigi.png'])
);
// tinyglobby always produces the same paths format
assert.deepEqual(files.sort(), ['package.json', 'luigi.png']);
// other libraries do not
assert.deepEqual(files2.sort(), ['./package.json', '/home/meow/project/luigi.png']);
Ordering
Despite being consistent most of the time, tinyglobby
's order of results is non-deterministic.
globby
and fast-glob
also do not return results in a deterministic order, according to this issue and fast-glob
's README.