File "utils.js"

Full Path: /home/vantageo/public_html/cache/cache/.wp-cli/wp-content/plugins/woocommerce/packages/woocommerce-blocks/assets/js/base/components/cart-checkout/payment-method-icons/utils.js
File size: 652 bytes
MIME-type: text/plain
Charset: utf-8

/**
 * For an array of icons, normalize into objects and remove duplicates.
 *
 * @param {Array} icons Array of icon objects or string based ids.
 */
export const normalizeIconConfig = ( icons ) => {
	const normalizedIcons = {};

	icons.forEach( ( raw ) => {
		let icon = {};

		if ( typeof raw === 'string' ) {
			icon = {
				id: raw,
				alt: raw,
				src: null,
			};
		}

		if ( typeof raw === 'object' ) {
			icon = {
				id: raw.id || '',
				alt: raw.alt || '',
				src: raw.src || null,
			};
		}

		if ( icon.id && ! normalizedIcons[ icon.id ] ) {
			normalizedIcons[ icon.id ] = icon;
		}
	} );

	return Object.values( normalizedIcons );
};