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

minlink

v2.0.1

Published

Minimum(~ 1kb) and isomorphic worker wrapper with comlink like rpc.

Downloads

6

Readme

minlink

Minimum(~ 1kb) and isomorphic worker wrapper with comlink like rpc.

npm install minlink --save
# or
yarn add minlink

Why?

  • WebWorker(DedicateWorker) and node's Worker(threads) have similar api but not same one. This library wraps them to same rpc.
  • minlink is inspired by comlink but to keep simple and small core, minlink does not use ES2015 Proxy(or its polyfill). Instead of proxy, minlink provides typescript's type utils.

Requirements

  • Node 14+
  • Modern Browser + IE11(WIP: Not tested yet)

Browser WebWorker

Minlink takes WebWorker as expose/wrap. Bundle them with webpack or rollup.

// browser worker.js
import { expose } from "minlink/dist/browser.mjs";
const impl = {
  async foo(n; number) {
    return n + 1;
  },
};
expose(self, impl);

// browesr main.js
// import { wrap } from "minlink/dist/browser.legacy.js"; // for ie11. UMD build.
import { wrap } from "minlink/dist/browser.mjs";
const api = wrap(new Worker("./worker.js"));
const ret = await api.exec("foo", 1);
console.log(ret); // => 2
await api.terminate();

Node Worker

Minlink takes worker_threads/Worker as expose/wrap.

// main.mjs
import { wrap } from "comlink/dist/node.mjs";
import { Worker } from "worker_threads";
const worker = new Worker("./worker.mjs");
const api = wrap(worker);
const res = await api.exec("foo", 1);
console.log("response", res);

// worker.mjs
import { expose } from "minlink/dist/node.mjs";
import { parentPort } from "worker_threads";
expose(parentPort, {
  async foo(n) {
    return n + 1;
  },
});

Advanced: TypeScript utilities

// browser/worker.ts
import { expose } from "minlink/dist/browser.mjs";
const impl = {
  async foo(n; number) {
    return n + 1;
  },
};
export type RemoteImpl = typeof impl;
expose(self, impl);

// browesr/main.ts
import type { RemoteImpl } from "./worker.ts"; // Typescript 3.9+ Type only import
import { wrap } from "minlink/dist/browser.mjs";
const api = wrap<RemoteImpl>(new Worker("/worker.js")); // take RemoteImpl as `wrap(...)`'s type argument.
const ret = await api.exec("foo", 1); // pass
const ret = await api.exec("foo", "invalid arg"); // type error

Advanced: Transferrable

const buf = new Uint8Array([1]);
const ret = await api.exec(["foo", [buf]], buf); // pass

Advanced: Call client expose from worker.

TBD

Inspired by ...

  • https://github.com/GoogleChromeLabs/comlink
  • https://github.com/developit/web-worker

ChangeLog

  • v2: transferrable uses ['foo', [buf]] from {cmd: 'foo', transferrable: [buf]}
  • v1: release

LICENSE

MIT