Better debugging experience with user profile
This commit is contained in:
@ -1,9 +1,38 @@
|
||||
import { assert } from "tsafe/assert";
|
||||
import { is } from "tsafe/is";
|
||||
|
||||
function deepClone<T>(src: T): T {
|
||||
const generateId = (() => {
|
||||
const prefix = "xIfKdLsIIdJdLdOeJqePe";
|
||||
|
||||
let counter = 0;
|
||||
|
||||
return () => `${prefix}${counter++}`;
|
||||
})();
|
||||
|
||||
const map = new Map<string, Function>();
|
||||
|
||||
return JSON.parse(
|
||||
JSON.stringify(src, (...[, value]) => {
|
||||
if (typeof value === "function") {
|
||||
const id = generateId();
|
||||
|
||||
map.set(id, value);
|
||||
|
||||
return id;
|
||||
}
|
||||
|
||||
return value;
|
||||
}),
|
||||
(...[, value]) => (typeof value === "string" && map.has(value) ? map.get(value) : value),
|
||||
);
|
||||
}
|
||||
|
||||
//Warning: Be mindful that because of array this is not idempotent.
|
||||
export function deepAssign(params: { target: Record<string, unknown>; source: Record<string, unknown> }) {
|
||||
const { target, source } = params;
|
||||
const { target } = params;
|
||||
|
||||
const source = deepClone(params.source);
|
||||
|
||||
Object.keys(source).forEach(key => {
|
||||
var dereferencedSource = source[key];
|
||||
|
Reference in New Issue
Block a user