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 = 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 { isDynamicPattern } from 'tinyglobby';
isDynamicPattern('my-dream.txt');
// ^ false
isDynamicPattern('star.*');
// ^ true
Whether to return absolute paths. Disable to have relative paths.
Default: falseEnables support for brace expansion syntax, like "{a,b}" or "{1..9}".
Default: trueWhether to match in case-sensitive mode.
Default: trueThe 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: falseMaximum directory depth to crawl.
Default: InfinityWhether to return entries that start with a dot, like .gitignore or .prettierrc.
Default: falseWhether to automatically expand directory patterns. Important to disable if migrating from fast-glob.
Default: trueEnables support for extglobs, like "+(pattern)".
Default: trueWhether to traverse and include symbolic links. Can slightly affect performance.
Default: trueAn 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: trueGlob patterns to exclude from the results.
Default: []Enable to only return directories. If true, disables onlyFiles.
Default: falseEnable to only return files.
Default: trueAn 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