
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
mutate-object
Advanced tools
Performs a deep mutation of an existing (destintation) object to equal a given (source) object. Similar to angular.merge but with one critical difference: the destination object will always end up equal to the source object. This means:
Note: this is basically the exact opposite of how Redux reducers perform modifications to the state object. Instead of ensuring no mutation, mutate-object uses mutation wherever possible to avoid creating new objects/arrays.
NPM
npm install https://github.com/jeremyhewett/mutate-object.git#v1.0.0
Bower
bower install https://github.com/jeremyhewett/mutate-object.git#v1.0.0
var oldState = {
title: 'Old',
todos: [{ id: 1, name: 'do it' }, { id: 2, name: 'do it again' }],
users: { user1: { name: 'bob' } }
};
var newState = {
title: 'New',
todos: [{ id: 1, name: 'do it' }],
users: { user1: { name: 'bob', alias: 'bobby' } }
};
var todos = oldState.todos;
var user1 = oldState.users.user1;
require('mutate-object')(oldState, newState);
//The following assertions will all be true...
expect(oldState).toEqual(newState); //Will always result in deeply equal objects.
expect(oldState).not.toBe(newState); //Will always result in a copy of the object
expect(oldState.todos).not.toBe(newState.todos); //with no shared references.
expect(oldState.todos).toBe(todos); //Will always mutate existing arrays/objects where possible
expect(oldState.user1).toBe(user1); //instead of creating new arrays/objects.
AngularJS watches the view model and re-render the view when the associated model changes. The Redux pattern disallows any state mutation and forces any small change in the state to "bubble" up and cause all parent objects to be re-created. If a new Redux state is applied directly to an angular view model, the entire hiearchy will be re-rendered because AngularJS will see that all the parent objects have changed. mutate-object solves this problem by preserving any unmodified parts of the view model and therefore avoiding all unnecessary re-rendering.
It would also be useful in an architecture where multiple modules are holding on to references to a shared state object. Naively updating that state would cause the held references to become stale. Using mutate-object would not change the shared objects themseleves, only the data within them.
| Param | Type | Details |
|---|---|---|
| oldObject | object | The destination object to be mutated |
| newObject | object | The new object that the old object should be mutated to equal |
| preserveRootProps | bool (optional) | true to prevent deleting undefined props at the root level. Eg. (in a simple AngularJS controller context) mutateObject($scope, newState, true) would avoid deleting controller functions and other values on the scope. |
FAQs
Performs a deep mutation of an existing object to equal a new object
We found that mutate-object demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.