Skip to content

Commit b62522b

Browse files
authoredDec 26, 2023
Merge pull request #374 from Martinarbez/feat/add.ilike.operator
feat/add.ilike.operator
2 parents cbd5337 + 0533585 commit b62522b

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed
 

‎src/utils/operators.ts

+17-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
export type OperatorName = "eq" | "ne" | "lt" | "gt" | "le" | "ge" | "like" | "nlike" | "in" | "nin";
1+
export type OperatorName = "eq" | "ne" | "lt" | "gt" | "le" | "ge" | "like" | "nlike" | "ilike"| "in" | "nin";
22

33
export const KnexOperators = {
44
eq: "=",
@@ -9,6 +9,7 @@ export const KnexOperators = {
99
ge: ">=",
1010
like: "like",
1111
nlike: "not like",
12+
ilike: "ilike",
1213
in: "in",
1314
nin: "not in",
1415
};
@@ -50,6 +51,21 @@ export const FunctionalOperators: { [T in OperatorName]: (actual: any, expected:
5051

5152
return false;
5253
},
54+
ilike: (actual: string, expected: string) => {
55+
if (expected.startsWith("%") && expected.endsWith("%")) {
56+
return actual.includes(expected.replace(/%/g, ""));
57+
}
58+
59+
if (expected.startsWith("%")) {
60+
return actual.endsWith(expected.replace(/%/g, ""));
61+
}
62+
63+
if (expected.endsWith("%")) {
64+
return actual.startsWith(expected.replace(/%/g, ""));
65+
}
66+
67+
return false;
68+
},
5369
in: <T = any>(actual: T, expected: T[]) => expected.includes(actual),
5470
nin: <T = any>(actual: T, expected: T[]) => !expected.includes(actual),
5571
};

0 commit comments

Comments
 (0)