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

bare-structured-clone

v1.6.0

Published

Structured cloning algorithm for JavaScript

Readme

bare-structured-clone

Structured cloning algorithm for JavaScript. Implements the HTML serialization, deserialization, and transfer steps (https://html.spec.whatwg.org/multipage/structured-data.html#structured-clone) and exposes a compact-encoding codec (https://github.com/holepunchto/compact-encoding) for encoding serialized values to a buffer.

npm i bare-structured-clone

Usage

const structuredClone = require('bare-structured-clone')

const copy = structuredClone({ hello: 'world' })

const buffer = new ArrayBuffer(4)
const transferred = structuredClone(buffer, { transfer: [buffer] })

To install structuredClone as a global, require the global submodule:

require('bare-structured-clone/global')

const copy = structuredClone({ hello: 'world' })

API

const copy = structuredClone(value[, options])

Clone value by serializing and then deserializing it. options may include a transfer list and an interfaces list:

options = {
  transfer: [],
  interfaces: []
}

transfer is an array of ArrayBuffer and Transferable objects whose ownership is transferred to the clone. After transfer, the original objects are detached. interfaces is an array of Serializable and Transferable constructors that may appear in value; each constructor must be present at both serialize and deserialize time.

const serialized = serialize(value[, forStorage[, interfaces]])

Serialize value to a SerializedValue describing its structure. If forStorage is true, the value is being serialized for persistent storage; types that cannot be persisted (such as SharedArrayBuffer) will throw.

const serialized = serializeWithTransfer(value[, transferList[, interfaces]])

Like serialize() but additionally detaches the objects in transferList and embeds their backing stores in the resulting SerializedTransfer.

const value = deserialize(serialized[, interfaces])

Deserialize a value previously produced by serialize().

const value = deserializeWithTransfer(serialized[, interfaces])

Deserialize a value previously produced by serializeWithTransfer(), attaching the transferred backing stores to new objects.

preencode(state, serialized)

encode(state, serialized)

const serialized = decode(state)

The module is itself a compact-encoding codec for SerializedValue and SerializedTransfer, prefixing the payload with an ABI version header. Use it with compact-encoding to encode a serialized value to a buffer:

const c = require('compact-encoding')
const structuredClone = require('bare-structured-clone')
const { serialize, deserialize } = structuredClone

const buffer = c.encode(structuredClone, serialize({ hello: 'world' }))
const value = deserialize(c.decode(structuredClone, buffer))

constants

Numeric tags used in serialized values. Also available as require('bare-structured-clone/constants').

constants = {
  VERSION,
  type: {
    UNDEFINED,
    NULL,
    TRUE,
    FALSE,
    NUMBER,
    BIGINT,
    STRING,
    DATE,
    REGEXP,
    ERROR,
    ARRAYBUFFER,
    RESIZABLEARRAYBUFFER,
    SHAREDARRAYBUFFER,
    GROWABLESHAREDARRAYBUFFER,
    TYPEDARRAY,
    DATAVIEW,
    MAP,
    SET,
    ARRAY,
    OBJECT,
    REFERENCE,
    TRANSFER,
    URL,
    BUFFER,
    EXTERNAL,
    SERIALIZABLE,
    TRANSFERABLE,
    typedarray: {
      /* ... */
    },
    error: {
      /* ... */
    }
  }
}

symbols

Well-known symbols used to implement custom Serializable and Transferable interfaces.

symbols = {
  serialize: Symbol.for('bare.serialize'),
  deserialize: Symbol.for('bare.deserialize'),
  detach: Symbol.for('bare.detach'),
  attach: Symbol.for('bare.attach')
}

class Serializable

Base class for custom serializable interfaces. Subclasses must implement two methods keyed by the symbols above:

const { Serializable, symbols } = require('bare-structured-clone')

class MySerializable extends Serializable {
  [symbols.serialize](forStorage) {
    // Return a `SerializableValue` describing this instance
  }

  static [symbols.deserialize](serialized) {
    // Return a new instance reconstructed from `serialized`
  }
}

The constructor must be registered via the interfaces option on both ends of the clone.

class Transferable

Base class for custom transferable interfaces. Instances carry a detached boolean that flips to true once ownership has been transferred. Subclasses must implement two methods keyed by the symbols above:

const { Transferable, symbols } = require('bare-structured-clone')

class MyTransferable extends Transferable {
  [symbols.detach]() {
    // Release ownership and return a `SerializableValue` describing
    // the detached state
  }

  static [symbols.attach](serialized) {
    // Return a new instance that takes ownership of `serialized`
  }
}

The constructor must be registered via the interfaces option on both ends of the clone. The base detach implementation sets detached to true; subclasses should call super[symbols.detach]() after releasing their state.

License

Apache-2.0