UNPKG

@scayle/storefront-core

Version:

Collection of essential utilities to work with the Storefront API

24 lines (23 loc) 642 B
export const getRowByIndex = (index, options = { columns: 2, page: 1, perPage: 24 }) => { const { columns, page, perPage } = options; const adjustedIndex = index + (page - 1) * perPage; return Math.floor(adjustedIndex / columns); }; export const getDisruptorsForRow = (row, disruptors) => { return disruptors.reduce((c, v, _) => { if (v.insert_in_row === row.toString()) { c.push(v); } return c; }, []); }; export const isFirstIndexOfRow = (index, columns) => { return index % columns === 0; }; export const hasDisruptorAtRow = (row, disruptorRows) => { return disruptorRows.includes(row.toString()); };