# add-or-extend

> Add to array or extend an object

Latest version **1.0.0** (published 2018-06-24) · MIT license · 0 weekly downloads

> **Deprecated.** This package is deprecated.

## Install

```sh
npm install add-or-extend
pnpm add add-or-extend
yarn add add-or-extend
bun add add-or-extend
```

## Health

**Score 10/100 (F)** — status: deprecated.

Negative: deprecated.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-06-24 |
| First published | 2018-06-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.10.0 |
| Dependencies | 1 |
| Unpacked size | 5.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Mike Savastano |
| Maintainers | millhouse |

## Links

- npm: https://www.npmjs.com/package/add-or-extend
- Repository: https://github.com/msavastano/add-or-extend
- Homepage: https://github.com/msavastano/add-or-extend#readme
- Issues: https://github.com/msavastano/add-or-extend/issues
- npm.io page: https://npm.io/package/add-or-extend

## Dependencies (1)

- [lodash](https://npm.io/package/lodash.md) ^4.17.10

## Recent versions

- 1.0.0 (latest) — 2018-06-24
- 1.0.0-rc — 2018-06-23

## README

## Description
 - Just adds or extends an object depending on whenther the key exists
## Usage

```
npm install add-or-extend --save
var addOrExtend = require('add-or-extend');
```

```
var targetObject = {
  theKey: [
    'hello', 
    'world'
  ]
};
```

```
var key = 'theKey';
var sourceObject = {
  any: 'thing'
}
// requires all params or will throw an error
var after = addOrExtend(targetObject, key, sourceObject)
console.log(after);
// { theKey: [ 'hello', 'world', { any: 'thing' } ] }
```

```
var key = 'anotherKey';
var sourceObject = {
    any: 'thing'
}
var after = addOrExtend(targetObject, key, sourceObject);
console.log(after);
//  { theKey: [ 'hello', 'world', { any: 'thing' } ], anotherKey: { any: 'thing' } }
```

```
var targetObject = {
  theKey: {
    hello: 'world'
  }
};
var sourceObject = {
    any: 'thing'
}
var key = 'theKey';
var after = addOrExtend(targetObject, key, sourceObject);
console.log(after);
//{ theKey: { hello: 'world', any: 'thing' } }
```

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