tinyglobby documentation v0.2.14

API

function glob(patterns: string | readonly string[], options?: Omit<GlobOptions, "patterns">): Promise<string[]> (+1 overload)
glob

Asynchronously match files following a glob pattern.

Usage:
import { glob } from 'tinyglobby';

const files = await glob('src/**', {
  cwd: './projects/best-cats'
});

function globSync(patterns: string | readonly string[], options?: Omit<GlobOptions, "patterns">): string[] (+1 overload)
globSync

Synchronously match files following a glob pattern.

Usage:
import { globSync } from 'tinyglobby';

const files = await globSync('src/**', {
  cwd: './projects/best-cats'
});

const convertPathToPattern: (path: string) => string
convertPathToPattern

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"

const escapePath: (path: string) => string
escapePath

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!\!\(\)!"

function isDynamicPattern(pattern: string, options?: {
    caseSensitiveMatch: boolean;
}): boolean
isDynamicPattern

Checks if a pattern has dynamic parts.

Has a few minor differences with fast-glob for better accuracy:

Usage:
import { convertPathToPattern } from 'tinyglobby';

convertPathToPattern("[413] home stuck funny moments*.mp4");
// Returns "\[413\] home stuck funny moments\*.mp4"

Options

import type { GlobOptions } from 'tinyglobby';

const absolute: boolean | undefined
absolute

Whether to return absolute paths. Disable to have relative paths.

Default: false

const braceExpansion: boolean | undefined
braceExpansion

Enables support for brace expansion syntax, like "{a,b}" or "{1..9}".

Default: true

const caseSensitiveMatch: boolean | undefined
caseSensitiveMatch

Whether to match in case-sensitive mode.

Default: true

const cwd: string | URL | undefined
cwd

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()

const debug: boolean | undefined
debug

Logs useful debug information. Meant for development purposes. Logs can change at any time.

Default: false

const deep: number | undefined
deep

Maximum directory depth to crawl.

Default: Infinity

const dot: boolean | undefined
dot

Whether to return entries that start with a dot, like .gitignore or .prettierrc.

Default: false

const expandDirectories: boolean | undefined
expandDirectories

Whether to automatically expand directory patterns. Important to disable if migrating from fast-glob.

Default: true

const extglob: boolean | undefined
extglob

Enables support for extglobs, like "+(pattern)".

Default: true

Whether to traverse and include symbolic links. Can slightly affect performance.

Default: true

const fs: Partial<FSLike> | undefined
fs

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')

const globstar: boolean | undefined
globstar

Enables support for matching nested directories with globstars ("**"). If false, "**" behaves exactly like "*".

Default: true

const ignore: string | readonly string[] | undefined
ignore

Glob patterns to exclude from the results.

Default: []

const onlyDirectories: boolean | undefined
onlyDirectories

Enable to only return directories. If true, disables onlyFiles.

Default: false

const onlyFiles: boolean | undefined
onlyFiles

Enable to only return files.

Default: true

const signal: AbortSignal | undefined
signal

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