@molassesapp/common
Advanced tools
Comparing version 0.7.0 to 0.8.0
@@ -6,2 +6,13 @@ # Change Log | ||
# [0.8.0](https://github.com/molassesapp/molasses-node/compare/v0.7.0...v0.8.0) (2021-07-10) | ||
### Features | ||
* Add support for semver and upgrade dependencies ([e07e019](https://github.com/molassesapp/molasses-node/commit/e07e0198e0790fbc4ee5272ce55d0d35bf216b13)) | ||
# [0.7.0](https://github.com/molassesapp/molasses-node/compare/v0.6.2...v0.7.0) (2021-02-11) | ||
@@ -8,0 +19,0 @@ |
@@ -29,3 +29,4 @@ export interface Feature { | ||
boolean = "boolean", | ||
string = "string" | ||
string = "string", | ||
semver = "semver" | ||
} | ||
@@ -32,0 +33,0 @@ export declare enum Operator { |
@@ -5,2 +5,3 @@ "use strict"; | ||
var crc32 = require("crc").crc32; | ||
var compare = require("semver/functions/compare-loose"); | ||
var SegmentType; | ||
@@ -17,2 +18,3 @@ (function (SegmentType) { | ||
UserParamType["string"] = "string"; | ||
UserParamType["semver"] = "semver"; | ||
})(UserParamType = exports.UserParamType || (exports.UserParamType = {})); | ||
@@ -34,3 +36,3 @@ var Operator; | ||
})(Operator = exports.Operator || (exports.Operator = {})); | ||
exports.getUserPercentage = function (id, percentage) { | ||
var getUserPercentage = function (id, percentage) { | ||
if (percentage === 100) { | ||
@@ -46,3 +48,4 @@ return true; | ||
}; | ||
exports.isActive = function (feature, user) { | ||
exports.getUserPercentage = getUserPercentage; | ||
var isActive = function (feature, user) { | ||
if (!feature.active) { | ||
@@ -80,2 +83,3 @@ return false; | ||
}; | ||
exports.isActive = isActive; | ||
var containsParamValue = function (listAsString, a) { | ||
@@ -109,2 +113,8 @@ var list = listAsString.split(","); | ||
break; | ||
case UserParamType.semver: | ||
var valueSemver = parseString(userValue); | ||
if (meetsConstraintForSemVer(valueSemver, paramExists, constraint)) { | ||
constraintsMet = constraintsMet + 1; | ||
} | ||
break; | ||
default: | ||
@@ -167,2 +177,43 @@ var value = parseString(userValue); | ||
}; | ||
var meetsConstraintForSemVer = function (userValue, paramExists, constraint) { | ||
var value = userValue; | ||
if (!paramExists) { | ||
return false; | ||
} | ||
switch (constraint.operator) { | ||
case Operator.equals: | ||
if (compare(value, constraint.values) === 0) { | ||
return true; | ||
} | ||
break; | ||
case Operator.doesNotEqual: | ||
if (compare(value, constraint.values) !== 0) { | ||
return true; | ||
} | ||
break; | ||
case Operator.lessThan: | ||
if (compare(value, constraint.values) < 0) { | ||
return true; | ||
} | ||
break; | ||
case Operator.lessThanOrEqualTo: | ||
if (compare(value, constraint.values) <= 0) { | ||
return true; | ||
} | ||
break; | ||
case Operator.greaterThan: | ||
if (compare(value, constraint.values) > 0) { | ||
return true; | ||
} | ||
break; | ||
case Operator.greaterThanOrEqualTo: | ||
if (compare(value, constraint.values) >= 0) { | ||
return true; | ||
} | ||
break; | ||
default: | ||
return false; | ||
} | ||
return false; | ||
}; | ||
var meetsConstraint = function (userValue, paramExists, constraint) { | ||
@@ -169,0 +220,0 @@ switch (constraint.operator) { |
{ | ||
"name": "@molassesapp/common", | ||
"version": "0.7.0", | ||
"version": "0.8.0", | ||
"description": "This is the common package for the @molasses node work - do not install instead use molasses-js or molasses-server", | ||
@@ -31,6 +31,7 @@ "keywords": [], | ||
}, | ||
"gitHead": "08a103b26f8016492970455345d2591d781c6c62", | ||
"gitHead": "6bb18cbfc3c238f6dda205adbffde3c0c1f9f86d", | ||
"dependencies": { | ||
"crc": "^3.8.0" | ||
"crc": "^3.8.0", | ||
"semver": "^7.3.5" | ||
} | ||
} |
const { crc32 } = require("crc") | ||
const compare = require("semver/functions/compare-loose") | ||
export interface Feature { | ||
@@ -30,2 +31,3 @@ id?: string | ||
} | ||
export enum UserParamType { | ||
@@ -35,3 +37,5 @@ number = "number", | ||
string = "string", | ||
semver = "semver", | ||
} | ||
export enum Operator { | ||
@@ -148,2 +152,8 @@ any = "any", | ||
break | ||
case UserParamType.semver: | ||
const valueSemver = parseString(userValue) | ||
if (meetsConstraintForSemVer(valueSemver as string, paramExists, constraint)) { | ||
constraintsMet = constraintsMet + 1 | ||
} | ||
break | ||
default: | ||
@@ -215,2 +225,47 @@ const value = parseString(userValue) | ||
} | ||
const meetsConstraintForSemVer = ( | ||
userValue: string, | ||
paramExists: boolean, | ||
constraint: UserConstraint, | ||
) => { | ||
const value = userValue | ||
if (!paramExists) { | ||
return false | ||
} | ||
switch (constraint.operator) { | ||
case Operator.equals: | ||
if (compare(value, constraint.values) === 0) { | ||
return true | ||
} | ||
break | ||
case Operator.doesNotEqual: | ||
if (compare(value, constraint.values) !== 0) { | ||
return true | ||
} | ||
break | ||
case Operator.lessThan: | ||
if (compare(value, constraint.values) < 0) { | ||
return true | ||
} | ||
break | ||
case Operator.lessThanOrEqualTo: | ||
if (compare(value, constraint.values) <= 0) { | ||
return true | ||
} | ||
break | ||
case Operator.greaterThan: | ||
if (compare(value, constraint.values) > 0) { | ||
return true | ||
} | ||
break | ||
case Operator.greaterThanOrEqualTo: | ||
if (compare(value, constraint.values) >= 0) { | ||
return true | ||
} | ||
break | ||
default: | ||
return false | ||
} | ||
return false | ||
} | ||
@@ -217,0 +272,0 @@ const meetsConstraint = (userValue: string, paramExists: boolean, constraint: UserConstraint) => { |
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
34917
741
2
+ Addedsemver@^7.3.5
+ Addedsemver@7.6.3(transitive)