@scayle/storefront-core
Version:
Collection of essential utilities to work with the Storefront API
15 lines (14 loc) • 617 B
JavaScript
import { getFirstAttributeValue } from "@scayle/storefront-api";
import { getAttributeValue } from "./attributeHelpers.mjs";
export function isImageType(type, image) {
const attributeValue = getFirstAttributeValue(image.attributes, "imageType");
if (attributeValue) {
return attributeValue.value === type;
}
return false;
}
export const getImageFromList = (images, imageType, imageView, fallback = true) => {
return images?.find(
(i) => getAttributeValue(i.attributes, "imageType") === imageType && getAttributeValue(i.attributes, "imageView") === imageView
) ?? (fallback ? images[0] : null);
};