PHP Classes

File: src/utils/pagination-response.js

Recommend this page to a friend!
  Classes of Maniruzzaman Akash   WP Emailer   src/utils/pagination-response.js   Download  
File: src/utils/pagination-response.js
Role: Auxiliary data
Content type: text/plain
Description: Auxiliary data
Class: WP Emailer
Allow WordPress users to configure email settings
Author: By
Last change:
Date: 1 year ago
Size: 699 bytes
 

Contents

Class file image Download
/** * Get paginated data. * * @param {Array} items Array of items. * @param {Number} currentPage Current page no. * @param {Number} perPage Per page no. * * @returns {Object} Paginated response. */ export function getPaginatedData(items, currentPage, perPage) { const totalItems = items.length; const totalPage = Math.ceil(totalItems / perPage); const startIndex = perPage * (currentPage - 1); const endIndex = startIndex + perPage; return { totalPage, totalItems, currentPage, perPage, data: items.filter((item, index) => { return index >= startIndex && index < endIndex; }), }; }