Security News
pnpm 10.0.0 Blocks Lifecycle Scripts by Default
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
@clipboard-health/rules-engine
Advanced tools
Exposes a functional rules-engine with 2 engines:
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); // 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 1,339 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 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.
Security News
pnpm 10 blocks lifecycle scripts by default to improve security, addressing supply chain attack risks but sparking debate over compatibility and workflow changes.
Product
Socket now supports uv.lock files to ensure consistent, secure dependency resolution for Python projects and enhance supply chain security.
Research
Security News
Socket researchers have discovered multiple malicious npm packages targeting Solana private keys, abusing Gmail to exfiltrate the data and drain Solana wallets.