MCPcopy Create free account
hub / github.com/freeCodeCamp/freeCodeCamp / transformSuperBlock

Function transformSuperBlock

curriculum/src/build-superblock.ts:475–527  ·  view source on GitHub ↗
(
  superblockData: {
    blocks?: string[];
    chapters?: Chapter[];
  },
  { showComingSoon } = { showComingSoon: false }
)

Source from the content-addressed store, hash-verified

473 * @returns {object[]} Array of block objects with dashedName, chapter, and module properties
474 */
475export function transformSuperBlock(
476 superblockData: {
477 blocks?: string[];
478 chapters?: Chapter[];
479 },
480 { showComingSoon } = { showComingSoon: false }
481) {
482 let blocks: BlockInfo[] = [];
483 const shouldAllowEmptyBlocks =
484 !showComingSoon &&
485 superblockData.chapters?.every(chapter => chapter.comingSoon);
486
487 // Handle simple blocks array format
488 if (superblockData.blocks) {
489 blocks = superblockData.blocks.map(dashedName => ({
490 dashedName
491 }));
492 }
493 // Handle nested chapters/modules/blocks format
494 else if (superblockData.chapters) {
495 for (const chapter of superblockData.chapters) {
496 if (chapter.comingSoon && !showComingSoon) {
497 continue;
498 }
499
500 if (chapter.modules) {
501 for (const module of chapter.modules) {
502 if (module.comingSoon && !showComingSoon) {
503 continue;
504 }
505
506 if (module.blocks) {
507 for (const block of module.blocks) {
508 blocks.push({
509 dashedName: block,
510 chapter: chapter.dashedName,
511 module: module.dashedName
512 });
513 }
514 }
515 }
516 }
517 }
518 }
519
520 if (isEmpty(blocks) && !shouldAllowEmptyBlocks) {
521 throw Error(`No blocks found in superblock data`);
522 }
523
524 const blockNames = blocks.map(block => block.dashedName);
525 log(`Found ${blocks.length} blocks: ${blockNames.join(', ')}`);
526 return blocks;
527}

Callers 3

getBlockMetadataFunction · 0.85
addSuperblockStructureFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected