@molassesapp/common
Advanced tools
Comparing version 0.2.7 to 0.3.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [0.3.0](https://github.com/molassesapp/molasses-node/compare/v0.2.7...v0.3.0) (2020-07-25) | ||
### Features | ||
* Add constraint field to FeatureSegment ([e645ff7](https://github.com/molassesapp/molasses-node/commit/e645ff789959496c442c6d3f206a715a51444687)) | ||
## [0.2.7](https://github.com/molassesapp/molasses-node/compare/v0.2.6...v0.2.7) (2020-07-23) | ||
@@ -8,0 +19,0 @@ |
@@ -12,2 +12,3 @@ export interface Feature { | ||
segmentType: SegmentType; | ||
constraint: Operator; | ||
} | ||
@@ -27,2 +28,3 @@ export interface UserConstraint { | ||
export declare enum Operator { | ||
any = "any", | ||
all = "all", | ||
@@ -29,0 +31,0 @@ in = "in", |
@@ -13,2 +13,3 @@ "use strict"; | ||
(function (Operator) { | ||
Operator["any"] = "any"; | ||
Operator["all"] = "all"; | ||
@@ -75,2 +76,4 @@ Operator["in"] = "in"; | ||
var isUserInSegment = function (user, s) { | ||
var constraintsToBeMet = s.constraint == Operator.any ? 1 : s.userConstraints.length; | ||
var constraintsMet = 0; | ||
for (var index = 0; index < s.userConstraints.length; index++) { | ||
@@ -84,39 +87,45 @@ var constraint = s.userConstraints[index]; | ||
} | ||
switch (constraint.operator) { | ||
case Operator.in: | ||
if (paramExists && containsParamValue(constraint.values, userValue)) { | ||
return true; | ||
} | ||
break; | ||
case Operator.nin: | ||
if (paramExists && !containsParamValue(constraint.values, userValue)) { | ||
return true; | ||
} | ||
break; | ||
case Operator.equals: | ||
if (paramExists && userValue === constraint.values) { | ||
return true; | ||
} | ||
break; | ||
case Operator.doesNotEqual: | ||
if (paramExists && userValue !== constraint.values) { | ||
return true; | ||
} | ||
break; | ||
case Operator.contains: | ||
if (paramExists && userValue.includes(constraint.values)) { | ||
return true; | ||
} | ||
break; | ||
case Operator.doesNotContain: | ||
if (paramExists && !userValue.includes(constraint.values)) { | ||
return true; | ||
} | ||
break; | ||
default: | ||
return false; | ||
if (meetsConstraint(userValue, paramExists, constraint)) { | ||
constraintsMet = constraintsMet + 1; | ||
} | ||
} | ||
return constraintsMet >= constraintsToBeMet; | ||
}; | ||
var meetsConstraint = function (userValue, paramExists, constraint) { | ||
switch (constraint.operator) { | ||
case Operator.in: | ||
if (paramExists && containsParamValue(constraint.values, userValue)) { | ||
return true; | ||
} | ||
break; | ||
case Operator.nin: | ||
if (paramExists && !containsParamValue(constraint.values, userValue)) { | ||
return true; | ||
} | ||
break; | ||
case Operator.equals: | ||
if (paramExists && userValue === constraint.values) { | ||
return true; | ||
} | ||
break; | ||
case Operator.doesNotEqual: | ||
if (paramExists && userValue !== constraint.values) { | ||
return true; | ||
} | ||
break; | ||
case Operator.contains: | ||
if (paramExists && userValue.includes(constraint.values)) { | ||
return true; | ||
} | ||
break; | ||
case Operator.doesNotContain: | ||
if (paramExists && !userValue.includes(constraint.values)) { | ||
return true; | ||
} | ||
break; | ||
default: | ||
return false; | ||
} | ||
return false; | ||
}; | ||
//# sourceMappingURL=feature.js.map |
{ | ||
"name": "@molassesapp/common", | ||
"version": "0.2.7", | ||
"version": "0.3.0", | ||
"description": "This is the common package for the @molasses node work - do not install instead use molasses-js or molasses-server", | ||
@@ -31,3 +31,3 @@ "keywords": [], | ||
}, | ||
"gitHead": "cec205e3f489be85036bb485082931dc4882924c", | ||
"gitHead": "1ed9670de84fd070f6049e644a29e73fae0e14ad", | ||
"dependencies": { | ||
@@ -34,0 +34,0 @@ "crc-32": "^1.2.0" |
@@ -16,2 +16,3 @@ import { str } from "crc-32" | ||
segmentType: SegmentType | ||
constraint: Operator | ||
} | ||
@@ -33,2 +34,3 @@ export interface UserConstraint { | ||
export enum Operator { | ||
any = "any", | ||
all = "all", | ||
@@ -114,2 +116,5 @@ in = "in", | ||
const isUserInSegment = (user: User, s: FeatureSegment) => { | ||
const constraintsToBeMet = s.constraint == Operator.any ? 1 : s.userConstraints.length | ||
let constraintsMet = 0 | ||
for (let index = 0; index < s.userConstraints.length; index++) { | ||
@@ -124,39 +129,46 @@ const constraint = s.userConstraints[index] | ||
} | ||
switch (constraint.operator) { | ||
case Operator.in: | ||
if (paramExists && containsParamValue(constraint.values, userValue)) { | ||
return true | ||
} | ||
break | ||
case Operator.nin: | ||
if (paramExists && !containsParamValue(constraint.values, userValue)) { | ||
return true | ||
} | ||
break | ||
case Operator.equals: | ||
if (paramExists && userValue === constraint.values) { | ||
return true | ||
} | ||
break | ||
case Operator.doesNotEqual: | ||
if (paramExists && userValue !== constraint.values) { | ||
return true | ||
} | ||
break | ||
case Operator.contains: | ||
if (paramExists && userValue.includes(constraint.values)) { | ||
return true | ||
} | ||
break | ||
case Operator.doesNotContain: | ||
if (paramExists && !userValue.includes(constraint.values)) { | ||
return true | ||
} | ||
break | ||
default: | ||
return false | ||
if (meetsConstraint(userValue, paramExists, constraint)) { | ||
constraintsMet = constraintsMet + 1 | ||
} | ||
} | ||
return constraintsMet >= constraintsToBeMet | ||
} | ||
const meetsConstraint = (userValue: string, paramExists: boolean, constraint: UserConstraint) => { | ||
switch (constraint.operator) { | ||
case Operator.in: | ||
if (paramExists && containsParamValue(constraint.values, userValue)) { | ||
return true | ||
} | ||
break | ||
case Operator.nin: | ||
if (paramExists && !containsParamValue(constraint.values, userValue)) { | ||
return true | ||
} | ||
break | ||
case Operator.equals: | ||
if (paramExists && userValue === constraint.values) { | ||
return true | ||
} | ||
break | ||
case Operator.doesNotEqual: | ||
if (paramExists && userValue !== constraint.values) { | ||
return true | ||
} | ||
break | ||
case Operator.contains: | ||
if (paramExists && userValue.includes(constraint.values)) { | ||
return true | ||
} | ||
break | ||
case Operator.doesNotContain: | ||
if (paramExists && !userValue.includes(constraint.values)) { | ||
return true | ||
} | ||
break | ||
default: | ||
return false | ||
} | ||
return false | ||
} |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
20383
16
402
1