# simple-evaluate

> [![NPM version][npm-image]][npm-url] [![build status][travis-image]][travis-url] [![Test coverage][coveralls-image]][coveralls-url] [![npm download][download-image]][download-url]

Latest version **1.4.6** (published 2022-09-24) · MIT license · 0 weekly downloads

## Install

```sh
npm install simple-evaluate
pnpm add simple-evaluate
yarn add simple-evaluate
bun add simple-evaluate
```

## Health

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

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.6 |
| Published | 2022-09-24 |
| First published | 2017-10-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 1 |
| Unpacked size | 41.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 61 |
| Author | sheperdwind |
| Maintainers | shepherdwind |

## Links

- npm: https://www.npmjs.com/package/simple-evaluate
- Repository: https://github.com/shepherdwind/simple-evaluate
- Homepage: https://github.com/shepherdwind/simple-evaluate#readme
- Issues: https://github.com/shepherdwind/simple-evaluate/issues
- npm.io page: https://npm.io/package/simple-evaluate

## Dependencies (1)

- [get-value](https://npm.io/package/get-value.md) ^2.0.6

## Recent versions

- 1.4.6 (latest) — 2022-09-24
- 1.3.0-beta (beta) — 2019-12-10
- 1.4.5 — 2022-07-07
- 1.4.4 — 2021-11-22
- 1.4.3 — 2021-02-25
- 1.4.2 — 2020-08-11
- 1.4.1 — 2020-08-10
- 1.4.0 — 2019-12-18
- 1.3.1 — 2019-12-11
- 1.3.0 — 2019-12-10
- 1.2.0 — 2018-09-11
- 1.1.0 — 2018-07-07
- 1.0.3 — 2017-11-29
- 1.0.2 — 2017-10-06
- 1.0.1 — 2017-10-04
- … 1 more at https://npm.io/package/simple-evaluate/versions

## README

# Simple Evaluate

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![npm download][download-image]][download-url]

[npm-image]: http://img.shields.io/npm/v/simple-evaluate.svg?style=flat-square
[npm-url]: http://npmjs.org/package/simple-evaluate
[download-image]: https://img.shields.io/npm/dm/simple-evaluate.svg?style=flat-square
[download-url]: https://npmjs.org/package/simple-evaluate
[travis-image]: https://img.shields.io/travis/shepherdwind/simple-evaluate.svg?style=flat-square
[travis-url]: https://travis-ci.org/shepherdwind/simple-evaluate
[coveralls-image]: https://img.shields.io/coveralls/shepherdwind/simple-evaluate.svg?style=flat-square
[coveralls-url]: https://coveralls.io/r/shepherdwind/simple-evaluate?branch=master


A safe parse for simple js expression.

### Usage

```js
import evaluate from 'simple-evaluate';
evaluate(null, '12 + 1 > 14');
evaluate({ a }, 'a + 1 > 14');
```

### Support operation include

- Math operator `+ - * / %`
- ternary expression `a ? b : c`
- Comparison `> < >= <= == != === !==`
- Logical `&& || !`
- Negation

You can run those expression, for example:

```js
evaluate({}, '!a > 0');
evaluate({}, 'a > 0 || a < -12 || 12 + 2*(4 + 4) < 12');
evaluate({ a: 1 }, '-a * 2');
```

### context find

`$.` stand for the root value all `context`, value path only support '.', and not support function call.

> since 1.2.0, `$.` is optional. That mean `$.a.b` is equal to `a.b`

### string and boolean

String and boolean support, string start with `' | "`, just the same as javascript expression.

Boolean use two key words, `true | false`.

### template string

You can use template string, just like the javascript syntax, for example.

```js
evaluate({ a: 22 }, "`I am ${ a >= 18 ? 'adult' : 'child' }`").should.equal('I am adult');
```

### Operation no support

- Funcion call

So, you can not run those expression

```js
evaluation({}, 'a(1) > 0');
```

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