import type { IconSizeOptions , LineHeightOptions , FontSizeOptions , IconSize , LineHeight , FontSize , } from '@twilio-paste/style-props' ; export const getInitialsFromName = ( fullname ) : string => { return fullname . split ( ' ' ) . map ( ( name ) => name . slice ( 0 , 1 ) ) . reduce ( ( previous , currentInitial , index , initials ) => { if ( index === 0 || index === initials . length - 1 ) { return `${ previous }${ currentInitial }` ; } return previous ; } , '' ) ; } ; export const getCorrespondingLineHeightFromSizeToken = ( size ) : LineHeightOptions => { if ( typeof size === 'string' && size . includes ( 'sizeIcon' ) ) { return size . replace ( 'sizeIcon' , 'lineHeight' ) as LineHeightOptions ; } throw new Error ( '[Avatar]: size must be of type IconSizeOptions.' ) ; } ; export const getCorrespondingFontSizeFromSizeToken = ( size ) : FontSizeOptions => { if ( typeof size === 'string' && size . includes ( 'sizeIcon' ) ) { switch ( size ) { case 'sizeIcon10' : case 'sizeIcon20' : case 'sizeIcon30' : case 'sizeIcon40' : case 'sizeIcon50' : case 'sizeIcon60' : default : return 'fontSize10' ; case 'sizeIcon70' : return 'fontSize20' ; case 'sizeIcon80' : return 'fontSize30' ; case 'sizeIcon90' : return 'fontSize40' ; case 'sizeIcon100' : return 'fontSize60' ; case 'sizeIcon110' : return 'fontSize70' ; } } throw new Error ( '[Avatar]: size must be of type IconSizeOptions.' ) ; } ; /**
 * Uses IconSizeOptions to return a smaller IconSize
 */ export const getCorrespondingIconSizeFromSizeToken = ( size ) : IconSizeOptions => { if ( typeof size === 'string' && size . includes ( 'sizeIcon' ) ) { switch ( size ) { case 'sizeIcon10' : case 'sizeIcon20' : case 'sizeIcon30' : case 'sizeIcon40' : default : return 'sizeIcon10' ; case 'sizeIcon50' : case 'sizeIcon60' : return 'sizeIcon20' ; case 'sizeIcon70' : return 'sizeIcon30' ; case 'sizeIcon80' : return 'sizeIcon40' ; case 'sizeIcon90' : return 'sizeIcon50' ; case 'sizeIcon100' : return 'sizeIcon70' ; case 'sizeIcon110' : return 'sizeIcon80' ; } } throw new Error ( '[Avatar]: size must be of type IconSizeOptions.' ) ; } ; export const getComputedTokenNames = ( size ) : { lineHeight : LineHeight ; fontSize : FontSize ; iconSize : IconSize ; } => { if ( typeof size === 'string' ) { return { lineHeight : getCorrespondingLineHeightFromSizeToken ( size ) , fontSize : getCorrespondingFontSizeFromSizeToken ( size ) , iconSize : getCorrespondingIconSizeFromSizeToken ( size ) , } ; } if ( Array . isArray ( size ) ) { return { lineHeight : size . map ( ( s ) => { if ( s != null ) { return getCorrespondingLineHeightFromSizeToken ( s ) ; } return null ; } ) , fontSize : size . map ( ( s ) => { if ( s != null ) { return getCorrespondingFontSizeFromSizeToken ( s ) ; } return null ; } ) , iconSize : size . map ( ( s ) => { if ( s != null ) { return getCorrespondingIconSizeFromSizeToken ( s ) ; } return null ; } ) , } ; } throw new Error ( '[Avatar]: size must be a string or an array' ) ; } ;