diff --git a/CHANGELOG.md b/CHANGELOG.md index 68d0d96..e8ad245 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,7 @@ # Change Log ## [unreleased] +* Fix support for Date objects and other non-plain objects (https://github.com/substantial/updeep/issues/36) ## [0.10.0] * Add support for wildcards (`*`) to `u.updateIn`. (https://github.com/substantial/updeep/issues/27) diff --git a/lib/update.js b/lib/update.js index e1c3dc3..507bff9 100644 --- a/lib/update.js +++ b/lib/update.js @@ -1,6 +1,7 @@ import wrap from './wrap'; import isEmpty from './util/isEmpty'; import defaultObject from './util/defaultObject'; +import isPlainObject from 'lodash/lang/isPlainObject'; function reduce(object, callback, initialValue) { return Object.keys(object).reduce((acc, key) => { @@ -58,7 +59,7 @@ function update(updates, object, ...args) { return updates(object, ...args); } - if (updates === null || typeof updates !== 'object') { + if (!isPlainObject(updates)) { return updates; } diff --git a/test/updeep-spec.js b/test/updeep-spec.js index bbfb4b9..17ece4b 100644 --- a/test/updeep-spec.js +++ b/test/updeep-spec.js @@ -146,4 +146,10 @@ describe('updeep', () => { const result = u({ a: {} }, {}); expect(result).to.eql({ a: {} }); }); + + it('works with date objects', () => { + const date = new Date(); + const result = u({ created: date }, {}); + expect(result).to.eql({ created: date }); + }); });