Skip to main content

Quickstart

Scan a directory for files matching *.ts:
Match a string against a glob pattern:
Glob is a class which implements the following interface:

Supported Glob Patterns

Bun supports the following glob patterns:

? - Match any single character

* - Matches zero or more characters, except for path separators (/ or \)

** - Match any number of characters including /

[ab] - Matches one of the characters contained in the brackets, as well as character ranges

You can use character ranges (e.g [0-9], [a-z]) as well as the negation operators ^ or ! to match anything except the characters contained within the braces (e.g [^ab], [!a-z])

{a,b,c} - Match any of the given patterns

These match patterns can be deeply nested (up to 10 levels), and contain any of the wildcards from above.

! - Negates the result at the start of a pattern

\ - Escapes any of the special characters above

Node.js fs.glob() compatibility

Bun also implements Node.js’s fs.glob() functions with additional features:
All three functions (fs.glob(), fs.globSync(), fs.promises.glob()) support:
  • Array of patterns as the first argument
  • exclude option to filter results