New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@jeanbenitez/logical-expression-parser

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@jeanbenitez/logical-expression-parser

Logical expression parser and evaluates result, suitable for permissions management

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.6K
increased by21.5%
Maintainers
1
Weekly downloads
 
Created
Source

Logical Expression Parser (Fork)

This is a logical expression parser for JavaScript, it can parse a logical expression into a AST object and evaluates the result using your token checking function.

Supported logical operators

  1. OR
  2. AND
  3. () Parentheses

How it works

  1. The parser parse and tokenize the expression, for example one of your function requires REGISTED AND (SPECIAL OR INVITED)
  2. Parser then will pass REGISTED, SPECIAL and INVITED into your token checking function to get a boolean result
  3. Finaly the parser will evaluates the final result

Example

const LEP = require('@jeanbenitez/lep');

const requirements = 'REGISTED AND (SPECIAL OR INVITED)';
const listA = ['REGISTED', 'INVITED'];
const listB = ['SPECIAL', 'EXPERT'];

const resultA = LEP.parse(requirements, t => listA.includes(t));
const resultB = LEP.parse(requirements, t => listB.includes(t));
console.log({ resultA, resultB });
// { resultA: true, resultB: false }

// Getting AST only
const ast = LEP.ast(requirements);
console.log({ ast });
/*
  {
    ast: ExpNode {
      op: 'AND',
      left: ExpNode {
        op: 'LITERAL',
        literal: 'REGISTED'
      },
      right: ExpNode {
        op: 'OR',
        left: [ExpNode],
        right: [ExpNode]
      }
    }
  }
*/

Keywords

FAQs

Package last updated on 19 Feb 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc