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

This commit is contained in:
medchedli 2025-06-04 17:36:57 +01:00
parent 04214b60e5
commit 520c60a8e7

View File

@ -30,8 +30,7 @@ export const isRegexString = (str: any) => {
* Ensures value is wrapped in slashes: /value/ * Ensures value is wrapped in slashes: /value/
*/ */
export const formatWithSlashes = (value: string): string => { export const formatWithSlashes = (value: string): string => {
if (!value) return "/"; if (!value || typeof value !== "string") return "/";
if (typeof value !== "string") return "/";
if (!value.startsWith("/")) value = "/" + value; if (!value.startsWith("/")) value = "/" + value;
if (!value.endsWith("/")) value = value + "/"; if (!value.endsWith("/")) value = value + "/";
@ -42,8 +41,12 @@ export const formatWithSlashes = (value: string): string => {
* Extracts the inner regex from /.../ * 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 (
if (value && value.startsWith("/") && value.endsWith("/")) { value &&
typeof value === "string" &&
value.startsWith("/") &&
value.endsWith("/")
) {
return value.slice(1, -1); return value.slice(1, -1);
} }