Research
Recent Trends in Malicious Packages Targeting Discord
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
query-builder-to-string
Advanced tools
Readme
This is a simple library to convert rules created from jQuery Query Builder to String Format
Dependencies
npm install query-builder-to-string
Navigate to https://querybuilder.js.org/demo.html for a demo or implement a rule builder using query builder.
After creating your rule, click the 'Get Rules' button and you will get below JSON as the output. You can use your own custom implementation to get the output from query builder.
The output form Query Builder will be like below,
{
"condition": "AND",
"rules": [{
"id": "price",
"field": "price",
"type": "double",
"input": "number",
"operator": "less",
"value": 10.25
},
{
"condition": "OR",
"rules": [{
"id": "category",
"field": "category",
"type": "integer",
"input": "select",
"operator": "equal",
"value": 2
},
{
"id": "category",
"field": "category",
"type": "integer",
"input": "select",
"operator": "equal",
"value": 1
},
{
"condition": "AND",
"rules": [{
"id": "in_stock",
"field": "in_stock",
"type": "integer",
"input": "radio",
"operator": "equal",
"value": 1
}]
}
]
}
],
"valid": true
};
So, we have the query builder input and now we are going to convert it to a rule defenition which is the input for durable rules engine.
const RuleConverter = require('query-builder-to-string');
// output from jQuery Query Builder
var ruleInput = {
"condition": "AND",
"rules": [{
"id": "price",
"field": "price",
"type": "double",
"input": "number",
"operator": "less",
"value": 10.25
},
{
"condition": "OR",
"rules": [{
"id": "category",
"field": "category",
"type": "integer",
"input": "select",
"operator": "equal",
"value": 2
},
{
"id": "category",
"field": "category",
"type": "integer",
"input": "select",
"operator": "equal",
"value": 1
},
{
"condition": "AND",
"rules": [{
"id": "in_stock",
"field": "in_stock",
"type": "integer",
"input": "radio",
"operator": "equal",
"value": 1
}]
}
]
}
],
"valid": true
};
var output = RuleConverter(ruleInput);
And the output will be string,
// "price < 10.25 && (category == 2 || category == 1 || (in_stock == 1))"
You can use the above definition in node rules engine like below format,
var RuleEngine = require("node-rules");
/* Creating Rule Engine instance */
var R = new RuleEngine();
/* Add a rule */
var rule = {
"condition": (R) => {
console.log(this);
R.when(eval([<PUT-THE-ABOVE-OUTPUT-HERE>]));
},
"consequence": (R) => {
this.result = false;
this.reason = "Put some reason message as needed.";
R.stop();
}
};
/* Register Rule */
R.register(rule);
Here is a runkit example: https://runkit.com/aravindnc/query-builder-to-string
Reference for JSON rules for Node Rules,
Currently the library support below operations only,
This is the draft version of the library, which you can use for your basic needs if you are using Node Rules.
FAQs
This is a simple library to convert rules created from jQuery Query Builder to String Format
We found that query-builder-to-string 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
The Socket research team breaks down a sampling of malicious packages that download and execute files, among other suspicious behaviors, targeting the popular Discord platform.
Security News
Socket CEO Feross Aboukhadijeh joins a16z partners to discuss how modern, sophisticated supply chain attacks require AI-driven defenses and explore the challenges and solutions in leveraging AI for threat detection early in the development life cycle.
Security News
NIST's new AI Risk Management Framework aims to enhance the security and reliability of generative AI systems and address the unique challenges of malicious AI exploits.