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

@sv-kit/workerify

v1.0.0

Published

Headless Web Worker RPC: wrap(url), workerify(fn), expose(api). Abort, transferables, and typed proxies.

Downloads

7

Readme

@sv-kit/workerify

轻量 Web Worker RPC 工具(零依赖):

  • Workerexpose({ foo(){...} }) 暴露方法
  • 主线程wrap(url) 生成同名代理,直接当异步函数调用
  • 想偷懒?workerify(fn) 一行把单函数变 Worker(动态 Blob)
  • 自带 AbortSignal 取消、错误序列化、自动收集 Transferable、默认 type:"module"、SSR 安全

安装

pnpm add @sv-kit/workerify

用法 1:多方法模块(推荐)

worker.ts

import { expose } from '@sv-kit/workerify';

function sha256(buf: ArrayBuffer, { signal }: { signal: AbortSignal }) {
  signal.throwIfAborted?.();
  return crypto.subtle.digest('SHA-256', buf);
}
async function heavySum(nums: Float64Array) {
  let s = 0;
  for (let i = 0; i < nums.length; i++) s += nums[i];
  return s;
}

expose({ sha256, heavySum });

主线程

import { wrap } from '@sv-kit/workerify';

const api = wrap<typeof import('./worker')>('/workers/worker.js', { name: 'calc' });

const ctrl = new AbortController();
setTimeout(() => ctrl.abort(), 1000); // 1s 取消

// 自动把 ArrayBuffer 作为 Transferable 传过去,不会拷贝
const buf = new Uint8Array([1,2,3]).buffer;
const digest = await api.sha256(buf, { signal: ctrl.signal }).catch(e => console.warn(e.name));

const sum = await api.heavySum(new Float64Array([1,2,3,4]));
api.terminate(); // 用完销毁

用法 2:单函数 worker(动态 Blob)

import { workerify } from '@sv-kit/workerify';

const fib = workerify((n: number) => {
  const f = (x: number): number => x <= 1 ? x : f(x-1) + f(x-2);
  return f(n);
}, { name: 'fib' });

console.log(await fib(35));
fib.terminate();

注意:workerify(fn) 会把 fn.toString() 注入 Worker,所以 fn 不要闭包外部变量

取消 / 错误

  • 主线程 wrap(url) 调用时传 { signal },Worker 内你的方法会收到 { signal } 作为最后一个参数(可选)。
  • Worker 里抛出的错误会被序列化回主线程(name/message/stack)。

Transferable(零拷贝)

调用时会自动递归收集 ArrayBufferMessagePortImageBitmapOffscreenCanvasTransferable 对象并随 postMessage 传输,避免拷贝大数据。 自定义结构深度可在 wrap(url,{transferDepth}) 调整(默认 3 层)。

SSR 安全

wrap/workerify 仅在浏览器有效;服务端调用会抛错以避免踩坑。

与 Svelte/React 的关系

这是 headless 工具,不依赖任何框架;你可在 Svelte action/store 或 React hooks 里随意包一层胶水。

许可

MIT