# @alexspirgel/extend

> Extends an object with vanilla JavaScript.

Latest version **4.0.0** (published 2021-11-02) · MIT license · 0 weekly downloads

## Install

```sh
npm install @alexspirgel/extend
pnpm add @alexspirgel/extend
yarn add @alexspirgel/extend
bun add @alexspirgel/extend
```

## 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 | 4.0.0 |
| Published | 2021-11-02 |
| First published | 2018-05-27 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Unpacked size | 4.1 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | Alexander Spirgel |
| Maintainers | alexspirgel |
| Keywords | vanilla, JavaScript, extend, deep, clone, merge |

## Links

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

## Dependencies (1)

- [@alexspirgel/is-plain-object](https://npm.io/package/@alexspirgel/is-plain-object.md) ^1.0.5

## Recent versions

- 4.0.0 (latest) — 2021-11-02
- 3.0.1 — 2021-02-24
- 3.0.0 — 2020-08-24
- 2.0.4 — 2020-08-07
- 2.0.3 — 2018-11-11
- 2.0.2 — 2018-11-11
- 2.0.1 — 2018-10-20
- 2.0.0 — 2018-08-25
- 1.2.1 — 2018-05-27

## README

# extend
Extends a value with another value using vanilla JavaScript. Similar in functionality to the jQuery extend function.

Notes:

* This function always performs a deep copy, there is no shallow copy option. Native solutions now exist for shallow copying.
* Arrays are not merged, they are replaced without referencing the original.
* Non-plain objects are passed by reference.
* `undefined` values are not merged into the target.

## Installation

### Using NPM:

```js
npm install @alexspirgel/extend
```

```js
const extend = require('@alexspirgel/extend');
```

### Using a script tag:

Download the `extend.js` file from the `/dist` folder.

```html
<script src="path/to/extend.js"></script>
```

## Usage

### Extend an object with other objects
```js
extend(object1, object2, objects3);
```
`object2` and `object3` will be merged into `object1`.

### Clone an object
```js
let object2 = extend({}, object1);
```
`object2` will be a clone of `object1`.

## Example

```js
const value1 = {
	a: 1,
	b: 2,
	c: {
		a: 1,
		b: 2
	},
	e: [
		true,
		'false'
	]
};

const value2 = {
	b: '2',
	body: document.body, // passed by reference
	c: {
		b: 200,
		c: 3
	},
	d: 4,
	e: [
		false
	]
};

const result = extend(value1, value2);

console.log(result);
/* 
Output:
{
	a: 1,
	b: '2',
	body: document.body,
	c: {
		a: 1,
		b: 200,
		c: 3
	}
	d: 4,
	e: [
		false
	]
}
*/
```

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