瀏覽代碼

feat: add comparison handler

Ahmad Kholid 3 年之前
父節點
當前提交
c7a529e712
共有 1 個文件被更改,包括 16 次插入0 次删除
  1. 16 0
      src/utils/compare-block-value.js

+ 16 - 0
src/utils/compare-block-value.js

@@ -0,0 +1,16 @@
+const handlers = {
+  '==': (a, b) => a === b,
+  '>': (a, b) => a > b,
+  '>=': (a, b) => a >= b,
+  '<': (a, b) => a < b,
+  '<=': (a, b) => a <= b,
+  '()': (a, b) => a?.includes(b) ?? false,
+};
+
+export default function (type, valueA, valueB) {
+  const handler = handlers[type];
+
+  if (handler) return handler(valueA, valueB);
+
+  return false;
+}