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

structuredclone-polyfill-js

v1.0.0

Published

Spec-like structuredClone polyfill with binary support

Readme

structuredclone-polyfill-js

Spec-inspired structuredClone polyfill for Node.js and browsers with support for binary types, circular references, Maps, Sets, and more.


Features

  • Deep clone for complex object graphs

  • Circular reference handling

  • Supports:

    • Object, Array
    • Date, RegExp
    • Map, Set
    • ArrayBuffer
    • TypedArrays (Uint8Array, Int32Array, Float32Array, etc.)
    • DataView
    • Error objects
  • Prototype preservation

  • Transfer list support (zero‑copy semantics)

  • TypeScript support


Non‑goals / Limitations

  • Functions are not cloneable (throws DataCloneError)
  • DOM nodes are not supported
  • WeakMap / WeakSet are not supported
  • ArrayBuffer detachment cannot be implemented in JavaScript (engine limitation). Transfer is simulated by reusing the same buffer.

Installation

npm install structuredclone-polyfill-js

Usage

Basic

import structuredClone from "structuredclone-polyfill-js";

const obj = { a: 1, nested: { b: 2 } };
const copy = structuredClone(obj);

Circular references

const obj = {};
obj.self = obj;

const cloned = structuredClone(obj);
console.log(cloned.self === cloned); // true

Binary types

const buffer = new ArrayBuffer(8);
const view = new Uint8Array(buffer);
view[0] = 42;

const cloned = structuredClone(buffer);

Transferable buffers (zero‑copy)

const buf = new ArrayBuffer(4);
const cloned = structuredClone(buf, { transfer: [buf] });

cloned === buf; // true

Note: JavaScript cannot detach ArrayBuffers manually. The polyfill reuses the same memory to simulate transfer semantics.


API

structuredClone(value: any, options?: {
  transfer?: ArrayBuffer[]
}): any

Benchmark

Environment: Node.js 22.x (Windows)

Large object graph (10,000 nodes)

| Implementation | Time | | -------------- | -------- | | Native | 47.66 ms | | Polyfill | 33.52 ms |

Binary cloning (10 MB ArrayBuffer)

| Implementation | Time | | -------------- | ------- | | Native | 8.62 ms | | Polyfill | 9036 ms |

Notes:

  • Native implementation uses optimized C++ engine paths.
  • Polyfill performance for large binary buffers is limited by JavaScript memory copying.
  • Object graph cloning performance is competitive for moderate sizes.

Supported Types

| Type | Supported | | ----------- | --------- | | Object | Yes | | Array | Yes | | Date | Yes | | RegExp | Yes | | Map | Yes | | Set | Yes | | ArrayBuffer | Yes | | TypedArray | Yes | | DataView | Yes | | Error | Yes | | Function | No | | DOM Node | No |


Development

npm install
npm test
npm run build
npm run bench

Project structure

src/        # polyfill implementation
tests/      # vitest test suite
bench/      # benchmark script
dist/       # compiled output

Why this project

This project demonstrates:

  • Deep understanding of JavaScript runtime internals
  • Binary memory handling (ArrayBuffer, TypedArrays)
  • Graph cloning with circular references
  • Prototype preservation
  • Spec‑aware error behavior
  • TypeScript library packaging
  • Benchmarking and performance analysis

License

MIT