File "sanitizeHtmlAttribute.js"

Full path: /home/webcknlt/admissiontell.com/wp-content/plugins/generateblocks/src/utils/sanitizeHtmlAttribute.js
File size: 548 B (548 B bytes)
MIME-type: text/plain
Charset: utf-8

Download   Open   Edit   Advanced Editor &nnbsp; Back

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, '&amp;' )
		.replace( /</g, '&lt;' )
		.replace( />/g, '&gt;' )
		.replace( /"/g, '&quot;' )
		.replace( /'/g, '&#039;' );
};