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

@lynkxy/postmessage-transfer

v0.0.3

Published

A package for sending objects via post message with support for serializing messages with proxy functions and sending them via post message channel across all major platforms including web, Node.js, Deno, etc.

Readme

@lynkxy/postmessage-transfer

A lightweight library for secure and flexible post message communication

@lynkxy/postmessage-transfer is a small, efficient library that simplifies sending and receiving objects, messages and even functions between different threads in different environments via postMessage channel.

Supported Environments

Features

  • Type-safe communication between threads.
  • Simple API (only 2 functions, serialize and deserialize)
  • Lightweight with no dependencies.
  • Package works in browser, node.js and deno in the same way.
  • Based on postMessage channel and transferable objects.

Installation

# Using npm (node.js)
npm install @lynkxy/postmessage-transfer

# Using deno
deno add @lynkxy/postmessage-transfer

Usage

Basic example (Deno)

Main thread (index.ts)

import { serialize } from "@lynkxy/postmessage-transfer";

export const logger = {
    log: (message) => {
        console.log("log >>>", message);
        return true;
    },
};

new Worker(new URL("./worker.ts", import.meta.url).href, {
  type: "module",
}).postMessage(...await serialize(logger));

Worker thread (worker.ts)

import { deserialize } from "@lynkxy/postmessage-transfer";
import type { logger } from "./index.ts";

self.addEventListener("message", async (e) => {
  deserialize<typeof logger>((e as MessageEvent).data);
  self.close();
});
deno run index.ts

log xxx

Basic example (Node.js)

Main thread (index.mjs)

// Main thread
import { serialize } from '@lynkxy/postmessage-transfer'
import { Worker } from "worker_threads";

const logger = {
    log: (message) => {
        console.log("log >>>", message);
        return true;
    },
};
new Worker(new URL("./worker.mjs", import.meta.url)).postMessage(...await serialize(logger));

Worker thread (worker.mjs)

import { deserialize } from "@lynkxy/postmessage-transfer";
import { parentPort } from "worker_threads";

parentPort.addEventListener("message", async (e) => {
  deserialize(e.data);
  parentPort.close();
});
node index.mjs

log xxx

API Reference

This library provides two main functions:

  1. serialize - Converts data into a format that can be sent through postMessage, handling functions, objects, and transferable items.
  2. deserialize - Converts data received via postMessage back into its original format, restoring functions and object structures.

Both functions work across browser and Node.js environments, enabling seamless communication between different execution contexts.

serialize

Serializes data to be transferred via MessageChannel.

| Parameter | Description | |-----------|-------------| | data | The data to serialize | | Returns | A tuple containing [serialized data, transferable objects] |

The first element is the serialized data. The second element is an object with a transfer array containing all Transferable objects.

Supported transferable data types:

  • ArrayBuffer and views (Uint8Array, Float32Array, etc.)
  • MessagePort
  • ImageBitmap
  • OffscreenCanvas
  • AudioData
  • VideoFrame
  • ReadableStream, WritableStream, TransformStream
  • Blob (converted to ArrayBuffer before transfer)
  • Functions (converted to serialized proxies with MessagePort)

deserialize

Deserializes data received via MessageChannel.

| Parameter | Description | |-----------|-------------| | data | The data to deserialize | | Returns | The deserialized data as type T |

Handles deserialization of:

  • Serialized functions (converts back to callable functions)
  • Serialized errors (converted to Error objects)
  • Arrays (recursively deserializes each element)
  • Objects (recursively deserializes each property)
  • Primitive values (returned as-is)

License

MIT