@cf-wasm/quickjs
v0.2.3
Published
QuickJS
Downloads
4,349
Readme
@cf-wasm/quickjs
A high-performance, secure, extensible JavaScript runtime.
Powered by quickjs-emscripten
[!WARNING] This package is in development. Breaking changes may be introduced without following semantic versioning.
Installation
npm install @cf-wasm/quickjs # npm
yarn add @cf-wasm/quickjs # yarn
pnpm add @cf-wasm/quickjs # pnpmUsage
Cloudflare Workers / Pages (Wrangler):
import { getQuickJSWASMModule } from "@cf-wasm/quickjs/workerd";Next.js Edge Runtime:
import { getQuickJSWASMModule } from "@cf-wasm/quickjs/edge-light";Node.js (file base):
import { getQuickJSWASMModule } from "@cf-wasm/quickjs/node";
Examples
Here are some examples for using this library.
Cloudflare Workers
If you are using Cloudflare Workers, you can use it as shown below:
import {
getQuickJSWASMModule,
shouldInterruptAfterDeadline,
} from "@cf-wasm/quickjs";
export default {
async fetch() {
const QuickJS = await getQuickJSWASMModule();
const result = QuickJS.evalCode(
"({ multiplication: 50 * 6, random: Math.random() })",
{
shouldInterrupt: shouldInterruptAfterDeadline(Date.now() + 1000),
memoryLimitBytes: 1024 * 1024,
}
);
return Response.json({ result });
},
} satisfies ExportedHandler;