Socket
Socket
Sign inDemoInstall

morph-expressions

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    morph-expressions

An extremely efficient and flexible parser for Math or Logical expression using Javascript. It has all the basic functions supported with extensive support for new functions, variable etc.


Version published
Weekly downloads
347
increased by10.51%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

morph-expressions

An extremely efficient and flexible parser for Math or Logical expression using Javascript. It has all the basic functions supported with extensive support for new functions, variable etc.

Build Status Coverage Status David npm MIT NPM Version

##Install

$ npm install morph-expressions

Usage

import Parser from 'morph-expressions';
const parser = new Parser();

const compiled = parser.parse('1 + 1');
compiled.eval(); // returns 2

You can also specify scope:

const compiled = parser.parse('x + 1 - y == 0');
compiled.identifiers; // ['x', 'y'] - returns list of identifiers, which used in expression
compiled.eval({ x: 2, y: 3 }); // returns true

//Or

parser.parseAndEval('x + 1 - y == 0', { x: 2, y: 3 });  // returns true
parser.parseAndEval('foo.bar[1] == 5', { foo: { bar: [4, 5, 6] } });  // returns true

For register the custom function or computed properties

parser.registerFunction('sqr', value => value * value);
parser.registerProperty('foo', scope => 'bar');

parser.parseAndEval('sqr(sqr(x))', { x: 2 });  // returns 16
parser.parseAndEval('foo', { x: 2 });  // returns 'bar'

Test

To execute tests for the library, install the project dependencies once:

npm install

Then, the tests can be executed:

npm test

Keywords

FAQs

Last updated on 21 Jun 2017

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc