export function prepareVariantsWithOptions ( variants ) { return variants . map ( ( variant ) => { const optionsDictionary = variant . selectedOptions ?. reduce ( ( options , option ) => { options [ `${ option ?. name ?. toLowerCase ( ) }` ] = option ?. value ; return options ; } , { } ) ; return { ... optionsDictionary , ... variant , } ; } ) as any [ ] ; } export const getPrice = ( price , currency ) => Intl . NumberFormat ( undefined , { currency , minimumFractionDigits : 2 , style : 'currency' , } ) . format ( parseFloat ( price ? price : '0' ) ) ; export function prepareVariantsImages ( variants , optionKey ) { const imageDictionary = variants . reduce < Record < string , ShopifyBuy . Image > > ( ( images , variant ) => { if ( variant [ optionKey ] ) { images [ variant [ optionKey ] ] = variant . image ; } return images ; } , { } ) ; const images = Object . keys ( imageDictionary ) . map ( ( key ) => { return { [ optionKey ] : key , src : imageDictionary [ key ] , } ; } ) ; return images ; }