src / adapters / SiteAdapterRegistry.ts
import { SiteAdapter } from "./SiteAdapter";
export class SiteAdapterRegistry {
private static adapters: SiteAdapter[] = [];
/**
* Registers a site-specific content adapter.
*/
public static register(adapter: SiteAdapter): void {
if (!this.adapters.some((a) => a.name === adapter.name)) {
this.adapters.push(adapter);
}
}
/**
* Performs synchronous hostname/pattern lookup against registered adapters.
* Returns matching SiteAdapter or undefined if no adapter matches.
*/
public static findAdapter(parsedUrl: URL): SiteAdapter | undefined {
for (const adapter of this.adapters) {
if (adapter.matches(parsedUrl)) {
return adapter;
}
}
return undefined;
}
/**
* Returns a copy of all currently registered adapters.
*/
public static getAdapters(): ReadonlyArray<SiteAdapter> {
return [...this.adapters];
}
/**
* Unregisters all adapters (primarily for testing and reset).
*/
public static clear(): void {
this.adapters = [];
}
}
src / adapters / SiteAdapterRegistry.ts
import { SiteAdapter } from "./SiteAdapter";
export class SiteAdapterRegistry {
private static adapters: SiteAdapter[] = [];
/**
* Registers a site-specific content adapter.
*/
public static register(adapter: SiteAdapter): void {
if (!this.adapters.some((a) => a.name === adapter.name)) {
this.adapters.push(adapter);
}
}
/**
* Performs synchronous hostname/pattern lookup against registered adapters.
* Returns matching SiteAdapter or undefined if no adapter matches.
*/
public static findAdapter(parsedUrl: URL): SiteAdapter | undefined {
for (const adapter of this.adapters) {
if (adapter.matches(parsedUrl)) {
return adapter;
}
}
return undefined;
}
/**
* Returns a copy of all currently registered adapters.
*/
public static getAdapters(): ReadonlyArray<SiteAdapter> {
return [...this.adapters];
}
/**
* Unregisters all adapters (primarily for testing and reset).
*/
public static clear(): void {
this.adapters = [];
}
}