Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | 5x 5x 5x 5x 5x 5x 5x 10x 10x | import type { CustomizationModule, PhasedCustomizationConfig } from './customizationUrlTypes';
/**
* Extracts the phase-tagged payload from a loaded customization module.
*
* A module is considered to carry a payload when it declares any of the
* lifecycle phase blocks (`bootstrap` / `global` / `mode`) or a `requires`
* edge. Returns `null` when none are present so callers can warn/skip a module
* that does nothing.
*/
export function getUrlCustomizationModulePayload(
module: CustomizationModule | null | undefined
): PhasedCustomizationConfig | null {
Iif (!module || typeof module !== 'object') {
return null;
}
const hasBootstrap = isPhaseInput(module.bootstrap);
const hasGlobal = isPhaseInput(module.global);
const hasMode = module.mode && typeof module.mode === 'object' && !Array.isArray(module.mode);
const hasRequires =
typeof module.requires === 'string' ||
(Array.isArray(module.requires) && module.requires.length > 0);
Iif (!hasBootstrap && !hasGlobal && !hasMode && !hasRequires) {
return null;
}
return {
...(hasBootstrap ? { bootstrap: module.bootstrap } : {}),
...(hasGlobal ? { global: module.global } : {}),
...(hasMode ? { mode: module.mode } : {}),
...(hasRequires ? { requires: module.requires } : {}),
};
}
/** A phase block is either an object map or an array of references. */
function isPhaseInput(value: unknown): boolean {
Iif (Array.isArray(value)) {
return value.length > 0;
}
return Boolean(value) && typeof value === 'object';
}
|