module.exports = (collection, page, qty) => { const itemsPerPage = qty ? qty : 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, totalPages: totalPages, pagesString: `${page + 1}/${totalPages}` }; }