TS-Scribe - v1.2.0
    Preparing search index...

    Function objectDeepClone

    • Creates a deep clone of a value using the native structuredClone algorithm.

      This is a thin, production-safe wrapper around the built-in structuredClone, which handles all standard cloneable types: primitives, plain objects, arrays, Date, RegExp, Map, Set, ArrayBuffer, typed arrays, and circular references.

      Type Parameters

      • T

      Parameters

      • object: T

        The value to deep clone.

      • Optionaloptions: DeepCloneOptions

        Optional configuration.

      Returns T

      A structurally identical deep clone of the input.

      If the value contains non-cloneable data (functions, symbols, or DOM nodes) that structuredClone cannot handle.

      const obj = { a: 1, b: { c: 2 } };
      const clone = objectDeepClone(obj);
      console.log(clone); // { a: 1, b: { c: 2 } }
      console.log(clone === obj); // false (different reference)
      console.log(clone.b === obj.b); // false (deep cloned)
      // Clone complex types
      const data = {
      date: new Date('2025-01-01'),
      pattern: /hello/i,
      map: new Map([['key', 'value']]),
      set: new Set([1, 2, 3])
      };
      const cloned = objectDeepClone(data);
      console.log(cloned.date instanceof Date); // true
      console.log(cloned.pattern instanceof RegExp); // true
      console.log(cloned.map.get('key')); // 'value'