safe-evaluate-expression
Advanced tools
Comparing version 1.4.2 to 1.4.3
@@ -5,2 +5,9 @@ # Changelog | ||
### [1.4.3](https://bitbucket.org/ttessarolo/safe-evaluate-expression/branches/compare/v1.4.2%0Dv1.4.3) (2020-12-03) | ||
### Tests | ||
* add Test case for empty basic rules ([f766774](https://github.com/ttessarolo/safe-evaluate-expression/commits/f7667747967a3124eea8443a663c56d6481904b8)) | ||
### [1.4.2](https://bitbucket.org/ttessarolo/safe-evaluate-expression/branches/compare/v1.4.1%0Dv1.4.2) (2020-12-03) | ||
@@ -7,0 +14,0 @@ |
{ | ||
"name": "safe-evaluate-expression", | ||
"version": "1.4.2", | ||
"version": "1.4.3", | ||
"description": "Small library to dynamically create and evaluate expression with multiple parameters (even undefined)", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -17,8 +17,14 @@ const { FUNC_PARAMS } = require('./factory'); | ||
const emptyValues = [ | ||
{ value: '', type: 'string' }, | ||
{ value: '', type: 'string' }, | ||
]; | ||
function compose(rule) { | ||
rule = rule.replace(/not /g, '!').trim(); | ||
const operator = rule.substring(0, rule.indexOf('(')); | ||
const values = rule | ||
.match(FUNC_PARAMS) | ||
.map((value) => ({ value: getValue(value), type: getType(value) })); | ||
const params = rule.match(FUNC_PARAMS); | ||
const values = params | ||
? params.map((value) => ({ value: getValue(value), type: getType(value) })) | ||
: emptyValues; | ||
@@ -25,0 +31,0 @@ return { operator, values }; |
@@ -13,3 +13,3 @@ const test = require('ava'); | ||
'equals(context_device, "desktop") OR equals(context_device, "tablet") AND equals(when_day_of_the_week, "Tuesday") AND greaterThan(now, "21") AND lessThan(now, "23")'; | ||
const basic8 = 'condition (equals(, ))'; | ||
const c3 = { | ||
@@ -375,2 +375,14 @@ and: [ | ||
const c8 = { | ||
and: [ | ||
{ | ||
operator: 'condition', | ||
values: [ | ||
{ value: '', type: 'string' }, | ||
{ value: '', type: 'string' }, | ||
], | ||
}, | ||
], | ||
}; | ||
test('test and or condition', (t) => { | ||
@@ -415,1 +427,6 @@ const result = basicToComplex(basic3); | ||
}); | ||
test('test basic8', (t) => { | ||
const result = basicToComplex(basic8); | ||
t.deepEqual(result, c8); | ||
}); |
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
51706
988