https://github.com/tmpfs/safe-merge
Fast, reliable merge that supports complex instances
https://github.com/tmpfs/safe-merge
Last synced: 8 months ago
JSON representation
Fast, reliable merge that supports complex instances
- Host: GitHub
- URL: https://github.com/tmpfs/safe-merge
- Owner: tmpfs
- Created: 2017-02-01T03:58:01.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2017-02-05T08:39:10.000Z (about 9 years ago)
- Last Synced: 2025-02-23T13:52:52.303Z (about 1 year ago)
- Language: JavaScript
- Size: 20.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Safe Merge
[](https://travis-ci.org/tmpfs/safe-merge)
[](https://npmjs.org/package/safe-merge)
[](https://coveralls.io/github/tmpfs/safe-merge?branch=master)
Fast and safe object merge that does not mangle complex instances.
* Tiny ES6 code, ~100 LOC
* Returns object copy
* Recursive merge by default
* Own properties only
* Complex instances by pointer
* Supports clone on complex instances
* Copies RegExp instances
* Errors on circular reference
You nearly always want a merge to be recursive (otherwise just use `Object.assign()`) and normally want a copy of the objects so that they can safely be modified without modifying the original source object. However when copying most merge libraries will convert complex instances (instances of custom classes) to vanilla objects which can break the code in subtle ways.
This library will pass complex instances by pointer unless they declare a `clone()` method that allows them to be copied.
---
- [Install](#install)
- [Usage](#usage)
- [License](#license)
---
## Install
```
npm i --save safe-merge
```
## Usage
```javascript
const merge = require('safe-merge')
const defaults = {devtool: 'sourcemap', plugins: []}
const input = {devtool: false}
const options = merge(defaults, input);
console.dir(options);
```
## License
MIT
---
Created by [mkdoc](https://github.com/mkdoc/mkdoc) on February 1, 2017
[mkdoc]: https://github.com/mkdoc/mkdoc
[jshint]: http://jshint.com
[jscs]: http://jscs.info