# 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.

Latest version **1.1.1** (published 2017-06-21) · MIT license · 0 weekly downloads

## Install

```sh
npm install morph-expressions
pnpm add morph-expressions
yarn add morph-expressions
bun add morph-expressions
```

## Health

**Score 20/100 (F)** — status: abandoned.

Positive: esm support; no vulnerabilities.

Warnings: low downloads; no types.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.1.1 |
| Published | 2017-06-21 |
| First published | 2016-05-25 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 17 |
| Author | Alex Bukurov |
| Maintainers | abukurov |
| Keywords | dsl, compiler, translator, expression, expressions, parser, lexer, parse, eval, source, math, mathematics, logic, logical, evaluate, evaluator |

## Links

- npm: https://www.npmjs.com/package/morph-expressions
- Repository: https://github.com/abukurov/morph-expressions
- Homepage: https://github.com/abukurov/morph-expressions#readme
- Issues: https://github.com/abukurov/morph-expressions/issues
- npm.io page: https://npm.io/package/morph-expressions

## Alternatives

- [babylon](https://npm.io/package/babylon.md) — 5.1M weekly downloads
- [csscolorparser](https://npm.io/package/csscolorparser.md) — 3.7M weekly downloads
- [expr-eval-fork](https://npm.io/package/expr-eval-fork.md) — 1.5M weekly downloads
- [@leeoniya/ufuzzy](https://npm.io/package/@leeoniya/ufuzzy.md) — 247.7K weekly downloads
- [xml-parser](https://npm.io/package/xml-parser.md) — 78.4K weekly downloads

## Recent versions

- 1.1.1 (latest) — 2017-06-21
- 1.1.0 — 2017-06-20
- 1.0.2 — 2017-02-02
- 1.0.1 — 2017-01-31
- 1.0.0 — 2017-01-31
- 0.0.6 — 2016-12-24
- 0.0.5 — 2016-12-24
- 0.0.4 — 2016-06-02
- 0.0.3 — 2016-05-25
- 0.0.2 — 2016-05-25
- 0.0.1 — 2016-05-25

## README

# 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](https://travis-ci.org/abukurov/morph-expressions.svg?branch=master)](https://travis-ci.org/abukurov/morph-expressions)
[![Coverage Status](https://coveralls.io/repos/github/abukurov/morph-expressions/badge.svg?branch=master)](https://coveralls.io/github/abukurov/morph-expressions?branch=master)
[![David](https://img.shields.io/david/abukurov/morph-expressions.svg)]()
[![npm](https://img.shields.io/npm/dt/morph-expressions.svg)](https://www.npmjs.com/package/morph-expressions)
[![MIT](https://img.shields.io/npm/l/morph-expressions.svg)](https://github.com/abukurov/morph-expressions/blob/master/LICENSE.md)
[![NPM Version](https://img.shields.io/npm/v/morph-expressions.svg)](https://www.npmjs.com/package/morph-expressions)

##Install
```
$ npm install morph-expressions
```

## Usage

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

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

You can also specify `scope`:

```javascript
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

```javascript
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

---
_Source: https://npm.io/package/morph-expressions · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
