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

micro-wrkr

v0.1.0

Published

Wrappers for built-in Web Workers enabling easy parallel data processing

Downloads

25

Readme

micro-wrkr

Wrappers for built-in Web Workers enabling easy parallel data processing.

  • 🔒 CSP-friendly: no evals, static file name
  • 🔍 Tested in browsers, node, deno, bun
  • 📦 Can be bundled using esbuild, rollup, webpack, parcel
  • 🏭 High-level type-safe helpers for batch processing
  • ⛓ Sync: much simpler than async, no queues / locks

Why

Browser Web Workers work fine, but have terrible APIs (just like most "web APIs"). Node.js doesn't have workers, while polyfilling them using node APIs breaks bundlers.

How could one pass a code to a worker?

  • eval: stringify function, then eval. Would break CSP and imports
  • wasm: much easier, just send binary blob of code. Would not work in envs without wasm
  • re-run module with if-workercode-else-maincode: fragile, need to track everything done before workers are initialized (IO such as HTTP, DOM)
  • build static file before publishing: works if wrkr is directly used, but not inside of other library

Check out webpack docs on webworkers.

The library could also be used in single-threaded manner: provide threads option to initBatch. Then slow functions can be ran outside of main thread, with async API.

Usage

npm install micro-wrkr

deno add jsr:@paulmillr/micro-wrkr

deno doc jsr:@paulmillr/micro-wrkr # command-line documentation

Main file main.js

import { bn254 } from '@noble/curves/bn254';
import { type ProjConstructor, type ProjPointType } from '@noble/curves/abstract/weierstrass';
import wrkr from 'micro-wrkr';
import { type Handlers } from './msm-worker.js';

function reducePoint<T>(p: ProjConstructor<T>) {
  return (lst: ProjPointType<T>[]) =>
    lst.map((i) => new p(i.px, i.py, i.pz)).reduce((acc, i) => acc.add(i), p.ZERO);
}

export function initMSM() {
  // Type-safe
  // worker should be in same directory as main thread code
  const { methods, terminate } = wrkr.initBatch<Handlers>(
    () => new Worker(new URL('./msm-worker.js', import.meta.url), { type: 'module' }),
    {
      // optional reducers
      bn254_msmG1: reducePoint(bn254.G1.ProjectivePoint),
      bn254_msmG2: reducePoint(bn254.G2.ProjectivePoint),
    }
  );
  // Use `terminate` to stop workers when app is paused or exported from library.
  // Otherwise, it won't terminate.
  return { methods, terminate };
}

Worker file msm-worker.js

import { bn254 } from '@noble/curves/bn254';
import wrkr from 'micro-wrkr';
import { type ProjConstructor, type ProjPointType } from '@noble/curves/abstract/weierstrass';

type MSMInput<T> = { point: ProjPointType<T>; scalar: T };

function buildMSM<T>(point: ProjConstructor<T>) {
  return (lst: MSMInput<T>[]): ProjPointType<T> => {
    if (!lst.length) return point.ZERO;
    const points = lst.map((i: any) => new point(i.point.px, i.point.py, i.point.pz));
    const scalars = lst.map((i: any) => i.scalar);
    return point.msm(points, scalars);
  };
}

const handlers = {
  bn254_msmG1: buildMSM(bn254.G1.ProjectivePoint),
  bn254_msmG2: buildMSM(bn254.G2.ProjectivePoint),
};
// Export Handlers type for type-safety
export type Handlers = typeof handlers;
wrkr.initWorker(handlers);

Testing

  • Browserify isn't supported
  • Webpack sometimes breaks CSP by encoding workers as data:url
    • Example: new Worker(new URL(e.p+e.u(44),e.b),{type:void 0})
# when no google chrome, thorium can also be used
export CHROME_BIN='/Applications/Thorium.app/Contents/MacOS/Thorium'
npm run build && npm run test:full

License

MIT (c) Paul Miller (https://paulmillr.com), see LICENSE file.