Browse Source
Identical rule evaluation logic existed in ConditionalSwitchNode.tsx and workflowStore.ts. Extract to src/store/utils/ruleEvaluation.ts and import from both locations. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>handoff-20260429-1057
3 changed files with 42 additions and 74 deletions
@ -0,0 +1,37 @@ |
|||||
|
import type { MatchMode } from "@/types"; |
||||
|
|
||||
|
/** |
||||
|
* Evaluates a rule against incoming text with the specified match mode. |
||||
|
* Returns true if any comma-separated value matches using OR logic. |
||||
|
*/ |
||||
|
export function evaluateRule(text: string | null, ruleValue: string, mode: MatchMode): boolean { |
||||
|
// Guard: no match if text or ruleValue is empty
|
||||
|
if (!text || !ruleValue) return false; |
||||
|
|
||||
|
// Normalize text
|
||||
|
const normalizedText = text.toLowerCase().trim(); |
||||
|
|
||||
|
// Split and normalize rule values (comma-separated)
|
||||
|
const values = ruleValue |
||||
|
.split(',') |
||||
|
.map(v => v.toLowerCase().trim()) |
||||
|
.filter(v => v.length > 0); |
||||
|
|
||||
|
if (values.length === 0) return false; |
||||
|
|
||||
|
// OR logic: match if ANY value matches
|
||||
|
return values.some(value => { |
||||
|
switch (mode) { |
||||
|
case "exact": |
||||
|
return normalizedText === value; |
||||
|
case "contains": |
||||
|
return normalizedText.includes(value); |
||||
|
case "starts-with": |
||||
|
return normalizedText.startsWith(value); |
||||
|
case "ends-with": |
||||
|
return normalizedText.endsWith(value); |
||||
|
default: |
||||
|
return false; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
Loading…
Reference in new issue