|
|
|
@ -1,4 +1,4 @@ |
|
|
|
import { Operator } from '.'; |
|
|
|
import { Operator } from './BaseOperator'; |
|
|
|
|
|
|
|
export enum StringOperation { |
|
|
|
contains = 'contains', |
|
|
|
@ -9,13 +9,9 @@ export enum StringOperation { |
|
|
|
trimEquals = 'trimEquals', |
|
|
|
} |
|
|
|
|
|
|
|
export class StringOperator extends Operator { |
|
|
|
constructor(private operator: StringOperation) { |
|
|
|
super(); |
|
|
|
} |
|
|
|
|
|
|
|
export class StringOperator extends Operator<StringOperation> { |
|
|
|
evaluate(left: string, right: string) { |
|
|
|
switch (this.operator) { |
|
|
|
switch (this.operation) { |
|
|
|
case StringOperation.contains: |
|
|
|
return left.includes(right); |
|
|
|
case StringOperation.startsWith: |
|
|
|
@ -23,14 +19,15 @@ export class StringOperator extends Operator { |
|
|
|
case StringOperation.endsWith: |
|
|
|
return left.endsWith(right); |
|
|
|
case StringOperation.matchesRegex: |
|
|
|
if (!right) throw new Error('Regex pattern must be provided.'); |
|
|
|
if (!right) this.em.logError('Regex pattern must be provided.'); |
|
|
|
return new RegExp(right).test(left); |
|
|
|
case StringOperation.equalsIgnoreCase: |
|
|
|
return left.toLowerCase() === right.toLowerCase(); |
|
|
|
case StringOperation.trimEquals: |
|
|
|
return left.trim() === right.trim(); |
|
|
|
default: |
|
|
|
throw new Error(`Unsupported string operator: ${this.operator}`); |
|
|
|
this.em.logError(`Unsupported string operation: ${this.operation}`); |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
} |