MCPcopy Create free account
hub / github.com/ecomfe/tempad-dev / pruneValue

Function pruneValue

packages/extension/utils/object.ts:47–71  ·  view source on GitHub ↗
(value: unknown, insideArray: boolean)

Source from the content-addressed store, hash-verified

45}
46
47function pruneValue(value: unknown, insideArray: boolean): unknown {
48 if (!isPlainObject(value) && !Array.isArray(value)) {
49 return value
50 }
51
52 if (Array.isArray(value)) {
53 return value.map((item) => pruneValue(item, true))
54 }
55
56 const result: Record<string, unknown> = {}
57 for (const [key, item] of Object.entries(value)) {
58 if (item === undefined) continue
59
60 const pruned = pruneValue(item, false)
61 if (pruned === undefined) continue
62
63 result[key] = pruned
64 }
65
66 if (Object.keys(result).length === 0) {
67 return insideArray ? {} : undefined
68 }
69
70 return result
71}

Callers 1

pruneFunction · 0.85

Calls 1

isPlainObjectFunction · 0.85

Tested by

no test coverage detected