Skip to content

compile

compile(patterns, opts?): Matcher

Compile a pattern-set once, then query it many times. Parses each pattern into a SegmentPattern up front; every method reuses that parsed set. Amortizes the parse when a fixed scope is tested against many paths/patterns.

ParameterTypeDescription
patternsPatternsThe pattern-set to compile (Patterns).
opts?OptionsMatching semantics (Options) baked into every query.

Matcher

A Matcher bound to patterns and opts.

const scope = compile(["src/api/**", "src/db/**"]);
scope.matches("src/api/user.ts"); // true
scope.matches("test/api/user.test.ts"); // false
scope.overlapping(["docs/**", "src/db/pool.ts"]); // ["src/db/pool.ts"]