1.1.9 • Published 5 months ago

jseval-wasm v1.1.9

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

jseval-wasm

A safe eval library based on WebAssembly and Duktape/QuickJS, that can run on nodejs, browser and workers(cloudflare workers).

Usage

import { QuickJs, DukTape } from "jseval-wasm";

QuickJs().then((quickjs) => {
  quickjs.evalJs("const aa = 10;aa").then((res) => {
    console.log("quickjs ", res); // 10
  });
});

DukTape().then((duktape) => {
  duktape.evalJs("const aa = 10;aa").then((res) => {
    console.log("duktape ", res); // 10
  });
});

OR

const { evalJs } = await QuickJs(); // or `const { evalJs } = await DukTape();`
const res = await evalJs("const aa = 10;aa");
console.log(res); // 10

when running on an edge environment like; cloudflare workers or deno deploy. Import it like this:

import { QuickJs } from 'jseval-wasm/index-bundler';

API

DukTape(): DukTape

Returns an instance of DukTape containing the evalJs function.

QuickJs(): QuickJs

Returns an instance of QuickJs containing the evalJs function.

evalJs: (jscode: string, timeout?: number) => Promise<any>

Evaluate JavaScript code string with the Quickjs or Duktape engine, and return a value.

Q&A

What can it runs?

DukTape can run ES5 syntax and some ES6, ES7 capabilities. QuickJs can run almost complete feature set of ES10.

Why two version?

DukTape is smaller, but less feature. QuickJs has a more complete JavaScript support, but it result in bigger size.

How can I return data from it?

Just like normal eval, for example var a={};a.prop=1;a will return { prop: 1 }. But keep in mind, only JSON serializable data can be returned.

How big is this?

DukTape is about 348kB, and gzipped version is 154kB. QuickJs is about 500kB, and gzipped version is 225kB.

1.1.9

5 months ago

1.1.8

5 months ago

1.1.7

8 months ago

1.1.6

8 months ago

1.1.5

8 months ago

1.1.4

8 months ago

1.1.3

8 months ago

1.1.2

8 months ago

1.1.1

8 months ago

1.1.0

8 months ago

1.0.9

8 months ago

1.0.8

8 months ago

1.0.7

8 months ago

1.0.6

8 months ago

1.0.5

8 months ago

1.0.4

8 months ago

1.0.3

8 months ago

1.0.2

8 months ago

1.0.1

8 months ago

1.0.0

8 months ago