@jsonlang/logic
v0.0.13
Published
JsonLang Extension for Logical Operations
Downloads
79,573
Maintainers
Readme
👋 JsonLang/Logic
It is JsonLang Plugin/Extension for Logical operations.
⏬ Installation
npm install @jsonlang/core @jsonlang/logic
🎉 Usage
import { JsonLang } from '@jsonlang/core';
import { LogicRules } from '@jsonlang/logic';
const jsonLang = new JsonLang();
jsonLang.import(LogicRules);
⚒️ Rules
And or &&
- Input[]: Array (Size: Unlimited).
- Output: Boolean (true or false).
- Description: Do the
Anding
operation, if any value inInput[]
has a value of (null, 0, false), it will returnfalse
, else it will returntrue
.
Or or ||
- Input[]: Array (Size: Unlimited).
- Output: Boolean (true or false).
- Description: Do the
Oring
operation, if all values inInput[]
has a value of (null, 0, false), it will returnfalse
, else it will returntrue
.
Equal or ==
- Input[]: Array (Size: 2).
- Output: Boolean (true or false).
- Description: It takes an array of 2 inputs to compare if element one
Equal
element two or not.
NotEqual or =
- Input[]: Array (Size: 2).
- Output: Boolean (true or false).
- Description: It takes an array of 2 inputs to compare if element one
Not Equal
to element two or not.
Not or !
- Input[]: Array (Size: 1).
- Output: Boolean (true or false).
- Description: It takes an array of 1 input inverts its value. If it
true
it will returnfalse
and vice versa.
GreaterThan or >
- Input[]: Array (Size: 2).
- Output: Boolean (true or false).
- Description: It takes an array of 2 inputs to compare if element one
Greater Than
element two or not.
LessThan or <
- Input[]: Array (Size: 2).
- Output: Boolean (true or false).
- Description: It takes an array of 2 inputs to compare if element one
Less Than
element two or not.
GreaterThanOrEqual or >=
- Input[]: Array (Size: 2).
- Output: Boolean (true or false).
- Description: It takes an array of 2 inputs to compare if element one
Greater Than or Equal
element two or not.
LessThanOrEqual or <=
- Input[]: Array (Size: 2).
- Output: Boolean (true or false).
- Description: It takes an array of 2 inputs to compare if element one
Less Than or Equal
element two or not.
💻Examples
import { JsonLang } from '@jsonlang/core';
import { LogicRules } from '@jsonlang/logic';
const jsonLang = new JsonLang();
jsonLang.import(LogicRules);
jsonLang.execute( { "$R": "LessThan" , "$I": [10, 20] }, undefined, { sync: true } ); // true
// or for short
jsonLang.execute( { "$R": "<" , "$I": [10, 20] }, undefined, { sync: true } ); // true
// or use the async function
jsonLang.execute( { "$R": "<" , "$I": [10, 20] } )
.then(result => {
console.log(result); // true
});
🔌 Compatibility
This library uses Array.map
and Array.reduce
, so it's not exactly Internet Explorer 8 friendly.
📜 License
JsonLang/Logic is MIT licensed