* Calculate the depth of a JSON object
(obj: any)
| 107 | * Calculate the depth of a JSON object |
| 108 | */ |
| 109 | function getJsonDepth(obj: any): number { |
| 110 | if (obj === null || typeof obj !== 'object') return 0 |
| 111 | |
| 112 | if (Array.isArray(obj)) { |
| 113 | return obj.length > 0 ? 1 + Math.max(...obj.map(getJsonDepth)) : 1 |
| 114 | } |
| 115 | |
| 116 | const depths = Object.values(obj).map(getJsonDepth) |
| 117 | return depths.length > 0 ? 1 + Math.max(...depths) : 1 |
| 118 | } |
no outgoing calls
no test coverage detected