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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@ngocro208/easy-worker

v0.1.0

Published

A lightweight library to create Web Workers from inline functions without needing a separate file, with TypeScript support.

Readme

Easy Worker

A lightweight, zero-dependency TypeScript library to create and manage Web Workers from inline functions, eliminating the need for separate worker files. Ideal for simplifying parallelism in web applications.

Features

  • No Separate Worker File: Define worker logic directly in your main script.
  • TypeScript Native: Written in TypeScript with full type support.
  • Async/Await Friendly: Returns Promises for easy integration.
  • Dependency Imports: Supports importing external scripts into the worker using importScripts().
  • Simple API: createInlineWorker function to get started quickly.
  • Fallback: Gracefully handles environments where Web Workers are not supported by running tasks on the main thread asynchronously.
  • Zero Dependencies: The core library has no runtime dependencies.

Installation

npm install easy-worker
# or
yarn add easy-worker

Usage

  • 01-basic-execution.ts: Basic synchronous and asynchronous function execution.
  • 02-error-handling.ts: Demonstrates how errors from worker functions are propagated.
  • 03-multiple-workers.ts: Shows creating and using multiple worker instances.
  • index.html: External dependencies imports. HTML file uses easy-worker via ESM module since Bun JS engine does not have importScripts

See Examples

API

createInlineWorker<TFunc>(func: TFunc, options?: CreateInlineWorkerOptions): InlineWorker<TFunc>

Creates and returns an InlineWorker.

  • func The function to execute in the Web Worker.

    • Important: This function is serialized using toString(). It must be self-contained and cannot rely on lexical closures from its original scope unless variables are simple constants or globally available in a worker context (e.g., Math, JSON, or imported via dependencies). Pass all dynamic data as arguments.
    • this context inside the worker function will be the worker's global scope (self) or undefined in strict mode.
  • options (optional):

    • dependencies?: string[]: An array of script URLs for importScripts().

InlineWorker<TFunc>

An executable function that is also an object with methods:

  • (...args: Parameters<TFunc>): Promise<ReturnType>: Call the worker.
  • terminate(): void: Terminates the worker.
  • getWorkerInstance(): Worker | null: Returns the raw Worker object (or null in fallback mode).

Limitations

  • Closures: True lexical closures are not transferred. Functions must be self-contained or rely on passed arguments / importScripts.
  • DOM Access: Workers cannot directly access the main thread's DOM.
  • Function Serialization: The function passed to createInlineWorker is converted to a string. This has implications for complex functions, this context, and prototypes. Standard arrow functions, function expressions, and named function declarations work best. Object method shorthands might require wrapping.

Contributing

Contributions are welcome! Please open an issue or submit a pull request. (Remember to add contribution guidelines if you wish).