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