From f7d292932f0ecd06bf23d7f6811f5a910060df9a Mon Sep 17 00:00:00 2001 From: Bauke Date: Thu, 20 Oct 2022 22:54:02 +0200 Subject: [PATCH] Add the regex matcher. --- source/redirect/base.ts | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/source/redirect/base.ts b/source/redirect/base.ts index ae20038..f19c8ee 100644 --- a/source/redirect/base.ts +++ b/source/redirect/base.ts @@ -1,6 +1,6 @@ import {customAlphabet} from 'nanoid'; -export const matcherTypes = ['hostname'] as const; +export const matcherTypes = ['hostname', 'regex'] as const; export const redirectTypes = ['hostname', 'simple'] as const; export type MatcherType = typeof matcherTypes[number]; @@ -42,6 +42,11 @@ export abstract class Redirect { return hostname === this.parameters.matcherValue; } + if (this.parameters.matcherType === 'regex') { + const regex = new RegExp(this.parameters.matcherValue, 'gi'); + return regex.test(url.href); + } + return false; }