Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

shallow-clone

Package Overview
Dependencies
Maintainers
2
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

shallow-clone

Make a shallow clone of an object, array or primitive.

  • 0.1.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
15M
decreased by-19.51%
Maintainers
2
Weekly downloads
 
Created

What is shallow-clone?

The shallow-clone npm package is designed to create shallow copies of various JavaScript data types, such as objects, arrays, and other native types. It is useful for cases where you need a new object with the same properties as the original but without deep copying nested structures.

What are shallow-clone's main functionalities?

Cloning Objects

Creates a shallow copy of an object. Changes to nested objects in the original will reflect in the clone.

const shallowClone = require('shallow-clone');
const obj = { a: 1, b: { c: 2 } };
const clonedObj = shallowClone(obj);
console.log(clonedObj); // { a: 1, b: { c: 2 } }

Cloning Arrays

Creates a shallow copy of an array. Changes to nested arrays in the original will reflect in the clone.

const shallowClone = require('shallow-clone');
const arr = [1, 2, [3, 4]];
const clonedArr = shallowClone(arr);
console.log(clonedArr); // [1, 2, [3, 4]]

Cloning Dates

Creates a shallow copy of a Date object, resulting in a new Date object with the same time.

const shallowClone = require('shallow-clone');
const date = new Date();
const clonedDate = shallowClone(date);
console.log(clonedDate); // outputs cloned date object

Cloning Regular Expressions

Creates a shallow copy of a RegExp object, including its flags and lastIndex property.

const shallowClone = require('shallow-clone');
const regex = /test/gi;
const clonedRegex = shallowClone(regex);
console.log(clonedRegex); // outputs cloned RegExp object

Other packages similar to shallow-clone

Keywords

FAQs

Package last updated on 17 Oct 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc