New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

logical-expression-parser

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

logical-expression-parser

Logical expression parser and evaluates result, suitable for permissions management

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
599
17.68%
Maintainers
1
Weekly downloads
 
Created
Source

Logical Expression Parser

npm version

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

  • | Or
  • & And
  • ! Not
  • () Parentheses

How it works

  • The parser parse and tokenize the expression, for example one of your function requires REGISTED&(SPECIAL|INVITED)
  • Parser then will pass REGISTED, SPECIAL and INVITED into your token checking function to get a boolean result
  • Finaly the parser will evaluates the final result

Example

const LEP = require('logical-expression-parser');

const REQUIREMENTS = 'REGISTED&(SPECIAL|INVITED)';
const LIST_A = ['REGISTED', 'INVITED'];
const LIST_B = ['SPECIAL', 'EXPERT'];

const RESULT_A = LEP.parse(REQUIREMENTS, t => LIST_A.indexOf(t) > -1);
const RESULT_B = LEP.parse(REQUIREMENTS, t => LIST_B.indexOf(t) > -1);

// RESULT_A: true
// RESULT_B: false

Keywords

parser

FAQs

Package last updated on 21 Apr 2023

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