| 8 | * @returns {Array<Object>} Array with one superblock containing the specified block, or the original array if block is not provided. |
| 9 | */ |
| 10 | export function filterByBlock<T extends { blocks: { dashedName: string }[] }>( |
| 11 | superblocks: T[], |
| 12 | { block }: { block?: string } = {} |
| 13 | ): T[] { |
| 14 | if (!block) return superblocks; |
| 15 | |
| 16 | const remainingSuperblocks = superblocks |
| 17 | .map(superblock => ({ |
| 18 | ...superblock, |
| 19 | blocks: superblock.blocks.filter(({ dashedName }) => dashedName === block) |
| 20 | })) |
| 21 | .filter(superblock => superblock.blocks.length > 0); |
| 22 | |
| 23 | return remainingSuperblocks; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Filters the superblocks array to only include superblocks with the specified name(s). |