( info: JSONValueType, path: JSONHeroPath )
| 97 | } |
| 98 | |
| 99 | function generateChildren( |
| 100 | info: JSONValueType, |
| 101 | path: JSONHeroPath |
| 102 | ): Array<JsonTreeViewNode> | undefined { |
| 103 | if (info.name === "array") { |
| 104 | return info.value.map((item, index) => { |
| 105 | const itemInfo = inferType(item); |
| 106 | const itemPath = path.child(index.toString()); |
| 107 | |
| 108 | return { |
| 109 | id: itemPath.toString(), |
| 110 | name: index.toString(), |
| 111 | title: index.toString(), |
| 112 | longTitle: `Index ${index.toString()}`, |
| 113 | subtitle: formatValue(itemInfo), |
| 114 | icon: iconForType(itemInfo), |
| 115 | children: generateChildren(itemInfo, itemPath), |
| 116 | }; |
| 117 | }); |
| 118 | } |
| 119 | |
| 120 | if (info.name === "object") { |
| 121 | return Object.entries(info.value).map(([key, value]) => { |
| 122 | const cleanKey = key.replace(/\./g, "\\."); |
| 123 | const itemInfo = inferType(value); |
| 124 | const itemPath = path.child(cleanKey); |
| 125 | return { |
| 126 | id: itemPath.toString(), |
| 127 | name: key, |
| 128 | title: key, |
| 129 | subtitle: formatValue(itemInfo), |
| 130 | icon: iconForType(itemInfo), |
| 131 | children: generateChildren(itemInfo, itemPath), |
| 132 | }; |
| 133 | }); |
| 134 | } |
| 135 | } |
no test coverage detected