safe-merge

1.1.3 • Public • Published

Safe Merge

Build Status npm version Coverage Status

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

npm i --save safe-merge

Usage

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 on February 1, 2017

Readme

Keywords

Package Sidebar

Install

npm i safe-merge

Weekly Downloads

3

Version

1.1.3

License

MIT

Last publish

Collaborators

  • tmpfs