Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

object-path-immutable

Package Overview
Dependencies
Maintainers
1
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

object-path-immutable - npm Package Compare versions

Comparing version 0.1.0 to 0.2.0

16

index.js

@@ -155,3 +155,19 @@ (function (root, factory){

objectPathImmutable.assign = function(obj, path, source) {
return changeImmutable(obj, path, function(clonedObj, finalPath) {
source = Object(source);
var target = clone(clonedObj[finalPath], true)
for (var key in source) {
if (_hasOwnProperty.call(source, key)) {
target[key] = source[key]
}
}
clonedObj[finalPath] = target
return clonedObj
})
}
return objectPathImmutable
})

2

package.json
{
"name": "object-path-immutable",
"version": "0.1.0",
"version": "0.2.0",
"description": "Modify deep object properties without modifying the original object (immutability). Works great with React and Redux.",

@@ -5,0 +5,0 @@ "author": "Mario Casciaro <mariocasciaro@gmail.com>",

@@ -122,2 +122,13 @@ object-path-immutable

//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

@@ -134,2 +145,2 @@ var newObj = immutable(obj).set(obj, 'a.b', 'f').del(obj, 'a.c.0').value()

* [Mario Casciaro](https://github.com/mariocasciaro) - Author
* [Mario Casciaro](https://github.com/mariocasciaro) - Author

@@ -133,2 +133,55 @@ 'use strict';

})
})
describe('assign', function() {
it('should assign an object without modifying the original object', function() {
var obj = {
a: {
b: 1
},
c: {
d: 2
}
}
var newObj = op.assign(obj, 'a', { b: 3 })
expect(newObj).not.to.be.equal(obj)
expect(newObj.a).not.to.be.equal(obj.a)
expect(obj.a).to.be.eql({b: 1})
expect(newObj.c).to.be.equal(obj.c)
expect(newObj.a.b).to.be.equal(3)
})
it('should keep existing fields that are not overwritten', function() {
var obj = {
a: {
b: 1
}
}
var newObj = op.assign(obj, 'a', { c: 2 })
expect(newObj).not.to.be.equal(obj)
expect(newObj.a).not.to.be.equal(obj.a)
expect(obj.a).to.be.eql({b: 1})
expect(newObj.a).to.be.eql({ b: 1, c: 2 })
})
it('should create intermediate objects', function() {
var obj = {
a: {},
c: {
d: 2
}
}
var newObj = op.assign(obj, 'a.b', { f: 'a' })
expect(newObj).not.to.be.equal(obj)
expect(newObj.a).not.to.be.equal(obj.a)
expect(obj.a).to.be.eql({})
expect(newObj.a).to.be.eql({b: {f: 'a'}})
})
})
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc