@fastify/deepmerge
Advanced tools
Comparing version 1.1.0 to 1.2.0
16
index.js
@@ -7,2 +7,4 @@ 'use strict' | ||
const JSON_PROTO = Object.getPrototypeOf({}) | ||
function deepmergeConstructor (options) { | ||
@@ -30,2 +32,6 @@ function isNotPrototypeKey (value) { | ||
if (cloneProtoObject && Object.getPrototypeOf(target) !== JSON_PROTO) { | ||
return cloneProtoObject(target) | ||
} | ||
const targetKeys = getKeys(target) | ||
@@ -68,2 +74,6 @@ let i, il, key | ||
const cloneProtoObject = typeof options?.cloneProtoObject === 'function' | ||
? options.cloneProtoObject | ||
: undefined | ||
function isMergeableObject (value) { | ||
@@ -77,5 +87,5 @@ return typeof value === 'object' && value !== null && !(value instanceof RegExp) && !(value instanceof Date) | ||
function isPrimitiveOrBuiltIn (value) { | ||
return typeof value !== 'object' || value === null || value instanceof RegExp || value instanceof Date | ||
} | ||
const isPrimitiveOrBuiltIn = typeof Buffer !== 'undefined' | ||
? (value) => typeof value !== 'object' || value === null || value instanceof RegExp || value instanceof Date || value instanceof Buffer | ||
: (value) => typeof value !== 'object' || value === null || value instanceof RegExp || value instanceof Date | ||
@@ -82,0 +92,0 @@ const mergeArray = options && typeof options.mergeArray === 'function' |
{ | ||
"name": "@fastify/deepmerge", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "Merges the enumerable properties of two or more objects deeply.", | ||
@@ -27,3 +27,4 @@ "main": "index.js", | ||
"tap": "^16.3.0", | ||
"tsd": "^0.22.0" | ||
"tape": "^5.6.1", | ||
"tsd": "^0.24.1" | ||
}, | ||
@@ -30,0 +31,0 @@ "files": [ |
@@ -27,2 +27,3 @@ # @fastify/deepmerge | ||
- `mergeArray` (`function`, optional) - provide a function, which returns a function to add custom array merging function | ||
- `cloneProtoObject` (`function`, optional) - provide a function, which must return a clone of the object with the prototype of the object | ||
@@ -116,2 +117,20 @@ ```js | ||
#### cloneProtoObject | ||
Merging objects with prototypes, such as Streams or Buffers, are not supported by default. | ||
You can provide a custom function to let this module deal with the object that has a `prototype` _(JSON object excluded)_. | ||
```js | ||
function cloneByReference (source) { | ||
return source | ||
} | ||
const deepmergeByReference = require('@fastify/deepmerge')({ | ||
cloneProtoObject: cloneByReference | ||
}) | ||
const result = deepmergeByReference({}, { stream: process.stdout }) | ||
console.log(result) // { stream: <ref *1> WriteStream } | ||
``` | ||
## Benchmarks | ||
@@ -118,0 +137,0 @@ |
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
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
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
14158
199
160
4
1