glob-to-regexp
A tiny, dependency-free JavaScript library that converts wildcard glob patterns into native RegExp objects, with optional bash-style extended and globstar matching.
Repository Health
Technical Analysis
glob-to-regexp turns a wildcard glob string such as *.min.js into a native JavaScript RegExp object, so any code that already knows how to work with regular expressions can match against glob-style patterns without pulling in a full glob-walking engine. Basic * wildcards are supported out of the box, with two opt-in modes: extended for bash-style ? single-character matches, [a-z] character ranges, and {a,b} alternation groups, and globstar for node-glob-compatible ** path-segment semantics.
The entire implementation is a single, dependency-free file, which is likely why it sees tens of millions of weekly downloads as a small transitive dependency inside larger build-tool and bundler dependency trees rather than as something most developers install directly.
What You Get
- A single default export function,
globToRegExp(glob, opts), that returns a nativeRegExp - Basic wildcard
*matching, translated to.*(or[^/]*per segment whenglobstaris enabled) - An
extendedoption enabling bash-style?,[abc]character ranges, and{a,b}alternation groups - A
globstaroption implementing**path-segment semantics compatible with node-glob - A
flagsoption that passes RegExp flags (e.g.'g','i') straight through to the constructed pattern
Common Use Cases
- Filtering file paths or URLs against a wildcard pattern without pulling in a full glob-matching engine
- Powering file-watch matching inside build tools that need a compiled RegExp rather than a stateful matcher
- Validating whether an asset URL (e.g.
*.min.js) matches a bundler or CDN naming convention - Implementing simple user-facing search or filter inputs that accept
*wildcards
Under The Hood
Architecture
glob-to-regexp is a single-function, single-file module (index.js) with no internal layering — the entire conversion happens inside one loop that walks the glob string character by character and appends to a growing regex string via a switch statement. Control flow relies on intentional switch-case fallthrough (the [, ], {, }, and , cases fall through toward the extended-mode branch and finally to a default escape), which is compact but requires care to read since a missing break looks like a bug rather than a deliberate ladder. State is minimal — a handful of booleans (extended, globstar, inGroup) plus the accumulating string — and there is no dependency injection or exposed internals to override; the entire surface area that could break is this one function behind a single CommonJS export.
Tech Stack
The package has zero runtime dependencies and no build step — it ships the raw CommonJS index.js directly as main, targeting any JavaScript environment with a native RegExp and no transpilation required. package.json declares only a test script (node test.js) built on Node’s core assert module rather than a test framework, and CI is configured via a long-dormant .travis.yml targeting Node 0.8/0.10, reflecting the library’s age (created 2013, last pushed 2019) rather than active tooling investment.
Code Quality
test.js is an extensive, if unconventional, regression suite — many assertMatch/assertNotMatch calls covering wildcard, extended, and globstar modes, exercised twice across globstar settings plus dedicated globstar-only cases. There are no TypeScript types, no JSDoc annotations, and no linter or formatter configuration in the repo; the only runtime validation is a single TypeError thrown when the input isn’t a string, and option values are silently coerced with !! rather than validated.
API Design
The public API is a single function, globToRegExp(glob, opts), returning a plain RegExp — there is no class to instantiate and no builder chain, and calling it with just a glob string works with sensible defaults. The small opts object (extended, globstar, flags) is documented with runnable examples in the README, so a new consumer can be productive from the README alone; the tradeoff is that the return value is a bare RegExp with no bundled TypeScript typings, so editor autocomplete for opts comes only from community @types packages, not the library itself.
Used by 3 apps in this directory
Directus
CMS · Low Code Platforms
Connect any SQL database and get instant REST and GraphQL APIs, a visual management Studio, and a native MCP server for AI agents — free for most organizations.
Element Web
Team Chat · Collaboration
A polished, self-hostable Matrix client for secure, decentralized messaging and collaboration that puts your organization in full control of its data.
Sourcebot
Search · Developer Tools · AI Code Assistants
A self-hosted, AI-powered code search engine that indexes every repo across GitHub, GitLab, Bitbucket, Gitea, Gerrit, and Azure DevOps, so both engineers and coding agents can search, browse, and ask questions about your codebase from one place.