Browse Source

feat: add comparison handler

Ahmad Kholid 3 years ago
parent
commit
c7a529e712
1 changed files with 16 additions and 0 deletions
  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;
+}