import { CSSProperties } from 'react' ; const uppercasePattern = /([A-Z])/g ; const msPattern = /^ms-/ ; const hyphenateStyleName = ( name ) : string => name . replace ( uppercasePattern , '-$1' ) . toLowerCase ( ) . replace ( msPattern , '-ms-' ) ; const isValueEmpty = value => value == null || typeof value === 'boolean' || value === '' ; export const styleAttrStringify = ( style ) => { if ( ! style ) { return '' ; } const keys = Object . keys ( style ) as Array < keyof CSSProperties > ; const styleParts = [ ] ; for ( const key of keys ) { const value = style [ key ] ; if ( ! isValueEmpty ( value ) ) { styleParts . push ( `${ hyphenateStyleName ( key ) }:${ value };` ) ; } } return styleParts . join ( '' ) ; } ;