merge-descriptors
TypeScript icon, indicating that this package has built-in type declarations

2.0.0 • Public • Published

merge-descriptors

Merge objects using their property descriptors

Install

npm install merge-descriptors

Usage

import mergeDescriptors from 'merge-descriptors';

const thing = {
	get name() {
		return 'John'
	}
}

const animal = {};

mergeDescriptors(animal, thing);

console.log(animal.name);
//=> 'John'

API

merge(destination, source, overwrite?)

Merges "own" properties from a source to a destination object, including non-enumerable and accessor-defined properties. It retains original values and descriptors, ensuring the destination receives a complete and accurate copy of the source's properties.

Returns the modified destination object.

destination

Type: object

The object to receive properties.

source

Type: object

The object providing properties.

overwrite

Type: boolean
Default: true

A boolean to control overwriting of existing properties.

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.0
    1,153
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 2.0.0
    1,153
  • 1.0.3
    357,162
  • 1.0.2
    273
  • 1.0.1
    25,496,729
  • 1.0.0
    129,963
  • 0.0.2
    31,309
  • 0.0.1
    8,284

Package Sidebar

Install

npm i merge-descriptors

Weekly Downloads

26,024,873

Version

2.0.0

License

MIT

Unpacked Size

4.37 kB

Total Files

5

Last publish

Collaborators

  • sindresorhus