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

libqalculate-lite-wasm

v0.1.2

Published

libqalculate compiled to WebAssembly with a single plain-text calculate() binding

Readme

libqalculate-lite-wasm

libqalculate compiled to WebAssembly, exposing calculate(expression, timeoutMs) with plain-text output plus the library's exchange-rate feeds. A trimmed fork of stephtr/libqalculate-wasm for use inside the unimo desktop launcher, where every platform's webview runs the same wasm and no native libqalculate build is needed.

Usage

import loadLibqalculate from 'libqalculate-lite-wasm';
import wasmUrl from 'libqalculate-lite-wasm/dist/libqalculate.wasm?url'; // vite

const calc = await loadLibqalculate({ locateFile: () => wasmUrl });
const { expression, result, messages } = calc.calculate('2^10', 300);
// expression: "2^10", result: "1024", messages: []

An unknown name is reported in messages as an error. The deadline is cooperative and covers evaluation only: parsing is not interruptible, a hit deadline is not reported (the result is then partial, unevaluated, or the literal timed out), and thousands of nested calls throw. Keep inputs short.

The loader is built for the web (fetch); in Node or bun pass the bytes instead:

const calc = await loadLibqalculate({ wasmBinary: await Bun.file('.../libqalculate.wasm').arrayBuffer() });

Under a Content Security Policy, script-src needs 'wasm-unsafe-eval'.

dist/libqalculate.wasm.br is the same wasm brotli-compressed (about a quarter of the size). Serve it with Content-Encoding: br where you control the headers; otherwise decompress it in the page, e.g. with brotli-wasm:

import loadLibqalculate from 'libqalculate-lite-wasm';
import brotliPromise from 'brotli-wasm';
import wasmBrUrl from 'libqalculate-lite-wasm/dist/libqalculate.wasm.br?url'; // vite

const [brotli, compressed] = await Promise.all([brotliPromise, fetch(wasmBrUrl).then(r => r.arrayBuffer())]);
const calc = await loadLibqalculate({ wasmBinary: brotli.decompress(new Uint8Array(compressed)) });

Exchange rates

Currencies work immediately from the ECB snapshot that libqalculate embeds at its release; results carry a warning once those rates are more than a week old. For live rates the host fetches libqalculate's own feed files and hands the bodies over:

| feed | source | body | |---|---|---| | 1 | European Central Bank, EUR base, about 30 currencies | eurofxref-daily.xml | | 2 | Coinbase spot price of BTC in EUR | JSON with amount and currency | | 3 | extra currencies (mycurrency.net, floatrates or currency-api layouts) | JSON |

for (const feed of [1, 2, 3] as const) {
  const body = await (await fetch(calc.exchangeRatesUrl(feed))).text(); // or your own proxy
  calc.setExchangeRates(feed, body);
}

The bodies live in the module's in-memory filesystem, so the host keeps them (and their fetch time) and feeds them again after every load, refetching when older than a day. Inside a webview the fetch is subject to CORS; do it from the host process or through a proxy. Pass the bodies through untouched: libqalculate's XML walk depends on the whitespace between the ECB file's elements, so a proxy that re-serialises or minifies it silently yields no rates.

Consumed as a git dependency pinned to a commit; dist/ is tracked, so a consumer never needs the toolchain.

Building

toolchain.sh installs emsdk and builds GMP, MPFR, libxml2 and libqalculate for wasm (versions pinned at its top); compile.sh turns src/libqalculate.cc into dist/libqalculate.js + dist/libqalculate.wasm, plus dist/libqalculate.wasm.br for hosts that can serve the wasm with Content-Encoding: br. Locally, ./build-wasm.sh runs both through Docker (the daemon must be running; the first image build takes a while, each toolchain step is its own layer, and any edit to toolchain.sh rebuilds them all). CI runs the same two scripts in a node:22-bookworm container on every push, tests the committed dist/ first, caches the built libraries until toolchain.sh changes, tests the fresh build, and uploads it.

Commit dist/ with the source change that produced it; bun test runs a smoke check against it.

Defaults set in src/libqalculate.cc: radians, an unknown word is an error rather than a product of one-letter units, 10 significant digits, and ASCII operators, no digit grouping and no 0.333... so a copied result pastes anywhere.

Differences from upstream

  • libqalculate pinned to a release tarball instead of git master.
  • Single calculate() returning plain text; no set_option, variables or plot data.
  • Exchange rates through libqalculate's own feed files (ECB, Coinbase BTC, extra currencies) instead of a JS rate table limited to EUR pairs.
  • ES module output with typed locateFile / wasmBinary options.
  • Built artifacts tracked in dist/, no npm publishing; Forgejo CI instead of GitHub Actions and a registry.

License

GPL-3.0-only, as upstream. libqalculate itself is GPL-2.0-or-later.