Research
Security News
Malicious npm Packages Inject SSH Backdoors via Typosquatted Libraries
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
merge-descriptors
Advanced tools
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.
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'
Lodash's merge function is similar to merge-descriptors but focuses more on deep merging of properties, including arrays and plain objects. Unlike merge-descriptors, lodash.merge does not handle property descriptors, making it less suitable for cases where property getters, setters, or other descriptor specifics are crucial.
The object-assign package provides a function to copy values of all enumerable own properties from one or more source objects to a target object. It is similar to Object.assign() and does not copy property descriptors, making merge-descriptors a better choice when descriptors need to be preserved.
Merge objects using descriptors.
var thing = {
get name() {
return 'jon'
}
}
var animal = {
}
merge(animal, thing)
animal.name === 'jon'
Overwrites destination
's descriptors with source
's.
The MIT License (MIT)
Copyright (c) 2013 Jonathan Ong me@jongleberry.com
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Merge objects using their property descriptors
The npm package merge-descriptors receives a total of 26,968,263 weekly downloads. As such, merge-descriptors popularity was classified as popular.
We found that merge-descriptors demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
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.
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.
Security News
MITRE's 2024 CWE Top 25 highlights critical software vulnerabilities like XSS, SQL Injection, and CSRF, reflecting shifts due to a refined ranking methodology.
Security News
In this segment of the Risky Business podcast, Feross Aboukhadijeh and Patrick Gray discuss the challenges of tracking malware discovered in open source softare.