MCPcopy Index your code
hub / github.com/microsoft/TypeChat / objectToString

Function objectToString

typescript/src/ts/program.ts:108–131  ·  view source on GitHub ↗
(obj: Record<string, unknown>)

Source from the content-addressed store, hash-verified

106 }
107
108 function objectToString(obj: Record<string, unknown>) {
109 if (obj.hasOwnProperty("@ref")) {
110 const index = obj["@ref"];
111 if (typeof index === "number" && index < currentStep && Object.keys(obj).length === 1) {
112 return `step${index + 1}`;
113 }
114 }
115 else if (obj.hasOwnProperty("@func")) {
116 const func = obj["@func"];
117 const hasArgs = obj.hasOwnProperty("@args");
118 const args = hasArgs ? obj["@args"] : [];
119 if (typeof func === "string" && (Array.isArray(args)) && Object.keys(obj).length === (hasArgs ? 2 : 1)) {
120 return `api.${func}(${arrayToString(args)})`;
121 }
122 }
123 else if (Array.isArray(obj)) {
124 return `[${arrayToString(obj)}]`;
125 }
126 else {
127 return `{ ${Object.keys(obj).map(key => `${JSON.stringify(key)}: ${exprToString(obj[key])}`).join(", ")} }`;
128 }
129 hasError = true;
130 return "";
131 }
132
133 function arrayToString(array: unknown[]) {
134 return array.map(exprToString).join(", ");

Callers 1

exprToStringFunction · 0.85

Calls 2

arrayToStringFunction · 0.85
exprToStringFunction · 0.85

Tested by

no test coverage detected