export const sanitizeHtmlAttribute = ( value ) => {
if ( null === value || undefined === value ) {
return '';
}
let stringValue = '';
if ( 'object' === typeof value ) {
try {
stringValue = JSON.stringify( value );
} catch ( e ) {
return '';
}
} else {
stringValue = String( value );
}
// Replace characters like &, <, >, " with their HTML entity equivalents
return stringValue
.replace( /&/g, '&' )
.replace( /</g, '<' )
.replace( />/g, '>' )
.replace( /"/g, '"' )
.replace( /'/g, ''' );
};