@scayle/storefront-core
Version:
Collection of essential utilities to work with the Storefront API
23 lines (22 loc) • 1.02 kB
TypeScript
import type { ProductImageType } from '../constants/product';
import type { Product, ProductImage } from '../index';
/**
* Checks if a product image matches a specific image type.
*
* @param type The image type to check against.
* @param image The product image.
*
* @returns True if the image matches the type, false otherwise.
*/
export declare function isImageType(type: ProductImageType, image: ProductImage): boolean;
/**
* Retrieves an image from a list of product images based on image type and view.
*
* @param images The list of product images.
* @param imageType The desired image type.
* @param imageView The desired image view.
* @param fallback Whether to return the first image if no match is found. Defaults to true.
*
* @returns The matching product image, the first image if fallback is true and no match is found, or null otherwise.
*/
export declare const getImageFromList: (images: Product["images"], imageType: string, imageView: string, fallback?: boolean) => ProductImage | null;