data_escape-html.js

/**
 * @module escapeHtml
 * @description Escapes html special characters in the specified string.
 *
 * @since 1.0.0
 *
 * @param {string} unsafe The string to be escaped.
 *
 * @return {string} Returns a string with all html special characters escaped.
 *
 * @example
 * import { escapeHtml } from "@gravityforms/utils";
 *
 * function Example() {
 *   const str = 'my <strong>bold</strong> text will be escaped'
 * 	 const escapedString = escapeHtml( str );
 * }
 *
 */
export default function( unsafe = '' ) {
	return String( unsafe )
		.replace( /&/g, '&amp;' )
		.replace( /</g, '&lt;' )
		.replace( />/g, '&gt;' )
		.replace( /"/g, '&quot;' )
		.replace( /'/g, '&#039;' );
}