← snapshot
639 bytes
/**
* Mirror of `RepoPath::is_under`: segment-wise, not string-wise.
* `src/auth-x` is NOT under `src/auth`, though it is a string prefix.
*/
export function isUnder(path: string, prefix: string): boolean {
const mine = path.split("/");
const wanted = prefix.split("/");
if (wanted.length > mine.length) return false;
return wanted.every((seg, i) => mine[i] === seg);
}
/** Which of `decisions` govern `path`, given each decision's scope prefixes. */
export function governing<T extends { scope: string[] }>(
path: string,
decisions: T[],
): T[] {
return decisions.filter((d) => d.scope.some((p) => isUnder(path, p)));
}