https://github.com/swordev/merge
https://github.com/swordev/merge
clone extend javascript merge typescript
Last synced: 9 months ago
JSON representation
- Host: GitHub
- URL: https://github.com/swordev/merge
- Owner: swordev
- License: mit
- Created: 2012-05-07T01:46:14.000Z (over 13 years ago)
- Default Branch: main
- Last Pushed: 2024-02-06T16:25:03.000Z (almost 2 years ago)
- Last Synced: 2025-03-21T09:37:40.869Z (9 months ago)
- Topics: clone, extend, javascript, merge, typescript
- Language: TypeScript
- Homepage:
- Size: 519 KB
- Stars: 176
- Watchers: 5
- Forks: 40
- Open Issues: 11
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# merge
[![workflow-badge]](https://github.com/swordev/merge/actions/workflows/ci.yaml) [![license-badge]](https://github.com/swordev/merge#license)
[workflow-badge]: https://img.shields.io/github/actions/workflow/status/swordev/merge/ci.yaml?branch=main
[license-badge]: https://img.shields.io/github/license/swordev/merge
> (recursive)? merging of (cloned)? objects.
## Installation
```sh
npm install merge
```
## Usage
### API
```ts
merge(clone: boolean, ...items: Object[])
merge(...items: Object[])
merge.recursive(clone: boolean, ...items: Object[])
merge.recursive(...items: Object[])
```
### Examples
```js
const objectA = {};
merge(objectA, { value: 1 }, { str: "hello world" });
const objectB = merge(true, objectA, { value: 2 });
objectA; // { value: 1, str: 'hello world' }
objectB; // { value: 2, str: 'hello world' }
```
```js
const objectA = {};
merge.recursive(
objectA,
{ level: { value: 1 } },
{ level: { str: "hello world" } },
);
const objectB = merge.recursive(true, objectA, { level: { value: 2 } });
objectA.level; // { value: 1, str: 'hello world' }
objectB.level; // { value: 2, str: 'hello world' }
```
## Development
### Requirements
- [Node.js v18](https://nodejs.org)
- [pnpm v8](https://pnpm.io)
### Build
```sh
pnpm build
```
### Test
```sh
pnpm test
```
## License
Distributed under the MIT License. See LICENSE file in each package for more information.