@ecomplus/utils
Version:
JS utility functions to E-Com Plus (not only) related apps
27 lines • 1.47 kB
TypeScript
export default img;
/**
* @method
* @memberof ecomUtils
* @name img
* @description Returns img object (with url and alt) from product body or pictures list.
* @param {Object.<string, *>|Array} product - Product body object or list of picture objects
* @param {string} [pictureId] - ObjectID of preferred picture to find in the list
* @param {string} [size=$ecomConfig.get('default_img_size')] - Preferred image size
* (generally `normal`) to find on picture object
* @returns {{ url: string; size?: string; alt?: string; }|undefined}
*
* @example
* const product = { 'pictures': [ { 'small': { 'url': 'https://ecom.com/imgs/100px/64gb.jpg'}, 'big': { 'url': 'https://ecom.com/imgs/700px/64gb.jpg' }, '_id': '694890155127368133600000' }, { 'small': { 'url': 'https://ecom.com/imgs/100px/e-5-64gb.jpg' }, 'big': { 'url': 'https://ecom.com/imgs/700px/e-5-64gb.jpg' }, '_id': '694890155127368133600001' }, { 'small': { 'url': 'https://ecom.com/imgs/100px/5-64gb.jpg' }, 'big': { 'url': 'https://ecom.com/imgs/700px/5-64gb.jpg' }, '_id': '694890155127368133600002' } ], 'name': 'Smartphone Xiaomi' }
* const id = '694890155127368133600001'
* const size = 'big'
* ecomUtils.img(product, id, size)
* // => {url: 'https://ecom.com/imgs/700px/e-5-64gb.jpg'}
*/
declare function img(product: {
[x: string]: any;
} | any[], pictureId?: string, size?: string): {
url: string;
size?: string;
alt?: string;
} | undefined;
//# sourceMappingURL=img.d.ts.map