
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Simple rule engine pattern. No dependencies.
Runs first rule where when returns a truthy value
Returns all rule objects where when returns a truthy value
Returns all results where when returns a truthy value
Constants:
const ruleSet = [
{ when: 'a', then: 'b' },
{ when: 1, then: 2 }
]
rules.first(ruleSet, 1); // returns 2
rules.first(ruleSet, 'a'); // returns 'b'
rules.first(ruleSet, '?'); // returns undefined
Functions:
const ruleSet = [
{ when: str => str.length > 3, then: str => str.substr(3).trim() },
{ when: true, then: str => str.toLowerCase() }
]
rules.first(ruleSet, '>>> value'); // returns 'value';
rules.first(ruleSet, 'B'); // returns 'b';
Multiple facts / parameters:
const ruleSet = [
{
when: function (platform, cmd) {
return platform === 'win32' && cmd === 'python';
},
then: function (platform, cmd) {
return cmd += '.exe'
}
},
{
when: function (platform, ) {
return platform === 'win32' && cmd === 'ls';
},
then: function (platform, cmd) {
return 'dir';
}
}
]
rules.first(ruleSet, 'win32', 'python'); // returns 'python.exe';
rules.first(ruleSet, 'win32', 'ls'); // returns 'dir';
Select all that apply:
const ruleSet = [
{ when: str => str.startsWith('fizz'), a: 'b', c: 'd' },
{ when: str => str.endsWith('buzz'), value: 7 },
{ when: str => str === 'fizzbuzz', width: 8, height: 9 }
]
rules.select(ruleSet, 'fizz'); // returns first item;
rules.select(ruleSet, 'buzz'); // returns second item;
rules.select(ruleSet, 'fizzbuzz'); // returns all three;
Get all the rule results that are truthy for when:
const ruleSet = [
{ when: facts => facts.isLoggedIn, then: facts => fetch('http://example.com/user/' + facts.userId) },
{ when: facts => facts.isAdmin, then: facts => fetch('http://example.com/rights/' + facts.rightsId) },
{ when: facts => facts.browser === 'IE', then: facts => fetch('http://iesupport.com') }
]
const promises = rules.all(ruleSet, {isLoggedIn: true, browser: 'IE'});
return Promises.all(promises); // resolves all the API calls.
FAQs
rules engine; chain-of-command implementation
We found that rulejs 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.