We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 2166204 commit 02114dcCopy full SHA for 02114dc
src/rules/isIn.ts
@@ -1,5 +1,15 @@
1
-export default (value: any, options: any[] | string): boolean => {
2
- const list: any[] = Array.isArray(options) ? options : options.split(",");
+export default (value: any, ...args: any[]): boolean => {
+ // Let's check the last item is IContext
3
+ const lastItem: any = args.at(-1);
4
+ if (lastItem.definition && lastItem.field) {
5
+ args.pop();
6
+ }
7
+
8
+ const [options] = args;
9
10
+ const list: any[] = Array.isArray(options)
11
+ ? options
12
+ : (options as string).split(",");
13
const listAsString = list.map((item) => String(item).trim());
14
15
if (Array.isArray(value)) {
tests/rules/in.test.ts
@@ -43,5 +43,18 @@ describe("isIn() ", () => {
43
44
it("should be able to parse string values", async () => {
45
expect(isIn("A", "A,B,B")).toBe(true);
46
+ expect(isIn("B", "A,B,C")).toBe(true);
47
+ expect(isIn("C", "A,B,C")).toBe(true);
48
+ expect(isIn("D", "A,B,C")).toBe(false);
49
50
+ expect(isIn("a", ["a", "b", "c"])).toBe(true);
51
+ expect(isIn("b", ["a", "b", "c"])).toBe(true);
52
+ expect(isIn("c", ["a", "b", "c"])).toBe(true);
53
+ expect(isIn("d", ["a", "b", "c"])).toBe(false);
54
+ });
55
56
+ it("should be able to work with spread-string options", async () => {
57
+ expect(isIn("A", ...["A,B,B"])).toBe(true);
58
+ expect(isIn("A", ...["A", "B", "C"])).toBe(true);
59
});
60
0 commit comments