als-deep-clone

1.0.0 • Public • Published

als-deep-clone

als-deep-clone is a JavaScript utility for deep cloning objects, supporting various built-in types with handling for circular references.

Installation

npm install als-deep-clone

Usage

const deepClone = require('als-deep-clone');

const original = {
  a: 1,
  b: [2, 3, { d: 4 }],
  c: { e: 5 }
};

const cloned = deepClone(original);
console.log(cloned);

Features

als-deep-clone supports deep cloning for the following JavaScript types:

  • Primitive types (Number, String, Boolean, null, undefined)
  • Objects (Plain objects and objects with a prototype chain)
  • Arrays
  • Date objects
  • Regular expressions

Additionally, the utility handles circular references within objects to prevent infinite loops during the cloning process.

Limitations

While als-deep-clone covers many common use cases, it does not support cloning for:

  • Functions: Due to the complexity and potential side effects of duplicating function scopes and closures.
  • Maps, Sets: These collections are not cloned because they can require special considerations for key equality.
  • Buffers, Typed Arrays: These binary data structures are not supported by default.
  • Promises and other complex built-in types that do not have a straightforward duplication strategy.

API

deepClone(object)

Clones an object deeply, returning a new object with the same structure and values, but with no shared references to the original.

  • Parameters
    • object (Object): The object to clone.
  • Returns
    • (Object): A deep clone of the provided object.

Readme

Keywords

none

Package Sidebar

Install

npm i als-deep-clone

Weekly Downloads

0

Version

1.0.0

License

MIT

Unpacked Size

4.12 kB

Total Files

4

Last publish

Collaborators

  • alexsorkin