0.0.3 • Published 10 months ago

@cf-wasm/quickjs v0.0.3

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

@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          # pnpm

Usage

  • Cloudflare Workers / Pages (Esbuild):

    import { getQuickJSWASMModule } from "@cf-wasm/quickjs";
  • Next.js Edge Runtime (Webpack):

    import { getQuickJSWASMModule } from "@cf-wasm/quickjs/next";
  • 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;
0.0.3

10 months ago

0.0.2

12 months ago

0.0.1

12 months ago