Skip to content

index

index<T>(entries, opts?): Registry<T>

Build the reverse index over labeled pattern-sets. Retains entry order and compiles each entry’s patterns once, up front.

Type ParameterDefault typeDescription
TstringThe id type, inferred from entries.
ParameterTypeDescription
entriesIterable<Labeled<T>>The labeled pattern-sets to index, in significant order.
opts?OptionsMatching semantics (Options) applied to every entry.

Registry<T>

A Registry whose queries echo matching ids in registration order.

Error duplicate registry id '<id>' if any id is supplied twice — rejected at construction rather than silently keeping first or last.

Registration order is significant and preserved: register general-to-specific and read a query result as a prioritization (first = most general, last = most specific). Intersect returns the order; the caller picks the precedence rule. Pure — target paths need not exist.

const guidelines = index([
{ id: "guidelines/api", patterns: ["src/api/**"] },
{ id: "guidelines/db", patterns: ["src/db/**"] },
]);
guidelines.applicableTo("src/api/**"); // ["guidelines/api"] — db does not overlap
guidelines.matching("src/db/pool.ts"); // ["guidelines/db"]

Duplicate ids throw at construction:

index([
{ id: "a", patterns: ["src/**"] },
{ id: "a", patterns: ["docs/**"] }, // same id, registered twice
]);
// → Error: duplicate registry id 'a'