Skip to content

Commit a2b7c16

Browse files
authored
OneOf operator should be case insensitive (#6)
* OneOf operator should be case insensitive * 0.0.6
1 parent 91a3e77 commit a2b7c16

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@eppo/js-client-sdk",
3-
"version": "0.0.5",
3+
"version": "0.0.6",
44
"description": "Eppo SDK for client-side JavaScript applications",
55
"main": "dist/index.js",
66
"files": [

src/rule_evaluator.spec.ts

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,33 @@ describe('matchesAnyRule', () => {
117117
expect(matchesAnyRule({ userId: 'user15' }, [notOneOfRule])).toEqual(true);
118118
});
119119

120+
it('does case insensitive matching with oneOf operator', () => {
121+
const oneOfRule: Rule = {
122+
conditions: [
123+
{
124+
operator: OperatorType.ONE_OF,
125+
value: ['CA', 'US'],
126+
attribute: 'country',
127+
},
128+
],
129+
};
130+
expect(matchesAnyRule({ country: 'us' }, [oneOfRule])).toEqual(true);
131+
expect(matchesAnyRule({ country: 'cA' }, [oneOfRule])).toEqual(true);
132+
});
133+
134+
it('does case insensitive matching with notOneOf operator', () => {
135+
const notOneOf: Rule = {
136+
conditions: [
137+
{
138+
operator: OperatorType.NOT_ONE_OF,
139+
value: ['1.0.BB', '1Ab'],
140+
attribute: 'deviceType',
141+
},
142+
],
143+
};
144+
expect(matchesAnyRule({ deviceType: '1ab' }, [notOneOf])).toEqual(false);
145+
});
146+
120147
it('handles oneOf rule with number', () => {
121148
const oneOfRule: Rule = {
122149
conditions: [

src/rule_evaluator.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,15 @@ function evaluateCondition(subjectAttributes: Record<string, any>, condition: Co
4646
}
4747

4848
function isOneOf(attributeValue: any, conditionValue: string[]) {
49-
return conditionValue.includes(attributeValue.toString());
49+
return getMatchingStringValues(attributeValue.toString(), conditionValue).length > 0;
5050
}
5151

5252
function isNotOneOf(attributeValue: any, conditionValue: string[]) {
53-
return !conditionValue.includes(attributeValue.toString());
53+
return getMatchingStringValues(attributeValue.toString(), conditionValue).length === 0;
54+
}
55+
56+
function getMatchingStringValues(attributeValue: string, conditionValues: string[]): string[] {
57+
return conditionValues.filter((value) => value.toLowerCase() === attributeValue.toLowerCase());
5458
}
5559

5660
function compareNumber(

0 commit comments

Comments
 (0)