
Research
/Security News
60 Malicious Ruby Gems Used in Targeted Credential Theft Campaign
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
json-expression-eval
Advanced tools
evaluate a json described boolean expression using dynamic functions
A Node.js module that evaluates a json described boolean expressions using dynamic functions and a given context.
The module is strictly typed, ensuring that passed expressions are 100% valid at compile time.
This module is especially useful if you need to serialize complex expressions (to be saved in DB for example)
npm install json-expression-eval
Or
yarn add json-expression-eval
Please see tests and examples dir for more usages and example (under /src)
import { Expression, evaluate } from 'json-expression-eval';
interface IExampleContext {
userId: string;
times: number;
}
const exampleContext: IExampleContext = {
userId: 'a2@b.com',
times: 5,
};
const functionsTable = {
countRange: ([min, max]: [number, number], context: IExampleContext): boolean => {
return context.times >= min && context.times < max;
},
};
const expression: Expression<IExampleContext, typeof functionsTable> = {
or: [
{
userId: 'a@b.com',
},
{
and: [
{
countRange: [2, 6],
},
{
userId: 'a2@b.com',
},
],
},
],
};
console.log(evaluate(expression, exampleContext, functionsTable)); // true
There are 4 types of operators you can use (evaluated in that order of precedence):
and
- accepts a non empty list of operatorsor
- accepts a non empty list of operatorsnot
- accepts another operator<user defined funcs>
- accepts any type of argument and evaluated by the user defined functions and given context.<compare funcs>
- operates on one of the context properties and compare it to a given value.
{property: {op: value}}
gt
- >gte
- >=lt
- <lte
- <=eq
- ===neq
- !=={property: value}
eq
op)Example expressions, assuming we have the user
and maxCount
user defined functions in place can be:
{
"or":[
{
"not":{
"user":"a@b.com"
}
},
{
"maxCount":1
},
{
"times": { "eq" : 5}
},
{
"country": "USA"
}
]
}
FAQs
json serializable rule engine / boolean expression evaluator
The npm package json-expression-eval receives a total of 255 weekly downloads. As such, json-expression-eval popularity was classified as not popular.
We found that json-expression-eval demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.
Research
/Security News
Two npm packages masquerading as WhatsApp developer libraries include a kill switch that deletes all files if the phone number isn’t whitelisted.