1.0.4 • Published 6 years ago

@kingjs/mutate.copy v1.0.4

Weekly downloads
-
License
MIT
Repository
github
Last release
6 years ago

@kingjs/mutate.copy

Copies own and inherited enumerable property values optionally skipping those already defined.

Usage

Copy properties from source to target like this:

var copy = require('@kingjs/mutate.copy');

var target = { 
  a: 0,
  b: 1, 
};

var source = { 
  b: 2,
  c: 3
};

copy.call(target, source); 

result:

{
  a: 0,
  b: 2,
  c: 3
}

API

declare function copy(
  this, 
  source?, 
  skipIfDefined?: boolean | (name) => boolean,
): any

Parameters

  • this: An object to which properties are copied.
  • source: An object whose properties are copied to this.
  • skipIfDefined: Prevent overwriting if:
    • true.
    • A function that returns true given:
      • name: The name of the existing property.

Returns

Returns this after copying properties and values from source.

Remarks

Inherited and own properties are copied.

Non-enumerable properties are not copied.

if source is null or undefined, then this is returned unmodified.

Install

With npm installed, run

$ npm install @kingjs/mutate.copy

License

MIT

Analytics

1.0.4

6 years ago

1.0.3

6 years ago

1.0.2

6 years ago

1.0.1

6 years ago

1.0.0

6 years ago