MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / removeUndefinedValues

Function removeUndefinedValues

cli/src/utils/codebuff-client.ts:20–37  ·  view source on GitHub ↗

* Recursively removes undefined values from an object to ensure clean JSON serialization. * This prevents issues with APIs that don't accept explicit undefined values.

(obj: T)

Source from the content-addressed store, hash-verified

18 * This prevents issues with APIs that don't accept explicit undefined values.
19 */
20function removeUndefinedValues<T>(obj: T): T {
21 if (obj === null || obj === undefined) {
22 return obj
23 }
24 if (Array.isArray(obj)) {
25 return obj.map(removeUndefinedValues) as T
26 }
27 if (typeof obj === 'object') {
28 const result: Record<string, unknown> = {}
29 for (const [key, value] of Object.entries(obj)) {
30 if (value !== undefined) {
31 result[key] = removeUndefinedValues(value)
32 }
33 }
34 return result as T
35 }
36 return obj
37}
38
39/**
40 * Reset the cached CodebuffClient instance.

Callers 1

getCodebuffClientFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected