Gathering detailed insights and metrics for @rules-tools/rules-machine
Gathering detailed insights and metrics for @rules-tools/rules-machine
Gathering detailed insights and metrics for @rules-tools/rules-machine
Gathering detailed insights and metrics for @rules-tools/rules-machine
📐 A fast, general-purpose JSON Rules Engine.
npm install @rules-tools/rules-machine
Typescript
Module System
Min. Node Version
Node Version
NPM Version
TypeScript (97.77%)
JavaScript (2.02%)
Shell (0.21%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
BSD-3-Clause License
57 Stars
115 Commits
5 Forks
5 Watchers
6 Branches
4 Contributors
Updated on Jun 24, 2025
Latest Version
1.1.6
Package Id
@rules-tools/rules-machine@1.1.6
Unpacked Size
147.61 kB
Size
103.25 kB
File Count
16
NPM Version
6.14.15
Node Version
14.18.0
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
Rules Against The Machine 🤘
Table of Content
Rules Machine
?It's a fast, general purpose JSON Rules Engine
library for both the Browser & Node.js! 🚀
applySalesTax
)App Logic != Business Rules
App Logic is close to Core component behavior. For example, adding a locale={countryCode}
to the <Calendar>
component will change it's App Logic.
Whereas "Prevent meeting requests on Weekends." is more of a Business Rule, because it's specific to a scheduling application, and its current context.
Using this as a mental model greatly accelerates identifying specific places to utilize a Rules Engine.
(I know there are other ways to describe this concept. I'm choosing to avoid CS jargon stuffing.)
Typically App Logic & Business Rules are woven together throughout the project. This co-location of logic is usually helpful, keeping things readable in small and even mid-sized projects.
This works great, until you run into one of the following challenges:
DepositTransaction
controller shouldn't require careful reading of 2,000 lines of custom rules around currency hackery & country-code checks.trace
, with details on each step, what happened, and the time taken.1[ 2 {"if": {"and": ["price >= 25", "price <= 50"]}, "then": "discount = 5"}, 3 {"if": "price > 50", "then": "discount = 10"}, 4 {"return": "discount"} 5]
1- if: {and: [price >= 25, price <= 50]} 2 then: discount = 5 3- if: price > 50 4 then: discount = 10 5- return: discount
1[ 2 { 3 "if": "user.plan == \"premium\"", 4 "then": "discount = 15" 5 }, 6 { 7 "if": "user.employee == true", 8 "then": "discount = 15" 9 }, 10 { 11 "return": "discount" 12 } 13]
1[ 2 { 3 "if": "price <= 100", 4 "then": "discount = 5" 5 }, 6 { 7 "if": { 8 "or": [ 9 "price >= 100", 10 "user.isAdmin == true" 11 ] 12 }, 13 "then": "discount = 20" 14 }, 15 { 16 "return": "discount" 17 } 18]
1- if: price <= 100 2 then: discount = 5 3- if: 4 or: [price >= 100, user.isAdmin == true] 5 then: discount = 20 6- return: discount
1[ 2 { 3 "if": "price <= 100", 4 "then": [ 5 "discount = 5", 6 "user.discountApplied = true" 7 ] 8 }, 9 { 10 "if": { 11 "and": [ 12 "price >= 90", 13 "user.discountApplied != true" 14 ] 15 }, 16 "then": "discount = 20" 17 }, 18 { 19 "return": "discount" 20 } 21]
1- if: price <= 100 2 then: 3 - discount = 5 4 - user.discountApplied = true 5- if: 6 and: 7 - price >= 90 8 - user.discountApplied != true 9 then: discount = 20 10- return: discount
{"runRules": "ruleSetName"}
{"throw": "error message"}
{"log": "rule/value expression"}
{"set": "newVar = value"}
eval
/Function('...')
parsing.Rule[]
the sole recursive type.{"and": []}
{"or": []}
).No vulnerabilities found.
No security vulnerabilities found.