Lightweight deep clone supporting Date, Map, Set, RegExp, typed arrays, and circular references.
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.
export function deepClone(value: unknown, opts?: CloneOptions): unknown
export interface CloneOptions {
transform?: (value: unknown, key?: string) => unknown
}npm install @ferrow/deep-clone-liteimport { 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- 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