# copy-own

> Copies an object’s own properties to another object.

Latest version **1.2.0** (published 2019-10-04) · MIT license · 0 weekly downloads

## Install

```sh
npm install copy-own
pnpm add copy-own
yarn add copy-own
bun add copy-own
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.0 |
| Published | 2019-10-04 |
| First published | 2018-01-31 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=6.0.0 |
| Dependencies | 0 |
| Unpacked size | 4.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Fr. John Lamansky |
| Maintainers | lamansky |
| Keywords | copy, own, object, properties |

## Links

- npm: https://www.npmjs.com/package/copy-own
- Repository: https://github.com/lamansky/copy-own
- Issues: https://github.com/lamansky/copy-own/issues
- npm.io page: https://npm.io/package/copy-own

## Alternatives

- [@mdxeditor/editor](https://npm.io/package/@mdxeditor/editor.md) — 962.4K weekly downloads
- [mmdb-lib](https://npm.io/package/mmdb-lib.md) — 680.9K weekly downloads
- [playcanvas](https://npm.io/package/playcanvas.md) — 36.2K weekly downloads
- [@glw907/cairn-cms](https://npm.io/package/@glw907/cairn-cms.md) — 967 weekly downloads
- [markdown-to-confluence](https://npm.io/package/markdown-to-confluence.md) — 103 weekly downloads

## Recent versions

- 1.2.0 (latest) — 2019-10-04
- 1.1.0 — 2018-03-06
- 1.0.0 — 2018-01-31

## README

# 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](https://nodejs.org/) 6.0.0 or above.

```bash
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

```javascript
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`:

```javascript
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:

```javascript
const copyOwn = require('copy-own')

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

---
_Source: https://npm.io/package/copy-own · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
