浏览代码

Merge pull request #596 from mgilangjanuar/dev

feat: add rgx comparison
Ahmad Kholid 2 年之前
父节点
当前提交
128763a4ad
共有 2 个文件被更改,包括 6 次插入0 次删除
  1. 1 0
      src/utils/shared.js
  2. 5 0
      src/utils/testConditions.js

+ 1 - 0
src/utils/shared.js

@@ -1233,6 +1233,7 @@ export const conditionBuilder = {
     { id: 'nct', name: 'Not contains', needValue: true, category: 'text' },
     { id: 'nct', name: 'Not contains', needValue: true, category: 'text' },
     { id: 'stw', name: 'Starts with', needValue: true, category: 'text' },
     { id: 'stw', name: 'Starts with', needValue: true, category: 'text' },
     { id: 'enw', name: 'Ends 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: 'itr', name: 'Is truthy', needValue: false, category: 'boolean' },
     { id: 'ifl', name: 'Is falsy', 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),
   nct: (a, b) => !comparisons.cnt(a, b),
   stw: (a, b) => a?.startsWith(b) ?? false,
   stw: (a, b) => a?.startsWith(b) ?? false,
   enw: (a, b) => a?.endsWith(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)),
   itr: (a) => Boolean(isBoolStr(a)),
   ifl: (a) => !isBoolStr(a),
   ifl: (a) => !isBoolStr(a),
 };
 };