fix(reactflowUtils.ts): fix typo in function name from scapedJSONStringfy to scapeJSONStringify
feat(reactflowUtils.ts): add customStringify function to handle special cases when stringifying JSON objects
This commit is contained in:
parent
11a2d12c6b
commit
712dcf3535
1 changed files with 27 additions and 1 deletions
|
|
@ -332,9 +332,10 @@ export function getConnectedNodes(
|
|||
}
|
||||
|
||||
export function scapedJSONStringfy(json: object): string {
|
||||
return JSON.stringify(json).replace(/"/g, '\\"');
|
||||
return customStringify(json).replace(/"/g, '\\"');
|
||||
}
|
||||
export function scapeJSONParse(json: string): any {
|
||||
console.log(json);
|
||||
return JSON.parse(json.replace(/\\"/g, '"'));
|
||||
}
|
||||
|
||||
|
|
@ -348,3 +349,28 @@ export function checkOldEdgesHandles(edges: Edge[]): boolean {
|
|||
!edge.targetHandle.includes("{")
|
||||
);
|
||||
}
|
||||
|
||||
function customStringify(obj: any) {
|
||||
console.log(obj);
|
||||
if (typeof obj === "undefined") {
|
||||
return "undefined";
|
||||
}
|
||||
|
||||
if (obj === null || typeof obj !== "object") {
|
||||
if (obj instanceof Date) {
|
||||
return `"${obj.toISOString()}"`;
|
||||
}
|
||||
return JSON.stringify(obj);
|
||||
}
|
||||
|
||||
if (Array.isArray(obj)) {
|
||||
const arrayItems = obj.map((item) => customStringify(item)).join(",");
|
||||
return `[${arrayItems}]`;
|
||||
}
|
||||
|
||||
const keys = Object.keys(obj).sort();
|
||||
const keyValuePairs = keys.map(
|
||||
(key) => `"${key}":${customStringify(obj[key])}`
|
||||
);
|
||||
return `{${keyValuePairs.join(",")}}`;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue