RuleScribe is a lightweight and powerful rule engine for JavaScript and TypeScript applications. It allows you to define and execute business rules in a declarative manner, enabling agile decision-making and automation of complex logic.
You can install RuleScribe via npm:
npm install rulescribe
To define a simple rule using RuleScribe, follow these steps:
-
Import the required modules:
import { Engine, Lexer, EngineScope } from "rulescribe";
-
Define the structure of the entity for which you're defining rules. For example, let's define a
Patient
type:type Patient = { name: string; lastVisit: number; }
-
Define a method to perform an action based on the rule. For example, let's define a method to send a checkup reminder SMS to a patient:
const sendCheckupReminderSMS = (patient: Patient) => { // Your business logic to send SMS goes here. }
-
Write the rule:
const rule = ` Rule "My First Rule" When patient.lastVisit > 90 Then sendCheckupReminderSMS(patient) End `
-
Set up the RuleScribe engine and execute the rule:
const scope = new EngineScope(); scope.builtinFunction.set("sendCheckupReminderSMS", { func: sendCheckupReminderSMS }); const lexer = new Lexer(rule, scope); const engine = new Engine(lexer); // Define the patient scope.define('patient', { name: "John Doe", lastVisit: 100 }); // Parse and execute the rule await engine.parse(scope); await engine.fire(scope);
This code will execute the rule "My First Rule" and send a checkup reminder SMS to the patient if their last visit was more than 90 days ago.
For more information on how to use RuleScribe, including advanced features and usage examples, refer to the RuleScribe Wiki. Please first review the disclaimer.
Contributions are welcome! If you encounter any issues or have suggestions for improvements, please feel free to open an issue or submit a pull request.
RuleScribe is an open-source project driven by a community of passionate developers and contributors. Your support can help ensure the continued growth and improvement of RuleScribe, enabling us to deliver innovative features, maintain compatibility with the latest technologies, and provide ongoing support to users.
-
Financial Contributions: Consider making a financial contribution to support RuleScribe development. Your donations help cover expenses such as server hosting, development tools, and community outreach efforts.
-
Sponsorship Opportunities: Explore sponsorship opportunities to showcase your organization's commitment to open-source software and innovation. Sponsorship packages may include recognition on our website, social media shoutouts, and other promotional benefits.
-
Contributions and Feedback: Get involved in the RuleScribe community by contributing code, reporting bugs, and providing feedback on features and enhancements. Your input helps shape the future direction of the project.
To learn more about how you can support RuleScribe development or inquire about sponsorship opportunities, please contact us at loghmanb@gmail.com. We appreciate your support and look forward to collaborating with you to make RuleScribe even better!
This project is licensed under the MIT License.