New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

copy-own

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

copy-own

Copies an object’s own properties to another object.

  • 1.2.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1.4K
decreased by-27.51%
Maintainers
1
Weekly downloads
 
Created
Source

copy-own

Copies an object’s own properties to another object.

“Own” properties are those that are not inherited from the prototype chain.

Installation

Requires Node.js 6.0.0 or above.

npm i copy-own

API

The module exports a single function.

Parameters

  1. from (object): The source object that possesses the properties to be copied.
  2. Optional: to (object): The destination object that should receive the copied properties. Defaults to a new object.
  3. Optional: Object argument:
    • enumOnly (boolean): Whether or not to limit the copy operation to only those properties that were defined with the enumerable flag. Defaults to false.
    • override (boolean): If omitted or set to true, all properties will be copied (unless overwrite specifies otherwise). If set to false, then existing properties in to will be neither overwritten nor overridden; that is, the copy operation will only include properties that do not share a name with properties already existing in to or in its prototype chain.
    • overwrite (boolean): This property is only taken into consideration if override (see above) is omitted or set to true. If this property is also omitted or set to true, all properties will be copied (the default behavior). If set to false, then existing properties in to will not be overwritten, but properties higher up in to’s prototype chain could still be overridden.

Return Value

The function modifies the second argument (to) and returns it. If to is omitted, a new object is created and returned.

Examples

const copyOwn = require('copy-own')

const from = {a: 'from', b: 'from'}
const to = {b: 'to', c: 'to'}
const to = copyOwn(from, to)
to.a // 'from'
to.b // 'from'
to.c // 'to'

Here is the same example repeated with overwrite set to false:

const copyOwn = require('copy-own')

const from = {a: 'from', b: 'from'}
const to = {b: 'to', c: 'to'}
const to = copyOwn(from, to, {overwrite: false})
to.a // 'from'
to.b // 'to'
to.c // 'to'

When no destination object is specified, a new object is created:

const copyOwn = require('copy-own')

const from = {a: 1, b: 2}
const to = copyOwn(from)
to.a // 1
to.b // 2

Keywords

FAQs

Package last updated on 04 Oct 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc