# wasm-eval

> Code used to demonstrate how to use wasm-pack

Latest version **0.1.1** (published 2018-12-14) · MIT/Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install wasm-eval
pnpm add wasm-eval
yarn add wasm-eval
bun add wasm-eval
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.1 |
| Published | 2018-12-14 |
| First published | 2018-12-13 |
| Weekly downloads | 0 |
| License | MIT/Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 0 |
| Unpacked size | 1.1 MB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 1 |
| Maintainers | habitbreaker |

## Links

- npm: https://www.npmjs.com/package/wasm-eval
- Repository: https://github.com/danielholzner/wasm-eval
- Homepage: https://github.com/danielholzner/wasm-eval#readme
- Issues: https://github.com/danielholzner/wasm-eval/issues
- npm.io page: https://npm.io/package/wasm-eval

## Recent versions

- 0.1.1 (latest) — 2018-12-14
- 0.1.0 — 2018-12-13

## README

## Description
This crate can evaluate expressions like `("{} + {} * {}", ["1","2","3"])`. It was developed to eval JavaScript-code of the client in a safe context.

The crate is based on the Rust [eval](https://docs.rs/eval)-crate and its supported 
operators are:

 `! != "" '' () [] . , > < >= <= == + - * / % && || n..m.`

 See for supported operators.
## Requirements
Your web-server must support the `application/wasm` Mime-Type.

Example for Jetty:
```java
//add new mime-type mapping
ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
MimeTypes mt = context.getMimeTypes();
mt.addMimeMapping("wasm", "application/wasm");
```

## Usage
Import the wasm-module into your app (e.g. import in ember via [ember-auto-import](https://github.com/ef4/ember-auto-import)):
```javascript
(async () => {
    // Importing wasm module
    const { eval_syn, schedule_eval } = await import('wasm-eval')
    const values = ["1", "2," "3"];
    const expr = "{} + {} * {}";

    //eval_syn returns the value directly
    console.log(eval_syn(expr, values)); // 1 + 2 * 3 = 7

    /**
     * returns a promise (non-blocking) 
     * Useful for long expressions
     */
    schedule_eval(expr, values).then(res => {
        if(res) {
            console.log(res); // 7
        } else { // null is returned on parse error
            console.log("Could not parse expression");
        }
    });
})();
```

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