1
0
Эх сурвалжийг харах

Merge pull request #596 from mgilangjanuar/dev

feat: add rgx comparison
Ahmad Kholid 2 жил өмнө
parent
commit
128763a4ad

+ 1 - 0
src/utils/shared.js

@@ -1233,6 +1233,7 @@ export const conditionBuilder = {
     { id: 'nct', name: 'Not contains', needValue: true, category: 'text' },
     { id: 'stw', name: 'Starts with', needValue: true, category: 'text' },
     { id: 'enw', name: 'Ends with', needValue: true, category: 'text' },
+    { id: 'rgx', name: 'Match with RegEx', needValue: true, category: 'text' },
     { id: 'itr', name: 'Is truthy', needValue: false, category: 'boolean' },
     { id: 'ifl', name: 'Is falsy', needValue: false, category: 'boolean' },
   ],

+ 5 - 0
src/utils/testConditions.js

@@ -21,6 +21,11 @@ const comparisons = {
   nct: (a, b) => !comparisons.cnt(a, b),
   stw: (a, b) => a?.startsWith(b) ?? false,
   enw: (a, b) => a?.endsWith(b) ?? false,
+  rgx: (a, b) => {
+    const match = b.match(/^\/(.*?)\/([gimy]*)$/);
+    const regex = new RegExp(match[1], match[2]);
+    return regex.test(a);
+  },
   itr: (a) => Boolean(isBoolStr(a)),
   ifl: (a) => !isBoolStr(a),
 };