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 🙏

© 2024 – Pkg Stats / Ryan Hefner

wasmwrap

v1.0.0

Published

Wrap WASM binaries in plain JS files (base64 encoded)

Downloads

410

Readme

📦 wasmwrap

Wrap WASM into JS files as base64.

This command line tool generates a typescript or a javascript file that you can simply import or require in your code, it plays nice with any bundler such as Webpack or Rollup.

Useful for shipping small WebAssembly libraries, in testing, and as a build step after generating .wasm files.

Installation

npm install --save wasmwrap

Usage

$ wasmwrap --help
Options:
  --help            Show help                                          [boolean]
  --version         Show version number                                [boolean]
  --input           Input filepath to wrap, can be any file. [string] [required]
  --output          Where to write the output, if not specified it prints the
                    file contents to STDOUT.                            [string]
  --language        language of output file, by default it looks at the output
                    filename.  [choices: "js", "ts", "match"] [default: "match"]
  --module          module type to generate, only necessary to change if you are
                    using an old node version.
                                   [choices: "esm", "commonjs"] [default: "esm"]
  --include-decode  include a base64 decode function that works both in the
                    browser and in node/deno (~1KB unminified).
                                                       [boolean] [default: true]

Examples

Generate JS file

wasmwrap --input myfile.wasm --output myfile.wasm.js 

Generate Typescript file

wasmwrap --input myfile.wasm --output myfile.wasm.ts

Advanced

Excluding the decode function

By default the generated file contains a base64 decode function that works in both the browser, node or deno. If you wish to exclude this and use your own you can specify --no-include-decode.

CommonJS module output

If you are using an old Node version you can instead generate a CommonJS module by passing --module=commonjs.

Motivation - Why not use a bundler for wrapping wasm?

Wrapping WebAssembly into a Javascript or Typescript file is something that you can do using various bundler plugins (such as my own rollup-plugin-base64), but for a lot of projects a bundler is overkill, or perhaps you need more control.

Using a bundler also leads to a more difficult testing story here: how do you test code that first requires the bundle step?

With this small but sharp tool you can add this as a build step right after you generate the .wasm or .wat file and generate a JS or TS file that you can then import. You can then still use your bundler without any special WebAssembly plugins.