Asynchronously match files following a glob pattern.
Usage:import { glob } from 'tinyglobby';
const files = await glob('src/**', {
cwd: './projects/best-cats'
});
Synchronously match files following a glob pattern.
Usage:import { globSync } from 'tinyglobby';
const files = await globSync('src/**', {
cwd: './projects/best-cats'
});
Converts a path to a pattern depending on the platform. Identical to escapePath
on POSIX systems.
Usage:import { convertPathToPattern } from 'tinyglobby';
convertPathToPattern("[413] home stuck funny moments*.mp4");
// Returns "\[413\] home stuck funny moments\*.mp4"
Escapes a path's special characters depending on the platform.
Usage:import { escapePath } from 'tinyglobby';
escapePath("!!()!()i use linux and i can use \\ in filenames!!()!");
// Returns "\!\!\(\)\!\(\)i use linux and i can use \\ in filenames!\!\(\)!"
Checks if a pattern has dynamic parts.
Has a few minor differences with fast-glob
for better accuracy:
- Doesn't necessarily return
false
on patterns that include "\\
". - Returns
true
if the pattern includes parentheses, regardless of them representing one single pattern or not. - Returns
true
for unfinished glob extensions i.e. "(h
", "+(h
". - Returns
true
for unfinished brace expansions as long as they include ",
" or "..
".
Usage:import { convertPathToPattern } from 'tinyglobby';
convertPathToPattern("[413] home stuck funny moments*.mp4");
// Returns "\[413\] home stuck funny moments\*.mp4"
Whether to return absolute paths. Disable to have relative paths.
Default: false
Enables support for brace expansion syntax, like "{a,b}
" or "{1..9}
".
Default: true
Whether to match in case-sensitive mode.
Default: true
The working directory in which to search. Results will be returned relative to this directory, unless absolute
is set.
It is important to avoid globbing outside this directory when possible, even with absolute paths enabled, as doing so can harm performance due to having to recalculate relative paths.
import { glob } from 'tinyglobby';
// Avoid this - will calculate it relative to `process.cwd()`!
await glob(`${searchDir}/*.ts`, {
absolute: true
});
// Do this instead:
await glob(`${searchDir}/*.ts`, {
absolute: true,
cwd: searchDir
});
Default: process.cwd()
Logs useful debug information. Meant for development purposes. Logs can change at any time.
Default: false
Maximum directory depth to crawl.
Default: Infinity
Whether to return entries that start with a dot, like .gitignore
or .prettierrc
.
Default: false
Whether to automatically expand directory patterns. Important to disable if migrating from fast-glob
.
Default: true
Enables support for extglobs, like "+(pattern)
".
Default: true
Whether to traverse and include symbolic links. Can slightly affect performance.
Default: true
An object that overrides node:fs
functions.
type FileSystemAdapter = {
readdir?: typeof fs.readdir;
readdirSync?: typeof fs.readdirSync;
realpath?: typeof fs.realpath;
realpathSync?: typeof fs.realpathSync;
stat?: typeof fs.stat;
statSync?: typeof fs.statSync;
};
Default: import('node:fs')
Enables support for matching nested directories with globstars ("**
"). If false
, "**
" behaves exactly like "*
".
Default: true
Glob patterns to exclude from the results.
Default: []
Enable to only return directories. If true
, disables onlyFiles
.
Default: false
Enable to only return files.
Default: true
An AbortSignal
to abort crawling the file system.
import { glob } from 'tinyglobby';
// Stops crawling if taking too long
await glob('**', {
signal: AbortSignal.timeout(1000)
});
Default: undefined