diff --git a/source/redirect/base.ts b/source/redirect/base.ts index 376199b..76f0549 100644 --- a/source/redirect/base.ts +++ b/source/redirect/base.ts @@ -2,8 +2,21 @@ import {HostnameParameters} from './hostname.js'; export type RedirectParameters = HostnameParameters; +export type Matcher = { + matchType: 'hostname'; + toMatch: string; +}; + export abstract class Redirect
{ - constructor(public parameters: P) {} + constructor(public parameters: P & Matcher) {} + + public isMatch(url: URL): boolean { + if (this.parameters.matchType === 'hostname') { + return url.hostname === this.parameters.toMatch; + } + + return false; + } public abstract redirect(url: URL | string): URL; } diff --git a/source/redirect/exports.ts b/source/redirect/exports.ts index 0b5e5f2..6a71e66 100644 --- a/source/redirect/exports.ts +++ b/source/redirect/exports.ts @@ -1,4 +1,3 @@ -import {RedirectParameters} from './base.js'; import {HostnameRedirect} from './hostname.js'; export * from './base.js'; @@ -6,7 +5,7 @@ export * from './hostname.js'; export type Redirects = HostnameRedirect; -export function parseRedirect
( +export function parseRedirect
( parameters: P, ): Redirects | undefined { if (parameters.type === 'hostname') {