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

workboots

v1.2.0

Published

a lightweight message proxy for webworkers and worker threads

Downloads

21

Readme

Work Boots

A lightweight message proxy for web workers and worker threads that provides a unified API for background processing across different JavaScript environments.

Features

  • Cross-Platform Support: Works in both browser (Web Workers) and Node.js (Worker Threads) environments
  • Browserify Integration: Full compatibility with Browserify for universal module support
  • Automatic Fallback: Gracefully falls back to local execution when workers aren't supported
  • Unified API: Same interface regardless of the underlying worker implementation
  • Message Queuing: Handles messages sent before the worker is ready
  • Error Recovery: Robust error handling and recovery mechanisms
  • Performance Optimized: Efficient message passing and memory management

Installation

npm install workboots

Quick Start

Browser Environment (with Browserify)

// Using Browserify bundle
const { WorkBoots } = require('workboots/dist/work-boots.browser.js');

const workBoots = new WorkBoots({
  socksFile: './worker-universal.js'
});

workBoots.onMessage(({ data }) => {
  console.log('Received:', data);
});

await workBoots.ready();
workBoots.postMessage({ message: 'Hello from browser!' });

Node.js Environment

// Using ES modules
import { WorkBoots } from 'workboots';

const workBoots = new WorkBoots({
  socksFile: './worker-universal.js'
});

workBoots.onMessage(({ data }) => {
  console.log('Received:', data);
});

await workBoots.ready();
workBoots.postMessage({ message: 'Hello from Node.js!' });

Universal Worker File

// worker-universal.js - Works in both browser and Node.js
import { Socks } from 'workboots';

const socks = new Socks(typeof self !== 'undefined' ? self : undefined);

socks.onMessage(({ data }) => {
  console.log('Worker received:', data);
  
  const result = {
    processed: true,
    original: data,
    timestamp: Date.now(),
    worker: typeof window !== 'undefined' ? 'browser' : 'node'
  };
  
  socks.postMessage(result);
});

socks.ready();
export { socks };

Browserify Integration

Why Browserify?

Browserify provides full cross-platform compatibility by:

  1. Unified Module System: Handles require() vs import differences
  2. Path Resolution: Consistent file paths across environments
  3. Dependency Management: Bundles all dependencies into a single file
  4. Testing Compatibility: Resolves Jest and testing environment issues

Build Process

# Build browser bundle
npm run build:browser

# Build Node.js version
npm run build:node

# Build worker bundle
npm run build:worker

# Build all versions
npm run build

Usage with Browserify

Browser Bundle

<!DOCTYPE html>
<html>
<head>
    <title>Work Boots Browserify Example</title>
</head>
<body>
    <script src="dist/work-boots.browser.js"></script>
    <script>
        const { WorkBoots } = window.WorkBoots;
        
        const workBoots = new WorkBoots({
            socksFile: './worker-universal.js'
        });

        workBoots.onMessage(({ data }) => {
            console.log('Browser received:', data);
        });

        workBoots.ready().then(() => {
            workBoots.postMessage({ browser: true });
        });
    </script>
</body>
</html>

Node.js with Browserify

const { WorkBoots } = require('workboots/dist/work-boots.browser.js');

const workBoots = new WorkBoots({
    socksFile: './worker-universal.js'
});

workBoots.onMessage(({ data }) => {
    console.log('Node.js received:', data);
});

workBoots.ready().then(() => {
    workBoots.postMessage({ node: true });
});

API Reference

WorkBoots

The main class for creating worker proxies.

Constructor

new WorkBoots({ socksFile, instantiateWorker })
  • socksFile (string, required): Path to the worker file
  • instantiateWorker (function, optional): Custom worker factory function

Methods

  • ready(): Returns a promise that resolves when the worker is ready
  • postMessage(data, origin, transfer): Send a message to the worker
  • onMessage(callback): Set up message handling
  • terminate(): Clean up the worker

Socks

The worker-side interface for handling messages.

Constructor

new Socks(self)
  • self (object, optional): The worker context (self in browser, parentPort in Node.js)

Methods

  • ready(): Signal that the worker is ready
  • postMessage(data, origin, transfer): Send a message to the main thread
  • onMessage(callback): Set up message handling
  • terminate(): Clean up the worker
  • onTerminate(callback): Set up termination callback

Advanced Usage

Custom Worker Factory

const customFactory = (socksFile) => {
    // Your custom worker creation logic
    return new CustomWorker(socksFile);
};

const workBoots = new WorkBoots({
    socksFile: './worker.js',
    instantiateWorker: customFactory
});

Error Handling

const workBoots = new WorkBoots({
    socksFile: './worker.js'
});

workBoots.onMessage(({ data }) => {
    try {
        console.log('Processing:', data);
    } catch (error) {
        console.error('Error processing message:', error);
    }
});

try {
    await workBoots.ready();
} catch (error) {
    console.error('Worker initialization failed:', error);
    // Fallback to local processing
}

Message Queuing

const workBoots = new WorkBoots({
    socksFile: './worker.js'
});

// Messages sent before ready() are queued
workBoots.postMessage({ queued: 1 });
workBoots.postMessage({ queued: 2 });

workBoots.onMessage(({ data }) => {
    console.log('Received:', data);
});

// Queued messages are sent after ready
await workBoots.ready();

Multiple Workers

const workers = [];
const workerCount = 3;

for (let i = 0; i < workerCount; i++) {
    const workBoots = new WorkBoots({
        socksFile: './worker.js'
    });

    workBoots.onMessage(({ data }) => {
        console.log(`Worker ${i} received:`, data);
    });

    await workBoots.ready();
    workers.push(workBoots);
}

// Send messages to all workers
workers.forEach((worker, index) => {
    worker.postMessage({ workerId: index });
});

Browserify Configuration

package.json

{
  "browserify": {
    "transform": [
      ["babelify", { "presets": ["@babel/preset-env"] }]
    ],
    "standalone": "WorkBoots"
  }
}

Build Scripts

{
  "scripts": {
    "build:browser": "browserify src/index.js -o dist/work-boots.browser.js -s WorkBoots",
    "build:node": "cp src/index.js dist/work-boots.js",
    "build:worker": "browserify src/work-boots.js -o dist/work-boots.worker.js -s WorkBoots"
  }
}

Testing

Run the test suite:

# Run all tests
npm test

# Run tests in watch mode
npm run test:watch

# Run tests with coverage
npm run test:coverage

# Run browser-specific tests
npm run test:browser

Performance Considerations

  • Message Size: Large messages may impact performance. Consider chunking large data.
  • Message Frequency: High-frequency messaging may cause queuing. Implement rate limiting if needed.
  • Memory Management: Always call terminate() when done to clean up resources.
  • Transferable Objects: Use transferable objects (ArrayBuffer, etc.) for large data to avoid copying.

Browser Compatibility

  • Modern browsers with Web Worker support
  • Node.js 12+ with Worker Threads support
  • Automatic fallback to local execution when workers aren't available
  • Full Browserify compatibility for universal module support

License

MIT