module.exports = (collection, page) => { const itemsPerPage = 10; const index = page * itemsPerPage; const totalPages = Math.ceil(collection.size / itemsPerPage); let state = page === 0 ? 'first' : 'middle'; const thisPage = new Array(); // Map the Djs Collection to an Array const collectionArray = collection.map((command) => command); for (let i = index; i < index + itemsPerPage; i++) { if (collectionArray[i]) { thisPage.push(collectionArray[i]); } else { state = 'last'; break; } if (i === collectionArray.size - 1) { state = 'last'; break; } } return { state: state, thisPage: thisPage, pages: `Page ${page + 1}/${totalPages}` }; }