Compare commits
3 Commits
Author | SHA1 | Date | |
---|---|---|---|
3a039c935f | |||
ac5b0b8b41 | |||
3f85c9cf7d |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.11.2",
|
||||
"version": "0.12.1",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
@ -14,8 +14,9 @@
|
||||
"types": "./dist/index.d.ts",
|
||||
"exports": {
|
||||
".": {
|
||||
"import": "./dist/utils.mjs",
|
||||
"require": "./dist/utils.cjs",
|
||||
"import": "./dist/utils.mjs"
|
||||
"types": "./dist/index.d.ts"
|
||||
}
|
||||
},
|
||||
"scripts": {
|
||||
|
@ -35,6 +35,27 @@ export function deepCopy<T>(value: T): T {
|
||||
return JSON.parse(JSON.stringify(value));
|
||||
}
|
||||
|
||||
/**
|
||||
* Merge any number of objects into the target
|
||||
*
|
||||
* @param target Destination of all properties
|
||||
* @param sources Objects that will copied into target
|
||||
* @return {any} The des
|
||||
*/
|
||||
export function deepMerge<T>(target: any, ...sources: any[]): T {
|
||||
for(const source of sources) {
|
||||
for(const key in source) {
|
||||
if(source[key] && typeof source[key] == 'object' && !Array.isArray(source[key])) {
|
||||
if(!target[key]) target[key] = {};
|
||||
deepMerge(target[key], source[key]);
|
||||
} else {
|
||||
target[key] = source[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
return target;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get/set a property of an object using dot notation
|
||||
*
|
||||
|
Reference in New Issue
Block a user