1.2.0 • Published 5 months ago

mirror-own v1.2.0

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

mirror-own Version Badge

github actions coverage License Downloads

npm badge

Mirror (copy) the own property descriptors from one object, onto another.

Getting started

npm install --save mirror-own

Usage/Examples

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');

Options

You may pass an optional options object as the third argument. The available options are:

skipFailures

Must be a boolean, if present. If true, then non-configurable keys on to will be silently skipped.

omit

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.

Tests

Clone the repo, npm install, and run npm test