object-path-immutable
Advanced tools
Comparing version 3.0.2 to 3.1.0
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global.objectPathImmutable = factory()); | ||
}(this, (function () { 'use strict'; | ||
(global = global || self, global.objectPathImmutable = factory()); | ||
}(this, function () { 'use strict'; | ||
@@ -14,12 +14,19 @@ /*! | ||
var isobject = function isObject(val) { | ||
function isObject(val) { | ||
return val != null && typeof val === 'object' && Array.isArray(val) === false; | ||
}; | ||
} | ||
/*! | ||
* is-plain-object <https://github.com/jonschlinkert/is-plain-object> | ||
* | ||
* Copyright (c) 2014-2017, Jon Schlinkert. | ||
* Released under the MIT License. | ||
*/ | ||
function isObjectObject(o) { | ||
return isobject(o) === true | ||
return isObject(o) === true | ||
&& Object.prototype.toString.call(o) === '[object Object]'; | ||
} | ||
var isPlainObject = function isPlainObject(o) { | ||
function isPlainObject(o) { | ||
var ctor,prot; | ||
@@ -44,3 +51,3 @@ | ||
return true; | ||
}; | ||
} | ||
@@ -323,2 +330,2 @@ var _hasOwnProperty = Object.prototype.hasOwnProperty; | ||
}))); | ||
})); |
@@ -7,3 +7,4 @@ type Path = string | ReadonlyArray<string>; | ||
del(path?: Path): WrappedObject<T> | ||
assign(path?: Path, source?: T): WrappedObject<T> | ||
assign(path?: Path, source?: any): WrappedObject<T> | ||
merge(path?: Path, source?: any): WrappedObject<T> | ||
update(path?: Path, updater?: (formerValue: any) => any): WrappedObject<T> | ||
@@ -20,2 +21,3 @@ insert(path?: Path, value?: any, index?: number): WrappedObject<T> | ||
assign<T = object>(src: T, path?: Path, source?: T): T | ||
merge<T = object>(src: T, path?: Path, source?: any): T | ||
update<T = object>(src: T, path?: Path, updater?: (formerValue: any) => any): WrappedObject<T> | ||
@@ -22,0 +24,0 @@ insert<T = object>(src: T, path?: Path, value?: any, index?: number): T |
{ | ||
"name": "object-path-immutable", | ||
"version": "3.0.2", | ||
"version": "3.1.0", | ||
"description": "Modify deep object properties without modifying the original object (immutability). Works great with React and Redux.", | ||
@@ -20,17 +20,18 @@ "author": "Mario Casciaro <m@mario.fyi>", | ||
"test": "npm run build && istanbul cover _mocha test.js --report html -- -R spec", | ||
"prepublish": "npm run test" | ||
"prepublish": "npm run test", | ||
"standard-fix": "standard --fix" | ||
}, | ||
"dependencies": { | ||
"is-plain-object": "^2.0.4" | ||
"is-plain-object": "3.0.0" | ||
}, | ||
"devDependencies": { | ||
"chai": "^3.5.0", | ||
"coveralls": "^3.0.3", | ||
"istanbul": "^0.4.5", | ||
"mocha": "^6.0.2", | ||
"mocha-lcov-reporter": "^1.2.0", | ||
"rollup": "^0.61.1", | ||
"rollup-plugin-commonjs": "^9.1.3", | ||
"rollup-plugin-node-resolve": "^3.3.0", | ||
"standard": "^8.3.0" | ||
"chai": "4.2.0", | ||
"coveralls": "3.0.4", | ||
"istanbul": "0.4.5", | ||
"mocha": "6.1.4", | ||
"mocha-lcov-reporter": "1.3.0", | ||
"rollup": "1.16.2", | ||
"rollup-plugin-commonjs": "10.0.1", | ||
"rollup-plugin-node-resolve": "5.1.0", | ||
"standard": "12.0.1" | ||
}, | ||
@@ -37,0 +38,0 @@ "keywords": [ |
59
test.js
@@ -23,3 +23,3 @@ /* globals describe, it */ | ||
expect(newObj.a).not.to.be.equal(obj.a) | ||
expect(obj.a).to.be.eql({b: 1}) | ||
expect(obj.a).to.be.eql({ b: 1 }) | ||
// this should be the same | ||
@@ -64,3 +64,3 @@ expect(newObj.c).to.be.equal(obj.c) | ||
expect(obj.a).to.be.eql({}) | ||
expect(newObj.a).to.be.eql({b: [, {f: 'a'}]}) // eslint-disable-line no-sparse-arrays | ||
expect(newObj.a).to.be.eql({ b: [, { f: 'a' }] }) // eslint-disable-line no-sparse-arrays | ||
}) | ||
@@ -96,3 +96,3 @@ | ||
expect(newObj.a).not.to.be.equal(obj.a) | ||
expect(obj.a).to.be.eql({b: 1}) | ||
expect(obj.a).to.be.eql({ b: 1 }) | ||
// this should be the same | ||
@@ -121,3 +121,3 @@ expect(newObj.c).to.be.equal(obj.c) | ||
expect(newObj.a).to.be.equal(obj.a) | ||
expect(obj.a).to.be.eql({b: 1}) | ||
expect(obj.a).to.be.eql({ b: 1 }) | ||
// this should be the same | ||
@@ -167,3 +167,3 @@ expect(newObj.c).to.be.equal(obj.c) | ||
d: ['a', 'b'], | ||
e: [{}, {f: 'g'}], | ||
e: [{}, { f: 'g' }], | ||
f: 'i' | ||
@@ -185,3 +185,3 @@ } | ||
d: ['a', 'b'], | ||
e: [{}, {f: 'g'}], | ||
e: [{}, { f: 'g' }], | ||
f: 'i' | ||
@@ -196,3 +196,10 @@ } | ||
expect(newObj).not.to.be.equal(obj) | ||
expect(newObj.b.d).to.be.eql(['a', 'b', , 'asdf']) // eslint-disable-line no-sparse-arrays | ||
expect(newObj.b.d[0]).to.be.eql('a') | ||
expect(newObj.b.d[1]).to.be.eql('b') | ||
// eslint-disable-next-line | ||
expect(newObj.b.d[2]).to.be.undefined | ||
expect(newObj.b.d[3]).to.be.eql('asdf') | ||
// eslint-disable-next-line | ||
expect(newObj.b.d[4]).to.be.undefined | ||
expect(newObj.b.d.length).to.be.eql(5) | ||
}) | ||
@@ -203,3 +210,3 @@ | ||
expect(function () { | ||
op.insert({foo: 'bar'}, 'foo', 'baz') | ||
op.insert({ foo: 'bar' }, 'foo', 'baz') | ||
}).to.throw() | ||
@@ -289,3 +296,3 @@ }) | ||
expect(newObj.a).to.be.eql({f: 2}) | ||
expect(newObj.a).to.be.eql({ f: 2 }) | ||
}) | ||
@@ -334,7 +341,7 @@ | ||
var newObj = op.assign(obj, 'a', {b: 3}) | ||
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(obj.a).to.be.eql({ b: 1 }) | ||
expect(newObj.c).to.be.equal(obj.c) | ||
@@ -352,8 +359,8 @@ | ||
var newObj = op.assign(obj, 'a', {c: 2}) | ||
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}) | ||
expect(obj.a).to.be.eql({ b: 1 }) | ||
expect(newObj.a).to.be.eql({ b: 1, c: 2 }) | ||
}) | ||
@@ -369,3 +376,3 @@ | ||
var newObj = op.assign(obj, 'a.b', {f: 'a'}) | ||
var newObj = op.assign(obj, 'a.b', { f: 'a' }) | ||
@@ -375,3 +382,3 @@ expect(newObj).not.to.be.equal(obj) | ||
expect(obj.a).to.be.eql({}) | ||
expect(newObj.a).to.be.eql({b: {f: 'a'}}) | ||
expect(newObj.a).to.be.eql({ b: { f: 'a' } }) | ||
}) | ||
@@ -428,7 +435,7 @@ | ||
var newObj = op.merge(obj, 'a', {b: 3}) | ||
var newObj = op.merge(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(obj.a).to.be.eql({ b: 1 }) | ||
expect(newObj.c).to.be.equal(obj.c) | ||
@@ -450,3 +457,3 @@ | ||
var newObj = op.merge(obj, 'a', {c: {e: 4}}) | ||
var newObj = op.merge(obj, 'a', { c: { e: 4 } }) | ||
@@ -473,3 +480,3 @@ expect(newObj).not.to.be.equal(obj) | ||
var newObj = op.merge(obj, 'a', {c: {e: [2]}}) | ||
var newObj = op.merge(obj, 'a', { c: { e: [2] } }) | ||
@@ -494,3 +501,3 @@ expect(obj.a.b).to.be.eql(1) | ||
var newObj = op.merge(obj, null, {a: {c: {e: [2]}}}) | ||
var newObj = op.merge(obj, null, { a: { c: { e: [2] } } }) | ||
@@ -515,4 +522,4 @@ expect(obj.a.b).to.be.eql(1) | ||
var newObj = op.merge(obj, 'a.c.f', {a: 1}) | ||
expect(newObj.a.c.f).to.be.eql({a: 1}) | ||
var newObj = op.merge(obj, 'a.c.f', { a: 1 }) | ||
expect(newObj.a.c.f).to.be.eql({ a: 1 }) | ||
}) | ||
@@ -531,4 +538,4 @@ | ||
var newObj = op(obj).merge('a.c.f', {a: 1}).value() | ||
expect(newObj.a.c.f).to.be.eql({a: 1}) | ||
var newObj = op(obj).merge('a.c.f', { a: 1 }).value() | ||
expect(newObj.a.c.f).to.be.eql({ a: 1 }) | ||
}) | ||
@@ -555,3 +562,3 @@ }) | ||
expect(newObj.a).to.be.eql({f: 3, q: 'q'}) | ||
expect(newObj.a).to.be.eql({ f: 3, q: 'q' }) | ||
}) | ||
@@ -558,0 +565,0 @@ |
36952
1027
+ Addedis-plain-object@3.0.0(transitive)
+ Addedisobject@4.0.0(transitive)
- Removedis-plain-object@2.0.4(transitive)
- Removedisobject@3.0.1(transitive)
Updatedis-plain-object@3.0.0