Mirror (copy) the own property descriptors from one object, onto another.
npm install --save mirror-own
const assert = require('assert');
const mirrorOwn = require('mirror-own');
const a = { a: 1, b: 2, [Symbol.toStringTag]: 'foo' };
const b = { c: 3 };
mirrorOwn(a, b);
assert.deepEqual(a, { a: 1, b: 2, [Symbol.toStringTag]: 'foo' }, 'source object unchanged');
assert.deepEqual(b, { a: 1, b: 2, c: 3, [Symbol.toStringTag]: 'foo' }, 'target object changed');
You may pass an optional options object as the third argument. The available options are:
Must be a boolean, if present.
If true
, then non-configurable keys on to
will be silently skipped.
Must be a predicate function, if present.
It will be invoked once per key of from
, and if it returns a truthy value, that key will not be mirrored onto to
.
Clone the repo, npm install
, and run npm test