Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@clipboard-health/rules-engine
Advanced tools
A pure functional rules engine with two rule runners:
firstMatch
: Runs the first rule that matches the criteriaall
: Runs all the rules that matches the criterianpm install @clipboard-health/rules-engine
// ./examples/rules.ts
import {
all,
appendOutput,
firstMatch,
type Rule,
type RuleContext,
} from "@clipboard-health/rules-engine";
interface Input {
number1: number;
number2: number;
}
interface Output {
result: number;
}
const exampleContext: RuleContext<Input, Output> = {
input: {
number1: 2,
number2: 5,
},
output: [],
};
const addNumbersIfPositiveRule: Rule<Input, Output> = {
runIf: (input) => input.number1 > 0 && input.number2 > 0,
run: (context) => {
const { number1, number2 } = context.input;
const sum = number1 + number2;
return appendOutput(context, { result: sum });
},
};
const multiplyNumbersIfPositiveRule: Rule<Input, Output> = {
runIf: (input) => input.number1 > 0 && input.number2 > 0,
run: (context) => {
const { number1, number2 } = context.input;
const sum = number1 * number2;
return appendOutput(context, { result: sum });
},
};
const divideNumbersIfNegative: Rule<Input, Output> = {
runIf: (input) => input.number1 < 0 && input.number2 < 0,
run: (context) => {
const { number1, number2 } = context.input;
const sum = number1 * number2;
return appendOutput(context, { result: sum });
},
};
// Using all() applies all the rules to the context
const allResult = all(
addNumbersIfPositiveRule,
divideNumbersIfNegative,
multiplyNumbersIfPositiveRule,
).run(exampleContext);
console.log(allResult.output);
// => [{ result: 7 }, { result: 10 }]
// Using firstMatch() applies the first the rules to the context
const firstMatchResult = firstMatch(
divideNumbersIfNegative,
addNumbersIfPositiveRule,
multiplyNumbersIfPositiveRule,
).run(exampleContext);
console.log(firstMatchResult.output);
// => [{ result: 7 }]
See package.json
scripts
for a list of commands.
FAQs
A pure functional rules engine to keep logic-dense code simple, reliable, understandable, and explainable.
The npm package @clipboard-health/rules-engine receives a total of 654 weekly downloads. As such, @clipboard-health/rules-engine popularity was classified as not popular.
We found that @clipboard-health/rules-engine demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.