safe-evaluate-expression
Version:
Small library to dynamically create and evaluate expression with multiple parameters (even undefined)
50 lines (45 loc) • 1.07 kB
JavaScript
const test = require('ava');
const { factory, operators } = require('../');
const evaluate = factory({ operators, multipleParams: true, translateLogical: true });
test('dotted condition', (t) => {
const condition = {
and: [
{
operator: 'sizeGreater',
values: [
{
type: 'metadata',
value: 'k.id',
},
{
value: '"4"',
type: 'number',
},
],
id: '2xSC4zIAh-',
},
],
};
t.true(evaluate(condition, { 'k.id': [1, 2, 3, 4, 5, 6] }, { ciao: 'mamma' }));
});
test('dotted_underscore condition', (t) => {
const condition = {
and: [
{
operator: 'sizeGreater',
values: [
{
type: 'metadata',
value: 'video_watched_w_ts.id',
},
{
value: '"4"',
type: 'number',
},
],
id: '2xSC4zIAh-',
},
],
};
t.true(evaluate(condition, { 'video_watched_w_ts.id': [1, 2, 3, 4, 5, 6] }, { ciao: 'mamma' }));
});