Skip to content

Overlap, matches, witness

The path API is a small set of primitives, all shapes over the same pairwise question. Each coerces its Patterns argument (a string or a set) to segment-patterns, then defers to the core.

PrimitiveShapeReturns
intersects(a, b)set ↔ settrue if some path matches both.
matches(path, patterns)path ↔ settrue if the path matches any pattern.
whichMatch(path, patterns)path ↔ setThe patterns that match the path, in input order.
overlapping(query, candidates)set ↔ setThe query subset that overlaps a candidate.
witness(a, b)set ↔ setA concrete common path, or null.
compile(patterns)A reusable Matcher for a fixed scope.
import { intersects, matches } from "@sksizer/intersect";
intersects("src/api/**", "src/**/*.ts");
matches("src/api/user.ts", ["src/api/**", "**/*.test.ts"]);
matches("README.md", ["src/api/**", "**/*.test.ts"]);
CallResultWhy
intersects("src/api/**", "src/**/*.ts")truesrc/api/x.ts is common to both
matches("src/api/user.ts", […])truematches the first pattern
matches("README.md", […])falsematches neither pattern
import { whichMatch } from "@sksizer/intersect";
whichMatch("src/api/user.ts", ["src/api/**", "src/**", "docs/**"]);
PathPatternsReturnsWhy
src/api/user.ts["src/api/**", "src/**", "docs/**"]["src/api/**", "src/**"]docs/** does not match

overlapping — mind which side is filtered

Section titled “overlapping — mind which side is filtered”

overlapping has two forms that filter opposite sides. The free function returns a subset of its first argument, query, in query order. A compiled Matcher.overlapping returns a subset of ITS argument, candidates.

import { overlapping, compile } from "@sksizer/intersect";
const taskA = ["src/api/**", "src/db/schema.ts"];
const taskB = ["src/api/routes/*.ts", "docs/**"];
overlapping(taskA, taskB);
compile(taskA).overlapping(taskB);
CallReturnsWhich side is filtered
overlapping(taskA, taskB)["src/api/**"]the query (first arg) subset
compile(taskA).overlapping(taskB)["src/api/routes/*.ts"]the candidates (argument) subset

A witness is a concrete path both sets match, or null when they are disjoint. It is free: the reachability path the engine already walked to prove the overlap. It turns “these overlap” into “these overlap at X”.

import { witness } from "@sksizer/intersect";
witness("src/api/**", "src/**/handler.ts");
witness("src/api/**", "src/web/**");
ABWitnessWhy
src/api/**src/**/handler.ts"src/api/handler.ts"a concrete path both match
src/api/**src/web/**nullno common path

For a scope tested against many paths or patterns, compile parses each pattern once; every method reuses that parsed set.

import { compile } from "@sksizer/intersect";
const scope = compile(["src/api/**", "src/db/**"]);
scope.matches("src/api/user.ts");
scope.matches("test/api/user.test.ts");
scope.overlapping(["docs/**", "src/db/pool.ts"]);
scope.witness("src/**/*.ts");
CallReturns
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"]
scope.witness("src/**/*.ts")e.g. "src/api/user.ts"