UNPKG

@open-tender/utils

Version:

A library of utils for use with Open Tender applications that utilize our cloud-based Order API.

39 lines (38 loc) 1.15 kB
import { range, sample } from './helpers'; export const selectItemsWithEqualDistribution = (min, max, cellsCount, coverage) => { const coverageCount = cellsCount / (coverage === 'whole' ? 1 : 2); const itemsRange = range(min, max + 1); const step = Math.ceil(itemsRange.length / coverageCount); const selectedItems = []; for (let i = 0; i < coverageCount; i++) { const startIndex = i * step; const endIndex = (i + 1) * step; selectedItems.push(sample(itemsRange.slice(startIndex, endIndex))); } return selectedItems; }; export const getCoverageMinMaxMap = (cellsCount) => ({ '1st-half': { min: cellsCount / 2, max: cellsCount - 1 }, '2nd-half': { min: 0, max: cellsCount / 2 - 1 }, whole: { min: 0, max: cellsCount - 1 } }); export const toppingAlignItems = { 0: 'flex-start', 1: 'center', 2: 'flex-end', 3: 'flex-end', 4: 'flex-start' }; export const toppingJustifyContent = { 0: 'flex-end', 1: 'center', 2: 'flex-start', 3: 'flex-end', 4: 'flex-start' }; export const squareSizeMap = { extra: 8, light: 4, normal: 6, triple: 10 };