Skip to content

Commit

Permalink
Fixed #62
Browse files Browse the repository at this point in the history
  • Loading branch information
ozziest committed Oct 27, 2024
1 parent b738383 commit fb814bd
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
3 changes: 2 additions & 1 deletion src/rules/isIn.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export default (value: any, list: any[]): boolean => {
export default (value: any, options: any[] | string): boolean => {
const list: any[] = Array.isArray(options) ? options : options.split(",");
const listAsString = list.map((item) => String(item).trim());

if (Array.isArray(value)) {
Expand Down
3 changes: 2 additions & 1 deletion src/rules/isNotIn.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
export default (value: any, list: any[]): boolean => {
export default (value: any, options: any[] | string): boolean => {
if (value === null || value === undefined) {
return false;
}

const list: any[] = Array.isArray(options) ? options : options.split(",");
const listAsString = list.map((item) => String(item).trim());

if (Array.isArray(value)) {
Expand Down
4 changes: 4 additions & 0 deletions tests/rules/in.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,8 @@ describe("isIn() ", () => {
expect(isIn("A", ["a", "b", "c"])).toBe(false);
expect(isIn("A", ["A", "B", "C"])).toBe(true);
});

it("should be able to parse string values", async () => {
expect(isIn("A", "A,B,B")).toBe(true);
});
});
5 changes: 5 additions & 0 deletions tests/rules/notIn.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,9 @@ describe("isNotIn() ", () => {
expect(isNotIn("A", ["a", "b", "c"])).toBe(true);
expect(isNotIn("A", ["A", "B", "C"])).toBe(false);
});

it("should be able to parse string values", async () => {
expect(isNotIn("A", "a,b,c")).toBe(true);
expect(isNotIn("A", "A,B,C")).toBe(false);
});
});

0 comments on commit fb814bd

Please sign in to comment.