Skip to Content
  • Website
Codsen
  • Home
  • Open Source
  • Articles
  • About

prevOpen Source→codsen-globnext

codsen-glob1.1.0

Fast TypeScript file globbing

Downloads per monthChangelogMIT Licenselibera manifesto
  • the top
  • Installation
  • Quick Take
  • Examples
  • IDEA
  • API — GLOB()
  • API — GLOBSYNC()
  • PATTERNS
  • THE OPTIONAL…
  • OPTS — EXPANDDIRECT…
  • API — VERSION
  • API — TYPES
  • Changelog

Installation

Quick Take

Examples

  • Abort an asynchronous search
  • Return absolute paths
  • Brace expansion and extglobs
  • Match without case sensitivity
  • Configure directory expansion
  • Return directories
  • Disable symbolic-link traversal
  • Include hidden entries
  • Veto matches with ignore patterns
  • Combine multiple patterns
  • Exclude matches with a negative pattern
  • Synchronous globbing
  • Use a file URL as the working directory

Idea

Find files on disk by wildcard pattern. Only one runtime dependency (picomatchopens in a new tab) (and a Node-only API).

import { glob } from "codsen-glob";

console.log(await glob("src/**/*.ts"));
// => ["src/main.test.ts", "src/main.ts", "src/nested/deep.ts"]

Results are returned sorted, with forward slashes on every platform, and relative to cwd unless you ask for absolute paths.

API — glob()

The main function glob() is imported like this:

It’s an async function which takes two input arguments and returns a promise resolving to an array of paths:

Input argumentTypeObligatoryDescription
patterns
Type: String or array of strings
Obligatory: yes
patternsString or array of stringsyesOne or more glob patterns to match.
optionsInput
Type: Plain object
Obligatory: no
optionsInputPlain objectnoOptional Options Object.

API — globSync()

The function globSync() is imported like this:

The synchronous counterpart of glob(). Same input arguments, same results, except it returns the array directly instead of a promise:

import { globSync } from "codsen-glob";

console.log(globSync("src/**/*.ts"));
// => ["src/main.test.ts", "src/main.ts", "src/nested/deep.ts"]

Patterns

A pattern prefixed with ! is negative — it removes from the results anything the positive patterns matched:

import { glob } from "codsen-glob";

console.log(await glob(["src/**/*.ts", "!src/**/*.test.ts"]));
// => ["src/main.ts", "src/nested/deep.ts"]

A pattern which names a directory is expanded to match everything inside it. See expandDirectories to control or switch off that behaviour.

The Optional Options Object

KeyTypeDefaultDescription
absolute
Type: Boolean
Default: false
absoluteBooleanfalseSet to true to return absolute paths instead of paths relative to cwd.
caseSensitiveMatch
Type: Boolean
Default: true
caseSensitiveMatchBooleantrueSet to false to match patterns regardless of letter case.
cwd
Type: String or URL
Default: process.cwd()
cwdString or URLprocess.cwd()Directory to resolve patterns and results against. A file: URL is accepted and converted to a path.
dot
Type: Boolean
Default: false
dotBooleanfalseSet to true to also match files and directories whose name starts with a dot.
expandDirectories
Type: Boolean, array of strings or object
Default: true
expandDirectoriesBoolean, array of strings or objecttrueControls how a pattern naming a directory is expanded, see below.
followSymbolicLinks
Type: Boolean
Default: true
followSymbolicLinksBooleantrueSet to false to leave symlinked entries unresolved.
ignore
Type: String or array of strings
Default: []
ignoreString or array of strings[]Patterns to exclude from the results. Equivalent to passing negative patterns, but kept separate for clarity.
onlyDirectories
Type: Boolean
Default: false
onlyDirectoriesBooleanfalseSet to true to return only directories. Enabling it forces onlyFiles to false.
onlyFiles
Type: Boolean
Default: true
onlyFilesBooleantrueSet to false to return directories alongside files.
signal
Type: AbortSignal
Default: undefined
signalAbortSignalundefinedAbort a traversal in progress.

The program throws if cwd is neither a string nor a URL, or if ignore is neither a string nor an array of strings.

opts.expandDirectories

When a pattern points at a directory rather than at files, the program appends **/* to it, so "src" behaves like "src/**/*":

import { glob } from "codsen-glob";

console.log(await glob("src"));
// => ["src/main.test.ts", "src/main.ts", "src/util.js", "src/nested/deep.ts"]

Set expandDirectories to false to switch this off — a bare directory name then matches nothing:

console.log(await glob("src", { expandDirectories: false }));
// => []

Pass an array of strings to name the files to look for inside the directory, or an object to be specific:

ValueExpands "src" into
true (default)
true (default)src/**/*
false
falsenothing — the pattern is used as-is
["index.js"]
["index.js"]src/**/index.js
{ extensions: ["ts"] }
{ extensions: ["ts"] }src/**/*.ts
{ files: ["index"], extensions: ["ts", "js"] }
{ files: ["index"], extensions: ["ts", "js"] }src/**/index.ts and src/**/index.js
console.log(await glob("src", { expandDirectories: { extensions: ["ts"] } }));
// => ["src/main.test.ts", "src/main.ts", "src/nested/deep.ts"]

API — version

You can import version:

API — types

This package is written in TypeScript and exports the following types:

TypeDescription
GlobOptions
Type: GlobOptions
GlobOptionsThe Optional Options Object of glob() and globSync(), shown above.
ExpandDirectories
Type: ExpandDirectories
ExpandDirectoriesThe accepted values of opts.expandDirectories, shown above.
import type { ExpandDirectories, GlobOptions } from "codsen-glob";

Changelog

Open Changelog
↑ back to top
prev next

Copyright

All rights reserved © Roy Revelt 2026
All our open source packages are under MIT licenceopens in a new tab

Activities

🐛 See a bug? Raise an issueopens in a new tab
💘 Check out the Indiewebopens in a new tab and Libera manifestoopens in a new tab