MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / globToRegExp

Function globToRegExp

scripts/agent-eval/probe-allocation.mjs:73–84  ·  view source on GitHub ↗

`internal/gen/**` → /^internal\/gen\/.*$/ . Supports `**`, `*` and literals.

(glob)

Source from the content-addressed store, hash-verified

71
72/** `internal/gen/**` → /^internal\/gen\/.*$/ . Supports `**`, `*` and literals. */
73function globToRegExp(glob) {
74 // Park `**` on a sentinel no path can contain, so the `*` pass cannot eat it.
75 // Written as an escape, not a literal byte — a raw NUL makes git treat this
76 // whole script as binary, which costs every future diff of it.
77 const DOUBLE_STAR = '\u0000';
78 const escaped = glob.replace(/[.+^${}()|[\]\\]/g, '\\$&');
79 const body = escaped
80 .replace(/\*\*/g, DOUBLE_STAR)
81 .replace(/\*/g, '[^/]*')
82 .replaceAll(DOUBLE_STAR, '.*');
83 return new RegExp(`^${body}$`);
84}
85
86const groupOf = (path, groups) => {
87 for (const [name, globs] of Object.entries(groups)) {

Callers 1

groupOfFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected