Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
7b2d4ba119 | |||
1a4e732fd5 |
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@ztimson/utils",
|
||||
"version": "0.12.1",
|
||||
"version": "0.12.3",
|
||||
"description": "Utility library",
|
||||
"author": "Zak Timson",
|
||||
"license": "MIT",
|
||||
|
@ -43,16 +43,16 @@ export function deepCopy<T>(value: T): T {
|
||||
* @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])) {
|
||||
sources.forEach(s => {
|
||||
for(const key in s) {
|
||||
if(s[key] && typeof s[key] == 'object' && !Array.isArray(s[key])) {
|
||||
if(!target[key]) target[key] = {};
|
||||
deepMerge(target[key], source[key]);
|
||||
deepMerge(target[key], s[key]);
|
||||
} else {
|
||||
target[key] = source[key];
|
||||
}
|
||||
target[key] = s[key];
|
||||
}
|
||||
}
|
||||
});
|
||||
return target;
|
||||
}
|
||||
|
||||
|
@ -83,8 +83,8 @@ export class XHR {
|
||||
|
||||
const payload = await decode();
|
||||
if(resp.ok) return payload;
|
||||
const text = resp.statusText || (typeof payload == 'string' ? payload : null);
|
||||
throw (text ? new Error(text) : payload);
|
||||
throw Object.assign(new Error(typeof payload == 'string' ? payload : resp.statusText),
|
||||
typeof payload == 'object' ? payload : {});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user