Files
formbricks/packages/lib/utils/testUrlMatch.ts
T
Piyush Gupta 6bfd02794d feat: Refactor Triggers and combine Action Classes and Inline Triggers (#2562)
Co-authored-by: Matthias Nannt <mail@matthiasnannt.com>
Co-authored-by: pandeymangg <anshuman.pandey9999@gmail.com>
Co-authored-by: Johannes <johannes@formbricks.com>
2024-05-07 13:47:41 +00:00

21 lines
784 B
TypeScript

export type MatchType = "exactMatch" | "contains" | "startsWith" | "endsWith" | "notMatch" | "notContains";
export function testURLmatch(testUrl: string, pageUrlValue: string, pageUrlRule: MatchType): string {
switch (pageUrlRule) {
case "exactMatch":
return testUrl === pageUrlValue ? "yes" : "no";
case "contains":
return testUrl.includes(pageUrlValue) ? "yes" : "no";
case "startsWith":
return testUrl.startsWith(pageUrlValue) ? "yes" : "no";
case "endsWith":
return testUrl.endsWith(pageUrlValue) ? "yes" : "no";
case "notMatch":
return testUrl !== pageUrlValue ? "yes" : "no";
case "notContains":
return !testUrl.includes(pageUrlValue) ? "yes" : "no";
default:
throw new Error("Invalid match type");
}
}