react-bootstrap-table2/packages/react-bootstrap-table2/test/test-helpers/productGenerator.js
Daniil Khanin 94d21fee77 fix #66
2017-10-10 01:52:32 -05:00

22 lines
603 B
JavaScript

/**
* products generator for stories
*
* @param {Number} quantity - quantity of products
* @param {Function} callback - callback func which is similiar to 'mapFunction'
* aims to customize product format
*
* @return {Array} - products array
*/
export const productsGenerator = (quantity = 5, callback) => {
if (callback) return Array.from({ length: quantity }, callback);
// if no given callback, retrun default product format.
return (
Array.from({ length: quantity }, (value, index) => ({
id: index,
name: `Item name ${index}`,
price: 2100 + index
}))
);
};