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

merge-descriptors

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

merge-descriptors

Merge objects using descriptors

  • 0.0.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
33M
increased by2.76%
Maintainers
1
Weekly downloads
 
Created

What is merge-descriptors?

The merge-descriptors npm package is a utility that allows you to copy enumerable properties from one or more source objects to a destination object, optionally defining property descriptors. It is commonly used to mix properties and their descriptors from one object into another, preserving more detailed configuration than a simple object spread or Object.assign.

What are merge-descriptors's main functionalities?

Merge properties with descriptors

This feature allows you to merge properties from the source object to the target object, including their getters and setters. The example shows how a property with a getter is copied to the target object, preserving its behavior.

const mergeDescriptors = require('merge-descriptors');
let target = {};
let source = { get foo() { return 'bar'; } };
mergeDescriptors(target, source);
console.log(target.foo); // Outputs: 'bar'

Merge properties without overwriting

This feature demonstrates how to merge properties without overwriting existing properties in the target object. The example merges a getter for 'foo' from the source into the target, but since 'foo' already exists in the target and the overwrite flag is set to false, the original value is preserved.

const mergeDescriptors = require('merge-descriptors');
let target = { foo: 'initial' };
let source = { get foo() { return 'bar'; } };
mergeDescriptors(target, source, false);
console.log(target.foo); // Outputs: 'initial'

Other packages similar to merge-descriptors

FAQs

Package last updated on 14 Dec 2013

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