Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fully supports comparison for data in Array data with all comparator … #444

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 26 additions & 1 deletion src/anonymousUserTracking/criteriaCompletionChecker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}

class CriteriaCompletionChecker {
private localStoredEventList: any[];

Check warning on line 39 in src/anonymousUserTracking/criteriaCompletionChecker.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type

constructor(localStoredEventList: string) {
this.localStoredEventList = JSON.parse(localStoredEventList);
Expand Down Expand Up @@ -72,9 +72,9 @@
return matchingCriteria ? matchingCriteria.criteriaId : null;
}

private prepareEventsToProcess(): any[] {

Check warning on line 75 in src/anonymousUserTracking/criteriaCompletionChecker.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
const eventsToProcess: any[] = this.getEventsWithCartItems();

Check warning on line 76 in src/anonymousUserTracking/criteriaCompletionChecker.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
const nonPurchaseEvents: any[] = this.getNonCartEvents();

Check warning on line 77 in src/anonymousUserTracking/criteriaCompletionChecker.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type

nonPurchaseEvents.forEach((event) => {
eventsToProcess.push(event);
Expand All @@ -83,7 +83,7 @@
return eventsToProcess;
}

private getEventsWithCartItems(): any[] {

Check warning on line 86 in src/anonymousUserTracking/criteriaCompletionChecker.ts

View workflow job for this annotation

GitHub Actions / build

Unexpected any. Specify a different type
const processedEvents: any[] = [];

this.localStoredEventList.forEach((localEventData) => {
Expand Down Expand Up @@ -470,6 +470,12 @@
}

private compareValueEquality(sourceTo: any, stringValue: string): boolean {
if (Array.isArray(sourceTo)) {
return sourceTo.some((source) =>
this.compareValueEquality(source, stringValue)
);
}

if (
(typeof sourceTo === 'number' || typeof sourceTo === 'boolean') &&
stringValue !== ''
Expand All @@ -493,7 +499,13 @@
compareOperator: string
): boolean {
// eslint-disable-next-line no-restricted-globals
if (!isNaN(parseFloat(stringValue))) {
if (Array.isArray(sourceTo)) {
return sourceTo.some((source) =>
this.compareNumericValues(source, stringValue, compareOperator)
);
}

if (!Number.isNaN(parseFloat(stringValue))) {
const sourceNumber = parseFloat(sourceTo);
const numericValue = parseFloat(stringValue);
switch (compareOperator) {
Expand All @@ -513,17 +525,30 @@
}

private compareStringContains(sourceTo: any, stringValue: string): boolean {
if (Array.isArray(sourceTo)) {
return sourceTo.some((source) =>
this.compareStringContains(source, stringValue)
);
}
return (
(typeof sourceTo === 'string' || typeof sourceTo === 'object') &&
sourceTo.includes(stringValue)
);
}

private compareStringStartsWith(sourceTo: any, stringValue: string): boolean {
if (Array.isArray(sourceTo)) {
return sourceTo.some((source) =>
this.compareStringStartsWith(source, stringValue)
);
}
return typeof sourceTo === 'string' && sourceTo.startsWith(stringValue);
}

private compareWithRegex(sourceTo: string, pattern: string): boolean {
if (Array.isArray(sourceTo)) {
return sourceTo.some((source) => this.compareWithRegex(source, pattern));
}
try {
const regexPattern = new RegExp(pattern);
return regexPattern.test(sourceTo);
Expand Down
Loading
Loading