1.1.0 • Published 10 months ago

@brixx/decision-script v1.1.0

Weekly downloads
-
License
Attribution-NonCo...
Repository
github
Last release
10 months ago

Brixx-Decision-Script

Decisions are the most important part of programming

Brixx-Decision-Script is a free JavaScript library for rule-based decision systems. With our Brixx-Decision-Script, the programming can be reduced to a minimum and for adjustments or extensions via rules, for example with a decision table, it can be replaced by a technical configuration (low-code development). Fast integration into any HTML document is possible, especially with the integrated Brixx-Script (smarte web components) as Brixx HTML elements or as Brixx script components in JavaScript applications and frameworks and also support JavaScript environments such as Node.js® (cross-platform JavaScript runtime environment). Rules can be easily managed in an external decision table definition file with the decision model notation (DMN). No programming tasks or complicated deployments are required for changes or adjustments and basic configurations from a decision table definition file can also be expanded with Brixx-Decision-Script HTML elements.

Why the rule engine for JavaScript?

We have decided to publish Brixx-Decision-Script as a decision table and rule engine for JavaScript. As a result, Brixx-Decision-Script can be used in common frameworks, development environments, programming languages and platforms as a web application or web service for low-code development without a special platform. In addition, Brixx-Decision-Script enables direct integration into an HTML document, which makes it special. This also gives non-programmers the opportunity to design dynamic websites. Ask about integration into your applications, whether Python, Java, as a RESTful API or as a Docker solution.

Usage

Web

Brixx web component in the Brixx script component file brixx-check-age.js

// Check decision table callback function (optional)
const checkDecisionTable = (output) => {
    console.log("Output:", output);
}

// Create a Brixx default element
Brixx.element = (
    <div>
        <p>HTML element &lt;brixx-check-age&gt; created with Brixx-Script.</p>
        <DecisionTable>
            <ul>
                <li>Baby (0 years old) - <i>It's still a baby!</i></li>
                <li>Preschool (under 5 years old) - <i>Unfortunately too young!</i></li>
                <li>Kids (under 13 years old) - <i>https://www.youtube.com/kids/</i></li>
                <li>Teens (13 years or older) - <i>https://www.youtube.com/</i></li>
            </ul>
            <Input name={"age"} type={"number"}>
                <div>Please enter age</div>
                <Field />
            </Input>
            <Output name={"info"}>
                <Field readonly />
            </Output>
            <Output name={"url"}>
                <Link />
            </Output>
            <Rule age={""} priority={30} info={"Please enter a valid age!"} url={"https://github.com/BietSoft/brixx.docs/"} />
            <Rule age={"0"} priority={40} info={"It's is still a baby!"} />
            <Rule age={"< 5"} priority={20} info={"Unfortunately too young!"} />
            <Rule age={">= 13"} url={"https://www.youtube.com/"} />
            <Rule age={"< 13"} priority={10} info={"Internet Safety for Kids"} url={"https://www.youtube.com/kids/"} />
            <Check button label={"Check age"} action={checkDecisionTable} />
        </DecisionTable>
    </div>
);

// Register a Brixx HTML-Element <brixx-check-age>
Brixx.registerElement({ name: "check-age" });

Brixx HTML element in the HTML file index.html

<!DOCTYPE html>
<html>
<head>
    <!-- Load Brixx-Decision-Script standalone for development-->
    <script src="https://brixx.it/@brixx/standalone/brixx-decision.min.js"></script>
    <!-- Include the Brixx script component files for development -->
    <script type="text/babel" src="./brixx-check-age.js" data-type="module" data-presets="brixx"></script>
</head>

<body>
    <!-- Add the Brixx HTML element -->
    <brixx-check-age></brixx-check-age>
</body>
</html>

Node.js

Install the Brixx-Decision-Script package e.g. in a Visual Studio Code terminal window (see documentation below).

> npm i @brixx/decision-script

Brixx decision table definition in the JSON file brixx_check_age.json

{
    "description": "Check age",
    "hitPolicy": "Priority",
    "input": {
        "age": {
        "description": "The age to check",
        "type": "number",
        "default": 0
        }
    },
    "output": {
        "info": {
        "description": "An additional information"
        },
        "url": {
        "description": "The url to link to"
        }
    },
    "rules": {
        "No entry": {
        "age": "",
        "info": "Please enter a valid age!",
        "url": "https://github.com/BietSoft/brixx.docs/",
        "priority": 30
        },
        "Baby": {
        "age": "0",
        "info": "It's is still a baby!",
        "priority": 40
        },
        "Preschool": {
        "age": "< 5",
        "info": "Unfortunately too young!",
        "priority": 20
        },
        "Teens": {
        "age": ">= 13",
        "url": "https://www.youtube.com/"
        },
        "Kids": {
        "age": "< 13",
        "info": "Internet Safety for Kids",
        "url": "https://www.youtube.com/kids/",
        "priority": 10
        }
    }
}

Node.js app in the JavaScript file ./brixx-check-age.js

// Imports
const BrixxDecisionTable = require("@brixx/decision-script/node").default;

/**
*  Set the decision table input data list to check
*  represents e.g. data from a web service or a database
*/
const input_data = [
    { age: "" },
    { age: 0 },
    { age: 3 },
    { age: 12 },
    { age: 13 }
]

// Create a BrixxDecisionTable instance
const table = new BrixxDecisionTable({ file: "./brixx_check_age.json" });

// Check the decision table input data list
input_data.map((input) => {
    // Get the output from decision table input data
    const output = table.check(input)
    // Prints the output to console
    console.log(output)
})

Start Brixx decision table application in terminal

> node brixx-check-age.js

Documentation

See BRIXX.it documentation repository

1.1.0

10 months ago

1.0.7

1 year ago

1.0.6

1 year ago

1.0.5

1 year ago

1.0.4

1 year ago

1.0.3

1 year ago

1.0.2

1 year ago

1.0.1

1 year ago

1.0.0

1 year ago

0.9.1

1 year ago

0.9.0

1 year ago

0.0.1

1 year ago