Security News
Node.js EOL Versions CVE Dubbed the "Worst CVE of the Year" by Security Experts
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
@clipboard-health/rules-engine
Advanced tools
A pure functional rules engine to keep logic-dense code simple, reliable, understandable, and explainable.
A pure functional rules engine to keep logic-dense code simple, reliable, understandable, and explainable.
The engine uses static rules created in code instead of dynamic rules serialized to a database since we haven't needed the latter yet.
npm install @clipboard-health/rules-engine
import { deepEqual } from "node:assert/strict";
import {
all,
appendOutput,
firstMatch,
type Rule,
type RuleContext,
} from "@clipboard-health/rules-engine";
interface Input {
a: number;
b: number;
}
interface Output {
result: number;
}
const exampleContext: RuleContext<Input, Output> = {
input: {
a: 2,
b: 5,
},
output: [],
};
const addNumbersIfPositiveRule: Rule<Input, Output> = {
runIf: (input) => input.a > 0 && input.b > 0,
run: (context) => {
const { a, b } = context.input;
return appendOutput(context, { result: a + b });
},
};
const multiplyNumbersIfPositiveRule: Rule<Input, Output> = {
runIf: (input) => input.a > 0 && input.b > 0,
run: (context) => {
const { a, b } = context.input;
return appendOutput(context, { result: a * b });
},
};
const divideNumbersIfNegative: Rule<Input, Output> = {
runIf: (input) => input.a < 0 && input.b < 0,
run: (context) => {
const { a, b } = context.input;
return appendOutput(context, { result: a / b });
},
};
// Using all() applies all the rules to the context
const allResult = all(
addNumbersIfPositiveRule,
divideNumbersIfNegative,
multiplyNumbersIfPositiveRule,
).run(exampleContext);
deepEqual(allResult.output, [{ result: 7 }, { result: 10 }]);
// Using firstMatch() applies the first the rules to the context
const firstMatchResult = firstMatch(
divideNumbersIfNegative,
addNumbersIfPositiveRule,
multiplyNumbersIfPositiveRule,
).run(exampleContext);
deepEqual(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 1,659 weekly downloads. As such, @clipboard-health/rules-engine popularity was classified as 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 3 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.
Security News
Critics call the Node.js EOL CVE a misuse of the system, sparking debate over CVE standards and the growing noise in vulnerability databases.
Security News
cURL and Go security teams are publicly rejecting CVSS as flawed for assessing vulnerabilities and are calling for more accurate, context-aware approaches.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.