# multimath

> Core to create fast image math in WebAssembly and JS.

Latest version **3.0.0** (published 2026-05-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install multimath
pnpm add multimath
yarn add multimath
bun add multimath
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads.

## Facts

| | |
|---|---|
| Version | 3.0.0 |
| Published | 2026-05-17 |
| First published | 2017-09-30 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 1 |
| Unpacked size | 33.2 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 74 |
| Maintainers | vitaly |
| Keywords | webassembly, math, image, multimath |

## Links

- npm: https://www.npmjs.com/package/multimath
- Repository: https://github.com/nodeca/multimath
- Homepage: https://github.com/nodeca/multimath#readme
- Issues: https://github.com/nodeca/multimath/issues
- npm.io page: https://npm.io/package/multimath

## Dependencies (1)

- [glur](https://npm.io/package/glur.md) ^2.0.0

## Alternatives

- [exif-parser](https://npm.io/package/exif-parser.md) — 3.8M weekly downloads
- [vite-plugin-compression](https://npm.io/package/vite-plugin-compression.md) — 569.5K weekly downloads
- [pica](https://npm.io/package/pica.md) — 442.4K weekly downloads
- [@reportportal/client-javascript](https://npm.io/package/@reportportal/client-javascript.md) — 408.8K weekly downloads
- [@tldraw/state](https://npm.io/package/@tldraw/state.md) — 316.0K weekly downloads

## Recent versions

- 3.0.0 (latest) — 2026-05-17
- 2.0.0 — 2019-07-15
- 1.0.3 — 2018-03-05
- 1.0.2 — 2017-10-13
- 1.0.1 — 2017-10-03
- 1.0.0 — 2017-09-30

## README

multimath
=========

[![NPM version](https://img.shields.io/npm/v/multimath.svg)](https://www.npmjs.org/package/multimath)

> Core to create fast image math in WebAssembly and JS.

`multimath` simplifies creation of small CPU-intensive webassembly modules
with fallback to JavaScript implementations.

- It cares about modules init, memory management and other things.
- Has built-in helpers to write webassembly code without additional runtimes.
- Use shared memory to chain webassembly calls without memory copy.

Built-in functions (currently - unsharp mask) are available as examples for
your extensions.


Install
-------

```bash
npm install multimath
```


Use
---

```js
import { MultiMath, unsharp_mask_plugin } from 'multimath'

const mm = new MultiMath()
             .use(unsharp_mask_plugin)
             .use(your_custom_plugin)

// Simple sync call. Will use sync wasm compile. Ok for webworkers.
// Can freeze interface at first call if wasm source is too big.
mm.unsharp_mask(rgba_buffer, width, height)

// Async init, compile all modules at once in async way.
await mm.init()
mm.unsharp_mask(rgba_buffer, width, height)
```


API
---


### new MultiMath(options)

Create library instance.

```js
const mm = new MultiMath({
  // Options are not mandatory, but you can disable js or wasm
  // implementations for testing
  js:   true,
  wasm: true
})
```


### .use(plugin)

Register new plugin, format is:

```js
{
  name:     String,    // method name to expose on instance
  fn:       Function,  // JS implementation
  wasm_fn:  Function,  // WebAssembly glue
  wasm_src: String     // Base64 encoded WebAssembly module
}
```

See `lib/unsharp_mask_plugin/` as an example implementation.


### .init() -> Promise

Optional. Compile all wasm modules asynchronously. Useful when:

1. Wasm module > 4K AND running in the main thread (not in a webworker).
   Some browsers prohibit sync wasm creation in this case.
2. Many small modules that should all be initialized before first use.

Note: a 3K wasm file initializes in ~3ms.


### .<your_method>

All plugins loaded via `.use()` pin their methods to the `MultiMath` instance.
The best implementation is selected automatically based on browser features
and constructor options.


### Development

Ways to go with your own plugins:

- See `lib/unsharp_mask_plugin/` as an example.
- See how [pica](https://github.com/nodeca/pica) uses this library.

---
_Source: https://npm.io/package/multimath · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
