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

worker-tls

v1.1.0

Published

worker-tls 提供了 动态Worker 功能 和 其它一些 Worker 场景下有用的工具集;让开发者可以像调用对象方法一样动态地调用Worker中的方法,也可以随时地往 Worker 中动态地添加函数 等等。

Readme

目录:

  1. 背景
  2. 简介
  3. 安装方式
    1. 方式1:通过 npm 安装
    2. 方式3:通过<script>标签引入
  4. 教程
  5. API接口文档

背景

在创建 Worker 时,总是需要提被运行代码的脚本文件的 url,这使得会有如下诸多不便:

  • 需要把在 Worker 中运行的代码放在一个独立的文件中。
  • 如果项目需要构建,还需要为这些在 Worker 中运行的文件配置专门的构建策略;
  • 如果你开发的是一个工具库,那 Worker 代码的构建包还不能直接在项目中引用,你和使用该工具库的用户还需要做以下操作,才能保存工具库正常运行:
    1. 你和用户事先约定好以下内容:
      • npm包中存放 Worker 代码的目录;
      • 运行时,用户如何告诉你 Worker 代码 路径;
    2. node_modules 中找到工具库的包;
    3. 将包中约定位置 下的 Worker 代码包拷贝到用户项目中不会被构建的目录中(比如:public);
    4. 用户将刚拷出来的 Worker 代码包 的运行时路径通过 第1步 中约定的方式告诉工具库;
    5. 当工具库更新时,用户需要重新执行下上面的步骤;

除此之外,Worker 的事件通信机制使得:

  • 在 TypeScript 场景中,Worker 之间传递数据的类型不明确;
  • Worker 之间不能像对象一样,互相调用对方的API;
  • 不能动态地往 Worker 中添加新的任务,或 删除旧的任务;
  • 等等

worker-tls 中的 动态Worker 就可以完全解决这些问题!

除了 动态Worker 之外,worker-tls 还为深度定制 Worker 提供了一些有用的工具方法。

简介

worker-tls 提供了 动态Worker 功能 和 其它一些 Worker 场景下有用的工具集;让开发者可以像调用对象方法一样动态地调用Worker中的方法,也可以随时地往 Worker 中动态地添加函数 等等。

具有以下特性:

  • 像调用对象方法一样调用Worker中的API;
  • 不需要特殊的构建就能使用 Worker;
  • 可以动态地向 Worker 中添加函数,就像给对象添加方法一样简单;
  • 可以动态地移除 Worker 中的函数,就像移除对象的方法一样简单;
  • 完善的 TypeScript 类型提示;
  • 运行时自动完善快捷命令;
  • 支持 流、Promise 及其深层嵌套;
  • 支持 专用Worker 和 共享Worker SharedWorker
  • 支持 worker 池:只需要传递一个数字,就可以创建一个 worker 池,并会自动地分配任务给 worker 池中的 worker 去执行;

详情请看:

如果您在使用的过程中遇到了问题,或者有好的建议和想法,您都可以通过以下方式联系我,期待与您的交流:

安装方式

目前,安装方式有以下几种:

方式1:通过 npm 安装

通过 npm (或 yarn、pnpm 等包管理器)安装

npm install worker-tls

方式3:通过<script>标签引入

您可直接从项目的 发行地址 中下载以 .iife.js 作为缀的文件,然后使用如下代码引用 和 使用 worker-tls:

  1. 引用 worker-tls

    <script src="path/to/package/worker-tls.iife.js"></script>
  2. 使用全局的 WorkerTls

    <script>
    // 使用全局的 WorkerTls
    </script>

教程

API接口文档

详情跳转至API接口文档