What is node.extend?
The node.extend package is a simple utility for deep and shallow extending (merging) of objects. It is useful for combining multiple objects into one, copying properties from one object to another, and creating new objects with inherited properties.
What are node.extend's main functionalities?
Shallow Extend
This feature allows you to perform a shallow merge of multiple objects. In the example, properties from obj2 overwrite those in obj1 where they conflict.
const extend = require('node.extend');
const obj1 = { a: 1, b: 2 };
const obj2 = { b: 3, c: 4 };
const result = extend({}, obj1, obj2);
console.log(result); // { a: 1, b: 3, c: 4 }
Deep Extend
This feature allows you to perform a deep merge of multiple objects. Nested objects are merged recursively. In the example, the nested properties of obj2 overwrite those in obj1 where they conflict.
const extend = require('node.extend');
const obj1 = { a: 1, b: { x: 1, y: 2 } };
const obj2 = { b: { y: 3, z: 4 }, c: 5 };
const result = extend(true, {}, obj1, obj2);
console.log(result); // { a: 1, b: { x: 1, y: 3, z: 4 }, c: 5 }
Clone Object
This feature allows you to create a deep clone of an object. The example demonstrates cloning an object with nested properties.
const extend = require('node.extend');
const obj = { a: 1, b: { x: 1, y: 2 } };
const clone = extend(true, {}, obj);
console.log(clone); // { a: 1, b: { x: 1, y: 2 } }
Other packages similar to node.extend
lodash
Lodash is a modern JavaScript utility library delivering modularity, performance, and extras. It provides a wide range of utility functions, including deep and shallow merging of objects. Compared to node.extend, lodash offers a more extensive set of utilities beyond object merging.
merge
The merge package is a simple utility for merging objects. It supports both deep and shallow merging. Compared to node.extend, merge is more focused on object merging and does not provide additional utilities.
deepmerge
Deepmerge is a library for deep merging of JavaScript objects. It is specifically designed for deep merging and handles arrays and objects recursively. Compared to node.extend, deepmerge is more specialized for deep merging scenarios.
node.extend
A port of jQuery.extend that actually works on node.js
Description
None of the existing ones on npm really work therefore I ported it myself.
Usage
Checkout the doc from jQuery
License
Copyright 2011, John Resig
Dual licensed under the MIT or GPL Version 2 licenses.
http://jquery.org/license