Compare commits

..

2 Commits

Author SHA1 Message Date
ac5b0b8b41 Added merge object
All checks were successful
Build / Build NPM Project (push) Successful in 21s
Build / Tag Version (push) Successful in 5s
2024-06-18 19:31:08 -04:00
3f85c9cf7d Updated package.json to include types file
All checks were successful
Build / Build NPM Project (push) Successful in 41s
Build / Tag Version (push) Successful in 5s
2024-06-17 10:23:48 -04:00
2 changed files with 24 additions and 2 deletions

View File

@ -1,6 +1,6 @@
{
"name": "@ztimson/utils",
"version": "0.11.2",
"version": "0.12.0",
"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": {

View File

@ -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
*/
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
*