deepmerge-plus
Advanced tools
Comparing version 2.1.0 to 2.1.1
@@ -137,6 +137,11 @@ (function (global, factory) { | ||
})(deepmerge || (deepmerge = {})); | ||
var deepmerge_1 = deepmerge; | ||
var core = deepmerge; | ||
const deepmerge$1 = core; | ||
deepmerge$1.deepmerge = deepmerge$1; | ||
deepmerge$1.default = deepmerge$1; | ||
var deepmerge_1 = deepmerge$1; | ||
return deepmerge_1; | ||
}))); |
@@ -1,28 +0,6 @@ | ||
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 { | ||
clone?: boolean; | ||
arrayMerge?(destination: any[], source: any[], options?: Options): any[]; | ||
isMergeableObject?(value: any, isMergeableObject: (value) => boolean, optionsArgument?: Options, key?: any): void; | ||
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; | ||
} | ||
import * as _deepmerge from './core'; | ||
declare const deepmerge: typeof _deepmerge & { | ||
deepmerge: typeof _deepmerge; | ||
default: typeof _deepmerge; | ||
}; | ||
export = deepmerge; | ||
declare global { | ||
interface Window { | ||
deepmerge<T>(x: Partial<T>, y: Partial<T>, options?: deepmerge.Options): T; | ||
deepmerge<T1, T2>(x: T1, y: T2, options?: deepmerge.Options): T1 & T2; | ||
} | ||
} | ||
export {}; |
110
index.js
"use strict"; | ||
const isMergeableObject = require("is-mergeable-object"); | ||
function emptyTarget(val) { | ||
return Array.isArray(val) ? [] : {}; | ||
} | ||
function cloneUnlessOtherwiseSpecified(value, optionsArgument, tmp) { | ||
let clone = !optionsArgument || optionsArgument.clone !== false; | ||
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, tmp) { | ||
let ret; | ||
if (optionsArgument && optionsArgument.isMergeableObject) { | ||
ret = optionsArgument.isMergeableObject(value, isMergeableObject, optionsArgument, tmp); | ||
} | ||
if (ret === null || typeof ret === 'undefined') { | ||
if (value && (typeof value[deepmerge.SYMBOL_IS_MERGEABLE] == 'boolean')) { | ||
ret = value[deepmerge.SYMBOL_IS_MERGEABLE]; | ||
} | ||
else { | ||
ret = isMergeableObject(value); | ||
} | ||
} | ||
return ret; | ||
} | ||
function defaultArrayMerge(target, source, optionsArgument) { | ||
return target.concat(source).map(function (element, index, array) { | ||
return cloneUnlessOtherwiseSpecified(element, optionsArgument, { | ||
key: index, | ||
}); | ||
}); | ||
} | ||
function mergeObject(target, source, optionsArgument) { | ||
let destination = {}; | ||
if (_isMergeableObject(target, optionsArgument)) { | ||
Object.keys(target).forEach(function (key) { | ||
destination[key] = cloneUnlessOtherwiseSpecified(target[key], optionsArgument, { | ||
key, | ||
source, | ||
target, | ||
destination, | ||
}); | ||
}); | ||
} | ||
Object.keys(source).forEach(function (key) { | ||
if (!_isMergeableObject(source[key], optionsArgument, { | ||
key, | ||
source, | ||
target, | ||
}) || !target[key]) { | ||
destination[key] = cloneUnlessOtherwiseSpecified(source[key], optionsArgument, { | ||
key, | ||
source, | ||
target, | ||
}); | ||
} | ||
else { | ||
destination[key] = deepmerge(target[key], source[key], optionsArgument); | ||
} | ||
}); | ||
return destination; | ||
} | ||
function deepmerge(target, source, optionsArgument) { | ||
let sourceIsArray = Array.isArray(source); | ||
let targetIsArray = Array.isArray(target); | ||
let options = optionsArgument || { arrayMerge: defaultArrayMerge }; | ||
let sourceAndTargetTypesMatch = sourceIsArray === targetIsArray; | ||
if (!sourceAndTargetTypesMatch) { | ||
return cloneUnlessOtherwiseSpecified(source, optionsArgument, { | ||
target, | ||
source, | ||
}); | ||
} | ||
else if (sourceIsArray) { | ||
let arrayMerge = options.arrayMerge || defaultArrayMerge; | ||
return arrayMerge(target, source, optionsArgument); | ||
} | ||
else { | ||
return mergeObject(target, source, optionsArgument); | ||
} | ||
} | ||
(function (deepmerge) { | ||
deepmerge.isMergeable = isMergeableObject; | ||
deepmerge.SYMBOL_IS_MERGEABLE = Symbol.for('SYMBOL_IS_MERGEABLE'); | ||
deepmerge.all = function deepmergeAll(array, optionsArgument) { | ||
if (!Array.isArray(array)) { | ||
throw new Error('first argument should be an array'); | ||
} | ||
return array.reduce(function (prev, next) { | ||
return deepmerge(prev, next, optionsArgument); | ||
}, {}); | ||
}; | ||
})(deepmerge || (deepmerge = {})); | ||
const _deepmerge = require("./core"); | ||
const deepmerge = _deepmerge; | ||
deepmerge.deepmerge = deepmerge; | ||
deepmerge.default = deepmerge; | ||
module.exports = deepmerge; |
198
index.ts
@@ -1,191 +0,15 @@ | ||
import * as isMergeableObject from 'is-mergeable-object'; | ||
/** | ||
* Created by user on 2018/2/28/028. | ||
*/ | ||
function emptyTarget(val) | ||
{ | ||
return Array.isArray(val) ? [] : {} | ||
} | ||
import * as _deepmerge from './core'; | ||
function cloneUnlessOtherwiseSpecified(value, optionsArgument: deepmerge.Options, tmp?: deepmerge.ICache) | ||
{ | ||
let clone = !optionsArgument || optionsArgument.clone !== false; | ||
const deepmerge = _deepmerge as typeof _deepmerge & { | ||
deepmerge: typeof _deepmerge, | ||
default: typeof _deepmerge, | ||
}; | ||
let bool = clone && _isMergeableObject(value, optionsArgument, tmp); | ||
deepmerge.deepmerge = deepmerge; | ||
deepmerge.default = deepmerge; | ||
let ret = (bool) | ||
? deepmerge(emptyTarget(value), value, optionsArgument) | ||
: 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, tmp?: deepmerge.ICache) | ||
{ | ||
let ret; | ||
if (optionsArgument && optionsArgument.isMergeableObject) | ||
{ | ||
ret = optionsArgument.isMergeableObject(value, isMergeableObject, optionsArgument, tmp) | ||
} | ||
if (ret === null || typeof ret === 'undefined') | ||
{ | ||
if (value && (typeof value[deepmerge.SYMBOL_IS_MERGEABLE] == 'boolean')) | ||
{ | ||
ret = value[deepmerge.SYMBOL_IS_MERGEABLE]; | ||
} | ||
else | ||
{ | ||
ret = isMergeableObject(value); | ||
} | ||
} | ||
return ret | ||
} | ||
function defaultArrayMerge(target, source, optionsArgument: deepmerge.Options) | ||
{ | ||
return target.concat(source).map(function (element, index, array) | ||
{ | ||
return cloneUnlessOtherwiseSpecified(element, optionsArgument, { | ||
key: index, | ||
}) | ||
}) | ||
} | ||
function mergeObject(target, source, optionsArgument: deepmerge.Options) | ||
{ | ||
let destination = {}; | ||
if (_isMergeableObject(target, optionsArgument)) | ||
{ | ||
Object.keys(target).forEach(function (key) | ||
{ | ||
destination[key] = cloneUnlessOtherwiseSpecified(target[key], optionsArgument, { | ||
key, | ||
source, | ||
target, | ||
destination, | ||
}) | ||
}) | ||
} | ||
Object.keys(source).forEach(function (key) | ||
{ | ||
if (!_isMergeableObject(source[key], optionsArgument, { | ||
key, | ||
source, | ||
target, | ||
}) || !target[key]) | ||
{ | ||
destination[key] = cloneUnlessOtherwiseSpecified(source[key], optionsArgument, { | ||
key, | ||
source, | ||
target, | ||
}) | ||
} | ||
else | ||
{ | ||
destination[key] = deepmerge(target[key], source[key], optionsArgument) | ||
} | ||
}); | ||
return destination | ||
} | ||
function deepmerge<T>(x: Partial<T>, y: Partial<T>, options?: deepmerge.Options): T | ||
function deepmerge<T1, T2>(x: T1, y: T2, options?: deepmerge.Options): T1 & T2 | ||
function deepmerge(target, source, optionsArgument) | ||
{ | ||
let sourceIsArray = Array.isArray(source); | ||
let targetIsArray = Array.isArray(target); | ||
let options = optionsArgument || { arrayMerge: defaultArrayMerge }; | ||
let sourceAndTargetTypesMatch = sourceIsArray === targetIsArray; | ||
if (!sourceAndTargetTypesMatch) | ||
{ | ||
return cloneUnlessOtherwiseSpecified(source, optionsArgument, { | ||
target, | ||
source, | ||
}); | ||
} | ||
else if (sourceIsArray) | ||
{ | ||
let arrayMerge = options.arrayMerge || defaultArrayMerge; | ||
return arrayMerge(target, source, optionsArgument); | ||
} | ||
else | ||
{ | ||
return mergeObject(target, source, optionsArgument); | ||
} | ||
} | ||
namespace deepmerge | ||
{ | ||
export interface ICache | ||
{ | ||
key? | ||
source? | ||
target? | ||
destination? | ||
} | ||
export interface Options | ||
{ | ||
clone?: boolean; | ||
arrayMerge?(destination: any[], source: any[], options?: Options): any[]; | ||
isMergeableObject?(value, isMergeableObject: (value) => boolean, optionsArgument?: Options, key?): void; | ||
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'); | ||
export const all = function deepmergeAll<T>(array: Array<Partial<T>>, optionsArgument?: Options): T | ||
{ | ||
if (!Array.isArray(array)) | ||
{ | ||
throw new Error('first argument should be an array') | ||
} | ||
// @ts-ignore | ||
return array.reduce(function (prev, next) | ||
{ | ||
return deepmerge(prev, next, optionsArgument) | ||
}, {}) | ||
} | ||
} | ||
export = deepmerge | ||
declare global | ||
{ | ||
interface Window | ||
{ | ||
deepmerge<T>(x: Partial<T>, y: Partial<T>, options?: deepmerge.Options): T; | ||
deepmerge<T1, T2>(x: T1, y: T2, options?: deepmerge.Options): T1 & T2; | ||
} | ||
} | ||
export = deepmerge; |
{ | ||
"name": "deepmerge-plus", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "A library for deep (recursive) merging of Javascript objects", | ||
"keywords": [ | ||
"and", | ||
"clone", | ||
@@ -12,3 +13,2 @@ "copy", | ||
"or", | ||
"and", | ||
"overwrite", | ||
@@ -21,26 +21,27 @@ "recursive" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/bluelovers/deepmerge.git" | ||
}, | ||
"license": "MIT", | ||
"author": "Nick Fisher", | ||
"main": "dist/umd.js", | ||
"module": "dist/es.js", | ||
"module": "index.js", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/bluelovers/deepmerge.git" | ||
}, | ||
"scripts": { | ||
"build": "npx rollup -c", | ||
"jsmd": "npx jsmd readme.md", | ||
"mocha-test": "npx mocha --require ts-node/register \"!(node_modules)/**/*.{test,spec}.{ts,tsx}\"", | ||
"tap-test": "tap test/*.tap.js", | ||
"test": "npm run build && npm run tap-test && npm run jsmd" | ||
"test": "npm run build && npm run mocha-test && npm run jsmd" | ||
}, | ||
"dependencies": {}, | ||
"dependencies": { | ||
"is-mergeable-object": "1.1.0" | ||
}, | ||
"devDependencies": { | ||
"is-mergeable-object": "1.1.0", | ||
"moment": "^2.20.1", | ||
"rollup-plugin-commonjs": "8.2.1", | ||
"rollup-plugin-node-resolve": "3.0.0", | ||
"tap": "~7.1.2" | ||
"rollup-plugin-node-resolve": "3.0.0" | ||
}, | ||
@@ -47,0 +48,0 @@ "engines": { |
@@ -15,4 +15,4 @@ import resolve from 'rollup-plugin-node-resolve' | ||
{ file: pkg.main, format: 'umd' }, | ||
{ file: pkg.module, format: 'es' }, | ||
//{ file: pkg.module, format: 'es' }, | ||
], | ||
} |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
34435
3
15
627
1
1
+ Addedis-mergeable-object@1.1.0
+ Addedis-mergeable-object@1.1.0(transitive)