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.
object-path-immutable
Advanced tools
Modify deep object properties without modifying the original object (immutability). Works great with React and Redux.
Tiny JS library to modify deep object properties without modifying the original object (immutability).
Works great with React (especially when using setState()
) and Redux (inside a reducer).
This can be seen as a simpler and more intuitive alternative to the React Immutability Helpers and Immutable.js
npm install object-path-immutable --save
The following, sets a property without modifying the original object.
It will minimize the number of clones down the line. The resulting object is just a plain JS object literal,
so be warned that it will not be protected against property mutations (like Immutable.js
)
var obj = {
a: {
b: 'c',
c: ['d', 'f']
}
}
//set a deep property
var newObj = immutable.set(obj, 'a.b', 'f')
//returns
//var obj = {
// a: {
// b: 'f',
// c: ['d', 'f']
// }
//}
//obj !== newObj
//obj.a !== newObj.a
//obj.b !== newObj.b
//However:
//obj.c === newObj.c
var obj = {
a: {
b: 'c',
c: ['d', 'f']
}
}
var immutable = require("object-path-immutable")
//set deep property
var newObj = immutable.set(obj, 'a.b', 'f')
//returns
//var obj = {
// a: {
// b: 'f',
// c: ['d', 'f']
// }
//}
//it can also use an array to describe the path
var newObj = immutable.set(obj, ['a', 'b'], 'f')
//if the path is specified as a string, then numbers are automatically interpreted as array indexes
var newObj = immutable.set(obj, 'a.c.1', 'fooo')
//returns
//var obj = {
// a: {
// b: 'f',
// c: ['d', 'fooo']
// }
//}
//push into a deep array (it will create intermediate objects/arrays if necessary)
var newObj = immutable.push(obj, 'a.d', 'f')
//returns
//var obj = {
// a: {
// b: 'f',
// c: ['d', 'f'],
// d: ['f']
// }
//}
//delete a deep property
var newObj = immutable.del(obj, 'a.c')
//returns
//var obj = {
// a: {
// b: 'f'
// }
//}
//delete a deep array item (splice)
var newObj = immutable.del(obj, 'a.c.0')
//var obj = {
// a: {
// b: 'f',
// c: ['f']
// }
//}
//shallow copy properties
var newObj = immutable.assign(obj, 'a', { b: 'f', g: 'h' })
//returns
//var obj = {
// a: {
// b: 'f',
// c: ['d, 'f'],
// g: 'h'
// }
//}
//Chaining mode. value() at the end of the chain is used to retrieve the resulting object
var newObj = immutable(obj).set('a.b', 'f').del('a.c.0').value()
FAQs
Modify deep object properties without modifying the original object (immutability). Works great with React and Redux.
The npm package object-path-immutable receives a total of 41,019 weekly downloads. As such, object-path-immutable popularity was classified as popular.
We found that object-path-immutable 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.
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.