Add the regex matcher.

This commit is contained in:
Bauke 2022-10-20 22:54:02 +02:00
parent 93096b839a
commit f7d292932f
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 6 additions and 1 deletions

View File

@ -1,6 +1,6 @@
import {customAlphabet} from 'nanoid'; 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 const redirectTypes = ['hostname', 'simple'] as const;
export type MatcherType = typeof matcherTypes[number]; export type MatcherType = typeof matcherTypes[number];
@ -42,6 +42,11 @@ export abstract class Redirect {
return hostname === this.parameters.matcherValue; 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; return false;
} }