( info: JSONValueType, path: JSONHeroPath )
| 19 | } |
| 20 | |
| 21 | function generateChildren( |
| 22 | info: JSONValueType, |
| 23 | path: JSONHeroPath |
| 24 | ): Array<ColumnViewNode> { |
| 25 | if (info.name === "array" && info.value) { |
| 26 | return info.value.map((value, index) => { |
| 27 | const childPath = path.child(index.toString()); |
| 28 | const childInfo = inferType(value); |
| 29 | const children = generateChildren(childInfo, childPath); |
| 30 | |
| 31 | return { |
| 32 | id: childPath.toString(), |
| 33 | name: index.toString(), |
| 34 | title: index.toString(), |
| 35 | longTitle: `Index ${index.toString()}`, |
| 36 | subtitle: formatValue(childInfo), |
| 37 | icon: iconForType(childInfo), |
| 38 | children, |
| 39 | }; |
| 40 | }); |
| 41 | } |
| 42 | |
| 43 | if (info.name === "object" && info.value) { |
| 44 | return Object.entries(info.value).map(([key, value]) => { |
| 45 | const cleanKey = key.replace(/\./g, "\\."); |
| 46 | const childPath = path.child(cleanKey); |
| 47 | const childInfo = inferType(value); |
| 48 | const children = generateChildren(childInfo, childPath); |
| 49 | |
| 50 | return { |
| 51 | id: childPath.toString(), |
| 52 | name: key, |
| 53 | title: key, |
| 54 | subtitle: formatValue(childInfo), |
| 55 | icon: iconForType(childInfo), |
| 56 | children, |
| 57 | }; |
| 58 | }); |
| 59 | } |
| 60 | |
| 61 | return []; |
| 62 | } |
| 63 | |
| 64 | export function generateNodesToPath( |
| 65 | json: unknown, |
no test coverage detected