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

@opsimathically/deepclone

v1.0.0

Published

Create a deep clone of an object, which unlike the builtin structuredClone, will include functions, et al. Does not clone literally-unclonables, like sockets etc, but will handle exceptions gracefully rather than throwing.

Readme

deepclone

When using structuredClone I was made aware that it doesn't copy/clone functions. This package is intended to work similarly to structuredClone, but will also work on functions etc. Cloning functions can be done in two ways, the first being using a wrapper that utilizes originalFn.apply, and the second is by stringifying and eval()'ing the function as a string. The first will preserve scope, closures, etc, the latter will not. It should be known that the second is also possibly insecure, considering that it requires the use of eval. For that reason, it's provided as an option (clone_functions_from_strings__insecure_eval) but is not used by default. Also, some things simply can't be cloned reliably, such as sockets etc. This package will do its best to clone as much as is possible, and will gracefully fail, executing a callback rather than asserting/erroring. This is so that you can attempt to clone things deeply with best-effort result generation. When working with unknown, unusual data, this is in my opinion, preferred.

Install

npm install @opsimathically/deepclone

Building from source

This package is intended to be run via npm, but if you'd like to build from source, clone this repo, enter directory, and run npm install for dev dependencies, then run npm run build.

Usage

See API Reference for documentation

See unit tests for more direct usage examples

import { deepClone, warn_callback_t } from '@opsimathically/deepclone';
import { deepEqual } from 'fast-equals';
import assert from 'node:assert';

(async function () {
  const clone_from_obj = {
    hello: {
      hi: 'hi',
      something: [1, 2, 3, 'somedata']
    },
    something_else: {
      a_map: new Map<any, any>([
        [1, 2],
        ['hi', 'there']
      ]),
      a_set: new Set<any>([1, 2, 3, 4])
    }
  };
  let cloned: any = deepClone(clone_from_obj);
  assert(deepEqual(clone_from_obj, cloned));

  const clone_from_str_insecure_eval = {
    some_func: (moo: any) => {
      return 'abcd1234';
    }
  };

  cloned = deepClone(clone_from_str_insecure_eval, {
    clone_functions_from_strings__insecure_eval: true
  });

  assert(
    clone_from_str_insecure_eval.some_func.toString() ===
      cloned.some_func.toString()
  );

  const clone_from_obj_with_unclonable = {
    hello: {
      a_promise: new Promise(function (resolve, reject) {})
    }
  };

  let fail_reason: string = '';
  cloned = deepClone(clone_from_obj_with_unclonable, {
    on_unclonable: 'nullify',
    warn_on_uncloneable: (path: string, value: any, reason: string) => {
      fail_reason = reason;
    }
  });

  assert(fail_reason === 'unhandled_type__promise');
  assert(cloned.hello.a_promise === null);

  // clone again, but use the original promise instead of nullifying
  // the value.
  cloned = deepClone(clone_from_obj_with_unclonable, {
    on_unclonable: 'use_original'
  });
  assert(typeof cloned.hello.a_promise === 'object');
  // Note: deepEqual will not work with cloned objects with functions, see the readme information
  //       at the top of this file as to why.
})();