All files util.ts

9.09% Statements 2/22
100% Branches 0/0
0% Functions 0/2
9.09% Lines 2/22

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          1x                           1x                                      
/**
 * Check if a value is an ES module.
 * @param obj - The object to check
 * @returns True if the object is an ES module
 */
export function isESModule(obj: unknown): obj is Record<string | symbol, any> {
    if (!obj || typeof obj !== 'object') return false;
    const module = obj as Record<string | symbol, any>;
    return (
        Boolean(module.__esModule) || module[Symbol.toStringTag] === 'Module'
    );
}
 
/**
 * Resolve a component from potentially wrapped module format.
 * Handles ES modules with default exports.
 * @param component - The component to resolve
 * @returns The resolved component
 */
export function resolveComponent(component: unknown): unknown {
    if (!component) return null;
 
    if (isESModule(component)) {
        return component.default || component;
    }
 
    if (
        component &&
        typeof component === 'object' &&
        !Array.isArray(component) &&
        'default' in component &&
        Object.keys(component).length === 1
    ) {
        return (component as { default: unknown }).default;
    }
 
    return component;
}