Comparing version 2.1.0 to 2.1.1
@@ -0,1 +1,8 @@ | ||
# [2.1.1](https://github.com/KyleAMathews/deepmerge/releases/tag/v2.1.1) | ||
- documentation: Rename "methods" to "api", note ESM syntax [#103](https://github.com/KyleAMathews/deepmerge/pull/103) | ||
- documentation: Fix grammar [#107](https://github.com/KyleAMathews/deepmerge/pull/107) | ||
- documentation: Restructure headers for clarity + some wording tweaks [108](https://github.com/KyleAMathews/deepmerge/pull/108) + [109](https://github.com/KyleAMathews/deepmerge/pull/109) | ||
# [2.1.0](https://github.com/KyleAMathews/deepmerge/releases/tag/v2.1.0) | ||
@@ -2,0 +9,0 @@ |
@@ -13,3 +13,3 @@ { | ||
], | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"homepage": "https://github.com/KyleAMathews/deepmerge", | ||
@@ -16,0 +16,0 @@ "repository": { |
107
readme.md
@@ -1,14 +0,17 @@ | ||
deepmerge | ||
========= | ||
# deepmerge | ||
Merges the enumerable attributes of two or more objects deeply. | ||
> UMD bundle is 567B minified+gzipped | ||
Merge the enumerable attributes of two objects deeply. | ||
### Migration from 1.x to 2.0.0 | ||
[***Check out the changes from version 1.x to 2.0.0***](https://github.com/KyleAMathews/deepmerge/blob/master/changelog.md#200) | ||
For the old array element-merging algorithm, see [the `arrayMerge` option below](#arraymerge). | ||
For the legacy array element-merging algorithm, see [the `arrayMerge` option below](#arraymerge). | ||
## Webpack bug | ||
### Webpack bug | ||
If you have `require('deepmerge')` (as opposed to `import merge from 'deepmerge'`) anywhere in your codebase, Webpack 3 and 4 have a bug that [breaks bundling](https://github.com/webpack/webpack/issues/6584). | ||
@@ -24,5 +27,6 @@ | ||
example | ||
======= | ||
## Getting Started | ||
### Example Usage | ||
<!--js | ||
@@ -72,12 +76,32 @@ var merge = require('./') | ||
methods | ||
======= | ||
### Installation | ||
With [npm](http://npmjs.org) do: | ||
```sh | ||
npm install deepmerge | ||
``` | ||
deepmerge can be used directly in the browser without the use of package managers/bundlers as well: [UMD version from unpkg.com](https://unpkg.com/deepmerge/dist/umd.js). | ||
### Includes | ||
CommonJS: | ||
``` | ||
var merge = require('deepmerge') | ||
``` | ||
merge(x, y, [options]) | ||
----------- | ||
ES Modules: | ||
``` | ||
import merge from 'deepmerge' | ||
``` | ||
# API | ||
## `merge(x, y, [options])` | ||
Merge two objects `x` and `y` deeply, returning a new merged object with the | ||
@@ -89,7 +113,7 @@ elements from both `x` and `y`. | ||
Merging creates a new object, so that neither `x` or `y` are be modified. | ||
Merging creates a new object, so that neither `x` or `y` is modified. | ||
merge.all(arrayOfObjects, [options]) | ||
----------- | ||
## `merge.all(arrayOfObjects, [options])` | ||
Merges any number of objects into a single result object. | ||
@@ -107,16 +131,19 @@ | ||
### options | ||
#### arrayMerge | ||
## Options | ||
The merge will also concatenate arrays and merge array values by default. | ||
### `arrayMerge` | ||
deepmerge, by default, concatenates arrays and merges array values. | ||
However, there are nigh-infinite valid ways to merge arrays, and you may want to supply your own. You can do this by passing an `arrayMerge` function as an option. | ||
There are however nigh-infinite valid ways to merge arrays, and you may want to supply your own method. You can do this by passing an `arrayMerge` function as an option. | ||
The options object will include the default `isMergeableObject` implementation if the top-level consumer didn't pass a custom function in. | ||
#### Examples | ||
Example of overwriting merge when merging arrays: | ||
```js | ||
function overwriteMerge(destinationArray, sourceArray, options) { | ||
return sourceArray | ||
} | ||
const overwriteMerge = (destinationArray, sourceArray, options) => sourceArray | ||
merge( | ||
@@ -129,11 +156,14 @@ [1, 2, 3], | ||
To prevent arrays from being merged: | ||
Example of preventing arrays inside of objects from being merged: | ||
```js | ||
const dontMerge = (destination, source) => source | ||
const output = merge({ coolThing: [1,2,3] }, { coolThing: ['a', 'b', 'c'] }, { arrayMerge: dontMerge }) | ||
output // => { coolThing: ['a', 'b', 'c'] } | ||
merge( | ||
{ coolThing: [1, 2, 3] }, | ||
{ coolThing: ['a', 'b', 'c'] }, | ||
{ arrayMerge: dontMerge } | ||
) // => { coolThing: ['a', 'b', 'c'] } | ||
``` | ||
To use the old (pre-version-2.0.0) array merging algorithm, pass in this function: | ||
To use the legacy (pre-version-2.0.0) array merging algorithm, use the following: | ||
@@ -144,3 +174,3 @@ ```js | ||
function oldArrayMerge(target, source, options) { | ||
function legacyArrayMerge(target, source, options) { | ||
const destination = target.slice() | ||
@@ -165,8 +195,9 @@ | ||
[{ b: true }, 'ah yup'], | ||
{ arrayMerge: oldArrayMerge } | ||
{ arrayMerge: legacyArrayMerge } | ||
) // => [{ a: true, b: true }, 'ah yup'] | ||
``` | ||
#### isMergeableObject | ||
### `isMergeableObject` | ||
By default, deepmerge clones every property from almost every kind of object. | ||
@@ -214,4 +245,5 @@ | ||
#### clone | ||
### `clone` | ||
*Deprecated.* | ||
@@ -223,16 +255,5 @@ | ||
install | ||
======= | ||
With [npm](http://npmjs.org) do: | ||
# Testing | ||
```sh | ||
npm install deepmerge | ||
``` | ||
Just want to download the file without using any package managers/bundlers? [Download the UMD version from unpkg.com](https://unpkg.com/deepmerge/dist/umd.js). | ||
test | ||
==== | ||
With [npm](http://npmjs.org) do: | ||
@@ -244,5 +265,5 @@ | ||
license | ||
======= | ||
# License | ||
MIT |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25281
9
305
260