(value: unknown, insideArray: boolean)
| 45 | } |
| 46 | |
| 47 | function 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 | } |
no test coverage detected