Skip to content
This repository has been archived by the owner on Jun 23, 2023. It is now read-only.

Commit

Permalink
Document all import methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
donmccurdy committed Mar 29, 2020
1 parent 4670a70 commit 28feab5
Showing 1 changed file with 18 additions and 15 deletions.
33 changes: 18 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,30 @@ Powered by [jsep](https://github.com/soney/jsep).

## Installation

Install:

```
npm install --save expression-eval
```

### Standalone script
```html
<script src="./dist/expression-eval.umd.js"></script>
<script>
expressionEval.parse()
expressionEval.eval()
...
</script>
Import:

```js
// ES6
import { parse, eval } from 'expression-eval';
// CommonJS
const { parse, eval } = require('expression-eval');
// UMD / standalone script
const { parse, eval } = window.expressionEval;
```

## API

### Parsing

```javascript
const expr = require('expression-eval');
const ast = expr.parse('1 + foo');
import { parse } from 'expression-eval';
const ast = parse('1 + foo');
```

The result of the parse is an AST (abstract syntax tree), like:
Expand All @@ -55,18 +58,18 @@ The result of the parse is an AST (abstract syntax tree), like:
### Evaluation

```javascript
const expr = require('expression-eval');
const ast = expr.parse('a + b / c'); // abstract syntax tree (AST)
const value = expr.eval(ast, {a: 2, b: 2, c: 5}); // 2.4
import { parse, eval } from 'expression-eval';
const ast = parse('a + b / c'); // abstract syntax tree (AST)
const value = eval(ast, {a: 2, b: 2, c: 5}); // 2.4
```

Alternatively, use `evalAsync` for asynchronous evaluation.

### Compilation

```javascript
const expr = require('expression-eval');
const fn = expr.compile('foo.bar + 10');
import { compile } from 'expression-eval';
const fn = compile('foo.bar + 10');
fn({foo: {bar: 'baz'}}); // 'baz10'
```

Expand Down

0 comments on commit 28feab5

Please sign in to comment.