npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

wasm-module-preprocessor

v0.0.3

Published

A general-purpose module for preprocessing WebAssembly (wasm).

Readme

wasm-module-preprocessor

A general-purpose module for preprocessing WebAssembly (wasm).

Install

npm install --save-dev wasm-module-preprocessor

Usage

wasm-module-preprocessor by default loads wasm modules asynchronously, and takes an optional importObject. All wasm modules are validated on build, so that there is no need for runtime testing and beyond just validating wasm modules, the size of the wasm module is checked too.

Async

file.wasm

<RANDOM GARBLED BINARY DATA>

test.js

import wasmModulePreprocessor from 'wasm-module-preprocessor';
import { readFileSync } from 'fs';
import { runInNewContext } from 'vm';

const bufferSource = readFileSync('file.wasm');

const wasmModuleExportString = wasmModulePreprocessor(
  bufferSource,
  {
    // Defaults to:
    // sync: false,
  }
);

const wasmModuleExport = runInNewContext(`(() => ${wasmModuleExportString})()`);

(async () => {
  try {
    const {
      instance: {
        exports: {
          main = () => undefined,
        },
      },
    } = await wasmModuleExport(
      // Add an optional `importObject`:
      // {
      //   global: {},
      //   env: {},
      // }
    );

    console.log(main() === 3); // true
  } catch (err) {
    console.error(err);
  }
})();

Sync

file.wasm

<RANDOM GARBLED BINARY DATA>

test.js

import wasmModulePreprocessor from 'wasm-module-preprocessor';
import { readFileSync } from 'fs';
import { runInNewContext } from 'vm';

const bufferSource = readFileSync('file.wasm');

const wasmModuleExportString = wasmModulePreprocessor(
  bufferSource,
  // Only use this for small wasm modules. The max size of the
  // binary will, by default, be restricted to less than 4KiB.
  { sync: true },
);

const wasmModuleExport = runInNewContext(`(() => ${wasmModuleExportString})()`);

const {
  exports: {
    main = () => undefined,
  },
} = wasmModuleExport(
  // Add an optional `importObject`:
  // {
  //   global: {},
  //   env: {},
  // }
);

console.log(main() === 3); // true

Documentation

wasmModulePreprocessor(bufferSource[, options])

  • bufferSource <string> | <Buffer> Default: <Buffer >

  • options <Object>

    • encoding <string> Default: 'binary'

    • maxBufferSourceSize <integer> Default: 1073741824

    • maxBufferSourceSizeSync <integer> Default: 4096

    • validate <boolean> Default: true

    • sync <boolean> Default: false

    • template <Object>

      • importObjectArg <string>

      • defaultImportObject <Function>

        • templateArgs <Object>

          • importObjectArg <string>
      • bufferSource <Function>

        • templateArgs <Object>

          • buffer <Buffer>
      • wasmModuleInstance <Function>

        • templateArgs <Object>

          • bufferSource <string>

          • importObject <string>

      • wasmModuleInstanceSync <Function>

        • templateArgs <Object>

          • bufferSource <string>

          • importObject <string>

      • moduleExport <Function>

        • templateArgs <Object>

          • bufferSource <string>

          • importObject <string>

bufferSource is the data from the binary wasm file. encoding is ignored if bufferSource is a buffer.

maxBufferSourceSize is the maximum size in bytes that the bufferSource can be and defaults to the max allowed by Node/V8 and most browsers. maxBufferSourceSizeSync is the maximum size in bytes that the bufferSource can be if used synchronously and defaults the max allowed by Chrome and most other browsers (Node/V8 has no such limitation).

validate is whether or not WebAssembly.validate is used to check the bufferSource before preprocessing.

sync is whether or not to preprocess the module as synchronous.

template is an object with properties to construct the string returned.