Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

deep-clone-lite

CI

Lightweight deep clone supporting Date, Map, Set, RegExp, typed arrays, and circular references.

What & Why

Clone any JavaScript value deeply without structuredClone's function-throwing behavior. Handles circular references via WeakMap tracking, optional per-value transform hook, and preserves functions by reference. Works in Node.js and browsers.

API

export function deepClone(value: unknown, opts?: CloneOptions): unknown
export interface CloneOptions {
  transform?: (value: unknown, key?: string) => unknown
}

Install

npm install @ferrow/deep-clone-lite

Quick Start

import { deepClone } from 'deep-clone-lite';

const original = {
  date: new Date('2026-01-01'),
  map: new Map([['key', 'value']]),
  circular: null as any,
};
original.circular = original;

const cloned = deepClone(original);
cloned.date.setFullYear(2025); // original unchanged
cloned.circular === cloned; // true, cycle preserved

Limits

  • Functions are passed by reference (not cloned).
  • Symbols are not cloned.
  • Custom class instances are treated as plain objects (constructor not preserved).
  • Large circular reference graphs may hit stack limits (each clone tracks seen objects, but not tail-call optimized).

Part of the ferrow-toolkit collection · Sponsored by Ferrow

About

Lightweight deep clone supporting Date, Map, Set, RegExp, typed arrays, and circular references

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages