Socket
Socket
Sign inDemoInstall

copy-descriptor

Package Overview
Dependencies
0
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    copy-descriptor

Copy a descriptor from object A to object B


Version published
Weekly downloads
10M
decreased by-13.87%
Maintainers
1
Install size
4.88 kB
Created
Weekly downloads
 

Package description

What is copy-descriptor?

The copy-descriptor npm package is designed for copying property descriptors from one object to another. It allows for precise control over how properties are copied, including their enumerability, configurability, writability, and whether they are getters/setters. This can be particularly useful when you want to replicate the behavior of an object's properties without altering the original object.

What are copy-descriptor's main functionalities?

Copying a single property descriptor

This feature allows you to copy a single property descriptor from the source object to the target object. The code sample demonstrates copying the getter for the 'foo' property from the source object to the target object, then logging the descriptor of the 'foo' property on the target to show that it has been copied.

const copyDescriptor = require('copy-descriptor');
let target = {};
let source = { get foo() { return 'bar'; } };
copyDescriptor(target, source, 'foo');
console.log(Object.getOwnPropertyDescriptor(target, 'foo'));

Copying multiple property descriptors

This feature enables the copying of multiple property descriptors from the source object to the target object in a single call. The code sample shows how to copy both the 'foo' getter and the 'bar' value property from the source to the target, then logs the descriptors to demonstrate that both properties have been successfully copied.

const copyDescriptor = require('copy-descriptor');
let target = {};
let source = { get foo() { return 'bar'; }, bar: 'baz' };
copyDescriptor(target, source, ['foo', 'bar']);
console.log(Object.getOwnPropertyDescriptor(target, 'foo'));
console.log(Object.getOwnPropertyDescriptor(target, 'bar'));

Other packages similar to copy-descriptor

Keywords

FAQs

Last updated on 09 Jun 2016

Did you know?

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc