QuickJS
npm install @cf-wasm/quickjsA 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.
``shell`
npm install @cf-wasm/quickjs # npm
yarn add @cf-wasm/quickjs # yarn
pnpm add @cf-wasm/quickjs # pnpm
- Cloudflare Workers / Pages (Wrangler):
`ts`
import { getQuickJSWASMModule } from "@cf-wasm/quickjs/workerd";
- Next.js Edge Runtime:
`ts`
import { getQuickJSWASMModule } from "@cf-wasm/quickjs/edge-light";
- Node.js (file base):
`ts`
import { getQuickJSWASMModule } from "@cf-wasm/quickjs/node";
Here are some examples for using this library.
If you are using Cloudflare Workers, you can use it as shown below:
`ts
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;
``