(ex)
| 160 | */ |
| 161 | |
| 162 | export function standardizeExample(ex) { |
| 163 | if (typeof ex === 'object' && !Array.isArray(ex)) { |
| 164 | if (ex.value !== undefined) { |
| 165 | // Case 1: Single object with 'value' property |
| 166 | return { Example: { ...ex } }; |
| 167 | } |
| 168 | // Case 2: Object where each key is an object with a 'value' property |
| 169 | const filteredEntries = Object.entries(ex).filter(([_, obj]) => obj.value !== undefined); // eslint-disable-line |
| 170 | // If no valid entries found, return JSON.stringify of the input |
| 171 | if (filteredEntries.length === 0) { |
| 172 | return undefined; |
| 173 | } |
| 174 | return Object.fromEntries(filteredEntries); |
| 175 | } if (Array.isArray(ex)) { |
| 176 | // Case 3: Array of primitive values |
| 177 | return ex.reduce((acc, value, index) => { |
| 178 | acc[`Example${index + 1}`] = { value }; |
| 179 | return acc; |
| 180 | }, {}); |
| 181 | } |
| 182 | // Case 4: Single primitive value |
| 183 | return ex ? { Example: { value: ex } } : undefined; |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * Normalize example object in the following format (List of object which is used to render example links and fill the input boxes) |
no test coverage detected
searching dependent graphs…