diff --git a/package-lock.json b/package-lock.json index 4e4b98b..1a8fdac 100644 --- a/package-lock.json +++ b/package-lock.json @@ -11,7 +11,7 @@ "devDependencies": { "@types/node": "^8.10.54", "is-mergeable-object": "1.1.0", - "is-plain-object": "^2.0.4", + "is-plain-object": "^5.0.0", "jsmd": "^1.0.2", "rollup": "^1.23.1", "rollup-plugin-commonjs": "^10.1.0", @@ -359,21 +359,9 @@ "dev": true }, "node_modules/is-plain-object": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", - "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", - "dev": true, - "dependencies": { - "isobject": "^3.0.1" - }, - "engines": { - "node": ">=0.10.0" - } - }, - "node_modules/is-plain-object/node_modules/isobject": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", - "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==", "dev": true, "engines": { "node": ">=0.10.0" @@ -1135,21 +1123,10 @@ "dev": true }, "is-plain-object": { - "version": "2.0.4", - "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-2.0.4.tgz", - "integrity": "sha512-h5PpgXkWitc38BBMYawTYMWJHFZJVnBquFE57xFpjB8pJFiF6gZ+bU+WyI/yqXiFR5mdLsgYNaPe8uao6Uv9Og==", - "dev": true, - "requires": { - "isobject": "^3.0.1" - }, - "dependencies": { - "isobject": { - "version": "3.0.1", - "resolved": "https://registry.npmjs.org/isobject/-/isobject-3.0.1.tgz", - "integrity": "sha1-TkMekrEalzFjaqH5yNHMvP2reN8=", - "dev": true - } - } + "version": "5.0.0", + "resolved": "https://registry.npmjs.org/is-plain-object/-/is-plain-object-5.0.0.tgz", + "integrity": "sha512-VRSzKkbMm5jMDoKLbltAkFQ5Qr7VDiTFGXxYFXXowVj387GeGNOCsOH6Msy00SGZ3Fp84b1Naa1psqgcCIEP5Q==", + "dev": true }, "is-reference": { "version": "1.1.4", diff --git a/package.json b/package.json index 3b8507b..b1283d5 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "devDependencies": { "@types/node": "^8.10.54", "is-mergeable-object": "1.1.0", - "is-plain-object": "^2.0.4", + "is-plain-object": "^5.0.0", "jsmd": "^1.0.2", "rollup": "^1.23.1", "rollup-plugin-commonjs": "^10.1.0", @@ -38,6 +38,5 @@ "typescript": "=2.2.2", "uglify-js": "^3.6.1" }, - "license": "MIT", - "dependencies": {} + "license": "MIT" } diff --git a/test/custom-is-mergeable-object.js b/test/custom-is-mergeable-object.js index ea247ab..f58bbb8 100644 --- a/test/custom-is-mergeable-object.js +++ b/test/custom-is-mergeable-object.js @@ -1,36 +1,72 @@ -var merge = require('../') -var test = require('tape') +const merge = require(`..`) +const test = require(`tape`) -test('isMergeableObject function copying object over object', function(t) { - var src = { key: { isMergeable: false }, baz: 'yes' } - var target = { key: { foo: 'wat' }, baz: 'whatever' } +test(`isMergeableObject function copying object over object`, t => { + const src = { key: { isMergeable: false }, baz: `yes` } + const target = { key: { foo: `wat` }, baz: `whatever` } function isMergeableObject(object) { - return object && typeof value === 'object' && object.isMergeable !== false + return object && typeof value === `object` && object.isMergeable !== false } - var res = merge(target, src, { - isMergeableObject: isMergeableObject + const res = merge(target, src, { + isMergeableObject, }) - t.deepEqual(res, { key: { isMergeable: false }, baz: 'yes' }) - t.equal(res.key, src.key, 'Object has the same identity and was not cloned') + t.deepEqual(res, { key: { isMergeable: false }, baz: `yes` }) + t.equal(res.key, src.key, `Object has the same identity and was not cloned`) t.end() }) -test('isMergeableObject function copying object over nothing', function(t) { - var src = { key: { isMergeable: false, foo: 'bar' }, baz: 'yes' } - var target = { baz: 'whatever' } +test(`isMergeableObject function copying object over nothing`, t => { + const src = { key: { isMergeable: false, foo: `bar` }, baz: `yes` } + const target = { baz: `whatever` } function isMergeableObject(object) { - return object && typeof value === 'object' && object.isMergeable !== false + return object && typeof value === `object` && object.isMergeable !== false } - var res = merge(target, src, { - isMergeableObject: isMergeableObject + const res = merge(target, src, { + isMergeableObject, }) - t.deepEqual(res, { key: { isMergeable: false, foo: 'bar' }, baz: 'yes' }) - t.equal(res.key, src.key, 'Object has the same identity and was not cloned') + t.deepEqual(res, { key: { isMergeable: false, foo: `bar` }, baz: `yes` }) + t.equal(res.key, src.key, `Object has the same identity and was not cloned`) + t.end() +}) + +test(`example from readme`, t => { + const { isPlainObject } = require(`is-plain-object`) + + function SuperSpecial() { + this.special = `oh yeah man totally` + } + + const instantiatedSpecialObject = new SuperSpecial() + + const target = { + someProperty: { + cool: `oh for sure`, + }, + } + + const source = { + someProperty: instantiatedSpecialObject, + } + + const defaultOutput = merge(target, source) + + t.equal(defaultOutput.someProperty.cool, `oh for sure`) + t.equal(defaultOutput.someProperty.special, `oh yeah man totally`) + t.equal(defaultOutput.someProperty instanceof SuperSpecial, false) + + const customMergeOutput = merge(target, source, { + isMergeableObject: isPlainObject, + }) + + t.equal(customMergeOutput.someProperty.cool, undefined) + t.equal(customMergeOutput.someProperty.special, `oh yeah man totally`) + t.equal(customMergeOutput.someProperty instanceof SuperSpecial, true) + t.end() })