Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

deepmerge-plus

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deepmerge-plus - npm Package Compare versions

Comparing version 2.0.4 to 2.1.0

59

dist/es.js

@@ -29,15 +29,33 @@ var isMergeableObject = function isMergeableObject(value) {

}
function cloneUnlessOtherwiseSpecified(value, optionsArgument, key) {
function cloneUnlessOtherwiseSpecified(value, optionsArgument, tmp) {
let clone = !optionsArgument || optionsArgument.clone !== false;
return (clone && _isMergeableObject(value, optionsArgument, key))
let bool = clone && _isMergeableObject(value, optionsArgument, tmp);
let ret = (bool)
? deepmerge(emptyTarget(value), value, optionsArgument)
: value;
if (optionsArgument && optionsArgument.keyValueOrMode && !bool && tmp && ('key' in tmp)) {
if (tmp.destination) {
ret = tmp.destination[tmp.key] || ret;
}
if (tmp.target) {
ret = tmp.target[tmp.key] || ret;
}
if (tmp.source) {
ret = tmp.source[tmp.key] || ret;
}
}
return ret;
}
function _isMergeableObject(value, optionsArgument, key) {
function _isMergeableObject(value, optionsArgument, tmp) {
let ret;
if (optionsArgument && optionsArgument.isMergeableObject) {
ret = optionsArgument.isMergeableObject(value, isMergeableObject, optionsArgument, key);
ret = optionsArgument.isMergeableObject(value, isMergeableObject, optionsArgument, tmp);
}
if (ret === null || typeof ret === 'undefined') {
ret = isMergeableObject(value);
if (value && (typeof value[deepmerge.SYMBOL_IS_MERGEABLE] == 'boolean')) {
ret = value[deepmerge.SYMBOL_IS_MERGEABLE];
}
else {
ret = isMergeableObject(value);
}
}

@@ -47,4 +65,6 @@ return ret;

function defaultArrayMerge(target, source, optionsArgument) {
return target.concat(source).map(function (element, index) {
return cloneUnlessOtherwiseSpecified(element, optionsArgument, index);
return target.concat(source).map(function (element, index, array) {
return cloneUnlessOtherwiseSpecified(element, optionsArgument, {
key: index,
});
});

@@ -56,8 +76,21 @@ }

Object.keys(target).forEach(function (key) {
destination[key] = cloneUnlessOtherwiseSpecified(target[key], optionsArgument, key);
destination[key] = cloneUnlessOtherwiseSpecified(target[key], optionsArgument, {
key,
source,
target,
destination,
});
});
}
Object.keys(source).forEach(function (key) {
if (!_isMergeableObject(source[key], optionsArgument, key) || !target[key]) {
destination[key] = cloneUnlessOtherwiseSpecified(source[key], optionsArgument, key);
if (!_isMergeableObject(source[key], optionsArgument, {
key,
source,
target,
}) || !target[key]) {
destination[key] = cloneUnlessOtherwiseSpecified(source[key], optionsArgument, {
key,
source,
target,
});
}

@@ -76,3 +109,6 @@ else {

if (!sourceAndTargetTypesMatch) {
return cloneUnlessOtherwiseSpecified(source, optionsArgument);
return cloneUnlessOtherwiseSpecified(source, optionsArgument, {
target,
source,
});
}

@@ -89,2 +125,3 @@ else if (sourceIsArray) {

deepmerge.isMergeable = isMergeableObject;
deepmerge.SYMBOL_IS_MERGEABLE = Symbol.for('SYMBOL_IS_MERGEABLE');
deepmerge.all = function deepmergeAll(array, optionsArgument) {

@@ -91,0 +128,0 @@ if (!Array.isArray(array)) {

@@ -35,15 +35,33 @@ (function (global, factory) {

}
function cloneUnlessOtherwiseSpecified(value, optionsArgument, key) {
function cloneUnlessOtherwiseSpecified(value, optionsArgument, tmp) {
let clone = !optionsArgument || optionsArgument.clone !== false;
return (clone && _isMergeableObject(value, optionsArgument, key))
let bool = clone && _isMergeableObject(value, optionsArgument, tmp);
let ret = (bool)
? deepmerge(emptyTarget(value), value, optionsArgument)
: value;
if (optionsArgument && optionsArgument.keyValueOrMode && !bool && tmp && ('key' in tmp)) {
if (tmp.destination) {
ret = tmp.destination[tmp.key] || ret;
}
if (tmp.target) {
ret = tmp.target[tmp.key] || ret;
}
if (tmp.source) {
ret = tmp.source[tmp.key] || ret;
}
}
return ret;
}
function _isMergeableObject(value, optionsArgument, key) {
function _isMergeableObject(value, optionsArgument, tmp) {
let ret;
if (optionsArgument && optionsArgument.isMergeableObject) {
ret = optionsArgument.isMergeableObject(value, isMergeableObject, optionsArgument, key);
ret = optionsArgument.isMergeableObject(value, isMergeableObject, optionsArgument, tmp);
}
if (ret === null || typeof ret === 'undefined') {
ret = isMergeableObject(value);
if (value && (typeof value[deepmerge.SYMBOL_IS_MERGEABLE] == 'boolean')) {
ret = value[deepmerge.SYMBOL_IS_MERGEABLE];
}
else {
ret = isMergeableObject(value);
}
}

@@ -53,4 +71,6 @@ return ret;

function defaultArrayMerge(target, source, optionsArgument) {
return target.concat(source).map(function (element, index) {
return cloneUnlessOtherwiseSpecified(element, optionsArgument, index);
return target.concat(source).map(function (element, index, array) {
return cloneUnlessOtherwiseSpecified(element, optionsArgument, {
key: index,
});
});

@@ -62,8 +82,21 @@ }

Object.keys(target).forEach(function (key) {
destination[key] = cloneUnlessOtherwiseSpecified(target[key], optionsArgument, key);
destination[key] = cloneUnlessOtherwiseSpecified(target[key], optionsArgument, {
key,
source,
target,
destination,
});
});
}
Object.keys(source).forEach(function (key) {
if (!_isMergeableObject(source[key], optionsArgument, key) || !target[key]) {
destination[key] = cloneUnlessOtherwiseSpecified(source[key], optionsArgument, key);
if (!_isMergeableObject(source[key], optionsArgument, {
key,
source,
target,
}) || !target[key]) {
destination[key] = cloneUnlessOtherwiseSpecified(source[key], optionsArgument, {
key,
source,
target,
});
}

@@ -82,3 +115,6 @@ else {

if (!sourceAndTargetTypesMatch) {
return cloneUnlessOtherwiseSpecified(source, optionsArgument);
return cloneUnlessOtherwiseSpecified(source, optionsArgument, {
target,
source,
});
}

@@ -95,2 +131,3 @@ else if (sourceIsArray) {

deepmerge.isMergeable = isMergeableObject;
deepmerge.SYMBOL_IS_MERGEABLE = Symbol.for('SYMBOL_IS_MERGEABLE');
deepmerge.all = function deepmergeAll(array, optionsArgument) {

@@ -97,0 +134,0 @@ if (!Array.isArray(array)) {

declare function deepmerge<T>(x: Partial<T>, y: Partial<T>, options?: deepmerge.Options): T;
declare function deepmerge<T1, T2>(x: T1, y: T2, options?: deepmerge.Options): T1 & T2;
declare namespace deepmerge {
interface ICache {
key?: any;
source?: any;
target?: any;
destination?: any;
}
interface Options {

@@ -9,4 +15,6 @@ clone?: boolean;

isMergeableObject?(value: any, isMergeableObject: (value) => boolean, optionsArgument?: Options, key?: any): boolean;
keyValueOrMode?: boolean;
}
const isMergeable: (value) => boolean;
const SYMBOL_IS_MERGEABLE: symbol;
const all: <T>(array: Partial<T>[], optionsArgument?: Options) => T;

@@ -13,0 +21,0 @@ }

@@ -6,15 +6,33 @@ "use strict";

}
function cloneUnlessOtherwiseSpecified(value, optionsArgument, key) {
function cloneUnlessOtherwiseSpecified(value, optionsArgument, tmp) {
let clone = !optionsArgument || optionsArgument.clone !== false;
return (clone && _isMergeableObject(value, optionsArgument, key))
let bool = clone && _isMergeableObject(value, optionsArgument, tmp);
let ret = (bool)
? deepmerge(emptyTarget(value), value, optionsArgument)
: value;
if (optionsArgument && optionsArgument.keyValueOrMode && !bool && tmp && ('key' in tmp)) {
if (tmp.destination) {
ret = tmp.destination[tmp.key] || ret;
}
if (tmp.target) {
ret = tmp.target[tmp.key] || ret;
}
if (tmp.source) {
ret = tmp.source[tmp.key] || ret;
}
}
return ret;
}
function _isMergeableObject(value, optionsArgument, key) {
function _isMergeableObject(value, optionsArgument, tmp) {
let ret;
if (optionsArgument && optionsArgument.isMergeableObject) {
ret = optionsArgument.isMergeableObject(value, isMergeableObject, optionsArgument, key);
ret = optionsArgument.isMergeableObject(value, isMergeableObject, optionsArgument, tmp);
}
if (ret === null || typeof ret === 'undefined') {
ret = isMergeableObject(value);
if (value && (typeof value[deepmerge.SYMBOL_IS_MERGEABLE] == 'boolean')) {
ret = value[deepmerge.SYMBOL_IS_MERGEABLE];
}
else {
ret = isMergeableObject(value);
}
}

@@ -24,4 +42,6 @@ return ret;

function defaultArrayMerge(target, source, optionsArgument) {
return target.concat(source).map(function (element, index) {
return cloneUnlessOtherwiseSpecified(element, optionsArgument, index);
return target.concat(source).map(function (element, index, array) {
return cloneUnlessOtherwiseSpecified(element, optionsArgument, {
key: index,
});
});

@@ -33,8 +53,21 @@ }

Object.keys(target).forEach(function (key) {
destination[key] = cloneUnlessOtherwiseSpecified(target[key], optionsArgument, key);
destination[key] = cloneUnlessOtherwiseSpecified(target[key], optionsArgument, {
key,
source,
target,
destination,
});
});
}
Object.keys(source).forEach(function (key) {
if (!_isMergeableObject(source[key], optionsArgument, key) || !target[key]) {
destination[key] = cloneUnlessOtherwiseSpecified(source[key], optionsArgument, key);
if (!_isMergeableObject(source[key], optionsArgument, {
key,
source,
target,
}) || !target[key]) {
destination[key] = cloneUnlessOtherwiseSpecified(source[key], optionsArgument, {
key,
source,
target,
});
}

@@ -53,3 +86,6 @@ else {

if (!sourceAndTargetTypesMatch) {
return cloneUnlessOtherwiseSpecified(source, optionsArgument);
return cloneUnlessOtherwiseSpecified(source, optionsArgument, {
target,
source,
});
}

@@ -66,2 +102,3 @@ else if (sourceIsArray) {

deepmerge.isMergeable = isMergeableObject;
deepmerge.SYMBOL_IS_MERGEABLE = Symbol.for('SYMBOL_IS_MERGEABLE');
deepmerge.all = function deepmergeAll(array, optionsArgument) {

@@ -68,0 +105,0 @@ if (!Array.isArray(array)) {

@@ -8,12 +8,37 @@ import * as isMergeableObject from 'is-mergeable-object';

function cloneUnlessOtherwiseSpecified(value, optionsArgument: deepmerge.Options, key?)
function cloneUnlessOtherwiseSpecified(value, optionsArgument: deepmerge.Options, tmp?: deepmerge.ICache)
{
let clone = !optionsArgument || optionsArgument.clone !== false;
return (clone && _isMergeableObject(value, optionsArgument, key))
let bool = clone && _isMergeableObject(value, optionsArgument, tmp);
let ret = (bool)
? deepmerge(emptyTarget(value), value, optionsArgument)
: value
: value;
if (optionsArgument && optionsArgument.keyValueOrMode && !bool && tmp && ('key' in tmp))
{
if (tmp.destination)
{
//console.log('destination', tmp.destination[tmp.key], ret, tmp.key);
ret = tmp.destination[tmp.key] || ret;
}
if (tmp.target)
{
//console.log('target', tmp.target[tmp.key], ret, tmp.key);
ret = tmp.target[tmp.key] || ret;
}
if (tmp.source)
{
//console.log('source', tmp.source[tmp.key], ret, tmp.key);
ret = tmp.source[tmp.key] || ret;
}
}
return ret;
}
function _isMergeableObject(value, optionsArgument: deepmerge.Options, key?)
function _isMergeableObject(value, optionsArgument: deepmerge.Options, tmp?: deepmerge.ICache)
{

@@ -23,7 +48,14 @@ let ret;

{
ret = optionsArgument.isMergeableObject(value, isMergeableObject, optionsArgument, key)
ret = optionsArgument.isMergeableObject(value, isMergeableObject, optionsArgument, tmp)
}
if (ret === null || typeof ret === 'undefined')
{
ret = isMergeableObject(value)
if (value && (typeof value[deepmerge.SYMBOL_IS_MERGEABLE] == 'boolean'))
{
ret = value[deepmerge.SYMBOL_IS_MERGEABLE];
}
else
{
ret = isMergeableObject(value);
}
}

@@ -35,5 +67,7 @@ return ret

{
return target.concat(source).map(function (element, index)
return target.concat(source).map(function (element, index, array)
{
return cloneUnlessOtherwiseSpecified(element, optionsArgument, index)
return cloneUnlessOtherwiseSpecified(element, optionsArgument, {
key: index,
})
})

@@ -49,3 +83,8 @@ }

{
destination[key] = cloneUnlessOtherwiseSpecified(target[key], optionsArgument, key)
destination[key] = cloneUnlessOtherwiseSpecified(target[key], optionsArgument, {
key,
source,
target,
destination,
})
})

@@ -55,5 +94,13 @@ }

{
if (!_isMergeableObject(source[key], optionsArgument, key) || !target[key])
if (!_isMergeableObject(source[key], optionsArgument, {
key,
source,
target,
}) || !target[key])
{
destination[key] = cloneUnlessOtherwiseSpecified(source[key], optionsArgument, key)
destination[key] = cloneUnlessOtherwiseSpecified(source[key], optionsArgument, {
key,
source,
target,
})
}

@@ -79,3 +126,6 @@ else

{
return cloneUnlessOtherwiseSpecified(source, optionsArgument);
return cloneUnlessOtherwiseSpecified(source, optionsArgument, {
target,
source,
});
}

@@ -95,2 +145,10 @@ else if (sourceIsArray)

{
export interface ICache
{
key?
source?
target?
destination?
}
export interface Options

@@ -105,5 +163,11 @@ {

isMergeableObject?(value, isMergeableObject: (value) => boolean, optionsArgument?: Options, key?): boolean;
/**
* (val = old || new) mode
*/
keyValueOrMode?: boolean,
}
export const isMergeable: (value) => boolean = isMergeableObject;
export const SYMBOL_IS_MERGEABLE = Symbol.for('SYMBOL_IS_MERGEABLE');

@@ -110,0 +174,0 @@ export const all = function deepmergeAll<T>(array: Array<Partial<T>>, optionsArgument?: Options): T

7

package.json
{
"name": "deepmerge-plus",
"version": "2.0.4",
"version": "2.1.0",
"description": "A library for deep (recursive) merging of Javascript objects",

@@ -11,2 +11,5 @@ "keywords": [

"merge",
"or",
"and",
"overwrite",
"recursive"

@@ -32,3 +35,3 @@ ],

"jsmd": "npx jsmd readme.md",
"tap-test": "tap test/*.js",
"tap-test": "tap test/*.tap.js",
"test": "npm run build && npm run tap-test && npm run jsmd"

@@ -35,0 +38,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc