Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

expression-parser-js

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

expression-parser-js

Implementation of logical expressions for JavaScript.

  • 0.1.0
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

Why Expression Parser?

  • Small and simple, but powerful.

  • No dependency, no ast.

Install

npm install expression-parser-js

Usage

var parser = require('expression-parser-js');
parser.parse(input, model)

examples

var model = {};
model.a = 1;
model.b = 2;
model.c = function () {
   return {
       d: 5
   }
};

model.e = ['a', 'b', 'c'];
model.f = [false];
model.h = ['a b', 'b c'];
model.g = [{
   a:1
}]
function exec(input) {
   return parser.parse(input, model);
}
console.log(exec('1 in [1,2,3]'));
console.log(exec('(1 in [1,2,3])'));
console.log(exec('a>=1'));
console.log(exec('c().d==5'));
console.log(exec('!(a>=1 && c().d == 5 && b<=2)'));
console.log(exec('a>=1 && c().d == 5 && b>2'));
console.log(exec('a>=1 || c().d == 5 || b>2'));
console.log(exec('(a>=1 && c().d == 5) || b>2'));
console.log(exec('a>=1 && (c().d == 5 || b>2)'));
console.log(exec('"a" in e'));
console.log(exec('"e" in e'));
console.log(exec('!("e" in e)'));
console.log(exec('!(f[0])'));
console.log(exec('f[0]'));
console.log(exec('"a b" in h'));
console.log(exec('a+1'));
console.log(exec('g[0].a+1'));

demo

open examples/index.html

Tests

npm install
mocha

Developer

npm install
gulp
open examples/index.html

Not Support

console.log(exec('a>=1 && c().d == 5 && !(b>2)'));

FAQs

Package last updated on 28 Sep 2018

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