{"id":26930217,"url":"https://github.com/dial-once/node-rules-engine","last_synced_at":"2025-04-02T06:17:33.028Z","repository":{"id":65472809,"uuid":"42528749","full_name":"dial-once/node-rules-engine","owner":"dial-once","description":"A node.js module to check if an event array matches some specifications.","archived":false,"fork":false,"pushed_at":"2016-11-04T14:59:11.000Z","size":45,"stargazers_count":13,"open_issues_count":4,"forks_count":0,"subscribers_count":9,"default_branch":"develop","last_synced_at":"2025-03-21T17:49:30.466Z","etag":null,"topics":["javascript","nodejs","rules"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dial-once.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-09-15T15:36:02.000Z","updated_at":"2024-05-15T01:19:41.000Z","dependencies_parsed_at":"2023-01-25T02:25:11.506Z","dependency_job_id":null,"html_url":"https://github.com/dial-once/node-rules-engine","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dial-once%2Fnode-rules-engine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dial-once%2Fnode-rules-engine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dial-once%2Fnode-rules-engine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dial-once%2Fnode-rules-engine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dial-once","download_url":"https://codeload.github.com/dial-once/node-rules-engine/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246763899,"owners_count":20829800,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["javascript","nodejs","rules"],"created_at":"2025-04-02T06:17:32.360Z","updated_at":"2025-04-02T06:17:33.015Z","avatar_url":"https://github.com/dial-once.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# node-rules-engine\n[![David](https://david-dm.org/dial-once/node-rules-engine.svg?style=flat-square)](https://david-dm.org/dial-once/node-rules-engine)\n[![Codacy](https://img.shields.io/codacy/1f7212250ea849ccb49ca273a9b4290e.svg?style=flat-square)](https://www.codacy.com/app/pukoren/node-rules-engine)\n[![Code Climate](https://img.shields.io/codeclimate/github/dial-once/node-rules-engine.svg?style=flat-square)](https://codeclimate.com/github/dial-once/node-rules-engine)\n[![Code Climate](https://img.shields.io/codeclimate/coverage/github/dial-once/node-rules-engine.svg?style=flat-square)](https://codeclimate.com/github/dial-once/node-rules-engine)\n[![Codeship](https://img.shields.io/codeship/20e197d0-3f4d-0133-ca24-22e25667a15e.svg?style=flat-square)](https://codeship.com/projects/103052)\n\nA node.js module to check if an event array matches some specifications.\nUsefull when you want to compare many rules with many events and check if the final output is true/false. \n\nDial Once uses this module to easily check if a user match a goal/funnel using our interfaces. See exemple below for a more explanatory exemple.\n\n# installation\n```\nnpm install rules-engine\n```\n```js\nvar engine = require('rules-engine');\nengine.apply(events, rules).then(function(result){\n  console.log(result); //boolean, true if events are matching rules, false otherwise\n});\n```\n\n# example\nWe want here to check if user viewed page 1, page 3, and then made a click (basic conversion test).\n('page' and 'click' here are arbitrary and you can use whatever you want)\n```js\n\nvar engine = require('rules-engine');\n\nvar events = [\n  {'page': {val: 1}},\n  {'page': {val: 3}},\n  {'click': {val: true}}\n];\n\nvar rules = [\n  {'page': {val: 1, should: true}},\n  {'page': {val: 3, should: true}},\n  {'click': {val: true, should: true}}\n];\n\nengine.apply(events, rules).then(function(result){\n  console.log(result); //true!\n});\n```\n\nThen things can be a bit more complicated, if we want to check if user viewed page 1, 3 but did not make any click:\n```js\nvar rules = [\n  {'page': {val: 1, should: true}},\n  {'page': {val: 3, should: true}},\n  {'click': {val: true, should: false}}\n];\nengine.apply(events, rules).then(function(result){\n  console.log(result); //false!\n});\n```\n\nSome more cases can be handled, like 'user viewed either page 1, 2, or 3 and made a click:\n```js\nvar rules = [\n  {'page': {val: [1, 2, 3], should: true}},\n  {'click': {val: true, should: true}}\n];\n```\n\nUser viewed any page:\n```js\nvar rules = [\n  {'page': {val: '*', should: true}}\n];\n```\nor\n```js\nvar rules = [\n  {'page': {val: /.+/, should: true}}\n];\n```\n\nUser viewed any page BUT page 3:\n```js\nvar rules = [\n  {'page': {val: '*', should: true}},\n  {'page': {val: 3, should: false}}\n];\n```\n\n# complex rules exemple\nThe following rules can be used in ```val``` to compute complex rules:\n```js\n{$gt: 0} //true if event val is greater than the value\n{$lt: 0} //true if event val is lesser than the value\n{$gte: 0} //greater than or equal\n{$lte: 0} //lesser than or equal\n```\nValue can be a ```Date```, number, string, etc. Anything natively comparable in JS\n\n\nUser should have made more than 10 clicks:\n```js\nvar events = [\n {'clicks': {val: 12}}\n];\nvar rules = [\n  {'clicks': {val: {$gt: 10}, should: true}}\n];\n```\n\n\n# OR conditions and optional rules\nYou can specify some rules as optional, thus if they don't match, other rules will have priority.\n\nUser should do more than 10 clicks OR less than 3 pageviews:\n```js\nvar events = [\n {'clicks': {val: 12}}\n];\nvar rules = [\n  {'clicks': {val: {$gt: 10}, should: true, optional: true}},\n  {'views': {val: {$lt: 3}, should: true, optional: true}}\n];\n```\n\nIf none are matched, it will be rejected. If one of the two matches, its a true!\n\nYou can then make some complex scenario, like:\nUser should do more than 10 clicks, AND (views less than 3 pages OR make 1 comment)\n```js\nvar events = [\n {'clicks': {val: 12}}\n];\nvar rules = [\n  {'clicks': {val: {$gt: 10}, should: true}},\n  {'views': {val: {$lt: 3}, should: true, optional: true }},\n  {'comments': {val: 1, should: true, optional: true }}\n];\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdial-once%2Fnode-rules-engine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdial-once%2Fnode-rules-engine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdial-once%2Fnode-rules-engine/lists"}