@jsonlang/logic
TypeScript icon, indicating that this package has built-in type declarations

0.0.13 • Public • Published

👋 JsonLang/Logic

JsonLang Logo

It is JsonLang Plugin/Extension for Logical operations.

npm version install size npm downloads Vulnerabilities Maintenance Build Programming Language License FOSSA Status Github Sponsor

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

For more Info and examples

  • And or &&

    • Input[]: Array (Size: Unlimited).
    • Output: Boolean (true or false).
    • Description: Do the Anding operation, if any value in Input[] has a value of (null, 0, false), it will return false, else it will return true.
  • Or or ||

    • Input[]: Array (Size: Unlimited).
    • Output: Boolean (true or false).
    • Description: Do the Oring operation, if all values in Input[] has a value of (null, 0, false), it will return false, else it will return true .
  • 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 return false 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.
  • More...

💻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

Package Sidebar

Install

npm i @jsonlang/logic

Homepage

jsonlang.dev

Weekly Downloads

17,444

Version

0.0.13

License

MIT

Unpacked Size

50.4 kB

Total Files

16

Last publish

Collaborators

  • ahmed.medhat.tawfiq