import { isH5WebComplex , formatScalarComplex , isScalarShape , isNumericType , DTypeClass , } from '@h5web/shared' ; import type { ComplexArray , H5WebComplex , Shape , DType } from '@h5web/shared' ; export function renderShape ( shape ) { if ( shape === null ) { return 'None' ; } if ( isScalarShape ( shape ) ) { return 'Scalar' ; } return shape . length === 1 ? shape . toString ( ) : `${ shape . join ( ' x ' ) } = ${ shape . reduce ( ( acc , value ) => acc * value ) }` ; } export function renderType ( type ) { if ( isNumericType ( type ) ) { const { endianness , size } = type ; return `${ type . class }, ${ size }-bit${ endianness ? `, ${ endianness }` : '' }` ; } if ( type . class === DTypeClass . String ) { const { length , charSet } = type ; return `${ charSet ? `${ charSet } string` : 'String' }${ length !== undefined ? `, ${ length } characters` : '' }` ; } return type . class ; } export function renderComplex ( complex ) { if ( isH5WebComplex ( complex ) ) { return formatScalarComplex ( complex ) ; } return `[ ${ complex . map ( ( c ) => renderComplex ( c ) ) . join ( ', ' ) } ]` ; }