MCPcopy Create free account
hub / github.com/ScaleML/AgentSPEX / normalizeObject

Function normalizeObject

yaml-flow-editor/src/utils/workflowStepConverters.ts:44–57  ·  view source on GitHub ↗
(obj: T | null | undefined)

Source from the content-addressed store, hash-verified

42 * Recursively normalize an object, converting null/undefined leaves to empty strings.
43 */
44export function normalizeObject<T extends Record<string, unknown>>(obj: T | null | undefined): T {
45 if (!obj) return {} as T;
46 const result: Record<string, unknown> = {};
47 for (const [key, value] of Object.entries(obj)) {
48 if (value === null || value === undefined) {
49 result[key] = '';
50 } else if (typeof value === 'object' && !Array.isArray(value)) {
51 result[key] = normalizeObject(value as Record<string, unknown>);
52 } else {
53 result[key] = value;
54 }
55 }
56 return result as T;
57}
58
59/** Add fields to a record only if they have a defined value. */
60function addOptional(obj: Record<string, unknown>, fields: Record<string, unknown>): void {

Callers 2

processWorkflowStepFunction · 0.90
yamlToGraphFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected