Skip to content

Commit

Permalink
fix: include check for contain fn
Browse files Browse the repository at this point in the history
  • Loading branch information
lawvs committed Aug 12, 2024
1 parent 4a6e88a commit 063a45d
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/core/src/presets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,17 @@ const genericContainFilter = defineGenericFn([
target: string | unknown | unknown[],
) => {
if (typeof value === "string" && typeof target === "string") {
// z.ZodString
return value.includes(target);
}
if (Array.isArray(value)) {
// z.ZodArray<z.ZodType>
return value.includes(target);
}
if (typeof value === "string" && Array.isArray(target)) {
// z.ZodUnion<[z.ZodLiteral<z.Primitive>]>
return target.includes(value);
}
throw new Error("Invalid input type!");
},
},
Expand Down Expand Up @@ -310,6 +316,9 @@ const genericContainFilter = defineGenericFn([
if (Array.isArray(value)) {
return !value.includes(target);
}
if (typeof value === "string" && Array.isArray(target)) {
return target.includes(value);
}
throw new Error("Invalid input type!");
},
},
Expand Down

0 comments on commit 063a45d

Please sign in to comment.