dom_has-class-from-array.js

/**
 * @module hasClassFromArray
 * @description Compares an HTMLElement's classList against an array of strings to see if any match.
 *
 * @since 1.0.0
 *
 * @param {HTMLElement} el     The element to check against.
 * @param {Array}       arr    The array of classes as strings to test against.
 * @param {string}      prefix Optional prefix string applied to all test strings.
 * @param {string}      suffix Optional suffix string.
 *
 * @return {boolean} Returns true if a matching css selector is found.
 *
 * @example
 * import { hasClassFromArray, getNodes } from "@gravityforms/utils";
 *
 * function Example() {
 *   const example = getNodes( '.some-custom-selector', false, document.body, true )[ 0 ];
 *   if( hasClassFromArray( example, [ 'one-class-string', 'another-class-string' ], 'gform-' ) ) {
 *      //do something
 *   }
 * }
 *
 */
export default function hasClassFromArray( el, arr = [], prefix = '', suffix = '' ) {
	return arr.some( ( c ) =>
		el.classList.contains( `${ prefix }${ c }${ suffix }` )
	);
}