re-nav/source/redirect/base.ts

23 lines
519 B
TypeScript
Raw Normal View History

2022-10-05 17:08:17 +00:00
import {HostnameParameters} from './hostname.js';
export type RedirectParameters = HostnameParameters;
2022-10-12 22:04:51 +00:00
export type Matcher = {
matchType: 'hostname';
toMatch: string;
};
2022-10-05 17:08:17 +00:00
export abstract class Redirect<P extends RedirectParameters> {
2022-10-12 22:04:51 +00:00
constructor(public parameters: P & Matcher) {}
public isMatch(url: URL): boolean {
if (this.parameters.matchType === 'hostname') {
return url.hostname === this.parameters.toMatch;
}
return false;
}
2022-10-05 17:08:17 +00:00
public abstract redirect(url: URL | string): URL;
}