fix: add type checks for string inputs in formatWithSlashes and extractRegexBody functions

This commit is contained in:
medchedli 2025-06-03 16:11:46 +01:00
parent 7d73ae72e2
commit 04214b60e5

View File

@ -31,6 +31,7 @@ export const isRegexString = (str: any) => {
*/
export const formatWithSlashes = (value: string): string => {
if (!value) return "/";
if (typeof value !== "string") return "/";
if (!value.startsWith("/")) value = "/" + value;
if (!value.endsWith("/")) value = value + "/";
@ -40,12 +41,13 @@ export const formatWithSlashes = (value: string): string => {
/**
* Extracts the inner regex from /.../
*/
export const extractRegexBody = (value: string | undefined): string => {
export const extractRegexBody = (value: string | undefined): string => {
if (typeof value !== "string") return "";
if (value && value.startsWith("/") && value.endsWith("/")) {
return value.slice(1, -1);
}
return '';
return "";
};
/**