@molassesapp/common
Advanced tools
Comparing version 0.6.0 to 0.7.0
@@ -6,2 +6,10 @@ # Change Log | ||
# [0.7.0](https://github.com/molassesapp/molasses-node/compare/v0.6.2...v0.7.0) (2021-02-11) | ||
**Note:** Version bump only for package @molassesapp/common | ||
# [0.6.0](https://github.com/molassesapp/molasses-node/compare/v0.5.0...v0.6.0) (2021-01-19) | ||
@@ -8,0 +16,0 @@ |
@@ -26,2 +26,7 @@ export interface Feature { | ||
} | ||
export declare enum UserParamType { | ||
number = "number", | ||
boolean = "boolean", | ||
string = "string" | ||
} | ||
export declare enum Operator { | ||
@@ -36,11 +41,12 @@ any = "any", | ||
doesNotContain = "doesNotContain", | ||
greaterThan = "greaterThan", | ||
lessThan = "lessThan", | ||
greaterThanOrEqualTo = "greaterThanOrEqualTo", | ||
lessThanOrEqualTo = "lessThanOrEqualTo" | ||
greaterThan = "gt", | ||
lessThan = "lt", | ||
greaterThanOrEqualTo = "gte", | ||
lessThanOrEqualTo = "lte" | ||
} | ||
export declare type InputType = string | number | boolean; | ||
export interface User { | ||
id: string; | ||
params: { | ||
[key: string]: string; | ||
[key: string]: InputType; | ||
}; | ||
@@ -47,0 +53,0 @@ } |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.isActive = exports.getUserPercentage = exports.Operator = exports.SegmentType = void 0; | ||
exports.isActive = exports.getUserPercentage = exports.Operator = exports.UserParamType = exports.SegmentType = void 0; | ||
var crc32 = require("crc").crc32; | ||
@@ -11,2 +11,8 @@ var SegmentType; | ||
})(SegmentType = exports.SegmentType || (exports.SegmentType = {})); | ||
var UserParamType; | ||
(function (UserParamType) { | ||
UserParamType["number"] = "number"; | ||
UserParamType["boolean"] = "boolean"; | ||
UserParamType["string"] = "string"; | ||
})(UserParamType = exports.UserParamType || (exports.UserParamType = {})); | ||
var Operator; | ||
@@ -22,6 +28,6 @@ (function (Operator) { | ||
Operator["doesNotContain"] = "doesNotContain"; | ||
Operator["greaterThan"] = "greaterThan"; | ||
Operator["lessThan"] = "lessThan"; | ||
Operator["greaterThanOrEqualTo"] = "greaterThanOrEqualTo"; | ||
Operator["lessThanOrEqualTo"] = "lessThanOrEqualTo"; | ||
Operator["greaterThan"] = "gt"; | ||
Operator["lessThan"] = "lt"; | ||
Operator["greaterThanOrEqualTo"] = "gte"; | ||
Operator["lessThanOrEqualTo"] = "lte"; | ||
})(Operator = exports.Operator || (exports.Operator = {})); | ||
@@ -87,4 +93,21 @@ exports.getUserPercentage = function (id, percentage) { | ||
} | ||
if (meetsConstraint(userValue, paramExists, constraint)) { | ||
constraintsMet = constraintsMet + 1; | ||
switch (constraint.userParamType) { | ||
case UserParamType.number: | ||
var valueNumber = parseNumber(userValue); | ||
if (meetsConstraintForNumber(valueNumber, paramExists, constraint)) { | ||
constraintsMet = constraintsMet + 1; | ||
} | ||
break; | ||
case UserParamType.boolean: | ||
var valueBoolean = parseBoolean(userValue); | ||
if (meetsConstraintForBool(valueBoolean, paramExists, constraint)) { | ||
constraintsMet = constraintsMet + 1; | ||
} | ||
break; | ||
default: | ||
var value = parseString(userValue); | ||
if (meetsConstraint(value, paramExists, constraint)) { | ||
constraintsMet = constraintsMet + 1; | ||
} | ||
break; | ||
} | ||
@@ -94,2 +117,49 @@ } | ||
}; | ||
var parseNumber = function (value) { | ||
switch (typeof value) { | ||
case "boolean": | ||
return 0; | ||
case "number": | ||
return value; | ||
default: | ||
return parseFloat(value); | ||
} | ||
}; | ||
var parseString = function (value) { | ||
switch (typeof value) { | ||
case "boolean": | ||
case "number": | ||
return value.toString(); | ||
default: | ||
return value; | ||
} | ||
}; | ||
var parseBoolean = function (value) { | ||
switch (typeof value) { | ||
case "string": | ||
return value === "true"; | ||
case "number": | ||
return !!value; | ||
default: | ||
return value; | ||
} | ||
}; | ||
var meetsConstraintForBool = function (userValue, paramExists, constraint) { | ||
var value = constraint.values === "true"; | ||
switch (constraint.operator) { | ||
case Operator.equals: | ||
if (paramExists && userValue === value) { | ||
return true; | ||
} | ||
break; | ||
case Operator.doesNotEqual: | ||
if (paramExists && userValue !== value) { | ||
return true; | ||
} | ||
break; | ||
default: | ||
return false; | ||
} | ||
return false; | ||
}; | ||
var meetsConstraint = function (userValue, paramExists, constraint) { | ||
@@ -132,2 +202,40 @@ switch (constraint.operator) { | ||
}; | ||
var meetsConstraintForNumber = function (userValue, paramExists, constraint) { | ||
var value = parseFloat(constraint.values); | ||
switch (constraint.operator) { | ||
case Operator.equals: | ||
if (paramExists && userValue === value) { | ||
return true; | ||
} | ||
break; | ||
case Operator.doesNotEqual: | ||
if (paramExists && userValue !== value) { | ||
return true; | ||
} | ||
break; | ||
case Operator.lessThan: | ||
if (paramExists && userValue < value) { | ||
return true; | ||
} | ||
break; | ||
case Operator.lessThanOrEqualTo: | ||
if (paramExists && userValue <= value) { | ||
return true; | ||
} | ||
break; | ||
case Operator.greaterThan: | ||
if (paramExists && userValue > value) { | ||
return true; | ||
} | ||
break; | ||
case Operator.greaterThanOrEqualTo: | ||
if (paramExists && userValue >= value) { | ||
return true; | ||
} | ||
break; | ||
default: | ||
return false; | ||
} | ||
return false; | ||
}; | ||
//# sourceMappingURL=feature.js.map |
{ | ||
"name": "@molassesapp/common", | ||
"version": "0.6.0", | ||
"version": "0.7.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": "e3aedefc4479c87c4bb5a476fb5e5cf4d504e4b1", | ||
"gitHead": "08a103b26f8016492970455345d2591d781c6c62", | ||
"dependencies": { | ||
@@ -34,0 +34,0 @@ "crc": "^3.8.0" |
@@ -9,3 +9,2 @@ const { crc32 } = require("crc") | ||
segments: FeatureSegment[] | ||
// tags: Tag[]; | ||
} | ||
@@ -32,3 +31,7 @@ | ||
} | ||
export enum UserParamType { | ||
number = "number", | ||
boolean = "boolean", | ||
string = "string", | ||
} | ||
export enum Operator { | ||
@@ -43,11 +46,13 @@ any = "any", | ||
doesNotContain = "doesNotContain", | ||
greaterThan = "greaterThan", | ||
lessThan = "lessThan", | ||
greaterThanOrEqualTo = "greaterThanOrEqualTo", | ||
lessThanOrEqualTo = "lessThanOrEqualTo", | ||
greaterThan = "gt", | ||
lessThan = "lt", | ||
greaterThanOrEqualTo = "gte", | ||
lessThanOrEqualTo = "lte", | ||
} | ||
export type InputType = string | number | boolean | ||
export interface User { | ||
id: string | ||
params: { | ||
[key: string]: string | ||
[key: string]: InputType | ||
} | ||
@@ -125,2 +130,3 @@ } | ||
let userValue = user.params[constraint.userParam] | ||
if (constraint.userParam == "id") { | ||
@@ -130,4 +136,22 @@ paramExists = true | ||
} | ||
if (meetsConstraint(userValue, paramExists, constraint)) { | ||
constraintsMet = constraintsMet + 1 | ||
switch (constraint.userParamType) { | ||
case UserParamType.number: | ||
const valueNumber = parseNumber(userValue) | ||
if (meetsConstraintForNumber(valueNumber as number, paramExists, constraint)) { | ||
constraintsMet = constraintsMet + 1 | ||
} | ||
break | ||
case UserParamType.boolean: | ||
const valueBoolean = parseBoolean(userValue) | ||
if (meetsConstraintForBool(valueBoolean as boolean, paramExists, constraint)) { | ||
constraintsMet = constraintsMet + 1 | ||
} | ||
break | ||
default: | ||
const value = parseString(userValue) | ||
if (meetsConstraint(value as string, paramExists, constraint)) { | ||
constraintsMet = constraintsMet + 1 | ||
} | ||
break | ||
} | ||
@@ -139,2 +163,57 @@ } | ||
const parseNumber = (value: string | boolean | number): number => { | ||
switch (typeof value) { | ||
case "boolean": | ||
return 0 | ||
case "number": | ||
return value | ||
default: | ||
return parseFloat(value) | ||
} | ||
} | ||
const parseString = (value: string | boolean | number): string => { | ||
switch (typeof value) { | ||
case "boolean": | ||
case "number": | ||
return value.toString() | ||
default: | ||
return value | ||
} | ||
} | ||
const parseBoolean = (value: string | boolean | number): boolean => { | ||
switch (typeof value) { | ||
case "string": | ||
return value === "true" | ||
case "number": | ||
return !!value | ||
default: | ||
return value | ||
} | ||
} | ||
const meetsConstraintForBool = ( | ||
userValue: boolean, | ||
paramExists: boolean, | ||
constraint: UserConstraint, | ||
) => { | ||
const value = constraint.values === "true" | ||
switch (constraint.operator) { | ||
case Operator.equals: | ||
if (paramExists && userValue === value) { | ||
return true | ||
} | ||
break | ||
case Operator.doesNotEqual: | ||
if (paramExists && userValue !== value) { | ||
return true | ||
} | ||
break | ||
default: | ||
return false | ||
} | ||
return false | ||
} | ||
const meetsConstraint = (userValue: string, paramExists: boolean, constraint: UserConstraint) => { | ||
@@ -177,1 +256,44 @@ switch (constraint.operator) { | ||
} | ||
const meetsConstraintForNumber = ( | ||
userValue: number, | ||
paramExists: boolean, | ||
constraint: UserConstraint, | ||
) => { | ||
const value = parseFloat(constraint.values) | ||
switch (constraint.operator) { | ||
case Operator.equals: | ||
if (paramExists && userValue === value) { | ||
return true | ||
} | ||
break | ||
case Operator.doesNotEqual: | ||
if (paramExists && userValue !== value) { | ||
return true | ||
} | ||
break | ||
case Operator.lessThan: | ||
if (paramExists && userValue < value) { | ||
return true | ||
} | ||
break | ||
case Operator.lessThanOrEqualTo: | ||
if (paramExists && userValue <= value) { | ||
return true | ||
} | ||
break | ||
case Operator.greaterThan: | ||
if (paramExists && userValue > value) { | ||
return true | ||
} | ||
break | ||
case Operator.greaterThanOrEqualTo: | ||
if (paramExists && userValue >= value) { | ||
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
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
30303
636